Exemple #1
0
static int
print_acl_from_stdin(acl_type_t type, int hflag, int iflag, int nflag,
    int qflag, int vflag)
{
	char	*p, pathname[PATH_MAX];
	int	carried_error = 0;

	while (fgets(pathname, (int)sizeof(pathname), stdin)) {
		if ((p = strchr(pathname, '\n')) != NULL)
			*p = '\0';
		if (print_acl(pathname, type, hflag, iflag, nflag,
		    qflag, vflag) == -1) {
			carried_error = -1;
		}
	}

	return(carried_error);
}
int main(int argc, char *argv[])
{
    struct posix_acl *user_acl;
    int f;
    int err;
    int uid;
    char *perm = NULL;
    int index;
    int c;
    int op = 1;
    int time;

    uid_t current_uid;
    struct stat sb;

    user_acl = malloc(sizeof(struct posix_acl));
    user_acl->a_count = 0;

    while ((c = getopt(argc, argv, "hu:g:s:p:t:m:")) != -1) {
        switch (c) {
        case 'h':
            print_help();
            op++;
            return 1;
        case 'u':
            index = user_acl->a_count;
            if (!strcmp(optarg, "o")) {
                user_acl->a_entries[index].e_tag = ACL_USER_OBJ;
                user_acl->a_entries[index].e_id =
                    ACL_UNDEFINED_ID;
            } else {
                user_acl->a_entries[index].e_tag = ACL_USER;
                user_acl->a_entries[index].e_id = atoi(optarg);
            }
            user_acl->a_count = index + 1;
            op = op + 2;
            break;
        case 'g':
            index = user_acl->a_count;
            if (!strcmp(optarg, "g")) {
                user_acl->a_entries[index].e_tag =
                    ACL_GROUP_OBJ;
                user_acl->a_entries[index].e_id =
                    ACL_UNDEFINED_ID;
            } else {
                user_acl->a_entries[index].e_tag = ACL_GROUP;
                user_acl->a_entries[index].e_id = atoi(optarg);
            }
            user_acl->a_count = index + 1;
            op = op + 2;
            break;
        case 's':
            index = user_acl->a_count;
            user_acl->a_entries[index].e_tag = ACL_SESSION;
            user_acl->a_entries[index].e_id = atoi(optarg);
            user_acl->a_count = index + 1;
            op = op + 2;
            break;
        case 'p':
            index = user_acl->a_count;
            user_acl->a_entries[index].e_tag = ACL_PROCESS;
            user_acl->a_entries[index].e_id = atoi(optarg);
            user_acl->a_count = index + 1;
            op = op + 2;
            break;
        case 't':
            printf("check t: optarg = %s\n", optarg);
            index = user_acl->a_count;
            time = parse_time(optarg);
            if (time < 0) {
                printf("error pase time\n");
                return -1;
            }
            user_acl->a_entries[index].e_tag = ACL_TIME;
            user_acl->a_entries[index].e_id = time;
            user_acl->a_count = index + 1;
            op = op + 2;
            break;
        case 'm':
            perm = optarg;
            break;
        }
    }

    if (perm != NULL) {
        set_perm(user_acl, perm);
        op = op + 2;
    }
    print_acl(user_acl);

    current_uid = getuid();
    if (stat(argv[op], &sb) == -1) {
        printf("error get file stat");
        return -1;
    }
    if (getuid() != sb.st_uid) {
        printf("You can't set acl on this file, because you do not own this file.");
        return -1;
    }

    f = open(argv[op], O_RDWR);
    if (f < 0) {
        printf("error open file\n");
        return -1;
    }

    printf("etag: %d", user_acl->a_entries[0].e_tag);

    err = ioctl(f, ECRYPTFS_SETACL, user_acl);
    if (err < 0) {
        printf("Error set acl\n");
        return -1;
    }
    return 0;

}
Exemple #3
0
int
main(int argc, char *argv[])
{
	acl_type_t	type = ACL_TYPE_ACCESS;
	int	carried_error = 0;
	int	ch, error, i;
	int	hflag, iflag, qflag, nflag, vflag;

	hflag = 0;
	iflag = 0;
	qflag = 0;
	nflag = 0;
	vflag = 0;
	while ((ch = getopt(argc, argv, "dhinqv")) != -1)
		switch(ch) {
		case 'd':
			type = ACL_TYPE_DEFAULT;
			break;
		case 'h':
			hflag = 1;
			break;
		case 'i':
			iflag = 1;
			break;
		case 'n':
			nflag = 1;
			break;
		case 'q':
			qflag = 1;
			break;
		case 'v':
			vflag = 1;
			break;
		default:
			usage();
			return(-1);
		}
	argc -= optind;
	argv += optind;

	if (argc == 0) {
		error = print_acl_from_stdin(type, hflag, iflag, nflag,
		    qflag, vflag);
		return(error ? 1 : 0);
	}

	for (i = 0; i < argc; i++) {
		if (!strcmp(argv[i], "-")) {
			error = print_acl_from_stdin(type, hflag, iflag, nflag,
			    qflag, vflag);
			if (error == -1)
				carried_error = -1;
		} else {
			error = print_acl(argv[i], type, hflag, iflag, nflag,
			    qflag, vflag);
			if (error == -1)
				carried_error = -1;
		}
	}

	return(carried_error ? 1 : 0);
}