Patchwork [4/8] libnsdb: Use path array for fedfsNfsPath attribute in nsdb_update_fsl_s()

login
register
mail settings
Submitter Chuck Lever
Date Dec. 21, 2011, 10:51 p.m.
Message ID <20111221225153.23950.97724.stgit@degas.1015granger.net>
Download mbox | patch
Permalink /patch/132752/
State Accepted
Headers show

Comments

Chuck Lever - Dec. 21, 2011, 10:51 p.m.
Since the beginning, I've tried to stick with representing local
pathnames using a C string, and converting to the array form only when
I need to transmit the pathname off-system.  That seemed more natural
for operating on Linux, whose VFS is POSIX-style.

However, if we want to allow creation of junctions that point to
servers that don't necessarily use '/' as the pathname component
separator, we will need a more general way to represent pathnames in
struct fedfs_fsl and friends.

That general way to represent pathnames is as an array of component
character strings.  This is, after all, what is done for fs_locations
in NFS.

Change the nsdb_update_fsl_s() API to expect an array of components
when asked to change the fedfsNfsPath attribute of an NFS FSL record.

Aside from exposing the richer fs_locations data structure to FedFS
callers, this change moves an important part of pathname resolution
policy out of libnsdb and into callers.  It should also provide an
opportunity for stronger and more consistent checks on incoming
pathnames.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 src/include/nsdb.h          |    2 +-
 src/libnsdb/administrator.c |    8 +++++---
 src/nsdbc/nsdb-update-fsl.c |   13 +++++++++++++
 3 files changed, 19 insertions(+), 4 deletions(-)

Patch

diff --git a/src/include/nsdb.h b/src/include/nsdb.h
index ba31135..84cabaf 100644
--- a/src/include/nsdb.h
+++ b/src/include/nsdb.h
@@ -279,7 +279,7 @@  FedFsStatus	 nsdb_delete_fsl_s(nsdb_t host, const char *nce,
 FedFsStatus	 nsdb_update_fsl_s(nsdb_t host, const char *nce,
 				const char *fsl_uuid,
 				const char *attribute,
-				const char *value,
+				const void *value,
 				unsigned int *ldap_err);
 
 /**
diff --git a/src/libnsdb/administrator.c b/src/libnsdb/administrator.c
index 117b0ba..cff679c 100644
--- a/src/libnsdb/administrator.c
+++ b/src/libnsdb/administrator.c
@@ -1001,14 +1001,14 @@  nsdb_update_fsl_remove_attribute_s(LDAP *ld, const char *dn,
  */
 static FedFsStatus
 nsdb_update_fsl_update_attribute_s(LDAP *ld, const char *dn,
-		const char *attribute, const char *value,
+		const char *attribute, const void *value,
 		unsigned int *ldap_err)
 {
 	struct berval newval;
 	FedFsStatus retval;
 
 	if (strcasecmp(attribute, "fedfsNfsPath") == 0) {
-		retval = nsdb_posix_path_to_xdr(value, &newval);
+		retval = nsdb_path_array_to_xdr((char * const *)value, &newval);
 		if (retval != FEDFS_OK)
 			return retval;
 	} else {
@@ -1020,6 +1020,8 @@  nsdb_update_fsl_update_attribute_s(LDAP *ld, const char *dn,
 
 	retval = nsdb_modify_attribute_s(ld, dn, attribute,
 						&newval, ldap_err);
+	if (strcasecmp(attribute, "fedfsNfsPath") == 0)
+		ber_memfree(newval.bv_val);
 	if (retval != FEDFS_OK)
 		return retval;
 
@@ -1046,7 +1048,7 @@  nsdb_update_fsl_update_attribute_s(LDAP *ld, const char *dn,
  */
 FedFsStatus
 nsdb_update_fsl_s(nsdb_t host, const char *nce, const char *fsl_uuid,
-		const char *attribute, const char *value,
+		const char *attribute, const void *value,
 		unsigned int *ldap_err)
 {
 	FedFsStatus retval;
diff --git a/src/nsdbc/nsdb-update-fsl.c b/src/nsdbc/nsdb-update-fsl.c
index ff0db80..e025a15 100644
--- a/src/nsdbc/nsdb-update-fsl.c
+++ b/src/nsdbc/nsdb-update-fsl.c
@@ -192,6 +192,17 @@  main(int argc, char **argv)
 		nsdb_update_fsl_usage(progname);
 	}
 
+	if (strcasecmp(attribute, "fedfsNfsPath") == 0) {
+		char **path_array;
+		retval = nsdb_posix_to_path_array(value, &path_array);
+		if (retval != FEDFS_OK) {
+			fprintf(stderr, "Bad path: %s\n",
+				nsdb_display_fedfsstatus(retval));
+			goto out;
+		}
+		value = (char *)path_array;
+	}
+
 	retval = nsdb_lookup_nsdb(nsdbname, nsdbport, &host, NULL);
 	switch (retval) {
 	case FEDFS_OK:
@@ -265,6 +276,8 @@  main(int argc, char **argv)
 
 out_free:
 	nsdb_free_nsdb(host);
+	if (strcasecmp(attribute, "fedfsNfsPath") == 0)
+		nsdb_free_string_array((char **)value);
 
 out:
 	exit((int)retval);