r10656: BIG merge from trunk. Features not copied over
[abartlet/samba.git/.git] / source3 / client / mount.cifs.c
index 0ebb52a96bad406e79c6db0e68cb5eb07cb3b269..5750deb31ca82bf482743a78360645a891878719 100755 (executable)
@@ -39,7 +39,7 @@
 #include <fcntl.h>
 
 #define MOUNT_CIFS_VERSION_MAJOR "1"
-#define MOUNT_CIFS_VERSION_MINOR "7"
+#define MOUNT_CIFS_VERSION_MINOR "8"
 
 #ifndef MOUNT_CIFS_VENDOR_SUFFIX
 #define MOUNT_CIFS_VENDOR_SUFFIX ""
@@ -61,7 +61,7 @@ static int got_gid = 0;
 static int free_share_name = 0;
 static char * user_name = NULL;
 static char * mountpassword = NULL;
-static char * domain_name = NULL;
+char * domain_name = NULL;
 
 
 /* BB finish BB
@@ -83,11 +83,11 @@ static void mount_cifs_usage(void)
        printf(" to a local directory.\n\nOptions:\n");
        printf("\tuser=<arg>\n\tpass=<arg>\n\tdom=<arg>\n");
        printf("\nLess commonly used options:");
-       printf("\n\tcredentials=<filename>,guest,perm,noperm,setuids,nosetuids,\n\trw,ro,sep=<char>,iocharset=<codepage>,suid,nosuid,exec,noexec,directio");
-       printf("\n\nOptions not needed for servers supporting CIFS Unix extensions (e.g. most Samba versions):");
+       printf("\n\tcredentials=<filename>,guest,perm,noperm,setuids,nosetuids,rw,ro,\n\tsep=<char>,iocharset=<codepage>,suid,nosuid,exec,noexec,serverino,\n\tdirectio,mapchars,nomapchars");
+       printf("\n\nOptions not needed for servers supporting CIFS Unix extensions\n\t(e.g. most Samba versions):");
        printf("\n\tuid=<uid>,gid=<gid>,dir_mode=<mode>,file_mode=<mode>");
        printf("\n\nRarely used options:");
-       printf("\n\tport=<tcpport>,rsize=<size>,wsize=<size>,unc=<unc_name>,ip=<ip_address>,dev,nodev");
+       printf("\n\tport=<tcpport>,rsize=<size>,wsize=<size>,unc=<unc_name>,ip=<ip_address>,\n\tdev,nodev,nouser_xattr,netbiosname,hard,soft,intr,nointr,noacl");
        printf("\n\nOptions are described in more detail in the manual page");
        printf("\n\tman 8 mount.cifs\n");
        printf("\nTo display the version number of the mount helper:");
@@ -185,13 +185,41 @@ static int open_cred_file(char * file_name)
                                        } else
                                                memset(mountpassword,0,64);
                                        if(mountpassword) {
-                                               /* BB add handling for commas in password here */
                                                strncpy(mountpassword,temp_val,length);
                                                got_password = 1;
                                        }
                                }
                        }
-               }
+                } else if (strncasecmp("domain",line_buf+i,6) == 0) {
+                        temp_val = strchr(line_buf+i,'=');
+                        if(temp_val) {
+                                /* go past equals sign */
+                                temp_val++;
+                               if(verboseflag)
+                                       printf("\nDomain %s\n",temp_val);
+                                for(length = 0;length<65;length++) {
+                                        if(temp_val[length] == '\n')
+                                                break;
+                                }
+                                if(length > 64) {
+                                        printf("mount.cifs failed: domain in credentials file too long\n");
+                                        if(mountpassword) {
+                                                memset(mountpassword,0,64);
+                                        }
+                                        exit(1);
+                                } else {
+                                        if(domain_name == NULL) {
+                                                domain_name = calloc(65,1);
+                                        } else
+                                                memset(domain_name,0,64);
+                                        if(domain_name) {
+                                                strncpy(domain_name,temp_val,length);
+                                                got_domain = 1;
+                                        }
+                                }
+                        }
+                }
+
        }
        fclose(fs);
        if(line_buf) {
@@ -494,6 +522,8 @@ static int parse_options(char * options, int * filesys_flags)
                        *filesys_flags |= MS_RDONLY;
                } else if (strncmp(data, "rw", 2) == 0) {
                        *filesys_flags &= ~MS_RDONLY;
+                } else if (strncmp(data, "remount", 7) == 0) {
+                        *filesys_flags |= MS_REMOUNT;
                } /* else if (strnicmp(data, "port", 4) == 0) {
                        if (value && *value) {
                                vol->port =
@@ -632,7 +662,6 @@ static char * check_for_domain(char **ppuser)
 
 /*     move_string(*ppuser, usernm+1) */
        len = strlen(usernm+1);
-       printf("\nlen %d original_len %d\n",len, original_len);
 
        if(len >= original_len) {
                /* should not happen */
@@ -661,7 +690,7 @@ static char * parse_server(char ** punc_name)
        int length = strnlen(unc_name,1024);
        char * share;
        char * ipaddress_string = NULL;
-       struct hostent * host_entry;
+       struct hostent * host_entry = NULL;
        struct in_addr server_ipaddr;
        int rc;
 
@@ -776,7 +805,6 @@ int main(int argc, char ** argv)
        int flags = MS_MANDLOCK; /* no need to set legacy MS_MGC_VAL */
        char * orgoptions = NULL;
        char * share_name = NULL;
-       char * domain_name = NULL;
        char * ipaddr = NULL;
        char * uuid = NULL;
        char * mountpoint;
@@ -888,6 +916,7 @@ int main(int argc, char ** argv)
                        break;
                case 'd':
                        domain_name = optarg; /* BB fix this - currently ignored */
+                       got_domain = 1;
                        break;
                case 'p':
                        if(mountpassword == NULL)
@@ -927,14 +956,12 @@ int main(int argc, char ** argv)
 
         if (orgoptions && parse_options(orgoptions, &flags))
                 return -1;
-       
        ipaddr = parse_server(&share_name);
        if((ipaddr == NULL) && (got_ip == 0)) {
                printf("No ip address specified and hostname not found\n");
                return -1;
        }
        
-
        /* BB save off path and pop after mount returns? */
        resolved_path = malloc(PATH_MAX+1);
        if(resolved_path) {
@@ -1019,16 +1046,18 @@ mount_retry:
 
        if(user_name) {
                /* check for syntax like user=domain\user */
-               domain_name = check_for_domain(&user_name);
+               if(got_domain == 0)
+                       domain_name = check_for_domain(&user_name);
                strncat(options,",user=",6);
                strcat(options,user_name);
-       } 
-       if(retry == 0)
+       }
+       if(retry == 0) {
                if(domain_name) { 
                        /* extra length accounted for in option string above */
                        strncat(options,",domain=",8);
                        strcat(options,domain_name);
                }
+       }
        if(mountpassword) {
                /* Commas have to be doubled, or else they will
                look like the parameter separator */