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 cli_state *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 = cli_netlogon_logon_ctrl2(cli, mem_ctx, query_level);
39 if (!NT_STATUS_IS_OK(result))
48 static NTSTATUS cmd_netlogon_logon_ctrl(struct cli_state *cli,
49 TALLOC_CTX *mem_ctx, int argc,
53 uint32 query_level = 1;
55 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
58 fprintf(stderr, "Usage: %s\n", argv[0]);
63 result = cli_netlogon_logon_ctrl(cli, mem_ctx, query_level);
64 if (!NT_STATUS_IS_OK(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)
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,
88 printf("Domain: %s\n", name);
90 case SAM_DELTA_GROUP_INFO:
91 unistr2_to_ascii(name,
92 &deltas[i].group_info.uni_grp_name,
94 printf("Group: %s\n", name);
96 case SAM_DELTA_ACCOUNT_INFO:
97 unistr2_to_ascii(name,
98 &deltas[i].account_info.uni_acct_name,
100 printf("Account: %s\n", name);
102 case SAM_DELTA_ALIAS_INFO:
103 unistr2_to_ascii(name,
104 &deltas[i].alias_info.uni_als_name,
106 printf("Alias: %s\n", name);
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++) {
114 sid_to_string(sid_str, &alias->sids[j].sid);
116 printf("%s\n", sid_str);
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]);
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);
135 printf("unknown delta type 0x%02x\n",
142 /* Perform sam synchronisation */
144 static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli,
145 TALLOC_CTX *mem_ctx, int argc,
148 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
149 unsigned char trust_passwd[16];
150 uint32 database_id = 0, num_deltas;
151 SAM_DELTA_HDR *hdr_deltas;
152 SAM_DELTA_CTR *deltas;
154 uint32 neg_flags = 0x000001ff;
157 fprintf(stderr, "Usage: %s [database_id]\n", argv[0]);
162 database_id = atoi(argv[1]);
164 if (!secrets_init()) {
165 fprintf(stderr, "Unable to initialise secrets database\n");
169 /* Initialise session credentials */
171 if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
173 fprintf(stderr, "could not fetch trust account password\n");
177 result = cli_nt_setup_creds(cli, get_sec_chan(), trust_passwd, &neg_flags, 2);
179 if (!NT_STATUS_IS_OK(result)) {
180 fprintf(stderr, "Error initialising session creds\n");
184 /* on first call the returnAuthenticator is empty */
185 memset(&ret_creds, 0, sizeof(ret_creds));
187 /* Synchronise sam database */
189 result = cli_netlogon_sam_sync(cli, mem_ctx, &ret_creds, database_id,
190 0, &num_deltas, &hdr_deltas, &deltas);
192 if (!NT_STATUS_IS_OK(result))
195 /* Display results */
197 display_sam_sync(num_deltas, hdr_deltas, deltas);
203 /* Perform sam delta synchronisation */
205 static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli,
206 TALLOC_CTX *mem_ctx, int argc,
209 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
210 unsigned char trust_passwd[16];
211 uint32 database_id, num_deltas, tmp;
212 SAM_DELTA_HDR *hdr_deltas;
213 SAM_DELTA_CTR *deltas;
215 uint32 neg_flags = 0x000001ff;
218 fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
222 database_id = atoi(argv[1]);
225 seqnum.low = tmp & 0xffff;
228 if (!secrets_init()) {
229 fprintf(stderr, "Unable to initialise secrets database\n");
233 /* Initialise session credentials */
235 if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
237 fprintf(stderr, "could not fetch trust account password\n");
241 result = cli_nt_setup_creds(cli, get_sec_chan(), trust_passwd, &neg_flags, 2);
243 if (!NT_STATUS_IS_OK(result)) {
244 fprintf(stderr, "Error initialising session creds\n");
248 /* Synchronise sam database */
250 result = cli_netlogon_sam_deltas(cli, mem_ctx, database_id,
252 &hdr_deltas, &deltas);
254 if (!NT_STATUS_IS_OK(result))
257 /* Display results */
259 display_sam_sync(num_deltas, hdr_deltas, deltas);
265 /* Log on a domain user */
267 static NTSTATUS cmd_netlogon_sam_logon(struct cli_state *cli,
268 TALLOC_CTX *mem_ctx, int argc,
271 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
272 int logon_type = NET_LOGON_TYPE;
273 const char *username, *password;
274 uint32 neg_flags = 0x000001ff;
277 /* Check arguments */
279 if (argc < 3 || argc > 6) {
280 fprintf(stderr, "Usage: samlogon <username> <password> "
281 "[logon_type] [neg flags] [auth level (2 or 3)]\n"
282 "neg flags being 0x000001ff or 0x6007ffff\n");
290 sscanf(argv[3], "%i", &logon_type);
293 sscanf(argv[4], "%i", &neg_flags);
296 sscanf(argv[5], "%i", &auth_level);
298 /* Perform the sam logon */
300 result = cli_netlogon_sam_logon(cli, mem_ctx, username, password, logon_type);
302 if (!NT_STATUS_IS_OK(result))
309 /* List of commands exported by this module */
311 struct cmd_set netlogon_commands[] = {
315 { "logonctrl2", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl2, NULL, PI_NETLOGON, "Logon Control 2", "" },
316 { "logonctrl", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl, NULL, PI_NETLOGON, "Logon Control", "" },
317 { "samsync", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync, NULL, PI_NETLOGON, "Sam Synchronisation", "" },
318 { "samdeltas", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas, NULL, PI_NETLOGON, "Query Sam Deltas", "" },
319 { "samlogon", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_logon, NULL, PI_NETLOGON, "Sam Logon", "" },