preparing for release of alpha.1.4
[Samba.git] / source / rpcclient / cmd_reg.c
blob559f6b9d894e1a641ebceac67e8669082cb5fbfe
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 NT Domain Authentication SMB / MSRPC client
5 Copyright (C) Andrew Tridgell 1994-1999
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1999
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 #ifdef SYSLOG
26 #undef SYSLOG
27 #endif
29 #include "includes.h"
30 #include "rpc_parse.h"
32 extern int DEBUGLEVEL;
34 extern FILE* out_hnd;
37 * keys. of the form:
38 * ----
40 * [HKLM]|[HKU]|[HKCR]\[parent_keyname]\[subkey]|[value]
42 * reg_getsubkey() splits this down into:
43 * [HKLM]|[HKU]|[HKCR]\[parent_keyname_components] and [subkey]|[value]
45 * reg_connect() splits the left side down further into:
46 * [HKLM]|[HKU]|[HKCR] and [parent_keyname_components].
48 * HKLM is short for HKEY_LOCAL_MACHINE
49 * HKCR is short for HKEY_CLASSES_ROOT
50 * HKU is short for HKEY_USERS
52 * oh, and HKEY stands for "Hive Key".
56 static void reg_display_key(int val, const char *full_keyname, int num)
58 switch (val)
60 case 0:
62 /* initialsation */
63 report(out_hnd, "Key Name:\t%s\n", full_keyname);
64 break;
66 case 1:
68 /* subkeys initialisation */
69 if (num > 0)
71 report(out_hnd,"Subkeys\n");
72 report(out_hnd,"-------\n");
74 break;
76 case 2:
78 /* values initialisation */
79 if (num > 0)
81 report(out_hnd,"Key Values\n");
82 report(out_hnd,"----------\n");
84 break;
86 case 3:
88 /* clean-up */
89 break;
91 default:
93 break;
98 void split_server_keyname(char *srv_name, char *key, const char* arg)
100 pstrcpy(key, arg);
102 if (strnequal("\\\\", key, 2))
104 char *p = strchr(&key[2], '\\');
105 if (p == NULL)
107 key[0] = 0;
108 return;
111 *p = 0;
113 fstrcpy(srv_name, key);
114 pstrcpy(key, &arg[strlen(srv_name)+1]);
118 /****************************************************************************
119 nt registry enum
120 ****************************************************************************/
121 BOOL msrpc_reg_enum_key(const char* srv_name, const char* full_keyname,
122 REG_FN(reg_fn),
123 REG_KEY_FN(reg_key_fn),
124 REG_VAL_FN(reg_val_fn))
126 BOOL res = True;
127 BOOL res1 = True;
128 BOOL res2 = True;
129 int i;
131 POLICY_HND key_pol;
132 POLICY_HND pol_con;
133 fstring key_name;
136 * query key info
139 fstring key_class;
140 uint32 max_class_len = 0;
141 uint32 num_subkeys;
142 uint32 max_subkeylen;
143 uint32 max_subkeysize;
144 uint32 num_values;
145 uint32 max_valnamelen;
146 uint32 max_valbufsize;
147 uint32 sec_desc;
148 NTTIME mod_time;
151 * unknown 0x1a request
154 uint32 unk_1a_response;
156 DEBUG(5, ("reg_enum_key: %s\n", full_keyname));
158 /* open registry receive a policy handle */
159 res = res ? reg_connect(srv_name, full_keyname, key_name, 0x02000000,
160 &pol_con) : False;
162 if ((*key_name) != 0)
164 /* open an entry */
165 res1 = res ? reg_open_entry(&pol_con,
166 key_name, 0x02000000, &key_pol) : False;
168 else
170 memcpy(&key_pol, &pol_con, sizeof(key_pol));
173 res1 = res1 ? reg_query_key(&key_pol,
174 key_class, &max_class_len,
175 &num_subkeys, &max_subkeylen, &max_subkeysize,
176 &num_values, &max_valnamelen, &max_valbufsize,
177 &sec_desc, &mod_time) : False;
179 if (res1 && reg_fn != NULL)
181 reg_fn(0, full_keyname, 0);
182 reg_fn(1, full_keyname, num_subkeys);
185 for (i = 0; i < num_subkeys && reg_key_fn != NULL; i++)
188 * enumerate key
191 fstring enum_name;
192 uint32 enum_unk1;
193 uint32 enum_unk2;
194 time_t key_mod_time;
196 /* unknown 1a it */
197 res2 = res1 ? reg_unknown_1a(&key_pol,
198 &unk_1a_response) : False;
200 if (res2 && unk_1a_response != 5)
202 report(out_hnd,"Unknown 1a response: %x\n", unk_1a_response);
205 /* enum key */
206 res2 = res2 ? reg_enum_key(&key_pol,
207 i, enum_name,
208 &enum_unk1, &enum_unk2,
209 &key_mod_time) : False;
211 if (res2)
213 reg_key_fn(full_keyname, enum_name, key_mod_time);
218 if (reg_fn != NULL)
220 reg_fn(2, full_keyname, num_values);
223 for (i = 0; i < num_values && reg_val_fn != NULL; i++)
226 * enumerate key
229 uint32 val_type;
230 BUFFER2 value;
231 fstring val_name;
233 /* unknown 1a it */
234 res2 = res1 ? reg_unknown_1a(&key_pol,
235 &unk_1a_response) : False;
237 if (res2 && unk_1a_response != 5)
239 report(out_hnd,"Unknown 1a response: %x\n", unk_1a_response);
242 /* enum key */
243 res2 = res2 ? reg_enum_val(&key_pol,
244 i, max_valnamelen, max_valbufsize,
245 val_name, &val_type, &value) : False;
247 if (res2)
249 reg_val_fn(full_keyname, val_name, val_type, &value);
253 if (res1 && reg_fn != NULL)
255 reg_fn(3, full_keyname, 0);
258 /* close the handles */
259 if ((*key_name) != 0)
261 res1 = res1 ? reg_close(&key_pol) : False;
263 res = res ? reg_close(&pol_con) : False;
265 if (res && res1 && res2)
267 DEBUG(5,("msrpc_reg_enum_key: query succeeded\n"));
269 else
271 DEBUG(5,("msrpc_reg_enum_key: query failed\n"));
274 return res1;
277 static void reg_display_key_info(const char *full_name,
278 const char *name, time_t key_mod_time)
280 display_reg_key_info(out_hnd, ACTION_HEADER , name, key_mod_time);
281 display_reg_key_info(out_hnd, ACTION_ENUMERATE, name, key_mod_time);
282 display_reg_key_info(out_hnd, ACTION_FOOTER , name, key_mod_time);
285 static void reg_display_val_info(const char *full_name,
286 const char* name,
287 uint32 type,
288 const BUFFER2 *const value)
290 display_reg_value_info(out_hnd, ACTION_HEADER , name, type, value);
291 display_reg_value_info(out_hnd, ACTION_ENUMERATE, name, type, value);
292 display_reg_value_info(out_hnd, ACTION_FOOTER , name, type, value);
295 /****************************************************************************
296 nt registry enum
297 ****************************************************************************/
298 void cmd_reg_enum(struct client_info *info, int argc, char *argv[])
300 pstring full_keyname;
302 fstring srv_name;
304 fstrcpy(srv_name, "\\\\");
305 fstrcat(srv_name, info->dest_host);
306 strupper(srv_name);
308 if (argc < 2)
310 report(out_hnd, "regenum <key_name>\n");
311 return;
314 split_server_keyname(srv_name, full_keyname, argv[1]);
316 (void)(msrpc_reg_enum_key(srv_name, full_keyname,
317 reg_display_key,
318 reg_display_key_info,
319 reg_display_val_info));
322 /****************************************************************************
323 nt registry query value info
324 ****************************************************************************/
325 void cmd_reg_query_info(struct client_info *info, int argc, char *argv[])
327 BOOL res = True;
328 BOOL res1 = True;
329 BOOL res2 = True;
331 POLICY_HND key_pol;
332 POLICY_HND pol_con;
333 pstring full_keyname;
334 fstring key_name;
335 fstring keyname;
336 fstring val_name;
339 * query value info
342 BUFFER2 buf;
343 uint32 type;
345 fstring srv_name;
347 fstrcpy(srv_name, "\\\\");
348 fstrcat(srv_name, info->dest_host);
349 strupper(srv_name);
351 if (argc < 2)
353 report(out_hnd, "regvalinfo value_name\n");
354 return;
357 split_server_keyname(srv_name, full_keyname, argv[1]);
359 reg_get_subkey(full_keyname, keyname, val_name);
361 if (keyname[0] == 0 || val_name[0] == 0)
363 report(out_hnd, "invalid value name\n");
364 return;
367 /* open registry receive a policy handle */
368 res = res ? reg_connect(srv_name, keyname, key_name, 0x02000000,
369 &pol_con) : False;
371 if ((*key_name) != 0)
373 /* open an entry */
374 res1 = res ? reg_open_entry(&pol_con,
375 key_name, 0x02000000, &key_pol) : False;
377 else
379 memcpy(&key_pol, &pol_con, sizeof(key_pol));
382 /* query it */
383 res2 = res1 ? reg_query_info(&key_pol,
384 val_name, &type, &buf) : False;
386 if (res2)
388 reg_display_val_info(full_keyname, val_name, type, &buf);
391 /* close the handles */
392 if ((*key_name) != 0)
394 res1 = res1 ? reg_close(&key_pol) : False;
396 res = res ? reg_close(&pol_con) : False;
398 if (res2)
400 DEBUG(5,("cmd_reg_query: query succeeded\n"));
402 else
404 DEBUG(5,("cmd_reg_query: query failed\n"));
408 /****************************************************************************
409 nt registry query key
410 ****************************************************************************/
411 void cmd_reg_query_key(struct client_info *info, int argc, char *argv[])
413 BOOL res = True;
414 BOOL res1 = True;
416 POLICY_HND key_pol;
417 POLICY_HND pol_con;
418 pstring full_keyname;
419 fstring key_name;
422 * query key info
425 fstring key_class;
426 uint32 key_class_len = 0;
427 uint32 num_subkeys;
428 uint32 max_subkeylen;
429 uint32 max_subkeysize;
430 uint32 num_values;
431 uint32 max_valnamelen;
432 uint32 max_valbufsize;
433 uint32 sec_desc;
434 NTTIME mod_time;
436 fstring srv_name;
438 fstrcpy(srv_name, "\\\\");
439 fstrcat(srv_name, info->dest_host);
440 strupper(srv_name);
442 if (argc < 2)
444 report(out_hnd, "regquery key_name\n");
445 return;
448 split_server_keyname(srv_name, full_keyname, argv[1]);
450 /* open registry receive a policy handle */
451 res = res ? reg_connect(srv_name, full_keyname, key_name, 0x02000000,
452 &pol_con) : False;
454 if ((*key_name) != 0)
456 /* open an entry */
457 res1 = res ? reg_open_entry(&pol_con,
458 key_name, 0x02000000, &key_pol) : False;
460 else
462 memcpy(&key_pol, &pol_con, sizeof(key_pol));
465 res1 = res1 ? reg_query_key(&key_pol,
466 key_class, &key_class_len,
467 &num_subkeys, &max_subkeylen, &max_subkeysize,
468 &num_values, &max_valnamelen, &max_valbufsize,
469 &sec_desc, &mod_time) : False;
471 if (res1 && key_class_len != 0)
473 res1 = res1 ? reg_query_key(&key_pol,
474 key_class, &key_class_len,
475 &num_subkeys, &max_subkeylen, &max_subkeysize,
476 &num_values, &max_valnamelen, &max_valbufsize,
477 &sec_desc, &mod_time) : False;
480 if (res1)
482 report(out_hnd,"Registry Query Info Key\n");
483 report(out_hnd,"key class: %s\n", key_class);
484 report(out_hnd,"subkeys, max_len, max_size: %d %d %d\n", num_subkeys, max_subkeylen, max_subkeysize);
485 report(out_hnd,"vals, max_len, max_size: 0x%x 0x%x 0x%x\n", num_values, max_valnamelen, max_valbufsize);
486 report(out_hnd,"sec desc: 0x%x\n", sec_desc);
487 report(out_hnd,"mod time: %s\n", http_timestring(nt_time_to_unix(&mod_time)));
490 /* close the handles */
491 if ((*key_name) != 0)
493 res1 = res1 ? reg_close(&key_pol) : False;
495 res = res ? reg_close(&pol_con) : False;
497 if (res && res1)
499 DEBUG(5,("cmd_reg_query: query succeeded\n"));
501 else
503 DEBUG(5,("cmd_reg_query: query failed\n"));
507 /****************************************************************************
508 nt registry create value
509 ****************************************************************************/
510 void cmd_reg_create_val(struct client_info *info, int argc, char *argv[])
512 BOOL res = True;
513 BOOL res3 = True;
514 BOOL res4 = True;
516 POLICY_HND parent_pol;
517 POLICY_HND pol_con;
518 pstring full_keyname;
519 fstring keyname;
520 fstring parent_name;
521 fstring val_name;
522 uint32 val_type;
523 BUFFER3 value;
525 #if 0
526 uint32 unk_0;
527 uint32 unk_1;
528 /* query it */
529 res1 = res1 ? reg_query_info(&val_pol,
530 type, &unk_0, &unk_1) : False;
531 #endif
533 fstring srv_name;
535 fstrcpy(srv_name, "\\\\");
536 fstrcat(srv_name, info->dest_host);
537 strupper(srv_name);
539 if (argc < 4)
541 report(out_hnd, "regcreate <val_name> <val_type (1|3|4)> <val>\n");
542 report(out_hnd, "(val_type 1=UNISTR, 3=BYTES, 4=DWORD supported\n");
543 return;
546 split_server_keyname(srv_name, full_keyname, argv[1]);
548 reg_get_subkey(full_keyname, keyname, val_name);
550 argc--;
551 argv++;
553 if (keyname[0] == 0 || val_name[0] == 0)
555 report(out_hnd, "invalid key name\n");
556 return;
559 if (argc < 2)
561 return;
564 argc--;
565 argv++;
567 val_type = atoi(argv[0]);
569 if (val_type != 1 && val_type != 3 && val_type != 4)
571 report(out_hnd, "val_type 1=UNISTR, 3=BYTES, 4=DWORD supported\n");
572 return;
575 argc--;
576 argv++;
578 switch (val_type)
580 case 0x01: /* UNISTR */
582 make_buffer3_str(&value, argv[0], strlen(argv[0])+1);
583 break;
585 case 0x03: /* BYTES */
587 make_buffer3_hex(&value, argv[0]);
588 break;
590 case 0x04: /* DWORD */
592 make_buffer3_uint32(&value, get_number(argv[0]));
593 break;
595 default:
597 report(out_hnd, "i told you i only deal with UNISTR, DWORD and BYTES!\n");
598 return;
602 DEBUG(10,("key data:\n"));
603 dump_data(10, (char *)value.buffer, value.buf_len);
605 /* open registry receive a policy handle */
606 res = res ? reg_connect(srv_name, keyname, parent_name, 0x02000000,
607 &pol_con) : False;
609 if ((*val_name) != 0)
611 /* open an entry */
612 res3 = res ? reg_open_entry(&pol_con,
613 parent_name, 0x02000000, &parent_pol) : False;
615 else
617 memcpy(&parent_pol, &pol_con, sizeof(parent_pol));
620 /* create an entry */
621 res4 = res3 ? reg_create_val(&parent_pol,
622 val_name, val_type, &value) : False;
624 /* flush the modified key */
625 res4 = res4 ? reg_flush_key(&parent_pol) : False;
627 /* close the val handle */
628 if ((*val_name) != 0)
630 res3 = res3 ? reg_close(&parent_pol) : False;
633 /* close the registry handles */
634 res = res ? reg_close(&pol_con) : False;
636 if (res && res3 && res4)
638 DEBUG(5,("cmd_reg_create_val: query succeeded\n"));
639 report(out_hnd,"OK\n");
641 else
643 DEBUG(5,("cmd_reg_create_val: query failed\n"));
647 /****************************************************************************
648 nt registry delete value
649 ****************************************************************************/
650 void cmd_reg_delete_val(struct client_info *info, int argc, char *argv[])
652 BOOL res = True;
653 BOOL res3 = True;
654 BOOL res4 = True;
656 POLICY_HND parent_pol;
657 POLICY_HND pol_con;
658 pstring full_keyname;
659 fstring keyname;
660 fstring parent_name;
661 fstring val_name;
663 fstring srv_name;
665 fstrcpy(srv_name, "\\\\");
666 fstrcat(srv_name, info->dest_host);
667 strupper(srv_name);
669 if (argc < 2)
671 report(out_hnd, "regdelete <val_name>\n");
672 return;
675 split_server_keyname(srv_name, full_keyname, argv[1]);
677 reg_get_subkey(full_keyname, keyname, val_name);
679 if (keyname[0] == 0 || val_name[0] == 0)
681 report(out_hnd, "invalid key name\n");
682 return;
685 /* open registry receive a policy handle */
686 res = res ? reg_connect(srv_name, keyname, parent_name, 0x02000000,
687 &pol_con) : False;
689 if ((*val_name) != 0)
691 /* open an entry */
692 res3 = res ? reg_open_entry(&pol_con,
693 parent_name, 0x02000000, &parent_pol) : False;
695 else
697 memcpy(&parent_pol, &pol_con, sizeof(parent_pol));
700 /* delete an entry */
701 res4 = res3 ? reg_delete_val(&parent_pol, val_name) : False;
703 /* flush the modified key */
704 res4 = res4 ? reg_flush_key(&parent_pol) : False;
706 /* close the key handle */
707 res3 = res3 ? reg_close(&parent_pol) : False;
709 /* close the registry handles */
710 res = res ? reg_close(&pol_con) : False;
712 if (res && res3 && res4)
714 DEBUG(5,("cmd_reg_delete_val: query succeeded\n"));
715 report(out_hnd,"OK\n");
717 else
719 DEBUG(5,("cmd_reg_delete_val: query failed\n"));
723 /****************************************************************************
724 nt registry delete key
725 ****************************************************************************/
726 void cmd_reg_delete_key(struct client_info *info, int argc, char *argv[])
728 BOOL res = True;
729 BOOL res3 = True;
730 BOOL res4 = True;
732 POLICY_HND parent_pol;
733 POLICY_HND pol_con;
734 pstring full_keyname;
735 fstring parent_name;
736 fstring key_name;
737 fstring subkey_name;
739 fstring srv_name;
741 fstrcpy(srv_name, "\\\\");
742 fstrcat(srv_name, info->dest_host);
743 strupper(srv_name);
745 if (argc < 2)
747 report(out_hnd, "regdeletekey <key_name>\n");
748 return;
751 split_server_keyname(srv_name, full_keyname, argv[1]);
753 reg_get_subkey(full_keyname, parent_name, subkey_name);
755 if (parent_name[0] == 0 || subkey_name[0] == 0)
757 report(out_hnd, "invalid key name\n");
758 return;
761 /* open registry receive a policy handle */
762 res = res ? reg_connect(srv_name, parent_name, key_name, 0x02000000,
763 &pol_con) : False;
765 if ((*key_name) != 0)
767 /* open an entry */
768 res3 = res ? reg_open_entry(&pol_con,
769 key_name, 0x02000000, &parent_pol) : False;
771 else
773 memcpy(&parent_pol, &pol_con, sizeof(parent_pol));
776 /* create an entry */
777 res4 = res3 ? reg_delete_key(&parent_pol, subkey_name) : False;
779 /* flush the modified key */
780 res4 = res4 ? reg_flush_key(&parent_pol) : False;
782 /* close the key handle */
783 if ((*key_name) != 0)
785 res3 = res3 ? reg_close(&parent_pol) : False;
788 /* close the registry handles */
789 res = res ? reg_close(&pol_con) : False;
791 if (res && res3 && res4)
793 DEBUG(5,("cmd_reg_delete_key: query succeeded\n"));
794 report(out_hnd,"OK\n");
796 else
798 DEBUG(5,("cmd_reg_delete_key: query failed\n"));
802 /****************************************************************************
803 nt registry create key
804 ****************************************************************************/
805 void cmd_reg_create_key(struct client_info *info, int argc, char *argv[])
807 BOOL res = True;
808 BOOL res3 = True;
809 BOOL res4 = True;
811 POLICY_HND parent_pol;
812 POLICY_HND key_pol;
813 POLICY_HND pol_con;
814 pstring full_keyname;
815 fstring parent_key;
816 fstring parent_name;
817 fstring key_name;
818 fstring key_class;
819 SEC_ACCESS sam_access;
821 fstring srv_name;
823 fstrcpy(srv_name, "\\\\");
824 fstrcat(srv_name, info->dest_host);
825 strupper(srv_name);
827 if (argc < 2)
829 report(out_hnd, "regcreate <key_name> [key_class]\n");
830 return;
833 split_server_keyname(srv_name, full_keyname, argv[1]);
835 reg_get_subkey(full_keyname, parent_key, key_name);
837 if (parent_key[0] == 0 || key_name[0] == 0)
839 report(out_hnd, "invalid key name\n");
840 return;
843 if (argc > 2)
845 fstrcpy(key_class, argv[2]);
847 else
849 memset(key_class, 0, sizeof(key_class));
852 /* set access permissions */
853 sam_access.mask = SEC_RIGHTS_READ;
855 /* open registry receive a policy handle */
856 res = res ? reg_connect(srv_name, parent_key, parent_name, 0x02000000,
857 &pol_con) : False;
859 if ((*parent_name) != 0)
861 /* open an entry */
862 res3 = res ? reg_open_entry(&pol_con,
863 parent_name, 0x02000000, &parent_pol) : False;
865 else
867 memcpy(&parent_pol, &pol_con, sizeof(parent_pol));
870 /* create an entry */
871 res4 = res3 ? reg_create_key(&parent_pol,
872 key_name, key_class, &sam_access, &key_pol) : False;
874 /* flush the modified key */
875 res4 = res4 ? reg_flush_key(&parent_pol) : False;
877 /* close the key handle */
878 res4 = res4 ? reg_close(&key_pol) : False;
880 /* close the key handle */
881 if ((*parent_name) != 0)
883 res3 = res3 ? reg_close(&parent_pol) : False;
886 /* close the registry handles */
887 res = res ? reg_close(&pol_con) : False;
889 if (res && res3 && res4)
891 DEBUG(5,("cmd_reg_create_key: query succeeded\n"));
892 report(out_hnd,"OK\n");
894 else
896 DEBUG(5,("cmd_reg_create_key: query failed\n"));
900 /****************************************************************************
901 nt registry security info
902 ****************************************************************************/
903 void cmd_reg_test_key_sec(struct client_info *info, int argc, char *argv[])
905 BOOL res = True;
906 BOOL res3 = True;
907 BOOL res4 = True;
909 POLICY_HND key_pol;
910 POLICY_HND pol_con;
911 pstring full_keyname;
912 fstring key_name;
915 * security info
918 uint32 sec_buf_size;
919 SEC_DESC_BUF sec_buf;
920 uint32 sec_info = 0x7;
922 fstring srv_name;
924 fstrcpy(srv_name, "\\\\");
925 fstrcat(srv_name, info->dest_host);
926 strupper(srv_name);
928 if (argc < 2)
930 report(out_hnd, "regtestkeysec <key_name>\n");
931 return;
934 split_server_keyname(srv_name, full_keyname, argv[1]);
936 /* open registry receive a policy handle */
937 res = res ? reg_connect(srv_name, full_keyname, key_name, 0x02000000,
938 &pol_con) : False;
940 if ((*key_name) != 0)
942 /* open an entry */
943 res3 = res ? reg_open_entry(&pol_con,
944 key_name, 0x02000000, &key_pol) : False;
946 else
948 memcpy(&key_pol, &pol_con, sizeof(key_pol));
951 /* open an entry */
952 res3 = res ? reg_open_entry(&pol_con,
953 key_name, 0x02000000, &key_pol) : False;
955 /* query key sec info. first call sets sec_buf_size. */
956 sec_buf_size = 0;
957 ZERO_STRUCT(sec_buf);
959 res4 = res3 ? reg_get_key_sec(&key_pol,
960 sec_info,
961 &sec_buf_size, &sec_buf) : False;
963 if (res4)
965 free_sec_desc_buf(&sec_buf);
968 res4 = res4 ? reg_get_key_sec(&key_pol,
969 sec_info,
970 &sec_buf_size, &sec_buf) : False;
972 if (res4 && sec_buf.len > 0 && sec_buf.sec != NULL)
974 display_sec_desc(out_hnd, ACTION_HEADER , sec_buf.sec);
975 display_sec_desc(out_hnd, ACTION_ENUMERATE, sec_buf.sec);
976 display_sec_desc(out_hnd, ACTION_FOOTER , sec_buf.sec);
978 res4 = res4 ? reg_set_key_sec(&key_pol,
979 sec_info, sec_buf_size, sec_buf.sec) : False;
981 free_sec_desc_buf(&sec_buf);
984 /* close the key handle */
985 if ((*key_name) != 0)
987 res3 = res3 ? reg_close(&key_pol) : False;
990 /* close the registry handles */
991 res = res ? reg_close(&pol_con) : False;
993 if (res && res3 && res4)
995 DEBUG(5,("cmd_reg_test2: query succeeded\n"));
996 report(out_hnd,"Registry Test2\n");
998 else
1000 DEBUG(5,("cmd_reg_test2: query failed\n"));
1004 /****************************************************************************
1005 nt registry security info
1006 ****************************************************************************/
1007 void cmd_reg_get_key_sec(struct client_info *info, int argc, char *argv[])
1009 BOOL res = True;
1010 BOOL res3 = True;
1011 BOOL res4 = True;
1013 POLICY_HND key_pol;
1014 POLICY_HND pol_con;
1015 pstring full_keyname;
1016 fstring key_name;
1019 * security info
1022 uint32 sec_buf_size;
1023 SEC_DESC_BUF sec_buf;
1024 uint32 sec_info = 0x7;
1026 fstring srv_name;
1028 fstrcpy(srv_name, "\\\\");
1029 fstrcat(srv_name, info->dest_host);
1030 strupper(srv_name);
1032 if (argc < 2)
1034 report(out_hnd, "reggetsec <key_name>\n");
1035 return;
1038 split_server_keyname(srv_name, full_keyname, argv[1]);
1040 /* open registry receive a policy handle */
1041 res = res ? reg_connect(srv_name, full_keyname, key_name, 0x02000000,
1042 &pol_con) : False;
1044 if ((*key_name) != 0)
1046 /* open an entry */
1047 res3 = res ? reg_open_entry(&pol_con,
1048 key_name, 0x02000000, &key_pol) : False;
1050 else
1052 memcpy(&key_pol, &pol_con, sizeof(key_pol));
1055 /* open an entry */
1056 res3 = res ? reg_open_entry(&pol_con,
1057 key_name, 0x02000000, &key_pol) : False;
1059 /* query key sec info. first call sets sec_buf_size. */
1060 sec_buf_size = 0;
1061 ZERO_STRUCT(sec_buf);
1063 res4 = res3 ? reg_get_key_sec(&key_pol,
1064 sec_info,
1065 &sec_buf_size, &sec_buf) : False;
1067 if (res4)
1069 free_sec_desc_buf(&sec_buf);
1072 res4 = res4 ? reg_get_key_sec(&key_pol,
1073 sec_info,
1074 &sec_buf_size, &sec_buf) : False;
1076 if (res4 && sec_buf.len > 0 && sec_buf.sec != NULL)
1078 display_sec_desc(out_hnd, ACTION_HEADER , sec_buf.sec);
1079 display_sec_desc(out_hnd, ACTION_ENUMERATE, sec_buf.sec);
1080 display_sec_desc(out_hnd, ACTION_FOOTER , sec_buf.sec);
1082 free(sec_buf.sec);
1085 /* close the key handle */
1086 if ((*key_name) != 0)
1088 res3 = res3 ? reg_close(&key_pol) : False;
1091 /* close the registry handles */
1092 res = res ? reg_close(&pol_con) : False;
1094 if (res && res3 && res4)
1096 DEBUG(5,("cmd_reg_get_key_sec: query succeeded\n"));
1098 else
1100 DEBUG(5,("cmd_reg_get_key_sec: query failed\n"));
1104 /****************************************************************************
1105 nt registry shutdown
1106 ****************************************************************************/
1107 void cmd_reg_shutdown(struct client_info *info, int argc, char *argv[])
1109 BOOL res = True;
1111 fstring msg;
1112 uint32 timeout = 20;
1113 uint16 flgs = 0;
1114 int opt;
1116 fstring srv_name;
1118 fstrcpy(srv_name, "\\\\");
1119 fstrcat(srv_name, info->dest_host);
1120 strupper(srv_name);
1122 while ((opt = getopt(argc, argv,"fim:t:r-")) != EOF)
1124 switch (opt)
1126 case 'm':
1128 safe_strcpy(msg, optarg, sizeof(msg)-1);
1129 break;
1131 case 't':
1133 timeout = atoi(optarg);
1134 break;
1136 case 'r':
1138 flgs |= 0x100;
1139 break;
1141 case 'f':
1143 flgs |= 0x001;
1144 break;
1146 case '-':
1148 if (strequal(optarg, "-reboot"))
1150 flgs |= 0x100;
1152 if (strequal(optarg, "-force-close"))
1154 flgs |= 0x001;
1156 break;
1161 /* create an entry */
1162 res = res ? reg_shutdown(srv_name, msg, timeout, flgs) : False;
1164 if (res)
1166 DEBUG(5,("cmd_reg_shutdown: query succeeded\n"));
1167 report(out_hnd,"OK\n");
1169 else
1171 DEBUG(5,("cmd_reg_shutdown: query failed\n"));
1172 report(out_hnd,"Failed\n");