2 Unix SMB/Netbios implementation.
6 Copyright (C) Tim Potter 2000
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 static NTSTATUS cmd_netlogon_logon_ctrl2(struct cli_state *cli, int argc,
28 uint32 query_level = 1;
30 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
33 printf("Usage: %s\n", argv[0]);
37 if (!(mem_ctx = talloc_init())) {
38 DEBUG(0,("cmd_srvsvc_srv_query_info: talloc_init failed\n"));
42 /* Initialise RPC connection */
44 if (!cli_nt_session_open (cli, PIPE_NETLOGON)) {
45 DEBUG(0, ("Could not initialize srvsvc pipe!\n"));
49 result = cli_netlogon_logon_ctrl2(cli, mem_ctx, query_level);
50 if (!NT_STATUS_IS_OK(result)) {
60 static NTSTATUS cmd_netlogon_logon_ctrl(struct cli_state *cli, int argc,
64 uint32 query_level = 1;
67 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
70 printf("Usage: %s\n", argv[0]);
74 if (!(mem_ctx = talloc_init())) {
75 DEBUG(0,("cmd_srvsvc_srv_query_info: talloc_init failed\n"));
79 /* Initialise RPC connection */
81 if (!cli_nt_session_open (cli, PIPE_NETLOGON)) {
82 DEBUG(0, ("Could not initialize netlogon pipe!\n"));
87 result = cli_netlogon_logon_ctrl(cli, mem_ctx, query_level);
88 if (!NT_STATUS_IS_OK(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)
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,
113 DEBUG(0, ("Domain: %s\n", name));
115 case SAM_DELTA_GROUP_INFO:
116 unistr2_to_ascii(name,
117 &deltas[i].group_info.uni_grp_name,
119 DEBUG(0, ("Group: %s\n", name));
121 case SAM_DELTA_ACCOUNT_INFO:
122 unistr2_to_ascii(name,
123 &deltas[i].account_info.uni_acct_name,
125 DEBUG(0, ("Account: %s\n", name));
127 case SAM_DELTA_ALIAS_INFO:
128 unistr2_to_ascii(name,
129 &deltas[i].alias_info.uni_als_name,
131 DEBUG(0, ("Alias: %s\n", name));
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++) {
139 sid_to_string(sid_str, &alias->sids[j].sid);
141 DEBUG(0, ("%s\n", sid_str));
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 DEBUG(0, ("rid 0x%x, attrib 0x%08x\n",
150 group->rids[j], group->attribs[j]));
153 case SAM_DELTA_SAM_STAMP: {
154 SAM_DELTA_STAMP *stamp = &deltas[i].stamp;
156 DEBUG(0, ("sam sequence update: 0x%04x\n",
161 DEBUG(0, ("unknown delta type 0x%02x\n",
162 hdr_deltas[i].type));
168 /* Perform sam synchronisation */
170 static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli, int argc,
173 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
174 unsigned char trust_passwd[16];
176 uint32 database_id = 0, num_deltas;
177 SAM_DELTA_HDR *hdr_deltas;
178 SAM_DELTA_CTR *deltas;
181 printf("Usage: %s [database_id]\n", argv[0]);
186 database_id = atoi(argv[1]);
188 if (!secrets_init()) {
189 DEBUG(0, ("Unable to initialise secrets database\n"));
193 if (!(mem_ctx = talloc_init())) {
194 DEBUG(0,("talloc_init failed\n"));
198 /* Initialise RPC connection */
200 if (!cli_nt_session_open (cli, PIPE_NETLOGON)) {
201 DEBUG(0, ("Could not initialize netlogon pipe!\n"));
205 /* Initialise session credentials */
207 if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
209 DEBUG(0, ("could not fetch trust account password\n"));
213 result = cli_nt_setup_creds(cli, trust_passwd);
215 if (!NT_STATUS_IS_OK(result)) {
216 DEBUG(0, ("Error initialising session creds\n"));
220 /* Synchronise sam database */
222 result = cli_netlogon_sam_sync(cli, mem_ctx, database_id,
223 &num_deltas, &hdr_deltas, &deltas);
224 if (!NT_STATUS_IS_OK(result)) {
228 /* Display results */
230 display_sam_sync(num_deltas, hdr_deltas, deltas);
233 cli_nt_session_close(cli);
234 talloc_destroy(mem_ctx);
239 /* Perform sam delta synchronisation */
241 static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli, int argc,
244 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
245 unsigned char trust_passwd[16];
246 TALLOC_CTX *mem_ctx = NULL;
247 uint32 database_id, num_deltas, tmp;
248 SAM_DELTA_HDR *hdr_deltas;
249 SAM_DELTA_CTR *deltas;
253 printf("Usage: %s database_id seqnum\n", argv[0]);
257 database_id = atoi(argv[1]);
260 seqnum.low = tmp & 0xffff;
263 if (!secrets_init()) {
264 DEBUG(0, ("Unable to initialise secrets database\n"));
268 if (!(mem_ctx = talloc_init())) {
269 DEBUG(0,("talloc_init failed\n"));
273 /* Initialise RPC connection */
275 if (!cli_nt_session_open (cli, PIPE_NETLOGON)) {
276 DEBUG(0, ("Could not initialize netlogon pipe!\n"));
280 /* Initialise session credentials */
282 if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
284 DEBUG(0, ("could not fetch trust account password\n"));
288 result = cli_nt_setup_creds(cli, trust_passwd);
290 if (!NT_STATUS_IS_OK(result)) {
291 DEBUG(0, ("Error initialising session creds\n"));
295 /* Synchronise sam database */
297 result = cli_netlogon_sam_deltas(cli, mem_ctx, database_id,
299 &hdr_deltas, &deltas);
300 if (!NT_STATUS_IS_OK(result)) {
304 /* Display results */
306 display_sam_sync(num_deltas, hdr_deltas, deltas);
309 cli_nt_session_close(cli);
310 talloc_destroy(mem_ctx);
315 /* List of commands exported by this module */
317 struct cmd_set netlogon_commands[] = {
321 { "logonctrl2", cmd_netlogon_logon_ctrl2, "Logon Control 2", "" },
322 { "logonctrl", cmd_netlogon_logon_ctrl, "Logon Control", "" },
323 { "samsync", cmd_netlogon_sam_sync, "Sam Synchronisation", "" },
324 { "samdeltas", cmd_netlogon_sam_deltas, "Query Sam Deltas", "" },