s3: client tools: Call popt_free_cmdline_auth_info() on all normal exits.
[bbaumbach/samba-autobuild/.git] / source3 / utils / smbcquotas.c
index e6f1dfb6d4670398a47c5263fdade5f1a2c83bca..031862f52a11f24b6357df33584ec38caf33b330 100644 (file)
@@ -44,7 +44,6 @@ static struct cli_state *cli_ipc;
 static struct rpc_pipe_client *global_pipe_hnd;
 static struct policy_handle pol;
 static bool got_policy_hnd;
-static struct user_auth_info *smbcquotas_auth_info;
 
 static struct cli_state *connect_one(const char *share);
 
@@ -339,6 +338,7 @@ static int do_quota(struct cli_state *cli,
        uint32_t fs_attrs = 0;
        uint16_t quota_fnum = 0;
        SMB_NTQUOTA_LIST *qtl = NULL;
+       TALLOC_CTX *qtl_ctx = NULL;
        SMB_NTQUOTA_STRUCT qt;
        NTSTATUS status;
 
@@ -386,8 +386,21 @@ static int do_quota(struct cli_state *cli,
                                        break;
                                case QUOTA_SETLIM:
                                        pqt->sid = qt.sid;
+                                       if ((qtl_ctx = talloc_init(
+                                                "SMB_USER_QUOTA_SET")) ==
+                                           NULL) {
+                                               return -1;
+                                       }
+
+                                       if (!add_record_to_ntquota_list(
+                                               qtl_ctx, pqt, &qtl)) {
+                                               TALLOC_FREE(qtl_ctx);
+                                               return -1;
+                                       }
+
                                        status = cli_set_user_quota(
-                                               cli, quota_fnum, pqt);
+                                           cli, quota_fnum, qtl);
+                                       free_ntquota_list(&qtl);
                                        if (!NT_STATUS_IS_OK(status)) {
                                                d_printf("%s cli_set_user_quota %s\n",
                                                         nt_errstr(status),
@@ -408,9 +421,9 @@ static int do_quota(struct cli_state *cli,
                                        status = cli_list_user_quota(
                                                cli, quota_fnum, &qtl);
                                        if (!NT_STATUS_IS_OK(status)) {
-                                               d_printf("%s cli_set_user_quota %s\n",
-                                                        nt_errstr(status),
-                                                        username_str);
+                                               d_printf(
+                                                   "%s cli_list_user_quota\n",
+                                                   nt_errstr(status));
                                                return -1;
                                        }
                                        dump_ntquota_list(&qtl,verbose,numeric,SidToString);
@@ -509,36 +522,34 @@ static struct cli_state *connect_one(const char *share)
        NTSTATUS nt_status;
        uint32_t flags = 0;
 
-       if (get_cmdline_auth_info_use_machine_account(smbcquotas_auth_info) &&
-           !set_cmdline_auth_info_machine_account_creds(smbcquotas_auth_info)) {
-               return NULL;
-       }
-
-       if (get_cmdline_auth_info_use_kerberos(smbcquotas_auth_info)) {
+       if (get_cmdline_auth_info_use_kerberos(popt_get_cmdline_auth_info())) {
                flags |= CLI_FULL_CONNECTION_USE_KERBEROS |
                         CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS;
 
        }
 
-       set_cmdline_auth_info_getpass(smbcquotas_auth_info);
-
        nt_status = cli_full_connection(&c, lp_netbios_name(), server,
                                            NULL, 0,
                                            share, "?????",
-                                           get_cmdline_auth_info_username(smbcquotas_auth_info),
+                                           get_cmdline_auth_info_username(
+                                               popt_get_cmdline_auth_info()),
                                            lp_workgroup(),
-                                           get_cmdline_auth_info_password(smbcquotas_auth_info),
+                                           get_cmdline_auth_info_password(
+                                               popt_get_cmdline_auth_info()),
                                            flags,
-                                           get_cmdline_auth_info_signing_state(smbcquotas_auth_info));
+                                           get_cmdline_auth_info_signing_state(
+                                               popt_get_cmdline_auth_info()));
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
                return NULL;
        }
 
-       if (get_cmdline_auth_info_smb_encrypt(smbcquotas_auth_info)) {
+       if (get_cmdline_auth_info_smb_encrypt(popt_get_cmdline_auth_info())) {
                nt_status = cli_cm_force_encryption(c,
-                                       get_cmdline_auth_info_username(smbcquotas_auth_info),
-                                       get_cmdline_auth_info_password(smbcquotas_auth_info),
+                                       get_cmdline_auth_info_username(
+                                               popt_get_cmdline_auth_info()),
+                                       get_cmdline_auth_info_password(
+                                               popt_get_cmdline_auth_info()),
                                        lp_workgroup(),
                                        share);
                if (!NT_STATUS_IS_OK(nt_status)) {
@@ -584,6 +595,8 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
                { "numeric", 'n', POPT_ARG_NONE, NULL, 'n', "Don't resolve sids or limits to names" },
                { "verbose", 'v', POPT_ARG_NONE, NULL, 'v', "be verbose" },
                { "test-args", 't', POPT_ARG_NONE, NULL, 't', "Test arguments"},
+               {"max-protocol", 'm', POPT_ARG_STRING, NULL, 'm',
+                "Set the max protocol level", "LEVEL"},
                POPT_COMMON_SAMBA
                POPT_COMMON_CREDENTIALS
                { NULL }
@@ -601,15 +614,6 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
 
        fault_setup();
 
-       lp_load_global(get_dyn_CONFIGFILE());
-       load_interfaces();
-
-       smbcquotas_auth_info = user_auth_info_init(frame);
-       if (smbcquotas_auth_info == NULL) {
-               exit(1);
-       }
-       popt_common_set_auth_info(smbcquotas_auth_info);
-
        pc = poptGetContext("smbcquotas", argc, argv_const, long_options, 0);
 
        poptSetOtherOptionHelp(pc, "//server1/share1");
@@ -665,6 +669,10 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
                        }
                        todo = SET_QUOTA;
                        break;
+               case 'm':
+                       lp_set_cmdline("client max protocol",
+                                      poptGetOptArg(pc));
+                       break;
                }
        }
 
@@ -673,7 +681,8 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
 
        if (!fix_user) {
                username_str = talloc_strdup(
-                       frame, get_cmdline_auth_info_username(smbcquotas_auth_info));
+                       frame, get_cmdline_auth_info_username(
+                               popt_get_cmdline_auth_info()));
                if (!username_str) {
                        exit(EXIT_PARSE_ERROR);
                }
@@ -723,6 +732,7 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
                        exit(EXIT_FAILED);
                }
        } else {
+               popt_free_cmdline_auth_info();
                exit(EXIT_OK);
        }
 
@@ -747,6 +757,7 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
                        break;
        }
 
+       popt_free_cmdline_auth_info();
        talloc_free(frame);
 
        return result;