s3: client tools: Call popt_free_cmdline_auth_info() on all normal exits.
[bbaumbach/samba-autobuild/.git] / source3 / utils / smbcacls.c
index d50219cf74a29d643f7f545aca4abc69d0e1c19f..11289e69e4368dddf98b27d3ce181e58e2eb5226 100644 (file)
@@ -57,7 +57,7 @@ static NTSTATUS cli_lsa_lookup_domain_sid(struct cli_state *cli,
        NTSTATUS status, result;
        TALLOC_CTX *frame = talloc_stackframe();
 
-       status = cli_tree_connect(cli, "IPC$", "?????", "", 0);
+       status = cli_tree_connect(cli, "IPC$", "?????", NULL);
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
@@ -505,10 +505,16 @@ static int cacl_set(struct cli_state *cli, const char *filename,
        if (!sd) return EXIT_PARSE_ERROR;
        if (test_args) return EXIT_OK;
 
-       old = get_secdesc(cli, filename);
+       if (mode != SMB_ACL_SET) {
+               /*
+                * Do not fetch old ACL when it will be overwritten
+                * completely with a new one.
+                */
+               old = get_secdesc(cli, filename);
 
-       if (!old) {
-               return EXIT_FAILED;
+               if (!old) {
+                       return EXIT_FAILED;
+               }
        }
 
        /* the logic here is rather more complex than I would like */
@@ -727,7 +733,7 @@ static int inherit(struct cli_state *cli, const char *filename,
 /*****************************************************
  Return a connection to a server.
 *******************************************************/
-static struct cli_state *connect_one(struct user_auth_info *auth_info,
+static struct cli_state *connect_one(const struct user_auth_info *auth_info,
                                     const char *server, const char *share)
 {
        struct cli_state *c = NULL;
@@ -739,13 +745,6 @@ static struct cli_state *connect_one(struct user_auth_info *auth_info,
                         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,
                                NULL, 0,
                                share, "?????",
@@ -823,7 +822,6 @@ int main(int argc, char *argv[])
        TALLOC_CTX *frame = talloc_stackframe();
        const char *owner_username = "";
        char *server;
-       struct user_auth_info *auth_info;
 
        smb_init_locale();
 
@@ -833,12 +831,7 @@ int main(int argc, char *argv[])
 
        setlinebuf(stdout);
 
-
-       auth_info = user_auth_info_init(frame);
-       if (auth_info == NULL) {
-               exit(1);
-       }
-       popt_common_set_auth_info(auth_info);
+       popt_common_credentials_set_ignore_missing_conf();
 
        pc = poptGetContext("smbcacls", argc, argv_const, long_options, 0);
 
@@ -903,9 +896,6 @@ int main(int argc, char *argv[])
                return -1;
        }
 
-       lp_load_global(get_dyn_CONFIGFILE());
-       load_interfaces();
-
        filename = talloc_strdup(frame, poptGetArg(pc));
        if (!filename) {
                return -1;
@@ -913,6 +903,7 @@ int main(int argc, char *argv[])
 
        poptFreeContext(pc);
        popt_burn_cmdline_password(argc, argv);
+       popt_common_credentials_post();
 
        string_replace(path,'/','\\');
 
@@ -930,11 +921,12 @@ int main(int argc, char *argv[])
        share++;
 
        if (!test_args) {
-               cli = connect_one(auth_info, server, share);
+               cli = connect_one(popt_get_cmdline_auth_info(), server, share);
                if (!cli) {
                        exit(EXIT_FAILED);
                }
        } else {
+               popt_free_cmdline_auth_info();
                exit(0);
        }
 
@@ -960,6 +952,7 @@ int main(int argc, char *argv[])
                result = cacl_dump(cli, filename, numeric);
        }
 
+       popt_free_cmdline_auth_info();
        TALLOC_FREE(frame);
 
        return result;