r10929: tagging release
[Samba.git] / RPCREWRITE / source / rpcclient / cmd_netlogon.c
blob153daa5cf2d51e3c8fa3fdb006a7c710dc5a982b
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
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.
22 #include "includes.h"
23 #include "rpcclient.h"
25 static NTSTATUS cmd_netlogon_logon_ctrl2(struct rpc_pipe_client *cli,
26 TALLOC_CTX *mem_ctx, int argc,
27 const char **argv)
29 uint32 query_level = 1;
30 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
32 if (argc > 1) {
33 fprintf(stderr, "Usage: %s\n", argv[0]);
34 return NT_STATUS_OK;
37 result = rpccli_netlogon_logon_ctrl2(cli, mem_ctx, query_level);
39 if (!NT_STATUS_IS_OK(result))
40 goto done;
42 /* Display results */
44 done:
45 return result;
48 static NTSTATUS cmd_netlogon_getdcname(struct rpc_pipe_client *cli,
49 TALLOC_CTX *mem_ctx, int argc,
50 const char **argv)
52 fstring dcname;
53 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
55 if (argc != 2) {
56 fprintf(stderr, "Usage: %s domainname\n", argv[0]);
57 return NT_STATUS_OK;
60 result = rpccli_netlogon_getdcname(cli, mem_ctx, cli->cli->desthost, argv[1], dcname);
62 if (!NT_STATUS_IS_OK(result))
63 goto done;
65 /* Display results */
67 printf("%s\n", dcname);
69 done:
70 return result;
73 static NTSTATUS cmd_netlogon_logon_ctrl(struct rpc_pipe_client *cli,
74 TALLOC_CTX *mem_ctx, int argc,
75 const char **argv)
77 #if 0
78 uint32 query_level = 1;
79 #endif
80 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
82 if (argc > 1) {
83 fprintf(stderr, "Usage: %s\n", argv[0]);
84 return NT_STATUS_OK;
87 #if 0
88 result = cli_netlogon_logon_ctrl(cli, mem_ctx, query_level);
89 if (!NT_STATUS_IS_OK(result)) {
90 goto done;
92 #endif
94 /* Display results */
96 return result;
99 /* Display sam synchronisation information */
101 static void display_sam_sync(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas,
102 SAM_DELTA_CTR *deltas)
104 fstring name;
105 uint32 i, j;
107 for (i = 0; i < num_deltas; i++) {
108 switch (hdr_deltas[i].type) {
109 case SAM_DELTA_DOMAIN_INFO:
110 unistr2_to_ascii(name,
111 &deltas[i].domain_info.uni_dom_name,
112 sizeof(name) - 1);
113 printf("Domain: %s\n", name);
114 break;
115 case SAM_DELTA_GROUP_INFO:
116 unistr2_to_ascii(name,
117 &deltas[i].group_info.uni_grp_name,
118 sizeof(name) - 1);
119 printf("Group: %s\n", name);
120 break;
121 case SAM_DELTA_ACCOUNT_INFO:
122 unistr2_to_ascii(name,
123 &deltas[i].account_info.uni_acct_name,
124 sizeof(name) - 1);
125 printf("Account: %s\n", name);
126 break;
127 case SAM_DELTA_ALIAS_INFO:
128 unistr2_to_ascii(name,
129 &deltas[i].alias_info.uni_als_name,
130 sizeof(name) - 1);
131 printf("Alias: %s\n", name);
132 break;
133 case SAM_DELTA_ALIAS_MEM: {
134 SAM_ALIAS_MEM_INFO *alias = &deltas[i].als_mem_info;
136 for (j = 0; j < alias->num_members; j++) {
137 fstring sid_str;
139 sid_to_string(sid_str, &alias->sids[j].sid);
141 printf("%s\n", sid_str);
143 break;
145 case SAM_DELTA_GROUP_MEM: {
146 SAM_GROUP_MEM_INFO *group = &deltas[i].grp_mem_info;
148 for (j = 0; j < group->num_members; j++)
149 printf("rid 0x%x, attrib 0x%08x\n",
150 group->rids[j], group->attribs[j]);
151 break;
153 case SAM_DELTA_MODIFIED_COUNT: {
154 SAM_DELTA_MOD_COUNT *mc = &deltas[i].mod_count;
156 printf("sam sequence update: 0x%04x\n", mc->seqnum);
157 break;
159 default:
160 printf("unknown delta type 0x%02x\n",
161 hdr_deltas[i].type);
162 break;
167 /* Perform sam synchronisation */
169 static NTSTATUS cmd_netlogon_sam_sync(struct rpc_pipe_client *cli,
170 TALLOC_CTX *mem_ctx, int argc,
171 const char **argv)
173 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
174 uint32 database_id = 0, num_deltas;
175 SAM_DELTA_HDR *hdr_deltas;
176 SAM_DELTA_CTR *deltas;
178 if (argc > 2) {
179 fprintf(stderr, "Usage: %s [database_id]\n", argv[0]);
180 return NT_STATUS_OK;
183 if (argc == 2)
184 database_id = atoi(argv[1]);
186 /* Synchronise sam database */
188 result = rpccli_netlogon_sam_sync(cli, mem_ctx, database_id,
189 0, &num_deltas, &hdr_deltas, &deltas);
191 if (!NT_STATUS_IS_OK(result))
192 goto done;
194 /* Display results */
196 display_sam_sync(num_deltas, hdr_deltas, deltas);
198 done:
199 return result;
202 /* Perform sam delta synchronisation */
204 static NTSTATUS cmd_netlogon_sam_deltas(struct rpc_pipe_client *cli,
205 TALLOC_CTX *mem_ctx, int argc,
206 const char **argv)
208 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
209 uint32 database_id, num_deltas, tmp;
210 SAM_DELTA_HDR *hdr_deltas;
211 SAM_DELTA_CTR *deltas;
212 UINT64_S seqnum;
214 if (argc != 3) {
215 fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
216 return NT_STATUS_OK;
219 database_id = atoi(argv[1]);
220 tmp = atoi(argv[2]);
222 seqnum.low = tmp & 0xffff;
223 seqnum.high = 0;
225 result = rpccli_netlogon_sam_deltas(cli, mem_ctx, database_id,
226 seqnum, &num_deltas,
227 &hdr_deltas, &deltas);
229 if (!NT_STATUS_IS_OK(result))
230 goto done;
232 /* Display results */
234 display_sam_sync(num_deltas, hdr_deltas, deltas);
236 done:
237 return result;
240 /* Log on a domain user */
242 static NTSTATUS cmd_netlogon_sam_logon(struct rpc_pipe_client *cli,
243 TALLOC_CTX *mem_ctx, int argc,
244 const char **argv)
246 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
247 int logon_type = NET_LOGON_TYPE;
248 const char *username, *password;
249 uint32 neg_flags = 0x000001ff;
250 int auth_level = 2;
252 /* Check arguments */
254 if (argc < 3 || argc > 6) {
255 fprintf(stderr, "Usage: samlogon <username> <password> "
256 "[logon_type] [neg flags] [auth level (2 or 3)]\n"
257 "neg flags being 0x000001ff or 0x6007ffff\n");
258 return NT_STATUS_OK;
261 username = argv[1];
262 password = argv[2];
264 if (argc >= 4)
265 sscanf(argv[3], "%i", &logon_type);
267 if (argc >= 5)
268 sscanf(argv[4], "%i", &neg_flags);
270 if (argc == 6)
271 sscanf(argv[5], "%i", &auth_level);
273 /* Perform the sam logon */
275 result = rpccli_netlogon_sam_logon(cli, mem_ctx, lp_workgroup(), username, password, logon_type);
277 if (!NT_STATUS_IS_OK(result))
278 goto done;
280 done:
281 return result;
284 /* Change the trust account password */
286 static NTSTATUS cmd_netlogon_change_trust_pw(struct rpc_pipe_client *cli,
287 TALLOC_CTX *mem_ctx, int argc,
288 const char **argv)
290 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
292 /* Check arguments */
294 if (argc > 1) {
295 fprintf(stderr, "Usage: change_trust_pw");
296 return NT_STATUS_OK;
299 /* Perform the sam logon */
301 result = trust_pw_find_change_and_store_it(cli, mem_ctx,
302 lp_workgroup());
304 if (!NT_STATUS_IS_OK(result))
305 goto done;
307 done:
308 return result;
312 /* List of commands exported by this module */
314 struct cmd_set netlogon_commands[] = {
316 { "NETLOGON" },
318 { "logonctrl2", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl2, NULL, PI_NETLOGON, NULL, "Logon Control 2", "" },
319 { "getdcname", RPC_RTYPE_NTSTATUS, cmd_netlogon_getdcname, NULL, PI_NETLOGON, NULL, "Get trusted DC name", "" },
320 { "logonctrl", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl, NULL, PI_NETLOGON, NULL, "Logon Control", "" },
321 { "samsync", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync, NULL, PI_NETLOGON, NULL, "Sam Synchronisation", "" },
322 { "samdeltas", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas, NULL, PI_NETLOGON, NULL, "Query Sam Deltas", "" },
323 { "samlogon", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_logon, NULL, PI_NETLOGON, NULL, "Sam Logon", "" },
324 { "change_trust_pw", RPC_RTYPE_NTSTATUS, cmd_netlogon_change_trust_pw, NULL, PI_NETLOGON, NULL, "Change Trust Account Password", "" },
326 { NULL }