[SCM] Samba Shared Repository - branch v3-0-test updated - release-3-0-32-46-g4558c09

Jeff Layton jlayton at samba.org
Thu Oct 9 14:52:57 GMT 2008


The branch, v3-0-test has been updated
       via  4558c09c921793dd358de3ad4b9b4dd091e43662 (commit)
       via  41849ee120297b845ef288c76b45d039ad04112d (commit)
      from  cfa9d20db78875969ea8065161f8efdf5281d003 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-0-test


- Log -----------------------------------------------------------------
commit 4558c09c921793dd358de3ad4b9b4dd091e43662
Author: Jeff Layton <jlayton at redhat.com>
Date:   Thu Oct 9 10:51:33 2008 -0400

    mount.cifs: make return codes match the return codes for /bin/mount (try #3)
    
    The manpage for /bin/mount specifies that the return code should be a
    positive integer (actually, it's a bitfield). Clean up the return
    codes from mount.cifs to make them match the expected return values
    from /bin/mount. This necessary for proper integration with autofs.
    
    This is the third attempt at this patch. The changes here are minor,
    just changing some return's from main() into exit() calls for
    consistency's sake.
    
    Signed-off-by: Jeff Layton <jlayton at redhat.com>

commit 41849ee120297b845ef288c76b45d039ad04112d
Author: Jeff Layton <jlayton at redhat.com>
Date:   Thu Oct 9 10:47:45 2008 -0400

    mount.cifs: have uppercase_string return success on NULL pointer
    
    We currently don't attempt to uppercase the device portion of the mount
    string if there isn't a prefixpath. Fix that by making uppercase_string
    return success without doing anything on a NULL pointer.
    
    Signed-off-by: Jeff Layton <jlayton at redhat.com>

-----------------------------------------------------------------------

Summary of changes:
 source/client/mount.cifs.c |   88 ++++++++++++++++++++++++-------------------
 1 files changed, 49 insertions(+), 39 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/client/mount.cifs.c b/source/client/mount.cifs.c
index 0d27c05..c97e938 100644
--- a/source/client/mount.cifs.c
+++ b/source/client/mount.cifs.c
@@ -68,6 +68,15 @@
 
 #define CONST_DISCARD(type, ptr)      ((type) ((void *) (ptr)))
 
+/* exit status - bits below are ORed */
+#define EX_USAGE        1       /* incorrect invocation or permission */
+#define EX_SYSERR       2       /* out of memory, cannot fork, ... */
+#define EX_SOFTWARE     4       /* internal mount bug or wrong version */
+#define EX_USER         8       /* user interrupt */
+#define EX_FILEIO      16       /* problems writing, locking, ... mtab/fstab */
+#define EX_FAIL        32       /* mount failure */
+#define EX_SOMEOK      64       /* some mount succeeded */
+
 const char *thisprogram;
 int verboseflag = 0;
 static int got_password = 0;
@@ -159,7 +168,7 @@ static void mount_cifs_usage(void)
 		free(mountpassword);
 		mountpassword = NULL;
 	}
-	exit(1);
+	exit(EX_USAGE);
 }
 
 /* caller frees username if necessary */
@@ -220,7 +229,7 @@ static int open_cred_file(char * file_name)
 					if(mountpassword) {
 						memset(mountpassword,0,64);
 					}
