patch from MORIYAMA Masayuki to save LDFLAGS during iconv detection; bug 570
[Samba/gebeck_regimport.git] / source3 / rpcclient / cmd_netlogon.c
bloba48b59bf6a38ec31b4a49dd77aec08c5b53dfa5c
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 cli_state *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 = cli_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_logon_ctrl(struct cli_state *cli,
49 TALLOC_CTX *mem_ctx, int argc,
50 const char **argv)
52 #if 0
53 uint32 query_level = 1;
54 #endif
55 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
57 if (argc > 1) {
58 fprintf(stderr, "Usage: %s\n", argv[0]);
59 return NT_STATUS_OK;
62 #if 0
63 result = cli_netlogon_logon_ctrl(cli, mem_ctx, query_level);
64 if (!NT_STATUS_IS_OK(result)) {
65 goto done;
67 #endif
69 /* Display results */
71 return result;
74 /* Display sam synchronisation information */
76 static void display_sam_sync(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas,
77 SAM_DELTA_CTR *deltas)
79 fstring name;
80 uint32 i, j;
82 for (i = 0; i < num_deltas; i++) {
83 switch (hdr_deltas[i].type) {
84 case SAM_DELTA_DOMAIN_INFO:
85 unistr2_to_ascii(name,
86 &deltas[i].domain_info.uni_dom_name,
87 sizeof(name) - 1);
88 printf("Domain: %s\n", name);
89 break;
90 case SAM_DELTA_GROUP_INFO:
91 unistr2_to_ascii(name,
92 &deltas[i].group_info.uni_grp_name,
93 sizeof(name) - 1);
94 printf("Group: %s\n", name);
95 break;
96 case SAM_DELTA_ACCOUNT_INFO:
97 unistr2_to_ascii(name,
98 &deltas[i].account_info.uni_acct_name,
99 sizeof(name) - 1);
100 printf("Account: %s\n", name);
101 break;
102 case SAM_DELTA_ALIAS_INFO:
103 unistr2_to_ascii(name,
104 &deltas[i].alias_info.uni_als_name,
105 sizeof(name) - 1);
106 printf("Alias: %s\n", name);
107 break;
108 case SAM_DELTA_ALIAS_MEM: {
109 SAM_ALIAS_MEM_INFO *alias = &deltas[i].als_mem_info;
111 for (j = 0; j < alias->num_members; j++) {
112 fstring sid_str;
114 sid_to_string(sid_str, &alias->sids[j].sid);
116 printf("%s\n", sid_str);
118 break;
120 case SAM_DELTA_GROUP_MEM: {
121 SAM_GROUP_MEM_INFO *group = &deltas[i].grp_mem_info;
123 for (j = 0; j < group->num_members; j++)
124 printf("rid 0x%x, attrib 0x%08x\n",
125 group->rids[j], group->attribs[j]);
126 break;
128 case SAM_DELTA_MODIFIED_COUNT: {
129 SAM_DELTA_MOD_COUNT *mc = &deltas[i].mod_count;
131 printf("sam sequence update: 0x%04x\n", mc->seqnum);
132 break;
134 default:
135 printf("unknown delta type 0x%02x\n",
136 hdr_deltas[i].type);
137 break;
142 /* Perform sam synchronisation */
144 static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli,
145 TALLOC_CTX *mem_ctx, int argc,
146 const char **argv)
148 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
149 uint32 database_id = 0, num_deltas;
150 SAM_DELTA_HDR *hdr_deltas;
151 SAM_DELTA_CTR *deltas;
152 DOM_CRED ret_creds;
154 if (argc > 2) {
155 fprintf(stderr, "Usage: %s [database_id]\n", argv[0]);
156 return NT_STATUS_OK;
159 if (argc == 2)
160 database_id = atoi(argv[1]);
162 /* on first call the returnAuthenticator is empty */
163 memset(&ret_creds, 0, sizeof(ret_creds));
165 /* Synchronise sam database */
167 result = cli_netlogon_sam_sync(cli, mem_ctx, &ret_creds, database_id,
168 0, &num_deltas, &hdr_deltas, &deltas);
170 if (!NT_STATUS_IS_OK(result))
171 goto done;
173 /* Display results */
175 display_sam_sync(num_deltas, hdr_deltas, deltas);
177 done:
178 return result;
181 /* Perform sam delta synchronisation */
183 static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli,
184 TALLOC_CTX *mem_ctx, int argc,
185 const char **argv)
187 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
188 uint32 database_id, num_deltas, tmp;
189 SAM_DELTA_HDR *hdr_deltas;
190 SAM_DELTA_CTR *deltas;
191 UINT64_S seqnum;
193 if (argc != 3) {
194 fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
195 return NT_STATUS_OK;
198 database_id = atoi(argv[1]);
199 tmp = atoi(argv[2]);
201 seqnum.low = tmp & 0xffff;
202 seqnum.high = 0;
204 result = cli_netlogon_sam_deltas(cli, mem_ctx, database_id,
205 seqnum, &num_deltas,
206 &hdr_deltas, &deltas);
208 if (!NT_STATUS_IS_OK(result))
209 goto done;
211 /* Display results */
213 display_sam_sync(num_deltas, hdr_deltas, deltas);
215 done:
216 return result;
219 /* Log on a domain user */
221 static NTSTATUS cmd_netlogon_sam_logon(struct cli_state *cli,
222 TALLOC_CTX *mem_ctx, int argc,
223 const char **argv)
225 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
226 int logon_type = NET_LOGON_TYPE;
227 const char *username, *password;
228 uint32 neg_flags = 0x000001ff;
229 int auth_level = 2;
230 DOM_CRED ret_creds;
232 /* Check arguments */
234 if (argc < 3 || argc > 6) {
235 fprintf(stderr, "Usage: samlogon <username> <password> "
236 "[logon_type] [neg flags] [auth level (2 or 3)]\n"
237 "neg flags being 0x000001ff or 0x6007ffff\n");
238 return NT_STATUS_OK;
241 username = argv[1];
242 password = argv[2];
244 if (argc == 4)
245 sscanf(argv[3], "%i", &logon_type);
247 if (argc == 5)
248 sscanf(argv[4], "%i", &neg_flags);
250 if (argc == 6)
251 sscanf(argv[5], "%i", &auth_level);
253 /* Perform the sam logon */
255 ZERO_STRUCT(ret_creds);
257 result = cli_netlogon_sam_logon(cli, mem_ctx, &ret_creds, username, password, logon_type);
259 clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), &ret_creds);
261 result = cli_netlogon_sam_logon(cli, mem_ctx, &ret_creds, username, password, logon_type);
263 clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), &ret_creds);
265 if (!NT_STATUS_IS_OK(result))
266 goto done;
268 done:
269 return result;
272 /* Change the trust account password */
274 static NTSTATUS cmd_netlogon_change_trust_pw(struct cli_state *cli,
275 TALLOC_CTX *mem_ctx, int argc,
276 const char **argv)
278 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
279 DOM_CRED ret_creds;
281 /* Check arguments */
283 if (argc > 1) {
284 fprintf(stderr, "Usage: change_trust_pw");
285 return NT_STATUS_OK;
288 /* Perform the sam logon */
290 ZERO_STRUCT(ret_creds);
292 result = trust_pw_find_change_and_store_it(cli, mem_ctx,
293 lp_workgroup());
295 clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), &ret_creds);
297 if (!NT_STATUS_IS_OK(result))
298 goto done;
300 done:
301 return result;
305 /* List of commands exported by this module */
307 struct cmd_set netlogon_commands[] = {
309 { "NETLOGON" },
311 { "logonctrl2", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl2, NULL, PI_NETLOGON, "Logon Control 2", "" },
312 { "logonctrl", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl, NULL, PI_NETLOGON, "Logon Control", "" },
313 { "samsync", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync, NULL, PI_NETLOGON, "Sam Synchronisation", "" },
314 { "samdeltas", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas, NULL, PI_NETLOGON, "Query Sam Deltas", "" },
315 { "samlogon", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_logon, NULL, PI_NETLOGON, "Sam Logon", "" },
316 { "samlogon", RPC_RTYPE_NTSTATUS, cmd_netlogon_change_trust_pw, NULL, PI_NETLOGON, "Change Trust Account Password", "" },
318 { NULL }