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;
57 fprintf(stderr, "Usage: %s domainname\n", argv[0]);
61 /* Make sure to wait for our DC's reply */
62 old_timeout = cli_set_timeout(cli->cli, MAX(cli->cli->timeout,30000)); /* 30 seconds. */
64 result = rpccli_netlogon_getanydcname(cli, mem_ctx, cli->cli->desthost, argv[1], dcname);
66 cli_set_timeout(cli->cli, old_timeout);
68 if (!W_ERROR_IS_OK(result))
73 printf("%s\n", dcname);
79 static WERROR cmd_netlogon_getdcname(struct rpc_pipe_client *cli,
80 TALLOC_CTX *mem_ctx, int argc,
84 WERROR result = WERR_GENERAL_FAILURE;
88 fprintf(stderr, "Usage: %s domainname\n", argv[0]);
92 /* Make sure to wait for our DC's reply */
93 old_timeout = cli_set_timeout(cli->cli, MAX(cli->cli->timeout,30000)); /* 30 seconds. */
95 result = rpccli_netlogon_getdcname(cli, mem_ctx, cli->cli->desthost, argv[1], dcname);
97 cli_set_timeout(cli->cli, old_timeout);
99 if (!W_ERROR_IS_OK(result))
102 /* Display results */
104 printf("%s\n", dcname);
110 static void display_ds_domain_controller_info(TALLOC_CTX *mem_ctx, const struct DS_DOMAIN_CONTROLLER_INFO *info)
112 d_printf("domain_controller_name: %s\n", info->domain_controller_name);
113 d_printf("domain_controller_address: %s\n", info->domain_controller_address);
114 d_printf("domain_controller_address_type: %d\n", info->domain_controller_address_type);
115 d_printf("domain_guid: %s\n", GUID_string(mem_ctx, info->domain_guid));
116 d_printf("domain_name: %s\n", info->domain_name);
117 d_printf("dns_forest_name: %s\n", info->dns_forest_name);
118 d_printf("flags: 0x%08x\n"
120 "\tIs a GC of the forest: %s\n"
121 "\tIs an LDAP server: %s\n"
122 "\tSupports DS: %s\n"
123 "\tIs running a KDC: %s\n"
124 "\tIs running time services: %s\n"
125 "\tIs the closest DC: %s\n"
126 "\tIs writable: %s\n"
127 "\tHas a hardware clock: %s\n"
128 "\tIs a non-domain NC serviced by LDAP server: %s\n"
129 "\tDomainControllerName is a DNS name: %s\n"
130 "\tDomainName is a DNS name: %s\n"
131 "\tDnsForestName is a DNS name: %s\n",
133 (info->flags & ADS_PDC) ? "yes" : "no",
134 (info->flags & ADS_GC) ? "yes" : "no",
135 (info->flags & ADS_LDAP) ? "yes" : "no",
136 (info->flags & ADS_DS) ? "yes" : "no",
137 (info->flags & ADS_KDC) ? "yes" : "no",
138 (info->flags & ADS_TIMESERV) ? "yes" : "no",
139 (info->flags & ADS_CLOSEST) ? "yes" : "no",
140 (info->flags & ADS_WRITABLE) ? "yes" : "no",
141 (info->flags & ADS_GOOD_TIMESERV) ? "yes" : "no",
142 (info->flags & ADS_NDNC) ? "yes" : "no",
143 (info->flags & ADS_DNS_CONTROLLER) ? "yes":"no",
144 (info->flags & ADS_DNS_DOMAIN) ? "yes":"no",
145 (info->flags & ADS_DNS_FOREST) ? "yes":"no");
147 d_printf("dc_site_name: %s\n", info->dc_site_name);
148 d_printf("client_site_name: %s\n", info->client_site_name);
151 static WERROR cmd_netlogon_dsr_getdcname(struct rpc_pipe_client *cli,
152 TALLOC_CTX *mem_ctx, int argc,
156 uint32 flags = DS_RETURN_DNS_NAME;
157 const char *server_name = cli->cli->desthost;
158 const char *domain_name;
159 struct GUID domain_guid = GUID_zero();
160 struct GUID site_guid = GUID_zero();
161 struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
164 fprintf(stderr, "Usage: %s [domainname] [domain_name] [domain_guid] [site_guid] [flags]\n", argv[0]);
169 domain_name = argv[1];
172 if (!NT_STATUS_IS_OK(GUID_from_string(argv[2], &domain_guid))) {
178 if (!NT_STATUS_IS_OK(GUID_from_string(argv[3], &site_guid))) {
184 sscanf(argv[4], "%x", &flags);
186 result = rpccli_netlogon_dsr_getdcname(cli, mem_ctx, server_name, domain_name,
187 &domain_guid, &site_guid, flags,
190 if (W_ERROR_IS_OK(result)) {
191 d_printf("DsGetDcName gave\n");
192 display_ds_domain_controller_info(mem_ctx, info);
196 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
202 static WERROR cmd_netlogon_dsr_getdcnameex(struct rpc_pipe_client *cli,
203 TALLOC_CTX *mem_ctx, int argc,
207 uint32 flags = DS_RETURN_DNS_NAME;
208 const char *server_name = cli->cli->desthost;
209 const char *domain_name;
210 const char *site_name = NULL;
211 struct GUID domain_guid = GUID_zero();
212 struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
215 fprintf(stderr, "Usage: %s [domainname] [domain_name] [domain_guid] [site_name] [flags]\n", argv[0]);
220 domain_name = argv[1];
223 if (!NT_STATUS_IS_OK(GUID_from_string(argv[2], &domain_guid))) {
232 sscanf(argv[4], "%x", &flags);
234 result = rpccli_netlogon_dsr_getdcnameex(cli, mem_ctx, server_name, domain_name,
235 &domain_guid, site_name, flags,
238 if (W_ERROR_IS_OK(result)) {
239 d_printf("DsGetDcNameEx gave\n");
240 display_ds_domain_controller_info(mem_ctx, info);
244 printf("rpccli_netlogon_dsr_getdcnameex returned %s\n",
250 static WERROR cmd_netlogon_dsr_getdcnameex2(struct rpc_pipe_client *cli,
251 TALLOC_CTX *mem_ctx, int argc,
255 uint32 flags = DS_RETURN_DNS_NAME;
256 const char *server_name = cli->cli->desthost;
257 const char *domain_name = NULL;
258 const char *client_account = NULL;
260 const char *site_name = NULL;
261 struct GUID domain_guid = GUID_zero();
262 struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
265 fprintf(stderr, "Usage: %s [domainname] [client_account] [acb_mask] [domain_name] [domain_guid] [site_name] [flags]\n", argv[0]);
270 client_account = argv[1];
273 mask = atoi(argv[2]);
276 domain_name = argv[3];
279 if (!NT_STATUS_IS_OK(GUID_from_string(argv[4], &domain_guid))) {
288 sscanf(argv[6], "%x", &flags);
290 result = rpccli_netlogon_dsr_getdcnameex2(cli, mem_ctx, server_name,
291 client_account, mask,
292 domain_name, &domain_guid,
296 if (W_ERROR_IS_OK(result)) {
297 d_printf("DsGetDcNameEx2 gave\n");
298 display_ds_domain_controller_info(mem_ctx, info);
302 printf("rpccli_netlogon_dsr_getdcnameex2 returned %s\n",
309 static WERROR cmd_netlogon_dsr_getsitename(struct rpc_pipe_client *cli,
310 TALLOC_CTX *mem_ctx, int argc,
317 fprintf(stderr, "Usage: %s computername\n", argv[0]);
321 result = rpccli_netlogon_dsr_getsitename(cli, mem_ctx, argv[1], &sitename);
323 if (!W_ERROR_IS_OK(result)) {
324 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
325 nt_errstr(werror_to_ntstatus(result)));
329 printf("Computer %s is on Site: %s\n", argv[1], sitename);
334 static NTSTATUS cmd_netlogon_logon_ctrl(struct rpc_pipe_client *cli,
335 TALLOC_CTX *mem_ctx, int argc,
339 uint32 query_level = 1;
341 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
344 fprintf(stderr, "Usage: %s\n", argv[0]);
349 result = cli_netlogon_logon_ctrl(cli, mem_ctx, query_level);
350 if (!NT_STATUS_IS_OK(result)) {
355 /* Display results */
360 /* Display sam synchronisation information */
362 static void display_sam_sync(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas,
363 SAM_DELTA_CTR *deltas)
368 for (i = 0; i < num_deltas; i++) {
369 switch (hdr_deltas[i].type) {
370 case SAM_DELTA_DOMAIN_INFO:
371 unistr2_to_ascii(name,
372 &deltas[i].domain_info.uni_dom_name,
374 printf("Domain: %s\n", name);
376 case SAM_DELTA_GROUP_INFO:
377 unistr2_to_ascii(name,
378 &deltas[i].group_info.uni_grp_name,
380 printf("Group: %s\n", name);
382 case SAM_DELTA_ACCOUNT_INFO:
383 unistr2_to_ascii(name,
384 &deltas[i].account_info.uni_acct_name,
386 printf("Account: %s\n", name);
388 case SAM_DELTA_ALIAS_INFO:
389 unistr2_to_ascii(name,
390 &deltas[i].alias_info.uni_als_name,
392 printf("Alias: %s\n", name);
394 case SAM_DELTA_ALIAS_MEM: {
395 SAM_ALIAS_MEM_INFO *alias = &deltas[i].als_mem_info;
397 for (j = 0; j < alias->num_members; j++) {
400 sid_to_string(sid_str, &alias->sids[j].sid);
402 printf("%s\n", sid_str);
406 case SAM_DELTA_GROUP_MEM: {
407 SAM_GROUP_MEM_INFO *group = &deltas[i].grp_mem_info;
409 for (j = 0; j < group->num_members; j++)
410 printf("rid 0x%x, attrib 0x%08x\n",
411 group->rids[j], group->attribs[j]);
414 case SAM_DELTA_MODIFIED_COUNT: {
415 SAM_DELTA_MOD_COUNT *mc = &deltas[i].mod_count;
417 printf("sam sequence update: 0x%04x\n", mc->seqnum);
421 printf("unknown delta type 0x%02x\n",
428 /* Perform sam synchronisation */
430 static NTSTATUS cmd_netlogon_sam_sync(struct rpc_pipe_client *cli,
431 TALLOC_CTX *mem_ctx, int argc,
434 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
435 uint32 database_id = 0, num_deltas;
436 SAM_DELTA_HDR *hdr_deltas;
437 SAM_DELTA_CTR *deltas;
440 fprintf(stderr, "Usage: %s [database_id]\n", argv[0]);
445 database_id = atoi(argv[1]);
447 /* Synchronise sam database */
449 result = rpccli_netlogon_sam_sync(cli, mem_ctx, database_id,
450 0, &num_deltas, &hdr_deltas, &deltas);
452 if (!NT_STATUS_IS_OK(result))
455 /* Display results */
457 display_sam_sync(num_deltas, hdr_deltas, deltas);
463 /* Perform sam delta synchronisation */
465 static NTSTATUS cmd_netlogon_sam_deltas(struct rpc_pipe_client *cli,
466 TALLOC_CTX *mem_ctx, int argc,
469 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
470 uint32 database_id, num_deltas, tmp;
471 SAM_DELTA_HDR *hdr_deltas;
472 SAM_DELTA_CTR *deltas;
476 fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
480 database_id = atoi(argv[1]);
483 seqnum = tmp & 0xffff;
485 result = rpccli_netlogon_sam_deltas(cli, mem_ctx, database_id,
487 &hdr_deltas, &deltas);
489 if (!NT_STATUS_IS_OK(result))
492 /* Display results */
494 display_sam_sync(num_deltas, hdr_deltas, deltas);
500 /* Log on a domain user */
502 static NTSTATUS cmd_netlogon_sam_logon(struct rpc_pipe_client *cli,
503 TALLOC_CTX *mem_ctx, int argc,
506 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
507 int logon_type = NET_LOGON_TYPE;
508 const char *username, *password;
510 uint32 logon_param = 0;
511 const char *workstation = NULL;
513 /* Check arguments */
515 if (argc < 3 || argc > 7) {
516 fprintf(stderr, "Usage: samlogon <username> <password> [workstation]"
517 "[logon_type (1 or 2)] [auth level (2 or 3)] [logon_parameter]\n");
525 workstation = argv[3];
528 sscanf(argv[4], "%i", &logon_type);
531 sscanf(argv[5], "%i", &auth_level);
534 sscanf(argv[6], "%x", &logon_param);
536 /* Perform the sam logon */
538 result = rpccli_netlogon_sam_logon(cli, mem_ctx, logon_param, lp_workgroup(), username, password, workstation, logon_type);
540 if (!NT_STATUS_IS_OK(result))
547 /* Change the trust account password */
549 static NTSTATUS cmd_netlogon_change_trust_pw(struct rpc_pipe_client *cli,
550 TALLOC_CTX *mem_ctx, int argc,
553 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
555 /* Check arguments */
558 fprintf(stderr, "Usage: change_trust_pw");
562 /* Perform the sam logon */
564 result = trust_pw_find_change_and_store_it(cli, mem_ctx,
567 if (!NT_STATUS_IS_OK(result))
575 /* List of commands exported by this module */
577 struct cmd_set netlogon_commands[] = {
581 { "logonctrl2", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl2, NULL, PI_NETLOGON, NULL, "Logon Control 2", "" },
582 { "getanydcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_getanydcname, PI_NETLOGON, NULL, "Get trusted DC name", "" },
583 { "getdcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_getdcname, PI_NETLOGON, NULL, "Get trusted PDC name", "" },
584 { "dsr_getdcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcname, PI_NETLOGON, NULL, "Get trusted DC name", "" },
585 { "dsr_getdcnameex", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcnameex, PI_NETLOGON, NULL, "Get trusted DC name", "" },
586 { "dsr_getdcnameex2", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcnameex2, PI_NETLOGON, NULL, "Get trusted DC name", "" },
587 { "dsr_getsitename", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getsitename, PI_NETLOGON, NULL, "Get sitename", "" },
588 { "logonctrl", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl, NULL, PI_NETLOGON, NULL, "Logon Control", "" },
589 { "samsync", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync, NULL, PI_NETLOGON, NULL, "Sam Synchronisation", "" },
590 { "samdeltas", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas, NULL, PI_NETLOGON, NULL, "Query Sam Deltas", "" },
591 { "samlogon", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_logon, NULL, PI_NETLOGON, NULL, "Sam Logon", "" },
592 { "change_trust_pw", RPC_RTYPE_NTSTATUS, cmd_netlogon_change_trust_pw, NULL, PI_NETLOGON, NULL, "Change Trust Account Password", "" },