3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1997,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8 * Copyright (C) Paul Ashton 1997.
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;
35 /****************************************************************************
37 ****************************************************************************/
38 BOOL do_reg_open_policy(struct cli_state *cli, uint16 unknown_0, uint32 level,
43 REG_Q_OPEN_POLICY q_o;
44 BOOL valid_pol = False;
46 if (hnd == NULL) return False;
48 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
49 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
51 /* create and send a MSRPC command with api REG_OPEN_POLICY */
53 DEBUG(4,("REG Open Policy\n"));
55 make_reg_q_open_pol(&q_o, unknown_0, level);
57 /* turn parameters into data stream */
58 reg_io_q_open_policy("", &q_o, &buf, 0);
60 /* send the data on \PIPE\ */
61 if (rpc_api_pipe_req(cli, REG_OPEN_POLICY, &buf, &rbuf))
63 REG_R_OPEN_POLICY r_o;
68 reg_io_r_open_policy("", &r_o, &rbuf, 0);
71 if (p && r_o.status != 0)
73 /* report error code */
74 DEBUG(0,("REG_OPEN_POLICY: %s\n", get_nt_error_msg(r_o.status)));
80 /* ok, at last: we're happy. return the policy handle */
81 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
92 /****************************************************************************
93 do a REG Open Unknown 4
94 ****************************************************************************/
95 BOOL do_reg_open_unk_4(struct cli_state *cli, uint16 unknown_0, uint32 level,
100 REG_Q_OPEN_UNK_4 q_o;
101 BOOL valid_pol = False;
103 if (hnd == NULL) return False;
105 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
106 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
108 /* create and send a MSRPC command with api REG_OPEN_UNK_4 */
110 DEBUG(4,("REG Open Unknown4\n"));
112 make_reg_q_open_unk_4(&q_o, unknown_0, level);
114 /* turn parameters into data stream */
115 reg_io_q_open_unk_4("", &q_o, &buf, 0);
117 /* send the data on \PIPE\ */
118 if (rpc_api_pipe_req(cli, REG_OPEN_UNK_4, &buf, &rbuf))
120 REG_R_OPEN_UNK_4 r_o;
125 reg_io_r_open_unk_4("", &r_o, &rbuf, 0);
126 p = rbuf.offset != 0;
128 if (p && r_o.status != 0)
130 /* report error code */
131 DEBUG(0,("REG_OPEN_UNK_4: %s\n", get_nt_error_msg(r_o.status)));
137 /* ok, at last: we're happy. return the policy handle */
138 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
149 /****************************************************************************
150 do a REG Unknown 0xB command. sent after a create key or create value.
151 this might be some sort of "sync" or "refresh" command, sent after
152 modification of the registry...
153 ****************************************************************************/
154 BOOL do_reg_unk_b(struct cli_state *cli, POLICY_HND *hnd)
159 BOOL valid_query = False;
161 if (hnd == NULL) return False;
163 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
164 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
166 /* create and send a MSRPC command with api REG_UNK_B */
168 DEBUG(4,("REG Unknown 0xB\n"));
170 make_reg_q_unk_b(&q_o, hnd);
172 /* turn parameters into data stream */
173 reg_io_q_unk_b("", &q_o, &buf, 0);
175 /* send the data on \PIPE\ */
176 if (rpc_api_pipe_req(cli, REG_UNK_B, &buf, &rbuf))
183 reg_io_r_unk_b("", &r_o, &rbuf, 0);
184 p = rbuf.offset != 0;
186 if (p && r_o.status != 0)
188 /* report error code */
189 DEBUG(0,("REG_UNK_B: %s\n", get_nt_error_msg(r_o.status)));
205 /****************************************************************************
207 ****************************************************************************/
208 BOOL do_reg_query_key(struct cli_state *cli, POLICY_HND *hnd,
209 char *class, uint32 *class_len,
210 uint32 *num_subkeys, uint32 *max_subkeylen,
211 uint32 *max_subkeysize, uint32 *num_values,
212 uint32 *max_valnamelen, uint32 *max_valbufsize,
213 uint32 *sec_desc, NTTIME *mod_time)
218 BOOL valid_query = 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_QUERY_KEY */
227 DEBUG(4,("REG Query Key\n"));
229 make_reg_q_query_key(&q_o, hnd, *class_len);
231 /* turn parameters into data stream */
232 reg_io_q_query_key("", &q_o, &buf, 0);
234 /* send the data on \PIPE\ */
235 if (rpc_api_pipe_req(cli, REG_QUERY_KEY, &buf, &rbuf))
242 reg_io_r_query_key("", &r_o, &rbuf, 0);
243 p = rbuf.offset != 0;
245 if (p && r_o.status != 0)
247 /* report error code */
248 DEBUG(0,("REG_QUERY_KEY: %s\n", get_nt_error_msg(r_o.status)));
256 *class_len = r_o.hdr_class.uni_max_len;
257 fstrcpy(class, unistr2_to_str(&r_o.uni_class));
258 *num_subkeys = r_o.num_subkeys ;
259 *max_subkeylen = r_o.max_subkeylen ;
260 *max_subkeysize = r_o.max_subkeysize;
261 *num_values = r_o.num_values ;
262 *max_valnamelen = r_o.max_valnamelen;
263 *max_valbufsize = r_o.max_valbufsize;
264 *sec_desc = r_o.sec_desc ;
265 *mod_time = r_o.mod_time ;
275 /****************************************************************************
277 ****************************************************************************/
278 BOOL do_reg_unknown_1a(struct cli_state *cli, POLICY_HND *hnd, uint32 *unk)
283 BOOL valid_query = False;
285 if (hnd == NULL) return False;
287 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
288 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
290 /* create and send a MSRPC command with api REG_UNKNOWN_1A */
292 DEBUG(4,("REG Unknown 1a\n"));
294 make_reg_q_unk_1a(&q_o, hnd);
296 /* turn parameters into data stream */
297 reg_io_q_unk_1a("", &q_o, &buf, 0);
299 /* send the data on \PIPE\ */
300 if (rpc_api_pipe_req(cli, REG_UNK_1A, &buf, &rbuf))
307 reg_io_r_unk_1a("", &r_o, &rbuf, 0);
308 p = rbuf.offset != 0;
310 if (p && r_o.status != 0)
312 /* report error code */
313 DEBUG(0,("REG_UNK_1A: %s\n", get_nt_error_msg(r_o.status)));
320 (*unk) = r_o.unknown;
330 /****************************************************************************
332 ****************************************************************************/
333 BOOL do_reg_query_info(struct cli_state *cli, POLICY_HND *hnd,
334 char *type, uint32 *unk_0, uint32 *unk_1)
339 BOOL valid_query = False;
341 if (hnd == NULL) return False;
343 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
344 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
346 /* create and send a MSRPC command with api REG_INFO */
348 DEBUG(4,("REG Query Info\n"));
350 make_reg_q_info(&q_o, hnd, "ProductType", time(NULL), 4, 1);
352 /* turn parameters into data stream */
353 reg_io_q_info("", &q_o, &buf, 0);
355 /* send the data on \PIPE\ */
356 if (rpc_api_pipe_req(cli, REG_INFO, &buf, &rbuf))
363 reg_io_r_info("", &r_o, &rbuf, 0);
364 p = rbuf.offset != 0;
366 if (p && r_o.status != 0)
368 /* report error code */
369 DEBUG(0,("REG_INFO: %s\n", get_nt_error_msg(r_o.status)));
376 fstrcpy(type, buffer2_to_str(&r_o.uni_type));
377 (*unk_0) = r_o.unknown_0;
378 (*unk_1) = r_o.unknown_1;
388 /****************************************************************************
389 do a REG Query Key Security
390 ****************************************************************************/
391 BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd,
392 uint32 *sec_buf_size, SEC_DESC_BUF *sec_buf)
396 REG_Q_GET_KEY_SEC q_o;
397 BOOL valid_query = False;
399 if (hnd == NULL) return False;
401 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
402 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
404 /* create and send a MSRPC command with api REG_GET_KEY_SEC */
406 DEBUG(4,("REG query key security. buf_size: %d\n", *sec_buf_size));
408 make_reg_q_get_key_sec(&q_o, hnd, *sec_buf_size, sec_buf);
410 /* turn parameters into data stream */
411 reg_io_q_get_key_sec("", &q_o, &buf, 0);
413 /* send the data on \PIPE\ */
414 if (rpc_api_pipe_req(cli, REG_GET_KEY_SEC, &buf, &rbuf))
416 REG_R_GET_KEY_SEC r_o;
422 reg_io_r_get_key_sec("", &r_o, &rbuf, 0);
423 p = rbuf.offset != 0;
425 if (p && r_o.status == 0x0000007a)
428 * get the maximum buffer size: it was too small
430 (*sec_buf_size) = r_o.hdr_sec.buf_max_len;
431 DEBUG(5,("sec_buf_size too small. use %d\n", *sec_buf_size));
434 else if (p && r_o.status != 0)
436 /* report error code */
437 DEBUG(0,("REG_GET_KEY_SEC: %s\n", get_nt_error_msg(r_o.status)));
443 (*sec_buf_size) = r_o.data->len;
453 /****************************************************************************
455 ****************************************************************************/
456 BOOL do_reg_delete_key(struct cli_state *cli, POLICY_HND *hnd, char *key_name)
460 REG_Q_DELETE_KEY q_o;
461 BOOL valid_delete = False;
463 if (hnd == NULL) return False;
465 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
466 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
468 /* create and send a MSRPC command with api REG_DELETE_KEY */
470 DEBUG(4,("REG Delete Key: %s\n", key_name));
472 make_reg_q_delete_key(&q_o, hnd, key_name);
474 /* turn parameters into data stream */
475 reg_io_q_delete_key("", &q_o, &buf, 0);
477 /* send the data on \PIPE\ */
478 if (rpc_api_pipe_req(cli, REG_DELETE_KEY, &buf, &rbuf))
480 REG_R_DELETE_KEY r_o;
485 reg_io_r_delete_key("", &r_o, &rbuf, 0);
486 p = rbuf.offset != 0;
488 if (p && r_o.status != 0)
490 /* report error code */
491 DEBUG(0,("REG_DELETE_KEY: %s\n", get_nt_error_msg(r_o.status)));
507 /****************************************************************************
509 ****************************************************************************/
510 BOOL do_reg_create_key(struct cli_state *cli, POLICY_HND *hnd,
511 char *key_name, char *key_class,
512 SEC_INFO *sam_access,
517 REG_Q_CREATE_KEY q_o;
518 BOOL valid_create = False;
520 if (hnd == NULL) return False;
522 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
523 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
525 /* create and send a MSRPC command with api REG_CREATE_KEY */
527 DEBUG(4,("REG Create Key: %s %s 0x%08x\n", key_name, key_class,
528 sam_access != NULL ? sam_access->perms : 0));
530 make_reg_q_create_key(&q_o, hnd, key_name, key_class, sam_access);
532 /* turn parameters into data stream */
533 reg_io_q_create_key("", &q_o, &buf, 0);
535 /* send the data on \PIPE\ */
536 if (rpc_api_pipe_req(cli, REG_CREATE_KEY, &buf, &rbuf))
538 REG_R_CREATE_KEY r_o;
543 reg_io_r_create_key("", &r_o, &rbuf, 0);
544 p = rbuf.offset != 0;
546 if (p && r_o.status != 0)
548 /* report error code */
549 DEBUG(0,("REG_CREATE_KEY: %s\n", get_nt_error_msg(r_o.status)));
556 memcpy(key, r_o.key_pol.data, sizeof(key->data));
566 /****************************************************************************
568 ****************************************************************************/
569 BOOL do_reg_enum_key(struct cli_state *cli, POLICY_HND *hnd,
570 int key_index, char *key_name,
571 uint32 *unk_1, uint32 *unk_2,
577 BOOL valid_query = False;
579 if (hnd == NULL) return False;
581 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
582 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
584 /* create and send a MSRPC command with api REG_ENUM_KEY */
586 DEBUG(4,("REG Enum Key\n"));
588 make_reg_q_enum_key(&q_o, hnd, key_index);
590 /* turn parameters into data stream */
591 reg_io_q_enum_key("", &q_o, &buf, 0);
593 /* send the data on \PIPE\ */
594 if (rpc_api_pipe_req(cli, REG_ENUM_KEY, &buf, &rbuf))
601 reg_io_r_enum_key("", &r_o, &rbuf, 0);
602 p = rbuf.offset != 0;
604 if (p && r_o.status != 0)
606 /* report error code */
607 DEBUG(0,("REG_ENUM_KEY: %s\n", get_nt_error_msg(r_o.status)));
614 (*unk_1) = r_o.unknown_1;
615 (*unk_2) = r_o.unknown_2;
616 fstrcpy(key_name, unistr2(r_o.key_name.str.buffer));
617 (*mod_time) = nt_time_to_unix(&r_o.time);
627 /****************************************************************************
628 do a REG Create Value
629 ****************************************************************************/
630 BOOL do_reg_create_val(struct cli_state *cli, POLICY_HND *hnd,
631 char *val_name, uint32 type, BUFFER3 *data)
635 REG_Q_CREATE_VALUE q_o;
636 BOOL valid_create = False;
638 if (hnd == NULL) return False;
640 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
641 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
643 /* create and send a MSRPC command with api REG_CREATE_VALUE */
645 DEBUG(4,("REG Create Value: %s\n", val_name));
647 make_reg_q_create_val(&q_o, hnd, val_name, type, data);
649 /* turn parameters into data stream */
650 reg_io_q_create_val("", &q_o, &buf, 0);
652 /* send the data on \PIPE\ */
653 if (rpc_api_pipe_req(cli, REG_CREATE_VALUE, &buf, &rbuf))
655 REG_R_CREATE_VALUE r_o;
660 reg_io_r_create_val("", &r_o, &rbuf, 0);
661 p = rbuf.offset != 0;
663 if (p && r_o.status != 0)
665 /* report error code */
666 DEBUG(0,("REG_CREATE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
682 /****************************************************************************
684 ****************************************************************************/
685 BOOL do_reg_enum_val(struct cli_state *cli, POLICY_HND *hnd,
686 int val_index, int max_valnamelen, int max_valbufsize,
688 uint32 *val_type, BUFFER2 *value)
692 REG_Q_ENUM_VALUE q_o;
693 BOOL valid_query = False;
695 if (hnd == NULL) return False;
697 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
698 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
700 /* create and send a MSRPC command with api REG_ENUM_VALUE */
702 DEBUG(4,("REG Enum Value\n"));
704 make_reg_q_enum_val(&q_o, hnd, val_index, max_valnamelen, max_valbufsize);
706 /* turn parameters into data stream */
707 reg_io_q_enum_val("", &q_o, &buf, 0);
709 /* send the data on \PIPE\ */
710 if (rpc_api_pipe_req(cli, REG_ENUM_VALUE, &buf, &rbuf))
712 REG_R_ENUM_VALUE r_o;
716 r_o.buf_value = value;
718 reg_io_r_enum_val("", &r_o, &rbuf, 0);
719 p = rbuf.offset != 0;
721 if (p && r_o.status != 0)
723 /* report error code */
724 DEBUG(0,("REG_ENUM_VALUE: %s\n", get_nt_error_msg(r_o.status)));
731 (*val_type) = r_o.type;
732 fstrcpy(val_name, unistr2_to_str(&r_o.uni_name));
742 /****************************************************************************
744 ****************************************************************************/
745 BOOL do_reg_open_entry(struct cli_state *cli, POLICY_HND *hnd,
746 char *key_name, uint32 unk_0,
751 REG_Q_OPEN_ENTRY q_o;
752 BOOL valid_pol = False;
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_OPEN_ENTRY */
761 DEBUG(4,("REG Open Entry\n"));
763 make_reg_q_open_entry(&q_o, hnd, key_name, unk_0);
765 /* turn parameters into data stream */
766 reg_io_q_open_entry("", &q_o, &buf, 0);
768 /* send the data on \PIPE\ */
769 if (rpc_api_pipe_req(cli, REG_OPEN_ENTRY, &buf, &rbuf))
771 REG_R_OPEN_ENTRY r_o;
776 reg_io_r_open_entry("", &r_o, &rbuf, 0);
777 p = rbuf.offset != 0;
779 if (p && r_o.status != 0)
781 /* report error code */
782 DEBUG(0,("REG_OPEN_ENTRY: %s\n", get_nt_error_msg(r_o.status)));
789 memcpy(key_hnd, r_o.pol.data, sizeof(key_hnd->data));
799 /****************************************************************************
801 ****************************************************************************/
802 BOOL do_reg_close(struct cli_state *cli, POLICY_HND *hnd)
807 BOOL valid_close = False;
809 if (hnd == NULL) return False;
811 /* create and send a MSRPC command with api REG_CLOSE */
813 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
814 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
816 DEBUG(4,("REG Close\n"));
818 /* store the parameters */
819 make_reg_q_close(&q_c, hnd);
821 /* turn parameters into data stream */
822 reg_io_q_close("", &q_c, &buf, 0);
824 /* send the data on \PIPE\ */
825 if (rpc_api_pipe_req(cli, REG_CLOSE, &buf, &rbuf))
832 reg_io_r_close("", &r_c, &rbuf, 0);
833 p = rbuf.offset != 0;
835 if (p && r_c.status != 0)
837 /* report error code */
838 DEBUG(0,("REG_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
844 /* check that the returned policy handle is all zeros */
848 for (i = 0; i < sizeof(r_c.pol.data); i++)
850 if (r_c.pol.data[i] != 0)
858 DEBUG(0,("REG_CLOSE: non-zero handle returned\n"));