diff options
author | kevlo <kevlo@FreeBSD.org> | 2007-09-19 02:04:47 +0000 |
---|---|---|
committer | kevlo <kevlo@FreeBSD.org> | 2007-09-19 02:04:47 +0000 |
commit | a3a58105f1952205e27debcee1e7fca92380d1b7 (patch) | |
tree | 1dd3ce28182b6f30322cbad9352786db17b3ee8e /bin/getfacl/getfacl.c | |
parent | c1a25d60970fe027ade04ff351d7ecedf52bf81b (diff) | |
download | FreeBSD-src-a3a58105f1952205e27debcee1e7fca92380d1b7.zip FreeBSD-src-a3a58105f1952205e27debcee1e7fca92380d1b7.tar.gz |
Use owner name and owning group name instead of uid and gid
for displaying the three-line comment header by default.
Reviewed by: kientzle
Approved by: re (bmah)
Diffstat (limited to 'bin/getfacl/getfacl.c')
-rw-r--r-- | bin/getfacl/getfacl.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/bin/getfacl/getfacl.c b/bin/getfacl/getfacl.c index b023cb4..1ab86cd 100644 --- a/bin/getfacl/getfacl.c +++ b/bin/getfacl/getfacl.c @@ -41,6 +41,8 @@ __FBSDID("$FreeBSD$"); #include <err.h> #include <errno.h> +#include <grp.h> +#include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -55,6 +57,32 @@ usage(void) fprintf(stderr, "getfacl [-dhq] [file ...]\n"); } +static char * +getuname(uid_t uid) +{ + struct passwd *pw; + static char uids[10]; + + if ((pw = getpwuid(uid)) == NULL) { + (void)snprintf(uids, sizeof(uids), "%u", uid); + return (uids); + } else + return (pw->pw_name); +} + +static char * +getgname(gid_t gid) +{ + struct group *gr; + static char gids[10]; + + if ((gr = getgrgid(gid)) == NULL) { + (void)snprintf(gids, sizeof(gids), "%u", gid); + return (gids); + } else + return (gr->gr_name); +} + /* * return an ACL corresponding to the permissions * contained in struct stat @@ -169,8 +197,8 @@ print_acl(char *path, acl_type_t type, int hflag, int qflag) more_than_one++; if (!qflag) - printf("#file:%s\n#owner:%d\n#group:%d\n", path, sb.st_uid, - sb.st_gid); + printf("# file: %s\n# owner: %s\n# group: %s\n", path, + getuname(sb.st_uid), getgname(sb.st_gid)); if (hflag) acl = acl_get_link_np(path, type); |