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
;
45 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
46 "<level> <domain>\n", argv
[0]);
51 logon_server
= argv
[1];
55 function_code
= atoi(argv
[2]);
59 level
= atoi(argv
[3]);
66 switch (function_code
) {
67 case NETLOGON_CONTROL_REDISCOVER
:
68 case NETLOGON_CONTROL_TC_QUERY
:
75 status
= dcerpc_netr_LogonControl2(b
, mem_ctx
,
82 if (!NT_STATUS_IS_OK(status
)) {
83 return ntstatus_to_werror(status
);
86 if (!W_ERROR_IS_OK(werr
)) {
95 static WERROR
cmd_netlogon_getanydcname(struct rpc_pipe_client
*cli
,
96 TALLOC_CTX
*mem_ctx
, int argc
,
99 const char *dcname
= NULL
;
103 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
106 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
110 /* Make sure to wait for our DC's reply */
111 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
112 rpccli_set_timeout(cli
, MAX(old_timeout
, 30000)); /* At least 30 sec */
114 status
= dcerpc_netr_GetAnyDCName(b
, mem_ctx
,
119 rpccli_set_timeout(cli
, old_timeout
);
121 if (!NT_STATUS_IS_OK(status
)) {
122 return ntstatus_to_werror(status
);
125 if (!W_ERROR_IS_OK(werr
)) {
129 /* Display results */
131 printf("%s\n", dcname
);
136 static WERROR
cmd_netlogon_getdcname(struct rpc_pipe_client
*cli
,
137 TALLOC_CTX
*mem_ctx
, int argc
,
140 const char *dcname
= NULL
;
144 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
147 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
151 /* Make sure to wait for our DC's reply */
152 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
153 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
155 status
= dcerpc_netr_GetDcName(b
, mem_ctx
,
160 rpccli_set_timeout(cli
, old_timeout
);
162 if (!NT_STATUS_IS_OK(status
)) {
163 return ntstatus_to_werror(status
);
166 if (!W_ERROR_IS_OK(werr
)) {
170 /* Display results */
172 printf("%s\n", dcname
);
177 static WERROR
cmd_netlogon_dsr_getdcname(struct rpc_pipe_client
*cli
,
178 TALLOC_CTX
*mem_ctx
, int argc
,
182 WERROR werr
= WERR_OK
;
183 uint32 flags
= DS_RETURN_DNS_NAME
;
184 const char *server_name
= cli
->desthost
;
185 const char *domain_name
;
186 struct GUID domain_guid
= GUID_zero();
187 struct GUID site_guid
= GUID_zero();
188 struct netr_DsRGetDCNameInfo
*info
= NULL
;
189 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
192 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
193 "[site_guid] [flags]\n", argv
[0]);
198 domain_name
= argv
[1];
201 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
207 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[3], &site_guid
))) {
213 sscanf(argv
[4], "%x", &flags
);
215 debug_dsdcinfo_flags(1,flags
);
217 result
= dcerpc_netr_DsRGetDCName(b
, mem_ctx
,
225 if (!NT_STATUS_IS_OK(result
)) {
226 return ntstatus_to_werror(result
);
229 if (W_ERROR_IS_OK(werr
)) {
230 d_printf("DsGetDcName gave: %s\n",
231 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
235 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
241 static WERROR
cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client
*cli
,
242 TALLOC_CTX
*mem_ctx
, int argc
,
247 uint32_t flags
= DS_RETURN_DNS_NAME
;
248 const char *server_name
= cli
->desthost
;
249 const char *domain_name
;
250 const char *site_name
= NULL
;
251 struct GUID domain_guid
= GUID_zero();
252 struct netr_DsRGetDCNameInfo
*info
= NULL
;
253 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
256 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
257 "[site_name] [flags]\n", argv
[0]);
261 domain_name
= argv
[1];
264 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
274 sscanf(argv
[4], "%x", &flags
);
277 debug_dsdcinfo_flags(1,flags
);
279 status
= dcerpc_netr_DsRGetDCNameEx(b
, mem_ctx
,
287 if (!NT_STATUS_IS_OK(status
)) {
288 return ntstatus_to_werror(status
);
291 if (!W_ERROR_IS_OK(result
)) {
295 d_printf("DsRGetDCNameEx gave %s\n",
296 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
301 static WERROR
cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client
*cli
,
302 TALLOC_CTX
*mem_ctx
, int argc
,
307 uint32_t flags
= DS_RETURN_DNS_NAME
;
308 const char *server_name
= cli
->desthost
;
309 const char *domain_name
= NULL
;
310 const char *client_account
= NULL
;
312 const char *site_name
= NULL
;
313 struct GUID domain_guid
= GUID_zero();
314 struct netr_DsRGetDCNameInfo
*info
= NULL
;
315 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
318 fprintf(stderr
, "Usage: %s [client_account] [acb_mask] "
319 "[domain_name] [domain_guid] [site_name] "
320 "[flags]\n", argv
[0]);
325 client_account
= argv
[1];
329 mask
= atoi(argv
[2]);
333 domain_name
= argv
[3];
337 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[4], &domain_guid
))) {
347 sscanf(argv
[6], "%x", &flags
);
350 debug_dsdcinfo_flags(1,flags
);
352 status
= dcerpc_netr_DsRGetDCNameEx2(b
, mem_ctx
,
362 if (!NT_STATUS_IS_OK(status
)) {
363 return ntstatus_to_werror(status
);
366 if (!W_ERROR_IS_OK(result
)) {
370 d_printf("DsRGetDCNameEx2 gave %s\n",
371 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
377 static WERROR
cmd_netlogon_dsr_getsitename(struct rpc_pipe_client
*cli
,
378 TALLOC_CTX
*mem_ctx
, int argc
,
383 const char *sitename
= NULL
;
384 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
387 fprintf(stderr
, "Usage: %s computername\n", argv
[0]);
391 status
= dcerpc_netr_DsRGetSiteName(b
, mem_ctx
,
395 if (!NT_STATUS_IS_OK(status
)) {
396 return ntstatus_to_werror(status
);
399 if (!W_ERROR_IS_OK(werr
)) {
400 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
401 nt_errstr(werror_to_ntstatus(werr
)));
405 printf("Computer %s is on Site: %s\n", argv
[1], sitename
);
410 static WERROR
cmd_netlogon_logon_ctrl(struct rpc_pipe_client
*cli
,
411 TALLOC_CTX
*mem_ctx
, int argc
,
414 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
416 const char *logon_server
= cli
->desthost
;
417 enum netr_LogonControlCode function_code
= 1;
419 union netr_CONTROL_QUERY_INFORMATION info
;
420 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
423 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
424 "<level>\n", argv
[0]);
429 logon_server
= argv
[1];
433 function_code
= atoi(argv
[2]);
437 level
= atoi(argv
[3]);
440 status
= dcerpc_netr_LogonControl(b
, mem_ctx
,
446 if (!NT_STATUS_IS_OK(status
)) {
447 return ntstatus_to_werror(status
);
450 if (!W_ERROR_IS_OK(werr
)) {
454 /* Display results */
459 /* Display sam synchronisation information */
461 static void display_sam_sync(struct netr_DELTA_ENUM_ARRAY
*r
)
465 for (i
=0; i
< r
->num_deltas
; i
++) {
467 union netr_DELTA_UNION u
= r
->delta_enum
[i
].delta_union
;
468 union netr_DELTA_ID_UNION id
= r
->delta_enum
[i
].delta_id_union
;
470 switch (r
->delta_enum
[i
].delta_type
) {
471 case NETR_DELTA_DOMAIN
:
472 printf("Domain: %s\n",
473 u
.domain
->domain_name
.string
);
475 case NETR_DELTA_GROUP
:
476 printf("Group: %s\n",
477 u
.group
->group_name
.string
);
479 case NETR_DELTA_DELETE_GROUP
:
480 printf("Delete Group: %d\n",
483 case NETR_DELTA_RENAME_GROUP
:
484 printf("Rename Group: %s -> %s\n",
485 u
.rename_group
->OldName
.string
,
486 u
.rename_group
->NewName
.string
);
488 case NETR_DELTA_USER
:
489 printf("Account: %s\n",
490 u
.user
->account_name
.string
);
492 case NETR_DELTA_DELETE_USER
:
493 printf("Delete User: %d\n",
496 case NETR_DELTA_RENAME_USER
:
497 printf("Rename user: %s -> %s\n",
498 u
.rename_user
->OldName
.string
,
499 u
.rename_user
->NewName
.string
);
501 case NETR_DELTA_GROUP_MEMBER
:
502 for (j
=0; j
< u
.group_member
->num_rids
; j
++) {
503 printf("rid 0x%x, attrib 0x%08x\n",
504 u
.group_member
->rids
[j
],
505 u
.group_member
->attribs
[j
]);
508 case NETR_DELTA_ALIAS
:
509 printf("Alias: %s\n",
510 u
.alias
->alias_name
.string
);
512 case NETR_DELTA_DELETE_ALIAS
:
513 printf("Delete Alias: %d\n",
516 case NETR_DELTA_RENAME_ALIAS
:
517 printf("Rename alias: %s -> %s\n",
518 u
.rename_alias
->OldName
.string
,
519 u
.rename_alias
->NewName
.string
);
521 case NETR_DELTA_ALIAS_MEMBER
:
522 for (j
=0; j
< u
.alias_member
->sids
.num_sids
; j
++) {
524 sid_to_fstring(sid_str
,
525 u
.alias_member
->sids
.sids
[j
].sid
);
526 printf("%s\n", sid_str
);
529 case NETR_DELTA_POLICY
:
530 printf("Policy: %s\n",
531 sid_string_dbg(id
.sid
));
533 case NETR_DELTA_TRUSTED_DOMAIN
:
534 printf("Trusted Domain: %s\n",
535 u
.trusted_domain
->domain_name
.string
);
537 case NETR_DELTA_DELETE_TRUST
:
538 printf("Delete Trust: %s\n",
539 sid_string_dbg(id
.sid
));
541 case NETR_DELTA_ACCOUNT
:
542 printf("Account: %s\n",
543 sid_string_dbg(id
.sid
));
545 case NETR_DELTA_DELETE_ACCOUNT
:
546 printf("Delete Account: %s\n",
547 sid_string_dbg(id
.sid
));
549 case NETR_DELTA_SECRET
:
550 printf("Secret: %s\n",
553 case NETR_DELTA_DELETE_SECRET
:
554 printf("Delete Secret: %s\n",
557 case NETR_DELTA_DELETE_GROUP2
:
558 printf("Delete Group2: %s\n",
559 u
.delete_group
->account_name
);
561 case NETR_DELTA_DELETE_USER2
:
562 printf("Delete User2: %s\n",
563 u
.delete_user
->account_name
);
565 case NETR_DELTA_MODIFY_COUNT
:
566 printf("sam sequence update: 0x%016llx\n",
567 (unsigned long long) *u
.modified_count
);
570 printf("unknown delta type 0x%02x\n",
571 r
->delta_enum
[i
].delta_type
);
577 /* Perform sam synchronisation */
579 static NTSTATUS
cmd_netlogon_sam_sync(struct rpc_pipe_client
*cli
,
580 TALLOC_CTX
*mem_ctx
, int argc
,
583 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
585 const char *logon_server
= cli
->desthost
;
586 const char *computername
= lp_netbios_name();
587 struct netr_Authenticator credential
;
588 struct netr_Authenticator return_authenticator
;
589 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
590 uint16_t restart_state
= 0;
591 uint32_t sync_context
= 0;
592 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
595 fprintf(stderr
, "Usage: %s [database_id]\n", argv
[0]);
600 database_id
= atoi(argv
[1]);
603 /* Synchronise sam database */
606 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
608 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
610 status
= dcerpc_netr_DatabaseSync2(b
, mem_ctx
,
614 &return_authenticator
,
621 if (!NT_STATUS_IS_OK(status
)) {
625 /* Check returned credentials. */
626 if (!netlogon_creds_client_check(cli
->dc
,
627 &return_authenticator
.cred
)) {
628 DEBUG(0,("credentials chain check failed\n"));
629 return NT_STATUS_ACCESS_DENIED
;
632 if (NT_STATUS_IS_ERR(result
)) {
636 /* Display results */
638 display_sam_sync(delta_enum_array
);
640 TALLOC_FREE(delta_enum_array
);
642 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
647 /* Perform sam delta synchronisation */
649 static NTSTATUS
cmd_netlogon_sam_deltas(struct rpc_pipe_client
*cli
,
650 TALLOC_CTX
*mem_ctx
, int argc
,
653 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
656 const char *logon_server
= cli
->desthost
;
657 const char *computername
= lp_netbios_name();
658 struct netr_Authenticator credential
;
659 struct netr_Authenticator return_authenticator
;
660 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
661 uint64_t sequence_num
;
662 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
665 fprintf(stderr
, "Usage: %s database_id seqnum\n", argv
[0]);
669 database_id
= atoi(argv
[1]);
672 sequence_num
= tmp
& 0xffff;
675 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
677 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
679 status
= dcerpc_netr_DatabaseDeltas(b
, mem_ctx
,
683 &return_authenticator
,
689 if (!NT_STATUS_IS_OK(status
)) {
693 /* Check returned credentials. */
694 if (!netlogon_creds_client_check(cli
->dc
,
695 &return_authenticator
.cred
)) {
696 DEBUG(0,("credentials chain check failed\n"));
697 return NT_STATUS_ACCESS_DENIED
;
700 if (NT_STATUS_IS_ERR(result
)) {
704 /* Display results */
706 display_sam_sync(delta_enum_array
);
708 TALLOC_FREE(delta_enum_array
);
710 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
715 /* Log on a domain user */
717 static NTSTATUS
cmd_netlogon_sam_logon(struct rpc_pipe_client
*cli
,
718 TALLOC_CTX
*mem_ctx
, int argc
,
721 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
722 int logon_type
= NetlogonNetworkInformation
;
723 const char *username
, *password
;
724 uint16_t validation_level
= 3;
725 uint32 logon_param
= 0;
726 const char *workstation
= NULL
;
728 /* Check arguments */
730 if (argc
< 3 || argc
> 7) {
731 fprintf(stderr
, "Usage: samlogon <username> <password> [workstation]"
732 "[logon_type (1 or 2)] [auth level (2 or 3)] [logon_parameter]\n");
740 workstation
= argv
[3];
743 sscanf(argv
[4], "%i", &logon_type
);
746 validation_level
= atoi(argv
[5]);
749 sscanf(argv
[6], "%x", &logon_param
);
751 /* Perform the sam logon */
753 result
= rpccli_netlogon_sam_logon(cli
, mem_ctx
, logon_param
, lp_workgroup(), username
, password
, workstation
, validation_level
, logon_type
);
755 if (!NT_STATUS_IS_OK(result
))
762 /* Change the trust account password */
764 static NTSTATUS
cmd_netlogon_change_trust_pw(struct rpc_pipe_client
*cli
,
765 TALLOC_CTX
*mem_ctx
, int argc
,
768 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
770 /* Check arguments */
773 fprintf(stderr
, "Usage: change_trust_pw");
777 /* Perform the sam logon */
779 result
= trust_pw_find_change_and_store_it(cli
, mem_ctx
,
782 if (!NT_STATUS_IS_OK(result
))
789 static WERROR
cmd_netlogon_gettrustrid(struct rpc_pipe_client
*cli
,
790 TALLOC_CTX
*mem_ctx
, int argc
,
793 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
794 WERROR werr
= WERR_GENERAL_FAILURE
;
795 const char *server_name
= cli
->desthost
;
796 const char *domain_name
= lp_workgroup();
798 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
800 if (argc
< 1 || argc
> 3) {
801 fprintf(stderr
, "Usage: %s <server_name> <domain_name>\n",
807 server_name
= argv
[1];
811 domain_name
= argv
[2];
814 status
= dcerpc_netr_LogonGetTrustRid(b
, mem_ctx
,
819 if (!NT_STATUS_IS_OK(status
)) {
820 werr
= ntstatus_to_werror(status
);
824 if (W_ERROR_IS_OK(werr
)) {
825 printf("Rid: %d\n", rid
);
831 static WERROR
cmd_netlogon_dsr_enumtrustdom(struct rpc_pipe_client
*cli
,
832 TALLOC_CTX
*mem_ctx
, int argc
,
835 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
836 WERROR werr
= WERR_GENERAL_FAILURE
;
837 const char *server_name
= cli
->desthost
;
838 uint32_t trust_flags
= NETR_TRUST_FLAG_IN_FOREST
;
839 struct netr_DomainTrustList trusts
;
840 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
842 if (argc
< 1 || argc
> 3) {
843 fprintf(stderr
, "Usage: %s <server_name> <trust_flags>\n",
849 server_name
= argv
[1];
853 sscanf(argv
[2], "%x", &trust_flags
);
856 status
= dcerpc_netr_DsrEnumerateDomainTrusts(b
, mem_ctx
,
861 if (!NT_STATUS_IS_OK(status
)) {
862 werr
= ntstatus_to_werror(status
);
866 if (W_ERROR_IS_OK(werr
)) {
869 printf("%d domains returned\n", trusts
.count
);
871 for (i
=0; i
<trusts
.count
; i
++ ) {
873 trusts
.array
[i
].dns_name
,
874 trusts
.array
[i
].netbios_name
);
881 static WERROR
cmd_netlogon_deregisterdnsrecords(struct rpc_pipe_client
*cli
,
882 TALLOC_CTX
*mem_ctx
, int argc
,
885 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
886 WERROR werr
= WERR_GENERAL_FAILURE
;
887 const char *server_name
= cli
->desthost
;
888 const char *domain
= lp_workgroup();
889 const char *dns_host
= NULL
;
890 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
892 if (argc
< 1 || argc
> 4) {
893 fprintf(stderr
, "Usage: %s <server_name> <domain_name> "
894 "<dns_host>\n", argv
[0]);
899 server_name
= argv
[1];
910 status
= dcerpc_netr_DsrDeregisterDNSHostRecords(b
, mem_ctx
,
917 if (!NT_STATUS_IS_OK(status
)) {
918 werr
= ntstatus_to_werror(status
);
922 if (W_ERROR_IS_OK(werr
)) {
929 static WERROR
cmd_netlogon_dsr_getforesttrustinfo(struct rpc_pipe_client
*cli
,
930 TALLOC_CTX
*mem_ctx
, int argc
,
933 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
934 WERROR werr
= WERR_GENERAL_FAILURE
;
935 const char *server_name
= cli
->desthost
;
936 const char *trusted_domain_name
= NULL
;
937 struct lsa_ForestTrustInformation
*info
= NULL
;
939 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
941 if (argc
< 1 || argc
> 4) {
942 fprintf(stderr
, "Usage: %s <server_name> <trusted_domain_name> "
943 "<flags>\n", argv
[0]);
948 server_name
= argv
[1];
952 trusted_domain_name
= argv
[2];
956 sscanf(argv
[3], "%x", &flags
);
959 status
= dcerpc_netr_DsRGetForestTrustInformation(b
, mem_ctx
,
965 if (!NT_STATUS_IS_OK(status
)) {
966 werr
= ntstatus_to_werror(status
);
970 if (W_ERROR_IS_OK(werr
)) {
977 static NTSTATUS
cmd_netlogon_enumtrusteddomains(struct rpc_pipe_client
*cli
,
978 TALLOC_CTX
*mem_ctx
, int argc
,
981 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
983 const char *server_name
= cli
->desthost
;
984 struct netr_Blob blob
;
985 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
988 if (argc
< 1 || argc
> 3) {
989 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
994 server_name
= argv
[1];
997 status
= dcerpc_netr_NetrEnumerateTrustedDomains(b
, mem_ctx
,
1001 if (!NT_STATUS_IS_OK(status
)) {
1005 if (!NT_STATUS_IS_OK(result
)) {
1010 printf("success\n");
1011 dump_data(1, blob
.data
, blob
.length
);
1016 static WERROR
cmd_netlogon_enumtrusteddomainsex(struct rpc_pipe_client
*cli
,
1017 TALLOC_CTX
*mem_ctx
, int argc
,
1020 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1021 WERROR werr
= WERR_GENERAL_FAILURE
;
1022 const char *server_name
= cli
->desthost
;
1023 struct netr_DomainTrustList list
;
1024 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1026 if (argc
< 1 || argc
> 3) {
1027 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1032 server_name
= argv
[1];
1035 status
= dcerpc_netr_NetrEnumerateTrustedDomainsEx(b
, mem_ctx
,
1039 if (!NT_STATUS_IS_OK(status
)) {
1040 werr
= ntstatus_to_werror(status
);
1044 if (W_ERROR_IS_OK(werr
)) {
1045 printf("success\n");
1051 static WERROR
cmd_netlogon_getdcsitecoverage(struct rpc_pipe_client
*cli
,
1052 TALLOC_CTX
*mem_ctx
, int argc
,
1055 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1056 WERROR werr
= WERR_GENERAL_FAILURE
;
1057 const char *server_name
= cli
->desthost
;
1058 struct DcSitesCtr
*ctr
= NULL
;
1059 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1061 if (argc
< 1 || argc
> 3) {
1062 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1067 server_name
= argv
[1];
1070 status
= dcerpc_netr_DsrGetDcSiteCoverageW(b
, mem_ctx
,
1074 if (!NT_STATUS_IS_OK(status
)) {
1075 werr
= ntstatus_to_werror(status
);
1079 if (W_ERROR_IS_OK(werr
) && ctr
->num_sites
) {
1081 printf("sites covered by this DC: %d\n", ctr
->num_sites
);
1082 for (i
=0; i
<ctr
->num_sites
; i
++) {
1083 printf("%s\n", ctr
->sites
[i
].string
);
1090 static NTSTATUS
cmd_netlogon_database_redo(struct rpc_pipe_client
*cli
,
1091 TALLOC_CTX
*mem_ctx
, int argc
,
1094 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1096 const char *server_name
= cli
->desthost
;
1097 uint32_t neg_flags
= NETLOGON_NEG_AUTH2_ADS_FLAGS
;
1098 struct netr_Authenticator clnt_creds
, srv_cred
;
1099 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1100 unsigned char trust_passwd_hash
[16];
1101 enum netr_SchannelType sec_channel_type
= 0;
1102 struct netr_ChangeLogEntry e
;
1104 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1107 fprintf(stderr
, "Usage: %s <user rid>\n", argv
[0]);
1108 return NT_STATUS_OK
;
1112 sscanf(argv
[1], "%d", &rid
);
1115 if (!secrets_fetch_trust_account_password(lp_workgroup(),
1117 NULL
, &sec_channel_type
)) {
1118 return NT_STATUS_UNSUCCESSFUL
;
1121 status
= rpccli_netlogon_setup_creds(cli
,
1122 server_name
, /* server name */
1123 lp_workgroup(), /* domain */
1124 lp_netbios_name(), /* client name */
1125 lp_netbios_name(), /* machine account name */
1130 if (!NT_STATUS_IS_OK(status
)) {
1134 netlogon_creds_client_authenticator(cli
->dc
, &clnt_creds
);
1139 e
.db_index
= SAM_DATABASE_DOMAIN
;
1140 e
.delta_type
= NETR_DELTA_USER
;
1142 status
= dcerpc_netr_DatabaseRedo(b
, mem_ctx
,
1148 0, /* is calculated automatically */
1151 if (!NT_STATUS_IS_OK(status
)) {
1155 if (!netlogon_creds_client_check(cli
->dc
, &srv_cred
.cred
)) {
1156 DEBUG(0,("credentials chain check failed\n"));
1157 return NT_STATUS_ACCESS_DENIED
;
1163 static NTSTATUS
cmd_netlogon_capabilities(struct rpc_pipe_client
*cli
,
1164 TALLOC_CTX
*mem_ctx
, int argc
,
1167 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1169 struct netr_Authenticator credential
;
1170 struct netr_Authenticator return_authenticator
;
1171 union netr_Capabilities capabilities
;
1173 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1176 fprintf(stderr
, "Usage: %s <level>\n", argv
[0]);
1177 return NT_STATUS_OK
;
1181 level
= atoi(argv
[1]);
1184 ZERO_STRUCT(return_authenticator
);
1186 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
1188 status
= dcerpc_netr_LogonGetCapabilities(b
, mem_ctx
,
1192 &return_authenticator
,
1196 if (!NT_STATUS_IS_OK(status
)) {
1200 if (!netlogon_creds_client_check(cli
->dc
,
1201 &return_authenticator
.cred
)) {
1202 DEBUG(0,("credentials chain check failed\n"));
1203 return NT_STATUS_ACCESS_DENIED
;
1206 printf("capabilities: 0x%08x\n", capabilities
.server_capabilities
);
1211 /* List of commands exported by this module */
1213 struct cmd_set netlogon_commands
[] = {
1217 { "logonctrl2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl2
, &ndr_table_netlogon
, NULL
, "Logon Control 2", "" },
1218 { "getanydcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getanydcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1219 { "getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted PDC name", "" },
1220 { "dsr_getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1221 { "dsr_getdcnameex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1222 { "dsr_getdcnameex2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex2
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1223 { "dsr_getsitename", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getsitename
, &ndr_table_netlogon
, NULL
, "Get sitename", "" },
1224 { "dsr_getforesttrustinfo", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getforesttrustinfo
, &ndr_table_netlogon
, NULL
, "Get Forest Trust Info", "" },
1225 { "logonctrl", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl
, &ndr_table_netlogon
, NULL
, "Logon Control", "" },
1226 { "samsync", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_sync
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Synchronisation", "" },
1227 { "samdeltas", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_deltas
, NULL
, &ndr_table_netlogon
, NULL
, "Query Sam Deltas", "" },
1228 { "samlogon", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_logon
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Logon", "" },
1229 { "change_trust_pw", RPC_RTYPE_NTSTATUS
, cmd_netlogon_change_trust_pw
, NULL
, &ndr_table_netlogon
, NULL
, "Change Trust Account Password", "" },
1230 { "gettrustrid", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_gettrustrid
, &ndr_table_netlogon
, NULL
, "Get trust rid", "" },
1231 { "dsr_enumtrustdom", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1232 { "dsenumdomtrusts", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate all trusted domains in an AD forest", "" },
1233 { "deregisterdnsrecords", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_deregisterdnsrecords
, &ndr_table_netlogon
, NULL
, "Deregister DNS records", "" },
1234 { "netrenumtrusteddomains", RPC_RTYPE_NTSTATUS
, cmd_netlogon_enumtrusteddomains
, NULL
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1235 { "netrenumtrusteddomainsex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_enumtrusteddomainsex
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1236 { "getdcsitecoverage", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcsitecoverage
, &ndr_table_netlogon
, NULL
, "Get the Site-Coverage from a DC", "" },
1237 { "database_redo", RPC_RTYPE_NTSTATUS
, cmd_netlogon_database_redo
, NULL
, &ndr_table_netlogon
, NULL
, "Replicate single object from a DC", "" },
1238 { "capabilities", RPC_RTYPE_NTSTATUS
, cmd_netlogon_capabilities
, NULL
, &ndr_table_netlogon
, NULL
, "Return Capabilities", "" },