diff options
author | Gerald Carter <jerry@samba.org> | 2006-02-03 22:19:41 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:06:23 -0500 |
commit | 0af1500fc0bafe61019f1b2ab1d9e1d369221240 (patch) | |
tree | 653fc2533795458d5f9696402285d9f14e527a21 /source3/rpcclient | |
parent | 21a30a1346c9f9a25659a0cea0d276d8c2e6ddca (diff) | |
download | samba-0af1500fc0bafe61019f1b2ab1d9e1d369221240.tar.gz samba-0af1500fc0bafe61019f1b2ab1d9e1d369221240.tar.xz samba-0af1500fc0bafe61019f1b2ab1d9e1d369221240.zip |
r13316: Let the carnage begin....
Sync with trunk as off r13315
(This used to be commit 17e63ac4ed8325c0d44fe62b2442449f3298559f)
Diffstat (limited to 'source3/rpcclient')
-rw-r--r-- | source3/rpcclient/cmd_dfs.c | 111 | ||||
-rw-r--r-- | source3/rpcclient/cmd_lsarpc.c | 4 | ||||
-rw-r--r-- | source3/rpcclient/cmd_samr.c | 137 |
3 files changed, 205 insertions, 47 deletions
diff --git a/source3/rpcclient/cmd_dfs.c b/source3/rpcclient/cmd_dfs.c index 956dbfa4027..b4d43bda5ee 100644 --- a/source3/rpcclient/cmd_dfs.c +++ b/source3/rpcclient/cmd_dfs.c @@ -3,6 +3,7 @@ RPC pipe client Copyright (C) Tim Potter 2000 + Copyright (C) Jelmer Vernooij 2005. 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 @@ -27,7 +28,7 @@ static NTSTATUS cmd_dfs_exist(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { - BOOL dfs_exists; + uint32 dfs_exists; NTSTATUS result; if (argc != 1) { @@ -35,7 +36,7 @@ static NTSTATUS cmd_dfs_exist(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } - result = rpccli_dfs_exist(cli, mem_ctx, &dfs_exists); + result = rpccli_dfs_GetManagerVersion(cli, mem_ctx, &dfs_exists); if (NT_STATUS_IS_OK(result)) printf("dfs is %spresent\n", dfs_exists ? "" : "not "); @@ -47,21 +48,21 @@ static NTSTATUS cmd_dfs_add(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { NTSTATUS result; - const char *entrypath, *servername, *sharename, *comment; + const char *path, *servername, *sharename, *comment; uint32 flags = 0; if (argc != 5) { - printf("Usage: %s entrypath servername sharename comment\n", + printf("Usage: %s path servername sharename comment\n", argv[0]); return NT_STATUS_OK; } - entrypath = argv[1]; + path = argv[1]; servername = argv[2]; sharename = argv[3]; comment = argv[4]; - result = rpccli_dfs_add(cli, mem_ctx, entrypath, servername, + result = rpccli_dfs_Add(cli, mem_ctx, path, servername, sharename, comment, flags); return result; @@ -71,18 +72,18 @@ static NTSTATUS cmd_dfs_remove(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { NTSTATUS result; - const char *entrypath, *servername, *sharename; + const char *path, *servername, *sharename; if (argc != 4) { - printf("Usage: %s entrypath servername sharename\n", argv[0]); + printf("Usage: %s path servername sharename\n", argv[0]); return NT_STATUS_OK; } - entrypath = argv[1]; + path = argv[1]; servername = argv[2]; sharename = argv[3]; - result = rpccli_dfs_remove(cli, mem_ctx, entrypath, servername, + result = rpccli_dfs_Remove(cli, mem_ctx, path, servername, sharename); return result; @@ -90,78 +91,92 @@ static NTSTATUS cmd_dfs_remove(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, /* Display a DFS_INFO_1 structure */ -static void display_dfs_info_1(DFS_INFO_1 *info1) +static void display_dfs_info_1(NETDFS_DFS_INFO1 *info1) { fstring temp; - unistr2_to_ascii(temp, &info1->entrypath, sizeof(temp) - 1); - printf("entrypath: %s\n", temp); + unistr2_to_ascii(temp, &info1->path, sizeof(temp) - 1); + printf("path: %s\n", temp); } /* Display a DFS_INFO_2 structure */ -static void display_dfs_info_2(DFS_INFO_2 *info2) +static void display_dfs_info_2(NETDFS_DFS_INFO2 *info2) { fstring temp; - unistr2_to_ascii(temp, &info2->entrypath, sizeof(temp) - 1); - printf("entrypath: %s\n", temp); + unistr2_to_ascii(temp, &info2->path, sizeof(temp) - 1); + printf("path: %s\n", temp); unistr2_to_ascii(temp, &info2->comment, sizeof(temp) - 1); printf("\tcomment: %s\n", temp); printf("\tstate: %d\n", info2->state); - printf("\tnum_storages: %d\n", info2->num_storages); + printf("\tnum_stores: %d\n", info2->num_stores); } /* Display a DFS_INFO_3 structure */ -static void display_dfs_info_3(DFS_INFO_3 *info3) +static void display_dfs_info_3(NETDFS_DFS_INFO3 *info3) { fstring temp; int i; - unistr2_to_ascii(temp, &info3->entrypath, sizeof(temp) - 1); - printf("entrypath: %s\n", temp); + unistr2_to_ascii(temp, &info3->path, sizeof(temp) - 1); + printf("path: %s\n", temp); unistr2_to_ascii(temp, &info3->comment, sizeof(temp) - 1); printf("\tcomment: %s\n", temp); printf("\tstate: %d\n", info3->state); - printf("\tnum_storages: %d\n", info3->num_storages); + printf("\tnum_stores: %d\n", info3->num_stores); - for (i = 0; i < info3->num_storages; i++) { - DFS_STORAGE_INFO *dsi = &info3->storages[i]; + for (i = 0; i < info3->num_stores; i++) { + NETDFS_DFS_STORAGEINFO *dsi = &info3->stores[i]; - unistr2_to_ascii(temp, &dsi->servername, sizeof(temp) - 1); - printf("\t\tstorage[%d] servername: %s\n", i, temp); + unistr2_to_ascii(temp, &dsi->server, sizeof(temp) - 1); + printf("\t\tstorage[%d] server: %s\n", i, temp); - unistr2_to_ascii(temp, &dsi->sharename, sizeof(temp) - 1); - printf("\t\tstorage[%d] sharename: %s\n", i, temp); + unistr2_to_ascii(temp, &dsi->share, sizeof(temp) - 1); + printf("\t\tstorage[%d] share: %s\n", i, temp); } } -/* Display a DFS_INFO_CTR structure */ -static void display_dfs_info_ctr(DFS_INFO_CTR *ctr) +/* Display a DFS_INFO_CTR structure */ +static void display_dfs_info(NETDFS_DFS_INFO_CTR *ctr) { - int i; - - for (i = 0; i < ctr->num_entries; i++) { - switch (ctr->switch_value) { + switch (ctr->switch_value) { case 0x01: - display_dfs_info_1(&ctr->dfs.info1[i]); + display_dfs_info_1(&ctr->u.info1); break; case 0x02: - display_dfs_info_2(&ctr->dfs.info2[i]); + display_dfs_info_2(&ctr->u.info2); break; case 0x03: - display_dfs_info_3(&ctr->dfs.info3[i]); + display_dfs_info_3(&ctr->u.info3); break; default: printf("unsupported info level %d\n", ctr->switch_value); break; + } +} + +static void display_dfs_enumstruct(NETDFS_DFS_ENUMSTRUCT *ctr) +{ + int i; + + /* count is always the first element, so we can just use info1 here */ + for (i = 0; i < ctr->e.u.info1.count; i++) { + switch (ctr->level) { + case 1: display_dfs_info_1(&ctr->e.u.info1.s[i]); break; + case 2: display_dfs_info_2(&ctr->e.u.info2.s[i]); break; + case 3: display_dfs_info_3(&ctr->e.u.info3.s[i]); break; + default: + printf("unsupported info level %d\n", + ctr->level); + return; } } } @@ -171,9 +186,11 @@ static void display_dfs_info_ctr(DFS_INFO_CTR *ctr) static NTSTATUS cmd_dfs_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) { - DFS_INFO_CTR ctr; + NETDFS_DFS_ENUMSTRUCT str; + NETDFS_DFS_ENUMINFO_CTR ctr; NTSTATUS result; uint32 info_level = 1; + uint32 unknown = 0, total = 0; if (argc > 2) { printf("Usage: %s [info_level]\n", argv[0]); @@ -183,10 +200,14 @@ static NTSTATUS cmd_dfs_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, if (argc == 2) info_level = atoi(argv[1]); - result = rpccli_dfs_enum(cli, mem_ctx, info_level, &ctr); + ZERO_STRUCT(ctr); + init_netdfs_dfs_EnumStruct(&str, info_level, ctr); + str.e.ptr0 = 1; + + result = rpccli_dfs_Enum(cli, mem_ctx, info_level, 0xFFFFFFFF, &str, &unknown, &total); if (NT_STATUS_IS_OK(result)) - display_dfs_info_ctr(&ctr); + display_dfs_enumstruct(&str); return result; } @@ -195,28 +216,28 @@ static NTSTATUS cmd_dfs_getinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx int argc, const char **argv) { NTSTATUS result; - const char *entrypath, *servername, *sharename; + const char *path, *servername, *sharename; uint32 info_level = 1; - DFS_INFO_CTR ctr; + NETDFS_DFS_INFO_CTR ctr; if (argc < 4 || argc > 5) { - printf("Usage: %s entrypath servername sharename " + printf("Usage: %s path servername sharename " "[info_level]\n", argv[0]); return NT_STATUS_OK; } - entrypath = argv[1]; + path = argv[1]; servername = argv[2]; sharename = argv[3]; if (argc == 5) info_level = atoi(argv[4]); - result = rpccli_dfs_get_info(cli, mem_ctx, entrypath, servername, + result = rpccli_dfs_GetInfo(cli, mem_ctx, path, servername, sharename, info_level, &ctr); if (NT_STATUS_IS_OK(result)) - display_dfs_info_ctr(&ctr); + display_dfs_info(&ctr); return result; } diff --git a/source3/rpcclient/cmd_lsarpc.c b/source3/rpcclient/cmd_lsarpc.c index 5adaf469818..1b7ebac45f9 100644 --- a/source3/rpcclient/cmd_lsarpc.c +++ b/source3/rpcclient/cmd_lsarpc.c @@ -47,7 +47,7 @@ static NTSTATUS name_to_sid(struct rpc_pipe_client *cli, if (!NT_STATUS_IS_OK(result)) goto done; - result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, 1, &name, &sids, &sid_types); + result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, 1, &name, NULL, &sids, &sid_types); if (!NT_STATUS_IS_OK(result)) goto done; @@ -165,7 +165,7 @@ static NTSTATUS cmd_lsa_lookup_names(struct rpc_pipe_client *cli, goto done; result = rpccli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1, - (const char**)(argv + 1), &sids, &types); + (const char**)(argv + 1), NULL, &sids, &types); if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED)) diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c index 991b55a13c8..93a3e390363 100644 --- a/source3/rpcclient/cmd_samr.c +++ b/source3/rpcclient/cmd_samr.c @@ -1065,6 +1065,82 @@ static NTSTATUS cmd_samr_query_aliasmem(struct rpc_pipe_client *cli, return result; } +/* Query delete an alias membership */ + +static NTSTATUS cmd_samr_delete_alias(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + POLICY_HND connect_pol, domain_pol, alias_pol; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + uint32 alias_rid; + uint32 access_mask = MAXIMUM_ALLOWED_ACCESS; + + if (argc != 3) { + printf("Usage: %s builtin|domain [rid|name]\n", argv[0]); + return NT_STATUS_OK; + } + + alias_rid = strtoul(argv[2], NULL, 10); + + /* Open SAMR handle */ + + result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS, + &connect_pol); + + if (!NT_STATUS_IS_OK(result)) + goto done; + + /* Open handle on domain */ + + if (StrCaseCmp(argv[1], "domain")==0) + result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol, + MAXIMUM_ALLOWED_ACCESS, + &domain_sid, &domain_pol); + else if (StrCaseCmp(argv[1], "builtin")==0) + result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol, + MAXIMUM_ALLOWED_ACCESS, + &global_sid_Builtin, &domain_pol); + else + return NT_STATUS_INVALID_PARAMETER; + + if (!NT_STATUS_IS_OK(result)) + goto done; + + /* Open handle on alias */ + + result = rpccli_samr_open_alias(cli, mem_ctx, &domain_pol, + access_mask, + alias_rid, &alias_pol); + if (!NT_STATUS_IS_OK(result) && (alias_rid == 0)) { + /* Probably this was a user name, try lookupnames */ + uint32 num_rids; + uint32 *rids, *types; + + result = rpccli_samr_lookup_names(cli, mem_ctx, &domain_pol, + 1000, 1, &argv[2], + &num_rids, &rids, + &types); + + if (NT_STATUS_IS_OK(result)) { + result = rpccli_samr_open_alias(cli, mem_ctx, + &domain_pol, + access_mask, + rids[0], &alias_pol); + } + } + + result = rpccli_samr_delete_dom_alias(cli, mem_ctx, &alias_pol); + + if (!NT_STATUS_IS_OK(result)) + goto done; + + rpccli_samr_close(cli, mem_ctx, &domain_pol); + rpccli_samr_close(cli, mem_ctx, &connect_pol); + done: + return result; +} + /* Query display info */ static NTSTATUS cmd_samr_query_dispinfo(struct rpc_pipe_client *cli, @@ -1405,6 +1481,65 @@ static NTSTATUS cmd_samr_create_dom_group(struct rpc_pipe_client *cli, return result; } +/* Create domain alias */ + +static NTSTATUS cmd_samr_create_dom_alias(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + POLICY_HND connect_pol, domain_pol, alias_pol; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + const char *alias_name; + uint32 access_mask = MAXIMUM_ALLOWED_ACCESS; + + if ((argc < 2) || (argc > 3)) { + printf("Usage: %s aliasname [access mask]\n", argv[0]); + return NT_STATUS_OK; + } + + alias_name = argv[1]; + + if (argc > 2) + sscanf(argv[2], "%x", &access_mask); + + /* Get sam policy handle */ + + result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS, + &connect_pol); + + if (!NT_STATUS_IS_OK(result)) + goto done; + + /* Get domain policy handle */ + + result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol, + access_mask, + &domain_sid, &domain_pol); + + if (!NT_STATUS_IS_OK(result)) + goto done; + + /* Create domain user */ + + result = rpccli_samr_create_dom_alias(cli, mem_ctx, &domain_pol, + alias_name, &alias_pol); + + if (!NT_STATUS_IS_OK(result)) + goto done; + + result = rpccli_samr_close(cli, mem_ctx, &alias_pol); + if (!NT_STATUS_IS_OK(result)) goto done; + + result = rpccli_samr_close(cli, mem_ctx, &domain_pol); + if (!NT_STATUS_IS_OK(result)) goto done; + + result = rpccli_samr_close(cli, mem_ctx, &connect_pol); + if (!NT_STATUS_IS_OK(result)) goto done; + + done: + return result; +} + /* Lookup sam names */ static NTSTATUS cmd_samr_lookup_names(struct rpc_pipe_client *cli, @@ -1793,6 +1928,7 @@ struct cmd_set samr_commands[] = { { "queryuseraliases", RPC_RTYPE_NTSTATUS, cmd_samr_query_useraliases, NULL, PI_SAMR, NULL, "Query user aliases", "" }, { "querygroupmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_groupmem, NULL, PI_SAMR, NULL, "Query group membership", "" }, { "queryaliasmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasmem, NULL, PI_SAMR, NULL, "Query alias membership", "" }, + { "deletealias", RPC_RTYPE_NTSTATUS, cmd_samr_delete_alias, NULL, PI_SAMR, NULL, "Delete an alias", "" }, { "querydispinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo, NULL, PI_SAMR, NULL, "Query display info", "" }, { "querydominfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dominfo, NULL, PI_SAMR, NULL, "Query domain info", "" }, { "enumdomusers", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_users, NULL, PI_SAMR, NULL, "Enumerate domain users", "" }, @@ -1801,6 +1937,7 @@ struct cmd_set samr_commands[] = { { "createdomuser", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_user, NULL, PI_SAMR, NULL, "Create domain user", "" }, { "createdomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_group, NULL, PI_SAMR, NULL, "Create domain group", "" }, + { "createdomalias", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_alias, NULL, PI_SAMR, NULL, "Create domain alias", "" }, { "samlookupnames", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_names, NULL, PI_SAMR, NULL, "Look up names", "" }, { "samlookuprids", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_rids, NULL, PI_SAMR, NULL, "Look up names", "" }, { "deletedomuser", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_user, NULL, PI_SAMR, NULL, "Delete domain user", "" }, |