trying to get HEAD building again. If you want the code
[gd/samba-autobuild/.git] / source3 / client / smbmount.c
index f90c56859f2665ea34828fbb053d6c0ebe208215..343d4f267576b7b7cf2821f8d9016817763f38ea 100644 (file)
@@ -41,12 +41,18 @@ static pstring options;
 static struct in_addr dest_ip;
 static BOOL have_ip;
 static int smb_port = 0;
+static BOOL got_user;
 static BOOL got_pass;
 static uid_t mount_uid;
 static gid_t mount_gid;
 static int mount_ro;
 static unsigned mount_fmask;
 static unsigned mount_dmask;
+static BOOL use_kerberos;
+/* TODO: Add code to detect smbfs version in kernel */
+static BOOL status32_smbfs = False;
+static BOOL smbfs_has_unicode = False;
+static BOOL smbfs_has_lfs = False;
 
 static void usage(void);
 
@@ -155,7 +161,14 @@ static struct cli_state *do_connection(char *the_service)
        }
 
        /* SPNEGO doesn't work till we get NTSTATUS error support */
-       c->use_spnego = False;
+       /* But it is REQUIRED for kerberos authentication */
+       if(!use_kerberos) c->use_spnego = False;
+
+       /* The kernel doesn't yet know how to sign it's packets */
+       c->sign_info.allow_smb_signing = False;
+
+       /* Use kerberos authentication if specified */
+       c->use_kerberos = use_kerberos;
 
        if (!cli_session_request(c, &calling, &called)) {
                char *p;
@@ -190,9 +203,16 @@ static struct cli_state *do_connection(char *the_service)
 
        /* This should be right for current smbfs. Future versions will support
          large files as well as unicode and oplocks. */
-       c->capabilities &= ~(CAP_UNICODE | CAP_LARGE_FILES | CAP_NT_SMBS |
-                               CAP_NT_FIND | CAP_STATUS32 | CAP_LEVEL_II_OPLOCKS);
-       c->force_dos_errors = True;
+       c->capabilities &= ~(CAP_NT_SMBS | CAP_NT_FIND | CAP_LEVEL_II_OPLOCKS);
+       if (!smbfs_has_lfs)
+               c->capabilities &= ~CAP_LARGE_FILES;
+       if (!smbfs_has_unicode)
+               c->capabilities &= ~CAP_UNICODE;
+       if (!status32_smbfs) {
+               c->capabilities &= ~CAP_STATUS32;
+               c->force_dos_errors = True;
+       }
+
        if (!cli_session_setup(c, username, 
                               password, strlen(password),
                               password, strlen(password),
@@ -379,7 +399,7 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat
                        }
 
                        /* here we are no longer interactive */
-                       set_remote_machine_name("smbmount");    /* sneaky ... */
+                       set_remote_machine_name("smbmount", False);     /* sneaky ... */
                        setup_logging("mount.smbfs", False);
                        reopen_logs();
                        DEBUG(0, ("mount.smbfs: entering daemon mode for service %s, pid=%d\n", the_service, sys_getpid()));
@@ -504,6 +524,9 @@ static void init_mount(void)
                fprintf(stderr,"smbmnt failed: %d\n", WEXITSTATUS(status));
                /* FIXME: do some proper error handling */
                exit(1);
+       } else if (WIFSIGNALED(status)) {
+               fprintf(stderr, "smbmnt killed by signal %d\n", WTERMSIG(status));
+               exit(1);
        }
 
        /* Ok...  This is the rubicon for that mount point...  At any point
@@ -623,8 +646,9 @@ static void read_credentials_file(char *filename)
                        pstrcpy(password, val);
                        got_pass = True;
                }
-               else if (strwicmp("username", param) == 0)
+               else if (strwicmp("username", param) == 0) {
                        pstrcpy(username, val);
+               }
 
                memset(buf, 0, sizeof(buf));
        }
@@ -646,6 +670,7 @@ static void usage(void)
       username=<arg>                  SMB username\n\
       password=<arg>                  SMB password\n\
       credentials=<filename>          file with username/password\n\
+      krb                             use kerberos (active directory)\n\
       netbiosname=<arg>               source NetBIOS name\n\
       uid=<arg>                       mount uid or username\n\
       gid=<arg>                       mount gid or groupname\n\
@@ -659,6 +684,8 @@ static void usage(void)
       scope=<arg>                     NetBIOS scope\n\
       iocharset=<arg>                 Linux charset (iso8859-1, utf8)\n\
       codepage=<arg>                  server codepage (cp850)\n\
+      unicode                         use unicode when communicating with server\n\
+      lfs                             large file system support\n\
       ttl=<arg>                       dircache time to live\n\
       guest                           don't prompt for a password\n\
       ro                              mount read-only\n\
@@ -732,6 +759,7 @@ static void parse_mount_smb(int argc, char **argv)
                         if (!strcmp(opts, "username") || 
                            !strcmp(opts, "logon")) {
                                char *lp;
+                               got_user = True;
                                pstrcpy(username,opteq+1);
                                if ((lp=strchr_m(username,'%'))) {
                                        *lp = 0;
@@ -789,10 +817,24 @@ static void parse_mount_smb(int argc, char **argv)
                        } else if(!strcmp(opts, "guest")) {
                                *password = '\0';
                                got_pass = True;
+                       } else if(!strcmp(opts, "krb")) {
+#ifdef HAVE_KRB5
+
+                               use_kerberos = True;
+                               if(!status32_smbfs)
+                                       fprintf(stderr, "Warning: kerberos support will only work for samba servers\n");
+#else
+                               fprintf(stderr,"No kerberos support compiled in\n");
+                               exit(1);
+#endif
                        } else if(!strcmp(opts, "rw")) {
                                mount_ro = 0;
                        } else if(!strcmp(opts, "ro")) {
                                mount_ro = 1;
+                       } else if(!strcmp(opts, "unicode")) {
+                               smbfs_has_unicode = True;
+                       } else if(!strcmp(opts, "lfs")) {
+                               smbfs_has_lfs = True;
                        } else {
                                strncpy(p, opts, sizeof(pstring) - (p - options) - 1);
                                p += strlen(opts);
@@ -849,7 +891,7 @@ static void parse_mount_smb(int argc, char **argv)
                        got_pass = True;
                        memset(strchr_m(getenv("USER"),'%')+1,'X',strlen(password));
                }
-               strupper(username);
+               strupper_m(username);
        }
 
        if (getenv("PASSWD")) {
@@ -873,6 +915,10 @@ static void parse_mount_smb(int argc, char **argv)
 
        parse_mount_smb(argc, argv);
 
+       if (use_kerberos && !got_user) {
+               got_pass = True;
+       }
+
        if (*credentials != 0) {
                read_credentials_file(credentials);
        }
@@ -887,7 +933,7 @@ static void parse_mount_smb(int argc, char **argv)
        if (!*my_netbios_name) {
                pstrcpy(my_netbios_name, myhostname());
        }
-       strupper(my_netbios_name);
+       strupper_m(my_netbios_name);
 
        init_mount();
        return 0;