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 result
= dcerpc_netr_DsRGetDCName(b
, mem_ctx
,
223 if (!NT_STATUS_IS_OK(result
)) {
224 return ntstatus_to_werror(result
);
227 if (W_ERROR_IS_OK(werr
)) {
228 d_printf("DsGetDcName gave: %s\n",
229 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
233 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
239 static WERROR
cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client
*cli
,
240 TALLOC_CTX
*mem_ctx
, int argc
,
245 uint32_t flags
= DS_RETURN_DNS_NAME
;
246 const char *server_name
= cli
->desthost
;
247 const char *domain_name
;
248 const char *site_name
= NULL
;
249 struct GUID domain_guid
= GUID_zero();
250 struct netr_DsRGetDCNameInfo
*info
= NULL
;
251 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
254 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
255 "[site_name] [flags]\n", argv
[0]);
259 domain_name
= argv
[1];
262 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
272 sscanf(argv
[4], "%x", &flags
);
275 status
= dcerpc_netr_DsRGetDCNameEx(b
, mem_ctx
,
283 if (!NT_STATUS_IS_OK(status
)) {
284 return ntstatus_to_werror(status
);
287 if (!W_ERROR_IS_OK(result
)) {
291 d_printf("DsRGetDCNameEx gave %s\n",
292 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
297 static WERROR
cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client
*cli
,
298 TALLOC_CTX
*mem_ctx
, int argc
,
303 uint32_t flags
= DS_RETURN_DNS_NAME
;
304 const char *server_name
= cli
->desthost
;
305 const char *domain_name
= NULL
;
306 const char *client_account
= NULL
;
308 const char *site_name
= NULL
;
309 struct GUID domain_guid
= GUID_zero();
310 struct netr_DsRGetDCNameInfo
*info
= NULL
;
311 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
314 fprintf(stderr
, "Usage: %s [client_account] [acb_mask] "
315 "[domain_name] [domain_guid] [site_name] "
316 "[flags]\n", argv
[0]);
321 client_account
= argv
[1];
325 mask
= atoi(argv
[2]);
329 domain_name
= argv
[3];
333 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[4], &domain_guid
))) {
343 sscanf(argv
[6], "%x", &flags
);
346 status
= dcerpc_netr_DsRGetDCNameEx2(b
, mem_ctx
,
356 if (!NT_STATUS_IS_OK(status
)) {
357 return ntstatus_to_werror(status
);
360 if (!W_ERROR_IS_OK(result
)) {
364 d_printf("DsRGetDCNameEx2 gave %s\n",
365 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
371 static WERROR
cmd_netlogon_dsr_getsitename(struct rpc_pipe_client
*cli
,
372 TALLOC_CTX
*mem_ctx
, int argc
,
377 const char *sitename
= NULL
;
378 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
381 fprintf(stderr
, "Usage: %s computername\n", argv
[0]);
385 status
= dcerpc_netr_DsRGetSiteName(b
, mem_ctx
,
389 if (!NT_STATUS_IS_OK(status
)) {
390 return ntstatus_to_werror(status
);
393 if (!W_ERROR_IS_OK(werr
)) {
394 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
395 nt_errstr(werror_to_ntstatus(werr
)));
399 printf("Computer %s is on Site: %s\n", argv
[1], sitename
);
404 static WERROR
cmd_netlogon_logon_ctrl(struct rpc_pipe_client
*cli
,
405 TALLOC_CTX
*mem_ctx
, int argc
,
408 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
410 const char *logon_server
= cli
->desthost
;
411 enum netr_LogonControlCode function_code
= 1;
413 union netr_CONTROL_QUERY_INFORMATION info
;
414 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
417 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
418 "<level>\n", argv
[0]);
423 logon_server
= argv
[1];
427 function_code
= atoi(argv
[2]);
431 level
= atoi(argv
[3]);
434 status
= dcerpc_netr_LogonControl(b
, mem_ctx
,
440 if (!NT_STATUS_IS_OK(status
)) {
441 return ntstatus_to_werror(status
);
444 if (!W_ERROR_IS_OK(werr
)) {
448 /* Display results */
453 /* Display sam synchronisation information */
455 static void display_sam_sync(struct netr_DELTA_ENUM_ARRAY
*r
)
459 for (i
=0; i
< r
->num_deltas
; i
++) {
461 union netr_DELTA_UNION u
= r
->delta_enum
[i
].delta_union
;
462 union netr_DELTA_ID_UNION id
= r
->delta_enum
[i
].delta_id_union
;
464 switch (r
->delta_enum
[i
].delta_type
) {
465 case NETR_DELTA_DOMAIN
:
466 printf("Domain: %s\n",
467 u
.domain
->domain_name
.string
);
469 case NETR_DELTA_GROUP
:
470 printf("Group: %s\n",
471 u
.group
->group_name
.string
);
473 case NETR_DELTA_DELETE_GROUP
:
474 printf("Delete Group: %d\n",
477 case NETR_DELTA_RENAME_GROUP
:
478 printf("Rename Group: %s -> %s\n",
479 u
.rename_group
->OldName
.string
,
480 u
.rename_group
->NewName
.string
);
482 case NETR_DELTA_USER
:
483 printf("Account: %s\n",
484 u
.user
->account_name
.string
);
486 case NETR_DELTA_DELETE_USER
:
487 printf("Delete User: %d\n",
490 case NETR_DELTA_RENAME_USER
:
491 printf("Rename user: %s -> %s\n",
492 u
.rename_user
->OldName
.string
,
493 u
.rename_user
->NewName
.string
);
495 case NETR_DELTA_GROUP_MEMBER
:
496 for (j
=0; j
< u
.group_member
->num_rids
; j
++) {
497 printf("rid 0x%x, attrib 0x%08x\n",
498 u
.group_member
->rids
[j
],
499 u
.group_member
->attribs
[j
]);
502 case NETR_DELTA_ALIAS
:
503 printf("Alias: %s\n",
504 u
.alias
->alias_name
.string
);
506 case NETR_DELTA_DELETE_ALIAS
:
507 printf("Delete Alias: %d\n",
510 case NETR_DELTA_RENAME_ALIAS
:
511 printf("Rename alias: %s -> %s\n",
512 u
.rename_alias
->OldName
.string
,
513 u
.rename_alias
->NewName
.string
);
515 case NETR_DELTA_ALIAS_MEMBER
:
516 for (j
=0; j
< u
.alias_member
->sids
.num_sids
; j
++) {
518 sid_to_fstring(sid_str
,
519 u
.alias_member
->sids
.sids
[j
].sid
);
520 printf("%s\n", sid_str
);
523 case NETR_DELTA_POLICY
:
524 printf("Policy: %s\n",
525 sid_string_dbg(id
.sid
));
527 case NETR_DELTA_TRUSTED_DOMAIN
:
528 printf("Trusted Domain: %s\n",
529 u
.trusted_domain
->domain_name
.string
);
531 case NETR_DELTA_DELETE_TRUST
:
532 printf("Delete Trust: %s\n",
533 sid_string_dbg(id
.sid
));
535 case NETR_DELTA_ACCOUNT
:
536 printf("Account: %s\n",
537 sid_string_dbg(id
.sid
));
539 case NETR_DELTA_DELETE_ACCOUNT
:
540 printf("Delete Account: %s\n",
541 sid_string_dbg(id
.sid
));
543 case NETR_DELTA_SECRET
:
544 printf("Secret: %s\n",
547 case NETR_DELTA_DELETE_SECRET
:
548 printf("Delete Secret: %s\n",
551 case NETR_DELTA_DELETE_GROUP2
:
552 printf("Delete Group2: %s\n",
553 u
.delete_group
->account_name
);
555 case NETR_DELTA_DELETE_USER2
:
556 printf("Delete User2: %s\n",
557 u
.delete_user
->account_name
);
559 case NETR_DELTA_MODIFY_COUNT
:
560 printf("sam sequence update: 0x%016llx\n",
561 (unsigned long long) *u
.modified_count
);
564 printf("unknown delta type 0x%02x\n",
565 r
->delta_enum
[i
].delta_type
);
571 /* Perform sam synchronisation */
573 static NTSTATUS
cmd_netlogon_sam_sync(struct rpc_pipe_client
*cli
,
574 TALLOC_CTX
*mem_ctx
, int argc
,
577 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
579 const char *logon_server
= cli
->desthost
;
580 const char *computername
= lp_netbios_name();
581 struct netr_Authenticator credential
;
582 struct netr_Authenticator return_authenticator
;
583 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
584 uint16_t restart_state
= 0;
585 uint32_t sync_context
= 0;
586 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
589 fprintf(stderr
, "Usage: %s [database_id]\n", argv
[0]);
594 database_id
= atoi(argv
[1]);
597 /* Synchronise sam database */
600 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
602 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
604 status
= dcerpc_netr_DatabaseSync2(b
, mem_ctx
,
608 &return_authenticator
,
615 if (!NT_STATUS_IS_OK(status
)) {
619 /* Check returned credentials. */
620 if (!netlogon_creds_client_check(cli
->dc
,
621 &return_authenticator
.cred
)) {
622 DEBUG(0,("credentials chain check failed\n"));
623 return NT_STATUS_ACCESS_DENIED
;
626 if (NT_STATUS_IS_ERR(result
)) {
630 /* Display results */
632 display_sam_sync(delta_enum_array
);
634 TALLOC_FREE(delta_enum_array
);
636 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
641 /* Perform sam delta synchronisation */
643 static NTSTATUS
cmd_netlogon_sam_deltas(struct rpc_pipe_client
*cli
,
644 TALLOC_CTX
*mem_ctx
, int argc
,
647 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
650 const char *logon_server
= cli
->desthost
;
651 const char *computername
= lp_netbios_name();
652 struct netr_Authenticator credential
;
653 struct netr_Authenticator return_authenticator
;
654 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
655 uint64_t sequence_num
;
656 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
659 fprintf(stderr
, "Usage: %s database_id seqnum\n", argv
[0]);
663 database_id
= atoi(argv
[1]);
666 sequence_num
= tmp
& 0xffff;
669 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
671 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
673 status
= dcerpc_netr_DatabaseDeltas(b
, mem_ctx
,
677 &return_authenticator
,
683 if (!NT_STATUS_IS_OK(status
)) {
687 /* Check returned credentials. */
688 if (!netlogon_creds_client_check(cli
->dc
,
689 &return_authenticator
.cred
)) {
690 DEBUG(0,("credentials chain check failed\n"));
691 return NT_STATUS_ACCESS_DENIED
;
694 if (NT_STATUS_IS_ERR(result
)) {
698 /* Display results */
700 display_sam_sync(delta_enum_array
);
702 TALLOC_FREE(delta_enum_array
);
704 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
709 /* Log on a domain user */
711 static NTSTATUS
cmd_netlogon_sam_logon(struct rpc_pipe_client
*cli
,
712 TALLOC_CTX
*mem_ctx
, int argc
,
715 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
716 int logon_type
= NetlogonNetworkInformation
;
717 const char *username
, *password
;
718 uint16_t validation_level
= 3;
719 uint32 logon_param
= 0;
720 const char *workstation
= NULL
;
722 /* Check arguments */
724 if (argc
< 3 || argc
> 7) {
725 fprintf(stderr
, "Usage: samlogon <username> <password> [workstation]"
726 "[logon_type (1 or 2)] [auth level (2 or 3)] [logon_parameter]\n");
734 workstation
= argv
[3];
737 sscanf(argv
[4], "%i", &logon_type
);
740 validation_level
= atoi(argv
[5]);
743 sscanf(argv
[6], "%x", &logon_param
);
745 /* Perform the sam logon */
747 result
= rpccli_netlogon_sam_logon(cli
, mem_ctx
, logon_param
, lp_workgroup(), username
, password
, workstation
, validation_level
, logon_type
);
749 if (!NT_STATUS_IS_OK(result
))
756 /* Change the trust account password */
758 static NTSTATUS
cmd_netlogon_change_trust_pw(struct rpc_pipe_client
*cli
,
759 TALLOC_CTX
*mem_ctx
, int argc
,
762 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
764 /* Check arguments */
767 fprintf(stderr
, "Usage: change_trust_pw");
771 /* Perform the sam logon */
773 result
= trust_pw_find_change_and_store_it(cli
, mem_ctx
,
776 if (!NT_STATUS_IS_OK(result
))
783 static WERROR
cmd_netlogon_gettrustrid(struct rpc_pipe_client
*cli
,
784 TALLOC_CTX
*mem_ctx
, int argc
,
787 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
788 WERROR werr
= WERR_GENERAL_FAILURE
;
789 const char *server_name
= cli
->desthost
;
790 const char *domain_name
= lp_workgroup();
792 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
794 if (argc
< 1 || argc
> 3) {
795 fprintf(stderr
, "Usage: %s <server_name> <domain_name>\n",
801 server_name
= argv
[1];
805 domain_name
= argv
[2];
808 status
= dcerpc_netr_LogonGetTrustRid(b
, mem_ctx
,
813 if (!NT_STATUS_IS_OK(status
)) {
814 werr
= ntstatus_to_werror(status
);
818 if (W_ERROR_IS_OK(werr
)) {
819 printf("Rid: %d\n", rid
);
825 static WERROR
cmd_netlogon_dsr_enumtrustdom(struct rpc_pipe_client
*cli
,
826 TALLOC_CTX
*mem_ctx
, int argc
,
829 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
830 WERROR werr
= WERR_GENERAL_FAILURE
;
831 const char *server_name
= cli
->desthost
;
832 uint32_t trust_flags
= NETR_TRUST_FLAG_IN_FOREST
;
833 struct netr_DomainTrustList trusts
;
834 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
836 if (argc
< 1 || argc
> 3) {
837 fprintf(stderr
, "Usage: %s <server_name> <trust_flags>\n",
843 server_name
= argv
[1];
847 sscanf(argv
[2], "%x", &trust_flags
);
850 status
= dcerpc_netr_DsrEnumerateDomainTrusts(b
, mem_ctx
,
855 if (!NT_STATUS_IS_OK(status
)) {
856 werr
= ntstatus_to_werror(status
);
860 if (W_ERROR_IS_OK(werr
)) {
863 printf("%d domains returned\n", trusts
.count
);
865 for (i
=0; i
<trusts
.count
; i
++ ) {
867 trusts
.array
[i
].dns_name
,
868 trusts
.array
[i
].netbios_name
);
875 static WERROR
cmd_netlogon_deregisterdnsrecords(struct rpc_pipe_client
*cli
,
876 TALLOC_CTX
*mem_ctx
, int argc
,
879 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
880 WERROR werr
= WERR_GENERAL_FAILURE
;
881 const char *server_name
= cli
->desthost
;
882 const char *domain
= lp_workgroup();
883 const char *dns_host
= NULL
;
884 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
886 if (argc
< 1 || argc
> 4) {
887 fprintf(stderr
, "Usage: %s <server_name> <domain_name> "
888 "<dns_host>\n", argv
[0]);
893 server_name
= argv
[1];
904 status
= dcerpc_netr_DsrDeregisterDNSHostRecords(b
, mem_ctx
,
911 if (!NT_STATUS_IS_OK(status
)) {
912 werr
= ntstatus_to_werror(status
);
916 if (W_ERROR_IS_OK(werr
)) {
923 static WERROR
cmd_netlogon_dsr_getforesttrustinfo(struct rpc_pipe_client
*cli
,
924 TALLOC_CTX
*mem_ctx
, int argc
,
927 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
928 WERROR werr
= WERR_GENERAL_FAILURE
;
929 const char *server_name
= cli
->desthost
;
930 const char *trusted_domain_name
= NULL
;
931 struct lsa_ForestTrustInformation
*info
= NULL
;
933 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
935 if (argc
< 1 || argc
> 4) {
936 fprintf(stderr
, "Usage: %s <server_name> <trusted_domain_name> "
937 "<flags>\n", argv
[0]);
942 server_name
= argv
[1];
946 trusted_domain_name
= argv
[2];
950 sscanf(argv
[3], "%x", &flags
);
953 status
= dcerpc_netr_DsRGetForestTrustInformation(b
, mem_ctx
,
959 if (!NT_STATUS_IS_OK(status
)) {
960 werr
= ntstatus_to_werror(status
);
964 if (W_ERROR_IS_OK(werr
)) {
971 static NTSTATUS
cmd_netlogon_enumtrusteddomains(struct rpc_pipe_client
*cli
,
972 TALLOC_CTX
*mem_ctx
, int argc
,
975 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
977 const char *server_name
= cli
->desthost
;
978 struct netr_Blob blob
;
979 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
982 if (argc
< 1 || argc
> 3) {
983 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
988 server_name
= argv
[1];
991 status
= dcerpc_netr_NetrEnumerateTrustedDomains(b
, mem_ctx
,
995 if (!NT_STATUS_IS_OK(status
)) {
999 if (!NT_STATUS_IS_OK(result
)) {
1004 printf("success\n");
1005 dump_data(1, blob
.data
, blob
.length
);
1010 static WERROR
cmd_netlogon_enumtrusteddomainsex(struct rpc_pipe_client
*cli
,
1011 TALLOC_CTX
*mem_ctx
, int argc
,
1014 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1015 WERROR werr
= WERR_GENERAL_FAILURE
;
1016 const char *server_name
= cli
->desthost
;
1017 struct netr_DomainTrustList list
;
1018 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1020 if (argc
< 1 || argc
> 3) {
1021 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1026 server_name
= argv
[1];
1029 status
= dcerpc_netr_NetrEnumerateTrustedDomainsEx(b
, mem_ctx
,
1033 if (!NT_STATUS_IS_OK(status
)) {
1034 werr
= ntstatus_to_werror(status
);
1038 if (W_ERROR_IS_OK(werr
)) {
1039 printf("success\n");
1045 static WERROR
cmd_netlogon_getdcsitecoverage(struct rpc_pipe_client
*cli
,
1046 TALLOC_CTX
*mem_ctx
, int argc
,
1049 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1050 WERROR werr
= WERR_GENERAL_FAILURE
;
1051 const char *server_name
= cli
->desthost
;
1052 struct DcSitesCtr
*ctr
= NULL
;
1053 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1055 if (argc
< 1 || argc
> 3) {
1056 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1061 server_name
= argv
[1];
1064 status
= dcerpc_netr_DsrGetDcSiteCoverageW(b
, mem_ctx
,
1068 if (!NT_STATUS_IS_OK(status
)) {
1069 werr
= ntstatus_to_werror(status
);
1073 if (W_ERROR_IS_OK(werr
) && ctr
->num_sites
) {
1075 printf("sites covered by this DC: %d\n", ctr
->num_sites
);
1076 for (i
=0; i
<ctr
->num_sites
; i
++) {
1077 printf("%s\n", ctr
->sites
[i
].string
);
1084 static NTSTATUS
cmd_netlogon_database_redo(struct rpc_pipe_client
*cli
,
1085 TALLOC_CTX
*mem_ctx
, int argc
,
1088 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1090 const char *server_name
= cli
->desthost
;
1091 uint32_t neg_flags
= NETLOGON_NEG_AUTH2_ADS_FLAGS
;
1092 struct netr_Authenticator clnt_creds
, srv_cred
;
1093 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1094 unsigned char trust_passwd_hash
[16];
1095 enum netr_SchannelType sec_channel_type
= 0;
1096 struct netr_ChangeLogEntry e
;
1098 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1101 fprintf(stderr
, "Usage: %s <user rid>\n", argv
[0]);
1102 return NT_STATUS_OK
;
1106 sscanf(argv
[1], "%d", &rid
);
1109 if (!secrets_fetch_trust_account_password(lp_workgroup(),
1111 NULL
, &sec_channel_type
)) {
1112 return NT_STATUS_UNSUCCESSFUL
;
1115 status
= rpccli_netlogon_setup_creds(cli
,
1116 server_name
, /* server name */
1117 lp_workgroup(), /* domain */
1118 lp_netbios_name(), /* client name */
1119 lp_netbios_name(), /* machine account name */
1124 if (!NT_STATUS_IS_OK(status
)) {
1128 netlogon_creds_client_authenticator(cli
->dc
, &clnt_creds
);
1133 e
.db_index
= SAM_DATABASE_DOMAIN
;
1134 e
.delta_type
= NETR_DELTA_USER
;
1136 status
= dcerpc_netr_DatabaseRedo(b
, mem_ctx
,
1142 0, /* is calculated automatically */
1145 if (!NT_STATUS_IS_OK(status
)) {
1149 if (!netlogon_creds_client_check(cli
->dc
, &srv_cred
.cred
)) {
1150 DEBUG(0,("credentials chain check failed\n"));
1151 return NT_STATUS_ACCESS_DENIED
;
1157 static NTSTATUS
cmd_netlogon_capabilities(struct rpc_pipe_client
*cli
,
1158 TALLOC_CTX
*mem_ctx
, int argc
,
1161 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1163 struct netr_Authenticator credential
;
1164 struct netr_Authenticator return_authenticator
;
1165 union netr_Capabilities capabilities
;
1167 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1170 fprintf(stderr
, "Usage: %s <level>\n", argv
[0]);
1171 return NT_STATUS_OK
;
1175 level
= atoi(argv
[1]);
1178 ZERO_STRUCT(return_authenticator
);
1180 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
1182 status
= dcerpc_netr_LogonGetCapabilities(b
, mem_ctx
,
1186 &return_authenticator
,
1190 if (!NT_STATUS_IS_OK(status
)) {
1194 if (!netlogon_creds_client_check(cli
->dc
,
1195 &return_authenticator
.cred
)) {
1196 DEBUG(0,("credentials chain check failed\n"));
1197 return NT_STATUS_ACCESS_DENIED
;
1200 printf("capabilities: 0x%08x\n", capabilities
.server_capabilities
);
1205 /* List of commands exported by this module */
1207 struct cmd_set netlogon_commands
[] = {
1211 { "logonctrl2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl2
, &ndr_table_netlogon
, NULL
, "Logon Control 2", "" },
1212 { "getanydcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getanydcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1213 { "getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted PDC name", "" },
1214 { "dsr_getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1215 { "dsr_getdcnameex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1216 { "dsr_getdcnameex2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex2
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1217 { "dsr_getsitename", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getsitename
, &ndr_table_netlogon
, NULL
, "Get sitename", "" },
1218 { "dsr_getforesttrustinfo", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getforesttrustinfo
, &ndr_table_netlogon
, NULL
, "Get Forest Trust Info", "" },
1219 { "logonctrl", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl
, &ndr_table_netlogon
, NULL
, "Logon Control", "" },
1220 { "samsync", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_sync
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Synchronisation", "" },
1221 { "samdeltas", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_deltas
, NULL
, &ndr_table_netlogon
, NULL
, "Query Sam Deltas", "" },
1222 { "samlogon", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_logon
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Logon", "" },
1223 { "change_trust_pw", RPC_RTYPE_NTSTATUS
, cmd_netlogon_change_trust_pw
, NULL
, &ndr_table_netlogon
, NULL
, "Change Trust Account Password", "" },
1224 { "gettrustrid", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_gettrustrid
, &ndr_table_netlogon
, NULL
, "Get trust rid", "" },
1225 { "dsr_enumtrustdom", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1226 { "dsenumdomtrusts", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate all trusted domains in an AD forest", "" },
1227 { "deregisterdnsrecords", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_deregisterdnsrecords
, &ndr_table_netlogon
, NULL
, "Deregister DNS records", "" },
1228 { "netrenumtrusteddomains", RPC_RTYPE_NTSTATUS
, cmd_netlogon_enumtrusteddomains
, NULL
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1229 { "netrenumtrusteddomainsex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_enumtrusteddomainsex
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1230 { "getdcsitecoverage", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcsitecoverage
, &ndr_table_netlogon
, NULL
, "Get the Site-Coverage from a DC", "" },
1231 { "database_redo", RPC_RTYPE_NTSTATUS
, cmd_netlogon_database_redo
, NULL
, &ndr_table_netlogon
, NULL
, "Replicate single object from a DC", "" },
1232 { "capabilities", RPC_RTYPE_NTSTATUS
, cmd_netlogon_capabilities
, NULL
, &ndr_table_netlogon
, NULL
, "Return Capabilities", "" },