Load samba-3.4.2 into branches/samba/upstream.
[abartlet/samba-debian.git] / source3 / client / mount.cifs.c
index 0c551cce7556932f6e00f9c48299697fb7563cd6..43dc7f618b63df6cf94acd2191efea2e155acc1b 100644 (file)
@@ -198,6 +198,11 @@ static int open_cred_file(char * file_name)
        char * temp_val;
        FILE * fs;
        int i, length;
+
+       i = access(file_name, R_OK);
+       if (i)
+               return i;
+
        fs = fopen(file_name,"r");
        if(fs == NULL)
                return errno;
@@ -320,6 +325,12 @@ static int get_password_from_file(int file_descript, char * filename)
        }
 
        if(filename != NULL) {
+               rc = access(filename, R_OK);
+               if (rc) {
+                       fprintf(stderr, "mount.cifs failed: access check of %s failed: %s\n",
+                                       filename, strerror(errno));
+                       exit(EX_SYSERR);
+               }
                file_descript = open(filename, O_RDONLY);
                if(file_descript < 0) {
                        printf("mount.cifs failed. %s attempting to open password file %s\n",
@@ -379,9 +390,6 @@ static int parse_options(char ** optionsp, int * filesys_flags)
                return 1;
        data = *optionsp;
 
-       if(verboseflag)
-               printf("parsing options: %s\n", data);
-
        /* BB fixme check for separator override BB */
 
        if (getuid()) {
@@ -470,18 +478,27 @@ static int parse_options(char ** optionsp, int * filesys_flags)
                } else if (strncmp(data, "pass", 4) == 0) {
                        if (!value || !*value) {
                                if(got_password) {
-                                       printf("\npassword specified twice, ignoring second\n");
+                                       fprintf(stderr, "\npassword specified twice, ignoring second\n");
                                } else
                                        got_password = 1;
-                       } else if (strnlen(value, 17) < 17) {
-                               if(got_password)
-                                       printf("\nmount.cifs warning - password specified twice\n");
-                               got_password = 1;
+                       } else if (strnlen(value, MOUNT_PASSWD_SIZE) < MOUNT_PASSWD_SIZE) {
+                               if (got_password) {
+                                       fprintf(stderr, "\nmount.cifs warning - password specified twice\n");
+                               } else {
+                                       mountpassword = strndup(value, MOUNT_PASSWD_SIZE);
+                                       if (!mountpassword) {
+                                               fprintf(stderr, "mount.cifs error: %s", strerror(ENOMEM));
+                                               SAFE_FREE(out);
+                                               return 1;
+                                       }
+                                       got_password = 1;
+                               }
                        } else {
-                               printf("password too long\n");
+                               fprintf(stderr, "password too long\n");
                                SAFE_FREE(out);
                                return 1;
                        }
+                       goto nocopy;
                } else if (strncmp(data, "sec", 3) == 0) {
                        if (value) {
                                if (!strncmp(value, "none", 4) ||
@@ -1384,15 +1401,6 @@ mount_retry:
                        strlcat(options,domain_name,options_size);
                }
        }
-       if(mountpassword) {
-               /* Commas have to be doubled, or else they will
-               look like the parameter separator */
-/*             if(sep is not set)*/
-               if(retry == 0)
-                       check_for_comma(&mountpassword);
-               strlcat(options,",pass=",options_size);
-               strlcat(options,mountpassword,options_size);
-       }
 
        strlcat(options,",ver=",options_size);
        strlcat(options,MOUNT_CIFS_VERSION_MAJOR,options_size);
@@ -1405,8 +1413,6 @@ mount_retry:
                strlcat(options,",prefixpath=",options_size);
                strlcat(options,prefixpath,options_size); /* no need to cat the / */
        }
-       if(verboseflag)
-               printf("\nmount.cifs kernel mount options %s \n",options);
 
        /* convert all '\\' to '/' in share portion so that /proc/mounts looks pretty */
        replace_char(dev_name, '\\', '/', strlen(share_name));
@@ -1438,6 +1444,25 @@ mount_retry:
                }
        }
 
+       if(verboseflag)
+               fprintf(stderr, "\nmount.cifs kernel mount options: %s", options);
+
+       if (mountpassword) {
+               /*
+                * Commas have to be doubled, or else they will
+                * look like the parameter separator
+                */
+               if(retry == 0)
+                       check_for_comma(&mountpassword);
+               strlcat(options,",pass=",options_size);
+               strlcat(options,mountpassword,options_size);
+               if (verboseflag)
+                       fprintf(stderr, ",pass=********");
+       }
+
+       if (verboseflag)
+               fprintf(stderr, "\n");
+
        if (!fakemnt && mount(dev_name, mountpoint, "cifs", flags, options)) {
                switch (errno) {
                case ECONNREFUSED: