Example #1
0
File: acl.c Project: vanElden/burp
int get_acl(struct asfd *asfd, struct sbuf *sb,
	char **acltext, size_t *alen, struct cntr *cntr)
{
	acl_t acl=NULL;
	const char *path=sb->path.buf;

	if((acl=acl_contains_something(path, ACL_TYPE_ACCESS)))
	{
		if(get_acl_string(asfd, acl,
			acltext, alen, path, META_ACCESS_ACL, cntr))
		{
			acl_free(acl);
			return -1;
		}
		acl_free(acl);
	}

	if(S_ISDIR(sb->statp.st_mode))
	{
		if((acl=acl_contains_something(path, ACL_TYPE_DEFAULT)))
		{
			if(get_acl_string(asfd, acl,
				acltext, alen, path, META_DEFAULT_ACL, cntr))
			{
				acl_free(acl);
				return -1;
			}
			acl_free(acl);
		}
	}
	return 0;
}
Example #2
0
File: acl.c Project: grke/burp
int get_acl(struct asfd *asfd, const char *path, int isdir,
	char **acltext, size_t *alen, struct cntr *cntr)
{
	int ret=-1;
	acl_t acl=NULL;

	if((acl=acl_contains_something(path, ACL_TYPE_ACCESS)))
	{
		if(get_acl_string(asfd, acl,
			acltext, alen, path, META_ACCESS_ACL, cntr))
				goto end;
	}

	if(isdir)
	{
		if(acl) acl_free(acl);
		if((acl=acl_contains_something(path, ACL_TYPE_DEFAULT)))
		{
			if(get_acl_string(asfd, acl,
				acltext, alen, path, META_DEFAULT_ACL, cntr))
					goto end;
		}
	}
	ret=0;
end:
	if(acl) acl_free(acl);
	return ret;
}
Example #3
0
/*
 * This file does the per-file evaluation and is run to generate every entry
 * in the manifest.
 *
 * All output is written to a pipe which is read by the child process,
 * which is running output_manifest().
 */
static int
eval_file(const char *fname, const struct stat64 *statb)
{
	int	fd, ret, err_code, i;
	char	last_field[PATH_MAX], ftype, *acl_str,
		*quoted_name;

	err_code = EXIT;

	switch (statb->st_mode & S_IFMT) {
	/* Regular file */
	case S_IFREG: ftype = 'F'; break;

	/* Directory */
	case S_IFDIR: ftype = 'D'; break;

	/* Block Device */
	case S_IFBLK: ftype = 'B'; break;

	/* Character Device */
	case S_IFCHR: ftype = 'C'; break;

	/* Named Pipe */
	case S_IFIFO: ftype = 'P'; break;

	/* Socket */
	case S_IFSOCK: ftype = 'S'; break;

	/* Door */
	case S_IFDOOR: ftype = 'O'; break;

	/* Symbolic link */
	case S_IFLNK: ftype = 'L'; break;

	default: ftype = '-'; break;
	}

	/* First, make sure this file should be cataloged */

	if ((subtree_root != NULL) &&
	    (exclude_fname(fname, ftype, subtree_root)))
		return (err_code);

	for (i = 0; i < PATH_MAX; i++)
		last_field[i] = '\0';

	/*
	 * Regular files, compute the MD5 checksum and put it into 'last_field'
	 * UNLESS instructed to ignore the checksums.
	 */
	if (ftype == 'F') {
		if (compute_chksum) {
			fd = open(fname, O_RDONLY|O_LARGEFILE);
			if (fd < 0) {
				err_code = WARNING_EXIT;
				perror(fname);

				/* default value since the computution failed */
				(void) strcpy(last_field, "-");
			} else {
				if (generate_hash(fd, last_field) != 0) {
					err_code = WARNING_EXIT;
					(void) fprintf(stderr, CONTENTS_WARN,
					    fname);
					(void) strcpy(last_field, "-");
				}
			}
			(void) close(fd);
		}
		/* Instructed to ignore checksums, just put in a '-' */
		else
			(void) strcpy(last_field, "-");
	}

	/*
	 * For symbolic links, put the destination of the symbolic link into
	 * 'last_field'
	 */
	if (ftype == 'L') {
		ret = readlink(fname, last_field, sizeof (last_field));
		if (ret < 0) {
			err_code = WARNING_EXIT;
			perror(fname);

			/* default value since the computation failed */
			(void) strcpy(last_field, "-");
		}
		else
			(void) strlcpy(last_field,
			    sanitized_fname(last_field, B_FALSE),
			    sizeof (last_field));

		/*
		 * Boundary condition: possible for a symlink to point to
		 * nothing [ ln -s '' link_name ].  For this case, set the
		 * destination to "\000".
		 */
		if (strlen(last_field) == 0)
			(void) strcpy(last_field, "\\000");
	}

	acl_str = get_acl_string(fname, statb, &err_code);

	/* Sanitize 'fname', so its in the proper format for the manifest */
	quoted_name = sanitized_fname(fname, B_TRUE);

	/* Start to build the entry.... */
	(void) printf("%s %c %d %o %s %x %d %d", quoted_name, ftype,
	    (int)statb->st_size, (int)statb->st_mode, acl_str,
	    (int)statb->st_mtime, (int)statb->st_uid, (int)statb->st_gid);

	/* Finish it off based upon whether or not it's a device node */
	if ((ftype == 'B') && (ftype == 'C'))
		(void) printf(" %x\n", (int)statb->st_rdev);
	else if (strlen(last_field) > 0)
		(void) printf(" %s\n", last_field);
	else
		(void) printf("\n");

	/* free the memory consumed */
	free(acl_str);
	free(quoted_name);

	return (err_code);
}