2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1998,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
6 * Copyright (C) Paul Ashton 1997-1998.
7 * Copyright (C) Jeremy Allison 1999.
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.
28 #define DBGC_CLASS DBGC_RPC_CLI
30 /****************************************************************************
32 ****************************************************************************/
33 BOOL do_reg_connect(struct cli_state *cli, char *full_keyname, char *key_name,
39 if (full_keyname == NULL)
42 ZERO_STRUCTP(reg_hnd);
45 * open registry receive a policy handle
48 if (!reg_split_key(full_keyname, ®_type, key_name)) {
49 DEBUG(0,("do_reg_connect: unrecognised key name %s\n", full_keyname));
54 case HKEY_LOCAL_MACHINE:
55 res = res ? do_reg_open_hklm(cli, 0x84E0, 0x02000000, reg_hnd) : False;
59 res = res ? do_reg_open_hku(cli, 0x84E0, 0x02000000, reg_hnd) : False;
63 DEBUG(0,("do_reg_connect: unrecognised hive key\n"));
70 /****************************************************************************
72 ****************************************************************************/
73 BOOL do_reg_open_hklm(struct cli_state *cli, uint16 unknown_0, uint32 level,
84 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
85 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
87 /* create and send a MSRPC command with api REG_OPEN_HKLM */
89 DEBUG(4,("REG Open HKLM\n"));
91 init_reg_q_open_hklm(&q_o, unknown_0, level);
93 /* turn parameters into data stream */
94 if(!reg_io_q_open_hklm("", &q_o, &buf, 0)) {
100 /* send the data on \PIPE\ */
101 if (!rpc_api_pipe_req(cli, REG_OPEN_HKLM, &buf, &rbuf)) {
111 if(!reg_io_r_open_hklm("", &r_o, &rbuf, 0)) {
116 if (r_o.status != 0) {
117 /* report error code */
118 DEBUG(0,("REG_OPEN_HKLM: %s\n", nt_errstr(r_o.status)));
123 /* ok, at last: we're happy. return the policy handle */
131 /****************************************************************************
133 ****************************************************************************/
134 BOOL do_reg_open_hku(struct cli_state *cli, uint16 unknown_0, uint32 level,
145 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
146 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
148 /* create and send a MSRPC command with api REG_OPEN_HKU */
150 DEBUG(4,("REG Open HKU\n"));
152 init_reg_q_open_hku(&q_o, unknown_0, level);
154 /* turn parameters into data stream */
155 if(!reg_io_q_open_hku("", &q_o, &buf, 0)) {
161 /* send the data on \PIPE\ */
162 if (rpc_api_pipe_req(cli, REG_OPEN_HKU, &buf, &rbuf)) {
172 if(!reg_io_r_open_hku("", &r_o, &rbuf, 0)) {
177 if (r_o.status != 0) {
178 /* report error code */
179 DEBUG(0,("REG_OPEN_HKU: %s\n", nt_errstr(r_o.status)));
184 /* ok, at last: we're happy. return the policy handle */
192 /****************************************************************************
193 do a REG Unknown 0xB command. sent after a create key or create value.
194 this might be some sort of "sync" or "refresh" command, sent after
195 modification of the registry...
196 ****************************************************************************/
197 BOOL do_reg_flush_key(struct cli_state *cli, POLICY_HND *hnd)
207 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
208 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
210 /* create and send a MSRPC command with api REG_FLUSH_KEY */
212 DEBUG(4,("REG Unknown 0xB\n"));
214 init_reg_q_flush_key(&q_o, hnd);
216 /* turn parameters into data stream */
217 if(!reg_io_q_flush_key("", &q_o, &buf, 0)) {
223 /* send the data on \PIPE\ */
224 if (!rpc_api_pipe_req(cli, REG_FLUSH_KEY, &buf, &rbuf)) {
234 if(!reg_io_r_flush_key("", &r_o, &rbuf, 0)) {
239 if (r_o.status != 0) {
240 /* report error code */
241 DEBUG(0,("REG_FLUSH_KEY: %s\n", nt_errstr(r_o.status)));
251 /****************************************************************************
253 ****************************************************************************/
254 BOOL do_reg_query_key(struct cli_state *cli, POLICY_HND *hnd,
255 char *class, uint32 *class_len,
256 uint32 *num_subkeys, uint32 *max_subkeylen,
257 uint32 *max_subkeysize, uint32 *num_values,
258 uint32 *max_valnamelen, uint32 *max_valbufsize,
259 uint32 *sec_desc, NTTIME *mod_time)
269 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
270 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
272 /* create and send a MSRPC command with api REG_QUERY_KEY */
274 DEBUG(4,("REG Query Key\n"));
276 init_reg_q_query_key(&q_o, hnd, *class_len);
278 /* turn parameters into data stream */
279 if(!reg_io_q_query_key("", &q_o, &buf, 0)) {
285 /* send the data on \PIPE\ */
286 if (!rpc_api_pipe_req(cli, REG_QUERY_KEY, &buf, &rbuf)) {
296 if(!reg_io_r_query_key("", &r_o, &rbuf, 0)) {
301 if (r_o.status != 0) {
302 /* report error code */
303 DEBUG(0,("REG_QUERY_KEY: %s\n", nt_errstr(r_o.status)));
308 *class_len = r_o.hdr_class.uni_max_len;
309 rpcstr_pull(class, &r_o.uni_class, -1, -1, 0);
310 *num_subkeys = r_o.num_subkeys ;
311 *max_subkeylen = r_o.max_subkeylen ;
312 *max_subkeysize = r_o.max_subkeysize;
313 *num_values = r_o.num_values ;
314 *max_valnamelen = r_o.max_valnamelen;
315 *max_valbufsize = r_o.max_valbufsize;
316 *sec_desc = r_o.sec_desc ;
317 *mod_time = r_o.mod_time ;
324 /****************************************************************************
326 ****************************************************************************/
327 BOOL do_reg_unknown_1a(struct cli_state *cli, POLICY_HND *hnd, uint32 *unk)
337 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
338 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
340 /* create and send a MSRPC command with api REG_UNKNOWN_1A */
342 DEBUG(4,("REG Unknown 1a\n"));
344 init_reg_q_unk_1a(&q_o, hnd);
346 /* turn parameters into data stream */
347 if(!reg_io_q_unk_1a("", &q_o, &buf, 0)) {
353 /* send the data on \PIPE\ */
354 if (rpc_api_pipe_req(cli, REG_UNK_1A, &buf, &rbuf)) {
364 if(!reg_io_r_unk_1a("", &r_o, &rbuf, 0)) {
369 if (r_o.status != 0) {
370 /* report error code */
371 DEBUG(0,("REG_UNK_1A: %s\n", nt_errstr(r_o.status)));
376 (*unk) = r_o.unknown;
383 /****************************************************************************
385 ****************************************************************************/
386 BOOL do_reg_query_info(struct cli_state *cli, POLICY_HND *hnd,
387 char *key_value, uint32* key_type)
397 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
398 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
400 /* create and send a MSRPC command with api REG_INFO */
402 DEBUG(4,("REG Query Info\n"));
404 init_reg_q_info(&q_o, hnd, "ProductType");
406 /* turn parameters into data stream */
407 if(!reg_io_q_info("", &q_o, &buf, 0)) {
413 /* send the data on \PIPE\ */
414 if (!rpc_api_pipe_req(cli, REG_INFO, &buf, &rbuf)) {
424 if(!reg_io_r_info("", &r_o, &rbuf, 0)) {
429 if ( r_o.status != 0) {
430 /* report error code */
431 DEBUG(0,("REG_INFO: %s\n", nt_errstr(r_o.status)));
436 /*fstrcpy(key_value, dos_buffer2_to_str(r_o.uni_val));*/
437 rpcstr_pull(key_value, r_o.uni_val->buffer, sizeof(fstring), r_o.uni_val->buf_len, 0);
438 *key_type = r_o.type;
445 /****************************************************************************
446 do a REG Set Key Security
447 ****************************************************************************/
448 BOOL do_reg_set_key_sec(struct cli_state *cli, POLICY_HND *hnd, SEC_DESC_BUF *sec_desc_buf)
452 REG_Q_SET_KEY_SEC q_o;
453 REG_R_SET_KEY_SEC r_o;
458 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
459 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
461 /* create and send a MSRPC command with api REG_SET_KEY_SEC */
463 DEBUG(4,("REG Set Key security.\n"));
465 init_reg_q_set_key_sec(&q_o, hnd, sec_desc_buf);
467 /* turn parameters into data stream */
468 if(!reg_io_q_set_key_sec("", &q_o, &buf, 0)) {
474 /* send the data on \PIPE\ */
475 if (!rpc_api_pipe_req(cli, REG_SET_KEY_SEC, &buf, &rbuf)) {
485 if(!reg_io_r_set_key_sec("", &r_o, &rbuf, 0)) {
490 if (r_o.status != 0) {
500 /****************************************************************************
501 do a REG Query Key Security
502 ****************************************************************************/
504 BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd, uint32 *sec_buf_size, SEC_DESC_BUF **ppsec_desc_buf)
508 REG_Q_GET_KEY_SEC q_o;
509 REG_R_GET_KEY_SEC r_o;
514 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
515 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
517 /* create and send a MSRPC command with api REG_GET_KEY_SEC */
519 DEBUG(4,("REG query key security. buf_size: %d\n", *sec_buf_size));
521 init_reg_q_get_key_sec(&q_o, hnd, *sec_buf_size, NULL);
523 /* turn parameters into data stream */
524 if(!reg_io_q_get_key_sec("", &q_o, &buf, 0)) {
530 /* send the data on \PIPE\ */
531 if (!rpc_api_pipe_req(cli, REG_GET_KEY_SEC, &buf, &rbuf)) {
541 if(!reg_io_r_get_key_sec("", &r_o, &rbuf, 0)) {
546 if (r_o.status == 0x0000007a) {
548 * get the maximum buffer size: it was too small
550 (*sec_buf_size) = r_o.hdr_sec.buf_max_len;
551 DEBUG(5,("sec_buf_size too small. use %d\n", *sec_buf_size));
552 } else if (r_o.status != 0) {
553 /* report error code */
554 DEBUG(0,("REG_GET_KEY_SEC: %s\n", nt_errstr(r_o.status)));
558 (*sec_buf_size) = r_o.data->len;
559 *ppsec_desc_buf = r_o.data;
567 /****************************************************************************
568 do a REG Delete Value
569 ****************************************************************************/
570 BOOL do_reg_delete_val(struct cli_state *cli, POLICY_HND *hnd, char *val_name)
574 REG_Q_DELETE_VALUE q_o;
575 REG_R_DELETE_VALUE r_o;
580 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
581 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
583 /* create and send a MSRPC command with api REG_DELETE_VALUE */
585 DEBUG(4,("REG Delete Value: %s\n", val_name));
587 init_reg_q_delete_val(&q_o, hnd, val_name);
589 /* turn parameters into data stream */
590 if(!reg_io_q_delete_val("", &q_o, &buf, 0)) {
596 /* send the data on \PIPE\ */
597 if (rpc_api_pipe_req(cli, REG_DELETE_VALUE, &buf, &rbuf)) {
607 if(!reg_io_r_delete_val("", &r_o, &rbuf, 0)) {
612 if (r_o.status != 0) {
613 /* report error code */
614 DEBUG(0,("REG_DELETE_VALUE: %s\n", nt_errstr(r_o.status)));
624 /****************************************************************************
626 ****************************************************************************/
627 BOOL do_reg_delete_key(struct cli_state *cli, POLICY_HND *hnd, char *key_name)
631 REG_Q_DELETE_KEY q_o;
632 REG_R_DELETE_KEY r_o;
637 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
638 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
640 /* create and send a MSRPC command with api REG_DELETE_KEY */
642 DEBUG(4,("REG Delete Key: %s\n", key_name));
644 init_reg_q_delete_key(&q_o, hnd, key_name);
646 /* turn parameters into data stream */
647 if(!reg_io_q_delete_key("", &q_o, &buf, 0)) {
653 /* send the data on \PIPE\ */
654 if (!rpc_api_pipe_req(cli, REG_DELETE_KEY, &buf, &rbuf)) {
664 if(!reg_io_r_delete_key("", &r_o, &rbuf, 0)) {
669 if (r_o.status != 0) {
670 /* report error code */
671 DEBUG(0,("REG_DELETE_KEY: %s\n", nt_errstr(r_o.status)));
681 /****************************************************************************
683 ****************************************************************************/
684 BOOL do_reg_create_key(struct cli_state *cli, POLICY_HND *hnd,
685 char *key_name, char *key_class,
686 SEC_ACCESS *sam_access,
691 REG_Q_CREATE_KEY q_o;
692 REG_R_CREATE_KEY r_o;
693 SEC_DESC *sec = NULL;
694 SEC_DESC_BUF *sec_buf = NULL;
702 /* create and send a MSRPC command with api REG_CREATE_KEY */
704 DEBUG(4,("REG Create Key: %s %s 0x%08x\n", key_name, key_class,
705 sam_access != NULL ? sam_access->mask : 0));
707 if((sec = make_sec_desc( cli->mem_ctx, 1, NULL, NULL, NULL, NULL, &sec_len)) == NULL) {
708 DEBUG(0,("make_sec_desc : malloc fail.\n"));
712 DEBUG(10,("make_sec_desc: len = %d\n", (int)sec_len));
714 if((sec_buf = make_sec_desc_buf( cli->mem_ctx, (int)sec_len, sec)) == NULL) {
715 DEBUG(0,("make_sec_desc : malloc fail (1)\n"));
719 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
720 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
722 init_reg_q_create_key(&q_o, hnd, key_name, key_class, sam_access, sec_buf);
724 /* turn parameters into data stream */
725 if(!reg_io_q_create_key("", &q_o, &buf, 0)) {
731 /* send the data on \PIPE\ */
732 if (rpc_api_pipe_req(cli, REG_CREATE_KEY, &buf, &rbuf)) {
742 if(!reg_io_r_create_key("", &r_o, &rbuf, 0)) {
747 if (r_o.status != 0) {
748 /* report error code */
749 DEBUG(0,("REG_CREATE_KEY: %s\n", nt_errstr(r_o.status)));
761 /****************************************************************************
763 ****************************************************************************/
764 BOOL do_reg_enum_key(struct cli_state *cli, POLICY_HND *hnd,
765 int key_index, char *key_name,
766 uint32 *unk_1, uint32 *unk_2,
777 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
778 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
780 /* create and send a MSRPC command with api REG_ENUM_KEY */
782 DEBUG(4,("REG Enum Key\n"));
784 init_reg_q_enum_key(&q_o, hnd, key_index);
786 /* turn parameters into data stream */
787 if(!reg_io_q_enum_key("", &q_o, &buf, 0)) {
793 /* send the data on \PIPE\ */
794 if (!rpc_api_pipe_req(cli, REG_ENUM_KEY, &buf, &rbuf)) {
804 if(!reg_io_r_enum_key("", &r_o, &rbuf, 0)) {
809 if (r_o.status != 0) {
810 /* report error code */
811 DEBUG(0,("REG_ENUM_KEY: %s\n", nt_errstr(r_o.status)));
816 (*unk_1) = r_o.unknown_1;
817 (*unk_2) = r_o.unknown_2;
818 rpcstr_pull(key_name, r_o.key_name.str.buffer, -1, -1, 0);
819 (*mod_time) = nt_time_to_unix(&r_o.time);
826 /****************************************************************************
827 do a REG Create Value
828 ****************************************************************************/
829 BOOL do_reg_create_val(struct cli_state *cli, POLICY_HND *hnd,
830 char *val_name, uint32 type, BUFFER3 *data)
834 REG_Q_CREATE_VALUE q_o;
835 REG_R_CREATE_VALUE r_o;
840 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
841 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
843 /* create and send a MSRPC command with api REG_CREATE_VALUE */
845 DEBUG(4,("REG Create Value: %s\n", val_name));
847 init_reg_q_create_val(&q_o, hnd, val_name, type, data);
849 /* turn parameters into data stream */
850 if(!reg_io_q_create_val("", &q_o, &buf, 0)) {
856 /* send the data on \PIPE\ */
857 if (!rpc_api_pipe_req(cli, REG_CREATE_VALUE, &buf, &rbuf)) {
867 if(!reg_io_r_create_val("", &r_o, &rbuf, 0)) {
872 if (r_o.status != 0) {
873 /* report error code */
874 DEBUG(0,("REG_CREATE_VALUE: %s\n", nt_errstr(r_o.status)));
884 /****************************************************************************
886 ****************************************************************************/
887 BOOL do_reg_enum_val(struct cli_state *cli, POLICY_HND *hnd,
888 int val_index, int max_valnamelen, int max_valbufsize,
890 uint32 *val_type, BUFFER2 *value)
894 REG_Q_ENUM_VALUE q_o;
895 REG_R_ENUM_VALUE r_o;
900 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
901 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
903 /* create and send a MSRPC command with api REG_ENUM_VALUE */
905 DEBUG(4,("REG Enum Value\n"));
907 init_reg_q_enum_val(&q_o, hnd, val_index, max_valnamelen, max_valbufsize);
909 /* turn parameters into data stream */
910 if(!reg_io_q_enum_val("", &q_o, &buf, 0)) {
916 /* send the data on \PIPE\ */
917 if (!rpc_api_pipe_req(cli, REG_ENUM_VALUE, &buf, &rbuf)) {
926 r_o.buf_value = value;
928 if(!reg_io_r_enum_val("", &r_o, &rbuf, 0)) {
933 if (r_o.status != 0) {
934 /* report error code */
935 DEBUG(0,("REG_ENUM_VALUE: %s\n", nt_errstr(r_o.status)));
940 (*val_type) = r_o.type;
941 rpcstr_pull(val_name, &r_o.uni_name, -1, -1, 0);
948 /****************************************************************************
950 ****************************************************************************/
951 BOOL do_reg_open_entry(struct cli_state *cli, POLICY_HND *hnd,
952 char *key_name, uint32 unk_0,
957 REG_Q_OPEN_ENTRY q_o;
958 REG_R_OPEN_ENTRY r_o;
963 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
964 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
966 /* create and send a MSRPC command with api REG_OPEN_ENTRY */
968 DEBUG(4,("REG Open Entry\n"));
970 init_reg_q_open_entry(&q_o, hnd, key_name, unk_0);
972 /* turn parameters into data stream */
973 if(!reg_io_q_open_entry("", &q_o, &buf, 0)) {
979 /* send the data on \PIPE\ */
980 if (!rpc_api_pipe_req(cli, REG_OPEN_ENTRY, &buf, &rbuf)) {
990 if(!reg_io_r_open_entry("", &r_o, &rbuf, 0)) {
995 if (r_o.status != 0) {
996 /* report error code */
997 DEBUG(0,("REG_OPEN_ENTRY: %s\n", nt_errstr(r_o.status)));
1004 prs_mem_free(&rbuf);
1009 /****************************************************************************
1011 ****************************************************************************/
1012 BOOL do_reg_close(struct cli_state *cli, POLICY_HND *hnd)
1022 /* create and send a MSRPC command with api REG_CLOSE */
1024 prs_init(&buf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
1025 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
1027 DEBUG(4,("REG Close\n"));
1029 /* store the parameters */
1030 init_reg_q_close(&q_c, hnd);
1032 /* turn parameters into data stream */
1033 if(!reg_io_q_close("", &q_c, &buf, 0)) {
1035 prs_mem_free(&rbuf);
1039 /* send the data on \PIPE\ */
1040 if (!rpc_api_pipe_req(cli, REG_CLOSE, &buf, &rbuf)) {
1042 prs_mem_free(&rbuf);
1050 if(!reg_io_r_close("", &r_c, &rbuf, 0)) {
1051 prs_mem_free(&rbuf);
1055 if (r_c.status != 0) {
1056 /* report error code */
1057 DEBUG(0,("REG_CLOSE: %s\n", nt_errstr(r_c.status)));
1058 prs_mem_free(&rbuf);
1062 /* check that the returned policy handle is all zeros */
1064 if (IVAL(&r_c.pol.data1,0) || IVAL(&r_c.pol.data2,0) || SVAL(&r_c.pol.data3,0) ||
1065 SVAL(&r_c.pol.data4,0) || IVAL(r_c.pol.data5,0) || IVAL(r_c.pol.data5,4) ) {
1066 prs_mem_free(&rbuf);
1067 DEBUG(0,("REG_CLOSE: non-zero handle returned\n"));
1071 prs_mem_free(&rbuf);