/*
- Unix SMB/Netbios implementation.
- Version 1.9.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1994-1997
- Copyright (C) Luke Kenneth Casson Leighton 1996-1997
+ Unix SMB/CIFS implementation.
+ RPC pipe client
+ Copyright (C) Tim Potter 2000-2001,
+ Copyright (C) Andrew Tridgell 1992-1997,2000,
+ Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
+ Copyright (C) Paul Ashton 1997,2000,
+ Copyright (C) Elrond 2000,
+ Copyright (C) Rafal Szczesniak 2002.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include "includes.h"
+/* Connect to SAMR database */
-#ifdef SYSLOG
-#undef SYSLOG
-#endif
+NTSTATUS cli_samr_connect(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ uint32 access_mask, POLICY_HND *connect_pol)
+{
+ prs_struct qbuf, rbuf;
+ SAMR_Q_CONNECT q;
+ SAMR_R_CONNECT r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-#include "includes.h"
-#include "nterr.h"
+ DEBUG(10,("cli_samr_connect to %s\n", cli->desthost));
-extern int DEBUGLEVEL;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
+ /* Initialise parse structures */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-/****************************************************************************
-do a SAMR create domain user
-****************************************************************************/
-BOOL create_samr_domain_user(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain,
- const char *acct_name, uint16 acb_info,
- uint32 *rid)
-{
- POLICY_HND pol_open_user;
- BOOL ret = True;
+ /* Marshall data and send request */
- if (pol_open_domain == NULL || acct_name == NULL) return False;
+ init_samr_q_connect(&q, cli->desthost, access_mask);
- /* send create user */
- if (!samr_create_dom_user(cli, fnum,
- pol_open_domain,
- acct_name, acb_info, 0xe005000b,
- &pol_open_user, rid))
- {
- return False;
+ if (!samr_io_q_connect("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_CONNECT, &qbuf, &rbuf))
+ goto done;
+
+ /* Unmarshall response */
+
+ if (!samr_io_r_connect("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
+
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *connect_pol = r.connect_pol;
+#ifdef __INSURE__
+ connect_pol->marker = malloc(1);
+#endif
}
- DEBUG(5,("create_samr_domain_user: name: %s rid 0x%x\n",
- acct_name, *rid));
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return samr_close(cli, fnum, &pol_open_user) && ret;
+ return result;
}
-/****************************************************************************
-do a SAMR create domain alias
-****************************************************************************/
-BOOL create_samr_domain_alias(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain,
- const char *acct_name, const char *acct_desc,
- uint32 *rid)
+/* Connect to SAMR database */
+
+NTSTATUS cli_samr_connect4(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ uint32 access_mask, POLICY_HND *connect_pol)
{
- POLICY_HND pol_open_alias;
- ALIAS_INFO_CTR ctr;
- BOOL ret = True;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_CONNECT4 q;
+ SAMR_R_CONNECT4 r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- if (pol_open_domain == NULL || acct_name == NULL || acct_desc == NULL) return False;
+ DEBUG(10,("cli_samr_connect4 to %s\n", cli->desthost));
- /* send create alias */
- if (!samr_create_dom_alias(cli, fnum,
- pol_open_domain,
- acct_name,
- &pol_open_alias, rid))
- {
- return False;
- }
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
+
+ /* Initialise parse structures */
+
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+
+ /* Marshall data and send request */
- DEBUG(5,("create_samr_domain_alias: name: %s rid 0x%x\n",
- acct_name, *rid));
+ init_samr_q_connect4(&q, cli->desthost, access_mask);
- ctr.switch_value1 = 3;
- make_samr_alias_info3(&ctr.alias.info3, acct_desc);
+ if (!samr_io_q_connect4("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_CONNECT4, &qbuf, &rbuf))
+ goto done;
- /* send set alias info */
- if (!samr_set_aliasinfo(cli, fnum,
- &pol_open_alias,
- &ctr))
- {
- DEBUG(5,("create_samr_domain_alias: error in samr_set_aliasinfo\n"));
- ret = False;
+ /* Unmarshall response */
+
+ if (!samr_io_r_connect4("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
+
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *connect_pol = r.connect_pol;
+#ifdef __INSURE__
+ connect_pol->marker = malloc(1);
+#endif
}
- return samr_close(cli, fnum,&pol_open_alias) && ret;
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-/****************************************************************************
-do a SAMR create domain group
-****************************************************************************/
-BOOL create_samr_domain_group(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain,
- const char *acct_name, const char *acct_desc,
- uint32 *rid)
+/* Close SAMR handle */
+
+NTSTATUS cli_samr_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *connect_pol)
{
- POLICY_HND pol_open_group;
- GROUP_INFO_CTR ctr;
- BOOL ret = True;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_CLOSE_HND q;
+ SAMR_R_CLOSE_HND r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- if (pol_open_domain == NULL || acct_name == NULL || acct_desc == NULL) return False;
+ DEBUG(10,("cli_samr_close\n"));
- /* send create group*/
- if (!samr_create_dom_group(cli, fnum,
- pol_open_domain,
- acct_name,
- &pol_open_group, rid))
- {
- return False;
- }
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- DEBUG(5,("create_samr_domain_group: name: %s rid 0x%x\n",
- acct_name, *rid));
+ /* Initialise parse structures */
- ctr.switch_value1 = 4;
- ctr.switch_value2 = 4;
- make_samr_group_info4(&ctr.group.info4, acct_desc);
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* send user groups query */
- if (!samr_set_groupinfo(cli, fnum,
- &pol_open_group,
- &ctr))
- {
- DEBUG(5,("create_samr_domain_group: error in samr_set_groupinfo\n"));
- ret = False;
- }
+ /* Marshall data and send request */
- return samr_close(cli, fnum,&pol_open_group) && ret;
-}
+ init_samr_q_close_hnd(&q, connect_pol);
-/****************************************************************************
-do a SAMR query user groups
-****************************************************************************/
-BOOL get_samr_query_usergroups(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain, uint32 user_rid,
- uint32 *num_groups, DOM_GID *gid)
-{
- POLICY_HND pol_open_user;
- BOOL ret = True;
+ if (!samr_io_q_close_hnd("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_CLOSE_HND, &qbuf, &rbuf))
+ goto done;
- if (pol_open_domain == NULL || num_groups == NULL || gid == NULL) return False;
+ /* Unmarshall response */
- /* send open domain (on user sid) */
- if (!samr_open_user(cli, fnum,
- pol_open_domain,
- 0x02011b, user_rid,
- &pol_open_user))
- {
- return False;
- }
+ if (!samr_io_r_close_hnd("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
- /* send user groups query */
- if (!samr_query_usergroups(cli, fnum,
- &pol_open_user,
- num_groups, gid))
- {
- DEBUG(5,("samr_query_usergroups: error in query user groups\n"));
- ret = False;
+ if (NT_STATUS_IS_OK(result = r.status)) {
+#ifdef __INSURE__
+ SAFE_FREE(connect_pol->marker);
+#endif
+ *connect_pol = r.pol;
}
- return samr_close(cli, fnum,&pol_open_user) && ret;
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-/****************************************************************************
-do a SAMR delete group
-****************************************************************************/
-BOOL delete_samr_dom_group(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain,
- uint32 group_rid)
+/* Open handle on a domain */
+
+NTSTATUS cli_samr_open_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *connect_pol, uint32 access_mask,
+ const DOM_SID *domain_sid, POLICY_HND *domain_pol)
{
- POLICY_HND pol_open_group;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_OPEN_DOMAIN q;
+ SAMR_R_OPEN_DOMAIN r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- if (pol_open_domain == NULL) return False;
+ DEBUG(10,("cli_samr_open_domain with sid %s\n", sid_string_static(domain_sid) ));
- /* send open domain (on group rid) */
- if (!samr_open_group(cli, fnum,pol_open_domain,
- 0x00000010, group_rid,
- &pol_open_group))
- {
- return False;
- }
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* send group delete */
- if (!samr_delete_dom_group(cli, fnum,&pol_open_group))
-
- {
- DEBUG(5,("delete_samr_dom_group: error in delete domain group\n"));
- samr_close(cli, fnum,&pol_open_group);
- return False;
- }
+ /* Initialise parse structures */
- return True;
-}
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+ /* Marshall data and send request */
-/****************************************************************************
-do a SAMR query group members
-****************************************************************************/
-BOOL get_samr_query_groupmem(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain,
- uint32 group_rid, uint32 *num_mem,
- uint32 *rid, uint32 *attr)
-{
- POLICY_HND pol_open_group;
- BOOL ret = True;
+ init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
- if (pol_open_domain == NULL || num_mem == NULL || rid == NULL || attr == NULL) return False;
+ if (!samr_io_q_open_domain("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_OPEN_DOMAIN, &qbuf, &rbuf))
+ goto done;
- /* send open domain (on group sid) */
- if (!samr_open_group(cli, fnum,pol_open_domain,
- 0x00000010, group_rid,
- &pol_open_group))
- {
- return False;
- }
+ /* Unmarshall response */
- /* send group info query */
- if (!samr_query_groupmem(cli, fnum,&pol_open_group, num_mem, rid, attr))
-
- {
- DEBUG(5,("samr_query_group: error in query group members\n"));
- ret = False;
+ if (!samr_io_r_open_domain("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
+
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *domain_pol = r.domain_pol;
+#ifdef __INSURE__
+ domain_pol->marker = malloc(1);
+#endif
}
- return samr_close(cli, fnum,&pol_open_group) && ret;
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-/****************************************************************************
-do a SAMR delete alias
-****************************************************************************/
-BOOL delete_samr_dom_alias(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain,
- uint32 alias_rid)
+/* Open handle on a user */
+
+NTSTATUS cli_samr_open_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol, uint32 access_mask,
+ uint32 user_rid, POLICY_HND *user_pol)
{
- POLICY_HND pol_open_alias;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_OPEN_USER q;
+ SAMR_R_OPEN_USER r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- if (pol_open_domain == NULL) return False;
+ DEBUG(10,("cli_samr_open_user with rid 0x%x\n", user_rid ));
- /* send open domain (on alias rid) */
- if (!samr_open_alias(cli, fnum,pol_open_domain,
- 0x000f001f, alias_rid, &pol_open_alias))
- {
- return False;
- }
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* send alias delete */
- if (!samr_delete_dom_alias(cli, fnum,&pol_open_alias))
-
- {
- DEBUG(5,("delete_samr_dom_alias: error in delete domain alias\n"));
- samr_close(cli, fnum,&pol_open_alias);
- return False;
- }
+ /* Initialise parse structures */
- return True;
-}
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+ /* Marshall data and send request */
-/****************************************************************************
-do a SAMR query alias members
-****************************************************************************/
-BOOL get_samr_query_aliasmem(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain,
- uint32 alias_rid, uint32 *num_mem, DOM_SID2 *sid)
-{
- POLICY_HND pol_open_alias;
- BOOL ret = True;
+ init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
- if (pol_open_domain == NULL || num_mem == NULL || sid == NULL) return False;
+ if (!samr_io_q_open_user("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_OPEN_USER, &qbuf, &rbuf))
+ goto done;
- /* send open domain (on alias sid) */
- if (!samr_open_alias(cli, fnum, pol_open_domain,
- 0x000f001f, alias_rid,
- &pol_open_alias))
- {
- return False;
- }
+ /* Unmarshall response */
+
+ if (!samr_io_r_open_user("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
- /* send alias info query */
- if (!samr_query_aliasmem(cli, fnum, &pol_open_alias, num_mem, sid))
-
- {
- DEBUG(5,("samr_query_alias: error in query alias members\n"));
- ret = False;
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *user_pol = r.user_pol;
+#ifdef __INSURE__
+ user_pol->marker = malloc(1);
+#endif
}
- return samr_close(cli, fnum,&pol_open_alias) && ret;
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-/****************************************************************************
-do a SAMR query user info
-****************************************************************************/
-BOOL get_samr_query_userinfo(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain,
- uint32 info_level,
- uint32 user_rid, SAM_USER_INFO_21 *usr)
+/* Open handle on a group */
+
+NTSTATUS cli_samr_open_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol, uint32 access_mask,
+ uint32 group_rid, POLICY_HND *group_pol)
{
- POLICY_HND pol_open_user;
- BOOL ret = True;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_OPEN_GROUP q;
+ SAMR_R_OPEN_GROUP r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- if (pol_open_domain == NULL || usr == NULL) return False;
+ DEBUG(10,("cli_samr_open_group with rid 0x%x\n", group_rid ));
- bzero(usr, sizeof(*usr));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* send open domain (on user sid) */
- if (!samr_open_user(cli, fnum,
- pol_open_domain,
- 0x02011b, user_rid,
- &pol_open_user))
- {
- return False;
- }
+ /* Initialise parse structures */
- /* send user info query */
- if (!samr_query_userinfo(cli, fnum,
- &pol_open_user,
- info_level, (void*)usr))
- {
- DEBUG(5,("samr_query_userinfo: error in query user info, level 0x%x\n",
- info_level));
- ret = False;
- }
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- return samr_close(cli, fnum,&pol_open_user) && ret;
-}
+ /* Marshall data and send request */
-/****************************************************************************
-do a SAMR query group info
-****************************************************************************/
-BOOL get_samr_query_groupinfo(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol_open_domain,
- uint32 info_level,
- uint32 group_rid, GROUP_INFO_CTR *ctr)
-{
- POLICY_HND pol_open_group;
- BOOL ret = True;
+ init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
- if (pol_open_domain == NULL || ctr == NULL) return False;
+ if (!samr_io_q_open_group("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_OPEN_GROUP, &qbuf, &rbuf))
+ goto done;
- bzero(ctr, sizeof(*ctr));
+ /* Unmarshall response */
- /* send open domain (on group sid) */
- if (!samr_open_group(cli, fnum,
- pol_open_domain,
- 0x00000010, group_rid, &pol_open_group))
- {
- return False;
- }
+ if (!samr_io_r_open_group("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
- /* send group info query */
- if (!samr_query_groupinfo(cli, fnum,
- &pol_open_group,
- info_level, ctr))
- {
- DEBUG(5,("samr_query_groupinfo: error in query group info, level 0x%x\n",
- info_level));
- ret = False;
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *group_pol = r.pol;
+#ifdef __INSURE__
+ group_pol->marker = malloc(1);
+#endif
}
- return samr_close(cli, fnum,&pol_open_group) && ret;
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-/****************************************************************************
-do a SAMR change user password command
-****************************************************************************/
-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])
+/* Create domain group */
+
+NTSTATUS cli_samr_create_dom_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol,
+ const char *group_name,
+ uint32 access_mask, POLICY_HND *group_pol)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_CREATE_DOM_GROUP q;
+ SAMR_R_CREATE_DOM_GROUP r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_CHGPASSWD_USER q_e;
- BOOL valid_pwc = False;
+ DEBUG(10,("cli_samr_create_dom_group\n"));
- /* create and send a MSRPC command with api SAMR_CHGPASSWD_USER */
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Initialise parse structures */
- DEBUG(4,("SAMR Change User Password. server:%s username:%s\n",
- srv_name, user_name));
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- make_samr_q_chgpasswd_user(&q_e, srv_name, user_name,
- nt_newpass, nt_oldhash,
- lm_newpass, lm_oldhash);
+ /* Marshall data and send request */
- /* turn parameters into data stream */
- samr_io_q_chgpasswd_user("", &q_e, &data, 0);
+ init_samr_q_create_dom_group(&q, domain_pol, group_name, access_mask);
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_CHGPASSWD_USER, &data, &rdata))
- {
- SAMR_R_CHGPASSWD_USER r_e;
- BOOL p;
+ if (!samr_io_q_create_dom_group("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_CREATE_DOM_GROUP, &qbuf, &rbuf))
+ goto done;
- samr_io_r_chgpasswd_user("", &r_e, &rdata, 0);
+ /* Unmarshall response */
- p = rdata.offset != 0;
- if (p && r_e.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_CHGPASSWD_USER: %s\n", get_nt_error_msg(r_e.status)));
- p = False;
- }
+ if (!samr_io_r_create_dom_group("", &r, &rbuf, 0))
+ goto done;
- if (p)
- {
- valid_pwc = True;
- }
- }
+ /* Return output parameters */
+
+ result = r.status;
+
+ if (NT_STATUS_IS_OK(result))
+ *group_pol = r.pol;
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pwc;
+ return result;
}
+/* Add a domain group member */
-/****************************************************************************
-do a SAMR unknown 0x38 command
-****************************************************************************/
-BOOL samr_unknown_38(struct cli_state *cli, uint16 fnum, char *srv_name)
+NTSTATUS cli_samr_add_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *group_pol, uint32 rid)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_ADD_GROUPMEM q;
+ SAMR_R_ADD_GROUPMEM r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_UNKNOWN_38 q_e;
- BOOL valid_un8 = False;
+ DEBUG(10,("cli_samr_add_groupmem\n"));
- /* create and send a MSRPC command with api SAMR_ENUM_DOM_USERS */
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Initialise parse structures */
- DEBUG(4,("SAMR Unknown 38 server:%s\n", srv_name));
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- make_samr_q_unknown_38(&q_e, srv_name);
+ /* Marshall data and send request */
- /* turn parameters into data stream */
- samr_io_q_unknown_38("", &q_e, &data, 0);
+ init_samr_q_add_groupmem(&q, group_pol, rid);
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_GET_DOM_PWINFO, &data, &rdata))
- {
- SAMR_R_UNKNOWN_38 r_e;
- BOOL p;
+ if (!samr_io_q_add_groupmem("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_ADD_GROUPMEM, &qbuf, &rbuf))
+ goto done;
- samr_io_r_unknown_38("", &r_e, &rdata, 0);
+ /* Unmarshall response */
- p = rdata.offset != 0;
-#if 0
- if (p && r_e.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_UNKNOWN_38: %s\n", get_nt_error_msg(r_e.status)));
- p = False;
- }
-#endif
- if (p)
- {
- valid_un8 = True;
- }
- }
+ if (!samr_io_r_add_groupmem("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ result = r.status;
- return valid_un8;
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-/****************************************************************************
-do a SAMR unknown 0x8 command
-****************************************************************************/
-BOOL samr_query_dom_info(struct cli_state *cli, uint16 fnum,
- POLICY_HND *domain_pol, uint16 switch_value,
- SAM_UNK_CTR *ctr)
+/* Delete a domain group member */
+
+NTSTATUS cli_samr_del_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *group_pol, uint32 rid)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_DEL_GROUPMEM q;
+ SAMR_R_DEL_GROUPMEM r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_QUERY_DOMAIN_INFO q_e;
- BOOL valid_un8 = False;
+ DEBUG(10,("cli_samr_del_groupmem\n"));
- DEBUG(4,("SAMR Unknown 8 switch:%d\n", switch_value));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (domain_pol == NULL) return False;
+ /* Initialise parse structures */
- /* create and send a MSRPC command with api SAMR_ENUM_DOM_USERS */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_query_dom_info(&q_e, domain_pol, switch_value);
+ init_samr_q_del_groupmem(&q, group_pol, rid);
- /* turn parameters into data stream */
- samr_io_q_query_dom_info("", &q_e, &data, 0);
+ if (!samr_io_q_del_groupmem("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_DEL_GROUPMEM, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_DOMAIN_INFO, &data, &rdata))
- {
- SAMR_R_QUERY_DOMAIN_INFO r_e;
- BOOL p;
+ /* Unmarshall response */
- r_e.ctr = ctr;
- samr_io_r_query_dom_info("", &r_e, &rdata, 0);
+ if (!samr_io_r_del_groupmem("", &r, &rbuf, 0))
+ goto done;
- p = rdata.offset != 0;
- if (p && r_e.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_QUERY_DOMAIN_INFO: %s\n", get_nt_error_msg(r_e.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- valid_un8 = True;
- }
- }
+ result = r.status;
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_un8;
+ return result;
}
-/****************************************************************************
-do a SAMR enumerate groups
-****************************************************************************/
-BOOL samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint32 size,
- struct acct_info **sam,
- int *num_sam_groups)
+/* Query user info */
+
+NTSTATUS cli_samr_query_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol, uint16 switch_value,
+ SAM_USERINFO_CTR **ctr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_USERINFO q;
+ SAMR_R_QUERY_USERINFO r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_ENUM_DOM_GROUPS q_e;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_query_userinfo\n"));
- DEBUG(4,("SAMR Enum SAM DB max size:%x\n", size));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (pol == NULL || num_sam_groups == NULL) return False;
+ /* Initialise parse structures */
- /* create and send a MSRPC command with api SAMR_ENUM_DOM_GROUPS */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_enum_dom_groups(&q_e, pol, size);
+ init_samr_q_query_userinfo(&q, user_pol, switch_value);
- /* turn parameters into data stream */
- samr_io_q_enum_dom_groups("", &q_e, &data, 0);
+ if (!samr_io_q_query_userinfo("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_USERINFO, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_ENUM_DOM_GROUPS, &data, &rdata))
- {
- SAMR_R_ENUM_DOM_GROUPS r_e;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_enum_dom_groups("", &r_e, &rdata, 0);
+ if (!samr_io_r_query_userinfo("", &r, &rbuf, 0))
+ goto done;
- p = rdata.offset != 0;
- if (p && r_e.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_ENUM_DOM_GROUPS: %s\n", get_nt_error_msg(r_e.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- int i;
- int name_idx = 0;
-
- *num_sam_groups = r_e.num_entries2;
- if (*num_sam_groups > MAX_SAM_ENTRIES)
- {
- *num_sam_groups = MAX_SAM_ENTRIES;
- DEBUG(2,("samr_enum_dom_groups: sam group entries limited to %d\n",
- *num_sam_groups));
- }
-
- *sam = (struct acct_info*) malloc(sizeof(struct acct_info) * (*num_sam_groups));
-
- if ((*sam) == NULL)
- {
- *num_sam_groups = 0;
- }
-
- for (i = 0; i < *num_sam_groups; i++)
- {
- (*sam)[i].rid = r_e.sam[i].rid;
- (*sam)[i].acct_name[0] = 0;
- (*sam)[i].acct_desc[0] = 0;
- if (r_e.sam[i].hdr_name.buffer)
- {
- unistr2_to_ascii((*sam)[i].acct_name, &r_e.uni_grp_name[name_idx], sizeof((*sam)[i].acct_name)-1);
- name_idx++;
- }
- DEBUG(5,("samr_enum_dom_groups: idx: %4d rid: %8x acct: %s\n",
- i, (*sam)[i].rid, (*sam)[i].acct_name));
- }
- valid_pol = True;
- }
- }
+ result = r.status;
+ *ctr = r.ctr;
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR enumerate aliases
-****************************************************************************/
-BOOL samr_enum_dom_aliases(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint32 size,
- struct acct_info **sam,
- int *num_sam_aliases)
+/* Set group info */
+
+NTSTATUS cli_samr_set_groupinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *group_pol, GROUP_INFO_CTR *ctr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_SET_GROUPINFO q;
+ SAMR_R_SET_GROUPINFO r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_ENUM_DOM_ALIASES q_e;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_set_groupinfo\n"));
- DEBUG(4,("SAMR Enum SAM DB max size:%x\n", size));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (pol == NULL || num_sam_aliases == NULL) return False;
+ /* Initialise parse structures */
- /* create and send a MSRPC command with api SAMR_ENUM_DOM_ALIASES */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_enum_dom_aliases(&q_e, pol, size);
+ init_samr_q_set_groupinfo(&q, group_pol, ctr);
- /* turn parameters into data stream */
- samr_io_q_enum_dom_aliases("", &q_e, &data, 0);
+ if (!samr_io_q_set_groupinfo("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_SET_GROUPINFO, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_ENUM_DOM_ALIASES, &data, &rdata))
- {
- SAMR_R_ENUM_DOM_ALIASES r_e;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_enum_dom_aliases("", &r_e, &rdata, 0);
+ if (!samr_io_r_set_groupinfo("", &r, &rbuf, 0))
+ goto done;
- p = rdata.offset != 0;
- if (p && r_e.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_ENUM_DOM_ALIASES: %s\n", get_nt_error_msg(r_e.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- int i;
- int name_idx = 0;
-
- *num_sam_aliases = r_e.num_entries2;
- if (*num_sam_aliases > MAX_SAM_ENTRIES)
- {
- *num_sam_aliases = MAX_SAM_ENTRIES;
- DEBUG(2,("samr_enum_dom_aliases: sam user entries limited to %d\n",
- *num_sam_aliases));
- }
-
- *sam = (struct acct_info*) malloc(sizeof(struct acct_info) * (*num_sam_aliases));
-
- if ((*sam) == NULL)
- {
- *num_sam_aliases = 0;
- }
-
- for (i = 0; i < *num_sam_aliases; i++)
- {
- (*sam)[i].rid = r_e.sam[i].rid;
- (*sam)[i].acct_name[0] = 0;
- (*sam)[i].acct_desc[0] = 0;
- if (r_e.sam[i].hdr_name.buffer)
- {
- unistr2_to_ascii((*sam)[i].acct_name, &r_e.uni_grp_name[name_idx], sizeof((*sam)[i].acct_name)-1);
- name_idx++;
- }
- DEBUG(5,("samr_enum_dom_aliases: idx: %4d rid: %8x acct: %s\n",
- i, (*sam)[i].rid, (*sam)[i].acct_name));
- }
- valid_pol = True;
- }
- }
+ result = r.status;
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR enumerate users
-****************************************************************************/
-BOOL samr_enum_dom_users(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint32 start_idx,
- uint16 acb_mask, uint16 unk_1, uint32 size,
- struct acct_info **sam,
- int *num_sam_users)
+/* Query group info */
+
+NTSTATUS cli_samr_query_groupinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *group_pol, uint32 info_level,
+ GROUP_INFO_CTR **ctr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_GROUPINFO q;
+ SAMR_R_QUERY_GROUPINFO r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_ENUM_DOM_USERS q_e;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_query_groupinfo\n"));
- DEBUG(4,("SAMR Enum SAM DB max size:%x\n", size));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (pol == NULL || num_sam_users == NULL) return False;
+ /* Initialise parse structures */
- /* create and send a MSRPC command with api SAMR_ENUM_DOM_USERS */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_enum_dom_users(&q_e, pol, start_idx, acb_mask, unk_1, size);
+ init_samr_q_query_groupinfo(&q, group_pol, info_level);
- /* turn parameters into data stream */
- samr_io_q_enum_dom_users("", &q_e, &data, 0);
+ if (!samr_io_q_query_groupinfo("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPINFO, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_ENUM_DOM_USERS, &data, &rdata))
- {
- SAMR_R_ENUM_DOM_USERS r_e;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_enum_dom_users("", &r_e, &rdata, 0);
+ if (!samr_io_r_query_groupinfo("", &r, &rbuf, 0))
+ goto done;
- p = rdata.offset != 0;
- if (p && r_e.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_ENUM_DOM_USERS: %s\n", get_nt_error_msg(r_e.status)));
- p = False;
- }
+ *ctr = r.ctr;
- if (p)
- {
- int i;
- int name_idx = 0;
-
- *num_sam_users = r_e.num_entries2;
- *sam = (struct acct_info*) malloc(sizeof(struct acct_info) * (*num_sam_users));
-
- if ((*sam) == NULL)
- {
- *num_sam_users = 0;
- }
-
- for (i = 0; i < *num_sam_users; i++)
- {
- (*sam)[i].rid = r_e.sam[i].rid;
- (*sam)[i].acct_name[0] = 0;
- (*sam)[i].acct_desc[0] = 0;
- if (r_e.sam[i].hdr_name.buffer)
- {
- unistr2_to_ascii((*sam)[i].acct_name, &r_e.uni_acct_name[name_idx], sizeof((*sam)[i].acct_name)-1);
- name_idx++;
- }
- DEBUG(5,("samr_enum_dom_users: idx: %4d rid: %8x acct: %s\n",
- i, (*sam)[i].rid, (*sam)[i].acct_name));
- }
- valid_pol = True;
- }
+ /* Return output parameters */
- if (r_e.sam != NULL)
- {
- free(r_e.sam);
- }
- if (r_e.uni_acct_name != NULL)
- {
- free(r_e.uni_acct_name);
- }
- }
+ result = r.status;
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR Connect
-****************************************************************************/
-BOOL samr_connect(struct cli_state *cli, uint16 fnum,
- char *srv_name, uint32 unknown_0,
- POLICY_HND *connect_pol)
+/* Query user groups */
+
+NTSTATUS cli_samr_query_usergroups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol, uint32 *num_groups,
+ DOM_GID **gid)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_USERGROUPS q;
+ SAMR_R_QUERY_USERGROUPS r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_CONNECT q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_query_usergroups\n"));
- DEBUG(4,("SAMR Open Policy server:%s undoc value:%x\n",
- srv_name, unknown_0));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (srv_name == NULL || connect_pol == NULL) return False;
+ /* Initialise parse structures */
- /* create and send a MSRPC command with api SAMR_CONNECT */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_connect(&q_o, srv_name, unknown_0);
+ init_samr_q_query_usergroups(&q, user_pol);
- /* turn parameters into data stream */
- samr_io_q_connect("", &q_o, &data, 0);
+ if (!samr_io_q_query_usergroups("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_USERGROUPS, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_CONNECT, &data, &rdata))
- {
- SAMR_R_CONNECT r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_connect("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_CONNECT: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_query_usergroups("", &r, &rbuf, 0))
+ goto done;
- if (p)
- {
- memcpy(connect_pol, &r_o.connect_pol, sizeof(r_o.connect_pol));
- valid_pol = True;
- }
+ /* Return output parameters */
+
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *num_groups = r.num_entries;
+ *gid = r.gid;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR Open User
-****************************************************************************/
-BOOL samr_open_user(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint32 unk_0, uint32 rid,
- POLICY_HND *user_pol)
+/* Set alias info */
+
+NTSTATUS cli_samr_set_aliasinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_SET_ALIASINFO q;
+ SAMR_R_SET_ALIASINFO r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_OPEN_USER q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_set_aliasinfo\n"));
- DEBUG(4,("SAMR Open User. unk_0: %08x RID:%x\n",
- unk_0, rid));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (pol == NULL || user_pol == NULL) return False;
+ /* Initialise parse structures */
- /* create and send a MSRPC command with api SAMR_OPEN_USER */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_open_user(&q_o, pol, unk_0, rid);
+ init_samr_q_set_aliasinfo(&q, alias_pol, ctr);
- /* turn parameters into data stream */
- samr_io_q_open_user("", &q_o, &data, 0);
+ if (!samr_io_q_set_aliasinfo("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_SET_ALIASINFO, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_OPEN_USER, &data, &rdata))
- {
- SAMR_R_OPEN_USER r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_open_user("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_OPEN_USER: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_set_aliasinfo("", &r, &rbuf, 0))
+ goto done;
- if (p)
- {
- memcpy(user_pol, &r_o.user_pol, sizeof(r_o.user_pol));
- valid_pol = True;
- }
- }
+ /* Return output parameters */
+
+ result = r.status;
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR Open Alias
-****************************************************************************/
-BOOL samr_open_alias(struct cli_state *cli, uint16 fnum,
- POLICY_HND *domain_pol,
- uint32 flags, uint32 rid,
- POLICY_HND *alias_pol)
-{
- prs_struct data;
- prs_struct rdata;
+/* Query user aliases */
- SAMR_Q_OPEN_ALIAS q_o;
- BOOL valid_pol = False;
+NTSTATUS cli_samr_query_useraliases(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol, uint32 num_sids, DOM_SID2 *sid,
+ uint32 *num_aliases, uint32 **als_rids)
+{
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_USERALIASES q;
+ SAMR_R_QUERY_USERALIASES r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ unsigned int ptr=1;
+
+ DEBUG(10,("cli_samr_query_useraliases\n"));
- DEBUG(4,("SAMR Open Alias. RID:%x\n", rid));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (alias_pol == NULL || domain_pol == NULL) return False;
+ /* Initialise parse structures */
- /* create and send a MSRPC command with api SAMR_OPEN_ALIAS */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_open_alias(&q_o, domain_pol, flags, rid);
+ init_samr_q_query_useraliases(&q, user_pol, num_sids, &ptr, sid);
- /* turn parameters into data stream */
- samr_io_q_open_alias("", &q_o, &data, 0);
+ if (!samr_io_q_query_useraliases("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_USERALIASES, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_OPEN_ALIAS, &data, &rdata))
- {
- SAMR_R_OPEN_ALIAS r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_open_alias("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_r_query_useraliases("", &r, &rbuf, 0))
+ goto done;
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_OPEN_ALIAS: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- memcpy(alias_pol, &r_o.pol, sizeof(r_o.pol));
- valid_pol = True;
- }
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *num_aliases = r.num_entries;
+ *als_rids = r.rid;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR Delete Alias Member
-****************************************************************************/
-BOOL samr_del_aliasmem(struct cli_state *cli, uint16 fnum,
- POLICY_HND *alias_pol, DOM_SID *sid)
+/* Query user groups */
+
+NTSTATUS cli_samr_query_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *group_pol, uint32 *num_mem,
+ uint32 **rid, uint32 **attr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_GROUPMEM q;
+ SAMR_R_QUERY_GROUPMEM r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_DEL_ALIASMEM q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_query_groupmem\n"));
- if (alias_pol == NULL || sid == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_DEL_ALIASMEM */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Delete Alias Member.\n"));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_del_aliasmem(&q_o, alias_pol, sid);
+ init_samr_q_query_groupmem(&q, group_pol);
- /* turn parameters into data stream */
- samr_io_q_del_aliasmem("", &q_o, &data, 0);
+ if (!samr_io_q_query_groupmem("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPMEM, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_DEL_ALIASMEM, &data, &rdata))
- {
- SAMR_R_DEL_ALIASMEM r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_del_aliasmem("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_r_query_groupmem("", &r, &rbuf, 0))
+ goto done;
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_DEL_ALIASMEM: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- valid_pol = True;
- }
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *num_mem = r.num_entries;
+ *rid = r.rid;
+ *attr = r.attr;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR Add Alias Member
-****************************************************************************/
-BOOL samr_add_aliasmem(struct cli_state *cli, uint16 fnum,
- POLICY_HND *alias_pol, DOM_SID *sid)
+/**
+ * Enumerate domain users
+ *
+ * @param cli client state structure
+ * @param mem_ctx talloc context
+ * @param pol opened domain policy handle
+ * @param start_idx starting index of enumeration, returns context for
+ next enumeration
+ * @param acb_mask account control bit mask (to enumerate some particular
+ * kind of accounts)
+ * @param size max acceptable size of response
+ * @param dom_users returned array of domain user names
+ * @param rids returned array of domain user RIDs
+ * @param num_dom_users numer returned entries
+ *
+ * @return NTSTATUS returned in rpc response
+ **/
+NTSTATUS cli_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *pol, uint32 *start_idx, uint16 acb_mask,
+ uint32 size, char ***dom_users, uint32 **rids,
+ uint32 *num_dom_users)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf;
+ prs_struct rbuf;
+ SAMR_Q_ENUM_DOM_USERS q;
+ SAMR_R_ENUM_DOM_USERS r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ int i;
+
+ DEBUG(10,("cli_samr_enum_dom_users starting at index %u\n", (unsigned int)*start_idx));
+
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
+
+ /* always init this */
+ *num_dom_users = 0;
+
+ /* Initialise parse structures */
+
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+
+ /* Fill query structure with parameters */
+
+ init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, 0, size);
+
+ if (!samr_io_q_enum_dom_users("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_USERS, &qbuf, &rbuf)) {
+ goto done;
+ }
- SAMR_Q_ADD_ALIASMEM q_o;
- BOOL valid_pol = False;
+ /* unpack received stream */
- if (alias_pol == NULL || sid == NULL) return False;
+ if(!samr_io_r_enum_dom_users("", &r, &rbuf, 0))
+ goto done;
+
+ result = r.status;
- /* create and send a MSRPC command with api SAMR_ADD_ALIASMEM */
+ if (!NT_STATUS_IS_OK(result) &&
+ NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
+ goto done;
+
+ *start_idx = r.next_idx;
+ *num_dom_users = r.num_entries2;
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ if (r.num_entries2) {
+ /* allocate memory needed to return received data */
+ *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2);
+ if (!*rids) {
+ DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2);
+ if (!*dom_users) {
+ DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ /* fill output buffers with rpc response */
+ for (i = 0; i < r.num_entries2; i++) {
+ fstring conv_buf;
+
+ (*rids)[i] = r.sam[i].rid;
+ unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf) - 1);
+ (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf);
+ }
+ }
+
+done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
+}
- DEBUG(4,("SAMR Add Alias Member.\n"));
+/* Enumerate domain groups */
- /* store the parameters */
- make_samr_q_add_aliasmem(&q_o, alias_pol, sid);
+NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *pol, uint32 *start_idx,
+ uint32 size, struct acct_info **dom_groups,
+ uint32 *num_dom_groups)
+{
+ prs_struct qbuf, rbuf;
+ SAMR_Q_ENUM_DOM_GROUPS q;
+ SAMR_R_ENUM_DOM_GROUPS r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ uint32 name_idx, i;
- /* turn parameters into data stream */
- samr_io_q_add_aliasmem("", &q_o, &data, 0);
+ DEBUG(10,("cli_samr_enum_dom_groups starting at index %u\n", (unsigned int)*start_idx));
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_ADD_ALIASMEM, &data, &rdata))
- {
- SAMR_R_ADD_ALIASMEM r_o;
- BOOL p;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- samr_io_r_add_aliasmem("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ /* Initialise parse structures */
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_ADD_ALIASMEM: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- if (p)
- {
- valid_pol = True;
- }
- }
+ /* Marshall data and send request */
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
- return valid_pol;
-}
+ if (!samr_io_q_enum_dom_groups("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_GROUPS, &qbuf, &rbuf))
+ goto done;
-/****************************************************************************
-do a SAMR Delete Domain Alias
-****************************************************************************/
-BOOL samr_delete_dom_alias(struct cli_state *cli, uint16 fnum,
- POLICY_HND *alias_pol)
-{
- prs_struct data;
- prs_struct rdata;
+ /* Unmarshall response */
- SAMR_Q_DELETE_DOM_ALIAS q_o;
- BOOL valid_pol = False;
+ if (!samr_io_r_enum_dom_groups("", &r, &rbuf, 0))
+ goto done;
- if (alias_pol == NULL) return False;
+ /* Return output parameters */
- /* delete and send a MSRPC command with api SAMR_DELETE_DOM_ALIAS */
+ result = r.status;
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ if (!NT_STATUS_IS_OK(result) &&
+ NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
+ goto done;
- DEBUG(4,("SAMR Delete Domain Alias.\n"));
+ *num_dom_groups = r.num_entries2;
- /* store the parameters */
- make_samr_q_delete_dom_alias(&q_o, alias_pol);
+ if (*num_dom_groups == 0)
+ goto done;
- /* turn parameters into data stream */
- samr_io_q_delete_dom_alias("", &q_o, &data, 0);
+ if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
+ result = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_DELETE_DOM_ALIAS, &data, &rdata))
- {
- SAMR_R_DELETE_DOM_ALIAS r_o;
- BOOL p;
+ memset(*dom_groups, 0, sizeof(struct acct_info) * (*num_dom_groups));
- samr_io_r_delete_dom_alias("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ name_idx = 0;
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_DELETE_DOM_ALIAS: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ for (i = 0; i < *num_dom_groups; i++) {
+
+ (*dom_groups)[i].rid = r.sam[i].rid;
- if (p)
- {
- valid_pol = True;
+ if (r.sam[i].hdr_name.buffer) {
+ unistr2_to_ascii((*dom_groups)[i].acct_name,
+ &r.uni_grp_name[name_idx],
+ sizeof(fstring) - 1);
+ name_idx++;
}
+
+ *start_idx = r.next_idx;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-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,
- uint32 unk_0, uint32 unk_1,
- POLICY_HND *user_pol, uint32 *rid)
+/* Enumerate domain groups */
+
+NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *pol, uint32 *start_idx,
+ uint32 size, struct acct_info **dom_aliases,
+ uint32 *num_dom_aliases)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_ENUM_DOM_ALIASES q;
+ SAMR_R_ENUM_DOM_ALIASES r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ uint32 name_idx, i;
- SAMR_Q_CREATE_USER q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_enum_als_groups starting at index %u\n", (unsigned int)*start_idx));
- if (user_pol == NULL || domain_pol == NULL || acct_name == NULL || rid == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_CREATE_USER */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Create Domain User. Name:%s\n", acct_name));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_create_user(&q_o, domain_pol, acct_name, unk_0, unk_1);
+ init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
- /* turn parameters into data stream */
- samr_io_q_create_user("", &q_o, &data, 0);
+ if (!samr_io_q_enum_dom_aliases("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_ALIASES, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_CREATE_USER, &data, &rdata))
- {
- SAMR_R_CREATE_USER r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_create_user("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_r_enum_dom_aliases("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_CREATE_USER: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
+
+ result = r.status;
+
+ if (!NT_STATUS_IS_OK(result) &&
+ NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
+ goto done;
+ }
+
+ *num_dom_aliases = r.num_entries2;
+
+ if (*num_dom_aliases == 0)
+ goto done;
+
+ if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) {
+ result = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ memset(*dom_aliases, 0, sizeof(struct acct_info) * *num_dom_aliases);
+
+ name_idx = 0;
+
+ for (i = 0; i < *num_dom_aliases; i++) {
+
+ (*dom_aliases)[i].rid = r.sam[i].rid;
- if (p)
- {
- memcpy(user_pol, &r_o.user_pol, sizeof(r_o.user_pol));
- *rid = r_o.user_rid;
- valid_pol = True;
+ if (r.sam[i].hdr_name.buffer) {
+ unistr2_to_ascii((*dom_aliases)[i].acct_name,
+ &r.uni_grp_name[name_idx],
+ sizeof(fstring) - 1);
+ name_idx++;
}
+
+ *start_idx = r.next_idx;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-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,
- POLICY_HND *alias_pol, uint32 *rid)
+/* Query alias members */
+
+NTSTATUS cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *alias_pol, uint32 *num_mem,
+ DOM_SID **sids)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_ALIASMEM q;
+ SAMR_R_QUERY_ALIASMEM r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ uint32 i;
- SAMR_Q_CREATE_DOM_ALIAS q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_query_aliasmem\n"));
- if (alias_pol == NULL || domain_pol == NULL || acct_name == NULL || rid == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_CREATE_DOM_ALIAS */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Create Domain Alias. Name:%s\n", acct_name));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_create_dom_alias(&q_o, domain_pol, acct_name);
+ init_samr_q_query_aliasmem(&q, alias_pol);
- /* turn parameters into data stream */
- samr_io_q_create_dom_alias("", &q_o, &data, 0);
+ if (!samr_io_q_query_aliasmem("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASMEM, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_CREATE_DOM_ALIAS, &data, &rdata))
- {
- SAMR_R_CREATE_DOM_ALIAS r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_create_dom_alias("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_r_query_aliasmem("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_CREATE_DOM_ALIAS: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- memcpy(alias_pol, &r_o.alias_pol, sizeof(r_o.alias_pol));
- *rid = r_o.rid;
- valid_pol = True;
- }
+ if (!NT_STATUS_IS_OK(result = r.status)) {
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ *num_mem = r.num_sids;
+
+ if (*num_mem == 0) {
+ *sids = NULL;
+ result = NT_STATUS_OK;
+ goto done;
+ }
+
+ if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) {
+ result = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
- return valid_pol;
+ for (i = 0; i < *num_mem; i++) {
+ (*sids)[i] = r.sid[i].sid;
+ }
+
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-#if 0
-/****************************************************************************
-do a SAMR Get Alias Info
-****************************************************************************/
-BOOL samr_get_aliasinfo(struct cli_state *cli, uint16 fnum,
- POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr)
+/* Open handle on an alias */
+
+NTSTATUS cli_samr_open_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol, uint32 access_mask,
+ uint32 alias_rid, POLICY_HND *alias_pol)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_OPEN_ALIAS q;
+ SAMR_R_OPEN_ALIAS r;
+ NTSTATUS result;
- SAMR_Q_GET_ALIASINFO q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_open_alias with rid 0x%x\n", alias_rid));
- if (alias_pol == NULL || ctr == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_GET_ALIASINFO */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Get Alias Info\n"));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_get_aliasinfo(&q_o, alias_pol, ctr);
+ init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
- /* turn parameters into data stream */
- samr_io_q_get_aliasinfo("", &q_o, &data, 0);
+ if (!samr_io_q_open_alias("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_OPEN_ALIAS, &qbuf, &rbuf)) {
+ result = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_GET_ALIASINFO, &data, &rdata))
- {
- SAMR_R_GET_ALIASINFO r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_get_aliasinfo("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_r_open_alias("", &r, &rbuf, 0)) {
+ result = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_GET_ALIASINFO: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- valid_pol = True;
- }
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *alias_pol = r.pol;
+#ifdef __INSURE__
+ alias_pol->marker = malloc(1);
+#endif
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-#endif
-/****************************************************************************
-do a SAMR Set Alias Info
-****************************************************************************/
-BOOL samr_set_aliasinfo(struct cli_state *cli, uint16 fnum,
- POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr)
+/* Create an alias */
+
+NTSTATUS cli_samr_create_dom_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol, const char *name,
+ POLICY_HND *alias_pol)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_CREATE_DOM_ALIAS q;
+ SAMR_R_CREATE_DOM_ALIAS r;
+ NTSTATUS result;
- SAMR_Q_SET_ALIASINFO q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_create_dom_alias named %s\n", name));
- if (alias_pol == NULL || ctr == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_SET_ALIASINFO */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Set Alias Info\n"));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_set_aliasinfo(&q_o, alias_pol, ctr);
+ init_samr_q_create_dom_alias(&q, domain_pol, name);
- /* turn parameters into data stream */
- samr_io_q_set_aliasinfo("", &q_o, &data, 0);
+ if (!samr_io_q_create_dom_alias("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_CREATE_DOM_ALIAS, &qbuf, &rbuf)) {
+ result = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_SET_ALIASINFO, &data, &rdata))
- {
- SAMR_R_SET_ALIASINFO r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_set_aliasinfo("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_r_create_dom_alias("", &r, &rbuf, 0)) {
+ result = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_SET_ALIASINFO: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- valid_pol = True;
- }
+ if (NT_STATUS_IS_OK(result = r.status)) {
+ *alias_pol = r.alias_pol;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR Open Group
-****************************************************************************/
-BOOL samr_open_group(struct cli_state *cli, uint16 fnum,
- POLICY_HND *domain_pol,
- uint32 flags, uint32 rid,
- POLICY_HND *group_pol)
-{
- prs_struct data;
- prs_struct rdata;
-
- SAMR_Q_OPEN_GROUP q_o;
- BOOL valid_pol = False;
+/* Add an alias member */
- DEBUG(4,("SAMR Open Group. RID:%x\n", rid));
+NTSTATUS cli_samr_add_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *alias_pol, DOM_SID *member)
+{
+ prs_struct qbuf, rbuf;
+ SAMR_Q_ADD_ALIASMEM q;
+ SAMR_R_ADD_ALIASMEM r;
+ NTSTATUS result;
- if (group_pol == NULL || domain_pol == NULL) return False;
+ DEBUG(10,("cli_samr_add_aliasmem"));
- /* create and send a MSRPC command with api SAMR_OPEN_GROUP */
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Initialise parse structures */
- /* store the parameters */
- make_samr_q_open_group(&q_o, domain_pol, flags, rid);
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* turn parameters into data stream */
- samr_io_q_open_group("", &q_o, &data, 0);
+ /* Marshall data and send request */
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_OPEN_GROUP, &data, &rdata))
- {
- SAMR_R_OPEN_GROUP r_o;
- BOOL p;
+ init_samr_q_add_aliasmem(&q, alias_pol, member);
- samr_io_r_open_group("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_q_add_aliasmem("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_ADD_ALIASMEM, &qbuf, &rbuf)) {
+ result = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_OPEN_GROUP: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Unmarshall response */
- if (p)
- {
- memcpy(group_pol, &r_o.pol, sizeof(r_o.pol));
- valid_pol = True;
- }
+ if (!samr_io_r_add_aliasmem("", &r, &rbuf, 0)) {
+ result = NT_STATUS_UNSUCCESSFUL;
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ result = r.status;
- return valid_pol;
-}
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
-/****************************************************************************
-do a SAMR Delete Group Member
-****************************************************************************/
-BOOL samr_del_groupmem(struct cli_state *cli, uint16 fnum,
- POLICY_HND *group_pol, uint32 rid)
-{
- prs_struct data;
- prs_struct rdata;
+ return result;
+}
- SAMR_Q_DEL_GROUPMEM q_o;
- BOOL valid_pol = False;
+/* Delete an alias member */
- if (group_pol == NULL) return False;
+NTSTATUS cli_samr_del_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *alias_pol, DOM_SID *member)
+{
+ prs_struct qbuf, rbuf;
+ SAMR_Q_DEL_ALIASMEM q;
+ SAMR_R_DEL_ALIASMEM r;
+ NTSTATUS result;
- /* create and send a MSRPC command with api SAMR_DEL_GROUPMEM */
+ DEBUG(10,("cli_samr_del_aliasmem"));
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- DEBUG(4,("SAMR Delete Group Member.\n"));
+ /* Initialise parse structures */
- /* store the parameters */
- make_samr_q_del_groupmem(&q_o, group_pol, rid);
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* turn parameters into data stream */
- samr_io_q_del_groupmem("", &q_o, &data, 0);
+ /* Marshall data and send request */
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_DEL_GROUPMEM, &data, &rdata))
- {
- SAMR_R_DEL_GROUPMEM r_o;
- BOOL p;
+ init_samr_q_del_aliasmem(&q, alias_pol, member);
- samr_io_r_del_groupmem("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_q_del_aliasmem("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_DEL_ALIASMEM, &qbuf, &rbuf)) {
+ result = NT_STATUS_UNSUCCESSFUL;
+ goto done;
+ }
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_DEL_GROUPMEM: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Unmarshall response */
- if (p)
- {
- valid_pol = True;
- }
+ if (!samr_io_r_del_aliasmem("", &r, &rbuf, 0)) {
+ result = NT_STATUS_UNSUCCESSFUL;
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ result = r.status;
+
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR Add Group Member
-****************************************************************************/
-BOOL samr_add_groupmem(struct cli_state *cli, uint16 fnum,
- POLICY_HND *group_pol, uint32 rid)
+/* Query alias info */
+
+NTSTATUS cli_samr_query_alias_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *alias_pol, uint16 switch_value,
+ ALIAS_INFO_CTR *ctr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_ALIASINFO q;
+ SAMR_R_QUERY_ALIASINFO r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_ADD_GROUPMEM q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_query_dom_info\n"));
- if (group_pol == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_ADD_GROUPMEM */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Add Group Member.\n"));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_add_groupmem(&q_o, group_pol, rid);
+ init_samr_q_query_aliasinfo(&q, alias_pol, switch_value);
- /* turn parameters into data stream */
- samr_io_q_add_groupmem("", &q_o, &data, 0);
+ if (!samr_io_q_query_aliasinfo("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASINFO, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_ADD_GROUPMEM, &data, &rdata))
- {
- SAMR_R_ADD_GROUPMEM r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_add_groupmem("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_r_query_aliasinfo("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_ADD_GROUPMEM: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- valid_pol = True;
- }
+ if (!NT_STATUS_IS_OK(result = r.status)) {
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ *ctr = r.ctr;
+
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR Delete Domain Group
-****************************************************************************/
-BOOL samr_delete_dom_group(struct cli_state *cli, uint16 fnum, POLICY_HND *group_pol)
+/* Query domain info */
+
+NTSTATUS cli_samr_query_dom_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol, uint16 switch_value,
+ SAM_UNK_CTR *ctr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_DOMAIN_INFO q;
+ SAMR_R_QUERY_DOMAIN_INFO r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_DELETE_DOM_GROUP q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_query_dom_info\n"));
- if (group_pol == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* delete and send a MSRPC command with api SAMR_DELETE_DOM_GROUP */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Delete Domain Group.\n"));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_delete_dom_group(&q_o, group_pol);
+ init_samr_q_query_dom_info(&q, domain_pol, switch_value);
- /* turn parameters into data stream */
- samr_io_q_delete_dom_group("", &q_o, &data, 0);
+ if (!samr_io_q_query_dom_info("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_DOMAIN_INFO, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_DELETE_DOM_GROUP, &data, &rdata))
- {
- SAMR_R_DELETE_DOM_GROUP r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_delete_dom_group("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ r.ctr = ctr;
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_DELETE_DOM_GROUP: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_query_dom_info("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p)
- {
- valid_pol = True;
- }
+ /* Return output parameters */
+
+ if (!NT_STATUS_IS_OK(result = r.status)) {
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-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,
- POLICY_HND *group_pol, uint32 *rid)
-{
- prs_struct data;
- prs_struct rdata;
+/* User change password */
- SAMR_Q_CREATE_DOM_GROUP q_o;
- BOOL valid_pol = False;
+NTSTATUS cli_samr_chgpasswd_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ const char *username,
+ const char *newpassword,
+ const char *oldpassword )
+{
+ prs_struct qbuf, rbuf;
+ SAMR_Q_CHGPASSWD_USER q;
+ SAMR_R_CHGPASSWD_USER r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+
+ uchar new_nt_password[516];
+ uchar new_lm_password[516];
+ uchar old_nt_hash[16];
+ uchar old_lanman_hash[16];
+ uchar old_nt_hash_enc[16];
+ uchar old_lanman_hash_enc[16];
+
+ uchar new_nt_hash[16];
+ uchar new_lanman_hash[16];
+
+ DEBUG(10,("cli_samr_query_dom_info\n"));
+
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
+
+ /* Calculate the MD4 hash (NT compatible) of the password */
+ E_md4hash(oldpassword, old_nt_hash);
+ E_md4hash(newpassword, new_nt_hash);
+
+ if (lp_client_lanman_auth()
+ && E_deshash(newpassword, new_lanman_hash)
+ && E_deshash(oldpassword, old_lanman_hash)) {
+ /* E_deshash returns false for 'long' passwords (> 14
+ DOS chars). This allows us to match Win2k, which
+ does not store a LM hash for these passwords (which
+ would reduce the effective password length to 14) */
+
+ encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE);
+
+ SamOEMhash( new_lm_password, old_nt_hash, 516);
+ E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc);
+ } else {
+ ZERO_STRUCT(new_lm_password);
+ ZERO_STRUCT(old_lanman_hash_enc);
+ }
- if (group_pol == NULL || domain_pol == NULL || acct_name == NULL || rid == NULL) return False;
+ encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE);
+
+ SamOEMhash( new_nt_password, old_nt_hash, 516);
+ E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc);
- /* create and send a MSRPC command with api SAMR_CREATE_DOM_GROUP */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Create Domain Group. Name:%s\n", acct_name));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_create_dom_group(&q_o, domain_pol, acct_name);
+ init_samr_q_chgpasswd_user(&q, cli->srv_name_slash, username,
+ new_nt_password,
+ old_nt_hash_enc,
+ new_lm_password,
+ old_lanman_hash_enc);
- /* turn parameters into data stream */
- samr_io_q_create_dom_group("", &q_o, &data, 0);
+ if (!samr_io_q_chgpasswd_user("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_CHGPASSWD_USER, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_CREATE_DOM_GROUP, &data, &rdata))
- {
- SAMR_R_CREATE_DOM_GROUP r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_create_dom_group("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_r_chgpasswd_user("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_CREATE_DOM_GROUP: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- memcpy(group_pol, &r_o.pol, sizeof(r_o.pol));
- *rid = r_o.rid;
- valid_pol = True;
- }
+ if (!NT_STATUS_IS_OK(result = r.status)) {
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_pol;
+ return result;
}
-/****************************************************************************
-do a SAMR Set Group Info
-****************************************************************************/
-BOOL samr_set_groupinfo(struct cli_state *cli, uint16 fnum,
- POLICY_HND *group_pol, GROUP_INFO_CTR *ctr)
+/* This function returns the bizzare set of (max_entries, max_size) required
+ for the QueryDisplayInfo RPC to actually work against a domain controller
+ with large (10k and higher) numbers of users. These values were
+ obtained by inspection using ethereal and NT4 running User Manager. */
+
+void get_query_dispinfo_params(int loop_count, uint32 *max_entries,
+ uint32 *max_size)
+{
+ switch(loop_count) {
+ case 0:
+ *max_entries = 512;
+ *max_size = 16383;
+ break;
+ case 1:
+ *max_entries = 1024;
+ *max_size = 32766;
+ break;
+ case 2:
+ *max_entries = 2048;
+ *max_size = 65532;
+ break;
+ case 3:
+ *max_entries = 4096;
+ *max_size = 131064;
+ break;
+ default: /* loop_count >= 4 */
+ *max_entries = 4096;
+ *max_size = 131071;
+ break;
+ }
+}
+
+/* Query display info */
+
+NTSTATUS cli_samr_query_dispinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol, uint32 *start_idx,
+ uint16 switch_value, uint32 *num_entries,
+ uint32 max_entries, uint32 max_size,
+ SAM_DISPINFO_CTR *ctr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_DISPINFO q;
+ SAMR_R_QUERY_DISPINFO r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_SET_GROUPINFO q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_query_dispinfo for start_idx = %u\n", *start_idx));
- if (group_pol == NULL || ctr == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_SET_GROUPINFO */
+ *num_entries = 0;
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Initialise parse structures */
- DEBUG(4,("SAMR Set Group Info\n"));
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* store the parameters */
- make_samr_q_set_groupinfo(&q_o, group_pol, ctr);
+ /* Marshall data and send request */
- /* turn parameters into data stream */
- samr_io_q_set_groupinfo("", &q_o, &data, 0);
+ init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
+ *start_idx, max_entries, max_size);
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_SET_GROUPINFO, &data, &rdata))
- {
- SAMR_R_SET_GROUPINFO r_o;
- BOOL p;
+ if (!samr_io_q_query_dispinfo("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_DISPINFO, &qbuf, &rbuf)) {
+ goto done;
+ }
- samr_io_r_set_groupinfo("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ /* Unmarshall response */
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_SET_GROUPINFO: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ r.ctr = ctr;
- if (p)
- {
- valid_pol = True;
- }
+ if (!samr_io_r_query_dispinfo("", &r, &rbuf, 0)) {
+ goto done;
+ }
+
+ /* Return output parameters */
+
+ result = r.status;
+
+ if (!NT_STATUS_IS_OK(result) &&
+ NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ *num_entries = r.num_entries;
+ *start_idx += r.num_entries; /* No next_idx in this structure! */
- return valid_pol;
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-/****************************************************************************
-do a SAMR Open Domain
-****************************************************************************/
-BOOL samr_open_domain(struct cli_state *cli, uint16 fnum,
- POLICY_HND *connect_pol, uint32 ace_perms,
- DOM_SID *sid,
- POLICY_HND *domain_pol)
+/* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
+ looked up in one packet. */
+
+NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol, uint32 flags,
+ uint32 num_rids, uint32 *rids,
+ uint32 *num_names, char ***names,
+ uint32 **name_types)
{
- pstring sid_str;
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_LOOKUP_RIDS q;
+ SAMR_R_LOOKUP_RIDS r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ uint32 i;
- SAMR_Q_OPEN_DOMAIN q_o;
- BOOL valid_pol = False;
+ DEBUG(10,("cli_samr_lookup_rids\n"));
- if (DEBUGLVL(4))
- {
- sid_to_string(sid_str, sid);
- DEBUG(4,("SAMR Open Domain. SID:%s Permissions:%x\n",
- sid_str, ace_perms));
- }
+ if (num_rids > 1000) {
+ DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
+ "more than ~1000 rids are looked up at once.\n"));
+ }
- if (connect_pol == NULL || sid == NULL || domain_pol == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_OPEN_DOMAIN */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* store the parameters */
- make_samr_q_open_domain(&q_o, connect_pol, ace_perms, sid);
+ /* Marshall data and send request */
- /* turn parameters into data stream */
- samr_io_q_open_domain("", &q_o, &data, 0);
+ init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, flags,
+ num_rids, rids);
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_OPEN_DOMAIN, &data, &rdata))
- {
- SAMR_R_OPEN_DOMAIN r_o;
- BOOL p;
+ if (!samr_io_q_lookup_rids("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_LOOKUP_RIDS, &qbuf, &rbuf)) {
+ goto done;
+ }
- samr_io_r_open_domain("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
+ /* Unmarshall response */
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_OPEN_DOMAIN: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_lookup_rids("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p)
- {
- memcpy(domain_pol, &r_o.domain_pol, sizeof(r_o.domain_pol));
- valid_pol = True;
- }
+ /* Return output parameters */
+
+ if (!NT_STATUS_IS_OK(result = r.status)) {
+ goto done;
+ }
+
+ if (r.num_names1 == 0) {
+ *num_names = 0;
+ *names = NULL;
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ *num_names = r.num_names1;
+ *names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
+ *name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
- return valid_pol;
+ for (i = 0; i < r.num_names1; i++) {
+ fstring tmp;
+
+ unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
+ (*names)[i] = talloc_strdup(mem_ctx, tmp);
+ (*name_types)[i] = r.type[i];
+ }
+
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-/****************************************************************************
-do a SAMR Query Lookup Domain
-****************************************************************************/
-BOOL samr_query_lookup_domain(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, const char *dom_name,
- DOM_SID *dom_sid)
+/* Lookup names */
+
+NTSTATUS cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol, uint32 flags,
+ uint32 num_names, const char **names,
+ uint32 *num_rids, uint32 **rids,
+ uint32 **rid_types)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_LOOKUP_NAMES q;
+ SAMR_R_LOOKUP_NAMES r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ uint32 i;
- SAMR_Q_LOOKUP_DOMAIN q_o;
- BOOL valid_query = False;
+ DEBUG(10,("cli_samr_lookup_names\n"));
- if (pol == NULL || dom_name == NULL || dom_sid == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_LOOKUP_DOMAIN */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Query Lookup Domain.\n"));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_lookup_domain(&q_o, pol, dom_name);
+ init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
+ num_names, names);
- /* turn parameters into data stream */
- samr_io_q_lookup_domain("", &q_o, &data, 0);
+ if (!samr_io_q_lookup_names("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_LOOKUP_NAMES, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_LOOKUP_DOMAIN, &data, &rdata))
- {
- SAMR_R_LOOKUP_DOMAIN r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_lookup_domain("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_LOOKUP_DOMAIN: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_lookup_names("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p && r_o.ptr_sid != 0)
- {
- sid_copy(dom_sid, &r_o.dom_sid.sid);
- valid_query = True;
- }
+ /* Return output parameters */
+
+ if (!NT_STATUS_IS_OK(result = r.status)) {
+ goto done;
+ }
+
+ if (r.num_rids1 == 0) {
+ *num_rids = 0;
+ goto done;
+ }
+
+ *num_rids = r.num_rids1;
+ *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
+ *rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
+
+ for (i = 0; i < r.num_rids1; i++) {
+ (*rids)[i] = r.rids[i];
+ (*rid_types)[i] = r.types[i];
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_query;
+ return result;
}
-/****************************************************************************
-do a SAMR Query Lookup Names
-****************************************************************************/
-BOOL samr_query_lookup_names(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint32 flags,
- uint32 num_names, const char **names,
- uint32 *num_rids,
- uint32 rid[MAX_LOOKUP_SIDS],
- uint32 type[MAX_LOOKUP_SIDS])
+/* Create a domain user */
+
+NTSTATUS cli_samr_create_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *domain_pol, const char *acct_name,
+ uint32 acb_info, uint32 unknown,
+ POLICY_HND *user_pol, uint32 *rid)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_CREATE_USER q;
+ SAMR_R_CREATE_USER r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_LOOKUP_NAMES q_o;
- BOOL valid_query = False;
+ DEBUG(10,("cli_samr_create_dom_user %s\n", acct_name));
- if (pol == NULL || flags == 0 || num_names == 0 || names == NULL ||
- num_rids == NULL || rid == NULL || type == NULL ) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_LOOKUP_NAMES */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- DEBUG(4,("SAMR Query Lookup NAMES.\n"));
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_lookup_names(&q_o, pol, flags, num_names, names);
+ init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
- /* turn parameters into data stream */
- samr_io_q_lookup_names("", &q_o, &data, 0);
+ if (!samr_io_q_create_user("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_CREATE_USER, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_LOOKUP_NAMES, &data, &rdata))
- {
- SAMR_R_LOOKUP_NAMES r_o;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_lookup_names("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_LOOKUP_NAMES: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_create_user("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p)
- {
- if (r_o.ptr_rids != 0 && r_o.ptr_types != 0 &&
- r_o.num_types1 == r_o.num_rids1)
- {
- int i;
-
- valid_query = True;
- *num_rids = r_o.num_rids1;
-
- for (i = 0; i < r_o.num_rids1; i++)
- {
- rid[i] = r_o.rid[i];
- }
- for (i = 0; i < r_o.num_types1; i++)
- {
- type[i] = r_o.type[i];
- }
- }
- else if (r_o.ptr_rids == 0 && r_o.ptr_types == 0)
- {
- valid_query = True;
- *num_rids = 0;
- }
- else
- {
- p = False;
- }
- }
+ /* Return output parameters */
+
+ if (!NT_STATUS_IS_OK(result = r.status)) {
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ if (user_pol)
+ *user_pol = r.user_pol;
+
+ if (rid)
+ *rid = r.user_rid;
- return valid_query;
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
}
-/****************************************************************************
-do a SAMR Query Lookup RIDS
-****************************************************************************/
-BOOL samr_query_lookup_rids(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint32 flags,
- uint32 num_rids, uint32 *rids,
- uint32 *num_names,
- fstring names[MAX_LOOKUP_SIDS],
- uint32 type [MAX_LOOKUP_SIDS])
+/* Set userinfo */
+
+NTSTATUS cli_samr_set_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol, uint16 switch_value,
+ DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_SET_USERINFO q;
+ SAMR_R_SET_USERINFO r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_LOOKUP_RIDS q_o;
- BOOL valid_query = False;
+ DEBUG(10,("cli_samr_set_userinfo\n"));
- if (pol == NULL || flags == 0 || num_rids == 0 || rids == NULL ||
- num_names == NULL || names == NULL || type == NULL ) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_LOOKUP_RIDS */
+ if (!sess_key->length) {
+ DEBUG(1, ("No user session key\n"));
+ return NT_STATUS_NO_USER_SESSION_KEY;
+ }
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Initialise parse structures */
- DEBUG(4,("SAMR Query Lookup RIDs.\n"));
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* store the parameters */
- make_samr_q_lookup_rids(&q_o, pol, flags, num_rids, rids);
+ /* Marshall data and send request */
- /* turn parameters into data stream */
- samr_io_q_lookup_rids("", &q_o, &data, 0);
+ q.ctr = ctr;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_LOOKUP_RIDS, &data, &rdata))
- {
- SAMR_R_LOOKUP_RIDS r_o;
- BOOL p;
+ init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
+ ctr->info.id);
- samr_io_r_lookup_rids("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_LOOKUP_RIDS: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_q_set_userinfo("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_SET_USERINFO, &qbuf, &rbuf)) {
+ goto done;
+ }
- if (p)
- {
- if (r_o.ptr_names != 0 && r_o.ptr_types != 0 &&
- r_o.num_types1 == r_o.num_names1)
- {
- int i;
-
- valid_query = True;
- *num_names = r_o.num_names1;
-
- for (i = 0; i < r_o.num_names1; i++)
- {
- unistr2_to_ascii(names[i], &r_o.uni_name[i], sizeof(fstring)-1);
- }
- for (i = 0; i < r_o.num_types1; i++)
- {
- type[i] = r_o.type[i];
- }
- }
- else if (r_o.ptr_names == 0 && r_o.ptr_types == 0)
- {
- valid_query = True;
- *num_names = 0;
- }
- else
- {
- p = False;
- }
- }
+ /* Unmarshall response */
+
+ if (!samr_io_r_set_userinfo("", &r, &rbuf, 0)) {
+ goto done;
+ }
+
+ /* Return output parameters */
+
+ if (!NT_STATUS_IS_OK(result = r.status)) {
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_query;
+ return result;
}
-/****************************************************************************
-do a SAMR Query Alias Members
-****************************************************************************/
-BOOL samr_query_aliasmem(struct cli_state *cli, uint16 fnum,
- POLICY_HND *alias_pol,
- uint32 *num_mem, DOM_SID2 *sid)
+/* Set userinfo2 */
+
+NTSTATUS cli_samr_set_userinfo2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol, uint16 switch_value,
+ DATA_BLOB *sess_key, SAM_USERINFO_CTR *ctr)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_SET_USERINFO2 q;
+ SAMR_R_SET_USERINFO2 r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_QUERY_ALIASMEM q_o;
- BOOL valid_query = False;
+ DEBUG(10,("cli_samr_set_userinfo2\n"));
- DEBUG(4,("SAMR Query Alias Members.\n"));
+ if (!sess_key->length) {
+ DEBUG(1, ("No user session key\n"));
+ return NT_STATUS_NO_USER_SESSION_KEY;
+ }
- if (alias_pol == NULL || sid == NULL || num_mem == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_QUERY_ALIASMEM */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* store the parameters */
- make_samr_q_query_aliasmem(&q_o, alias_pol);
+ /* Marshall data and send request */
- /* turn parameters into data stream */
- samr_io_q_query_aliasmem("", &q_o, &data, 0);
+ init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_ALIASMEM, &data, &rdata))
- {
- SAMR_R_QUERY_ALIASMEM r_o;
- BOOL p;
+ if (!samr_io_q_set_userinfo2("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_SET_USERINFO2, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* get user info */
- r_o.sid = sid;
+ /* Unmarshall response */
- samr_io_r_query_aliasmem("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_QUERY_ALIASMEM: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_set_userinfo2("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p && r_o.ptr != 0)
- {
- valid_query = True;
- *num_mem = r_o.num_sids;
- }
+ /* Return output parameters */
+ if (!NT_STATUS_IS_OK(result = r.status)) {
+ goto done;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_query;
+ return result;
}
-/****************************************************************************
-do a SAMR Query User Aliases
-****************************************************************************/
-BOOL samr_query_useraliases(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, DOM_SID *sid,
- uint32 *num_aliases, uint32 *rid)
+/* Delete domain group */
+
+NTSTATUS cli_samr_delete_dom_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *group_pol)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_DELETE_DOM_GROUP q;
+ SAMR_R_DELETE_DOM_GROUP r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_QUERY_USERALIASES q_o;
- BOOL valid_query = False;
+ DEBUG(10,("cli_samr_delete_dom_group\n"));
- DEBUG(4,("SAMR Query User Aliases.\n"));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (pol == NULL || sid == NULL || rid == NULL || num_aliases == 0) return False;
+ /* Initialise parse structures */
- /* create and send a MSRPC command with api SAMR_QUERY_USERALIASES */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_query_useraliases(&q_o, pol, sid);
+ init_samr_q_delete_dom_group(&q, group_pol);
- /* turn parameters into data stream */
- samr_io_q_query_useraliases("", &q_o, &data, 0);
+ if (!samr_io_q_delete_dom_group("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_GROUP, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_USERALIASES, &data, &rdata))
- {
- SAMR_R_QUERY_USERALIASES r_o;
- BOOL p;
+ /* Unmarshall response */
- /* get user info */
- r_o.rid = rid;
+ if (!samr_io_r_delete_dom_group("", &r, &rbuf, 0)) {
+ goto done;
+ }
- samr_io_r_query_useraliases("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_QUERY_USERALIASES: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p && r_o.ptr != 0)
- {
- valid_query = True;
- *num_aliases = r_o.num_entries;
- }
+ result = r.status;
- }
-
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_query;
+ return result;
}
-/****************************************************************************
-do a SAMR Query Group Members
-****************************************************************************/
-BOOL samr_query_groupmem(struct cli_state *cli, uint16 fnum,
- POLICY_HND *group_pol,
- uint32 *num_mem, uint32 *rid, uint32 *attr)
-{
- prs_struct data;
- prs_struct rdata;
+/* Delete domain alias */
- SAMR_Q_QUERY_GROUPMEM q_o;
- BOOL valid_query = False;
+NTSTATUS cli_samr_delete_dom_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *alias_pol)
+{
+ prs_struct qbuf, rbuf;
+ SAMR_Q_DELETE_DOM_ALIAS q;
+ SAMR_R_DELETE_DOM_ALIAS r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- DEBUG(4,("SAMR Query Group Members.\n"));
+ DEBUG(10,("cli_samr_delete_dom_alias\n"));
- if (group_pol == NULL || rid == NULL || attr == NULL || num_mem == NULL) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_QUERY_GROUPMEM */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* store the parameters */
- make_samr_q_query_groupmem(&q_o, group_pol);
+ /* Marshall data and send request */
- /* turn parameters into data stream */
- samr_io_q_query_groupmem("", &q_o, &data, 0);
+ init_samr_q_delete_dom_alias(&q, alias_pol);
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_GROUPMEM, &data, &rdata))
- {
- SAMR_R_QUERY_GROUPMEM r_o;
- BOOL p;
+ if (!samr_io_q_delete_dom_alias("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_ALIAS, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* get user info */
- r_o.rid = rid;
- r_o.attr = attr;
+ /* Unmarshall response */
- samr_io_r_query_groupmem("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_QUERY_GROUPMEM: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_delete_dom_alias("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p && r_o.ptr != 0 &&
- r_o.ptr_rids != 0 && r_o.ptr_attrs != 0 &&
- r_o.num_rids == r_o.num_attrs)
- {
- valid_query = True;
- *num_mem = r_o.num_rids;
- }
+ /* Return output parameters */
- }
+ result = r.status;
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_query;
+ return result;
}
-/****************************************************************************
-do a SAMR Query User Groups
-****************************************************************************/
-BOOL samr_query_usergroups(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint32 *num_groups, DOM_GID *gid)
-{
- prs_struct data;
- prs_struct rdata;
+/* Delete domain user */
- SAMR_Q_QUERY_USERGROUPS q_o;
- BOOL valid_query = False;
+NTSTATUS cli_samr_delete_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol)
+{
+ prs_struct qbuf, rbuf;
+ SAMR_Q_DELETE_DOM_USER q;
+ SAMR_R_DELETE_DOM_USER r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- DEBUG(4,("SAMR Query User Groups.\n"));
+ DEBUG(10,("cli_samr_delete_dom_user\n"));
- if (pol == NULL || gid == NULL || num_groups == 0) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_QUERY_USERGROUPS */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* store the parameters */
- make_samr_q_query_usergroups(&q_o, pol);
+ /* Marshall data and send request */
- /* turn parameters into data stream */
- samr_io_q_query_usergroups("", &q_o, &data, 0);
+ init_samr_q_delete_dom_user(&q, user_pol);
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_USERGROUPS, &data, &rdata))
- {
- SAMR_R_QUERY_USERGROUPS r_o;
- BOOL p;
+ if (!samr_io_q_delete_dom_user("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_USER, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* get user info */
- r_o.gid = gid;
+ /* Unmarshall response */
- samr_io_r_query_usergroups("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_QUERY_USERGROUPS: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_delete_dom_user("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p && r_o.ptr_0 != 0)
- {
- valid_query = True;
- *num_groups = r_o.num_entries;
- }
+ /* Return output parameters */
- }
+ result = r.status;
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_query;
+ return result;
}
-/****************************************************************************
-do a SAMR Query Group Info
-****************************************************************************/
-BOOL samr_query_groupinfo(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol,
- uint16 switch_value, GROUP_INFO_CTR* ctr)
-{
- prs_struct data;
- prs_struct rdata;
+/* Query user security object */
- SAMR_Q_QUERY_GROUPINFO q_o;
- BOOL valid_query = False;
+NTSTATUS cli_samr_query_sec_obj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol, uint16 switch_value,
+ TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
+{
+ prs_struct qbuf, rbuf;
+ SAMR_Q_QUERY_SEC_OBJ q;
+ SAMR_R_QUERY_SEC_OBJ r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- DEBUG(4,("SAMR Query Group Info. level: %d\n", switch_value));
+ DEBUG(10,("cli_samr_query_sec_obj\n"));
- if (pol == NULL || ctr == NULL || switch_value == 0) return False;
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- /* create and send a MSRPC command with api SAMR_QUERY_GROUPINFO */
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* store the parameters */
- make_samr_q_query_groupinfo(&q_o, pol, switch_value);
+ /* Marshall data and send request */
- /* turn parameters into data stream */
- samr_io_q_query_groupinfo("", &q_o, &data, 0);
+ init_samr_q_query_sec_obj(&q, user_pol, switch_value);
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_GROUPINFO, &data, &rdata))
- {
- SAMR_R_QUERY_GROUPINFO r_o;
- BOOL p;
+ if (!samr_io_q_query_sec_obj("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_QUERY_SEC_OBJECT, &qbuf, &rbuf)) {
+ goto done;
+ }
- /* get user info */
- r_o.ctr = ctr;
+ /* Unmarshall response */
- samr_io_r_query_groupinfo("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_QUERY_GROUPINFO: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ if (!samr_io_r_query_sec_obj("", &r, &rbuf, 0)) {
+ goto done;
+ }
- if (p && r_o.ctr->switch_value1 != switch_value)
- {
- DEBUG(0,("SAMR_R_QUERY_GROUPINFO: received incorrect level %d\n",
- r_o.ctr->switch_value1));
- }
+ /* Return output parameters */
- if (p && r_o.ptr != 0)
- {
- valid_query = True;
- }
- }
+ result = r.status;
+ *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_query;
+ return result;
}
-/****************************************************************************
-do a SAMR Query User Info
-****************************************************************************/
-BOOL samr_query_userinfo(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint16 switch_value, void* usr)
+/* Get domain password info */
+
+NTSTATUS cli_samr_get_dom_pwinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ uint16 *unk_0, uint16 *unk_1)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_GET_DOM_PWINFO q;
+ SAMR_R_GET_DOM_PWINFO r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_QUERY_USERINFO q_o;
- BOOL valid_query = False;
+ DEBUG(10,("cli_samr_get_dom_pwinfo\n"));
- DEBUG(4,("SAMR Query User Info. level: %d\n", switch_value));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (pol == NULL || usr == NULL || switch_value == 0) return False;
+ /* Initialise parse structures */
- /* create and send a MSRPC command with api SAMR_QUERY_USERINFO */
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_query_userinfo(&q_o, pol, switch_value);
+ init_samr_q_get_dom_pwinfo(&q, cli->desthost);
- /* turn parameters into data stream */
- samr_io_q_query_userinfo("", &q_o, &data, 0);
+ if (!samr_io_q_get_dom_pwinfo("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_GET_DOM_PWINFO, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_QUERY_USERINFO, &data, &rdata))
- {
- SAMR_R_QUERY_USERINFO r_o;
- BOOL p;
+ /* Unmarshall response */
- /* get user info */
- r_o.info.id = usr;
+ if (!samr_io_r_get_dom_pwinfo("", &r, &rbuf, 0))
+ goto done;
- samr_io_r_query_userinfo("", &r_o, &rdata, 0);
- p = rdata.offset != 0;
-
- if (p && r_o.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_R_QUERY_USERINFO: %s\n", get_nt_error_msg(r_o.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p && r_o.switch_value != switch_value)
- {
- DEBUG(0,("SAMR_R_QUERY_USERINFO: received incorrect level %d\n",
- r_o.switch_value));
- }
+ result = r.status;
- if (p && r_o.ptr != 0)
- {
- valid_query = True;
- }
+ if (NT_STATUS_IS_OK(result)) {
+ if (unk_0)
+ *unk_0 = r.unk_0;
+ if (unk_1)
+ *unk_1 = r.unk_1;
}
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
- return valid_query;
+ return result;
}
-/****************************************************************************
-do a SAMR Close
-****************************************************************************/
-BOOL samr_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
+/* Lookup Domain Name */
+
+NTSTATUS cli_samr_lookup_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol, char *domain_name,
+ DOM_SID *sid)
{
- prs_struct data;
- prs_struct rdata;
+ prs_struct qbuf, rbuf;
+ SAMR_Q_LOOKUP_DOMAIN q;
+ SAMR_R_LOOKUP_DOMAIN r;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- SAMR_Q_CLOSE_HND q_c;
- BOOL valid_close = False;
+ DEBUG(10,("cli_samr_lookup_domain\n"));
- DEBUG(4,("SAMR Close\n"));
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
- if (hnd == NULL) return False;
+ /* Initialise parse structures */
- prs_init(&data , 1024, 4, SAFETY_MARGIN, False);
- prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- /* create and send a MSRPC command with api SAMR_CLOSE_HND */
+ /* Marshall data and send request */
- /* store the parameters */
- make_samr_q_close_hnd(&q_c, hnd);
+ init_samr_q_lookup_domain(&q, user_pol, domain_name);
- /* turn parameters into data stream */
- samr_io_q_close_hnd("", &q_c, &data, 0);
+ if (!samr_io_q_lookup_domain("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SAMR_LOOKUP_DOMAIN, &qbuf, &rbuf))
+ goto done;
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, fnum, SAMR_CLOSE_HND, &data, &rdata))
- {
- SAMR_R_CLOSE_HND r_c;
- BOOL p;
+ /* Unmarshall response */
- samr_io_r_close_hnd("", &r_c, &rdata, 0);
- p = rdata.offset != 0;
+ if (!samr_io_r_lookup_domain("", &r, &rbuf, 0))
+ goto done;
- if (p && r_c.status != 0)
- {
- /* report error code */
- DEBUG(0,("SAMR_CLOSE_HND: %s\n", get_nt_error_msg(r_c.status)));
- p = False;
- }
+ /* Return output parameters */
- if (p)
- {
- /* check that the returned policy handle is all zeros */
- int i;
- valid_close = True;
-
- for (i = 0; i < sizeof(r_c.pol.data); i++)
- {
- if (r_c.pol.data[i] != 0)
- {
- valid_close = False;
- break;
- }
- }
- if (!valid_close)
- {
- DEBUG(0,("SAMR_CLOSE_HND: non-zero handle returned\n"));
- }
- }
- }
+ result = r.status;
- prs_mem_free(&data );
- prs_mem_free(&rdata );
+ if (NT_STATUS_IS_OK(result))
+ sid_copy(sid, &r.dom_sid.sid);
- return valid_close;
-}
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+ return result;
+}