Changeset View
Changeset View
Standalone View
Standalone View
bin/getfacl/getfacl.c
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | getgname(gid_t gid) | ||||
if ((gr = getgrgid(gid)) == NULL) { | if ((gr = getgrgid(gid)) == NULL) { | ||||
(void)snprintf(gids, sizeof(gids), "%u", gid); | (void)snprintf(gids, sizeof(gids), "%u", gid); | ||||
return (gids); | return (gids); | ||||
} else | } else | ||||
return (gr->gr_name); | return (gr->gr_name); | ||||
} | } | ||||
/* | |||||
* return an ACL corresponding to the permissions | |||||
* contained in mode_t | |||||
*/ | |||||
static acl_t | |||||
acl_from_mode(const mode_t mode) | |||||
{ | |||||
acl_t acl; | |||||
acl_entry_t entry; | |||||
acl_permset_t perms; | |||||
/* create the ACL */ | |||||
acl = acl_init(3); | |||||
if (!acl) | |||||
return NULL; | |||||
/* First entry: ACL_USER_OBJ */ | |||||
if (acl_create_entry(&acl, &entry) == -1) | |||||
return NULL; | |||||
if (acl_set_tag_type(entry, ACL_USER_OBJ) == -1) | |||||
return NULL; | |||||
if (acl_get_permset(entry, &perms) == -1) | |||||
return NULL; | |||||
if (acl_clear_perms(perms) == -1) | |||||
return NULL; | |||||
/* calculate user mode */ | |||||
if (mode & S_IRUSR) | |||||
if (acl_add_perm(perms, ACL_READ) == -1) | |||||
return NULL; | |||||
if (mode & S_IWUSR) | |||||
if (acl_add_perm(perms, ACL_WRITE) == -1) | |||||
return NULL; | |||||
if (mode & S_IXUSR) | |||||
if (acl_add_perm(perms, ACL_EXECUTE) == -1) | |||||
return NULL; | |||||
if (acl_set_permset(entry, perms) == -1) | |||||
return NULL; | |||||
/* Second entry: ACL_GROUP_OBJ */ | |||||
if (acl_create_entry(&acl, &entry) == -1) | |||||
return NULL; | |||||
if (acl_set_tag_type(entry, ACL_GROUP_OBJ) == -1) | |||||
return NULL; | |||||
if (acl_get_permset(entry, &perms) == -1) | |||||
return NULL; | |||||
if (acl_clear_perms(perms) == -1) | |||||
return NULL; | |||||
/* calculate group mode */ | |||||
if (mode & S_IRGRP) | |||||
if (acl_add_perm(perms, ACL_READ) == -1) | |||||
return NULL; | |||||
if (mode & S_IWGRP) | |||||
if (acl_add_perm(perms, ACL_WRITE) == -1) | |||||
return NULL; | |||||
if (mode & S_IXGRP) | |||||
if (acl_add_perm(perms, ACL_EXECUTE) == -1) | |||||
return NULL; | |||||
if (acl_set_permset(entry, perms) == -1) | |||||
return NULL; | |||||
/* Third entry: ACL_OTHER */ | |||||
if (acl_create_entry(&acl, &entry) == -1) | |||||
return NULL; | |||||
if (acl_set_tag_type(entry, ACL_OTHER) == -1) | |||||
return NULL; | |||||
if (acl_get_permset(entry, &perms) == -1) | |||||
return NULL; | |||||
if (acl_clear_perms(perms) == -1) | |||||
return NULL; | |||||
/* calculate other mode */ | |||||
if (mode & S_IROTH) | |||||
if (acl_add_perm(perms, ACL_READ) == -1) | |||||
return NULL; | |||||
if (mode & S_IWOTH) | |||||
if (acl_add_perm(perms, ACL_WRITE) == -1) | |||||
return NULL; | |||||
if (mode & S_IXOTH) | |||||
if (acl_add_perm(perms, ACL_EXECUTE) == -1) | |||||
return NULL; | |||||
if (acl_set_permset(entry, perms) == -1) | |||||
return NULL; | |||||
return(acl); | |||||
} | |||||
static int | static int | ||||
print_acl(char *path, acl_type_t type, int hflag, int iflag, int nflag, | print_acl(char *path, acl_type_t type, int hflag, int iflag, int nflag, | ||||
int qflag, int vflag) | int qflag, int vflag) | ||||
{ | { | ||||
struct stat sb; | struct stat sb; | ||||
acl_t acl; | acl_t acl; | ||||
char *acl_text; | char *acl_text; | ||||
int error, flags = 0, ret; | int error, flags = 0, ret; | ||||
Show All 39 Lines | print_acl(char *path, acl_type_t type, int hflag, int iflag, int nflag, | ||||
if (!acl) { | if (!acl) { | ||||
if (errno != EOPNOTSUPP) { | if (errno != EOPNOTSUPP) { | ||||
warn("%s", path); | warn("%s", path); | ||||
return(-1); | return(-1); | ||||
} | } | ||||
errno = 0; | errno = 0; | ||||
if (type == ACL_TYPE_DEFAULT) | if (type == ACL_TYPE_DEFAULT) | ||||
return(0); | return(0); | ||||
acl = acl_from_mode(sb.st_mode); | acl = acl_from_mode_np(sb.st_mode); | ||||
if (!acl) { | if (!acl) { | ||||
warn("%s: acl_from_mode() failed", path); | warn("%s: acl_from_mode() failed", path); | ||||
return(-1); | return(-1); | ||||
} | } | ||||
} | } | ||||
if (iflag) | if (iflag) | ||||
flags |= ACL_TEXT_APPEND_ID; | flags |= ACL_TEXT_APPEND_ID; | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |