summaryrefslogtreecommitdiff
path: root/source3/rpc_client
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-04-25 01:12:08 +0000
committerJeremy Allison <jra@samba.org>1998-04-25 01:12:08 +0000
commite7ac86607c80912e55ac7179b100cea22749c16f (patch)
tree257b85ec9e88be65c95cf82afb1f6e7c4c20e4c7 /source3/rpc_client
parent9189005f7f884123d29c8f27db73687b68c80bb9 (diff)
downloadsamba-e7ac86607c80912e55ac7179b100cea22749c16f.tar.gz
samba-e7ac86607c80912e55ac7179b100cea22749c16f.tar.bz2
samba-e7ac86607c80912e55ac7179b100cea22749c16f.zip
This looks like a big change but really isn't.
It is changing the global variables "myname" and "myworkgroup" to "global_myname" and "global_myworkgroup" respectively. This is to make it very explicit when we are messing with a global (don't ask - it makes the domain client code much clearer :-). Jeremy. (This used to be commit 866406bfe399cf757c8275093dacd5ce4843afa0)
Diffstat (limited to 'source3/rpc_client')
-rw-r--r--source3/rpc_client/cli_login.c113
-rw-r--r--source3/rpc_client/cli_netlogon.c57
-rw-r--r--source3/rpc_client/cli_pipe.c100
3 files changed, 85 insertions, 185 deletions
diff --git a/source3/rpc_client/cli_login.c b/source3/rpc_client/cli_login.c
index 771ff7108e..ad176ffe8f 100644
--- a/source3/rpc_client/cli_login.c
+++ b/source3/rpc_client/cli_login.c
@@ -26,13 +26,10 @@
extern int DEBUGLEVEL;
/****************************************************************************
-Initialize domain session.
+Initialize domain session credentials.
****************************************************************************/
-BOOL do_nt_session_open(struct cli_state *cli, uint16 fnum,
- char *dest_host, char *myhostname,
- char *mach_acct,
- uchar sess_key[16], DOM_CRED *clnt_cred)
+BOOL cli_nt_setup_creds(struct cli_state *cli, unsigned char mach_pwd[16])
{
DOM_CHAL clnt_chal;
DOM_CHAL srv_chal;
@@ -41,57 +38,19 @@ BOOL do_nt_session_open(struct cli_state *cli, uint16 fnum,
UTIME zerotime;
- char nt_owf_mach_pwd[16];
-
RPC_IFACE abstract;
RPC_IFACE transfer;
- fstring mach_pwd;
- fstring dest_srv;
-
/******************** initialise ********************************/
zerotime.time = 0;
- DEBUG(10,("do_nt_session_open: %d\n", __LINE__));
-
- /**************** Set Named Pipe State ***************/
- if (!rpc_pipe_set_hnd_state(cli, PIPE_NETLOGON, fnum, 0x4300))
- {
- DEBUG(0,("do_nt_session_open: pipe hnd state failed\n"));
- return False;
- }
-
- /******************* bind request on \PIPE\NETLOGON *****************/
-
- if (!rpc_pipe_bind(cli, PIPE_NETLOGON, fnum, &abstract, &transfer,
- False, NULL, NULL))
- {
- DEBUG(0,("do_nt_session_open: rpc bind failed\n"));
- return False;
- }
-
- /************ Check workstation trust account *******************/
-
-FIXME !!
- /* default machine password is lower-case machine name (really secure) */
- fstrcpy(mach_pwd, myhostname);
- strlower(mach_pwd);
-
- /* default machine password is lower-case machine name (really secure) */
- fstrcpy(prev_mpd, myhostname);
- strlower(prev_mpd);
-
/******************* Request Challenge ********************/
generate_random_buffer( clnt_chal.data, 8, False);
- strcpy(dest_srv, "\\\\");
- strcat(dest_srv, dest_host);
- strupper(dest_srv);
-
/* send a client challenge; receive a server challenge */
- if (!do_net_req_chal(cli, fnum, dest_srv, myhostname, &clnt_chal, &srv_chal))
+ if (!cli_net_req_chal(cli, &clnt_chal, &srv_chal))
{
DEBUG(0,("do_nt_session_open: request challenge failed\n"));
return False;
@@ -99,17 +58,8 @@ FIXME !!
/**************** Long-term Session key **************/
-#ifdef DEBUG_PASSWORD
- DEBUG(100,("generating nt owf from initial machine pwd: %s\n", mach_pwd));
-#endif
- nt_owf_gen( mach_pwd, nt_owf_mach_pwd);
-
-#ifdef DEBUG_PASSWORD
- dump_data(6, nt_owf_mach_pwd, 16);
-#endif
-
/* calculate the session key */
- cred_session_key(&clnt_chal, &srv_chal, nt_owf_mach_pwd, sess_key);
+ cred_session_key(&clnt_chal, &srv_chal, mach_pwd, sess_key);
bzero(sess_key+8, 8);
/******************* Authenticate 2 ********************/
@@ -118,22 +68,22 @@ FIXME !!
cred_create(sess_key, &clnt_chal, zerotime, &(clnt_cred->challenge));
/* send client auth-2 challenge; receive an auth-2 challenge */
- if (!do_net_auth2(cli, fnum, dest_srv, mach_acct,
- SEC_CHAN_WKSTA, myhostname,
- &(clnt_cred->challenge), 0x000001ff, &auth2_srv_chal))
+ if (!cli_net_auth2(cli, SEC_CHAN_WKSTA, 0x000001ff,
+ &(cli->clnt_cred->challenge), &auth2_srv_chal))
{
- DEBUG(0,("do_nt_session_open: request challenge failed\n"));
+ DEBUG(0,("do_nt_session_open: auth2 challenge failed\n"));
return False;
}
return True;
}
+#if 0
/****************************************************************************
server password set
****************************************************************************/
-BOOL do_nt_srv_pwset(struct cli_state *cli, int t_idx, uint16 fnum,
+BOOL do_nt_srv_pwset(struct cli_state *cli,
uint8 sess_key[16], DOM_CRED *clnt_cred, DOM_CRED *rtn_cred,
char *new_mach_pwd,
char *dest_host, char *mach_acct, char *myhostname)
@@ -208,14 +158,13 @@ void make_nt_login_interactive(NET_ID_INFO_CTR *ctr,
smb_userid, 0, username, myhostname,
sess_key, lm_owf_user_pwd, nt_owf_user_pwd);
}
+#endif
/****************************************************************************
make network sam login info
****************************************************************************/
-void make_nt_login_network(NET_ID_INFO_CTR *ctr,
- char *workgroup, char *myhostname,
- uint32 smb_userid, char *username,
+void make_nt_login_network(NET_ID_INFO_CTR *ctr, uint32 smb_userid, char *username,
char lm_chal[8], char lm_chal_resp[24],
char nt_chal_resp[24])
{
@@ -223,7 +172,7 @@ void make_nt_login_network(NET_ID_INFO_CTR *ctr,
ctr->switch_value = 2;
/* this is used in both the SAM Logon and the SAM Logoff */
- make_id_info2(&ctr->auth.id2, workgroup, 0, smb_userid, 0,
+ make_id_info2(&ctr->auth.id2, myworkgroup, 0, smb_userid, 0,
username, myhostname,
lm_chal, lm_chal_resp, nt_chal_resp);
}
@@ -232,10 +181,9 @@ void make_nt_login_network(NET_ID_INFO_CTR *ctr,
NT login.
****************************************************************************/
-BOOL do_nt_login(struct cli_state *cli, uint16 fnum,
- uint8 sess_key[16], DOM_CRED *clnt_cred, DOM_CRED *rtn_cred,
- NET_ID_INFO_CTR *ctr, char *dest_host, char *myhostname,
- NET_USER_INFO_3 *user_info3)
+BOOL cli_nt_login(struct cli_state *cli,
+ DOM_CRED *clnt_cred, DOM_CRED *rtn_cred,
+ NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3)
{
DOM_CRED sam_logon_rtn_cred;
DOM_CRED cred;
@@ -246,12 +194,12 @@ BOOL do_nt_login(struct cli_state *cli, uint16 fnum,
/*********************** SAM Logon **********************/
- clnt_cred->timestamp.time = time(NULL);
+ cli->clnt_cred->timestamp.time = time(NULL);
- memcpy(&cred, clnt_cred, sizeof(cred));
+ memcpy(&cred, cli->clnt_cred, sizeof(cred));
/* calculate sam logon credentials */
- cred_create(sess_key, &(clnt_cred->challenge),
+ cred_create(sess_key, &(cli->clnt_cred->challenge),
cred.timestamp, &(cred.challenge));
strcpy(dest_srv, "\\\\");
@@ -262,8 +210,7 @@ BOOL do_nt_login(struct cli_state *cli, uint16 fnum,
strupper(my_host_name);
/* send client sam-logon challenge */
- return do_net_sam_logon(cli, fnum, sess_key, clnt_cred,
- dest_srv, my_host_name,
+ return cli_net_sam_logon(cli, dest_srv, my_host_name,
&cred, &sam_logon_rtn_cred,
ctr->switch_value, ctr, 3, user_info3,
rtn_cred);
@@ -273,8 +220,7 @@ BOOL do_nt_login(struct cli_state *cli, uint16 fnum,
nt sam logoff
****************************************************************************/
-BOOL do_nt_logoff(struct cli_state *cli, uint16 fnum,
- uint8 sess_key[16], DOM_CRED *clnt_cred, DOM_CRED *rtn_cred,
+BOOL cli_nt_logoff(struct cli_state *cli, DOM_CRED *rtn_cred,
NET_ID_INFO_CTR *ctr, char *dest_host, char *myhostname)
{
DOM_CRED sam_logoff_rtn_cred;
@@ -288,10 +234,10 @@ BOOL do_nt_logoff(struct cli_state *cli, uint16 fnum,
clnt_cred->timestamp.time = time(NULL);
- memcpy(&cred, clnt_cred, sizeof(cred));
+ memcpy(&cred, cli->clnt_cred, sizeof(cred));
/* calculate sam logoff credentials */
- cred_create(sess_key, &(clnt_cred->challenge),
+ cred_create(sess_key, &(cli->clnt_cred->challenge),
cred.timestamp, &(cred.challenge));
strcpy(dest_srv, "\\\\");
@@ -302,22 +248,9 @@ BOOL do_nt_logoff(struct cli_state *cli, uint16 fnum,
strupper(my_host_name);
/* send client sam-logoff challenge; receive a sam-logoff challenge */
- return do_net_sam_logoff(cli, fnum, sess_key, clnt_cred,
+ return cli_net_sam_logoff(cli, fnum, sess_key, clnt_cred,
dest_srv, my_host_name,
&cred, &sam_logoff_rtn_cred,
ctr->switch_value, ctr, 3,
rtn_cred);
}
-
-/****************************************************************************
-Close the NT pipe.
-****************************************************************************/
-
-void do_nt_session_close(struct cli_state *cli, uint16 fnum)
-{
- /******************** close the \PIPE\NETLOGON file **************/
- if (fnum != 0xffff)
- {
- cli_close(cli, fnum);
- }
-}
diff --git a/source3/rpc_client/cli_netlogon.c b/source3/rpc_client/cli_netlogon.c
index a1a868ce96..654445b31d 100644
--- a/source3/rpc_client/cli_netlogon.c
+++ b/source3/rpc_client/cli_netlogon.c
@@ -65,7 +65,7 @@ BOOL do_net_logon_ctrl2(struct cli_state *cli, uint16 fnum,
net_io_q_logon_ctrl2("", &q_l, &buf, 0);
/* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, NET_LOGON_CTRL2, &buf, &rbuf))
+ if (rpc_api_pipe_req(cli, NET_LOGON_CTRL2, &buf, &rbuf))
{
NET_R_LOGON_CTRL2 r_l;
BOOL ok;
@@ -77,6 +77,7 @@ BOOL do_net_logon_ctrl2(struct cli_state *cli, uint16 fnum,
{
/* report error code */
DEBUG(0,("NET_R_LOGON_CTRL: %s\n", get_nt_error_msg(r_l.status)));
+ cli->nt_error = r_l.status;
ok = False;
}
@@ -96,38 +97,32 @@ BOOL do_net_logon_ctrl2(struct cli_state *cli, uint16 fnum,
do a LSA Authenticate 2
****************************************************************************/
-BOOL do_net_auth2(struct cli_state *cli, uint16 fnum,
- char *logon_srv, char *acct_name, uint16 sec_chan,
- char *comp_name, DOM_CHAL *clnt_chal, uint32 neg_flags,
- DOM_CHAL *srv_chal)
+BOOL cli_net_auth2(struct cli_state *cli, uint16 sec_chan,
+ uint32 neg_flags, DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal)
{
prs_struct rbuf;
prs_struct buf;
NET_Q_AUTH_2 q_a;
BOOL valid_chal = False;
- if (srv_chal == NULL || clnt_chal == NULL)
- return False;
-
prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
prs_init(&rbuf, 0, 4, SAFETY_MARGIN, True );
-
/* create and send a MSRPC command with api NET_AUTH2 */
DEBUG(4,("LSA Authenticate 2: srv:%s acct:%s sc:%x mc: %s chal %s neg: %lx\n",
- logon_srv, acct_name, sec_chan, comp_name,
+ cli->srv_name, cli->mach_acct, sec_chan, global_myname,
credstr(clnt_chal->data), neg_flags));
/* store the parameters */
- make_q_auth_2(&q_a, logon_srv, acct_name, sec_chan, comp_name,
+ make_q_auth_2(&q_a, cli->srv_name, cli->mach_acct, sec_chan, global_myname,
clnt_chal, neg_flags);
/* turn parameters into data stream */
net_io_q_auth_2("", &q_a, &buf, 0);
/* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, NET_AUTH2, &buf, &rbuf))
+ if (rpc_api_pipe_req(cli, NET_AUTH2, &buf, &rbuf))
{
NET_R_AUTH_2 r_a;
BOOL ok;
@@ -139,6 +134,7 @@ BOOL do_net_auth2(struct cli_state *cli, uint16 fnum,
{
/* report error code */
DEBUG(0,("NET_AUTH2: %s\n", get_nt_error_msg(r_a.status)));
+ cli->nt_error = r_a.status;
ok = False;
}
@@ -168,9 +164,7 @@ BOOL do_net_auth2(struct cli_state *cli, uint16 fnum,
do a LSA Request Challenge
****************************************************************************/
-BOOL do_net_req_chal(struct cli_state *cli, uint16 fnum,
- char *desthost, char *myhostname,
- DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal)
+BOOL cli_net_req_chal(struct cli_state *cli, DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal)
{
prs_struct rbuf;
prs_struct buf;
@@ -183,20 +177,19 @@ BOOL do_net_req_chal(struct cli_state *cli, uint16 fnum,
prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
prs_init(&rbuf, 0, 4, SAFETY_MARGIN, True );
-
/* create and send a MSRPC command with api NET_REQCHAL */
- DEBUG(4,("LSA Request Challenge from %s to %s: %s\n",
- desthost, myhostname, credstr(clnt_chal->data)));
+ DEBUG(4,("cli_net_req_chal: LSA Request Challenge from %s to %s: %s\n",
+ cli->desthost, global_myname, credstr(clnt_chal->data)));
/* store the parameters */
- make_q_req_chal(&q_c, desthost, myhostname, clnt_chal);
+ make_q_req_chal(&q_c, desthost, global_myname, clnt_chal);
/* turn parameters into data stream */
net_io_q_req_chal("", &q_c, &buf, 0);
/* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, NET_REQCHAL, &buf, &rbuf))
+ if (rpc_api_pipe_req(cli, NET_REQCHAL, &buf, &rbuf))
{
NET_R_REQ_CHAL r_c;
BOOL ok;
@@ -208,6 +201,7 @@ BOOL do_net_req_chal(struct cli_state *cli, uint16 fnum,
{
/* report error code */
DEBUG(0,("NET_REQ_CHAL: %s\n", get_nt_error_msg(r_c.status)));
+ cli->nt_error = r_a.status;
ok = False;
}
@@ -261,7 +255,7 @@ BOOL do_net_srv_pwset(struct cli_state *cli, uint16 fnum,
net_io_q_srv_pwset("", &q_s, &buf, 0);
/* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, NET_SRVPWSET, &buf, &rbuf))
+ if (rpc_api_pipe_req(cli, NET_SRVPWSET, &buf, &rbuf))
{
NET_R_SRV_PWSET r_s;
BOOL ok;
@@ -273,6 +267,7 @@ BOOL do_net_srv_pwset(struct cli_state *cli, uint16 fnum,
{
/* report error code */
DEBUG(0,("NET_R_SRV_PWSET: %s\n", get_nt_error_msg(r_s.status)));
+ cli->nt_error = r_s.status;
ok = False;
}
@@ -302,8 +297,7 @@ BOOL do_net_srv_pwset(struct cli_state *cli, uint16 fnum,
do a LSA SAM Logon
****************************************************************************/
-BOOL do_net_sam_logon(struct cli_state *cli, uint16 fnum,
- uchar sess_key[8], DOM_CRED *sto_clnt_cred,
+BOOL cli_net_sam_logon(struct cli_state *cli, DOM_CRED *sto_clnt_cred,
char *logon_srv, char *comp_name,
DOM_CRED *clnt_cred, DOM_CRED *rtn_cred,
uint16 logon_level, NET_ID_INFO_CTR *ctr,
@@ -321,24 +315,23 @@ BOOL do_net_sam_logon(struct cli_state *cli, uint16 fnum,
prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
prs_init(&rbuf, 0, 4, SAFETY_MARGIN, True );
-
/* create and send a MSRPC command with api NET_SAMLOGON */
DEBUG(4,("LSA SAM Logon: srv:%s mc:%s clnt %s %lx rtn: %s %lx ll: %d\n",
- logon_srv, comp_name,
- credstr(clnt_cred->challenge.data), clnt_cred->timestamp.time,
+ cli->srv_name, global_myname,
+ credstr(cli->clnt_cred->challenge.data), cli->clnt_cred->timestamp.time,
credstr(rtn_cred->challenge.data), rtn_cred ->timestamp.time,
logon_level));
/* store the parameters */
- make_sam_info(&(q_s.sam_id), logon_srv, comp_name,
- clnt_cred, rtn_cred, logon_level, ctr, validation_level);
+ make_sam_info(&(q_s.sam_id), cli->srv_name, global_myname,
+ cli->clnt_cred, rtn_cred, logon_level, ctr, validation_level);
/* turn parameters into data stream */
net_io_q_sam_logon("", &q_s, &buf, 0);
/* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, NET_SAMLOGON, &buf, &rbuf))
+ if (rpc_api_pipe_req(cli, NET_SAMLOGON, &buf, &rbuf))
{
NET_R_SAM_LOGON r_s;
BOOL ok;
@@ -352,6 +345,7 @@ BOOL do_net_sam_logon(struct cli_state *cli, uint16 fnum,
{
/* report error code */
DEBUG(0,("NET_SAMLOGON: %s\n", get_nt_error_msg(r_s.status)));
+ cli->nt_error = r_s.status;
ok = False;
}
@@ -365,7 +359,7 @@ BOOL do_net_sam_logon(struct cli_state *cli, uint16 fnum,
if (ok)
{
- if (clnt_deal_with_creds(sess_key, sto_clnt_cred, &(r_s.srv_creds)))
+ if (clnt_deal_with_creds(cli->sess_key, sto_clnt_cred, &(r_s.srv_creds)))
{
DEBUG(5, ("do_net_sam_logon: server credential check OK\n"));
/* ok, at last: we're happy. return the challenge */
@@ -423,7 +417,7 @@ BOOL do_net_sam_logoff(struct cli_state *cli, uint16 fnum,
net_io_q_sam_logoff("", &q_s, &buf, 0);
/* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, NET_SAMLOGOFF, &buf, &rbuf))
+ if (rpc_api_pipe_req(cli, NET_SAMLOGOFF, &buf, &rbuf))
{
NET_R_SAM_LOGOFF r_s;
BOOL ok;
@@ -435,6 +429,7 @@ BOOL do_net_sam_logoff(struct cli_state *cli, uint16 fnum,
{
/* report error code */
DEBUG(0,("NET_SAMLOGOFF: %s\n", get_nt_error_msg(r_s.status)));
+ cli->nt_error = r_s.status;
ok = False;
}
diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c
index 7ac0f72c77..d57009a47a 100644
--- a/source3/rpc_client/cli_pipe.c
+++ b/source3/rpc_client/cli_pipe.c
@@ -46,7 +46,7 @@ uint32 get_rpc_call_id(void)
uses SMBreadX to get rest of rpc data
********************************************************************/
-static BOOL rpc_read(struct cli_state *cli, uint16 fnum,
+static BOOL rpc_read(struct cli_state *cli,
prs_struct *rdata, uint32 data_to_read,
uint32 rdata_offset)
{
@@ -83,7 +83,7 @@ static BOOL rpc_read(struct cli_state *cli, uint16 fnum,
DEBUG(5,("rpc_read: grow buffer to %d\n", rdata->data->data_used));
}
- num_read = cli_read(cli, fnum, data, file_offset + 0x100000, size);
+ num_read = cli_read(cli, cli->nt_pipe_fnum, data, file_offset + 0x100000, size);
DEBUG(5,("rpc_read: read offset: %d read: %d to read: %d\n",
file_offset, num_read, data_to_read));
@@ -153,7 +153,7 @@ static BOOL rpc_check_hdr(prs_struct *rdata, uint8 *pkt_type,
****************************************************************************/
-BOOL rpc_api_pipe(struct cli_state *cli, uint16 cmd, uint16 fnum,
+BOOL rpc_api_pipe(struct cli_state *cli, uint16 cmd,
prs_struct *param , prs_struct *data,
prs_struct *rparam, prs_struct *rdata)
{
@@ -184,7 +184,7 @@ BOOL rpc_api_pipe(struct cli_state *cli, uint16 cmd, uint16 fnum,
/* create setup parameters. */
setup[0] = cmd;
- setup[1] = fnum; /* pipe file handle. got this from an SMBcreateX. */
+ setup[1] = cli->nt_pipe_fnum; /* pipe file handle. got this from an SMBOpenX. */
/* send the data: receive a response. */
if (!cli_api_pipe(cli, "\\PIPE\\\0\0\0", 8,
@@ -231,7 +231,7 @@ BOOL rpc_api_pipe(struct cli_state *cli, uint16 cmd, uint16 fnum,
/* err status is only informational: the _real_ check is on the length */
if (len > 0) /* || err == (0x80000000 | STATUS_BUFFER_OVERFLOW)) */
{
- if (!rpc_read(cli, fnum, rdata, len, rdata->data->data_used))
+ if (!rpc_read(cli, rdata, len, rdata->data->data_used))
return False;
}
@@ -251,7 +251,7 @@ BOOL rpc_api_pipe(struct cli_state *cli, uint16 cmd, uint16 fnum,
prs_init(&hps, 0x18, 4, 0, True);
- num_read = cli_read(cli, fnum, hps.data->data, 0, 0x18);
+ num_read = cli_read(cli, cli->nt_pipe_fnum, hps.data->data, 0, 0x18);
DEBUG(5,("rpc_api_pipe: read header (size:%d)\n", num_read));
if (num_read != 0x18)
@@ -275,7 +275,7 @@ BOOL rpc_api_pipe(struct cli_state *cli, uint16 cmd, uint16 fnum,
}
len = rhdr.frag_len - hps.offset;
- if (!rpc_read(cli, fnum, rdata, len, rdata->data->data_used))
+ if (!rpc_read(cli, rdata, len, rdata->data->data_used))
return False;
}
@@ -400,7 +400,7 @@ static BOOL create_rpc_request(prs_struct *rhdr, uint8 op_num, int data_len)
/****************************************************************************
send a request on an rpc pipe.
****************************************************************************/
-BOOL rpc_api_pipe_req(struct cli_state *cli, uint16 fnum, uint8 op_num,
+BOOL rpc_api_pipe_req(struct cli_state *cli, uint8 op_num,
prs_struct *data, prs_struct *rdata)
{
/* fudge this, at the moment: create the header; memcpy the data. oops. */
@@ -421,7 +421,7 @@ BOOL rpc_api_pipe_req(struct cli_state *cli, uint16 fnum, uint8 op_num,
hdr.data->offset.end = data_len;
mem_buf_copy(mem_data(&(hdr.data), 0x18), data->data, 0, data->offset);
- ret = rpc_api_pipe(cli, 0x0026, fnum, NULL, &hdr, &rparam, rdata);
+ ret = rpc_api_pipe(cli, 0x0026, NULL, &hdr, &rparam, rdata);
prs_mem_free(&rparam);
prs_mem_free(&hdr);
@@ -434,8 +434,7 @@ BOOL rpc_api_pipe_req(struct cli_state *cli, uint16 fnum, uint8 op_num,
do an rpc bind
****************************************************************************/
-BOOL rpc_pipe_set_hnd_state(struct cli_state *cli, char *pipe_name,
- uint16 fnum, uint16 device_state)
+BOOL rpc_pipe_set_hnd_state(struct cli_state *cli, char *pipe_name, uint16 device_state)
{
BOOL state_set = False;
char param[2];
@@ -448,14 +447,14 @@ BOOL rpc_pipe_set_hnd_state(struct cli_state *cli, char *pipe_name,
return False;
DEBUG(5,("Set Handle state Pipe[%x]: %s - device state:%x\n",
- fnum, pipe_name, device_state));
+ cli->nt_pipe_fnum, pipe_name, device_state));
/* create parameters: device state */
SSVAL(param, 0, device_state);
/* create setup parameters. */
setup[0] = 0x0001;
- setup[1] = fnum; /* pipe file handle. got this from an SMBcreateX. */
+ setup[1] = cli->nt_pipe_fnum; /* pipe file handle. got this from an SMBOpenX. */
/* send the data on \PIPE\ */
if (cli_api_pipe(cli, "\\PIPE\\\0\0\0", 8,
@@ -575,9 +574,8 @@ static BOOL check_bind_response(RPC_HDR_BA *hdr_ba, char *pipe_name, RPC_IFACE *
do an rpc bind
****************************************************************************/
-BOOL rpc_pipe_bind(struct cli_state *cli, char *pipe_name, uint16 fnum,
- RPC_IFACE *abstract, RPC_IFACE *transfer, BOOL ntlmssp_auth,
- char *my_name, char *domain)
+BOOL rpc_pipe_bind(struct cli_state *cli, char *pipe_name,
+ RPC_IFACE *abstract, RPC_IFACE *transfer, BOOL ntlmssp_auth)
{
prs_struct hdr;
prs_struct hdr_rb;
@@ -591,7 +589,7 @@ BOOL rpc_pipe_bind(struct cli_state *cli, char *pipe_name, uint16 fnum,
if (pipe_name == NULL || abstract == NULL || transfer == NULL)
return False;
- DEBUG(5,("Bind RPC Pipe[%x]: %s\n", fnum, pipe_name));
+ DEBUG(5,("Bind RPC Pipe[%x]: %s\n", cli->nt_pipe_fnum, pipe_name));
if (!valid_pipe_name(pipe_name, abstract, transfer))
return False;
@@ -604,14 +602,14 @@ BOOL rpc_pipe_bind(struct cli_state *cli, char *pipe_name, uint16 fnum,
prs_init(&rparam, 0 , 4, SAFETY_MARGIN, True );
create_rpc_bind_req(&hdr, &hdr_rb, ntlmssp_auth ? &auth_req : NULL,
- abstract, transfer, my_name, domain);
+ abstract, transfer, myname, myworkgroup);
/* this is a hack due to limitations in rpc_api_pipe */
prs_init(&data, mem_buf_len(hdr.data), 4, 0x0, False);
mem_buf_copy(data.data->data, hdr.data, 0, mem_buf_len(hdr.data));
/* send data on \PIPE\. receive a response */
- if (rpc_api_pipe(cli, 0x0026, fnum, NULL, &data, &rparam, &rdata))
+ if (rpc_api_pipe(cli, 0x0026, NULL, &data, &rparam, &rdata))
{
RPC_HDR_BA hdr_ba;
@@ -637,67 +635,44 @@ BOOL rpc_pipe_bind(struct cli_state *cli, char *pipe_name, uint16 fnum,
open a session
****************************************************************************/
-BOOL do_session_open(struct cli_state *cli, char *pipe_name, uint16 *fnum)
+BOOL cli_nt_session_open(struct cli_state *cli, char *pipe_name, BOOL encrypted)
{
RPC_IFACE abstract;
RPC_IFACE transfer;
+ int fnum;
/******************* open the pipe *****************/
- if (((*fnum) = cli_open(cli, pipe_name, O_CREAT|O_WRONLY, DENY_NONE)) == 0xffff)
+ if ((fnum = cli_open(cli, pipe_name, O_CREAT|O_RDWR, DENY_NONE)) == -1)
{
- DEBUG(1,("do_session_open: cli_open failed\n"));
+ DEBUG(1,("do_session_open: cli_open failed on pipe %s to machine %s. \
+Error was %s.\n", pipe_name, cli->desthost, cli_errstr(&cli)));
return False;
}
+ cli->nt_pipe_fnum = (uint16)fnum;
+
/**************** Set Named Pipe State ***************/
- if (!rpc_pipe_set_hnd_state(cli, pipe_name, (*fnum), 0x4300))
+ if (!rpc_pipe_set_hnd_state(cli, pipe_name, 0x4300))
{
- DEBUG(1,("do_session_open: pipe hnd state failed\n"));
+ DEBUG(1,("do_session_open: pipe hnd state failed.\n"));
return False;
}
/******************* bind request on pipe *****************/
- if (!rpc_pipe_bind(cli, pipe_name, (*fnum), &abstract, &transfer,
- False, NULL, NULL))
+ if (!rpc_pipe_bind(cli, pipe_name, &abstract, &transfer, encrypted))
{
- DEBUG(1,("do_session_open: rpc bind failed\n"));
+ DEBUG(1,("do_session_open: rpc bind failed.\n"));
return False;
}
- return True;
-}
-
-/****************************************************************************
- open an encrypted session
- ****************************************************************************/
-
-BOOL do_ntlm_session_open(struct cli_state *cli, char *pipe_name, uint16 *fnum,
- char *my_name, char *domain)
-{
- RPC_IFACE abstract;
- RPC_IFACE transfer;
-
- /******************* open the pipe *****************/
- if (((*fnum) = cli_open(cli, pipe_name, O_CREAT|O_WRONLY, DENY_NONE)) == 0xffff)
- {
- DEBUG(1,("do_ntlm_session_open: cli_open failed\n"));
- return False;
- }
+ /*
+ * Setup the remote server name prefixed by \ and the machine account name.
+ */
- /**************** Set Named Pipe State ***************/
- if (!rpc_pipe_set_hnd_state(cli, pipe_name, (*fnum), 0x4300))
- {
- DEBUG(1,("do_ntlm_session_open: pipe hnd state failed\n"));
- return False;
- }
+ sprintf(cli->srv_name, "\\\\%s", cli->desthost);
+ strupper(cli->srv_name);
- /******************* bind request on pipe *****************/
- if (!rpc_pipe_bind(cli, pipe_name, (*fnum), &abstract, &transfer,
- True, my_name, domain))
- {
- DEBUG(1,("do_ntlm_session_open: rpc bind failed\n"));
- return False;
- }
+ sprintf(cli->mach_acct, "%s$", myname);
return True;
}
@@ -706,10 +681,7 @@ BOOL do_ntlm_session_open(struct cli_state *cli, char *pipe_name, uint16 *fnum,
close the session
****************************************************************************/
-void do_session_close(struct cli_state *cli, uint16 fnum)
+void nt_session_close(struct cli_state *cli)
{
- if (fnum != 0xffff)
- {
- cli_close(cli, fnum);
- }
+ cli_close(cli, cli->nt_pipe_fnum);
}