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"
29 #include "../libcli/auth/netlogon_creds_cli.h"
31 static WERROR
cmd_netlogon_logon_ctrl2(struct rpc_pipe_client
*cli
,
32 TALLOC_CTX
*mem_ctx
, int argc
,
35 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
37 const char *logon_server
= cli
->desthost
;
38 enum netr_LogonControlCode function_code
= NETLOGON_CONTROL_REDISCOVER
;
40 union netr_CONTROL_DATA_INFORMATION data
;
41 union netr_CONTROL_QUERY_INFORMATION query
;
42 const char *domain
= lp_workgroup();
43 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
45 #define fn_code_level(x, item) { x, #x, #item }
47 enum netr_LogonControlCode code
;
50 } supported_levels
[] = {
51 fn_code_level(NETLOGON_CONTROL_REDISCOVER
, domain
),
52 fn_code_level(NETLOGON_CONTROL_TC_QUERY
, domain
),
53 fn_code_level(NETLOGON_CONTROL_TRANSPORT_NOTIFY
, domain
),
54 fn_code_level(NETLOGON_CONTROL_FIND_USER
, user
),
55 fn_code_level(NETLOGON_CONTROL_CHANGE_PASSWORD
, domain
),
56 fn_code_level(NETLOGON_CONTROL_TC_VERIFY
, domain
),
57 fn_code_level(NETLOGON_CONTROL_SET_DBFLAG
, debug_level
),
61 if ((argc
> 5) || (argc
< 2)) {
62 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
63 "<level:1..4> <argument>\n", argv
[0]);
64 fprintf(stderr
, "Supported combinations:\n");
65 fprintf(stderr
, "function_code\targument\n");
66 for(i
=0; supported_levels
[i
].code
; i
++) {
67 fprintf(stderr
, "%7d\t\t%s\t(%s)\n",
68 supported_levels
[i
].code
,
69 supported_levels
[i
].argument
,
70 supported_levels
[i
].name
);
76 logon_server
= argv
[1];
80 function_code
= atoi(argv
[2]);
84 level
= atoi(argv
[3]);
91 switch (function_code
) {
92 case NETLOGON_CONTROL_REDISCOVER
:
93 case NETLOGON_CONTROL_TC_QUERY
:
94 case NETLOGON_CONTROL_CHANGE_PASSWORD
:
95 case NETLOGON_CONTROL_TRANSPORT_NOTIFY
:
96 case NETLOGON_CONTROL_TC_VERIFY
:
99 case NETLOGON_CONTROL_FIND_USER
:
102 case NETLOGON_CONTROL_SET_DBFLAG
:
103 data
.debug_level
= atoi(domain
);
108 status
= dcerpc_netr_LogonControl2(b
, mem_ctx
,
115 if (!NT_STATUS_IS_OK(status
)) {
116 return ntstatus_to_werror(status
);
119 if (!W_ERROR_IS_OK(werr
)) {
123 /* Display results */
128 static WERROR
cmd_netlogon_getanydcname(struct rpc_pipe_client
*cli
,
129 TALLOC_CTX
*mem_ctx
, int argc
,
132 const char *dcname
= NULL
;
136 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
139 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
143 /* Make sure to wait for our DC's reply */
144 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
145 rpccli_set_timeout(cli
, MAX(old_timeout
, 30000)); /* At least 30 sec */
147 status
= dcerpc_netr_GetAnyDCName(b
, mem_ctx
,
152 rpccli_set_timeout(cli
, old_timeout
);
154 if (!NT_STATUS_IS_OK(status
)) {
155 return ntstatus_to_werror(status
);
158 if (!W_ERROR_IS_OK(werr
)) {
162 /* Display results */
164 printf("%s\n", dcname
);
169 static WERROR
cmd_netlogon_getdcname(struct rpc_pipe_client
*cli
,
170 TALLOC_CTX
*mem_ctx
, int argc
,
173 const char *dcname
= NULL
;
177 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
180 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
184 /* Make sure to wait for our DC's reply */
185 old_timeout
= rpccli_set_timeout(cli
, 30000); /* 30 seconds. */
186 rpccli_set_timeout(cli
, MAX(30000, old_timeout
)); /* At least 30 sec */
188 status
= dcerpc_netr_GetDcName(b
, mem_ctx
,
193 rpccli_set_timeout(cli
, old_timeout
);
195 if (!NT_STATUS_IS_OK(status
)) {
196 return ntstatus_to_werror(status
);
199 if (!W_ERROR_IS_OK(werr
)) {
203 /* Display results */
205 printf("%s\n", dcname
);
210 static WERROR
cmd_netlogon_dsr_getdcname(struct rpc_pipe_client
*cli
,
211 TALLOC_CTX
*mem_ctx
, int argc
,
215 WERROR werr
= WERR_OK
;
216 uint32_t flags
= DS_RETURN_DNS_NAME
;
217 const char *server_name
= cli
->desthost
;
218 const char *domain_name
;
219 struct GUID domain_guid
= GUID_zero();
220 struct GUID site_guid
= GUID_zero();
221 struct netr_DsRGetDCNameInfo
*info
= NULL
;
222 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
225 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
226 "[site_guid] [flags]\n", argv
[0]);
231 domain_name
= argv
[1];
234 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
235 return WERR_NOT_ENOUGH_MEMORY
;
240 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[3], &site_guid
))) {
241 return WERR_NOT_ENOUGH_MEMORY
;
246 sscanf(argv
[4], "%x", &flags
);
248 result
= dcerpc_netr_DsRGetDCName(b
, mem_ctx
,
256 if (!NT_STATUS_IS_OK(result
)) {
257 return ntstatus_to_werror(result
);
260 if (W_ERROR_IS_OK(werr
)) {
261 d_printf("DsGetDcName gave: %s\n",
262 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
266 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
272 static WERROR
cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client
*cli
,
273 TALLOC_CTX
*mem_ctx
, int argc
,
278 uint32_t flags
= DS_RETURN_DNS_NAME
;
279 const char *server_name
= cli
->desthost
;
280 const char *domain_name
;
281 const char *site_name
= NULL
;
282 struct GUID domain_guid
= GUID_zero();
283 struct netr_DsRGetDCNameInfo
*info
= NULL
;
284 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
287 fprintf(stderr
, "Usage: %s [domain_name] [domain_guid] "
288 "[site_name] [flags]\n", argv
[0]);
292 domain_name
= argv
[1];
295 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
296 return WERR_NOT_ENOUGH_MEMORY
;
305 sscanf(argv
[4], "%x", &flags
);
308 status
= dcerpc_netr_DsRGetDCNameEx(b
, mem_ctx
,
316 if (!NT_STATUS_IS_OK(status
)) {
317 return ntstatus_to_werror(status
);
320 if (!W_ERROR_IS_OK(result
)) {
324 d_printf("DsRGetDCNameEx gave %s\n",
325 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
330 static WERROR
cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client
*cli
,
331 TALLOC_CTX
*mem_ctx
, int argc
,
336 uint32_t flags
= DS_RETURN_DNS_NAME
;
337 const char *server_name
= cli
->desthost
;
338 const char *domain_name
= NULL
;
339 const char *client_account
= NULL
;
341 const char *site_name
= NULL
;
342 struct GUID domain_guid
= GUID_zero();
343 struct netr_DsRGetDCNameInfo
*info
= NULL
;
344 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
347 fprintf(stderr
, "Usage: %s [client_account] [acb_mask] "
348 "[domain_name] [domain_guid] [site_name] "
349 "[flags]\n", argv
[0]);
354 client_account
= argv
[1];
358 mask
= atoi(argv
[2]);
362 domain_name
= argv
[3];
366 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[4], &domain_guid
))) {
367 return WERR_NOT_ENOUGH_MEMORY
;
376 sscanf(argv
[6], "%x", &flags
);
379 status
= dcerpc_netr_DsRGetDCNameEx2(b
, mem_ctx
,
389 if (!NT_STATUS_IS_OK(status
)) {
390 return ntstatus_to_werror(status
);
393 if (!W_ERROR_IS_OK(result
)) {
397 d_printf("DsRGetDCNameEx2 gave %s\n",
398 NDR_PRINT_STRUCT_STRING(mem_ctx
, netr_DsRGetDCNameInfo
, info
));
404 static WERROR
cmd_netlogon_dsr_getsitename(struct rpc_pipe_client
*cli
,
405 TALLOC_CTX
*mem_ctx
, int argc
,
410 const char *sitename
= NULL
;
411 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
414 fprintf(stderr
, "Usage: %s computername\n", argv
[0]);
418 status
= dcerpc_netr_DsRGetSiteName(b
, mem_ctx
,
422 if (!NT_STATUS_IS_OK(status
)) {
423 return ntstatus_to_werror(status
);
426 if (!W_ERROR_IS_OK(werr
)) {
427 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
428 nt_errstr(werror_to_ntstatus(werr
)));
432 printf("Computer %s is on Site: %s\n", argv
[1], sitename
);
437 static WERROR
cmd_netlogon_logon_ctrl(struct rpc_pipe_client
*cli
,
438 TALLOC_CTX
*mem_ctx
, int argc
,
441 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
443 const char *logon_server
= cli
->desthost
;
444 enum netr_LogonControlCode function_code
= 1;
446 union netr_CONTROL_QUERY_INFORMATION info
;
447 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
450 fprintf(stderr
, "Usage: %s <logon_server> <function_code> "
451 "<level>\n", argv
[0]);
456 logon_server
= argv
[1];
460 function_code
= atoi(argv
[2]);
464 level
= atoi(argv
[3]);
467 status
= dcerpc_netr_LogonControl(b
, mem_ctx
,
473 if (!NT_STATUS_IS_OK(status
)) {
474 return ntstatus_to_werror(status
);
477 if (!W_ERROR_IS_OK(werr
)) {
481 /* Display results */
486 /* Display sam synchronisation information */
488 static void display_sam_sync(struct netr_DELTA_ENUM_ARRAY
*r
)
492 for (i
=0; i
< r
->num_deltas
; i
++) {
494 union netr_DELTA_UNION u
= r
->delta_enum
[i
].delta_union
;
495 union netr_DELTA_ID_UNION id
= r
->delta_enum
[i
].delta_id_union
;
497 switch (r
->delta_enum
[i
].delta_type
) {
498 case NETR_DELTA_DOMAIN
:
499 printf("Domain: %s\n",
500 u
.domain
->domain_name
.string
);
502 case NETR_DELTA_GROUP
:
503 printf("Group: %s\n",
504 u
.group
->group_name
.string
);
506 case NETR_DELTA_DELETE_GROUP
:
507 printf("Delete Group: %d\n",
510 case NETR_DELTA_RENAME_GROUP
:
511 printf("Rename Group: %s -> %s\n",
512 u
.rename_group
->OldName
.string
,
513 u
.rename_group
->NewName
.string
);
515 case NETR_DELTA_USER
:
516 printf("Account: %s\n",
517 u
.user
->account_name
.string
);
519 case NETR_DELTA_DELETE_USER
:
520 printf("Delete User: %d\n",
523 case NETR_DELTA_RENAME_USER
:
524 printf("Rename user: %s -> %s\n",
525 u
.rename_user
->OldName
.string
,
526 u
.rename_user
->NewName
.string
);
528 case NETR_DELTA_GROUP_MEMBER
:
529 for (j
=0; j
< u
.group_member
->num_rids
; j
++) {
530 printf("rid 0x%x, attrib 0x%08x\n",
531 u
.group_member
->rids
[j
],
532 u
.group_member
->attribs
[j
]);
535 case NETR_DELTA_ALIAS
:
536 printf("Alias: %s\n",
537 u
.alias
->alias_name
.string
);
539 case NETR_DELTA_DELETE_ALIAS
:
540 printf("Delete Alias: %d\n",
543 case NETR_DELTA_RENAME_ALIAS
:
544 printf("Rename alias: %s -> %s\n",
545 u
.rename_alias
->OldName
.string
,
546 u
.rename_alias
->NewName
.string
);
548 case NETR_DELTA_ALIAS_MEMBER
:
549 for (j
=0; j
< u
.alias_member
->sids
.num_sids
; j
++) {
551 sid_to_fstring(sid_str
,
552 u
.alias_member
->sids
.sids
[j
].sid
);
553 printf("%s\n", sid_str
);
556 case NETR_DELTA_POLICY
:
557 printf("Policy: %s\n",
558 sid_string_dbg(id
.sid
));
560 case NETR_DELTA_TRUSTED_DOMAIN
:
561 printf("Trusted Domain: %s\n",
562 u
.trusted_domain
->domain_name
.string
);
564 case NETR_DELTA_DELETE_TRUST
:
565 printf("Delete Trust: %s\n",
566 sid_string_dbg(id
.sid
));
568 case NETR_DELTA_ACCOUNT
:
569 printf("Account: %s\n",
570 sid_string_dbg(id
.sid
));
572 case NETR_DELTA_DELETE_ACCOUNT
:
573 printf("Delete Account: %s\n",
574 sid_string_dbg(id
.sid
));
576 case NETR_DELTA_SECRET
:
577 printf("Secret: %s\n",
580 case NETR_DELTA_DELETE_SECRET
:
581 printf("Delete Secret: %s\n",
584 case NETR_DELTA_DELETE_GROUP2
:
585 printf("Delete Group2: %s\n",
586 u
.delete_group
->account_name
);
588 case NETR_DELTA_DELETE_USER2
:
589 printf("Delete User2: %s\n",
590 u
.delete_user
->account_name
);
592 case NETR_DELTA_MODIFY_COUNT
:
593 printf("sam sequence update: 0x%016llx\n",
594 (unsigned long long) *u
.modified_count
);
597 printf("unknown delta type 0x%02x\n",
598 r
->delta_enum
[i
].delta_type
);
604 /* Perform sam synchronisation */
606 static NTSTATUS
cmd_netlogon_sam_sync(struct rpc_pipe_client
*cli
,
607 TALLOC_CTX
*mem_ctx
, int argc
,
610 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
612 const char *logon_server
= cli
->desthost
;
613 const char *computername
= lp_netbios_name();
614 struct netr_Authenticator credential
;
615 struct netr_Authenticator return_authenticator
;
616 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
617 uint16_t restart_state
= 0;
618 uint32_t sync_context
= 0;
619 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
622 fprintf(stderr
, "Usage: %s [database_id]\n", argv
[0]);
627 database_id
= atoi(argv
[1]);
630 /* Synchronise sam database */
633 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
634 struct netlogon_creds_CredentialState
*creds
= NULL
;
636 if (rpcclient_netlogon_creds
== NULL
) {
637 return NT_STATUS_UNSUCCESSFUL
;
640 status
= netlogon_creds_cli_lock(rpcclient_netlogon_creds
,
642 if (!NT_STATUS_IS_OK(status
)) {
646 netlogon_creds_client_authenticator(creds
, &credential
);
648 status
= dcerpc_netr_DatabaseSync2(b
, mem_ctx
,
652 &return_authenticator
,
659 if (!NT_STATUS_IS_OK(status
)) {
664 /* Check returned credentials. */
665 if (!netlogon_creds_client_check(creds
,
666 &return_authenticator
.cred
)) {
667 DEBUG(0,("credentials chain check failed\n"));
669 return NT_STATUS_ACCESS_DENIED
;
673 if (NT_STATUS_IS_ERR(result
)) {
677 /* Display results */
679 display_sam_sync(delta_enum_array
);
681 TALLOC_FREE(delta_enum_array
);
683 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
688 /* Perform sam delta synchronisation */
690 static NTSTATUS
cmd_netlogon_sam_deltas(struct rpc_pipe_client
*cli
,
691 TALLOC_CTX
*mem_ctx
, int argc
,
694 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
697 const char *logon_server
= cli
->desthost
;
698 const char *computername
= lp_netbios_name();
699 struct netr_Authenticator credential
;
700 struct netr_Authenticator return_authenticator
;
701 enum netr_SamDatabaseID database_id
= SAM_DATABASE_DOMAIN
;
702 uint64_t sequence_num
;
703 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
706 fprintf(stderr
, "Usage: %s database_id seqnum\n", argv
[0]);
710 database_id
= atoi(argv
[1]);
713 sequence_num
= tmp
& 0xffff;
716 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
717 struct netlogon_creds_CredentialState
*creds
= NULL
;
719 if (rpcclient_netlogon_creds
== NULL
) {
720 return NT_STATUS_UNSUCCESSFUL
;
723 status
= netlogon_creds_cli_lock(rpcclient_netlogon_creds
,
725 if (!NT_STATUS_IS_OK(status
)) {
729 netlogon_creds_client_authenticator(creds
, &credential
);
731 status
= dcerpc_netr_DatabaseDeltas(b
, mem_ctx
,
735 &return_authenticator
,
741 if (!NT_STATUS_IS_OK(status
)) {
746 /* Check returned credentials. */
747 if (!netlogon_creds_client_check(creds
,
748 &return_authenticator
.cred
)) {
749 DEBUG(0,("credentials chain check failed\n"));
751 return NT_STATUS_ACCESS_DENIED
;
755 if (NT_STATUS_IS_ERR(result
)) {
759 /* Display results */
761 display_sam_sync(delta_enum_array
);
763 TALLOC_FREE(delta_enum_array
);
765 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
770 /* Log on a domain user */
772 static NTSTATUS
cmd_netlogon_sam_logon(struct rpc_pipe_client
*cli
,
773 TALLOC_CTX
*mem_ctx
, int argc
,
776 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
777 int logon_type
= NetlogonNetworkInformation
;
778 const char *username
, *password
;
779 uint32_t logon_param
= 0;
780 const char *workstation
= NULL
;
781 struct netr_SamInfo3
*info3
= NULL
;
783 /* Check arguments */
785 if (argc
< 3 || argc
> 6) {
786 fprintf(stderr
, "Usage: samlogon <username> <password> [workstation]"
787 "[logon_type (1 or 2)] [logon_parameter]\n");
795 workstation
= argv
[3];
798 sscanf(argv
[4], "%i", &logon_type
);
801 sscanf(argv
[5], "%x", &logon_param
);
803 if (rpcclient_netlogon_creds
== NULL
) {
804 result
= NT_STATUS_UNSUCCESSFUL
;
808 /* Perform the sam logon */
810 result
= rpccli_netlogon_password_logon(rpcclient_netlogon_creds
,
820 if (!NT_STATUS_IS_OK(result
))
827 /* Change the trust account password */
829 static NTSTATUS
cmd_netlogon_change_trust_pw(struct rpc_pipe_client
*cli
,
830 TALLOC_CTX
*mem_ctx
, int argc
,
833 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
834 const char *dcname
= cli
->desthost
;
836 /* Check arguments */
839 fprintf(stderr
, "Usage: change_trust_pw");
843 result
= trust_pw_change(rpcclient_netlogon_creds
,
849 if (!NT_STATUS_IS_OK(result
))
856 static WERROR
cmd_netlogon_gettrustrid(struct rpc_pipe_client
*cli
,
857 TALLOC_CTX
*mem_ctx
, int argc
,
860 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
861 WERROR werr
= WERR_GEN_FAILURE
;
862 const char *server_name
= cli
->desthost
;
863 const char *domain_name
= lp_workgroup();
865 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
867 if (argc
< 1 || argc
> 3) {
868 fprintf(stderr
, "Usage: %s <server_name> <domain_name>\n",
874 server_name
= argv
[1];
878 domain_name
= argv
[2];
881 status
= dcerpc_netr_LogonGetTrustRid(b
, mem_ctx
,
886 if (!NT_STATUS_IS_OK(status
)) {
887 werr
= ntstatus_to_werror(status
);
891 if (W_ERROR_IS_OK(werr
)) {
892 printf("Rid: %d\n", rid
);
898 static WERROR
cmd_netlogon_dsr_enumtrustdom(struct rpc_pipe_client
*cli
,
899 TALLOC_CTX
*mem_ctx
, int argc
,
902 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
903 WERROR werr
= WERR_GEN_FAILURE
;
904 const char *server_name
= cli
->desthost
;
905 uint32_t trust_flags
= NETR_TRUST_FLAG_IN_FOREST
;
906 struct netr_DomainTrustList trusts
;
907 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
909 if (argc
< 1 || argc
> 3) {
910 fprintf(stderr
, "Usage: %s <server_name> <trust_flags>\n",
916 server_name
= argv
[1];
920 sscanf(argv
[2], "%x", &trust_flags
);
923 status
= dcerpc_netr_DsrEnumerateDomainTrusts(b
, mem_ctx
,
928 if (!NT_STATUS_IS_OK(status
)) {
929 werr
= ntstatus_to_werror(status
);
933 if (W_ERROR_IS_OK(werr
)) {
936 printf("%d domains returned\n", trusts
.count
);
938 for (i
=0; i
<trusts
.count
; i
++ ) {
940 trusts
.array
[i
].dns_name
,
941 trusts
.array
[i
].netbios_name
);
948 static WERROR
cmd_netlogon_deregisterdnsrecords(struct rpc_pipe_client
*cli
,
949 TALLOC_CTX
*mem_ctx
, int argc
,
952 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
953 WERROR werr
= WERR_GEN_FAILURE
;
954 const char *server_name
= cli
->desthost
;
955 const char *domain
= lp_workgroup();
956 const char *dns_host
= NULL
;
957 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
959 if (argc
< 1 || argc
> 4) {
960 fprintf(stderr
, "Usage: %s <server_name> <domain_name> "
961 "<dns_host>\n", argv
[0]);
966 server_name
= argv
[1];
977 status
= dcerpc_netr_DsrDeregisterDNSHostRecords(b
, mem_ctx
,
984 if (!NT_STATUS_IS_OK(status
)) {
985 werr
= ntstatus_to_werror(status
);
989 if (W_ERROR_IS_OK(werr
)) {
996 static WERROR
cmd_netlogon_dsr_getforesttrustinfo(struct rpc_pipe_client
*cli
,
997 TALLOC_CTX
*mem_ctx
, int argc
,
1000 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1001 WERROR werr
= WERR_GEN_FAILURE
;
1002 const char *server_name
= cli
->desthost
;
1003 const char *trusted_domain_name
= NULL
;
1004 struct lsa_ForestTrustInformation
*info
= NULL
;
1006 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1008 if (argc
< 1 || argc
> 4) {
1009 fprintf(stderr
, "Usage: %s <server_name> <trusted_domain_name> "
1010 "<flags>\n", argv
[0]);
1015 server_name
= argv
[1];
1019 trusted_domain_name
= argv
[2];
1023 sscanf(argv
[3], "%x", &flags
);
1026 status
= dcerpc_netr_DsRGetForestTrustInformation(b
, mem_ctx
,
1028 trusted_domain_name
,
1032 if (!NT_STATUS_IS_OK(status
)) {
1033 werr
= ntstatus_to_werror(status
);
1037 if (W_ERROR_IS_OK(werr
)) {
1038 printf("success\n");
1044 static NTSTATUS
cmd_netlogon_enumtrusteddomains(struct rpc_pipe_client
*cli
,
1045 TALLOC_CTX
*mem_ctx
, int argc
,
1048 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1050 const char *server_name
= cli
->desthost
;
1051 struct netr_Blob blob
;
1052 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1055 if (argc
< 1 || argc
> 3) {
1056 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1057 return NT_STATUS_OK
;
1061 server_name
= argv
[1];
1064 status
= dcerpc_netr_NetrEnumerateTrustedDomains(b
, mem_ctx
,
1068 if (!NT_STATUS_IS_OK(status
)) {
1072 if (!NT_STATUS_IS_OK(result
)) {
1077 printf("success\n");
1078 dump_data(1, blob
.data
, blob
.length
);
1083 static WERROR
cmd_netlogon_enumtrusteddomainsex(struct rpc_pipe_client
*cli
,
1084 TALLOC_CTX
*mem_ctx
, int argc
,
1087 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1088 WERROR werr
= WERR_GEN_FAILURE
;
1089 const char *server_name
= cli
->desthost
;
1090 struct netr_DomainTrustList list
;
1091 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1093 if (argc
< 1 || argc
> 3) {
1094 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1099 server_name
= argv
[1];
1102 status
= dcerpc_netr_NetrEnumerateTrustedDomainsEx(b
, mem_ctx
,
1106 if (!NT_STATUS_IS_OK(status
)) {
1107 werr
= ntstatus_to_werror(status
);
1111 if (W_ERROR_IS_OK(werr
)) {
1112 printf("success\n");
1118 static WERROR
cmd_netlogon_getdcsitecoverage(struct rpc_pipe_client
*cli
,
1119 TALLOC_CTX
*mem_ctx
, int argc
,
1122 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1123 WERROR werr
= WERR_GEN_FAILURE
;
1124 const char *server_name
= cli
->desthost
;
1125 struct DcSitesCtr
*ctr
= NULL
;
1126 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1128 if (argc
< 1 || argc
> 3) {
1129 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1134 server_name
= argv
[1];
1137 status
= dcerpc_netr_DsrGetDcSiteCoverageW(b
, mem_ctx
,
1141 if (!NT_STATUS_IS_OK(status
)) {
1142 werr
= ntstatus_to_werror(status
);
1146 if (W_ERROR_IS_OK(werr
) && ctr
->num_sites
) {
1148 printf("sites covered by this DC: %d\n", ctr
->num_sites
);
1149 for (i
=0; i
<ctr
->num_sites
; i
++) {
1150 printf("%s\n", ctr
->sites
[i
].string
);
1157 static NTSTATUS
cmd_netlogon_database_redo(struct rpc_pipe_client
*cli
,
1158 TALLOC_CTX
*mem_ctx
, int argc
,
1161 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1163 const char *server_name
= cli
->desthost
;
1164 struct netr_Authenticator clnt_creds
, srv_cred
;
1165 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1166 struct netr_ChangeLogEntry e
;
1168 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1169 struct netlogon_creds_CredentialState
*creds
= NULL
;
1172 fprintf(stderr
, "Usage: %s <user rid>\n", argv
[0]);
1173 return NT_STATUS_OK
;
1177 sscanf(argv
[1], "%d", &rid
);
1180 if (rpcclient_netlogon_creds
== NULL
) {
1181 return NT_STATUS_UNSUCCESSFUL
;
1184 status
= netlogon_creds_cli_lock(rpcclient_netlogon_creds
,
1186 if (!NT_STATUS_IS_OK(status
)) {
1190 netlogon_creds_client_authenticator(creds
, &clnt_creds
);
1195 e
.db_index
= SAM_DATABASE_DOMAIN
;
1196 e
.delta_type
= NETR_DELTA_USER
;
1198 status
= dcerpc_netr_DatabaseRedo(b
, mem_ctx
,
1204 0, /* is calculated automatically */
1207 if (!NT_STATUS_IS_OK(status
)) {
1212 if (!netlogon_creds_client_check(creds
, &srv_cred
.cred
)) {
1213 DEBUG(0,("credentials chain check failed\n"));
1215 return NT_STATUS_ACCESS_DENIED
;
1222 static NTSTATUS
cmd_netlogon_capabilities(struct rpc_pipe_client
*cli
,
1223 TALLOC_CTX
*mem_ctx
, int argc
,
1226 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1228 struct netr_Authenticator credential
;
1229 struct netr_Authenticator return_authenticator
;
1230 union netr_Capabilities capabilities
;
1232 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1233 struct netlogon_creds_CredentialState
*creds
= NULL
;
1236 fprintf(stderr
, "Usage: %s <level>\n", argv
[0]);
1237 return NT_STATUS_OK
;
1241 level
= atoi(argv
[1]);
1244 ZERO_STRUCT(return_authenticator
);
1246 if (rpcclient_netlogon_creds
== NULL
) {
1247 return NT_STATUS_UNSUCCESSFUL
;
1250 status
= netlogon_creds_cli_lock(rpcclient_netlogon_creds
,
1252 if (!NT_STATUS_IS_OK(status
)) {
1256 netlogon_creds_client_authenticator(creds
, &credential
);
1258 status
= dcerpc_netr_LogonGetCapabilities(b
, mem_ctx
,
1262 &return_authenticator
,
1266 if (!NT_STATUS_IS_OK(status
)) {
1271 if (!netlogon_creds_client_check(creds
,
1272 &return_authenticator
.cred
)) {
1273 DEBUG(0,("credentials chain check failed\n"));
1275 return NT_STATUS_ACCESS_DENIED
;
1279 printf("capabilities: 0x%08x\n", capabilities
.server_capabilities
);
1284 /* List of commands exported by this module */
1286 struct cmd_set netlogon_commands
[] = {
1290 { "logonctrl2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl2
, &ndr_table_netlogon
, NULL
, "Logon Control 2", "" },
1291 { "getanydcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getanydcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1292 { "getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted PDC name", "" },
1293 { "dsr_getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1294 { "dsr_getdcnameex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1295 { "dsr_getdcnameex2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex2
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1296 { "dsr_getsitename", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getsitename
, &ndr_table_netlogon
, NULL
, "Get sitename", "" },
1297 { "dsr_getforesttrustinfo", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getforesttrustinfo
, &ndr_table_netlogon
, NULL
, "Get Forest Trust Info", "" },
1298 { "logonctrl", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl
, &ndr_table_netlogon
, NULL
, "Logon Control", "" },
1299 { "samsync", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_sync
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Synchronisation", "", .use_netlogon_creds
= true, },
1300 { "samdeltas", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_deltas
, NULL
, &ndr_table_netlogon
, NULL
, "Query Sam Deltas", "", .use_netlogon_creds
= true, },
1301 { "samlogon", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_logon
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Logon", "", .use_netlogon_creds
= true, },
1302 { "change_trust_pw", RPC_RTYPE_NTSTATUS
, cmd_netlogon_change_trust_pw
, NULL
, &ndr_table_netlogon
, NULL
, "Change Trust Account Password", "", .use_netlogon_creds
= true, },
1303 { "gettrustrid", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_gettrustrid
, &ndr_table_netlogon
, NULL
, "Get trust rid", "" },
1304 { "dsr_enumtrustdom", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1305 { "dsenumdomtrusts", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate all trusted domains in an AD forest", "" },
1306 { "deregisterdnsrecords", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_deregisterdnsrecords
, &ndr_table_netlogon
, NULL
, "Deregister DNS records", "" },
1307 { "netrenumtrusteddomains", RPC_RTYPE_NTSTATUS
, cmd_netlogon_enumtrusteddomains
, NULL
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1308 { "netrenumtrusteddomainsex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_enumtrusteddomainsex
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1309 { "getdcsitecoverage", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcsitecoverage
, &ndr_table_netlogon
, NULL
, "Get the Site-Coverage from a DC", "" },
1310 { "database_redo", RPC_RTYPE_NTSTATUS
, cmd_netlogon_database_redo
, NULL
, &ndr_table_netlogon
, NULL
, "Replicate single object from a DC", "", .use_netlogon_creds
= true, },
1311 { "capabilities", RPC_RTYPE_NTSTATUS
, cmd_netlogon_capabilities
, NULL
, &ndr_table_netlogon
, NULL
, "Return Capabilities", "", .use_netlogon_creds
= true, },