2 Unix SMB/CIFS implementation.
3 dump the remote SAM using rpc samsync operations
5 Copyright (C) Andrew Tridgell 2002
6 Copyright (C) Tim Potter 2001,2002
7 Modified by Volker Lendecke 2002
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "../utils/net.h"
27 extern DOM_SID global_sid_Builtin;
29 static void display_group_mem_info(uint32 rid, SAM_GROUP_MEM_INFO *g)
32 d_printf("Group mem %u: ", rid);
33 for (i=0;i<g->num_members;i++) {
34 d_printf("%u ", g->rids[i]);
39 static void display_alias_info(uint32 rid, SAM_ALIAS_INFO *a)
41 d_printf("Alias '%s' ", unistr2_static(&a->uni_als_name));
42 d_printf("desc='%s' rid=%u\n", unistr2_static(&a->uni_als_desc), a->als_rid);
45 static void display_alias_mem(uint32 rid, SAM_ALIAS_MEM_INFO *a)
48 d_printf("Alias rid %u: ", rid);
49 for (i=0;i<a->num_members;i++) {
50 d_printf("%s ", sid_string_static(&a->sids[i].sid));
55 static void display_account_info(uint32 rid, SAM_ACCOUNT_INFO *a)
57 fstring hex_nt_passwd, hex_lm_passwd;
58 uchar lm_passwd[16], nt_passwd[16];
59 static uchar zero_buf[16];
61 /* Decode hashes from password hash (if they are not NULL) */
63 if (memcmp(a->pass.buf_lm_pwd, zero_buf, 16) != 0) {
64 sam_pwd_hash(a->user_rid, a->pass.buf_lm_pwd, lm_passwd, 0);
65 smbpasswd_sethexpwd(hex_lm_passwd, lm_passwd, a->acb_info);
67 smbpasswd_sethexpwd(hex_lm_passwd, NULL, 0);
70 if (memcmp(a->pass.buf_nt_pwd, zero_buf, 16) != 0) {
71 sam_pwd_hash(a->user_rid, a->pass.buf_nt_pwd, nt_passwd, 0);
72 smbpasswd_sethexpwd(hex_nt_passwd, nt_passwd, a->acb_info);
74 smbpasswd_sethexpwd(hex_nt_passwd, NULL, 0);
77 printf("%s:%d:%s:%s:%s:LCT-0\n", unistr2_static(&a->uni_acct_name),
78 a->user_rid, hex_lm_passwd, hex_nt_passwd,
79 smbpasswd_encode_acb_info(a->acb_info));
82 static void display_domain_info(SAM_DOMAIN_INFO *a)
84 d_printf("Domain name: %s\n", unistr2_static(&a->uni_dom_name));
87 static void display_group_info(uint32 rid, SAM_GROUP_INFO *a)
89 d_printf("Group '%s' ", unistr2_static(&a->uni_grp_name));
90 d_printf("desc='%s', rid=%u\n", unistr2_static(&a->uni_grp_desc), rid);
93 static void display_sam_entry(SAM_DELTA_HDR *hdr_delta, SAM_DELTA_CTR *delta)
95 switch (hdr_delta->type) {
96 case SAM_DELTA_ACCOUNT_INFO:
97 display_account_info(hdr_delta->target_rid, &delta->account_info);
99 case SAM_DELTA_GROUP_MEM:
100 display_group_mem_info(hdr_delta->target_rid, &delta->grp_mem_info);
102 case SAM_DELTA_ALIAS_INFO:
103 display_alias_info(hdr_delta->target_rid, &delta->alias_info);
105 case SAM_DELTA_ALIAS_MEM:
106 display_alias_mem(hdr_delta->target_rid, &delta->als_mem_info);
108 case SAM_DELTA_DOMAIN_INFO:
109 display_domain_info(&delta->domain_info);
111 case SAM_DELTA_GROUP_INFO:
112 display_group_info(hdr_delta->target_rid, &delta->group_info);
114 /* The following types are recognised but not handled */
115 case SAM_DELTA_RENAME_GROUP:
116 d_printf("SAM_DELTA_RENAME_GROUP not handled\n");
118 case SAM_DELTA_RENAME_USER:
119 d_printf("SAM_DELTA_RENAME_USER not handled\n");
121 case SAM_DELTA_RENAME_ALIAS:
122 d_printf("SAM_DELTA_RENAME_ALIAS not handled\n");
124 case SAM_DELTA_POLICY_INFO:
125 d_printf("SAM_DELTA_POLICY_INFO not handled\n");
127 case SAM_DELTA_TRUST_DOMS:
128 d_printf("SAM_DELTA_TRUST_DOMS not handled\n");
130 case SAM_DELTA_PRIVS_INFO:
131 d_printf("SAM_DELTA_PRIVS_INFO not handled\n");
133 case SAM_DELTA_SECRET_INFO:
134 d_printf("SAM_DELTA_SECRET_INFO not handled\n");
136 case SAM_DELTA_DELETE_GROUP:
137 d_printf("SAM_DELTA_DELETE_GROUP not handled\n");
139 case SAM_DELTA_DELETE_USER:
140 d_printf("SAM_DELTA_DELETE_USER not handled\n");
142 case SAM_DELTA_MODIFIED_COUNT:
143 d_printf("SAM_DELTA_MODIFIED_COUNT not handled\n");
146 d_printf("Unknown delta record type %d\n", hdr_delta->type);
152 static void dump_database(struct cli_state *cli, unsigned db_type, DOM_CRED *ret_creds)
154 unsigned sync_context = 0;
158 SAM_DELTA_HDR *hdr_deltas;
159 SAM_DELTA_CTR *deltas;
162 if (!(mem_ctx = talloc_init("dump_database"))) {
167 case SAM_DATABASE_DOMAIN:
168 d_printf("Dumping DOMAIN database\n");
170 case SAM_DATABASE_BUILTIN:
171 d_printf("Dumping BUILTIN database\n");
173 case SAM_DATABASE_PRIVS:
174 d_printf("Dumping PRIVS databases\n");
177 d_printf("Dumping unknown database type %u\n", db_type );
182 result = cli_netlogon_sam_sync(cli, mem_ctx, ret_creds, db_type,
184 &num_deltas, &hdr_deltas, &deltas);
185 clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), ret_creds);
186 for (i = 0; i < num_deltas; i++) {
187 display_sam_entry(&hdr_deltas[i], &deltas[i]);
190 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
192 talloc_destroy(mem_ctx);
195 /* dump sam database via samsync rpc calls */
196 int rpc_samdump(int argc, const char **argv)
199 struct cli_state *cli = NULL;
200 uchar trust_password[16];
202 uint32 neg_flags = 0x000001ff;
205 ZERO_STRUCT(ret_creds);
207 /* Connect to remote machine */
208 if (!(cli = net_make_ipc_connection(NET_FLAGS_ANONYMOUS | NET_FLAGS_PDC))) {
212 if (!cli_nt_session_open(cli, PI_NETLOGON)) {
213 DEBUG(0,("Error connecting to NETLOGON pipe\n"));
217 if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_password, NULL)) {
218 d_printf("Could not retrieve domain trust secret\n");
222 result = cli_nt_setup_creds(cli, SEC_CHAN_BDC, trust_password, &neg_flags, 2);
223 if (!NT_STATUS_IS_OK(result)) {
224 d_printf("Failed to setup BDC creds\n");
228 dump_database(cli, SAM_DATABASE_DOMAIN, &ret_creds);
229 dump_database(cli, SAM_DATABASE_BUILTIN, &ret_creds);
230 dump_database(cli, SAM_DATABASE_PRIVS, &ret_creds);
232 cli_nt_session_close(cli);
238 cli_nt_session_close(cli);
243 /* Convert a SAM_ACCOUNT_DELTA to a SAM_ACCOUNT. */
244 #define STRING_CHANGED (old_string && !new_string) ||\
245 (!old_string && new_string) ||\
246 (old_string && new_string && (strcmp(old_string, new_string) != 0))
249 sam_account_from_delta(SAM_ACCOUNT *account, SAM_ACCOUNT_INFO *delta)
251 const char *old_string, *new_string;
252 time_t unix_time, stored_time;
253 uchar lm_passwd[16], nt_passwd[16];
254 static uchar zero_buf[16];
256 /* Username, fullname, home dir, dir drive, logon script, acct
257 desc, workstations, profile. */
259 if (delta->hdr_acct_name.buffer) {
260 old_string = pdb_get_nt_username(account);
261 new_string = unistr2_static(&delta->uni_acct_name);
263 if (STRING_CHANGED) {
264 pdb_set_nt_username(account, new_string, PDB_CHANGED);
268 /* Unix username is the same - for sanity */
269 old_string = pdb_get_username( account );
270 if (STRING_CHANGED) {
271 pdb_set_username(account, new_string, PDB_CHANGED);
275 if (delta->hdr_full_name.buffer) {
276 old_string = pdb_get_fullname(account);
277 new_string = unistr2_static(&delta->uni_full_name);
280 pdb_set_fullname(account, new_string, PDB_CHANGED);
283 if (delta->hdr_home_dir.buffer) {
284 old_string = pdb_get_homedir(account);
285 new_string = unistr2_static(&delta->uni_home_dir);
288 pdb_set_homedir(account, new_string, PDB_CHANGED);
291 if (delta->hdr_dir_drive.buffer) {
292 old_string = pdb_get_dir_drive(account);
293 new_string = unistr2_static(&delta->uni_dir_drive);
296 pdb_set_dir_drive(account, new_string, PDB_CHANGED);
299 if (delta->hdr_logon_script.buffer) {
300 old_string = pdb_get_logon_script(account);
301 new_string = unistr2_static(&delta->uni_logon_script);
304 pdb_set_logon_script(account, new_string, PDB_CHANGED);
307 if (delta->hdr_acct_desc.buffer) {
308 old_string = pdb_get_acct_desc(account);
309 new_string = unistr2_static(&delta->uni_acct_desc);
312 pdb_set_acct_desc(account, new_string, PDB_CHANGED);
315 if (delta->hdr_workstations.buffer) {
316 old_string = pdb_get_workstations(account);
317 new_string = unistr2_static(&delta->uni_workstations);
320 pdb_set_workstations(account, new_string, PDB_CHANGED);
323 if (delta->hdr_profile.buffer) {
324 old_string = pdb_get_profile_path(account);
325 new_string = unistr2_static(&delta->uni_profile);
328 pdb_set_profile_path(account, new_string, PDB_CHANGED);
331 /* User and group sid */
332 if (pdb_get_user_rid(account) != delta->user_rid)
333 pdb_set_user_sid_from_rid(account, delta->user_rid, PDB_CHANGED);
334 if (pdb_get_group_rid(account) != delta->group_rid)
335 pdb_set_group_sid_from_rid(account, delta->group_rid, PDB_CHANGED);
337 /* Logon and password information */
338 if (!nt_time_is_zero(&delta->logon_time)) {
339 unix_time = nt_time_to_unix(&delta->logon_time);
340 stored_time = pdb_get_logon_time(account);
341 if (stored_time != unix_time)
342 pdb_set_logon_time(account, unix_time, PDB_CHANGED);
345 if (!nt_time_is_zero(&delta->logoff_time)) {
346 unix_time = nt_time_to_unix(&delta->logoff_time);
347 stored_time = pdb_get_logoff_time(account);
348 if (stored_time != unix_time)
349 pdb_set_logoff_time(account, unix_time,PDB_CHANGED);
352 if (pdb_get_logon_divs(account) != delta->logon_divs)
353 pdb_set_logon_divs(account, delta->logon_divs, PDB_CHANGED);
355 /* TODO: logon hours */
356 /* TODO: bad password count */
357 /* TODO: logon count */
359 if (!nt_time_is_zero(&delta->pwd_last_set_time)) {
360 unix_time = nt_time_to_unix(&delta->pwd_last_set_time);
361 stored_time = pdb_get_pass_last_set_time(account);
362 if (stored_time != unix_time)
363 pdb_set_pass_last_set_time(account, unix_time, PDB_CHANGED);
367 /* No kickoff time in the delta? */
368 if (!nt_time_is_zero(&delta->kickoff_time)) {
369 unix_time = nt_time_to_unix(&delta->kickoff_time);
370 stored_time = pdb_get_kickoff_time(account);
371 if (stored_time != unix_time)
372 pdb_set_kickoff_time(account, unix_time, PDB_CHANGED);
376 /* Decode hashes from password hash
377 Note that win2000 may send us all zeros for the hashes if it doesn't
378 think this channel is secure enough - don't set the passwords at all
381 if (memcmp(delta->pass.buf_lm_pwd, zero_buf, 16) != 0) {
382 sam_pwd_hash(delta->user_rid, delta->pass.buf_lm_pwd, lm_passwd, 0);
383 pdb_set_lanman_passwd(account, lm_passwd, PDB_CHANGED);
386 if (memcmp(delta->pass.buf_nt_pwd, zero_buf, 16) != 0) {
387 sam_pwd_hash(delta->user_rid, delta->pass.buf_nt_pwd, nt_passwd, 0);
388 pdb_set_nt_passwd(account, nt_passwd, PDB_CHANGED);
391 /* TODO: account expiry time */
393 if (pdb_get_acct_ctrl(account) != delta->acb_info)
394 pdb_set_acct_ctrl(account, delta->acb_info, PDB_CHANGED);
396 pdb_set_domain(account, lp_workgroup(), PDB_CHANGED);
402 fetch_account_info(uint32 rid, SAM_ACCOUNT_INFO *delta)
407 SAM_ACCOUNT *sam_account=NULL;
411 BOOL try_add = False;
413 fstrcpy(account, unistr2_static(&delta->uni_acct_name));
414 d_printf("Creating account: %s\n", account);
416 if (!NT_STATUS_IS_OK(nt_ret = pdb_init_sam(&sam_account)))
419 if (!pdb_getsampwnam(sam_account, account)) {
420 /* Create appropriate user */
421 if (delta->acb_info & ACB_NORMAL) {
422 pstrcpy(add_script, lp_adduser_script());
423 } else if ( (delta->acb_info & ACB_WSTRUST) ||
424 (delta->acb_info & ACB_SVRTRUST) ||
425 (delta->acb_info & ACB_DOMTRUST) ) {
426 pstrcpy(add_script, lp_addmachine_script());
428 DEBUG(1, ("Unknown user type: %s\n",
429 smbpasswd_encode_acb_info(delta->acb_info)));
430 pdb_free_sam(&sam_account);
431 return NT_STATUS_NO_SUCH_USER;
435 all_string_sub(add_script, "%u", account,
437 add_ret = smbrun(add_script,NULL);
438 DEBUG(1,("fetch_account: Running the command `%s' "
439 "gave %d\n", add_script, add_ret));
445 sam_account_from_delta(sam_account, delta);
448 if (!pdb_add_sam_account(sam_account)) {
449 DEBUG(1, ("SAM Account for %s failed to be added to the passdb!\n",
453 if (!pdb_update_sam_account(sam_account)) {
454 DEBUG(1, ("SAM Account for %s failed to be updated in the passdb!\n",
459 sid = *pdb_get_group_sid(sam_account);
461 if (!pdb_getgrsid(&map, sid, False)) {
462 DEBUG(0, ("Primary group of %s has no mapping!\n",
463 pdb_get_username(sam_account)));
464 pdb_free_sam(&sam_account);
465 return NT_STATUS_NO_SUCH_GROUP;
468 if (!(grp = getgrgid(map.gid))) {
469 DEBUG(0, ("Could not find unix group %d for user %s (group SID=%s)\n",
470 map.gid, pdb_get_username(sam_account), sid_string_static(&sid)));
471 pdb_free_sam(&sam_account);
472 return NT_STATUS_NO_SUCH_GROUP;
475 smb_set_primary_group(grp->gr_name, pdb_get_username(sam_account));
477 pdb_free_sam(&sam_account);
482 fetch_group_info(uint32 rid, SAM_GROUP_INFO *delta)
486 struct group *grp = NULL;
492 unistr2_to_ascii(name, &delta->uni_grp_name, sizeof(name)-1);
493 unistr2_to_ascii(comment, &delta->uni_grp_desc, sizeof(comment)-1);
495 /* add the group to the mapping table */
496 sid_copy(&group_sid, get_global_sam_sid());
497 sid_append_rid(&group_sid, rid);
498 sid_to_string(sid_string, &group_sid);
500 if (pdb_getgrsid(&map, group_sid, False)) {
501 grp = getgrgid(map.gid);
509 /* No group found from mapping, find it from its name. */
510 if ((grp = getgrnam(name)) == NULL) {
511 /* No appropriate group found, create one */
512 d_printf("Creating unix group: '%s'\n", name);
513 if (smb_create_group(name, &gid) != 0)
514 return NT_STATUS_ACCESS_DENIED;
515 if ((grp = getgrgid(gid)) == NULL)
516 return NT_STATUS_ACCESS_DENIED;
520 map.gid = grp->gr_gid;
522 map.sid_name_use = SID_NAME_DOM_GRP;
523 fstrcpy(map.nt_name, name);
524 fstrcpy(map.comment, comment);
526 map.priv_set.count = 0;
527 map.priv_set.set = NULL;
530 pdb_add_group_mapping_entry(&map);
532 pdb_update_group_mapping_entry(&map);
538 fetch_group_mem_info(uint32 rid, SAM_GROUP_MEM_INFO *delta)
541 TALLOC_CTX *t = NULL;
542 char **nt_members = NULL;
548 if (delta->num_members == 0) {
552 sid_copy(&group_sid, get_global_sam_sid());
553 sid_append_rid(&group_sid, rid);
555 if (!get_domain_group_from_sid(group_sid, &map, False)) {
556 DEBUG(0, ("Could not find global group %d\n", rid));
557 return NT_STATUS_NO_SUCH_GROUP;
560 if (!(grp = getgrgid(map.gid))) {
561 DEBUG(0, ("Could not find unix group %d\n", map.gid));
562 return NT_STATUS_NO_SUCH_GROUP;
565 d_printf("Group members of %s: ", grp->gr_name);
567 if (!(t = talloc_init("fetch_group_mem_info"))) {
568 DEBUG(0, ("could not talloc_init\n"));
569 return NT_STATUS_NO_MEMORY;
572 nt_members = talloc_zero(t, sizeof(char *) * delta->num_members);
574 for (i=0; i<delta->num_members; i++) {
576 SAM_ACCOUNT *member = NULL;
579 if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam_talloc(t, &member))) {
584 sid_copy(&member_sid, get_global_sam_sid());
585 sid_append_rid(&member_sid, delta->rids[i]);
587 if (!pdb_getsampwsid(member, &member_sid)) {
588 DEBUG(1, ("Found bogus group member: %d (member_sid=%s group=%s)\n",
589 delta->rids[i], sid_string_static(&member_sid), grp->gr_name));
590 pdb_free_sam(&member);
594 if (pdb_get_group_rid(member) == rid) {
595 d_printf("%s(primary),", pdb_get_username(member));
596 pdb_free_sam(&member);
600 d_printf("%s,", pdb_get_username(member));
601 nt_members[i] = talloc_strdup(t, pdb_get_username(member));
602 pdb_free_sam(&member);
607 unix_members = grp->gr_mem;
609 while (*unix_members) {
610 BOOL is_nt_member = False;
611 for (i=0; i<delta->num_members; i++) {
612 if (nt_members[i] == NULL) {
613 /* This was a primary group */
617 if (strcmp(*unix_members, nt_members[i]) == 0) {
623 /* We look at a unix group member that is not
624 an nt group member. So, remove it. NT is
626 smb_delete_user_group(grp->gr_name, *unix_members);
631 for (i=0; i<delta->num_members; i++) {
632 BOOL is_unix_member = False;
634 if (nt_members[i] == NULL) {
635 /* This was the primary group */
639 unix_members = grp->gr_mem;
641 while (*unix_members) {
642 if (strcmp(*unix_members, nt_members[i]) == 0) {
643 is_unix_member = True;
649 if (!is_unix_member) {
650 /* We look at a nt group member that is not a
651 unix group member currently. So, add the nt
653 smb_add_user_group(grp->gr_name, nt_members[i]);
661 static NTSTATUS fetch_alias_info(uint32 rid, SAM_ALIAS_INFO *delta,
666 struct group *grp = NULL;
672 unistr2_to_ascii(name, &delta->uni_als_name, sizeof(name)-1);
673 unistr2_to_ascii(comment, &delta->uni_als_desc, sizeof(comment)-1);
675 /* Find out whether the group is already mapped */
676 sid_copy(&alias_sid, &dom_sid);
677 sid_append_rid(&alias_sid, rid);
678 sid_to_string(sid_string, &alias_sid);
680 if (pdb_getgrsid(&map, alias_sid, False)) {
681 grp = getgrgid(map.gid);
688 /* No group found from mapping, find it from its name. */
689 if ((grp = getgrnam(name)) == NULL) {
690 /* No appropriate group found, create one */
691 d_printf("Creating unix group: '%s'\n", name);
692 if (smb_create_group(name, &gid) != 0)
693 return NT_STATUS_ACCESS_DENIED;
694 if ((grp = getgrgid(gid)) == NULL)
695 return NT_STATUS_ACCESS_DENIED;
699 map.gid = grp->gr_gid;
702 if (sid_equal(&dom_sid, &global_sid_Builtin))
703 map.sid_name_use = SID_NAME_WKN_GRP;
705 map.sid_name_use = SID_NAME_ALIAS;
707 fstrcpy(map.nt_name, name);
708 fstrcpy(map.comment, comment);
710 map.priv_set.count = 0;
711 map.priv_set.set = NULL;
714 pdb_add_group_mapping_entry(&map);
716 pdb_update_group_mapping_entry(&map);
722 fetch_alias_mem(uint32 rid, SAM_ALIAS_MEM_INFO *delta, DOM_SID dom_sid)
729 fetch_sam_entry(SAM_DELTA_HDR *hdr_delta, SAM_DELTA_CTR *delta,
732 switch(hdr_delta->type) {
733 case SAM_DELTA_ACCOUNT_INFO:
734 fetch_account_info(hdr_delta->target_rid,
735 &delta->account_info);
737 case SAM_DELTA_GROUP_INFO:
738 fetch_group_info(hdr_delta->target_rid,
741 case SAM_DELTA_GROUP_MEM:
742 fetch_group_mem_info(hdr_delta->target_rid,
743 &delta->grp_mem_info);
745 case SAM_DELTA_ALIAS_INFO:
746 fetch_alias_info(hdr_delta->target_rid,
747 &delta->alias_info, dom_sid);
749 case SAM_DELTA_ALIAS_MEM:
750 fetch_alias_mem(hdr_delta->target_rid,
751 &delta->als_mem_info, dom_sid);
753 case SAM_DELTA_DOMAIN_INFO:
754 d_printf("SAMBA_DELTA_DOMAIN_INFO not handled\n");
757 d_printf("Unknown delta record type %d\n", hdr_delta->type);
763 fetch_database(struct cli_state *cli, unsigned db_type, DOM_CRED *ret_creds,
766 unsigned sync_context = 0;
770 SAM_DELTA_HDR *hdr_deltas;
771 SAM_DELTA_CTR *deltas;
774 if (!(mem_ctx = talloc_init("fetch_database"))) {
779 case SAM_DATABASE_DOMAIN:
780 d_printf("Fetching DOMAIN database\n");
782 case SAM_DATABASE_BUILTIN:
783 d_printf("Fetching BUILTIN database\n");
785 case SAM_DATABASE_PRIVS:
786 d_printf("Fetching PRIVS databases\n");
789 d_printf("Fetching unknown database type %u\n", db_type );
794 result = cli_netlogon_sam_sync(cli, mem_ctx, ret_creds,
795 db_type, sync_context,
797 &hdr_deltas, &deltas);
798 clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred),
800 for (i = 0; i < num_deltas; i++) {
801 fetch_sam_entry(&hdr_deltas[i], &deltas[i], dom_sid);
804 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
806 talloc_destroy(mem_ctx);
809 /* dump sam database via samsync rpc calls */
810 int rpc_vampire(int argc, const char **argv)
813 struct cli_state *cli = NULL;
814 uchar trust_password[16];
816 uint32 neg_flags = 0x000001ff;
819 ZERO_STRUCT(ret_creds);
821 /* Connect to remote machine */
822 if (!(cli = net_make_ipc_connection(NET_FLAGS_ANONYMOUS |
827 if (!cli_nt_session_open(cli, PI_NETLOGON)) {
828 DEBUG(0,("Error connecting to NETLOGON pipe\n"));
832 if (!secrets_fetch_trust_account_password(lp_workgroup(),
833 trust_password, NULL)) {
834 d_printf("Could not retrieve domain trust secret\n");
838 result = cli_nt_setup_creds(cli, SEC_CHAN_BDC, trust_password,
840 if (!NT_STATUS_IS_OK(result)) {
841 d_printf("Failed to setup BDC creds\n");
845 dom_sid = *get_global_sam_sid();
846 fetch_database(cli, SAM_DATABASE_DOMAIN, &ret_creds, dom_sid);
848 sid_copy(&dom_sid, &global_sid_Builtin);
849 fetch_database(cli, SAM_DATABASE_BUILTIN, &ret_creds, dom_sid);
851 /* Currently we crash on PRIVS somewhere in unmarshalling */
852 /* Dump_database(cli, SAM_DATABASE_PRIVS, &ret_creds); */
854 cli_nt_session_close(cli);
860 cli_nt_session_close(cli);