From: Andreas Schneider Date: Tue, 1 Dec 2020 12:48:03 +0000 (+0100) Subject: s3:rpcclient: Migrate rpcclient to new cmdline option parser X-Git-Tag: tevent-0.11.0~791 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4fb4da396c60992acf890305230b560c97320f2c;p=thirdparty%2Fsamba.git s3:rpcclient: Migrate rpcclient to new cmdline option parser Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c index 1706cec4ddb..dc8bbd16185 100644 --- a/source3/rpcclient/cmd_spoolss.c +++ b/source3/rpcclient/cmd_spoolss.c @@ -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 \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; diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index a7a9748968d..92d200e94e4 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -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...] \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); diff --git a/source3/rpcclient/wscript_build b/source3/rpcclient/wscript_build index 52a955c914b..75935755f1a 100644 --- a/source3/rpcclient/wscript_build +++ b/source3/rpcclient/wscript_build @@ -25,7 +25,8 @@ bld.SAMBA3_BINARY('rpcclient', ''', deps=''' talloc - popt_samba3_cmdline + CMDLINE_S3 + cmdline_contexts pdb libsmb smbconf diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 9b7271ea6d5..13f0466802e 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -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"),