diff options
Diffstat (limited to 'source3/rpc_client')
-rw-r--r-- | source3/rpc_client/cli_login.c | 173 | ||||
-rw-r--r-- | source3/rpc_client/cli_netlogon.c | 470 | ||||
-rw-r--r-- | source3/rpc_client/cli_pipe.c | 3 | ||||
-rw-r--r-- | source3/rpc_client/cli_reg.c | 3 | ||||
-rw-r--r-- | source3/rpc_client/cli_samr.c | 3 | ||||
-rw-r--r-- | source3/rpc_client/cli_spoolss.c | 3 | ||||
-rw-r--r-- | source3/rpc_client/cli_spoolss_notify.c | 447 | ||||
-rw-r--r-- | source3/rpc_client/cli_srvsvc.c | 30 | ||||
-rw-r--r-- | source3/rpc_client/cli_wkssvc.c | 3 | ||||
-rw-r--r-- | source3/rpc_client/msrpc_spoolss.c | 3 | ||||
-rw-r--r-- | source3/rpc_client/ntclienttrust.c | 157 |
11 files changed, 1260 insertions, 35 deletions
diff --git a/source3/rpc_client/cli_login.c b/source3/rpc_client/cli_login.c new file mode 100644 index 0000000000..7b5bf90c5d --- /dev/null +++ b/source3/rpc_client/cli_login.c @@ -0,0 +1,173 @@ +/* + Unix SMB/CIFS implementation. + NT Domain Authentication SMB / MSRPC client + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1996-1997 + Copyright (C) Jeremy Allison 1999. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +extern fstring global_myworkgroup; +extern pstring global_myname; + +/**************************************************************************** +Initialize domain session credentials. +****************************************************************************/ + +NTSTATUS cli_nt_setup_creds(struct cli_state *cli, unsigned char mach_pwd[16]) +{ + NTSTATUS result; + DOM_CHAL clnt_chal; + DOM_CHAL srv_chal; + + UTIME zerotime; + + /******************* Request Challenge ********************/ + + generate_random_buffer( clnt_chal.data, 8, False); + + /* send a client challenge; receive a server challenge */ + if (!cli_net_req_chal(cli, &clnt_chal, &srv_chal)) + { + DEBUG(0,("cli_nt_setup_creds: request challenge failed\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + /**************** Long-term Session key **************/ + + /* calculate the session key */ + cred_session_key(&clnt_chal, &srv_chal, (char *)mach_pwd, cli->sess_key); + memset((char *)cli->sess_key+8, '\0', 8); + + /******************* Authenticate 2 ********************/ + + /* calculate auth-2 credentials */ + zerotime.time = 0; + cred_create(cli->sess_key, &clnt_chal, zerotime, &(cli->clnt_cred.challenge)); + + /* + * Send client auth-2 challenge. + * Receive an auth-2 challenge response and check it. + */ + + result = cli_net_auth2(cli, (lp_server_role() == ROLE_DOMAIN_MEMBER) ? + SEC_CHAN_WKSTA : SEC_CHAN_BDC, 0x000001ff, &srv_chal); + + if (!NT_STATUS_IS_OK(result)) + { + DEBUG(0,("cli_nt_setup_creds: auth2 challenge failed\n")); + return result; + } + + return NT_STATUS_OK; +} + +/**************************************************************************** +NT login - interactive. +*NEVER* use this code. This method of doing a logon (sending the cleartext +password equivalents, protected by the session key) is inherently insecure +given the current design of the NT Domain system. JRA. + ****************************************************************************/ +NTSTATUS cli_nt_login_interactive(struct cli_state *cli, char *domain, char *username, + uint32 smb_userid_low, char *password, + NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3) +{ + uchar lm_owf_user_pwd[16]; + uchar nt_owf_user_pwd[16]; + NTSTATUS ret; + + DEBUG(5,("cli_nt_login_interactive: %d\n", __LINE__)); + + nt_lm_owf_gen(password, nt_owf_user_pwd, lm_owf_user_pwd); + +#ifdef DEBUG_PASSWORD + + DEBUG(100,("nt owf of user password: ")); + dump_data(100, (char *)lm_owf_user_pwd, 16); + + DEBUG(100,("nt owf of user password: ")); + dump_data(100, (char *)nt_owf_user_pwd, 16); + +#endif + + DEBUG(5,("cli_nt_login_interactive: %d\n", __LINE__)); + + /* indicate an "interactive" login */ + ctr->switch_value = INTERACTIVE_LOGON_TYPE; + + /* Create the structure needed for SAM logon. */ + init_id_info1(&ctr->auth.id1, domain, 0, + smb_userid_low, 0, + username, cli->clnt_name_slash, + (char *)cli->sess_key, lm_owf_user_pwd, nt_owf_user_pwd); + + /* Ensure we overwrite all the plaintext password + equivalents. */ + memset(lm_owf_user_pwd, '\0', sizeof(lm_owf_user_pwd)); + memset(nt_owf_user_pwd, '\0', sizeof(nt_owf_user_pwd)); + + /* Send client sam-logon request - update credentials on success. */ + ret = cli_net_sam_logon(cli, ctr, user_info3); + + memset(ctr->auth.id1.lm_owf.data, '\0', sizeof(lm_owf_user_pwd)); + memset(ctr->auth.id1.nt_owf.data, '\0', sizeof(nt_owf_user_pwd)); + + return ret; +} + +/**************************************************************************** +NT login - network. +*ALWAYS* use this call to validate a user as it does not expose plaintext +password equivalents over the network. JRA. +****************************************************************************/ + +NTSTATUS cli_nt_login_network(struct cli_state *cli, + const auth_usersupplied_info *user_info, + uchar chal[8], + uint32 smb_userid_low, NET_ID_INFO_CTR *ctr, + NET_USER_INFO_3 *user_info3) +{ + DEBUG(5,("cli_nt_login_network: %d\n", __LINE__)); + /* indicate a "network" login */ + ctr->switch_value = NET_LOGON_TYPE; + + /* Create the structure needed for SAM logon. */ + init_id_info2(&ctr->auth.id2, user_info->domain.str, 0, smb_userid_low, 0, + user_info->smb_name.str, + /* Send our cleint's workstaion name if we have it, otherwise ours */ + ((user_info->wksta_name.len > 0) ? + user_info->wksta_name.str : + cli->clnt_name_slash), + chal, + user_info->lm_resp.data, user_info->lm_resp.length, + user_info->nt_resp.data, user_info->nt_resp.length); + + /* Send client sam-logon request - update credentials on success. */ + return cli_net_sam_logon(cli, ctr, user_info3); +} + +/**************************************************************************** +NT Logoff. +****************************************************************************/ +BOOL cli_nt_logoff(struct cli_state *cli, NET_ID_INFO_CTR *ctr) +{ + DEBUG(5,("cli_nt_logoff: %d\n", __LINE__)); + + /* Send client sam-logoff request - update credentials on success. */ + return cli_net_sam_logoff(cli, ctr); +} diff --git a/source3/rpc_client/cli_netlogon.c b/source3/rpc_client/cli_netlogon.c new file mode 100644 index 0000000000..90c8a34c21 --- /dev/null +++ b/source3/rpc_client/cli_netlogon.c @@ -0,0 +1,470 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Andrew Tridgell 1992-1997, + * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, + * Copyright (C) Paul Ashton 1997. + * Copyright (C) Jeremy Allison 1998. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#include "includes.h" + +extern pstring global_myname; +extern fstring global_myworkgroup; + +/**************************************************************************** +Generate the next creds to use. +****************************************************************************/ + +static void gen_next_creds( struct cli_state *cli, DOM_CRED *new_clnt_cred) +{ + /* + * Create the new client credentials. + */ + + cli->clnt_cred.timestamp.time = time(NULL); + + memcpy(new_clnt_cred, &cli->clnt_cred, sizeof(*new_clnt_cred)); + + /* Calculate the new credentials. */ + cred_create(cli->sess_key, &(cli->clnt_cred.challenge), + new_clnt_cred->timestamp, &(new_clnt_cred->challenge)); + +} + +#if UNUSED_CODE +/**************************************************************************** +do a LSA Logon Control2 +****************************************************************************/ +BOOL cli_net_logon_ctrl2(struct cli_state *cli, NTSTATUS status_level) +{ + prs_struct rbuf; + prs_struct buf; + NET_Q_LOGON_CTRL2 q_l; + BOOL ok = False; + + prs_init(&buf , 1024, cli->mem_ctx, MARSHALL); + prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + + /* create and send a MSRPC command with api NET_LOGON_CTRL2 */ + + DEBUG(4,("do_net_logon_ctrl2 from %s status level:%x\n", + global_myname, status_level)); + + /* store the parameters */ + init_q_logon_ctrl2(&q_l, cli->srv_name_slash, + status_level); + + /* turn parameters into data stream */ + if(!net_io_q_logon_ctrl2("", &q_l, &buf, 0)) { + DEBUG(0,("cli_net_logon_ctrl2: Error : failed to marshall NET_Q_LOGON_CTRL2 struct.\n")); + prs_mem_free(&buf); + prs_mem_free(&rbuf); + return False; + } + + /* send the data on \PIPE\ */ + if (rpc_api_pipe_req(cli, NET_LOGON_CTRL2, &buf, &rbuf)) + { + NET_R_LOGON_CTRL2 r_l; + + /* + * Unmarshall the return buffer. + */ + ok = net_io_r_logon_ctrl2("", &r_l, &rbuf, 0); + + if (ok && r_l.status != 0) + { + /* report error code */ + DEBUG(0,("do_net_logon_ctrl2: Error %s\n", nt_errstr(r_l.status))); + cli->nt_error = r_l.status; + ok = False; + } + } + + prs_mem_free(&buf); + prs_mem_free(&rbuf); + + return ok; +} +#endif + +/**************************************************************************** +LSA Authenticate 2 + +Send the client credential, receive back a server credential. +Ensure that the server credential returned matches the session key +encrypt of the server challenge originally received. JRA. +****************************************************************************/ + +NTSTATUS cli_net_auth2(struct cli_state *cli, uint16 sec_chan, + uint32 neg_flags, DOM_CHAL *srv_chal) +{ + prs_struct rbuf; + prs_struct buf; + NET_Q_AUTH_2 q_a; + BOOL ok = False; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + + prs_init(&buf , 1024, cli->mem_ctx, MARSHALL); + prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + + /* create and send a MSRPC command with api NET_AUTH2 */ + + DEBUG(4,("cli_net_auth2: srv:%s acct:%s sc:%x mc: %s chal %s neg: %x\n", + cli->srv_name_slash, cli->mach_acct, sec_chan, global_myname, + credstr(cli->clnt_cred.challenge.data), neg_flags)); + + /* store the parameters */ + init_q_auth_2(&q_a, cli->srv_name_slash, cli->mach_acct, + sec_chan, global_myname, &cli->clnt_cred.challenge, neg_flags); + + /* turn parameters into data stream */ + if(!net_io_q_auth_2("", &q_a, &buf, 0)) { + DEBUG(0,("cli_net_auth2: Error : failed to marshall NET_Q_AUTH_2 struct.\n")); + prs_mem_free(&buf); + prs_mem_free(&rbuf); + return result; + } + + /* send the data on \PIPE\ */ + if (rpc_api_pipe_req(cli, NET_AUTH2, &buf, &rbuf)) + { + NET_R_AUTH_2 r_a; + + ok = net_io_r_auth_2("", &r_a, &rbuf, 0); + result = r_a.status; + + if (ok && !NT_STATUS_IS_OK(result)) + { + /* report error code */ + DEBUG(0,("cli_net_auth2: Error %s\n", nt_errstr(result))); + ok = False; + } + + if (ok) + { + /* + * Check the returned value using the initial + * server received challenge. + */ + UTIME zerotime; + + zerotime.time = 0; + if(cred_assert( &r_a.srv_chal, cli->sess_key, srv_chal, zerotime) == 0) { + /* + * Server replied with bad credential. Fail. + */ + DEBUG(0,("cli_net_auth2: server %s replied with bad credential (bad machine \ +password ?).\n", cli->desthost )); + ok = False; + } + } + +#if 0 + /* + * Try commenting this out to see if this makes the connect + * work for a NT 3.51 PDC. JRA. + */ + + if (ok && r_a.srv_flgs.neg_flags != q_a.clnt_flgs.neg_flags) + { + /* report different neg_flags */ + DEBUG(0,("cli_net_auth2: error neg_flags (q,r) differ - (%x,%x)\n", + q_a.clnt_flgs.neg_flags, r_a.srv_flgs.neg_flags)); + ok = False; + } +#endif + + } + + prs_mem_free(&buf); + prs_mem_free(&rbuf); + + return result; +} + +/**************************************************************************** +LSA Request Challenge. Sends our challenge to server, then gets +server response. These are used to generate the credentials. +****************************************************************************/ + +BOOL cli_net_req_chal(struct cli_state *cli, DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal) +{ + prs_struct rbuf; + prs_struct buf; + NET_Q_REQ_CHAL q_c; + BOOL valid_chal = False; + + prs_init(&buf , 1024, cli->mem_ctx, MARSHALL); + prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + + /* create and send a MSRPC command with api NET_REQCHAL */ + + 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 */ + init_q_req_chal(&q_c, cli->srv_name_slash, + global_myname, clnt_chal); + + /* turn parameters into data stream */ + if(!net_io_q_req_chal("", &q_c, &buf, 0)) { + DEBUG(0,("cli_net_req_chal: Error : failed to marshall NET_Q_REQ_CHAL struct.\n")); + prs_mem_free(&buf); + prs_mem_free(&rbuf); + return False; + } + + /* send the data on \PIPE\ */ + if (rpc_api_pipe_req(cli, NET_REQCHAL, &buf, &rbuf)) + { + NET_R_REQ_CHAL r_c; + BOOL ok; + + ok = net_io_r_req_chal("", &r_c, &rbuf, 0); + + if (ok && !NT_STATUS_IS_OK(r_c.status)) + { + /* report error code */ + DEBUG(0,("cli_net_req_chal: Error %s\n", nt_errstr(r_c.status))); + ok = False; + } + + if (ok) + { + /* ok, at last: we're happy. return the challenge */ + memcpy(srv_chal, r_c.srv_chal.data, sizeof(srv_chal->data)); + valid_chal = True; + } + } + + prs_mem_free(&buf); + prs_mem_free(&rbuf); + + return valid_chal; +} +/*************************************************************************** + LSA SAM Logon internal - interactive or network. Does level 2 or 3 but always + returns level 3. +****************************************************************************/ + +static NTSTATUS cli_net_sam_logon_internal(struct cli_state *cli, NET_ID_INFO_CTR *ctr, + NET_USER_INFO_3 *user_info3, + uint16 validation_level) +{ + DOM_CRED new_clnt_cred; + DOM_CRED dummy_rtn_creds; + prs_struct rbuf; + prs_struct buf; + NET_Q_SAM_LOGON q_s; + NET_R_SAM_LOGON r_s; + NTSTATUS retval = NT_STATUS_OK; + + gen_next_creds( cli, &new_clnt_cred); + + prs_init(&buf , 1024, cli->mem_ctx, MARSHALL); + prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + + /* create and send a MSRPC command with api NET_SAMLOGON */ + + DEBUG(4,("cli_net_sam_logon_internal: srv:%s mc:%s clnt %s %x ll: %d\n", + cli->srv_name_slash, global_myname, + credstr(new_clnt_cred.challenge.data), cli->clnt_cred.timestamp.time, + ctr->switch_value)); + + memset(&dummy_rtn_creds, '\0', sizeof(dummy_rtn_creds)); + dummy_rtn_creds.timestamp.time = time(NULL); + + /* store the parameters */ + q_s.validation_level = validation_level; + init_sam_info(&q_s.sam_id, cli->srv_name_slash, + global_myname, &new_clnt_cred, &dummy_rtn_creds, + ctr->switch_value, ctr); + + /* turn parameters into data stream */ + if(!net_io_q_sam_logon("", &q_s, &buf, 0)) { + DEBUG(0,("cli_net_sam_logon_internal: Error : failed to marshall NET_Q_SAM_LOGON struct.\n")); + retval = NT_STATUS_NO_MEMORY; + goto out; + } + + /* send the data on \PIPE\ */ + if (!rpc_api_pipe_req(cli, NET_SAMLOGON, &buf, &rbuf)) { + DEBUG(0,("cli_net_sam_logon_internal: Error rpc_api_pipe_req failed.\n")); + retval = NT_STATUS_UNSUCCESSFUL; + goto out; + } + + r_s.user = user_info3; + + if(!net_io_r_sam_logon("", &r_s, &rbuf, 0)) { + DEBUG(0,("cli_net_sam_logon_internal: Error : failed to unmarshal NET_R_SAM_LOGON struct.\n")); + retval = NT_STATUS_NO_MEMORY; + goto out; + } + + retval = r_s.status; + + /* + * Don't treat NT_STATUS_INVALID_INFO_CLASS as an error - we will re-issue + * the call. + */ + + if (NT_STATUS_V(retval) == NT_STATUS_V(NT_STATUS_INVALID_INFO_CLASS)) { + goto out; + } + + if (!NT_STATUS_IS_OK(retval)) { + /* report error code */ + DEBUG(0,("cli_net_sam_logon_internal: %s\n", nt_errstr(r_s.status))); + goto out; + } + + /* Update the credentials. */ + if (!clnt_deal_with_creds(cli->sess_key, &cli->clnt_cred, &r_s.srv_creds)) { + /* + * Server replied with bad credential. Fail. + */ + DEBUG(0,("cli_net_sam_logon_internal: server %s replied with bad credential (bad machine \ +password ?).\n", cli->desthost )); + retval = NT_STATUS_WRONG_PASSWORD; + } + + if (r_s.switch_value != validation_level) { + /* report different switch_value */ + DEBUG(0,("cli_net_sam_logon: switch_value of %x expected %x\n", (unsigned int)validation_level, + (unsigned int)r_s.switch_value)); + retval = NT_STATUS_INVALID_PARAMETER; + } + +out: + + prs_mem_free(&buf); + prs_mem_free(&rbuf); + + return retval; +} + +/*************************************************************************** +LSA SAM Logon - interactive or network. +****************************************************************************/ + +NTSTATUS cli_net_sam_logon(struct cli_state *cli, NET_ID_INFO_CTR *ctr, + NET_USER_INFO_3 *user_info3) +{ + uint16 validation_level=3; + NTSTATUS result; + + result = cli_net_sam_logon_internal(cli, ctr, user_info3, + validation_level); + + if (NT_STATUS_IS_OK(result)) { + DEBUG(10,("cli_net_sam_logon: Success \n")); + } else if (NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_INVALID_INFO_CLASS)) { + DEBUG(10,("cli_net_sam_logon: STATUS INVALID INFO CLASS \n")); + + validation_level=2; + + /* + * Since this is the second time we call this function, don't care + * for the error. If its error, return False. + */ + + result = cli_net_sam_logon_internal(cli, ctr, user_info3, + validation_level); + } + + return result; +} + +/*************************************************************************** +LSA SAM Logoff. + +This currently doesnt work correctly as the domain controller +returns NT_STATUS_INVALID_INFO_CLASS - we obviously need to +send a different info level. Right now though, I'm not sure +what that needs to be (I need to see one on the wire before +I can be sure). JRA. +****************************************************************************/ +BOOL cli_net_sam_logoff(struct cli_state *cli, NET_ID_INFO_CTR *ctr) +{ + DOM_CRED new_clnt_cred; + DOM_CRED dummy_rtn_creds; + prs_struct rbuf; + prs_struct buf; + NET_Q_SAM_LOGOFF q_s; + BOOL ok = False; + + gen_next_creds( cli, &new_clnt_cred); + + prs_init(&buf , 1024, cli->mem_ctx, MARSHALL); + prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + + /* create and send a MSRPC command with api NET_SAMLOGOFF */ + + DEBUG(4,("cli_net_sam_logoff: srv:%s mc:%s clnt %s %x ll: %d\n", + cli->srv_name_slash, global_myname, + credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time, + ctr->switch_value)); + + memset(&dummy_rtn_creds, '\0', sizeof(dummy_rtn_creds)); + + init_sam_info(&q_s.sam_id, cli->srv_name_slash, + global_myname, &new_clnt_cred, &dummy_rtn_creds, + ctr->switch_value, ctr); + + /* turn parameters into data stream */ + if(!net_io_q_sam_logoff("", &q_s, &buf, 0)) { + DEBUG(0,("cli_net_sam_logoff: Error : failed to marshall NET_Q_SAM_LOGOFF struct.\n")); + prs_mem_free(&buf); + prs_mem_free(&rbuf); + return False; + } + + /* send the data on \PIPE\ */ + if (rpc_api_pipe_req(cli, NET_SAMLOGOFF, &buf, &rbuf)) + { + NET_R_SAM_LOGOFF r_s; + + ok = net_io_r_sam_logoff("", &r_s, &rbuf, 0); + + if (ok && !NT_STATUS_IS_OK(r_s.status)) + { + /* report error code */ + DEBUG(0,("cli_net_sam_logoff: %s\n", nt_errstr(r_s.status))); + ok = False; + } + + /* Update the credentials. */ + if (ok && !clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), &(r_s.srv_creds))) + { + /* + * Server replied with bad credential. Fail. + */ + DEBUG(0,("cli_net_sam_logoff: server %s replied with bad credential (bad machine \ +password ?).\n", cli->desthost )); + ok = False; + } + } + + prs_mem_free(&buf); + prs_mem_free(&rbuf); + + return ok; +} diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c index eae6be5128..a7049f78df 100644 --- a/source3/rpc_client/cli_pipe.c +++ b/source3/rpc_client/cli_pipe.c @@ -23,9 +23,6 @@ #include "includes.h" -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_RPC_CLI - extern struct pipe_id_info pipe_names[]; extern fstring global_myworkgroup; extern pstring global_myname; diff --git a/source3/rpc_client/cli_reg.c b/source3/rpc_client/cli_reg.c index 07001f13bd..628cd576a8 100644 --- a/source3/rpc_client/cli_reg.c +++ b/source3/rpc_client/cli_reg.c @@ -24,9 +24,6 @@ #include "includes.h" -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_RPC_CLI - /**************************************************************************** do a REG Open Policy ****************************************************************************/ diff --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c index 0d4db7f88f..6467ae4fa9 100644 --- a/source3/rpc_client/cli_samr.c +++ b/source3/rpc_client/cli_samr.c @@ -22,9 +22,6 @@ #include "includes.h" -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_RPC_CLI - /**************************************************************************** do a SAMR query user groups ****************************************************************************/ diff --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c index 5292569ed4..ca01808f59 100644 --- a/source3/rpc_client/cli_spoolss.c +++ b/source3/rpc_client/cli_spoolss.c @@ -25,9 +25,6 @@ #include "rpc_parse.h" #include "nterr.h" -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_RPC_CLI - /**************************************************************************** do a SPOOLSS Enum Printer Drivers ****************************************************************************/ diff --git a/source3/rpc_client/cli_spoolss_notify.c b/source3/rpc_client/cli_spoolss_notify.c new file mode 100644 index 0000000000..320708736e --- /dev/null +++ b/source3/rpc_client/cli_spoolss_notify.c @@ -0,0 +1,447 @@ +/* + * Unix SMB/CIFS implementation. + * RPC Pipe client / server routines + * Copyright (C) Andrew Tridgell 1992-2000, + * Copyright (C) Jean Francois Micouleau 1998-2000, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" +#if 0 +#include "rpc_parse.h" +#include "nterr.h" +#endif +extern pstring global_myname; + +struct msg_info_table { + uint32 msg; + uint32 field; + char* name; + void (*construct_fn) (int snum, SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx); +}; + +struct msg_info_table msg_table[] = { +{ PRINTER_MESSAGE_DRIVER, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_MESSAGE_DRIVER", spoolss_notify_driver_name }, +{ PRINTER_MESSAGE_ATTRIBUTES, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_MESSAGE_ATTRIBUTES", spoolss_notify_attributes }, +{ PRINTER_MESSAGE_COMMENT, PRINTER_NOTIFY_COMMENT, "PRINTER_MESSAGE_COMMENT", spoolss_notify_comment }, +{ PRINTER_MESSAGE_LOCATION, PRINTER_NOTIFY_LOCATION, "PRINTER_MESSAGE_LOCATION", spoolss_notify_location }, +{ PRINTER_MESSAGE_PRINTERNAME, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_MESSAGE_PRINTERNAME", spoolss_notify_printer_name }, +{ PRINTER_MESSAGE_SHARENAME, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_MESSAGE_SHARENAME", spoolss_notify_share_name }, +{ PRINTER_MESSAGE_PORT, PRINTER_NOTIFY_PORT_NAME, "PRINTER_MESSAGE_PORT", spoolss_notify_port_name }, +{ PRINTER_MESSAGE_CJOBS, PRINTER_NOTIFY_CJOBS, "PRINTER_MESSAGE_CJOBS", spoolss_notify_cjobs }, +{ PRINTER_MESSAGE_SEPFILE, PRINTER_NOTIFY_SEPFILE, "PRINTER_MESSAGE_SEPFILE", spoolss_notify_sepfile }, +{ PRINTER_MESSAGE_PARAMS, PRINTER_NOTIFY_PARAMETERS, "PRINTER_MESSAGE_PARAMETERS", spoolss_notify_parameters }, +{ PRINTER_MESSAGE_DATATYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_MESSAGE_DATATYPE", spoolss_notify_datatype }, +{ PRINTER_MESSAGE_NULL, 0x0, "", NULL }, +}; + +/********************************************************* + Disconnect from the client machine. +**********************************************************/ +BOOL spoolss_disconnect_from_client( struct cli_state *cli) +{ + cli_nt_session_close(cli); + cli_ulogoff(cli); + cli_shutdown(cli); + + return True; +} + + +/********************************************************* + Connect to the client machine. +**********************************************************/ + +BOOL spoolss_connect_to_client( struct cli_state *cli, char *remote_machine) +{ + ZERO_STRUCTP(cli); + if(cli_initialise(cli) == NULL) { + DEBUG(0,("connect_to_client: unable to initialize client connection.\n")); + return False; + } + + if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) { + DEBUG(0,("connect_to_client: Can't resolve address for %s\n", remote_machine)); + cli_shutdown(cli); + return False; + } + + if (ismyip(cli->dest_ip)) { + DEBUG(0,("connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine)); + cli_shutdown(cli); + return False; + } + + if (!cli_connect(cli, remote_machine, &cli->dest_ip)) { + DEBUG(0,("connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) )); + cli_shutdown(cli); + return False; + } + + if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) { + DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request.\n", + remote_machine)); + return False; + } + + cli->protocol = PROTOCOL_NT1; + + if (!cli_negprot(cli)) { + DEBUG(0,("connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(cli) )); + cli_shutdown(cli); + return False; + } + + if (cli->protocol != PROTOCOL_NT1) { + DEBUG(0,("connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine)); + cli_shutdown(cli); + return False; + } + + /* + * Do an anonymous session setup. + */ + + if (!cli_session_setup(cli, "", "", 0, "", 0, "")) { + DEBUG(0,("connect_to_client: machine %s rejected the session setup. Error was : %s.\n", remote_machine, cli_errstr(cli) )); + cli_shutdown(cli); + return False; + } + + if (!(cli->sec_mode & 1)) { + DEBUG(0,("connect_to_client: machine %s isn't in user level security mode\n", remote_machine)); + cli_shutdown(cli); + return False; + } + + if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) { + DEBUG(0,("connect_to_client: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", remote_machine, cli_errstr(cli) )); + cli_shutdown(cli); + return False; + } + + /* + * Ok - we have an anonymous connection to the IPC$ share. + * Now start the NT Domain stuff :-). + */ + + if(cli_nt_session_open(cli, PIPE_SPOOLSS) == False) { + DEBUG(0,("connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli))); + cli_nt_session_close(cli); + cli_ulogoff(cli); + cli_shutdown(cli); + return False; + } + + return True; +} + +/* + * SPOOLSS Client RPC's used by servers as the notification + * back channel + */ + +/*************************************************************************** + do a reply open printer +****************************************************************************/ + +WERROR cli_spoolss_reply_open_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx, + char *printer, uint32 localprinter, uint32 type, + POLICY_HND *handle) +{ + WERROR result = W_ERROR(ERRgeneral); + + prs_struct rbuf; + prs_struct buf; + + SPOOL_Q_REPLYOPENPRINTER q_s; + SPOOL_R_REPLYOPENPRINTER r_s; + + prs_init(&buf, 1024, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL ); + + /* create and send a MSRPC command with api SPOOLSS_REPLYOPENPRINTER */ + + /* store the parameters */ + make_spoolss_q_replyopenprinter(&q_s, printer, localprinter, type); + + /* turn parameters into data stream */ + if(!spoolss_io_q_replyopenprinter("", &q_s, &buf, 0)) { + DEBUG(0,("cli_spoolss_reply_open_printer: Error : failed to marshall SPOOL_Q_REPLYOPENPRINTER struct.\n")); + goto done; + } + + /* send the data on \PIPE\ */ + if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYOPENPRINTER, &buf, &rbuf)) + goto done; + + /* turn data stream into parameters*/ + if(!spoolss_io_r_replyopenprinter("", &r_s, &rbuf, 0)) { + DEBUG(0,("cli_spoolss_reply_open_printer: Error : failed to unmarshall SPOOL_R_REPLYOPENPRINTER struct.\n")); + goto done; + } + + memcpy(handle, &r_s.handle, sizeof(r_s.handle)); + result = r_s.status; + +done: + prs_mem_free(&buf); + prs_mem_free(&rbuf); + + return result; +} + +/*************************************************************************** + do a reply open printer +****************************************************************************/ + +WERROR cli_spoolss_reply_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *handle) +{ + WERROR result = W_ERROR(ERRgeneral); + prs_struct rbuf; + prs_struct buf; + + SPOOL_Q_REPLYCLOSEPRINTER q_s; + SPOOL_R_REPLYCLOSEPRINTER r_s; + + prs_init(&buf, 1024, cli->mem_ctx, MARSHALL); + prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL ); + + /* create and send a MSRPC command with api */ + + /* store the parameters */ + make_spoolss_q_reply_closeprinter(&q_s, handle); + + /* turn parameters into data stream */ + if(!spoolss_io_q_replycloseprinter("", &q_s, &buf, 0)) { + DEBUG(0,("cli_spoolss_reply_close_printer: Error : failed to marshall SPOOL_Q_REPLY_CLOSEPRINTER struct.\n")); + goto done; + } + + /* send the data on \PIPE\ */ + if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYCLOSEPRINTER, &buf, &rbuf)) + goto done; + + /* turn data stream into parameters*/ + if(!spoolss_io_r_replycloseprinter("", &r_s, &rbuf, 0)) { + DEBUG(0,("cli_spoolss_reply_close_printer: Error : failed to marshall SPOOL_R_REPLY_CLOSEPRINTER struct.\n")); + goto done; + } + + + result = r_s.status; + +done: + prs_mem_free(&buf); + prs_mem_free(&rbuf); + + return result; +} + + +/********************************************************************* + This SPOOLSS_ROUTERREPLYPRINTER function is used to send a change + notification event when the registration **did not** use + SPOOL_NOTIFY_OPTION_TYPE structure to specify the events to monitor. + Also see cli_spolss_reply_rrpcn() + *********************************************************************/ + +WERROR cli_spoolss_routerreplyprinter (struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol, uint32 condition, uint32 changd_id) +{ + prs_struct qbuf, rbuf; + SPOOL_Q_ROUTERREPLYPRINTER q; + SPOOL_R_ROUTERREPLYPRINTER r; + WERROR result = W_ERROR(ERRgeneral); + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + + /* Initialise input parameters */ + + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + + + /* write the request */ + make_spoolss_q_routerreplyprinter(&q, pol, condition, changd_id); + + /* Marshall data and send request */ + if (!spoolss_io_q_routerreplyprinter ("", &q, &qbuf, 0)) { + DEBUG(0,("cli_spoolss_routerreplyprinter: Unable to marshall SPOOL_Q_ROUTERREPLYPRINTER!\n")); + goto done; + } + + + if (!rpc_api_pipe_req (cli, SPOOLSS_ROUTERREPLYPRINTER, &qbuf, &rbuf)) + goto done; + + /* Unmarshall response */ + if (!spoolss_io_r_routerreplyprinter ("", &r, &rbuf, 0)) { + DEBUG(0,("cli_spoolss_routerreplyprinter: Unable to unmarshall SPOOL_R_ROUTERREPLYPRINTER!\n")); + goto done; + } + + /* Return output parameters */ + result = r.status; + +done: + prs_mem_free(&qbuf); + prs_mem_free(&rbuf); + + return result; +} + + +/********************************************************************************** + Build the SPOOL_NOTIFY_INFO_DATA entries based upon the flags which have been set + *********************************************************************************/ + +static int build_notify_data (TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printer, uint32 flags, + SPOOL_NOTIFY_INFO_DATA **notify_data) +{ + SPOOL_NOTIFY_INFO_DATA *data; + uint32 idx = 0; + int i = 0; + + while ((msg_table[i].msg != PRINTER_MESSAGE_NULL) && flags) + { + if (flags & msg_table[i].msg) + { + DEBUG(10,("build_notify_data: %s set on [%s][%d]\n", msg_table[i].name, + printer->info_2->printername, idx)); + if ((data=Realloc(*notify_data, (idx+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + DEBUG(0,("build_notify_data: Realloc() failed with size [%d]!\n", + (idx+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))); + return -1; + } + *notify_data = data; + + /* clear memory */ + memset(*notify_data+idx, 0x0, sizeof(SPOOL_NOTIFY_INFO_DATA)); + + /* + * 'id' (last param here) is undefined when type == PRINTER_NOTIFY_TYPE + * See PRINTER_NOTIFY_INFO_DATA entries in MSDN + * --jerry + */ + construct_info_data(*notify_data+idx, PRINTER_NOTIFY_TYPE, msg_table[i].field, 0x00); + + msg_table[i].construct_fn(-1, *notify_data+idx, NULL, printer, ctx); + idx++; + } + + i++; + } + + return idx; +} + +/********************************************************************* + This SPOOLSS_ROUTERREPLYPRINTER function is used to send a change + notification event when the registration **did** use + SPOOL_NOTIFY_OPTION_TYPE structure to specify the events to monitor + Also see cli_spoolss_routereplyprinter() + *********************************************************************/ + +WERROR cli_spoolss_reply_rrpcn(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *handle, PRINTER_MESSAGE_INFO *info, + NT_PRINTER_INFO_LEVEL *printer) +{ + prs_struct rbuf; + prs_struct buf; + + SPOOL_NOTIFY_INFO notify_info; + SPOOL_NOTIFY_INFO_DATA *notify_data = NULL; + uint32 data_len; + + WERROR result = W_ERROR(ERRgeneral); + + SPOOL_Q_REPLY_RRPCN q_s; + SPOOL_R_REPLY_RRPCN r_s; + + if (!info) { + DEBUG(5,("cli_spoolss_reply_rrpcn: NULL printer message info pointer!\n")); + goto done; + } + + prs_init(&buf, 1024, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL ); + + ZERO_STRUCT(notify_info); + +/* + * See comments in _spoolss_setprinter() about PRINTER_CHANGE_XXX + * events. --jerry +*/ + DEBUG(10,("cli_spoolss_reply_rrpcn: PRINTER_MESSAGE flags = 0x%8x\n", info->flags)); + + data_len = build_notify_data(mem_ctx, printer, info->flags, ¬ify_data); + if (info->flags && (data_len == -1)) { + DEBUG(0,("cli_spoolss_reply_rrpcn: Failed to build SPOOL_NOTIFY_INFO_DATA [flags == 0x%x] for printer [%s]\n", + info->flags, info->printer_name)); + result = WERR_NOMEM; + goto done; + } + notify_info.version = 0x2; + notify_info.flags = 0x00020000; /* ?? */ + notify_info.count = data_len; + notify_info.data = notify_data; + + /* create and send a MSRPC command with api */ + /* store the parameters */ + + make_spoolss_q_reply_rrpcn(&q_s, handle, info->low, info->high, ¬ify_info); + + /* turn parameters into data stream */ + if(!spoolss_io_q_reply_rrpcn("", &q_s, &buf, 0)) { + DEBUG(0,("cli_spoolss_reply_rrpcn: Error : failed to marshall SPOOL_Q_REPLY_RRPCN struct.\n")); + goto done; + } + + /* send the data on \PIPE\ */ + if (!rpc_api_pipe_req(cli, SPOOLSS_RRPCN, &buf, &rbuf)) + goto done; + + + /* turn data stream into parameters*/ + if(!spoolss_io_r_reply_rrpcn("", &r_s, &rbuf, 0)) { + DEBUG(0,("cli_spoolss_reply_rrpcn: Error : failed to unmarshall SPOOL_R_REPLY_RRPCN struct.\n")); + goto done; + } + + if (r_s.unknown0 == 0x00080000) { + DEBUG(8,("cli_spoolss_reply_rrpcn: I think the spooler resonded that the notification was ignored.\n")); + } + + result = r_s.status; + +done: + prs_mem_free(&buf); + prs_mem_free(&rbuf); + /* + * The memory allocated in this array is talloc'd so we only need + * free the array here. JRA. + */ + SAFE_FREE(notify_data); + + return result; +} + diff --git a/source3/rpc_client/cli_srvsvc.c b/source3/rpc_client/cli_srvsvc.c index 06e733893e..024e711789 100644 --- a/source3/rpc_client/cli_srvsvc.c +++ b/source3/rpc_client/cli_srvsvc.c @@ -23,9 +23,6 @@ #include "includes.h" -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_RPC_CLI - /**************************************************************************** do a server net conn enum ****************************************************************************/ @@ -46,7 +43,7 @@ BOOL do_srv_net_srv_conn_enum(struct cli_state *cli, prs_init(&data, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); prs_init(&rdata, 0, cli->mem_ctx, UNMARSHALL); - /* create and send a MSRPC command with api SRV_NET_CONN_ENUM */ + /* create and send a MSRPC command with api SRV_NETCONNENUM */ DEBUG(4,("SRV Net Server Connection Enum(%s, %s), level %d, enum:%8x\n", server_name, qual_name, switch_value, get_enum_hnd(hnd))); @@ -70,7 +67,7 @@ BOOL do_srv_net_srv_conn_enum(struct cli_state *cli, } /* send the data on \PIPE\ */ - if(!rpc_api_pipe_req(cli, SRV_NET_CONN_ENUM, &data, &rdata)) { + if(!rpc_api_pipe_req(cli, SRV_NETCONNENUM, &data, &rdata)) { prs_mem_free(&data); prs_mem_free(&rdata); return False; @@ -110,11 +107,10 @@ do a server net sess enum ****************************************************************************/ BOOL do_srv_net_srv_sess_enum(struct cli_state *cli, - char *server_name, char *qual_name, - char *user_name, - uint32 switch_value, SRV_SESS_INFO_CTR *ctr, - uint32 preferred_len, - ENUM_HND *hnd) + char *server_name, char *qual_name, + uint32 switch_value, SRV_SESS_INFO_CTR *ctr, + uint32 preferred_len, + ENUM_HND *hnd) { prs_struct data; prs_struct rdata; @@ -127,7 +123,7 @@ BOOL do_srv_net_srv_sess_enum(struct cli_state *cli, prs_init(&data, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); prs_init(&rdata, 0, cli->mem_ctx, UNMARSHALL); - /* create and send a MSRPC command with api SRV_NET_SESS_ENUM */ + /* create and send a MSRPC command with api SRV_NETSESSENUM */ DEBUG(4,("SRV Net Session Enum (%s), level %d, enum:%8x\n", server_name, switch_value, get_enum_hnd(hnd))); @@ -138,7 +134,7 @@ BOOL do_srv_net_srv_sess_enum(struct cli_state *cli, ctr->sess.info0.ptr_sess_info = 1; /* store the parameters */ - init_srv_q_net_sess_enum(&q_o, server_name, qual_name, user_name, + init_srv_q_net_sess_enum(&q_o, server_name, qual_name, switch_value, ctr, preferred_len, hnd); @@ -151,7 +147,7 @@ BOOL do_srv_net_srv_sess_enum(struct cli_state *cli, } /* send the data on \PIPE\ */ - if (!rpc_api_pipe_req(cli, SRV_NET_SESS_ENUM, &data, &rdata)) { + if (!rpc_api_pipe_req(cli, SRV_NETSESSENUM, &data, &rdata)) { prs_mem_free(&data); prs_mem_free(&rdata); return False; @@ -204,7 +200,7 @@ BOOL do_srv_net_srv_share_enum(struct cli_state *cli, prs_init(&data, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); prs_init(&rdata, 0, cli->mem_ctx, UNMARSHALL); - /* create and send a MSRPC command with api SRV_NET_SHARE_ENUM */ + /* create and send a MSRPC command with api SRV_NETSHAREENUM */ DEBUG(4,("SRV Get Share Info (%s), level %d, enum:%8x\n", server_name, switch_value, get_enum_hnd(hnd))); @@ -221,7 +217,7 @@ BOOL do_srv_net_srv_share_enum(struct cli_state *cli, } /* send the data on \PIPE\ */ - if (!rpc_api_pipe_req(cli, SRV_NET_SHARE_ENUM, &data, &rdata)) { + if (!rpc_api_pipe_req(cli, SRV_NETSHAREENUM, &data, &rdata)) { prs_mem_free(&data); prs_mem_free(&rdata); return False; @@ -275,7 +271,7 @@ BOOL do_srv_net_srv_file_enum(struct cli_state *cli, prs_init(&data, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); prs_init(&rdata, 0, cli->mem_ctx, UNMARSHALL); - /* create and send a MSRPC command with api SRV_NET_FILE_ENUM */ + /* create and send a MSRPC command with api SRV_NETFILEENUM */ DEBUG(4,("SRV Get File Info (%s), level %d, enum:%8x\n", server_name, switch_value, get_enum_hnd(hnd))); @@ -301,7 +297,7 @@ BOOL do_srv_net_srv_file_enum(struct cli_state *cli, } /* send the data on \PIPE\ */ - if (!rpc_api_pipe_req(cli, SRV_NET_FILE_ENUM, &data, &rdata)) { + if (!rpc_api_pipe_req(cli, SRV_NETFILEENUM, &data, &rdata)) { prs_mem_free(&data); prs_mem_free(&rdata); return False; diff --git a/source3/rpc_client/cli_wkssvc.c b/source3/rpc_client/cli_wkssvc.c index 90269dfbee..788d60c56e 100644 --- a/source3/rpc_client/cli_wkssvc.c +++ b/source3/rpc_client/cli_wkssvc.c @@ -23,9 +23,6 @@ #include "includes.h" -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_RPC_CLI - /**************************************************************************** do a WKS Open Policy ****************************************************************************/ diff --git a/source3/rpc_client/msrpc_spoolss.c b/source3/rpc_client/msrpc_spoolss.c index 56c70730ba..2267190d8e 100644 --- a/source3/rpc_client/msrpc_spoolss.c +++ b/source3/rpc_client/msrpc_spoolss.c @@ -25,9 +25,6 @@ #include "rpc_parse.h" #include "rpcclient.h" -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_RPC_CLI - #define DEBUG_TESTING extern FILE* out_hnd; diff --git a/source3/rpc_client/ntclienttrust.c b/source3/rpc_client/ntclienttrust.c new file mode 100644 index 0000000000..284fd491f8 --- /dev/null +++ b/source3/rpc_client/ntclienttrust.c @@ -0,0 +1,157 @@ +/* + Unix SMB/CIFS implementation. + NT Domain Authentication SMB / MSRPC client + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1996-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +/************************************************************************ + check workstation trust account status + ************************************************************************/ +BOOL trust_account_check(struct in_addr dest_ip, char *dest_host, + char *hostname, char *domain, fstring mach_acct, + fstring new_mach_pwd) +{ + pstring tmp; + fstring mach_pwd; + struct cli_state cli_trust; + uchar lm_owf_mach_pwd[16]; + uchar nt_owf_mach_pwd[16]; + uchar lm_sess_pwd[24]; + uchar nt_sess_pwd[24]; + + BOOL right_error_code = False; + uint8 err_cls; + uint32 err_num; + + char *start_mach_pwd; + char *change_mach_pwd; + + /* initial machine password */ + fstrcpy(mach_pwd, hostname); + strlower(mach_pwd); + + slprintf(tmp, sizeof(tmp) - 1,"Enter Workstation Trust Account password for [%s].\nDefault is [%s].\nPassword:", + mach_acct, mach_pwd); + + start_mach_pwd = (char*)getpass(tmp); + + if (start_mach_pwd[0] != 0) + { + fstrcpy(mach_pwd, start_mach_pwd); + } + + slprintf(tmp, sizeof(tmp)-1, "Enter new Workstation Trust Account password for [%s]\nPress Return to leave at old value.\nNew Password:", + mach_acct); + + change_mach_pwd = (char*)getpass(tmp); + + if (change_mach_pwd[0] != 0) + { + fstrcpy(new_mach_pwd, change_mach_pwd); + } + else + { + DEBUG(1,("trust_account_check: password change not requested\n")); + change_mach_pwd[0] = 0; + } + + DEBUG(1,("initialise cli_trust connection\n")); + + if (!cli_initialise(&cli_trust)) + { + DEBUG(1,("cli_initialise failed for cli_trust\n")); + return False; + } + + DEBUG(1,("server connect for cli_trust\n")); + + if (!server_connect_init(&cli_trust, hostname, dest_ip, dest_host)) + { + cli_error(&cli_trust, &err_cls, &err_num, NULL); + DEBUG(1,("server_connect_init failed (%s)\n", cli_errstr(&cli_trust))); + + cli_shutdown(&cli_trust); + return False; + } + + DEBUG(1,("server connect cli_trust succeeded\n")); + + nt_lm_owf_gen(mach_pwd, nt_owf_mach_pwd, lm_owf_mach_pwd); + + DEBUG(5,("generating nt owf from initial machine pwd: %s\n", mach_pwd)); + +#ifdef DEBUG_PASSWORD + DEBUG(100,("client cryptkey: ")); + dump_data(100, cli_trust.cryptkey, sizeof(cli_trust.cryptkey)); +#endif + + SMBencrypt(nt_owf_mach_pwd, cli_trust.cryptkey, nt_sess_pwd); + +#ifdef DEBUG_PASSWORD + DEBUG(100,("nt_owf_mach_pwd: ")); + dump_data(100, nt_owf_mach_pwd, sizeof(lm_owf_mach_pwd)); + DEBUG(100,("nt_sess_pwd: ")); + dump_data(100, nt_sess_pwd, sizeof(nt_sess_pwd)); +#endif + + SMBencrypt(lm_owf_mach_pwd, cli_trust.cryptkey, lm_sess_pwd); + +#ifdef DEBUG_PASSWORD + DEBUG(100,("lm_owf_mach_pwd: ")); + dump_data(100, lm_owf_mach_pwd, sizeof(lm_owf_mach_pwd)); + DEBUG(100,("lm_sess_pwd: ")); + dump_data(100, lm_sess_pwd, sizeof(lm_sess_pwd)); +#endif + + right_error_code = False; + + if (cli_session_setup(&cli_trust, mach_acct, + nt_owf_mach_pwd, sizeof(nt_owf_mach_pwd), + nt_owf_mach_pwd, sizeof(nt_owf_mach_pwd), domain)) + { + DEBUG(0,("cli_session_setup: NO ERROR! AAAGH! BUG IN SERVER DETECTED!!!\n")); + cli_shutdown(&cli_trust); + + return False; + } + + cli_error(&cli_trust, &err_cls, &err_num, NULL); + + if (err_num == (0xC0000000 | NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT)) + { + DEBUG(1,("cli_send_tconX: valid workstation trust account exists\n")); + right_error_code = True; + } + + if (err_num == (0xC0000000 | NT_STATUS_NO_SUCH_USER)) + { + DEBUG(1,("cli_send_tconX: workstation trust account does not exist\n")); + right_error_code = False; + } + + if (!right_error_code) + { + DEBUG(1,("server_validate failed (%s)\n", cli_errstr(&cli_trust))); + } + + cli_shutdown(&cli_trust); + return right_error_code; +} |