summaryrefslogtreecommitdiff
path: root/source3/rpcclient/rpcclient.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2001-12-03 07:42:18 +0000
committerAndrew Bartlett <abartlet@samba.org>2001-12-03 07:42:18 +0000
commit3ea7519b061a464ecec55341f218802ca0c2eb47 (patch)
tree8fe41db83d06ea704db8ba8e81ad6f799eb181ac /source3/rpcclient/rpcclient.c
parent8e16021383b95ed5169555f12e11af70603c92b6 (diff)
downloadsamba-3ea7519b061a464ecec55341f218802ca0c2eb47.tar.gz
samba-3ea7519b061a464ecec55341f218802ca0c2eb47.tar.bz2
samba-3ea7519b061a464ecec55341f218802ca0c2eb47.zip
This change reworkes the connection code for both rpcclient and net new
'net' untility. This should make it easier to port rpcclient code across to net. It also allows SPNEGO (the NTLMSSP subsystem in particular) to work, becouse it kills off the early destruction of the clear-text password. Andrew Bartlett (This used to be commit eee925861a3af3aa16efa3b1700a980c9510c14e)
Diffstat (limited to 'source3/rpcclient/rpcclient.c')
-rw-r--r--source3/rpcclient/rpcclient.c122
1 files changed, 36 insertions, 86 deletions
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index c7d1604a0b..5a8d6f62b4 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -243,27 +243,6 @@ void fetch_machine_sid(struct cli_state *cli)
exit(1);
}
-/* Initialise client credentials for authenticated pipe access */
-
-void init_rpcclient_creds(struct ntuser_creds *creds, char* username,
- char* domain, char* password)
-{
- ZERO_STRUCTP(creds);
-
- if (lp_encrypted_passwords()) {
- pwd_make_lm_nt_16(&creds->pwd, password);
- } else {
- pwd_set_cleartext(&creds->pwd, password);
- }
-
- fstrcpy(creds->user_name, username);
- fstrcpy(creds->domain, domain);
-
- if (! *username) {
- creds->pwd.null_pwd = True;
- }
-}
-
/* Display help on commands */
@@ -550,47 +529,6 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
return result;
}
-/************************************************************************/
-struct cli_state *setup_connection(struct cli_state *cli, char *system_name,
- struct ntuser_creds *creds)
-{
- struct in_addr dest_ip;
- struct nmb_name calling, called;
- fstring dest_host;
- extern pstring global_myname;
- struct ntuser_creds anon;
-
- /* Initialise cli_state information */
- if (!cli_initialise(cli)) {
- return NULL;
- }
-
- if (!creds) {
- ZERO_STRUCT(anon);
- anon.pwd.null_pwd = 1;
- creds = &anon;
- }
-
- cli_init_creds(cli, creds);
-
- /* Establish a SMB connection */
- if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
- fprintf(stderr, "Could not resolve %s\n", dest_host);
- return NULL;
- }
-
- make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
- make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
-
- if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
- &called, "IPC$", "IPC", False, True)) {
- fprintf(stderr, "Error establishing IPC$ connection\n");
- return NULL;
- }
-
- return cli;
-}
-
/* Print usage information */
static void usage(void)
@@ -621,13 +559,14 @@ static void usage(void)
int opt;
int olddebug;
pstring cmdstr = "";
- struct ntuser_creds creds;
- struct cli_state cli;
+ struct cli_state *cli;
fstring password,
username,
domain,
server;
struct cmd_set **cmd_set;
+ struct in_addr server_ip;
+ NTSTATUS nt_status;
setlinebuf(stdout);
@@ -718,33 +657,42 @@ static void usage(void)
get_myname((*global_myname)?NULL:global_myname);
strupper(global_myname);
+
+
+ /* resolve the IP address */
+ if (!resolve_name(server, &server_ip, 0x20)) {
+ DEBUG(1,("Unable to resolve server name\n"));
+ return 1;
+ }
/*
- * initialize the credentials struct. Get password
+ * Get password
* from stdin if necessary
*/
+
+ if (!got_pass) {
+ char *pass = getpass("Password:");
+ if (pass) {
+ fstrcpy(password, pass);
+ }
+ }
+
if (!strlen(username) && !got_pass)
get_username(username);
- if (!got_pass) {
- init_rpcclient_creds (&creds, username, domain, "");
- pwd_read(&creds.pwd, "Enter Password: ", lp_encrypted_passwords());
- }
- else {
- init_rpcclient_creds (&creds, username, domain, password);
- }
- memset(password,'X',sizeof(password));
-
- /* open a connection to the specified server */
- ZERO_STRUCTP (&cli);
- if (!setup_connection (&cli, server, &creds)) {
+ nt_status = cli_full_connection(&cli, global_myname, server,
+ &server_ip, 0,
+ "IPC$", "IPC",
+ username, domain,
+ password, strlen(password));
+
+ if (!NT_STATUS_IS_OK(nt_status)) {
+ DEBUG(1,("Cannot connect to server. Error was %s\n", get_nt_error_msg(nt_status)));
return 1;
}
-
- /* There are no pointers in ntuser_creds struct so zero it out */
- ZERO_STRUCTP (&creds);
-
+ memset(password,'X',sizeof(password));
+
/* Load command lists */
cmd_set = rpcclient_command_list;
@@ -755,7 +703,7 @@ static void usage(void)
cmd_set++;
}
- fetch_machine_sid(&cli);
+ fetch_machine_sid(cli);
/* Do anything specified with -c */
if (cmdstr[0]) {
@@ -763,9 +711,10 @@ static void usage(void)
char *p = cmdstr;
while((cmd=next_command(&p)) != NULL) {
- process_cmd(&cli, cmd);
+ process_cmd(cli, cmd);
}
-
+
+ cli_shutdown(cli);
return 0;
}
@@ -783,8 +732,9 @@ static void usage(void)
break;
if (line[0] != '\n')
- process_cmd(&cli, line);
+ process_cmd(cli, line);
}
-
+
+ cli_shutdown(cli);
return 0;
}