summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-11-16 18:32:32 +0000
committerJeremy Allison <jra@samba.org>2001-11-16 18:32:32 +0000
commit6bf2505cce7db770fd4db5b19999a78588e96b58 (patch)
treedb672f379270f3eb3ea3977e85316164041a2f28 /source
parentb3e34ad3207f53310b2d59c07a4cec765a0f81bf (diff)
downloadsamba-6bf2505cce7db770fd4db5b19999a78588e96b58.tar.gz
I *love* removing code :-). Removed 4 files that weren't being used.
All this stuff was being pulled in due to *one* unneeded call to fetch a domain SID which smbpasswd already puts in the database... Jeremy.
Diffstat (limited to 'source')
-rw-r--r--source/Makefile.in18
-rw-r--r--source/include/doserr.h1
-rw-r--r--source/lib/util_list.c111
-rw-r--r--source/lib/util_seaccess.c2
-rw-r--r--source/rpc_client/cli_connect.c380
-rw-r--r--source/rpc_client/cli_lsarpc.c693
-rw-r--r--source/rpc_client/cli_trust.c17
-rw-r--r--source/rpc_client/cli_use.c448
-rw-r--r--source/rpc_client/ncacn_np_use.c451
9 files changed, 23 insertions, 2098 deletions
diff --git a/source/Makefile.in b/source/Makefile.in
index d91cc1c6769..6c257cd3f28 100644
--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -162,10 +162,9 @@ RPC_PARSE_OBJ = rpc_parse/parse_lsa.o rpc_parse/parse_net.o \
RPC_CLIENT_OBJ = rpc_client/cli_netlogon.o rpc_client/cli_pipe.o \
- rpc_client/cli_lsarpc.o rpc_client/cli_connect.o \
- rpc_client/cli_use.o rpc_client/cli_login.o \
- rpc_client/cli_spoolss_notify.o rpc_client/ncacn_np_use.o \
- lib/util_list.o rpc_client/cli_trust.o
+ rpc_client/cli_login.o rpc_client/cli_trust.o \
+ rpc_client/cli_spoolss_notify.o \
+ lib/util_list.o
LOCKING_OBJ = locking/locking.o locking/brlock.o locking/posix.o
@@ -191,6 +190,11 @@ AUTH_OBJ = smbd/auth.o smbd/auth_smbpasswd.o smbd/auth_server.o smbd/auth_domain
libsmb/domain_client_validate.o
+SMBD_RPC_CLIENT_OBJ = rpc_client/cli_netlogon.o rpc_client/cli_pipe.o \
+ rpc_client/cli_login.o rpc_client/cli_trust.o \
+ rpc_client/cli_spoolss_notify.o \
+ lib/util_list.o
+
SMBD_OBJ1 = smbd/server.o smbd/files.o smbd/chgpasswd.o smbd/connection.o \
smbd/utmp.o smbd/session.o \
smbd/dfree.o smbd/dir.o smbd/password.o smbd/conn.o smbd/fileio.o \
@@ -214,7 +218,7 @@ PRINTBACKEND_OBJ = printing/printing.o printing/nt_printing.o
MSDFS_OBJ = msdfs/msdfs.o
SMBD_OBJ = $(SMBD_OBJ1) $(MSDFS_OBJ) $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) \
- $(RPC_SERVER_OBJ) $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) \
+ $(RPC_SERVER_OBJ) $(SMBD_RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) \
$(LOCKING_OBJ) $(PASSDB_OBJ) $(PRINTING_OBJ) $(PROFILE_OBJ) \
$(LIB_OBJ) $(PRINTBACKEND_OBJ) $(QUOTAOBJS) $(OPLOCK_OBJ) \
$(NOTIFY_OBJ) $(GROUPDB_OBJ) $(AUTH_OBJ)
@@ -237,7 +241,7 @@ NMBD_OBJ = $(NMBD_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) \
SWAT_OBJ = web/cgi.o web/diagnose.o web/startstop.o web/statuspage.o \
web/swat.o web/neg_lang.o $(PRINTING_OBJ) $(LIBSMB_OBJ) $(LOCKING_OBJ) \
- $(PARAM_OBJ) $(PASSDB_OBJ) $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) \
+ $(PARAM_OBJ) $(PASSDB_OBJ) $(SMBD_RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) \
$(UBIQX_OBJ) $(LIB_OBJ) $(GROUPDB_OBJ) $(PLAINTEXT_AUTH_OBJ) \
smbwrapper/shared.o
@@ -264,7 +268,7 @@ TESTPRNS_OBJ = utils/testprns.o $(PARAM_OBJ) $(PRINTING_OBJ) $(UBIQX_OBJ) \
SMBPASSWD_OBJ = utils/smbpasswd.o $(PARAM_OBJ) \
$(LIBSMB_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ)\
- $(UBIQX_OBJ) $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) $(LIB_OBJ) \
+ $(UBIQX_OBJ) $(SMBD_RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) $(LIB_OBJ) \
libsmb/cli_lsarpc.o libsmb/cli_samr.o libsmb/cli_pipe_util.o
PDBEDIT_OBJ = utils/pdbedit.o $(PARAM_OBJ) $(LIBSMB_OBJ) $(PASSDB_OBJ) \
diff --git a/source/include/doserr.h b/source/include/doserr.h
index dc5bd0414a3..3dcfe02827f 100644
--- a/source/include/doserr.h
+++ b/source/include/doserr.h
@@ -140,6 +140,7 @@
#define WERR_BADFID W_ERROR(6)
#define WERR_BADFUNC W_ERROR(1)
#define WERR_INSUFFICIENT_BUFFER W_ERROR(122)
+#define WERR_NO_SUCH_SHARE W_ERROR(67)
#define WERR_INVALID_PARAM W_ERROR(87)
#define WERR_NOT_SUPPORTED W_ERROR(50)
#define WERR_BAD_PASSWORD W_ERROR(86)
diff --git a/source/lib/util_list.c b/source/lib/util_list.c
index 9795932ecab..b6c82b7371b 100644
--- a/source/lib/util_list.c
+++ b/source/lib/util_list.c
@@ -210,114 +210,3 @@ BOOL copy_policy_hnd (POLICY_HND *dest, const POLICY_HND *src)
*dest = *src;
return True;
}
-
-/* -------------------------------------------------------------
- Functions to implement the RpcHandle list
- -------------------------------------------------------------- */
-
-
-
-/***************************************************************
- Return True if the to RPC_HND_NODEs are equivalent in value.
- Return False if they are not. Since a POLICY_HND is really
- a UUID, two RPC_HND_NODES are considered to be the same if the
- POLICY_HND value matches.
-
- No ordering between the two is attempted.
- **************************************************************/
-BOOL compare_rpc_hnd_node(const RPC_HND_NODE *x,
- const RPC_HND_NODE *y)
-{
- /* only compare valid nodes */
- if (x==NULL || y==NULL)
- return False;
-
- /* if the POLICY_HND field(s) are ever changed, this
- will need to be updated. Probably should be a set of
- support function for dealing with POLICY_HND */
- return (memcmp(&x->hnd, &y->hnd, sizeof(POLICY_HND)) == 0);
-}
-
-/***************************************************************
- associate a POLICY_HND with a cli_connection
- **************************************************************/
-BOOL RpcHndList_set_connection(const POLICY_HND *hnd,
- struct cli_connection *con)
-{
-
- RPC_HND_NODE *node = NULL;
-
- /* initialize the list if necessary */
- if (!hnds.initialized)
- generic_list_init(&hnds);
-
- /* allocate a node to insert */
- if ((node=(RPC_HND_NODE*)malloc(sizeof(RPC_HND_NODE))) == NULL)
- {
- DEBUG(0, ("ERROR: Unable to allocate memory for an RPC_HND_NODE!\n"));
- return False;
- }
-
- /* fill in the RPC_HND_NODE */
- copy_policy_hnd (&node->hnd, hnd);
- node->cli = con;
-
- /* insert the node into the list:
- The 3rd parameter is set to 0 since we don't care
- anything about the type field */
- return (generic_list_insert(&hnds, (void*)node, 0));
-}
-
-/************************************************************************
- delete a POLICY_HND (and associated cli_connection) from the list
- ***********************************************************************/
-BOOL RpcHndList_del_connection(const POLICY_HND *hnd)
-{
- RPC_HND_NODE node, *located;
-
- /* return NULL if the list has not been initialized */
- if (!hnds.initialized)
- return False;
-
- /* fill in the RPC_HND_NODE */
- copy_policy_hnd (&node.hnd, hnd);
- node.cli = NULL;
-
- /* search for the POLICY_HND */
- located = (RPC_HND_NODE*)generic_list_remove(&hnds, &node,
- (BOOL(*)(const void*, const void*))compare_rpc_hnd_node);
- if (located == NULL)
- return False;
-
- /* delete the information */
- cli_connection_free(located->cli);
- SAFE_FREE(located);
- return True;
-}
-
-/************************************************************************
- search for a POLICY_HND and return a pointer to the associated
- cli_connection struct in the list
- **********************************************************************/
-struct cli_connection* RpcHndList_get_connection(const POLICY_HND *hnd)
-{
- RPC_HND_NODE node, *located;
-
- /* return NULL if the list has not been initialized */
- if (!hnds.initialized)
- return NULL;
-
- /* fill in the RPC_HND_NODE */
- copy_policy_hnd (&node.hnd, hnd);
- node.cli = NULL;
-
- /* search for the POLICY_HND */
- located = (RPC_HND_NODE*)generic_list_locate(&hnds, &node,
- (BOOL(*)(const void*, const void*))compare_rpc_hnd_node);
- if (located == NULL)
- return NULL;
- else
- return located->cli;
-}
-
-
diff --git a/source/lib/util_seaccess.c b/source/lib/util_seaccess.c
index 82fb1e8527b..852ded56279 100644
--- a/source/lib/util_seaccess.c
+++ b/source/lib/util_seaccess.c
@@ -241,7 +241,7 @@ BOOL se_access_check(SEC_DESC *sd, NT_USER_TOKEN *token,
/* The user sid is the first in the token */
- DEBUG(3, ("se_access_check: user sid is %s\n", sid_to_string(sid_str, &token->user_sids[0]) ));
+ DEBUG(3, ("se_access_check: user sid is %s\n", sid_to_string(sid_str, &token->user_sids[PRIMARY_USER_SID_INDEX]) ));
for (i = 1; i < token->num_sids; i++) {
DEBUG(3, ("se_access_check: also %s\n",
diff --git a/source/rpc_client/cli_connect.c b/source/rpc_client/cli_connect.c
deleted file mode 100644
index 239bd9c6d59..00000000000
--- a/source/rpc_client/cli_connect.c
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- SMB client generic functions
- Copyright (C) Andrew Tridgell 1994-2000
- Copyright (C) Luke Kenneth Casson Leighton 1996-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.
-*/
-
-#define NO_SYSLOG
-
-#include "includes.h"
-#include "rpc_parse.h"
-
-
-static struct cli_connection **con_list = NULL;
-static uint32 num_cons = 0;
-
-struct user_creds *usr_creds = NULL;
-vuser_key *user_key = NULL;
-
-extern pstring global_myname;
-/*
- * needed for the struct cli_connection
- * none of these functions are implemented in HEAD currently
- * rpc_client/cli_connect.c for details
- *
- * the 'typedef struct _cli_auth_fns cli_auth_fns;' is in
- * rpc_misc.h
- */
-struct _cli_auth_fns {
-
- /* these three will do for now. they *should* match with server-side */
- BOOL (*create_bind_req) (struct cli_connection *, prs_struct *,
- uint32, RPC_IFACE *, RPC_IFACE *);
- BOOL (*decode_bind_resp) (struct cli_connection *, prs_struct *);
- BOOL (*create_bind_cont) (struct cli_connection *, prs_struct *, uint32);
-
- /* creates an authenticated PDU */
- BOOL (*cli_create_pdu) (struct cli_connection *, uint8, prs_struct *,
- int, int *, prs_struct *, uint8 *);
-
- /* decodes an authenticated PDU */
- BOOL (*cli_decode_pdu) (struct cli_connection *, prs_struct *, int, int);
-
-};
-
-cli_auth_fns cli_noauth_fns =
-{
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
-};
-
-
-
-
-void init_connections(void)
-{
- con_list = NULL;
- num_cons = 0;
-
- init_cli_use();
-}
-
-static void free_con_array(uint32 num_entries,
- struct cli_connection **entries)
-{
- void (*fn) (void *) = (void (*)(void *))&cli_connection_free;
- free_void_array(num_entries, (void **)entries, *fn);
-}
-
-
-static struct cli_connection *add_con_to_array(uint32 * len,
- struct cli_connection ***array,
- struct cli_connection *con)
-{
- return (struct cli_connection *)add_item_to_array(len,
- (void ***)array,
- (void *)con);
-
-}
-
-void free_connections(void)
-{
- DEBUG(3, ("free_connections: closing all MSRPC connections\n"));
- free_con_array(num_cons, con_list);
- free_cli_use();
-
- init_connections();
-}
-
-static struct cli_connection *cli_con_get(const char *srv_name,
- char *pipe_name,
- cli_auth_fns * auth,
- void *auth_creds, BOOL reuse)
-{
- struct cli_connection *con = NULL;
- BOOL is_new_connection = False;
- CREDS_NT usr;
- struct ntuser_creds *ntc = NULL;
- struct ncacn_np *pNcacn;
-
- /*
- * initialization stuff
- */
- con = (struct cli_connection *)malloc(sizeof(*con));
- if (con == NULL)
- {
- return NULL;
- }
- memset(con, 0, sizeof(*con));
-
- copy_user_creds(&con->usr_creds, NULL);
- con->usr_creds.reuse = reuse;
-
- if (srv_name != NULL)
- {
- con->srv_name = strdup(srv_name);
- }
- if (pipe_name != NULL)
- {
- con->pipe_name = strdup(pipe_name);
- }
- if (usr_creds != NULL)
- {
- ntc = &usr_creds->ntc;
- }
-
- /* fix me XXXX **WHAT** a hack. The cli_state* is malloc'd
- deep within the call stack, so we can grab that pointer.
- ncacn_np* is stored in an array which is currently handled
- by underlying systems. --jerry */
- pNcacn = ncacn_np_use_add(pipe_name, user_key, srv_name,
- ntc, reuse,
- &is_new_connection);
- if (pNcacn == NULL)
- return NULL;
-
- con->pCli_state = pNcacn->smb;
-
- if (con->pCli_state == NULL)
- return NULL;
-
- con->pCli_state->key.pid = 0;
- con->pCli_state->key.vuid = UID_FIELD_INVALID;
- create_ntc_from_cli_state ( &usr, con->pCli_state );
- copy_nt_creds(&con->usr_creds.ntc, &usr);
-
- if (is_new_connection)
- {
- con->auth_info = NULL;
- con->auth_creds = auth_creds;
-
- if (auth != NULL)
- {
- con->auth = auth;
- }
- else
- {
- con->auth = &cli_noauth_fns;
- }
-
- if (!rpc_pipe_bind(con->pCli_state, pipe_name, global_myname))
- {
- DEBUG(0, ("rpc_pipe_bind failed\n"));
- cli_connection_free(con);
- return NULL;
- }
- }
- else
- {
- con->auth_info = cli_conn_get_auth_creds(con);
- con->auth = cli_conn_get_authfns(con);
- if (con->auth_info != NULL)
- {
- DEBUG(1,("cli_con_get: TODO: auth reuse\n"));
- cli_connection_free(con);
- return NULL;
- }
- else
- {
- con->auth = &cli_noauth_fns;
- }
- }
-
- add_con_to_array(&num_cons, &con_list, con);
- return con;
-}
-
-
-/****************************************************************************
-terminate client connection
-****************************************************************************/
-void cli_connection_free(struct cli_connection *con)
-{
- BOOL closed = False;
- struct cli_state *oldcli = NULL;
- int i;
-
- DEBUG(10, ("cli_connection_free: %d\n", __LINE__));
-
- if (con->pCli_state != NULL)
- {
- DEBUG(10, ("msrpc smb connection\n"));
- ncacn_np_use_del(con->srv_name, con->pipe_name,
- &con->pCli_state->key, False, &closed);
- oldcli = con->pCli_state;
- con->pCli_state = NULL;
- }
-
- DEBUG(10, ("cli_connection_free: closed: %s\n", BOOLSTR(closed)));
-
- if (closed)
- {
- for (i = 0; i < num_cons; i++)
- {
- struct cli_connection *c = con_list[i];
- if (c != NULL && con != c && c->pCli_state == oldcli)
- {
- /* WHOOPS! fnum already open: too bad!!!
- get rid of all other connections that
- were using that connection
- */
- c->pCli_state = NULL;
- }
- }
- }
-
- /* don't free the cli_state since it is being handled
- by the *clis list in rpc_client/cli_use.c.
- This code needs to be fixed badly. It is **way**
- to complicated. --jerry */
- /* if (oldcli != NULL)
- {
- free(oldcli);
- } */
-
- SAFE_FREE(con->srv_name);
- SAFE_FREE(con->pipe_name);
- SAFE_FREE(con->auth_info);
-
- memset(&con->usr_creds, 0, sizeof(con->usr_creds));
-
- for (i = 0; i < num_cons; i++)
- {
- if (con == con_list[i])
- {
- con_list[i] = NULL;
- }
- }
-
- SAFE_FREE(con);
-}
-
-void cli_connection_unlink(struct cli_connection *con)
-{
- if (con != NULL)
- {
- cli_connection_free(con);
- }
- return;
-}
-
-/****************************************************************************
-init client state
-****************************************************************************/
-BOOL cli_connection_init(const char *srv_name, char *pipe_name,
- struct cli_connection **con)
-{
- return cli_connection_init_auth(srv_name, pipe_name, con, NULL, NULL);
-}
-
-/****************************************************************************
-init client state
-****************************************************************************/
-BOOL cli_connection_init_auth(const char *srv_name, char *pipe_name,
- struct cli_connection **con,
- cli_auth_fns * auth, void *auth_creds)
-{
- BOOL reuse = True;
-
- /*
- * allocate
- */
-
- DEBUG(10, ("cli_connection_init_auth: %s %s\n",
- srv_name != NULL ? srv_name : "<null>", pipe_name));
-
- *con = cli_con_get(srv_name, pipe_name, auth, auth_creds, reuse);
-
- return (*con) != NULL;
-}
-
-/****************************************************************************
- get auth functions associated with an msrpc session.
-****************************************************************************/
-struct _cli_auth_fns *cli_conn_get_authfns(struct cli_connection *con)
-{
- return con != NULL ? con->auth : NULL;
-}
-
-
-/****************************************************************************
- get auth info associated with an msrpc session.
-****************************************************************************/
-void *cli_conn_get_auth_creds(struct cli_connection *con)
-{
- return con != NULL ? con->auth_creds : NULL;
-}
-
-
-/****************************************************************************
- 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;
-
- /* we need this to locate the cli_connection associated
- with the POLICY_HND */
- if ((con=RpcHndList_get_connection(hnd)) == NULL)
- return False;
-
- if (!rpc_con_ok(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)
-{
- BOOL ret;
- DEBUG(10, ("rpc_con_pipe_req: op_num %d offset %d used: %d\n",
- op_num, data->data_offset, data->buffer_size));
- prs_dump("in_rpcclient", (int)op_num, data);
-
- /* Why does this use prs->data_offset? --jerry */
- /* prs_realloc_data(data, data->data_offset); */
-
- ret = rpc_api_pipe_req(con->pCli_state, op_num, data, rdata);
- prs_dump("out_rpcclient", (int)op_num, rdata);
- return ret;
-}
-
-/****************************************************************************
- this allows us to detect dead servers. The cli->fd is set to -1 when
- we get an error
-*****************************************************************************/
-BOOL rpc_con_ok(struct cli_connection *con)
-{
- if (!con)
- return False;
-
- if (!con->pCli_state)
- return False;
- if (con->pCli_state->fd == -1)
- return False;
-
- return True;
-}
diff --git a/source/rpc_client/cli_lsarpc.c b/source/rpc_client/cli_lsarpc.c
deleted file mode 100644
index ead820aafd3..00000000000
--- a/source/rpc_client/cli_lsarpc.c
+++ /dev/null
@@ -1,693 +0,0 @@
-/*
- * Unix SMB/Netbios implementation.
- * Version 1.9.
- * 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 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"
-
-/****************************************************************************
-do a LSA Open Policy
-****************************************************************************/
-
-BOOL do_lsa_open_policy(struct cli_state *cli,
- char *system_name, POLICY_HND *hnd,
- BOOL sec_qos)
-{
- prs_struct rbuf;
- prs_struct buf;
- LSA_Q_OPEN_POL q_o;
- LSA_SEC_QOS qos;
- LSA_R_OPEN_POL r_o;
-
- if (hnd == NULL)
- return False;
-
- prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
-
- /* create and send a MSRPC command with api LSA_OPENPOLICY */
-
- DEBUG(4,("LSA Open Policy\n"));
-
- /* store the parameters */
- if (sec_qos) {
- init_lsa_sec_qos(&qos, 2, 1, 0, 0x20000000);
- init_q_open_pol(&q_o, 0x5c, 0, 0, &qos);
- } else {
- init_q_open_pol(&q_o, 0x5c, 0, 0x1, NULL);
- }
-
- /* turn parameters into data stream */
- if(!lsa_io_q_open_pol("", &q_o, &buf, 0)) {
- prs_mem_free(&buf);
- prs_mem_free(&rbuf);
- return False;
- }
-
- /* send the data on \PIPE\ */
- if (!rpc_api_pipe_req(cli, LSA_OPENPOLICY, &buf, &rbuf)) {
- prs_mem_free(&buf);
- prs_mem_free(&rbuf);
- return False;
- }
-
- prs_mem_free(&buf);
-
- if(!lsa_io_r_open_pol("", &r_o, &rbuf, 0)) {
- DEBUG(0,("do_lsa_open_policy: Failed to unmarshall LSA_R_OPEN_POL\n"));
- prs_mem_free(&rbuf);
- return False;
- }
-
- if (!NT_STATUS_IS_OK(r_o.status)) {
- /* report error code */
- DEBUG(0,("LSA_OPENPOLICY: %s\n", get_nt_error_msg(r_o.status)));
- prs_mem_free(&rbuf);
- return False;
- } else {
- /* ok, at last: we're happy. return the policy handle */
- *hnd = r_o.pol;
- }
-
- prs_mem_free(&rbuf);
-
- return True;
-}
-
-/****************************************************************************
-do a LSA Query Info Policy
-****************************************************************************/
-BOOL do_lsa_query_info_pol(struct cli_state *cli,
- POLICY_HND *hnd, uint16 info_class,
- fstring domain_name, DOM_SID *domain_sid)
-{
- prs_struct rbuf;
- prs_struct buf;
- LSA_Q_QUERY_INFO q_q;
- LSA_R_QUERY_INFO r_q;
- fstring sid_str;
-
- ZERO_STRUCTP(domain_sid);
- domain_name[0] = 0;
-
- if (hnd == NULL || domain_name == NULL || domain_sid == NULL)
- return False;
-
- prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
-
- /* create and send a MSRPC command with api LSA_QUERYINFOPOLICY */
-
- DEBUG(4,("LSA Query Info Policy\n"));
-
- /* store the parameters */
- init_q_query(&q_q, hnd, info_class);
-
- /* turn parameters into data stream */
- if(!lsa_io_q_query("", &q_q, &buf, 0)) {
- prs_mem_free(&buf);
- prs_mem_free(&rbuf);
- return False;
- }
-
- /* send the data on \PIPE\ */
- if (!rpc_api_pipe_req(cli, LSA_QUERYINFOPOLICY, &buf, &rbuf)) {
- prs_mem_free(&buf);
- prs_mem_free(&rbuf);
- return False;
- }
-
- prs_mem_free(&buf);
-
- if(!lsa_io_r_query("", &r_q, &rbuf, 0)) {
- prs_mem_free(&rbuf);
- return False;
- }
-
- if (!NT_STATUS_IS_OK(r_q.status)) {
- /* report error code */
- DEBUG(0,("LSA_QUERYINFOPOLICY: %s\n", get_nt_error_msg(r_q.status)));
- prs_mem_free(&rbuf);
- return False;
- }
-
- if (r_q.info_class != q_q.info_class) {
- /* report different info classes */
- DEBUG(0,("LSA_QUERYINFOPOLICY: error info_class (q,r) differ - (%x,%x)\n",
- q_q.info_class, r_q.info_class));
- prs_mem_free(&rbuf);
- return False;
- }
-
- /* ok, at last: we're happy. */
- switch (r_q.info_class) {
- case 3:
- if (r_q.dom.id3.buffer_dom_name != 0) {
- rpcstr_pull(domain_name, r_q.dom.id3.uni_domain_name.buffer, sizeof(domain_name), r_q.dom.id3.uni_domain_name.uni_str_len*2, 0);
- }
- if (r_q.dom.id3.buffer_dom_sid != 0)
- *domain_sid = r_q.dom.id3.dom_sid.sid;
- break;
- case 5:
- if (r_q.dom.id5.buffer_dom_name != 0) {
- rpcstr_pull(domain_name, r_q.dom.id5.uni_domain_name.buffer, sizeof(domain_name), r_q.dom.id5.uni_domain_name.uni_str_len*2, 0);
- }
- if (r_q.dom.id5.buffer_dom_sid != 0)
- *domain_sid = r_q.dom.id5.dom_sid.sid;
- break;
- default:
- DEBUG(3,("LSA_QUERYINFOPOLICY: unknown info class\n"));
- domain_name[0] = 0;
-
- prs_mem_free(&rbuf);
- return False;
- }
-
- sid_to_string(sid_str, domain_sid);
- DEBUG(3,("LSA_QUERYINFOPOLICY (level %x): domain:%s domain sid:%s\n",
- r_q.info_class, domain_name, sid_str));
-
- prs_mem_free(&rbuf);
-
- return True;
-}
-
-/****************************************************************************
-do a LSA Close
-****************************************************************************/
-
-BOOL do_lsa_close(struct cli_state *cli, POLICY_HND *hnd)
-{
- prs_struct rbuf;
- prs_struct buf;
- LSA_Q_CLOSE q_c;
- LSA_R_CLOSE r_c;
-
- if (hnd == NULL)
- return False;
-
- /* create and send a MSRPC command with api LSA_OPENPOLICY */
-
- prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
-
- DEBUG(4,("LSA Close\n"));
-
- /* store the parameters */
- init_lsa_q_close(&q_c, hnd);
-
- /* turn parameters into data stream */
- if(!lsa_io_q_close("", &q_c, &buf, 0)) {
- prs_mem_free(&buf);
- prs_mem_free(&rbuf);
- return False;
- }
-
- /* send the data on \PIPE\ */
- if (!rpc_api_pipe_req(cli, LSA_CLOSE, &buf, &rbuf)) {
- prs_mem_free(&buf);
- prs_mem_free(&rbuf);
- return False;
- }
-
- prs_mem_free(&buf);
-
- if(!lsa_io_r_close("", &r_c, &rbuf, 0)) {
- prs_mem_free(&rbuf);
- return False;
- }
-
- if (!NT_STATUS_IS_OK(r_c.status)) {
- /* report error code */
- DEBUG(0,("LSA_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
- prs_mem_free(&rbuf);
- return False;
- }
-
- /* check that the returned policy handle is all zeros */
-
- if (IVAL(&r_c.pol.data1,0) || IVAL(&r_c.pol.data2,0) || SVAL(&r_c.pol.data3,0) ||
- SVAL(&r_c.pol.data4,0) || IVAL(r_c.pol.data5,0) || IVAL(r_c.pol.data5,4) ) {
- DEBUG(0,("LSA_CLOSE: non-zero handle returned\n"));
- prs_mem_free(&rbuf);
- return False;
- }
-
- prs_mem_free(&rbuf);
-
- return True;
-}
-
-/****************************************************************************
-obtain a server's SAM SID and save it in the secrets database
-****************************************************************************/
-
-BOOL cli_lsa_get_domain_sid(struct cli_state *cli, char *server)
-{
- fstring domain;
- POLICY_HND pol;
- DOM_SID sid;
- BOOL res, res2, res3;
-
- res = cli_nt_session_open(cli, PIPE_LSARPC);
- res2 = res ? do_lsa_open_policy(cli, server, &pol, 0) : False;
- res3 = res2 ? do_lsa_query_info_pol(cli, &pol, 5, domain, &sid) : False;
-
- res3 = res3 ? secrets_store_domain_sid(domain, &sid) : False;
-
- res2 = res2 ? do_lsa_close(cli, &pol) : False;
- cli_nt_session_close(cli);
-
- return res3;
-}
-
-/****************************************************************************
-do a LSA Open Policy
-****************************************************************************/
-NTSTATUS lsa_open_policy(const char *system_name, POLICY_HND *hnd,
- BOOL sec_qos, uint32 des_access)
-{
- prs_struct rbuf;
- prs_struct buf;
- LSA_Q_OPEN_POL q_o;
- LSA_SEC_QOS qos;
- struct cli_connection *con = NULL;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- if (!cli_connection_init(system_name, PIPE_LSARPC, &con)) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (hnd == NULL) return NT_STATUS_UNSUCCESSFUL;
-
- prs_init(&buf, MAX_PDU_FRAG_LEN, NULL, MARSHALL);
- prs_init(&rbuf, 0, NULL, UNMARSHALL);
-
- /* create and send a MSRPC command with api LSA_OPENPOLICY */
-
- DEBUG(4, ("LSA Open Policy\n"));
-
- /* store the parameters */
- if (sec_qos) {
- init_lsa_sec_qos(&qos, 2, 1, 0, des_access);
- init_q_open_pol(&q_o, '\\', 0, des_access, &qos);
- } else {
- init_q_open_pol(&q_o, '\\', 0, des_access, NULL);
- }
-
- /* turn parameters into data stream */
- if (lsa_io_q_open_pol("", &q_o, &buf, 0) &&
- rpc_con_pipe_req(con, LSA_OPENPOLICY, &buf, &rbuf)) {
- LSA_R_OPEN_POL r_o;
- BOOL p;
-
- lsa_io_r_open_pol("", &r_o, &rbuf, 0);
- p = rbuf.data_offset != 0;
-
- result = r_o.status;
-
- if (p && !NT_STATUS_IS_OK(r_o.status)) {
- /* report error code */
- DEBUG(0,
- ("LSA_OPENPOLICY: %s\n",
- get_nt_error_msg(r_o.status)));
- p = False;
- }
-
- if (p) {
-
- /* Return the policy handle */
-
- *hnd = r_o.pol;
-
- if (!RpcHndList_set_connection(hnd, con)) {
- result = NT_STATUS_NO_MEMORY;
- }
- }
- }
-
- prs_mem_free(&rbuf);
- prs_mem_free(&buf);
-
- return result;
-}
-
-/****************************************************************************
-do a LSA Close
-****************************************************************************/
-NTSTATUS lsa_close(POLICY_HND *hnd)
-{
- prs_struct rbuf;
- prs_struct buf;
- LSA_Q_CLOSE q_c;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- if (hnd == NULL) return NT_STATUS_INVALID_PARAMETER;
-
- /* Create and send a MSRPC command with api LSA_OPENPOLICY */
-
- prs_init(&buf, MAX_PDU_FRAG_LEN, NULL, MARSHALL);
- prs_init(&rbuf, 0, NULL, UNMARSHALL);
-
- DEBUG(4, ("LSA Close\n"));
-
- /* Store the parameters */
-
- init_lsa_q_close(&q_c, hnd);
-
- /* Turn parameters into data stream */
-
- if (lsa_io_q_close("", &q_c, &buf, 0) &&
- rpc_hnd_pipe_req(hnd, LSA_CLOSE, &buf, &rbuf)) {
- LSA_R_CLOSE r_c;
- BOOL p;
-
- lsa_io_r_close("", &r_c, &rbuf, 0);
- p = rbuf.data_offset != 0;
- result = r_c.status;
-
- if (p && !NT_STATUS_IS_OK(r_c.status)) {
-
- /* Report error code */
-
- DEBUG(0, ("LSA_CLOSE: %s\n",
- get_nt_error_msg(r_c.status)));
-
- p = False;
- }
-
- }
-
- prs_mem_free(&rbuf);
- prs_mem_free(&buf);
-
- return result;
-}
-
-/****************************************************************************
-do a LSA Lookup SIDs
-****************************************************************************/
-NTSTATUS lsa_lookup_sids(POLICY_HND *hnd, int num_sids, DOM_SID *sids,
- char ***names, uint32 **types, int *num_names)
-{
- prs_struct rbuf;
- prs_struct buf;
- LSA_Q_LOOKUP_SIDS q_l;
- TALLOC_CTX *ctx = talloc_init();
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q_l);
-
- if (hnd == NULL || num_sids == 0 || sids == NULL)
- return NT_STATUS_INVALID_PARAMETER;
-
- if (num_names != NULL) {
- *num_names = 0;
- }
-
- if (types != NULL) {
- *types = NULL;
- }
-
- if (names != NULL) {
- *names = NULL;
- }
-
- prs_init(&buf, MAX_PDU_FRAG_LEN, ctx, MARSHALL);
- prs_init(&rbuf, 0, ctx, UNMARSHALL);
-
- /* Create and send a MSRPC command with api LSA_LOOKUP_SIDS */
-
- DEBUG(4, ("LSA Lookup SIDs\n"));
-
- /* Store the parameters */
-
- init_q_lookup_sids(ctx, &q_l, hnd, num_sids, sids, 1);
-
- /* turn parameters into data stream */
- if (lsa_io_q_lookup_sids("", &q_l, &buf, 0) &&
- rpc_hnd_pipe_req(hnd, LSA_LOOKUPSIDS, &buf, &rbuf)) {
- LSA_R_LOOKUP_SIDS r_l;
- DOM_R_REF ref;
- LSA_TRANS_NAME_ENUM t_names;
- BOOL p, valid_response = False;
-
- r_l.dom_ref = &ref;
- r_l.names = &t_names;
-
- lsa_io_r_lookup_sids("", &r_l, &rbuf, 0);
- p = rbuf.data_offset != 0;
- result = r_l.status;
-
- if (p && !NT_STATUS_IS_OK(r_l.status) &&
- NT_STATUS_V(r_l.status) != 0x107 &&
- NT_STATUS_V(r_l.status) != NT_STATUS_V(NT_STATUS_NONE_MAPPED)) {
- /* Report error code */
-
- DEBUG(1, ("LSA_LOOKUP_SIDS: %s\n",
- get_nt_error_msg(r_l.status)));
-
- return r_l.status;
- }
-
- result = NT_STATUS_OK;
-
- if (p) {
- if (t_names.ptr_trans_names != 0
- && r_l.ptr_dom_ref != 0) {
- valid_response = True;
- }
- }
-
- if (num_names != NULL && valid_response) {
- (*num_names) = t_names.num_entries;
- }
-
- if (valid_response) {
- uint32 i;
-
- for (i = 0; i < t_names.num_entries; i++) {
- if ((t_names.name[i].domain_idx >=
- ref.num_ref_doms_1)
- && (t_names.name[i].domain_idx !=
- 0xffffffff)) {
- DEBUG(0,
- ("LSA_LOOKUP_SIDS: domain index out of bounds\n"));
- valid_response = False;
- break;
- }
- }
- }
-
- if (types != NULL && valid_response && (*num_names) != 0) {
- (*types) = (uint32 *) malloc((*num_names) *
- sizeof(uint32));
- }
-
- if (names != NULL && valid_response && (*num_names) != 0) {
- (*names) = (char **)malloc((*num_names) *
- sizeof(char *));
- }
-
- if (names != NULL && (*names) != NULL) {
- int i;
-
- /* Take each name, construct a \DOMAIN\name string */
-
- for (i = 0; i < (*num_names); i++) {
- fstring name;
- fstring dom_name;
- fstring full_name;
- uint32 dom_idx = t_names.name[i].domain_idx;
-
- if (dom_idx != 0xffffffff) {
- unistr2_to_ascii(dom_name,
- &ref.
- ref_dom[dom_idx].
- uni_dom_name,
- sizeof(dom_name) -
- 1);
- unistr2_to_ascii(name,
- &t_names.uni_name[i],
- sizeof(name) - 1);
-
- memset(full_name, 0,
- sizeof(full_name));
-
- slprintf(full_name,
- sizeof(full_name) - 1,
- "%s\\%s", dom_name, name);
-
- (*names)[i] = strdup(full_name);
- if (types != NULL &&
- (*types) != NULL) {
- (*types)[i] = t_names.name[i].sid_name_use;
- }
- } else {
- (*names)[i] = NULL;
- if (types != NULL &&
- (*types) != NULL) {
- (*types)[i] = SID_NAME_UNKNOWN;
- }
- }
- }
- }
- }
-
- prs_mem_free(&rbuf);
- prs_mem_free(&buf);
-
- return result;
-}
-
-/****************************************************************************
-do a LSA Lookup Names
-****************************************************************************/
-NTSTATUS lsa_lookup_names(POLICY_HND *hnd, int num_names, char **names,
- DOM_SID **sids, uint32 **types, int *num_sids)
-{
- prs_struct rbuf;
- prs_struct buf;
- LSA_Q_LOOKUP_NAMES q_l;
- BOOL valid_response = False;
- TALLOC_CTX *ctx = talloc_init();
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- if (hnd == NULL || num_sids == 0 || sids == NULL)
- return NT_STATUS_INVALID_PARAMETER;
-
- prs_init(&buf, MAX_PDU_FRAG_LEN, ctx, MARSHALL);
- prs_init(&rbuf, 0, ctx, UNMARSHALL);
-
- /* create and send a MSRPC command with api LSA_LOOKUP_NAMES */
-
- DEBUG(4, ("LSA Lookup NAMEs\n"));
-
- /* store the parameters */
- init_q_lookup_names(ctx, &q_l, hnd, num_names, names);
-
- /* turn parameters into data stream */
- if (lsa_io_q_lookup_names("", &q_l, &buf, 0) &&
- rpc_hnd_pipe_req(hnd, LSA_LOOKUPNAMES, &buf, &rbuf)) {
- LSA_R_LOOKUP_NAMES r_l;
- DOM_R_REF ref;
- DOM_RID2 t_rids[MAX_LOOKUP_SIDS];
- BOOL p;
-
- ZERO_STRUCT(ref);
- ZERO_STRUCT(t_rids);
-
- r_l.dom_ref = &ref;
- r_l.dom_rid = t_rids;
-
- lsa_io_r_lookup_names("", &r_l, &rbuf, 0);
- p = rbuf.data_offset != 0;
-
- if (p && !NT_STATUS_IS_OK(r_l.status)) {
- /* report error code */
- DEBUG(1,
- ("LSA_LOOKUP_NAMES: %s\n",
- get_nt_error_msg(r_l.status)));
- p = False;
-
- return r_l.status;
- }
-
- result = r_l.status;
-
- if (p) {
- if (r_l.ptr_dom_ref != 0 && r_l.ptr_entries != 0) {
- valid_response = True;
- }
- }
-
- if (num_sids != NULL && valid_response) {
- (*num_sids) = r_l.num_entries;
- }
-
- if (valid_response) {
- uint32 i;
-
- for (i = 0; i < r_l.num_entries; i++) {
- if (t_rids[i].rid_idx >= ref.num_ref_doms_1 &&
- t_rids[i].rid_idx != 0xffffffff) {
- DEBUG(0,
- ("LSA_LOOKUP_NAMES: domain index %d out of bounds\n",
- t_rids[i].rid_idx));
- valid_response = False;
- break;
- }
- }
- }
-
- if (types != NULL && valid_response && r_l.num_entries != 0) {
- (*types) = (uint32 *) malloc((*num_sids) *
- sizeof(uint32));
- }
-
- if (sids != NULL && valid_response && r_l.num_entries != 0) {
- (*sids) = (DOM_SID *) malloc((*num_sids) *
- sizeof(DOM_SID));
- }
-
- if (sids != NULL && (*sids) != NULL) {
- int i;
-
- /* Take each name, construct a SID */
-
- for (i = 0; i < (*num_sids); i++) {
- uint32 dom_idx = t_rids[i].rid_idx;
- uint32 dom_rid = t_rids[i].rid;
- DOM_SID *sid = &(*sids)[i];
-
- if (dom_idx != 0xffffffff) {
-
- sid_copy(sid,
- &ref.ref_dom[dom_idx].
- ref_dom.sid);
-
- if (dom_rid != 0xffffffff) {
- sid_append_rid(sid, dom_rid);
- }
-
- if (types != NULL &&
- (*types) != NULL) {
- (*types)[i] = t_rids[i].type;
- }
-
- } else {
- ZERO_STRUCTP(sid);
-
- if (types != NULL &&
- (*types) != NULL) {
- (*types)[i] = SID_NAME_UNKNOWN;
- }
- }
- }
- }
- }
-
- prs_mem_free(&rbuf);
- prs_mem_free(&buf);
-
- return result;
-}
diff --git a/source/rpc_client/cli_trust.c b/source/rpc_client/cli_trust.c
index d7faf4975f6..a12f4035eed 100644
--- a/source/rpc_client/cli_trust.c
+++ b/source/rpc_client/cli_trust.c
@@ -36,6 +36,16 @@ static BOOL modify_trust_password( char *domain, char *remote_machine,
{
struct cli_state cli;
NTSTATUS result;
+ DOM_SID domain_sid;
+
+ /*
+ * Ensure we have the domain SID for this domain.
+ */
+
+ if (!secrets_fetch_domain_sid(domain, &domain_sid)) {
+ DEBUG(0, ("domain_client_validate: unable to fetch domain sid.\n"));
+ return False;
+ }
ZERO_STRUCT(cli);
if(cli_initialise(&cli) == NULL) {
@@ -116,13 +126,6 @@ Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
* Now start the NT Domain stuff :-).
*/
- if(cli_lsa_get_domain_sid(&cli, remote_machine) == False) {
- DEBUG(0,("modify_trust_password: unable to obtain domain sid from %s. Error was : %s.\n", remote_machine, cli_errstr(&cli)));
- cli_ulogoff(&cli);
- cli_shutdown(&cli);
- return False;
- }
-
if(cli_nt_session_open(&cli, PIPE_NETLOGON) == False) {
DEBUG(0,("modify_trust_password: unable to open the domain client session to \
machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli)));
diff --git a/source/rpc_client/cli_use.c b/source/rpc_client/cli_use.c
deleted file mode 100644
index 2809f8c69fd..00000000000
--- a/source/rpc_client/cli_use.c
+++ /dev/null
@@ -1,448 +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 "trans2.h"
-
-extern pstring scope;
-extern pstring global_myname;
-
-struct cli_use
-{
- struct cli_state *cli;
- uint32 num_users;
-};
-
-static struct cli_use **clis = NULL;
-static uint32 num_clis = 0;
-
-/****************************************************************************
-terminate client connection
-****************************************************************************/
-static void cli_use_free(struct cli_use *cli)
-{
- if (cli->cli != NULL)
- {
- if (cli->cli->initialised)
- {
- /* only logoff if we have a valid socket */
- if (cli->cli->fd != -1)
- cli_ulogoff(cli->cli);
- cli_shutdown(cli->cli);
- }
- SAFE_FREE(cli->cli);
- }
-
- SAFE_FREE(cli);
-}
-
-/****************************************************************************
-free a client array
-****************************************************************************/
-static void free_cli_array(uint32 num_entries, struct cli_use **entries)
-{
- void (*fn) (void *) = (void (*)(void *))&cli_use_free;
- free_void_array(num_entries, (void **)entries, *fn);
-}
-
-/****************************************************************************
-add a client state to the array
-****************************************************************************/
-static struct cli_use *add_cli_to_array(uint32 *len,
- struct cli_use ***array,
- struct cli_use *cli)
-{
- int i;
- for (i = 0; i < num_clis; i++)
- {
- if (clis[i] == NULL)
- {
- clis[i] = cli;
- return cli;
- }
- }
-
- return (struct cli_use *)add_item_to_array(len,
- (void ***)array,
- (void *)cli);
-
-}
-
-/****************************************************************************
-initiate client array
-****************************************************************************/
-void init_cli_use(void)
-{
- clis = NULL;
- num_clis = 0;
-}
-
-/****************************************************************************
-terminate client array
-****************************************************************************/
-void free_cli_use(void)
-{
- free_cli_array(num_clis, clis);
- init_cli_use();
-}
-
-/****************************************************************************
-find client state. server name, user name, domain name and password must all
-match.
-****************************************************************************/
-static struct cli_use *cli_find(const char *srv_name,
- const struct ntuser_creds *usr_creds,
- BOOL reuse)
-{
- int i;
- const char *sv_name = srv_name;
- struct ntuser_creds null_usr;
-
- if (usr_creds == NULL)
- {
- copy_nt_creds(&null_usr, usr_creds);
- usr_creds = &null_usr;
- }
-
- if (strnequal("\\\\", sv_name, 2))
- {
- sv_name = &sv_name[2];
- }
-
- DEBUG(10, ("cli_find: %s %s %s reuse: %s\n",
- srv_name, usr_creds->user_name, usr_creds->domain,
- BOOLSTR(reuse)));
-
-
- for (i = 0; i < num_clis; i++)
- {
- char *cli_name = NULL;
- struct cli_use *c = clis[i];
-
- if (c == NULL || !c->cli->initialised || c->cli->fd == -1)
- {
- continue;
- }
-
- cli_name = c->cli->desthost;
-
- DEBUG(10, ("cli_find[%d]: %s %s %s\n",
- i, cli_name,
- c->cli->user_name, c->cli->domain));
-
- if (strnequal("\\\\", cli_name, 2))
- {
- cli_name = &cli_name[2];
- }
-
- if (!strequal(cli_name, sv_name))
- {
- continue;
- }
- if (strequal(usr_creds->user_name, "") &&
- strequal(usr_creds->domain, "") &&
- pwd_is_nullpwd(&usr_creds->pwd))
- {
- return c;
- }
- if (!strequal(usr_creds->user_name, c->cli->user_name))
- {
- continue;
- }
- if (!reuse && !pwd_compare(&usr_creds->pwd, &c->cli->pwd))
- {
- DEBUG(100, ("password doesn't match\n"));
- continue;
- }
- if (usr_creds->domain[0] == 0)
- {
- return c;
- }
- if (strequal(usr_creds->domain, c->cli->domain))
- {
- return c;
- }
- }
-
- return NULL;
-}
-
-/****************************************************************************
-create a new client state from user credentials
-****************************************************************************/
-static struct cli_use *cli_use_get(const char *srv_name,
- const struct ntuser_creds *usr_creds)
-{
- struct cli_use *cli = (struct cli_use *)malloc(sizeof(*cli));
-
- if (cli == NULL)
- {
- return NULL;
- }
-
- memset(cli, 0, sizeof(*cli));
-
- cli->cli = cli_initialise(NULL);
-
- if (cli->cli == NULL)
- {
- return NULL;
- }
-
- cli_init_creds(cli->cli, usr_creds);
-
- return cli;
-}
-
-/****************************************************************************
-init client state
-****************************************************************************/
-struct cli_state *cli_net_use_add(const char *srv_name,
- const struct ntuser_creds *usr_creds,
- BOOL reuse, BOOL *is_new)
-{
- struct nmb_name calling;
- struct nmb_name called;
- struct in_addr *dest_ip = NULL;
- fstring dest_host;
- struct in_addr ip;
- struct cli_use *cli;
-
- DEBUG(10, ("cli_net_use_add\n"));
-
- cli = cli_find(srv_name, usr_creds, reuse);
-
- if (cli != NULL)
- {
- cli->num_users++;
- DEBUG(10,
- ("cli_net_use_add: num_users: %d\n", cli->num_users));
- (*is_new) = False;
- return cli->cli;
- }
-
- /* reuse an existing connection requested, and one was not found */
- if (usr_creds != NULL && reuse)
- {
- return False;
- }
-
- /*
- * allocate
- */
-
- cli = cli_use_get(srv_name, usr_creds);
-
- if (resolve_srv_name(srv_name, dest_host, &ip))
- {
- dest_ip = &ip;
- }
- else
- {
- cli_use_free(cli);
- return NULL;
- }
-
- make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
- make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
-
- /*
- * connect
- */
-
- if (!cli_establish_connection(cli->cli,
- dest_host, dest_ip,
- &calling, &called,
- "IPC$", "IPC", False, True))
- {
- DEBUG(0, ("cli_net_use_add: connection failed\n"));
- cli_use_free(cli);
- return NULL;
- }
-
- add_cli_to_array(&num_clis, &clis, cli);
- cli->num_users++;
-
- DEBUG(10, ("cli_net_use_add: num_users: %d\n", cli->num_users));
-
- (*is_new) = True;
-
- return cli->cli;
-}
-
-/****************************************************************************
-delete a client state
-****************************************************************************/
-BOOL cli_net_use_del(const char *srv_name,
- const struct ntuser_creds *usr_creds,
- BOOL force_close, BOOL *connection_closed)
-{
- int i;
- const char *sv_name = srv_name;
-
- DEBUG(10, ("cli_net_use_del: %s. %s. %s. force close: %s\n",
- srv_name,
- usr_creds ? usr_creds->user_name : "",
- usr_creds ? usr_creds->domain : "", BOOLSTR(force_close)));
-
- if (strnequal("\\\\", sv_name, 2))
- {
- sv_name = &sv_name[2];
- }
-
- if (connection_closed != NULL)
- {
- *connection_closed = False;
- }
-
- for (i = 0; i < num_clis; i++)
- {
- char *cli_name = NULL;
-
- if (clis[i] == NULL)
- continue;
- if (clis[i]->cli == NULL)
- continue;
-
- cli_name = clis[i]->cli->desthost;
-
- DEBUG(10, ("connection: %s %s %s\n", cli_name,
- clis[i]->cli->user_name,
- clis[i]->cli->domain));
-
- if (strnequal("\\\\", cli_name, 2))
- {
- cli_name = &cli_name[2];
- }
-
- if (!strequal(cli_name, sv_name))
- continue;
-
- if (strequal(usr_creds ? usr_creds->user_name : "",
- clis[i]->cli->user_name) &&
- strequal(usr_creds ? usr_creds->domain : "",
- clis[i]->cli->domain))
- {
- /* 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)
- {
- cli_use_free(clis[i]);
- clis[i] = NULL;
- if (connection_closed != NULL)
- {
- *connection_closed = True;
- }
- }
- return True;
- }
- }
-
- return False;
-}
-
-/****************************************************************************
-enumerate client states
-****************************************************************************/
-void cli_net_use_enum(uint32 *num_cons, struct use_info ***use)
-{
- int i;
-
- *num_cons = 0;
- *use = NULL;
-
- for (i = 0; i < num_clis; i++)
- {
- struct use_info item;
-
- ZERO_STRUCT(item);
-
- if (clis[i] == NULL)
- continue;
-
- item.connected = clis[i]->cli != NULL ? True : False;
-
- if (item.connected)
- {
- item.srv_name = clis[i]->cli->desthost;
- item.user_name = clis[i]->cli->user_name;
- item.key = clis[i]->cli->key;
- item.domain = clis[i]->cli->domain;
- }
-
- add_use_info_to_array(num_cons, use, &item);
- }
-}
-
-
-/****************************************************************************
-wait for keyboard activity, swallowing network packets on all client states.
-****************************************************************************/
-void cli_use_wait_keyboard(void)
-{
- fd_set fds;
- struct timeval timeout;
-
- while (1)
- {
- int i;
- int maxfd = fileno(stdin);
- FD_ZERO(&fds);
- FD_SET(fileno(stdin), &fds);
- for (i = 0; i < num_clis; i++)
- {
- if (clis[i] != NULL && clis[i]->cli != NULL)
- {
- int fd = clis[i]->cli->fd;
- FD_SET(fd, &fds);
- maxfd = MAX(fd, maxfd);
- }
- }
-
- timeout.tv_sec = 20;
- timeout.tv_usec = 0;
- sys_select(maxfd + 1, &fds, &timeout);
-
- if (FD_ISSET(fileno(stdin), &fds))
- return;
-
- /* We deliberately use receive_smb instead of
- client_receive_smb as we want to receive
- session keepalives and then drop them here.
- */
- for (i = 0; i < num_clis; i++)
- {
- int fd;
- if (clis[i] == NULL || clis[i]->cli == NULL)
- continue;
- fd = clis[i]->cli->fd;
- if (FD_ISSET(fd, &fds))
- receive_smb(fd, clis[i]->cli->inbuf, 0);
- }
- }
-}
diff --git a/source/rpc_client/ncacn_np_use.c b/source/rpc_client/ncacn_np_use.c
deleted file mode 100644
index 137be635f7e..00000000000
--- a/source/rpc_client/ncacn_np_use.c
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- SMB client generic functions
- Copyright (C) Andrew Tridgell 1994-2000
- Copyright (C) Luke Kenneth Casson Leighton 1996-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.
-*/
-
-#define NO_SYSLOG
-
-#include "includes.h"
-#include "rpc_parse.h"
-#include "trans2.h"
-
-extern pstring global_myname;
-
-struct ncacn_np_use
-{
- struct ncacn_np *cli;
- uint32 num_users;
-};
-
-static struct ncacn_np_use **msrpcs = NULL;
-static uint32 num_msrpcs = 0;
-
-/****************************************************************************
-terminate client connection
-****************************************************************************/
-static void ncacn_np_shutdown(struct ncacn_np *cli)
-{
- struct ntuser_creds usr;
- BOOL closed;
-
- if (cli != NULL)
- {
- if (cli->smb != NULL)
- {
- if (cli->smb->initialised)
- {
- /* cli_nt_session_close(cli->smb, cli->fnum); JERRY */
- cli_nt_session_close(cli->smb);
- }
- create_ntc_from_cli_state(&usr, cli->smb);
- cli_net_use_del(cli->smb->desthost, &usr, False, &closed);
- }
- }
-}
-
-static BOOL ncacn_np_establish_connection(struct ncacn_np *cli,
- const char *srv_name,
- const struct ntuser_creds *ntc,
- const char *pipe_name,
- BOOL reuse)
-{
- BOOL new_smb_conn;
- cli->smb = cli_net_use_add(srv_name, ntc,
- True, &new_smb_conn);
- if (cli->smb == NULL)
- {
- return False;
- }
- /* if (!cli_nt_session_open(cli->smb, pipe_name, &cli->fnum)) by JERRY */
- if (!cli_nt_session_open(cli->smb, pipe_name))
- {
- cli_net_use_del(srv_name, ntc, False, NULL);
- return False;
- }
- fstrcpy(cli->pipe_name, pipe_name);
- return True;
-}
-
-
-
-/****************************************************************************
-terminate client connection
-****************************************************************************/
-static void ncacn_np_use_free(struct ncacn_np_use *cli)
-{
- if (cli->cli != NULL)
- {
- if (cli->cli->initialised)
- {
- ncacn_np_shutdown(cli->cli);
- }
- ZERO_STRUCTP(cli->cli);
- SAFE_FREE(cli->cli);
- }
- ZERO_STRUCTP(cli);
- SAFE_FREE(cli);
-}
-
-/****************************************************************************
-add a client state to the array
-****************************************************************************/
-static struct ncacn_np_use *add_ncacn_np_to_array(uint32 * len,
- struct ncacn_np_use
- ***array,
- struct ncacn_np_use *cli)
-{
-
- int i;
-
- /* traverse the list and try to find a previously
- allocate spot that is not being used */
- for (i = 0; i < num_msrpcs; i++)
- {
- if (msrpcs[i] == NULL)
- {
- /* found and empty spot to
- store the cli pointer */
- msrpcs[i] = cli;
- return cli;
- }
- }
-
- return (struct ncacn_np_use *)add_item_to_array(len,
- (void ***)array,
- (void *)cli);
-
-}
-
-
-
-/****************************************************************************
-delete a client state
-****************************************************************************/
-BOOL ncacn_np_use_del(const char *srv_name, const char *pipe_name,
- const vuser_key * key,
- BOOL force_close, BOOL *connection_closed)
-{
- int i;
- DEBUG(10, ("ncacn_np_net_use_del: %s. force close: %s ",
- pipe_name, BOOLSTR(force_close)));
- if (key != NULL)
- {
- DEBUG(10, ("[%d,%x]", key->pid, key->vuid));
- }
- DEBUG(10, ("\n"));
-
- if (connection_closed != NULL)
- {
- *connection_closed = False;
- }
-
- if (strnequal("\\PIPE\\", pipe_name, 6))
- {
- pipe_name = &pipe_name[6];
- }
-
- if (strnequal("\\\\", srv_name, 2))
- {
- srv_name = &srv_name[2];
- }
-
- for (i = 0; i < num_msrpcs; i++)
- {
- char *ncacn_np_name = NULL;
- char *ncacn_np_srv_name = NULL;
- struct ncacn_np_use *c = msrpcs[i];
- vuser_key k;
-
- if (c == NULL || c->cli == NULL || c->cli->smb == NULL)
- continue;
-
- ncacn_np_name = c->cli->pipe_name;
- ncacn_np_srv_name = c->cli->smb->desthost;
-
- k = c->cli->smb->key;
-
- DEBUG(10, ("use_del[%d]: %s %s %s %s [%d,%x]\n",
- i, ncacn_np_name, ncacn_np_srv_name,
- c->cli->smb->user_name,
- c->cli->smb->domain, k.pid, k.vuid));
-
- if (strnequal("\\PIPE\\", ncacn_np_name, 6))
- {
- ncacn_np_name = &ncacn_np_name[6];
- }
- if (!strequal(ncacn_np_name, pipe_name))
- {
- continue;
- }
- if (strnequal("\\\\", ncacn_np_srv_name, 2))
- {
- ncacn_np_srv_name = &ncacn_np_srv_name[2];
- }
- if (!strequal(ncacn_np_srv_name, srv_name))
- {
- continue;
- }
- if (key->pid != k.pid || key->vuid != k.vuid)
- {
- continue;
- }
- /* decrement number of users */
- c->num_users--;
- DEBUG(10, ("idx: %i num_users now: %d\n",
- i, c->num_users));
- if (force_close || c->num_users == 0)
- {
- ncacn_np_use_free(c);
- msrpcs[i] = NULL;
- if (connection_closed != NULL)
- {
- *connection_closed = True;
- }
- }
- return True;
- }
-
- return False;
-}
-
-/****************************************************************************
-find client state. server name, user name, domain name and password must all
-match.
-****************************************************************************/
-static struct ncacn_np_use *ncacn_np_find(const char *srv_name,
- const char *pipe_name,
- const vuser_key * key,
- const struct ntuser_creds
- *usr_creds, BOOL reuse)
-{
- int i;
- const char *sv_name = srv_name;
-
- if (strnequal("\\PIPE\\", pipe_name, 6))
- {
- pipe_name = &pipe_name[6];
- }
-
- if (strnequal("\\\\", sv_name, 2))
- {
- sv_name = &sv_name[2];
- }
-
- if (usr_creds != NULL)
- {
- DEBUG(10, ("ncacn_np_find: %s %s %s",
- srv_name, usr_creds->user_name, usr_creds->domain));
- }
- else
- {
- DEBUG(10,("ncacn_np_find: %s (no creds)\n", srv_name));
- }
-
- if (key != NULL)
- {
- DEBUG(10, ("[%d,%x]", key->pid, key->vuid));
- }
- DEBUG(10, ("\n"));
-
- for (i = 0; i < num_msrpcs; i++)
- {
- char *ncacn_np_srv_name = NULL;
- struct ncacn_np_use *c = msrpcs[i];
- vuser_key k;
-
- char *ncacn_np_name = NULL;
-
- if (c == NULL || c->cli == NULL || c->cli->smb == NULL ||
- c->cli->smb->fd == -1 ||
- !c->cli->initialised)
- {
- continue;
- }
-
- ncacn_np_name = c->cli->pipe_name;
- ncacn_np_srv_name = c->cli->smb->desthost;
-
- k = c->cli->smb->key;
-
- DEBUG(10, ("ncacn_np_find[%d]: %s %s %s %s [%d,%x]\n",
- i, ncacn_np_name, ncacn_np_srv_name,
- c->cli->smb->user_name,
- c->cli->smb->domain, k.pid, k.vuid));
-
- if (strnequal("\\\\", ncacn_np_srv_name, 2))
- {
- ncacn_np_srv_name = &ncacn_np_srv_name[2];
- }
-
- if (strnequal("\\PIPE\\", ncacn_np_name, 6))
- {
- ncacn_np_name = &ncacn_np_name[6];
- }
-
- if (!strequal(ncacn_np_name, pipe_name))
- {
- continue;
- }
- if (!strequal(ncacn_np_srv_name, sv_name))
- {
- continue;
- }
- if (key != NULL && (k.pid != key->pid || k.vuid != key->vuid))
- {
- continue;
- }
- if (usr_creds == NULL)
- {
- if (reuse)
- {
- return c;
- }
- else
- {
- continue;
- }
- }
- if (!strequal
- (usr_creds->user_name, c->cli->smb->user_name))
- {
- continue;
- }
- if (!reuse
- && !pwd_compare(&usr_creds->pwd, &c->cli->smb->pwd))
- {
- DEBUG(100, ("password doesn't match\n"));
- continue;
- }
- if (usr_creds->domain[0] == 0)
- return c;
-
- if (strequal(usr_creds->domain, c->cli->smb->domain))
- return c;
- }
-
- return NULL;
-}
-
-
-/****************************************************************************
-initialise a msrpcent structure
-****************************************************************************/
-struct ncacn_np *ncacn_np_initialise(struct ncacn_np *msrpc,
- const vuser_key * key)
-{
- if (!msrpc)
- {
- msrpc = (struct ncacn_np *)malloc(sizeof(*msrpc));
- if (!msrpc)
- return NULL;
- ZERO_STRUCTP(msrpc);
- }
-
- if (msrpc->initialised)
- {
- ncacn_np_shutdown(msrpc);
- }
-
- ZERO_STRUCTP(msrpc);
-
- msrpc->fnum = -1;
- msrpc->initialised = 1;
-
- return msrpc;
-}
-
-/****************************************************************************
-create a new client state from user credentials
-****************************************************************************/
-static struct ncacn_np_use *ncacn_np_use_get(const char *pipe_name,
- const vuser_key * key)
-{
- struct ncacn_np_use *cli =
- (struct ncacn_np_use *)malloc(sizeof(*cli));
-
- if (cli == NULL)
- {
- return NULL;
- }
-
- memset(cli, 0, sizeof(*cli));
-
- cli->cli = ncacn_np_initialise(NULL, key);
-
- if (cli->cli == NULL)
- {
- return NULL;
- }
-
- return cli;
-}
-
-/****************************************************************************
-init client state
-****************************************************************************/
-struct ncacn_np *ncacn_np_use_add(const char *pipe_name,
- const vuser_key * key,
- const char *srv_name,
- const struct ntuser_creds *ntc,
- BOOL reuse, BOOL *is_new_connection)
-{
- struct ncacn_np_use *cli;
- DEBUG(10, ("ncacn_np_use_add: %s\n", pipe_name));
-
- (*is_new_connection) = False;
- cli = ncacn_np_find(srv_name, pipe_name, key, ntc, reuse);
-
- if (cli != NULL)
- {
- cli->num_users++;
- return cli->cli;
- }
-
- /*
- * allocate
- */
-
- (*is_new_connection) = True;
-
- cli = ncacn_np_use_get(pipe_name, key);
-
- if (!ncacn_np_establish_connection
- (cli->cli, srv_name, ntc, pipe_name, True))
- {
- DEBUG(0, ("ncacn_np_use_add: connection failed\n"));
- cli->cli = NULL;
- ncacn_np_use_free(cli);
- return NULL;
- }
-
- if (key != NULL)
- {
- cli->cli->smb->key = *key;
- }
- else
- {
- cli->cli->smb->key.pid = sys_getpid();
- cli->cli->smb->key.vuid = UID_FIELD_INVALID;
- }
-
- add_ncacn_np_to_array(&num_msrpcs, &msrpcs, cli);
- cli->num_users++;
- return cli->cli;
-}