00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "includes.h"
00026 #include "rpcclient.h"
00027
00028 extern DOM_SID domain_sid;
00029
00030
00031
00032
00033 static void display_sam_user_info_7(SAM_USER_INFO_7 *usr)
00034 {
00035 fstring temp;
00036
00037 unistr2_to_ascii(temp, &usr->uni_name, sizeof(temp)-1);
00038 printf("\tUser Name :\t%s\n", temp);
00039 }
00040
00041
00042
00043
00044 static void display_sam_user_info_9(SAM_USER_INFO_9 *usr)
00045 {
00046 printf("\tPrimary group RID :\tox%x\n", usr->rid_group);
00047 }
00048
00049
00050
00051
00052 static void display_sam_user_info_16(SAM_USER_INFO_16 *usr)
00053 {
00054 printf("\tAcct Flags :\tox%x\n", usr->acb_info);
00055 }
00056
00057
00058
00059
00060 static void display_sam_user_info_21(SAM_USER_INFO_21 *usr)
00061 {
00062 fstring temp;
00063
00064 unistr2_to_ascii(temp, &usr->uni_user_name, sizeof(temp)-1);
00065 printf("\tUser Name :\t%s\n", temp);
00066
00067 unistr2_to_ascii(temp, &usr->uni_full_name, sizeof(temp)-1);
00068 printf("\tFull Name :\t%s\n", temp);
00069
00070 unistr2_to_ascii(temp, &usr->uni_home_dir, sizeof(temp)-1);
00071 printf("\tHome Drive :\t%s\n", temp);
00072
00073 unistr2_to_ascii(temp, &usr->uni_dir_drive, sizeof(temp)-1);
00074 printf("\tDir Drive :\t%s\n", temp);
00075
00076 unistr2_to_ascii(temp, &usr->uni_profile_path, sizeof(temp)-1);
00077 printf("\tProfile Path:\t%s\n", temp);
00078
00079 unistr2_to_ascii(temp, &usr->uni_logon_script, sizeof(temp)-1);
00080 printf("\tLogon Script:\t%s\n", temp);
00081
00082 unistr2_to_ascii(temp, &usr->uni_acct_desc, sizeof(temp)-1);
00083 printf("\tDescription :\t%s\n", temp);
00084
00085 unistr2_to_ascii(temp, &usr->uni_workstations, sizeof(temp)-1);
00086 printf("\tWorkstations:\t%s\n", temp);
00087
00088 unistr2_to_ascii(temp, &usr->uni_comment, sizeof(temp)-1);
00089 printf("\tUnknown Str :\t%s\n", temp);
00090
00091 unistr2_to_ascii(temp, &usr->uni_munged_dial, sizeof(temp)-1);
00092 printf("\tRemote Dial :\t%s\n", temp);
00093
00094 printf("\tLogon Time :\t%s\n",
00095 http_timestring(nt_time_to_unix(usr->logon_time)));
00096 printf("\tLogoff Time :\t%s\n",
00097 http_timestring(nt_time_to_unix(usr->logoff_time)));
00098 printf("\tKickoff Time :\t%s\n",
00099 http_timestring(nt_time_to_unix(usr->kickoff_time)));
00100 printf("\tPassword last set Time :\t%s\n",
00101 http_timestring(nt_time_to_unix(usr->pass_last_set_time)));
00102 printf("\tPassword can change Time :\t%s\n",
00103 http_timestring(nt_time_to_unix(usr->pass_can_change_time)));
00104 printf("\tPassword must change Time:\t%s\n",
00105 http_timestring(nt_time_to_unix(usr->pass_must_change_time)));
00106
00107 printf("\tunknown_2[0..31]...\n");
00108
00109 printf("\tuser_rid :\t0x%x\n" , usr->user_rid );
00110 printf("\tgroup_rid:\t0x%x\n" , usr->group_rid);
00111 printf("\tacb_info :\t0x%08x\n", usr->acb_info );
00112
00113 printf("\tfields_present:\t0x%08x\n", usr->fields_present);
00114 printf("\tlogon_divs:\t%d\n", usr->logon_divs);
00115 printf("\tbad_password_count:\t0x%08x\n", usr->bad_password_count);
00116 printf("\tlogon_count:\t0x%08x\n", usr->logon_count);
00117
00118 printf("\tpadding1[0..7]...\n");
00119
00120 if (usr->ptr_logon_hrs) {
00121 printf("\tlogon_hrs[0..%d]...\n", usr->logon_hrs.len);
00122 }
00123 }
00124
00125
00126 static void display_password_properties(uint32 password_properties)
00127 {
00128 printf("password_properties: 0x%08x\n", password_properties);
00129
00130 if (password_properties & DOMAIN_PASSWORD_COMPLEX)
00131 printf("\tDOMAIN_PASSWORD_COMPLEX\n");
00132
00133 if (password_properties & DOMAIN_PASSWORD_NO_ANON_CHANGE)
00134 printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n");
00135
00136 if (password_properties & DOMAIN_PASSWORD_NO_CLEAR_CHANGE)
00137 printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n");
00138
00139 if (password_properties & DOMAIN_LOCKOUT_ADMINS)
00140 printf("\tDOMAIN_LOCKOUT_ADMINS\n");
00141
00142 if (password_properties & DOMAIN_PASSWORD_STORE_CLEARTEXT)
00143 printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n");
00144
00145 if (password_properties & DOMAIN_REFUSE_PASSWORD_CHANGE)
00146 printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n");
00147 }
00148
00149 static void display_sam_unk_info_1(SAM_UNK_INFO_1 *info1)
00150 {
00151
00152 printf("Minimum password length:\t\t\t%d\n", info1->min_length_password);
00153 printf("Password uniqueness (remember x passwords):\t%d\n", info1->password_history);
00154 display_password_properties(info1->password_properties);
00155 printf("password expire in:\t\t\t\t%s\n", display_time(info1->expire));
00156 printf("Min password age (allow changing in x days):\t%s\n", display_time(info1->min_passwordage));
00157 }
00158
00159 static void display_sam_unk_info_2(SAM_UNK_INFO_2 *info2)
00160 {
00161 fstring name;
00162
00163 unistr2_to_ascii(name, &info2->uni_domain, sizeof(name) - 1);
00164 printf("Domain:\t\t%s\n", name);
00165
00166 unistr2_to_ascii(name, &info2->uni_server, sizeof(name) - 1);
00167 printf("Server:\t\t%s\n", name);
00168
00169 unistr2_to_ascii(name, &info2->uni_comment, sizeof(name) - 1);
00170 printf("Comment:\t%s\n", name);
00171
00172 printf("Total Users:\t%d\n", info2->num_domain_usrs);
00173 printf("Total Groups:\t%d\n", info2->num_domain_grps);
00174 printf("Total Aliases:\t%d\n", info2->num_local_grps);
00175
00176 printf("Sequence No:\t%llu\n", (unsigned long long)info2->seq_num);
00177
00178 printf("Force Logoff:\t%d\n", (int)nt_time_to_unix_abs(&info2->logout));
00179
00180 printf("Unknown 4:\t0x%x\n", info2->unknown_4);
00181 printf("Server Role:\t%s\n", server_role_str(info2->server_role));
00182 printf("Unknown 6:\t0x%x\n", info2->unknown_6);
00183 }
00184
00185 static void display_sam_unk_info_3(SAM_UNK_INFO_3 *info3)
00186 {
00187 printf("Force Logoff:\t%d\n", (int)nt_time_to_unix_abs(&info3->logout));
00188 }
00189
00190 static void display_sam_unk_info_4(SAM_UNK_INFO_4 *info4)
00191 {
00192 fstring name;
00193
00194 unistr2_to_ascii(name, &info4->uni_comment, sizeof(name) - 1);
00195 printf("Comment:\t%s\n", name);
00196 }
00197
00198 static void display_sam_unk_info_5(SAM_UNK_INFO_5 *info5)
00199 {
00200 fstring name;
00201
00202 unistr2_to_ascii(name, &info5->uni_domain, sizeof(name) - 1);
00203 printf("Domain:\t\t%s\n", name);
00204 }
00205
00206 static void display_sam_unk_info_6(SAM_UNK_INFO_6 *info6)
00207 {
00208 fstring name;
00209
00210 unistr2_to_ascii(name, &info6->uni_server, sizeof(name) - 1);
00211 printf("Server:\t\t%s\n", name);
00212 }
00213
00214 static void display_sam_unk_info_7(SAM_UNK_INFO_7 *info7)
00215 {
00216 printf("Server Role:\t%s\n", server_role_str(info7->server_role));
00217 }
00218
00219 static void display_sam_unk_info_8(SAM_UNK_INFO_8 *info8)
00220 {
00221 printf("Sequence No:\t%llu\n", (unsigned long long)info8->seq_num);
00222 printf("Domain Create Time:\t%s\n",
00223 http_timestring(nt_time_to_unix(info8->domain_create_time)));
00224 }
00225
00226 static void display_sam_unk_info_9(SAM_UNK_INFO_9 *info9)
00227 {
00228 printf("unknown:\t%d (0x%08x)\n", info9->unknown, info9->unknown);
00229 }
00230
00231 static void display_sam_unk_info_12(SAM_UNK_INFO_12 *info12)
00232 {
00233 printf("Bad password lockout duration: %s\n", display_time(info12->duration));
00234 printf("Reset Lockout after: %s\n", display_time(info12->reset_count));
00235 printf("Lockout after bad attempts: %d\n", info12->bad_attempt_lockout);
00236 }
00237
00238 static void display_sam_unk_info_13(SAM_UNK_INFO_13 *info13)
00239 {
00240 printf("Sequence No:\t%llu\n", (unsigned long long)info13->seq_num);
00241 printf("Domain Create Time:\t%s\n",
00242 http_timestring(nt_time_to_unix(info13->domain_create_time)));
00243 printf("Unknown1:\t%d\n", info13->unknown1);
00244 printf("Unknown2:\t%d\n", info13->unknown2);
00245
00246 }
00247
00248 static void display_sam_info_1(SAM_ENTRY1 *e1, SAM_STR1 *s1)
00249 {
00250 fstring tmp;
00251
00252 printf("index: 0x%x ", e1->user_idx);
00253 printf("RID: 0x%x ", e1->rid_user);
00254 printf("acb: 0x%x ", e1->acb_info);
00255
00256 unistr2_to_ascii(tmp, &s1->uni_acct_name, sizeof(tmp)-1);
00257 printf("Account: %s\t", tmp);
00258
00259 unistr2_to_ascii(tmp, &s1->uni_full_name, sizeof(tmp)-1);
00260 printf("Name: %s\t", tmp);
00261
00262 unistr2_to_ascii(tmp, &s1->uni_acct_desc, sizeof(tmp)-1);
00263 printf("Desc: %s\n", tmp);
00264 }
00265
00266 static void display_sam_info_2(SAM_ENTRY2 *e2, SAM_STR2 *s2)
00267 {
00268 fstring tmp;
00269
00270 printf("index: 0x%x ", e2->user_idx);
00271 printf("RID: 0x%x ", e2->rid_user);
00272 printf("acb: 0x%x ", e2->acb_info);
00273
00274 unistr2_to_ascii(tmp, &s2->uni_srv_name, sizeof(tmp)-1);
00275 printf("Account: %s\t", tmp);
00276
00277 unistr2_to_ascii(tmp, &s2->uni_srv_desc, sizeof(tmp)-1);
00278 printf("Name: %s\n", tmp);
00279
00280 }
00281
00282 static void display_sam_info_3(SAM_ENTRY3 *e3, SAM_STR3 *s3)
00283 {
00284 fstring tmp;
00285
00286 printf("index: 0x%x ", e3->grp_idx);
00287 printf("RID: 0x%x ", e3->rid_grp);
00288 printf("attr: 0x%x ", e3->attr);
00289
00290 unistr2_to_ascii(tmp, &s3->uni_grp_name, sizeof(tmp)-1);
00291 printf("Account: %s\t", tmp);
00292
00293 unistr2_to_ascii(tmp, &s3->uni_grp_desc, sizeof(tmp)-1);
00294 printf("Name: %s\n", tmp);
00295
00296 }
00297
00298 static void display_sam_info_4(SAM_ENTRY4 *e4, SAM_STR4 *s4)
00299 {
00300 int i;
00301
00302 printf("index: %d ", e4->user_idx);
00303
00304 printf("Account: ");
00305 for (i=0; i<s4->acct_name.str_str_len; i++)
00306 printf("%c", s4->acct_name.buffer[i]);
00307 printf("\n");
00308
00309 }
00310
00311 static void display_sam_info_5(SAM_ENTRY5 *e5, SAM_STR5 *s5)
00312 {
00313 int i;
00314
00315 printf("index: 0x%x ", e5->grp_idx);
00316
00317 printf("Account: ");
00318 for (i=0; i<s5->grp_name.str_str_len; i++)
00319 printf("%c", s5->grp_name.buffer[i]);
00320 printf("\n");
00321
00322 }
00323
00324
00325
00326
00327 static NTSTATUS try_samr_connects(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
00328 uint32 access_mask, POLICY_HND *connect_pol)
00329 {
00330 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
00331
00332 result = rpccli_samr_connect4(cli, mem_ctx, access_mask, connect_pol);
00333 if (!NT_STATUS_IS_OK(result)) {
00334 result = rpccli_samr_connect(cli, mem_ctx, access_mask,
00335 connect_pol);
00336 }
00337 return result;
00338 }
00339
00340
00341
00342
00343 static NTSTATUS cmd_samr_query_user(struct rpc_pipe_client *cli,
00344 TALLOC_CTX *mem_ctx,
00345 int argc, const char **argv)
00346 {
00347 POLICY_HND connect_pol, domain_pol, user_pol;
00348 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
00349 uint32 info_level = 21;
00350 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
00351 SAM_USERINFO_CTR *user_ctr;
00352 fstring server;
00353 uint32 user_rid = 0;
00354
00355 if ((argc < 2) || (argc > 4)) {
00356 printf("Usage: %s rid [info level] [access mask] \n", argv[0]);
00357 return NT_STATUS_OK;
00358 }
00359
00360 sscanf(argv[1], "%i", &user_rid);
00361
00362 if (argc > 2)
00363 sscanf(argv[2], "%i", &info_level);
00364
00365 if (argc > 3)
00366 sscanf(argv[3], "%x", &access_mask);
00367
00368
00369 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
00370 strupper_m(server);
00371
00372 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
00373 &connect_pol);
00374
00375 if (!NT_STATUS_IS_OK(result))
00376 goto done;
00377
00378 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
00379 MAXIMUM_ALLOWED_ACCESS,
00380 &domain_sid, &domain_pol);
00381
00382 if (!NT_STATUS_IS_OK(result))
00383 goto done;
00384
00385 result = rpccli_samr_open_user(cli, mem_ctx, &domain_pol,
00386 access_mask,
00387 user_rid, &user_pol);
00388
00389 if (NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER) &&
00390 (user_rid == 0)) {
00391
00392
00393 uint32 num_rids;
00394 uint32 *rids, *types;
00395
00396 result = rpccli_samr_lookup_names(cli, mem_ctx, &domain_pol,
00397 1000, 1, &argv[1],
00398 &num_rids, &rids,
00399 &types);
00400
00401 if (NT_STATUS_IS_OK(result)) {
00402 result = rpccli_samr_open_user(cli, mem_ctx,
00403 &domain_pol,
00404 access_mask,
00405 rids[0], &user_pol);
00406 }
00407 }
00408
00409
00410 if (!NT_STATUS_IS_OK(result))
00411 goto done;
00412
00413 ZERO_STRUCT(user_ctr);
00414
00415 result = rpccli_samr_query_userinfo(cli, mem_ctx, &user_pol,
00416 info_level, &user_ctr);
00417
00418 if (!NT_STATUS_IS_OK(result))
00419 goto done;
00420
00421 switch (user_ctr->switch_value) {
00422 case 7:
00423 display_sam_user_info_7(user_ctr->info.id7);
00424 break;
00425 case 9:
00426 display_sam_user_info_9(user_ctr->info.id9);
00427 break;
00428 case 16:
00429 display_sam_user_info_16(user_ctr->info.id16);
00430 break;
00431 case 21:
00432 display_sam_user_info_21(user_ctr->info.id21);
00433 break;
00434 default:
00435 printf("Unsupported infolevel: %d\n", info_level);
00436 break;
00437 }
00438
00439 rpccli_samr_close(cli, mem_ctx, &user_pol);
00440 rpccli_samr_close(cli, mem_ctx, &domain_pol);
00441 rpccli_samr_close(cli, mem_ctx, &connect_pol);
00442
00443 done:
00444 return result;
00445 }
00446
00447
00448
00449
00450 static void display_group_info1(GROUP_INFO1 *info1)
00451 {
00452 fstring temp;
00453
00454 unistr2_to_ascii(temp, &info1->uni_acct_name, sizeof(temp)-1);
00455 printf("\tGroup Name:\t%s\n", temp);
00456 unistr2_to_ascii(temp, &info1->uni_acct_desc, sizeof(temp)-1);
00457 printf("\tDescription:\t%s\n", temp);
00458 printf("\tGroup Attribute:%d\n", info1->group_attr);
00459 printf("\tNum Members:%d\n", info1->num_members);
00460 }
00461
00462
00463
00464
00465 static void display_group_info2(GROUP_INFO2 *info2)
00466 {
00467 fstring name;
00468
00469 unistr2_to_ascii(name, &info2->uni_acct_name, sizeof(name)-1);
00470 printf("\tGroup Description:%s\n", name);
00471 }
00472
00473
00474
00475
00476
00477 static void display_group_info3(GROUP_INFO3 *info3)
00478 {
00479 printf("\tGroup Attribute:%d\n", info3->group_attr);
00480 }
00481
00482
00483
00484
00485
00486 static void display_group_info4(GROUP_INFO4 *info4)
00487 {
00488 fstring desc;
00489
00490 unistr2_to_ascii(desc, &info4->uni_acct_desc, sizeof(desc)-1);
00491 printf("\tGroup Description:%s\n", desc);
00492 }
00493
00494
00495
00496
00497 static void display_group_info5(GROUP_INFO5 *info5)
00498 {
00499 fstring temp;
00500
00501 unistr2_to_ascii(temp, &info5->uni_acct_name, sizeof(temp)-1);
00502 printf("\tGroup Name:\t%s\n", temp);
00503 unistr2_to_ascii(temp, &info5->uni_acct_desc, sizeof(temp)-1);
00504 printf("\tDescription:\t%s\n", temp);
00505 printf("\tGroup Attribute:%d\n", info5->group_attr);
00506 printf("\tNum Members:%d\n", info5->num_members);
00507 }
00508
00509
00510
00511
00512 static void display_group_info_ctr(GROUP_INFO_CTR *ctr)
00513 {
00514 switch (ctr->switch_value1) {
00515 case 1:
00516 display_group_info1(&ctr->group.info1);
00517 break;
00518 case 2:
00519 display_group_info2(&ctr->group.info2);
00520 break;
00521 case 3:
00522 display_group_info3(&ctr->group.info3);
00523 break;
00524 case 4:
00525 display_group_info4(&ctr->group.info4);
00526 break;
00527 case 5:
00528 display_group_info5(&ctr->group.info5);
00529 break;
00530
00531 }
00532 }
00533
00534
00535
00536
00537 static NTSTATUS cmd_samr_query_group(struct rpc_pipe_client *cli,
00538 TALLOC_CTX *mem_ctx,
00539 int argc, const char **argv)
00540 {
00541 POLICY_HND connect_pol, domain_pol, group_pol;
00542 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
00543 uint32 info_level = 1;
00544 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
00545 GROUP_INFO_CTR *group_ctr;
00546 fstring server;
00547 uint32 group_rid;
00548
00549 if ((argc < 2) || (argc > 4)) {
00550 printf("Usage: %s rid [info level] [access mask]\n", argv[0]);
00551 return NT_STATUS_OK;
00552 }
00553
00554 sscanf(argv[1], "%i", &group_rid);
00555
00556 if (argc > 2)
00557 sscanf(argv[2], "%i", &info_level);
00558
00559 if (argc > 3)
00560 sscanf(argv[3], "%x", &access_mask);
00561
00562 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
00563 strupper_m(server);
00564
00565 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
00566 &connect_pol);
00567
00568 if (!NT_STATUS_IS_OK(result))
00569 goto done;
00570
00571 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
00572 MAXIMUM_ALLOWED_ACCESS,
00573 &domain_sid, &domain_pol);
00574
00575 if (!NT_STATUS_IS_OK(result))
00576 goto done;
00577
00578 result = rpccli_samr_open_group(cli, mem_ctx, &domain_pol,
00579 access_mask,
00580 group_rid, &group_pol);
00581
00582 if (!NT_STATUS_IS_OK(result))
00583 goto done;
00584
00585 result = rpccli_samr_query_groupinfo(cli, mem_ctx, &group_pol,
00586 info_level, &group_ctr);
00587 if (!NT_STATUS_IS_OK(result)) {
00588 goto done;
00589 }
00590
00591 display_group_info_ctr(group_ctr);
00592
00593 rpccli_samr_close(cli, mem_ctx, &group_pol);
00594 rpccli_samr_close(cli, mem_ctx, &domain_pol);
00595 rpccli_samr_close(cli, mem_ctx, &connect_pol);
00596 done:
00597 return result;
00598 }
00599
00600
00601
00602 static NTSTATUS cmd_samr_query_usergroups(struct rpc_pipe_client *cli,
00603 TALLOC_CTX *mem_ctx,
00604 int argc, const char **argv)
00605 {
00606 POLICY_HND connect_pol,
00607 domain_pol,
00608 user_pol;
00609 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
00610 uint32 num_groups,
00611 user_rid;
00612 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
00613 DOM_GID *user_gids;
00614 int i;
00615 fstring server;
00616
00617 if ((argc < 2) || (argc > 3)) {
00618 printf("Usage: %s rid [access mask]\n", argv[0]);
00619 return NT_STATUS_OK;
00620 }
00621
00622 sscanf(argv[1], "%i", &user_rid);
00623
00624 if (argc > 2)
00625 sscanf(argv[2], "%x", &access_mask);
00626
00627 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
00628 strupper_m(server);
00629
00630 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
00631 &connect_pol);
00632
00633 if (!NT_STATUS_IS_OK(result))
00634 goto done;
00635
00636 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
00637 MAXIMUM_ALLOWED_ACCESS,
00638 &domain_sid, &domain_pol);
00639
00640 if (!NT_STATUS_IS_OK(result))
00641 goto done;
00642
00643 result = rpccli_samr_open_user(cli, mem_ctx, &domain_pol,
00644 access_mask,
00645 user_rid, &user_pol);
00646
00647 if (!NT_STATUS_IS_OK(result))
00648 goto done;
00649
00650 result = rpccli_samr_query_usergroups(cli, mem_ctx, &user_pol,
00651 &num_groups, &user_gids);
00652
00653 if (!NT_STATUS_IS_OK(result))
00654 goto done;
00655
00656 for (i = 0; i < num_groups; i++) {
00657 printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
00658 user_gids[i].g_rid, user_gids[i].attr);
00659 }
00660
00661 rpccli_samr_close(cli, mem_ctx, &user_pol);
00662 rpccli_samr_close(cli, mem_ctx, &domain_pol);
00663 rpccli_samr_close(cli, mem_ctx, &connect_pol);
00664 done:
00665 return result;
00666 }
00667
00668
00669
00670 static NTSTATUS cmd_samr_query_useraliases(struct rpc_pipe_client *cli,
00671 TALLOC_CTX *mem_ctx,
00672 int argc, const char **argv)
00673 {
00674 POLICY_HND connect_pol, domain_pol;
00675 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
00676 DOM_SID *sids;
00677 size_t num_sids;
00678 uint32 num_aliases, *alias_rids;
00679 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
00680 int i;
00681 fstring server;
00682 DOM_SID2 *sid2;
00683
00684 if (argc < 3) {
00685 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv[0]);
00686 return NT_STATUS_INVALID_PARAMETER;
00687 }
00688
00689 sids = NULL;
00690 num_sids = 0;
00691
00692 for (i=2; i<argc; i++) {
00693 DOM_SID tmp_sid;
00694 if (!string_to_sid(&tmp_sid, argv[i])) {
00695 printf("%s is not a legal SID\n", argv[i]);
00696 return NT_STATUS_INVALID_PARAMETER;
00697 }
00698 if (!add_sid_to_array(mem_ctx, &tmp_sid, &sids, &num_sids)) {
00699 return NT_STATUS_NO_MEMORY;
00700 }
00701 }
00702
00703 if (num_sids) {
00704 sid2 = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_sids);
00705 if (sid2 == NULL)
00706 return NT_STATUS_NO_MEMORY;
00707 } else {
00708 sid2 = NULL;
00709 }
00710
00711 for (i=0; i<num_sids; i++) {
00712 sid_copy(&sid2[i].sid, &sids[i]);
00713 sid2[i].num_auths = sid2[i].sid.num_auths;
00714 }
00715
00716 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
00717 strupper_m(server);
00718
00719 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
00720 &connect_pol);
00721
00722 if (!NT_STATUS_IS_OK(result))
00723 goto done;
00724
00725 if (StrCaseCmp(argv[1], "domain")==0)
00726 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
00727 access_mask,
00728 &domain_sid, &domain_pol);
00729 else if (StrCaseCmp(argv[1], "builtin")==0)
00730 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
00731 access_mask,
00732 &global_sid_Builtin,
00733 &domain_pol);
00734 else {
00735 printf("Usage: %s builtin|domain sid1 sid2 ...\n", argv[0]);
00736 return NT_STATUS_INVALID_PARAMETER;
00737 }
00738
00739 if (!NT_STATUS_IS_OK(result))
00740 goto done;
00741
00742 result = rpccli_samr_query_useraliases(cli, mem_ctx, &domain_pol,
00743 num_sids, sid2,
00744 &num_aliases, &alias_rids);
00745
00746 if (!NT_STATUS_IS_OK(result))
00747 goto done;
00748
00749 for (i = 0; i < num_aliases; i++) {
00750 printf("\tgroup rid:[0x%x]\n", alias_rids[i]);
00751 }
00752
00753 rpccli_samr_close(cli, mem_ctx, &domain_pol);
00754 rpccli_samr_close(cli, mem_ctx, &connect_pol);
00755 done:
00756 return result;
00757 }
00758
00759
00760
00761 static NTSTATUS cmd_samr_query_groupmem(struct rpc_pipe_client *cli,
00762 TALLOC_CTX *mem_ctx,
00763 int argc, const char **argv)
00764 {
00765 POLICY_HND connect_pol, domain_pol, group_pol;
00766 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
00767 uint32 num_members, *group_rids, *group_attrs, group_rid;
00768 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
00769 int i;
00770 fstring server;
00771 unsigned int old_timeout;
00772
00773 if ((argc < 2) || (argc > 3)) {
00774 printf("Usage: %s rid [access mask]\n", argv[0]);
00775 return NT_STATUS_OK;
00776 }
00777
00778 sscanf(argv[1], "%i", &group_rid);
00779
00780 if (argc > 2)
00781 sscanf(argv[2], "%x", &access_mask);
00782
00783 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
00784 strupper_m(server);
00785
00786 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
00787 &connect_pol);
00788
00789 if (!NT_STATUS_IS_OK(result))
00790 goto done;
00791
00792 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
00793 MAXIMUM_ALLOWED_ACCESS,
00794 &domain_sid, &domain_pol);
00795
00796 if (!NT_STATUS_IS_OK(result))
00797 goto done;
00798
00799 result = rpccli_samr_open_group(cli, mem_ctx, &domain_pol,
00800 access_mask,
00801 group_rid, &group_pol);
00802
00803 if (!NT_STATUS_IS_OK(result))
00804 goto done;
00805
00806
00807 old_timeout = cli_set_timeout(cli->cli, MAX(cli->cli->timeout,30000));
00808
00809 result = rpccli_samr_query_groupmem(cli, mem_ctx, &group_pol,
00810 &num_members, &group_rids,
00811 &group_attrs);
00812
00813 cli_set_timeout(cli->cli, old_timeout);
00814
00815 if (!NT_STATUS_IS_OK(result))
00816 goto done;
00817
00818 for (i = 0; i < num_members; i++) {
00819 printf("\trid:[0x%x] attr:[0x%x]\n", group_rids[i],
00820 group_attrs[i]);
00821 }
00822
00823 rpccli_samr_close(cli, mem_ctx, &group_pol);
00824 rpccli_samr_close(cli, mem_ctx, &domain_pol);
00825 rpccli_samr_close(cli, mem_ctx, &connect_pol);
00826 done:
00827 return result;
00828 }
00829
00830
00831
00832 static NTSTATUS cmd_samr_enum_dom_users(struct rpc_pipe_client *cli,
00833 TALLOC_CTX *mem_ctx,
00834 int argc, const char **argv)
00835 {
00836 POLICY_HND connect_pol, domain_pol;
00837 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
00838 uint32 start_idx, size, num_dom_users, i;
00839 char **dom_users;
00840 uint32 *dom_rids;
00841 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
00842 uint32 acb_mask = ACB_NORMAL;
00843 BOOL got_connect_pol = False, got_domain_pol = False;
00844
00845 if ((argc < 1) || (argc > 3)) {
00846 printf("Usage: %s [access_mask] [acb_mask]\n", argv[0]);
00847 return NT_STATUS_OK;
00848 }
00849
00850 if (argc > 1)
00851 sscanf(argv[1], "%x", &access_mask);
00852
00853 if (argc > 2)
00854 sscanf(argv[2], "%x", &acb_mask);
00855
00856
00857
00858 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
00859 &connect_pol);
00860
00861 if (!NT_STATUS_IS_OK(result))
00862 goto done;
00863
00864 got_connect_pol = True;
00865
00866
00867
00868 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
00869 access_mask,
00870 &domain_sid, &domain_pol);
00871
00872 if (!NT_STATUS_IS_OK(result))
00873 goto done;
00874
00875 got_domain_pol = True;
00876
00877
00878
00879 start_idx = 0;
00880 size = 0xffff;
00881
00882 do {
00883 result = rpccli_samr_enum_dom_users(
00884 cli, mem_ctx, &domain_pol, &start_idx, acb_mask,
00885 size, &dom_users, &dom_rids, &num_dom_users);
00886
00887 if (NT_STATUS_IS_OK(result) ||
00888 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
00889
00890 for (i = 0; i < num_dom_users; i++)
00891 printf("user:[%s] rid:[0x%x]\n",
00892 dom_users[i], dom_rids[i]);
00893 }
00894
00895 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
00896
00897 done:
00898 if (got_domain_pol)
00899 rpccli_samr_close(cli, mem_ctx, &domain_pol);
00900
00901 if (got_connect_pol)
00902 rpccli_samr_close(cli, mem_ctx, &connect_pol);
00903
00904 return result;
00905 }
00906
00907
00908
00909 static NTSTATUS cmd_samr_enum_dom_groups(struct rpc_pipe_client *cli,
00910 TALLOC_CTX *mem_ctx,
00911 int argc, const char **argv)
00912 {
00913 POLICY_HND connect_pol, domain_pol;
00914 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
00915 uint32 start_idx, size, num_dom_groups, i;
00916 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
00917 struct acct_info *dom_groups;
00918 BOOL got_connect_pol = False, got_domain_pol = False;
00919
00920 if ((argc < 1) || (argc > 2)) {
00921 printf("Usage: %s [access_mask]\n", argv[0]);
00922 return NT_STATUS_OK;
00923 }
00924
00925 if (argc > 1)
00926 sscanf(argv[1], "%x", &access_mask);
00927
00928
00929
00930 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
00931 &connect_pol);
00932
00933 if (!NT_STATUS_IS_OK(result))
00934 goto done;
00935
00936 got_connect_pol = True;
00937
00938
00939
00940 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
00941 access_mask,
00942 &domain_sid, &domain_pol);
00943
00944 if (!NT_STATUS_IS_OK(result))
00945 goto done;
00946
00947 got_domain_pol = True;
00948
00949
00950
00951 start_idx = 0;
00952 size = 0xffff;
00953
00954 do {
00955 result = rpccli_samr_enum_dom_groups(
00956 cli, mem_ctx, &domain_pol, &start_idx, size,
00957 &dom_groups, &num_dom_groups);
00958
00959 if (NT_STATUS_IS_OK(result) ||
00960 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
00961
00962 for (i = 0; i < num_dom_groups; i++)
00963 printf("group:[%s] rid:[0x%x]\n",
00964 dom_groups[i].acct_name,
00965 dom_groups[i].rid);
00966 }
00967
00968 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
00969
00970 done:
00971 if (got_domain_pol)
00972 rpccli_samr_close(cli, mem_ctx, &domain_pol);
00973
00974 if (got_connect_pol)
00975 rpccli_samr_close(cli, mem_ctx, &connect_pol);
00976
00977 return result;
00978 }
00979
00980
00981
00982 static NTSTATUS cmd_samr_enum_als_groups(struct rpc_pipe_client *cli,
00983 TALLOC_CTX *mem_ctx,
00984 int argc, const char **argv)
00985 {
00986 POLICY_HND connect_pol, domain_pol;
00987 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
00988 uint32 start_idx, size, num_als_groups, i;
00989 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
00990 struct acct_info *als_groups;
00991 BOOL got_connect_pol = False, got_domain_pol = False;
00992
00993 if ((argc < 2) || (argc > 3)) {
00994 printf("Usage: %s builtin|domain [access mask]\n", argv[0]);
00995 return NT_STATUS_OK;
00996 }
00997
00998 if (argc > 2)
00999 sscanf(argv[2], "%x", &access_mask);
01000
01001
01002
01003 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01004 &connect_pol);
01005
01006 if (!NT_STATUS_IS_OK(result))
01007 goto done;
01008
01009 got_connect_pol = True;
01010
01011
01012
01013 if (StrCaseCmp(argv[1], "domain")==0)
01014 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01015 access_mask,
01016 &domain_sid, &domain_pol);
01017 else if (StrCaseCmp(argv[1], "builtin")==0)
01018 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01019 access_mask,
01020 &global_sid_Builtin, &domain_pol);
01021 else
01022 return NT_STATUS_OK;
01023
01024 if (!NT_STATUS_IS_OK(result))
01025 goto done;
01026
01027 got_domain_pol = True;
01028
01029
01030
01031 start_idx = 0;
01032 size = 0xffff;
01033
01034 do {
01035 result = rpccli_samr_enum_als_groups(
01036 cli, mem_ctx, &domain_pol, &start_idx, size,
01037 &als_groups, &num_als_groups);
01038
01039 if (NT_STATUS_IS_OK(result) ||
01040 NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
01041
01042 for (i = 0; i < num_als_groups; i++)
01043 printf("group:[%s] rid:[0x%x]\n",
01044 als_groups[i].acct_name,
01045 als_groups[i].rid);
01046 }
01047 } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
01048
01049 done:
01050 if (got_domain_pol)
01051 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01052
01053 if (got_connect_pol)
01054 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01055
01056 return result;
01057 }
01058
01059
01060
01061 static NTSTATUS cmd_samr_query_aliasmem(struct rpc_pipe_client *cli,
01062 TALLOC_CTX *mem_ctx,
01063 int argc, const char **argv)
01064 {
01065 POLICY_HND connect_pol, domain_pol, alias_pol;
01066 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01067 uint32 alias_rid, num_members, i;
01068 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
01069 DOM_SID *alias_sids;
01070
01071 if ((argc < 3) || (argc > 4)) {
01072 printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
01073 return NT_STATUS_OK;
01074 }
01075
01076 sscanf(argv[2], "%i", &alias_rid);
01077
01078 if (argc > 3)
01079 sscanf(argv[3], "%x", &access_mask);
01080
01081
01082
01083 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01084 &connect_pol);
01085
01086 if (!NT_STATUS_IS_OK(result))
01087 goto done;
01088
01089
01090
01091 if (StrCaseCmp(argv[1], "domain")==0)
01092 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01093 MAXIMUM_ALLOWED_ACCESS,
01094 &domain_sid, &domain_pol);
01095 else if (StrCaseCmp(argv[1], "builtin")==0)
01096 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01097 MAXIMUM_ALLOWED_ACCESS,
01098 &global_sid_Builtin, &domain_pol);
01099 else
01100 return NT_STATUS_OK;
01101
01102 if (!NT_STATUS_IS_OK(result))
01103 goto done;
01104
01105
01106
01107 result = rpccli_samr_open_alias(cli, mem_ctx, &domain_pol,
01108 access_mask,
01109 alias_rid, &alias_pol);
01110 if (!NT_STATUS_IS_OK(result))
01111 goto done;
01112
01113 result = rpccli_samr_query_aliasmem(cli, mem_ctx, &alias_pol,
01114 &num_members, &alias_sids);
01115
01116 if (!NT_STATUS_IS_OK(result))
01117 goto done;
01118
01119 for (i = 0; i < num_members; i++) {
01120 fstring sid_str;
01121
01122 sid_to_string(sid_str, &alias_sids[i]);
01123 printf("\tsid:[%s]\n", sid_str);
01124 }
01125
01126 rpccli_samr_close(cli, mem_ctx, &alias_pol);
01127 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01128 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01129 done:
01130 return result;
01131 }
01132
01133
01134
01135 static NTSTATUS cmd_samr_delete_alias(struct rpc_pipe_client *cli,
01136 TALLOC_CTX *mem_ctx,
01137 int argc, const char **argv)
01138 {
01139 POLICY_HND connect_pol, domain_pol, alias_pol;
01140 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01141 uint32 alias_rid;
01142 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
01143
01144 if (argc != 3) {
01145 printf("Usage: %s builtin|domain [rid|name]\n", argv[0]);
01146 return NT_STATUS_OK;
01147 }
01148
01149 alias_rid = strtoul(argv[2], NULL, 10);
01150
01151
01152
01153 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01154 &connect_pol);
01155
01156 if (!NT_STATUS_IS_OK(result))
01157 goto done;
01158
01159
01160
01161 if (StrCaseCmp(argv[1], "domain")==0)
01162 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01163 MAXIMUM_ALLOWED_ACCESS,
01164 &domain_sid, &domain_pol);
01165 else if (StrCaseCmp(argv[1], "builtin")==0)
01166 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01167 MAXIMUM_ALLOWED_ACCESS,
01168 &global_sid_Builtin, &domain_pol);
01169 else
01170 return NT_STATUS_INVALID_PARAMETER;
01171
01172 if (!NT_STATUS_IS_OK(result))
01173 goto done;
01174
01175
01176
01177 result = rpccli_samr_open_alias(cli, mem_ctx, &domain_pol,
01178 access_mask,
01179 alias_rid, &alias_pol);
01180 if (!NT_STATUS_IS_OK(result) && (alias_rid == 0)) {
01181
01182 uint32 num_rids;
01183 uint32 *rids, *types;
01184
01185 result = rpccli_samr_lookup_names(cli, mem_ctx, &domain_pol,
01186 1000, 1, &argv[2],
01187 &num_rids, &rids,
01188 &types);
01189
01190 if (NT_STATUS_IS_OK(result)) {
01191 result = rpccli_samr_open_alias(cli, mem_ctx,
01192 &domain_pol,
01193 access_mask,
01194 rids[0], &alias_pol);
01195 }
01196 }
01197
01198 result = rpccli_samr_delete_dom_alias(cli, mem_ctx, &alias_pol);
01199
01200 if (!NT_STATUS_IS_OK(result))
01201 goto done;
01202
01203 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01204 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01205 done:
01206 return result;
01207 }
01208
01209
01210
01211 static NTSTATUS cmd_samr_query_dispinfo(struct rpc_pipe_client *cli,
01212 TALLOC_CTX *mem_ctx,
01213 int argc, const char **argv)
01214 {
01215 POLICY_HND connect_pol, domain_pol;
01216 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01217 uint32 start_idx=0, max_entries=250, max_size = 0xffff, num_entries, i;
01218 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
01219 uint32 info_level = 1;
01220 SAM_DISPINFO_CTR ctr;
01221 SAM_DISPINFO_1 info1;
01222 SAM_DISPINFO_2 info2;
01223 SAM_DISPINFO_3 info3;
01224 SAM_DISPINFO_4 info4;
01225 SAM_DISPINFO_5 info5;
01226 int loop_count = 0;
01227 BOOL got_params = False;
01228
01229 if (argc > 6) {
01230 printf("Usage: %s [info level] [start index] [max entries] [max size] [access mask]\n", argv[0]);
01231 return NT_STATUS_OK;
01232 }
01233
01234 if (argc >= 2)
01235 sscanf(argv[1], "%i", &info_level);
01236
01237 if (argc >= 3)
01238 sscanf(argv[2], "%i", &start_idx);
01239
01240 if (argc >= 4) {
01241 sscanf(argv[3], "%i", &max_entries);
01242 got_params = True;
01243 }
01244
01245 if (argc >= 5) {
01246 sscanf(argv[4], "%i", &max_size);
01247 got_params = True;
01248 }
01249
01250 if (argc >= 6)
01251 sscanf(argv[5], "%x", &access_mask);
01252
01253
01254
01255 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01256 &connect_pol);
01257
01258 if (!NT_STATUS_IS_OK(result))
01259 goto done;
01260
01261
01262
01263 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01264 access_mask,
01265 &domain_sid, &domain_pol);
01266
01267 if (!NT_STATUS_IS_OK(result))
01268 goto done;
01269
01270
01271
01272 ZERO_STRUCT(ctr);
01273 ZERO_STRUCT(info1);
01274
01275 switch (info_level) {
01276 case 1:
01277 ZERO_STRUCT(info1);
01278 ctr.sam.info1 = &info1;
01279 break;
01280 case 2:
01281 ZERO_STRUCT(info2);
01282 ctr.sam.info2 = &info2;
01283 break;
01284 case 3:
01285 ZERO_STRUCT(info3);
01286 ctr.sam.info3 = &info3;
01287 break;
01288 case 4:
01289 ZERO_STRUCT(info4);
01290 ctr.sam.info4 = &info4;
01291 break;
01292 case 5:
01293 ZERO_STRUCT(info5);
01294 ctr.sam.info5 = &info5;
01295 break;
01296 }
01297
01298
01299 do {
01300
01301 if (!got_params)
01302 get_query_dispinfo_params(
01303 loop_count, &max_entries, &max_size);
01304
01305 result = rpccli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
01306 &start_idx, info_level,
01307 &num_entries, max_entries,
01308 max_size, &ctr);
01309
01310 loop_count++;
01311
01312 if (NT_STATUS_IS_ERR(result))
01313 break;
01314
01315 if (num_entries == 0)
01316 break;
01317
01318 for (i = 0; i < num_entries; i++) {
01319 switch (info_level) {
01320 case 1:
01321 display_sam_info_1(&ctr.sam.info1->sam[i], &ctr.sam.info1->str[i]);
01322 break;
01323 case 2:
01324 display_sam_info_2(&ctr.sam.info2->sam[i], &ctr.sam.info2->str[i]);
01325 break;
01326 case 3:
01327 display_sam_info_3(&ctr.sam.info3->sam[i], &ctr.sam.info3->str[i]);
01328 break;
01329 case 4:
01330 display_sam_info_4(&ctr.sam.info4->sam[i], &ctr.sam.info4->str[i]);
01331 break;
01332 case 5:
01333 display_sam_info_5(&ctr.sam.info5->sam[i], &ctr.sam.info5->str[i]);
01334 break;
01335 }
01336 }
01337 } while ( NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
01338
01339 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01340 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01341 done:
01342 return result;
01343 }
01344
01345
01346
01347 static NTSTATUS cmd_samr_query_dominfo(struct rpc_pipe_client *cli,
01348 TALLOC_CTX *mem_ctx,
01349 int argc, const char **argv)
01350 {
01351 POLICY_HND connect_pol, domain_pol;
01352 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01353 uint32 switch_level = 2;
01354 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
01355 SAM_UNK_CTR ctr;
01356
01357 if (argc > 3) {
01358 printf("Usage: %s [info level] [access mask]\n", argv[0]);
01359 return NT_STATUS_OK;
01360 }
01361
01362 if (argc > 1)
01363 sscanf(argv[1], "%i", &switch_level);
01364
01365 if (argc > 2)
01366 sscanf(argv[2], "%x", &access_mask);
01367
01368
01369
01370 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01371 &connect_pol);
01372
01373 if (!NT_STATUS_IS_OK(result))
01374 goto done;
01375
01376
01377
01378 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01379 access_mask,
01380 &domain_sid, &domain_pol);
01381
01382 if (!NT_STATUS_IS_OK(result))
01383 goto done;
01384
01385
01386
01387 result = rpccli_samr_query_dom_info(cli, mem_ctx, &domain_pol,
01388 switch_level, &ctr);
01389
01390 if (!NT_STATUS_IS_OK(result))
01391 goto done;
01392
01393
01394
01395 switch (switch_level) {
01396 case 1:
01397 display_sam_unk_info_1(&ctr.info.inf1);
01398 break;
01399 case 2:
01400 display_sam_unk_info_2(&ctr.info.inf2);
01401 break;
01402 case 3:
01403 display_sam_unk_info_3(&ctr.info.inf3);
01404 break;
01405 case 4:
01406 display_sam_unk_info_4(&ctr.info.inf4);
01407 break;
01408 case 5:
01409 display_sam_unk_info_5(&ctr.info.inf5);
01410 break;
01411 case 6:
01412 display_sam_unk_info_6(&ctr.info.inf6);
01413 break;
01414 case 7:
01415 display_sam_unk_info_7(&ctr.info.inf7);
01416 break;
01417 case 8:
01418 display_sam_unk_info_8(&ctr.info.inf8);
01419 break;
01420 case 9:
01421 display_sam_unk_info_9(&ctr.info.inf9);
01422 break;
01423 case 12:
01424 display_sam_unk_info_12(&ctr.info.inf12);
01425 break;
01426 case 13:
01427 display_sam_unk_info_13(&ctr.info.inf13);
01428 break;
01429
01430 default:
01431 printf("cannot display domain info for switch value %d\n",
01432 switch_level);
01433 break;
01434 }
01435
01436 done:
01437
01438 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01439 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01440 return result;
01441 }
01442
01443
01444
01445 static NTSTATUS cmd_samr_create_dom_user(struct rpc_pipe_client *cli,
01446 TALLOC_CTX *mem_ctx,
01447 int argc, const char **argv)
01448 {
01449 POLICY_HND connect_pol, domain_pol, user_pol;
01450 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01451 const char *acct_name;
01452 uint32 acb_info;
01453 uint32 acct_flags, user_rid;
01454 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
01455
01456 if ((argc < 2) || (argc > 3)) {
01457 printf("Usage: %s username [access mask]\n", argv[0]);
01458 return NT_STATUS_OK;
01459 }
01460
01461 acct_name = argv[1];
01462
01463 if (argc > 2)
01464 sscanf(argv[2], "%x", &access_mask);
01465
01466
01467
01468 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01469 &connect_pol);
01470
01471 if (!NT_STATUS_IS_OK(result))
01472 goto done;
01473
01474
01475
01476 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01477 access_mask,
01478 &domain_sid, &domain_pol);
01479
01480 if (!NT_STATUS_IS_OK(result))
01481 goto done;
01482
01483
01484
01485 acb_info = ACB_NORMAL;
01486 acct_flags = SAMR_GENERIC_READ | SAMR_GENERIC_WRITE |
01487 SAMR_GENERIC_EXECUTE | SAMR_STANDARD_WRITEDAC |
01488 SAMR_STANDARD_DELETE | SAMR_USER_SETPASS | SAMR_USER_GETATTR |
01489 SAMR_USER_SETATTR;
01490 DEBUG(10, ("Creating account with flags: %d\n",acct_flags));
01491 result = rpccli_samr_create_dom_user(cli, mem_ctx, &domain_pol,
01492 acct_name, acb_info, acct_flags,
01493 &user_pol, &user_rid);
01494
01495 if (!NT_STATUS_IS_OK(result))
01496 goto done;
01497
01498 result = rpccli_samr_close(cli, mem_ctx, &user_pol);
01499 if (!NT_STATUS_IS_OK(result)) goto done;
01500
01501 result = rpccli_samr_close(cli, mem_ctx, &domain_pol);
01502 if (!NT_STATUS_IS_OK(result)) goto done;
01503
01504 result = rpccli_samr_close(cli, mem_ctx, &connect_pol);
01505 if (!NT_STATUS_IS_OK(result)) goto done;
01506
01507 done:
01508 return result;
01509 }
01510
01511
01512
01513 static NTSTATUS cmd_samr_create_dom_group(struct rpc_pipe_client *cli,
01514 TALLOC_CTX *mem_ctx,
01515 int argc, const char **argv)
01516 {
01517 POLICY_HND connect_pol, domain_pol, group_pol;
01518 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01519 const char *grp_name;
01520 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
01521
01522 if ((argc < 2) || (argc > 3)) {
01523 printf("Usage: %s groupname [access mask]\n", argv[0]);
01524 return NT_STATUS_OK;
01525 }
01526
01527 grp_name = argv[1];
01528
01529 if (argc > 2)
01530 sscanf(argv[2], "%x", &access_mask);
01531
01532
01533
01534 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01535 &connect_pol);
01536
01537 if (!NT_STATUS_IS_OK(result))
01538 goto done;
01539
01540
01541
01542 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01543 access_mask,
01544 &domain_sid, &domain_pol);
01545
01546 if (!NT_STATUS_IS_OK(result))
01547 goto done;
01548
01549
01550
01551 result = rpccli_samr_create_dom_group(cli, mem_ctx, &domain_pol,
01552 grp_name, MAXIMUM_ALLOWED_ACCESS,
01553 &group_pol);
01554
01555 if (!NT_STATUS_IS_OK(result))
01556 goto done;
01557
01558 result = rpccli_samr_close(cli, mem_ctx, &group_pol);
01559 if (!NT_STATUS_IS_OK(result)) goto done;
01560
01561 result = rpccli_samr_close(cli, mem_ctx, &domain_pol);
01562 if (!NT_STATUS_IS_OK(result)) goto done;
01563
01564 result = rpccli_samr_close(cli, mem_ctx, &connect_pol);
01565 if (!NT_STATUS_IS_OK(result)) goto done;
01566
01567 done:
01568 return result;
01569 }
01570
01571
01572
01573 static NTSTATUS cmd_samr_create_dom_alias(struct rpc_pipe_client *cli,
01574 TALLOC_CTX *mem_ctx,
01575 int argc, const char **argv)
01576 {
01577 POLICY_HND connect_pol, domain_pol, alias_pol;
01578 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01579 const char *alias_name;
01580 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
01581
01582 if ((argc < 2) || (argc > 3)) {
01583 printf("Usage: %s aliasname [access mask]\n", argv[0]);
01584 return NT_STATUS_OK;
01585 }
01586
01587 alias_name = argv[1];
01588
01589 if (argc > 2)
01590 sscanf(argv[2], "%x", &access_mask);
01591
01592
01593
01594 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01595 &connect_pol);
01596
01597 if (!NT_STATUS_IS_OK(result))
01598 goto done;
01599
01600
01601
01602 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01603 access_mask,
01604 &domain_sid, &domain_pol);
01605
01606 if (!NT_STATUS_IS_OK(result))
01607 goto done;
01608
01609
01610
01611 result = rpccli_samr_create_dom_alias(cli, mem_ctx, &domain_pol,
01612 alias_name, &alias_pol);
01613
01614 if (!NT_STATUS_IS_OK(result))
01615 goto done;
01616
01617 result = rpccli_samr_close(cli, mem_ctx, &alias_pol);
01618 if (!NT_STATUS_IS_OK(result)) goto done;
01619
01620 result = rpccli_samr_close(cli, mem_ctx, &domain_pol);
01621 if (!NT_STATUS_IS_OK(result)) goto done;
01622
01623 result = rpccli_samr_close(cli, mem_ctx, &connect_pol);
01624 if (!NT_STATUS_IS_OK(result)) goto done;
01625
01626 done:
01627 return result;
01628 }
01629
01630
01631
01632 static NTSTATUS cmd_samr_lookup_names(struct rpc_pipe_client *cli,
01633 TALLOC_CTX *mem_ctx,
01634 int argc, const char **argv)
01635 {
01636 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01637 POLICY_HND connect_pol, domain_pol;
01638 uint32 flags = 0x000003e8;
01639 uint32 num_rids, num_names, *name_types, *rids;
01640 const char **names;
01641 int i;
01642
01643 if (argc < 3) {
01644 printf("Usage: %s domain|builtin name1 [name2 [name3] [...]]\n", argv[0]);
01645 printf("check on the domain SID: S-1-5-21-x-y-z\n");
01646 printf("or check on the builtin SID: S-1-5-32\n");
01647 return NT_STATUS_OK;
01648 }
01649
01650
01651
01652 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01653 &connect_pol);
01654
01655 if (!NT_STATUS_IS_OK(result))
01656 goto done;
01657
01658 if (StrCaseCmp(argv[1], "domain")==0)
01659 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01660 MAXIMUM_ALLOWED_ACCESS,
01661 &domain_sid, &domain_pol);
01662 else if (StrCaseCmp(argv[1], "builtin")==0)
01663 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01664 MAXIMUM_ALLOWED_ACCESS,
01665 &global_sid_Builtin, &domain_pol);
01666 else
01667 return NT_STATUS_OK;
01668
01669 if (!NT_STATUS_IS_OK(result))
01670 goto done;
01671
01672
01673
01674 num_names = argc - 2;
01675 if (num_names) {
01676 if ((names = TALLOC_ARRAY(mem_ctx, const char *, num_names)) == NULL) {
01677 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01678 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01679 result = NT_STATUS_NO_MEMORY;
01680 goto done;
01681 }
01682 } else {
01683 names = NULL;
01684 }
01685
01686 for (i = 0; i < argc - 2; i++)
01687 names[i] = argv[i + 2];
01688
01689 result = rpccli_samr_lookup_names(cli, mem_ctx, &domain_pol,
01690 flags, num_names, names,
01691 &num_rids, &rids, &name_types);
01692
01693 if (!NT_STATUS_IS_OK(result))
01694 goto done;
01695
01696
01697
01698 for (i = 0; i < num_names; i++)
01699 printf("name %s: 0x%x (%d)\n", names[i], rids[i],
01700 name_types[i]);
01701
01702 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01703 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01704 done:
01705 return result;
01706 }
01707
01708
01709
01710 static NTSTATUS cmd_samr_lookup_rids(struct rpc_pipe_client *cli,
01711 TALLOC_CTX *mem_ctx,
01712 int argc, const char **argv)
01713 {
01714 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01715 POLICY_HND connect_pol, domain_pol;
01716 uint32 num_rids, num_names, *rids, *name_types;
01717 char **names;
01718 int i;
01719
01720 if (argc < 3) {
01721 printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv[0]);
01722 return NT_STATUS_OK;
01723 }
01724
01725
01726
01727 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01728 &connect_pol);
01729
01730 if (!NT_STATUS_IS_OK(result))
01731 goto done;
01732
01733 if (StrCaseCmp(argv[1], "domain")==0)
01734 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01735 MAXIMUM_ALLOWED_ACCESS,
01736 &domain_sid, &domain_pol);
01737 else if (StrCaseCmp(argv[1], "builtin")==0)
01738 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01739 MAXIMUM_ALLOWED_ACCESS,
01740 &global_sid_Builtin, &domain_pol);
01741 else
01742 return NT_STATUS_OK;
01743
01744 if (!NT_STATUS_IS_OK(result))
01745 goto done;
01746
01747
01748
01749 num_rids = argc - 2;
01750 if (num_rids) {
01751 if ((rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids)) == NULL) {
01752 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01753 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01754 result = NT_STATUS_NO_MEMORY;
01755 goto done;
01756 }
01757 } else {
01758 rids = NULL;
01759 }
01760
01761 for (i = 0; i < argc - 2; i++)
01762 sscanf(argv[i + 2], "%i", &rids[i]);
01763
01764 result = rpccli_samr_lookup_rids(cli, mem_ctx, &domain_pol, num_rids, rids,
01765 &num_names, &names, &name_types);
01766
01767 if (!NT_STATUS_IS_OK(result) &&
01768 !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED))
01769 goto done;
01770
01771
01772
01773 for (i = 0; i < num_names; i++)
01774 printf("rid 0x%x: %s (%d)\n", rids[i], names[i], name_types[i]);
01775
01776 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01777 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01778 done:
01779 return result;
01780 }
01781
01782
01783
01784 static NTSTATUS cmd_samr_delete_dom_user(struct rpc_pipe_client *cli,
01785 TALLOC_CTX *mem_ctx,
01786 int argc, const char **argv)
01787 {
01788 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01789 POLICY_HND connect_pol, domain_pol, user_pol;
01790 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
01791
01792 if ((argc < 2) || (argc > 3)) {
01793 printf("Usage: %s username\n", argv[0]);
01794 return NT_STATUS_OK;
01795 }
01796
01797 if (argc > 2)
01798 sscanf(argv[2], "%x", &access_mask);
01799
01800
01801
01802 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01803 &connect_pol);
01804
01805 if (!NT_STATUS_IS_OK(result))
01806 goto done;
01807
01808 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01809 MAXIMUM_ALLOWED_ACCESS,
01810 &domain_sid, &domain_pol);
01811
01812 if (!NT_STATUS_IS_OK(result))
01813 goto done;
01814
01815
01816
01817 {
01818 uint32 *user_rids, num_rids, *name_types;
01819 uint32 flags = 0x000003e8;
01820
01821 result = rpccli_samr_lookup_names(cli, mem_ctx, &domain_pol,
01822 flags, 1, (const char **)&argv[1],
01823 &num_rids, &user_rids,
01824 &name_types);
01825
01826 if (!NT_STATUS_IS_OK(result))
01827 goto done;
01828
01829 result = rpccli_samr_open_user(cli, mem_ctx, &domain_pol,
01830 access_mask,
01831 user_rids[0], &user_pol);
01832
01833 if (!NT_STATUS_IS_OK(result))
01834 goto done;
01835 }
01836
01837
01838
01839 result = rpccli_samr_delete_dom_user(cli, mem_ctx, &user_pol);
01840
01841 if (!NT_STATUS_IS_OK(result))
01842 goto done;
01843
01844
01845
01846 rpccli_samr_close(cli, mem_ctx, &user_pol);
01847 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01848 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01849
01850 done:
01851 return result;
01852 }
01853
01854
01855
01856
01857 static NTSTATUS cmd_samr_query_sec_obj(struct rpc_pipe_client *cli,
01858 TALLOC_CTX *mem_ctx,
01859 int argc, const char **argv)
01860 {
01861 POLICY_HND connect_pol, domain_pol, user_pol, *pol;
01862 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01863 uint32 sec_info = DACL_SECURITY_INFORMATION;
01864 fstring server;
01865 uint32 user_rid = 0;
01866 TALLOC_CTX *ctx = NULL;
01867 SEC_DESC_BUF *sec_desc_buf=NULL;
01868 BOOL domain = False;
01869
01870 ctx=talloc_init("cmd_samr_query_sec_obj");
01871
01872 if ((argc < 1) || (argc > 3)) {
01873 printf("Usage: %s [rid|-d] [sec_info]\n", argv[0]);
01874 printf("\tSpecify rid for security on user, -d for security on domain\n");
01875 talloc_destroy(ctx);
01876 return NT_STATUS_OK;
01877 }
01878
01879 if (argc > 1) {
01880 if (strcmp(argv[1], "-d") == 0)
01881 domain = True;
01882 else
01883 sscanf(argv[1], "%i", &user_rid);
01884 }
01885
01886 if (argc == 3) {
01887 sec_info = atoi(argv[2]);
01888 }
01889
01890 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
01891 strupper_m(server);
01892 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01893 &connect_pol);
01894
01895 if (!NT_STATUS_IS_OK(result))
01896 goto done;
01897
01898 if (domain || user_rid)
01899 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01900 MAXIMUM_ALLOWED_ACCESS,
01901 &domain_sid, &domain_pol);
01902
01903 if (!NT_STATUS_IS_OK(result))
01904 goto done;
01905
01906 if (user_rid)
01907 result = rpccli_samr_open_user(cli, mem_ctx, &domain_pol,
01908 MAXIMUM_ALLOWED_ACCESS,
01909 user_rid, &user_pol);
01910
01911 if (!NT_STATUS_IS_OK(result))
01912 goto done;
01913
01914
01915
01916 pol = &connect_pol;
01917
01918 if (domain)
01919 pol = &domain_pol;
01920
01921 if (user_rid)
01922 pol = &user_pol;
01923
01924
01925
01926 result = rpccli_samr_query_sec_obj(cli, mem_ctx, pol, sec_info, ctx,
01927 &sec_desc_buf);
01928
01929 if (!NT_STATUS_IS_OK(result))
01930 goto done;
01931
01932 display_sec_desc(sec_desc_buf->sec);
01933
01934 rpccli_samr_close(cli, mem_ctx, &user_pol);
01935 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01936 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01937 done:
01938 talloc_destroy(ctx);
01939 return result;
01940 }
01941
01942 static NTSTATUS cmd_samr_get_usrdom_pwinfo(struct rpc_pipe_client *cli,
01943 TALLOC_CTX *mem_ctx,
01944 int argc, const char **argv)
01945 {
01946 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
01947 POLICY_HND connect_pol, domain_pol, user_pol;
01948 uint16 min_pwd_length;
01949 uint32 password_properties, unknown1, rid;
01950
01951 if (argc != 2) {
01952 printf("Usage: %s rid\n", argv[0]);
01953 return NT_STATUS_OK;
01954 }
01955
01956 sscanf(argv[1], "%i", &rid);
01957
01958 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
01959 &connect_pol);
01960
01961 if (!NT_STATUS_IS_OK(result)) {
01962 goto done;
01963 }
01964
01965 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
01966 MAXIMUM_ALLOWED_ACCESS, &domain_sid, &domain_pol);
01967
01968 if (!NT_STATUS_IS_OK(result)) {
01969 goto done;
01970 }
01971
01972 result = rpccli_samr_open_user(cli, mem_ctx, &domain_pol,
01973 MAXIMUM_ALLOWED_ACCESS,
01974 rid, &user_pol);
01975
01976 if (!NT_STATUS_IS_OK(result)) {
01977 goto done;
01978 }
01979
01980 result = rpccli_samr_get_usrdom_pwinfo(cli, mem_ctx, &user_pol,
01981 &min_pwd_length, &password_properties,
01982 &unknown1) ;
01983
01984 if (NT_STATUS_IS_OK(result)) {
01985 printf("min_pwd_length: %d\n", min_pwd_length);
01986 printf("unknown1: %d\n", unknown1);
01987 display_password_properties(password_properties);
01988 }
01989
01990 done:
01991 rpccli_samr_close(cli, mem_ctx, &user_pol);
01992 rpccli_samr_close(cli, mem_ctx, &domain_pol);
01993 rpccli_samr_close(cli, mem_ctx, &connect_pol);
01994
01995 return result;
01996 }
01997
01998
01999 static NTSTATUS cmd_samr_get_dom_pwinfo(struct rpc_pipe_client *cli,
02000 TALLOC_CTX *mem_ctx,
02001 int argc, const char **argv)
02002 {
02003 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
02004 uint16 min_pwd_length;
02005 uint32 password_properties;
02006
02007 if (argc != 1) {
02008 printf("Usage: %s\n", argv[0]);
02009 return NT_STATUS_OK;
02010 }
02011
02012 result = rpccli_samr_get_dom_pwinfo(cli, mem_ctx, &min_pwd_length, &password_properties) ;
02013
02014 if (NT_STATUS_IS_OK(result)) {
02015 printf("min_pwd_length: %d\n", min_pwd_length);
02016 display_password_properties(password_properties);
02017 }
02018
02019 return result;
02020 }
02021
02022
02023
02024 static NTSTATUS cmd_samr_lookup_domain(struct rpc_pipe_client *cli,
02025 TALLOC_CTX *mem_ctx,
02026 int argc, const char **argv)
02027 {
02028 POLICY_HND connect_pol, domain_pol;
02029 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
02030 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
02031 fstring domain_name,sid_string;
02032 DOM_SID sid;
02033
02034 if (argc != 2) {
02035 printf("Usage: %s domain_name\n", argv[0]);
02036 return NT_STATUS_OK;
02037 }
02038
02039 sscanf(argv[1], "%s", domain_name);
02040
02041 result = try_samr_connects(cli, mem_ctx, access_mask, &connect_pol);
02042
02043 if (!NT_STATUS_IS_OK(result))
02044 goto done;
02045
02046 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
02047 access_mask, &domain_sid, &domain_pol);
02048
02049 if (!NT_STATUS_IS_OK(result))
02050 goto done;
02051
02052 result = rpccli_samr_lookup_domain(
02053 cli, mem_ctx, &connect_pol, domain_name, &sid);
02054
02055 sid_to_string(sid_string,&sid);
02056
02057 if (NT_STATUS_IS_OK(result))
02058 printf("SAMR_LOOKUP_DOMAIN: Domain Name: %s Domain SID: %s\n",
02059 domain_name,sid_string);
02060
02061 rpccli_samr_close(cli, mem_ctx, &domain_pol);
02062 rpccli_samr_close(cli, mem_ctx, &connect_pol);
02063 done:
02064 return result;
02065 }
02066
02067
02068
02069 static NTSTATUS cmd_samr_chgpasswd2(struct rpc_pipe_client *cli,
02070 TALLOC_CTX *mem_ctx,
02071 int argc, const char **argv)
02072 {
02073 POLICY_HND connect_pol, domain_pol;
02074 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
02075 const char *user, *oldpass, *newpass;
02076 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
02077
02078 if (argc < 3) {
02079 printf("Usage: %s username oldpass newpass\n", argv[0]);
02080 return NT_STATUS_INVALID_PARAMETER;
02081 }
02082
02083 user = argv[1];
02084 oldpass = argv[2];
02085 newpass = argv[3];
02086
02087
02088
02089 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
02090 &connect_pol);
02091
02092 if (!NT_STATUS_IS_OK(result))
02093 goto done;
02094
02095
02096
02097 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
02098 access_mask,
02099 &domain_sid, &domain_pol);
02100
02101 if (!NT_STATUS_IS_OK(result))
02102 goto done;
02103
02104
02105 result = rpccli_samr_chgpasswd_user(cli, mem_ctx, user, newpass, oldpass);
02106
02107 if (!NT_STATUS_IS_OK(result))
02108 goto done;
02109
02110 result = rpccli_samr_close(cli, mem_ctx, &domain_pol);
02111 if (!NT_STATUS_IS_OK(result)) goto done;
02112
02113 result = rpccli_samr_close(cli, mem_ctx, &connect_pol);
02114 if (!NT_STATUS_IS_OK(result)) goto done;
02115
02116 done:
02117 return result;
02118 }
02119
02120
02121
02122
02123 static NTSTATUS cmd_samr_chgpasswd3(struct rpc_pipe_client *cli,
02124 TALLOC_CTX *mem_ctx,
02125 int argc, const char **argv)
02126 {
02127 POLICY_HND connect_pol, domain_pol;
02128 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
02129 const char *user, *oldpass, *newpass;
02130 uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
02131 SAM_UNK_INFO_1 info;
02132 SAMR_CHANGE_REJECT reject;
02133
02134 if (argc < 3) {
02135 printf("Usage: %s username oldpass newpass\n", argv[0]);
02136 return NT_STATUS_INVALID_PARAMETER;
02137 }
02138
02139 user = argv[1];
02140 oldpass = argv[2];
02141 newpass = argv[3];
02142
02143
02144
02145 result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
02146 &connect_pol);
02147
02148 if (!NT_STATUS_IS_OK(result))
02149 goto done;
02150
02151
02152
02153 result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol,
02154 access_mask,
02155 &domain_sid, &domain_pol);
02156
02157 if (!NT_STATUS_IS_OK(result))
02158 goto done;
02159
02160
02161 result = rpccli_samr_chgpasswd3(cli, mem_ctx, user, newpass, oldpass, &info, &reject);
02162
02163 if (NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_RESTRICTION)) {
02164
02165 display_sam_unk_info_1(&info);
02166
02167 switch (reject.reject_reason) {
02168 case REJECT_REASON_TOO_SHORT:
02169 d_printf("REJECT_REASON_TOO_SHORT\n");
02170 break;
02171 case REJECT_REASON_IN_HISTORY:
02172 d_printf("REJECT_REASON_IN_HISTORY\n");
02173 break;
02174 case REJECT_REASON_NOT_COMPLEX:
02175 d_printf("REJECT_REASON_NOT_COMPLEX\n");
02176 break;
02177 case REJECT_REASON_OTHER:
02178 d_printf("REJECT_REASON_OTHER\n");
02179 break;
02180 default:
02181 d_printf("unknown reject reason: %d\n", reject.reject_reason);
02182 break;
02183 }
02184 }
02185
02186 if (!NT_STATUS_IS_OK(result))
02187 goto done;
02188
02189 result = rpccli_samr_close(cli, mem_ctx, &domain_pol);
02190 if (!NT_STATUS_IS_OK(result)) goto done;
02191
02192 result = rpccli_samr_close(cli, mem_ctx, &connect_pol);
02193 if (!NT_STATUS_IS_OK(result)) goto done;
02194
02195 done:
02196 return result;
02197 }
02198
02199
02200
02201 struct cmd_set samr_commands[] = {
02202
02203 { "SAMR" },
02204
02205 { "queryuser", RPC_RTYPE_NTSTATUS, cmd_samr_query_user, NULL, PI_SAMR, NULL, "Query user info", "" },
02206 { "querygroup", RPC_RTYPE_NTSTATUS, cmd_samr_query_group, NULL, PI_SAMR, NULL, "Query group info", "" },
02207 { "queryusergroups", RPC_RTYPE_NTSTATUS, cmd_samr_query_usergroups, NULL, PI_SAMR, NULL, "Query user groups", "" },
02208 { "queryuseraliases", RPC_RTYPE_NTSTATUS, cmd_samr_query_useraliases, NULL, PI_SAMR, NULL, "Query user aliases", "" },
02209 { "querygroupmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_groupmem, NULL, PI_SAMR, NULL, "Query group membership", "" },
02210 { "queryaliasmem", RPC_RTYPE_NTSTATUS, cmd_samr_query_aliasmem, NULL, PI_SAMR, NULL, "Query alias membership", "" },
02211 { "deletealias", RPC_RTYPE_NTSTATUS, cmd_samr_delete_alias, NULL, PI_SAMR, NULL, "Delete an alias", "" },
02212 { "querydispinfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dispinfo, NULL, PI_SAMR, NULL, "Query display info", "" },
02213 { "querydominfo", RPC_RTYPE_NTSTATUS, cmd_samr_query_dominfo, NULL, PI_SAMR, NULL, "Query domain info", "" },
02214 { "enumdomusers", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_users, NULL, PI_SAMR, NULL, "Enumerate domain users", "" },
02215 { "enumdomgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_dom_groups, NULL, PI_SAMR, NULL, "Enumerate domain groups", "" },
02216 { "enumalsgroups", RPC_RTYPE_NTSTATUS, cmd_samr_enum_als_groups, NULL, PI_SAMR, NULL, "Enumerate alias groups", "" },
02217
02218 { "createdomuser", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_user, NULL, PI_SAMR, NULL, "Create domain user", "" },
02219 { "createdomgroup", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_group, NULL, PI_SAMR, NULL, "Create domain group", "" },
02220 { "createdomalias", RPC_RTYPE_NTSTATUS, cmd_samr_create_dom_alias, NULL, PI_SAMR, NULL, "Create domain alias", "" },
02221 { "samlookupnames", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_names, NULL, PI_SAMR, NULL, "Look up names", "" },
02222 { "samlookuprids", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_rids, NULL, PI_SAMR, NULL, "Look up names", "" },
02223 { "deletedomuser", RPC_RTYPE_NTSTATUS, cmd_samr_delete_dom_user, NULL, PI_SAMR, NULL, "Delete domain user", "" },
02224 { "samquerysecobj", RPC_RTYPE_NTSTATUS, cmd_samr_query_sec_obj, NULL, PI_SAMR, NULL, "Query SAMR security object", "" },
02225 { "getdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_dom_pwinfo, NULL, PI_SAMR, NULL, "Retrieve domain password info", "" },
02226 { "getusrdompwinfo", RPC_RTYPE_NTSTATUS, cmd_samr_get_usrdom_pwinfo, NULL, PI_SAMR, NULL, "Retrieve user domain password info", "" },
02227
02228 { "lookupdomain", RPC_RTYPE_NTSTATUS, cmd_samr_lookup_domain, NULL, PI_SAMR, NULL, "Lookup Domain Name", "" },
02229 { "chgpasswd2", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd2, NULL, PI_SAMR, NULL, "Change user password", "" },
02230 { "chgpasswd3", RPC_RTYPE_NTSTATUS, cmd_samr_chgpasswd3, NULL, PI_SAMR, NULL, "Change user password", "" },
02231 { NULL }
02232 };