s4:libcli: remove unused line in config.mk
[jra/samba/.git] / source4 / client / smbmount.c
index 8c0a6fcdf11b79b4f8da041ce9b1dd08076bd523..c219a42f3ae043fd704ad6e2a7269b45dda19300 100644 (file)
@@ -24,6 +24,9 @@
 #include <asm/types.h>
 #include <linux/smb_fs.h>
 
+#define pstrcpy(d,s) safe_strcpy((d),(s),sizeof(pstring)-1)
+#define pstrcat(d,s) safe_strcat((d),(s),sizeof(pstring)-1)
+
 static pstring credentials;
 static pstring my_netbios_name;
 static pstring password;
@@ -111,7 +114,8 @@ static void usr1_handler(int x)
 /***************************************************** 
 return a connection to a server
 *******************************************************/
-static struct smbcli_state *do_connection(const char *the_service, bool unicode, int maxprotocol)
+static struct smbcli_state *do_connection(const char *the_service, bool unicode, int maxprotocol,
+                                         struct smbcli_session_options session_options)
 {
        struct smbcli_state *c;
        struct nmb_name called, calling;
@@ -210,11 +214,12 @@ static struct smbcli_state *do_connection(const char *the_service, bool unicode,
        if (!smbcli_session_setup(c, username, 
                               password, strlen(password),
                               password, strlen(password),
-                              workgroup)) {
+                              workgroup, session_options)) {
                /* if a password was not supplied then try again with a
                        null username */
                if (password[0] || !username[0] ||
-                               !smbcli_session_setup(c, "", "", 0, "", 0, workgroup)) {
+                               !smbcli_session_setup(c, "", "", 0, "", 0, workgroup, 
+                                                     session_options)) {
                        DEBUG(0,("%d: session setup failed: %s\n",
                                sys_getpid(), smbcli_errstr(c)));
                        talloc_free(c);
@@ -323,11 +328,15 @@ static void smb_umount(const char *mount_point)
  * not exit after open_sockets() or send_login() errors,
  * as the smbfs mount would then have no way to recover.
  */
-static void send_fs_socket(const char *the_service, const char *mount_point, struct smbcli_state *c)
+static void send_fs_socket(struct loadparm_context *lp_ctx,
+                          const char *the_service, const char *mount_point, struct smbcli_state *c)
 {
        int fd, closed = 0, res = 1;
        pid_t parentpid = getppid();
        struct smb_conn_opt conn_options;
+       struct smbcli_session_options session_options;
+
+       lp_smbcli_session_options(lp_ctx, &session_options);
 
        memset(&conn_options, 0, sizeof(conn_options));
 
@@ -406,7 +415,10 @@ static void send_fs_socket(const char *the_service, const char *mount_point, str
                        CatchSignal(SIGUSR1, &usr1_handler);
                        pause();
                        DEBUG(2,("mount.smbfs[%d]: got signal, getting new socket\n", sys_getpid()));
-                       c = do_connection(the_service, lp_unicode(global_loadparm), lp_cli_maxprotocol(global_loadparm));
+                       c = do_connection(the_service, 
+                                         lp_unicode(lp_ctx), 
+                                         lp_cli_maxprotocol(lp_ctx),
+                                         session_options);
                }
        }
 
@@ -419,7 +431,7 @@ static void send_fs_socket(const char *the_service, const char *mount_point, str
 /**
  * Mount a smbfs
  **/
-static void init_mount(void)
+static void init_mount(struct loadparm_context *lp_ctx)
 {
        char mount_point[MAXPATHLEN+1];
        pstring tmp;
@@ -427,14 +439,17 @@ static void init_mount(void)
        struct smbcli_state *c;
        char *args[20];
        int i, status;
+       struct smbcli_session_options session_options;
 
        if (realpath(mpoint, mount_point) == NULL) {
                fprintf(stderr, "Could not resolve mount point %s\n", mpoint);
                return;
        }
 
+       lp_smbcli_session_options(lp_ctx, &session_options);
 
-       c = do_connection(service, lp_unicode(global_loadparm), lp_cli_maxprotocol(global_loadparm));
+       c = do_connection(service, lp_unicode(lp_ctx), lp_cli_maxprotocol(lp_ctx),
+                         session_options);
        if (!c) {
                fprintf(stderr,"SMB connection failed\n");
                exit(1);
@@ -527,7 +542,7 @@ static void init_mount(void)
           for any reason, we will have to unmount the mount point.  There
           is no exit from the next call...
        */
-       send_fs_socket(service, mount_point, c);
+       send_fs_socket(lp_ctx, service, mount_point, c);
 }
 
 
@@ -785,7 +800,7 @@ static void parse_mount_smb(int argc, char **argv)
                                DEBUGLEVEL = val;
                        } else if(!strcmp(opts, "ip")) {
                                dest_ip = interpret_addr2(opteq+1);
-                               if (is_zero_ip(dest_ip)) {
+                               if (is_zero_ip_v4(dest_ip)) {
                                        fprintf(stderr,"Can't resolve address %s\n", opteq+1);
                                        exit(1);
                                }
@@ -850,6 +865,7 @@ static void parse_mount_smb(int argc, char **argv)
        extern char *optarg;
        extern int optind;
        char *p;
+       struct loadparm_context *lp_ctx;
 
        DEBUGLEVEL = 1;
 
@@ -880,7 +896,7 @@ static void parse_mount_smb(int argc, char **argv)
        }
 
        if (getenv("PASSWD")) {
-               pstrcpy(password,getenv("PASSWD"));
+               pstrcpy(password, getenv("PASSWD"));
                got_pass = true;
        }
 
@@ -893,7 +909,9 @@ static void parse_mount_smb(int argc, char **argv)
                pstrcpy(username,getenv("LOGNAME"));
        }
 
-       if (!lp_load(dyn_CONFIGFILE)) {
+       lp_ctx = loadparm_init(talloc_autofree_context());
+
+       if (!lp_load(lp_ctx, dyn_CONFIGFILE)) {
                fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
                        lp_config_file());
        }
@@ -919,6 +937,6 @@ static void parse_mount_smb(int argc, char **argv)
        }
        strupper(my_netbios_name);
 
-       init_mount();
+       init_mount(lp_ctx);
        return 0;
 }