cool! completed a samr* API that _would_ look like an msdn samr* api...
authorLuke Leighton <lkcl@samba.org>
Thu, 25 Nov 1999 05:26:48 +0000 (05:26 +0000)
committerLuke Leighton <lkcl@samba.org>
Thu, 25 Nov 1999 05:26:48 +0000 (05:26 +0000)
if microsoft bothered to publish it.  actually, there are good reasons
for not publishing it: people might write programs for it, and then
those programs wouldn't work on nt5, for example...
(This used to be commit 8ce93b80d3b4e1c1e28aa1dde38cdef184eff3c1)

source3/include/proto.h
source3/lib/util_hnd.c
source3/rpc_client/cli_pipe.c
source3/rpc_client/cli_reg.c
source3/rpc_client/cli_samr.c
source3/rpc_client/msrpc_samr.c
source3/rpc_parse/parse_samr.c
source3/rpc_server/srv_lsa_hnd.c
source3/rpcclient/cmd_samr.c
source3/rpcclient/rpcclient.c

index f23106ed1825a86460d38881ed5d5628eca332f9..3a15e8d6893204798f273adfce6775952ef57a24 100644 (file)
@@ -1795,6 +1795,8 @@ BOOL cli_state_init(const char* server_name, const char* pipe_name,
 BOOL cli_state_get(const POLICY_HND *pol,
                                struct cli_state **cli,
                                uint16 *fnum);
+BOOL cli_pol_link(POLICY_HND *to, const POLICY_HND *from);
+BOOL cli_get_usr_sesskey(const POLICY_HND *pol, uchar sess_key[16]);
 
 /*The following definitions come from  rpc_client/cli_eventlog.c  */
 
@@ -1900,6 +1902,8 @@ BOOL create_rpc_bind_resp(struct pwd_info *pwd,
                                prs_struct *rhdr,
                                 prs_struct *rhdr_autha,
                                 prs_struct *auth_resp);
+BOOL rpc_hnd_pipe_req(const POLICY_HND *hnd, uint8 op_num,
+                      prs_struct *data, prs_struct *rdata);
 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);
