summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2000-07-14 17:04:04 +0000
committerGerald Carter <jerry@samba.org>2000-07-14 17:04:04 +0000
commit8213b96fd9b3959c9500aa2a595182526c865402 (patch)
treeeef7ddf530c7b3eaf18d641d1f278264542f75ac
parent5af82b6d09d700906eb8c1e65ecbf2617033435d (diff)
downloadsamba-8213b96fd9b3959c9500aa2a595182526c865402.tar.gz
samba-8213b96fd9b3959c9500aa2a595182526c865402.tar.bz2
samba-8213b96fd9b3959c9500aa2a595182526c865402.zip
More functions merged from TNG for rpcclient. They don't all work
currently as I have to do something about the policy handle caching issues. --jerry (This used to be commit 233b074f490b3b01f3a462284aa8117536df0082)
-rw-r--r--source3/rpc_client/cli_pipe.c11
-rw-r--r--source3/rpc_client/msrpc_spoolss.c415
-rw-r--r--source3/rpc_client/ncacn_np_use.c9
-rw-r--r--source3/rpc_client/ncalrpc_l_use.c285
4 files changed, 410 insertions, 310 deletions
diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c
index ade31dbb5b..d39f742579 100644
--- a/source3/rpc_client/cli_pipe.c
+++ b/source3/rpc_client/cli_pipe.c
@@ -522,7 +522,7 @@ static BOOL create_rpc_bind_req(prs_struct *rpc_out, BOOL do_auth, uint32 rpc_ca
prs_struct auth_info;
int auth_len = 0;
- prs_init(&auth_info, 0, 4, MARSHALL);
+ prs_init(&auth_info, MAX_PDU_FRAG_LEN, 4, MARSHALL);
if (do_auth) {
RPC_HDR_AUTH hdr_auth;
@@ -1087,20 +1087,13 @@ BOOL rpc_pipe_bind(struct cli_state *cli, char *pipe_name, char *my_name)
prs_struct rdata;
BOOL do_auth = (cli->ntlmssp_cli_flgs != 0);
uint32 rpc_call_id;
- char buffer[MAX_PDU_FRAG_LEN];
DEBUG(5,("Bind RPC Pipe[%x]: %s\n", cli->nt_pipe_fnum, pipe_name));
if (!valid_pipe_name(pipe_name, &abstract, &transfer))
return False;
- prs_init(&rpc_out, 0, 4, MARSHALL);
-
- /*
- * Use the MAX_PDU_FRAG_LEN buffer to store the bind request.
- */
-
- prs_give_memory( &rpc_out, buffer, sizeof(buffer), False);
+ prs_init(&rpc_out, MAX_PDU_FRAG_LEN, 4, MARSHALL);
rpc_call_id = get_rpc_call_id();
diff --git a/source3/rpc_client/msrpc_spoolss.c b/source3/rpc_client/msrpc_spoolss.c
index ea3d482837..be0f59a8fe 100644
--- a/source3/rpc_client/msrpc_spoolss.c
+++ b/source3/rpc_client/msrpc_spoolss.c
@@ -37,21 +37,18 @@ extern struct user_creds *usr_creds;
/********************************************************************
initialize a spoolss NEW_BUFFER.
-
- ** WARNING ** Calling this function on an existing buffer
- (which already hgolds data in the buffer->prs.data_p)
- will result in memory leakage
********************************************************************/
static void init_buffer(NEW_BUFFER *buffer, uint32 size)
{
buffer->ptr = (size!=0)? 1:0;
buffer->size=size;
buffer->string_at_end=size;
- prs_init(&(buffer->prs), size, 4, MARSHALL);
+ prs_init(&buffer->prs, size, 4, MARSHALL);
buffer->struct_start = prs_offset(&buffer->prs);
}
-static void decode_printer_info_0(NEW_BUFFER *buffer, uint32 returned, PRINTER_INFO_0 **info)
+static void decode_printer_info_0(NEW_BUFFER *buffer, uint32 returned,
+ PRINTER_INFO_0 **info)
{
uint32 i;
PRINTER_INFO_0 *inf;
@@ -67,7 +64,8 @@ static void decode_printer_info_0(NEW_BUFFER *buffer, uint32 returned, PRINTER_I
*info=inf;
}
-static void decode_printer_info_1(NEW_BUFFER *buffer, uint32 returned, PRINTER_INFO_1 **info)
+static void decode_printer_info_1(NEW_BUFFER *buffer, uint32 returned,
+ PRINTER_INFO_1 **info)
{
uint32 i;
PRINTER_INFO_1 *inf;
@@ -83,7 +81,8 @@ static void decode_printer_info_1(NEW_BUFFER *buffer, uint32 returned, PRINTER_I
*info=inf;
}
-static void decode_printer_info_2(NEW_BUFFER *buffer, uint32 returned, PRINTER_INFO_2 **info)
+static void decode_printer_info_2(NEW_BUFFER *buffer, uint32 returned,
+ PRINTER_INFO_2 **info)
{
uint32 i;
PRINTER_INFO_2 *inf;
@@ -99,7 +98,8 @@ static void decode_printer_info_2(NEW_BUFFER *buffer, uint32 returned, PRINTER_I
*info=inf;
}
-static void decode_printer_info_3(NEW_BUFFER *buffer, uint32 returned, PRINTER_INFO_3 **info)
+static void decode_printer_info_3(NEW_BUFFER *buffer, uint32 returned,
+ PRINTER_INFO_3 **info)
{
uint32 i;
PRINTER_INFO_3 *inf;
@@ -115,7 +115,8 @@ static void decode_printer_info_3(NEW_BUFFER *buffer, uint32 returned, PRINTER_I
*info=inf;
}
-static void decode_printer_driver_1(NEW_BUFFER *buffer, uint32 returned, DRIVER_INFO_1 **info)
+static void decode_printer_driver_1(NEW_BUFFER *buffer, uint32 returned,
+ DRIVER_INFO_1 **info)
{
uint32 i;
DRIVER_INFO_1 *inf;
@@ -131,7 +132,8 @@ static void decode_printer_driver_1(NEW_BUFFER *buffer, uint32 returned, DRIVER_
*info=inf;
}
-static void decode_printer_driver_2(NEW_BUFFER *buffer, uint32 returned, DRIVER_INFO_2 **info)
+static void decode_printer_driver_2(NEW_BUFFER *buffer, uint32 returned,
+ DRIVER_INFO_2 **info)
{
uint32 i;
DRIVER_INFO_2 *inf;
@@ -147,7 +149,8 @@ static void decode_printer_driver_2(NEW_BUFFER *buffer, uint32 returned, DRIVER_
*info=inf;
}
-static void decode_printer_driver_3(NEW_BUFFER *buffer, uint32 returned, DRIVER_INFO_3 **info)
+static void decode_printer_driver_3(NEW_BUFFER *buffer, uint32 returned,
+ DRIVER_INFO_3 **info)
{
uint32 i;
DRIVER_INFO_3 *inf;
@@ -169,7 +172,7 @@ static void decode_printerdriverdir_info_1(NEW_BUFFER *buffer, DRIVER_DIRECTORY_
inf=(DRIVER_DIRECTORY_1 *)malloc(returned*sizeof(DRIVER_DIRECTORY_1));
*/
- buffer->prs.data_offset=0;
+ prs_set_offset(&buffer->prs, 0);
new_smb_io_driverdir_1("", buffer, info, 0);
@@ -177,10 +180,12 @@ static void decode_printerdriverdir_info_1(NEW_BUFFER *buffer, DRIVER_DIRECTORY_
}
+
/****************************************************************************
nt spoolss query
****************************************************************************/
-BOOL msrpc_spoolss_enum_printers(char* srv_name, uint32 flags, uint32 level, PRINTER_INFO_CTR ctr)
+BOOL msrpc_spoolss_enum_printers(char* srv_name, uint32 flags,
+ uint32 level, PRINTER_INFO_CTR ctr)
{
uint32 status;
NEW_BUFFER buffer;
@@ -190,11 +195,13 @@ BOOL msrpc_spoolss_enum_printers(char* srv_name, uint32 flags, uint32 level, PRI
init_buffer(&buffer, 0);
/* send a NULL buffer first */
- status=spoolss_enum_printers(flags, srv_name, level, &buffer, 0, &needed, &returned);
+ status=spoolss_enum_printers(flags, srv_name, level, &buffer, 0,
+ &needed, &returned);
if (status==ERROR_INSUFFICIENT_BUFFER) {
init_buffer(&buffer, needed);
- status=spoolss_enum_printers(flags, srv_name, level, &buffer, needed, &needed, &returned);
+ status=spoolss_enum_printers(flags, srv_name, level, &buffer,
+ needed, &needed, &returned);
}
report(out_hnd, "\tstatus:[%d (%x)]\n", status, status);
@@ -220,4 +227,380 @@ BOOL msrpc_spoolss_enum_printers(char* srv_name, uint32 flags, uint32 level, PRI
return True;
}
+/****************************************************************************
+nt spoolss query
+****************************************************************************/
+uint32 msrpc_spoolss_getprinterdata( const char* printer_name,
+ const char* station,
+ const char* user_name,
+ const char* value_name,
+ uint32 *type,
+ NEW_BUFFER *buffer,
+ void *fn)
+{
+ POLICY_HND hnd;
+ uint32 status;
+ uint32 needed;
+ uint32 size;
+ char *data;
+ UNISTR2 uni_val_name;
+
+ DEBUG(4,("spoolgetdata - printer: %s server: %s user: %s value: %s\n",
+ printer_name, station, user_name, value_name));
+
+ if(!spoolss_open_printer_ex( printer_name, 0, 0, station, user_name,
+ &hnd))
+ {
+ return NT_STATUS_ACCESS_DENIED;
+ }
+
+ init_unistr2(&uni_val_name, value_name, 0);
+ size = 0;
+ init_buffer(buffer, size);
+ data = NULL;
+ status = spoolss_getprinterdata(&hnd, &uni_val_name, size, type, &size,
+ data, &needed);
+
+ if (status == ERROR_INSUFFICIENT_BUFFER)
+ {
+ size = needed;
+ init_buffer(buffer, size);
+ data = prs_data_p(&buffer->prs);
+ status = spoolss_getprinterdata(&hnd, &uni_val_name,
+ size, type, &size,
+ data, &needed);
+ }
+
+ if (status != NT_STATUS_NO_PROBLEMO) {
+ if (!spoolss_closeprinter(&hnd))
+ return NT_STATUS_ACCESS_DENIED;
+ return status;
+ }
+
+#if 0
+ if (fn != NULL)
+ fn(printer_name, station, level, returned, *ctr);
+#endif
+
+ return status;
+}
+
+/****************************************************************************
+nt spoolss query
+****************************************************************************/
+BOOL msrpc_spoolss_enum_jobs( const char* printer_name,
+ const char* station, const char* user_name,
+ uint32 level,
+ void ***ctr, JOB_INFO_FN(fn))
+{
+ POLICY_HND hnd;
+ uint32 status;
+ NEW_BUFFER buffer;
+ uint32 needed;
+ uint32 returned;
+ uint32 firstjob=0;
+ uint32 numofjobs=0xffff;
+
+ DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n",
+ printer_name, station, user_name));
+
+ if(!spoolss_open_printer_ex( printer_name, 0, 0, station, user_name, &hnd))
+ return False;
+
+ init_buffer(&buffer, 0);
+ status = spoolss_enum_jobs(&hnd, firstjob, numofjobs, level, &buffer, 0, &needed, &returned);
+
+ if (status == ERROR_INSUFFICIENT_BUFFER)
+ {
+ init_buffer(&buffer, needed);
+ status = spoolss_enum_jobs( &hnd, firstjob, numofjobs, level, &buffer, needed, &needed, &returned);
+ }
+
+ if (status!=NT_STATUS_NO_PROBLEMO) {
+ if (!spoolss_closeprinter(&hnd))
+ return False;
+ return False;
+ }
+
+ if (fn != NULL)
+ fn(printer_name, station, level, returned, *ctr);
+
+ return True;
+}
+
+
+/****************************************************************************
+nt spoolss query
+****************************************************************************/
+BOOL msrpc_spoolss_enum_printerdata( const char* printer_name,
+ const char* station, const char* user_name )
+{
+ POLICY_HND hnd;
+ uint32 status;
+ uint32 idx;
+ uint32 valuelen;
+ uint16 *value;
+ uint32 rvaluelen;
+ uint32 type;
+ uint32 datalen;
+ uint8 *data;
+ uint32 rdatalen;
+
+ DEBUG(4,("spoolenum_printerdata - printer: %s\n", printer_name));
+
+ if(!spoolss_open_printer_ex( printer_name, 0, 0, station, user_name, &hnd))
+ return False;
+
+ status = spoolss_enum_printerdata(&hnd, 0, &valuelen, value,
+ &rvaluelen, &type, &datalen,
+ data, &rdatalen);
+
+ valuelen=rvaluelen;
+ datalen=rdatalen;
+
+ value=(uint16 *)malloc(valuelen*sizeof(uint16));
+ data=(uint8 *)malloc(datalen*sizeof(uint8));
+
+ display_printer_enumdata(out_hnd, ACTION_HEADER, idx, valuelen,
+ value, rvaluelen, type, datalen, data, rdatalen);
+
+ do {
+
+ status = spoolss_enum_printerdata(&hnd, idx, &valuelen,
+ value, &rvaluelen, &type,
+ &datalen, data, &rdatalen);
+ display_printer_enumdata(out_hnd, ACTION_ENUMERATE, idx,
+ valuelen, value, rvaluelen, type,
+ datalen, data, rdatalen);
+ idx++;
+
+ } while (status != 0x0103); /* NO_MORE_ITEMS */
+
+ display_printer_enumdata(out_hnd, ACTION_FOOTER, idx, valuelen,
+ value, rvaluelen, type, datalen, data, rdatalen);
+
+
+ if (status!=NT_STATUS_NO_PROBLEMO) {
+ /*
+ * the check on this if statement is redundant
+ * since is the status is bad we're going to
+ * return False anyways. The caller will be
+ * unable to determine if there really was a problem
+ * with the spoolss_closeprinter() call --jerry
+ */
+ spoolss_closeprinter(&hnd);
+ return False;
+ }
+
+ return True;
+}
+
+/****************************************************************************
+nt spoolss query
+****************************************************************************/
+BOOL msrpc_spoolss_getprinter( const char* printer_name, const uint32 level,
+ const char* station, const char* user_name,
+ PRINTER_INFO_CTR ctr)
+{
+ POLICY_HND hnd;
+ uint32 status=0;
+ NEW_BUFFER buffer;
+ uint32 needed;
+
+ DEBUG(4,("spoolenum_getprinter - printer: %s\n", printer_name));
+
+ if(!spoolss_open_printer_ex( printer_name, "", PRINTER_ALL_ACCESS, station, user_name, &hnd))
+ return False;
+
+ init_buffer(&buffer, 0);
+
+ status = spoolss_getprinter(&hnd, level, &buffer, 0, &needed);
+
+ if (status==ERROR_INSUFFICIENT_BUFFER) {
+ init_buffer(&buffer, needed);
+ status = spoolss_getprinter(&hnd, level, &buffer, needed, &needed);
+ }
+
+ report(out_hnd, "\tstatus:[%d (%x)]\n", status, status);
+
+ if (status!=NT_STATUS_NO_PROBLEMO)
+ return False;
+
+ switch (level) {
+ case 0:
+ decode_printer_info_0(&buffer, 1, &(ctr.printers_0));
+ break;
+ case 1:
+ decode_printer_info_1(&buffer, 1, &(ctr.printers_1));
+ break;
+ case 2:
+ decode_printer_info_2(&buffer, 1, &(ctr.printers_2));
+ break;
+ case 3:
+ decode_printer_info_3(&buffer, 1, &(ctr.printers_3));
+ break;
+ }
+
+ display_printer_info_ctr(out_hnd, ACTION_HEADER , level, 1, ctr);
+ display_printer_info_ctr(out_hnd, ACTION_ENUMERATE, level, 1, ctr);
+ display_printer_info_ctr(out_hnd, ACTION_FOOTER , level, 1, ctr);
+
+ if (status!=NT_STATUS_NO_PROBLEMO) {
+ if (!spoolss_closeprinter(&hnd))
+ return False;
+ return False;
+ }
+
+ return True;
+}
+
+/****************************************************************************
+nt spoolss query
+****************************************************************************/
+BOOL msrpc_spoolss_getprinterdriver( const char* printer_name,
+ const char *environment, const uint32 level,
+ const char* station, const char* user_name,
+ PRINTER_DRIVER_CTR ctr)
+{
+ POLICY_HND hnd;
+ uint32 status=0;
+ NEW_BUFFER buffer;
+ uint32 needed;
+
+ DEBUG(4,("spoolenum_getprinterdriver - printer: %s\n", printer_name));
+
+ if(!spoolss_open_printer_ex( printer_name, "", PRINTER_ALL_ACCESS, station, user_name, &hnd))
+ return False;
+
+ init_buffer(&buffer, 0);
+
+ status = spoolss_getprinterdriver(&hnd, environment, level, &buffer, 0, &needed);
+
+ if (status==ERROR_INSUFFICIENT_BUFFER) {
+ init_buffer(&buffer, needed);
+ status = spoolss_getprinterdriver(&hnd, environment, level, &buffer, needed, &needed);
+ }
+
+ report(out_hnd, "\tstatus:[%d (%x)]\n", status, status);
+
+ if (status!=NT_STATUS_NO_PROBLEMO)
+ return False;
+
+ switch (level) {
+ case 1:
+ decode_printer_driver_1(&buffer, 1, &(ctr.info1));
+ break;
+ case 2:
+ decode_printer_driver_2(&buffer, 1, &(ctr.info2));
+ break;
+ case 3:
+ decode_printer_driver_3(&buffer, 1, &(ctr.info3));
+ break;
+ }
+
+ display_printer_driver_ctr(out_hnd, ACTION_HEADER , level, 1, ctr);
+ display_printer_driver_ctr(out_hnd, ACTION_ENUMERATE, level, 1, ctr);
+ display_printer_driver_ctr(out_hnd, ACTION_FOOTER , level, 1, ctr);
+
+ if (status!=NT_STATUS_NO_PROBLEMO) {
+ if (!spoolss_closeprinter(&hnd))
+ return False;
+ return False;
+ }
+
+ return True;
+}
+
+/****************************************************************************
+nt spoolss query
+****************************************************************************/
+BOOL msrpc_spoolss_enumprinterdrivers( const char* srv_name,
+ const char *environment, const uint32 level,
+ PRINTER_DRIVER_CTR ctr)
+{
+ uint32 status=0;
+ NEW_BUFFER buffer;
+ uint32 needed;
+ uint32 returned;
+
+ DEBUG(4,("spoolenum_enumprinterdrivers - server: %s\n", srv_name));
+
+ init_buffer(&buffer, 0);
+
+ status = spoolss_enum_printerdrivers(srv_name, environment,
+ level, &buffer, 0, &needed, &returned);
+
+ if (status == ERROR_INSUFFICIENT_BUFFER)
+ {
+ init_buffer(&buffer, needed);
+ status = spoolss_enum_printerdrivers( srv_name, environment,
+ level, &buffer, needed, &needed, &returned);
+ }
+
+ report(out_hnd, "\tstatus:[%d (%x)]\n", status, status);
+
+ if (status!=NT_STATUS_NO_PROBLEMO)
+ return False;
+
+ switch (level)
+ {
+ case 1:
+ {
+ decode_printer_driver_1(&buffer, returned, &(ctr.info1));
+ break;
+ }
+ case 2:
+ {
+ decode_printer_driver_2(&buffer, returned, &(ctr.info2));
+ break;
+ }
+ case 3:
+ {
+ decode_printer_driver_3(&buffer, returned, &(ctr.info3));
+ break;
+ }
+ }
+
+ display_printer_driver_ctr(out_hnd, ACTION_HEADER , level, returned, ctr);
+ display_printer_driver_ctr(out_hnd, ACTION_ENUMERATE, level, returned, ctr);
+ display_printer_driver_ctr(out_hnd, ACTION_FOOTER , level, returned, ctr);
+
+ return True;
+}
+
+/****************************************************************************
+nt spoolss query
+****************************************************************************/
+BOOL msrpc_spoolss_getprinterdriverdir(char* srv_name, char* env_name, uint32 level, DRIVER_DIRECTORY_CTR ctr)
+{
+ uint32 status;
+ NEW_BUFFER buffer;
+ uint32 needed;
+
+ init_buffer(&buffer, 0);
+
+ /* send a NULL buffer first */
+ status=spoolss_getprinterdriverdir(srv_name, env_name, level, &buffer, 0, &needed);
+
+ if (status==ERROR_INSUFFICIENT_BUFFER) {
+ init_buffer(&buffer, needed);
+ status=spoolss_getprinterdriverdir(srv_name, env_name, level, &buffer, needed, &needed);
+ }
+
+ report(out_hnd, "\tstatus:[%d (%x)]\n", status, status);
+
+ if (status!=NT_STATUS_NO_PROBLEMO)
+ return False;
+
+ switch (level) {
+ case 1:
+ decode_printerdriverdir_info_1(&buffer, &(ctr.driver.info_1));
+ break;
+ }
+
+ display_printerdriverdir_info_ctr(out_hnd, ACTION_HEADER , level, ctr);
+ display_printerdriverdir_info_ctr(out_hnd, ACTION_ENUMERATE, level, ctr);
+ display_printerdriverdir_info_ctr(out_hnd, ACTION_FOOTER , level, ctr);
+ return True;
+}
diff --git a/source3/rpc_client/ncacn_np_use.c b/source3/rpc_client/ncacn_np_use.c
index 12c2f2381d..0ab2802cc1 100644
--- a/source3/rpc_client/ncacn_np_use.c
+++ b/source3/rpc_client/ncacn_np_use.c
@@ -20,6 +20,15 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+/*************************************************************
+ Ever wonder where Luke comes up with some of these names?
+
+ (N)etwork (C)omputing (A)rchitechture ???
+
+ get it? --jerry
+*************************************************************/
+
+
#define NO_SYSLOG
#include "includes.h"
diff --git a/source3/rpc_client/ncalrpc_l_use.c b/source3/rpc_client/ncalrpc_l_use.c
deleted file mode 100644
index c876fe4b5a..0000000000
--- a/source3/rpc_client/ncalrpc_l_use.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- SMB client generic functions
- Copyright (C) Andrew Tridgell 1994-1999
- Copyright (C) Luke Kenneth Casson Leighton 1996-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.
-*/
-
-#define NO_SYSLOG
-
-#include "includes.h"
-#include "rpc_parse.h"
-
-extern int DEBUGLEVEL;
-
-struct ncalrpc_use
-{
- struct msrpc_local *cli;
- uint32 num_users;
-};
-
-static struct ncalrpc_use **clis = NULL;
-static uint32 num_clis = 0;
-
-/****************************************************************************
-add a client state to the array
-****************************************************************************/
-static struct ncalrpc_use *add_cli_to_array(uint32 * len,
- struct ncalrpc_use ***array,
- struct ncalrpc_use *cli)
-{
- int i;
- for (i = 0; i < num_clis; i++)
- {
- if (clis[i] == NULL)
- {
- clis[i] = cli;
- return cli;
- }
- }
-
- return (struct ncalrpc_use *)add_item_to_array(len,
- (void ***)array,
- (void *)cli);
-
-}
-
-/****************************************************************************
-terminate client connection
-****************************************************************************/
-static void ncalrpc_use_free(struct ncalrpc_use *cli)
-{
- if (cli->cli != NULL)
- {
- if (cli->cli->initialised)
- {
- ncalrpc_l_shutdown(cli->cli);
- }
- free(cli->cli);
- }
-
- free(cli);
-}
-
-/****************************************************************************
-find client state. server name, user name, vuid name and password must all
-match.
-****************************************************************************/
-static struct ncalrpc_use *ncalrpc_l_find(const char *pipe_name,
- const vuser_key * key, BOOL reuse)
-{
- int i;
- vuser_key null_usr;
-
- if (key == NULL)
- {
- key = &null_usr;
- null_usr.pid = sys_getpid();
- null_usr.vuid = UID_FIELD_INVALID;
- }
-
- DEBUG(10, ("ncalrpc_l_find: %s [%d,%x]\n",
- pipe_name, key->pid, key->vuid));
-
- for (i = 0; i < num_clis; i++)
- {
- char *cli_name = NULL;
- struct ncalrpc_use *c = clis[i];
-
- if (c == NULL || !c->cli->initialised)
- {
- continue;
- }
-
- cli_name = c->cli->pipe_name;
-
- DEBUG(10, ("ncalrpc_l_find[%d]: %s [%d,%x]\n",
- i, cli_name,
- c->cli->nt.key.pid, c->cli->nt.key.vuid));
-
- if (!strequal(cli_name, pipe_name))
- {
- continue;
- }
- if (reuse)
- {
- return c;
- }
- if (key->vuid == c->cli->nt.key.vuid &&
- key->pid == c->cli->nt.key.pid)
- {
- return c;
- }
- }
-
- return NULL;
-}
-
-/****************************************************************************
-create a new client state from user credentials
-****************************************************************************/
-static struct ncalrpc_use *ncalrpc_use_get(const char *pipe_name,
- const vuser_key * key)
-{
- struct ncalrpc_use *cli = (struct ncalrpc_use *)malloc(sizeof(*cli));
-
- if (cli == NULL)
- {
- return NULL;
- }
-
- memset(cli, 0, sizeof(*cli));
-
- cli->cli = ncalrpc_l_initialise(NULL, key);
-
- if (cli->cli == NULL)
- {
- return NULL;
- }
-
- return cli;
-}
-
-
-/****************************************************************************
-init client state
-****************************************************************************/
-struct msrpc_local *ncalrpc_l_use_add(const char *pipe_name,
- const vuser_key * key,
- BOOL reuse, BOOL *is_new)
-{
- struct ncalrpc_use *cli;
-
- DEBUG(10, ("ncalrpc_l_use_add\n"));
-
- if (strnequal("\\PIPE\\", pipe_name, 6))
- {
- pipe_name = &pipe_name[6];
- }
-
- cli = ncalrpc_l_find(pipe_name, key, reuse);
-
- if (cli != NULL)
- {
- cli->num_users++;
- DEBUG(10,
- ("ncalrpc_l_use_add: num_users: %d\n", cli->num_users));
- (*is_new) = False;
- return cli->cli;
- }
-
- /*
- * allocate
- */
-
- cli = ncalrpc_use_get(pipe_name, key);
-
- /*
- * connect
- */
-
- if (!ncalrpc_l_establish_connection(cli->cli, pipe_name))
- {
- DEBUG(0, ("ncalrpc_l_use_add: connection failed\n"));
- cli->cli = NULL;
- ncalrpc_use_free(cli);
- return NULL;
- }
-
- add_cli_to_array(&num_clis, &clis, cli);
- cli->num_users++;
-
- DEBUG(10, ("ncalrpc_l_use_add: num_users: %d\n", cli->num_users));
-
- (*is_new) = True;
-
- return cli->cli;
-}
-
-/****************************************************************************
-delete a client state
-****************************************************************************/
-BOOL ncalrpc_l_use_del(const char *pipe_name,
- const vuser_key * key,
- BOOL force_close, BOOL *connection_closed)
-{
- int i;
-
- if (strnequal("\\PIPE\\", pipe_name, 6))
- {
- pipe_name = &pipe_name[6];
- }
-
- DEBUG(10, ("ncalrpc_l_use_del: %s. [%d,%x] force close: %s\n",
- pipe_name, key->pid, key->vuid, BOOLSTR(force_close)));
-
- if (connection_closed != NULL)
- {
- *connection_closed = False;
- }
-
- for (i = 0; i < num_clis; i++)
- {
- char *ncalrpc_name = NULL;
-
- if (clis[i] == NULL)
- continue;
- if (clis[i]->cli == NULL)
- continue;
-
- ncalrpc_name = clis[i]->cli->pipe_name;
-
- if (strnequal("\\PIPE\\", pipe_name, 6))
- {
- ncalrpc_name = &ncalrpc_name[6];
- }
-
- DEBUG(10, ("connection: %s [%d,%x]", ncalrpc_name,
- clis[i]->cli->nt.key.pid,
- clis[i]->cli->nt.key.vuid));
-
- if (!strequal(ncalrpc_name, pipe_name))
- continue;
-
- if (key->pid != clis[i]->cli->nt.key.pid ||
- key->vuid != clis[i]->cli->nt.key.vuid)
- {
- continue;
- }
- /* decrement number of users */
- clis[i]->num_users--;
-
- DEBUG(10, ("idx: %i num_users now: %d\n",
- i, clis[i]->num_users));
-
- if (force_close || clis[i]->num_users == 0)
- {
- ncalrpc_use_free(clis[i]);
- clis[i] = NULL;
- if (connection_closed != NULL)
- {
- *connection_closed = True;
- }
- }
- return True;
- }
-
- return False;
-}
-
-