PERFORCE change 143831 for review

Edward Tomasz Napierala trasz at FreeBSD.org
Fri Jun 20 18:34:39 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=143831

Change 143831 by trasz at trasz_traszkan on 2008/06/20 18:33:52

	Refactor acl_from_text(3) by breaking out part that is POSIX-specific.
	There should be no functional change.

Affected files ...

.. //depot/projects/soc2008/trasz_nfs4acl/lib/libc/posix1e/acl_from_text.c#2 edit

Differences ...

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

@@ -109,6 +109,91 @@
 	}
 }
 
+static int
+_posix1e_acl_entry_from_text(acl_t aclp, char *entry)
+{
+	acl_tag_t	 t;
+	acl_perm_t	 p;
+	char		*tag, *qualifier, *permission;
+	uid_t		 id;
+	int		 error;
+
+	/* Split into three ':' delimited fields. */
+	tag = strsep(&entry, ":");
+	if (tag == NULL) {
+		errno = EINVAL;
+		return (-1);
+	}
+	tag = string_skip_whitespace(tag);
+	if ((*tag == '\0') && (!entry)) {
+		/*
+		 * Is an entirely comment line, skip to next
+		 * comma.
+		 */
+		return (0);
+	}
+	string_trim_trailing_whitespace(tag);
+
+	qualifier = strsep(&entry, ":");
+	if (qualifier == NULL) {
+		errno = EINVAL;
+		return (-1);
+	}
+	qualifier = string_skip_whitespace(qualifier);
+	string_trim_trailing_whitespace(qualifier);
+
+	permission = strsep(&entry, ":");
+	if (permission == NULL || entry) {
+		errno = EINVAL;
+		return (-1);
+	}
+	permission = string_skip_whitespace(permission);
+	string_trim_trailing_whitespace(permission);
+
+	t = acl_string_to_tag(tag, qualifier);
+	if (t == -1) {
+		errno = EINVAL;
+		return (-1);
+	}
+
+	error = _posix1e_acl_string_to_perm(permission, &p);
+	if (error == -1) {
+		errno = EINVAL;
+		return (-1);
+	}		
+
+	switch(t) {
+		case ACL_USER_OBJ:
+		case ACL_GROUP_OBJ:
+		case ACL_MASK:
+		case ACL_OTHER:
+			if (*qualifier != '\0') {
+				errno = EINVAL;
+				return (-1);
+			}
+			id = 0;
+			break;
+
+		case ACL_USER:
+		case ACL_GROUP:
+			error = _posix1e_acl_name_to_id(t, qualifier,
+					&id);
+			if (error == -1)
+				return (-1);
+			break;
+
+		default:
+			errno = EINVAL;
+			return (-1);
+	}
+
+	error = _posix1e_acl_add_entry(aclp, t, id, p);
+	if (error == -1)
+		return (-1);
+
+	return (0);
+}
+
 /*
  * acl_from_text -- Convert a string into an ACL.
  * Postpone most validity checking until the end and call acl_valid() to do
@@ -117,13 +202,9 @@
 acl_t
 acl_from_text(const char *buf_p)
 {
-	acl_tag_t	 t;
-	acl_perm_t	 p;
 	acl_t		 acl;
 	char		*mybuf_p, *line, *cur, *notcomment, *comment, *entry;
-	char		*tag, *qualifier, *permission;
 	int		 error;
-	uid_t		 id;
 
 	/* Local copy we can mess up. */
 	mybuf_p = strdup(buf_p);
@@ -145,77 +226,8 @@
 
 		/* Inner loop: delimit at ',' boundaries. */
 		while ((entry = strsep(&notcomment, ","))) {
-			/* Now split into three ':' delimited fields. */
-			tag = strsep(&entry, ":");
-			if (tag == NULL) {
-				errno = EINVAL;
-				goto error_label;
-			}
-			tag = string_skip_whitespace(tag);
-			if ((*tag == '\0') && (!entry)) {
-				/*
-				 * Is an entirely comment line, skip to next
-				 * comma.
-				 */
-				continue;
-			}
-			string_trim_trailing_whitespace(tag);
-
-			qualifier = strsep(&entry, ":");
-			if (qualifier == NULL) {
-				errno = EINVAL;
-				goto error_label;
-			}
-			qualifier = string_skip_whitespace(qualifier);
-			string_trim_trailing_whitespace(qualifier);
-
-			permission = strsep(&entry, ":");
-			if (permission == NULL || entry) {
-				errno = EINVAL;
-				goto error_label;
-			}
-			permission = string_skip_whitespace(permission);
-			string_trim_trailing_whitespace(permission);
-
-			t = acl_string_to_tag(tag, qualifier);
-			if (t == -1) {
-				errno = EINVAL;
-				goto error_label;
-			}
-
-			error = _posix1e_acl_string_to_perm(permission, &p);
-			if (error == -1) {
-				errno = EINVAL;
-				goto error_label;
-			}		
-
-			switch(t) {
-			case ACL_USER_OBJ:
-			case ACL_GROUP_OBJ:
-			case ACL_MASK:
-			case ACL_OTHER:
-				if (*qualifier != '\0') {
-					errno = EINVAL;
-					goto error_label;
-				}
-				id = 0;
-				break;
-
-			case ACL_USER:
-			case ACL_GROUP:
-				error = _posix1e_acl_name_to_id(t, qualifier,
-				    &id);
-				if (error == -1)
-					goto error_label;
-				break;
-
-			default:
-				errno = EINVAL;
-				goto error_label;
-			}
-
-			error = _posix1e_acl_add_entry(acl, t, id, p);
-			if (error == -1)
+			error = _posix1e_acl_entry_from_text(acl, entry);
+			if (error)
 				goto error_label;
 		}
 	}


More information about the p4-projects mailing list