@@ -1964,123 +1968,90 @@ BOOL reg_shutdown(const char *srv_name,
 
 /*The following definitions come from  rpc_client/cli_samr.c  */
 
-BOOL samr_chgpasswd_user(struct cli_state *cli, uint16 fnum,
+BOOL samr_chgpasswd_user( struct cli_state *cli, uint16 fnum,
                char *srv_name, char *user_name,
                char nt_newpass[516], uchar nt_oldhash[16],
                char lm_newpass[516], uchar lm_oldhash[16]);
 BOOL samr_unknown_38(struct cli_state *cli, uint16 fnum, char *srv_name);
-BOOL samr_query_dom_info(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *domain_pol, uint16 switch_value,
+BOOL samr_query_dom_info(  POLICY_HND *domain_pol, uint16 switch_value,
                                SAM_UNK_CTR *ctr);
-uint32 samr_enum_domains(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol,
+uint32 samr_enum_domains(  POLICY_HND *pol,
                                uint32 *start_idx, uint32 size,
                                struct acct_info **sam,
                                uint32 *num_sam_domains);
-uint32 samr_enum_dom_groups(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol,
+uint32 samr_enum_dom_groups(  POLICY_HND *pol,
                                uint32 *start_idx, uint32 size,
                                struct acct_info **sam,
                                uint32 *num_sam_groups);
-uint32 samr_enum_dom_aliases(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol,
+uint32 samr_enum_dom_aliases(  POLICY_HND *pol,
                                uint32 *start_idx, uint32 size,
                                struct acct_info **sam,
                                uint32 *num_sam_aliases);
-uint32 samr_enum_dom_users(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint32 *start_idx, 
+uint32 samr_enum_dom_users(  POLICY_HND *pol, uint32 *start_idx, 
                                uint16 acb_mask, uint16 unk_1, uint32 size,
                                struct acct_info **sam,
                                uint32 *num_sam_users);
-BOOL samr_connect(struct cli_state *cli, uint16 fnum, 
-                               const char *srv_name, uint32 unknown_0,
+BOOL samr_connect(  const char *srv_name, uint32 unknown_0,
                                POLICY_HND *connect_pol);
-BOOL samr_open_user(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *pol,
+BOOL samr_open_user(  const POLICY_HND *pol,
                                uint32 unk_0, uint32 rid, 
                                POLICY_HND *user_pol);
-BOOL samr_open_alias(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *domain_pol,
+BOOL samr_open_alias(  const POLICY_HND *domain_pol,
                                uint32 flags, uint32 rid,
                                POLICY_HND *alias_pol);
-BOOL samr_del_aliasmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol, DOM_SID *sid);
-BOOL samr_add_aliasmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol, DOM_SID *sid);
-BOOL samr_delete_dom_alias(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol);
-BOOL samr_create_dom_user(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *domain_pol, const char *acct_name,
+BOOL samr_del_aliasmem(  POLICY_HND *alias_pol, DOM_SID *sid);
+BOOL samr_add_aliasmem(  POLICY_HND *alias_pol, DOM_SID *sid);
+BOOL samr_delete_dom_alias(  POLICY_HND *alias_pol);
+BOOL samr_create_dom_user(  POLICY_HND *domain_pol, const char *acct_name,
                                uint32 unk_0, uint32 unk_1,
                                POLICY_HND *user_pol, uint32 *rid);
-BOOL samr_create_dom_alias(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *domain_pol, const char *acct_name,
+BOOL samr_create_dom_alias(  POLICY_HND *domain_pol, const char *acct_name,
                                POLICY_HND *alias_pol, uint32 *rid);
-BOOL samr_query_aliasinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol, uint16 switch_value,
+BOOL samr_query_aliasinfo(  POLICY_HND *alias_pol, uint16 switch_value,
                                ALIAS_INFO_CTR *ctr);
-BOOL samr_set_aliasinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr);
-BOOL samr_open_group(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *domain_pol,
+BOOL samr_set_aliasinfo(  POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr);
+BOOL samr_open_group(  const POLICY_HND *domain_pol,
                                uint32 flags, uint32 rid,
                                POLICY_HND *group_pol);
-BOOL samr_del_groupmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *group_pol, uint32 rid);
-BOOL samr_add_groupmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *group_pol, uint32 rid);
-BOOL samr_delete_dom_group(struct cli_state *cli, uint16 fnum, POLICY_HND *group_pol);
-BOOL samr_create_dom_group(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *domain_pol, const char *acct_name,
+BOOL samr_del_groupmem(  POLICY_HND *group_pol, uint32 rid);
+BOOL samr_add_groupmem(  POLICY_HND *group_pol, uint32 rid);
+BOOL samr_delete_dom_group(  POLICY_HND *group_pol);
+BOOL samr_create_dom_group(  POLICY_HND *domain_pol, const char *acct_name,
                                POLICY_HND *group_pol, uint32 *rid);
-BOOL samr_set_groupinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *group_pol, GROUP_INFO_CTR *ctr);
-BOOL samr_open_domain(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *connect_pol,
+BOOL samr_set_groupinfo(  POLICY_HND *group_pol, GROUP_INFO_CTR *ctr);
+BOOL samr_open_domain(  const POLICY_HND *connect_pol,
                                uint32 ace_perms,
                                const DOM_SID *sid,
                                POLICY_HND *domain_pol);
-BOOL samr_query_lookup_domain(struct cli_state *cli, uint16 fnum, 
-                             POLICY_HND *pol, const char *dom_name,
+BOOL samr_query_lookup_domain(  POLICY_HND *pol, const char *dom_name,
                              DOM_SID *dom_sid);
-BOOL samr_query_lookup_names(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint32 flags,
+BOOL samr_query_lookup_names(  POLICY_HND *pol, uint32 flags,
                                uint32 num_names, char **names,
                                uint32 *num_rids,
                                uint32 rid[MAX_LOOKUP_SIDS],
                                uint32 type[MAX_LOOKUP_SIDS]);
-BOOL samr_query_lookup_rids(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *pol, uint32 flags,
+BOOL samr_query_lookup_rids(  const POLICY_HND *pol, uint32 flags,
                                uint32 num_rids, uint32 *rids,
                                uint32 *num_names,
                                char   ***names,
                                uint32 **type);
-BOOL samr_query_aliasmem(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *alias_pol, 
+BOOL samr_query_aliasmem(  const POLICY_HND *alias_pol, 
                                uint32 *num_mem, DOM_SID2 *sid);
-BOOL samr_query_useraliases(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *pol,
+BOOL samr_query_useraliases(  const POLICY_HND *pol,
                                uint32 *ptr_sid, DOM_SID2 *sid,
                                uint32 *num_aliases, uint32 **rid);
-BOOL samr_query_groupmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *group_pol, 
+BOOL samr_query_groupmem(  POLICY_HND *group_pol, 
                                uint32 *num_mem, uint32 **rid, uint32 **attr);
-BOOL samr_query_usergroups(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint32 *num_groups,
+BOOL samr_query_usergroups(  POLICY_HND *pol, uint32 *num_groups,
                                DOM_GID **gid);
-BOOL samr_query_groupinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol,
+BOOL samr_query_groupinfo(  POLICY_HND *pol,
                                uint16 switch_value, GROUP_INFO_CTR* ctr);
-BOOL samr_set_userinfo2(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint16 switch_value,
+BOOL samr_set_userinfo2(  POLICY_HND *pol, uint16 switch_value,
                                void* usr);
-BOOL samr_set_userinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint16 switch_value, void* usr);
-BOOL samr_query_userinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint16 switch_value, void* usr);
-BOOL samr_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd);
-BOOL samr_query_dispinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol_open_domain, uint16 level,
+BOOL samr_set_userinfo(  POLICY_HND *pol, uint16 switch_value, void* usr);
+BOOL samr_query_userinfo(  POLICY_HND *pol, uint16 switch_value, void* usr);
+BOOL samr_close(  POLICY_HND *hnd);
+BOOL samr_query_dispinfo(  POLICY_HND *pol_domain, uint16 level,
                                uint32 *num_entries,
                                SAM_DISPINFO_CTR *ctr);
 
@@ -2187,13 +2158,12 @@ BOOL msrpc_lsa_query_secret(const char* srv_name,
 
 /*The following definitions come from  rpc_client/msrpc_samr.c  */
 
-BOOL req_user_info(struct cli_state *cli, uint16 fnum,
-                               POLICY_HND *pol_dom,
+BOOL req_user_info( POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
                                uint32 user_rid,
                                USER_INFO_FN(usr_inf));
-uint32 sam_query_usergroups(struct cli_state *cli, uint16 fnum,
+uint32 sam_query_usergroups(
                                const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
@@ -2204,132 +2174,123 @@ uint32 sam_query_usergroups(struct cli_state *cli, uint16 fnum,
                                char    ***name,
                                uint32  **type,
                                USER_MEM_FN(usr_mem));
-int msrpc_sam_enum_users(struct cli_state *cli,
+int msrpc_sam_enum_users( const char* srv_name,
                        const char* domain,
                        const DOM_SID *sid1,
-                       const char* srv_name,
                        struct acct_info **sam,
                        uint32 *num_sam_entries,
                        USER_FN(usr_fn),
                        USER_INFO_FN(usr_inf_fn),
                        USER_MEM_FN(usr_grp_fn),
                        USER_MEM_FN(usr_als_fn));
-BOOL sam_query_dominfo(struct cli_state *cli, 
+BOOL sam_query_dominfo(const char* srv_name,
                                const DOM_SID *sid1,
                                uint32 switch_value, SAM_UNK_CTR *ctr);
-BOOL query_aliasinfo(struct cli_state *cli, uint16 fnum,
+BOOL query_aliasinfo(
                                const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
                                uint32 alias_rid,
                                ALIAS_INFO_FN(grp_inf));
-BOOL sam_query_aliasmem(struct cli_state *cli, uint16 fnum,
+BOOL sam_query_aliasmem(const char *srv_name,
                                const POLICY_HND *pol_dom,
                                uint32 alias_rid,
                                uint32 *num_names,
                                DOM_SID ***sids,
                                char ***name,
                                uint8 **type);
-BOOL req_aliasmem_info(struct cli_state *cli, uint16 fnum,
+BOOL req_aliasmem_info(const char* srv_name,
                                const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
                                uint32 alias_rid,
                                const char *alias_name,
                                ALIAS_MEM_FN(als_mem));
-BOOL sam_query_groupmem(struct cli_state *cli, uint16 fnum,
+BOOL sam_query_groupmem(
                                const POLICY_HND *pol_dom,
                                uint32 group_rid,
                                uint32 *num_names,
                                uint32 **rid_mem,
                                char ***name,
                                uint32 **type);
-BOOL query_groupinfo(struct cli_state *cli, uint16 fnum,
-                               const POLICY_HND *pol_dom,
+BOOL query_groupinfo( const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
                                uint32 group_rid,
                                GROUP_INFO_FN(grp_inf));
-BOOL req_groupmem_info(struct cli_state *cli, uint16 fnum,
-                               const POLICY_HND *pol_dom,
+BOOL req_groupmem_info( const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
                                uint32 group_rid,
                                const char *group_name,
                                GROUP_MEM_FN(grp_mem));
-uint32 msrpc_sam_enum_domains(struct cli_state *cli,
-                               const char* srv_name,
+uint32 msrpc_sam_enum_domains( const char* srv_name,
                                struct acct_info **sam,
                                uint32 *num_sam_entries,
                                DOMAIN_FN(dom_fn));
-uint32 msrpc_sam_enum_groups(struct cli_state *cli,
+uint32 msrpc_sam_enum_groups( const char* srv_name,
                                const char* domain,
                                const DOM_SID *sid1,
-                               const char* srv_name,
                                struct acct_info **sam,
                                uint32 *num_sam_entries,
                                GROUP_FN(grp_fn),
                                GROUP_INFO_FN(grp_inf_fn),
                                GROUP_MEM_FN(grp_mem_fn));
-uint32 msrpc_sam_enum_aliases(struct cli_state *cli,
+uint32 msrpc_sam_enum_aliases( const char* srv_name,
                                const char* domain,
                                const DOM_SID *sid1,
-                               const char* srv_name,
                                struct acct_info **sam,
                                uint32 *num_sam_entries,
                                ALIAS_FN(als_fn),
                                ALIAS_INFO_FN(als_inf_fn),
                                ALIAS_MEM_FN(als_mem_fn));
-BOOL create_samr_domain_user(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol_open_domain,
+BOOL create_samr_domain_user( POLICY_HND *pol_open_domain,
                                const char *acct_name, uint16 acb_info,
                                uint32 *rid);
-BOOL create_samr_domain_alias(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol_open_domain,
+BOOL create_samr_domain_alias( POLICY_HND *pol_open_domain,
                                const char *acct_name, const char *acct_desc,
                                uint32 *rid);
-BOOL create_samr_domain_group(struct cli_state *cli, uint16 fnum, 
+BOOL create_samr_domain_group(
                                POLICY_HND *pol_open_domain,
                                const char *acct_name, const char *acct_desc,
                                uint32 *rid);
-BOOL get_samr_query_usergroups(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *pol_open_domain,
+BOOL get_samr_query_usergroups( const POLICY_HND *pol_open_domain,
                                uint32 user_rid,
                                uint32 *num_groups, DOM_GID **gid);
-BOOL delete_samr_dom_group(struct cli_state *cli, uint16 fnum, 
+BOOL delete_samr_dom_group(
                                POLICY_HND *pol_open_domain,
                                uint32 group_rid);
-BOOL get_samr_query_groupmem(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_groupmem( 
                                const POLICY_HND *pol_open_domain,
                                uint32 group_rid, uint32 *num_mem,
                                uint32 **rid, uint32 **attr);
-BOOL delete_samr_dom_alias(struct cli_state *cli, uint16 fnum, 
+BOOL delete_samr_dom_alias( 
                                POLICY_HND *pol_open_domain,
                                uint32 alias_rid);
-BOOL get_samr_query_aliasmem(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_aliasmem( 
                                const POLICY_HND *pol_open_domain,
                                uint32 alias_rid, uint32 *num_mem, DOM_SID2 *sid);
-BOOL set_samr_set_userinfo2(struct cli_state *cli, uint16 fnum, 
+BOOL set_samr_set_userinfo2( 
                                POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 user_rid, void *usr);
-BOOL set_samr_set_userinfo(struct cli_state *cli, uint16 fnum, 
+BOOL set_samr_set_userinfo( 
                                POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 user_rid, void *usr);
-BOOL get_samr_query_userinfo(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_userinfo( 
                                POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 user_rid, void *usr);
-BOOL get_samr_query_groupinfo(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_groupinfo( 
                                const POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 group_rid, GROUP_INFO_CTR *ctr);
-BOOL get_samr_query_aliasinfo(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_aliasinfo( 
                                const POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 alias_rid, ALIAS_INFO_CTR *ctr);
-BOOL msrpc_sam_create_dom_user(struct cli_state *cli, DOM_SID *sid1,
+BOOL msrpc_sam_create_dom_user(const char* srv_name, DOM_SID *sid1,
                                char *acct_name, uint16 acb_info,
                                uint32 *rid);
 
index b32b3322b33d4bb9df5cdbd222ffecddcd8cf8b7..add040aa3d1ef8bbee248907fcc24cba1e6e810f 100644 (file)
@@ -411,8 +411,14 @@ BOOL get_policy_cli_state(const POLICY_HND *hnd, struct cli_state **cli,
        {
                DEBUG(3,("Getting cli state pnum=%x\n", p->pnum));
 
-               (*cli ) = p->dev.cli->cli;
-               (*fnum) = p->dev.cli->fnum;
+               if (cli != NULL)
+               {
+                       (*cli ) = p->dev.cli->cli;
+               }
+               if (fnum != NULL)
+               {
+                       (*fnum) = p->dev.cli->fnum;
+               }
 
                return True;
        }
index 9aad93246e04b78c3391ec4420dfb2ef4c57d093..08d7e42270717fefb20fa04a901f81f8a0b8419c 100644 (file)
@@ -625,6 +625,23 @@ static BOOL create_rpc_request(prs_struct *rhdr, uint8 op_num, int data_len,
 }
 
 
+/****************************************************************************
+ 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_state *cli = NULL;
+       uint16 fnum = 0xffff;
+
+       if (!cli_state_get(hnd, &cli, &fnum))
+       {
+               return False;
+       }
+
+       return rpc_api_pipe_req(cli, fnum, op_num, data, rdata);
+}
+
 /****************************************************************************
  send a request on an rpc pipe.
  ****************************************************************************/
index 46ab55dcab70dc7ad1c577c29ad1dfd63ac8e7f1..9242d5587ce0dcc781d57acdfee4f892a8099f47 100644 (file)
@@ -300,14 +300,6 @@ BOOL reg_flush_key( POLICY_HND *hnd)
        REG_Q_FLUSH_KEY q_o;
        BOOL valid_query = 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);
@@ -323,7 +315,7 @@ BOOL reg_flush_key( POLICY_HND *hnd)
        reg_io_q_flush_key("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_FLUSH_KEY, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_FLUSH_KEY, &buf, &rbuf))
        {
                REG_R_FLUSH_KEY r_o;
                BOOL p;
@@ -367,14 +359,6 @@ BOOL reg_query_key( POLICY_HND *hnd,
        REG_Q_QUERY_KEY q_o;
        BOOL valid_query = 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);
@@ -390,7 +374,7 @@ BOOL reg_query_key( POLICY_HND *hnd,
        reg_io_q_query_key("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_QUERY_KEY, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_QUERY_KEY, &buf, &rbuf))
        {
                REG_R_QUERY_KEY r_o;
                BOOL p;
@@ -440,14 +424,6 @@ BOOL reg_unknown_1a( POLICY_HND *hnd, uint32 *unk)
        REG_Q_UNK_1A q_o;
        BOOL valid_query = 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);
@@ -463,7 +439,7 @@ BOOL reg_unknown_1a( POLICY_HND *hnd, uint32 *unk)
        reg_io_q_unk_1a("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_UNK_1A, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_UNK_1A, &buf, &rbuf))
        {
                REG_R_UNK_1A r_o;
                BOOL p;
@@ -505,14 +481,6 @@ BOOL reg_query_info( POLICY_HND *hnd,
        REG_Q_INFO q_o;
        BOOL valid_query = 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);
@@ -528,7 +496,7 @@ BOOL reg_query_info( POLICY_HND *hnd,
        reg_io_q_info("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_INFO, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_INFO, &buf, &rbuf))
        {
                REG_R_INFO r_o;
                BOOL p;
@@ -572,14 +540,6 @@ BOOL reg_set_key_sec( POLICY_HND *hnd,
        REG_Q_SET_KEY_SEC q_o;
        BOOL valid_query = 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);
@@ -595,7 +555,7 @@ BOOL reg_set_key_sec( POLICY_HND *hnd,
        reg_io_q_set_key_sec("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_SET_KEY_SEC, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_SET_KEY_SEC, &buf, &rbuf))
        {
                REG_R_SET_KEY_SEC r_o;
                BOOL p;
@@ -630,14 +590,6 @@ BOOL reg_get_key_sec( POLICY_HND *hnd,
        REG_Q_GET_KEY_SEC q_o;
        BOOL valid_query = 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);
@@ -653,7 +605,7 @@ BOOL reg_get_key_sec( POLICY_HND *hnd,
        reg_io_q_get_key_sec("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_GET_KEY_SEC, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_GET_KEY_SEC, &buf, &rbuf))
        {
                REG_R_GET_KEY_SEC r_o;
                BOOL p;
@@ -706,14 +658,6 @@ BOOL reg_delete_val( POLICY_HND *hnd, char *val_name)
        REG_Q_DELETE_VALUE q_o;
        BOOL valid_delete = 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);
@@ -729,7 +673,7 @@ BOOL reg_delete_val( POLICY_HND *hnd, char *val_name)
        reg_io_q_delete_val("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_DELETE_VALUE, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_DELETE_VALUE, &buf, &rbuf))
        {
                REG_R_DELETE_VALUE r_o;
                BOOL p;
@@ -768,14 +712,6 @@ BOOL reg_delete_key( POLICY_HND *hnd, char *key_name)
        REG_Q_DELETE_KEY q_o;
        BOOL valid_delete = 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);
@@ -791,7 +727,7 @@ BOOL reg_delete_key( POLICY_HND *hnd, char *key_name)
        reg_io_q_delete_key("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_DELETE_KEY, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_DELETE_KEY, &buf, &rbuf))
        {
                REG_R_DELETE_KEY r_o;
                BOOL p;
@@ -836,14 +772,6 @@ BOOL reg_create_key( POLICY_HND *hnd,
        SEC_DESC_BUF sec_buf;
        int sec_len;
 
-       struct cli_state *cli = NULL;
-       uint16 fnum = 0xffff;
-
-       if (!cli_state_get(hnd, &cli, &fnum))
-       {
-               return False;
-       }
-
        ZERO_STRUCT(sec);
        ZERO_STRUCT(sec_buf);
        ZERO_STRUCT(q_o);
@@ -870,7 +798,7 @@ BOOL reg_create_key( POLICY_HND *hnd,
        reg_io_q_create_key("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_CREATE_KEY, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_CREATE_KEY, &buf, &rbuf))
        {
                REG_R_CREATE_KEY r_o;
                BOOL p;
@@ -915,14 +843,6 @@ BOOL reg_enum_key( POLICY_HND *hnd,
        REG_Q_ENUM_KEY q_o;
        BOOL valid_query = 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);
@@ -938,7 +858,7 @@ BOOL reg_enum_key( POLICY_HND *hnd,
        reg_io_q_enum_key("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_ENUM_KEY, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_ENUM_KEY, &buf, &rbuf))
        {
                REG_R_ENUM_KEY r_o;
                BOOL p;
@@ -983,14 +903,6 @@ BOOL reg_create_val( POLICY_HND *hnd,
        REG_Q_CREATE_VALUE q_o;
        BOOL valid_create = 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);
@@ -1006,7 +918,7 @@ BOOL reg_create_val( POLICY_HND *hnd,
        reg_io_q_create_val("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_CREATE_VALUE, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_CREATE_VALUE, &buf, &rbuf))
        {
                REG_R_CREATE_VALUE r_o;
                BOOL p;
@@ -1048,14 +960,6 @@ BOOL reg_enum_val( POLICY_HND *hnd,
        REG_Q_ENUM_VALUE q_o;
        BOOL valid_query = 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);
@@ -1071,7 +975,7 @@ BOOL reg_enum_val( POLICY_HND *hnd,
        reg_io_q_enum_val("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_ENUM_VALUE, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_ENUM_VALUE, &buf, &rbuf))
        {
                REG_R_ENUM_VALUE r_o;
                BOOL p;
@@ -1115,14 +1019,6 @@ BOOL reg_open_entry( POLICY_HND *hnd,
        REG_Q_OPEN_ENTRY q_o;
        BOOL valid_pol = 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);
@@ -1138,7 +1034,7 @@ BOOL reg_open_entry( POLICY_HND *hnd,
        reg_io_q_open_entry("", &q_o, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_OPEN_ENTRY, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_OPEN_ENTRY, &buf, &rbuf))
        {
                REG_R_OPEN_ENTRY r_o;
                BOOL p;
@@ -1157,9 +1053,16 @@ BOOL reg_open_entry( POLICY_HND *hnd,
 
                if (p)
                {
+                       struct cli_state *cli = NULL;
+                       uint16 fnum = 0xffff;
+
+                       if (!cli_state_get(hnd, &cli, &fnum))
+                       {
+                               return False;
+                       }
+
                        memcpy(key_hnd, r_o.pol.data, sizeof(key_hnd->data));
-                       valid_pol = register_policy_hnd(key_hnd) &&
-                               set_policy_cli_state(key_hnd, cli, fnum, NULL);
+                       valid_pol = cli_pol_link(key_hnd, hnd);
                }
        }
 
@@ -1179,14 +1082,6 @@ BOOL reg_close( POLICY_HND *hnd)
        REG_Q_CLOSE q_c;
        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;
 
        /* create and send a MSRPC command with api REG_CLOSE */
@@ -1203,7 +1098,7 @@ BOOL reg_close( POLICY_HND *hnd)
        reg_io_q_close("", &q_c, &buf, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, REG_CLOSE, &buf, &rbuf))
+       if (rpc_hnd_pipe_req(hnd, REG_CLOSE, &buf, &rbuf))
        {
                REG_R_CLOSE r_c;
                BOOL p;
@@ -1263,7 +1158,7 @@ BOOL reg_shutdown(const char *srv_name,
        struct cli_state *cli = NULL;
        uint16 fnum = 0xffff;
 
-       if (!cli_state_init(srv_name, PIPE_WINREG, &cli, &fnum))
+       if (!cli_state_init(srv_name, PIPE_LSARPC, &cli, &fnum))
        {
                return False;
        }
index 97e218b1b3b76f551545e23882e8d3885b84960d..44425b5358dfb56d803010d9cb1d27669f8f78b7 100644 (file)
 
 extern int DEBUGLEVEL;
 
+#if 0
+               if (p)
+               {
+                       /* ok, at last: we're happy. return the policy handle */
+                       memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
+                       valid_pol = register_policy_hnd(hnd) &&
+                                   set_policy_cli_state(hnd, cli, fnum,
+                                                        cli_state_free);
+               }
+
+       struct cli_state *cli = NULL;
+       uint16 fnum = 0xffff;
+
+       if (!cli_state_get(connect_pol, &cli, &fnum))
+       {
+               return False;
+       }
+#endif
 
 /****************************************************************************
 do a SAMR change user password command
 ****************************************************************************/
-BOOL samr_chgpasswd_user(struct cli_state *cli, uint16 fnum,
+BOOL samr_chgpasswd_user( struct cli_state *cli, uint16 fnum,
                char *srv_name, char *user_name,
                char nt_newpass[516], uchar nt_oldhash[16],
                char lm_newpass[516], uchar lm_oldhash[16])
@@ -86,6 +104,8 @@ BOOL samr_chgpasswd_user(struct cli_state *cli, uint16 fnum,
        prs_mem_free(&data   );
        prs_mem_free(&rdata  );
 
+       cli_state_free(cli, fnum);
+
        return valid_pwc;
 }
 
@@ -145,8 +165,7 @@ BOOL samr_unknown_38(struct cli_state *cli, uint16 fnum, char *srv_name)
 /****************************************************************************
 do a SAMR unknown 0x8 command
 ****************************************************************************/
-BOOL samr_query_dom_info(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *domain_pol, uint16 switch_value,
+BOOL samr_query_dom_info(  POLICY_HND *domain_pol, uint16 switch_value,
                                SAM_UNK_CTR *ctr)
 {
        prs_struct data;
@@ -171,7 +190,7 @@ BOOL samr_query_dom_info(struct cli_state *cli, uint16 fnum,
        samr_io_q_query_dom_info("", &q_e, &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_DOMAIN_INFO, &data, &rdata))
+       if (rpc_hnd_pipe_req(domain_pol, SAMR_QUERY_DOMAIN_INFO, &data, &rdata))
        {
                SAMR_R_QUERY_DOMAIN_INFO r_e;
                BOOL p;
@@ -202,8 +221,7 @@ BOOL samr_query_dom_info(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR enumerate Domains
 ****************************************************************************/
-uint32 samr_enum_domains(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol,
+uint32 samr_enum_domains(  POLICY_HND *pol,
                                uint32 *start_idx, uint32 size,
                                struct acct_info **sam,
                                uint32 *num_sam_domains)
@@ -233,7 +251,7 @@ uint32 samr_enum_domains(struct cli_state *cli, uint16 fnum,
        samr_io_q_enum_domains("", &q_e, &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_ENUM_DOMAINS, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_ENUM_DOMAINS, &data, &rdata))
        {
                SAMR_R_ENUM_DOMAINS r_e;
                BOOL p;
@@ -304,8 +322,7 @@ uint32 samr_enum_domains(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR enumerate groups
 ****************************************************************************/
-uint32 samr_enum_dom_groups(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol,
+uint32 samr_enum_dom_groups(  POLICY_HND *pol,
                                uint32 *start_idx, uint32 size,
                                struct acct_info **sam,
                                uint32 *num_sam_groups)
@@ -335,7 +352,7 @@ uint32 samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
        samr_io_q_enum_dom_groups("", &q_e, &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_ENUM_DOM_GROUPS, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_ENUM_DOM_GROUPS, &data, &rdata))
        {
                SAMR_R_ENUM_DOM_GROUPS r_e;
                BOOL p;
@@ -406,8 +423,7 @@ uint32 samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR enumerate aliases
 ****************************************************************************/
-uint32 samr_enum_dom_aliases(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol,
+uint32 samr_enum_dom_aliases(  POLICY_HND *pol,
                                uint32 *start_idx, uint32 size,
                                struct acct_info **sam,
                                uint32 *num_sam_aliases)
@@ -437,7 +453,7 @@ uint32 samr_enum_dom_aliases(struct cli_state *cli, uint16 fnum,
        samr_io_q_enum_dom_aliases("", &q_e, &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_ENUM_DOM_ALIASES, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_ENUM_DOM_ALIASES, &data, &rdata))
        {
                SAMR_R_ENUM_DOM_ALIASES r_e;
                BOOL p;
@@ -507,8 +523,7 @@ uint32 samr_enum_dom_aliases(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR enumerate users
 ****************************************************************************/
-uint32 samr_enum_dom_users(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint32 *start_idx, 
+uint32 samr_enum_dom_users(  POLICY_HND *pol, uint32 *start_idx, 
                                uint16 acb_mask, uint16 unk_1, uint32 size,
                                struct acct_info **sam,
                                uint32 *num_sam_users)
@@ -539,7 +554,7 @@ uint32 samr_enum_dom_users(struct cli_state *cli, uint16 fnum,
        samr_io_q_enum_dom_users("", &q_e, &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_ENUM_DOM_USERS, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_ENUM_DOM_USERS, &data, &rdata))
        {
                SAMR_R_ENUM_DOM_USERS r_e;
                BOOL p;
@@ -615,8 +630,7 @@ uint32 samr_enum_dom_users(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Connect
 ****************************************************************************/
-BOOL samr_connect(struct cli_state *cli, uint16 fnum, 
-                               const char *srv_name, uint32 unknown_0,
+BOOL samr_connect(  const char *srv_name, uint32 unknown_0,
                                POLICY_HND *connect_pol)
 {
        prs_struct data;
@@ -625,6 +639,14 @@ BOOL samr_connect(struct cli_state *cli, uint16 fnum,
        SAMR_Q_CONNECT q_o;
        BOOL valid_pol = False;
 
+       struct cli_state *cli = NULL;
+       uint16 fnum = 0xffff;
+
+       if (!cli_state_init(srv_name, PIPE_SAMR, &cli, &fnum))
+       {
+               return False;
+       }
+
        DEBUG(4,("SAMR Open Policy server:%s undoc value:%x\n",
                                srv_name, unknown_0));
 
@@ -660,7 +682,9 @@ BOOL samr_connect(struct cli_state *cli, uint16 fnum,
                if (p)
                {
                        memcpy(connect_pol, &r_o.connect_pol, sizeof(r_o.connect_pol));
-                       valid_pol = True;
+                       valid_pol = register_policy_hnd(connect_pol) &&
+                                   set_policy_cli_state(connect_pol, cli, fnum,
+                                                        cli_state_free);
                }
        }
 
@@ -673,8 +697,7 @@ BOOL samr_connect(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Open User
 ****************************************************************************/
-BOOL samr_open_user(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *pol,
+BOOL samr_open_user(  const POLICY_HND *pol,
                                uint32 unk_0, uint32 rid, 
                                POLICY_HND *user_pol)
 {
@@ -701,7 +724,7 @@ BOOL samr_open_user(struct cli_state *cli, uint16 fnum,
        samr_io_q_open_user("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_OPEN_USER, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_OPEN_USER, &data, &rdata))
        {
                SAMR_R_OPEN_USER r_o;
                BOOL p;
@@ -719,7 +742,7 @@ BOOL samr_open_user(struct cli_state *cli, uint16 fnum,
                if (p)
                {
                        memcpy(user_pol, &r_o.user_pol, sizeof(r_o.user_pol));
-                       valid_pol = True;
+                       valid_pol = cli_pol_link(user_pol, pol);
                }
        }
 
@@ -732,8 +755,7 @@ BOOL samr_open_user(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Open Alias
 ****************************************************************************/
-BOOL samr_open_alias(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *domain_pol,
+BOOL samr_open_alias(  const POLICY_HND *domain_pol,
                                uint32 flags, uint32 rid,
                                POLICY_HND *alias_pol)
 {
@@ -759,7 +781,7 @@ BOOL samr_open_alias(struct cli_state *cli, uint16 fnum,
        samr_io_q_open_alias("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_OPEN_ALIAS, &data, &rdata))
+       if (rpc_hnd_pipe_req(domain_pol, SAMR_OPEN_ALIAS, &data, &rdata))
        {
                SAMR_R_OPEN_ALIAS r_o;
                BOOL p;
@@ -777,7 +799,7 @@ BOOL samr_open_alias(struct cli_state *cli, uint16 fnum,
                if (p)
                {
                        memcpy(alias_pol, &r_o.pol, sizeof(r_o.pol));
-                       valid_pol = True;
+                       valid_pol = cli_pol_link(alias_pol, domain_pol);
                }
        }
 
@@ -790,8 +812,7 @@ BOOL samr_open_alias(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Delete Alias Member
 ****************************************************************************/
-BOOL samr_del_aliasmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol, DOM_SID *sid)
+BOOL samr_del_aliasmem(  POLICY_HND *alias_pol, DOM_SID *sid)
 {
        prs_struct data;
        prs_struct rdata;
@@ -815,7 +836,7 @@ BOOL samr_del_aliasmem(struct cli_state *cli, uint16 fnum,
        samr_io_q_del_aliasmem("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_DEL_ALIASMEM, &data, &rdata))
+       if (rpc_hnd_pipe_req(alias_pol, SAMR_DEL_ALIASMEM, &data, &rdata))
        {
                SAMR_R_DEL_ALIASMEM r_o;
                BOOL p;
@@ -845,8 +866,7 @@ BOOL samr_del_aliasmem(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Add Alias Member
 ****************************************************************************/
-BOOL samr_add_aliasmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol, DOM_SID *sid)
+BOOL samr_add_aliasmem(  POLICY_HND *alias_pol, DOM_SID *sid)
 {
        prs_struct data;
        prs_struct rdata;
@@ -870,7 +890,7 @@ BOOL samr_add_aliasmem(struct cli_state *cli, uint16 fnum,
        samr_io_q_add_aliasmem("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_ADD_ALIASMEM, &data, &rdata))
+       if (rpc_hnd_pipe_req(alias_pol, SAMR_ADD_ALIASMEM, &data, &rdata))
        {
                SAMR_R_ADD_ALIASMEM r_o;
                BOOL p;
@@ -900,8 +920,7 @@ BOOL samr_add_aliasmem(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Delete Domain Alias
 ****************************************************************************/
-BOOL samr_delete_dom_alias(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol)
+BOOL samr_delete_dom_alias(  POLICY_HND *alias_pol)
 {
        prs_struct data;
        prs_struct rdata;
@@ -925,7 +944,7 @@ BOOL samr_delete_dom_alias(struct cli_state *cli, uint16 fnum,
        samr_io_q_delete_dom_alias("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_DELETE_DOM_ALIAS, &data, &rdata))
+       if (rpc_hnd_pipe_req(alias_pol, SAMR_DELETE_DOM_ALIAS, &data, &rdata))
        {
                SAMR_R_DELETE_DOM_ALIAS r_o;
                BOOL p;
@@ -955,8 +974,7 @@ BOOL samr_delete_dom_alias(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Create Domain User
 ****************************************************************************/
-BOOL samr_create_dom_user(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *domain_pol, const char *acct_name,
+BOOL samr_create_dom_user(  POLICY_HND *domain_pol, const char *acct_name,
                                uint32 unk_0, uint32 unk_1,
                                POLICY_HND *user_pol, uint32 *rid)
 {
@@ -982,7 +1000,7 @@ BOOL samr_create_dom_user(struct cli_state *cli, uint16 fnum,
        samr_io_q_create_user("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_CREATE_USER, &data, &rdata))
+       if (rpc_hnd_pipe_req(domain_pol, SAMR_CREATE_USER, &data, &rdata))
        {
                SAMR_R_CREATE_USER r_o;
                BOOL p;
@@ -1001,7 +1019,7 @@ BOOL samr_create_dom_user(struct cli_state *cli, uint16 fnum,
                {
                        memcpy(user_pol, &r_o.user_pol, sizeof(r_o.user_pol));
                        *rid = r_o.user_rid;
-                       valid_pol = True;
+                       valid_pol = cli_pol_link(user_pol, domain_pol);
                }
        }
 
@@ -1014,8 +1032,7 @@ BOOL samr_create_dom_user(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Create Domain Alias
 ****************************************************************************/
-BOOL samr_create_dom_alias(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *domain_pol, const char *acct_name,
+BOOL samr_create_dom_alias(  POLICY_HND *domain_pol, const char *acct_name,
                                POLICY_HND *alias_pol, uint32 *rid)
 {
        prs_struct data;
@@ -1040,7 +1057,7 @@ BOOL samr_create_dom_alias(struct cli_state *cli, uint16 fnum,
        samr_io_q_create_dom_alias("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_CREATE_DOM_ALIAS, &data, &rdata))
+       if (rpc_hnd_pipe_req(domain_pol, SAMR_CREATE_DOM_ALIAS, &data, &rdata))
        {
                SAMR_R_CREATE_DOM_ALIAS r_o;
                BOOL p;
@@ -1059,7 +1076,7 @@ BOOL samr_create_dom_alias(struct cli_state *cli, uint16 fnum,
                {
                        memcpy(alias_pol, &r_o.alias_pol, sizeof(r_o.alias_pol));
                        *rid = r_o.rid;
-                       valid_pol = True;
+                       valid_pol = cli_pol_link(alias_pol, domain_pol);
                }
        }
 
@@ -1072,8 +1089,7 @@ BOOL samr_create_dom_alias(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Get Alias Info
 ****************************************************************************/
-BOOL samr_query_aliasinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol, uint16 switch_value,
+BOOL samr_query_aliasinfo(  POLICY_HND *alias_pol, uint16 switch_value,
                                ALIAS_INFO_CTR *ctr)
 {
        prs_struct data;
@@ -1098,7 +1114,7 @@ BOOL samr_query_aliasinfo(struct cli_state *cli, uint16 fnum,
        samr_io_q_query_aliasinfo("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_ALIASINFO, &data, &rdata))
+       if (rpc_hnd_pipe_req(alias_pol, SAMR_QUERY_ALIASINFO, &data, &rdata))
        {
                SAMR_R_QUERY_ALIASINFO r_o;
                BOOL p;
@@ -1131,8 +1147,7 @@ BOOL samr_query_aliasinfo(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Set Alias Info
 ****************************************************************************/
-BOOL samr_set_aliasinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr)
+BOOL samr_set_aliasinfo(  POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr)
 {
        prs_struct data;
        prs_struct rdata;
@@ -1156,7 +1171,7 @@ BOOL samr_set_aliasinfo(struct cli_state *cli, uint16 fnum,
        samr_io_q_set_aliasinfo("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_SET_ALIASINFO, &data, &rdata))
+       if (rpc_hnd_pipe_req(alias_pol, SAMR_SET_ALIASINFO, &data, &rdata))
        {
                SAMR_R_SET_ALIASINFO r_o;
                BOOL p;
@@ -1186,8 +1201,7 @@ BOOL samr_set_aliasinfo(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Open Group
 ****************************************************************************/
-BOOL samr_open_group(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *domain_pol,
+BOOL samr_open_group(  const POLICY_HND *domain_pol,
                                uint32 flags, uint32 rid,
                                POLICY_HND *group_pol)
 {
@@ -1213,7 +1227,7 @@ BOOL samr_open_group(struct cli_state *cli, uint16 fnum,
        samr_io_q_open_group("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_OPEN_GROUP, &data, &rdata))
+       if (rpc_hnd_pipe_req(domain_pol, SAMR_OPEN_GROUP, &data, &rdata))
        {
                SAMR_R_OPEN_GROUP r_o;
                BOOL p;
@@ -1231,7 +1245,7 @@ BOOL samr_open_group(struct cli_state *cli, uint16 fnum,
                if (p)
                {
                        memcpy(group_pol, &r_o.pol, sizeof(r_o.pol));
-                       valid_pol = True;
+                       valid_pol = cli_pol_link(group_pol, domain_pol);
                }
        }
 
@@ -1244,8 +1258,7 @@ BOOL samr_open_group(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Delete Group Member
 ****************************************************************************/
-BOOL samr_del_groupmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *group_pol, uint32 rid)
+BOOL samr_del_groupmem(  POLICY_HND *group_pol, uint32 rid)
 {
        prs_struct data;
        prs_struct rdata;
@@ -1269,7 +1282,7 @@ BOOL samr_del_groupmem(struct cli_state *cli, uint16 fnum,
        samr_io_q_del_groupmem("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_DEL_GROUPMEM, &data, &rdata))
+       if (rpc_hnd_pipe_req(group_pol, SAMR_DEL_GROUPMEM, &data, &rdata))
        {
                SAMR_R_DEL_GROUPMEM r_o;
                BOOL p;
@@ -1299,8 +1312,7 @@ BOOL samr_del_groupmem(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Add Group Member
 ****************************************************************************/
-BOOL samr_add_groupmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *group_pol, uint32 rid)
+BOOL samr_add_groupmem(  POLICY_HND *group_pol, uint32 rid)
 {
        prs_struct data;
        prs_struct rdata;
@@ -1324,7 +1336,7 @@ BOOL samr_add_groupmem(struct cli_state *cli, uint16 fnum,
        samr_io_q_add_groupmem("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_ADD_GROUPMEM, &data, &rdata))
+       if (rpc_hnd_pipe_req(group_pol, SAMR_ADD_GROUPMEM, &data, &rdata))
        {
                SAMR_R_ADD_GROUPMEM r_o;
                BOOL p;
@@ -1354,7 +1366,7 @@ BOOL samr_add_groupmem(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Delete Domain Group
 ****************************************************************************/
-BOOL samr_delete_dom_group(struct cli_state *cli, uint16 fnum, POLICY_HND *group_pol)
+BOOL samr_delete_dom_group(  POLICY_HND *group_pol)
 {
        prs_struct data;
        prs_struct rdata;
@@ -1378,7 +1390,7 @@ BOOL samr_delete_dom_group(struct cli_state *cli, uint16 fnum, POLICY_HND *group
        samr_io_q_delete_dom_group("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_DELETE_DOM_GROUP, &data, &rdata))
+       if (rpc_hnd_pipe_req(group_pol, SAMR_DELETE_DOM_GROUP, &data, &rdata))
        {
                SAMR_R_DELETE_DOM_GROUP r_o;
                BOOL p;
@@ -1408,8 +1420,7 @@ BOOL samr_delete_dom_group(struct cli_state *cli, uint16 fnum, POLICY_HND *group
 /****************************************************************************
 do a SAMR Create Domain Group
 ****************************************************************************/
-BOOL samr_create_dom_group(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *domain_pol, const char *acct_name,
+BOOL samr_create_dom_group(  POLICY_HND *domain_pol, const char *acct_name,
                                POLICY_HND *group_pol, uint32 *rid)
 {
        prs_struct data;
@@ -1434,7 +1445,7 @@ BOOL samr_create_dom_group(struct cli_state *cli, uint16 fnum,
        samr_io_q_create_dom_group("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_CREATE_DOM_GROUP, &data, &rdata))
+       if (rpc_hnd_pipe_req(domain_pol, SAMR_CREATE_DOM_GROUP, &data, &rdata))
        {
                SAMR_R_CREATE_DOM_GROUP r_o;
                BOOL p;
@@ -1453,7 +1464,7 @@ BOOL samr_create_dom_group(struct cli_state *cli, uint16 fnum,
                {
                        memcpy(group_pol, &r_o.pol, sizeof(r_o.pol));
                        *rid = r_o.rid;
-                       valid_pol = True;
+                       valid_pol = cli_pol_link(group_pol, domain_pol);
                }
        }
 
@@ -1466,8 +1477,7 @@ BOOL samr_create_dom_group(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Set Group Info
 ****************************************************************************/
-BOOL samr_set_groupinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *group_pol, GROUP_INFO_CTR *ctr)
+BOOL samr_set_groupinfo(  POLICY_HND *group_pol, GROUP_INFO_CTR *ctr)
 {
        prs_struct data;
        prs_struct rdata;
@@ -1491,7 +1501,7 @@ BOOL samr_set_groupinfo(struct cli_state *cli, uint16 fnum,
        samr_io_q_set_groupinfo("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_SET_GROUPINFO, &data, &rdata))
+       if (rpc_hnd_pipe_req(group_pol, SAMR_SET_GROUPINFO, &data, &rdata))
        {
                SAMR_R_SET_GROUPINFO r_o;
                BOOL p;
@@ -1521,8 +1531,7 @@ BOOL samr_set_groupinfo(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Open Domain
 ****************************************************************************/
-BOOL samr_open_domain(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *connect_pol,
+BOOL samr_open_domain(  const POLICY_HND *connect_pol,
                                uint32 ace_perms,
                                const DOM_SID *sid,
                                POLICY_HND *domain_pol)
@@ -1555,7 +1564,7 @@ BOOL samr_open_domain(struct cli_state *cli, uint16 fnum,
        samr_io_q_open_domain("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_OPEN_DOMAIN, &data, &rdata))
+       if (rpc_hnd_pipe_req(connect_pol, SAMR_OPEN_DOMAIN, &data, &rdata))
        {
                SAMR_R_OPEN_DOMAIN r_o;
                BOOL p;
@@ -1573,7 +1582,7 @@ BOOL samr_open_domain(struct cli_state *cli, uint16 fnum,
                if (p)
                {
                        memcpy(domain_pol, &r_o.domain_pol, sizeof(r_o.domain_pol));
-                       valid_pol = True;
+                       valid_pol = cli_pol_link(domain_pol, connect_pol);
                }
        }
 
@@ -1586,8 +1595,7 @@ BOOL samr_open_domain(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Query Lookup Domain
 ****************************************************************************/
-BOOL samr_query_lookup_domain(struct cli_state *cli, uint16 fnum, 
-                             POLICY_HND *pol, const char *dom_name,
+BOOL samr_query_lookup_domain(  POLICY_HND *pol, const char *dom_name,
                              DOM_SID *dom_sid)
 {
        prs_struct data;
@@ -1612,7 +1620,7 @@ BOOL samr_query_lookup_domain(struct cli_state *cli, uint16 fnum,
        samr_io_q_lookup_domain("", &q_o, &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_LOOKUP_DOMAIN, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_LOOKUP_DOMAIN, &data, &rdata))
        {
                SAMR_R_LOOKUP_DOMAIN r_o;
                BOOL p;
@@ -1643,8 +1651,7 @@ BOOL samr_query_lookup_domain(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Query Lookup Names
 ****************************************************************************/
-BOOL samr_query_lookup_names(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint32 flags,
+BOOL samr_query_lookup_names(  POLICY_HND *pol, uint32 flags,
                                uint32 num_names, char **names,
                                uint32 *num_rids,
                                uint32 rid[MAX_LOOKUP_SIDS],
@@ -1673,7 +1680,7 @@ BOOL samr_query_lookup_names(struct cli_state *cli, uint16 fnum,
        samr_io_q_lookup_names("", &q_o, &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_LOOKUP_NAMES, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_LOOKUP_NAMES, &data, &rdata))
        {
                SAMR_R_LOOKUP_NAMES r_o;
                BOOL p;
@@ -1728,8 +1735,7 @@ BOOL samr_query_lookup_names(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Query Lookup RIDS
 ****************************************************************************/
-BOOL samr_query_lookup_rids(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *pol, uint32 flags,
+BOOL samr_query_lookup_rids(  const POLICY_HND *pol, uint32 flags,
                                uint32 num_rids, uint32 *rids,
                                uint32 *num_names,
                                char   ***names,
@@ -1758,7 +1764,7 @@ BOOL samr_query_lookup_rids(struct cli_state *cli, uint16 fnum,
        samr_io_q_lookup_rids("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_LOOKUP_RIDS, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_LOOKUP_RIDS, &data, &rdata))
        {
                SAMR_R_LOOKUP_RIDS r_o;
                BOOL p;
@@ -1827,8 +1833,7 @@ BOOL samr_query_lookup_rids(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Query Alias Members
 ****************************************************************************/
-BOOL samr_query_aliasmem(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *alias_pol, 
+BOOL samr_query_aliasmem(  const POLICY_HND *alias_pol, 
                                uint32 *num_mem, DOM_SID2 *sid)
 {
        prs_struct data;
@@ -1853,7 +1858,7 @@ BOOL samr_query_aliasmem(struct cli_state *cli, uint16 fnum,
        samr_io_q_query_aliasmem("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_ALIASMEM, &data, &rdata))
+       if (rpc_hnd_pipe_req(alias_pol, SAMR_QUERY_ALIASMEM, &data, &rdata))
        {
                SAMR_R_QUERY_ALIASMEM r_o;
                BOOL p;
@@ -1888,8 +1893,7 @@ BOOL samr_query_aliasmem(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Query User Aliases
 ****************************************************************************/
-BOOL samr_query_useraliases(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *pol,
+BOOL samr_query_useraliases(  const POLICY_HND *pol,
                                uint32 *ptr_sid, DOM_SID2 *sid,
                                uint32 *num_aliases, uint32 **rid)
 {
@@ -1916,7 +1920,7 @@ BOOL samr_query_useraliases(struct cli_state *cli, uint16 fnum,
        samr_io_q_query_useraliases("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_USERALIASES, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_QUERY_USERALIASES, &data, &rdata))
        {
                SAMR_R_QUERY_USERALIASES r_o;
                BOOL p;
@@ -1951,8 +1955,7 @@ BOOL samr_query_useraliases(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Query Group Members
 ****************************************************************************/
-BOOL samr_query_groupmem(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *group_pol, 
+BOOL samr_query_groupmem(  POLICY_HND *group_pol, 
                                uint32 *num_mem, uint32 **rid, uint32 **attr)
 {
        prs_struct data;
@@ -1977,7 +1980,7 @@ BOOL samr_query_groupmem(struct cli_state *cli, uint16 fnum,
        samr_io_q_query_groupmem("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_GROUPMEM, &data, &rdata))
+       if (rpc_hnd_pipe_req(group_pol, SAMR_QUERY_GROUPMEM, &data, &rdata))
        {
                SAMR_R_QUERY_GROUPMEM r_o;
                BOOL p;
@@ -2016,8 +2019,7 @@ BOOL samr_query_groupmem(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Query User Groups
 ****************************************************************************/
-BOOL samr_query_usergroups(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint32 *num_groups,
+BOOL samr_query_usergroups(  POLICY_HND *pol, uint32 *num_groups,
                                DOM_GID **gid)
 {
        prs_struct data;
@@ -2042,7 +2044,7 @@ BOOL samr_query_usergroups(struct cli_state *cli, uint16 fnum,
        samr_io_q_query_usergroups("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_USERGROUPS, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_QUERY_USERGROUPS, &data, &rdata))
        {
                SAMR_R_QUERY_USERGROUPS r_o;
                BOOL p;
@@ -2078,8 +2080,7 @@ BOOL samr_query_usergroups(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Query Group Info
 ****************************************************************************/
-BOOL samr_query_groupinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol,
+BOOL samr_query_groupinfo(  POLICY_HND *pol,
                                uint16 switch_value, GROUP_INFO_CTR* ctr)
 {
        prs_struct data;
@@ -2104,7 +2105,7 @@ BOOL samr_query_groupinfo(struct cli_state *cli, uint16 fnum,
        samr_io_q_query_groupinfo("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_GROUPINFO, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_QUERY_GROUPINFO, &data, &rdata))
        {
                SAMR_R_QUERY_GROUPINFO r_o;
                BOOL p;
@@ -2143,8 +2144,7 @@ BOOL samr_query_groupinfo(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Set User Info
 ****************************************************************************/
-BOOL samr_set_userinfo2(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint16 switch_value,
+BOOL samr_set_userinfo2(  POLICY_HND *pol, uint16 switch_value,
                                void* usr)
 {
        prs_struct data;
@@ -2169,7 +2169,7 @@ BOOL samr_set_userinfo2(struct cli_state *cli, uint16 fnum,
        samr_io_q_set_userinfo2("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_SET_USERINFO2, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_SET_USERINFO2, &data, &rdata))
        {
                SAMR_R_SET_USERINFO2 r_o;
                BOOL p;
@@ -2199,8 +2199,7 @@ BOOL samr_set_userinfo2(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Set User Info
 ****************************************************************************/
-BOOL samr_set_userinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint16 switch_value, void* usr)
+BOOL samr_set_userinfo(  POLICY_HND *pol, uint16 switch_value, void* usr)
 {
        prs_struct data;
        prs_struct rdata;
@@ -2224,7 +2223,7 @@ BOOL samr_set_userinfo(struct cli_state *cli, uint16 fnum,
        samr_io_q_set_userinfo("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_SET_USERINFO, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_SET_USERINFO, &data, &rdata))
        {
                SAMR_R_SET_USERINFO r_o;
                BOOL p;
@@ -2254,8 +2253,7 @@ BOOL samr_set_userinfo(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Query User Info
 ****************************************************************************/
-BOOL samr_query_userinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol, uint16 switch_value, void* usr)
+BOOL samr_query_userinfo(  POLICY_HND *pol, uint16 switch_value, void* usr)
 {
        prs_struct data;
        prs_struct rdata;
@@ -2279,7 +2277,7 @@ BOOL samr_query_userinfo(struct cli_state *cli, uint16 fnum,
        samr_io_q_query_userinfo("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_USERINFO, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol, SAMR_QUERY_USERINFO, &data, &rdata))
        {
                SAMR_R_QUERY_USERINFO r_o;
                BOOL p;
@@ -2318,7 +2316,7 @@ BOOL samr_query_userinfo(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR Close
 ****************************************************************************/
-BOOL samr_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
+BOOL samr_close(  POLICY_HND *hnd)
 {
        prs_struct data;
        prs_struct rdata;
@@ -2342,7 +2340,7 @@ BOOL samr_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
        samr_io_q_close_hnd("", &q_c,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_CLOSE_HND, &data, &rdata))
+       if (rpc_hnd_pipe_req(hnd, SAMR_CLOSE_HND, &data, &rdata))
        {
                SAMR_R_CLOSE_HND r_c;
                BOOL p;
@@ -2381,14 +2379,15 @@ BOOL samr_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
        prs_mem_free(&data   );
        prs_mem_free(&rdata  );
 
+       close_policy_hnd(hnd);
+
        return valid_close;
 }
 
 /****************************************************************************
 do a SAMR query display info
 ****************************************************************************/
-BOOL samr_query_dispinfo(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol_open_domain, uint16 level,
+BOOL samr_query_dispinfo(  POLICY_HND *pol_domain, uint16 level,
                                uint32 *num_entries,
                                SAM_DISPINFO_CTR *ctr)
 {
@@ -2400,7 +2399,7 @@ BOOL samr_query_dispinfo(struct cli_state *cli, uint16 fnum,
 
        DEBUG(4,("SAMR Query Display Info.  level: %d\n", level));
 
-       if (pol_open_domain == NULL || num_entries == NULL || ctr == NULL ||
+       if (pol_domain == NULL || num_entries == NULL || ctr == NULL ||
            level == 0)
        {
                return False;
@@ -2412,13 +2411,13 @@ BOOL samr_query_dispinfo(struct cli_state *cli, uint16 fnum,
        prs_init(&rdata, 0   , 4, SAFETY_MARGIN, True );
 
        /* store the parameters */
-       make_samr_q_query_dispinfo(&q_o, pol_open_domain, level, 0, 0xffffffff);
+       make_samr_q_query_dispinfo(&q_o, pol_domain, level, 0, 0xffffffff);
 
        /* turn parameters into data stream */
        samr_io_q_query_dispinfo("", &q_o,  &data, 0);
 
        /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_DISPINFO, &data, &rdata))
+       if (rpc_hnd_pipe_req(pol_domain, SAMR_QUERY_DISPINFO, &data, &rdata))
        {
                SAMR_R_QUERY_DISPINFO r_o;
                BOOL p;
index d5a37832f387f0026b6753fcb988eeced98dad02..8dd5201bb1ca39446e22a4b0f7ed1918623132bf 100644 (file)
@@ -33,8 +33,7 @@ extern int DEBUGLEVEL;
 
 #define DEBUG_TESTING
 
-BOOL req_user_info(struct cli_state *cli, uint16 fnum,
-                               POLICY_HND *pol_dom,
+BOOL req_user_info( POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
                                uint32 user_rid,
@@ -42,7 +41,7 @@ BOOL req_user_info(struct cli_state *cli, uint16 fnum,
 {
        SAM_USER_INFO_21 usr;
        /* send user info query, level 0x15 */
-       if (get_samr_query_userinfo(cli, fnum,
+       if (get_samr_query_userinfo(
                                    pol_dom,
                                    0x15, user_rid, &usr))
        {
@@ -58,7 +57,7 @@ BOOL req_user_info(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 SAM Query User Groups.
 ****************************************************************************/
-uint32 sam_query_usergroups(struct cli_state *cli, uint16 fnum,
+uint32 sam_query_usergroups(
                                const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
@@ -73,7 +72,7 @@ uint32 sam_query_usergroups(struct cli_state *cli, uint16 fnum,
        uint32 num_names = 0;
        (*gid) = NULL;
        /* send user group query */
-       if (get_samr_query_usergroups(cli, fnum,
+       if (get_samr_query_usergroups(
                                      pol_dom,
                                      user_rid, num_groups, gid) &&
            gid != NULL)
@@ -95,7 +94,7 @@ uint32 sam_query_usergroups(struct cli_state *cli, uint16 fnum,
                        rid_mem[i] = (*gid)[i].g_rid;
                }
 
-               if (samr_query_lookup_rids(cli, fnum, 
+               if (samr_query_lookup_rids(
                                pol_dom, 0x3e8,
                                (*num_groups), rid_mem, 
                                &num_names, name, type))
@@ -109,7 +108,7 @@ uint32 sam_query_usergroups(struct cli_state *cli, uint16 fnum,
        return num_names;
 }
 
-static uint32 req_group_info(struct cli_state *cli, uint16 fnum,
+static uint32 req_group_info(
                                const POLICY_HND *pol_dom,
                                const char *domain, const DOM_SID *sid,
                                uint32 user_rid, const char *user_name,
@@ -121,7 +120,7 @@ static uint32 req_group_info(struct cli_state *cli, uint16 fnum,
        char    **name   = NULL;
        uint32  *type    = NULL;
 
-       num_names = sam_query_usergroups(cli, fnum, pol_dom,
+       num_names = sam_query_usergroups( pol_dom,
                                domain, sid,
                                user_rid, user_name,
                                &num_groups, &gid,
@@ -141,7 +140,7 @@ static uint32 req_group_info(struct cli_state *cli, uint16 fnum,
        return num_names;
 }
 
-static void req_alias_info(struct cli_state *cli, uint16 fnum,
+static void req_alias_info(
                                const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid1, uint32 user_rid,
@@ -163,7 +162,7 @@ static void req_alias_info(struct cli_state *cli, uint16 fnum,
        ptr_sid[0] = 1;
 
        /* send user alias query */
-       if (samr_query_useraliases(cli, fnum,
+       if (samr_query_useraliases(
                                pol_dom,
                                ptr_sid, als_sid, &num_aliases, &rid_mem))
        {
@@ -180,7 +179,7 @@ static void req_alias_info(struct cli_state *cli, uint16 fnum,
                        {
                                rid_copy[i] = rid_mem[i];
                        }
-                       if (samr_query_lookup_rids(cli, fnum, 
+                       if (samr_query_lookup_rids( 
                                        pol_dom, 0x3e8,
                                        num_aliases, rid_copy, 
                                        &num_names, &name, &type))
@@ -219,10 +218,9 @@ static void req_alias_info(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 experimental SAM users enum.
 ****************************************************************************/
-int msrpc_sam_enum_users(struct cli_state *cli,
+int msrpc_sam_enum_users( const char* srv_name,
                        const char* domain,
                        const DOM_SID *sid1,
-                       const char* srv_name,
                        struct acct_info **sam,
                        uint32 *num_sam_entries,
                        USER_FN(usr_fn),
@@ -230,7 +228,6 @@ int msrpc_sam_enum_users(struct cli_state *cli,
                        USER_MEM_FN(usr_grp_fn),
                        USER_MEM_FN(usr_als_fn))
 {
-       uint16 fnum;
        DOM_SID sid_1_5_20;
        uint32 user_idx;
        BOOL res = True;
@@ -254,22 +251,16 @@ int msrpc_sam_enum_users(struct cli_state *cli,
        DEBUG(5,("Number of entries:%d unk_0:%04x acb_mask:%04x unk_1:%04x\n",
                  start_idx, unk_0, acb_mask, unk_1));
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(cli, fnum, 
-                               srv_name, 0x02000000,
+       res = res ? samr_connect( srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res1 = res ? samr_open_domain(cli, fnum, 
-                   &sam_pol, ace_perms, sid1,
+       res1 = res ? samr_open_domain( &sam_pol, ace_perms, sid1,
                    &pol_dom) : False;
 
        /* connect to the S-1-5-20 domain */
-       res2 = res ? samr_open_domain(cli, fnum, 
-                   &sam_pol, ace_perms, &sid_1_5_20,
+       res2 = res ? samr_open_domain( &sam_pol, ace_perms, &sid_1_5_20,
                    &pol_blt) : False;
 
        if (res1)
@@ -277,7 +268,7 @@ int msrpc_sam_enum_users(struct cli_state *cli,
                /* read some users */
                do
                {
-                       status = samr_enum_dom_users(cli, fnum, 
+                       status = samr_enum_dom_users(
                             &pol_dom,
                             &start_idx, acb_mask, unk_1, 0x100000,
                             sam, num_sam_entries);
@@ -305,7 +296,7 @@ int msrpc_sam_enum_users(struct cli_state *cli,
 
                        if (usr_inf_fn != NULL)
                        {
-                               req_user_info(cli, fnum, &pol_dom,
+                               req_user_info(&pol_dom,
                                                  domain, sid1,
                                                  user_rid, 
                                                  usr_inf_fn);
@@ -313,7 +304,7 @@ int msrpc_sam_enum_users(struct cli_state *cli,
 
                        if (usr_grp_fn != NULL)
                        {
-                               req_group_info(cli, fnum, &pol_dom,
+                               req_group_info(&pol_dom,
                                                  domain, sid1,
                                                  user_rid, user_name,
                                                  usr_grp_fn);
@@ -321,11 +312,11 @@ int msrpc_sam_enum_users(struct cli_state *cli,
 
                        if (usr_als_fn != NULL)
                        {
-                               req_alias_info(cli, fnum, &pol_dom,
+                               req_alias_info(&pol_dom,
                                                  domain, sid1,
                                                  user_rid, user_name,
                                                  usr_als_fn);
-                               req_alias_info(cli, fnum, &pol_blt,
+                               req_alias_info(&pol_blt,
                                                  domain, sid1,
                                                  user_rid, user_name,
                                                  usr_als_fn);
@@ -333,12 +324,9 @@ int msrpc_sam_enum_users(struct cli_state *cli,
                }
        }
 
-       res2 = res2 ? samr_close(cli, fnum, &pol_blt) : False;
-       res1 = res1 ? samr_close(cli, fnum, &pol_dom) : False;
-       res  = res  ? samr_close(cli, fnum, &sam_pol) : False;
-
-       /* close the session */
-       cli_nt_session_close(cli, fnum);
+       res2 = res2 ? samr_close( &pol_blt) : False;
+       res1 = res1 ? samr_close( &pol_dom) : False;
+       res  = res  ? samr_close( &sam_pol) : False;
 
        if (res)
        {
@@ -356,12 +344,10 @@ int msrpc_sam_enum_users(struct cli_state *cli,
 /****************************************************************************
 experimental SAM domain info query.
 ****************************************************************************/
-BOOL sam_query_dominfo(struct cli_state *cli, 
+BOOL sam_query_dominfo(const char* srv_name,
                                const DOM_SID *sid1,
                                uint32 switch_value, SAM_UNK_CTR *ctr)
 {
-       uint16 fnum;
-       fstring srv_name;
        BOOL res = True;
        BOOL res1 = True;
        BOOL res2 = True;
@@ -369,36 +355,26 @@ BOOL sam_query_dominfo(struct cli_state *cli,
        POLICY_HND sam_pol;
        POLICY_HND pol_dom;
 
-       fstrcpy(srv_name, "\\\\");
-       fstrcat(srv_name, cli->desthost);
-       strupper(srv_name);
-
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res1 = res ? samr_open_domain(cli, fnum, 
+       res1 = res ? samr_open_domain( 
                    &sam_pol, ace_perms, sid1,
                    &pol_dom) : False;
 
        /* send a samr 0x8 command */
-       res2 = res ? samr_query_dom_info(cli, fnum,
+       res2 = res ? samr_query_dom_info(
                    &pol_dom, switch_value, ctr) : False;
 
-       res1 = res1 ? samr_close(cli, fnum,
+       res1 = res1 ? samr_close(
                    &sam_pol) : False;
 
-       res = res ? samr_close(cli, fnum, 
+       res = res ? samr_close( 
                    &pol_dom) : False;
 
-       /* close the session */
-       cli_nt_session_close(cli, fnum);
-
        if (res2)
        {
                DEBUG(5,("sam_query_dominfo: succeeded\n"));
@@ -412,7 +388,7 @@ BOOL sam_query_dominfo(struct cli_state *cli,
 }
 
 
-BOOL query_aliasinfo(struct cli_state *cli, uint16 fnum,
+BOOL query_aliasinfo(
                                const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
@@ -422,7 +398,7 @@ BOOL query_aliasinfo(struct cli_state *cli, uint16 fnum,
        ALIAS_INFO_CTR ctr;
 
        /* send alias info query */
-       if (get_samr_query_aliasinfo(cli, fnum,
+       if (get_samr_query_aliasinfo(
                                      pol_dom,
                                      3, /* info level */
                                      alias_rid, &ctr))
@@ -436,7 +412,7 @@ BOOL query_aliasinfo(struct cli_state *cli, uint16 fnum,
        return False;
 }
 
-BOOL sam_query_aliasmem(struct cli_state *cli, uint16 fnum,
+BOOL sam_query_aliasmem(const char *srv_name,
                                const POLICY_HND *pol_dom,
                                uint32 alias_rid,
                                uint32 *num_names,
@@ -455,22 +431,17 @@ BOOL sam_query_aliasmem(struct cli_state *cli, uint16 fnum,
        *type = NULL;
 
        /* get alias members */
-       res3 = get_samr_query_aliasmem(cli, fnum, 
+       res3 = get_samr_query_aliasmem( 
                        pol_dom,
                        alias_rid, &num_aliases, sid_mem);
 
        if (res3 && num_aliases != 0)
        {
-               fstring srv_name;
                POLICY_HND lsa_pol;
 
                uint32 i;
                uint32 numsids = 0;
 
-               fstrcpy(srv_name, "\\\\");
-               fstrcat(srv_name, cli->desthost);
-               strupper(srv_name);
-
                for (i = 0; i < num_aliases; i++)
                {
                        add_sid_to_array(&numsids, sids, &sid_mem[i].sid);
@@ -508,7 +479,7 @@ BOOL sam_query_aliasmem(struct cli_state *cli, uint16 fnum,
        return res4;
 }
 
-BOOL req_aliasmem_info(struct cli_state *cli, uint16 fnum,
+BOOL req_aliasmem_info(const char* srv_name,
                                const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
@@ -521,7 +492,7 @@ BOOL req_aliasmem_info(struct cli_state *cli, uint16 fnum,
        uint8 *type = NULL;
        DOM_SID **sids = NULL;
 
-       if (sam_query_aliasmem(cli, fnum, pol_dom, alias_rid,
+       if (sam_query_aliasmem( srv_name, pol_dom, alias_rid,
                                        &num_names, &sids,
                                        &name, &type))
        {
@@ -543,7 +514,7 @@ BOOL req_aliasmem_info(struct cli_state *cli, uint16 fnum,
        return False;
 }
 
-BOOL sam_query_groupmem(struct cli_state *cli, uint16 fnum,
+BOOL sam_query_groupmem(
                                const POLICY_HND *pol_dom,
                                uint32 group_rid,
                                uint32 *num_names,
@@ -561,7 +532,7 @@ BOOL sam_query_groupmem(struct cli_state *cli, uint16 fnum,
        *type = NULL;
 
        /* get group members */
-       res3 = get_samr_query_groupmem(cli, fnum, 
+       res3 = get_samr_query_groupmem( 
                pol_dom,
                group_rid, &num_mem, rid_mem, &attr_mem);
 
@@ -578,7 +549,7 @@ BOOL sam_query_groupmem(struct cli_state *cli, uint16 fnum,
                                rid_copy[i] = (*rid_mem)[i];
                        }
                        /* resolve names */
-                       res3 = samr_query_lookup_rids(cli, fnum,
+                       res3 = samr_query_lookup_rids(
                                   pol_dom, 1000,
                                   num_mem, rid_copy, num_names, name, type);
                }
@@ -617,8 +588,7 @@ BOOL sam_query_groupmem(struct cli_state *cli, uint16 fnum,
        return res3;
 }
 
-BOOL query_groupinfo(struct cli_state *cli, uint16 fnum,
-                               const POLICY_HND *pol_dom,
+BOOL query_groupinfo( const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
                                uint32 group_rid,
@@ -627,7 +597,7 @@ BOOL query_groupinfo(struct cli_state *cli, uint16 fnum,
        GROUP_INFO_CTR ctr;
 
        /* send group info query */
-       if (get_samr_query_groupinfo(cli, fnum,
+       if (get_samr_query_groupinfo(
                                      pol_dom,
                                      1, /* info level */
                                      group_rid, &ctr))
@@ -641,8 +611,7 @@ BOOL query_groupinfo(struct cli_state *cli, uint16 fnum,
        return False;
 }
 
-BOOL req_groupmem_info(struct cli_state *cli, uint16 fnum,
-                               const POLICY_HND *pol_dom,
+BOOL req_groupmem_info( const POLICY_HND *pol_dom,
                                const char *domain,
                                const DOM_SID *sid,
                                uint32 group_rid,
@@ -654,7 +623,7 @@ BOOL req_groupmem_info(struct cli_state *cli, uint16 fnum,
        uint32 *type = NULL;
        uint32 *rid_mem = NULL;
 
-       if (sam_query_groupmem(cli, fnum, pol_dom, group_rid,
+       if (sam_query_groupmem(pol_dom, group_rid,
                                &num_names, &rid_mem, &name, &type))
        {
                grp_mem(domain, sid,
@@ -680,24 +649,18 @@ SAM Domains query.
                                DOMAIN_INFO_FN(dom_inf_fn),
                                DOMAIN_MEM_FN(dom_mem_fn))
 ****************************************************************************/
-uint32 msrpc_sam_enum_domains(struct cli_state *cli,
-                               const char* srv_name,
+uint32 msrpc_sam_enum_domains( const char* srv_name,
                                struct acct_info **sam,
                                uint32 *num_sam_entries,
                                DOMAIN_FN(dom_fn))
 {
-       uint16 fnum;
        BOOL res = True;
        uint32 ace_perms = 0x02000000; /* access control permissions. */
        POLICY_HND sam_pol;
        uint32 status;
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(cli, fnum,
-                               srv_name, ace_perms,
+       res = res ? samr_connect( srv_name, ace_perms,
                                &sam_pol) : False;
 
        (*sam) = NULL;
@@ -710,8 +673,7 @@ uint32 msrpc_sam_enum_domains(struct cli_state *cli,
                /* read some domains */
                do
                {
-                       status = samr_enum_domains(cli, fnum, 
-                            &sam_pol,
+                       status = samr_enum_domains( &sam_pol,
                             &start_idx, 0x10000,
                             sam, num_sam_entries);
 
@@ -736,13 +698,13 @@ uint32 msrpc_sam_enum_domains(struct cli_state *cli,
 #if 0
                        if (dom_inf_fn != NULL)
                        {
-                               query_domaininfo(cli, fnum, &sam_pol,
+                               query_domaininfo(&sam_pol,
                                                  domain_name,
                                                  dom_inf_fn);
                        }
                        if (dom_mem_fn != NULL)
                        {
-                               req_domainmem_info(cli, fnum, &sam_pol,
+                               req_domainmem_info(&sam_pol,
                                                  domain_name,
                                                  dom_mem_fn);
                        }
@@ -750,10 +712,7 @@ uint32 msrpc_sam_enum_domains(struct cli_state *cli,
                }
        }
 
-       res = res ? samr_close(cli, fnum, &sam_pol) : False;
-
-       /* close the session */
-       cli_nt_session_close(cli, fnum);
+       res = res ? samr_close(&sam_pol) : False;
 
        if (res)
        {
@@ -769,34 +728,27 @@ uint32 msrpc_sam_enum_domains(struct cli_state *cli,
 /****************************************************************************
 SAM groups query.
 ****************************************************************************/
-uint32 msrpc_sam_enum_groups(struct cli_state *cli,
+uint32 msrpc_sam_enum_groups( const char* srv_name,
                                const char* domain,
                                const DOM_SID *sid1,
-                               const char* srv_name,
                                struct acct_info **sam,
                                uint32 *num_sam_entries,
                                GROUP_FN(grp_fn),
                                GROUP_INFO_FN(grp_inf_fn),
                                GROUP_MEM_FN(grp_mem_fn))
 {
-       uint16 fnum;
        BOOL res = True;
        uint32 ace_perms = 0x02000000; /* access control permissions. */
        POLICY_HND sam_pol;
        POLICY_HND pol_dom;
        uint32 status;
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(cli, fnum,
-                               srv_name, 0x02000000,
+       res = res ? samr_connect( srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(cli, fnum,
-                   &sam_pol, ace_perms, sid1,
+       res = res ? samr_open_domain( &sam_pol, ace_perms, sid1,
                    &pol_dom) : False;
 
        (*sam) = NULL;
@@ -809,7 +761,7 @@ uint32 msrpc_sam_enum_groups(struct cli_state *cli,
                /* read some groups */
                do
                {
-                       status = samr_enum_dom_groups(cli, fnum, 
+                       status = samr_enum_dom_groups(
                             &pol_dom,
                             &start_idx, 0x100000,
                             sam, num_sam_entries);
@@ -835,14 +787,14 @@ uint32 msrpc_sam_enum_groups(struct cli_state *cli,
 
                        if (grp_inf_fn != NULL)
                        {
-                               query_groupinfo(cli, fnum, &pol_dom,
+                               query_groupinfo(&pol_dom,
                                                  domain, sid1,
                                                  group_rid, 
                                                  grp_inf_fn);
                        }
                        if (grp_mem_fn != NULL)
                        {
-                               req_groupmem_info(cli, fnum, &pol_dom,
+                               req_groupmem_info(&pol_dom,
                                                  domain, sid1,
                                                  group_rid, group_name,
                                                  grp_mem_fn);
@@ -850,11 +802,8 @@ uint32 msrpc_sam_enum_groups(struct cli_state *cli,
                }
        }
 
-       res = res ? samr_close(cli, fnum, &pol_dom) : False;
-       res = res ? samr_close(cli, fnum, &sam_pol) : False;
-
-       /* close the session */
-       cli_nt_session_close(cli, fnum);
+       res = res ? samr_close(&pol_dom) : False;
+       res = res ? samr_close(&sam_pol) : False;
 
        if (res)
        {
@@ -870,33 +819,27 @@ uint32 msrpc_sam_enum_groups(struct cli_state *cli,
 /****************************************************************************
 SAM aliases query.
 ****************************************************************************/
-uint32 msrpc_sam_enum_aliases(struct cli_state *cli,
+uint32 msrpc_sam_enum_aliases( const char* srv_name,
                                const char* domain,
                                const DOM_SID *sid1,
-                               const char* srv_name,
                                struct acct_info **sam,
                                uint32 *num_sam_entries,
                                ALIAS_FN(als_fn),
                                ALIAS_INFO_FN(als_inf_fn),
                                ALIAS_MEM_FN(als_mem_fn))
 {
-       uint16 fnum;
        BOOL res = True;
        uint32 ace_perms = 0x02000000; /* access control permissions */
        POLICY_HND sam_pol;
        POLICY_HND pol_dom;
        uint32 status = 0x0;
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(cli, fnum,
-                               srv_name, 0x02000000,
+       res = res ? samr_connect( srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(cli, fnum,
+       res = res ? samr_open_domain(
                    &sam_pol, ace_perms, sid1,
                    &pol_dom) : False;
 
@@ -910,7 +853,7 @@ uint32 msrpc_sam_enum_aliases(struct cli_state *cli,
                /* read some groups */
                do
                {
-                       status = samr_enum_dom_aliases(cli, fnum, 
+                       status = samr_enum_dom_aliases(
                             &pol_dom,
                             &start_idx, 0x100000,
                             sam, num_sam_entries);
@@ -936,14 +879,14 @@ uint32 msrpc_sam_enum_aliases(struct cli_state *cli,
 
                        if (als_inf_fn != NULL)
                        {
-                               query_aliasinfo(cli, fnum, &pol_dom,
+                               query_aliasinfo(&pol_dom,
                                                  domain, sid1,
                                                  alias_rid, 
                                                  als_inf_fn);
                        }
                        if (als_mem_fn != NULL)
                        {
-                               req_aliasmem_info(cli, fnum, &pol_dom,
+                               req_aliasmem_info(srv_name, &pol_dom,
                                                  domain, sid1,
                                                  alias_rid, alias_name,
                                                  als_mem_fn);
@@ -951,11 +894,8 @@ uint32 msrpc_sam_enum_aliases(struct cli_state *cli,
                }
        }
 
-       res = res ? samr_close(cli, fnum, &sam_pol) : False;
-       res = res ? samr_close(cli, fnum, &pol_dom) : False;
-
-       /* close the session */
-       cli_nt_session_close(cli, fnum);
+       res = res ? samr_close(&sam_pol) : False;
+       res = res ? samr_close(&pol_dom) : False;
 
        if (res)
        {
@@ -972,8 +912,7 @@ uint32 msrpc_sam_enum_aliases(struct cli_state *cli,
 /****************************************************************************
 do a SAMR create domain user
 ****************************************************************************/
-BOOL create_samr_domain_user(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol_open_domain,
+BOOL create_samr_domain_user( POLICY_HND *pol_open_domain,
                                const char *acct_name, uint16 acb_info,
                                uint32 *rid)
 {
@@ -983,8 +922,7 @@ BOOL create_samr_domain_user(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL || acct_name == NULL) return False;
 
        /* send create user */
-       if (!samr_create_dom_user(cli, fnum,
-                               pol_open_domain,
+       if (!samr_create_dom_user( pol_open_domain,
                                acct_name, acb_info, 0xe005000b,
                                &pol_open_user, rid))
        {
@@ -994,14 +932,13 @@ BOOL create_samr_domain_user(struct cli_state *cli, uint16 fnum,
        DEBUG(5,("create_samr_domain_user: name: %s rid 0x%x\n",
                  acct_name, *rid));
 
-       return samr_close(cli, fnum, &pol_open_user) && ret;
+       return samr_close(&pol_open_user) && ret;
 }
 
 /****************************************************************************
 do a SAMR create domain alias
 ****************************************************************************/
-BOOL create_samr_domain_alias(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *pol_open_domain,
+BOOL create_samr_domain_alias( POLICY_HND *pol_open_domain,
                                const char *acct_name, const char *acct_desc,
                                uint32 *rid)
 {
@@ -1012,7 +949,7 @@ BOOL create_samr_domain_alias(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL || acct_name == NULL || acct_desc == NULL) return False;
 
        /* send create alias */
-       if (!samr_create_dom_alias(cli, fnum,
+       if (!samr_create_dom_alias(
                                pol_open_domain,
                                acct_name,
                                &pol_open_alias, rid))
@@ -1027,7 +964,7 @@ BOOL create_samr_domain_alias(struct cli_state *cli, uint16 fnum,
        make_samr_alias_info3(&ctr.alias.info3, acct_desc);
 
        /* send set alias info */
-       if (!samr_set_aliasinfo(cli, fnum,
+       if (!samr_set_aliasinfo(
                                &pol_open_alias,
                                &ctr))
        {
@@ -1035,13 +972,13 @@ BOOL create_samr_domain_alias(struct cli_state *cli, uint16 fnum,
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_alias) && ret;
+       return samr_close(&pol_open_alias) && ret;
 }
 
 /****************************************************************************
 do a SAMR create domain group
 ****************************************************************************/
-BOOL create_samr_domain_group(struct cli_state *cli, uint16 fnum, 
+BOOL create_samr_domain_group(
                                POLICY_HND *pol_open_domain,
                                const char *acct_name, const char *acct_desc,
                                uint32 *rid)
@@ -1053,7 +990,7 @@ BOOL create_samr_domain_group(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL || acct_name == NULL || acct_desc == NULL) return False;
 
        /* send create group*/
-       if (!samr_create_dom_group(cli, fnum,
+       if (!samr_create_dom_group(
                                pol_open_domain,
                                acct_name,
                                &pol_open_group, rid))
@@ -1069,7 +1006,7 @@ BOOL create_samr_domain_group(struct cli_state *cli, uint16 fnum,
        make_samr_group_info4(&ctr.group.info4, acct_desc);
 
        /* send user groups query */
-       if (!samr_set_groupinfo(cli, fnum,
+       if (!samr_set_groupinfo(
                                &pol_open_group,
                                &ctr))
        {
@@ -1077,14 +1014,13 @@ BOOL create_samr_domain_group(struct cli_state *cli, uint16 fnum,
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_group) && ret;
+       return samr_close(&pol_open_group) && ret;
 }
 
 /****************************************************************************
 do a SAMR query user groups
 ****************************************************************************/
-BOOL get_samr_query_usergroups(struct cli_state *cli, uint16 fnum, 
-                               const POLICY_HND *pol_open_domain,
+BOOL get_samr_query_usergroups( const POLICY_HND *pol_open_domain,
                                uint32 user_rid,
                                uint32 *num_groups, DOM_GID **gid)
 {
@@ -1094,7 +1030,7 @@ BOOL get_samr_query_usergroups(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL || num_groups == NULL || gid == NULL) return False;
 
        /* send open domain (on user sid) */
-       if (!samr_open_user(cli, fnum,
+       if (!samr_open_user(
                                pol_open_domain,
                                0x02011b, user_rid,
                                &pol_open_user))
@@ -1103,7 +1039,7 @@ BOOL get_samr_query_usergroups(struct cli_state *cli, uint16 fnum,
        }
 
        /* send user groups query */
-       if (!samr_query_usergroups(cli, fnum,
+       if (!samr_query_usergroups(
                                &pol_open_user,
                                num_groups, gid))
        {
@@ -1111,13 +1047,13 @@ BOOL get_samr_query_usergroups(struct cli_state *cli, uint16 fnum,
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_user) && ret;
+       return samr_close(&pol_open_user) && ret;
 }
 
 /****************************************************************************
 do a SAMR delete group 
 ****************************************************************************/
-BOOL delete_samr_dom_group(struct cli_state *cli, uint16 fnum, 
+BOOL delete_samr_dom_group(
                                POLICY_HND *pol_open_domain,
                                uint32 group_rid)
 {
@@ -1126,7 +1062,7 @@ BOOL delete_samr_dom_group(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL) return False;
 
        /* send open domain (on group rid) */
-       if (!samr_open_group(cli, fnum,pol_open_domain,
+       if (!samr_open_group(pol_open_domain,
                                0x00000010, group_rid,
                                &pol_open_group))
        {
@@ -1134,11 +1070,11 @@ BOOL delete_samr_dom_group(struct cli_state *cli, uint16 fnum,
        }
 
        /* send group delete */
-       if (!samr_delete_dom_group(cli, fnum,&pol_open_group))
+       if (!samr_delete_dom_group(&pol_open_group))
                                
        {
                DEBUG(5,("delete_samr_dom_group: error in delete domain group\n"));
-               samr_close(cli, fnum,&pol_open_group);
+               samr_close(&pol_open_group);
                return False;
        }
 
@@ -1149,7 +1085,7 @@ BOOL delete_samr_dom_group(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR query group members 
 ****************************************************************************/
-BOOL get_samr_query_groupmem(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_groupmem( 
                                const POLICY_HND *pol_open_domain,
                                uint32 group_rid, uint32 *num_mem,
                                uint32 **rid, uint32 **attr)
@@ -1160,7 +1096,7 @@ BOOL get_samr_query_groupmem(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL || num_mem == NULL || rid == NULL || attr == NULL) return False;
 
        /* send open domain (on group sid) */
-       if (!samr_open_group(cli, fnum, pol_open_domain,
+       if (!samr_open_group( pol_open_domain,
                                0x00000010, group_rid,
                                &pol_open_group))
        {
@@ -1168,20 +1104,20 @@ BOOL get_samr_query_groupmem(struct cli_state *cli, uint16 fnum,
        }
 
        /* send group info query */
-       if (!samr_query_groupmem(cli, fnum,&pol_open_group, num_mem, rid, attr))
+       if (!samr_query_groupmem(&pol_open_group, num_mem, rid, attr))
                                
        {
                DEBUG(5,("samr_query_group: error in query group members\n"));
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_group) && ret;
+       return samr_close(&pol_open_group) && ret;
 }
 
 /****************************************************************************
 do a SAMR delete alias 
 ****************************************************************************/
-BOOL delete_samr_dom_alias(struct cli_state *cli, uint16 fnum, 
+BOOL delete_samr_dom_alias( 
                                POLICY_HND *pol_open_domain,
                                uint32 alias_rid)
 {
@@ -1190,18 +1126,18 @@ BOOL delete_samr_dom_alias(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL) return False;
 
        /* send open domain (on alias rid) */
-       if (!samr_open_alias(cli, fnum,pol_open_domain,
+       if (!samr_open_alias(pol_open_domain,
                                0x000f001f, alias_rid, &pol_open_alias))
        {
                return False;
        }
 
        /* send alias delete */
-       if (!samr_delete_dom_alias(cli, fnum,&pol_open_alias))
+       if (!samr_delete_dom_alias(&pol_open_alias))
                                
        {
                DEBUG(5,("delete_samr_dom_alias: error in delete domain alias\n"));
-               samr_close(cli, fnum,&pol_open_alias);
+               samr_close(&pol_open_alias);
                return False;
        }
 
@@ -1212,7 +1148,7 @@ BOOL delete_samr_dom_alias(struct cli_state *cli, uint16 fnum,
 /****************************************************************************
 do a SAMR query alias members 
 ****************************************************************************/
-BOOL get_samr_query_aliasmem(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_aliasmem( 
                                const POLICY_HND *pol_open_domain,
                                uint32 alias_rid, uint32 *num_mem, DOM_SID2 *sid)
 {
@@ -1222,7 +1158,7 @@ BOOL get_samr_query_aliasmem(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL || num_mem == NULL || sid == NULL) return False;
 
        /* send open domain (on alias sid) */
-       if (!samr_open_alias(cli, fnum, pol_open_domain,
+       if (!samr_open_alias( pol_open_domain,
                                0x000f001f, alias_rid,
                                &pol_open_alias))
        {
@@ -1230,20 +1166,20 @@ BOOL get_samr_query_aliasmem(struct cli_state *cli, uint16 fnum,
        }
 
        /* send alias info query */
-       if (!samr_query_aliasmem(cli, fnum, &pol_open_alias, num_mem, sid))
+       if (!samr_query_aliasmem( &pol_open_alias, num_mem, sid))
                                
        {
                DEBUG(5,("samr_query_alias: error in query alias members\n"));
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_alias) && ret;
+       return samr_close(&pol_open_alias) && ret;
 }
 
 /****************************************************************************
 do a SAMR set user info
 ****************************************************************************/
-BOOL set_samr_set_userinfo2(struct cli_state *cli, uint16 fnum, 
+BOOL set_samr_set_userinfo2( 
                                POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 user_rid, void *usr)
@@ -1254,7 +1190,7 @@ BOOL set_samr_set_userinfo2(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL || usr == NULL) return False;
 
        /* send open domain (on user sid) */
-       if (!samr_open_user(cli, fnum,
+       if (!samr_open_user(
                                pol_open_domain,
                                0x000601b4, user_rid,
                                &pol_open_user))
@@ -1263,7 +1199,7 @@ BOOL set_samr_set_userinfo2(struct cli_state *cli, uint16 fnum,
        }
 
        /* send user info query */
-       if (!samr_set_userinfo2(cli, fnum,
+       if (!samr_set_userinfo2(
                                &pol_open_user,
                                info_level, usr))
        {
@@ -1272,13 +1208,13 @@ BOOL set_samr_set_userinfo2(struct cli_state *cli, uint16 fnum,
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_user) && ret;
+       return samr_close(&pol_open_user) && ret;
 }
 
 /****************************************************************************
 do a SAMR set user info
 ****************************************************************************/
-BOOL set_samr_set_userinfo(struct cli_state *cli, uint16 fnum, 
+BOOL set_samr_set_userinfo( 
                                POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 user_rid, void *usr)
@@ -1289,7 +1225,7 @@ BOOL set_samr_set_userinfo(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL || usr == NULL) return False;
 
        /* send open domain (on user sid) */
-       if (!samr_open_user(cli, fnum,
+       if (!samr_open_user(
                                pol_open_domain,
                                0x000601b4, user_rid,
                                &pol_open_user))
@@ -1298,7 +1234,7 @@ BOOL set_samr_set_userinfo(struct cli_state *cli, uint16 fnum,
        }
 
        /* send user info query */
-       if (!samr_set_userinfo(cli, fnum,
+       if (!samr_set_userinfo(
                                &pol_open_user,
                                info_level, usr))
        {
@@ -1307,13 +1243,13 @@ BOOL set_samr_set_userinfo(struct cli_state *cli, uint16 fnum,
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_user) && ret;
+       return samr_close(&pol_open_user) && ret;
 }
 
 /****************************************************************************
 do a SAMR query user info
 ****************************************************************************/
-BOOL get_samr_query_userinfo(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_userinfo( 
                                POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 user_rid, void *usr)
@@ -1324,7 +1260,7 @@ BOOL get_samr_query_userinfo(struct cli_state *cli, uint16 fnum,
        if (pol_open_domain == NULL || usr == NULL) return False;
 
        /* send open domain (on user sid) */
-       if (!samr_open_user(cli, fnum,
+       if (!samr_open_user(
                                pol_open_domain,
                                0x02011b, user_rid,
                                &pol_open_user))
@@ -1333,7 +1269,7 @@ BOOL get_samr_query_userinfo(struct cli_state *cli, uint16 fnum,
        }
 
        /* send user info query */
-       if (!samr_query_userinfo(cli, fnum,
+       if (!samr_query_userinfo(
                                &pol_open_user,
                                info_level, usr))
        {
@@ -1342,13 +1278,13 @@ BOOL get_samr_query_userinfo(struct cli_state *cli, uint16 fnum,
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_user) && ret;
+       return samr_close(&pol_open_user) && ret;
 }
 
 /****************************************************************************
 do a SAMR query group info
 ****************************************************************************/
-BOOL get_samr_query_groupinfo(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_groupinfo( 
                                const POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 group_rid, GROUP_INFO_CTR *ctr)
@@ -1361,7 +1297,7 @@ BOOL get_samr_query_groupinfo(struct cli_state *cli, uint16 fnum,
        bzero(ctr, sizeof(*ctr));
 
        /* send open domain (on group sid) */
-       if (!samr_open_group(cli, fnum,
+       if (!samr_open_group(
                                pol_open_domain,
                                0x02000000, group_rid, &pol_open_group))
        {
@@ -1369,7 +1305,7 @@ BOOL get_samr_query_groupinfo(struct cli_state *cli, uint16 fnum,
        }
 
        /* send group info query */
-       if (!samr_query_groupinfo(cli, fnum,
+       if (!samr_query_groupinfo(
                                &pol_open_group,
                                info_level, ctr))
        {
@@ -1378,13 +1314,13 @@ BOOL get_samr_query_groupinfo(struct cli_state *cli, uint16 fnum,
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_group) && ret;
+       return samr_close(&pol_open_group) && ret;
 }
 
 /****************************************************************************
 do a SAMR query alias info
 ****************************************************************************/
-BOOL get_samr_query_aliasinfo(struct cli_state *cli, uint16 fnum, 
+BOOL get_samr_query_aliasinfo( 
                                const POLICY_HND *pol_open_domain,
                                uint32 info_level,
                                uint32 alias_rid, ALIAS_INFO_CTR *ctr)
@@ -1397,7 +1333,7 @@ BOOL get_samr_query_aliasinfo(struct cli_state *cli, uint16 fnum,
        bzero(ctr, sizeof(*ctr));
 
        /* send open domain (on alias sid) */
-       if (!samr_open_alias(cli, fnum,
+       if (!samr_open_alias(
                                pol_open_domain,
                                0x02000000, alias_rid, &pol_open_alias))
        {
@@ -1405,7 +1341,7 @@ BOOL get_samr_query_aliasinfo(struct cli_state *cli, uint16 fnum,
        }
 
        /* send alias info query */
-       if (!samr_query_aliasinfo(cli, fnum,
+       if (!samr_query_aliasinfo(
                                &pol_open_alias,
                                info_level, ctr))
        {
@@ -1414,18 +1350,16 @@ BOOL get_samr_query_aliasinfo(struct cli_state *cli, uint16 fnum,
                ret = False;
        }
 
-       return samr_close(cli, fnum,&pol_open_alias) && ret;
+       return samr_close(&pol_open_alias) && ret;
 }
 
 /****************************************************************************
 SAM create domain user.
 ****************************************************************************/
-BOOL msrpc_sam_create_dom_user(struct cli_state *cli, DOM_SID *sid1,
+BOOL msrpc_sam_create_dom_user(const char* srv_name, DOM_SID *sid1,
                                char *acct_name, uint16 acb_info,
                                uint32 *rid)
 {
-       uint16 fnum;
-       fstring srv_name;
        BOOL res = True;
        BOOL res1 = True;
        BOOL res2 = True;
@@ -1434,33 +1368,23 @@ BOOL msrpc_sam_create_dom_user(struct cli_state *cli, DOM_SID *sid1,
        POLICY_HND sam_pol;
        POLICY_HND pol_dom;
 
-       fstrcpy(srv_name, "\\\\");
-       fstrcat(srv_name, cli->desthost);
-       strupper(srv_name);
-
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res1 = res ? samr_open_domain(cli, fnum, 
+       res1 = res ? samr_open_domain( 
                    &sam_pol, ace_perms, sid1,
                    &pol_dom) : False;
 
        /* create a domain user */
-       res2 = res1 ? create_samr_domain_user(cli, fnum, 
+       res2 = res1 ? create_samr_domain_user( 
                                &pol_dom,
                                acct_name, acb_info, &user_rid) : False;
 
-       res1 = res1 ? samr_close(cli, fnum, &pol_dom) : False;
-       res  = res  ? samr_close(cli, fnum, &sam_pol) : False;
-
-       /* close the session */
-       cli_nt_session_close(cli, fnum);
+       res1 = res1 ? samr_close( &pol_dom) : False;
+       res  = res  ? samr_close( &sam_pol) : False;
 
        if (res2)
        {
index dad9d412e17f7ac2566cc5ccefb8e6df929b502d..50f85ea5f28a7d5a62aabd93cbd80623587fdb17 100644 (file)
@@ -5671,8 +5671,28 @@ BOOL make_samr_q_set_userinfo(SAMR_Q_SET_USERINFO *q_u,
        switch (switch_value)
        {
                case 0x18:
+               {
+                       uchar sess_key[16];
+                       if (!cli_get_usr_sesskey(hnd, sess_key))
+                       {
+                               return False;
+                       }
+#ifdef DEBUG_PASSWORD
+                       dump_data(100, sess_key, 16);
+#endif
+                       SamOEMhash(q_u->info.id24->pass, sess_key, 1);
+               }
                case 0x17:
                {
+                       uchar sess_key[16];
+                       if (!cli_get_usr_sesskey(hnd, sess_key))
+                       {
+                               return False;
+                       }
+#ifdef DEBUG_PASSWORD
+                       dump_data(100, sess_key, 16);
+#endif
+                       SamOEMhash(q_u->info.id23->pass, sess_key, 1);
                        break;
                }
                default:
index b32b3322b33d4bb9df5cdbd222ffecddcd8cf8b7..add040aa3d1ef8bbee248907fcc24cba1e6e810f 100644 (file)
@@ -411,8 +411,14 @@ BOOL get_policy_cli_state(const POLICY_HND *hnd, struct cli_state **cli,
        {
                DEBUG(3,("Getting cli state pnum=%x\n", p->pnum));
 
-               (*cli ) = p->dev.cli->cli;
-               (*fnum) = p->dev.cli->fnum;
+               if (cli != NULL)
+               {
+                       (*cli ) = p->dev.cli->cli;
+               }
+               if (fnum != NULL)
+               {
+                       (*fnum) = p->dev.cli->fnum;
+               }
 
                return True;
        }
index 17b251f1e1b090b32738c36568c44a8850db4c1a..cdb56e0a325829ba118d4e866c8589e5a5004ad3 100644 (file)
@@ -256,7 +256,6 @@ Lookup domain in SAM server.
 ****************************************************************************/
 void cmd_sam_lookup_domain(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        char *domain;
        fstring str_sid;
@@ -278,22 +277,16 @@ void cmd_sam_lookup_domain(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "Lookup Domain in SAM Server\n");
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect(
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_query_lookup_domain(smb_cli, fnum, 
+       res = res ? samr_query_lookup_domain( 
                    &sam_pol, domain, &dom_sid) : False;
 
-       res = res ? samr_close(smb_cli, fnum, &sam_pol) : False;
-
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
+       res = res ? samr_close( &sam_pol) : False;
 
        if (res)
        {
@@ -315,7 +308,6 @@ SAM delete alias member.
 ****************************************************************************/
 void cmd_sam_del_aliasmem(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid;
@@ -357,21 +349,18 @@ void cmd_sam_del_aliasmem(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Domain Alias Member\n");
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum, 
+       res = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid1,
                    &pol_dom) : False;
 
        /* connect to the domain */
-       res1 = res ? samr_open_alias(smb_cli, fnum,
+       res1 = res ? samr_open_alias(
                    &pol_dom,
                    0x000f001f, alias_rid, &alias_pol) : False;
 
@@ -381,7 +370,7 @@ void cmd_sam_del_aliasmem(struct client_info *info, int argc, char *argv[])
                argv++;
                /* get a sid, delete a member from the alias */
                res2 = res2 ? string_to_sid(&member_sid, argv[0]) : False;
-               res2 = res2 ? samr_del_aliasmem(smb_cli, fnum, &alias_pol, &member_sid) : False;
+               res2 = res2 ? samr_del_aliasmem( &alias_pol, &member_sid) : False;
 
                if (res2)
                {
@@ -389,12 +378,9 @@ void cmd_sam_del_aliasmem(struct client_info *info, int argc, char *argv[])
                }
        }
 
-       res1 = res1 ? samr_close(smb_cli, fnum, &alias_pol) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &pol_dom) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &sam_pol) : False;
-
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
+       res1 = res1 ? samr_close( &alias_pol) : False;
+       res  = res  ? samr_close( &pol_dom) : False;
+       res  = res  ? samr_close( &sam_pol) : False;
 
        if (res && res1 && res2)
        {
@@ -413,7 +399,6 @@ SAM delete alias.
 ****************************************************************************/
 void cmd_sam_delete_dom_alias(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        char *name;
@@ -456,22 +441,19 @@ void cmd_sam_delete_dom_alias(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Delete Domain Alias\n");
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum, 
+       res = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid1,
                    &pol_dom) : False;
 
        names[0] = name;
 
-       res1 = res ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res ? samr_query_lookup_names(
                    &pol_dom, 0x000003e8,
                    1, names,
                    &num_rids, rid, type) : False;
@@ -482,18 +464,15 @@ void cmd_sam_delete_dom_alias(struct client_info *info, int argc, char *argv[])
        }
 
        /* connect to the domain */
-       res1 = res1 ? samr_open_alias(smb_cli, fnum,
+       res1 = res1 ? samr_open_alias(
                    &pol_dom,
                    0x000f001f, alias_rid, &alias_pol) : False;
 
-       res2 = res1 ? samr_delete_dom_alias(smb_cli, fnum, &alias_pol) : False;
-
-       res1 = res1 ? samr_close(smb_cli, fnum, &alias_pol) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &pol_dom) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &sam_pol) : False;
+       res2 = res1 ? samr_delete_dom_alias( &alias_pol) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
+       res1 = res1 ? samr_close( &alias_pol) : False;
+       res  = res  ? samr_close( &pol_dom) : False;
+       res  = res  ? samr_close( &sam_pol) : False;
 
        if (res && res1 && res2)
        {
@@ -512,7 +491,6 @@ SAM add alias member.
 ****************************************************************************/
 void cmd_sam_add_aliasmem(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring tmp;
@@ -593,28 +571,25 @@ void cmd_sam_add_aliasmem(struct client_info *info, int argc, char *argv[])
                }
        }
 
-       /* open SAMR session.  negotiate credentials */
-       res = res4 ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum, 
+       res = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid1,
                    &pol_dom) : False;
 
        /* connect to the domain */
-       res1 = res ? samr_open_alias(smb_cli, fnum,
+       res1 = res ? samr_open_alias(
                    &pol_dom,
                    0x000f001f, alias_rid, &alias_pol) : False;
 
        for (i = 1; i < num_sids && res2 && res1; i++)
        {
                /* add a member to the alias */
-               res2 = res2 ? samr_add_aliasmem(smb_cli, fnum, &alias_pol, &sids[i]) : False;
+               res2 = res2 ? samr_add_aliasmem( &alias_pol, &sids[i]) : False;
 
                if (res2)
                {
@@ -623,12 +598,9 @@ void cmd_sam_add_aliasmem(struct client_info *info, int argc, char *argv[])
                }
        }
 
-       res1 = res1 ? samr_close(smb_cli, fnum, &alias_pol) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &pol_dom) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &sam_pol) : False;
-
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
+       res1 = res1 ? samr_close( &alias_pol) : False;
+       res  = res  ? samr_close( &pol_dom) : False;
+       res  = res  ? samr_close( &sam_pol) : False;
 
        if (sids != NULL)
        {
@@ -716,7 +688,7 @@ void cmd_sam_create_dom_trusting(struct client_info *info, int argc, char *argv[
        }
        report(out_hnd, "SAM Create Domain Trusting Account\n");
 
-       if (msrpc_sam_create_dom_user(smb_cli, &sid1,
+       if (msrpc_sam_create_dom_user(srv_name,
                                      acct_name, ACB_WSTRUST, &user_rid))
        {
                report(out_hnd, "Create Domain User: OK\n");
@@ -740,6 +712,11 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[])
        uint32 user_rid; 
        uint16 acb_info = ACB_NORMAL;
        int opt;
+       fstring srv_name;
+       fstrcpy(srv_name, "\\\\");
+       fstrcat(srv_name, info->dest_host);
+       strupper(srv_name);
+
 
        sid_copy(&sid1, &info->dom.level5_sid);
        sid_to_string(sid, &sid1);
@@ -791,7 +768,7 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[])
                          domain, acct_name,
            pwdb_encode_acct_ctrl(acb_info, NEW_PW_FORMAT_SPACE_PADDED_LEN));
 
-       if (msrpc_sam_create_dom_user(smb_cli, &sid1,
+       if (msrpc_sam_create_dom_user(srv_name, &sid1,
                                      acct_name, acb_info, &user_rid))
        {
                report(out_hnd, "Create Domain User: OK\n");
@@ -808,7 +785,6 @@ SAM create domain alias.
 ****************************************************************************/
 void cmd_sam_create_dom_alias(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        char *acct_name;
@@ -857,33 +833,27 @@ void cmd_sam_create_dom_alias(struct client_info *info, int argc, char *argv[])
        report(out_hnd, "Domain: %s Name: %s Description: %s\n",
                          domain, acct_name, acct_desc);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum, 
+       res = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid1,
                    &pol_dom) : False;
 
        /* create a domain alias */
-       res1 = res ? create_samr_domain_alias(smb_cli, fnum, 
+       res1 = res ? create_samr_domain_alias( 
                                &pol_dom,
                                acct_name, acct_desc, &alias_rid) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &pol_dom) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res && res1)
        {
                DEBUG(5,("cmd_sam_create_dom_alias: succeeded\n"));
@@ -902,7 +872,6 @@ SAM delete group member.
 ****************************************************************************/
 void cmd_sam_del_groupmem(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid;
@@ -944,21 +913,18 @@ void cmd_sam_del_groupmem(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Add Domain Group member\n");
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum, 
+       res = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid1,
                    &pol_dom) : False;
 
        /* connect to the domain */
-       res1 = res ? samr_open_group(smb_cli, fnum,
+       res1 = res ? samr_open_group(
                    &pol_dom,
                    0x0000001f, group_rid, &pol_grp) : False;
 
@@ -969,7 +935,7 @@ void cmd_sam_del_groupmem(struct client_info *info, int argc, char *argv[])
 
                /* get a rid, delete a member from the group */
                member_rid = get_number(argv[0]);
-               res2 = res2 ? samr_del_groupmem(smb_cli, fnum, &pol_grp, member_rid) : False;
+               res2 = res2 ? samr_del_groupmem( &pol_grp, member_rid) : False;
 
                if (res2)
                {
@@ -977,12 +943,9 @@ void cmd_sam_del_groupmem(struct client_info *info, int argc, char *argv[])
                }
        }
 
-       res1 = res1 ? samr_close(smb_cli, fnum, &pol_grp) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &pol_dom) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &sam_pol) : False;
-
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
+       res1 = res1 ? samr_close( &pol_grp) : False;
+       res  = res  ? samr_close( &pol_dom) : False;
+       res  = res  ? samr_close( &sam_pol) : False;
 
        if (res && res1 && res2)
        {
@@ -1002,7 +965,6 @@ SAM delete group.
 ****************************************************************************/
 void cmd_sam_delete_dom_group(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        char *name;
@@ -1045,22 +1007,19 @@ void cmd_sam_delete_dom_group(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Delete Domain Group\n");
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum, 
+       res = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid1,
                    &pol_dom) : False;
 
        names[0] = name;
 
-       res1 = res ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res ? samr_query_lookup_names(
                    &pol_dom, 0x000003e8,
                    1, names,
                    &num_rids, rid, type) : False;
@@ -1071,18 +1030,15 @@ void cmd_sam_delete_dom_group(struct client_info *info, int argc, char *argv[])
        }
 
        /* connect to the domain */
-       res1 = res1 ? samr_open_group(smb_cli, fnum,
+       res1 = res1 ? samr_open_group(
                    &pol_dom,
                    0x0000001f, group_rid, &pol_grp) : False;
 
-       res2 = res1 ? samr_delete_dom_group(smb_cli, fnum, &pol_grp) : False;
-
-       res1 = res1 ? samr_close(smb_cli, fnum, &pol_grp) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &pol_dom) : False;
-       res  = res  ? samr_close(smb_cli, fnum, &sam_pol) : False;
+       res2 = res1 ? samr_delete_dom_group( &pol_grp) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
+       res1 = res1 ? samr_close( &pol_grp) : False;
+       res  = res  ? samr_close( &pol_dom) : False;
+       res  = res  ? samr_close( &sam_pol) : False;
 
        if (res && res1 && res2)
        {
@@ -1102,7 +1058,6 @@ SAM add group member.
 ****************************************************************************/
 void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid;
@@ -1165,43 +1120,40 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Add Domain Group member\n");
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res4 = res ? samr_open_domain(smb_cli, fnum, 
+       res4 = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid1,
                    &pol_dom) : False;
 
        /* connect to the domain */
-       res3 = res ? samr_open_domain(smb_cli, fnum, 
+       res3 = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid_1_5_20,
                    &pol_blt) : False;
 
-       res2 = res4 ? samr_query_lookup_names(smb_cli, fnum,
+       res2 = res4 ? samr_query_lookup_names(
                    &pol_dom, 0x000003e8,
                    1, group_names,
                    &num_group_rids, group_rid, group_type) : False;
 
        /* open the group */
-       res2 = res2 ? samr_open_group(smb_cli, fnum,
+       res2 = res2 ? samr_open_group(
                    &pol_dom,
                    0x0000001f, group_rid[0], &pol_grp) : False;
 
        if (!res2 || (group_type != NULL && group_type[0] == SID_NAME_UNKNOWN))
        {
-               res2 = res3 ? samr_query_lookup_names(smb_cli, fnum,
+               res2 = res3 ? samr_query_lookup_names(
                            &pol_blt, 0x000003e8,
                            1, group_names, 
                            &num_group_rids, group_rid, group_type) : False;
 
                /* open the group */
-               res2 = res2 ? samr_open_group(smb_cli, fnum,
+               res2 = res2 ? samr_open_group(
                            &pol_blt,
                            0x0000001f, group_rid[0], &pol_grp) : False;
        }
@@ -1212,7 +1164,7 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[])
                        group_name);
                return;
        }
-       res1 = res2 ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res2 ? samr_query_lookup_names(
                    &pol_dom, 0x000003e8,
                    num_names, names,
                    &num_rids, rid, type) : False;
@@ -1229,7 +1181,7 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[])
                }
                else
                {
-                       if (samr_add_groupmem(smb_cli, fnum, &pol_grp, rid[i]))
+                       if (samr_add_groupmem( &pol_grp, rid[i]))
                        {
                                report(out_hnd, "RID added to Group 0x%x: 0x%x\n",
                                                 group_rid[0], rid[i]);
@@ -1237,13 +1189,10 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[])
                }
        }
 
-       res1 = res ? samr_close(smb_cli, fnum, &pol_grp) : False;
-       res1 = res3 ? samr_close(smb_cli, fnum, &pol_blt) : False;
-       res1 = res4 ? samr_close(smb_cli, fnum, &pol_dom) : False;
-       res  = res ? samr_close(smb_cli, fnum, &sam_pol) : False;
-
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
+       res1 = res ? samr_close( &pol_grp) : False;
+       res1 = res3 ? samr_close( &pol_blt) : False;
+       res1 = res4 ? samr_close( &pol_dom) : False;
+       res  = res ? samr_close( &sam_pol) : False;
 
        free_char_array(num_names, names);
        
@@ -1275,7 +1224,6 @@ SAM create domain group.
 ****************************************************************************/
 void cmd_sam_create_dom_group(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        char *acct_name;
@@ -1325,33 +1273,27 @@ void cmd_sam_create_dom_group(struct client_info *info, int argc, char *argv[])
        report(out_hnd, "Domain: %s Name: %s Description: %s\n",
                          domain, acct_name, acct_desc);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum, 
+       res = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid1,
                    &pol_dom) : False;
 
        /* read some users */
-       res1 = res ? create_samr_domain_group(smb_cli, fnum, 
+       res1 = res ? create_samr_domain_group( 
                                &pol_dom,
                                acct_name, acct_desc, &group_rid) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &pol_dom) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res && res1)
        {
                DEBUG(5,("cmd_sam_create_dom_group: succeeded\n"));
@@ -1421,7 +1363,7 @@ void cmd_sam_enum_users(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Enumerate Users\n");
 
-       msrpc_sam_enum_users(smb_cli, domain, &sid1, srv_name,
+       msrpc_sam_enum_users( srv_name, domain, &sid1,
                    &sam, &num_sam_entries,
                    sam_display_user,
                    request_user_info  ? sam_display_user_info     : NULL,
@@ -1440,7 +1382,6 @@ experimental SAM group query members.
 ****************************************************************************/
 void cmd_sam_query_groupmem(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid_str;
@@ -1483,29 +1424,26 @@ void cmd_sam_query_groupmem(struct client_info *info, int argc, char *argv[])
        report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
                          info->myhostname, srv_name, domain, sid_str);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum,
+       res = res ? samr_connect(
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum,
+       res = res ? samr_open_domain(
                    &sam_pol, 0x304, &sid,
                    &pol_dom) : False;
 
        /* look up group rid */
        names[0] = group_name;
-       res1 = res ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res ? samr_query_lookup_names(
                                        &pol_dom, 0x3e8,
                                        1, names,
                                        &num_rids, rid, type) : False;
 
        if (res1 && num_rids == 1)
        {
-               res1 = req_groupmem_info(smb_cli, fnum,
+               res1 = req_groupmem_info(
                                &pol_dom,
                                domain,
                                &sid,
@@ -1514,15 +1452,12 @@ void cmd_sam_query_groupmem(struct client_info *info, int argc, char *argv[])
                                sam_display_group_members);
        }
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &pol_dom) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res1)
        {
                DEBUG(5,("cmd_sam_query_group: succeeded\n"));
@@ -1539,7 +1474,6 @@ experimental SAM group query.
 ****************************************************************************/
 void cmd_sam_query_group(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid_str;
@@ -1582,29 +1516,26 @@ void cmd_sam_query_group(struct client_info *info, int argc, char *argv[])
        report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
                          info->myhostname, srv_name, domain, sid_str);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum,
+       res = res ? samr_connect(
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum,
+       res = res ? samr_open_domain(
                    &sam_pol, 0x304, &sid,
                    &pol_dom) : False;
 
        /* look up group rid */
        names[0] = group_name;
-       res1 = res ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res ? samr_query_lookup_names(
                                        &pol_dom, 0x3e8,
                                        1, names,
                                        &num_rids, rid, type) : False;
 
        if (res1 && num_rids == 1)
        {
-               res1 = query_groupinfo(smb_cli, fnum,
+               res1 = query_groupinfo(
                                &pol_dom,
                                domain,
                                &sid,
@@ -1612,15 +1543,12 @@ void cmd_sam_query_group(struct client_info *info, int argc, char *argv[])
                                sam_display_group_info);
        }
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &pol_dom) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res1)
        {
                DEBUG(5,("cmd_sam_query_group: succeeded\n"));
@@ -1637,7 +1565,6 @@ experimental SAM user query.
 ****************************************************************************/
 void cmd_sam_query_user(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid_str;
@@ -1680,22 +1607,19 @@ void cmd_sam_query_user(struct client_info *info, int argc, char *argv[])
        report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
                          info->myhostname, srv_name, domain, sid_str);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum,
+       res = res ? samr_connect(
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum,
+       res = res ? samr_open_domain(
                    &sam_pol, 0x304, &sid,
                    &pol_dom) : False;
 
        /* look up user rid */
        names[0] = user_name;
-       res1 = res ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res ? samr_query_lookup_names(
                                        &pol_dom, 0x3e8,
                                        1, names,
                                        &num_rids, rid, type) : False;
@@ -1703,22 +1627,19 @@ void cmd_sam_query_user(struct client_info *info, int argc, char *argv[])
        /* send user info query */
        if (res1 && num_rids == 1)
        {
-               res1 = req_user_info(smb_cli, fnum,
+               res1 = req_user_info(
                                &pol_dom,
                                domain,
                                &sid,
                                rid[0],
                                sam_display_user_info);
        }
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &pol_dom) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res1)
        {
                DEBUG(5,("cmd_sam_query_user: succeeded\n"));
@@ -1735,7 +1656,6 @@ experimental SAM user set.
 ****************************************************************************/
 void cmd_sam_set_userinfo2(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid_str;
@@ -1800,28 +1720,25 @@ void cmd_sam_set_userinfo2(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Set User Info: %s\n", user_name);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum,
+       res = res ? samr_connect(
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum,
+       res = res ? samr_open_domain(
                    &sam_pol, 0x02000000, &sid,
                    &pol_dom) : False;
 
        /* look up user rid */
        names[0] = user_name;
-       res1 = res ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res ? samr_query_lookup_names(
                                        &pol_dom, 0x3e8,
                                        1, names,
                                        &num_rids, rid, type) : False;
 
        /* send set user info */
-       if (res1 && num_rids == 1 && get_samr_query_userinfo(smb_cli, fnum,
+       if (res1 && num_rids == 1 && get_samr_query_userinfo(
                                                    &pol_dom,
                                                    0x10, rid[0],
                                                    (void*)&usr16))
@@ -1845,20 +1762,17 @@ void cmd_sam_set_userinfo2(struct client_info *info, int argc, char *argv[])
                
                if (usr != NULL)
                {
-                       res1 = set_samr_set_userinfo2(smb_cli, fnum,
+                       res1 = set_samr_set_userinfo2(
                                            &pol_dom,
                                            switch_value, rid[0], usr);
                }
        }
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &pol_dom) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res1)
        {
                report(out_hnd, "Set User Info: OK\n");
@@ -1876,7 +1790,6 @@ experimental SAM user set.
 ****************************************************************************/
 void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid_str;
@@ -1961,28 +1874,25 @@ void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[])
        report(out_hnd, "SAM Set User Info: %s\n", user_name);
        report(out_hnd, "Password: %s\n", password);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum,
+       res = res ? samr_connect(
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum,
+       res = res ? samr_open_domain(
                    &sam_pol, 0x02000000, &sid,
                    &pol_dom) : False;
 
        /* look up user rid */
        names[0] = user_name;
-       res1 = res ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res ? samr_query_lookup_names(
                                        &pol_dom, 0x3e8,
                                        1, names,
                                        &num_rids, rid, type) : False;
 
        /* send set user info */
-       if (res1 && num_rids == 1 && get_samr_query_userinfo(smb_cli, fnum,
+       if (res1 && num_rids == 1 && get_samr_query_userinfo(
                                                    &pol_dom,
                                                    0x15, rid[0], &usr21))
        {
@@ -1994,10 +1904,6 @@ void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[])
                {
                        encode_pw_buffer(pwbuf, password,
                                       strlen(password), True);
-#ifdef DEBUG_PASSWORD
-                       dump_data(100, smb_cli->sess_key, 16);
-#endif
-                       SamOEMhash(pwbuf, smb_cli->sess_key, 1);
                }
 
                if (True)
@@ -2048,20 +1954,17 @@ void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[])
                }
                if (usr != NULL)
                {
-                       res1 = set_samr_set_userinfo(smb_cli, fnum,
+                       res1 = set_samr_set_userinfo(
                                            &pol_dom,
                                            switch_value, rid[0], usr);
                }
        }
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &pol_dom) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res1)
        {
                report(out_hnd, "Set User Info: OK\n");
@@ -2080,7 +1983,6 @@ experimental SAM query display info.
 ****************************************************************************/
 void cmd_sam_query_dispinfo(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid;
@@ -2118,35 +2020,29 @@ void cmd_sam_query_dispinfo(struct client_info *info, int argc, char *argv[])
        fprintf(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
                          info->myhostname, srv_name, domain, sid);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum, 
+       res = res ? samr_connect( 
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum, 
+       res = res ? samr_open_domain( 
                    &sam_pol, ace_perms, &sid1,
                    &pol_dom) : False;
 
        ctr.sam.info1 = &inf1;
 
        /* send a samr query_disp_info command */
-       res = res ? samr_query_dispinfo(smb_cli, fnum,
+       res = res ? samr_query_dispinfo(
                    &pol_dom, switch_value, 
                    &num_entries, &ctr) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       res = res ? samr_close(smb_cli, fnum, 
+       res = res ? samr_close( 
                    &pol_dom) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res)
        {
                DEBUG(5,("cmd_sam_query_dispinfo: succeeded\n"));
@@ -2172,6 +2068,11 @@ void cmd_sam_query_dominfo(struct client_info *info, int argc, char *argv[])
        DOM_SID sid1;
        uint32 switch_value = 2;
        SAM_UNK_CTR ctr;
+       fstring srv_name;
+       fstrcpy(srv_name, "\\\\");
+       fstrcat(srv_name, info->dest_host);
+       strupper(srv_name);
+
 
        sid_to_string(sid, &info->dom.level5_sid);
        fstrcpy(domain, info->dom.level5_dom);
@@ -2193,7 +2094,7 @@ void cmd_sam_query_dominfo(struct client_info *info, int argc, char *argv[])
        report(out_hnd, "From: %s Domain: %s SID: %s\n",
                          info->myhostname, domain, sid);
 
-       if (sam_query_dominfo(smb_cli, &sid1, switch_value, &ctr))
+       if (sam_query_dominfo( srv_name, &sid1, switch_value, &ctr))
        {
                DEBUG(5,("cmd_sam_query_dominfo: succeeded\n"));
                display_sam_unk_ctr(out_hnd, ACTION_HEADER   , switch_value, &ctr);
@@ -2211,7 +2112,6 @@ experimental SAM alias query members.
 ****************************************************************************/
 void cmd_sam_query_aliasmem(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid_str;
@@ -2254,29 +2154,26 @@ void cmd_sam_query_aliasmem(struct client_info *info, int argc, char *argv[])
        report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
                          info->myhostname, srv_name, domain, sid_str);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum,
+       res = res ? samr_connect(
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum,
+       res = res ? samr_open_domain(
                    &sam_pol, 0x304, &sid,
                    &pol_dom) : False;
 
        /* look up alias rid */
        names[0] = alias_name;
-       res1 = res ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res ? samr_query_lookup_names(
                                        &pol_dom, 0x3e8,
                                        1, names,
                                        &num_rids, rid, type) : False;
 
        if (res1 && num_rids == 1)
        {
-               res1 = req_aliasmem_info(smb_cli, fnum,
+               res1 = req_aliasmem_info(
                                &pol_dom,
                                domain,
                                &sid,
@@ -2285,15 +2182,12 @@ void cmd_sam_query_aliasmem(struct client_info *info, int argc, char *argv[])
                                sam_display_alias_members);
        }
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &pol_dom) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res1)
        {
                DEBUG(5,("cmd_sam_query_alias: succeeded\n"));
@@ -2310,7 +2204,6 @@ experimental SAM alias query.
 ****************************************************************************/
 void cmd_sam_query_alias(struct client_info *info, int argc, char *argv[])
 {
-       uint16 fnum;
        fstring srv_name;
        fstring domain;
        fstring sid_str;
@@ -2353,29 +2246,26 @@ void cmd_sam_query_alias(struct client_info *info, int argc, char *argv[])
        report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
                          info->myhostname, srv_name, domain, sid_str);
 
-       /* open SAMR session.  negotiate credentials */
-       res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
-
        /* establish a connection. */
-       res = res ? samr_connect(smb_cli, fnum,
+       res = res ? samr_connect(
                                srv_name, 0x02000000,
                                &sam_pol) : False;
 
        /* connect to the domain */
-       res = res ? samr_open_domain(smb_cli, fnum,
+       res = res ? samr_open_domain(
                    &sam_pol, 0x304, &sid,
                    &pol_dom) : False;
 
        /* look up alias rid */
        names[0] = alias_name;
-       res1 = res ? samr_query_lookup_names(smb_cli, fnum,
+       res1 = res ? samr_query_lookup_names(
                                        &pol_dom, 0x3e8,
                                        1, names,
                                        &num_rids, rid, type) : False;
 
        if (res1 && num_rids == 1)
        {
-               res1 = query_aliasinfo(smb_cli, fnum,
+               res1 = query_aliasinfo(
                                &pol_dom,
                                domain,
                                &sid,
@@ -2383,15 +2273,12 @@ void cmd_sam_query_alias(struct client_info *info, int argc, char *argv[])
                                sam_display_alias_info);
        }
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &sam_pol) : False;
 
-       res = res ? samr_close(smb_cli, fnum,
+       res = res ? samr_close(
                    &pol_dom) : False;
 
-       /* close the session */
-       cli_nt_session_close(smb_cli, fnum);
-
        if (res1)
        {
                DEBUG(5,("cmd_sam_query_alias: succeeded\n"));
@@ -2454,7 +2341,7 @@ void cmd_sam_enum_aliases(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Enumerate Aliases\n");
 
-       msrpc_sam_enum_aliases(smb_cli, domain, &sid1, srv_name,
+       msrpc_sam_enum_aliases(srv_name, domain, &sid1, 
                    &sam, &num_sam_entries,
                    sam_display_alias,
                    request_alias_info  ? sam_display_alias_info    : NULL,
@@ -2517,7 +2404,7 @@ void cmd_sam_enum_groups(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Enumerate Groups\n");
 
-       msrpc_sam_enum_groups(smb_cli, domain, &sid1, srv_name,
+       msrpc_sam_enum_groups(srv_name, domain, &sid1, 
                    &sam, &num_sam_entries,
                    sam_display_group,
                    request_group_info  ? sam_display_group_info    : NULL,
@@ -2562,7 +2449,7 @@ void cmd_sam_enum_domains(struct client_info *info, int argc, char *argv[])
 
        report(out_hnd, "SAM Enumerate Domains\n");
 
-       msrpc_sam_enum_domains(smb_cli, srv_name,
+       msrpc_sam_enum_domains(srv_name,
                    &sam, &num_sam_entries,
                    sam_display_domain);
 
index da20431b6c18b7e39ec912b958b4b50cd495d190..490c52ab3d305d590c3c85c17c6b9da04fb847e9 100644 (file)
@@ -974,8 +974,7 @@ static char *complete_samenum_usr(char *text, int state)
                num_usrs = 0;
 
                /* Iterate all users */
-               if (msrpc_sam_enum_users(smb_cli,
-                                  domain, &sid1, srv_name,
+               if (msrpc_sam_enum_users(srv_name, domain, &sid1, 
                                   &sam, &num_usrs,
                                   NULL, NULL, NULL, NULL) == 0)
                {
@@ -1030,8 +1029,7 @@ static char *complete_samenum_als(char *text, int state)
                num_als = 0;
 
                /* Iterate all aliases */
-               if (msrpc_sam_enum_aliases(smb_cli,
-                                  domain, &sid1, srv_name,
+               if (msrpc_sam_enum_aliases(srv_name, domain, &sid1, 
                                   &sam, &num_als,
                                   NULL, NULL, NULL) == 0)
                {
@@ -1086,8 +1084,8 @@ static char *complete_samenum_grp(char *text, int state)
                num_grps = 0;
 
                /* Iterate all groups */
-               if (msrpc_sam_enum_groups(smb_cli,
-                                  domain, &sid1, srv_name,
+               if (msrpc_sam_enum_groups(srv_name,
+                                  domain, &sid1, 
                                   &sam, &num_grps,
                                   NULL, NULL, NULL) == 0)
                {