slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
- if ((result = cli_samr_connect(cli, mem_ctx, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
- if ((result = cli_samr_connect(cli, mem_ctx, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
- if ((result = cli_samr_connect(cli, mem_ctx, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
- if ((result = cli_samr_connect(cli, mem_ctx, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
uint32 result = NT_STATUS_UNSUCCESSFUL;
BOOL got_connect_pol = False, got_domain_pol = False;
TALLOC_CTX *mem_ctx;
- fstring server;
uint32 start_idx, size, num_dom_groups, i;
struct acct_info *dom_groups;
return NT_STATUS_UNSUCCESSFUL;
}
- slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper(server);
-
/* Get sam policy handle */
- if ((result = cli_samr_connect(cli, mem_ctx, server,
- MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
uint32 result = NT_STATUS_UNSUCCESSFUL, alias_rid, num_members, i;
DOM_SID *alias_sids;
- fstring server;
-
if (argc != 2) {
printf("Usage: %s rid\n", argv[0]);
return 0;
/* Open SAMR handle */
- slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper(server);
-
- if ((result = cli_samr_connect(cli, mem_ctx, server,
- MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
uint32 result = NT_STATUS_UNSUCCESSFUL;
BOOL got_connect_pol = False, got_domain_pol = False;
TALLOC_CTX *mem_ctx;
- fstring server;
uint32 start_idx, max_entries, num_entries, i;
uint16 info_level = 1;
SAM_DISPINFO_CTR ctr;
return NT_STATUS_UNSUCCESSFUL;
}
- slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper(server);
-
/* Get sam policy handle */
- if ((result = cli_samr_connect(cli, mem_ctx, server,
- MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol))
!= NT_STATUS_NOPROBLEMO) {
goto done;
uint32 result = NT_STATUS_UNSUCCESSFUL;
BOOL got_connect_pol = False, got_domain_pol = False;
TALLOC_CTX *mem_ctx;
- fstring server;
uint16 switch_value = 2;
SAM_UNK_CTR ctr;
return NT_STATUS_UNSUCCESSFUL;
}
- slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper(server);
-
/* Get sam policy handle */
- if ((result = cli_samr_connect(cli, mem_ctx, server,
- MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol))
!= NT_STATUS_NOPROBLEMO) {
goto done;
BOOL got_connect_pol = False, got_domain_pol = False,
got_user_pol = False;
TALLOC_CTX *mem_ctx;
- fstring server;
char *acct_name;
uint16 acb_info;
uint32 unknown, user_rid;
return NT_STATUS_UNSUCCESSFUL;
}
- slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper(server);
-
/* Get sam policy handle */
- if ((result = cli_samr_connect(cli, mem_ctx, server,
- MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol))
!= NT_STATUS_NOPROBLEMO) {
goto done;
return result;
}
+/* Lookup sam names */
+
+static uint32 cmd_samr_lookup_names(struct cli_state *cli, int argc,
+ char **argv)
+{
+ TALLOC_CTX *mem_ctx;
+ uint32 result = NT_STATUS_UNSUCCESSFUL;
+ POLICY_HND connect_pol, domain_pol;
+ BOOL got_connect_pol = False, got_domain_pol = False;
+ uint32 flags = 0x000003e8;
+ uint32 num_rids, num_names, *name_types, *rids;
+ char **names;
+ int i;
+
+ if (argc < 2) {
+ printf("Usage: %s name1 [name2 [name3] [...]]\n", argv[0]);
+ return 0;
+ }
+
+ if (!(mem_ctx = talloc_init())) {
+ DEBUG(0, ("cmd_samr_lookup_names: talloc_init failed\n"));
+ return result;
+ }
+
+ fetch_domain_sid(cli);
+
+ /* Initialise RPC connection */
+
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ /* Get sam policy and domain handles */
+
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
+ &connect_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
+
+ got_connect_pol = True;
+
+ if ((result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ &domain_sid, &domain_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
+
+ got_domain_pol = True;
+
+ /* Look up names */
+
+ num_names = argc - 1;
+ names = (char **)talloc(mem_ctx, sizeof(char *) * num_names);
+
+ for (i = 0; i < argc - 1; i++)
+ names[i] = argv[i + 1];
+
+ if ((result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
+ flags, num_names, names,
+ &num_rids, &rids, &name_types))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
+
+ /* Display results */
+
+ for (i = 0; i < num_names; i++)
+ printf("name %s: %x (%d)\n", names[i], rids[i], name_types[i]);
+
+ done:
+ if (got_domain_pol) cli_samr_close(cli, mem_ctx, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, mem_ctx, &connect_pol);
+
+ cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
+
+ return result;
+}
+
+/* Lookup sam rids */
+
+static uint32 cmd_samr_lookup_rids(struct cli_state *cli, int argc,
+ char **argv)
+{
+ TALLOC_CTX *mem_ctx;
+ uint32 result = NT_STATUS_UNSUCCESSFUL;
+ POLICY_HND connect_pol, domain_pol;
+ BOOL got_connect_pol = False, got_domain_pol = False;
+ uint32 flags = 0x000003e8;
+ uint32 num_rids, num_names, *rids, *name_types;
+ char **names;
+ int i;
+
+ if (argc < 2) {
+ printf("Usage: %s rid1 [rid2 [rid3] [...]]\n", argv[0]);
+ return 0;
+ }
+
+ if (!(mem_ctx = talloc_init())) {
+ DEBUG(0, ("cmd_samr_lookup_rids: talloc_init failed\n"));
+ return result;
+ }
+
+ fetch_domain_sid(cli);
+
+ /* Initialise RPC connection */
+
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ /* Get sam policy and domain handles */
+
+ if ((result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
+ &connect_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
+
+ got_connect_pol = True;
+
+ if ((result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ &domain_sid, &domain_pol))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
+
+ got_domain_pol = True;
+
+ /* Look up rids */
+
+ num_rids = argc - 1;
+ rids = (uint32 *)talloc(mem_ctx, sizeof(uint32) * num_rids);
+
+ for (i = 0; i < argc - 1; i++)
+ rids[i] = atoi(argv[i + 1]);
+
+ if ((result = cli_samr_lookup_rids(cli, mem_ctx, &domain_pol,
+ flags, num_rids, rids,
+ &num_names, &names, &name_types))
+ != NT_STATUS_NOPROBLEMO) {
+ goto done;
+ }
+
+ /* Display results */
+
+ for (i = 0; i < num_names; i++)
+ printf("rid %x: %s (%d)\n", rids[i], names[i], name_types[i]);
+
+ done:
+ if (got_domain_pol) cli_samr_close(cli, mem_ctx, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, mem_ctx, &connect_pol);
+
+ cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
+
+ return result;
+}
+
/* List of commands exported by this module */
struct cmd_set samr_commands[] = {
{ "enumdomgroups", cmd_samr_enum_dom_groups, "Enumerate domain groups" },
{ "createdomuser", cmd_samr_create_dom_user, "Create domain user" },
+ { "samlookupnames", cmd_samr_lookup_names, "Look up names" },
+ { "samlookuprids", cmd_samr_lookup_rids, "Look up names" },
{ NULL, NULL, NULL }
};