3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1998,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
8 * Copyright (C) Paul Ashton 1997-1998.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 extern int DEBUGLEVEL;
34 /****************************************************************************
36 ****************************************************************************/
37 BOOL reg_connect( const char* srv_name,
38 const char *full_keyname,
45 struct cli_state *cli = NULL;
48 if (!cli_state_init(srv_name, PIPE_WINREG, &cli, &fnum))
53 ZERO_STRUCTP(reg_hnd);
55 if (full_keyname == NULL)
61 * open registry receive a policy handle
64 if (!reg_split_key(full_keyname, ®_type, key_name))
66 DEBUG(0,("reg_connect: unrecognised key name %s\n",
73 case HKEY_CLASSES_ROOT:
75 res = res ? reg_open_hkcr(cli, fnum,
81 case HKEY_LOCAL_MACHINE:
83 res = res ? reg_open_hklm(cli, fnum,
91 res = res ? reg_open_hku(cli, fnum,
98 DEBUG(0,("reg_connect: unrecognised hive key\n"));
105 if (!register_policy_hnd(reg_hnd) ||
106 !set_policy_cli_state(reg_hnd, cli, fnum,
109 cli_state_free(cli, fnum);
117 /****************************************************************************
119 ****************************************************************************/
120 BOOL reg_open_hkcr( struct cli_state *cli, uint16 fnum,
121 uint16 unknown_0, uint32 level,
127 BOOL valid_pol = False;
129 if (hnd == NULL) return False;
131 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
132 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
134 /* create and send a MSRPC command with api REG_OPEN_HKCR */
136 DEBUG(4,("REG Open HKCR\n"));
138 make_reg_q_open_hkcr(&q_o, unknown_0, level);
140 /* turn parameters into data stream */
141 reg_io_q_open_hkcr("", &q_o, &buf, 0);
143 /* send the data on \PIPE\ */
144 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_HKCR, &buf, &rbuf))
151 reg_io_r_open_hkcr("", &r_o, &rbuf, 0);
152 p = rbuf.offset != 0;
154 if (p && r_o.status != 0)
156 /* report error code */
157 DEBUG(0,("REG_OPEN_HKCR: %s\n", get_nt_error_msg(r_o.status)));
163 /* ok, at last: we're happy. return the policy handle */
164 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
175 /****************************************************************************
177 ****************************************************************************/
178 BOOL reg_open_hklm( struct cli_state *cli, uint16 fnum,
179 uint16 unknown_0, uint32 level,
185 BOOL valid_pol = False;
187 if (hnd == NULL) return False;
189 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
190 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
192 /* create and send a MSRPC command with api REG_OPEN_HKLM */
194 DEBUG(4,("REG Open HKLM\n"));
196 make_reg_q_open_hklm(&q_o, unknown_0, level);
198 /* turn parameters into data stream */
199 reg_io_q_open_hklm("", &q_o, &buf, 0);
201 /* send the data on \PIPE\ */
202 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_HKLM, &buf, &rbuf))
209 reg_io_r_open_hklm("", &r_o, &rbuf, 0);
210 p = rbuf.offset != 0;
212 if (p && r_o.status != 0)
214 /* report error code */
215 DEBUG(0,("REG_OPEN_HKLM: %s\n", get_nt_error_msg(r_o.status)));
221 /* ok, at last: we're happy. return the policy handle */
222 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
233 /****************************************************************************
235 ****************************************************************************/
236 BOOL reg_open_hku( struct cli_state *cli, uint16 fnum,
237 uint16 unknown_0, uint32 level,
243 BOOL valid_pol = False;
245 if (hnd == NULL) return False;
247 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
248 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
250 /* create and send a MSRPC command with api REG_OPEN_HKU */
252 DEBUG(4,("REG Open HKU\n"));
254 make_reg_q_open_hku(&q_o, unknown_0, level);
256 /* turn parameters into data stream */
257 reg_io_q_open_hku("", &q_o, &buf, 0);
259 /* send the data on \PIPE\ */
260 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_HKU, &buf, &rbuf))
267 reg_io_r_open_hku("", &r_o, &rbuf, 0);
268 p = rbuf.offset != 0;
270 if (p && r_o.status != 0)
272 /* report error code */
273 DEBUG(0,("REG_OPEN_HKU: %s\n", get_nt_error_msg(r_o.status)));
279 /* ok, at last: we're happy. return the policy handle */
280 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
291 /****************************************************************************
292 do a REG Unknown 0xB command. sent after a create key or create value.
293 this might be some sort of "sync" or "refresh" command, sent after
294 modification of the registry...
295 ****************************************************************************/
296 BOOL reg_flush_key( POLICY_HND *hnd)
301 BOOL valid_query = False;
303 struct cli_state *cli = NULL;
304 uint16 fnum = 0xffff;
306 if (!cli_state_get(hnd, &cli, &fnum))
311 if (hnd == NULL) return False;
313 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
314 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
316 /* create and send a MSRPC command with api REG_FLUSH_KEY */
318 DEBUG(4,("REG Unknown 0xB\n"));
320 make_reg_q_flush_key(&q_o, hnd);
322 /* turn parameters into data stream */
323 reg_io_q_flush_key("", &q_o, &buf, 0);
325 /* send the data on \PIPE\ */
326 if (rpc_api_pipe_req(cli, fnum, REG_FLUSH_KEY, &buf, &rbuf))
333 reg_io_r_flush_key("", &r_o, &rbuf, 0);
334 p = rbuf.offset != 0;
336 if (p && r_o.status != 0)
338 /* report error code */
339 DEBUG(0,("REG_FLUSH_KEY: %s\n", get_nt_error_msg(r_o.status)));
355 /****************************************************************************
357 ****************************************************************************/
358 BOOL reg_query_key( POLICY_HND *hnd,
359 char *key_class, uint32 *class_len,
360 uint32 *num_subkeys, uint32 *max_subkeylen,
361 uint32 *max_subkeysize, uint32 *num_values,
362 uint32 *max_valnamelen, uint32 *max_valbufsize,
363 uint32 *sec_desc, NTTIME *mod_time)
368 BOOL valid_query = False;
370 struct cli_state *cli = NULL;
371 uint16 fnum = 0xffff;
373 if (!cli_state_get(hnd, &cli, &fnum))
378 if (hnd == NULL) return False;
380 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
381 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
383 /* create and send a MSRPC command with api REG_QUERY_KEY */
385 DEBUG(4,("REG Query Key\n"));
387 make_reg_q_query_key(&q_o, hnd, *class_len);
389 /* turn parameters into data stream */
390 reg_io_q_query_key("", &q_o, &buf, 0);
392 /* send the data on \PIPE\ */
393 if (rpc_api_pipe_req(cli, fnum, REG_QUERY_KEY, &buf, &rbuf))
400 reg_io_r_query_key("", &r_o, &rbuf, 0);
401 p = rbuf.offset != 0;
403 if (p && r_o.status != 0)
405 /* report error code */
406 DEBUG(0,("REG_QUERY_KEY: %s\n", get_nt_error_msg(r_o.status)));
414 *class_len = r_o.hdr_class.uni_max_len;
415 unistr2_to_ascii(key_class, &r_o.uni_class, sizeof(fstring)-1);
416 *num_subkeys = r_o.num_subkeys ;
417 *max_subkeylen = r_o.max_subkeylen ;
418 *max_subkeysize = r_o.max_subkeysize;
419 *num_values = r_o.num_values ;
420 *max_valnamelen = r_o.max_valnamelen;
421 *max_valbufsize = r_o.max_valbufsize;
422 *sec_desc = r_o.sec_desc ;
423 *mod_time = r_o.mod_time ;
433 /****************************************************************************
435 ****************************************************************************/
436 BOOL reg_unknown_1a( POLICY_HND *hnd, uint32 *unk)
441 BOOL valid_query = False;
443 struct cli_state *cli = NULL;
444 uint16 fnum = 0xffff;
446 if (!cli_state_get(hnd, &cli, &fnum))
451 if (hnd == NULL) return False;
453 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
454 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
456 /* create and send a MSRPC command with api REG_UNKNOWN_1A */
458 DEBUG(4,("REG Unknown 1a\n"));
460 make_reg_q_unk_1a(&q_o, hnd);
462 /* turn parameters into data stream */
463 reg_io_q_unk_1a("", &q_o, &buf, 0);
465 /* send the data on \PIPE\ */
466 if (rpc_api_pipe_req(cli, fnum, REG_UNK_1A, &buf, &rbuf))
473 reg_io_r_unk_1a("", &r_o, &rbuf, 0);
474 p = rbuf.offset != 0;
476 if (p && r_o.status != 0)
478 /* report error code */
479 DEBUG(0,("REG_UNK_1A: %s\n", get_nt_error_msg(r_o.status)));
486 (*unk) = r_o.unknown;
496 /****************************************************************************
498 ****************************************************************************/
499 BOOL reg_query_info( POLICY_HND *hnd,
500 const char* val_name,
501 uint32 *type, BUFFER2 *buffer)
506 BOOL valid_query = False;
508 struct cli_state *cli = NULL;
509 uint16 fnum = 0xffff;
511 if (!cli_state_get(hnd, &cli, &fnum))
516 if (hnd == NULL) return False;
518 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
519 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
521 /* create and send a MSRPC command with api REG_INFO */
523 DEBUG(4,("REG Query Info\n"));
525 make_reg_q_info(&q_o, hnd, val_name, 4, 0);
527 /* turn parameters into data stream */
528 reg_io_q_info("", &q_o, &buf, 0);
530 /* send the data on \PIPE\ */
531 if (rpc_api_pipe_req(cli, fnum, REG_INFO, &buf, &rbuf))
539 r_o.uni_type = buffer;
541 reg_io_r_info("", &r_o, &rbuf, 0);
542 p = rbuf.offset != 0;
544 if (p && r_o.status != 0)
546 /* report error code */
547 DEBUG(0,("REG_INFO: %s\n", get_nt_error_msg(r_o.status)));
563 /****************************************************************************
564 do a REG Set Key Security
565 ****************************************************************************/
566 BOOL reg_set_key_sec( POLICY_HND *hnd,
568 uint32 sec_buf_size, SEC_DESC *sec_buf)
572 REG_Q_SET_KEY_SEC q_o;
573 BOOL valid_query = False;
575 struct cli_state *cli = NULL;
576 uint16 fnum = 0xffff;
578 if (!cli_state_get(hnd, &cli, &fnum))
583 if (hnd == NULL) return False;
585 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
586 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
588 /* create and send a MSRPC command with api REG_SET_KEY_SEC */
590 DEBUG(4,("REG Set Key security.\n"));
592 make_reg_q_set_key_sec(&q_o, hnd, sec_info, sec_buf_size, sec_buf);
594 /* turn parameters into data stream */
595 reg_io_q_set_key_sec("", &q_o, &buf, 0);
597 /* send the data on \PIPE\ */
598 if (rpc_api_pipe_req(cli, fnum, REG_SET_KEY_SEC, &buf, &rbuf))
600 REG_R_SET_KEY_SEC r_o;
605 reg_io_r_set_key_sec("", &r_o, &rbuf, 0);
606 p = rbuf.offset != 0;
608 if (p && r_o.status != 0)
621 /****************************************************************************
622 do a REG Query Key Security
623 ****************************************************************************/
624 BOOL reg_get_key_sec( POLICY_HND *hnd,
626 uint32 *sec_buf_size, SEC_DESC_BUF *sec_buf)
630 REG_Q_GET_KEY_SEC q_o;
631 BOOL valid_query = False;
633 struct cli_state *cli = NULL;
634 uint16 fnum = 0xffff;
636 if (!cli_state_get(hnd, &cli, &fnum))
641 if (hnd == NULL) return False;
643 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
644 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
646 /* create and send a MSRPC command with api REG_GET_KEY_SEC */
648 DEBUG(4,("REG query key security. buf_size: %d\n", *sec_buf_size));
650 make_reg_q_get_key_sec(&q_o, hnd, sec_info, *sec_buf_size, sec_buf);
652 /* turn parameters into data stream */
653 reg_io_q_get_key_sec("", &q_o, &buf, 0);
655 /* send the data on \PIPE\ */
656 if (rpc_api_pipe_req(cli, fnum, REG_GET_KEY_SEC, &buf, &rbuf))
658 REG_R_GET_KEY_SEC r_o;
664 if (*sec_buf_size != 0)
666 sec_buf->sec = (SEC_DESC*)malloc(*sec_buf_size);
668 reg_io_r_get_key_sec("", &r_o, &rbuf, 0);
669 p = rbuf.offset != 0;
671 if (p && r_o.status == 0x0000007a)
674 * get the maximum buffer size: it was too small
676 (*sec_buf_size) = r_o.hdr_sec.buf_max_len;
677 DEBUG(5,("sec_buf_size too small. use %d\n", *sec_buf_size));
680 else if (p && r_o.status != 0)
682 /* report error code */
683 DEBUG(0,("REG_GET_KEY_SEC: %s\n", get_nt_error_msg(r_o.status)));
689 (*sec_buf_size) = r_o.data->len;
699 /****************************************************************************
700 do a REG Delete Value
701 ****************************************************************************/
702 BOOL reg_delete_val( POLICY_HND *hnd, char *val_name)
706 REG_Q_DELETE_VALUE q_o;
707 BOOL valid_delete = False;
709 struct cli_state *cli = NULL;
710 uint16 fnum = 0xffff;
712 if (!cli_state_get(hnd, &cli, &fnum))
717 if (hnd == NULL) return False;
719 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
720 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
722 /* create and send a MSRPC command with api REG_DELETE_VALUE */
724 DEBUG(4,("REG Delete Value: %s\n", val_name));
726 make_reg_q_delete_val(&q_o, hnd, val_name);
728 /* turn parameters into data stream */
729 reg_io_q_delete_val("", &q_o, &buf, 0);
731 /* send the data on \PIPE\ */
732 if (rpc_api_pipe_req(cli, fnum, REG_DELETE_VALUE, &buf, &rbuf))
734 REG_R_DELETE_VALUE r_o;
739 reg_io_r_delete_val("", &r_o, &rbuf, 0);
740 p = rbuf.offset != 0;
742 if (p && r_o.status != 0)
744 /* report error code */
745 DEBUG(0,("REG_DELETE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
761 /****************************************************************************
763 ****************************************************************************/
764 BOOL reg_delete_key( POLICY_HND *hnd, char *key_name)
768 REG_Q_DELETE_KEY q_o;
769 BOOL valid_delete = False;
771 struct cli_state *cli = NULL;
772 uint16 fnum = 0xffff;
774 if (!cli_state_get(hnd, &cli, &fnum))
779 if (hnd == NULL) return False;
781 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
782 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
784 /* create and send a MSRPC command with api REG_DELETE_KEY */
786 DEBUG(4,("REG Delete Key: %s\n", key_name));
788 make_reg_q_delete_key(&q_o, hnd, key_name);
790 /* turn parameters into data stream */
791 reg_io_q_delete_key("", &q_o, &buf, 0);
793 /* send the data on \PIPE\ */
794 if (rpc_api_pipe_req(cli, fnum, REG_DELETE_KEY, &buf, &rbuf))
796 REG_R_DELETE_KEY r_o;
801 reg_io_r_delete_key("", &r_o, &rbuf, 0);
802 p = rbuf.offset != 0;
804 if (p && r_o.status != 0)
806 /* report error code */
807 DEBUG(0,("REG_DELETE_KEY: %s\n", get_nt_error_msg(r_o.status)));
823 /****************************************************************************
825 ****************************************************************************/
826 BOOL reg_create_key( POLICY_HND *hnd,
827 char *key_name, char *key_class,
828 SEC_ACCESS *sam_access,
833 REG_Q_CREATE_KEY q_o;
834 BOOL valid_create = False;
836 SEC_DESC_BUF sec_buf;
839 struct cli_state *cli = NULL;
840 uint16 fnum = 0xffff;
842 if (!cli_state_get(hnd, &cli, &fnum))
848 ZERO_STRUCT(sec_buf);
851 if (hnd == NULL) return False;
853 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
854 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
856 /* create and send a MSRPC command with api REG_CREATE_KEY */
858 DEBUG(4,("REG Create Key: %s %s 0x%08x\n", key_name, key_class,
859 sam_access != NULL ? sam_access->mask : 0));
861 sec_len = make_sec_desc(&sec, 1, SEC_DESC_SELF_RELATIVE,
862 NULL, NULL, NULL, NULL);
864 DEBUG(10,("make_sec_desc: len = %d\n", sec_len));
866 make_reg_q_create_key(&q_o, hnd, key_name, key_class, sam_access,
867 &sec_buf, sec_len, &sec);
869 /* turn parameters into data stream */
870 reg_io_q_create_key("", &q_o, &buf, 0);
872 /* send the data on \PIPE\ */
873 if (rpc_api_pipe_req(cli, fnum, REG_CREATE_KEY, &buf, &rbuf))
875 REG_R_CREATE_KEY r_o;
880 reg_io_r_create_key("", &r_o, &rbuf, 0);
881 p = rbuf.offset != 0;
883 if (p && r_o.status != 0)
885 /* report error code */
886 DEBUG(0,("REG_CREATE_KEY: %s\n", get_nt_error_msg(r_o.status)));
893 memcpy(key, r_o.key_pol.data, sizeof(key->data));
905 /****************************************************************************
907 ****************************************************************************/
908 BOOL reg_enum_key( POLICY_HND *hnd,
909 int key_index, char *key_name,
910 uint32 *unk_1, uint32 *unk_2,
916 BOOL valid_query = False;
918 struct cli_state *cli = NULL;
919 uint16 fnum = 0xffff;
921 if (!cli_state_get(hnd, &cli, &fnum))
926 if (hnd == NULL) return False;
928 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
929 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
931 /* create and send a MSRPC command with api REG_ENUM_KEY */
933 DEBUG(4,("REG Enum Key\n"));
935 make_reg_q_enum_key(&q_o, hnd, key_index);
937 /* turn parameters into data stream */
938 reg_io_q_enum_key("", &q_o, &buf, 0);
940 /* send the data on \PIPE\ */
941 if (rpc_api_pipe_req(cli, fnum, REG_ENUM_KEY, &buf, &rbuf))
948 reg_io_r_enum_key("", &r_o, &rbuf, 0);
949 p = rbuf.offset != 0;
951 if (p && r_o.status != 0)
953 /* report error code */
954 DEBUG(0,("REG_ENUM_KEY: %s\n", get_nt_error_msg(r_o.status)));
961 (*unk_1) = r_o.unknown_1;
962 (*unk_2) = r_o.unknown_2;
963 unistr_to_ascii(key_name, r_o.key_name.str.buffer,
965 (*mod_time) = nt_time_to_unix(&r_o.time);
975 /****************************************************************************
976 do a REG Create Value
977 ****************************************************************************/
978 BOOL reg_create_val( POLICY_HND *hnd,
979 char *val_name, uint32 type, BUFFER3 *data)
983 REG_Q_CREATE_VALUE q_o;
984 BOOL valid_create = False;
986 struct cli_state *cli = NULL;
987 uint16 fnum = 0xffff;
989 if (!cli_state_get(hnd, &cli, &fnum))
994 if (hnd == NULL) return False;
996 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
997 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
999 /* create and send a MSRPC command with api REG_CREATE_VALUE */
1001 DEBUG(4,("REG Create Value: %s\n", val_name));
1003 make_reg_q_create_val(&q_o, hnd, val_name, type, data);
1005 /* turn parameters into data stream */
1006 reg_io_q_create_val("", &q_o, &buf, 0);
1008 /* send the data on \PIPE\ */
1009 if (rpc_api_pipe_req(cli, fnum, REG_CREATE_VALUE, &buf, &rbuf))
1011 REG_R_CREATE_VALUE r_o;
1016 reg_io_r_create_val("", &r_o, &rbuf, 0);
1017 p = rbuf.offset != 0;
1019 if (p && r_o.status != 0)
1021 /* report error code */
1022 DEBUG(0,("REG_CREATE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
1028 valid_create = True;
1032 prs_mem_free(&rbuf);
1033 prs_mem_free(&buf );
1035 return valid_create;
1038 /****************************************************************************
1040 ****************************************************************************/
1041 BOOL reg_enum_val( POLICY_HND *hnd,
1042 int val_index, int max_valnamelen, int max_valbufsize,
1044 uint32 *val_type, BUFFER2 *value)
1048 REG_Q_ENUM_VALUE q_o;
1049 BOOL valid_query = False;
1051 struct cli_state *cli = NULL;
1052 uint16 fnum = 0xffff;
1054 if (!cli_state_get(hnd, &cli, &fnum))
1059 if (hnd == NULL) return False;
1061 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1062 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1064 /* create and send a MSRPC command with api REG_ENUM_VALUE */
1066 DEBUG(4,("REG Enum Value\n"));
1068 make_reg_q_enum_val(&q_o, hnd, val_index, max_valnamelen, max_valbufsize);
1070 /* turn parameters into data stream */
1071 reg_io_q_enum_val("", &q_o, &buf, 0);
1073 /* send the data on \PIPE\ */
1074 if (rpc_api_pipe_req(cli, fnum, REG_ENUM_VALUE, &buf, &rbuf))
1076 REG_R_ENUM_VALUE r_o;
1080 r_o.buf_value = value;
1082 reg_io_r_enum_val("", &r_o, &rbuf, 0);
1083 p = rbuf.offset != 0;
1085 if (p && r_o.status != 0)
1087 /* report error code */
1088 DEBUG(0,("REG_ENUM_VALUE: %s\n", get_nt_error_msg(r_o.status)));
1095 (*val_type) = r_o.type;
1096 unistr2_to_ascii(val_name, &r_o.uni_name, sizeof(fstring)-1);
1100 prs_mem_free(&rbuf);
1101 prs_mem_free(&buf );
1106 /****************************************************************************
1108 ****************************************************************************/
1109 BOOL reg_open_entry( POLICY_HND *hnd,
1110 char *key_name, uint32 unk_0,
1111 POLICY_HND *key_hnd)
1115 REG_Q_OPEN_ENTRY q_o;
1116 BOOL valid_pol = False;
1118 struct cli_state *cli = NULL;
1119 uint16 fnum = 0xffff;
1121 if (!cli_state_get(hnd, &cli, &fnum))
1126 if (hnd == NULL) return False;
1128 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1129 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1131 /* create and send a MSRPC command with api REG_OPEN_ENTRY */
1133 DEBUG(4,("REG Open Entry\n"));
1135 make_reg_q_open_entry(&q_o, hnd, key_name, unk_0);
1137 /* turn parameters into data stream */
1138 reg_io_q_open_entry("", &q_o, &buf, 0);
1140 /* send the data on \PIPE\ */
1141 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_ENTRY, &buf, &rbuf))
1143 REG_R_OPEN_ENTRY r_o;
1148 reg_io_r_open_entry("", &r_o, &rbuf, 0);
1149 p = rbuf.offset != 0;
1151 if (p && r_o.status != 0)
1153 /* report error code */
1154 DEBUG(0,("REG_OPEN_ENTRY: %s\n", get_nt_error_msg(r_o.status)));
1160 memcpy(key_hnd, r_o.pol.data, sizeof(key_hnd->data));
1161 valid_pol = register_policy_hnd(key_hnd) &&
1162 set_policy_cli_state(key_hnd, cli, fnum, NULL);
1166 prs_mem_free(&rbuf);
1167 prs_mem_free(&buf );
1172 /****************************************************************************
1174 ****************************************************************************/
1175 BOOL reg_close( POLICY_HND *hnd)
1180 BOOL valid_close = False;
1182 struct cli_state *cli = NULL;
1183 uint16 fnum = 0xffff;
1185 if (!cli_state_get(hnd, &cli, &fnum))
1190 if (hnd == NULL) return False;
1192 /* create and send a MSRPC command with api REG_CLOSE */
1194 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1195 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1197 DEBUG(4,("REG Close\n"));
1199 /* store the parameters */
1200 make_reg_q_close(&q_c, hnd);
1202 /* turn parameters into data stream */
1203 reg_io_q_close("", &q_c, &buf, 0);
1205 /* send the data on \PIPE\ */
1206 if (rpc_api_pipe_req(cli, fnum, REG_CLOSE, &buf, &rbuf))
1213 reg_io_r_close("", &r_c, &rbuf, 0);
1214 p = rbuf.offset != 0;
1216 if (p && r_c.status != 0)
1218 /* report error code */
1219 DEBUG(0,("REG_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
1225 /* check that the returned policy handle is all zeros */
1229 for (i = 0; i < sizeof(r_c.pol.data); i++)
1231 if (r_c.pol.data[i] != 0)
1233 valid_close = False;
1239 DEBUG(0,("REG_CLOSE: non-zero handle returned\n"));
1244 prs_mem_free(&rbuf);
1245 prs_mem_free(&buf );
1247 close_policy_hnd(hnd);
1252 /****************************************************************************
1253 do a REG Shutdown Server
1254 ****************************************************************************/
1255 BOOL reg_shutdown(const char *srv_name,
1256 const char *msg, uint32 timeout, uint16 flags)
1261 BOOL valid_shutdown = False;
1263 struct cli_state *cli = NULL;
1264 uint16 fnum = 0xffff;
1266 if (!cli_state_init(srv_name, PIPE_WINREG, &cli, &fnum))
1271 if (msg == NULL) return False;
1273 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1274 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1276 /* create and send a MSRPC command with api REG_SHUTDOWN */
1278 DEBUG(4,("REG Shutdown: (timeout: %d secs) %s\n", timeout, msg));
1280 make_reg_q_shutdown(&q_o, msg, timeout, flags);
1282 /* turn parameters into data stream */
1283 reg_io_q_shutdown("", &q_o, &buf, 0);
1285 /* send the data on \PIPE\ */
1286 if (rpc_api_pipe_req(cli, fnum, REG_SHUTDOWN, &buf, &rbuf))
1293 reg_io_r_shutdown("", &r_o, &rbuf, 0);
1294 p = rbuf.offset != 0;
1296 if (p && r_o.status != 0)
1298 /* report error code */
1299 DEBUG(0,("REG_SHUTDOWN: %s\n", get_nt_error_msg(r_o.status)));
1305 valid_shutdown = True;
1309 prs_mem_free(&rbuf);
1310 prs_mem_free(&buf );
1312 cli_state_free(cli, fnum);
1314 return valid_shutdown;