コード例 #1
0
ファイル: stringrep.c プロジェクト: DanAlbert/selinux
access_vector_t string_to_av_perm(security_class_t tclass, const char *s)
{
	struct discover_class_node *node;
	security_class_t kclass = unmap_class(tclass);

	node = get_class_cache_entry_value(kclass);
	if (node != NULL) {
		size_t i;
		for (i=0; i<MAXVECTORS && node->perms[i] != NULL; i++)
			if (strcmp(node->perms[i],s) == 0)
				return map_perm(tclass, 1<<i);
	}

	errno = EINVAL;
	return 0;
}
コード例 #2
0
ファイル: perm.c プロジェクト: JamesLinus/vsta
/*
 * fchmod()
 *	Change mode of open file
 *
 * Our mapping of POSIXese to VSTa is as follows:
 *	"Other" affects the default protection granted
 *	"Group" affects all intermediate protections
 *	"User" affects the final, most specific match
 */
int
fchmod(int fd, int mode)
{
	char *prot, buf[PERMLEN*8];
	uchar prots[PERMLEN+1];
	uint nprot, x;

	/*
	 * Get current protections
	 */
	prot = rstat(__fd_port(fd), "acc");
	if (prot == 0) {
		return(__seterr(EINVAL));
	}

	/*
	 * Explode out to prots[]
	 */
	nprot = 0;
	while ((nprot < (PERMLEN + 1)) && *prot && (*prot != '\n')) {
		prots[nprot++] = atoi(prot);
		prot = strchr(prot, '/');
		if (!prot) {
			break;
		}
		prot += 1;
	}

	/*
	 * Now mung up the protections based on a mapping of POSIX
	 * protection concepts.
	 */

	/*
	 * "User".  Apllies to the most specific.
	 */
	map_perm(&prots[nprot-1], mode);

	/*
	 * "Group".  Applies to all of the rest except the most specific.
	 */
	mode <<= 3;
	for (x = 1; x < (nprot-1); ++x) {
		map_perm(&prots[x], mode);
	}

	/*
	 * "Other".  Affects first (default) protection slot
	 */
	mode <<= 3;
	map_perm(&prots[0], mode);

	/*
	 * Build a "acc=X" to reflect potentially changed protection
	 */
	strcpy(buf, "acc=");
	for (x = 0; x < nprot; ++x) {
		sprintf(buf + strlen(buf), "%s%d",
			x ? "/" : "",
			prots[x]);
	}
	strcat(buf, "\n");

	/*
	 * Send it back
	 */
	return(wstat(__fd_port(fd), buf));
}