summaryrefslogtreecommitdiff
path: root/source3/rpc_client/cli_connect.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/rpc_client/cli_connect.c')
-rw-r--r--source3/rpc_client/cli_connect.c162
1 files changed, 132 insertions, 30 deletions
diff --git a/source3/rpc_client/cli_connect.c b/source3/rpc_client/cli_connect.c
index 39a7e50bc5..0b5d20d913 100644
--- a/source3/rpc_client/cli_connect.c
+++ b/source3/rpc_client/cli_connect.c
@@ -31,22 +31,92 @@ extern int DEBUGLEVEL;
extern pstring scope;
extern pstring global_myname;
+struct cli_connection
+{
+ struct cli_state *cli;
+ uint16 fnum;
+};
+
+
+/****************************************************************************
+terminate client connection
+****************************************************************************/
+void cli_connection_free(struct cli_connection *con)
+{
+ cli_nt_session_close(con->cli, con->fnum);
+ cli_shutdown(con->cli);
+ free(con->cli);
+ free(con);
+}
+
/****************************************************************************
terminate client state
****************************************************************************/
-void cli_state_free(struct cli_state *cli, uint16 fnum)
+void cli_connection_unlink(struct cli_connection *con)
{
- cli_nt_session_close(cli, fnum);
- cli_shutdown(cli);
- free(cli);
+ if (con != NULL)
+ {
+ cli_connection_free(con);
+ }
+ return;
+}
+
+/****************************************************************************
+init client state
+****************************************************************************/
+BOOL cli_connection_init_list(char* servers, const char* pipe_name,
+ struct cli_connection **con)
+{
+ BOOL res = True;
+
+ /*
+ * allocate
+ */
+
+ (*con) = (struct cli_connection*)malloc(sizeof(**con));
+
+ if ((*con) == NULL)
+ {
+ return False;
+ }
+
+ (*con)->cli = cli_initialise(NULL);
+ (*con)->fnum = 0xffff;
+
+ if ((*con)->cli == NULL)
+ {
+ return False;
+ }
+
+ /*
+ * initialise
+ */
+
+ (*con)->cli->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
+ cli_init_creds((*con)->cli, usr_creds);
+
+ (*con)->cli->use_ntlmv2 = lp_client_ntlmv2();
+
+ if (!cli_connect_serverlist((*con)->cli, servers))
+ {
+ DEBUG(0,("cli_state_init: connection failed\n"));
+ cli_connection_free((*con));
+ return False;
+ }
+
+ (*con)->cli->ntlmssp_cli_flgs = 0x0;
+
+ res = res ? cli_nt_session_open((*con)->cli, pipe_name,
+ &(*con)->fnum) : False;
+
+ return res;
}
/****************************************************************************
init client state
****************************************************************************/
-BOOL cli_state_init(const char* server_name, const char* pipe_name,
- struct cli_state **cli,
- uint16 *fnum)
+BOOL cli_connection_init(const char* server_name, const char* pipe_name,
+ struct cli_connection **con)
{
struct nmb_name calling;
struct nmb_name called;
@@ -60,9 +130,17 @@ BOOL cli_state_init(const char* server_name, const char* pipe_name,
* allocate
*/
- *cli = cli_initialise(NULL);
+ (*con) = (struct cli_connection*)malloc(sizeof(**con));
- if ((*cli) == NULL)
+ if ((*con) == NULL)
+ {
+ return False;
+ }
+
+ (*con)->cli = cli_initialise(NULL);
+ (*con)->fnum = 0xffff;
+
+ if ((*con)->cli == NULL)
{
return False;
}
@@ -71,10 +149,10 @@ BOOL cli_state_init(const char* server_name, const char* pipe_name,
* initialise
*/
- (*cli)->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
- cli_init_creds(*cli, usr_creds);
+ (*con)->cli->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
+ cli_init_creds((*con)->cli, usr_creds);
- (*cli)->use_ntlmv2 = lp_client_ntlmv2();
+ (*con)->cli->use_ntlmv2 = lp_client_ntlmv2();
if (resolve_srv_name(server_name, dest_host, &ip))
{
@@ -92,21 +170,21 @@ BOOL cli_state_init(const char* server_name, const char* pipe_name,
* connect
*/
- if (!cli_establish_connection((*cli),
+ if (!cli_establish_connection((*con)->cli,
dest_host, dest_ip,
&calling, &called,
"IPC$", "IPC",
False, True))
{
DEBUG(0,("cli_state_init: connection failed\n"));
- cli_shutdown((*cli));
- free(*cli);
+ cli_connection_free((*con));
return False;
}
- (*cli)->ntlmssp_cli_flgs = 0x0;
+ (*con)->cli->ntlmssp_cli_flgs = 0x0;
- res = res ? cli_nt_session_open(*cli, pipe_name, fnum) : False;
+ res = res ? cli_nt_session_open((*con)->cli, pipe_name,
+ &(*con)->fnum) : False;
return res;
}
@@ -114,11 +192,9 @@ BOOL cli_state_init(const char* server_name, const char* pipe_name,
/****************************************************************************
obtain client state
****************************************************************************/
-BOOL cli_state_get(const POLICY_HND *pol,
- struct cli_state **cli,
- uint16 *fnum)
+BOOL cli_connection_get(const POLICY_HND *pol, struct cli_connection **con)
{
- return get_policy_cli_state(pol, cli, fnum);
+ return get_policy_con(pol, con);
}
/****************************************************************************
@@ -126,29 +202,55 @@ link a child policy handle to a parent one
****************************************************************************/
BOOL cli_pol_link(POLICY_HND *to, const POLICY_HND *from)
{
- struct cli_state *cli = NULL;
- uint16 fnum = 0xffff;
+ struct cli_connection *con = NULL;
- if (!cli_state_get(from, &cli, &fnum))
+ if (!cli_connection_get(from, &con))
{
return False;
}
- return register_policy_hnd(to) &&
- set_policy_cli_state(to, cli, fnum, NULL);
+ return register_policy_hnd(to) && set_policy_con(to, con, NULL);
}
+/****************************************************************************
+get a user session key associated with a connection associated with a
+policy handle.
+****************************************************************************/
BOOL cli_get_usr_sesskey(const POLICY_HND *pol, uchar sess_key[16])
{
- struct cli_state *cli = NULL;
- uint16 fnum = 0xffff;
+ struct cli_connection *con = NULL;
- if (!cli_state_get(pol, &cli, &fnum))
+ if (!cli_connection_get(pol, &con))
{
return False;
}
- memcpy(sess_key, cli->sess_key, sizeof(cli->sess_key));
+ memcpy(sess_key, con->cli->sess_key, sizeof(con->cli->sess_key));
return True;
}
+
+/****************************************************************************
+ send a request on an rpc pipe.
+ ****************************************************************************/
+BOOL rpc_hnd_pipe_req(const POLICY_HND *hnd, uint8 op_num,
+ prs_struct *data, prs_struct *rdata)
+{
+ struct cli_connection *con = NULL;
+
+ if (!cli_connection_get(hnd, &con))
+ {
+ return False;
+ }
+
+ return rpc_con_pipe_req(con, op_num, data, rdata);
+}
+
+/****************************************************************************
+ send a request on an rpc pipe.
+ ****************************************************************************/
+BOOL rpc_con_pipe_req(struct cli_connection *con, uint8 op_num,
+ prs_struct *data, prs_struct *rdata)
+{
+ return rpc_api_pipe_req(con->cli, con->fnum, op_num, data, rdata);
+}