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
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
{
fstring temp;
- unistr2_to_ascii(temp, &usr->uni_name, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_name, sizeof(temp));
printf("\tUser Name :\t%s\n", temp);
}
{
fstring temp;
- unistr2_to_ascii(temp, &usr->uni_user_name, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_user_name, sizeof(temp));
printf("\tUser Name :\t%s\n", temp);
- unistr2_to_ascii(temp, &usr->uni_full_name, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_full_name, sizeof(temp));
printf("\tFull Name :\t%s\n", temp);
- unistr2_to_ascii(temp, &usr->uni_home_dir, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_home_dir, sizeof(temp));
printf("\tHome Drive :\t%s\n", temp);
- unistr2_to_ascii(temp, &usr->uni_dir_drive, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_dir_drive, sizeof(temp));
printf("\tDir Drive :\t%s\n", temp);
- unistr2_to_ascii(temp, &usr->uni_profile_path, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_profile_path, sizeof(temp));
printf("\tProfile Path:\t%s\n", temp);
- unistr2_to_ascii(temp, &usr->uni_logon_script, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_logon_script, sizeof(temp));
printf("\tLogon Script:\t%s\n", temp);
- unistr2_to_ascii(temp, &usr->uni_acct_desc, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_acct_desc, sizeof(temp));
printf("\tDescription :\t%s\n", temp);
- unistr2_to_ascii(temp, &usr->uni_workstations, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_workstations, sizeof(temp));
printf("\tWorkstations:\t%s\n", temp);
- unistr2_to_ascii(temp, &usr->uni_comment, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_comment, sizeof(temp));
printf("\tUnknown Str :\t%s\n", temp);
- unistr2_to_ascii(temp, &usr->uni_munged_dial, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &usr->uni_munged_dial, sizeof(temp));
printf("\tRemote Dial :\t%s\n", temp);
printf("\tLogon Time :\t%s\n",
{
fstring name;
- unistr2_to_ascii(name, &info2->uni_domain, sizeof(name) - 1);
+ unistr2_to_ascii(name, &info2->uni_domain, sizeof(name));
printf("Domain:\t\t%s\n", name);
- unistr2_to_ascii(name, &info2->uni_server, sizeof(name) - 1);
+ unistr2_to_ascii(name, &info2->uni_server, sizeof(name));
printf("Server:\t\t%s\n", name);
- unistr2_to_ascii(name, &info2->uni_comment, sizeof(name) - 1);
+ unistr2_to_ascii(name, &info2->uni_comment, sizeof(name));
printf("Comment:\t%s\n", name);
printf("Total Users:\t%d\n", info2->num_domain_usrs);
{
fstring name;
- unistr2_to_ascii(name, &info4->uni_comment, sizeof(name) - 1);
+ unistr2_to_ascii(name, &info4->uni_comment, sizeof(name));
printf("Comment:\t%s\n", name);
}
{
fstring name;
- unistr2_to_ascii(name, &info5->uni_domain, sizeof(name) - 1);
+ unistr2_to_ascii(name, &info5->uni_domain, sizeof(name));
printf("Domain:\t\t%s\n", name);
}
{
fstring name;
- unistr2_to_ascii(name, &info6->uni_server, sizeof(name) - 1);
+ unistr2_to_ascii(name, &info6->uni_server, sizeof(name));
printf("Server:\t\t%s\n", name);
}
printf("RID: 0x%x ", e1->rid_user);
printf("acb: 0x%x ", e1->acb_info);
- unistr2_to_ascii(tmp, &s1->uni_acct_name, sizeof(tmp)-1);
+ unistr2_to_ascii(tmp, &s1->uni_acct_name, sizeof(tmp));
printf("Account: %s\t", tmp);
- unistr2_to_ascii(tmp, &s1->uni_full_name, sizeof(tmp)-1);
+ unistr2_to_ascii(tmp, &s1->uni_full_name, sizeof(tmp));
printf("Name: %s\t", tmp);
- unistr2_to_ascii(tmp, &s1->uni_acct_desc, sizeof(tmp)-1);
+ unistr2_to_ascii(tmp, &s1->uni_acct_desc, sizeof(tmp));
printf("Desc: %s\n", tmp);
}
printf("RID: 0x%x ", e2->rid_user);
printf("acb: 0x%x ", e2->acb_info);
- unistr2_to_ascii(tmp, &s2->uni_srv_name, sizeof(tmp)-1);
+ unistr2_to_ascii(tmp, &s2->uni_srv_name, sizeof(tmp));
printf("Account: %s\t", tmp);
- unistr2_to_ascii(tmp, &s2->uni_srv_desc, sizeof(tmp)-1);
+ unistr2_to_ascii(tmp, &s2->uni_srv_desc, sizeof(tmp));
printf("Name: %s\n", tmp);
}
printf("RID: 0x%x ", e3->rid_grp);
printf("attr: 0x%x ", e3->attr);
- unistr2_to_ascii(tmp, &s3->uni_grp_name, sizeof(tmp)-1);
+ unistr2_to_ascii(tmp, &s3->uni_grp_name, sizeof(tmp));
printf("Account: %s\t", tmp);
- unistr2_to_ascii(tmp, &s3->uni_grp_desc, sizeof(tmp)-1);
+ unistr2_to_ascii(tmp, &s3->uni_grp_desc, sizeof(tmp));
printf("Name: %s\n", tmp);
}
{
fstring temp;
- unistr2_to_ascii(temp, &info1->uni_acct_name, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &info1->uni_acct_name, sizeof(temp));
printf("\tGroup Name:\t%s\n", temp);
- unistr2_to_ascii(temp, &info1->uni_acct_desc, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &info1->uni_acct_desc, sizeof(temp));
printf("\tDescription:\t%s\n", temp);
printf("\tGroup Attribute:%d\n", info1->group_attr);
printf("\tNum Members:%d\n", info1->num_members);
{
fstring name;
- unistr2_to_ascii(name, &info2->uni_acct_name, sizeof(name)-1);
+ unistr2_to_ascii(name, &info2->uni_acct_name, sizeof(name));
printf("\tGroup Description:%s\n", name);
}
{
fstring desc;
- unistr2_to_ascii(desc, &info4->uni_acct_desc, sizeof(desc)-1);
+ unistr2_to_ascii(desc, &info4->uni_acct_desc, sizeof(desc));
printf("\tGroup Description:%s\n", desc);
}
{
fstring temp;
- unistr2_to_ascii(temp, &info5->uni_acct_name, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &info5->uni_acct_name, sizeof(temp));
printf("\tGroup Name:\t%s\n", temp);
- unistr2_to_ascii(temp, &info5->uni_acct_desc, sizeof(temp)-1);
+ unistr2_to_ascii(temp, &info5->uni_acct_desc, sizeof(temp));
printf("\tDescription:\t%s\n", temp);
printf("\tGroup Attribute:%d\n", info5->group_attr);
printf("\tNum Members:%d\n", info5->num_members);
}
}
- sid2 = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_sids);
- if (sid2 == NULL)
- return NT_STATUS_NO_MEMORY;
+ if (num_sids) {
+ sid2 = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_sids);
+ if (sid2 == NULL)
+ return NT_STATUS_NO_MEMORY;
+ } else {
+ sid2 = NULL;
+ }
for (i=0; i<num_sids; i++) {
sid_copy(&sid2[i].sid, &sids[i]);
uint32 *dom_rids;
uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
uint32 acb_mask = ACB_NORMAL;
- BOOL got_connect_pol = False, got_domain_pol = False;
+ bool got_connect_pol = False, got_domain_pol = False;
if ((argc < 1) || (argc > 3)) {
printf("Usage: %s [access_mask] [acb_mask]\n", argv[0]);
uint32 start_idx, size, num_dom_groups, i;
uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
struct acct_info *dom_groups;
- BOOL got_connect_pol = False, got_domain_pol = False;
+ bool got_connect_pol = False, got_domain_pol = False;
if ((argc < 1) || (argc > 2)) {
printf("Usage: %s [access_mask]\n", argv[0]);
uint32 start_idx, size, num_als_groups, i;
uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
struct acct_info *als_groups;
- BOOL got_connect_pol = False, got_domain_pol = False;
+ bool got_connect_pol = False, got_domain_pol = False;
if ((argc < 2) || (argc > 3)) {
printf("Usage: %s builtin|domain [access mask]\n", argv[0]);
/* Query display info */
-static NTSTATUS cmd_samr_query_dispinfo_int(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx,
- int argc, const char **argv,
- int opcode)
+static NTSTATUS cmd_samr_query_dispinfo(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, const char **argv)
{
POLICY_HND connect_pol, domain_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 start_idx=0, max_entries=250, max_size = (uint32) -1, num_entries, i;
+ uint32 start_idx=0, max_entries=250, max_size = 0xffff, num_entries, i;
uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
uint32 info_level = 1;
SAM_DISPINFO_CTR ctr;
SAM_DISPINFO_4 info4;
SAM_DISPINFO_5 info5;
int loop_count = 0;
- BOOL got_params = False; /* Use get_query_dispinfo_params() or not? */
+ bool got_params = False; /* Use get_query_dispinfo_params() or not? */
if (argc > 6) {
printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv[0]);
if (argc >= 6)
sscanf(argv[5], "%x", &access_mask);
-
/* Get sam policy handle */
result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
if (!got_params)
get_query_dispinfo_params(
loop_count, &max_entries, &max_size);
-
- switch (opcode) {
- case SAMR_QUERY_DISPINFO:
- result = rpccli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
- &start_idx, info_level,
- &num_entries, max_entries,
- max_size, &ctr);
- break;
- case SAMR_QUERY_DISPINFO2:
- result = rpccli_samr_query_dispinfo2(cli, mem_ctx, &domain_pol,
- &start_idx, info_level,
- &num_entries, max_entries,
- max_size, &ctr);
- break;
- case SAMR_QUERY_DISPINFO3:
- result = rpccli_samr_query_dispinfo3(cli, mem_ctx, &domain_pol,
- &start_idx, info_level,
- &num_entries, max_entries,
- max_size, &ctr);
- break;
- default:
- printf("unknown opcode: %d\n", opcode);
- return NT_STATUS_INVALID_PARAMETER;
- break;
- }
+
+ result = rpccli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
+ &start_idx, info_level,
+ &num_entries, max_entries,
+ max_size, &ctr);
loop_count++;
return result;
}
-static NTSTATUS cmd_samr_query_dispinfo(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx,
- int argc, const char **argv)
-{
- return cmd_samr_query_dispinfo_int(cli, mem_ctx, argc, argv, SAMR_QUERY_DISPINFO);
-}
-
-static NTSTATUS cmd_samr_query_dispinfo2(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx,
- int argc, const char **argv)
-{
- return cmd_samr_query_dispinfo_int(cli, mem_ctx, argc, argv, SAMR_QUERY_DISPINFO2);
-}
-
-static NTSTATUS cmd_samr_query_dispinfo3(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx,
- int argc, const char **argv)
-{
- return cmd_samr_query_dispinfo_int(cli, mem_ctx, argc, argv, SAMR_QUERY_DISPINFO3);
-}
-
-/* Query display info index */
-
-static NTSTATUS cmd_samr_get_dispenum_index_int(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx,
- int argc, const char **argv,
- int opcode)
-{
- POLICY_HND connect_pol, domain_pol;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
- uint16 info_level = 1;
- uint32 idx;
-
- if (argc < 2 || argc > 3) {
- printf("Usage: %s name [info level]\n", argv[0]);
- return NT_STATUS_OK;
- }
-
- if (argc >= 3) {
- sscanf(argv[2], "%hd", &info_level);
- }
-
- /* 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;
- }
-
- /* Query display info index */
-
- switch (opcode) {
- case SAMR_GET_DISPENUM_INDEX:
- result = rpccli_samr_get_dispenum_index(cli, mem_ctx, &domain_pol,
- info_level, argv[1], &idx);
- break;
- case SAMR_GET_DISPENUM_INDEX2:
- result = rpccli_samr_get_dispenum_index2(cli, mem_ctx, &domain_pol,
- info_level, argv[1], &idx);
- break;
- default:
- printf("unknown opcode\n");
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- if (NT_STATUS_IS_ERR(result)) {
- goto done;
- };
-
- printf("idx is: %d (0x%08x)\n", idx, idx);
-
- rpccli_samr_close(cli, mem_ctx, &domain_pol);
- rpccli_samr_close(cli, mem_ctx, &connect_pol);
- done:
- return result;
-}
-
-/* Query display info index */
-
-static NTSTATUS cmd_samr_get_dispenum_index(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx,
- int argc, const char **argv)
-{
- return cmd_samr_get_dispenum_index_int(cli, mem_ctx, argc, argv, SAMR_GET_DISPENUM_INDEX);
-}
-
-/* Query display info index2 */
-
-static NTSTATUS cmd_samr_get_dispenum_index2(struct rpc_pipe_client *cli,
- TALLOC_CTX *mem_ctx,
- int argc, const char **argv)
-{
- return cmd_samr_get_dispenum_index_int(cli, mem_ctx, argc, argv, SAMR_GET_DISPENUM_INDEX2);
-}
-
/* Query domain info */
static NTSTATUS cmd_samr_query_dominfo(struct rpc_pipe_client *cli,
/* Look up names */
num_names = argc - 2;
+
if ((names = TALLOC_ARRAY(mem_ctx, const char *, num_names)) == NULL) {
rpccli_samr_close(cli, mem_ctx, &domain_pol);
rpccli_samr_close(cli, mem_ctx, &connect_pol);
goto done;
}
- for (i = 0; i < argc - 2; i++)
+ for (i = 0; i < num_names; i++)
names[i] = argv[i + 2];
result = rpccli_samr_lookup_names(cli, mem_ctx, &domain_pol,
/* Look up rids */
num_rids = argc - 2;
- rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids);
+
if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
rpccli_samr_close(cli, mem_ctx, &domain_pol);
rpccli_samr_close(cli, mem_ctx, &connect_pol);
return result;
}
+/* Delete domain group */
+
+static NTSTATUS cmd_samr_delete_dom_group(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, const char **argv)
+{
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ POLICY_HND connect_pol, domain_pol, group_pol;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
+
+ if ((argc < 2) || (argc > 3)) {
+ printf("Usage: %s groupname\n", argv[0]);
+ return NT_STATUS_OK;
+ }
+
+ if (argc > 2)
+ sscanf(argv[2], "%x", &access_mask);
+
+ /* Get sam policy and domain handles */
+
+ result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
+ &connect_pol);
+
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
+
+ result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ &domain_sid, &domain_pol);
+
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
+
+ /* Get handle on group */
+
+ {
+ uint32 *group_rids, num_rids, *name_types;
+ uint32 flags = 0x000003e8; /* Unknown */
+
+ result = rpccli_samr_lookup_names(cli, mem_ctx, &domain_pol,
+ flags, 1, (const char **)&argv[1],
+ &num_rids, &group_rids,
+ &name_types);
+
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
+
+ result = rpccli_samr_open_group(cli, mem_ctx, &domain_pol,
+ access_mask,
+ group_rids[0], &group_pol);
+
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
+ }
+
+ /* Delete user */
+
+ result = rpccli_samr_delete_dom_group(cli, mem_ctx, &group_pol);
+
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
+
+ /* Display results */
+
+ rpccli_samr_close(cli, mem_ctx, &group_pol);
+ rpccli_samr_close(cli, mem_ctx, &domain_pol);
+ rpccli_samr_close(cli, mem_ctx, &connect_pol);
+
+ done:
+ return result;
+}
+
/* Delete domain user */
static NTSTATUS cmd_samr_delete_dom_user(struct rpc_pipe_client *cli,
uint32 user_rid = 0;
TALLOC_CTX *ctx = NULL;
SEC_DESC_BUF *sec_desc_buf=NULL;
- BOOL domain = False;
+ bool domain = False;
ctx=talloc_init("cmd_samr_query_sec_obj");
if ((argc < 1) || (argc > 3)) {
printf("Usage: %s [rid|-d] [sec_info]\n", argv[0]);
printf("\tSpecify rid for security on user, -d for security on domain\n");
+ talloc_destroy(ctx);
return NT_STATUS_OK;
}
{ "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", "" },
- { "querydispinfo2", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo2, NULL, PI_SAMR, NULL, "Query display info 2", "" },
- { "querydispinfo3", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo3, NULL, PI_SAMR, NULL, "Query display info 3", "" },
- { "getdispenumindex", RPC_RTYPE_NTSTATUS, cmd_samr_get_dispenum_index, NULL, PI_SAMR, NULL, "Query display info index", "" },
- { "getdispenumindex2", RPC_RTYPE_NTSTATUS, cmd_samr_get_dispenum_index2, NULL, PI_SAMR, NULL, "Query display info index", "" },
{ "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", "" },
{ "enumdomgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_groups, NULL, PI_SAMR, NULL, "Enumerate domain groups", "" },
{ "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", "" },
+ { "deletedomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_group, NULL, PI_SAMR, NULL, "Delete domain group", "" },
{ "deletedomuser", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_user, NULL, PI_SAMR, NULL, "Delete domain user", "" },
{ "samquerysecobj", RPC_RTYPE_NTSTATUS, cmd_samr_query_sec_obj, NULL, PI_SAMR, NULL, "Query SAMR security object", "" },
{ "getdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_dom_pwinfo, NULL, PI_SAMR, NULL, "Retrieve domain password info", "" },