2 * Unix SMB/CIFS implementation.
4 * SPOOLSS RPC Pipe server / winreg client routines
6 * Copyright (c) 2010 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "srv_spoolss_util.h"
24 #include "../librpc/gen_ndr/srv_winreg.h"
25 #include "../librpc/gen_ndr/cli_winreg.h"
30 * @brief Connect to the interal winreg server and open the given printer key.
32 * The function will create the needed subkeys if they don't exist.
34 * @param[in] mem_ctx The memory context to use.
36 * @param[in] server_info The supplied server info.
38 * @param[out] winreg_pipe A pointer for the winreg rpc client pipe.
40 * @param[in] name The name of the printer.
42 * @param[in] key The key to open.
44 * @param[in] create_key Set to true if the key should be created if it
47 * @param[in] access_mask The access mask to open the key.
49 * @param[out] hive_handle A policy handle for the opened hive.
51 * @param[out] key_handle A policy handle for the opened key.
53 * @return WERR_OK on success, the corresponding DOS error
54 * code if something gone wrong.
56 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
57 struct auth_serversupplied_info *server_info,
58 struct rpc_pipe_client **winreg_pipe,
63 struct policy_handle *hive_handle,
64 struct policy_handle *key_handle)
66 struct rpc_pipe_client *pipe_handle;
67 struct winreg_String wkey, wkeyclass;
70 WERROR result = WERR_OK;
72 /* create winreg connection */
73 status = rpc_pipe_open_internal(mem_ctx,
74 &ndr_table_winreg.syntax_id,
78 if (!NT_STATUS_IS_OK(status)) {
79 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg_pipe: %s\n",
81 return ntstatus_to_werror(status);
84 status = rpccli_winreg_OpenHKLM(pipe_handle,
90 if (!NT_STATUS_IS_OK(status)) {
91 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
93 talloc_free(pipe_handle);
94 if (!W_ERROR_IS_OK(result)) {
97 return ntstatus_to_werror(status);
101 keyname = talloc_asprintf(mem_ctx,
102 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers\\%s\\%s",
106 keyname = talloc_asprintf(mem_ctx,
107 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers\\%s",
110 if (keyname == NULL) {
111 talloc_free(pipe_handle);
119 enum winreg_CreateAction action = REG_ACTION_NONE;
121 ZERO_STRUCT(wkeyclass);
124 status = rpccli_winreg_CreateKey(pipe_handle,
136 case REG_ACTION_NONE:
137 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
139 case REG_CREATED_NEW_KEY:
140 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
142 case REG_OPENED_EXISTING_KEY:
143 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
147 status = rpccli_winreg_OpenKey(pipe_handle,
156 if (!NT_STATUS_IS_OK(status)) {
157 talloc_free(pipe_handle);
158 if (!W_ERROR_IS_OK(result)) {
161 return ntstatus_to_werror(status);
164 *winreg_pipe = pipe_handle;