rpc_client/cli_netlogon_sync.o \
rpc_client/cli_reg.o \
rpc_client/cli_pipe.o \
+ rpc_client/cli_connect.o \
rpc_client/cli_spoolss.o \
rpc_client/cli_lsarpc.o \
rpc_client/cli_wkssvc.o \
/*The following definitions come from lib/util_hnd.c */
BOOL init_policy_hnd(int num_pol_hnds);
+BOOL register_policy_hnd(POLICY_HND *hnd);
BOOL open_policy_hnd(POLICY_HND *hnd);
-int find_policy_by_hnd(POLICY_HND *hnd);
+int find_policy_by_hnd(const POLICY_HND *hnd);
BOOL set_policy_samr_rid(POLICY_HND *hnd, uint32 rid);
BOOL set_policy_samr_pol_status(POLICY_HND *hnd, uint32 pol_status);
BOOL set_policy_samr_sid(POLICY_HND *hnd, DOM_SID *sid);
BOOL get_policy_reg_name(POLICY_HND *hnd, fstring name);
BOOL set_policy_cli_state(POLICY_HND *hnd, struct cli_state *cli, uint16 fnum,
void (*free_fn)(struct cli_state *, uint16));
-BOOL get_policy_cli_state(POLICY_HND *hnd, struct cli_state **cli, uint16 *fnum);
+BOOL get_policy_cli_state(const POLICY_HND *hnd, struct cli_state **cli,
+ uint16 *fnum);
BOOL close_policy_hnd(POLICY_HND *hnd);
/*The following definitions come from lib/util_pwdb.c */
BOOL cli_unlink(struct cli_state *cli, char *fname);
BOOL cli_mkdir(struct cli_state *cli, char *dname);
BOOL cli_rmdir(struct cli_state *cli, char *dname);
-int cli_nt_create(struct cli_state *cli, char *fname);
-int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode);
+int cli_nt_create(struct cli_state *cli, const char *fname);
+int cli_open(struct cli_state *cli, const char *fname,
+ int flags, int share_mode);
BOOL cli_close(struct cli_state *cli, int fnum);
BOOL cli_lock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout);
BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout);
const char *server_name, uint32 switch_value,
void *id);
+/*The following definitions come from rpc_client/cli_connect.c */
+
+void cli_state_free(struct cli_state *cli, uint16 fnum);
+BOOL cli_state_init(const char* server_name, const char* pipe_name,
+ struct cli_state **cli,
+ uint16 *fnum);
+BOOL cli_state_get(const POLICY_HND *pol,
+ struct cli_state **cli,
+ uint16 *fnum);
+
/*The following definitions come from rpc_client/cli_eventlog.c */
BOOL do_event_open(struct cli_state *cli, uint16 fnum, char *log, POLICY_HND *hnd);
BOOL get_trust_sid_and_domain(const char* myname, char *server,
DOM_SID *sid,
char *domain, size_t len);
-BOOL lsa_open_policy(struct cli_state *cli, uint16 fnum,
- const char *server_name, POLICY_HND *hnd,
+BOOL lsa_open_policy(const char *server_name, POLICY_HND *hnd,
BOOL sec_qos);
-BOOL lsa_open_policy2(struct cli_state *cli, uint16 fnum,
- const char *server_name, POLICY_HND *hnd,
+BOOL lsa_open_policy2( const char *server_name, POLICY_HND *hnd,
BOOL sec_qos);
-BOOL lsa_open_secret(struct cli_state *cli, uint16 fnum,
- const POLICY_HND *hnd_pol,
+BOOL lsa_open_secret( const POLICY_HND *hnd,
const char *secret_name,
uint32 des_access,
POLICY_HND *hnd_secret);
-BOOL lsa_query_secret(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, STRING2 *enc_secret,
+BOOL lsa_query_secret(POLICY_HND *hnd, STRING2 *secret,
NTTIME *last_update);
-BOOL lsa_lookup_names(struct cli_state *cli, uint16 fnum,
- POLICY_HND *hnd,
+BOOL lsa_lookup_names( POLICY_HND *hnd,
int num_names,
char **names,
DOM_SID **sids,
uint8 **types,
int *num_sids);
-BOOL lsa_lookup_sids(struct cli_state *cli, uint16 fnum,
- POLICY_HND *hnd,
+BOOL lsa_lookup_sids(POLICY_HND *hnd,
int num_sids,
DOM_SID **sids,
char ***names,
uint8 **types,
int *num_names);
-BOOL lsa_query_info_pol(struct cli_state *cli, uint16 fnum,
- POLICY_HND *hnd, uint16 info_class,
+BOOL lsa_query_info_pol(POLICY_HND *hnd, uint16 info_class,
fstring domain_name, DOM_SID *domain_sid);
-BOOL lsa_enum_trust_dom(struct cli_state *cli, uint16 fnum,
- POLICY_HND *hnd, uint32 *enum_ctx,
+BOOL lsa_enum_trust_dom(POLICY_HND *hnd, uint32 *enum_ctx,
uint32 *num_doms, char ***names,
DOM_SID ***sids);
-BOOL lsa_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd);
+BOOL lsa_close(POLICY_HND *hnd);
/*The following definitions come from rpc_client/cli_netlogon.c */
BOOL rpc_api_pipe_req(struct cli_state *cli, uint16 fnum, uint8 op_num,
prs_struct *data, prs_struct *rdata);
void cli_nt_set_ntlmssp_flgs(struct cli_state *cli, uint32 ntlmssp_flgs);
-BOOL cli_nt_session_open(struct cli_state *cli, char *pipe_name, uint16* fnum);
+BOOL cli_nt_session_open(struct cli_state *cli, const char *pipe_name,
+ uint16* fnum);
void cli_nt_session_close(struct cli_state *cli, uint16 fnum);
/*The following definitions come from rpc_client/cli_reg.c */
/*The following definitions come from rpc_client/msrpc_lsarpc.c */
-BOOL msrpc_lsa_query_secret(struct cli_state *cli,
+BOOL msrpc_lsa_query_secret(const char* srv_name,
const char* secret_name,
STRING2 *secret,
NTTIME *last_update);
{
struct cli_state cli;
POLICY_HND lsa_pol;
- uint16 fnum_lsa;
fstring srv_name;
+ extern struct cli_state *rpc_smb_cli;
BOOL res3 = True;
BOOL res4 = True;
uint8 *types;
char *names[1];
+ rpc_smb_cli = &cli;
+
DEBUG(5,("lookup_remote_ntname: %s\n", ntname));
if (!cli_connect_serverlist(&cli, lp_passwordserver()))
fstrcat(srv_name, cli.desthost);
strupper(srv_name);
- /* open LSARPC session. */
- res3 = res3 ? cli_nt_session_open(&cli, PIPE_LSARPC, &fnum_lsa) : False;
-
/* lookup domain controller; receive a policy handle */
- res3 = res3 ? lsa_open_policy(&cli, fnum_lsa,
- srv_name,
+ res3 = res3 ? lsa_open_policy( srv_name,
&lsa_pol, True) : False;
/* send lsa lookup sids call */
- res4 = res3 ? lsa_lookup_names(&cli, fnum_lsa,
- &lsa_pol,
+ res4 = res3 ? lsa_lookup_names( &lsa_pol,
1, names,
&sids, &types, &num_sids) : False;
- res3 = res3 ? lsa_close(&cli, fnum_lsa, &lsa_pol) : False;
-
- cli_nt_session_close(&cli, fnum_lsa);
+ res3 = res3 ? lsa_close(&lsa_pol) : False;
if (res4 && res3 && sids != NULL && types != NULL)
{
/****************************************************************************
find first available policy slot. creates a policy handle for you.
****************************************************************************/
-BOOL open_policy_hnd(POLICY_HND *hnd)
+BOOL register_policy_hnd(POLICY_HND *hnd)
{
int i;
struct policy *p;
p->pnum = i;
p->type = POL_NO_INFO;
- create_pol_hnd(hnd);
memcpy(&p->pol_hnd, hnd, sizeof(*hnd));
bitmap_set(bmap, i);
return True;
}
+/****************************************************************************
+ find first available policy slot. creates a policy handle for you.
+****************************************************************************/
+BOOL open_policy_hnd(POLICY_HND *hnd)
+{
+ create_pol_hnd(hnd);
+ return register_policy_hnd(hnd);
+}
+
/****************************************************************************
find policy by handle
****************************************************************************/
-static struct policy *find_policy(POLICY_HND *hnd)
+static struct policy *find_policy(const POLICY_HND *hnd)
{
struct policy *p;
for (p=Policy;p;p=p->next) {
if (memcmp(&p->pol_hnd, hnd, sizeof(*hnd)) == 0) {
DEBUG(4,("Found policy hnd[%x] ", p->pnum));
- dump_data(4, (char *)hnd->data, sizeof(hnd->data));
+ dump_data(4, (const char *)hnd->data,
+ sizeof(hnd->data));
return p;
}
}
DEBUG(4,("Policy not found: "));
- dump_data(4, (char *)hnd->data, sizeof(hnd->data));
+ dump_data(4, (const char *)hnd->data, sizeof(hnd->data));
return NULL;
}
/****************************************************************************
find policy index by handle
****************************************************************************/
-int find_policy_by_hnd(POLICY_HND *hnd)
+int find_policy_by_hnd(const POLICY_HND *hnd)
{
struct policy *p = find_policy(hnd);
/****************************************************************************
get cli state
****************************************************************************/
-BOOL get_policy_cli_state(POLICY_HND *hnd, struct cli_state **cli, uint16 *fnum)
+BOOL get_policy_cli_state(const POLICY_HND *hnd, struct cli_state **cli,
+ uint16 *fnum)
{
struct policy *p = find_policy(hnd);
#include "includes.h"
#include "trans2.h"
-
extern int DEBUGLEVEL;
/*
/****************************************************************************
open a file
****************************************************************************/
-int cli_nt_create(struct cli_state *cli, char *fname)
+int cli_nt_create(struct cli_state *cli, const char *fname)
{
char *p;
/****************************************************************************
open a file
****************************************************************************/
-int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode)
+int cli_open(struct cli_state *cli, const char *fname,
+ int flags, int share_mode)
{
char *p;
unsigned openfn=0;
return True;
}
+
extern int DEBUGLEVEL;
+extern struct cli_state *rpc_smb_cli;
/****************************************************************************
obtain the sid from the PDC. do some verification along the way...
BOOL get_domain_sids(const char *myname,
DOM_SID *sid3, DOM_SID *sid5, char *servers)
{
- uint16 nt_pipe_fnum;
POLICY_HND pol;
fstring srv_name;
struct cli_state cli;
fstring dom3;
fstring dom5;
+ rpc_smb_cli = &cli;
+
if (sid3 == NULL && sid5 == NULL)
{
/* don't waste my time... */
fstrcat(srv_name, myname);
strupper(srv_name);
- /* open LSARPC session. */
- res = res ? cli_nt_session_open(&cli, PIPE_LSARPC, &nt_pipe_fnum) : False;
-
/* lookup domain controller; receive a policy handle */
- res = res ? lsa_open_policy(&cli, nt_pipe_fnum, srv_name, &pol, False) : False;
+ res = res ? lsa_open_policy(srv_name, &pol, False) : False;
if (sid3 != NULL)
{
/* send client info query, level 3. receive domain name and sid */
- res = res ? lsa_query_info_pol(&cli, nt_pipe_fnum, &pol, 3, dom3, sid3) : False;
+ res = res ? lsa_query_info_pol(&pol, 3, dom3, sid3) : False;
}
if (sid5 != NULL)
{
/* send client info query, level 5. receive domain name and sid */
- res = res ? lsa_query_info_pol(&cli, nt_pipe_fnum, &pol, 5, dom5, sid5) : False;
+ res = res ? lsa_query_info_pol(&pol, 5, dom5, sid5) : False;
}
/* close policy handle */
- res = res ? lsa_close(&cli, nt_pipe_fnum, &pol) : False;
+ res = res ? lsa_close(&pol) : False;
/* close the session */
- cli_nt_session_close(&cli, nt_pipe_fnum);
cli_ulogoff(&cli);
cli_shutdown(&cli);
DOM_SID *sid,
char *domain, size_t len)
{
- uint16 nt_pipe_fnum;
POLICY_HND pol;
fstring srv_name;
struct cli_state cli;
fstring dom3;
fstring dom5;
+ rpc_smb_cli = &cli;
+
if (!cli_connect_serverlist(&cli, server))
{
DEBUG(0,("get_trust_sid: unable to initialise client connection.\n"));
fstrcat(srv_name, myname);
strupper(srv_name);
- /* open LSARPC session. */
- res = res ? cli_nt_session_open(&cli, PIPE_LSARPC, &nt_pipe_fnum) : False;
-
/* lookup domain controller; receive a policy handle */
- res = res ? lsa_open_policy(&cli, nt_pipe_fnum, srv_name, &pol, False) : False;
+ res = res ? lsa_open_policy(srv_name, &pol, False) : False;
/* send client info query, level 3. receive domain name and sid */
- res1 = res ? lsa_query_info_pol(&cli, nt_pipe_fnum, &pol, 3, dom3, &sid3) : False;
+ res1 = res ? lsa_query_info_pol(&pol, 3, dom3, &sid3) : False;
/* send client info query, level 5. receive domain name and sid */
- res1 = res1 ? lsa_query_info_pol(&cli, nt_pipe_fnum, &pol, 5, dom5, &sid5) : False;
+ res1 = res1 ? lsa_query_info_pol(&pol, 5, dom5, &sid5) : False;
/* close policy handle */
- res = res ? lsa_close(&cli, nt_pipe_fnum, &pol) : False;
+ res = res ? lsa_close(&pol) : False;
/* close the session */
- cli_nt_session_close(&cli, nt_pipe_fnum);
cli_ulogoff(&cli);
cli_shutdown(&cli);
/****************************************************************************
do a LSA Open Policy
****************************************************************************/
-BOOL lsa_open_policy(struct cli_state *cli, uint16 fnum,
- const char *server_name, POLICY_HND *hnd,
+BOOL lsa_open_policy(const char *server_name, POLICY_HND *hnd,
BOOL sec_qos)
{
prs_struct rbuf;
LSA_Q_OPEN_POL q_o;
LSA_SEC_QOS qos;
BOOL valid_pol = False;
+ struct cli_state *cli = NULL;
+ uint16 fnum = 0xffff;
+
+ if (!cli_state_init(server_name, PIPE_LSARPC, &cli, &fnum))
+ {
+ return False;
+ }
if (hnd == NULL) return False;
{
/* ok, at last: we're happy. return the policy handle */
memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
- valid_pol = True;
+
+ valid_pol = register_policy_hnd(hnd) &&
+ set_policy_cli_state(hnd, cli, fnum,
+ cli_state_free);
}
}
/****************************************************************************
do a LSA Open Policy2
****************************************************************************/
-BOOL lsa_open_policy2(struct cli_state *cli, uint16 fnum,
- const char *server_name, POLICY_HND *hnd,
+BOOL lsa_open_policy2( const char *server_name, POLICY_HND *hnd,
BOOL sec_qos)
{
prs_struct rbuf;
LSA_SEC_QOS qos;
BOOL valid_pol = False;
+ struct cli_state *cli = NULL;
+ uint16 fnum = 0xffff;
+
+ if (!cli_state_init(server_name, PIPE_LSARPC, &cli, &fnum))
+ {
+ return False;
+ }
+
if (hnd == NULL) return False;
prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
{
/* ok, at last: we're happy. return the policy handle */
memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
- valid_pol = True;
+ valid_pol = register_policy_hnd(hnd) &&
+ set_policy_cli_state(hnd, cli, fnum,
+ cli_state_free);
}
}
/****************************************************************************
do a LSA Open Secret
****************************************************************************/
-BOOL lsa_open_secret(struct cli_state *cli, uint16 fnum,
- const POLICY_HND *hnd_pol,
+BOOL lsa_open_secret( const POLICY_HND *hnd,
const char *secret_name,
uint32 des_access,
POLICY_HND *hnd_secret)
LSA_Q_OPEN_SECRET q_o;
BOOL valid_pol = False;
- if (hnd_pol == NULL) return False;
+ struct cli_state *cli = NULL;
+ uint16 fnum = 0xffff;
+
+ if (!cli_state_get(hnd, &cli, &fnum))
+ {
+ return False;
+ }
+
+ if (hnd == NULL) return False;
prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
DEBUG(4,("LSA Open Secret\n"));
- make_q_open_secret(&q_o, hnd_pol, secret_name, des_access);
+ make_q_open_secret(&q_o, hnd, secret_name, des_access);
/* turn parameters into data stream */
lsa_io_q_open_secret("", &q_o, &buf, 0);
/****************************************************************************
do a LSA Query Secret
****************************************************************************/
-BOOL lsa_query_secret(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, STRING2 *enc_secret,
+BOOL lsa_query_secret(POLICY_HND *hnd, STRING2 *secret,
NTTIME *last_update)
{
prs_struct rbuf;
LSA_Q_QUERY_SECRET q_q;
BOOL valid_info = False;
- if (pol == NULL) return False;
+ struct cli_state *cli = NULL;
+ uint16 fnum = 0xffff;
+
+ if (!cli_state_get(hnd, &cli, &fnum))
+ {
+ return False;
+ }
+
+ if (hnd == NULL) return False;
prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
DEBUG(4,("LSA Query Secret\n"));
- make_q_query_secret(&q_q, pol);
+ make_q_query_secret(&q_q, hnd);
/* turn parameters into data stream */
lsa_io_q_query_secret("", &q_q, &buf, 0);
(r_q.info.value.ptr_secret != 0) &&
(r_q.info.ptr_update != 0))
{
- memcpy(enc_secret, &(r_q.info.value.enc_secret), sizeof(STRING2));
+ STRING2 enc_secret;
+ memcpy(&enc_secret, &(r_q.info.value.enc_secret), sizeof(STRING2));
memcpy(last_update, &(r_q.info.last_update), sizeof(NTTIME));
- valid_info = True;
+ valid_info = nt_decrypt_string2(secret, &enc_secret,
+ (char*)(cli->pwd.smb_nt_pwd));
}
}
/****************************************************************************
do a LSA Lookup Names
****************************************************************************/
-BOOL lsa_lookup_names(struct cli_state *cli, uint16 fnum,
- POLICY_HND *hnd,
+BOOL lsa_lookup_names( POLICY_HND *hnd,
int num_names,
char **names,
DOM_SID **sids,
LSA_Q_LOOKUP_NAMES q_l;
BOOL valid_response = False;
+ struct cli_state *cli = NULL;
+ uint16 fnum = 0xffff;
+
+ if (!cli_state_get(hnd, &cli, &fnum))
+ {
+ return False;
+ }
+
if (hnd == NULL || num_sids == 0 || sids == NULL) return False;
prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
/****************************************************************************
do a LSA Lookup SIDs
****************************************************************************/
-BOOL lsa_lookup_sids(struct cli_state *cli, uint16 fnum,
- POLICY_HND *hnd,
+BOOL lsa_lookup_sids(POLICY_HND *hnd,
int num_sids,
DOM_SID **sids,
char ***names,
LSA_Q_LOOKUP_SIDS q_l;
BOOL valid_response = False;
+ struct cli_state *cli = NULL;
+ uint16 fnum = 0xffff;
+
+ if (!cli_state_get(hnd, &cli, &fnum))
+ {
+ return False;
+ }
+
ZERO_STRUCT(q_l);
if (hnd == NULL || num_sids == 0 || sids == NULL) return False;
/****************************************************************************
do a LSA Query Info Policy
****************************************************************************/
-BOOL lsa_query_info_pol(struct cli_state *cli, uint16 fnum,
- POLICY_HND *hnd, uint16 info_class,
+BOOL lsa_query_info_pol(POLICY_HND *hnd, uint16 info_class,
fstring domain_name, DOM_SID *domain_sid)
{
prs_struct rbuf;
LSA_Q_QUERY_INFO q_q;
BOOL valid_response = False;
+ struct cli_state *cli = NULL;
+ uint16 fnum = 0xffff;
+
+ if (!cli_state_get(hnd, &cli, &fnum))
+ {
+ return False;
+ }
+
ZERO_STRUCTP(domain_sid);
domain_name[0] = 0;
/****************************************************************************
do a LSA Enumerate Trusted Domain
****************************************************************************/
-BOOL lsa_enum_trust_dom(struct cli_state *cli, uint16 fnum,
- POLICY_HND *hnd, uint32 *enum_ctx,
+BOOL lsa_enum_trust_dom(POLICY_HND *hnd, uint32 *enum_ctx,
uint32 *num_doms, char ***names,
DOM_SID ***sids)
{
LSA_Q_ENUM_TRUST_DOM q_q;
BOOL valid_response = False;
+ struct cli_state *cli = NULL;
+ uint16 fnum = 0xffff;
+
+ if (!cli_state_get(hnd, &cli, &fnum))
+ {
+ return False;
+ }
+
if (hnd == NULL || num_doms == NULL || names == NULL) return False;
prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
/****************************************************************************
do a LSA Close
****************************************************************************/
-BOOL lsa_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
+BOOL lsa_close(POLICY_HND *hnd)
{
prs_struct rbuf;
prs_struct buf;
LSA_Q_CLOSE q_c;
- BOOL valid_close = False;
+ BOOL valid_close = False;
+
+ struct cli_state *cli = NULL;
+ uint16 fnum = 0xffff;
+
+ if (!cli_state_get(hnd, &cli, &fnum))
+ {
+ return False;
+ }
if (hnd == NULL) return False;
prs_mem_free(&rbuf);
prs_mem_free(&buf );
+ close_policy_hnd(hnd);
+
return valid_close;
}
****************************************************************************/
static BOOL rpc_pipe_set_hnd_state(struct cli_state *cli, uint16 fnum,
- char *pipe_name, uint16 device_state)
+ const char *pipe_name, uint16 device_state)
{
BOOL state_set = False;
char param[2];
check the rpc bind acknowledge response
****************************************************************************/
-static BOOL valid_pipe_name(char *pipe_name, RPC_IFACE *abstract, RPC_IFACE *transfer)
+static BOOL valid_pipe_name(const char *pipe_name,
+ RPC_IFACE *abstract, RPC_IFACE *transfer)
{
int pipe_idx = 0;
check the rpc bind acknowledge response
****************************************************************************/
-static BOOL check_bind_response(RPC_HDR_BA *hdr_ba, char *pipe_name, RPC_IFACE *transfer)
+static BOOL check_bind_response(RPC_HDR_BA *hdr_ba, const char *pipe_name,
+ RPC_IFACE *transfer)
{
int i = 0;
****************************************************************************/
static BOOL rpc_pipe_bind(struct cli_state *cli, uint16 fnum,
- char *pipe_name,
+ const char *pipe_name,
RPC_IFACE *abstract, RPC_IFACE *transfer,
char *my_name)
{
open a session
****************************************************************************/
-BOOL cli_nt_session_open(struct cli_state *cli, char *pipe_name, uint16* fnum)
+BOOL cli_nt_session_open(struct cli_state *cli, const char *pipe_name,
+ uint16* fnum)
{
RPC_IFACE abstract;
RPC_IFACE transfer;
/****************************************************************************
nt lsa query secret
****************************************************************************/
-BOOL msrpc_lsa_query_secret(struct cli_state *cli,
+BOOL msrpc_lsa_query_secret(const char* srv_name,
const char* secret_name,
STRING2 *secret,
NTTIME *last_update)
{
- uint16 nt_pipe_fnum;
- fstring srv_name;
BOOL res = True;
BOOL res1;
BOOL res2;
POLICY_HND pol_sec;
POLICY_HND lsa_pol;
- STRING2 enc_secret;
-
- fstrcpy(srv_name, "\\\\");
- fstrcat(srv_name, cli->desthost);
- strupper(srv_name);
-
- /* open LSARPC session. */
- res = res ? cli_nt_session_open(cli, PIPE_LSARPC, &nt_pipe_fnum) : False;
/* lookup domain controller; receive a policy handle */
- res = res ? lsa_open_policy2(cli, nt_pipe_fnum,
- srv_name,
+ res = res ? lsa_open_policy2( srv_name,
&lsa_pol, False) : False;
/* lookup domain controller; receive a policy handle */
- res1 = res ? lsa_open_secret(cli, nt_pipe_fnum,
- &lsa_pol,
+ res1 = res ? lsa_open_secret( &lsa_pol,
secret_name, 0x02000000, &pol_sec) : False;
- res2 = res1 ? lsa_query_secret(cli, nt_pipe_fnum,
- &pol_sec, &enc_secret, last_update) : False;
-
- res1 = res1 ? lsa_close(cli, nt_pipe_fnum, &pol_sec) : False;
-
- res = res ? lsa_close(cli, nt_pipe_fnum, &lsa_pol) : False;
+ res2 = res1 ? lsa_query_secret(&pol_sec, secret, last_update) : False;
- /* close the session */
- cli_nt_session_close(cli, nt_pipe_fnum);
+ res1 = res1 ? lsa_close(&pol_sec) : False;
- res2 = res2 ? nt_decrypt_string2(secret, &enc_secret, (char*)(cli->pwd.smb_nt_pwd)) : False;
+ res = res ? lsa_close(&lsa_pol) : False;
return res2;
}
if (res3 && num_aliases != 0)
{
fstring srv_name;
- uint16 fnum_lsa;
POLICY_HND lsa_pol;
uint32 i;
add_sid_to_array(&numsids, sids, &sid_mem[i].sid);
}
- /* open LSARPC session. */
- res3 = res3 ? cli_nt_session_open(cli, PIPE_LSARPC, &fnum_lsa) : False;
-
/* lookup domain controller; receive a policy handle */
- res3 = res3 ? lsa_open_policy(cli, fnum_lsa,
- srv_name,
+ res3 = res3 ? lsa_open_policy( srv_name,
&lsa_pol, True) : False;
/* send lsa lookup sids call */
- res4 = res3 ? lsa_lookup_sids(cli, fnum_lsa,
- &lsa_pol,
+ res4 = res3 ? lsa_lookup_sids( &lsa_pol,
num_aliases, *sids,
name, type, num_names) : False;
- res3 = res3 ? lsa_close(cli, fnum_lsa, &lsa_pol) : False;
-
- cli_nt_session_close(cli, fnum_lsa);
+ res3 = res3 ? lsa_close(&lsa_pol) : False;
}
if (!res4)
/****************************************************************************
find first available policy slot. creates a policy handle for you.
****************************************************************************/
-BOOL open_policy_hnd(POLICY_HND *hnd)
+BOOL register_policy_hnd(POLICY_HND *hnd)
{
int i;
struct policy *p;
p->pnum = i;
p->type = POL_NO_INFO;
- create_pol_hnd(hnd);
memcpy(&p->pol_hnd, hnd, sizeof(*hnd));
bitmap_set(bmap, i);
return True;
}
+/****************************************************************************
+ find first available policy slot. creates a policy handle for you.
+****************************************************************************/
+BOOL open_policy_hnd(POLICY_HND *hnd)
+{
+ create_pol_hnd(hnd);
+ return register_policy_hnd(hnd);
+}
+
/****************************************************************************
find policy by handle
****************************************************************************/
-static struct policy *find_policy(POLICY_HND *hnd)
+static struct policy *find_policy(const POLICY_HND *hnd)
{
struct policy *p;
for (p=Policy;p;p=p->next) {
if (memcmp(&p->pol_hnd, hnd, sizeof(*hnd)) == 0) {
DEBUG(4,("Found policy hnd[%x] ", p->pnum));
- dump_data(4, (char *)hnd->data, sizeof(hnd->data));
+ dump_data(4, (const char *)hnd->data,
+ sizeof(hnd->data));
return p;
}
}
DEBUG(4,("Policy not found: "));
- dump_data(4, (char *)hnd->data, sizeof(hnd->data));
+ dump_data(4, (const char *)hnd->data, sizeof(hnd->data));
return NULL;
}
/****************************************************************************
find policy index by handle
****************************************************************************/
-int find_policy_by_hnd(POLICY_HND *hnd)
+int find_policy_by_hnd(const POLICY_HND *hnd)
{
struct policy *p = find_policy(hnd);
/****************************************************************************
get cli state
****************************************************************************/
-BOOL get_policy_cli_state(POLICY_HND *hnd, struct cli_state **cli, uint16 *fnum)
+BOOL get_policy_cli_state(const POLICY_HND *hnd, struct cli_state **cli,
+ uint16 *fnum)
{
struct policy *p = find_policy(hnd);
extern FILE* out_hnd;
-extern struct cli_state *smb_cli;
-extern int smb_tidx;
-
/****************************************************************************
nt enumerate trusted domains
****************************************************************************/
void cmd_lsa_enum_trust_dom(struct client_info *info, int argc, char *argv[])
{
- uint16 nt_pipe_fnum;
fstring srv_name;
uint32 num_doms = 0;
char **domains = NULL;
DEBUG(4,("cmd_lsa_enum_trust_dom: server:%s\n", srv_name));
- /* open LSARPC session. */
- res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC, &nt_pipe_fnum) : False;
-
/* lookup domain controller; receive a policy handle */
- res = res ? lsa_open_policy(smb_cli, nt_pipe_fnum,
- srv_name,
+ res = res ? lsa_open_policy( srv_name,
&info->dom.lsa_info_pol, False) : False;
do
{
/* send enum trusted domains query */
- res = res ? lsa_enum_trust_dom(smb_cli, nt_pipe_fnum,
- &info->dom.lsa_info_pol,
+ res = res ? lsa_enum_trust_dom( &info->dom.lsa_info_pol,
&enum_ctx,
&num_doms, &domains, &sids) : False;
} while (res && enum_ctx != 0);
- res = res ? lsa_close(smb_cli, nt_pipe_fnum, &info->dom.lsa_info_pol) : False;
-
- /* close the session */
- cli_nt_session_close(smb_cli, nt_pipe_fnum);
+ res = res ? lsa_close(&info->dom.lsa_info_pol) : False;
if (res)
{
****************************************************************************/
void cmd_lsa_query_info(struct client_info *info, int argc, char *argv[])
{
- uint16 nt_pipe_fnum;
fstring srv_name;
BOOL res = True;
DEBUG(4,("cmd_lsa_query_info: server:%s\n", srv_name));
- DEBUG(5, ("cmd_lsa_query_info: smb_cli->fd:%d\n", smb_cli->fd));
-
- /* open LSARPC session. */
- res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC, &nt_pipe_fnum) : False;
-
/* lookup domain controller; receive a policy handle */
- res = res ? lsa_open_policy(smb_cli, nt_pipe_fnum,
- srv_name,
+ res = res ? lsa_open_policy( srv_name,
&info->dom.lsa_info_pol, False) : False;
/* send client info query, level 3. receive domain name and sid */
- res = res ? lsa_query_info_pol(smb_cli, nt_pipe_fnum,
- &info->dom.lsa_info_pol, 0x03,
+ res = res ? lsa_query_info_pol( &info->dom.lsa_info_pol, 0x03,
info->dom.level3_dom,
&info->dom.level3_sid) : False;
/* send client info query, level 5. receive domain name and sid */
- res = res ? lsa_query_info_pol(smb_cli, nt_pipe_fnum,
- &info->dom.lsa_info_pol, 0x05,
+ res = res ? lsa_query_info_pol( &info->dom.lsa_info_pol, 0x05,
info->dom.level5_dom,
&info->dom.level5_sid) : False;
- res = res ? lsa_close(smb_cli, nt_pipe_fnum, &info->dom.lsa_info_pol) : False;
-
- /* close the session */
- cli_nt_session_close(smb_cli, nt_pipe_fnum);
+ res = res ? lsa_close(&info->dom.lsa_info_pol) : False;
if (res)
{
****************************************************************************/
void cmd_lsa_lookup_names(struct client_info *info, int argc, char *argv[])
{
- uint16 nt_pipe_fnum;
fstring temp;
int i;
fstring srv_name;
return;
}
- /* open LSARPC session. */
- res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC, &nt_pipe_fnum) : False;
-
/* lookup domain controller; receive a policy handle */
- res = res ? lsa_open_policy(smb_cli, nt_pipe_fnum,
- srv_name,
+ res = res ? lsa_open_policy( srv_name,
&info->dom.lsa_info_pol, True) : False;
/* send lsa lookup sids call */
- res = res ? lsa_lookup_names(smb_cli, nt_pipe_fnum,
- &info->dom.lsa_info_pol,
+ res = res ? lsa_lookup_names( &info->dom.lsa_info_pol,
num_names, names,
&sids, NULL, &num_sids) : False;
- res = res ? lsa_close(smb_cli, nt_pipe_fnum, &info->dom.lsa_info_pol) : False;
-
- /* close the session */
- cli_nt_session_close(smb_cli, nt_pipe_fnum);
+ res = res ? lsa_close(&info->dom.lsa_info_pol) : False;
if (res)
{
****************************************************************************/
void cmd_lsa_lookup_sids(struct client_info *info, int argc, char *argv[])
{
- uint16 nt_pipe_fnum;
int i;
pstring sid_name;
fstring srv_name;
return;
}
- /* open LSARPC session. */
- res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC, &nt_pipe_fnum) : False;
-
/* lookup domain controller; receive a policy handle */
- res = res ? lsa_open_policy(smb_cli, nt_pipe_fnum,
- srv_name,
+ res = res ? lsa_open_policy( srv_name,
&info->dom.lsa_info_pol, True) : False;
/* send lsa lookup sids call */
- res = res ? lsa_lookup_sids(smb_cli, nt_pipe_fnum,
- &info->dom.lsa_info_pol,
+ res = res ? lsa_lookup_sids( &info->dom.lsa_info_pol,
num_sids, sids,
&names, NULL, &num_names) : False;
- res = res ? lsa_close(smb_cli, nt_pipe_fnum, &info->dom.lsa_info_pol) : False;
-
- /* close the session */
- cli_nt_session_close(smb_cli, nt_pipe_fnum);
+ res = res ? lsa_close(&info->dom.lsa_info_pol) : False;
if (res)
{
char *secret_name;
STRING2 secret;
NTTIME last_update;
+ fstring srv_name;
+
+ fstrcpy(srv_name, "\\\\");
+ fstrcat(srv_name, info->dest_host);
+ strupper(srv_name);
if (argc > 2)
{
secret_name = argv[1];
- if (msrpc_lsa_query_secret(smb_cli, secret_name, &secret, &last_update))
+ if (msrpc_lsa_query_secret(srv_name, secret_name, &secret, &last_update))
{
int i;
report(out_hnd, "\tValue : ");
}
}
-
void cmd_sam_add_aliasmem(struct client_info *info, int argc, char *argv[])
{
uint16 fnum;
- uint16 fnum_lsa;
fstring srv_name;
fstring domain;
fstring tmp;
report(out_hnd, "SAM Domain Alias Member\n");
- /* open LSARPC session. */
- res3 = res3 ? cli_nt_session_open(smb_cli, PIPE_LSARPC, &fnum_lsa) : False;
-
/* lookup domain controller; receive a policy handle */
- res3 = res3 ? lsa_open_policy(smb_cli, fnum_lsa,
- srv_name,
+ res3 = res3 ? lsa_open_policy( srv_name,
&lsa_pol, True) : False;
/* send lsa lookup sids call */
- res4 = res3 ? lsa_lookup_names(smb_cli, fnum_lsa,
- &lsa_pol,
+ res4 = res3 ? lsa_lookup_names( &lsa_pol,
num_names, names,
&sids, NULL, &num_sids) : False;
- res3 = res3 ? lsa_close(smb_cli, fnum_lsa, &lsa_pol) : False;
-
- cli_nt_session_close(smb_cli, fnum_lsa);
+ res3 = res3 ? lsa_close(&lsa_pol) : False;
res4 = num_sids < 2 ? False : res4;
static struct cli_state smbcli;
struct cli_state *smb_cli = &smbcli;
+extern struct cli_state *rpc_smb_cli;
static struct client_info cli_info;
void rpcclient_init(void)
{
bzero(smb_cli, sizeof(smb_cli));
+ rpc_smb_cli = smb_cli;
cli_initialise(smb_cli);
smb_cli->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
}
out_hnd = stdout;
fstrcpy(debugf, argv[0]);
+ init_policy_hnd(64);
rpcclient_init();
#ifdef KANJI
DEBUG(0,("lsahandle test: connection failed\n"));
return;
}
- /* open session. */
- if (!cli_nt_session_open(smb_cli, PIPE_LSARPC, &nt_pipe_fnum))
- {
- DEBUG(0,("lsahandle test: session open failed\n"));
- return;
- }
-
for (i = 1; i <= numops * 100; i++)
{
+ extern struct cli_state *rpc_smb_cli;
+ rpc_smb_cli = smb_cli;
POLICY_HND pol;
- if (!lsa_open_policy(smb_cli, nt_pipe_fnum, srv_name, &pol, False))
+ if (!lsa_open_policy(srv_name, &pol, False))
{
failed++;
}
count++;
}
- /* close the session */
- cli_nt_session_close(smb_cli, nt_pipe_fnum);
-
/* close the rpc pipe */
rpcclient_stop();