]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:rpcclient: Migrate rpcclient to new cmdline option parser
authorAndreas Schneider <asn@samba.org>
Tue, 1 Dec 2020 12:48:03 +0000 (13:48 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 20 May 2021 02:58:36 +0000 (02:58 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/rpcclient/cmd_spoolss.c
source3/rpcclient/rpcclient.c
source3/rpcclient/wscript_build
source3/selftest/tests.py

index 1706cec4ddb72bad9b0f9c30e015008728d699db..dc8bbd161858c0d0d084e1bbd0153e58f4f28387 100644 (file)
@@ -33,9 +33,9 @@
 #include "../libcli/security/security_descriptor.h"
 #include "../libcli/registry/util_reg.h"
 #include "libsmb/libsmb.h"
-#include "popt_common_cmdline.h"
 #include "lib/util/smb_strtox.h"
 #include "lib/util/string_wrappers.h"
+#include "lib/cmdline/cmdline.h"
 
 #define RPCCLIENT_PRINTERNAME(_printername, _cli, _arg) \
 { \
@@ -3505,6 +3505,7 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
        struct policy_handle hPrinter1, hPrinter2;
        NTSTATUS nt_status;
        WERROR werror;
+       struct cli_credentials *creds = samba_cmdline_get_creds();
 
        if ( argc != 3 )  {
                printf("Usage: %s <printer> <server>\n", argv[0]);
@@ -3518,8 +3519,7 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
        nt_status = cli_full_connection_creds(&cli_server2, lp_netbios_name(), argv[2],
                                NULL, 0,
                                "IPC$", "IPC",
-                               get_cmdline_auth_info_creds(
-                                       popt_get_cmdline_auth_info()),
+                               creds,
                                CLI_FULL_CONNECTION_IPC);
        if ( !NT_STATUS_IS_OK(nt_status) )
                return WERR_GEN_FAILURE;
index a7a9748968d6c1eddcdadb2d533e3d8d4b8ec29c..92d200e94e4ff495851dcef91445306a29634f6b 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "includes.h"
 #include "../libcli/auth/netlogon_creds_cli.h"
-#include "popt_common_cmdline.h"
 #include "rpcclient.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "../librpc/gen_ndr/ndr_lsa_c.h"
@@ -37,6 +36,7 @@
 #include "messages.h"
 #include "cmdline_contexts.h"
 #include "../librpc/gen_ndr/ndr_samr.h"
+#include "lib/cmdline/cmdline.h"
 
 enum pipe_auth_type_spnego {
        PIPE_AUTH_TYPE_SPNEGO_NONE = 0,
@@ -1133,8 +1133,8 @@ out_free:
        enum dcerpc_transport_t transport;
        const char *binding_string = NULL;
        const char *host;
-       int signing_state = SMB_SIGNING_IPC_DEFAULT;
        struct cli_credentials *creds = NULL;
+       bool ok;
 
        /* make sure the vars that get altered (4th field) are in
           a fixed location or certain compilers complain */
@@ -1147,6 +1147,8 @@ out_free:
                POPT_COMMON_SAMBA
                POPT_COMMON_CONNECTION
                POPT_COMMON_CREDENTIALS
+               POPT_LEGACY_S3
+               POPT_COMMON_VERSION
                POPT_TABLEEND
        };
 
@@ -1156,17 +1158,26 @@ out_free:
 
        setlinebuf(stdout);
 
-       /* the following functions are part of the Samba debugging
-          facilities.  See lib/debug.c */
-       setup_logging("rpcclient", DEBUG_STDOUT);
+       ok = samba_cmdline_init(frame,
+                               SAMBA_CMDLINE_CONFIG_CLIENT,
+                               false /* require_smbconf */);
+       if (!ok) {
+               DBG_ERR("Failed to init cmdline parser!\n");
+       }
        lp_set_cmdline("log level", "0");
 
        /* Parse options */
+       pc = samba_popt_get_context(getprogname(),
+                                   argc,
+                                   const_argv,
+                                   long_options,
+                                   0);
+       if (pc == NULL) {
+               DBG_ERR("Failed to setup popt context!\n");
+               exit(1);
+       }
 
-       pc = poptGetContext("rpcclient", argc, const_argv,
-                           long_options, 0);
-
-       poptSetOtherOptionHelp(pc, "[OPTION...] <server>\nOptions:");
+       poptSetOtherOptionHelp(pc, "[OPTION...] BINDING-STRING|HOST\nOptions:");
 
        if (argc == 1) {
                poptPrintHelp(pc, stderr, 0);
@@ -1200,10 +1211,10 @@ out_free:
        }
 
        poptFreeContext(pc);
-       popt_burn_cmdline_password(argc, argv);
+       samba_cmdline_burn(argc, argv);
 
        rpcclient_msg_ctx = cmdline_messaging_context(get_dyn_CONFIGFILE());
-       creds = get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+       creds = samba_cmdline_get_creds();
 
        /*
         * Get password
@@ -1246,19 +1257,7 @@ out_free:
 
        host = dcerpc_binding_get_string_option(binding, "host");
 
-       signing_state = get_cmdline_auth_info_signing_state(
-                       popt_get_cmdline_auth_info());
-       switch (signing_state) {
-       case SMB_SIGNING_OFF:
-               lp_set_cmdline("client ipc signing", "no");
-               break;
-       case SMB_SIGNING_REQUIRED:
-               lp_set_cmdline("client ipc signing", "required");
-               break;
-       }
-
-       rpcclient_netlogon_domain = get_cmdline_auth_info_domain(
-                       popt_get_cmdline_auth_info());
+       rpcclient_netlogon_domain = cli_credentials_get_domain(creds);
        if (rpcclient_netlogon_domain == NULL ||
            rpcclient_netlogon_domain[0] == '\0')
        {
@@ -1274,8 +1273,7 @@ out_free:
                        opt_port,
                        "IPC$",
                        "IPC",
-                       get_cmdline_auth_info_creds(
-                               popt_get_cmdline_auth_info()),
+                       creds,
                        flags);
 
                if (!NT_STATUS_IS_OK(nt_status)) {
@@ -1344,7 +1342,6 @@ done:
        if (cli != NULL) {
                cli_shutdown(cli);
        }
-       popt_free_cmdline_auth_info();
        netlogon_creds_cli_close_global_db();
        TALLOC_FREE(rpcclient_msg_ctx);
        TALLOC_FREE(frame);
index 52a955c914b75eeb1874be110848bba7112907b6..75935755f1abc0e5c3954f105c84208afecad535 100644 (file)
@@ -25,7 +25,8 @@ bld.SAMBA3_BINARY('rpcclient',
                 ''',
                  deps='''
                  talloc
-                 popt_samba3_cmdline
+                 CMDLINE_S3
+                 cmdline_contexts
                  pdb
                  libsmb
                  smbconf
index 9b7271ea6d59bf3285e20a403835c987c86b8e38..13f0466802e62b51ba4750d4454df6ce346e41cd 100755 (executable)
@@ -1008,7 +1008,7 @@ for s in signseal_options:
             [os.path.join(samba3srcdir, "script/tests/test_rpcclient.sh"),
              "$PREFIX/ktest/krb5_ccache-3",
              binding_string,
-             "-k -c getusername",
+             "--use-krb5-ccache=$PREFIX/ktest/krb5_ccache-3 -c getusername",
              configuration])
 
 plantestsuite("samba3.blackbox.rpcclient_samlogon", "ad_member:local", [os.path.join(samba3srcdir, "script/tests/test_rpcclient_samlogon.sh"),