2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2000
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "rpcclient.h"
25 static NTSTATUS
cmd_netlogon_logon_ctrl2(struct rpc_pipe_client
*cli
,
26 TALLOC_CTX
*mem_ctx
, int argc
,
29 uint32 query_level
= 1;
30 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
33 fprintf(stderr
, "Usage: %s\n", argv
[0]);
37 result
= rpccli_netlogon_logon_ctrl2(cli
, mem_ctx
, query_level
);
39 if (!NT_STATUS_IS_OK(result
))
48 static WERROR
cmd_netlogon_getanydcname(struct rpc_pipe_client
*cli
,
49 TALLOC_CTX
*mem_ctx
, int argc
,
53 WERROR result
= WERR_GENERAL_FAILURE
;
56 fprintf(stderr
, "Usage: %s domainname\n", argv
[0]);
60 result
= rpccli_netlogon_getanydcname(cli
, mem_ctx
, cli
->cli
->desthost
, argv
[1], dcname
);
62 if (!W_ERROR_IS_OK(result
))
67 printf("%s\n", dcname
);
73 static void display_ds_domain_controller_info(TALLOC_CTX
*mem_ctx
, const struct DS_DOMAIN_CONTROLLER_INFO
*info
)
75 d_printf("domain_controller_name: %s\n", info
->domain_controller_name
);
76 d_printf("domain_controller_address: %s\n", info
->domain_controller_address
);
77 d_printf("domain_controller_address_type: %d\n", info
->domain_controller_address_type
);
78 d_printf("domain_guid: %s\n", GUID_string(mem_ctx
, info
->domain_guid
));
79 d_printf("domain_name: %s\n", info
->domain_name
);
80 d_printf("dns_forest_name: %s\n", info
->dns_forest_name
);
81 d_printf("flags: 0x%08x\n"
83 "\tIs a GC of the forest: %s\n"
84 "\tIs an LDAP server: %s\n"
86 "\tIs running a KDC: %s\n"
87 "\tIs running time services: %s\n"
88 "\tIs the closest DC: %s\n"
90 "\tHas a hardware clock: %s\n"
91 "\tIs a non-domain NC serviced by LDAP server: %s\n"
92 "\tDomainControllerName is a DNS name: %s\n"
93 "\tDomainName is a DNS name: %s\n"
94 "\tDnsForestName is a DNS name: %s\n",
96 (info
->flags
& ADS_PDC
) ? "yes" : "no",
97 (info
->flags
& ADS_GC
) ? "yes" : "no",
98 (info
->flags
& ADS_LDAP
) ? "yes" : "no",
99 (info
->flags
& ADS_DS
) ? "yes" : "no",
100 (info
->flags
& ADS_KDC
) ? "yes" : "no",
101 (info
->flags
& ADS_TIMESERV
) ? "yes" : "no",
102 (info
->flags
& ADS_CLOSEST
) ? "yes" : "no",
103 (info
->flags
& ADS_WRITABLE
) ? "yes" : "no",
104 (info
->flags
& ADS_GOOD_TIMESERV
) ? "yes" : "no",
105 (info
->flags
& ADS_NDNC
) ? "yes" : "no",
106 (info
->flags
& ADS_DNS_CONTROLLER
) ? "yes":"no",
107 (info
->flags
& ADS_DNS_DOMAIN
) ? "yes":"no",
108 (info
->flags
& ADS_DNS_FOREST
) ? "yes":"no");
110 d_printf("dc_site_name: %s\n", info
->dc_site_name
);
111 d_printf("client_site_name: %s\n", info
->client_site_name
);
114 static WERROR
cmd_netlogon_dsr_getdcname(struct rpc_pipe_client
*cli
,
115 TALLOC_CTX
*mem_ctx
, int argc
,
119 uint32 flags
= DS_RETURN_DNS_NAME
;
120 const char *server_name
= cli
->cli
->desthost
;
121 const char *domain_name
;
122 struct GUID domain_guid
= GUID_zero();
123 struct GUID site_guid
= GUID_zero();
124 struct DS_DOMAIN_CONTROLLER_INFO
*info
= NULL
;
127 fprintf(stderr
, "Usage: %s [domainname] [domain_name] [domain_guid] [site_guid] [flags]\n", argv
[0]);
132 domain_name
= argv
[1];
135 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
141 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[3], &site_guid
))) {
147 sscanf(argv
[4], "%x", &flags
);
149 result
= rpccli_netlogon_dsr_getdcname(cli
, mem_ctx
, server_name
, domain_name
,
150 &domain_guid
, &site_guid
, flags
,
153 if (W_ERROR_IS_OK(result
)) {
154 d_printf("DsGetDcName gave\n");
155 display_ds_domain_controller_info(mem_ctx
, info
);
159 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
165 static WERROR
cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client
*cli
,
166 TALLOC_CTX
*mem_ctx
, int argc
,
170 uint32 flags
= DS_RETURN_DNS_NAME
;
171 const char *server_name
= cli
->cli
->desthost
;
172 const char *domain_name
;
173 const char *site_name
= NULL
;
174 struct GUID domain_guid
= GUID_zero();
175 struct DS_DOMAIN_CONTROLLER_INFO
*info
= NULL
;
178 fprintf(stderr
, "Usage: %s [domainname] [domain_name] [domain_guid] [site_name] [flags]\n", argv
[0]);
183 domain_name
= argv
[1];
186 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[2], &domain_guid
))) {
195 sscanf(argv
[4], "%x", &flags
);
197 result
= rpccli_netlogon_dsr_getdcnameex(cli
, mem_ctx
, server_name
, domain_name
,
198 &domain_guid
, site_name
, flags
,
201 if (W_ERROR_IS_OK(result
)) {
202 d_printf("DsGetDcNameEx gave\n");
203 display_ds_domain_controller_info(mem_ctx
, info
);
207 printf("rpccli_netlogon_dsr_getdcnameex returned %s\n",
213 static WERROR
cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client
*cli
,
214 TALLOC_CTX
*mem_ctx
, int argc
,
218 uint32 flags
= DS_RETURN_DNS_NAME
;
219 const char *server_name
= cli
->cli
->desthost
;
220 const char *domain_name
;
221 const char *client_account
= NULL
;
223 const char *site_name
= NULL
;
224 struct GUID domain_guid
= GUID_zero();
225 struct DS_DOMAIN_CONTROLLER_INFO
*info
= NULL
;
228 fprintf(stderr
, "Usage: %s [domainname] [client_account] [acb_mask] [domain_name] [domain_guid] [site_name] [flags]\n", argv
[0]);
233 client_account
= argv
[1];
236 mask
= atoi(argv
[2]);
239 domain_name
= argv
[3];
242 if (!NT_STATUS_IS_OK(GUID_from_string(argv
[4], &domain_guid
))) {
251 sscanf(argv
[6], "%x", &flags
);
253 result
= rpccli_netlogon_dsr_getdcnameex2(cli
, mem_ctx
, server_name
,
254 client_account
, mask
,
255 domain_name
, &domain_guid
,
259 if (W_ERROR_IS_OK(result
)) {
260 d_printf("DsGetDcNameEx2 gave\n");
261 display_ds_domain_controller_info(mem_ctx
, info
);
265 printf("rpccli_netlogon_dsr_getdcnameex2 returned %s\n",
272 static WERROR
cmd_netlogon_dsr_getsitename(struct rpc_pipe_client
*cli
,
273 TALLOC_CTX
*mem_ctx
, int argc
,
280 fprintf(stderr
, "Usage: %s computername\n", argv
[0]);
284 result
= rpccli_netlogon_dsr_getsitename(cli
, mem_ctx
, argv
[1], &sitename
);
286 if (!W_ERROR_IS_OK(result
)) {
287 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
288 nt_errstr(werror_to_ntstatus(result
)));
292 printf("Computer %s is on Site: %s\n", argv
[1], sitename
);
297 static NTSTATUS
cmd_netlogon_logon_ctrl(struct rpc_pipe_client
*cli
,
298 TALLOC_CTX
*mem_ctx
, int argc
,
302 uint32 query_level
= 1;
304 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
307 fprintf(stderr
, "Usage: %s\n", argv
[0]);
312 result
= cli_netlogon_logon_ctrl(cli
, mem_ctx
, query_level
);
313 if (!NT_STATUS_IS_OK(result
)) {
318 /* Display results */
323 /* Display sam synchronisation information */
325 static void display_sam_sync(uint32 num_deltas
, SAM_DELTA_HDR
*hdr_deltas
,
326 SAM_DELTA_CTR
*deltas
)
331 for (i
= 0; i
< num_deltas
; i
++) {
332 switch (hdr_deltas
[i
].type
) {
333 case SAM_DELTA_DOMAIN_INFO
:
334 unistr2_to_ascii(name
,
335 &deltas
[i
].domain_info
.uni_dom_name
,
337 printf("Domain: %s\n", name
);
339 case SAM_DELTA_GROUP_INFO
:
340 unistr2_to_ascii(name
,
341 &deltas
[i
].group_info
.uni_grp_name
,
343 printf("Group: %s\n", name
);
345 case SAM_DELTA_ACCOUNT_INFO
:
346 unistr2_to_ascii(name
,
347 &deltas
[i
].account_info
.uni_acct_name
,
349 printf("Account: %s\n", name
);
351 case SAM_DELTA_ALIAS_INFO
:
352 unistr2_to_ascii(name
,
353 &deltas
[i
].alias_info
.uni_als_name
,
355 printf("Alias: %s\n", name
);
357 case SAM_DELTA_ALIAS_MEM
: {
358 SAM_ALIAS_MEM_INFO
*alias
= &deltas
[i
].als_mem_info
;
360 for (j
= 0; j
< alias
->num_members
; j
++) {
363 sid_to_string(sid_str
, &alias
->sids
[j
].sid
);
365 printf("%s\n", sid_str
);
369 case SAM_DELTA_GROUP_MEM
: {
370 SAM_GROUP_MEM_INFO
*group
= &deltas
[i
].grp_mem_info
;
372 for (j
= 0; j
< group
->num_members
; j
++)
373 printf("rid 0x%x, attrib 0x%08x\n",
374 group
->rids
[j
], group
->attribs
[j
]);
377 case SAM_DELTA_MODIFIED_COUNT
: {
378 SAM_DELTA_MOD_COUNT
*mc
= &deltas
[i
].mod_count
;
380 printf("sam sequence update: 0x%04x\n", mc
->seqnum
);
384 printf("unknown delta type 0x%02x\n",
391 /* Perform sam synchronisation */
393 static NTSTATUS
cmd_netlogon_sam_sync(struct rpc_pipe_client
*cli
,
394 TALLOC_CTX
*mem_ctx
, int argc
,
397 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
398 uint32 database_id
= 0, num_deltas
;
399 SAM_DELTA_HDR
*hdr_deltas
;
400 SAM_DELTA_CTR
*deltas
;
403 fprintf(stderr
, "Usage: %s [database_id]\n", argv
[0]);
408 database_id
= atoi(argv
[1]);
410 /* Synchronise sam database */
412 result
= rpccli_netlogon_sam_sync(cli
, mem_ctx
, database_id
,
413 0, &num_deltas
, &hdr_deltas
, &deltas
);
415 if (!NT_STATUS_IS_OK(result
))
418 /* Display results */
420 display_sam_sync(num_deltas
, hdr_deltas
, deltas
);
426 /* Perform sam delta synchronisation */
428 static NTSTATUS
cmd_netlogon_sam_deltas(struct rpc_pipe_client
*cli
,
429 TALLOC_CTX
*mem_ctx
, int argc
,
432 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
433 uint32 database_id
, num_deltas
, tmp
;
434 SAM_DELTA_HDR
*hdr_deltas
;
435 SAM_DELTA_CTR
*deltas
;
439 fprintf(stderr
, "Usage: %s database_id seqnum\n", argv
[0]);
443 database_id
= atoi(argv
[1]);
446 seqnum
= tmp
& 0xffff;
448 result
= rpccli_netlogon_sam_deltas(cli
, mem_ctx
, database_id
,
450 &hdr_deltas
, &deltas
);
452 if (!NT_STATUS_IS_OK(result
))
455 /* Display results */
457 display_sam_sync(num_deltas
, hdr_deltas
, deltas
);
463 /* Log on a domain user */
465 static NTSTATUS
cmd_netlogon_sam_logon(struct rpc_pipe_client
*cli
,
466 TALLOC_CTX
*mem_ctx
, int argc
,
469 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
470 int logon_type
= NET_LOGON_TYPE
;
471 const char *username
, *password
;
473 uint32 logon_param
= 0;
474 const char *workstation
= NULL
;
476 /* Check arguments */
478 if (argc
< 3 || argc
> 7) {
479 fprintf(stderr
, "Usage: samlogon <username> <password> [workstation]"
480 "[logon_type (1 or 2)] [auth level (2 or 3)] [logon_parameter]\n");
488 workstation
= argv
[3];
491 sscanf(argv
[4], "%i", &logon_type
);
494 sscanf(argv
[5], "%i", &auth_level
);
497 sscanf(argv
[6], "%x", &logon_param
);
499 /* Perform the sam logon */
501 result
= rpccli_netlogon_sam_logon(cli
, mem_ctx
, logon_param
, lp_workgroup(), username
, password
, workstation
, logon_type
);
503 if (!NT_STATUS_IS_OK(result
))
510 /* Change the trust account password */
512 static NTSTATUS
cmd_netlogon_change_trust_pw(struct rpc_pipe_client
*cli
,
513 TALLOC_CTX
*mem_ctx
, int argc
,
516 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
518 /* Check arguments */
521 fprintf(stderr
, "Usage: change_trust_pw");
525 /* Perform the sam logon */
527 result
= trust_pw_find_change_and_store_it(cli
, mem_ctx
,
530 if (!NT_STATUS_IS_OK(result
))
538 /* List of commands exported by this module */
540 struct cmd_set netlogon_commands
[] = {
544 { "logonctrl2", RPC_RTYPE_NTSTATUS
, cmd_netlogon_logon_ctrl2
, NULL
, PI_NETLOGON
, NULL
, "Logon Control 2", "" },
545 { "getanydcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_getanydcname
, PI_NETLOGON
, NULL
, "Get trusted DC name", "" },
546 { "dsr_getdcname", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcname
, PI_NETLOGON
, NULL
, "Get trusted DC name", "" },
547 { "dsr_getdcnameex", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex
, PI_NETLOGON
, NULL
, "Get trusted DC name", "" },
548 { "dsr_getdcnameex2", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getdcnameex2
, PI_NETLOGON
, NULL
, "Get trusted DC name", "" },
549 { "dsr_getsitename", RPC_RTYPE_WERROR
, NULL
, cmd_netlogon_dsr_getsitename
, PI_NETLOGON
, NULL
, "Get sitename", "" },
550 { "logonctrl", RPC_RTYPE_NTSTATUS
, cmd_netlogon_logon_ctrl
, NULL
, PI_NETLOGON
, NULL
, "Logon Control", "" },
551 { "samsync", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_sync
, NULL
, PI_NETLOGON
, NULL
, "Sam Synchronisation", "" },
552 { "samdeltas", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_deltas
, NULL
, PI_NETLOGON
, NULL
, "Query Sam Deltas", "" },
553 { "samlogon", RPC_RTYPE_NTSTATUS
, cmd_netlogon_sam_logon
, NULL
, PI_NETLOGON
, NULL
, "Sam Logon", "" },
554 { "change_trust_pw", RPC_RTYPE_NTSTATUS
, cmd_netlogon_change_trust_pw
, NULL
, PI_NETLOGON
, NULL
, "Change Trust Account Password", "" },