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"
26 static WERROR
cmd_netlogon_logon_ctrl2(struct rpc_pipe_client
*cli
,
27 TALLOC_CTX
*mem_ctx
, int argc
,
30 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
32 const char *logon_server
= cli
->desthost
;
33 enum netr_LogonControlCode function_code
= NETLOGON_CONTROL_REDISCOVER
;
35 union netr_CONTROL_DATA_INFORMATION data
;
36 union netr_CONTROL_QUERY_INFORMATION query
;
37 const char *domain
= lp_workgroup();
40 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
41 "<level> <domain>\n", argv
[0]);
46 logon_server
= argv
[1];
50 function_code
= atoi(argv
[2]);
54 level
= atoi(argv
[3]);
61 switch (function_code
) {
62 case NETLOGON_CONTROL_REDISCOVER
:
63 case NETLOGON_CONTROL_TC_QUERY
:
70 status
= rpccli_netr_LogonControl2(cli
, mem_ctx
,
77 if (!NT_STATUS_IS_OK(status
)) {
78 return ntstatus_to_werror(status
);
81 if (!W_ERROR_IS_OK(werr
)) {
90 static WERROR
cmd_netlogon_getanydcname(struct rpc_pipe_client
*cli
,
91 TALLOC_CTX
*mem_ctx
, int argc
,
94 const char *dcname
= NULL
;
100 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
104 /* Make sure to wait for our DC's reply */
105 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
106 rpccli_set_timeout(cli
, MAX(old_timeout
, 30000)); /* At least 30 sec */
108 status
= rpccli_netr_GetAnyDCName(cli
, mem_ctx
,
113 rpccli_set_timeout(cli
, old_timeout
);
115 if (!NT_STATUS_IS_OK(status
)) {
116 return ntstatus_to_werror(status
);
119 if (!W_ERROR_IS_OK(werr
)) {
123 /* Display results */
125 printf("%s\n", dcname
);
130 static WERROR
cmd_netlogon_getdcname(struct rpc_pipe_client
*cli
,
131 TALLOC_CTX
*mem_ctx
, int argc
,
134 const char *dcname
= NULL
;
140 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
144 /* Make sure to wait for our DC's reply */
145 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
146 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
148 status
= rpccli_netr_GetDcName(cli
, mem_ctx
,
153 rpccli_set_timeout(cli
, old_timeout
);
155 if (!NT_STATUS_IS_OK(status
)) {
156 return ntstatus_to_werror(status
);
159 if (!W_ERROR_IS_OK(werr
)) {
163 /* Display results */
165 printf("%s\n", dcname
);
170 static WERROR
cmd_netlogon_dsr_getdcname(struct rpc_pipe_client
*cli
,
171 TALLOC_CTX
*mem_ctx
, int argc
,
175 WERROR werr
= WERR_OK
;
176 uint32 flags
= DS_RETURN_DNS_NAME
;
177 const char *server_name
= cli
->desthost
;
178 const char *domain_name
;
179 struct GUID domain_guid
= GUID_zero();
180 struct GUID site_guid
= GUID_zero();
181 struct netr_DsRGetDCNameInfo
*info
= NULL
;
184 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
185 "[site_guid] [flags]\n", argv
[0]);
190 domain_name
= argv
[1];
193 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
199 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[3], &site_guid
))) {
205 sscanf(argv
[4], "%x", &flags
);
207 debug_dsdcinfo_flags(1,flags
);
209 result
= rpccli_netr_DsRGetDCName(cli
, mem_ctx
,
218 if (W_ERROR_IS_OK(werr
)) {
219 d_printf("DsGetDcName gave: %s\n",
220 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
224 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
230 static WERROR
cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client
*cli
,
231 TALLOC_CTX
*mem_ctx
, int argc
,
236 uint32_t flags
= DS_RETURN_DNS_NAME
;
237 const char *server_name
= cli
->desthost
;
238 const char *domain_name
;
239 const char *site_name
= NULL
;
240 struct GUID domain_guid
= GUID_zero();
241 struct netr_DsRGetDCNameInfo
*info
= NULL
;
244 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
245 "[site_name] [flags]\n", argv
[0]);
249 domain_name
= argv
[1];
252 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
262 sscanf(argv
[4], "%x", &flags
);
265 debug_dsdcinfo_flags(1,flags
);
267 status
= rpccli_netr_DsRGetDCNameEx(cli
, mem_ctx
,
275 if (!NT_STATUS_IS_OK(status
)) {
276 return ntstatus_to_werror(status
);
279 if (!W_ERROR_IS_OK(result
)) {
283 d_printf("DsRGetDCNameEx gave %s\n",
284 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
289 static WERROR
cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client
*cli
,
290 TALLOC_CTX
*mem_ctx
, int argc
,
295 uint32_t flags
= DS_RETURN_DNS_NAME
;
296 const char *server_name
= cli
->desthost
;
297 const char *domain_name
= NULL
;
298 const char *client_account
= NULL
;
300 const char *site_name
= NULL
;
301 struct GUID domain_guid
= GUID_zero();
302 struct netr_DsRGetDCNameInfo
*info
= NULL
;
305 fprintf(stderr
, "Usage: %s [client_account] [acb_mask] "
306 "[domain_name] [domain_guid] [site_name] "
307 "[flags]\n", argv
[0]);
312 client_account
= argv
[1];
316 mask
= atoi(argv
[2]);
320 domain_name
= argv
[3];
324 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[4], &domain_guid
))) {
334 sscanf(argv
[6], "%x", &flags
);
337 debug_dsdcinfo_flags(1,flags
);
339 status
= rpccli_netr_DsRGetDCNameEx2(cli
, mem_ctx
,
349 if (!NT_STATUS_IS_OK(status
)) {
350 return ntstatus_to_werror(status
);
353 if (!W_ERROR_IS_OK(result
)) {
357 d_printf("DsRGetDCNameEx2 gave %s\n",
358 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
364 static WERROR
cmd_netlogon_dsr_getsitename(struct rpc_pipe_client
*cli
,
365 TALLOC_CTX
*mem_ctx
, int argc
,
370 const char *sitename
= NULL
;
373 fprintf(stderr
, "Usage: %s computername\n", argv
[0]);
377 status
= rpccli_netr_DsRGetSiteName(cli
, mem_ctx
,
381 if (!NT_STATUS_IS_OK(status
)) {
382 return ntstatus_to_werror(status
);
385 if (!W_ERROR_IS_OK(werr
)) {
386 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
387 nt_errstr(werror_to_ntstatus(werr
)));
391 printf("Computer %s is on Site: %s\n", argv
[1], sitename
);
396 static WERROR
cmd_netlogon_logon_ctrl(struct rpc_pipe_client
*cli
,
397 TALLOC_CTX
*mem_ctx
, int argc
,
400 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
402 const char *logon_server
= cli
->desthost
;
403 enum netr_LogonControlCode function_code
= 1;
405 union netr_CONTROL_QUERY_INFORMATION info
;
408 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
409 "<level>\n", argv
[0]);
414 logon_server
= argv
[1];
418 function_code
= atoi(argv
[2]);
422 level
= atoi(argv
[3]);
425 status
= rpccli_netr_LogonControl(cli
, mem_ctx
,
431 if (!NT_STATUS_IS_OK(status
)) {
432 return ntstatus_to_werror(status
);
435 if (!W_ERROR_IS_OK(werr
)) {
439 /* Display results */
444 /* Display sam synchronisation information */
446 static void display_sam_sync(struct netr_DELTA_ENUM_ARRAY
*r
)
450 for (i
=0; i
< r
->num_deltas
; i
++) {
452 union netr_DELTA_UNION u
= r
->delta_enum
[i
].delta_union
;
453 union netr_DELTA_ID_UNION id
= r
->delta_enum
[i
].delta_id_union
;
455 switch (r
->delta_enum
[i
].delta_type
) {
456 case NETR_DELTA_DOMAIN
:
457 printf("Domain: %s\n",
458 u
.domain
->domain_name
.string
);
460 case NETR_DELTA_GROUP
:
461 printf("Group: %s\n",
462 u
.group
->group_name
.string
);
464 case NETR_DELTA_DELETE_GROUP
:
465 printf("Delete Group: %d\n",
466 u
.delete_account
.unknown
);
468 case NETR_DELTA_RENAME_GROUP
:
469 printf("Rename Group: %s -> %s\n",
470 u
.rename_group
->OldName
.string
,
471 u
.rename_group
->NewName
.string
);
473 case NETR_DELTA_USER
:
474 printf("Account: %s\n",
475 u
.user
->account_name
.string
);
477 case NETR_DELTA_DELETE_USER
:
478 printf("Delete User: %d\n",
481 case NETR_DELTA_RENAME_USER
:
482 printf("Rename user: %s -> %s\n",
483 u
.rename_user
->OldName
.string
,
484 u
.rename_user
->NewName
.string
);
486 case NETR_DELTA_GROUP_MEMBER
:
487 for (j
=0; j
< u
.group_member
->num_rids
; j
++) {
488 printf("rid 0x%x, attrib 0x%08x\n",
489 u
.group_member
->rids
[j
],
490 u
.group_member
->attribs
[j
]);
493 case NETR_DELTA_ALIAS
:
494 printf("Alias: %s\n",
495 u
.alias
->alias_name
.string
);
497 case NETR_DELTA_DELETE_ALIAS
:
498 printf("Delete Alias: %d\n",
499 r
->delta_enum
[i
].delta_id_union
.rid
);
501 case NETR_DELTA_RENAME_ALIAS
:
502 printf("Rename alias: %s -> %s\n",
503 u
.rename_alias
->OldName
.string
,
504 u
.rename_alias
->NewName
.string
);
506 case NETR_DELTA_ALIAS_MEMBER
:
507 for (j
=0; j
< u
.alias_member
->sids
.num_sids
; j
++) {
509 sid_to_fstring(sid_str
,
510 u
.alias_member
->sids
.sids
[j
].sid
);
511 printf("%s\n", sid_str
);
514 case NETR_DELTA_POLICY
:
517 case NETR_DELTA_TRUSTED_DOMAIN
:
518 printf("Trusted Domain: %s\n",
519 u
.trusted_domain
->domain_name
.string
);
521 case NETR_DELTA_DELETE_TRUST
:
522 printf("Delete Trust: %d\n",
523 u
.delete_trust
.unknown
);
525 case NETR_DELTA_ACCOUNT
:
528 case NETR_DELTA_DELETE_ACCOUNT
:
529 printf("Delete Account: %d\n",
530 u
.delete_account
.unknown
);
532 case NETR_DELTA_SECRET
:
535 case NETR_DELTA_DELETE_SECRET
:
536 printf("Delete Secret: %d\n",
537 u
.delete_secret
.unknown
);
539 case NETR_DELTA_DELETE_GROUP2
:
540 printf("Delete Group2: %s\n",
541 u
.delete_group
->account_name
);
543 case NETR_DELTA_DELETE_USER2
:
544 printf("Delete User2: %s\n",
545 u
.delete_user
->account_name
);
547 case NETR_DELTA_MODIFY_COUNT
:
548 printf("sam sequence update: 0x%016llx\n",
549 (unsigned long long) *u
.modified_count
);
552 printf("unknown delta type 0x%02x\n",
553 r
->delta_enum
[i
].delta_type
);
559 /* Perform sam synchronisation */
561 static NTSTATUS
cmd_netlogon_sam_sync(struct rpc_pipe_client
*cli
,
562 TALLOC_CTX
*mem_ctx
, int argc
,
565 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
566 const char *logon_server
= cli
->desthost
;
567 const char *computername
= global_myname();
568 struct netr_Authenticator credential
;
569 struct netr_Authenticator return_authenticator
;
570 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
571 uint16_t restart_state
= 0;
572 uint32_t sync_context
= 0;
575 fprintf(stderr
, "Usage: %s [database_id]\n", argv
[0]);
580 database_id
= atoi(argv
[1]);
583 /* Synchronise sam database */
586 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
588 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
590 result
= rpccli_netr_DatabaseSync2(cli
, mem_ctx
,
594 &return_authenticator
,
601 /* Check returned credentials. */
602 if (!netlogon_creds_client_check(cli
->dc
,
603 &return_authenticator
.cred
)) {
604 DEBUG(0,("credentials chain check failed\n"));
605 return NT_STATUS_ACCESS_DENIED
;
608 if (NT_STATUS_IS_ERR(result
)) {
612 /* Display results */
614 display_sam_sync(delta_enum_array
);
616 TALLOC_FREE(delta_enum_array
);
618 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
623 /* Perform sam delta synchronisation */
625 static NTSTATUS
cmd_netlogon_sam_deltas(struct rpc_pipe_client
*cli
,
626 TALLOC_CTX
*mem_ctx
, int argc
,
629 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
631 const char *logon_server
= cli
->desthost
;
632 const char *computername
= global_myname();
633 struct netr_Authenticator credential
;
634 struct netr_Authenticator return_authenticator
;
635 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
636 uint64_t sequence_num
;
639 fprintf(stderr
, "Usage: %s database_id seqnum\n", argv
[0]);
643 database_id
= atoi(argv
[1]);
646 sequence_num
= tmp
& 0xffff;
649 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
651 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
653 result
= rpccli_netr_DatabaseDeltas(cli
, mem_ctx
,
657 &return_authenticator
,
663 /* Check returned credentials. */
664 if (!netlogon_creds_client_check(cli
->dc
,
665 &return_authenticator
.cred
)) {
666 DEBUG(0,("credentials chain check failed\n"));
667 return NT_STATUS_ACCESS_DENIED
;
670 if (NT_STATUS_IS_ERR(result
)) {
674 /* Display results */
676 display_sam_sync(delta_enum_array
);
678 TALLOC_FREE(delta_enum_array
);
680 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
685 /* Log on a domain user */
687 static NTSTATUS
cmd_netlogon_sam_logon(struct rpc_pipe_client
*cli
,
688 TALLOC_CTX
*mem_ctx
, int argc
,
691 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
692 int logon_type
= NetlogonNetworkInformation
;
693 const char *username
, *password
;
695 uint32 logon_param
= 0;
696 const char *workstation
= NULL
;
698 /* Check arguments */
700 if (argc
< 3 || argc
> 7) {
701 fprintf(stderr
, "Usage: samlogon <username> <password> [workstation]"
702 "[logon_type (1 or 2)] [auth level (2 or 3)] [logon_parameter]\n");
710 workstation
= argv
[3];
713 sscanf(argv
[4], "%i", &logon_type
);
716 sscanf(argv
[5], "%i", &auth_level
);
719 sscanf(argv
[6], "%x", &logon_param
);
721 /* Perform the sam logon */
723 result
= rpccli_netlogon_sam_logon(cli
, mem_ctx
, logon_param
, lp_workgroup(), username
, password
, workstation
, logon_type
);
725 if (!NT_STATUS_IS_OK(result
))
732 /* Change the trust account password */
734 static NTSTATUS
cmd_netlogon_change_trust_pw(struct rpc_pipe_client
*cli
,
735 TALLOC_CTX
*mem_ctx
, int argc
,
738 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
740 /* Check arguments */
743 fprintf(stderr
, "Usage: change_trust_pw");
747 /* Perform the sam logon */
749 result
= trust_pw_find_change_and_store_it(cli
, mem_ctx
,
752 if (!NT_STATUS_IS_OK(result
))
759 static WERROR
cmd_netlogon_gettrustrid(struct rpc_pipe_client
*cli
,
760 TALLOC_CTX
*mem_ctx
, int argc
,
763 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
764 WERROR werr
= WERR_GENERAL_FAILURE
;
765 const char *server_name
= cli
->desthost
;
766 const char *domain_name
= lp_workgroup();
769 if (argc
< 1 || argc
> 3) {
770 fprintf(stderr
, "Usage: %s <server_name> <domain_name>\n",
776 server_name
= argv
[1];
780 domain_name
= argv
[2];
783 status
= rpccli_netr_LogonGetTrustRid(cli
, mem_ctx
,
788 if (!NT_STATUS_IS_OK(status
)) {
792 if (W_ERROR_IS_OK(werr
)) {
793 printf("Rid: %d\n", rid
);
799 static WERROR
cmd_netlogon_dsr_enumtrustdom(struct rpc_pipe_client
*cli
,
800 TALLOC_CTX
*mem_ctx
, int argc
,
803 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
804 WERROR werr
= WERR_GENERAL_FAILURE
;
805 const char *server_name
= cli
->desthost
;
806 uint32_t trust_flags
= NETR_TRUST_FLAG_IN_FOREST
;
807 struct netr_DomainTrustList trusts
;
809 if (argc
< 1 || argc
> 3) {
810 fprintf(stderr
, "Usage: %s <server_name> <trust_flags>\n",
816 server_name
= argv
[1];
820 sscanf(argv
[2], "%x", &trust_flags
);
823 status
= rpccli_netr_DsrEnumerateDomainTrusts(cli
, mem_ctx
,
828 if (!NT_STATUS_IS_OK(status
)) {
832 if (W_ERROR_IS_OK(werr
)) {
835 printf("%d domains returned\n", trusts
.count
);
837 for (i
=0; i
<trusts
.count
; i
++ ) {
839 trusts
.array
[i
].dns_name
,
840 trusts
.array
[i
].netbios_name
);
847 static WERROR
cmd_netlogon_deregisterdnsrecords(struct rpc_pipe_client
*cli
,
848 TALLOC_CTX
*mem_ctx
, int argc
,
851 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
852 WERROR werr
= WERR_GENERAL_FAILURE
;
853 const char *server_name
= cli
->desthost
;
854 const char *domain
= lp_workgroup();
855 const char *dns_host
= NULL
;
857 if (argc
< 1 || argc
> 4) {
858 fprintf(stderr
, "Usage: %s <server_name> <domain_name> "
859 "<dns_host>\n", argv
[0]);
864 server_name
= argv
[1];
875 status
= rpccli_netr_DsrDeregisterDNSHostRecords(cli
, mem_ctx
,
882 if (!NT_STATUS_IS_OK(status
)) {
886 if (W_ERROR_IS_OK(werr
)) {
893 static WERROR
cmd_netlogon_dsr_getforesttrustinfo(struct rpc_pipe_client
*cli
,
894 TALLOC_CTX
*mem_ctx
, int argc
,
897 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
898 WERROR werr
= WERR_GENERAL_FAILURE
;
899 const char *server_name
= cli
->desthost
;
900 const char *trusted_domain_name
= NULL
;
901 struct lsa_ForestTrustInformation
*info
= NULL
;
904 if (argc
< 1 || argc
> 4) {
905 fprintf(stderr
, "Usage: %s <server_name> <trusted_domain_name> "
906 "<flags>\n", argv
[0]);
911 server_name
= argv
[1];
915 trusted_domain_name
= argv
[2];
919 sscanf(argv
[3], "%x", &flags
);
922 status
= rpccli_netr_DsRGetForestTrustInformation(cli
, mem_ctx
,
928 if (!NT_STATUS_IS_OK(status
)) {
932 if (W_ERROR_IS_OK(werr
)) {
939 static WERROR
cmd_netlogon_enumtrusteddomains(struct rpc_pipe_client
*cli
,
940 TALLOC_CTX
*mem_ctx
, int argc
,
943 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
944 WERROR werr
= WERR_GENERAL_FAILURE
;
945 const char *server_name
= cli
->desthost
;
946 struct netr_Blob blob
;
949 if (argc
< 1 || argc
> 3) {
950 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
955 server_name
= argv
[1];
958 status
= rpccli_netr_NetrEnumerateTrustedDomains(cli
, mem_ctx
,
962 if (!NT_STATUS_IS_OK(status
)) {
966 if (W_ERROR_IS_OK(werr
)) {
968 dump_data(1, blob
.data
, blob
.length
);
974 static WERROR
cmd_netlogon_enumtrusteddomainsex(struct rpc_pipe_client
*cli
,
975 TALLOC_CTX
*mem_ctx
, int argc
,
978 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
979 WERROR werr
= WERR_GENERAL_FAILURE
;
980 const char *server_name
= cli
->desthost
;
981 struct netr_DomainTrustList list
;
983 if (argc
< 1 || argc
> 3) {
984 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
989 server_name
= argv
[1];
992 status
= rpccli_netr_NetrEnumerateTrustedDomainsEx(cli
, mem_ctx
,
996 if (!NT_STATUS_IS_OK(status
)) {
1000 if (W_ERROR_IS_OK(werr
)) {
1001 printf("success\n");
1007 static WERROR
cmd_netlogon_getdcsitecoverage(struct rpc_pipe_client
*cli
,
1008 TALLOC_CTX
*mem_ctx
, int argc
,
1011 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1012 WERROR werr
= WERR_GENERAL_FAILURE
;
1013 const char *server_name
= cli
->desthost
;
1014 struct DcSitesCtr
*ctr
= NULL
;
1016 if (argc
< 1 || argc
> 3) {
1017 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1022 server_name
= argv
[1];
1025 status
= rpccli_netr_DsrGetDcSiteCoverageW(cli
, mem_ctx
,
1029 if (!NT_STATUS_IS_OK(status
)) {
1033 if (W_ERROR_IS_OK(werr
) && ctr
->num_sites
) {
1035 printf("sites covered by this DC: %d\n", ctr
->num_sites
);
1036 for (i
=0; i
<ctr
->num_sites
; i
++) {
1037 printf("%s\n", ctr
->sites
[i
].string
);
1044 static NTSTATUS
cmd_netlogon_database_redo(struct rpc_pipe_client
*cli
,
1045 TALLOC_CTX
*mem_ctx
, int argc
,
1048 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1049 const char *server_name
= cli
->desthost
;
1050 uint32_t neg_flags
= NETLOGON_NEG_AUTH2_ADS_FLAGS
;
1051 struct netr_Authenticator clnt_creds
, srv_cred
;
1052 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1053 unsigned char trust_passwd_hash
[16];
1054 uint32_t sec_channel_type
= 0;
1055 struct netr_ChangeLogEntry e
;
1059 fprintf(stderr
, "Usage: %s <user rid>\n", argv
[0]);
1060 return NT_STATUS_OK
;
1064 sscanf(argv
[1], "%d", &rid
);
1067 if (!secrets_fetch_trust_account_password(lp_workgroup(),
1069 NULL
, &sec_channel_type
)) {
1070 return NT_STATUS_UNSUCCESSFUL
;
1073 status
= rpccli_netlogon_setup_creds(cli
,
1074 server_name
, /* server name */
1075 lp_workgroup(), /* domain */
1076 global_myname(), /* client name */
1077 global_myname(), /* machine account name */
1082 if (!NT_STATUS_IS_OK(status
)) {
1086 netlogon_creds_client_authenticator(cli
->dc
, &clnt_creds
);
1091 e
.db_index
= SAM_DATABASE_DOMAIN
;
1092 e
.delta_type
= NETR_DELTA_USER
;
1094 status
= rpccli_netr_DatabaseRedo(cli
, mem_ctx
,
1100 0, /* is calculated automatically */
1103 if (!netlogon_creds_client_check(cli
->dc
, &srv_cred
.cred
)) {
1104 DEBUG(0,("credentials chain check failed\n"));
1105 return NT_STATUS_ACCESS_DENIED
;
1111 static NTSTATUS
cmd_netlogon_capabilities(struct rpc_pipe_client
*cli
,
1112 TALLOC_CTX
*mem_ctx
, int argc
,
1115 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1116 struct netr_Authenticator credential
;
1117 struct netr_Authenticator return_authenticator
;
1118 union netr_Capabilities capabilities
;
1122 fprintf(stderr
, "Usage: %s <level>\n", argv
[0]);
1123 return NT_STATUS_OK
;
1127 level
= atoi(argv
[1]);
1131 netlogon_creds_client_authenticator(cli
->dc
, &credential
);
1133 ZERO_STRUCT(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
;
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", "" },