summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-11-16 19:11:17 +0000
committerJeremy Allison <jra@samba.org>2001-11-16 19:11:17 +0000
commit2eeddeaa39e27268ae1b5854203e81d9ff3ea6af (patch)
tree94c5bf7e3c326ad92b0876aa2d474c28d98c3a57
parent9b41dddeb802b224c7405f8c214a0e942c6408ad (diff)
downloadsamba-2eeddeaa39e27268ae1b5854203e81d9ff3ea6af.tar.gz
samba-2eeddeaa39e27268ae1b5854203e81d9ff3ea6af.tar.xz
samba-2eeddeaa39e27268ae1b5854203e81d9ff3ea6af.zip
Did the same removal as I just did in HEAD. Lots of unused code deleted.
Jeremy.
-rw-r--r--source/Makefile.in8
-rw-r--r--source/lib/util_list.c111
-rw-r--r--source/rpc_client/cli_connect.c396
-rw-r--r--source/rpc_client/cli_lsarpc.c696
-rw-r--r--source/rpc_client/cli_trust.c17
-rw-r--r--source/rpc_client/cli_use.c449
-rw-r--r--source/rpc_client/ncacn_np_use.c459
-rw-r--r--source/rpc_parse/parse_creds.c622
8 files changed, 13 insertions, 2745 deletions
diff --git a/source/Makefile.in b/source/Makefile.in
index b3f23ba8a0e..0ac977f5d31 100644
--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -158,13 +158,11 @@ RPC_PARSE_OBJ = rpc_parse/parse_lsa.o rpc_parse/parse_net.o \
rpc_parse/parse_reg.o rpc_parse/parse_rpc.o \
rpc_parse/parse_samr.o rpc_parse/parse_srv.o \
rpc_parse/parse_wks.o \
- rpc_parse/parse_spoolss.o rpc_parse/parse_dfs.o \
- rpc_parse/parse_creds.o
+ rpc_parse/parse_spoolss.o rpc_parse/parse_dfs.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 \
+ rpc_client/cli_login.o \
+ rpc_client/cli_spoolss_notify.o \
lib/util_list.o rpc_client/cli_trust.o
LOCKING_OBJ = locking/locking.o locking/brlock.o locking/posix.o
diff --git a/source/lib/util_list.c b/source/lib/util_list.c
index 0175a7c8a16..d3bf2ee1625 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 eqivalent 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 betweeen 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);
- 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/rpc_client/cli_connect.c b/source/rpc_client/cli_connect.c
deleted file mode 100644
index b1606ae3345..00000000000
--- a/source/rpc_client/cli_connect.c
+++ /dev/null
@@ -1,396 +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 "rpc_client.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 0
- if (!rpc_pipe_bind(con->pCli_state, pipe_name, global_myname))
- {
- DEBUG(0, ("rpc_pipe_bind failed\n"));
- cli_connection_free(con);
- return NULL;
- }
-#endif
- }
- 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);
- } */
-
- if (con->srv_name != NULL)
- {
- free(con->srv_name);
- con->srv_name = NULL;
- }
- if (con->pipe_name != NULL)
- {
- free(con->pipe_name);
- con->pipe_name = NULL;
- }
-
- if (con->auth_info != NULL)
- {
- free(con->auth_info);
- con->auth_info = NULL;
- }
-
- 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;
- }
- }
-
- 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 23e709214fc..00000000000
--- a/source/rpc_client/cli_lsarpc.c
+++ /dev/null
@@ -1,696 +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 (r_o.status != 0) {
- /* 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 (r_q.status != 0) {
- /* 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) {
- char *dom_name = dos_unistrn2(r_q.dom.id3.uni_domain_name.buffer,
- r_q.dom.id3.uni_domain_name.uni_str_len);
- fstrcpy(domain_name, dom_name);
- }
- 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) {
- char *dom_name = dos_unistrn2(r_q.dom.id5.uni_domain_name.buffer,
- r_q.dom.id5.uni_domain_name.uni_str_len);
- fstrcpy(domain_name, dom_name);
- }
- 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 (r_c.status != 0) {
- /* 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
-****************************************************************************/
-uint32 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;
- uint32 result = 0;
-
- 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 && r_o.status != 0) {
- /* 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
-****************************************************************************/
-uint32 lsa_close(POLICY_HND *hnd)
-{
- prs_struct rbuf;
- prs_struct buf;
- LSA_Q_CLOSE q_c;
- uint32 result = 0;
-
- if (hnd == NULL) return False;
-
- /* 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 && r_c.status != 0) {
-
- /* 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
-****************************************************************************/
-uint32 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();
- uint32 result = 0;
-
- ZERO_STRUCT(q_l);
-
- if (hnd == NULL || num_sids == 0 || sids == NULL) return False;
-
- 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 && r_l.status != 0 &&
- r_l.status != 0x107 &&
- r_l.status != (0xC0000000 | 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
-****************************************************************************/
-uint32 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();
- uint32 result = 0;
-
- if (hnd == NULL || num_sids == 0 || sids == NULL) return False;
-
- 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 && r_l.status != 0) {
- /* 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 440cc5143a2..6fb21fa5988 100644
--- a/source/rpc_client/cli_trust.c
+++ b/source/rpc_client/cli_trust.c
@@ -35,6 +35,16 @@ static BOOL modify_trust_password( char *domain, char *remote_machine,
unsigned char new_trust_passwd_hash[16])
{
struct cli_state cli;
+ 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) {
@@ -115,13 +125,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 ee6e7ea8abf..00000000000
--- a/source/rpc_client/cli_use.c
+++ /dev/null
@@ -1,449 +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"
-#include "rpc_client.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);
- }
- free(cli->cli);
- }
-
- 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((struct pwd_info *)&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 7eec2fd44c6..00000000000
--- a/source/rpc_client/ncacn_np_use.c
+++ /dev/null
@@ -1,459 +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 "rpc_client.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, (char *)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);
- free(cli->cli);
- }
- ZERO_STRUCTP(cli);
- 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((struct pwd_info *)&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;
-}
-
-
-
diff --git a/source/rpc_parse/parse_creds.c b/source/rpc_parse/parse_creds.c
deleted file mode 100644
index 36e08f5746e..00000000000
--- a/source/rpc_parse/parse_creds.c
+++ /dev/null
@@ -1,622 +0,0 @@
-/*
- * Unix SMB/Netbios implementation.
- * Version 1.9.
- * RPC Pipe client / server routines
- * Copyright (C) Andrew Tridgell 1992-1999,
- * Copyright (C) Luke Kenneth Casson Leighton 1996-1999,
- * Copyright (C) Paul Ashton 1997-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, Cambgrpsge, MA 02139, USA.
- */
-
-#include "includes.h"
-
-/*******************************************************************
-makes a CREDS_UNIX structure.
-********************************************************************/
-BOOL make_creds_unix(CREDS_UNIX *r_u, const char* user_name,
- const char* requested_name,
- const char* real_name,
- BOOL guest)
-{
- if (r_u == NULL) return False;
-
- DEBUG(5,("make_creds_unix\n"));
-
- fstrcpy(r_u->user_name , user_name);
- fstrcpy(r_u->requested_name, requested_name);
- fstrcpy(r_u->real_name , real_name);
- r_u->guest = guest;
-
- return True;
-}
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-BOOL creds_io_unix(char *desc, CREDS_UNIX *r_u, prs_struct *ps, int depth)
-{
- if (r_u == NULL) return False;
-
- prs_debug(ps, depth, desc, "creds_io_unix");
- depth++;
-
- prs_align(ps);
- prs_string("user_name", ps, depth, r_u->user_name, strlen(r_u->user_name), sizeof(r_u->user_name));
- prs_align(ps);
- prs_string("requested_name", ps, depth, r_u->requested_name, strlen(r_u->requested_name), sizeof(r_u->requested_name));
- prs_align(ps);
- prs_string("real_name", ps, depth, r_u->real_name, strlen(r_u->real_name), sizeof(r_u->real_name));
- prs_align(ps);
- prs_uint32("guest", ps, depth, (uint32 *)&(r_u->guest));
- return True;
-}
-
-
-/*******************************************************************
-frees a structure.
-********************************************************************/
-void creds_free_unix(CREDS_UNIX *r_u)
-{
-}
-
-/*******************************************************************
-makes a CREDS_UNIX_SEC structure.
-********************************************************************/
-BOOL make_creds_unix_sec(CREDS_UNIX_SEC *r_u,
- uint32 uid, uint32 gid, uint32 num_grps, gid_t *grps)
-{
- int i;
- if (r_u == NULL) return False;
-
- DEBUG(5,("make_creds_unix_sec\n"));
-
- r_u->uid = uid;
- r_u->gid = gid;
- r_u->num_grps = num_grps;
- r_u->grps = (uint32*)malloc(sizeof(r_u->grps[0]) * r_u->num_grps);
- if (r_u->grps == NULL && num_grps != 0)
- {
- return False;
- }
- for (i = 0; i < num_grps; i++)
- {
- r_u->grps[i] = (gid_t)grps[i];
- }
-
- return True;
-}
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-BOOL creds_io_unix_sec(char *desc, CREDS_UNIX_SEC *r_u, prs_struct *ps, int depth)
-{
- uint32 i;
-
- if (r_u == NULL) return False;
-
- prs_debug(ps, depth, desc, "creds_io_unix_sec");
- depth++;
-
- prs_align(ps);
-
- prs_uint32("uid", ps, depth, &(r_u->uid));
- prs_uint32("gid", ps, depth, &(r_u->gid));
- prs_uint32("num_grps", ps, depth, (uint32 *)&(r_u->num_grps));
- if (r_u->num_grps != 0)
- {
- uint32 *tgr;
-
- tgr = (uint32*)Realloc(r_u->grps,
- sizeof(r_u->grps[0]) *
- r_u->num_grps);
- if (tgr == NULL)
- {
- creds_free_unix_sec(r_u);
- return False;
- }
- else r_u->grps = tgr;
- }
- for (i = 0; i < r_u->num_grps; i++)
- {
- prs_uint32("", ps, depth, &(r_u->grps[i]));
- }
- return True;
-}
-
-
-/*******************************************************************
-frees a structure.
-********************************************************************/
-void creds_free_unix_sec(CREDS_UNIX_SEC *r_u)
-{
- SAFE_FREE(r_u->grps);
-}
-
-/*******************************************************************
-makes a CREDS_NT_SEC structure.
-********************************************************************/
-BOOL make_creds_nt_sec(CREDS_NT_SEC *r_u,
- DOM_SID *sid, uint32 num_grps, uint32 *grps)
-{
- int i;
- if (r_u == NULL) return False;
-
- DEBUG(5,("make_creds_unix_sec\n"));
-
- sid_copy(&r_u->sid, sid);
- r_u->num_grps = num_grps;
- r_u->grp_rids = (uint32*)malloc(sizeof(r_u->grp_rids[0]) * r_u->num_grps);
-
- if (r_u->grp_rids == NULL && num_grps != 0)
- {
- return False;
- }
- for (i = 0; i < num_grps; i++)
- {
- r_u->grp_rids[i] = grps[i];
- }
-
- return True;
-}
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-BOOL creds_io_nt_sec(char *desc, CREDS_NT_SEC *r_u, prs_struct *ps, int depth)
-{
- int i;
- if (r_u == NULL) return False;
-
- prs_debug(ps, depth, desc, "creds_io_nt");
- depth++;
-
- prs_align(ps);
-
- smb_io_dom_sid ("sid", &r_u->sid, ps, depth);
- prs_align(ps);
-
- prs_uint32("num_grps", ps, depth, &(r_u->num_grps));
- if (r_u->num_grps != 0)
- {
- uint32 *tgrid;
-
- tgrid = (uint32*)Realloc(r_u->grp_rids,
- sizeof(r_u->grp_rids[0]) *
- r_u->num_grps);
- if (tgrid == NULL)
- {
- creds_free_nt_sec(r_u);
- return False;
- }
- else r_u->grp_rids = tgrid;
- }
- for (i = 0; i < r_u->num_grps; i++)
- {
- prs_uint32("", ps, depth, &(r_u->grp_rids[i]));
- }
-
- return True;
-}
-
-/*******************************************************************
-frees a structure.
-********************************************************************/
-void creds_free_nt_sec(CREDS_NT_SEC *r_u)
-{
- SAFE_FREE(r_u->grp_rids);
-}
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-BOOL creds_io_pwd_info(char *desc, struct pwd_info *pwd, prs_struct *ps, int depth)
-{
- if (pwd == NULL) return False;
-
- prs_debug(ps, depth, desc, "creds_io_pwd_info");
- depth++;
-
- prs_align(ps);
-
- prs_uint32("nullpwd", ps, depth, (uint32 *)&(pwd->null_pwd));
- if (pwd->null_pwd)
- {
- return True;
- }
-
- prs_uint32("cleartext", ps, depth, (uint32 *)&(pwd->cleartext));
- if (pwd->cleartext)
- {
- prs_string("password", ps, depth, pwd->password, strlen(pwd->password), sizeof(pwd->password));
- prs_align(ps);
- return True;
- }
- prs_uint32("crypted", ps, depth, (uint32 *)&(pwd->crypted));
-
- prs_uint8s(False, "smb_lm_pwd", ps, depth, (unsigned char*)&pwd->smb_lm_pwd, sizeof(pwd->smb_lm_pwd));
- prs_align(ps);
- prs_uint8s(False, "smb_nt_pwd", ps, depth, (unsigned char*)&pwd->smb_nt_pwd, sizeof(pwd->smb_nt_pwd));
- prs_align(ps);
-
- prs_uint8s(False, "smb_lm_owf", ps, depth, (unsigned char*)&pwd->smb_lm_owf, sizeof(pwd->smb_lm_owf));
- prs_align(ps);
- prs_uint32("nt_owf_len", ps, depth, &(pwd->nt_owf_len));
- if (pwd->nt_owf_len > sizeof(pwd->smb_nt_owf))
- {
- return False;
- }
- prs_uint8s(False, "smb_nt_owf", ps, depth, (unsigned char*)&pwd->smb_nt_owf, pwd->nt_owf_len);
- prs_align(ps);
-
- prs_uint8s(False, "lm_cli_chal", ps, depth, (unsigned char*)&pwd->lm_cli_chal, sizeof(pwd->lm_cli_chal));
- prs_align(ps);
- prs_uint32("nt_cli_chal_len", ps, depth, &(pwd->nt_cli_chal_len));
-
- if (pwd->nt_cli_chal_len > sizeof(pwd->nt_cli_chal))
- {
- return False;
- }
- prs_uint8s(False, "nt_cli_chal", ps, depth, (unsigned char*)&pwd->nt_cli_chal, pwd->nt_cli_chal_len);
- prs_align(ps);
-
- return True;
-}
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-BOOL creds_io_nt(char *desc, CREDS_NT *r_u, prs_struct *ps, int depth)
-{
- if (r_u == NULL) return False;
-
- prs_debug(ps, depth, desc, "creds_io_nt");
- depth++;
-
- prs_align(ps);
-
- /* lkclXXXX CHEAT!!!!!!!! */
- prs_string("user_name", ps, depth, r_u->user_name, strlen(r_u->user_name), sizeof(r_u->user_name));
- prs_align(ps);
- prs_string("domain", ps, depth, r_u->domain, strlen(r_u->domain), sizeof(r_u->domain));
- prs_align(ps);
-
- creds_io_pwd_info("pwd", &r_u->pwd, ps, depth);
- prs_align(ps);
-
- prs_uint32("ntlmssp", ps, depth, &(r_u->ntlmssp_flags));
-
- return True;
-}
-
-/*******************************************************************
-frees a structure.
-********************************************************************/
-void creds_free_nt(CREDS_NT *r_u)
-{
-}
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-BOOL creds_io_hybrid(char *desc, CREDS_HYBRID *r_u, prs_struct *ps, int depth)
-{
- if (r_u == NULL) return False;
-
- prs_debug(ps, depth, desc, "creds_io_hybrid");
- depth++;
-
- prs_align(ps);
-
- prs_uint32("reuse", ps, depth, (uint32 *)&(r_u->reuse));
-
- prs_uint32("ptr_ntc", ps, depth, &(r_u->ptr_ntc));
- prs_uint32("ptr_uxc", ps, depth, &(r_u->ptr_uxc));
- prs_uint32("ptr_nts", ps, depth, &(r_u->ptr_nts));
- prs_uint32("ptr_uxs", ps, depth, &(r_u->ptr_uxs));
- prs_uint32("ptr_ssk", ps, depth, &(r_u->ptr_ssk));
- if (r_u->ptr_ntc != 0)
- {
- if (!creds_io_nt ("ntc", &r_u->ntc, ps, depth)) return False;
- }
- if (r_u->ptr_uxc != 0)
- {
- if (!creds_io_unix("uxc", &r_u->uxc, ps, depth)) return False;
- }
- if (r_u->ptr_nts != 0)
- {
- if (!creds_io_nt_sec ("nts", &r_u->nts, ps, depth)) return False;
- }
- if (r_u->ptr_uxs != 0)
- {
- if (!creds_io_unix_sec("uxs", &r_u->uxs, ps, depth)) return False;
- }
- if (r_u->ptr_ssk != 0)
- {
- prs_uint8s(False, "usr_sess_key", ps, depth, (unsigned char*)&r_u->usr_sess_key, sizeof(r_u->usr_sess_key));
- }
- else
- {
- memset(r_u->usr_sess_key, 0, sizeof(r_u->usr_sess_key));
- }
- return True;
-}
-
-void copy_unix_creds(CREDS_UNIX *to, const CREDS_UNIX *from)
-{
- if (from == NULL)
- {
- to->user_name[0] = 0;
- return;
- }
- fstrcpy(to->user_name, from->user_name);
-}
-
-void copy_nt_sec_creds(CREDS_NT_SEC *to, const CREDS_NT_SEC *from)
-{
- if (from == NULL)
- {
- ZERO_STRUCTP(to);
- return;
- }
- sid_copy(&to->sid, &from->sid);
- to->num_grps = 0;
- to->grp_rids = NULL;
-
- if (from->num_grps != 0)
- {
- size_t size = from->num_grps * sizeof(from->grp_rids[0]);
- to->grp_rids = (uint32*)malloc(size);
- if (to->grp_rids == NULL)
- {
- return;
- }
- to->num_grps = from->num_grps;
- memcpy(to->grp_rids, from->grp_rids, size);
- }
-}
-
-void copy_unix_sec_creds(CREDS_UNIX_SEC *to, const CREDS_UNIX_SEC *from)
-{
- if (from == NULL)
- {
- to->uid = -1;
- to->gid = -1;
- to->num_grps = 0;
- to->grps = NULL;
- return;
- }
- to->uid = from->uid;
- to->gid = from->gid;
- to->num_grps = 0;
- to->grps = NULL;
-
- if (from->num_grps != 0)
- {
- size_t size = from->num_grps * sizeof(from->grps[0]);
- to->grps = (uint32*)malloc(size);
- if (to->grps == NULL)
- {
- return;
- }
- to->num_grps = from->num_grps;
- memcpy(to->grps, from->grps, size);
- }
-}
-
-void create_ntc_from_cli_state (CREDS_NT *to, const struct cli_state *cli_from)
-{
- /*
- * NULL credentials --
- * if this gets executed, it is a programming error.
- * fall through to copy_nt_creds()
- */
- if (cli_from == NULL)
- {
- copy_nt_creds (to, NULL);
- return;
- }
-
- safe_strcpy(to->domain , cli_from->domain , sizeof(cli_from->domain )-1);
- safe_strcpy(to->user_name, cli_from->user_name, sizeof(cli_from->user_name)-1);
- memcpy(&to->pwd, &cli_from->pwd, sizeof(cli_from->pwd));
- to->ntlmssp_flags = cli_from->ntlmssp_flags;
- DEBUG(10,("create_ntc_fromcli_state: user %s domain %s flgs: %x\n",
- to->user_name, to->domain,
- to->ntlmssp_flags));
-
-}
-
-
-void copy_nt_creds(struct ntuser_creds *to,
- const struct ntuser_creds *from)
-{
- if (from == NULL)
- {
- DEBUG(10,("copy_nt_creds: null creds\n"));
- to->domain[0] = 0;
- to->user_name[0] = 0;
- pwd_set_nullpwd(&to->pwd);
- to->ntlmssp_flags = 0;
-
- return;
- }
- safe_strcpy(to->domain , from->domain , sizeof(from->domain )-1);
- safe_strcpy(to->user_name, from->user_name, sizeof(from->user_name)-1);
- memcpy(&to->pwd, &from->pwd, sizeof(from->pwd));
- to->ntlmssp_flags = from->ntlmssp_flags;
- DEBUG(10,("copy_nt_creds: user %s domain %s flgs: %x\n",
- to->user_name, to->domain,
- to->ntlmssp_flags));
-}
-
-void copy_user_creds(struct user_creds *to,
- const struct user_creds *from)
-{
- ZERO_STRUCTP(to);
- if (from == NULL)
- {
- to->ptr_ntc = 0;
- to->ptr_uxc = 0;
- to->ptr_nts = 0;
- to->ptr_uxs = 0;
- to->ptr_ssk = 0;
- copy_nt_creds(&to->ntc, NULL);
- copy_unix_creds(&to->uxc, NULL);
- copy_nt_sec_creds(&to->nts, NULL);
- copy_unix_sec_creds(&to->uxs, NULL);
- to->reuse = False;
- return;
- }
-
- to->reuse = from->reuse;
-
- to->ptr_nts = from->ptr_nts;
- to->ptr_uxs = from->ptr_uxs;
- to->ptr_ntc = from->ptr_ntc;
- to->ptr_uxc = from->ptr_uxc;
- to->ptr_ssk = from->ptr_ssk;
-
- if (to->ptr_ntc != 0)
- {
- copy_nt_creds(&to->ntc, &from->ntc);
- }
- if (to->ptr_uxc != 0)
- {
- copy_unix_creds(&to->uxc, &from->uxc);
- }
- if (to->ptr_nts != 0)
- {
- copy_nt_sec_creds(&to->nts, &from->nts);
- }
- if (to->ptr_uxs != 0)
- {
- copy_unix_sec_creds(&to->uxs, &from->uxs);
- }
- if (to->ptr_ssk != 0)
- {
- memcpy(to->usr_sess_key, from->usr_sess_key,
- sizeof(to->usr_sess_key));
- }
-}
-
-void free_user_creds(struct user_creds *creds)
-{
- creds_free_unix(&creds->uxc);
- creds_free_nt (&creds->ntc);
- creds_free_unix_sec(&creds->uxs);
- creds_free_nt_sec (&creds->nts);
-}
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-BOOL creds_io_cmd(char *desc, CREDS_CMD *r_u, prs_struct *ps, int depth)
-{
- if (r_u == NULL) return False;
-
- prs_debug(ps, depth, desc, "creds_io_cmd");
- depth++;
-
- prs_align(ps);
-
- prs_uint16("version", ps, depth, &(r_u->version));
- prs_uint16("command", ps, depth, &(r_u->command));
- prs_uint32("pid ", ps, depth, &(r_u->pid ));
-
- prs_string("name ", ps, depth, r_u->name, strlen(r_u->name), sizeof(r_u->name));
- prs_align(ps);
-
- prs_uint32("ptr_creds", ps, depth, &(r_u->ptr_creds));
- if (r_u->ptr_creds != 0)
- {
- if (!creds_io_hybrid("creds", r_u->cred, ps, depth))
- {
- return False;
- }
- }
-
-
- return True;
-}
-
-
-BOOL create_ntuser_creds( prs_struct *ps,
- const char* name,
- uint16 version, uint16 command,
- uint32 pid,
- const struct ntuser_creds *ntu,
- BOOL reuse)
-{
- CREDS_CMD cmd;
- struct user_creds usr;
-
- ZERO_STRUCT(cmd);
- ZERO_STRUCT(usr);
-
- DEBUG(10,("create_user_creds: %s %d %d\n",
- name, version, command));
-
- usr.reuse = reuse;
-
- fstrcpy(cmd.name, name);
- cmd.version = version;
- cmd.command = command;
- cmd.pid = pid ;
- cmd.ptr_creds = ntu != NULL ? 1 : 0;
- cmd.cred = &usr;
-
- if (ntu != NULL)
- {
- copy_nt_creds(&usr.ntc, ntu);
- usr.ptr_ntc = 1;
- }
- else
- {
- usr.ptr_ntc = 0;
- }
-
- prs_init(ps, 1024, NULL, MARSHALL);
-
- ps->data_offset = 4;
- return creds_io_cmd("creds", &cmd, ps, 0);
-}
-
-BOOL create_user_creds( prs_struct *ps,
- const char* name,
- uint16 version, uint16 command,
- uint32 pid,
- struct user_creds *usr)
-{
- CREDS_CMD cmd;
-
- ZERO_STRUCT(cmd);
-
- DEBUG(10,("create_user_creds: %s %d %d\n",
- name, version, command));
-
- fstrcpy(cmd.name, name);
- cmd.version = version;
- cmd.command = command;
- cmd.pid = pid ;
- cmd.ptr_creds = usr != NULL ? 1 : 0;
- cmd.cred = usr;
-
- prs_init(ps, 1024, NULL, MARSHALL);
-
- ps->data_offset = 4;
- return creds_io_cmd("creds", &cmd, ps, 0);
-}