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"
26 #include "rpc_client/cli_netlogon.h"
28 static WERROR
cmd_netlogon_logon_ctrl2(struct rpc_pipe_client
*cli
,
29 TALLOC_CTX
*mem_ctx
, int argc
,
32 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
34 const char *logon_server
= cli
->desthost
;
35 enum netr_LogonControlCode function_code
= NETLOGON_CONTROL_REDISCOVER
;
37 union netr_CONTROL_DATA_INFORMATION data
;
38 union netr_CONTROL_QUERY_INFORMATION query
;
39 const char *domain
= lp_workgroup();
42 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
43 "<level> <domain>\n", argv
[0]);
48 logon_server
= argv
[1];
52 function_code
= atoi(argv
[2]);
56 level
= atoi(argv
[3]);
63 switch (function_code
) {
64 case NETLOGON_CONTROL_REDISCOVER
:
65 case NETLOGON_CONTROL_TC_QUERY
:
72 status
= rpccli_netr_LogonControl2(cli
, mem_ctx
,
79 if (!NT_STATUS_IS_OK(status
)) {
80 return ntstatus_to_werror(status
);
83 if (!W_ERROR_IS_OK(werr
)) {
92 static WERROR
cmd_netlogon_getanydcname(struct rpc_pipe_client
*cli
,
93 TALLOC_CTX
*mem_ctx
, int argc
,
96 const char *dcname
= NULL
;
102 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
106 /* Make sure to wait for our DC's reply */
107 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
108 rpccli_set_timeout(cli
, MAX(old_timeout
, 30000)); /* At least 30 sec */
110 status
= rpccli_netr_GetAnyDCName(cli
, mem_ctx
,
115 rpccli_set_timeout(cli
, old_timeout
);
117 if (!NT_STATUS_IS_OK(status
)) {
118 return ntstatus_to_werror(status
);
121 if (!W_ERROR_IS_OK(werr
)) {
125 /* Display results */
127 printf("%s\n", dcname
);
132 static WERROR
cmd_netlogon_getdcname(struct rpc_pipe_client
*cli
,
133 TALLOC_CTX
*mem_ctx
, int argc
,
136 const char *dcname
= NULL
;
142 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
146 /* Make sure to wait for our DC's reply */
147 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
148 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
150 status
= rpccli_netr_GetDcName(cli
, mem_ctx
,
155 rpccli_set_timeout(cli
, old_timeout
);
157 if (!NT_STATUS_IS_OK(status
)) {
158 return ntstatus_to_werror(status
);
161 if (!W_ERROR_IS_OK(werr
)) {
165 /* Display results */
167 printf("%s\n", dcname
);
172 static WERROR
cmd_netlogon_dsr_getdcname(struct rpc_pipe_client
*cli
,
173 TALLOC_CTX
*mem_ctx
, int argc
,
177 WERROR werr
= WERR_OK
;
178 uint32 flags
= DS_RETURN_DNS_NAME
;
179 const char *server_name
= cli
->desthost
;
180 const char *domain_name
;
181 struct GUID domain_guid
= GUID_zero();
182 struct GUID site_guid
= GUID_zero();
183 struct netr_DsRGetDCNameInfo
*info
= NULL
;
186 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
187 "[site_guid] [flags]\n", argv
[0]);
192 domain_name
= argv
[1];
195 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
201 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[3], &site_guid
))) {
207 sscanf(argv
[4], "%x", &flags
);
209 debug_dsdcinfo_flags(1,flags
);
211 result
= rpccli_netr_DsRGetDCName(cli
, mem_ctx
,
220 if (W_ERROR_IS_OK(werr
)) {
221 d_printf("DsGetDcName gave: %s\n",
222 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
226 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
232 static WERROR
cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client
*cli
,
233 TALLOC_CTX
*mem_ctx
, int argc
,
238 uint32_t flags
= DS_RETURN_DNS_NAME
;
239 const char *server_name
= cli
->desthost
;
240 const char *domain_name
;
241 const char *site_name
= NULL
;
242 struct GUID domain_guid
= GUID_zero();
243 struct netr_DsRGetDCNameInfo
*info
= NULL
;
246 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
247 "[site_name] [flags]\n", argv
[0]);
251 domain_name
= argv
[1];
254 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
264 sscanf(argv
[4], "%x", &flags
);
267 debug_dsdcinfo_flags(1,flags
);
269 status
= rpccli_netr_DsRGetDCNameEx(cli
, mem_ctx
,
277 if (!NT_STATUS_IS_OK(status
)) {
278 return ntstatus_to_werror(status
);
281 if (!W_ERROR_IS_OK(result
)) {
285 d_printf("DsRGetDCNameEx gave %s\n",
286 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
291 static WERROR
cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client
*cli
,
292 TALLOC_CTX
*mem_ctx
, int argc
,
297 uint32_t flags
= DS_RETURN_DNS_NAME
;
298 const char *server_name
= cli
->desthost
;
299 const char *domain_name
= NULL
;
300 const char *client_account
= NULL
;
302 const char *site_name
= NULL
;
303 struct GUID domain_guid
= GUID_zero();
304 struct netr_DsRGetDCNameInfo
*info
= NULL
;
307 fprintf(stderr
, "Usage: %s [client_account] [acb_mask] "
308 "[domain_name] [domain_guid] [site_name] "
309 "[flags]\n", argv
[0]);
314 client_account
= argv
[1];
318 mask
= atoi(argv
[2]);
322 domain_name
= argv
[3];
326 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[4], &domain_guid
))) {
336 sscanf(argv
[6], "%x", &flags
);
339 debug_dsdcinfo_flags(1,flags
);
341 status
= rpccli_netr_DsRGetDCNameEx2(cli
, mem_ctx
,
351 if (!NT_STATUS_IS_OK(status
)) {
352 return ntstatus_to_werror(status
);
355 if (!W_ERROR_IS_OK(result
)) {
359 d_printf("DsRGetDCNameEx2 gave %s\n",
360 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
366 static WERROR
cmd_netlogon_dsr_getsitename(struct rpc_pipe_client
*cli
,
367 TALLOC_CTX
*mem_ctx
, int argc
,
372 const char *sitename
= NULL
;
375 fprintf(stderr
, "Usage: %s computername\n", argv
[0]);
379 status
= rpccli_netr_DsRGetSiteName(cli
, mem_ctx
,
383 if (!NT_STATUS_IS_OK(status
)) {
384 return ntstatus_to_werror(status
);
387 if (!W_ERROR_IS_OK(werr
)) {
388 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
389 nt_errstr(werror_to_ntstatus(werr
)));
393 printf("Computer %s is on Site: %s\n", argv
[1], sitename
);
398 static WERROR
cmd_netlogon_logon_ctrl(struct rpc_pipe_client
*cli
,
399 TALLOC_CTX
*mem_ctx
, int argc
,
402 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
404 const char *logon_server
= cli
->desthost
;
405 enum netr_LogonControlCode function_code
= 1;
407 union netr_CONTROL_QUERY_INFORMATION info
;
410 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
411 "<level>\n", argv
[0]);
416 logon_server
= argv
[1];
420 function_code
= atoi(argv
[2]);
424 level
= atoi(argv
[3]);
427 status
= rpccli_netr_LogonControl(cli
, mem_ctx
,
433 if (!NT_STATUS_IS_OK(status
)) {
434 return ntstatus_to_werror(status
);
437 if (!W_ERROR_IS_OK(werr
)) {
441 /* Display results */
446 /* Display sam synchronisation information */
448 static void display_sam_sync(struct netr_DELTA_ENUM_ARRAY
*r
)
452 for (i
=0; i
< r
->num_deltas
; i
++) {
454 union netr_DELTA_UNION u
= r
->delta_enum
[i
].delta_union
;
455 union netr_DELTA_ID_UNION id
= r
->delta_enum
[i
].delta_id_union
;
457 switch (r
->delta_enum
[i
].delta_type
) {
458 case NETR_DELTA_DOMAIN
:
459 printf("Domain: %s\n",
460 u
.domain
->domain_name
.string
);
462 case NETR_DELTA_GROUP
:
463 printf("Group: %s\n",
464 u
.group
->group_name
.string
);
466 case NETR_DELTA_DELETE_GROUP
:
467 printf("Delete Group: %d\n",
468 u
.delete_account
.unknown
);
470 case NETR_DELTA_RENAME_GROUP
:
471 printf("Rename Group: %s -> %s\n",
472 u
.rename_group
->OldName
.string
,
473 u
.rename_group
->NewName
.string
);
475 case NETR_DELTA_USER
:
476 printf("Account: %s\n",
477 u
.user
->account_name
.string
);
479 case NETR_DELTA_DELETE_USER
:
480 printf("Delete User: %d\n",
483 case NETR_DELTA_RENAME_USER
:
484 printf("Rename user: %s -> %s\n",
485 u
.rename_user
->OldName
.string
,
486 u
.rename_user
->NewName
.string
);
488 case NETR_DELTA_GROUP_MEMBER
:
489 for (j
=0; j
< u
.group_member
->num_rids
; j
++) {
490 printf("rid 0x%x, attrib 0x%08x\n",
491 u
.group_member
->rids
[j
],
492 u
.group_member
->attribs
[j
]);
495 case NETR_DELTA_ALIAS
:
496 printf("Alias: %s\n",
497 u
.alias
->alias_name
.string
);
499 case NETR_DELTA_DELETE_ALIAS
:
500 printf("Delete Alias: %d\n",
501 r
->delta_enum
[i
].delta_id_union
.rid
);
503 case NETR_DELTA_RENAME_ALIAS
:
504 printf("Rename alias: %s -> %s\n",
505 u
.rename_alias
->OldName
.string
,
506 u
.rename_alias
->NewName
.string
);
508 case NETR_DELTA_ALIAS_MEMBER
:
509 for (j
=0; j
< u
.alias_member
->sids
.num_sids
; j
++) {
511 sid_to_fstring(sid_str
,
512 u
.alias_member
->sids
.sids
[j
].sid
);
513 printf("%s\n", sid_str
);
516 case NETR_DELTA_POLICY
:
519 case NETR_DELTA_TRUSTED_DOMAIN
:
520 printf("Trusted Domain: %s\n",
521 u
.trusted_domain
->domain_name
.string
);
523 case NETR_DELTA_DELETE_TRUST
:
524 printf("Delete Trust: %d\n",
525 u
.delete_trust
.unknown
);
527 case NETR_DELTA_ACCOUNT
:
530 case NETR_DELTA_DELETE_ACCOUNT
:
531 printf("Delete Account: %d\n",
532 u
.delete_account
.unknown
);
534 case NETR_DELTA_SECRET
:
537 case NETR_DELTA_DELETE_SECRET
:
538 printf("Delete Secret: %d\n",
539 u
.delete_secret
.unknown
);
541 case NETR_DELTA_DELETE_GROUP2
:
542 printf("Delete Group2: %s\n",
543 u
.delete_group
->account_name
);
545 case NETR_DELTA_DELETE_USER2
:
546 printf("Delete User2: %s\n",
547 u
.delete_user
->account_name
);
549 case NETR_DELTA_MODIFY_COUNT
:
550 printf("sam sequence update: 0x%016llx\n",
551 (unsigned long long) *u
.modified_count
);
554 printf("unknown delta type 0x%02x\n",
555 r
->delta_enum
[i
].delta_type
);
561 /* Perform sam synchronisation */
563 static NTSTATUS
cmd_netlogon_sam_sync(struct rpc_pipe_client
*cli
,
564 TALLOC_CTX
*mem_ctx
, int argc
,
567 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
568 const char *logon_server
= cli
->desthost
;
569 const char *computername
= global_myname();
570 struct netr_Authenticator credential
;
571 struct netr_Authenticator return_authenticator
;
572 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
573 uint16_t restart_state
= 0;
574 uint32_t sync_context
= 0;
577 fprintf(stderr
, "Usage: %s [database_id]\n", argv
[0]);
582 database_id
= atoi(argv
[1]);
585 /* Synchronise sam database */
588 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
590 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
592 result
= rpccli_netr_DatabaseSync2(cli
, mem_ctx
,
596 &return_authenticator
,
603 /* Check returned credentials. */
604 if (!netlogon_creds_client_check(cli
->dc
,
605 &return_authenticator
.cred
)) {
606 DEBUG(0,("credentials chain check failed\n"));
607 return NT_STATUS_ACCESS_DENIED
;
610 if (NT_STATUS_IS_ERR(result
)) {
614 /* Display results */
616 display_sam_sync(delta_enum_array
);
618 TALLOC_FREE(delta_enum_array
);
620 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
625 /* Perform sam delta synchronisation */
627 static NTSTATUS
cmd_netlogon_sam_deltas(struct rpc_pipe_client
*cli
,
628 TALLOC_CTX
*mem_ctx
, int argc
,
631 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
633 const char *logon_server
= cli
->desthost
;
634 const char *computername
= global_myname();
635 struct netr_Authenticator credential
;
636 struct netr_Authenticator return_authenticator
;
637 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
638 uint64_t sequence_num
;
641 fprintf(stderr
, "Usage: %s database_id seqnum\n", argv
[0]);
645 database_id
= atoi(argv
[1]);
648 sequence_num
= tmp
& 0xffff;
651 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
653 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
655 result
= rpccli_netr_DatabaseDeltas(cli
, mem_ctx
,
659 &return_authenticator
,
665 /* Check returned credentials. */
666 if (!netlogon_creds_client_check(cli
->dc
,
667 &return_authenticator
.cred
)) {
668 DEBUG(0,("credentials chain check failed\n"));
669 return NT_STATUS_ACCESS_DENIED
;
672 if (NT_STATUS_IS_ERR(result
)) {
676 /* Display results */
678 display_sam_sync(delta_enum_array
);
680 TALLOC_FREE(delta_enum_array
);
682 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
687 /* Log on a domain user */
689 static NTSTATUS
cmd_netlogon_sam_logon(struct rpc_pipe_client
*cli
,
690 TALLOC_CTX
*mem_ctx
, int argc
,
693 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
694 int logon_type
= NetlogonNetworkInformation
;
695 const char *username
, *password
;
697 uint32 logon_param
= 0;
698 const char *workstation
= NULL
;
700 /* Check arguments */
702 if (argc
< 3 || argc
> 7) {
703 fprintf(stderr
, "Usage: samlogon <username> <password> [workstation]"
704 "[logon_type (1 or 2)] [auth level (2 or 3)] [logon_parameter]\n");
712 workstation
= argv
[3];
715 sscanf(argv
[4], "%i", &logon_type
);
718 sscanf(argv
[5], "%i", &auth_level
);
721 sscanf(argv
[6], "%x", &logon_param
);
723 /* Perform the sam logon */
725 result
= rpccli_netlogon_sam_logon(cli
, mem_ctx
, logon_param
, lp_workgroup(), username
, password
, workstation
, logon_type
);
727 if (!NT_STATUS_IS_OK(result
))
734 /* Change the trust account password */
736 static NTSTATUS
cmd_netlogon_change_trust_pw(struct rpc_pipe_client
*cli
,
737 TALLOC_CTX
*mem_ctx
, int argc
,
740 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
742 /* Check arguments */
745 fprintf(stderr
, "Usage: change_trust_pw");
749 /* Perform the sam logon */
751 result
= trust_pw_find_change_and_store_it(cli
, mem_ctx
,
754 if (!NT_STATUS_IS_OK(result
))
761 static WERROR
cmd_netlogon_gettrustrid(struct rpc_pipe_client
*cli
,
762 TALLOC_CTX
*mem_ctx
, int argc
,
765 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
766 WERROR werr
= WERR_GENERAL_FAILURE
;
767 const char *server_name
= cli
->desthost
;
768 const char *domain_name
= lp_workgroup();
771 if (argc
< 1 || argc
> 3) {
772 fprintf(stderr
, "Usage: %s <server_name> <domain_name>\n",
778 server_name
= argv
[1];
782 domain_name
= argv
[2];
785 status
= rpccli_netr_LogonGetTrustRid(cli
, mem_ctx
,
790 if (!NT_STATUS_IS_OK(status
)) {
794 if (W_ERROR_IS_OK(werr
)) {
795 printf("Rid: %d\n", rid
);
801 static WERROR
cmd_netlogon_dsr_enumtrustdom(struct rpc_pipe_client
*cli
,
802 TALLOC_CTX
*mem_ctx
, int argc
,
805 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
806 WERROR werr
= WERR_GENERAL_FAILURE
;
807 const char *server_name
= cli
->desthost
;
808 uint32_t trust_flags
= NETR_TRUST_FLAG_IN_FOREST
;
809 struct netr_DomainTrustList trusts
;
811 if (argc
< 1 || argc
> 3) {
812 fprintf(stderr
, "Usage: %s <server_name> <trust_flags>\n",
818 server_name
= argv
[1];
822 sscanf(argv
[2], "%x", &trust_flags
);
825 status
= rpccli_netr_DsrEnumerateDomainTrusts(cli
, mem_ctx
,
830 if (!NT_STATUS_IS_OK(status
)) {
834 if (W_ERROR_IS_OK(werr
)) {
837 printf("%d domains returned\n", trusts
.count
);
839 for (i
=0; i
<trusts
.count
; i
++ ) {
841 trusts
.array
[i
].dns_name
,
842 trusts
.array
[i
].netbios_name
);
849 static WERROR
cmd_netlogon_deregisterdnsrecords(struct rpc_pipe_client
*cli
,
850 TALLOC_CTX
*mem_ctx
, int argc
,
853 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
854 WERROR werr
= WERR_GENERAL_FAILURE
;
855 const char *server_name
= cli
->desthost
;
856 const char *domain
= lp_workgroup();
857 const char *dns_host
= NULL
;
859 if (argc
< 1 || argc
> 4) {
860 fprintf(stderr
, "Usage: %s <server_name> <domain_name> "
861 "<dns_host>\n", argv
[0]);
866 server_name
= argv
[1];
877 status
= rpccli_netr_DsrDeregisterDNSHostRecords(cli
, mem_ctx
,
884 if (!NT_STATUS_IS_OK(status
)) {
888 if (W_ERROR_IS_OK(werr
)) {
895 static WERROR
cmd_netlogon_dsr_getforesttrustinfo(struct rpc_pipe_client
*cli
,
896 TALLOC_CTX
*mem_ctx
, int argc
,
899 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
900 WERROR werr
= WERR_GENERAL_FAILURE
;
901 const char *server_name
= cli
->desthost
;
902 const char *trusted_domain_name
= NULL
;
903 struct lsa_ForestTrustInformation
*info
= NULL
;
906 if (argc
< 1 || argc
> 4) {
907 fprintf(stderr
, "Usage: %s <server_name> <trusted_domain_name> "
908 "<flags>\n", argv
[0]);
913 server_name
= argv
[1];
917 trusted_domain_name
= argv
[2];
921 sscanf(argv
[3], "%x", &flags
);
924 status
= rpccli_netr_DsRGetForestTrustInformation(cli
, mem_ctx
,
930 if (!NT_STATUS_IS_OK(status
)) {
934 if (W_ERROR_IS_OK(werr
)) {
941 static WERROR
cmd_netlogon_enumtrusteddomains(struct rpc_pipe_client
*cli
,
942 TALLOC_CTX
*mem_ctx
, int argc
,
945 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
946 WERROR werr
= WERR_GENERAL_FAILURE
;
947 const char *server_name
= cli
->desthost
;
948 struct netr_Blob blob
;
951 if (argc
< 1 || argc
> 3) {
952 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
957 server_name
= argv
[1];
960 status
= rpccli_netr_NetrEnumerateTrustedDomains(cli
, mem_ctx
,
964 if (!NT_STATUS_IS_OK(status
)) {
968 if (W_ERROR_IS_OK(werr
)) {
970 dump_data(1, blob
.data
, blob
.length
);
976 static WERROR
cmd_netlogon_enumtrusteddomainsex(struct rpc_pipe_client
*cli
,
977 TALLOC_CTX
*mem_ctx
, int argc
,
980 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
981 WERROR werr
= WERR_GENERAL_FAILURE
;
982 const char *server_name
= cli
->desthost
;
983 struct netr_DomainTrustList list
;
985 if (argc
< 1 || argc
> 3) {
986 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
991 server_name
= argv
[1];
994 status
= rpccli_netr_NetrEnumerateTrustedDomainsEx(cli
, mem_ctx
,
998 if (!NT_STATUS_IS_OK(status
)) {
1002 if (W_ERROR_IS_OK(werr
)) {
1003 printf("success\n");
1009 static WERROR
cmd_netlogon_getdcsitecoverage(struct rpc_pipe_client
*cli
,
1010 TALLOC_CTX
*mem_ctx
, int argc
,
1013 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1014 WERROR werr
= WERR_GENERAL_FAILURE
;
1015 const char *server_name
= cli
->desthost
;
1016 struct DcSitesCtr
*ctr
= NULL
;
1018 if (argc
< 1 || argc
> 3) {
1019 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1024 server_name
= argv
[1];
1027 status
= rpccli_netr_DsrGetDcSiteCoverageW(cli
, mem_ctx
,
1031 if (!NT_STATUS_IS_OK(status
)) {
1035 if (W_ERROR_IS_OK(werr
) && ctr
->num_sites
) {
1037 printf("sites covered by this DC: %d\n", ctr
->num_sites
);
1038 for (i
=0; i
<ctr
->num_sites
; i
++) {
1039 printf("%s\n", ctr
->sites
[i
].string
);
1046 static NTSTATUS
cmd_netlogon_database_redo(struct rpc_pipe_client
*cli
,
1047 TALLOC_CTX
*mem_ctx
, int argc
,
1050 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1051 const char *server_name
= cli
->desthost
;
1052 uint32_t neg_flags
= NETLOGON_NEG_AUTH2_ADS_FLAGS
;
1053 struct netr_Authenticator clnt_creds
, srv_cred
;
1054 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1055 unsigned char trust_passwd_hash
[16];
1056 enum netr_SchannelType sec_channel_type
= 0;
1057 struct netr_ChangeLogEntry e
;
1061 fprintf(stderr
, "Usage: %s <user rid>\n", argv
[0]);
1062 return NT_STATUS_OK
;
1066 sscanf(argv
[1], "%d", &rid
);
1069 if (!secrets_fetch_trust_account_password(lp_workgroup(),
1071 NULL
, &sec_channel_type
)) {
1072 return NT_STATUS_UNSUCCESSFUL
;
1075 status
= rpccli_netlogon_setup_creds(cli
,
1076 server_name
, /* server name */
1077 lp_workgroup(), /* domain */
1078 global_myname(), /* client name */
1079 global_myname(), /* machine account name */
1084 if (!NT_STATUS_IS_OK(status
)) {
1088 netlogon_creds_client_authenticator(cli
->dc
, &clnt_creds
);
1093 e
.db_index
= SAM_DATABASE_DOMAIN
;
1094 e
.delta_type
= NETR_DELTA_USER
;
1096 status
= rpccli_netr_DatabaseRedo(cli
, mem_ctx
,
1102 0, /* is calculated automatically */
1105 if (!netlogon_creds_client_check(cli
->dc
, &srv_cred
.cred
)) {
1106 DEBUG(0,("credentials chain check failed\n"));
1107 return NT_STATUS_ACCESS_DENIED
;
1113 static NTSTATUS
cmd_netlogon_capabilities(struct rpc_pipe_client
*cli
,
1114 TALLOC_CTX
*mem_ctx
, int argc
,
1117 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1118 struct netr_Authenticator credential
;
1119 struct netr_Authenticator return_authenticator
;
1120 union netr_Capabilities capabilities
;
1124 fprintf(stderr
, "Usage: %s <level>\n", argv
[0]);
1125 return NT_STATUS_OK
;
1129 level
= atoi(argv
[1]);
1132 ZERO_STRUCT(return_authenticator
);
1134 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
1136 status
= rpccli_netr_LogonGetCapabilities(cli
, mem_ctx
,
1140 &return_authenticator
,
1144 if (!netlogon_creds_client_check(cli
->dc
,
1145 &return_authenticator
.cred
)) {
1146 DEBUG(0,("credentials chain check failed\n"));
1147 return NT_STATUS_ACCESS_DENIED
;
1150 printf("capabilities: 0x%08x\n", capabilities
.server_capabilities
);
1155 /* List of commands exported by this module */
1157 struct cmd_set netlogon_commands
[] = {
1161 { "logonctrl2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl2
, &ndr_table_netlogon
.syntax_id
, NULL
, "Logon Control 2", "" },
1162 { "getanydcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getanydcname
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted DC name", "" },
1163 { "getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcname
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted PDC name", "" },
1164 { "dsr_getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcname
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted DC name", "" },
1165 { "dsr_getdcnameex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted DC name", "" },
1166 { "dsr_getdcnameex2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex2
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trusted DC name", "" },
1167 { "dsr_getsitename", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getsitename
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get sitename", "" },
1168 { "dsr_getforesttrustinfo", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getforesttrustinfo
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get Forest Trust Info", "" },
1169 { "logonctrl", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl
, &ndr_table_netlogon
.syntax_id
, NULL
, "Logon Control", "" },
1170 { "samsync", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_sync
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Sam Synchronisation", "" },
1171 { "samdeltas", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_deltas
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Query Sam Deltas", "" },
1172 { "samlogon", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_logon
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Sam Logon", "" },
1173 { "change_trust_pw", RPC_RTYPE_NTSTATUS
, cmd_netlogon_change_trust_pw
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Change Trust Account Password", "" },
1174 { "gettrustrid", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_gettrustrid
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get trust rid", "" },
1175 { "dsr_enumtrustdom", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
.syntax_id
, NULL
, "Enumerate trusted domains", "" },
1176 { "dsenumdomtrusts", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
.syntax_id
, NULL
, "Enumerate all trusted domains in an AD forest", "" },
1177 { "deregisterdnsrecords", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_deregisterdnsrecords
, &ndr_table_netlogon
.syntax_id
, NULL
, "Deregister DNS records", "" },
1178 { "netrenumtrusteddomains", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_enumtrusteddomains
, &ndr_table_netlogon
.syntax_id
, NULL
, "Enumerate trusted domains", "" },
1179 { "netrenumtrusteddomainsex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_enumtrusteddomainsex
, &ndr_table_netlogon
.syntax_id
, NULL
, "Enumerate trusted domains", "" },
1180 { "getdcsitecoverage", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcsitecoverage
, &ndr_table_netlogon
.syntax_id
, NULL
, "Get the Site-Coverage from a DC", "" },
1181 { "database_redo", RPC_RTYPE_NTSTATUS
, cmd_netlogon_database_redo
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Replicate single object from a DC", "" },
1182 { "capabilities", RPC_RTYPE_NTSTATUS
, cmd_netlogon_capabilities
, NULL
, &ndr_table_netlogon
.syntax_id
, NULL
, "Return Capabilities", "" },