2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-2000,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 * Copyright (C) Paul Ashton 1997-2000.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "rpc_parse.h"
26 #include "rpc_client.h"
28 extern int DEBUGLEVEL
;
30 /****************************************************************************
32 ****************************************************************************/
33 BOOL
reg_connect(const char *srv_name
,
34 const char *full_keyname
,
42 struct cli_connection
*con
= NULL
;
44 if (!cli_connection_init(srv_name
, PIPE_WINREG
, &con
))
49 ZERO_STRUCTP(reg_hnd
);
51 if (full_keyname
== NULL
)
57 * open registry receive a policy handle
60 if (!reg_split_key(full_keyname
, ®_type
, key_name
))
62 DEBUG(0,("reg_connect: unrecognised key name %s\n",
69 case HKEY_CLASSES_ROOT
:
71 res
= res
? reg_open_hkcr(con
,
77 case HKEY_LOCAL_MACHINE
:
79 res
= res
? reg_open_hklm(con
,
87 res
= res
? reg_open_hku(con
,
94 DEBUG(0,("reg_connect: unrecognised hive key\n"));
101 if (!register_policy_hnd(get_global_hnd_cache(),
102 cli_con_sec_ctx(con
),
103 reg_hnd
, access_mask
)
104 || !set_policy_con(get_global_hnd_cache(), reg_hnd
, con
,
105 cli_connection_unlink
))
107 cli_connection_unlink(con
);
115 /****************************************************************************
117 ****************************************************************************/
118 BOOL
reg_open_hkcr(struct cli_connection
*con
,
119 uint16 unknown_0
, uint32 level
, POLICY_HND
*hnd
)
124 BOOL valid_pol
= False
;
126 if (hnd
== NULL
) return False
;
128 prs_init(&buf
, 0, 4, False
);
129 prs_init(&rbuf
, 0, 4, True
);
131 /* create and send a MSRPC command with api REG_OPEN_HKCR */
133 DEBUG(4,("REG Open HKCR\n"));
135 make_reg_q_open_hkcr(&q_o
, unknown_0
, level
);
137 /* turn parameters into data stream */
138 if (reg_io_q_open_hkcr("", &q_o
, &buf
, 0) &&
139 rpc_con_pipe_req(con
, REG_OPEN_HKCR
, &buf
, &rbuf
))
146 reg_io_r_open_hkcr("", &r_o
, &rbuf
, 0);
147 p
= rbuf
.offset
!= 0;
149 if (p
&& r_o
.status
!= 0)
151 /* report error code */
152 DEBUG(0, ("REG_OPEN_HKCR: %s\n",
153 get_nt_error_msg(r_o
.status
)));
159 /* ok, at last: we're happy. return the policy handle */
165 prs_free_data(&rbuf
);
166 prs_free_data(&buf
);
171 /****************************************************************************
173 ****************************************************************************/
174 BOOL
reg_open_hklm(struct cli_connection
*con
,
175 uint16 unknown_0
, uint32 level
,
181 BOOL valid_pol
= False
;
183 if (hnd
== NULL
) return False
;
185 prs_init(&buf
, 0, 4, False
);
186 prs_init(&rbuf
, 0, 4, True
);
188 /* create and send a MSRPC command with api REG_OPEN_HKLM */
190 DEBUG(4,("REG Open HKLM\n"));
192 make_reg_q_open_hklm(&q_o
, unknown_0
, level
);
194 /* turn parameters into data stream */
195 if (reg_io_q_open_hklm("", &q_o
, &buf
, 0) &&
196 rpc_con_pipe_req(con
, REG_OPEN_HKLM
, &buf
, &rbuf
))
203 reg_io_r_open_hklm("", &r_o
, &rbuf
, 0);
204 p
= rbuf
.offset
!= 0;
206 if (p
&& r_o
.status
!= 0)
208 /* report error code */
209 DEBUG(0, ("REG_OPEN_HKLM: %s\n",
210 get_nt_error_msg(r_o
.status
)));
216 /* ok, at last: we're happy. return the policy handle */
222 prs_free_data(&rbuf
);
223 prs_free_data(&buf
);
228 /****************************************************************************
230 ****************************************************************************/
231 BOOL
reg_open_hku(struct cli_connection
*con
,
232 uint16 unknown_0
, uint32 level
,
238 BOOL valid_pol
= False
;
240 if (hnd
== NULL
) return False
;
242 prs_init(&buf
, 0, 4, False
);
243 prs_init(&rbuf
, 0, 4, True
);
245 /* create and send a MSRPC command with api REG_OPEN_HKU */
247 DEBUG(4,("REG Open HKU\n"));
249 make_reg_q_open_hku(&q_o
, unknown_0
, level
);
251 /* turn parameters into data stream */
252 if (reg_io_q_open_hku("", &q_o
, &buf
, 0) &&
253 rpc_con_pipe_req(con
, REG_OPEN_HKU
, &buf
, &rbuf
))
260 reg_io_r_open_hku("", &r_o
, &rbuf
, 0);
261 p
= rbuf
.offset
!= 0;
263 if (p
&& r_o
.status
!= 0)
265 /* report error code */
266 DEBUG(0, ("REG_OPEN_HKU: %s\n",
267 get_nt_error_msg(r_o
.status
)));
273 /* ok, at last: we're happy. return the policy handle */
279 prs_free_data(&rbuf
);
280 prs_free_data(&buf
);
285 /****************************************************************************
286 do a REG Unknown 0xB command. sent after a create key or create value.
287 this might be some sort of "sync" or "refresh" command, sent after
288 modification of the registry...
289 ****************************************************************************/
290 BOOL
reg_flush_key(POLICY_HND
*hnd
)
295 BOOL valid_query
= False
;
297 if (hnd
== NULL
) return False
;
299 prs_init(&buf
, 0, 4, False
);
300 prs_init(&rbuf
, 0, 4, True
);
302 /* create and send a MSRPC command with api REG_FLUSH_KEY */
304 DEBUG(4,("REG Unknown 0xB\n"));
306 make_reg_q_flush_key(&q_o
, hnd
);
308 /* turn parameters into data stream */
309 if (reg_io_q_flush_key("", &q_o
, &buf
, 0) &&
310 rpc_hnd_pipe_req(hnd
, REG_FLUSH_KEY
, &buf
, &rbuf
))
317 reg_io_r_flush_key("", &r_o
, &rbuf
, 0);
318 p
= rbuf
.offset
!= 0;
320 if (p
&& r_o
.status
!= 0)
322 /* report error code */
323 DEBUG(0, ("REG_FLUSH_KEY: %s\n",
324 get_nt_error_msg(r_o
.status
)));
334 prs_free_data(&rbuf
);
335 prs_free_data(&buf
);
340 /****************************************************************************
342 ****************************************************************************/
343 BOOL
reg_query_key(POLICY_HND
*hnd
,
344 char *key_class
, uint32
*class_len
,
345 uint32
*num_subkeys
, uint32
*max_subkeylen
,
346 uint32
*max_subkeysize
, uint32
*num_values
,
347 uint32
*max_valnamelen
, uint32
*max_valbufsize
,
348 uint32
*sec_desc
, NTTIME
*mod_time
)
353 BOOL valid_query
= False
;
355 if (hnd
== NULL
) return False
;
357 prs_init(&buf
, 0, 4, False
);
358 prs_init(&rbuf
, 0, 4, True
);
360 /* create and send a MSRPC command with api REG_QUERY_KEY */
362 DEBUG(4,("REG Query Key\n"));
364 make_reg_q_query_key(&q_o
, hnd
, *class_len
);
366 /* turn parameters into data stream */
367 if (reg_io_q_query_key("", &q_o
, &buf
, 0) &&
368 rpc_hnd_pipe_req(hnd
, REG_QUERY_KEY
, &buf
, &rbuf
))
375 reg_io_r_query_key("", &r_o
, &rbuf
, 0);
376 p
= rbuf
.offset
!= 0;
378 if (p
&& r_o
.status
!= 0)
380 /* report error code */
381 DEBUG(0, ("REG_QUERY_KEY: %s\n",
382 get_nt_error_msg(r_o
.status
)));
390 *class_len
= r_o
.hdr_class
.uni_max_len
;
391 unistr2_to_ascii(key_class
, &r_o
.uni_class
, sizeof(fstring
)-1);
392 *num_subkeys
= r_o
.num_subkeys
;
393 *max_subkeylen
= r_o
.max_subkeylen
;
394 *max_subkeysize
= r_o
.max_subkeysize
;
395 *num_values
= r_o
.num_values
;
396 *max_valnamelen
= r_o
.max_valnamelen
;
397 *max_valbufsize
= r_o
.max_valbufsize
;
398 *sec_desc
= r_o
.sec_desc
;
399 *mod_time
= r_o
.mod_time
;
403 prs_free_data(&rbuf
);
404 prs_free_data(&buf
);
409 /****************************************************************************
411 ****************************************************************************/
412 BOOL
reg_unknown_1a(POLICY_HND
*hnd
, uint32
*unk
)
417 BOOL valid_query
= False
;
419 if (hnd
== NULL
) return False
;
421 prs_init(&buf
, 0, 4, False
);
422 prs_init(&rbuf
, 0, 4, True
);
424 /* create and send a MSRPC command with api REG_UNKNOWN_1A */
426 DEBUG(4,("REG Unknown 1a\n"));
428 make_reg_q_unk_1a(&q_o
, hnd
);
430 /* turn parameters into data stream */
431 if (reg_io_q_unk_1a("", &q_o
, &buf
, 0) &&
432 rpc_hnd_pipe_req(hnd
, REG_UNK_1A
, &buf
, &rbuf
))
439 reg_io_r_unk_1a("", &r_o
, &rbuf
, 0);
440 p
= rbuf
.offset
!= 0;
442 if (p
&& r_o
.status
!= 0)
444 /* report error code */
445 DEBUG(0, ("REG_UNK_1A: %s\n",
446 get_nt_error_msg(r_o
.status
)));
453 (*unk
) = r_o
.unknown
;
457 prs_free_data(&rbuf
);
458 prs_free_data(&buf
);
463 /****************************************************************************
465 ****************************************************************************/
466 BOOL
reg_query_info(POLICY_HND
*hnd
, const char *val_name
,
467 uint32
*type
, BUFFER2
*buffer
)
472 BOOL valid_query
= False
;
474 if (hnd
== NULL
) return False
;
476 prs_init(&buf
, 0, 4, False
);
477 prs_init(&rbuf
, 0, 4, True
);
479 /* create and send a MSRPC command with api REG_INFO */
481 DEBUG(4,("REG Query Info\n"));
483 make_reg_q_info(&q_o
, hnd
, val_name
, 4, 0, buffer
->buf_max_len
);
485 /* turn parameters into data stream */
486 if (reg_io_q_info("", &q_o
, &buf
, 0) &&
487 rpc_hnd_pipe_req(hnd
, REG_INFO
, &buf
, &rbuf
))
495 r_o
.uni_val
= buffer
;
497 reg_io_r_info("", &r_o
, &rbuf
, 0);
498 p
= rbuf
.offset
!= 0;
500 if (p
&& r_o
.status
!= 0)
502 /* report error code */
503 DEBUG(0, ("REG_INFO: %s\n",
504 get_nt_error_msg(r_o
.status
)));
514 prs_free_data(&rbuf
);
515 prs_free_data(&buf
);
520 /****************************************************************************
521 do a REG Set Key Security
522 ****************************************************************************/
523 BOOL
reg_set_key_sec(POLICY_HND
*hnd
,
525 uint32 sec_buf_size
, SEC_DESC
*sec_buf
)
529 REG_Q_SET_KEY_SEC q_o
;
530 BOOL valid_query
= False
;
532 if (hnd
== NULL
) return False
;
534 prs_init(&buf
, 0, 4, False
);
535 prs_init(&rbuf
, 0, 4, True
);
537 /* create and send a MSRPC command with api REG_SET_KEY_SEC */
539 DEBUG(4,("REG Set Key security.\n"));
541 make_reg_q_set_key_sec(&q_o
, hnd
, sec_info
, sec_buf_size
, sec_buf
);
543 /* turn parameters into data stream */
544 if (reg_io_q_set_key_sec("", &q_o
, &buf
, 0) &&
545 rpc_hnd_pipe_req(hnd
, REG_SET_KEY_SEC
, &buf
, &rbuf
))
547 REG_R_SET_KEY_SEC r_o
;
552 reg_io_r_set_key_sec("", &r_o
, &rbuf
, 0);
553 p
= rbuf
.offset
!= 0;
555 if (p
&& r_o
.status
!= 0)
561 prs_free_data(&rbuf
);
562 prs_free_data(&buf
);
568 /****************************************************************************
569 do a REG Query Key Security
570 ****************************************************************************/
571 BOOL
reg_get_key_sec(POLICY_HND
*hnd
,
573 uint32
*sec_buf_size
, SEC_DESC_BUF
*sec_buf
)
577 REG_Q_GET_KEY_SEC q_o
;
578 BOOL valid_query
= False
;
580 if (hnd
== NULL
) return False
;
582 prs_init(&buf
, 0, 4, False
);
583 prs_init(&rbuf
, 0, 4, True
);
585 /* create and send a MSRPC command with api REG_GET_KEY_SEC */
587 DEBUG(4,("REG query key security. buf_size: %d\n", *sec_buf_size
));
589 make_reg_q_get_key_sec(&q_o
, hnd
, sec_info
, *sec_buf_size
, sec_buf
);
591 /* turn parameters into data stream */
592 if (reg_io_q_get_key_sec("", &q_o
, &buf
, 0) &&
593 rpc_hnd_pipe_req(hnd
, REG_GET_KEY_SEC
, &buf
, &rbuf
))
595 REG_R_GET_KEY_SEC r_o
;
601 if (*sec_buf_size
!= 0)
603 sec_buf
->sec
= (SEC_DESC
*)malloc(*sec_buf_size
);
605 reg_io_r_get_key_sec("", &r_o
, &rbuf
, 0);
606 p
= rbuf
.offset
!= 0;
608 if (p
&& r_o
.status
== 0x0000007a)
611 * get the maximum buffer size: it was too small
613 (*sec_buf_size
) = r_o
.hdr_sec
.buf_max_len
;
614 DEBUG(5, ("sec_buf_size too small. use %d\n",
618 else if (p
&& r_o
.status
!= 0)
620 /* report error code */
621 DEBUG(0, ("REG_GET_KEY_SEC: %s\n",
622 get_nt_error_msg(r_o
.status
)));
628 (*sec_buf_size
) = r_o
.data
->len
;
632 prs_free_data(&rbuf
);
633 prs_free_data(&buf
);
638 /****************************************************************************
639 do a REG Delete Value
640 ****************************************************************************/
641 BOOL
reg_delete_val(POLICY_HND
*hnd
, char *val_name
)
645 REG_Q_DELETE_VALUE q_o
;
646 BOOL valid_delete
= False
;
648 if (hnd
== NULL
) return False
;
650 prs_init(&buf
, 0, 4, False
);
651 prs_init(&rbuf
, 0, 4, True
);
653 /* create and send a MSRPC command with api REG_DELETE_VALUE */
655 DEBUG(4,("REG Delete Value: %s\n", val_name
));
657 make_reg_q_delete_val(&q_o
, hnd
, val_name
);
659 /* turn parameters into data stream */
660 if (reg_io_q_delete_val("", &q_o
, &buf
, 0) &&
661 rpc_hnd_pipe_req(hnd
, REG_DELETE_VALUE
, &buf
, &rbuf
))
663 REG_R_DELETE_VALUE r_o
;
668 reg_io_r_delete_val("", &r_o
, &rbuf
, 0);
669 p
= rbuf
.offset
!= 0;
671 if (p
&& r_o
.status
!= 0)
673 /* report error code */
674 DEBUG(0, ("REG_DELETE_VALUE: %s\n",
675 get_nt_error_msg(r_o
.status
)));
685 prs_free_data(&rbuf
);
686 prs_free_data(&buf
);
691 /****************************************************************************
693 ****************************************************************************/
694 BOOL
reg_delete_key(POLICY_HND
*hnd
, char *key_name
)
698 REG_Q_DELETE_KEY q_o
;
699 BOOL valid_delete
= False
;
701 if (hnd
== NULL
) return False
;
703 prs_init(&buf
, 0, 4, False
);
704 prs_init(&rbuf
, 0, 4, True
);
706 /* create and send a MSRPC command with api REG_DELETE_KEY */
708 DEBUG(4,("REG Delete Key: %s\n", key_name
));
710 make_reg_q_delete_key(&q_o
, hnd
, key_name
);
712 /* turn parameters into data stream */
713 if (reg_io_q_delete_key("", &q_o
, &buf
, 0) &&
714 rpc_hnd_pipe_req(hnd
, REG_DELETE_KEY
, &buf
, &rbuf
))
716 REG_R_DELETE_KEY r_o
;
721 reg_io_r_delete_key("", &r_o
, &rbuf
, 0);
722 p
= rbuf
.offset
!= 0;
724 if (p
&& r_o
.status
!= 0)
726 /* report error code */
727 DEBUG(0, ("REG_DELETE_KEY: %s\n",
728 get_nt_error_msg(r_o
.status
)));
738 prs_free_data(&rbuf
);
739 prs_free_data(&buf
);
744 /****************************************************************************
746 ****************************************************************************/
747 BOOL
reg_create_key(POLICY_HND
*hnd
,
748 char *key_name
, char *key_class
,
749 SEC_ACCESS
*sam_access
,
754 REG_Q_CREATE_KEY q_o
;
755 BOOL valid_create
= False
;
757 SEC_DESC_BUF sec_buf
;
761 ZERO_STRUCT(sec_buf
);
764 if (hnd
== NULL
) return False
;
766 prs_init(&buf
, 0, 4, False
);
767 prs_init(&rbuf
, 0, 4, True
);
769 /* create and send a MSRPC command with api REG_CREATE_KEY */
771 DEBUG(4,("REG Create Key: %s %s 0x%08x\n", key_name
, key_class
,
772 sam_access
!= NULL
? sam_access
->mask
: 0));
774 sec_len
= make_sec_desc(&sec
, 1, SEC_DESC_SELF_RELATIVE
,
775 NULL
, NULL
, NULL
, NULL
);
777 DEBUG(10,("make_sec_desc: len = %d\n", sec_len
));
779 make_reg_q_create_key(&q_o
, hnd
, key_name
, key_class
, sam_access
,
780 &sec_buf
, sec_len
, &sec
);
782 /* turn parameters into data stream */
783 if (reg_io_q_create_key("", &q_o
, &buf
, 0) &&
784 rpc_hnd_pipe_req(hnd
, REG_CREATE_KEY
, &buf
, &rbuf
))
786 REG_R_CREATE_KEY r_o
;
791 reg_io_r_create_key("", &r_o
, &rbuf
, 0);
792 p
= rbuf
.offset
!= 0;
794 if (p
&& r_o
.status
!= 0)
796 /* report error code */
797 DEBUG(0, ("REG_CREATE_KEY: %s\n",
798 get_nt_error_msg(r_o
.status
)));
811 prs_free_data(&rbuf
);
812 prs_free_data(&buf
);
817 /****************************************************************************
819 ****************************************************************************/
820 BOOL
reg_enum_key(POLICY_HND
*hnd
,
821 int key_index
, char *key_name
,
822 uint32
*unk_1
, uint32
*unk_2
,
828 BOOL valid_query
= False
;
830 if (hnd
== NULL
) return False
;
832 prs_init(&buf
, 0, 4, False
);
833 prs_init(&rbuf
, 0, 4, True
);
835 /* create and send a MSRPC command with api REG_ENUM_KEY */
837 DEBUG(4,("REG Enum Key\n"));
839 make_reg_q_enum_key(&q_o
, hnd
, key_index
);
841 /* turn parameters into data stream */
842 if (reg_io_q_enum_key("", &q_o
, &buf
, 0) &&
843 rpc_hnd_pipe_req(hnd
, REG_ENUM_KEY
, &buf
, &rbuf
))
850 reg_io_r_enum_key("", &r_o
, &rbuf
, 0);
851 p
= rbuf
.offset
!= 0;
853 if (p
&& r_o
.status
!= 0)
855 /* report error code */
856 DEBUG(0, ("REG_ENUM_KEY: %s\n",
857 get_nt_error_msg(r_o
.status
)));
864 (*unk_1
) = r_o
.unknown_1
;
865 (*unk_2
) = r_o
.unknown_2
;
866 unistr_to_ascii(key_name
, r_o
.key_name
.str
.buffer
,
868 (*mod_time
) = nt_time_to_unix(&r_o
.time
);
872 prs_free_data(&rbuf
);
873 prs_free_data(&buf
);
878 /****************************************************************************
879 do a REG Create Value
880 ****************************************************************************/
881 BOOL
reg_create_val(POLICY_HND
*hnd
,
882 char *val_name
, uint32 type
, BUFFER3
*data
)
886 REG_Q_CREATE_VALUE q_o
;
887 BOOL valid_create
= False
;
889 if (hnd
== NULL
) return False
;
891 prs_init(&buf
, 0, 4, False
);
892 prs_init(&rbuf
, 0, 4, True
);
894 /* create and send a MSRPC command with api REG_CREATE_VALUE */
896 DEBUG(4,("REG Create Value: %s\n", val_name
));
898 make_reg_q_create_val(&q_o
, hnd
, val_name
, type
, data
);
900 /* turn parameters into data stream */
901 if (reg_io_q_create_val("", &q_o
, &buf
, 0) &&
902 rpc_hnd_pipe_req(hnd
, REG_CREATE_VALUE
, &buf
, &rbuf
))
904 REG_R_CREATE_VALUE r_o
;
909 reg_io_r_create_val("", &r_o
, &rbuf
, 0);
910 p
= rbuf
.offset
!= 0;
912 if (p
&& r_o
.status
!= 0)
914 /* report error code */
915 DEBUG(0, ("REG_CREATE_VALUE: %s\n",
916 get_nt_error_msg(r_o
.status
)));
926 prs_free_data(&rbuf
);
927 prs_free_data(&buf
);
932 /****************************************************************************
934 ****************************************************************************/
935 BOOL
reg_enum_val(POLICY_HND
*hnd
,
936 int val_index
, int max_valnamelen
, int max_valbufsize
,
938 uint32
*val_type
, BUFFER2
*value
)
942 REG_Q_ENUM_VALUE q_o
;
943 BOOL valid_query
= False
;
945 if (hnd
== NULL
) return False
;
947 prs_init(&buf
, 0, 4, False
);
948 prs_init(&rbuf
, 0, 4, True
);
950 /* create and send a MSRPC command with api REG_ENUM_VALUE */
952 DEBUG(4,("REG Enum Value\n"));
954 make_reg_q_enum_val(&q_o
, hnd
, val_index
, max_valnamelen
, max_valbufsize
);
956 /* turn parameters into data stream */
957 if (reg_io_q_enum_val("", &q_o
, &buf
, 0) &&
958 rpc_hnd_pipe_req(hnd
, REG_ENUM_VALUE
, &buf
, &rbuf
))
960 REG_R_ENUM_VALUE r_o
;
964 r_o
.buf_value
= value
;
966 reg_io_r_enum_val("", &r_o
, &rbuf
, 0);
967 p
= rbuf
.offset
!= 0;
969 if (p
&& r_o
.status
!= 0)
971 /* report error code */
972 DEBUG(0, ("REG_ENUM_VALUE: %s\n",
973 get_nt_error_msg(r_o
.status
)));
980 (*val_type
) = r_o
.type
;
981 unistr2_to_ascii(val_name
, &r_o
.uni_name
, sizeof(fstring
)-1);
985 prs_free_data(&rbuf
);
986 prs_free_data(&buf
);
991 /****************************************************************************
993 ****************************************************************************/
994 BOOL
reg_open_entry(POLICY_HND
*hnd
,
995 char *key_name
, uint32 unk_0
,
1000 REG_Q_OPEN_ENTRY q_o
;
1001 BOOL valid_pol
= False
;
1003 if (hnd
== NULL
) return False
;
1005 prs_init(&buf
, 0, 4, False
);
1006 prs_init(&rbuf
, 0, 4, True
);
1008 /* create and send a MSRPC command with api REG_OPEN_ENTRY */
1010 DEBUG(4,("REG Open Entry\n"));
1012 make_reg_q_open_entry(&q_o
, hnd
, key_name
, unk_0
);
1014 /* turn parameters into data stream */
1015 if (reg_io_q_open_entry("", &q_o
, &buf
, 0) &&
1016 rpc_hnd_pipe_req(hnd
, REG_OPEN_ENTRY
, &buf
, &rbuf
))
1018 REG_R_OPEN_ENTRY r_o
;
1023 reg_io_r_open_entry("", &r_o
, &rbuf
, 0);
1024 p
= rbuf
.offset
!= 0;
1026 if (p
&& r_o
.status
!= 0)
1028 /* report error code */
1029 DEBUG(0, ("REG_OPEN_ENTRY: %s\n",
1030 get_nt_error_msg(r_o
.status
)));
1036 struct cli_connection
*con
= NULL
;
1038 if (!cli_connection_get(hnd
, &con
))
1044 valid_pol
= cli_pol_link(key_hnd
, hnd
);
1048 prs_free_data(&rbuf
);
1049 prs_free_data(&buf
);
1054 /****************************************************************************
1056 ****************************************************************************/
1057 BOOL
reg_close(POLICY_HND
*hnd
)
1062 BOOL valid_close
= False
;
1064 if (hnd
== NULL
) return False
;
1066 /* create and send a MSRPC command with api REG_CLOSE */
1068 prs_init(&buf
, 0, 4, False
);
1069 prs_init(&rbuf
, 0, 4, True
);
1071 DEBUG(4,("REG Close\n"));
1073 /* store the parameters */
1074 make_reg_q_close(&q_c
, hnd
);
1076 /* turn parameters into data stream */
1077 if (reg_io_q_close("", &q_c
, &buf
, 0) &&
1078 rpc_hnd_pipe_req(hnd
, REG_CLOSE
, &buf
, &rbuf
))
1085 reg_io_r_close("", &r_c
, &rbuf
, 0);
1086 p
= rbuf
.offset
!= 0;
1088 if (p
&& r_c
.status
!= 0)
1090 /* report error code */
1091 DEBUG(0, ("REG_CLOSE: %s\n",
1092 get_nt_error_msg(r_c
.status
)));
1102 prs_free_data(&rbuf
);
1103 prs_free_data(&buf
);
1105 close_policy_hnd(get_global_hnd_cache(), hnd
);
1110 /****************************************************************************
1111 do a REG Shutdown Server
1112 ****************************************************************************/
1113 BOOL
reg_shutdown(const char *srv_name
,
1114 const char *msg
, uint32 timeout
, uint16 flags
)
1119 BOOL valid_shutdown
= False
;
1121 struct cli_connection
*con
= NULL
;
1123 if (!cli_connection_init(srv_name
, PIPE_WINREG
, &con
))
1128 if (msg
== NULL
) return False
;
1130 prs_init(&buf
, 0, 4, False
);
1131 prs_init(&rbuf
, 0, 4, True
);
1133 /* create and send a MSRPC command with api REG_SHUTDOWN */
1135 DEBUG(4,("REG Shutdown: (timeout: %d secs) %s\n", timeout
, msg
));
1137 make_reg_q_shutdown(&q_o
, msg
, timeout
, flags
);
1139 /* turn parameters into data stream */
1140 if (reg_io_q_shutdown("", &q_o
, &buf
, 0) &&
1141 rpc_con_pipe_req(con
, REG_SHUTDOWN
, &buf
, &rbuf
))
1148 reg_io_r_shutdown("", &r_o
, &rbuf
, 0);
1149 p
= rbuf
.offset
!= 0;
1151 if (p
&& r_o
.status
!= 0)
1153 /* report error code */
1154 DEBUG(0, ("REG_SHUTDOWN: %s\n",
1155 get_nt_error_msg(r_o
.status
)));
1161 valid_shutdown
= True
;
1165 prs_free_data(&rbuf
);
1166 prs_free_data(&buf
);
1168 cli_connection_unlink(con
);
1170 return valid_shutdown
;
1174 /****************************************************************************
1175 do a REG Abort Shutdown
1176 ****************************************************************************/
1177 BOOL
reg_abort_shutdown(const char *srv_name
)
1181 REG_Q_ABORT_SHUTDOWN q_o
;
1182 BOOL valid_abort
= False
;
1184 struct cli_connection
*con
= NULL
;
1186 if (!cli_connection_init(srv_name
, PIPE_WINREG
, &con
))
1191 prs_init(&buf
, 0, 4, False
);
1192 prs_init(&rbuf
, 0, 4, True
);
1194 /* create and send a MSRPC command with api REG_ABORT_SHUTDOWN */
1196 DEBUG(4,("REG Abort Shutdown\n"));
1198 make_reg_q_abort_shutdown(&q_o
);
1200 /* turn parameters into data stream */
1201 if (reg_io_q_abort_shutdown("", &q_o
, &buf
, 0) &&
1202 rpc_con_pipe_req(con
, REG_ABORT_SHUTDOWN
, &buf
, &rbuf
))
1204 REG_R_ABORT_SHUTDOWN r_o
;
1209 reg_io_r_abort_shutdown("", &r_o
, &rbuf
, 0);
1210 p
= rbuf
.offset
!= 0;
1212 if (p
&& r_o
.status
!= 0)
1214 /* report error code */
1215 DEBUG(0, ("REG_ABORT_SHUTDOWN: %s\n",
1216 get_nt_error_msg(r_o
.status
)));
1226 prs_free_data(&rbuf
);
1227 prs_free_data(&buf
);
1229 cli_connection_unlink(con
);