summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2004-06-02 14:25:29 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:51:52 -0500
commit47af5445f39202b91e29bce0fff8933e56063789 (patch)
tree9a8af8fd32bdc6549d83d13fa2a7ff489359927d /source3
parentefc96df3d5b415ca9c19527a44d0619992712b6d (diff)
downloadsamba-47af5445f39202b91e29bce0fff8933e56063789.tar.gz
samba-47af5445f39202b91e29bce0fff8933e56063789.tar.bz2
samba-47af5445f39202b91e29bce0fff8933e56063789.zip
r977: Implement 'net rpc group rename' -- rename domain groups.
Volker (This used to be commit 9ceff803278bdbc09cb5ab678a108cea24ab49a9)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/rpc_samr.h9
-rw-r--r--source3/rpc_parse/parse_samr.c46
-rw-r--r--source3/utils/net_rpc.c78
3 files changed, 133 insertions, 0 deletions
diff --git a/source3/include/rpc_samr.h b/source3/include/rpc_samr.h
index 089941de3a..6dc679996d 100644
--- a/source3/include/rpc_samr.h
+++ b/source3/include/rpc_samr.h
@@ -1068,6 +1068,14 @@ typedef struct samr_group_info1
} GROUP_INFO1;
+typedef struct samr_group_info2
+{
+ uint16 level;
+ UNIHDR hdr_acct_name;
+ UNISTR2 uni_acct_name;
+
+} GROUP_INFO2;
+
typedef struct samr_group_info3
{
uint32 unknown_1; /* 0x0000 0003 - number of group members? */
@@ -1090,6 +1098,7 @@ typedef struct group_info_ctr
union
{
GROUP_INFO1 info1;
+ GROUP_INFO2 info2;
GROUP_INFO3 info3;
GROUP_INFO4 info4;
diff --git a/source3/rpc_parse/parse_samr.c b/source3/rpc_parse/parse_samr.c
index 85eedc7baa..e6d7e847ad 100644
--- a/source3/rpc_parse/parse_samr.c
+++ b/source3/rpc_parse/parse_samr.c
@@ -2204,12 +2204,17 @@ reads or writes a structure.
BOOL samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1,
prs_struct *ps, int depth)
{
+ uint16 dummy = 1;
+
if (gr1 == NULL)
return False;
prs_debug(ps, depth, desc, "samr_io_group_info1");
depth++;
+ if(!prs_uint16("level", ps, depth, &dummy))
+ return False;
+
if(!prs_align(ps))
return False;
@@ -2236,6 +2241,43 @@ BOOL samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1,
}
/*******************************************************************
+inits a GROUP_INFO2 structure.
+********************************************************************/
+
+void init_samr_group_info2(GROUP_INFO2 * gr2, const char *acct_name)
+{
+ DEBUG(5, ("init_samr_group_info2\n"));
+
+ gr2->level = 2;
+ init_unistr2(&gr2->uni_acct_name, acct_name, UNI_FLAGS_NONE);
+ init_uni_hdr(&gr2->hdr_acct_name, &gr2->uni_acct_name);
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_group_info2(const char *desc, GROUP_INFO2 *gr2, prs_struct *ps, int depth)
+{
+ if (gr2 == NULL)
+ return False;
+
+ prs_debug(ps, depth, desc, "samr_io_group_info2");
+ depth++;
+
+ if(!prs_uint16("hdr_level", ps, depth, &gr2->level))
+ return False;
+
+ if(!smb_io_unihdr("hdr_acct_name", &gr2->hdr_acct_name, ps, depth))
+ return False;
+ if(!smb_io_unistr2("uni_acct_name", &gr2->uni_acct_name,
+ gr2->hdr_acct_name.buffer, ps, depth))
+ return False;
+
+ return True;
+}
+
+/*******************************************************************
inits a GROUP_INFO3 structure.
********************************************************************/
@@ -2328,6 +2370,10 @@ static BOOL samr_group_info_ctr(const char *desc, GROUP_INFO_CTR **ctr,
if(!samr_io_group_info1("group_info1", &(*ctr)->group.info1, ps, depth))
return False;
break;
+ case 2:
+ if(!samr_io_group_info2("group_info2", &(*ctr)->group.info2, ps, depth))
+ return False;
+ break;
case 3:
if(!samr_io_group_info3("group_info3", &(*ctr)->group.info3, ps, depth))
return False;
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index 41ab5ff8a7..e21f79df30 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -2209,6 +2209,83 @@ static int rpc_group_members(int argc, const char **argv)
argc, argv);
}
+static NTSTATUS
+rpc_group_rename_internals(const DOM_SID *domain_sid,
+ const char *domain_name,
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, int argc, const char **argv)
+{
+ NTSTATUS result;
+ POLICY_HND connect_pol, domain_pol, group_pol;
+ uint32 num_rids, *rids, *rid_types;
+ GROUP_INFO_CTR ctr;
+
+ if (argc != 2) {
+ d_printf("Usage: 'net rpc group rename group newname'\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ /* Get sam policy handle */
+
+ result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
+ &connect_pol);
+
+ if (!NT_STATUS_IS_OK(result))
+ return result;
+
+ /* Get domain policy handle */
+
+ result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ domain_sid, &domain_pol);
+
+ if (!NT_STATUS_IS_OK(result))
+ return result;
+
+ result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol, 1000,
+ 1, argv, &num_rids, &rids, &rid_types);
+
+ if (num_rids != 1) {
+ d_printf("Couldn't find group %s\n", argv[0]);
+ return result;
+ }
+
+ if (rid_types[0] != SID_NAME_DOM_GRP) {
+ d_printf("Can only rename domain groups\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ rids[0], &group_pol);
+
+ if (!NT_STATUS_IS_OK(result))
+ return result;
+
+ ZERO_STRUCT(ctr);
+
+ ctr.switch_value1 = 2;
+ init_samr_group_info2(&ctr.group.info2, argv[1]);
+
+ result = cli_samr_set_groupinfo(cli, mem_ctx, &group_pol, &ctr);
+
+ if (!NT_STATUS_IS_OK(result))
+ return result;
+
+ return NT_STATUS_NO_SUCH_GROUP;
+}
+
+static int rpc_group_rename(int argc, const char **argv)
+{
+ if (argc != 2) {
+ return rpc_group_usage(argc, argv);
+ }
+
+ return run_rpc_command(NULL, PI_SAMR, 0,
+ rpc_group_rename_internals,
+ argc, argv);
+}
+
/**
* 'net rpc group' entrypoint.
* @param argc Standard main() style argc
@@ -2225,6 +2302,7 @@ int net_rpc_group(int argc, const char **argv)
{"delmem", rpc_group_delmem},
{"list", rpc_group_list},
{"members", rpc_group_members},
+ {"rename", rpc_group_rename},
{NULL, NULL}
};