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 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
))) {
240 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[3], &site_guid
))) {
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
))) {
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
))) {
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 logon_param
= 0;
780 const char *workstation
= NULL
;
782 /* Check arguments */
784 if (argc
< 3 || argc
> 6) {
785 fprintf(stderr
, "Usage: samlogon <username> <password> [workstation]"
786 "[logon_type (1 or 2)] [logon_parameter]\n");
794 workstation
= argv
[3];
797 sscanf(argv
[4], "%i", &logon_type
);
800 sscanf(argv
[5], "%x", &logon_param
);
802 /* Perform the sam logon */
804 result
= rpccli_netlogon_password_logon(rpcclient_netlogon_creds
,
812 if (!NT_STATUS_IS_OK(result
))
819 /* Change the trust account password */
821 static NTSTATUS
cmd_netlogon_change_trust_pw(struct rpc_pipe_client
*cli
,
822 TALLOC_CTX
*mem_ctx
, int argc
,
825 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
827 /* Check arguments */
830 fprintf(stderr
, "Usage: change_trust_pw");
834 result
= trust_pw_change(rpcclient_netlogon_creds
,
839 if (!NT_STATUS_IS_OK(result
))
846 static WERROR
cmd_netlogon_gettrustrid(struct rpc_pipe_client
*cli
,
847 TALLOC_CTX
*mem_ctx
, int argc
,
850 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
851 WERROR werr
= WERR_GENERAL_FAILURE
;
852 const char *server_name
= cli
->desthost
;
853 const char *domain_name
= lp_workgroup();
855 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
857 if (argc
< 1 || argc
> 3) {
858 fprintf(stderr
, "Usage: %s <server_name> <domain_name>\n",
864 server_name
= argv
[1];
868 domain_name
= argv
[2];
871 status
= dcerpc_netr_LogonGetTrustRid(b
, mem_ctx
,
876 if (!NT_STATUS_IS_OK(status
)) {
877 werr
= ntstatus_to_werror(status
);
881 if (W_ERROR_IS_OK(werr
)) {
882 printf("Rid: %d\n", rid
);
888 static WERROR
cmd_netlogon_dsr_enumtrustdom(struct rpc_pipe_client
*cli
,
889 TALLOC_CTX
*mem_ctx
, int argc
,
892 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
893 WERROR werr
= WERR_GENERAL_FAILURE
;
894 const char *server_name
= cli
->desthost
;
895 uint32_t trust_flags
= NETR_TRUST_FLAG_IN_FOREST
;
896 struct netr_DomainTrustList trusts
;
897 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
899 if (argc
< 1 || argc
> 3) {
900 fprintf(stderr
, "Usage: %s <server_name> <trust_flags>\n",
906 server_name
= argv
[1];
910 sscanf(argv
[2], "%x", &trust_flags
);
913 status
= dcerpc_netr_DsrEnumerateDomainTrusts(b
, mem_ctx
,
918 if (!NT_STATUS_IS_OK(status
)) {
919 werr
= ntstatus_to_werror(status
);
923 if (W_ERROR_IS_OK(werr
)) {
926 printf("%d domains returned\n", trusts
.count
);
928 for (i
=0; i
<trusts
.count
; i
++ ) {
930 trusts
.array
[i
].dns_name
,
931 trusts
.array
[i
].netbios_name
);
938 static WERROR
cmd_netlogon_deregisterdnsrecords(struct rpc_pipe_client
*cli
,
939 TALLOC_CTX
*mem_ctx
, int argc
,
942 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
943 WERROR werr
= WERR_GENERAL_FAILURE
;
944 const char *server_name
= cli
->desthost
;
945 const char *domain
= lp_workgroup();
946 const char *dns_host
= NULL
;
947 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
949 if (argc
< 1 || argc
> 4) {
950 fprintf(stderr
, "Usage: %s <server_name> <domain_name> "
951 "<dns_host>\n", argv
[0]);
956 server_name
= argv
[1];
967 status
= dcerpc_netr_DsrDeregisterDNSHostRecords(b
, mem_ctx
,
974 if (!NT_STATUS_IS_OK(status
)) {
975 werr
= ntstatus_to_werror(status
);
979 if (W_ERROR_IS_OK(werr
)) {
986 static WERROR
cmd_netlogon_dsr_getforesttrustinfo(struct rpc_pipe_client
*cli
,
987 TALLOC_CTX
*mem_ctx
, int argc
,
990 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
991 WERROR werr
= WERR_GENERAL_FAILURE
;
992 const char *server_name
= cli
->desthost
;
993 const char *trusted_domain_name
= NULL
;
994 struct lsa_ForestTrustInformation
*info
= NULL
;
996 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
998 if (argc
< 1 || argc
> 4) {
999 fprintf(stderr
, "Usage: %s <server_name> <trusted_domain_name> "
1000 "<flags>\n", argv
[0]);
1005 server_name
= argv
[1];
1009 trusted_domain_name
= argv
[2];
1013 sscanf(argv
[3], "%x", &flags
);
1016 status
= dcerpc_netr_DsRGetForestTrustInformation(b
, mem_ctx
,
1018 trusted_domain_name
,
1022 if (!NT_STATUS_IS_OK(status
)) {
1023 werr
= ntstatus_to_werror(status
);
1027 if (W_ERROR_IS_OK(werr
)) {
1028 printf("success\n");
1034 static NTSTATUS
cmd_netlogon_enumtrusteddomains(struct rpc_pipe_client
*cli
,
1035 TALLOC_CTX
*mem_ctx
, int argc
,
1038 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1040 const char *server_name
= cli
->desthost
;
1041 struct netr_Blob blob
;
1042 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1045 if (argc
< 1 || argc
> 3) {
1046 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1047 return NT_STATUS_OK
;
1051 server_name
= argv
[1];
1054 status
= dcerpc_netr_NetrEnumerateTrustedDomains(b
, mem_ctx
,
1058 if (!NT_STATUS_IS_OK(status
)) {
1062 if (!NT_STATUS_IS_OK(result
)) {
1067 printf("success\n");
1068 dump_data(1, blob
.data
, blob
.length
);
1073 static WERROR
cmd_netlogon_enumtrusteddomainsex(struct rpc_pipe_client
*cli
,
1074 TALLOC_CTX
*mem_ctx
, int argc
,
1077 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1078 WERROR werr
= WERR_GENERAL_FAILURE
;
1079 const char *server_name
= cli
->desthost
;
1080 struct netr_DomainTrustList list
;
1081 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1083 if (argc
< 1 || argc
> 3) {
1084 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1089 server_name
= argv
[1];
1092 status
= dcerpc_netr_NetrEnumerateTrustedDomainsEx(b
, mem_ctx
,
1096 if (!NT_STATUS_IS_OK(status
)) {
1097 werr
= ntstatus_to_werror(status
);
1101 if (W_ERROR_IS_OK(werr
)) {
1102 printf("success\n");
1108 static WERROR
cmd_netlogon_getdcsitecoverage(struct rpc_pipe_client
*cli
,
1109 TALLOC_CTX
*mem_ctx
, int argc
,
1112 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1113 WERROR werr
= WERR_GENERAL_FAILURE
;
1114 const char *server_name
= cli
->desthost
;
1115 struct DcSitesCtr
*ctr
= NULL
;
1116 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1118 if (argc
< 1 || argc
> 3) {
1119 fprintf(stderr
, "Usage: %s <server_name>\n", argv
[0]);
1124 server_name
= argv
[1];
1127 status
= dcerpc_netr_DsrGetDcSiteCoverageW(b
, mem_ctx
,
1131 if (!NT_STATUS_IS_OK(status
)) {
1132 werr
= ntstatus_to_werror(status
);
1136 if (W_ERROR_IS_OK(werr
) && ctr
->num_sites
) {
1138 printf("sites covered by this DC: %d\n", ctr
->num_sites
);
1139 for (i
=0; i
<ctr
->num_sites
; i
++) {
1140 printf("%s\n", ctr
->sites
[i
].string
);
1147 static NTSTATUS
cmd_netlogon_database_redo(struct rpc_pipe_client
*cli
,
1148 TALLOC_CTX
*mem_ctx
, int argc
,
1151 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1153 const char *server_name
= cli
->desthost
;
1154 struct netr_Authenticator clnt_creds
, srv_cred
;
1155 struct netr_DELTA_ENUM_ARRAY
*delta_enum_array
= NULL
;
1156 struct netr_ChangeLogEntry e
;
1158 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1159 struct netlogon_creds_CredentialState
*creds
= NULL
;
1162 fprintf(stderr
, "Usage: %s <user rid>\n", argv
[0]);
1163 return NT_STATUS_OK
;
1167 sscanf(argv
[1], "%d", &rid
);
1170 if (rpcclient_netlogon_creds
== NULL
) {
1171 return NT_STATUS_UNSUCCESSFUL
;
1174 status
= netlogon_creds_cli_lock(rpcclient_netlogon_creds
,
1176 if (!NT_STATUS_IS_OK(status
)) {
1180 netlogon_creds_client_authenticator(creds
, &clnt_creds
);
1185 e
.db_index
= SAM_DATABASE_DOMAIN
;
1186 e
.delta_type
= NETR_DELTA_USER
;
1188 status
= dcerpc_netr_DatabaseRedo(b
, mem_ctx
,
1194 0, /* is calculated automatically */
1197 if (!NT_STATUS_IS_OK(status
)) {
1202 if (!netlogon_creds_client_check(creds
, &srv_cred
.cred
)) {
1203 DEBUG(0,("credentials chain check failed\n"));
1205 return NT_STATUS_ACCESS_DENIED
;
1212 static NTSTATUS
cmd_netlogon_capabilities(struct rpc_pipe_client
*cli
,
1213 TALLOC_CTX
*mem_ctx
, int argc
,
1216 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
1218 struct netr_Authenticator credential
;
1219 struct netr_Authenticator return_authenticator
;
1220 union netr_Capabilities capabilities
;
1222 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
1223 struct netlogon_creds_CredentialState
*creds
= NULL
;
1226 fprintf(stderr
, "Usage: %s <level>\n", argv
[0]);
1227 return NT_STATUS_OK
;
1231 level
= atoi(argv
[1]);
1234 ZERO_STRUCT(return_authenticator
);
1236 if (rpcclient_netlogon_creds
== NULL
) {
1237 return NT_STATUS_UNSUCCESSFUL
;
1240 status
= netlogon_creds_cli_lock(rpcclient_netlogon_creds
,
1242 if (!NT_STATUS_IS_OK(status
)) {
1246 netlogon_creds_client_authenticator(creds
, &credential
);
1248 status
= dcerpc_netr_LogonGetCapabilities(b
, mem_ctx
,
1252 &return_authenticator
,
1256 if (!NT_STATUS_IS_OK(status
)) {
1261 if (!netlogon_creds_client_check(creds
,
1262 &return_authenticator
.cred
)) {
1263 DEBUG(0,("credentials chain check failed\n"));
1265 return NT_STATUS_ACCESS_DENIED
;
1269 printf("capabilities: 0x%08x\n", capabilities
.server_capabilities
);
1274 /* List of commands exported by this module */
1276 struct cmd_set netlogon_commands
[] = {
1280 { "logonctrl2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl2
, &ndr_table_netlogon
, NULL
, "Logon Control 2", "" },
1281 { "getanydcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getanydcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1282 { "getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted PDC name", "" },
1283 { "dsr_getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcname
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1284 { "dsr_getdcnameex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1285 { "dsr_getdcnameex2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex2
, &ndr_table_netlogon
, NULL
, "Get trusted DC name", "" },
1286 { "dsr_getsitename", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getsitename
, &ndr_table_netlogon
, NULL
, "Get sitename", "" },
1287 { "dsr_getforesttrustinfo", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getforesttrustinfo
, &ndr_table_netlogon
, NULL
, "Get Forest Trust Info", "" },
1288 { "logonctrl", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_logon_ctrl
, &ndr_table_netlogon
, NULL
, "Logon Control", "" },
1289 { "samsync", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_sync
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Synchronisation", "" },
1290 { "samdeltas", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_deltas
, NULL
, &ndr_table_netlogon
, NULL
, "Query Sam Deltas", "" },
1291 { "samlogon", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_logon
, NULL
, &ndr_table_netlogon
, NULL
, "Sam Logon", "" },
1292 { "change_trust_pw", RPC_RTYPE_NTSTATUS
, cmd_netlogon_change_trust_pw
, NULL
, &ndr_table_netlogon
, NULL
, "Change Trust Account Password", "" },
1293 { "gettrustrid", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_gettrustrid
, &ndr_table_netlogon
, NULL
, "Get trust rid", "" },
1294 { "dsr_enumtrustdom", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1295 { "dsenumdomtrusts", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_enumtrustdom
, &ndr_table_netlogon
, NULL
, "Enumerate all trusted domains in an AD forest", "" },
1296 { "deregisterdnsrecords", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_deregisterdnsrecords
, &ndr_table_netlogon
, NULL
, "Deregister DNS records", "" },
1297 { "netrenumtrusteddomains", RPC_RTYPE_NTSTATUS
, cmd_netlogon_enumtrusteddomains
, NULL
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1298 { "netrenumtrusteddomainsex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_enumtrusteddomainsex
, &ndr_table_netlogon
, NULL
, "Enumerate trusted domains", "" },
1299 { "getdcsitecoverage", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getdcsitecoverage
, &ndr_table_netlogon
, NULL
, "Get the Site-Coverage from a DC", "" },
1300 { "database_redo", RPC_RTYPE_NTSTATUS
, cmd_netlogon_database_redo
, NULL
, &ndr_table_netlogon
, NULL
, "Replicate single object from a DC", "" },
1301 { "capabilities", RPC_RTYPE_NTSTATUS
, cmd_netlogon_capabilities
, NULL
, &ndr_table_netlogon
, NULL
, "Return Capabilities", "" },