-					exit(1);
+					exit(EX_USAGE);
 				} else {
 					got_user = 1;
 					user_name = (char *)calloc(1 + length,1);
@@ -246,7 +255,7 @@ static int open_cred_file(char * file_name)
 					if(mountpassword) {
 						memset(mountpassword,0,64);
 					}
-					exit(1);
+					exit(EX_USAGE);
 				} else {
 					if(mountpassword == NULL) {
 						mountpassword = (char *)calloc(65,1);
@@ -276,7 +285,7 @@ static int open_cred_file(char * file_name)
                                         if(mountpassword) {
                                                 memset(mountpassword,0,64);
                                         }
-                                        exit(1);
+                                        exit(EX_USAGE);
                                 } else {
                                         if(domain_name == NULL) {
                                                 domain_name = (char *)calloc(65,1);
@@ -313,7 +322,7 @@ static int get_password_from_file(int file_descript, char * filename)
 
 	if (mountpassword == NULL) {
 		printf("malloc failed\n");
-		exit(1);
+		exit(EX_SYSERR);
 	}
 
 	if(filename != NULL) {
@@ -321,7 +330,7 @@ static int get_password_from_file(int file_descript, char * filename)
 		if(file_descript < 0) {
 			printf("mount.cifs failed. %s attempting to open password file %s\n",
 				   strerror(errno),filename);
-			exit(1);
+			exit(EX_SYSERR);
 		}
 	}
 	/* else file already open and fd provided */
@@ -333,7 +342,7 @@ static int get_password_from_file(int file_descript, char * filename)
 			memset(mountpassword,0,64);
 			if(filename != NULL)
 				close(file_descript);
-			exit(1);
+			exit(EX_SYSERR);
 		} else if(rc == 0) {
 			if(mountpassword[0] == 0) {
 				if(verboseflag)
@@ -553,7 +562,7 @@ static int parse_options(char ** optionsp, int * filesys_flags)
 
 					if (!(pw = getpwnam(value))) {
 						printf("bad user name \"%s\"\n", value);
-						exit(1);
+						exit(EX_USAGE);
 					}
 					snprintf(user, sizeof(user), "%u", pw->pw_uid);
 				} else {
@@ -569,7 +578,7 @@ static int parse_options(char ** optionsp, int * filesys_flags)
 
 					if (!(gr = getgrnam(value))) {
 						printf("bad group name \"%s\"\n", value);
-						exit(1);
+						exit(EX_USAGE);
 					}
 					snprintf(group, sizeof(group), "%u", gr->gr_gid);
 				} else {
@@ -664,7 +673,7 @@ static int parse_options(char ** optionsp, int * filesys_flags)
 		out = (char *)realloc(out, out_len + word_len + 2);
 		if (out == NULL) {
 			perror("malloc");
-			exit(1);
+			exit(EX_SYSERR);
 		}
 
 		if (out_len) {
@@ -689,7 +698,7 @@ nocopy:
 		out = (char *)realloc(out, out_len + word_len + 6);
 		if (out == NULL) {
 			perror("malloc");
-			exit(1);
+			exit(EX_SYSERR);
 		}
 
 		if (out_len) {
@@ -705,7 +714,7 @@ nocopy:
 		out = (char *)realloc(out, out_len + 1 + word_len + 6);
 		if (out == NULL) {
 		perror("malloc");
-			exit(1);
+			exit(EX_SYSERR);
 		}
 
 		if (out_len) {
@@ -986,12 +995,12 @@ static struct option longopts[] = {
 };
 
 /* convert a string to uppercase. return false if the string
- * wasn't ASCII or was a NULL ptr */
+ * wasn't ASCII. Return success on a NULL ptr */
 static int
 uppercase_string(char *string)
 {
 	if (!string)
-		return 0;
+		return 1;
 
 	while (*string) {
 		/* check for unicode */
@@ -1040,7 +1049,7 @@ int main(int argc, char ** argv)
 		thisprogram = argv[0];
 	} else {
 		mount_cifs_usage();
-		exit(1);
+		exit(EX_USAGE);
 	}
 
 	if(thisprogram == NULL)
@@ -1057,12 +1066,12 @@ int main(int argc, char ** argv)
 		share_name = strndup(argv[1], MAX_UNC_LEN);
 		if (share_name == NULL) {
 			fprintf(stderr, "%s: %s", argv[0], strerror(ENOMEM));
-			exit(1);
+			exit(EX_SYSERR);
 		}
 		mountpoint = argv[2];
 	} else {
 		mount_cifs_usage();
-		exit(1);
+		exit(EX_USAGE);
 	}
 
 	/* add sharename in opts string as unc= parm */
@@ -1084,7 +1093,7 @@ int main(int argc, char ** argv)
 		case '?':
 		case 'h':	 /* help */
 			mount_cifs_usage ();
-			exit(1);
+			exit(EX_USAGE);
 		case 'n':
 		    ++nomtab;
 		    break;
@@ -1141,14 +1150,14 @@ int main(int argc, char ** argv)
 				uid = strtoul(optarg, &ep, 10);
 				if (*ep) {
 					printf("bad uid value \"%s\"\n", optarg);
-					exit(1);
+					exit(EX_USAGE);
 				}
 			} else {
 				struct passwd *pw;
 
 				if (!(pw = getpwnam(optarg))) {
 					printf("bad user name \"%s\"\n", optarg);
-					exit(1);
+					exit(EX_USAGE);
 				}
 				uid = pw->pw_uid;
 				endpwent();
@@ -1161,14 +1170,14 @@ int main(int argc, char ** argv)
 				gid = strtoul(optarg, &ep, 10);
 				if (*ep) {
 					printf("bad gid value \"%s\"\n", optarg);
-					exit(1);
+					exit(EX_USAGE);
 				}
 			} else {
 				struct group *gr;
 
 				if (!(gr = getgrnam(optarg))) {
 					printf("bad user name \"%s\"\n", optarg);
-					exit(1);
+					exit(EX_USAGE);
 				}
 				gid = gr->gr_gid;
 				endpwent();
@@ -1198,13 +1207,13 @@ int main(int argc, char ** argv)
 		default:
 			printf("unknown mount option %c\n",c);
 			mount_cifs_usage();
-			exit(1);
+			exit(EX_USAGE);
 		}
 	}
 
 	if((argc < 3) || (dev_name == NULL) || (mountpoint == NULL)) {
 		mount_cifs_usage();
-		exit(1);
+		exit(EX_USAGE);
 	}
 
 	if (getenv("PASSWD")) {
@@ -1221,13 +1230,13 @@ int main(int argc, char ** argv)
 	}
 
         if (orgoptions && parse_options(&orgoptions, &flags)) {
-                rc = -1;
+                rc = EX_USAGE;
 		goto mount_exit;
 	}
 	ipaddr = parse_server(&share_name);
 	if((ipaddr == NULL) && (got_ip == 0)) {
 		printf("No ip address specified and hostname not found\n");
-		rc = -1;
+		rc = EX_USAGE;
 		goto mount_exit;
 	}
 	
@@ -1242,19 +1251,19 @@ int main(int argc, char ** argv)
 	}
 	if(chdir(mountpoint)) {
 		printf("mount error: can not change directory into mount target %s\n",mountpoint);
-		rc = -1;
+		rc = EX_USAGE;
 		goto mount_exit;
 	}
 
 	if(stat (".", &statbuf)) {
 		printf("mount error: mount point %s does not exist\n",mountpoint);
-		rc = -1;
+		rc = EX_USAGE;
 		goto mount_exit;
 	}
 
 	if (S_ISDIR(statbuf.st_mode) == 0) {
 		printf("mount error: mount point %s is not a directory\n",mountpoint);
-		rc = -1;
+		rc = EX_USAGE;
 		goto mount_exit;
 	}
 
@@ -1267,7 +1276,7 @@ int main(int argc, char ** argv)
 #endif						
 		} else {
 			printf("mount error: permission denied or not superuser and mount.cifs not installed SUID\n"); 
-			return -1;
+			exit(EX_USAGE);
 		}
 	}
 
@@ -1282,8 +1291,8 @@ int main(int argc, char ** argv)
 						     no good replacement yet */
 		mountpassword = (char *)calloc(65,1);
 		if (!tmp_pass || !mountpassword) {
-			printf("Password not entered, exiting.\n");
-			return -1;
+			printf("Password not entered, exiting\n");
+			exit(EX_USAGE);
 		}
 		strncpy(mountpassword, tmp_pass, 64);
 						 
@@ -1302,7 +1311,7 @@ mount_retry:
 	else {
 		printf("No server share name specified\n");
 		printf("\nMounting the DFS root for server not implemented yet\n");
-                exit(1);
+                exit(EX_USAGE);
 	}
 	if(user_name)
 		optlen += strlen(user_name) + 6;
@@ -1319,7 +1328,7 @@ mount_retry:
 
 	if(options == NULL) {
 		printf("Could not allocate memory for mount options\n");
-		return -1;
+		exit(EX_SYSERR);
 	}
 
 	options[0] = 0;
@@ -1398,8 +1407,7 @@ mount_retry:
 			printf("mount error %d = %s\n",errno,strerror(errno));
 		}
 		printf("Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n");
-		rc = -1;
-		goto mount_exit;
+		rc = EX_FAIL;
 	} else {
 		pmntfile = setmntent(MOUNTED, "a+");
 		if(pmntfile) {
@@ -1440,11 +1448,13 @@ mount_retry:
 				free(mountent.mnt_opts);
 				mountent.mnt_opts = NULL;
 			}
+			if (rc)
+				rc = EX_FILEIO;
 		} else {
-		    printf("could not update mount table\n");
+			printf("could not update mount table\n");
+			rc = EX_FILEIO;
 		}
 	}
-	rc = 0;
 mount_exit:
 	if(mountpassword) {
 		int len = strlen(mountpassword);
@@ -1470,5 +1480,5 @@ mount_exit:
 	}
 
 	free(share_name);
-	return rc;
+	exit(rc);
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list