[Midnightbsd-cvs] src: bin/getfacl: use owner name and group name instead of uid and gid.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jun 29 23:20:01 EDT 2008


Log Message:
-----------
use owner name and group name instead of uid and gid.

Allow suppresion of the header with -q

Modified Files:
--------------
    src/bin/getfacl:
        getfacl.1 (r1.2 -> r1.3)
        getfacl.c (r1.3 -> r1.4)

-------------- next part --------------
Index: getfacl.c
===================================================================
RCS file: /home/cvs/src/bin/getfacl/getfacl.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L bin/getfacl/getfacl.c -L bin/getfacl/getfacl.c -u -r1.3 -r1.4
--- bin/getfacl/getfacl.c
+++ bin/getfacl/getfacl.c
@@ -41,6 +41,8 @@
 
 #include <err.h>
 #include <errno.h>
+#include <grp.h>
+#include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -52,7 +54,33 @@
 usage(void)
 {
 
-	fprintf(stderr, "getfacl [-dh] [file ...]\n");
+	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);
 }
 
 /*
@@ -147,7 +175,7 @@
 }
 
 static int
-print_acl(char *path, acl_type_t type, int hflag)
+print_acl(char *path, acl_type_t type, int hflag, int qflag)
 {
 	struct stat	sb;
 	acl_t	acl;
@@ -168,7 +196,9 @@
 	else
 		more_than_one++;
 
-	printf("#file:%s\n#owner:%d\n#group:%d\n", path, sb.st_uid, sb.st_gid);
+	if (!qflag)
+		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);
@@ -204,7 +234,7 @@
 }
 
 static int
-print_acl_from_stdin(acl_type_t type, int hflag)
+print_acl_from_stdin(acl_type_t type, int hflag, int qflag)
 {
 	char	*p, pathname[PATH_MAX];
 	int	carried_error = 0;
@@ -212,7 +242,7 @@
 	while (fgets(pathname, (int)sizeof(pathname), stdin)) {
 		if ((p = strchr(pathname, '\n')) != NULL)
 			*p = '\0';
-		if (print_acl(pathname, type, hflag) == -1) {
+		if (print_acl(pathname, type, hflag, qflag) == -1) {
 			carried_error = -1;
 		}
 	}
@@ -226,10 +256,11 @@
 	acl_type_t	type = ACL_TYPE_ACCESS;
 	int	carried_error = 0;
 	int	ch, error, i;
-	int	hflag;
+	int	hflag, qflag;
 
 	hflag = 0;
-	while ((ch = getopt(argc, argv, "dh")) != -1)
+	qflag = 0;
+	while ((ch = getopt(argc, argv, "dhq")) != -1)
 		switch(ch) {
 		case 'd':
 			type = ACL_TYPE_DEFAULT;
@@ -237,6 +268,9 @@
 		case 'h':
 			hflag = 1;
 			break;
+		case 'q':
+			qflag = 1;
+			break;
 		default:
 			usage();
 			return(-1);
@@ -245,17 +279,17 @@
 	argv += optind;
 
 	if (argc == 0) {
-		error = print_acl_from_stdin(type, hflag);
+		error = print_acl_from_stdin(type, hflag, qflag);
 		return(error ? 1 : 0);
 	}
 
 	for (i = 0; i < argc; i++) {
 		if (!strcmp(argv[i], "-")) {
-			error = print_acl_from_stdin(type, hflag);
+			error = print_acl_from_stdin(type, hflag, qflag);
 			if (error == -1)
 				carried_error = -1;
 		} else {
-			error = print_acl(argv[i], type, hflag);
+			error = print_acl(argv[i], type, hflag, qflag);
 			if (error == -1)
 				carried_error = -1;
 		}
Index: getfacl.1
===================================================================
RCS file: /home/cvs/src/bin/getfacl/getfacl.1,v
retrieving revision 1.2
retrieving revision 1.3
diff -L bin/getfacl/getfacl.1 -L bin/getfacl/getfacl.1 -u -r1.2 -r1.3
--- bin/getfacl/getfacl.1
+++ bin/getfacl/getfacl.1
@@ -31,7 +31,7 @@
 .\" Developed by the TrustedBSD Project.
 .\" Support for POSIX.1e access control lists.
 .\"
-.Dd December 30, 2002
+.Dd June 29, 2008
 .Dt GETFACL 1
 .Os
 .Sh NAME
@@ -65,6 +65,10 @@
 .It Fl h
 If the target of the operation is a symbolic link, return the ACL from
 the symbolic link itself rather than following the link.
+.It Fl q
+Do not write commented information about file name and ownership.
+This is
+useful when dealing with filenames with unprintable characters.
 .El
 .Pp
 The following operand is available:


More information about the Midnightbsd-cvs mailing list