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,
38 const char *full_keyname,
45 if (full_keyname == NULL)
50 ZERO_STRUCTP(reg_hnd);
53 * open registry receive a policy handle
56 if (!reg_split_key(full_keyname, ®_type, key_name))
58 DEBUG(0,("do_reg_connect: unrecognised key name %s\n", full_keyname));
64 case HKEY_CLASSES_ROOT:
66 res = res ? do_reg_open_hkcr(cli, fnum,
72 case HKEY_LOCAL_MACHINE:
74 res = res ? do_reg_open_hklm(cli, fnum,
82 res = res ? do_reg_open_hku(cli, fnum,
89 DEBUG(0,("do_reg_connect: unrecognised hive key\n"));
97 /****************************************************************************
99 ****************************************************************************/
100 BOOL do_reg_open_hkcr(struct cli_state *cli, uint16 fnum, uint16 unknown_0, uint32 level,
106 BOOL valid_pol = False;
108 if (hnd == NULL) return False;
110 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
111 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
113 /* create and send a MSRPC command with api REG_OPEN_HKCR */
115 DEBUG(4,("REG Open HKCR\n"));
117 make_reg_q_open_hkcr(&q_o, unknown_0, level);
119 /* turn parameters into data stream */
120 reg_io_q_open_hkcr("", &q_o, &buf, 0);
122 /* send the data on \PIPE\ */
123 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_HKCR, &buf, &rbuf))
130 reg_io_r_open_hkcr("", &r_o, &rbuf, 0);
131 p = rbuf.offset != 0;
133 if (p && r_o.status != 0)
135 /* report error code */
136 DEBUG(0,("REG_OPEN_HKCR: %s\n", get_nt_error_msg(r_o.status)));
142 /* ok, at last: we're happy. return the policy handle */
143 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
154 /****************************************************************************
156 ****************************************************************************/
157 BOOL do_reg_open_hklm(struct cli_state *cli, uint16 fnum, uint16 unknown_0, uint32 level,
163 BOOL valid_pol = False;
165 if (hnd == NULL) return False;
167 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
168 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
170 /* create and send a MSRPC command with api REG_OPEN_HKLM */
172 DEBUG(4,("REG Open HKLM\n"));
174 make_reg_q_open_hklm(&q_o, unknown_0, level);
176 /* turn parameters into data stream */
177 reg_io_q_open_hklm("", &q_o, &buf, 0);
179 /* send the data on \PIPE\ */
180 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_HKLM, &buf, &rbuf))
187 reg_io_r_open_hklm("", &r_o, &rbuf, 0);
188 p = rbuf.offset != 0;
190 if (p && r_o.status != 0)
192 /* report error code */
193 DEBUG(0,("REG_OPEN_HKLM: %s\n", get_nt_error_msg(r_o.status)));
199 /* ok, at last: we're happy. return the policy handle */
200 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
211 /****************************************************************************
213 ****************************************************************************/
214 BOOL do_reg_open_hku(struct cli_state *cli, uint16 fnum, uint16 unknown_0, uint32 level,
220 BOOL valid_pol = False;
222 if (hnd == NULL) return False;
224 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
225 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
227 /* create and send a MSRPC command with api REG_OPEN_HKU */
229 DEBUG(4,("REG Open HKU\n"));
231 make_reg_q_open_hku(&q_o, unknown_0, level);
233 /* turn parameters into data stream */
234 reg_io_q_open_hku("", &q_o, &buf, 0);
236 /* send the data on \PIPE\ */
237 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_HKU, &buf, &rbuf))
244 reg_io_r_open_hku("", &r_o, &rbuf, 0);
245 p = rbuf.offset != 0;
247 if (p && r_o.status != 0)
249 /* report error code */
250 DEBUG(0,("REG_OPEN_HKU: %s\n", get_nt_error_msg(r_o.status)));
256 /* ok, at last: we're happy. return the policy handle */
257 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
268 /****************************************************************************
269 do a REG Unknown 0xB command. sent after a create key or create value.
270 this might be some sort of "sync" or "refresh" command, sent after
271 modification of the registry...
272 ****************************************************************************/
273 BOOL do_reg_flush_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
278 BOOL valid_query = False;
280 if (hnd == NULL) return False;
282 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
283 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
285 /* create and send a MSRPC command with api REG_FLUSH_KEY */
287 DEBUG(4,("REG Unknown 0xB\n"));
289 make_reg_q_flush_key(&q_o, hnd);
291 /* turn parameters into data stream */
292 reg_io_q_flush_key("", &q_o, &buf, 0);
294 /* send the data on \PIPE\ */
295 if (rpc_api_pipe_req(cli, fnum, REG_FLUSH_KEY, &buf, &rbuf))
302 reg_io_r_flush_key("", &r_o, &rbuf, 0);
303 p = rbuf.offset != 0;
305 if (p && r_o.status != 0)
307 /* report error code */
308 DEBUG(0,("REG_FLUSH_KEY: %s\n", get_nt_error_msg(r_o.status)));
324 /****************************************************************************
326 ****************************************************************************/
327 BOOL do_reg_query_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
328 char *key_class, uint32 *class_len,
329 uint32 *num_subkeys, uint32 *max_subkeylen,
330 uint32 *max_subkeysize, uint32 *num_values,
331 uint32 *max_valnamelen, uint32 *max_valbufsize,
332 uint32 *sec_desc, NTTIME *mod_time)
337 BOOL valid_query = False;
339 if (hnd == NULL) return False;
341 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
342 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
344 /* create and send a MSRPC command with api REG_QUERY_KEY */
346 DEBUG(4,("REG Query Key\n"));
348 make_reg_q_query_key(&q_o, hnd, *class_len);
350 /* turn parameters into data stream */
351 reg_io_q_query_key("", &q_o, &buf, 0);
353 /* send the data on \PIPE\ */
354 if (rpc_api_pipe_req(cli, fnum, REG_QUERY_KEY, &buf, &rbuf))
361 reg_io_r_query_key("", &r_o, &rbuf, 0);
362 p = rbuf.offset != 0;
364 if (p && r_o.status != 0)
366 /* report error code */
367 DEBUG(0,("REG_QUERY_KEY: %s\n", get_nt_error_msg(r_o.status)));
375 *class_len = r_o.hdr_class.uni_max_len;
376 unistr2_to_ascii(key_class, &r_o.uni_class, sizeof(fstring)-1);
377 *num_subkeys = r_o.num_subkeys ;
378 *max_subkeylen = r_o.max_subkeylen ;
379 *max_subkeysize = r_o.max_subkeysize;
380 *num_values = r_o.num_values ;
381 *max_valnamelen = r_o.max_valnamelen;
382 *max_valbufsize = r_o.max_valbufsize;
383 *sec_desc = r_o.sec_desc ;
384 *mod_time = r_o.mod_time ;
394 /****************************************************************************
396 ****************************************************************************/
397 BOOL do_reg_unknown_1a(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, uint32 *unk)
402 BOOL valid_query = False;
404 if (hnd == NULL) return False;
406 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
407 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
409 /* create and send a MSRPC command with api REG_UNKNOWN_1A */
411 DEBUG(4,("REG Unknown 1a\n"));
413 make_reg_q_unk_1a(&q_o, hnd);
415 /* turn parameters into data stream */
416 reg_io_q_unk_1a("", &q_o, &buf, 0);
418 /* send the data on \PIPE\ */
419 if (rpc_api_pipe_req(cli, fnum, REG_UNK_1A, &buf, &rbuf))
426 reg_io_r_unk_1a("", &r_o, &rbuf, 0);
427 p = rbuf.offset != 0;
429 if (p && r_o.status != 0)
431 /* report error code */
432 DEBUG(0,("REG_UNK_1A: %s\n", get_nt_error_msg(r_o.status)));
439 (*unk) = r_o.unknown;
449 /****************************************************************************
451 ****************************************************************************/
452 BOOL do_reg_query_info(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
453 char *type, uint32 *unk_0, uint32 *unk_1)
458 BOOL valid_query = False;
460 if (hnd == NULL) return False;
462 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
463 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
465 /* create and send a MSRPC command with api REG_INFO */
467 DEBUG(4,("REG Query Info\n"));
469 make_reg_q_info(&q_o, hnd, "ProductType", time(NULL), 4, 1);
471 /* turn parameters into data stream */
472 reg_io_q_info("", &q_o, &buf, 0);
474 /* send the data on \PIPE\ */
475 if (rpc_api_pipe_req(cli, fnum, REG_INFO, &buf, &rbuf))
482 reg_io_r_info("", &r_o, &rbuf, 0);
483 p = rbuf.offset != 0;
485 if (p && r_o.status != 0)
487 /* report error code */
488 DEBUG(0,("REG_INFO: %s\n", get_nt_error_msg(r_o.status)));
495 unibuf_to_ascii(type, (const char*)r_o.uni_type.buffer,
496 MIN(r_o.uni_type.buf_len, sizeof(fstring)-1));
497 (*unk_0) = r_o.unknown_0;
498 (*unk_1) = r_o.unknown_1;
508 /****************************************************************************
509 do a REG Set Key Security
510 ****************************************************************************/
511 BOOL do_reg_set_key_sec(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
512 uint32 sec_buf_size, SEC_DESC *sec_buf)
516 REG_Q_SET_KEY_SEC q_o;
517 BOOL valid_query = False;
519 if (hnd == NULL) return False;
521 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
522 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
524 /* create and send a MSRPC command with api REG_SET_KEY_SEC */
526 DEBUG(4,("REG Set Key security.\n"));
528 make_reg_q_set_key_sec(&q_o, hnd, sec_buf_size, sec_buf);
530 /* turn parameters into data stream */
531 reg_io_q_set_key_sec("", &q_o, &buf, 0);
533 /* send the data on \PIPE\ */
534 if (rpc_api_pipe_req(cli, fnum, REG_SET_KEY_SEC, &buf, &rbuf))
536 REG_R_SET_KEY_SEC r_o;
541 reg_io_r_set_key_sec("", &r_o, &rbuf, 0);
542 p = rbuf.offset != 0;
544 if (p && r_o.status != 0)
557 /****************************************************************************
558 do a REG Query Key Security
559 ****************************************************************************/
560 BOOL do_reg_get_key_sec(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
561 uint32 *sec_buf_size, SEC_DESC_BUF *sec_buf)
565 REG_Q_GET_KEY_SEC q_o;
566 BOOL valid_query = False;
568 if (hnd == NULL) return False;
570 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
571 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
573 /* create and send a MSRPC command with api REG_GET_KEY_SEC */
575 DEBUG(4,("REG query key security. buf_size: %d\n", *sec_buf_size));
577 make_reg_q_get_key_sec(&q_o, hnd, *sec_buf_size, sec_buf);
579 /* turn parameters into data stream */
580 reg_io_q_get_key_sec("", &q_o, &buf, 0);
582 /* send the data on \PIPE\ */
583 if (rpc_api_pipe_req(cli, fnum, REG_GET_KEY_SEC, &buf, &rbuf))
585 REG_R_GET_KEY_SEC r_o;
591 if (*sec_buf_size != 0)
593 sec_buf->sec = (SEC_DESC*)malloc(*sec_buf_size);
595 reg_io_r_get_key_sec("", &r_o, &rbuf, 0);
596 p = rbuf.offset != 0;
598 if (p && r_o.status == 0x0000007a)
601 * get the maximum buffer size: it was too small
603 (*sec_buf_size) = r_o.hdr_sec.buf_max_len;
604 DEBUG(5,("sec_buf_size too small. use %d\n", *sec_buf_size));
607 else if (p && r_o.status != 0)
609 /* report error code */
610 DEBUG(0,("REG_GET_KEY_SEC: %s\n", get_nt_error_msg(r_o.status)));
616 (*sec_buf_size) = r_o.data->len;
626 /****************************************************************************
627 do a REG Delete Value
628 ****************************************************************************/
629 BOOL do_reg_delete_val(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, char *val_name)
633 REG_Q_DELETE_VALUE q_o;
634 BOOL valid_delete = False;
636 if (hnd == NULL) return False;
638 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
639 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
641 /* create and send a MSRPC command with api REG_DELETE_VALUE */
643 DEBUG(4,("REG Delete Value: %s\n", val_name));
645 make_reg_q_delete_val(&q_o, hnd, val_name);
647 /* turn parameters into data stream */
648 reg_io_q_delete_val("", &q_o, &buf, 0);
650 /* send the data on \PIPE\ */
651 if (rpc_api_pipe_req(cli, fnum, REG_DELETE_VALUE, &buf, &rbuf))
653 REG_R_DELETE_VALUE r_o;
658 reg_io_r_delete_val("", &r_o, &rbuf, 0);
659 p = rbuf.offset != 0;
661 if (p && r_o.status != 0)
663 /* report error code */
664 DEBUG(0,("REG_DELETE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
680 /****************************************************************************
682 ****************************************************************************/
683 BOOL do_reg_delete_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, char *key_name)
687 REG_Q_DELETE_KEY q_o;
688 BOOL valid_delete = False;
690 if (hnd == NULL) return False;
692 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
693 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
695 /* create and send a MSRPC command with api REG_DELETE_KEY */
697 DEBUG(4,("REG Delete Key: %s\n", key_name));
699 make_reg_q_delete_key(&q_o, hnd, key_name);
701 /* turn parameters into data stream */
702 reg_io_q_delete_key("", &q_o, &buf, 0);
704 /* send the data on \PIPE\ */
705 if (rpc_api_pipe_req(cli, fnum, REG_DELETE_KEY, &buf, &rbuf))
707 REG_R_DELETE_KEY r_o;
712 reg_io_r_delete_key("", &r_o, &rbuf, 0);
713 p = rbuf.offset != 0;
715 if (p && r_o.status != 0)
717 /* report error code */
718 DEBUG(0,("REG_DELETE_KEY: %s\n", get_nt_error_msg(r_o.status)));
734 /****************************************************************************
736 ****************************************************************************/
737 BOOL do_reg_create_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
738 char *key_name, char *key_class,
739 SEC_ACCESS *sam_access,
744 REG_Q_CREATE_KEY q_o;
745 BOOL valid_create = False;
747 SEC_DESC_BUF sec_buf;
751 ZERO_STRUCT(sec_buf);
754 if (hnd == NULL) return False;
756 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
757 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
759 /* create and send a MSRPC command with api REG_CREATE_KEY */
761 DEBUG(4,("REG Create Key: %s %s 0x%08x\n", key_name, key_class,
762 sam_access != NULL ? sam_access->mask : 0));
764 sec_len = make_sec_desc(&sec, 1, SEC_DESC_SELF_RELATIVE,
765 NULL, NULL, NULL, NULL);
767 DEBUG(10,("make_sec_desc: len = %d\n", sec_len));
769 make_reg_q_create_key(&q_o, hnd, key_name, key_class, sam_access,
770 &sec_buf, sec_len, &sec);
772 /* turn parameters into data stream */
773 reg_io_q_create_key("", &q_o, &buf, 0);
775 /* send the data on \PIPE\ */
776 if (rpc_api_pipe_req(cli, fnum, REG_CREATE_KEY, &buf, &rbuf))
778 REG_R_CREATE_KEY r_o;
783 reg_io_r_create_key("", &r_o, &rbuf, 0);
784 p = rbuf.offset != 0;
786 if (p && r_o.status != 0)
788 /* report error code */
789 DEBUG(0,("REG_CREATE_KEY: %s\n", get_nt_error_msg(r_o.status)));
796 memcpy(key, r_o.key_pol.data, sizeof(key->data));
808 /****************************************************************************
810 ****************************************************************************/
811 BOOL do_reg_enum_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
812 int key_index, char *key_name,
813 uint32 *unk_1, uint32 *unk_2,
819 BOOL valid_query = False;
821 if (hnd == NULL) return False;
823 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
824 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
826 /* create and send a MSRPC command with api REG_ENUM_KEY */
828 DEBUG(4,("REG Enum Key\n"));
830 make_reg_q_enum_key(&q_o, hnd, key_index);
832 /* turn parameters into data stream */
833 reg_io_q_enum_key("", &q_o, &buf, 0);
835 /* send the data on \PIPE\ */
836 if (rpc_api_pipe_req(cli, fnum, REG_ENUM_KEY, &buf, &rbuf))
843 reg_io_r_enum_key("", &r_o, &rbuf, 0);
844 p = rbuf.offset != 0;
846 if (p && r_o.status != 0)
848 /* report error code */
849 DEBUG(0,("REG_ENUM_KEY: %s\n", get_nt_error_msg(r_o.status)));
856 (*unk_1) = r_o.unknown_1;
857 (*unk_2) = r_o.unknown_2;
858 unistr_to_ascii(key_name, r_o.key_name.str.buffer,
860 (*mod_time) = nt_time_to_unix(&r_o.time);
870 /****************************************************************************
871 do a REG Create Value
872 ****************************************************************************/
873 BOOL do_reg_create_val(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
874 char *val_name, uint32 type, BUFFER3 *data)
878 REG_Q_CREATE_VALUE q_o;
879 BOOL valid_create = False;
881 if (hnd == NULL) return False;
883 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
884 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
886 /* create and send a MSRPC command with api REG_CREATE_VALUE */
888 DEBUG(4,("REG Create Value: %s\n", val_name));
890 make_reg_q_create_val(&q_o, hnd, val_name, type, data);
892 /* turn parameters into data stream */
893 reg_io_q_create_val("", &q_o, &buf, 0);
895 /* send the data on \PIPE\ */
896 if (rpc_api_pipe_req(cli, fnum, REG_CREATE_VALUE, &buf, &rbuf))
898 REG_R_CREATE_VALUE r_o;
903 reg_io_r_create_val("", &r_o, &rbuf, 0);
904 p = rbuf.offset != 0;
906 if (p && r_o.status != 0)
908 /* report error code */
909 DEBUG(0,("REG_CREATE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
925 /****************************************************************************
927 ****************************************************************************/
928 BOOL do_reg_enum_val(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
929 int val_index, int max_valnamelen, int max_valbufsize,
931 uint32 *val_type, BUFFER2 *value)
935 REG_Q_ENUM_VALUE q_o;
936 BOOL valid_query = False;
938 if (hnd == NULL) return False;
940 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
941 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
943 /* create and send a MSRPC command with api REG_ENUM_VALUE */
945 DEBUG(4,("REG Enum Value\n"));
947 make_reg_q_enum_val(&q_o, hnd, val_index, max_valnamelen, max_valbufsize);
949 /* turn parameters into data stream */
950 reg_io_q_enum_val("", &q_o, &buf, 0);
952 /* send the data on \PIPE\ */
953 if (rpc_api_pipe_req(cli, fnum, REG_ENUM_VALUE, &buf, &rbuf))
955 REG_R_ENUM_VALUE r_o;
959 r_o.buf_value = value;
961 reg_io_r_enum_val("", &r_o, &rbuf, 0);
962 p = rbuf.offset != 0;
964 if (p && r_o.status != 0)
966 /* report error code */
967 DEBUG(0,("REG_ENUM_VALUE: %s\n", get_nt_error_msg(r_o.status)));
974 (*val_type) = r_o.type;
975 unistr2_to_ascii(val_name, &r_o.uni_name, sizeof(fstring)-1);
985 /****************************************************************************
987 ****************************************************************************/
988 BOOL do_reg_open_entry(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd,
989 char *key_name, uint32 unk_0,
994 REG_Q_OPEN_ENTRY q_o;
995 BOOL valid_pol = False;
997 if (hnd == NULL) return False;
999 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1000 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1002 /* create and send a MSRPC command with api REG_OPEN_ENTRY */
1004 DEBUG(4,("REG Open Entry\n"));
1006 make_reg_q_open_entry(&q_o, hnd, key_name, unk_0);
1008 /* turn parameters into data stream */
1009 reg_io_q_open_entry("", &q_o, &buf, 0);
1011 /* send the data on \PIPE\ */
1012 if (rpc_api_pipe_req(cli, fnum, REG_OPEN_ENTRY, &buf, &rbuf))
1014 REG_R_OPEN_ENTRY r_o;
1019 reg_io_r_open_entry("", &r_o, &rbuf, 0);
1020 p = rbuf.offset != 0;
1022 if (p && r_o.status != 0)
1024 /* report error code */
1025 DEBUG(0,("REG_OPEN_ENTRY: %s\n", get_nt_error_msg(r_o.status)));
1032 memcpy(key_hnd, r_o.pol.data, sizeof(key_hnd->data));
1036 prs_mem_free(&rbuf);
1037 prs_mem_free(&buf );
1042 /****************************************************************************
1044 ****************************************************************************/
1045 BOOL do_reg_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
1050 BOOL valid_close = False;
1052 if (hnd == NULL) return False;
1054 /* create and send a MSRPC command with api REG_CLOSE */
1056 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1057 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1059 DEBUG(4,("REG Close\n"));
1061 /* store the parameters */
1062 make_reg_q_close(&q_c, hnd);
1064 /* turn parameters into data stream */
1065 reg_io_q_close("", &q_c, &buf, 0);
1067 /* send the data on \PIPE\ */
1068 if (rpc_api_pipe_req(cli, fnum, REG_CLOSE, &buf, &rbuf))
1075 reg_io_r_close("", &r_c, &rbuf, 0);
1076 p = rbuf.offset != 0;
1078 if (p && r_c.status != 0)
1080 /* report error code */
1081 DEBUG(0,("REG_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
1087 /* check that the returned policy handle is all zeros */
1091 for (i = 0; i < sizeof(r_c.pol.data); i++)
1093 if (r_c.pol.data[i] != 0)
1095 valid_close = False;
1101 DEBUG(0,("REG_CLOSE: non-zero handle returned\n"));
1106 prs_mem_free(&rbuf);
1107 prs_mem_free(&buf );
1112 /****************************************************************************
1113 do a REG Shutdown Server
1114 ****************************************************************************/
1115 BOOL do_reg_shutdown(struct cli_state *cli, uint16 fnum,
1116 char *msg, uint32 timeout, uint16 flags)
1121 BOOL valid_shutdown = False;
1123 if (msg == NULL) return False;
1125 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
1126 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
1128 /* create and send a MSRPC command with api REG_SHUTDOWN */
1130 DEBUG(4,("REG Shutdown: (timeout: %d secs) %s\n", timeout, msg));
1132 make_reg_q_shutdown(&q_o, msg, timeout, flags);
1134 /* turn parameters into data stream */
1135 reg_io_q_shutdown("", &q_o, &buf, 0);
1137 /* send the data on \PIPE\ */
1138 if (rpc_api_pipe_req(cli, fnum, REG_SHUTDOWN, &buf, &rbuf))
1145 reg_io_r_shutdown("", &r_o, &rbuf, 0);
1146 p = rbuf.offset != 0;
1148 if (p && r_o.status != 0)
1150 /* report error code */
1151 DEBUG(0,("REG_SHUTDOWN: %s\n", get_nt_error_msg(r_o.status)));
1157 valid_shutdown = True;
1161 prs_mem_free(&rbuf);
1162 prs_mem_free(&buf );
1164 return valid_shutdown;