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_connection *con = NULL;
47 if (!cli_connection_init(srv_name, PIPE_WINREG, &con))
52 ZERO_STRUCTP(reg_hnd);
54 if (full_keyname == NULL)
60 * open registry receive a policy handle
63 if (!reg_split_key(full_keyname, ®_type, key_name))
65 DEBUG(0,("reg_connect: unrecognised key name %s\n",
72 case HKEY_CLASSES_ROOT:
74 res = res ? reg_open_hkcr(con,
80 case HKEY_LOCAL_MACHINE:
82 res = res ? reg_open_hklm(con,
90 res = res ? reg_open_hku(con,
97 DEBUG(0,("reg_connect: unrecognised hive key\n"));
104 if (!register_policy_hnd(reg_hnd) ||
105 !set_policy_con(reg_hnd, con,
106 cli_connection_unlink))
108 cli_connection_unlink(con);
116 /****************************************************************************
118 ****************************************************************************/
119 BOOL reg_open_hkcr( struct cli_connection *con,
120 uint16 unknown_0, uint32 level,
126 BOOL valid_pol = False;
128 if (hnd == NULL) return False;
130 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
131 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
133 /* create and send a MSRPC command with api REG_OPEN_HKCR */
135 DEBUG(4,("REG Open HKCR\n"));
137 make_reg_q_open_hkcr(&q_o, unknown_0, level);
139 /* turn parameters into data stream */
140 reg_io_q_open_hkcr("", &q_o, &buf, 0);
142 /* send the data on \PIPE\ */
143 if (rpc_con_pipe_req(con, REG_OPEN_HKCR, &buf, &rbuf))
150 reg_io_r_open_hkcr("", &r_o, &rbuf, 0);
151 p = rbuf.offset != 0;
153 if (p && r_o.status != 0)
155 /* report error code */
156 DEBUG(0,("REG_OPEN_HKCR: %s\n", get_nt_error_msg(r_o.status)));
162 /* ok, at last: we're happy. return the policy handle */
163 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
174 /****************************************************************************
176 ****************************************************************************/
177 BOOL reg_open_hklm( struct cli_connection *con,
178 uint16 unknown_0, uint32 level,
184 BOOL valid_pol = False;
186 if (hnd == NULL) return False;
188 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
189 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
191 /* create and send a MSRPC command with api REG_OPEN_HKLM */
193 DEBUG(4,("REG Open HKLM\n"));
195 make_reg_q_open_hklm(&q_o, unknown_0, level);
197 /* turn parameters into data stream */
198 reg_io_q_open_hklm("", &q_o, &buf, 0);
200 /* send the data on \PIPE\ */
201 if (rpc_con_pipe_req(con, REG_OPEN_HKLM, &buf, &rbuf))
208 reg_io_r_open_hklm("", &r_o, &rbuf, 0);
209 p = rbuf.offset != 0;
211 if (p && r_o.status != 0)
213 /* report error code */
214 DEBUG(0,("REG_OPEN_HKLM: %s\n", get_nt_error_msg(r_o.status)));
220 /* ok, at last: we're happy. return the policy handle */
221 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
232 /****************************************************************************
234 ****************************************************************************/
235 BOOL reg_open_hku( struct cli_connection *con,
236 uint16 unknown_0, uint32 level,
242 BOOL valid_pol = False;
244 if (hnd == NULL) return False;
246 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
247 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
249 /* create and send a MSRPC command with api REG_OPEN_HKU */
251 DEBUG(4,("REG Open HKU\n"));
253 make_reg_q_open_hku(&q_o, unknown_0, level);
255 /* turn parameters into data stream */
256 reg_io_q_open_hku("", &q_o, &buf, 0);
258 /* send the data on \PIPE\ */
259 if (rpc_con_pipe_req(con, REG_OPEN_HKU, &buf, &rbuf))
266 reg_io_r_open_hku("", &r_o, &rbuf, 0);
267 p = rbuf.offset != 0;
269 if (p && r_o.status != 0)
271 /* report error code */
272 DEBUG(0,("REG_OPEN_HKU: %s\n", get_nt_error_msg(r_o.status)));
278 /* ok, at last: we're happy. return the policy handle */
279 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
290 /****************************************************************************
291 do a REG Unknown 0xB command. sent after a create key or create value.
292 this might be some sort of "sync" or "refresh" command, sent after
293 modification of the registry...
294 ****************************************************************************/
295 BOOL reg_flush_key( POLICY_HND *hnd)
300 BOOL valid_query = False;
302 if (hnd == NULL) return False;
304 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
305 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
307 /* create and send a MSRPC command with api REG_FLUSH_KEY */
309 DEBUG(4,("REG Unknown 0xB\n"));
311 make_reg_q_flush_key(&q_o, hnd);
313 /* turn parameters into data stream */
314 reg_io_q_flush_key("", &q_o, &buf, 0);
316 /* send the data on \PIPE\ */
317 if (rpc_hnd_pipe_req(hnd, REG_FLUSH_KEY, &buf, &rbuf))
324 reg_io_r_flush_key("", &r_o, &rbuf, 0);
325 p = rbuf.offset != 0;
327 if (p && r_o.status != 0)
329 /* report error code */
330 DEBUG(0,("REG_FLUSH_KEY: %s\n", get_nt_error_msg(r_o.status)));
346 /****************************************************************************
348 ****************************************************************************/
349 BOOL reg_query_key( POLICY_HND *hnd,
350 char *key_class, uint32 *class_len,
351 uint32 *num_subkeys, uint32 *max_subkeylen,
352 uint32 *max_subkeysize, uint32 *num_values,
353 uint32 *max_valnamelen, uint32 *max_valbufsize,
354 uint32 *sec_desc, NTTIME *mod_time)
359 BOOL valid_query = False;
361 if (hnd == NULL) return False;
363 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
364 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
366 /* create and send a MSRPC command with api REG_QUERY_KEY */
368 DEBUG(4,("REG Query Key\n"));
370 make_reg_q_query_key(&q_o, hnd, *class_len);
372 /* turn parameters into data stream */
373 reg_io_q_query_key("", &q_o, &buf, 0);
375 /* send the data on \PIPE\ */
376 if (rpc_hnd_pipe_req(hnd, REG_QUERY_KEY, &buf, &rbuf))
383 reg_io_r_query_key("", &r_o, &rbuf, 0);
384 p = rbuf.offset != 0;
386 if (p && r_o.status != 0)
388 /* report error code */
389 DEBUG(0,("REG_QUERY_KEY: %s\n", get_nt_error_msg(r_o.status)));
397 *class_len = r_o.hdr_class.uni_max_len;
398 unistr2_to_ascii(key_class, &r_o.uni_class, sizeof(fstring)-1);
399 *num_subkeys = r_o.num_subkeys ;
400 *max_subkeylen = r_o.max_subkeylen ;
401 *max_subkeysize = r_o.max_subkeysize;
402 *num_values = r_o.num_values ;
403 *max_valnamelen = r_o.max_valnamelen;
404 *max_valbufsize = r_o.max_valbufsize;
405 *sec_desc = r_o.sec_desc ;
406 *mod_time = r_o.mod_time ;
416 /****************************************************************************
418 ****************************************************************************/
419 BOOL reg_unknown_1a( POLICY_HND *hnd, uint32 *unk)
424 BOOL valid_query = False;
426 if (hnd == NULL) return False;
428 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
429 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
431 /* create and send a MSRPC command with api REG_UNKNOWN_1A */
433 DEBUG(4,("REG Unknown 1a\n"));
435 make_reg_q_unk_1a(&q_o, hnd);
437 /* turn parameters into data stream */
438 reg_io_q_unk_1a("", &q_o, &buf, 0);
440 /* send the data on \PIPE\ */
441 if (rpc_hnd_pipe_req(hnd, REG_UNK_1A, &buf, &rbuf))
448 reg_io_r_unk_1a("", &r_o, &rbuf, 0);
449 p = rbuf.offset != 0;
451 if (p && r_o.status != 0)
453 /* report error code */
454 DEBUG(0,("REG_UNK_1A: %s\n", get_nt_error_msg(r_o.status)));
461 (*unk) = r_o.unknown;
471 /****************************************************************************
473 ****************************************************************************/
474 BOOL reg_query_info( POLICY_HND *hnd,
475 const char* val_name,
476 uint32 *type, BUFFER2 *buffer)
481 BOOL valid_query = False;
483 if (hnd == NULL) return False;
485 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
486 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
488 /* create and send a MSRPC command with api REG_INFO */
490 DEBUG(4,("REG Query Info\n"));
492 make_reg_q_info(&q_o, hnd, val_name, 4, 0);
494 /* turn parameters into data stream */
495 reg_io_q_info("", &q_o, &buf, 0);
497 /* send the data on \PIPE\ */
498 if (rpc_hnd_pipe_req(hnd, REG_INFO, &buf, &rbuf))
506 r_o.uni_type = buffer;
508 reg_io_r_info("", &r_o, &rbuf, 0);
509 p = rbuf.offset != 0;
511 if (p && r_o.status != 0)
513 /* report error code */
514 DEBUG(0,("REG_INFO: %s\n", get_nt_error_msg(r_o.status)));
530 /****************************************************************************
531 do a REG Set Key Security
532 ****************************************************************************/
533 BOOL reg_set_key_sec( POLICY_HND *hnd,
535 uint32 sec_buf_size, SEC_DESC *sec_buf)
539 REG_Q_SET_KEY_SEC q_o;
540 BOOL valid_query = False;
542 if (hnd == NULL) return False;
544 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
545 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
547 /* create and send a MSRPC command with api REG_SET_KEY_SEC */
549 DEBUG(4,("REG Set Key security.\n"));
551 make_reg_q_set_key_sec(&q_o, hnd, sec_info, sec_buf_size, sec_buf);
553 /* turn parameters into data stream */
554 reg_io_q_set_key_sec("", &q_o, &buf, 0);
556 /* send the data on \PIPE\ */
557 if (rpc_hnd_pipe_req(hnd, REG_SET_KEY_SEC, &buf, &rbuf))
559 REG_R_SET_KEY_SEC r_o;
564 reg_io_r_set_key_sec("", &r_o, &rbuf, 0);
565 p = rbuf.offset != 0;
567 if (p && r_o.status != 0)
580 /****************************************************************************
581 do a REG Query Key Security
582 ****************************************************************************/
583 BOOL reg_get_key_sec( POLICY_HND *hnd,
585 uint32 *sec_buf_size, SEC_DESC_BUF *sec_buf)
589 REG_Q_GET_KEY_SEC q_o;
590 BOOL valid_query = False;
592 if (hnd == NULL) return False;
594 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
595 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
597 /* create and send a MSRPC command with api REG_GET_KEY_SEC */
599 DEBUG(4,("REG query key security. buf_size: %d\n", *sec_buf_size));
601 make_reg_q_get_key_sec(&q_o, hnd, sec_info, *sec_buf_size, sec_buf);
603 /* turn parameters into data stream */
604 reg_io_q_get_key_sec("", &q_o, &buf, 0);
606 /* send the data on \PIPE\ */
607 if (rpc_hnd_pipe_req(hnd, REG_GET_KEY_SEC, &buf, &rbuf))
609 REG_R_GET_KEY_SEC r_o;
615 if (*sec_buf_size != 0)
617 sec_buf->sec = (SEC_DESC*)malloc(*sec_buf_size);
619 reg_io_r_get_key_sec("", &r_o, &rbuf, 0);
620 p = rbuf.offset != 0;
622 if (p && r_o.status == 0x0000007a)
625 * get the maximum buffer size: it was too small
627 (*sec_buf_size) = r_o.hdr_sec.buf_max_len;
628 DEBUG(5,("sec_buf_size too small. use %d\n", *sec_buf_size));
631 else if (p && r_o.status != 0)
633 /* report error code */
634 DEBUG(0,("REG_GET_KEY_SEC: %s\n", get_nt_error_msg(r_o.status)));
640 (*sec_buf_size) = r_o.data->len;
650 /****************************************************************************
651 do a REG Delete Value
652 ****************************************************************************/
653 BOOL reg_delete_val( POLICY_HND *hnd, char *val_name)
657 REG_Q_DELETE_VALUE q_o;
658 BOOL valid_delete = False;
660 if (hnd == NULL) return False;
662 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
663 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
665 /* create and send a MSRPC command with api REG_DELETE_VALUE */
667 DEBUG(4,("REG Delete Value: %s\n", val_name));
669 make_reg_q_delete_val(&q_o, hnd, val_name);
671 /* turn parameters into data stream */
672 reg_io_q_delete_val("", &q_o, &buf, 0);
674 /* send the data on \PIPE\ */
675 if (rpc_hnd_pipe_req(hnd, REG_DELETE_VALUE, &buf, &rbuf))
677 REG_R_DELETE_VALUE r_o;
682 reg_io_r_delete_val("", &r_o, &rbuf, 0);
683 p = rbuf.offset != 0;
685 if (p && r_o.status != 0)
687 /* report error code */
688 DEBUG(0,("REG_DELETE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
704 /****************************************************************************
706 ****************************************************************************/
707 BOOL reg_delete_key( POLICY_HND *hnd, char *key_name)
711 REG_Q_DELETE_KEY q_o;
712 BOOL valid_delete = False;
714 if (hnd == NULL) return False;
716 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
717 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
719 /* create and send a MSRPC command with api REG_DELETE_KEY */
721 DEBUG(4,("REG Delete Key: %s\n", key_name));
723 make_reg_q_delete_key(&q_o, hnd, key_name);
725 /* turn parameters into data stream */
726 reg_io_q_delete_key("", &q_o, &buf, 0);
728 /* send the data on \PIPE\ */
729 if (rpc_hnd_pipe_req(hnd, REG_DELETE_KEY, &buf, &rbuf))
731 REG_R_DELETE_KEY r_o;
736 reg_io_r_delete_key("", &r_o, &rbuf, 0);
737 p = rbuf.offset != 0;
739 if (p && r_o.status != 0)
741 /* report error code */
742 DEBUG(0,("REG_DELETE_KEY: %s\n", get_nt_error_msg(r_o.status)));
758 /****************************************************************************
760 ****************************************************************************/
761 BOOL reg_create_key( POLICY_HND *hnd,
762 char *key_name, char *key_class,
763 SEC_ACCESS *sam_access,
768 REG_Q_CREATE_KEY q_o;
769 BOOL valid_create = False;
771 SEC_DESC_BUF sec_buf;
775 ZERO_STRUCT(sec_buf);
778 if (hnd == NULL) return False;
780 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
781 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
783 /* create and send a MSRPC command with api REG_CREATE_KEY */
785 DEBUG(4,("REG Create Key: %s %s 0x%08x\n", key_name, key_class,
786 sam_access != NULL ? sam_access->mask : 0));
788 sec_len = make_sec_desc(&sec, 1, SEC_DESC_SELF_RELATIVE,
789 NULL, NULL, NULL, NULL);
791 DEBUG(10,("make_sec_desc: len = %d\n", sec_len));
793 make_reg_q_create_key(&q_o, hnd, key_name, key_class, sam_access,
794 &sec_buf, sec_len, &sec);
796 /* turn parameters into data stream */
797 reg_io_q_create_key("", &q_o, &buf, 0);
799 /* send the data on \PIPE\ */
800 if (rpc_hnd_pipe_req(hnd, REG_CREATE_KEY, &buf, &rbuf))
802 REG_R_CREATE_KEY r_o;
807 reg_io_r_create_key("", &r_o, &rbuf, 0);
808 p = rbuf.offset != 0;
810 if (p && r_o.status != 0)
812 /* report error code */
813 DEBUG(0,("REG_CREATE_KEY: %s\n", get_nt_error_msg(r_o.status)));
820 memcpy(key, r_o.key_pol.data, sizeof(key->data));
832 /****************************************************************************
834 ****************************************************************************/
835 BOOL reg_enum_key( POLICY_HND *hnd,
836 int key_index, char *key_name,
837 uint32 *unk_1, uint32 *unk_2,
843 BOOL valid_query = False;
845 if (hnd == NULL) return False;
847 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
848 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
850 /* create and send a MSRPC command with api REG_ENUM_KEY */
852 DEBUG(4,("REG Enum Key\n"));
854 make_reg_q_enum_key(&q_o, hnd, key_index);
856 /* turn parameters into data stream */
857 reg_io_q_enum_key("", &q_o, &buf, 0);
859 /* send the data on \PIPE\ */
860 if (rpc_hnd_pipe_req(hnd, REG_ENUM_KEY, &buf, &rbuf))
867 reg_io_r_enum_key("", &r_o, &rbuf, 0);
868 p = rbuf.offset != 0;
870 if (p && r_o.status != 0)
872 /* report error code */
873 DEBUG(0,("REG_ENUM_KEY: %s\n", get_nt_error_msg(r_o.status)));
880 (*unk_1) = r_o.unknown_1;
881 (*unk_2) = r_o.unknown_2;
882 unistr_to_ascii(key_name, r_o.key_name.str.buffer,
884 (*mod_time) = nt_time_to_unix(&r_o.time);
894 /****************************************************************************
895 do a REG Create Value
896 ****************************************************************************/
897 BOOL reg_create_val( POLICY_HND *hnd,
898 char *val_name, uint32 type, BUFFER3 *data)
902 REG_Q_CREATE_VALUE q_o;
903 BOOL valid_create = False;
905 if (hnd == NULL) return False;
907 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
908 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
910 /* create and send a MSRPC command with api REG_CREATE_VALUE */
912 DEBUG(4,("REG Create Value: %s\n", val_name));
914 make_reg_q_create_val(&q_o, hnd, val_name, type, data);
916 /* turn parameters into data stream */
917 reg_io_q_create_val("", &q_o, &buf, 0);
919 /* send the data on \PIPE\ */
920 if (rpc_hnd_pipe_req(hnd, REG_CREATE_VALUE, &buf, &rbuf))
922 REG_R_CREATE_VALUE r_o;
927 reg_io_r_create_val("", &r_o, &rbuf, 0);
928 p = rbuf.offset != 0;
930 if (p && r_o.status != 0)
932 /* report error code */
933 DEBUG(0,("REG_CREATE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
949 /****************************************************************************
951 ****************************************************************************/
952 BOOL reg_enum_val( POLICY_HND *hnd,
953 int val_index, int max_valnamelen, int max_valbufsize,
955 uint32 *val_type, BUFFER2 *value)
959 REG_Q_ENUM_VALUE q_o;
960 BOOL valid_query = False;
962 if (hnd == NULL) return False;
964 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
965 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
967 /* create and send a MSRPC command with api REG_ENUM_VALUE */
969 DEBUG(4,("REG Enum Value\n"));
971 make_reg_q_enum_val(&q_o, hnd, val_index, max_valnamelen, max_valbufsize);
973 /* turn parameters into data stream */
974 reg_io_q_enum_val("", &q_o, &buf, 0);
976 /* send the data on \PIPE\ */
977 if (rpc_hnd_pipe_req(hnd, REG_ENUM_VALUE, &buf, &rbuf))
979 REG_R_ENUM_VALUE r_o;
983 r_o.buf_value = value;
985 reg_io_r_enum_val("", &r_o, &rbuf, 0);
986 p = rbuf.offset != 0;
988 if (p && r_o.status != 0)
990 /* report error code */
991 DEBUG(0,("REG_ENUM_VALUE: %s\n", get_nt_error_msg(r_o.status)));
998 (*val_type) = r_o.type;
999 unistr2_to_ascii(val_name, &r_o.uni_name, sizeof(fstring)-1);
1003 prs_mem_free(&rbuf);
1004 prs_mem_free(&buf );
1009 /****************************************************************************
1011 ****************************************************************************/
1012 BOOL reg_open_entry( POLICY_HND *hnd,
1013 char *key_name, uint32 unk_0,
1014 POLICY_HND *key_hnd)
1018 REG_Q_OPEN_ENTRY q_o;
1019 BOOL valid_pol = False;
1021 if (hnd == NULL) return False;
1023 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1024 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1026 /* create and send a MSRPC command with api REG_OPEN_ENTRY */
1028 DEBUG(4,("REG Open Entry\n"));
1030 make_reg_q_open_entry(&q_o, hnd, key_name, unk_0);
1032 /* turn parameters into data stream */
1033 reg_io_q_open_entry("", &q_o, &buf, 0);
1035 /* send the data on \PIPE\ */
1036 if (rpc_hnd_pipe_req(hnd, REG_OPEN_ENTRY, &buf, &rbuf))
1038 REG_R_OPEN_ENTRY r_o;
1043 reg_io_r_open_entry("", &r_o, &rbuf, 0);
1044 p = rbuf.offset != 0;
1046 if (p && r_o.status != 0)
1048 /* report error code */
1049 DEBUG(0,("REG_OPEN_ENTRY: %s\n", get_nt_error_msg(r_o.status)));
1055 struct cli_connection *con = NULL;
1057 if (!cli_connection_get(hnd, &con))
1062 memcpy(key_hnd, r_o.pol.data, sizeof(key_hnd->data));
1063 valid_pol = cli_pol_link(key_hnd, hnd);
1067 prs_mem_free(&rbuf);
1068 prs_mem_free(&buf );
1073 /****************************************************************************
1075 ****************************************************************************/
1076 BOOL reg_close( POLICY_HND *hnd)
1081 BOOL valid_close = False;
1083 if (hnd == NULL) return False;
1085 /* create and send a MSRPC command with api REG_CLOSE */
1087 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1088 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1090 DEBUG(4,("REG Close\n"));
1092 /* store the parameters */
1093 make_reg_q_close(&q_c, hnd);
1095 /* turn parameters into data stream */
1096 reg_io_q_close("", &q_c, &buf, 0);
1098 /* send the data on \PIPE\ */
1099 if (rpc_hnd_pipe_req(hnd, REG_CLOSE, &buf, &rbuf))
1106 reg_io_r_close("", &r_c, &rbuf, 0);
1107 p = rbuf.offset != 0;
1109 if (p && r_c.status != 0)
1111 /* report error code */
1112 DEBUG(0,("REG_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
1118 /* check that the returned policy handle is all zeros */
1122 for (i = 0; i < sizeof(r_c.pol.data); i++)
1124 if (r_c.pol.data[i] != 0)
1126 valid_close = False;
1132 DEBUG(0,("REG_CLOSE: non-zero handle returned\n"));
1137 prs_mem_free(&rbuf);
1138 prs_mem_free(&buf );
1140 close_policy_hnd(hnd);
1145 /****************************************************************************
1146 do a REG Shutdown Server
1147 ****************************************************************************/
1148 BOOL reg_shutdown(const char *srv_name,
1149 const char *msg, uint32 timeout, uint16 flags)
1154 BOOL valid_shutdown = False;
1156 struct cli_connection *con = NULL;
1158 if (!cli_connection_init(srv_name, PIPE_LSARPC, &con))
1163 if (msg == NULL) return False;
1165 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1166 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1168 /* create and send a MSRPC command with api REG_SHUTDOWN */
1170 DEBUG(4,("REG Shutdown: (timeout: %d secs) %s\n", timeout, msg));
1172 make_reg_q_shutdown(&q_o, msg, timeout, flags);
1174 /* turn parameters into data stream */
1175 reg_io_q_shutdown("", &q_o, &buf, 0);
1177 /* send the data on \PIPE\ */
1178 if (rpc_con_pipe_req(con, REG_SHUTDOWN, &buf, &rbuf))
1185 reg_io_r_shutdown("", &r_o, &rbuf, 0);
1186 p = rbuf.offset != 0;
1188 if (p && r_o.status != 0)
1190 /* report error code */
1191 DEBUG(0,("REG_SHUTDOWN: %s\n", get_nt_error_msg(r_o.status)));
1197 valid_shutdown = True;
1201 prs_mem_free(&rbuf);
1202 prs_mem_free(&buf );
1204 cli_connection_unlink(con);
1206 return valid_shutdown;