diff options
author | Günther Deschner <gd@samba.org> | 2005-01-20 16:51:24 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:55:05 -0500 |
commit | 725edd20f1589be310a8d1bab7a0aa907a55416e (patch) | |
tree | c18312d0ecc635f6dfee0aba66c9bf244177cbfb /source3/utils/net_rpc.c | |
parent | e86235fbdcfe8dd71b2ee887052e27f67a240fab (diff) | |
download | samba-725edd20f1589be310a8d1bab7a0aa907a55416e.tar.gz samba-725edd20f1589be310a8d1bab7a0aa907a55416e.tar.bz2 samba-725edd20f1589be310a8d1bab7a0aa907a55416e.zip |
r4868: Add "net rpc user RENAME"-command.
Note that Samba3 does not yet support it server-side.
Guenther
(This used to be commit b2c8220931733593fd312fc25b6c73f440b4567a)
Diffstat (limited to 'source3/utils/net_rpc.c')
-rw-r--r-- | source3/utils/net_rpc.c | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c index 5374d48de6..430649d81b 100644 --- a/source3/utils/net_rpc.c +++ b/source3/utils/net_rpc.c @@ -670,6 +670,133 @@ static NTSTATUS rpc_user_del_internals(const DOM_SID *domain_sid, } /** + * Rename a user on a remote RPC server + * + * All parameters are provided by the run_rpc_command function, except for + * argc, argv which are passes through. + * + * @param domain_sid The domain sid acquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on completion of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ + +static NTSTATUS rpc_user_rename_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) { + + POLICY_HND connect_pol, domain_pol, user_pol; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + uint32 info_level = 7; + const char *old_name, *new_name; + uint32 *user_rid; + uint32 flags = 0x000003e8; /* Unknown */ + uint32 num_rids, *name_types; + uint32 num_names = 1; + const char **names; + SAM_USERINFO_CTR *user_ctr; + SAM_USERINFO_CTR ctr; + SAM_USER_INFO_7 info7; + + if (argc != 2) { + d_printf("New and old username must be specified\n"); + rpc_user_usage(argc, argv); + return NT_STATUS_OK; + } + + old_name = argv[0]; + new_name = argv[1]; + + ZERO_STRUCT(ctr); + ZERO_STRUCT(user_ctr); + + /* Get sam policy handle */ + + result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS, + &connect_pol); + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + /* 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)) { + goto done; + } + + names = TALLOC_ARRAY(mem_ctx, const char *, num_names); + names[0] = old_name; + result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol, + flags, num_names, names, + &num_rids, &user_rid, &name_types); + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + /* Open domain user */ + result = cli_samr_open_user(cli, mem_ctx, &domain_pol, + MAXIMUM_ALLOWED_ACCESS, user_rid[0], &user_pol); + + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + /* Query user info */ + result = cli_samr_query_userinfo(cli, mem_ctx, &user_pol, + info_level, &user_ctr); + + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + ctr.switch_value = info_level; + ctr.info.id7 = &info7; + + init_sam_user_info7(&info7, new_name); + + /* Set new name */ + result = cli_samr_set_userinfo(cli, mem_ctx, &user_pol, + info_level, &cli->user_session_key, &ctr); + + if (!NT_STATUS_IS_OK(result)) { + goto done; + } + + done: + if (!NT_STATUS_IS_OK(result)) { + d_printf("Failed to rename user from %s to %s - %s\n", old_name, new_name, + nt_errstr(result)); + } else { + d_printf("Renamed user from %s to %s\n", old_name, new_name); + } + return result; +} + + +/** + * Rename a user on a remote RPC server + * + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return A shell status integer (0 for success) + **/ + +static int rpc_user_rename(int argc, const char **argv) +{ + return run_rpc_command(NULL, PI_SAMR, 0, rpc_user_rename_internals, + argc, argv); +} + +/** * Delete a user from a remote RPC server * * @param argc Standard main() style argc @@ -1011,6 +1138,7 @@ int net_rpc_user(int argc, const char **argv) {"info", rpc_user_info}, {"delete", rpc_user_delete}, {"password", rpc_user_password}, + {"rename", rpc_user_rename}, {NULL, NULL} }; |