s3: client tools: Call popt_free_cmdline_auth_info() on all normal exits.
[bbaumbach/samba-autobuild/.git] / examples / fuse / smb2mount.c
index 2c06ed563761df0bd8f30a3a81d359a74b891a11..816b0b597ad4847fe5cc8a963696d5b0b9b782a6 100644 (file)
@@ -25,8 +25,9 @@
 #include "libsmb/proto.h"
 #include "clifuse.h"
 
 #include "libsmb/proto.h"
 #include "clifuse.h"
 
-static struct cli_state *connect_one(struct user_auth_info *auth_info,
-                                    const char *server, const char *share)
+static struct cli_state *connect_one(const struct user_auth_info *auth_info,
+                                    const char *server, int port,
+                                    const char *share)
 {
        struct cli_state *c = NULL;
        NTSTATUS nt_status;
 {
        struct cli_state *c = NULL;
        NTSTATUS nt_status;
@@ -37,15 +38,8 @@ static struct cli_state *connect_one(struct user_auth_info *auth_info,
                         CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS;
        }
 
                         CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS;
        }
 
-       if (get_cmdline_auth_info_use_machine_account(auth_info) &&
-           !set_cmdline_auth_info_machine_account_creds(auth_info)) {
-               return NULL;
-       }
-
-       set_cmdline_auth_info_getpass(auth_info);
-
        nt_status = cli_full_connection(&c, lp_netbios_name(), server,
        nt_status = cli_full_connection(&c, lp_netbios_name(), server,
-                               NULL, 0,
+                               NULL, port,
                                share, "?????",
                                get_cmdline_auth_info_username(auth_info),
                                lp_workgroup(),
                                share, "?????",
                                get_cmdline_auth_info_username(auth_info),
                                lp_workgroup(),
@@ -78,9 +72,9 @@ int main(int argc, char *argv[])
 {
        const char **argv_const = discard_const_p(const char *, argv);
        TALLOC_CTX *frame = talloc_stackframe();
 {
        const char **argv_const = discard_const_p(const char *, argv);
        TALLOC_CTX *frame = talloc_stackframe();
-       struct user_auth_info *auth_info;
        poptContext pc;
        int opt, ret;
        poptContext pc;
        int opt, ret;
+       int port = 0;
        char *unc, *mountpoint, *server, *share;
        struct cli_state *cli;
 
        char *unc, *mountpoint, *server, *share;
        struct cli_state *cli;
 
@@ -88,6 +82,8 @@ int main(int argc, char *argv[])
                POPT_AUTOHELP
                POPT_COMMON_SAMBA
                POPT_COMMON_CREDENTIALS
                POPT_AUTOHELP
                POPT_COMMON_SAMBA
                POPT_COMMON_CREDENTIALS
+               { "port", 'p', POPT_ARG_INT, &port, 'p', "Port to connect to",
+                 "PORT" },
                POPT_TABLEEND
        };
 
                POPT_TABLEEND
        };
 
@@ -96,12 +92,6 @@ int main(int argc, char *argv[])
        lp_set_cmdline("client min protocol", "SMB2");
        lp_set_cmdline("client max protocol", "SMB3_11");
 
        lp_set_cmdline("client min protocol", "SMB2");
        lp_set_cmdline("client max protocol", "SMB3_11");
 
-       auth_info = user_auth_info_init(frame);
-       if (auth_info == NULL) {
-               exit(1);
-       }
-       popt_common_set_auth_info(auth_info);
-
        lp_load_global(get_dyn_CONFIGFILE());
        load_interfaces();
 
        lp_load_global(get_dyn_CONFIGFILE());
        load_interfaces();
 
@@ -110,6 +100,8 @@ int main(int argc, char *argv[])
 
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch(opt) {
 
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch(opt) {
+                   case 'p':
+                           break;
                    default:
                            fprintf(stderr, "Unknown Option: %c\n", opt);
                            exit(1);
                    default:
                            fprintf(stderr, "Unknown Option: %c\n", opt);
                            exit(1);
@@ -151,7 +143,7 @@ int main(int argc, char *argv[])
        *share = 0;
        share++;
 
        *share = 0;
        share++;
 
-       cli = connect_one(auth_info, server, share);
+       cli = connect_one(popt_get_cmdline_auth_info(), server, port, share);
        if (cli == NULL) {
                return -1;
        }
        if (cli == NULL) {
                return -1;
        }
@@ -162,6 +154,7 @@ int main(int argc, char *argv[])
                return -1;
        }
 
                return -1;
        }
 
+       popt_free_cmdline_auth_info();
        TALLOC_FREE(frame);
        return 0;
 }
        TALLOC_FREE(frame);
        return 0;
 }