Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Aug 2008 13:01:40 GMT
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 147078 for review
Message-ID:  <200808101301.m7AD1eZ8001216@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147078

Change 147078 by trasz@trasz_traszkan on 2008/08/10 13:01:20

	Parse appended id.  Note that it's not really compatible with
	Sun's implementation - they tend to omit "flags" field; parsing
	it in that form would be harder.  Sun folks just use yacc parser.

Affected files ...

.. //depot/projects/soc2008/trasz_nfs4acl/lib/libc/posix1e/acl_from_text_nfs4.c#6 edit

Differences ...

==== //depot/projects/soc2008/trasz_nfs4acl/lib/libc/posix1e/acl_from_text_nfs4.c#6 (text+ko) ====

@@ -43,9 +43,15 @@
 
 #define MAX_ENTRY_LENGTH 512
 
+/*
+ * Parse the tag field of ACL entry passed as "str".  If qualifier
+ * needs to follow, then the variable referenced by "need_qualifier"
+ * is set to 1, otherwise it's set to 0.
+ */
 static int
 parse_tag(const char *str, acl_entry_t entry, int *need_qualifier)
 {
+	assert(need_qualifier != NULL);
 	*need_qualifier = 0;
 
 	if (strcmp(str, "owner@") == 0)
@@ -70,8 +76,13 @@
 	return (-1);
 }
 
+/*
+ * Parse the qualifier field of ACL entry passed as "str".
+ * If user or group name cannot be resolved, then the variable
+ * referenced by "need_qualifier" is set to 1.
+ */
 static int
-parse_qualifier(char *str, acl_entry_t entry)
+parse_qualifier(char *str, acl_entry_t entry, int *need_qualifier)
 {
 	int qualifier_length, error;
 	id_t id;
@@ -80,6 +91,9 @@
 	struct group *grp;
 	acl_tag_t tag;
 
+	assert(need_qualifier != NULL);
+	*need_qualifier = 0;
+
 	qualifier_length = strlen(str);
 
 	if (qualifier_length == 0) {
@@ -110,8 +124,8 @@
 		/* XXX: Thread-unsafe. */
 		pwd = getpwnam(str);
 		if (pwd == NULL) {
-			warnx("malformed ACL: unknown user \"%s\"", str);
-			return (-1);
+			*need_qualifier = 1;
+			return (0);
 		}
 
 		return (acl_set_qualifier(entry, &(pwd->pw_uid)));
@@ -120,8 +134,8 @@
 	/* XXX: Thread-unsafe. */
 	grp = getgrnam(str);
 	if (grp == NULL) {
-		warnx("malformed ACL: unknown group \"%s\"", str);
-		return (-1);
+		*need_qualifier = 1;
+		return (0);
 	}
 
 	return (acl_set_qualifier(entry, &(grp->gr_gid)));
@@ -176,6 +190,29 @@
 }
 
 static int
+parse_appended_id(char *str, acl_entry_t entry)
+{
+	int qualifier_length;
+	char *end;
+	id_t id;
+
+	qualifier_length = strlen(str);
+	if (qualifier_length == 0) {
+		warnx("malformed ACL: \"appended id\" field present, "
+	           "but empty");
+		return (-1);
+	}
+
+	id = strtod(str, &end);
+	if (end - str != qualifier_length) {
+		warnx("malformed ACL: appended id is not a number");
+		return (-1);
+	}
+
+	return (acl_set_qualifier(entry, &id));
+}
+
+static int
 number_of_colons(const char *str)
 {
 	int count = 0;
@@ -195,7 +232,7 @@
 {
 	int error, need_qualifier;
 	acl_entry_t entry;
-	char *field;
+	char *field, *qualifier_field;
 
 	error = acl_create_entry(&aclp, &entry);
 	if (error)
@@ -223,8 +260,8 @@
 	if (need_qualifier) {
 		if (str == NULL)
 			goto truncated_entry;
-		field = strsep(&str, ":");
-		error = parse_qualifier(field, entry);
+		qualifier_field = field = strsep(&str, ":");
+		error = parse_qualifier(field, entry, &need_qualifier);
 		if (error)
 			goto malformed_field;
 	}
@@ -248,10 +285,23 @@
 
 	if (str == NULL)
 		goto truncated_entry;
-	error = parse_extended(str, entry);
+	field = strsep(&str, ":");
+	error = parse_extended(field, entry);
 	if (error)
 		goto malformed_field;
 
+	if (need_qualifier) {
+		if (str == NULL) {
+			warnx("malformed ACL: unknown user or group name "
+			    "\"%s\"", qualifier_field);
+			goto truncated_entry;
+		}
+
+		error = parse_appended_id(str, entry);
+		if (error)
+			goto malformed_field;
+	}
+
 	return (0);
 
 truncated_entry:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808101301.m7AD1eZ8001216>