2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2000
6 Copyright (C) Guenther Deschner 2008
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "rpcclient.h"
24 #include "../libcli/auth/libcli_auth.h"
25 #include "../librpc/gen_ndr/ndr_netlogon.h"
26 #include "../librpc/gen_ndr/ndr_netlogon_c.h"
27 #include "rpc_client/cli_netlogon.h"
30 static WERROR
cmd_netlogon_logon_ctrl2(struct rpc_pipe_client
*cli
,
31 TALLOC_CTX
*mem_ctx
, int argc
,
34 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
36 const char *logon_server
= cli
->desthost
;
37 enum netr_LogonControlCode function_code
= NETLOGON_CONTROL_REDISCOVER
;
39 union netr_CONTROL_DATA_INFORMATION data
;
40 union netr_CONTROL_QUERY_INFORMATION query
;
41 const char *domain
= lp_workgroup();
42 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
44 #define fn_code_level(x, item) { x, #x, #item }
46 enum netr_LogonControlCode code
;
49 } supported_levels
[] = {
50 fn_code_level(NETLOGON_CONTROL_REDISCOVER
, domain
),
51 fn_code_level(NETLOGON_CONTROL_TC_QUERY
, domain
),
52 fn_code_level(NETLOGON_CONTROL_TRANSPORT_NOTIFY
, domain
),
53 fn_code_level(NETLOGON_CONTROL_FIND_USER
, user
),
54 fn_code_level(NETLOGON_CONTROL_CHANGE_PASSWORD
, domain
),
55 fn_code_level(NETLOGON_CONTROL_TC_VERIFY
, domain
),
56 fn_code_level(NETLOGON_CONTROL_SET_DBFLAG
, debug_level
),
60 if ((argc
> 5) || (argc
< 2)) {
61 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
62 "<level:1..4> <argument>\n", argv
[0]);
63 fprintf(stderr
, "Supported combinations:\n");
64 fprintf(stderr
, "function_code\targument\n");
65 for(i
=0; supported_levels
[i
].code
; i
++) {
66 fprintf(stderr
, "%7d\t\t%s\t(%s)\n",
67 supported_levels
[i
].code
,
68 supported_levels
[i
].argument
,
69 supported_levels
[i
].name
);
75 logon_server
= argv
[1];
79 function_code
= atoi(argv
[2]);
83 level
= atoi(argv
[3]);
90 switch (function_code
) {
91 case NETLOGON_CONTROL_REDISCOVER
:
92 case NETLOGON_CONTROL_TC_QUERY
:
93 case NETLOGON_CONTROL_CHANGE_PASSWORD
:
94 case NETLOGON_CONTROL_TRANSPORT_NOTIFY
:
95 case NETLOGON_CONTROL_TC_VERIFY
:
98 case NETLOGON_CONTROL_FIND_USER
:
101 case NETLOGON_CONTROL_SET_DBFLAG
:
102 data
.debug_level
= atoi(domain
);
107 status
= dcerpc_netr_LogonControl2(b
, mem_ctx
,
114 if (!NT_STATUS_IS_OK(status
)) {
115 return ntstatus_to_werror(status
);
118 if (!W_ERROR_IS_OK(werr
)) {
122 /* Display results */
127 static WERROR
cmd_netlogon_getanydcname(struct rpc_pipe_client
*cli
,
128 TALLOC_CTX
*mem_ctx
, int argc
,
131 const char *dcname
= NULL
;
135 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
138 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
142 /* Make sure to wait for our DC's reply */
143 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
144 rpccli_set_timeout(cli
, MAX(old_timeout
, 30000)); /* At least 30 sec */
146 status
= dcerpc_netr_GetAnyDCName(b
, mem_ctx
,
151 rpccli_set_timeout(cli
, old_timeout
);
153 if (!NT_STATUS_IS_OK(status
)) {
154 return ntstatus_to_werror(status
);
157 if (!W_ERROR_IS_OK(werr
)) {
161 /* Display results */
163 printf("%s\n", dcname
);
168 static WERROR
cmd_netlogon_getdcname(struct rpc_pipe_client
*cli
,
169 TALLOC_CTX
*mem_ctx
, int argc
,
172 const char *dcname
= NULL
;
176 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
179 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
183 /* Make sure to wait for our DC's reply */
184 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
185 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
187 status
= dcerpc_netr_GetDcName(b
, mem_ctx
,
192 rpccli_set_timeout(cli
, old_timeout
);
194 if (!NT_STATUS_IS_OK(status
)) {
195 return ntstatus_to_werror(status
);
198 if (!W_ERROR_IS_OK(werr
)) {
202 /* Display results */
204 printf("%s\n", dcname
);
209 static WERROR
cmd_netlogon_dsr_getdcname(struct rpc_pipe_client
*cli
,
210 TALLOC_CTX
*mem_ctx
, int argc
,
214 WERROR werr
= WERR_OK
;
215 uint32 flags
= DS_RETURN_DNS_NAME
;
216 const char *server_name
= cli
->desthost
;
217 const char *domain_name
;
218 struct GUID domain_guid
= GUID_zero();
219 struct GUID site_guid
= GUID_zero();
220 struct netr_DsRGetDCNameInfo
*info
= NULL
;
221 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
224 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
225 "[site_guid] [flags]\n", argv
[0]);
230 domain_name
= argv
[1];
233 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
239 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[3], &site_guid
))) {
245 sscanf(argv
[4], "%x", &flags
);
247 result
= dcerpc_netr_DsRGetDCName(b
, mem_ctx
,
255 if (!NT_STATUS_IS_OK(result
)) {
256 return ntstatus_to_werror(result
);
259 if (W_ERROR_IS_OK(werr
)) {
260 d_printf("DsGetDcName gave: %s\n",
261 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
265 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
271 static WERROR
cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client
*cli
,
272 TALLOC_CTX
*mem_ctx
, int argc
,
277 uint32_t flags
= DS_RETURN_DNS_NAME
;
278 const char *server_name
= cli
->desthost
;
279 const char *domain_name
;
280 const char *site_name
= NULL
;
281 struct GUID domain_guid
= GUID_zero();
282 struct netr_DsRGetDCNameInfo
*info
= NULL
;
283 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
286 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
287 "[site_name] [flags]\n", argv
[0]);
291 domain_name
= argv
[1];
294 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
304 sscanf(argv
[4], "%x", &flags
);
307 status
= dcerpc_netr_DsRGetDCNameEx(b
, mem_ctx
,
315 if (!NT_STATUS_IS_OK(status
)) {
316 return ntstatus_to_werror(status
);
319 if (!W_ERROR_IS_OK(result
)) {
323 d_printf("DsRGetDCNameEx gave %s\n",
324 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
329 static WERROR
cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client
*cli
,
330 TALLOC_CTX
*mem_ctx
, int argc
,
335 uint32_t flags
= DS_RETURN_DNS_NAME
;
336 const char *server_name
= cli
->desthost
;
337 const char *domain_name
= NULL
;
338 const char *client_account
= NULL
;
340 const char *site_name
= NULL
;
341 struct GUID domain_guid
= GUID_zero();
342 struct netr_DsRGetDCNameInfo
*info
= NULL
;
343 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
346 fprintf(stderr
, "Usage: %s [client_account] [acb_mask] "
347 "[domain_name] [domain_guid] [site_name] "
348 "[flags]\n", argv
[0]);
353 client_account
= argv
[1];
357 mask
= atoi(argv
[2]);
361 domain_name
= argv
[3];
365 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[4], &domain_guid
))) {
375 sscanf(argv
[6], "%x", &flags
);
378 status
= dcerpc_netr_DsRGetDCNameEx2(b
, mem_ctx
,
388 if (!NT_STATUS_IS_OK(status
)) {
389 return ntstatus_to_werror(status
);
392 if (!W_ERROR_IS_OK(result
)) {
396 d_printf("DsRGetDCNameEx2 gave %s\n",
397 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
403 static WERROR
cmd_netlogon_dsr_getsitename(struct rpc_pipe_client
*cli
,
404 TALLOC_CTX
*mem_ctx
, int argc
,
409 const char *sitename
= NULL
;
410 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
413 fprintf(stderr
, "Usage: %s computername\n", argv
[0]);
417 status
= dcerpc_netr_DsRGetSiteName(b
, mem_ctx
,
421 if (!NT_STATUS_IS_OK(status
)) {
422 return ntstatus_to_werror(status
);
425 if (!W_ERROR_IS_OK(werr
)) {
426 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
427 nt_errstr(werror_to_ntstatus(werr
)));
431 printf("Computer %s is on Site: %s\n", argv
[1], sitename
);
436 static WERROR
cmd_netlogon_logon_ctrl(struct rpc_pipe_client
*cli
,
437 TALLOC_CTX
*mem_ctx
, int argc
,
440 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
442 const char *logon_server
= cli
->desthost
;
443 enum netr_LogonControlCode function_code
= 1;
445 union netr_CONTROL_QUERY_INFORMATION info
;
446 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
449 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
450 "<level>\n", argv
[0]);
455 logon_server
= argv
[1];
459 function_code
= atoi(argv
[2]);
463 level
= atoi(argv
[3]);
466 status
= dcerpc_netr_LogonControl(b
, mem_ctx
,
472 if (!NT_STATUS_IS_OK(status
)) {
473 return ntstatus_to_werror(status
);
476 if (!W_ERROR_IS_OK(werr
)) {
480 /* Display results */
485 /* Display sam synchronisation information */
487 static void display_sam_sync(struct netr_DELTA_ENUM_ARRAY
*r
)
491 for (i
=0; i
< r
->num_deltas
; i
++) {
493 union netr_DELTA_UNION u
= r
->delta_enum
[i
].delta_union
;
494 union netr_DELTA_ID_UNION id
= r
->delta_enum
[i
].delta_id_union
;
496 switch (r
->delta_enum
[i
].delta_type
) {
497 case NETR_DELTA_DOMAIN
:
498 printf("Domain: %s\n",
499 u
.domain
->domain_name
.string
);
501 case NETR_DELTA_GROUP
:
502 printf("Group: %s\n",
503 u
.group
->group_name
.string
);
505 case NETR_DELTA_DELETE_GROUP
:
506 printf("Delete Group: %d\n",
509 case NETR_DELTA_RENAME_GROUP
:
510 printf("Rename Group: %s -> %s\n",
511 u
.rename_group
->OldName
.string
,
512 u
.rename_group
->NewName
.string
);
514 case NETR_DELTA_USER
:
515 printf("Account: %s\n",
516 u
.user
->account_name
.string
);
518 case NETR_DELTA_DELETE_USER
:
519 printf("Delete User: %d\n",
522 case NETR_DELTA_RENAME_USER
:
523 printf("Rename user: %s -> %s\n",
524 u
.rename_user
->OldName
.string
,
525 u
.rename_user
->NewName
.string
);
527 case NETR_DELTA_GROUP_MEMBER
:
528 for (j
=0; j
< u
.group_member
->num_rids
; j
++) {
529 printf("rid 0x%x, attrib 0x%08x\n",
530 u
.group_member
->rids
[j
],
531 u
.group_member
->attribs
[j
]);
534 case NETR_DELTA_ALIAS
:
535 printf("Alias: %s\n",
536 u
.alias
->alias_name
.string
);
538 case NETR_DELTA_DELETE_ALIAS
:
539 printf("Delete Alias: %d\n",
542 case NETR_DELTA_RENAME_ALIAS
:
543 printf("Rename alias: %s -> %s\n",
544 u
.rename_alias
->OldName
.string
,
545 u
.rename_alias
->NewName
.string
);
547 case NETR_DELTA_ALIAS_MEMBER
:
548 for (j
=0; j
< u
.alias_member
->sids
.num_sids
; j
++) {
550 sid_to_fstring(sid_str
,
551 u
.alias_member
->sids
.sids
[j
].sid
);
552 printf("%s\n", sid_str
);
555 case NETR_DELTA_POLICY
:
556 printf("Policy: %s\n",
557 sid_string_dbg(id
.sid
));
559 case NETR_DELTA_TRUSTED_DOMAIN
:
560 printf("Trusted Domain: %s\n",
561 u
.trusted_domain
->domain_name
.string
);
563 case NETR_DELTA_DELETE_TRUST
:
564 printf("Delete Trust: %s\n",
565 sid_string_dbg(id
.sid
));
567 case NETR_DELTA_ACCOUNT
:
568 printf("Account: %s\n",
569 sid_string_dbg(id
.sid
));
571 case NETR_DELTA_DELETE_ACCOUNT
:
572 printf("Delete Account: %s\n",
573 sid_string_dbg(id
.sid
));
575 case NETR_DELTA_SECRET
:
576 printf("Secret: %s\n",
579 case NETR_DELTA_DELETE_SECRET
:
580 printf("Delete Secret: %s\n",
583 case NETR_DELTA_DELETE_GROUP2
:
584 printf("Delete Group2: %s\n",
585 u
.delete_group
->account_name
);
587 case NETR_DELTA_DELETE_USER2
:
588 printf("Delete User2: %s\n",
589 u
.delete_user
->account_name
);
591 case NETR_DELTA_MODIFY_COUNT
:
592 printf("sam sequence update: 0x%016llx\n",
593 (unsigned long long) *u
.modified_count
);
596 printf("unknown delta type 0x%02x\n",
597 r
->delta_enum
[i
].delta_type
);
603 /* Perform sam synchronisation */
605 static NTSTATUS
cmd_netlogon_sam_sync(struct rpc_pipe_client
*cli
,
606 TALLOC_CTX
*mem_ctx
, int argc
,
609 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
611 const char *logon_server
= cli
->desthost
;
612 const char *computername
= lp_netbios_name();
613 struct netr_Authenticator credential
;
614 struct netr_Authenticator return_authenticator
;
615 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
616 uint16_t restart_state
= 0;
617 uint32_t sync_context
= 0;
618 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
621 fprintf(stderr
, "Usage: %s [database_id]\n", argv
[0]);
626 database_id
= atoi(argv
[1]);
629 /* Synchronise sam database */
632 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
634 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
636 status
= dcerpc_netr_DatabaseSync2(b
, mem_ctx
,
640 &return_authenticator
,
647 if (!NT_STATUS_IS_OK(status
)) {
651 /* Check returned credentials. */
652 if (!netlogon_creds_client_check(cli
->dc
,
653 &return_authenticator
.cred
)) {
654 DEBUG(0,("credentials chain check failed\n"));
655 return NT_STATUS_ACCESS_DENIED
;
658 if (NT_STATUS_IS_ERR(result
)) {
662 /* Display results */
664 display_sam_sync(delta_enum_array
);
666 TALLOC_FREE(delta_enum_array
);
668 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
673 /* Perform sam delta synchronisation */
675 static NTSTATUS
cmd_netlogon_sam_deltas(struct rpc_pipe_client
*cli
,
676 TALLOC_CTX
*mem_ctx
, int argc
,
679 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
682 const char *logon_server
= cli
->desthost
;
683 const char *computername
= lp_netbios_name();
684 struct netr_Authenticator credential
;
685 struct netr_Authenticator return_authenticator
;
686 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
687 uint64_t sequence_num
;
688 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
691 fprintf(stderr
, "Usage: %s database_id seqnum\n", argv
[0]);
695 database_id
= atoi(argv
[1]);
698 sequence_num
= tmp
& 0xffff;
701 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
703 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
705 status
= dcerpc_netr_DatabaseDeltas(b
, mem_ctx
,
709 &return_authenticator
,
715 if (!NT_STATUS_IS_OK(status
)) {
719 /* Check returned credentials. */
720 if (!netlogon_creds_client_check(cli
->dc
,
721 &return_authenticator
.cred
)) {
722 DEBUG(0,("credentials chain check failed\n"));
723 return NT_STATUS_ACCESS_DENIED
;
726 if (NT_STATUS_IS_ERR(result
)) {
730 /* Display results */
732 display_sam_sync(delta_enum_array
);
734 TALLOC_FREE(delta_enum_array
);
736 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
741 /* Log on a domain user */
743 static NTSTATUS
cmd_netlogon_sam_logon(struct rpc_pipe_client
*cli
,
744 TALLOC_CTX
*mem_ctx
, int argc
,
747 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
748 int logon_type
= NetlogonNetworkInformation
;
749 const char *username
, *password
;
750 uint16_t validation_level
= 3;
751 uint32 logon_param
= 0;
752 const char *workstation
= NULL
;
754 /* Check arguments */
756 if (argc
< 3 || argc
> 7) {
757 fprintf(stderr
, "Usage: samlogon <username> <password> [workstation]"
758 "[logon_type (1 or 2)] [auth level (2 or 3)] [logon_parameter]\n");
766 workstation
= argv
[3];
769 sscanf(argv
[4], "%i", &logon_type
);
772 validation_level
= atoi(argv
[5]);
775 sscanf(argv
[6], "%x", &logon_param
);
777 /* Perform the sam logon */
779 result
= rpccli_netlogon_sam_logon(cli
, mem_ctx
, logon_param
, lp_workgroup(), username
, password
, workstation
, validation_level
, logon_type
);
781 if (!NT_STATUS_IS_OK(result
))
788 /* Change the trust account password */
790 static NTSTATUS
cmd_netlogon_change_trust_pw(struct rpc_pipe_client
*cli
,
791 TALLOC_CTX
*mem_ctx
, int argc
,
794 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
796 /* Check arguments */
799 fprintf(stderr
, "Usage: change_trust_pw");
803 /* Perform the sam logon */
805 result
= trust_pw_find_change_and_store_it(cli
, mem_ctx
,
808 if (!NT_STATUS_IS_OK(result
))
815 static WERROR
cmd_netlogon_gettrustrid(struct rpc_pipe_client
*cli
,
816 TALLOC_CTX
*mem_ctx
, int argc
,
819 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
820 WERROR werr
= WERR_GENERAL_FAILURE
;
821 const char *server_name
= cli
->desthost
;
822 const char *domain_name
= lp_workgroup();
824 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
826 if (argc
< 1 || argc
> 3) {
827 fprintf(stderr
, "Usage: %s <server_name> <domain_name>\n",
833 server_name
= argv
[1];
837 domain_name
= argv
[2];
840 status
= dcerpc_netr_LogonGetTrustRid(b
, mem_ctx
,
845 if (!NT_STATUS_IS_OK(status
)) {
846 werr
= ntstatus_to_werror(status
);
850 if (W_ERROR_IS_OK(werr
)) {
851 printf("Rid: %d\n", rid
);
857 static WERROR
cmd_netlogon_dsr_enumtrustdom(struct rpc_pipe_client
*cli
,
858 TALLOC_CTX
*mem_ctx
, int argc
,
861 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
862 WERROR werr
= WERR_GENERAL_FAILURE
;
863 const char *server_name
= cli
->desthost
;
864 uint32_t trust_flags
= NETR_TRUST_FLAG_IN_FOREST
;
865 struct netr_DomainTrustList trusts
;
866 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
868 if (argc
< 1 || argc
> 3) {
869 fprintf(stderr
, "Usage: %s <server_name> <trust_flags>\n",
875 server_name
= argv
[1];
879 sscanf(argv
[2], "%x", &trust_flags
);
882 status
= dcerpc_netr_DsrEnumerateDomainTrusts(b
, mem_ctx
,
887 if (!NT_STATUS_IS_OK(status
)) {
888 werr
= ntstatus_to_werror(status
);
892 if (W_ERROR_IS_OK(werr
)) {
895 printf("%d domains returned\n", trusts
.count
);
897 for (i
=0; i
<trusts
.count
; i
++ ) {
899 trusts
.array
[i
].dns_name
,
900 trusts
.array
[i
].netbios_name
);
907 static WERROR
cmd_netlogon_deregisterdnsrecords(struct rpc_pipe_client
*cli
,
908 TALLOC_CTX
*mem_ctx
, int argc
,
911 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
912 WERROR werr
= WERR_GENERAL_FAILURE
;
913 const char *server_name
= cli
->desthost
;
914 const char *domain
= lp_workgroup();
915 const char *dns_host
= NULL
;
916 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
918 if (argc
< 1 || argc
> 4) {
919 fprintf(stderr
, "Usage: %s <server_name> <domain_name> "
920 "<dns_host>\n", argv
[0]);
925 server_name
= argv
[1];
936 status
= dcerpc_netr_DsrDeregisterDNSHostRecords(b
, mem_ctx
,
943 if (!NT_STATUS_IS_OK(status
)) {
944 werr
= ntstatus_to_werror(status
);
948 if (W_ERROR_IS_OK(werr
)) {
955 static WERROR
cmd_netlogon_dsr_getforesttrustinfo(struct rpc_pipe_client
*cli
,
956 TALLOC_CTX
*mem_ctx
, int argc
,
959 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
960 WERROR werr
= WERR_GENERAL_FAILURE
;
961 const char *server_name
= cli
->desthost
;
962 const char *trusted_domain_name
= NULL
;
963 struct lsa_ForestTrustInformation
*info
= NULL
;
965 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
967 if (argc
< 1 || argc
> 4) {
968 fprintf(stderr
, "Usage: %s <server_name> <trusted_domain_name> "
969 "<flags>\n", argv
[0]);
974 server_name
= argv
[1];
978 trusted_domain_name
= argv
[2];
982 sscanf(argv
[3], "%x", &flags
);
985 status
= dcerpc_netr_DsRGetForestTrustInformation(b
, mem_ctx
,
991 if (!NT_STATUS_IS_OK(status
)) {
992 werr
= ntstatus_to_werror(status
);
996 if (W_ERROR_IS_OK(werr
)) {
1003 static NTSTATUS
cmd_netlogon_enumtrusteddomains(struct rpc_pipe_client
*cli
,
1004 TALLOC_CTX
*mem_ctx
, int argc
,
1007 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1009 const char *server_name
= cli
->desthost
;
1010 struct netr_Blob blob
;
1011 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1014 if (argc
< 1 || argc
> 3) {
1015 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1016 return NT_STATUS_OK
;
1020 server_name
= argv
[1];
1023 status
= dcerpc_netr_NetrEnumerateTrustedDomains(b
, mem_ctx
,
1027 if (!NT_STATUS_IS_OK(status
)) {
1031 if (!NT_STATUS_IS_OK(result
)) {
1036 printf("success\n");
1037 dump_data(1, blob
.data
, blob
.length
);
1042 static WERROR
cmd_netlogon_enumtrusteddomainsex(struct rpc_pipe_client
*cli
,
1043 TALLOC_CTX
*mem_ctx
, int argc
,
1046 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1047 WERROR werr
= WERR_GENERAL_FAILURE
;
1048 const char *server_name
= cli
->desthost
;
1049 struct netr_DomainTrustList list
;
1050 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1052 if (argc
< 1 || argc
> 3) {
1053 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1058 server_name
= argv
[1];
1061 status
= dcerpc_netr_NetrEnumerateTrustedDomainsEx(b
, mem_ctx
,
1065 if (!NT_STATUS_IS_OK(status
)) {
1066 werr
= ntstatus_to_werror(status
);
1070 if (W_ERROR_IS_OK(werr
)) {
1071 printf("success\n");
1077 static WERROR
cmd_netlogon_getdcsitecoverage(struct rpc_pipe_client
*cli
,
1078 TALLOC_CTX
*mem_ctx
, int argc
,
1081 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1082 WERROR werr
= WERR_GENERAL_FAILURE
;
1083 const char *server_name
= cli
->desthost
;
1084 struct DcSitesCtr
*ctr
= NULL
;
1085 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1087 if (argc
< 1 || argc
> 3) {
1088 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1093 server_name
= argv
[1];
1096 status
= dcerpc_netr_DsrGetDcSiteCoverageW(b
, mem_ctx
,
1100 if (!NT_STATUS_IS_OK(status
)) {
1101 werr
= ntstatus_to_werror(status
);
1105 if (W_ERROR_IS_OK(werr
) && ctr
->num_sites
) {
1107 printf("sites covered by this DC: %d\n", ctr
->num_sites
);
1108 for (i
=0; i
<ctr
->num_sites
; i
++) {
1109 printf("%s\n", ctr
->sites
[i
].string
);
1116 static NTSTATUS
cmd_netlogon_database_redo(struct rpc_pipe_client
*cli
,
1117 TALLOC_CTX
*mem_ctx
, int argc
,
1120 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1122 const char *server_name
= cli
->desthost
;
1123 uint32_t neg_flags
= NETLOGON_NEG_AUTH2_ADS_FLAGS
;
1124 struct netr_Authenticator clnt_creds
, srv_cred
;
1125 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1126 unsigned char trust_passwd_hash
[16];
1127 enum netr_SchannelType sec_channel_type
= 0;
1128 struct netr_ChangeLogEntry e
;
1130 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1133 fprintf(stderr
, "Usage: %s <user rid>\n", argv
[0]);
1134 return NT_STATUS_OK
;
1138 sscanf(argv
[1], "%d", &rid
);
1141 if (!secrets_fetch_trust_account_password(lp_workgroup(),
1143 NULL
, &sec_channel_type
)) {
1144 return NT_STATUS_UNSUCCESSFUL
;
1147 status
= rpccli_netlogon_setup_creds(cli
,
1148 server_name
, /* server name */
1149 lp_workgroup(), /* domain */
1150 lp_netbios_name(), /* client name */
1151 lp_netbios_name(), /* machine account name */
1156 if (!NT_STATUS_IS_OK(status
)) {
1160 netlogon_creds_client_authenticator(cli
->dc
, &clnt_creds
);
1165 e
.db_index
= SAM_DATABASE_DOMAIN
;
1166 e
.delta_type
= NETR_DELTA_USER
;
1168 status
= dcerpc_netr_DatabaseRedo(b
, mem_ctx
,
1174 0, /* is calculated automatically */
1177 if (!NT_STATUS_IS_OK(status
)) {
1181 if (!netlogon_creds_client_check(cli
->dc
, &srv_cred
.cred
)) {
1182 DEBUG(0,("credentials chain check failed\n"));
1183 return NT_STATUS_ACCESS_DENIED
;
1189 static NTSTATUS
cmd_netlogon_capabilities(struct rpc_pipe_client
*cli
,
1190 TALLOC_CTX
*mem_ctx
, int argc
,
1193 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1195 struct netr_Authenticator credential
;
1196 struct netr_Authenticator return_authenticator
;
1197 union netr_Capabilities capabilities
;
1199 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1202 fprintf(stderr
, "Usage: %s <level>\n", argv
[0]);
1203 return NT_STATUS_OK
;
1207 level
= atoi(argv
[1]);
1210 ZERO_STRUCT(return_authenticator
);
1212 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
1214 status
= dcerpc_netr_LogonGetCapabilities(b
, mem_ctx
,
1218 &return_authenticator
,
1222 if (!NT_STATUS_IS_OK(status
)) {
1226 if (!netlogon_creds_client_check(cli
->dc
,
1227 &return_authenticator
.cred
)) {
1228 DEBUG(0,("credentials chain check failed\n"));
1229 return NT_STATUS_ACCESS_DENIED
;
1232 printf("capabilities: 0x%08x\n", capabilities
.server_capabilities
);
1237 /* List of commands exported by this module */
1239 struct cmd_set netlogon_commands
[] = {
1243 { "logonctrl2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl2
, &ndr_table_netlogon
, NULL
, "Logon Control 2", "" },
1244 { "getanydcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getanydcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1245 { "getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted PDC name", "" },
1246 { "dsr_getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1247 { "dsr_getdcnameex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1248 { "dsr_getdcnameex2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex2
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1249 { "dsr_getsitename", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getsitename
, &ndr_table_netlogon
, NULL
, "Get sitename", "" },
1250 { "dsr_getforesttrustinfo", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getforesttrustinfo
, &ndr_table_netlogon
, NULL
, "Get Forest Trust Info", "" },
1251 { "logonctrl", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl
, &ndr_table_netlogon
, NULL
, "Logon Control", "" },
1252 { "samsync", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_sync
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Synchronisation", "" },
1253 { "samdeltas", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_deltas
, NULL
, &ndr_table_netlogon
, NULL
, "Query Sam Deltas", "" },
1254 { "samlogon", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_logon
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Logon", "" },
1255 { "change_trust_pw", RPC_RTYPE_NTSTATUS
, cmd_netlogon_change_trust_pw
, NULL
, &ndr_table_netlogon
, NULL
, "Change Trust Account Password", "" },
1256 { "gettrustrid", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_gettrustrid
, &ndr_table_netlogon
, NULL
, "Get trust rid", "" },
1257 { "dsr_enumtrustdom", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1258 { "dsenumdomtrusts", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate all trusted domains in an AD forest", "" },
1259 { "deregisterdnsrecords", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_deregisterdnsrecords
, &ndr_table_netlogon
, NULL
, "Deregister DNS records", "" },
1260 { "netrenumtrusteddomains", RPC_RTYPE_NTSTATUS
, cmd_netlogon_enumtrusteddomains
, NULL
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1261 { "netrenumtrusteddomainsex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_enumtrusteddomainsex
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1262 { "getdcsitecoverage", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcsitecoverage
, &ndr_table_netlogon
, NULL
, "Get the Site-Coverage from a DC", "" },
1263 { "database_redo", RPC_RTYPE_NTSTATUS
, cmd_netlogon_database_redo
, NULL
, &ndr_table_netlogon
, NULL
, "Replicate single object from a DC", "" },
1264 { "capabilities", RPC_RTYPE_NTSTATUS
, cmd_netlogon_capabilities
, NULL
, &ndr_table_netlogon
, NULL
, "Return Capabilities", "" },