fixed seg fault in registry frontend caused by trying to
[Samba.git] / source / rpcclient / cmd_reg.c
blobc089917f9b66d1f36b57a52f15fc2310322c007e
1 /*
2 Unix SMB/CIFS implementation.
3 NT Domain Authentication SMB / MSRPC client
4 Copyright (C) Andrew Tridgell 1994-1997
5 Copyright (C) Luke Kenneth Casson Leighton 1996-1997
6 Copyright (C) Simo Sorce 2001
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.
23 #include "includes.h"
24 #include "rpcclient.h"
27 * keys. of the form:
28 * ----
30 * [HKLM]|[HKU]\[parent_keyname_components]\[subkey]|[value]
32 * reg_getsubkey() splits this down into:
33 * [HKLM]|[HKU]\[parent_keyname_components] and [subkey]|[value]
35 * do_reg_connect() splits the left side down further into:
36 * [HKLM]|[HKU] and [parent_keyname_components].
38 * HKLM is short for HKEY_LOCAL_MACHINE
39 * HKU is short for HKEY_USERS
41 * oh, and HKEY stands for "Hive Key".
45 #if 0 /* Simo: reg functions need to be updated to the new cmd interface */
47 /****************************************************************************
48 nt registry enum
49 ****************************************************************************/
50 static void cmd_reg_enum(struct client_info *info)
52 BOOL res = True;
53 BOOL res1 = True;
54 BOOL res2 = True;
55 int i;
57 POLICY_HND key_pol;
58 fstring full_keyname;
59 fstring key_name;
62 * query key info
65 fstring key_class;
66 uint32 max_class_len = 0;
67 uint32 num_subkeys;
68 uint32 max_subkeylen;
69 uint32 max_subkeysize;
70 uint32 num_values;
71 uint32 max_valnamelen;
72 uint32 max_valbufsize;
73 uint32 sec_desc;
74 NTTIME mod_time;
77 * unknown 0x1a request
80 uint32 unk_1a_response;
82 DEBUG(5, ("cmd_reg_enum: smb_cli->fd:%d\n", smb_cli->fd));
84 if (!next_token_nr(NULL, full_keyname, NULL, sizeof(full_keyname)))
86 fprintf(out_hnd, "regenum <key_name>\n");
87 return;
90 /* open WINREG session. */
91 res = res ? cli_nt_session_open(smb_cli, PIPE_WINREG) : False;
93 /* open registry receive a policy handle */
94 res = res ? do_reg_connect(smb_cli, full_keyname, key_name,
95 &info->dom.reg_pol_connect) : False;
97 if ((*key_name) != 0)
99 /* open an entry */
100 res1 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
101 key_name, 0x02000000, &key_pol) : False;
103 else
105 memcpy(&key_pol, &info->dom.reg_pol_connect, sizeof(key_pol));
108 res1 = res1 ? do_reg_query_key(smb_cli,
109 &key_pol,
110 key_class, &max_class_len,
111 &num_subkeys, &max_subkeylen, &max_subkeysize,
112 &num_values, &max_valnamelen, &max_valbufsize,
113 &sec_desc, &mod_time) : False;
115 if (res1 && num_subkeys > 0)
117 fprintf(out_hnd,"Subkeys\n");
118 fprintf(out_hnd,"-------\n");
121 for (i = 0; i < num_subkeys; i++)
124 * enumerate key
127 fstring enum_name;
128 uint32 enum_unk1;
129 uint32 enum_unk2;
130 time_t key_mod_time;
132 /* unknown 1a it */
133 res2 = res1 ? do_reg_unknown_1a(smb_cli, &key_pol,
134 &unk_1a_response) : False;
136 if (res2 && unk_1a_response != 5)
138 fprintf(out_hnd,"Unknown 1a response: %x\n", unk_1a_response);
141 /* enum key */
142 res2 = res2 ? do_reg_enum_key(smb_cli, &key_pol,
143 i, enum_name,
144 &enum_unk1, &enum_unk2,
145 &key_mod_time) : False;
147 if (res2)
149 display_reg_key_info(out_hnd, ACTION_HEADER , enum_name, key_mod_time);
150 display_reg_key_info(out_hnd, ACTION_ENUMERATE, enum_name, key_mod_time);
151 display_reg_key_info(out_hnd, ACTION_FOOTER , enum_name, key_mod_time);
156 if (num_values > 0)
158 fprintf(out_hnd,"Key Values\n");
159 fprintf(out_hnd,"----------\n");
162 for (i = 0; i < num_values; i++)
165 * enumerate key
168 uint32 val_type;
169 BUFFER2 value;
170 fstring val_name;
172 /* unknown 1a it */
173 res2 = res1 ? do_reg_unknown_1a(smb_cli, &key_pol,
174 &unk_1a_response) : False;
176 if (res2 && unk_1a_response != 5)
178 fprintf(out_hnd,"Unknown 1a response: %x\n", unk_1a_response);
181 /* enum key */
182 res2 = res2 ? do_reg_enum_val(smb_cli, &key_pol,
183 i, max_valnamelen, max_valbufsize,
184 val_name, &val_type, &value) : False;
186 if (res2)
188 display_reg_value_info(out_hnd, ACTION_HEADER , val_name, val_type, &value);
189 display_reg_value_info(out_hnd, ACTION_ENUMERATE, val_name, val_type, &value);
190 display_reg_value_info(out_hnd, ACTION_FOOTER , val_name, val_type, &value);
194 /* close the handles */
195 if ((*key_name) != 0)
197 res1 = res1 ? do_reg_close(smb_cli, &key_pol) : False;
199 res = res ? do_reg_close(smb_cli, &info->dom.reg_pol_connect) : False;
201 /* close the session */
202 cli_nt_session_close(smb_cli);
204 if (res && res1 && res2)
206 DEBUG(5,("cmd_reg_enum: query succeeded\n"));
208 else
210 DEBUG(5,("cmd_reg_enum: query failed\n"));
214 /****************************************************************************
215 nt registry query key
216 ****************************************************************************/
217 static void cmd_reg_query_key(struct client_info *info)
219 BOOL res = True;
220 BOOL res1 = True;
222 POLICY_HND key_pol;
223 fstring full_keyname;
224 fstring key_name;
227 * query key info
230 fstring key_class;
231 uint32 key_class_len = 0;
232 uint32 num_subkeys;
233 uint32 max_subkeylen;
234 uint32 max_subkeysize;
235 uint32 num_values;
236 uint32 max_valnamelen;
237 uint32 max_valbufsize;
238 uint32 sec_desc;
239 NTTIME mod_time;
241 DEBUG(5, ("cmd_reg_enum: smb_cli->fd:%d\n", smb_cli->fd));
243 if (!next_token_nr(NULL, full_keyname, NULL, sizeof(full_keyname)))
245 fprintf(out_hnd, "regquery key_name\n");
246 return;
249 /* open WINREG session. */
250 res = res ? cli_nt_session_open(smb_cli, PIPE_WINREG) : False;
252 /* open registry receive a policy handle */
253 res = res ? do_reg_connect(smb_cli, full_keyname, key_name,
254 &info->dom.reg_pol_connect) : False;
256 if ((*key_name) != 0)
258 /* open an entry */
259 res1 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
260 key_name, 0x02000000, &key_pol) : False;
262 else
264 memcpy(&key_pol, &info->dom.reg_pol_connect, sizeof(key_pol));
267 res1 = res1 ? do_reg_query_key(smb_cli,
268 &key_pol,
269 key_class, &key_class_len,
270 &num_subkeys, &max_subkeylen, &max_subkeysize,
271 &num_values, &max_valnamelen, &max_valbufsize,
272 &sec_desc, &mod_time) : False;
274 if (res1 && key_class_len != 0)
276 res1 = res1 ? do_reg_query_key(smb_cli,
277 &key_pol,
278 key_class, &key_class_len,
279 &num_subkeys, &max_subkeylen, &max_subkeysize,
280 &num_values, &max_valnamelen, &max_valbufsize,
281 &sec_desc, &mod_time) : False;
284 if (res1)
286 fprintf(out_hnd,"Registry Query Info Key\n");
287 fprintf(out_hnd,"key class: %s\n", key_class);
288 fprintf(out_hnd,"subkeys, max_len, max_size: %d %d %d\n", num_subkeys, max_subkeylen, max_subkeysize);
289 fprintf(out_hnd,"vals, max_len, max_size: 0x%x 0x%x 0x%x\n", num_values, max_valnamelen, max_valbufsize);
290 fprintf(out_hnd,"sec desc: 0x%x\n", sec_desc);
291 fprintf(out_hnd,"mod time: %s\n", http_timestring(nt_time_to_unix(&mod_time)));
294 /* close the handles */
295 if ((*key_name) != 0)
297 res1 = res1 ? do_reg_close(smb_cli, &key_pol) : False;
299 res = res ? do_reg_close(smb_cli, &info->dom.reg_pol_connect) : False;
301 /* close the session */
302 cli_nt_session_close(smb_cli);
304 if (res && res1)
306 DEBUG(5,("cmd_reg_query: query succeeded\n"));
308 else
310 DEBUG(5,("cmd_reg_query: query failed\n"));
314 /****************************************************************************
315 nt registry create value
316 ****************************************************************************/
317 static void cmd_reg_create_val(struct client_info *info)
319 BOOL res = True;
320 BOOL res3 = True;
321 BOOL res4 = True;
323 POLICY_HND parent_pol;
324 fstring full_keyname;
325 fstring keyname;
326 fstring parent_name;
327 fstring val_name;
328 fstring tmp;
329 uint32 val_type;
330 BUFFER3 value;
332 #if 0
333 uint32 unk_0;
334 uint32 unk_1;
335 /* query it */
336 res1 = res1 ? do_reg_query_info(smb_cli, &val_pol,
337 val_name, *val_type) : False;
338 #endif
340 DEBUG(5, ("cmd_reg_create_val: smb_cli->fd:%d\n", smb_cli->fd));
342 if (!next_token_nr(NULL, full_keyname, NULL, sizeof(full_keyname)))
344 fprintf(out_hnd, "regcreate <val_name> <val_type> <val>\n");
345 return;
348 reg_get_subkey(full_keyname, keyname, val_name);
350 if (keyname[0] == 0 || val_name[0] == 0)
352 fprintf(out_hnd, "invalid key name\n");
353 return;
356 if (!next_token_nr(NULL, tmp, NULL, sizeof(tmp)))
358 fprintf(out_hnd, "regcreate <val_name> <val_type (1|4)> <val>\n");
359 return;
362 val_type = atoi(tmp);
364 if (val_type != 1 && val_type != 3 && val_type != 4)
366 fprintf(out_hnd, "val_type 1=UNISTR, 3=BYTES, 4=DWORD supported\n");
367 return;
370 if (!next_token_nr(NULL, tmp, NULL, sizeof(tmp)))
372 fprintf(out_hnd, "regcreate <val_name> <val_type (1|4)> <val>\n");
373 return;
376 switch (val_type)
378 case 0x01: /* UNISTR */
380 init_buffer3_str(&value, tmp, strlen(tmp)+1);
381 break;
383 case 0x03: /* BYTES */
385 init_buffer3_hex(&value, tmp);
386 break;
388 case 0x04: /* DWORD */
390 uint32 tmp_val;
391 if (strnequal(tmp, "0x", 2))
393 tmp_val = strtol(tmp, (char**)NULL, 16);
395 else
397 tmp_val = strtol(tmp, (char**)NULL, 10);
399 init_buffer3_uint32(&value, tmp_val);
400 break;
402 default:
404 fprintf(out_hnd, "i told you i only deal with UNISTR, DWORD and BYTES!\n");
405 return;
409 DEBUG(10,("key data:\n"));
410 dump_data(10, (char *)value.buffer, value.buf_len);
412 /* open WINREG session. */
413 res = res ? cli_nt_session_open(smb_cli, PIPE_WINREG) : False;
415 /* open registry receive a policy handle */
416 res = res ? do_reg_connect(smb_cli, keyname, parent_name,
417 &info->dom.reg_pol_connect) : False;
419 if ((*val_name) != 0)
421 /* open an entry */
422 res3 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
423 parent_name, 0x02000000, &parent_pol) : False;
425 else
427 memcpy(&parent_pol, &info->dom.reg_pol_connect, sizeof(parent_pol));
430 /* create an entry */
431 res4 = res3 ? do_reg_create_val(smb_cli, &parent_pol,
432 val_name, val_type, &value) : False;
434 /* flush the modified key */
435 res4 = res4 ? do_reg_flush_key(smb_cli, &parent_pol) : False;
437 /* close the val handle */
438 if ((*val_name) != 0)
440 res3 = res3 ? do_reg_close(smb_cli, &parent_pol) : False;
443 /* close the registry handles */
444 res = res ? do_reg_close(smb_cli, &info->dom.reg_pol_connect) : False;
446 /* close the session */
447 cli_nt_session_close(smb_cli);
449 if (res && res3 && res4)
451 DEBUG(5,("cmd_reg_create_val: query succeeded\n"));
452 fprintf(out_hnd,"OK\n");
454 else
456 DEBUG(5,("cmd_reg_create_val: query failed\n"));
460 /****************************************************************************
461 nt registry delete value
462 ****************************************************************************/
463 static void cmd_reg_delete_val(struct client_info *info)
465 BOOL res = True;
466 BOOL res3 = True;
467 BOOL res4 = True;
469 POLICY_HND parent_pol;
470 fstring full_keyname;
471 fstring keyname;
472 fstring parent_name;
473 fstring val_name;
475 DEBUG(5, ("cmd_reg_delete_val: smb_cli->fd:%d\n", smb_cli->fd));
477 if (!next_token_nr(NULL, full_keyname, NULL, sizeof(full_keyname)))
479 fprintf(out_hnd, "regdelete <val_name>\n");
480 return;
483 reg_get_subkey(full_keyname, keyname, val_name);
485 if (keyname[0] == 0 || val_name[0] == 0)
487 fprintf(out_hnd, "invalid key name\n");
488 return;
491 /* open WINREG session. */
492 res = res ? cli_nt_session_open(smb_cli, PIPE_WINREG) : False;
494 /* open registry receive a policy handle */
495 res = res ? do_reg_connect(smb_cli, keyname, parent_name,
496 &info->dom.reg_pol_connect) : False;
498 if ((*val_name) != 0)
500 /* open an entry */
501 res3 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
502 parent_name, 0x02000000, &parent_pol) : False;
504 else
506 memcpy(&parent_pol, &info->dom.reg_pol_connect, sizeof(parent_pol));
509 /* delete an entry */
510 res4 = res3 ? do_reg_delete_val(smb_cli, &parent_pol, val_name) : False;
512 /* flush the modified key */
513 res4 = res4 ? do_reg_flush_key(smb_cli, &parent_pol) : False;
515 /* close the key handle */
516 res3 = res3 ? do_reg_close(smb_cli, &parent_pol) : False;
518 /* close the registry handles */
519 res = res ? do_reg_close(smb_cli, &info->dom.reg_pol_connect) : False;
521 /* close the session */
522 cli_nt_session_close(smb_cli);
524 if (res && res3 && res4)
526 DEBUG(5,("cmd_reg_delete_val: query succeeded\n"));
527 fprintf(out_hnd,"OK\n");
529 else
531 DEBUG(5,("cmd_reg_delete_val: query failed\n"));
535 /****************************************************************************
536 nt registry delete key
537 ****************************************************************************/
538 static void cmd_reg_delete_key(struct client_info *info)
540 BOOL res = True;
541 BOOL res3 = True;
542 BOOL res4 = True;
544 POLICY_HND parent_pol;
545 fstring full_keyname;
546 fstring parent_name;
547 fstring key_name;
548 fstring subkey_name;
550 DEBUG(5, ("cmd_reg_delete_key: smb_cli->fd:%d\n", smb_cli->fd));
552 if (!next_token_nr(NULL, full_keyname, NULL, sizeof(full_keyname)))
554 fprintf(out_hnd, "regdeletekey <key_name>\n");
555 return;
558 reg_get_subkey(full_keyname, parent_name, subkey_name);
560 if (parent_name[0] == 0 || subkey_name[0] == 0)
562 fprintf(out_hnd, "invalid key name\n");
563 return;
566 /* open WINREG session. */
567 res = res ? cli_nt_session_open(smb_cli, PIPE_WINREG) : False;
569 /* open registry receive a policy handle */
570 res = res ? do_reg_connect(smb_cli, parent_name, key_name,
571 &info->dom.reg_pol_connect) : False;
573 if ((*key_name) != 0)
575 /* open an entry */
576 res3 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
577 key_name, 0x02000000, &parent_pol) : False;
579 else
581 memcpy(&parent_pol, &info->dom.reg_pol_connect, sizeof(parent_pol));
584 /* create an entry */
585 res4 = res3 ? do_reg_delete_key(smb_cli, &parent_pol, subkey_name) : False;
587 /* flush the modified key */
588 res4 = res4 ? do_reg_flush_key(smb_cli, &parent_pol) : False;
590 /* close the key handle */
591 if ((*key_name) != 0)
593 res3 = res3 ? do_reg_close(smb_cli, &parent_pol) : False;
596 /* close the registry handles */
597 res = res ? do_reg_close(smb_cli, &info->dom.reg_pol_connect) : False;
599 /* close the session */
600 cli_nt_session_close(smb_cli);
602 if (res && res3 && res4)
604 DEBUG(5,("cmd_reg_delete_key: query succeeded\n"));
605 fprintf(out_hnd,"OK\n");
607 else
609 DEBUG(5,("cmd_reg_delete_key: query failed\n"));
613 /****************************************************************************
614 nt registry create key
615 ****************************************************************************/
616 static void cmd_reg_create_key(struct client_info *info)
618 BOOL res = True;
619 BOOL res3 = True;
620 BOOL res4 = True;
622 POLICY_HND parent_pol;
623 POLICY_HND key_pol;
624 fstring full_keyname;
625 fstring parent_key;
626 fstring parent_name;
627 fstring key_name;
628 fstring key_class;
629 SEC_ACCESS sam_access;
631 DEBUG(5, ("cmd_reg_create_key: smb_cli->fd:%d\n", smb_cli->fd));
633 if (!next_token_nr(NULL, full_keyname, NULL, sizeof(full_keyname)))
635 fprintf(out_hnd, "regcreate <key_name> [key_class]\n");
636 return;
639 reg_get_subkey(full_keyname, parent_key, key_name);
641 if (parent_key[0] == 0 || key_name[0] == 0)
643 fprintf(out_hnd, "invalid key name\n");
644 return;
647 if (!next_token_nr(NULL, key_class, NULL, sizeof(key_class)))
649 memset(key_class, 0, sizeof(key_class));
652 /* set access permissions */
653 sam_access.mask = SEC_RIGHTS_READ;
655 /* open WINREG session. */
656 res = res ? cli_nt_session_open(smb_cli, PIPE_WINREG) : False;
658 /* open registry receive a policy handle */
659 res = res ? do_reg_connect(smb_cli, parent_key, parent_name,
660 &info->dom.reg_pol_connect) : False;
662 if ((*parent_name) != 0)
664 /* open an entry */
665 res3 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
666 parent_name, 0x02000000, &parent_pol) : False;
668 else
670 memcpy(&parent_pol, &info->dom.reg_pol_connect, sizeof(parent_pol));
673 /* create an entry */
674 res4 = res3 ? do_reg_create_key(smb_cli, &parent_pol,
675 key_name, key_class, &sam_access, &key_pol) : False;
677 /* flush the modified key */
678 res4 = res4 ? do_reg_flush_key(smb_cli, &parent_pol) : False;
680 /* close the key handle */
681 res4 = res4 ? do_reg_close(smb_cli, &key_pol) : False;
683 /* close the key handle */
684 if ((*parent_name) != 0)
686 res3 = res3 ? do_reg_close(smb_cli, &parent_pol) : False;
689 /* close the registry handles */
690 res = res ? do_reg_close(smb_cli, &info->dom.reg_pol_connect) : False;
692 /* close the session */
693 cli_nt_session_close(smb_cli);
695 if (res && res3 && res4)
697 DEBUG(5,("cmd_reg_create_key: query succeeded\n"));
698 fprintf(out_hnd,"OK\n");
700 else
702 DEBUG(5,("cmd_reg_create_key: query failed\n"));
706 /****************************************************************************
707 nt registry security info
708 ****************************************************************************/
709 static void cmd_reg_test_key_sec(struct client_info *info)
711 BOOL res = True;
712 BOOL res3 = True;
713 BOOL res4 = True;
715 POLICY_HND key_pol;
716 fstring full_keyname;
717 fstring key_name;
720 * security info
723 uint32 sec_buf_size;
724 SEC_DESC_BUF *psdb;
726 DEBUG(5, ("cmd_reg_get_key_sec: smb_cli->fd:%d\n", smb_cli->fd));
728 if (!next_token_nr(NULL, full_keyname, NULL, sizeof(full_keyname)))
730 fprintf(out_hnd, "reggetsec <key_name>\n");
731 return;
734 /* open WINREG session. */
735 res = res ? cli_nt_session_open(smb_cli, PIPE_WINREG) : False;
737 /* open registry receive a policy handle */
738 res = res ? do_reg_connect(smb_cli, full_keyname, key_name,
739 &info->dom.reg_pol_connect) : False;
741 if ((*key_name) != 0)
743 /* open an entry */
744 res3 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
745 key_name, 0x02000000, &key_pol) : False;
747 else
749 memcpy(&key_pol, &info->dom.reg_pol_connect, sizeof(key_pol));
752 /* open an entry */
753 res3 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
754 key_name, 0x02000000, &key_pol) : False;
756 /* query key sec info. first call sets sec_buf_size. */
758 sec_buf_size = 0;
759 res4 = res3 ? do_reg_get_key_sec(smb_cli, &key_pol,
760 &sec_buf_size, &psdb) : False;
762 free_sec_desc_buf(&psdb);
764 res4 = res4 ? do_reg_get_key_sec(smb_cli, &key_pol,
765 &sec_buf_size, &psdb) : False;
767 if (res4 && psdb->len > 0 && psdb->sec != NULL)
769 display_sec_desc(out_hnd, ACTION_HEADER , psdb->sec);
770 display_sec_desc(out_hnd, ACTION_ENUMERATE, psdb->sec);
771 display_sec_desc(out_hnd, ACTION_FOOTER , psdb->sec);
773 res4 = res4 ? do_reg_set_key_sec(smb_cli, &key_pol, psdb) : False;
776 free_sec_desc_buf(&psdb);
778 /* close the key handle */
779 if ((*key_name) != 0)
781 res3 = res3 ? do_reg_close(smb_cli, &key_pol) : False;
784 /* close the registry handles */
785 res = res ? do_reg_close(smb_cli, &info->dom.reg_pol_connect) : False;
787 /* close the session */
788 cli_nt_session_close(smb_cli);
790 if (res && res3 && res4)
792 DEBUG(5,("cmd_reg_test2: query succeeded\n"));
793 fprintf(out_hnd,"Registry Test2\n");
795 else
797 DEBUG(5,("cmd_reg_test2: query failed\n"));
801 /****************************************************************************
802 nt registry security info
803 ****************************************************************************/
804 static void cmd_reg_get_key_sec(struct client_info *info)
806 BOOL res = True;
807 BOOL res3 = True;
808 BOOL res4 = True;
810 POLICY_HND key_pol;
811 fstring full_keyname;
812 fstring key_name;
815 * security info
818 uint32 sec_buf_size;
819 SEC_DESC_BUF *psdb;
821 DEBUG(5, ("cmd_reg_get_key_sec: smb_cli->fd:%d\n", smb_cli->fd));
823 if (!next_token_nr(NULL, full_keyname, NULL, sizeof(full_keyname)))
825 fprintf(out_hnd, "reggetsec <key_name>\n");
826 return;
829 /* open WINREG session. */
830 res = res ? cli_nt_session_open(smb_cli, PIPE_WINREG) : False;
832 /* open registry receive a policy handle */
833 res = res ? do_reg_connect(smb_cli, full_keyname, key_name,
834 &info->dom.reg_pol_connect) : False;
836 if ((*key_name) != 0)
838 /* open an entry */
839 res3 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
840 key_name, 0x02000000, &key_pol) : False;
842 else
844 memcpy(&key_pol, &info->dom.reg_pol_connect, sizeof(key_pol));
847 /* open an entry */
848 res3 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
849 key_name, 0x02000000, &key_pol) : False;
851 /* Get the size. */
852 sec_buf_size = 0;
853 res4 = res3 ? do_reg_get_key_sec(smb_cli, &key_pol,
854 &sec_buf_size, &psdb) : False;
856 free_sec_desc_buf(&psdb);
858 res4 = res4 ? do_reg_get_key_sec(smb_cli, &key_pol,
859 &sec_buf_size, &psdb) : False;
861 if (res4 && psdb->len > 0 && psdb->sec != NULL)
863 display_sec_desc(out_hnd, ACTION_HEADER , psdb->sec);
864 display_sec_desc(out_hnd, ACTION_ENUMERATE, psdb->sec);
865 display_sec_desc(out_hnd, ACTION_FOOTER , psdb->sec);
868 free_sec_desc_buf(&psdb);
870 /* close the key handle */
871 if ((*key_name) != 0)
873 res3 = res3 ? do_reg_close(smb_cli, &key_pol) : False;
876 /* close the registry handles */
877 res = res ? do_reg_close(smb_cli, &info->dom.reg_pol_connect) : False;
879 /* close the session */
880 cli_nt_session_close(smb_cli);
882 if (res && res3 && res4)
884 DEBUG(5,("cmd_reg_get_key_sec: query succeeded\n"));
886 else
888 DEBUG(5,("cmd_reg_get_key_sec: query failed\n"));
892 #endif /* 0 */
894 /****************************************************************************
895 nt registry shutdown
896 ****************************************************************************/
897 static NTSTATUS cmd_reg_shutdown(struct cli_state *cli, TALLOC_CTX *mem_ctx,
898 int argc, char **argv)
900 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
901 fstring msg;
902 uint32 timeout = 20;
903 uint16 flgs = 0;
904 int opt;
906 *msg = 0;
907 optind = 0; /* TODO: test if this hack works on other systems too --simo */
909 while ((opt = getopt(argc, argv, "m:t:rf")) != EOF)
911 fprintf (stderr, "[%s]\n", argv[argc-1]);
913 switch (opt)
915 case 'm':
917 safe_strcpy(msg, optarg, sizeof(msg)-1);
918 fprintf (stderr, "[%s|%s]\n", optarg, msg);
919 break;
921 case 't':
923 timeout = atoi(optarg);
924 fprintf (stderr, "[%s|%d]\n", optarg, timeout);
925 break;
927 case 'r':
929 flgs |= 0x100;
930 break;
932 case 'f':
934 flgs |= 0x001;
935 break;
940 /* create an entry */
941 result = cli_reg_shutdown(cli, mem_ctx, msg, timeout, flgs);
943 if (NT_STATUS_IS_OK(result))
944 DEBUG(5,("cmd_reg_shutdown: query succeeded\n"));
945 else
946 DEBUG(5,("cmd_reg_shutdown: query failed\n"));
948 return result;
951 /****************************************************************************
952 abort a shutdown
953 ****************************************************************************/
954 static NTSTATUS cmd_reg_abort_shutdown(struct cli_state *cli,
955 TALLOC_CTX *mem_ctx, int argc,
956 char **argv)
958 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
960 result = cli_reg_abort_shutdown(cli, mem_ctx);
962 if (NT_STATUS_IS_OK(result))
963 DEBUG(5,("cmd_reg_abort_shutdown: query succeeded\n"));
964 else
965 DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
967 return result;
971 /* List of commands exported by this module */
972 struct cmd_set reg_commands[] = {
974 { "REG" },
976 { "shutdown", cmd_reg_shutdown, PIPE_WINREG, "Remote Shutdown",
977 "[-m message] [-t timeout] [-r] [-f] (-r == reboot, -f == force)" },
979 { "abortshutdown", cmd_reg_abort_shutdown, PIPE_WINREG, "Abort Shutdown",
980 "" },
982 { "regenum", cmd_reg_enum, "Registry Enumeration",
983 "<keyname>" },
985 { "regdeletekey", cmd_reg_delete_key, "Registry Key Delete",
986 "<keyname>" },
988 { "regcreatekey", cmd_reg_create_key, "Registry Key Create",
989 "<keyname> [keyclass]" },
991 { "regqueryval", cmd_reg_query_info, "Registry Value Query",
992 "<valname>" },
994 { "regquerykey", cmd_reg_query_key, "Registry Key Query",
995 "<keyname>" },
997 { "regdeleteval", cmd_reg_delete_val, "Registry Value Delete",
998 "<valname>" },
1000 { "regcreateval", cmd_reg_create_val, "Registry Key Create",
1001 "<valname> <valtype> <value>" },
1003 { "reggetsec", cmd_reg_get_key_sec, "Registry Key Security",
1004 "<keyname>" },
1006 { "regtestsec", cmd_reg_test_key_sec, "Test Registry Key Security",
1007 "<keyname>" },
1009 { NULL }