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/cli_netlogon.h"
27 static WERROR
cmd_netlogon_logon_ctrl2(struct rpc_pipe_client
*cli
,
28 TALLOC_CTX
*mem_ctx
, int argc
,
31 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
33 const char *logon_server
= cli
->desthost
;
34 enum netr_LogonControlCode function_code
= NETLOGON_CONTROL_REDISCOVER
;
36 union netr_CONTROL_DATA_INFORMATION data
;
37 union netr_CONTROL_QUERY_INFORMATION query
;
38 const char *domain
= lp_workgroup();
41 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
42 "<level> <domain>\n", argv
[0]);
47 logon_server
= argv
[1];
51 function_code
= atoi(argv
[2]);
55 level
= atoi(argv
[3]);
62 switch (function_code
) {
63 case NETLOGON_CONTROL_REDISCOVER
:
64 case NETLOGON_CONTROL_TC_QUERY
:
71 status
= rpccli_netr_LogonControl2(cli
, mem_ctx
,
78 if (!NT_STATUS_IS_OK(status
)) {
79 return ntstatus_to_werror(status
);
82 if (!W_ERROR_IS_OK(werr
)) {
91 static WERROR
cmd_netlogon_getanydcname(struct rpc_pipe_client
*cli
,
92 TALLOC_CTX
*mem_ctx
, int argc
,
95 const char *dcname
= NULL
;
101 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
105 /* Make sure to wait for our DC's reply */
106 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
107 rpccli_set_timeout(cli
, MAX(old_timeout
, 30000)); /* At least 30 sec */
109 status
= rpccli_netr_GetAnyDCName(cli
, mem_ctx
,
114 rpccli_set_timeout(cli
, old_timeout
);
116 if (!NT_STATUS_IS_OK(status
)) {
117 return ntstatus_to_werror(status
);
120 if (!W_ERROR_IS_OK(werr
)) {
124 /* Display results */
126 printf("%s\n", dcname
);
131 static WERROR
cmd_netlogon_getdcname(struct rpc_pipe_client
*cli
,
132 TALLOC_CTX
*mem_ctx
, int argc
,
135 const char *dcname
= NULL
;
141 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
145 /* Make sure to wait for our DC's reply */
146 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
147 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
149 status
= rpccli_netr_GetDcName(cli
, mem_ctx
,
154 rpccli_set_timeout(cli
, old_timeout
);
156 if (!NT_STATUS_IS_OK(status
)) {
157 return ntstatus_to_werror(status
);
160 if (!W_ERROR_IS_OK(werr
)) {
164 /* Display results */
166 printf("%s\n", dcname
);
171 static WERROR
cmd_netlogon_dsr_getdcname(struct rpc_pipe_client
*cli
,
172 TALLOC_CTX
*mem_ctx
, int argc
,
176 WERROR werr
= WERR_OK
;
177 uint32 flags
= DS_RETURN_DNS_NAME
;
178 const char *server_name
= cli
->desthost
;
179 const char *domain_name
;
180 struct GUID domain_guid
= GUID_zero();
181 struct GUID site_guid
= GUID_zero();
182 struct netr_DsRGetDCNameInfo
*info
= NULL
;
185 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
186 "[site_guid] [flags]\n", argv
[0]);
191 domain_name
= argv
[1];
194 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
200 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[3], &site_guid
))) {
206 sscanf(argv
[4], "%x", &flags
);
208 debug_dsdcinfo_flags(1,flags
);
210 result
= rpccli_netr_DsRGetDCName(cli
, mem_ctx
,
219 if (W_ERROR_IS_OK(werr
)) {
220 d_printf("DsGetDcName gave: %s\n",
221 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
225 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
231 static WERROR
cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client
*cli
,
232 TALLOC_CTX
*mem_ctx
, int argc
,
237 uint32_t flags
= DS_RETURN_DNS_NAME
;
238 const char *server_name
= cli
->desthost
;
239 const char *domain_name
;
240 const char *site_name
= NULL
;
241 struct GUID domain_guid
= GUID_zero();
242 struct netr_DsRGetDCNameInfo
*info
= NULL
;
245 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
246 "[site_name] [flags]\n", argv
[0]);
250 domain_name
= argv
[1];
253 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
263 sscanf(argv
[4], "%x", &flags
);
266 debug_dsdcinfo_flags(1,flags
);
268 status
= rpccli_netr_DsRGetDCNameEx(cli
, mem_ctx
,
276 if (!NT_STATUS_IS_OK(status
)) {
277 return ntstatus_to_werror(status
);
280 if (!W_ERROR_IS_OK(result
)) {
284 d_printf("DsRGetDCNameEx gave %s\n",
285 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
290 static WERROR
cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client
*cli
,
291 TALLOC_CTX
*mem_ctx
, int argc
,
296 uint32_t flags
= DS_RETURN_DNS_NAME
;
297 const char *server_name
= cli
->desthost
;
298 const char *domain_name
= NULL
;
299 const char *client_account
= NULL
;
301 const char *site_name
= NULL
;
302 struct GUID domain_guid
= GUID_zero();
303 struct netr_DsRGetDCNameInfo
*info
= NULL
;
306 fprintf(stderr
, "Usage: %s [client_account] [acb_mask] "
307 "[domain_name] [domain_guid] [site_name] "
308 "[flags]\n", argv
[0]);
313 client_account
= argv
[1];
317 mask
= atoi(argv
[2]);
321 domain_name
= argv
[3];
325 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[4], &domain_guid
))) {
335 sscanf(argv
[6], "%x", &flags
);
338 debug_dsdcinfo_flags(1,flags
);
340 status
= rpccli_netr_DsRGetDCNameEx2(cli
, mem_ctx
,
350 if (!NT_STATUS_IS_OK(status
)) {
351 return ntstatus_to_werror(status
);
354 if (!W_ERROR_IS_OK(result
)) {
358 d_printf("DsRGetDCNameEx2 gave %s\n",
359 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
365 static WERROR
cmd_netlogon_dsr_getsitename(struct rpc_pipe_client
*cli
,
366 TALLOC_CTX
*mem_ctx
, int argc
,
371 const char *sitename
= NULL
;
374 fprintf(stderr
, "Usage: %s computername\n", argv
[0]);
378 status
= rpccli_netr_DsRGetSiteName(cli
, mem_ctx
,
382 if (!NT_STATUS_IS_OK(status
)) {
383 return ntstatus_to_werror(status
);
386 if (!W_ERROR_IS_OK(werr
)) {
387 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
388 nt_errstr(werror_to_ntstatus(werr
)));
392 printf("Computer %s is on Site: %s\n", argv
[1], sitename
);
397 static WERROR
cmd_netlogon_logon_ctrl(struct rpc_pipe_client
*cli
,
398 TALLOC_CTX
*mem_ctx
, int argc
,
401 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
403 const char *logon_server
= cli
->desthost
;
404 enum netr_LogonControlCode function_code
= 1;
406 union netr_CONTROL_QUERY_INFORMATION info
;
409 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
410 "<level>\n", argv
[0]);
415 logon_server
= argv
[1];
419 function_code
= atoi(argv
[2]);
423 level
= atoi(argv
[3]);
426 status
= rpccli_netr_LogonControl(cli
, mem_ctx
,
432 if (!NT_STATUS_IS_OK(status
)) {
433 return ntstatus_to_werror(status
);
436 if (!W_ERROR_IS_OK(werr
)) {
440 /* Display results */
445 /* Display sam synchronisation information */
447 static void display_sam_sync(struct netr_DELTA_ENUM_ARRAY
*r
)
451 for (i
=0; i
< r
->num_deltas
; i
++) {
453 union netr_DELTA_UNION u
= r
->delta_enum
[i
].delta_union
;
454 union netr_DELTA_ID_UNION id
= r
->delta_enum
[i
].delta_id_union
;
456 switch (r
->delta_enum
[i
].delta_type
) {
457 case NETR_DELTA_DOMAIN
:
458 printf("Domain: %s\n",
459 u
.domain
->domain_name
.string
);
461 case NETR_DELTA_GROUP
:
462 printf("Group: %s\n",
463 u
.group
->group_name
.string
);
465 case NETR_DELTA_DELETE_GROUP
:
466 printf("Delete Group: %d\n",
467 u
.delete_account
.unknown
);
469 case NETR_DELTA_RENAME_GROUP
:
470 printf("Rename Group: %s -> %s\n",
471 u
.rename_group
->OldName
.string
,
472 u
.rename_group
->NewName
.string
);
474 case NETR_DELTA_USER
:
475 printf("Account: %s\n",
476 u
.user
->account_name
.string
);
478 case NETR_DELTA_DELETE_USER
:
479 printf("Delete User: %d\n",
482 case NETR_DELTA_RENAME_USER
:
483 printf("Rename user: %s -> %s\n",
484 u
.rename_user
->OldName
.string
,
485 u
.rename_user
->NewName
.string
);
487 case NETR_DELTA_GROUP_MEMBER
:
488 for (j
=0; j
< u
.group_member
->num_rids
; j
++) {
489 printf("rid 0x%x, attrib 0x%08x\n",
490 u
.group_member
->rids
[j
],
491 u
.group_member
->attribs
[j
]);
494 case NETR_DELTA_ALIAS
:
495 printf("Alias: %s\n",
496 u
.alias
->alias_name
.string
);
498 case NETR_DELTA_DELETE_ALIAS
:
499 printf("Delete Alias: %d\n",
500 r
->delta_enum
[i
].delta_id_union
.rid
);
502 case NETR_DELTA_RENAME_ALIAS
:
503 printf("Rename alias: %s -> %s\n",
504 u
.rename_alias
->OldName
.string
,
505 u
.rename_alias
->NewName
.string
);
507 case NETR_DELTA_ALIAS_MEMBER
:
508 for (j
=0; j
< u
.alias_member
->sids
.num_sids
; j
++) {
510 sid_to_fstring(sid_str
,
511 u
.alias_member
->sids
.sids
[j
].sid
);
512 printf("%s\n", sid_str
);
515 case NETR_DELTA_POLICY
:
518 case NETR_DELTA_TRUSTED_DOMAIN
:
519 printf("Trusted Domain: %s\n",
520 u
.trusted_domain
->domain_name
.string
);
522 case NETR_DELTA_DELETE_TRUST
:
523 printf("Delete Trust: %d\n",
524 u
.delete_trust
.unknown
);
526 case NETR_DELTA_ACCOUNT
:
529 case NETR_DELTA_DELETE_ACCOUNT
:
530 printf("Delete Account: %d\n",
531 u
.delete_account
.unknown
);
533 case NETR_DELTA_SECRET
:
536 case NETR_DELTA_DELETE_SECRET
:
537 printf("Delete Secret: %d\n",
538 u
.delete_secret
.unknown
);
540 case NETR_DELTA_DELETE_GROUP2
:
541 printf("Delete Group2: %s\n",
542 u
.delete_group
->account_name
);
544 case NETR_DELTA_DELETE_USER2
:
545 printf("Delete User2: %s\n",
546 u
.delete_user
->account_name
);
548 case NETR_DELTA_MODIFY_COUNT
:
549 printf("sam sequence update: 0x%016llx\n",
550 (unsigned long long) *u
.modified_count
);
553 printf("unknown delta type 0x%02x\n",
554 r
->delta_enum
[i
].delta_type
);
560 /* Perform sam synchronisation */
562 static NTSTATUS
cmd_netlogon_sam_sync(struct rpc_pipe_client
*cli
,
563 TALLOC_CTX
*mem_ctx
, int argc
,
566 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
567 const char *logon_server
= cli
->desthost
;
568 const char *computername
= global_myname();
569 struct netr_Authenticator credential
;
570 struct netr_Authenticator return_authenticator
;
571 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
572 uint16_t restart_state
= 0;
573 uint32_t sync_context
= 0;
576 fprintf(stderr
, "Usage: %s [database_id]\n", argv
[0]);
581 database_id
= atoi(argv
[1]);
584 /* Synchronise sam database */
587 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
589 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
591 result
= rpccli_netr_DatabaseSync2(cli
, mem_ctx
,
595 &return_authenticator
,
602 /* Check returned credentials. */
603 if (!netlogon_creds_client_check(cli
->dc
,
604 &return_authenticator
.cred
)) {
605 DEBUG(0,("credentials chain check failed\n"));
606 return NT_STATUS_ACCESS_DENIED
;
609 if (NT_STATUS_IS_ERR(result
)) {
613 /* Display results */
615 display_sam_sync(delta_enum_array
);
617 TALLOC_FREE(delta_enum_array
);
619 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
624 /* Perform sam delta synchronisation */
626 static NTSTATUS
cmd_netlogon_sam_deltas(struct rpc_pipe_client
*cli
,
627 TALLOC_CTX
*mem_ctx
, int argc
,
630 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
632 const char *logon_server
= cli
->desthost
;
633 const char *computername
= global_myname();
634 struct netr_Authenticator credential
;
635 struct netr_Authenticator return_authenticator
;
636 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
637 uint64_t sequence_num
;
640 fprintf(stderr
, "Usage: %s database_id seqnum\n", argv
[0]);
644 database_id
= atoi(argv
[1]);
647 sequence_num
= tmp
& 0xffff;
650 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
652 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
654 result
= rpccli_netr_DatabaseDeltas(cli
, mem_ctx
,
658 &return_authenticator
,
664 /* Check returned credentials. */
665 if (!netlogon_creds_client_check(cli
->dc
,
666 &return_authenticator
.cred
)) {
667 DEBUG(0,("credentials chain check failed\n"));
668 return NT_STATUS_ACCESS_DENIED
;
671 if (NT_STATUS_IS_ERR(result
)) {
675 /* Display results */
677 display_sam_sync(delta_enum_array
);
679 TALLOC_FREE(delta_enum_array
);
681 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
686 /* Log on a domain user */
688 static NTSTATUS
cmd_netlogon_sam_logon(struct rpc_pipe_client
*cli
,
689 TALLOC_CTX
*mem_ctx
, int argc
,
692 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
693 int logon_type
= NetlogonNetworkInformation
;
694 const char *username
, *password
;
696 uint32 logon_param
= 0;
697 const char *workstation
= NULL
;
699 /* Check arguments */
701 if (argc
< 3 || argc
> 7) {
702 fprintf(stderr
, "Usage: samlogon <username> <password> [workstation]"
703 "[logon_type (1 or 2)] [auth level (2 or 3)] [logon_parameter]\n");
711 workstation
= argv
[3];
714 sscanf(argv
[4], "%i", &logon_type
);
717 sscanf(argv
[5], "%i", &auth_level
);
720 sscanf(argv
[6], "%x", &logon_param
);
722 /* Perform the sam logon */
724 result
= rpccli_netlogon_sam_logon(cli
, mem_ctx
, logon_param
, lp_workgroup(), username
, password
, workstation
, logon_type
);
726 if (!NT_STATUS_IS_OK(result
))
733 /* Change the trust account password */
735 static NTSTATUS
cmd_netlogon_change_trust_pw(struct rpc_pipe_client
*cli
,
736 TALLOC_CTX
*mem_ctx
, int argc
,
739 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
741 /* Check arguments */
744 fprintf(stderr
, "Usage: change_trust_pw");
748 /* Perform the sam logon */
750 result
= trust_pw_find_change_and_store_it(cli
, mem_ctx
,
753 if (!NT_STATUS_IS_OK(result
))
760 static WERROR
cmd_netlogon_gettrustrid(struct rpc_pipe_client
*cli
,
761 TALLOC_CTX
*mem_ctx
, int argc
,
764 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
765 WERROR werr
= WERR_GENERAL_FAILURE
;
766 const char *server_name
= cli
->desthost
;
767 const char *domain_name
= lp_workgroup();
770 if (argc
< 1 || argc
> 3) {
771 fprintf(stderr
, "Usage: %s <server_name> <domain_name>\n",
777 server_name
= argv
[1];
781 domain_name
= argv
[2];
784 status
= rpccli_netr_LogonGetTrustRid(cli
, mem_ctx
,
789 if (!NT_STATUS_IS_OK(status
)) {
793 if (W_ERROR_IS_OK(werr
)) {
794 printf("Rid: %d\n", rid
);
800 static WERROR
cmd_netlogon_dsr_enumtrustdom(struct rpc_pipe_client
*cli
,
801 TALLOC_CTX
*mem_ctx
, int argc
,
804 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
805 WERROR werr
= WERR_GENERAL_FAILURE
;
806 const char *server_name
= cli
->desthost
;
807 uint32_t trust_flags
= NETR_TRUST_FLAG_IN_FOREST
;
808 struct netr_DomainTrustList trusts
;
810 if (argc
< 1 || argc
> 3) {
811 fprintf(stderr
, "Usage: %s <server_name> <trust_flags>\n",
817 server_name
= argv
[1];
821 sscanf(argv
[2], "%x", &trust_flags
);
824 status
= rpccli_netr_DsrEnumerateDomainTrusts(cli
, mem_ctx
,
829 if (!NT_STATUS_IS_OK(status
)) {
833 if (W_ERROR_IS_OK(werr
)) {
836 printf("%d domains returned\n", trusts
.count
);
838 for (i
=0; i
<trusts
.count
; i
++ ) {
840 trusts
.array
[i
].dns_name
,
841 trusts
.array
[i
].netbios_name
);
848 static WERROR
cmd_netlogon_deregisterdnsrecords(struct rpc_pipe_client
*cli
,
849 TALLOC_CTX
*mem_ctx
, int argc
,
852 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
853 WERROR werr
= WERR_GENERAL_FAILURE
;
854 const char *server_name
= cli
->desthost
;
855 const char *domain
= lp_workgroup();
856 const char *dns_host
= NULL
;
858 if (argc
< 1 || argc
> 4) {
859 fprintf(stderr
, "Usage: %s <server_name> <domain_name> "
860 "<dns_host>\n", argv
[0]);
865 server_name
= argv
[1];
876 status
= rpccli_netr_DsrDeregisterDNSHostRecords(cli
, mem_ctx
,
883 if (!NT_STATUS_IS_OK(status
)) {
887 if (W_ERROR_IS_OK(werr
)) {
894 static WERROR
cmd_netlogon_dsr_getforesttrustinfo(struct rpc_pipe_client
*cli
,
895 TALLOC_CTX
*mem_ctx
, int argc
,
898 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
899 WERROR werr
= WERR_GENERAL_FAILURE
;
900 const char *server_name
= cli
->desthost
;
901 const char *trusted_domain_name
= NULL
;
902 struct lsa_ForestTrustInformation
*info
= NULL
;
905 if (argc
< 1 || argc
> 4) {
906 fprintf(stderr
, "Usage: %s <server_name> <trusted_domain_name> "
907 "<flags>\n", argv
[0]);
912 server_name
= argv
[1];
916 trusted_domain_name
= argv
[2];
920 sscanf(argv
[3], "%x", &flags
);
923 status
= rpccli_netr_DsRGetForestTrustInformation(cli
, mem_ctx
,
929 if (!NT_STATUS_IS_OK(status
)) {
933 if (W_ERROR_IS_OK(werr
)) {
940 static WERROR
cmd_netlogon_enumtrusteddomains(struct rpc_pipe_client
*cli
,
941 TALLOC_CTX
*mem_ctx
, int argc
,
944 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
945 WERROR werr
= WERR_GENERAL_FAILURE
;
946 const char *server_name
= cli
->desthost
;
947 struct netr_Blob blob
;
950 if (argc
< 1 || argc
> 3) {
951 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
956 server_name
= argv
[1];
959 status
= rpccli_netr_NetrEnumerateTrustedDomains(cli
, mem_ctx
,
963 if (!NT_STATUS_IS_OK(status
)) {
967 if (W_ERROR_IS_OK(werr
)) {
969 dump_data(1, blob
.data
, blob
.length
);
975 static WERROR
cmd_netlogon_enumtrusteddomainsex(struct rpc_pipe_client
*cli
,
976 TALLOC_CTX
*mem_ctx
, int argc
,
979 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
980 WERROR werr
= WERR_GENERAL_FAILURE
;
981 const char *server_name
= cli
->desthost
;
982 struct netr_DomainTrustList list
;
984 if (argc
< 1 || argc
> 3) {
985 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
990 server_name
= argv
[1];
993 status
= rpccli_netr_NetrEnumerateTrustedDomainsEx(cli
, mem_ctx
,
997 if (!NT_STATUS_IS_OK(status
)) {
1001 if (W_ERROR_IS_OK(werr
)) {
1002 printf("success\n");
1008 static WERROR
cmd_netlogon_getdcsitecoverage(struct rpc_pipe_client
*cli
,
1009 TALLOC_CTX
*mem_ctx
, int argc
,
1012 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1013 WERROR werr
= WERR_GENERAL_FAILURE
;
1014 const char *server_name
= cli
->desthost
;
1015 struct DcSitesCtr
*ctr
= NULL
;
1017 if (argc
< 1 || argc
> 3) {
1018 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1023 server_name
= argv
[1];
1026 status
= rpccli_netr_DsrGetDcSiteCoverageW(cli
, mem_ctx
,
1030 if (!NT_STATUS_IS_OK(status
)) {
1034 if (W_ERROR_IS_OK(werr
) && ctr
->num_sites
) {
1036 printf("sites covered by this DC: %d\n", ctr
->num_sites
);
1037 for (i
=0; i
<ctr
->num_sites
; i
++) {
1038 printf("%s\n", ctr
->sites
[i
].string
);
1045 static NTSTATUS
cmd_netlogon_database_redo(struct rpc_pipe_client
*cli
,
1046 TALLOC_CTX
*mem_ctx
, int argc
,
1049 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1050 const char *server_name
= cli
->desthost
;
1051 uint32_t neg_flags
= NETLOGON_NEG_AUTH2_ADS_FLAGS
;
1052 struct netr_Authenticator clnt_creds
, srv_cred
;
1053 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1054 unsigned char trust_passwd_hash
[16];
1055 enum netr_SchannelType sec_channel_type
= 0;
1056 struct netr_ChangeLogEntry e
;
1060 fprintf(stderr
, "Usage: %s <user rid>\n", argv
[0]);
1061 return NT_STATUS_OK
;
1065 sscanf(argv
[1], "%d", &rid
);
1068 if (!secrets_fetch_trust_account_password(lp_workgroup(),
1070 NULL
, &sec_channel_type
)) {
1071 return NT_STATUS_UNSUCCESSFUL
;
1074 status
= rpccli_netlogon_setup_creds(cli
,
1075 server_name
, /* server name */
1076 lp_workgroup(), /* domain */
1077 global_myname(), /* client name */
1078 global_myname(), /* machine account name */
1083 if (!NT_STATUS_IS_OK(status
)) {
1087 netlogon_creds_client_authenticator(cli
->dc
, &clnt_creds
);
1092 e
.db_index
= SAM_DATABASE_DOMAIN
;
1093 e
.delta_type
= NETR_DELTA_USER
;
1095 status
= rpccli_netr_DatabaseRedo(cli
, mem_ctx
,
1101 0, /* is calculated automatically */
1104 if (!netlogon_creds_client_check(cli
->dc
, &srv_cred
.cred
)) {
1105 DEBUG(0,("credentials chain check failed\n"));
1106 return NT_STATUS_ACCESS_DENIED
;
1112 static NTSTATUS
cmd_netlogon_capabilities(struct rpc_pipe_client
*cli
,
1113 TALLOC_CTX
*mem_ctx
, int argc
,
1116 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1117 struct netr_Authenticator credential
;
1118 struct netr_Authenticator return_authenticator
;
1119 union netr_Capabilities capabilities
;
1123 fprintf(stderr
, "Usage: %s <level>\n", argv
[0]);
1124 return NT_STATUS_OK
;
1128 level
= atoi(argv
[1]);
1131 ZERO_STRUCT(return_authenticator
);
1133 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
1135 status
= rpccli_netr_LogonGetCapabilities(cli
, mem_ctx
,
1139 &return_authenticator
,
1143 if (!netlogon_creds_client_check(cli
->dc
,
1144 &return_authenticator
.cred
)) {
1145 DEBUG(0,("credentials chain check failed\n"));
1146 return NT_STATUS_ACCESS_DENIED
;
1149 printf("capabilities: 0x%08x\n", capabilities
.server_capabilities
);
1154 /* List of commands exported by this module */
1156 struct cmd_set netlogon_commands
[] = {
1160 { "logonctrl2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl2
, &ndr_table_netlogon
.syntax_id
, NULL
, "Logon Control 2", "" },
1161 { "getanydcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getanydcname
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted DC name", "" },
1162 { "getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcname
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted PDC name", "" },
1163 { "dsr_getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcname
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted DC name", "" },
1164 { "dsr_getdcnameex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted DC name", "" },
1165 { "dsr_getdcnameex2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex2
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted DC name", "" },
1166 { "dsr_getsitename", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getsitename
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get sitename", "" },
1167 { "dsr_getforesttrustinfo", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getforesttrustinfo
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get Forest Trust Info", "" },
1168 { "logonctrl", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl
, &ndr_table_netlogon
.syntax_id
, NULL
, "Logon Control", "" },
1169 { "samsync", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_sync
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Sam Synchronisation", "" },
1170 { "samdeltas", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_deltas
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Query Sam Deltas", "" },
1171 { "samlogon", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_logon
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Sam Logon", "" },
1172 { "change_trust_pw", RPC_RTYPE_NTSTATUS
, cmd_netlogon_change_trust_pw
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Change Trust Account Password", "" },
1173 { "gettrustrid", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_gettrustrid
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trust rid", "" },
1174 { "dsr_enumtrustdom", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
.syntax_id
, NULL
, "Enumerate trusted domains", "" },
1175 { "dsenumdomtrusts", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
.syntax_id
, NULL
, "Enumerate all trusted domains in an AD forest", "" },
1176 { "deregisterdnsrecords", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_deregisterdnsrecords
, &ndr_table_netlogon
.syntax_id
, NULL
, "Deregister DNS records", "" },
1177 { "netrenumtrusteddomains", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_enumtrusteddomains
, &ndr_table_netlogon
.syntax_id
, NULL
, "Enumerate trusted domains", "" },
1178 { "netrenumtrusteddomainsex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_enumtrusteddomainsex
, &ndr_table_netlogon
.syntax_id
, NULL
, "Enumerate trusted domains", "" },
1179 { "getdcsitecoverage", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcsitecoverage
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get the Site-Coverage from a DC", "" },
1180 { "database_redo", RPC_RTYPE_NTSTATUS
, cmd_netlogon_database_redo
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Replicate single object from a DC", "" },
1181 { "capabilities", RPC_RTYPE_NTSTATUS
, cmd_netlogon_capabilities
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Return Capabilities", "" },