r6369: update release notes
[Samba.git] / source / rpc_client / cli_reg.c
blob0d7d194850c91608fcfd51d4cceebc82ade6617c
1 /*
2 Unix SMB/CIFS implementation.
3 RPC Pipe client
5 Copyright (C) Andrew Tridgell 1992-2000,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 Copyright (C) Paul Ashton 1997-2000.
8 Copyright (C) Jeremy Allison 1999.
9 Copyright (C) Simo Sorce 2001
10 Copyright (C) Jeremy Cooper 2004
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "includes.h"
29 /* Shutdown a server */
31 /* internal connect to a registry hive root (open a registry policy) */
33 static WERROR cli_reg_open_hive_int(struct cli_state *cli,
34 TALLOC_CTX *mem_ctx, uint16 op_code,
35 const char *op_name,
36 uint32 access_mask, POLICY_HND *hnd)
38 prs_struct rbuf;
39 prs_struct qbuf;
40 REG_Q_OPEN_HIVE q_o;
41 REG_R_OPEN_HIVE r_o;
42 WERROR result = WERR_GENERAL_FAILURE;
44 ZERO_STRUCT(q_o);
45 ZERO_STRUCT(r_o);
47 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
48 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
50 init_reg_q_open_hive(&q_o, access_mask);
52 /* Marshall the query parameters */
53 if (!reg_io_q_open_hive("", &q_o, &qbuf, 0))
54 goto done;
56 /* Send the request, receive the response */
57 if (!rpc_api_pipe_req(cli, PI_WINREG, op_code, &qbuf, &rbuf))
58 goto done;
60 /* Unmarshall the response */
61 if (!reg_io_r_open_hive("", &r_o, &rbuf, 0))
62 goto done;
64 result = r_o.status;
65 if (NT_STATUS_IS_OK(result))
66 *hnd = r_o.pol;
68 done:
69 prs_mem_free(&rbuf);
70 prs_mem_free(&qbuf);
72 return result;
76 WERROR cli_reg_shutdown(struct cli_state * cli, TALLOC_CTX *mem_ctx,
77 const char *msg, uint32 timeout, BOOL do_reboot,
78 BOOL force)
80 prs_struct qbuf;
81 prs_struct rbuf;
82 REG_Q_SHUTDOWN q_s;
83 REG_R_SHUTDOWN r_s;
84 WERROR result = WERR_GENERAL_FAILURE;
86 if (msg == NULL) return WERR_INVALID_PARAM;
88 ZERO_STRUCT (q_s);
89 ZERO_STRUCT (r_s);
91 prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
92 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
94 /* Marshall data and send request */
96 init_reg_q_shutdown(&q_s, msg, timeout, do_reboot, force);
98 if (!reg_io_q_shutdown("", &q_s, &qbuf, 0) ||
99 !rpc_api_pipe_req(cli, PI_WINREG, REG_SHUTDOWN, &qbuf, &rbuf))
100 goto done;
102 /* Unmarshall response */
104 if(reg_io_r_shutdown("", &r_s, &rbuf, 0))
105 result = r_s.status;
107 done:
108 prs_mem_free(&rbuf);
109 prs_mem_free(&qbuf);
111 return result;
115 /* Abort a server shutdown */
117 WERROR cli_reg_abort_shutdown(struct cli_state * cli, TALLOC_CTX *mem_ctx)
119 prs_struct rbuf;
120 prs_struct qbuf;
121 REG_Q_ABORT_SHUTDOWN q_s;
122 REG_R_ABORT_SHUTDOWN r_s;
123 WERROR result = WERR_GENERAL_FAILURE;
125 ZERO_STRUCT (q_s);
126 ZERO_STRUCT (r_s);
128 prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
129 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
131 /* Marshall data and send request */
133 init_reg_q_abort_shutdown(&q_s);
135 if (!reg_io_q_abort_shutdown("", &q_s, &qbuf, 0) ||
136 !rpc_api_pipe_req(cli, PI_WINREG, REG_ABORT_SHUTDOWN, &qbuf, &rbuf))
137 goto done;
139 /* Unmarshall response */
141 if (reg_io_r_abort_shutdown("", &r_s, &rbuf, 0))
142 result = r_s.status;
144 done:
145 prs_mem_free(&rbuf);
146 prs_mem_free(&qbuf );
148 return result;
151 /* connect to a registry hive root (open a registry policy) */
153 WERROR cli_reg_connect(struct cli_state *cli, TALLOC_CTX *mem_ctx,
154 uint32 reg_type, uint32 access_mask,
155 POLICY_HND *reg_hnd)
156 { uint16 op_code;
157 const char *op_name;
159 ZERO_STRUCTP(reg_hnd);
161 switch (reg_type)
163 case HKEY_CLASSES_ROOT:
164 op_code = REG_OPEN_HKCR;
165 op_name = "REG_OPEN_HKCR";
166 break;
167 case HKEY_LOCAL_MACHINE:
168 op_code = REG_OPEN_HKLM;
169 op_name = "REG_OPEN_HKLM";
170 break;
171 case HKEY_USERS:
172 op_code = REG_OPEN_HKU;
173 op_name = "REG_OPEN_HKU";
174 break;
175 case HKEY_PERFORMANCE_DATA:
176 op_code = REG_OPEN_HKPD;
177 op_name = "REG_OPEN_HKPD";
178 break;
179 default:
180 return WERR_INVALID_PARAM;
183 return cli_reg_open_hive_int(cli, mem_ctx, op_code, op_name,
184 access_mask, reg_hnd);
187 /****************************************************************************
188 do a REG Unknown 0xB command. sent after a create key or create value.
189 this might be some sort of "sync" or "refresh" command, sent after
190 modification of the registry...
191 ****************************************************************************/
192 WERROR cli_reg_flush_key(struct cli_state *cli, TALLOC_CTX *mem_ctx,
193 POLICY_HND *hnd)
195 prs_struct rbuf;
196 prs_struct qbuf;
197 REG_Q_FLUSH_KEY q_o;
198 REG_R_FLUSH_KEY r_o;
199 WERROR result = WERR_GENERAL_FAILURE;
201 prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
202 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
204 /* Marshall data and send request */
206 init_reg_q_flush_key(&q_o, hnd);
208 if (!reg_io_q_flush_key("", &q_o, &qbuf, 0) ||
209 !rpc_api_pipe_req(cli, PI_WINREG, REG_FLUSH_KEY, &qbuf, &rbuf))
210 goto done;
212 ZERO_STRUCT(r_o);
214 /* Unmarshall response */
216 if (reg_io_r_flush_key("", &r_o, &rbuf, 0))
217 result = r_o.status;
219 done:
220 prs_mem_free(&rbuf);
221 prs_mem_free(&qbuf);
223 return result;
226 /****************************************************************************
227 do a REG Query Key
228 ****************************************************************************/
229 WERROR cli_reg_query_key(struct cli_state *cli, TALLOC_CTX *mem_ctx,
230 POLICY_HND *hnd,
231 char *key_class, uint32 *class_len,
232 uint32 *num_subkeys, uint32 *max_subkeylen,
233 uint32 *max_classlen, uint32 *num_values,
234 uint32 *max_valnamelen, uint32 *max_valbufsize,
235 uint32 *sec_desc, NTTIME *mod_time)
237 prs_struct rbuf;
238 prs_struct qbuf;
239 REG_Q_QUERY_KEY q_o;
240 REG_R_QUERY_KEY r_o;
241 uint32 saved_class_len = *class_len;
242 WERROR result = WERR_GENERAL_FAILURE;
244 prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
245 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
247 /* Marshall data and send request */
249 init_reg_q_query_key( &q_o, hnd, key_class );
251 if (!reg_io_q_query_key("", &q_o, &qbuf, 0) ||
252 !rpc_api_pipe_req(cli, PI_WINREG, REG_QUERY_KEY, &qbuf, &rbuf))
253 goto done;
255 ZERO_STRUCT(r_o);
257 /* Unmarshall response */
259 if (!reg_io_r_query_key("", &r_o, &rbuf, 0))
260 goto done;
262 result = r_o.status;
263 if (NT_STATUS_EQUAL(result, ERROR_INSUFFICIENT_BUFFER)) {
264 *class_len = r_o.class.string->uni_max_len;
265 goto done;
266 } else if (!NT_STATUS_IS_OK(result))
267 goto done;
269 *class_len = r_o.class.string->uni_max_len;
270 unistr2_to_ascii(key_class, r_o.class.string, saved_class_len-1);
271 *num_subkeys = r_o.num_subkeys ;
272 *max_subkeylen = r_o.max_subkeylen ;
273 *num_values = r_o.num_values ;
274 *max_valnamelen = r_o.max_valnamelen;
275 *max_valbufsize = r_o.max_valbufsize;
276 *sec_desc = r_o.sec_desc ;
277 *mod_time = r_o.mod_time ;
278 /* Maybe: *max_classlen = r_o.reserved; */
280 done:
281 prs_mem_free(&rbuf);
282 prs_mem_free(&qbuf);
284 return result;
287 /****************************************************************************
288 do a REG Unknown 1A
289 ****************************************************************************/
290 WERROR cli_reg_getversion(struct cli_state *cli, TALLOC_CTX *mem_ctx,
291 POLICY_HND *hnd, uint32 *unk)
293 prs_struct rbuf;
294 prs_struct qbuf;
295 REG_Q_GETVERSION q_o;
296 REG_R_GETVERSION r_o;
297 WERROR result = WERR_GENERAL_FAILURE;
299 prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
300 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
302 /* Marshall data and send request */
304 init_reg_q_getversion(&q_o, hnd);
306 if (!reg_io_q_getversion("", &q_o, &qbuf, 0) ||
307 !rpc_api_pipe_req(cli, PI_WINREG, REG_GETVERSION, &qbuf, &rbuf))
308 goto done;
310 ZERO_STRUCT(r_o);
312 /* Unmarshall response */
314 if (!reg_io_r_getversion("", &r_o, &rbuf, 0))
315 goto done;
317 result = r_o.status;
318 if (NT_STATUS_IS_OK(result))
319 if (unk != NULL)
320 *unk = r_o.unknown;
322 done:
323 prs_mem_free(&rbuf);
324 prs_mem_free(&qbuf);
326 return result;
329 /****************************************************************************
330 do a REG Query Info
331 ****************************************************************************/
332 WERROR cli_reg_query_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
333 POLICY_HND *hnd, const char *val_name,
334 uint32 *type, REGVAL_BUFFER *buffer)
336 prs_struct rbuf;
337 prs_struct qbuf;
338 REG_Q_INFO q_o;
339 REG_R_INFO r_o;
340 WERROR result = WERR_GENERAL_FAILURE;
342 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
343 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
345 /* Marshall data and send request */
347 init_reg_q_info(&q_o, hnd, val_name, buffer);
349 if (!reg_io_q_info("", &q_o, &qbuf, 0) ||
350 !rpc_api_pipe_req(cli, PI_WINREG, REG_INFO, &qbuf, &rbuf))
351 goto done;
353 ZERO_STRUCT(r_o);
355 /* Unmarshall response */
357 if (!reg_io_r_info("", &r_o, &rbuf, 0))
358 goto done;
360 result = r_o.status;
361 if (NT_STATUS_IS_OK(result)) {
362 *type = *r_o.type;
363 *buffer = *r_o.value;
366 done:
367 prs_mem_free(&rbuf);
368 prs_mem_free(&qbuf);
370 return result;
373 /****************************************************************************
374 do a REG Set Key Security
375 ****************************************************************************/
376 WERROR cli_reg_set_key_sec(struct cli_state *cli, TALLOC_CTX *mem_ctx,
377 POLICY_HND *hnd, uint32 sec_info,
378 size_t secdesc_size, SEC_DESC *sec_desc)
380 prs_struct rbuf;
381 prs_struct qbuf;
382 REG_Q_SET_KEY_SEC q_o;
383 REG_R_SET_KEY_SEC r_o;
384 SEC_DESC_BUF *sec_desc_buf;
385 WERROR result = WERR_GENERAL_FAILURE;
388 * Flatten the security descriptor.
390 sec_desc_buf = make_sec_desc_buf(mem_ctx, secdesc_size, sec_desc);
391 if (sec_desc_buf == NULL)
392 goto done;
394 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
395 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
397 /* Marshall data and send request */
399 init_reg_q_set_key_sec(&q_o, hnd, sec_info, sec_desc_buf);
401 if (!reg_io_q_set_key_sec("", &q_o, &qbuf, 0) ||
402 !rpc_api_pipe_req(cli, PI_WINREG, REG_SET_KEY_SEC, &qbuf, &rbuf))
403 goto done;
405 ZERO_STRUCT(r_o);
407 /* Unmarshall response */
409 if (reg_io_r_set_key_sec("", &r_o, &rbuf, 0))
410 result = r_o.status;
412 done:
413 prs_mem_free(&rbuf);
414 prs_mem_free(&qbuf);
416 return result;
420 /****************************************************************************
421 do a REG Query Key Security
422 ****************************************************************************/
423 WERROR cli_reg_get_key_sec(struct cli_state *cli, TALLOC_CTX *mem_ctx,
424 POLICY_HND *hnd, uint32 sec_info,
425 uint32 *sec_buf_size, SEC_DESC_BUF *sec_buf)
427 prs_struct rbuf;
428 prs_struct qbuf;
429 REG_Q_GET_KEY_SEC q_o;
430 REG_R_GET_KEY_SEC r_o;
431 WERROR result = WERR_GENERAL_FAILURE;
433 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
434 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
436 /* Marshall data and send request */
438 init_reg_q_get_key_sec(&q_o, hnd, sec_info, *sec_buf_size, sec_buf);
440 if (!reg_io_q_get_key_sec("", &q_o, &qbuf, 0) ||
441 !rpc_api_pipe_req(cli, PI_WINREG, REG_GET_KEY_SEC, &qbuf, &rbuf))
442 goto done;
444 ZERO_STRUCT(r_o);
446 /* Unmarshall response */
448 r_o.data = sec_buf;
450 if (*sec_buf_size != 0)
452 sec_buf->sec = (SEC_DESC*)talloc(mem_ctx, *sec_buf_size);
455 if (!reg_io_r_get_key_sec("", &r_o, &rbuf, 0))
456 goto done;
458 result = r_o.status;
459 if (NT_STATUS_IS_OK(result))
460 (*sec_buf_size) = r_o.data->len;
461 else if (NT_STATUS_EQUAL(result, ERROR_INSUFFICIENT_BUFFER))
464 * get the maximum buffer size: it was too small
466 (*sec_buf_size) = r_o.hdr_sec.buf_max_len;
469 done:
470 prs_mem_free(&rbuf);
471 prs_mem_free(&qbuf);
473 return result;
476 /****************************************************************************
477 do a REG Delete Value
478 ****************************************************************************/
479 WERROR cli_reg_delete_val(struct cli_state *cli, TALLOC_CTX *mem_ctx,
480 POLICY_HND *hnd, char *val_name)
482 prs_struct rbuf;
483 prs_struct qbuf;
484 REG_Q_DELETE_VALUE q_o;
485 REG_R_DELETE_VALUE r_o;
486 WERROR result = WERR_GENERAL_FAILURE;
488 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
489 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
491 /* Marshall data and send request */
493 init_reg_q_delete_val(&q_o, hnd, val_name);
495 if (!reg_io_q_delete_val("", &q_o, &qbuf, 0) ||
496 !rpc_api_pipe_req(cli, PI_WINREG, REG_DELETE_VALUE, &qbuf, &rbuf))
497 goto done;
499 ZERO_STRUCT(r_o);
501 /* Unmarshall response */
503 if (reg_io_r_delete_val("", &r_o, &rbuf, 0))
504 result = r_o.status;
506 done:
507 prs_mem_free(&rbuf);
508 prs_mem_free(&qbuf);
510 return result;
513 /****************************************************************************
514 do a REG Delete Key
515 ****************************************************************************/
516 WERROR cli_reg_delete_key(struct cli_state *cli, TALLOC_CTX *mem_ctx,
517 POLICY_HND *hnd, char *key_name)
519 prs_struct rbuf;
520 prs_struct qbuf;
521 REG_Q_DELETE_KEY q_o;
522 REG_R_DELETE_KEY r_o;
523 WERROR result = WERR_GENERAL_FAILURE;
525 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
526 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
528 /* Marshall data and send request */
530 init_reg_q_delete_key(&q_o, hnd, key_name);
532 if (!reg_io_q_delete_key("", &q_o, &qbuf, 0) ||
533 !rpc_api_pipe_req(cli, PI_WINREG, REG_DELETE_KEY, &qbuf, &rbuf))
534 goto done;
536 ZERO_STRUCT(r_o);
538 /* Unmarshall response */
540 if (reg_io_r_delete_key("", &r_o, &rbuf, 0))
541 result = r_o.status;
543 done:
544 prs_mem_free(&rbuf);
545 prs_mem_free(&qbuf);
547 return result;
550 /****************************************************************************
551 do a REG Create Key
552 ****************************************************************************/
553 WERROR cli_reg_create_key(struct cli_state *cli, TALLOC_CTX *mem_ctx,
554 POLICY_HND *hnd, char *key_name, char *key_class,
555 uint32 access_desired, POLICY_HND *key)
557 prs_struct rbuf;
558 prs_struct qbuf;
559 REG_Q_CREATE_KEY q_o;
560 REG_R_CREATE_KEY r_o;
561 SEC_DESC *sec;
562 SEC_DESC_BUF *sec_buf;
563 size_t sec_len;
564 WERROR result = WERR_GENERAL_FAILURE;
566 ZERO_STRUCT(q_o);
568 if ((sec = make_sec_desc(mem_ctx, 1, SEC_DESC_SELF_RELATIVE,
569 NULL, NULL, NULL, NULL, &sec_len)) == NULL)
570 goto done;
572 if ((sec_buf = make_sec_desc_buf(mem_ctx, sec_len, sec)) == NULL)
573 goto done;
575 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
576 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
578 /* Marshall data and send request */
580 init_reg_q_create_key(&q_o, hnd, key_name, key_class, access_desired, sec_buf);
582 if (!reg_io_q_create_key("", &q_o, &qbuf, 0) ||
583 !rpc_api_pipe_req(cli, PI_WINREG, REG_CREATE_KEY, &qbuf, &rbuf))
584 goto done;
586 ZERO_STRUCT(r_o);
588 /* Unmarshall response */
590 if (!reg_io_r_create_key("", &r_o, &rbuf, 0))
591 goto done;
593 result = r_o.status;
594 if (NT_STATUS_IS_OK(result))
595 *key = r_o.key_pol;
597 done:
598 prs_mem_free(&rbuf);
599 prs_mem_free(&qbuf);
601 return result;
604 /****************************************************************************
605 do a REG Enum Key
606 ****************************************************************************/
607 WERROR cli_reg_enum_key(struct cli_state *cli, TALLOC_CTX *mem_ctx,
608 POLICY_HND *hnd, int key_index, fstring key_name,
609 uint32 *unk_1, uint32 *unk_2, time_t *mod_time)
611 prs_struct rbuf;
612 prs_struct qbuf;
613 REG_Q_ENUM_KEY q_o;
614 REG_R_ENUM_KEY r_o;
615 WERROR result = WERR_GENERAL_FAILURE;
617 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
618 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
620 /* Marshall data and send request */
622 init_reg_q_enum_key(&q_o, hnd, key_index);
624 if (!reg_io_q_enum_key("", &q_o, &qbuf, 0) ||
625 !rpc_api_pipe_req(cli, PI_WINREG, REG_ENUM_KEY, &qbuf, &rbuf))
626 goto done;
628 ZERO_STRUCT(r_o);
630 /* Unmarshall response */
632 if (!reg_io_r_enum_key("", &r_o, &rbuf, 0))
633 goto done;
635 result = r_o.status;
636 if (NT_STATUS_IS_OK(result)) {
637 (*unk_1) = r_o.unknown_1;
638 (*unk_2) = r_o.unknown_2;
639 unistr3_to_ascii(key_name, &r_o.key_name,
640 sizeof(fstring)-1);
641 (*mod_time) = nt_time_to_unix(&r_o.time);
644 done:
645 prs_mem_free(&rbuf);
646 prs_mem_free(&qbuf);
648 return result;
651 /****************************************************************************
652 do a REG Create Value
653 ****************************************************************************/
654 WERROR cli_reg_set_val(struct cli_state *cli, TALLOC_CTX *mem_ctx,
655 POLICY_HND *hnd, char *val_name, uint32 type,
656 RPC_DATA_BLOB *data)
658 prs_struct rbuf;
659 prs_struct qbuf;
660 REG_Q_SET_VALUE q_o;
661 REG_R_SET_VALUE r_o;
662 WERROR result = WERR_GENERAL_FAILURE;
664 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
665 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
667 /* Marshall data and send request */
669 init_reg_q_set_val(&q_o, hnd, val_name, type, data);
671 if (!reg_io_q_set_val("", &q_o, &qbuf, 0) ||
672 !rpc_api_pipe_req(cli, PI_WINREG, REG_SET_VALUE, &qbuf, &rbuf))
673 goto done;
675 ZERO_STRUCT(r_o);
677 /* Unmarshal response */
679 if (reg_io_r_set_val("", &r_o, &rbuf, 0))
680 result = r_o.status;
682 done:
683 prs_mem_free(&rbuf);
684 prs_mem_free(&qbuf);
686 return result;
689 /****************************************************************************
690 do a REG Enum Value
691 ****************************************************************************/
692 WERROR cli_reg_enum_val(struct cli_state *cli, TALLOC_CTX *mem_ctx,
693 POLICY_HND *hnd, int val_index, int max_valnamelen,
694 int max_valbufsize, fstring val_name,
695 uint32 *val_type, REGVAL_BUFFER *value)
697 prs_struct rbuf;
698 prs_struct qbuf;
699 REG_Q_ENUM_VALUE q_o;
700 REG_R_ENUM_VALUE r_o;
701 WERROR result = WERR_GENERAL_FAILURE;
703 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
704 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
706 /* Marshall data and send request */
708 init_reg_q_enum_val(&q_o, hnd, val_index, val_name, max_valbufsize);
710 if (!reg_io_q_enum_val("", &q_o, &qbuf, 0) ||
711 !rpc_api_pipe_req(cli, PI_WINREG, REG_ENUM_VALUE, &qbuf, &rbuf))
712 goto done;
714 ZERO_STRUCT(r_o);
716 /* Unmarshall response */
718 if (!reg_io_r_enum_val("", &r_o, &rbuf, 0))
719 goto done;
721 result = r_o.status;
722 if (NT_STATUS_IS_OK(result) ||
723 NT_STATUS_EQUAL(result, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
724 (*val_type) = *r_o.type;
725 unistr2_to_ascii(val_name, r_o.name.string, sizeof(fstring)-1);
726 *value = *r_o.value;
729 done:
730 prs_mem_free(&rbuf);
731 prs_mem_free(&qbuf);
733 return result;
736 /****************************************************************************
737 do a REG Open Key
738 ****************************************************************************/
739 WERROR cli_reg_open_entry(struct cli_state *cli, TALLOC_CTX *mem_ctx,
740 POLICY_HND *hnd, char *key_name,
741 uint32 access_desired, POLICY_HND *key_hnd)
743 prs_struct rbuf;
744 prs_struct qbuf;
745 REG_Q_OPEN_ENTRY q_o;
746 REG_R_OPEN_ENTRY r_o;
747 WERROR result = WERR_GENERAL_FAILURE;
749 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
750 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
752 /* Marshall data and send request */
754 init_reg_q_open_entry(&q_o, hnd, key_name, access_desired);
756 /* turn parameters into data stream */
757 if (!reg_io_q_open_entry("", &q_o, &qbuf, 0) ||
758 !rpc_api_pipe_req(cli, PI_WINREG, REG_OPEN_ENTRY, &qbuf, &rbuf))
759 goto done;
761 ZERO_STRUCT(r_o);
763 /* Unmarsall response */
765 if (!reg_io_r_open_entry("", &r_o, &rbuf, 0))
766 goto done;
768 result = r_o.status;
769 if (NT_STATUS_IS_OK(result))
770 *key_hnd = r_o.pol;
772 done:
773 prs_mem_free(&rbuf);
774 prs_mem_free(&qbuf);
776 return result;
779 /****************************************************************************
780 do a REG Close
781 ****************************************************************************/
782 WERROR cli_reg_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
783 POLICY_HND *hnd)
785 prs_struct rbuf;
786 prs_struct qbuf;
787 REG_Q_CLOSE q_c;
788 REG_R_CLOSE r_c;
789 WERROR result = WERR_GENERAL_FAILURE;
791 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
792 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
794 /* Marshall data and send request */
796 init_reg_q_close(&q_c, hnd);
798 if (!reg_io_q_close("", &q_c, &qbuf, 0) ||
799 !rpc_api_pipe_req(cli, PI_WINREG, REG_CLOSE, &qbuf, &rbuf))
800 goto done;
802 ZERO_STRUCT(r_c);
804 /* Unmarshall response */
806 if (reg_io_r_close("", &r_c, &rbuf, 0))
807 result = r_c.status;
809 done:
810 prs_mem_free(&rbuf);
811 prs_mem_free(&qbuf);
813 return result;