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 NTSTATUS cmd_netlogon_getdcname(struct rpc_pipe_client *cli,
49 TALLOC_CTX *mem_ctx, int argc,
53 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
56 fprintf(stderr, "Usage: %s domainname\n", argv[0]);
60 result = rpccli_netlogon_getdcname(cli, mem_ctx, cli->cli->desthost, argv[1], dcname);
62 if (!NT_STATUS_IS_OK(result))
67 printf("%s\n", dcname);
73 static WERROR cmd_netlogon_dsr_getdcname(struct rpc_pipe_client *cli,
74 TALLOC_CTX *mem_ctx, int argc,
78 char *dcname, *dcaddress;
81 fprintf(stderr, "Usage: %s domainname\n", argv[0]);
85 result = rpccli_netlogon_dsr_getdcname(
86 cli, mem_ctx, cli->cli->desthost, argv[1], NULL, NULL,
87 0x40000000, &dcname, &dcaddress, NULL, NULL, NULL, NULL,
90 if (W_ERROR_IS_OK(result)) {
91 printf("Domain %s's DC is called %s at IP %s\n",
92 argv[1], dcname, dcaddress);
96 printf("rpccli_netlogon_dsr_getdcname returned %s\n",
97 nt_errstr(werror_to_ntstatus(result)));
102 static WERROR cmd_netlogon_dsr_getsitename(struct rpc_pipe_client *cli,
103 TALLOC_CTX *mem_ctx, int argc,
110 fprintf(stderr, "Usage: %s computername\n", argv[0]);
114 result = rpccli_netlogon_dsr_getsitename(cli, mem_ctx, argv[1], &sitename);
116 if (!W_ERROR_IS_OK(result)) {
117 printf("rpccli_netlogon_dsr_gesitename returned %s\n",
118 nt_errstr(werror_to_ntstatus(result)));
122 printf("Computer %s is on Site: %s\n", argv[1], sitename);
127 static NTSTATUS cmd_netlogon_logon_ctrl(struct rpc_pipe_client *cli,
128 TALLOC_CTX *mem_ctx, int argc,
132 uint32 query_level = 1;
134 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
137 fprintf(stderr, "Usage: %s\n", argv[0]);
142 result = cli_netlogon_logon_ctrl(cli, mem_ctx, query_level);
143 if (!NT_STATUS_IS_OK(result)) {
148 /* Display results */
153 /* Display sam synchronisation information */
155 static void display_sam_sync(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas,
156 SAM_DELTA_CTR *deltas)
161 for (i = 0; i < num_deltas; i++) {
162 switch (hdr_deltas[i].type) {
163 case SAM_DELTA_DOMAIN_INFO:
164 unistr2_to_ascii(name,
165 &deltas[i].domain_info.uni_dom_name,
167 printf("Domain: %s\n", name);
169 case SAM_DELTA_GROUP_INFO:
170 unistr2_to_ascii(name,
171 &deltas[i].group_info.uni_grp_name,
173 printf("Group: %s\n", name);
175 case SAM_DELTA_ACCOUNT_INFO:
176 unistr2_to_ascii(name,
177 &deltas[i].account_info.uni_acct_name,
179 printf("Account: %s\n", name);
181 case SAM_DELTA_ALIAS_INFO:
182 unistr2_to_ascii(name,
183 &deltas[i].alias_info.uni_als_name,
185 printf("Alias: %s\n", name);
187 case SAM_DELTA_ALIAS_MEM: {
188 SAM_ALIAS_MEM_INFO *alias = &deltas[i].als_mem_info;
190 for (j = 0; j < alias->num_members; j++) {
193 sid_to_string(sid_str, &alias->sids[j].sid);
195 printf("%s\n", sid_str);
199 case SAM_DELTA_GROUP_MEM: {
200 SAM_GROUP_MEM_INFO *group = &deltas[i].grp_mem_info;
202 for (j = 0; j < group->num_members; j++)
203 printf("rid 0x%x, attrib 0x%08x\n",
204 group->rids[j], group->attribs[j]);
207 case SAM_DELTA_MODIFIED_COUNT: {
208 SAM_DELTA_MOD_COUNT *mc = &deltas[i].mod_count;
210 printf("sam sequence update: 0x%04x\n", mc->seqnum);
214 printf("unknown delta type 0x%02x\n",
221 /* Perform sam synchronisation */
223 static NTSTATUS cmd_netlogon_sam_sync(struct rpc_pipe_client *cli,
224 TALLOC_CTX *mem_ctx, int argc,
227 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
228 uint32 database_id = 0, num_deltas;
229 SAM_DELTA_HDR *hdr_deltas;
230 SAM_DELTA_CTR *deltas;
233 fprintf(stderr, "Usage: %s [database_id]\n", argv[0]);
238 database_id = atoi(argv[1]);
240 /* Synchronise sam database */
242 result = rpccli_netlogon_sam_sync(cli, mem_ctx, database_id,
243 0, &num_deltas, &hdr_deltas, &deltas);
245 if (!NT_STATUS_IS_OK(result))
248 /* Display results */
250 display_sam_sync(num_deltas, hdr_deltas, deltas);
256 /* Perform sam delta synchronisation */
258 static NTSTATUS cmd_netlogon_sam_deltas(struct rpc_pipe_client *cli,
259 TALLOC_CTX *mem_ctx, int argc,
262 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
263 uint32 database_id, num_deltas, tmp;
264 SAM_DELTA_HDR *hdr_deltas;
265 SAM_DELTA_CTR *deltas;
269 fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
273 database_id = atoi(argv[1]);
276 seqnum.low = tmp & 0xffff;
279 result = rpccli_netlogon_sam_deltas(cli, mem_ctx, database_id,
281 &hdr_deltas, &deltas);
283 if (!NT_STATUS_IS_OK(result))
286 /* Display results */
288 display_sam_sync(num_deltas, hdr_deltas, deltas);
294 /* Log on a domain user */
296 static NTSTATUS cmd_netlogon_sam_logon(struct rpc_pipe_client *cli,
297 TALLOC_CTX *mem_ctx, int argc,
300 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
301 int logon_type = NET_LOGON_TYPE;
302 const char *username, *password;
303 uint32 neg_flags = 0x000001ff;
306 /* Check arguments */
308 if (argc < 3 || argc > 6) {
309 fprintf(stderr, "Usage: samlogon <username> <password> "
310 "[logon_type] [neg flags] [auth level (2 or 3)]\n"
311 "neg flags being 0x000001ff or 0x6007ffff\n");
319 sscanf(argv[3], "%i", &logon_type);
322 sscanf(argv[4], "%i", &neg_flags);
325 sscanf(argv[5], "%i", &auth_level);
327 /* Perform the sam logon */
329 result = rpccli_netlogon_sam_logon(cli, mem_ctx, 0, lp_workgroup(), username, password, logon_type);
331 if (!NT_STATUS_IS_OK(result))
338 /* Change the trust account password */
340 static NTSTATUS cmd_netlogon_change_trust_pw(struct rpc_pipe_client *cli,
341 TALLOC_CTX *mem_ctx, int argc,
344 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
346 /* Check arguments */
349 fprintf(stderr, "Usage: change_trust_pw");
353 /* Perform the sam logon */
355 result = trust_pw_find_change_and_store_it(cli, mem_ctx,
358 if (!NT_STATUS_IS_OK(result))
366 /* List of commands exported by this module */
368 struct cmd_set netlogon_commands[] = {
372 { "logonctrl2", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl2, NULL, PI_NETLOGON, NULL, "Logon Control 2", "" },
373 { "getdcname", RPC_RTYPE_NTSTATUS, cmd_netlogon_getdcname, NULL, PI_NETLOGON, NULL, "Get trusted DC name", "" },
374 { "dsr_getdcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcname, PI_NETLOGON, NULL, "Get trusted DC name", "" },
375 { "dsr_getsitename", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getsitename, PI_NETLOGON, NULL, "Get sitename", "" },
376 { "logonctrl", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl, NULL, PI_NETLOGON, NULL, "Logon Control", "" },
377 { "samsync", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync, NULL, PI_NETLOGON, NULL, "Sam Synchronisation", "" },
378 { "samdeltas", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas, NULL, PI_NETLOGON, NULL, "Query Sam Deltas", "" },
379 { "samlogon", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_logon, NULL, PI_NETLOGON, NULL, "Sam Logon", "" },
380 { "change_trust_pw", RPC_RTYPE_NTSTATUS, cmd_netlogon_change_trust_pw, NULL, PI_NETLOGON, NULL, "Change Trust Account Password", "" },