diff mbox

[09/12] fedfs.h: Narrow the range of field types in struct fedfs_nfs_fsl

Message ID 20111213225217.15402.97778.stgit@degas.1015granger.net
State Accepted
Headers show

Commit Message

Chuck Lever Dec. 13, 2011, 10:52 p.m. UTC
The type of some of the fields in struct fedfs_nfs_fsl allow the
expression of values outside the ranges specified in the NSDB
protocol draft.

These fields are supposed to match up with the type ranges in NFS's
fs_locations_info4 data structure.

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

 src/include/nsdb.h          |   20 ++++++++++----------
 src/libnsdb/fileserver.c    |   20 ++++++++++----------
 src/libnsdb/ldap.c          |   35 +++++++++++++++++++++++++++++++++++
 src/libnsdb/nsdb-internal.h |    2 ++
 4 files changed, 57 insertions(+), 20 deletions(-)
diff mbox

Patch

diff --git a/src/include/nsdb.h b/src/include/nsdb.h
index 2ba1b7a..942db23 100644
--- a/src/include/nsdb.h
+++ b/src/include/nsdb.h
@@ -67,16 +67,16 @@  struct fedfs_nfs_fsl {
 	_Bool			  fn_gen_going;
 	_Bool			  fn_gen_split;
 	_Bool			  fn_trans_rdma;
-	int			  fn_class_simul;
-	int			  fn_class_handle;
-	int			  fn_class_fileid;
-	int			  fn_class_writever;
-	int			  fn_class_change;
-	int			  fn_class_readdir;
-	int			  fn_readrank;
-	int			  fn_readorder;
-	int			  fn_writerank;
-	int			  fn_writeorder;
+	unsigned char		  fn_class_simul;
+	unsigned char		  fn_class_handle;
+	unsigned char		  fn_class_fileid;
+	unsigned char		  fn_class_writever;
+	unsigned char		  fn_class_change;
+	unsigned char		  fn_class_readdir;
+	unsigned char		  fn_readrank;
+	unsigned char		  fn_readorder;
+	unsigned char		  fn_writerank;
+	unsigned char		  fn_writeorder;
 	_Bool			  fn_varsub;
 	int			  fn_validfor;
 };
diff --git a/src/libnsdb/fileserver.c b/src/libnsdb/fileserver.c
index b22d83f..b1b3deb 100644
--- a/src/libnsdb/fileserver.c
+++ b/src/libnsdb/fileserver.c
@@ -687,34 +687,34 @@  nsdb_resolve_fsn_parse_attribute(LDAP *ld, LDAPMessage *entry, char *attr,
 		retval = nsdb_parse_singlevalue_bool(attr, values,
 				&nfsl->fn_trans_rdma);
 	else if (strcasecmp(attr, "fedfsNfsClassSimul") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_class_simul);
 	else if (strcasecmp(attr, "fedfsNfsClassHandle") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_class_handle);
 	else if (strcasecmp(attr, "fedfsNfsClassFileid") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_class_fileid);
 	else if (strcasecmp(attr, "fedfsNfsClassWritever") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_class_writever);
 	else if (strcasecmp(attr, "fedfsNfsClassChange") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_class_change);
 	else if (strcasecmp(attr, "fedfsNfsClassReaddir") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_class_readdir);
 	else if (strcasecmp(attr, "fedfsNfsReadRank") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_readrank);
 	else if (strcasecmp(attr, "fedfsNfsReadOrder") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_readorder);
 	else if (strcasecmp(attr, "fedfsNfsWriteRank") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_readrank);
 	else if (strcasecmp(attr, "fedfsNfsWriteOrder") == 0)
-		retval = nsdb_parse_singlevalue_int(attr, values,
+		retval = nsdb_parse_singlevalue_uchar(attr, values,
 				&nfsl->fn_readorder);
 	else if (strcasecmp(attr, "fedfsNfsVarSub") == 0)
 		retval = nsdb_parse_singlevalue_bool(attr, values,
diff --git a/src/libnsdb/ldap.c b/src/libnsdb/ldap.c
index 618b62a..d972ef8 100644
--- a/src/libnsdb/ldap.c
+++ b/src/libnsdb/ldap.c
@@ -207,6 +207,41 @@  nsdb_parse_singlevalue_bool(char *attr, struct berval **values, _Bool *result)
 }
 
 /**
+ * Parse the value of a single-value unsigned char attribute
+ *
+ * @param attr a NUL-terminated C string containing the name of an attribute
+ * @param values a NULL-terminated array of pointers to bervals
+ * @param result OUT: unsigned char into which to copy the value
+ * @return a FedFsStatus code
+ */
+FedFsStatus
+nsdb_parse_singlevalue_uchar(char *attr, struct berval **values,
+		unsigned char *result)
+{
+	char *endptr;
+	long tmp;
+
+	if (values[1] != NULL) {
+		xlog(L_ERROR, "%s: Expecting only one value for attribute %s",
+			__func__, attr);
+		return FEDFS_ERR_NSDB_RESPONSE;
+	}
+
+	errno = 0;
+	tmp = strtol(values[0]->bv_val, &endptr, 10);
+	if (errno != 0 || *endptr != '\0' || tmp < 0 || tmp > 255) {
+		xlog(D_CALL, "%s: Attribute %s contains out-of-range value %.*s",
+			__func__, attr, values[0]->bv_len, values[0]->bv_val);
+		return FEDFS_ERR_NSDB_RESPONSE;
+	}
+
+	*result = (unsigned char)tmp;
+	xlog(D_CALL, "%s: Attribute %s contains value %d",
+		__func__, attr, *result);
+	return FEDFS_OK;
+}
+
+/**
  * Parse the value of a single-value integer attribute
  *
  * @param attr a NUL-terminated C string containing the name of an attribute
diff --git a/src/libnsdb/nsdb-internal.h b/src/libnsdb/nsdb-internal.h
index 7c63333..b6414b1 100644
--- a/src/libnsdb/nsdb-internal.h
+++ b/src/libnsdb/nsdb-internal.h
@@ -63,6 +63,8 @@  void		 nsdb_init_del_attribute(LDAPMod *mod,
 
 FedFsStatus	 nsdb_parse_singlevalue_bool(char *attr,
 				struct berval **values, _Bool *result);
+FedFsStatus	 nsdb_parse_singlevalue_uchar(char *attr,
+				struct berval **values, unsigned char *result);
 FedFsStatus	 nsdb_parse_singlevalue_int(char *attr,
 				struct berval **values, int *result);
 FedFsStatus	 nsdb_parse_singlevalue_str(char *attr,