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 do_reg_connect(struct cli_state *cli, uint16 fnum, char *full_keyname, char *key_name,
43 if (full_keyname == NULL)
48 ZERO_STRUCTP(reg_hnd);
51 * open registry receive a policy handle
54 if (!reg_split_key(full_keyname, ®_type, key_name))
56 DEBUG(0,("do_reg_connect: unrecognised key name %s\n", full_keyname));
62 case HKEY_CLASSES_ROOT:
64 res = res ? do_reg_open_hkcr(cli, fnum,
70 case HKEY_LOCAL_MACHINE:
72 res = res ? do_reg_open_hklm(cli, fnum,
80 res = res ? do_reg_open_hku(cli, fnum,
87 DEBUG(0,("do_reg_connect: unrecognised hive key\n"));
95 /****************************************************************************
97 ****************************************************************************/
98 BOOL do_reg_open_hkcr(struct cli_state *cli, uint16 fnum, uint16 unknown_0, uint32 level,
104 BOOL valid_pol = False;
106 if (hnd == NULL) return False;
108 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
109 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
111 /* create and send a MSRPC command with api REG_OPEN_HKCR */
113 DEBUG(4,("REG Open HKCR\n"));
115 make_reg_q_open_hkcr(&q_o, unknown_0, level);
117 /* turn parameters into data stream */
118 reg_io_q_open_hkcr("", &q_o, &buf, 0);
120 /* send the data on \PIPE\ */
121 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_HKCR, &buf, &rbuf))
128 reg_io_r_open_hkcr("", &r_o, &rbuf, 0);
129 p = rbuf.offset != 0;
131 if (p && r_o.status != 0)
133 /* report error code */
134 DEBUG(0,("REG_OPEN_HKCR: %s\n", get_nt_error_msg(r_o.status)));
140 /* ok, at last: we're happy. return the policy handle */
141 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
152 /****************************************************************************
154 ****************************************************************************/
155 BOOL do_reg_open_hklm(struct cli_state *cli, uint16 fnum, uint16 unknown_0, uint32 level,
161 BOOL valid_pol = False;
163 if (hnd == NULL) return False;
165 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
166 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
168 /* create and send a MSRPC command with api REG_OPEN_HKLM */
170 DEBUG(4,("REG Open HKLM\n"));
172 make_reg_q_open_hklm(&q_o, unknown_0, level);
174 /* turn parameters into data stream */
175 reg_io_q_open_hklm("", &q_o, &buf, 0);
177 /* send the data on \PIPE\ */
178 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_HKLM, &buf, &rbuf))
185 reg_io_r_open_hklm("", &r_o, &rbuf, 0);
186 p = rbuf.offset != 0;
188 if (p && r_o.status != 0)
190 /* report error code */
191 DEBUG(0,("REG_OPEN_HKLM: %s\n", get_nt_error_msg(r_o.status)));
197 /* ok, at last: we're happy. return the policy handle */
198 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
209 /****************************************************************************
211 ****************************************************************************/
212 BOOL do_reg_open_hku(struct cli_state *cli, uint16 fnum, uint16 unknown_0, uint32 level,
218 BOOL valid_pol = False;
220 if (hnd == NULL) return False;
222 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
223 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
225 /* create and send a MSRPC command with api REG_OPEN_HKU */
227 DEBUG(4,("REG Open HKU\n"));
229 make_reg_q_open_hku(&q_o, unknown_0, level);
231 /* turn parameters into data stream */
232 reg_io_q_open_hku("", &q_o, &buf, 0);
234 /* send the data on \PIPE\ */
235 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_HKU, &buf, &rbuf))
242 reg_io_r_open_hku("", &r_o, &rbuf, 0);
243 p = rbuf.offset != 0;
245 if (p && r_o.status != 0)
247 /* report error code */
248 DEBUG(0,("REG_OPEN_HKU: %s\n", get_nt_error_msg(r_o.status)));
254 /* ok, at last: we're happy. return the policy handle */
255 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
266 /****************************************************************************
267 do a REG Unknown 0xB command. sent after a create key or create value.
268 this might be some sort of "sync" or "refresh" command, sent after
269 modification of the registry...
270 ****************************************************************************/
271 BOOL do_reg_flush_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
276 BOOL valid_query = False;
278 if (hnd == NULL) return False;
280 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
281 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
283 /* create and send a MSRPC command with api REG_FLUSH_KEY */
285 DEBUG(4,("REG Unknown 0xB\n"));
287 make_reg_q_flush_key(&q_o, hnd);
289 /* turn parameters into data stream */
290 reg_io_q_flush_key("", &q_o, &buf, 0);
292 /* send the data on \PIPE\ */
293 if (rpc_api_pipe_req(cli, fnum, REG_FLUSH_KEY, &buf, &rbuf))
300 reg_io_r_flush_key("", &r_o, &rbuf, 0);
301 p = rbuf.offset != 0;
303 if (p && r_o.status != 0)
305 /* report error code */
306 DEBUG(0,("REG_FLUSH_KEY: %s\n", get_nt_error_msg(r_o.status)));
322 /****************************************************************************
324 ****************************************************************************/
325 BOOL do_reg_query_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
326 char *key_class, uint32 *class_len,
327 uint32 *num_subkeys, uint32 *max_subkeylen,
328 uint32 *max_subkeysize, uint32 *num_values,
329 uint32 *max_valnamelen, uint32 *max_valbufsize,
330 uint32 *sec_desc, NTTIME *mod_time)
335 BOOL valid_query = False;
337 if (hnd == NULL) return False;
339 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
340 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
342 /* create and send a MSRPC command with api REG_QUERY_KEY */
344 DEBUG(4,("REG Query Key\n"));
346 make_reg_q_query_key(&q_o, hnd, *class_len);
348 /* turn parameters into data stream */
349 reg_io_q_query_key("", &q_o, &buf, 0);
351 /* send the data on \PIPE\ */
352 if (rpc_api_pipe_req(cli, fnum, REG_QUERY_KEY, &buf, &rbuf))
359 reg_io_r_query_key("", &r_o, &rbuf, 0);
360 p = rbuf.offset != 0;
362 if (p && r_o.status != 0)
364 /* report error code */
365 DEBUG(0,("REG_QUERY_KEY: %s\n", get_nt_error_msg(r_o.status)));
373 *class_len = r_o.hdr_class.uni_max_len;
374 unistr2_to_ascii(key_class, &r_o.uni_class, sizeof(fstring)-1);
375 *num_subkeys = r_o.num_subkeys ;
376 *max_subkeylen = r_o.max_subkeylen ;
377 *max_subkeysize = r_o.max_subkeysize;
378 *num_values = r_o.num_values ;
379 *max_valnamelen = r_o.max_valnamelen;
380 *max_valbufsize = r_o.max_valbufsize;
381 *sec_desc = r_o.sec_desc ;
382 *mod_time = r_o.mod_time ;
392 /****************************************************************************
394 ****************************************************************************/
395 BOOL do_reg_unknown_1a(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, uint32 *unk)
400 BOOL valid_query = False;
402 if (hnd == NULL) return False;
404 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
405 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
407 /* create and send a MSRPC command with api REG_UNKNOWN_1A */
409 DEBUG(4,("REG Unknown 1a\n"));
411 make_reg_q_unk_1a(&q_o, hnd);
413 /* turn parameters into data stream */
414 reg_io_q_unk_1a("", &q_o, &buf, 0);
416 /* send the data on \PIPE\ */
417 if (rpc_api_pipe_req(cli, fnum, REG_UNK_1A, &buf, &rbuf))
424 reg_io_r_unk_1a("", &r_o, &rbuf, 0);
425 p = rbuf.offset != 0;
427 if (p && r_o.status != 0)
429 /* report error code */
430 DEBUG(0,("REG_UNK_1A: %s\n", get_nt_error_msg(r_o.status)));
437 (*unk) = r_o.unknown;
447 /****************************************************************************
449 ****************************************************************************/
450 BOOL do_reg_query_info(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
451 char *type, uint32 *unk_0, uint32 *unk_1)
456 BOOL valid_query = False;
458 if (hnd == NULL) return False;
460 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
461 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
463 /* create and send a MSRPC command with api REG_INFO */
465 DEBUG(4,("REG Query Info\n"));
467 make_reg_q_info(&q_o, hnd, "ProductType", time(NULL), 4, 1);
469 /* turn parameters into data stream */
470 reg_io_q_info("", &q_o, &buf, 0);
472 /* send the data on \PIPE\ */
473 if (rpc_api_pipe_req(cli, fnum, REG_INFO, &buf, &rbuf))
480 reg_io_r_info("", &r_o, &rbuf, 0);
481 p = rbuf.offset != 0;
483 if (p && r_o.status != 0)
485 /* report error code */
486 DEBUG(0,("REG_INFO: %s\n", get_nt_error_msg(r_o.status)));
493 unibuf_to_ascii(type, (const char*)r_o.uni_type.buffer,
494 MIN(r_o.uni_type.buf_len, sizeof(fstring)-1));
495 (*unk_0) = r_o.unknown_0;
496 (*unk_1) = r_o.unknown_1;
506 /****************************************************************************
507 do a REG Set Key Security
508 ****************************************************************************/
509 BOOL do_reg_set_key_sec(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
510 uint32 sec_buf_size, SEC_DESC *sec_buf)
514 REG_Q_SET_KEY_SEC q_o;
515 BOOL valid_query = False;
517 if (hnd == NULL) return False;
519 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
520 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
522 /* create and send a MSRPC command with api REG_SET_KEY_SEC */
524 DEBUG(4,("REG Set Key security.\n"));
526 make_reg_q_set_key_sec(&q_o, hnd, sec_buf_size, sec_buf);
528 /* turn parameters into data stream */
529 reg_io_q_set_key_sec("", &q_o, &buf, 0);
531 /* send the data on \PIPE\ */
532 if (rpc_api_pipe_req(cli, fnum, REG_SET_KEY_SEC, &buf, &rbuf))
534 REG_R_SET_KEY_SEC r_o;
539 reg_io_r_set_key_sec("", &r_o, &rbuf, 0);
540 p = rbuf.offset != 0;
542 if (p && r_o.status != 0)
555 /****************************************************************************
556 do a REG Query Key Security
557 ****************************************************************************/
558 BOOL do_reg_get_key_sec(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
559 uint32 *sec_buf_size, SEC_DESC_BUF *sec_buf)
563 REG_Q_GET_KEY_SEC q_o;
564 BOOL valid_query = False;
566 if (hnd == NULL) return False;
568 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
569 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
571 /* create and send a MSRPC command with api REG_GET_KEY_SEC */
573 DEBUG(4,("REG query key security. buf_size: %d\n", *sec_buf_size));
575 make_reg_q_get_key_sec(&q_o, hnd, *sec_buf_size, sec_buf);
577 /* turn parameters into data stream */
578 reg_io_q_get_key_sec("", &q_o, &buf, 0);
580 /* send the data on \PIPE\ */
581 if (rpc_api_pipe_req(cli, fnum, REG_GET_KEY_SEC, &buf, &rbuf))
583 REG_R_GET_KEY_SEC r_o;
589 if (*sec_buf_size != 0)
591 sec_buf->sec = (SEC_DESC*)malloc(*sec_buf_size);
593 reg_io_r_get_key_sec("", &r_o, &rbuf, 0);
594 p = rbuf.offset != 0;
596 if (p && r_o.status == 0x0000007a)
599 * get the maximum buffer size: it was too small
601 (*sec_buf_size) = r_o.hdr_sec.buf_max_len;
602 DEBUG(5,("sec_buf_size too small. use %d\n", *sec_buf_size));
605 else if (p && r_o.status != 0)
607 /* report error code */
608 DEBUG(0,("REG_GET_KEY_SEC: %s\n", get_nt_error_msg(r_o.status)));
614 (*sec_buf_size) = r_o.data->len;
624 /****************************************************************************
625 do a REG Delete Value
626 ****************************************************************************/
627 BOOL do_reg_delete_val(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, char *val_name)
631 REG_Q_DELETE_VALUE q_o;
632 BOOL valid_delete = False;
634 if (hnd == NULL) return False;
636 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
637 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
639 /* create and send a MSRPC command with api REG_DELETE_VALUE */
641 DEBUG(4,("REG Delete Value: %s\n", val_name));
643 make_reg_q_delete_val(&q_o, hnd, val_name);
645 /* turn parameters into data stream */
646 reg_io_q_delete_val("", &q_o, &buf, 0);
648 /* send the data on \PIPE\ */
649 if (rpc_api_pipe_req(cli, fnum, REG_DELETE_VALUE, &buf, &rbuf))
651 REG_R_DELETE_VALUE r_o;
656 reg_io_r_delete_val("", &r_o, &rbuf, 0);
657 p = rbuf.offset != 0;
659 if (p && r_o.status != 0)
661 /* report error code */
662 DEBUG(0,("REG_DELETE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
678 /****************************************************************************
680 ****************************************************************************/
681 BOOL do_reg_delete_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, char *key_name)
685 REG_Q_DELETE_KEY q_o;
686 BOOL valid_delete = False;
688 if (hnd == NULL) return False;
690 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
691 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
693 /* create and send a MSRPC command with api REG_DELETE_KEY */
695 DEBUG(4,("REG Delete Key: %s\n", key_name));
697 make_reg_q_delete_key(&q_o, hnd, key_name);
699 /* turn parameters into data stream */
700 reg_io_q_delete_key("", &q_o, &buf, 0);
702 /* send the data on \PIPE\ */
703 if (rpc_api_pipe_req(cli, fnum, REG_DELETE_KEY, &buf, &rbuf))
705 REG_R_DELETE_KEY r_o;
710 reg_io_r_delete_key("", &r_o, &rbuf, 0);
711 p = rbuf.offset != 0;
713 if (p && r_o.status != 0)
715 /* report error code */
716 DEBUG(0,("REG_DELETE_KEY: %s\n", get_nt_error_msg(r_o.status)));
732 /****************************************************************************
734 ****************************************************************************/
735 BOOL do_reg_create_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
736 char *key_name, char *key_class,
737 SEC_ACCESS *sam_access,
742 REG_Q_CREATE_KEY q_o;
743 BOOL valid_create = False;
745 SEC_DESC_BUF sec_buf;
749 ZERO_STRUCT(sec_buf);
752 if (hnd == NULL) return False;
754 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
755 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
757 /* create and send a MSRPC command with api REG_CREATE_KEY */
759 DEBUG(4,("REG Create Key: %s %s 0x%08x\n", key_name, key_class,
760 sam_access != NULL ? sam_access->mask : 0));
762 sec_len = make_sec_desc(&sec, 1, SEC_DESC_SELF_RELATIVE,
763 NULL, NULL, NULL, NULL);
765 DEBUG(10,("make_sec_desc: len = %d\n", sec_len));
767 make_reg_q_create_key(&q_o, hnd, key_name, key_class, sam_access,
768 &sec_buf, sec_len, &sec);
770 /* turn parameters into data stream */
771 reg_io_q_create_key("", &q_o, &buf, 0);
773 /* send the data on \PIPE\ */
774 if (rpc_api_pipe_req(cli, fnum, REG_CREATE_KEY, &buf, &rbuf))
776 REG_R_CREATE_KEY r_o;
781 reg_io_r_create_key("", &r_o, &rbuf, 0);
782 p = rbuf.offset != 0;
784 if (p && r_o.status != 0)
786 /* report error code */
787 DEBUG(0,("REG_CREATE_KEY: %s\n", get_nt_error_msg(r_o.status)));
794 memcpy(key, r_o.key_pol.data, sizeof(key->data));
806 /****************************************************************************
808 ****************************************************************************/
809 BOOL do_reg_enum_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
810 int key_index, char *key_name,
811 uint32 *unk_1, uint32 *unk_2,
817 BOOL valid_query = False;
819 if (hnd == NULL) return False;
821 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
822 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
824 /* create and send a MSRPC command with api REG_ENUM_KEY */
826 DEBUG(4,("REG Enum Key\n"));
828 make_reg_q_enum_key(&q_o, hnd, key_index);
830 /* turn parameters into data stream */
831 reg_io_q_enum_key("", &q_o, &buf, 0);
833 /* send the data on \PIPE\ */
834 if (rpc_api_pipe_req(cli, fnum, REG_ENUM_KEY, &buf, &rbuf))
841 reg_io_r_enum_key("", &r_o, &rbuf, 0);
842 p = rbuf.offset != 0;
844 if (p && r_o.status != 0)
846 /* report error code */
847 DEBUG(0,("REG_ENUM_KEY: %s\n", get_nt_error_msg(r_o.status)));
854 (*unk_1) = r_o.unknown_1;
855 (*unk_2) = r_o.unknown_2;
856 unistr_to_ascii(key_name, r_o.key_name.str.buffer,
858 (*mod_time) = nt_time_to_unix(&r_o.time);
868 /****************************************************************************
869 do a REG Create Value
870 ****************************************************************************/
871 BOOL do_reg_create_val(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
872 char *val_name, uint32 type, BUFFER3 *data)
876 REG_Q_CREATE_VALUE q_o;
877 BOOL valid_create = False;
879 if (hnd == NULL) return False;
881 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
882 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
884 /* create and send a MSRPC command with api REG_CREATE_VALUE */
886 DEBUG(4,("REG Create Value: %s\n", val_name));
888 make_reg_q_create_val(&q_o, hnd, val_name, type, data);
890 /* turn parameters into data stream */
891 reg_io_q_create_val("", &q_o, &buf, 0);
893 /* send the data on \PIPE\ */
894 if (rpc_api_pipe_req(cli, fnum, REG_CREATE_VALUE, &buf, &rbuf))
896 REG_R_CREATE_VALUE r_o;
901 reg_io_r_create_val("", &r_o, &rbuf, 0);
902 p = rbuf.offset != 0;
904 if (p && r_o.status != 0)
906 /* report error code */
907 DEBUG(0,("REG_CREATE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
923 /****************************************************************************
925 ****************************************************************************/
926 BOOL do_reg_enum_val(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
927 int val_index, int max_valnamelen, int max_valbufsize,
929 uint32 *val_type, BUFFER2 *value)
933 REG_Q_ENUM_VALUE q_o;
934 BOOL valid_query = False;
936 if (hnd == NULL) return False;
938 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
939 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
941 /* create and send a MSRPC command with api REG_ENUM_VALUE */
943 DEBUG(4,("REG Enum Value\n"));
945 make_reg_q_enum_val(&q_o, hnd, val_index, max_valnamelen, max_valbufsize);
947 /* turn parameters into data stream */
948 reg_io_q_enum_val("", &q_o, &buf, 0);
950 /* send the data on \PIPE\ */
951 if (rpc_api_pipe_req(cli, fnum, REG_ENUM_VALUE, &buf, &rbuf))
953 REG_R_ENUM_VALUE r_o;
957 r_o.buf_value = value;
959 reg_io_r_enum_val("", &r_o, &rbuf, 0);
960 p = rbuf.offset != 0;
962 if (p && r_o.status != 0)
964 /* report error code */
965 DEBUG(0,("REG_ENUM_VALUE: %s\n", get_nt_error_msg(r_o.status)));
972 (*val_type) = r_o.type;
973 unistr2_to_ascii(val_name, &r_o.uni_name, sizeof(fstring)-1);
983 /****************************************************************************
985 ****************************************************************************/
986 BOOL do_reg_open_entry(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
987 char *key_name, uint32 unk_0,
992 REG_Q_OPEN_ENTRY q_o;
993 BOOL valid_pol = False;
995 if (hnd == NULL) return False;
997 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
998 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1000 /* create and send a MSRPC command with api REG_OPEN_ENTRY */
1002 DEBUG(4,("REG Open Entry\n"));
1004 make_reg_q_open_entry(&q_o, hnd, key_name, unk_0);
1006 /* turn parameters into data stream */
1007 reg_io_q_open_entry("", &q_o, &buf, 0);
1009 /* send the data on \PIPE\ */
1010 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_ENTRY, &buf, &rbuf))
1012 REG_R_OPEN_ENTRY r_o;
1017 reg_io_r_open_entry("", &r_o, &rbuf, 0);
1018 p = rbuf.offset != 0;
1020 if (p && r_o.status != 0)
1022 /* report error code */
1023 DEBUG(0,("REG_OPEN_ENTRY: %s\n", get_nt_error_msg(r_o.status)));
1030 memcpy(key_hnd, r_o.pol.data, sizeof(key_hnd->data));
1034 prs_mem_free(&rbuf);
1035 prs_mem_free(&buf );
1040 /****************************************************************************
1042 ****************************************************************************/
1043 BOOL do_reg_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
1048 BOOL valid_close = False;
1050 if (hnd == NULL) return False;
1052 /* create and send a MSRPC command with api REG_CLOSE */
1054 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1055 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1057 DEBUG(4,("REG Close\n"));
1059 /* store the parameters */
1060 make_reg_q_close(&q_c, hnd);
1062 /* turn parameters into data stream */
1063 reg_io_q_close("", &q_c, &buf, 0);
1065 /* send the data on \PIPE\ */
1066 if (rpc_api_pipe_req(cli, fnum, REG_CLOSE, &buf, &rbuf))
1073 reg_io_r_close("", &r_c, &rbuf, 0);
1074 p = rbuf.offset != 0;
1076 if (p && r_c.status != 0)
1078 /* report error code */
1079 DEBUG(0,("REG_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
1085 /* check that the returned policy handle is all zeros */
1089 for (i = 0; i < sizeof(r_c.pol.data); i++)
1091 if (r_c.pol.data[i] != 0)
1093 valid_close = False;
1099 DEBUG(0,("REG_CLOSE: non-zero handle returned\n"));
1104 prs_mem_free(&rbuf);
1105 prs_mem_free(&buf );
1110 /****************************************************************************
1111 do a REG Shutdown Server
1112 ****************************************************************************/
1113 BOOL do_reg_shutdown(struct cli_state *cli, uint16 fnum,
1114 char *msg, uint32 timeout, uint16 flags)
1119 BOOL valid_shutdown = False;
1121 if (msg == NULL) return False;
1123 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1124 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1126 /* create and send a MSRPC command with api REG_SHUTDOWN */
1128 DEBUG(4,("REG Shutdown: (timeout: %d secs) %s\n", timeout, msg));
1130 make_reg_q_shutdown(&q_o, msg, timeout, flags);
1132 /* turn parameters into data stream */
1133 reg_io_q_shutdown("", &q_o, &buf, 0);
1135 /* send the data on \PIPE\ */
1136 if (rpc_api_pipe_req(cli, fnum, REG_SHUTDOWN, &buf, &rbuf))
1143 reg_io_r_shutdown("", &r_o, &rbuf, 0);
1144 p = rbuf.offset != 0;
1146 if (p && r_o.status != 0)
1148 /* report error code */
1149 DEBUG(0,("REG_SHUTDOWN: %s\n", get_nt_error_msg(r_o.status)));
1155 valid_shutdown = True;
1159 prs_mem_free(&rbuf);
1160 prs_mem_free(&buf );
1162 return valid_shutdown;