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"
27 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
28 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
29 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
30 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
32 /* FLAGS, NAME, with, height, left, top, right, bottom */
33 static const struct spoolss_FormInfo1 builtin_forms1[] = {
34 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
35 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
36 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
37 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
38 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
39 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
40 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
41 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
42 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
43 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
44 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
45 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
46 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
47 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
48 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
49 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
50 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
51 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
52 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
53 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
54 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
55 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
56 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
57 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
58 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
59 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
60 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
61 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
62 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
63 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
64 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
65 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
66 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
67 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
68 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
69 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
70 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
71 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
72 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} },
73 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
74 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
75 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
76 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
77 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
78 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
79 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
80 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
81 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
82 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
83 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
84 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
85 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
86 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
87 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
88 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
89 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
90 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
91 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
92 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
93 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
94 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
95 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
96 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
97 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
98 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
99 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
100 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
101 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
102 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
103 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
104 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
105 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
106 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
107 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
108 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
109 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
110 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
111 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
112 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
113 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
114 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
115 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
116 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
117 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
118 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
119 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
120 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
121 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
122 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
123 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
124 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
125 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
126 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
127 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
128 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
129 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
130 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
131 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
132 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
133 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
134 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
135 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
136 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
137 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
138 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
139 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
140 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
141 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
142 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
143 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
144 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
145 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
146 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
147 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
148 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
149 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
150 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} }
154 /********************************************************************
155 static helper functions
156 ********************************************************************/
161 * @brief Connect to the interal winreg server and open the given printer key.
163 * The function will create the needed subkeys if they don't exist.
165 * @param[in] mem_ctx The memory context to use.
167 * @param[in] server_info The supplied server info.
169 * @param[out] winreg_pipe A pointer for the winreg rpc client pipe.
171 * @param[in] path The path to the key to open.
173 * @param[in] key The key to open.
175 * @param[in] create_key Set to true if the key should be created if it
178 * @param[in] access_mask The access mask to open the key.
180 * @param[out] hive_handle A policy handle for the opened hive.
182 * @param[out] key_handle A policy handle for the opened key.
184 * @return WERR_OK on success, the corresponding DOS error
185 * code if something gone wrong.
187 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
188 struct auth_serversupplied_info *server_info,
189 struct rpc_pipe_client **winreg_pipe,
193 uint32_t access_mask,
194 struct policy_handle *hive_handle,
195 struct policy_handle *key_handle)
197 struct rpc_pipe_client *pipe_handle;
198 struct winreg_String wkey, wkeyclass;
201 WERROR result = WERR_OK;
203 /* create winreg connection */
204 status = rpc_pipe_open_internal(mem_ctx,
205 &ndr_table_winreg.syntax_id,
209 if (!NT_STATUS_IS_OK(status)) {
210 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg_pipe: %s\n",
212 return ntstatus_to_werror(status);
215 status = rpccli_winreg_OpenHKLM(pipe_handle,
221 if (!NT_STATUS_IS_OK(status)) {
222 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
224 talloc_free(pipe_handle);
225 if (!W_ERROR_IS_OK(result)) {
228 return ntstatus_to_werror(status);
232 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
234 keyname = talloc_strdup(mem_ctx, path);
236 if (keyname == NULL) {
237 talloc_free(pipe_handle);
245 enum winreg_CreateAction action = REG_ACTION_NONE;
247 ZERO_STRUCT(wkeyclass);
250 status = rpccli_winreg_CreateKey(pipe_handle,
262 case REG_ACTION_NONE:
263 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
265 case REG_CREATED_NEW_KEY:
266 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
268 case REG_OPENED_EXISTING_KEY:
269 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
273 status = rpccli_winreg_OpenKey(pipe_handle,
282 if (!NT_STATUS_IS_OK(status)) {
283 talloc_free(pipe_handle);
284 if (!W_ERROR_IS_OK(result)) {
287 return ntstatus_to_werror(status);
290 *winreg_pipe = pipe_handle;
296 * @brief Create the registry keyname for the given printer.
298 * @param[in] mem_ctx The memory context to use.
300 * @param[in] printer The name of the printer to get the registry key.
302 * @return The registry key or NULL on error.
304 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
305 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
311 * @brief Enumerate values of an opened key handle and retrieve the data.
313 * @param[in] mem_ctx The memory context to use.
315 * @param[in] pipe_handle The pipe handle for the rpc connection.
317 * @param[in] key_hnd The opened key handle.
319 * @param[out] pnum_values A pointer to store he number of values found.
321 * @param[out] pnum_values A pointer to store the number of values we found.
323 * @return WERR_OK on success, the corresponding DOS error
324 * code if something gone wrong.
326 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
327 struct rpc_pipe_client *pipe_handle,
328 struct policy_handle *key_hnd,
329 uint32_t *pnum_values,
330 struct spoolss_PrinterEnumValues **penum_values)
333 uint32_t num_subkeys, max_subkeylen, max_classlen;
334 uint32_t num_values, max_valnamelen, max_valbufsize;
335 uint32_t secdescsize;
337 NTTIME last_changed_time;
338 struct winreg_String classname;
340 struct spoolss_PrinterEnumValues *enum_values;
342 WERROR result = WERR_OK;
345 tmp_ctx = talloc_new(mem_ctx);
346 if (tmp_ctx == NULL) {
350 ZERO_STRUCT(classname);
352 status = rpccli_winreg_QueryInfoKey(pipe_handle,
365 if (!NT_STATUS_IS_OK(status)) {
366 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
368 if (!W_ERROR_IS_OK(result)) {
371 result = ntstatus_to_werror(status);
375 if (num_values == 0) {
377 TALLOC_FREE(tmp_ctx);
381 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
382 if (enum_values == NULL) {
387 for (i = 0; i < num_values; i++) {
388 struct spoolss_PrinterEnumValues val;
389 struct winreg_ValNameBuf name_buf;
390 enum winreg_Type type = REG_NONE;
391 uint8_t *data = NULL;
397 name_buf.size = max_valnamelen + 2;
400 data_size = max_valbufsize;
401 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
404 status = rpccli_winreg_EnumValue(pipe_handle,
414 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
416 status = NT_STATUS_OK;
420 if (!NT_STATUS_IS_OK(status)) {
421 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
423 if (!W_ERROR_IS_OK(result)) {
426 result = ntstatus_to_werror(status);
430 if (name_buf.name == NULL) {
431 result = WERR_INVALID_PARAMETER;
435 val.value_name = talloc_strdup(enum_values, name_buf.name);
436 if (val.value_name == NULL) {
440 val.value_name_len = strlen_m_term(val.value_name) * 2;
443 val.data_length = data_size;
445 if (val.data_length) {
446 val.data = talloc(enum_values, DATA_BLOB);
447 if (val.data == NULL) {
451 *val.data = data_blob_talloc(enum_values, data, data_size);
454 enum_values[i] = val;
457 *pnum_values = num_values;
459 *penum_values = talloc_move(mem_ctx, &enum_values);
465 TALLOC_FREE(tmp_ctx);
472 * @brief Enumerate subkeys of an opened key handle and get the names.
474 * @param[in] mem_ctx The memory context to use.
476 * @param[in] pipe_handle The pipe handle for the rpc connection.
478 * @param[in] key_hnd The opened key handle.
480 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
482 * @param[in] psubkeys A pointer to an array to store the found names of
485 * @return WERR_OK on success, the corresponding DOS error
486 * code if something gone wrong.
488 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
489 struct rpc_pipe_client *pipe_handle,
490 struct policy_handle *key_hnd,
491 uint32_t *pnum_subkeys,
492 const char ***psubkeys)
495 const char **subkeys;
496 uint32_t num_subkeys, max_subkeylen, max_classlen;
497 uint32_t num_values, max_valnamelen, max_valbufsize;
499 NTTIME last_changed_time;
500 uint32_t secdescsize;
501 struct winreg_String classname;
502 WERROR result = WERR_OK;
505 tmp_ctx = talloc_new(mem_ctx);
506 if (tmp_ctx == NULL) {
510 ZERO_STRUCT(classname);
512 status = rpccli_winreg_QueryInfoKey(pipe_handle,
525 if (!NT_STATUS_IS_OK(status)) {
526 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
528 if (!W_ERROR_IS_OK(result)) {
531 result = ntstatus_to_werror(status);
535 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
536 if (subkeys == NULL) {
541 if (num_subkeys == 0) {
542 subkeys[0] = talloc_strdup(subkeys, "");
543 if (subkeys[0] == NULL) {
549 *psubkeys = talloc_move(mem_ctx, &subkeys);
552 TALLOC_FREE(tmp_ctx);
556 for (i = 0; i < num_subkeys; i++) {
560 struct winreg_StringBuf class_buf;
561 struct winreg_StringBuf name_buf;
565 class_buf.size = max_classlen + 2;
566 class_buf.length = 0;
569 name_buf.size = max_subkeylen + 2;
572 ZERO_STRUCT(modtime);
574 status = rpccli_winreg_EnumKey(pipe_handle,
582 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
584 status = NT_STATUS_OK;
588 if (!NT_STATUS_IS_OK(status)) {
589 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
591 if (!W_ERROR_IS_OK(result)) {
594 result = ntstatus_to_werror(status);
598 if (name_buf.name == NULL) {
599 result = WERR_INVALID_PARAMETER;
603 name = talloc_strdup(subkeys, name_buf.name);
612 *pnum_subkeys = num_subkeys;
614 *psubkeys = talloc_move(mem_ctx, &subkeys);
618 TALLOC_FREE(tmp_ctx);
625 * @brief A function to delete a key and its subkeys recurively.
627 * @param[in] mem_ctx The memory context to use.
629 * @param[in] pipe_handle The pipe handle for the rpc connection.
631 * @param[in] hive_handle A opened hive handle to the key.
633 * @param[in] access_mask The access mask to access the key.
635 * @param[in] key The key to delete
637 * @return WERR_OK on success, the corresponding DOS error
638 * code if something gone wrong.
640 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
641 struct rpc_pipe_client *pipe_handle,
642 struct policy_handle *hive_handle,
643 uint32_t access_mask,
646 const char **subkeys = NULL;
647 uint32_t num_subkeys = 0;
648 struct policy_handle key_hnd;
649 struct winreg_String wkey;
650 WERROR result = WERR_OK;
654 ZERO_STRUCT(key_hnd);
657 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
659 status = rpccli_winreg_OpenKey(pipe_handle,
667 if (!NT_STATUS_IS_OK(status)) {
668 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
669 wkey.name, nt_errstr(status)));
670 if (!W_ERROR_IS_OK(result)) {
673 return ntstatus_to_werror(status);
676 result = winreg_printer_enumkeys(mem_ctx,
681 if (!W_ERROR_IS_OK(result)) {
685 for (i = 0; i < num_subkeys; i++) {
686 /* create key + subkey */
687 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
688 if (subkey == NULL) {
692 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
693 result = winreg_printer_delete_subkeys(mem_ctx,
698 if (!W_ERROR_IS_OK(result)) {
703 if (is_valid_policy_hnd(&key_hnd)) {
704 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
709 status = rpccli_winreg_DeleteKey(pipe_handle,
716 if (is_valid_policy_hnd(&key_hnd)) {
717 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
723 /********************************************************************
724 Public winreg function for spoolss
725 ********************************************************************/
727 /* Set printer data over the winreg pipe. */
728 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
729 struct auth_serversupplied_info *server_info,
733 enum winreg_Type type,
737 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
738 struct rpc_pipe_client *winreg_pipe = NULL;
739 struct policy_handle hive_hnd, key_hnd;
740 struct winreg_String wvalue;
742 WERROR result = WERR_OK;
746 tmp_ctx = talloc_new(mem_ctx);
747 if (tmp_ctx == NULL) {
751 path = winreg_printer_data_keyname(tmp_ctx, printer);
753 TALLOC_FREE(tmp_ctx);
757 ZERO_STRUCT(hive_hnd);
758 ZERO_STRUCT(key_hnd);
760 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
761 key, value, access_mask, printer));
762 result = winreg_printer_openkey(tmp_ctx,
771 if (!W_ERROR_IS_OK(result)) {
772 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
773 key, win_errstr(result)));
778 status = rpccli_winreg_SetValue(winreg_pipe,
786 if (!NT_STATUS_IS_OK(status)) {
787 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
788 value, nt_errstr(status)));
789 if (!W_ERROR_IS_OK(result)) {
792 result = ntstatus_to_werror(status);
798 if (winreg_pipe != NULL) {
799 if (is_valid_policy_hnd(&key_hnd)) {
800 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
802 if (is_valid_policy_hnd(&hive_hnd)) {
803 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
807 TALLOC_FREE(tmp_ctx);
811 /* Get printer data over a winreg pipe. */
812 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
813 struct auth_serversupplied_info *server_info,
817 enum winreg_Type *type,
821 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
822 struct rpc_pipe_client *winreg_pipe = NULL;
823 struct policy_handle hive_hnd, key_hnd;
824 struct winreg_String wvalue;
825 enum winreg_Type type_in;
828 uint32_t data_in_size = 0;
829 uint32_t value_len = 0;
830 WERROR result = WERR_OK;
834 tmp_ctx = talloc_new(mem_ctx);
835 if (tmp_ctx == NULL) {
839 path = winreg_printer_data_keyname(tmp_ctx, printer);
841 TALLOC_FREE(tmp_ctx);
845 ZERO_STRUCT(hive_hnd);
846 ZERO_STRUCT(key_hnd);
848 result = winreg_printer_openkey(tmp_ctx,
857 if (!W_ERROR_IS_OK(result)) {
858 DEBUG(0, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
859 key, win_errstr(result)));
866 * call QueryValue once with data == NULL to get the
867 * needed memory size to be allocated, then allocate
868 * data buffer and call again.
870 status = rpccli_winreg_QueryValue(winreg_pipe,
879 if (!NT_STATUS_IS_OK(status)) {
880 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
881 value, nt_errstr(status)));
882 if (!W_ERROR_IS_OK(result)) {
885 result = ntstatus_to_werror(status);
889 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
890 if (data_in == NULL) {
896 status = rpccli_winreg_QueryValue(winreg_pipe,
905 if (!NT_STATUS_IS_OK(status)) {
906 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
907 value, nt_errstr(status)));
908 if (!W_ERROR_IS_OK(result)) {
909 result = ntstatus_to_werror(status);
915 *data_size = data_in_size;
917 *data = talloc_move(mem_ctx, &data_in);
922 if (winreg_pipe != NULL) {
923 if (is_valid_policy_hnd(&key_hnd)) {
924 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
926 if (is_valid_policy_hnd(&hive_hnd)) {
927 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
931 TALLOC_FREE(tmp_ctx);
935 /* Enumerate on the values of a given key and provide the data. */
936 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
937 struct auth_serversupplied_info *server_info,
940 uint32_t *pnum_values,
941 struct spoolss_PrinterEnumValues **penum_values)
943 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
944 struct rpc_pipe_client *winreg_pipe = NULL;
945 struct policy_handle hive_hnd, key_hnd;
947 struct spoolss_PrinterEnumValues *enum_values = NULL;
948 uint32_t num_values = 0;
950 WERROR result = WERR_OK;
954 tmp_ctx = talloc_new(mem_ctx);
955 if (tmp_ctx == NULL) {
959 path = winreg_printer_data_keyname(tmp_ctx, printer);
961 TALLOC_FREE(tmp_ctx);
965 result = winreg_printer_openkey(tmp_ctx,
974 if (!W_ERROR_IS_OK(result)) {
975 DEBUG(0, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
976 key, win_errstr(result)));
980 result = winreg_printer_enumvalues(tmp_ctx,
985 if (!W_ERROR_IS_OK(result)) {
986 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
987 key, win_errstr(result)));
991 *pnum_values = num_values;
993 *penum_values = talloc_move(mem_ctx, &enum_values);
998 if (winreg_pipe != NULL) {
999 if (is_valid_policy_hnd(&key_hnd)) {
1000 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1002 if (is_valid_policy_hnd(&hive_hnd)) {
1003 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1007 TALLOC_FREE(tmp_ctx);
1011 /* Delete printer data over a winreg pipe. */
1012 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
1013 struct auth_serversupplied_info *server_info,
1014 const char *printer,
1018 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1019 struct rpc_pipe_client *winreg_pipe = NULL;
1020 struct policy_handle hive_hnd, key_hnd;
1021 struct winreg_String wvalue;
1023 WERROR result = WERR_OK;
1026 TALLOC_CTX *tmp_ctx;
1028 tmp_ctx = talloc_new(mem_ctx);
1029 if (tmp_ctx == NULL) {
1033 path = winreg_printer_data_keyname(tmp_ctx, printer);
1035 TALLOC_FREE(tmp_ctx);
1039 ZERO_STRUCT(hive_hnd);
1040 ZERO_STRUCT(key_hnd);
1042 result = winreg_printer_openkey(tmp_ctx,
1051 if (!W_ERROR_IS_OK(result)) {
1052 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
1053 key, win_errstr(result)));
1057 wvalue.name = value;
1058 status = rpccli_winreg_DeleteValue(winreg_pipe,
1063 if (!NT_STATUS_IS_OK(status)) {
1064 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
1065 value, nt_errstr(status)));
1066 if (!W_ERROR_IS_OK(result)) {
1069 result = ntstatus_to_werror(status);
1075 if (winreg_pipe != NULL) {
1076 if (is_valid_policy_hnd(&key_hnd)) {
1077 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1079 if (is_valid_policy_hnd(&hive_hnd)) {
1080 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1084 TALLOC_FREE(tmp_ctx);
1088 /* Enumerate on the subkeys of a given key and provide the data. */
1089 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
1090 struct auth_serversupplied_info *server_info,
1091 const char *printer,
1093 uint32_t *pnum_subkeys,
1094 const char ***psubkeys)
1096 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1097 struct rpc_pipe_client *winreg_pipe = NULL;
1098 struct policy_handle hive_hnd, key_hnd;
1100 const char **subkeys = NULL;
1101 uint32_t num_subkeys = -1;
1103 WERROR result = WERR_OK;
1105 TALLOC_CTX *tmp_ctx;
1107 tmp_ctx = talloc_new(mem_ctx);
1108 if (tmp_ctx == NULL) {
1112 path = winreg_printer_data_keyname(tmp_ctx, printer);
1114 TALLOC_FREE(tmp_ctx);
1118 ZERO_STRUCT(hive_hnd);
1119 ZERO_STRUCT(key_hnd);
1121 result = winreg_printer_openkey(tmp_ctx,
1130 if (!W_ERROR_IS_OK(result)) {
1131 DEBUG(0, ("winreg_enum_printer_key: Could not open key %s: %s\n",
1132 key, win_errstr(result)));
1136 result = winreg_printer_enumkeys(tmp_ctx,
1141 if (!W_ERROR_IS_OK(result)) {
1142 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
1143 key, win_errstr(result)));
1147 *pnum_subkeys = num_subkeys;
1149 *psubkeys = talloc_move(mem_ctx, &subkeys);
1154 if (winreg_pipe != NULL) {
1155 if (is_valid_policy_hnd(&key_hnd)) {
1156 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1158 if (is_valid_policy_hnd(&hive_hnd)) {
1159 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1163 TALLOC_FREE(tmp_ctx);
1167 /* Delete a key with subkeys of a given printer. */
1168 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
1169 struct auth_serversupplied_info *server_info,
1170 const char *printer,
1173 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1174 struct rpc_pipe_client *winreg_pipe = NULL;
1175 struct policy_handle hive_hnd, key_hnd;
1179 TALLOC_CTX *tmp_ctx;
1181 tmp_ctx = talloc_new(mem_ctx);
1182 if (tmp_ctx == NULL) {
1186 path = winreg_printer_data_keyname(tmp_ctx, printer);
1188 TALLOC_FREE(tmp_ctx);
1192 result = winreg_printer_openkey(tmp_ctx,
1201 if (!W_ERROR_IS_OK(result)) {
1202 /* key doesn't exist */
1203 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1208 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
1209 key, win_errstr(result)));
1213 if (is_valid_policy_hnd(&key_hnd)) {
1214 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1217 keyname = talloc_asprintf(tmp_ctx,
1221 if (keyname == NULL) {
1222 result = WERR_NOMEM;
1226 result = winreg_printer_delete_subkeys(tmp_ctx,
1231 if (!W_ERROR_IS_OK(result)) {
1232 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
1233 key, win_errstr(result)));
1238 if (winreg_pipe != NULL) {
1239 if (is_valid_policy_hnd(&key_hnd)) {
1240 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1242 if (is_valid_policy_hnd(&hive_hnd)) {
1243 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1247 TALLOC_FREE(tmp_ctx);
1252 * The special behaviour of the spoolss forms is documented at the website:
1254 * Managing Win32 Printserver Forms
1255 * http://unixwiz.net/techtips/winspooler-forms.html
1258 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
1259 struct auth_serversupplied_info *server_info,
1260 struct spoolss_AddFormInfo1 *form)
1262 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1263 struct rpc_pipe_client *winreg_pipe = NULL;
1264 struct policy_handle hive_hnd, key_hnd;
1265 struct winreg_String wvalue;
1267 uint32_t num_info = 0;
1268 union spoolss_FormInfo *info = NULL;
1272 TALLOC_CTX *tmp_ctx;
1274 tmp_ctx = talloc_new(mem_ctx);
1275 if (tmp_ctx == NULL) {
1279 ZERO_STRUCT(hive_hnd);
1280 ZERO_STRUCT(key_hnd);
1282 result = winreg_printer_openkey(tmp_ctx,
1285 TOP_LEVEL_CONTROL_FORMS_KEY,
1291 if (!W_ERROR_IS_OK(result)) {
1292 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
1293 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
1297 result = winreg_printer_enumforms1(tmp_ctx, server_info, &num_info, &info);
1298 if (!W_ERROR_IS_OK(result)) {
1299 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
1300 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
1304 /* If form name already exists or is builtin return ALREADY_EXISTS */
1305 for (i = 0; i < num_info; i++) {
1306 if (strequal(info[i].info1.form_name, form->form_name)) {
1307 result = WERR_FILE_EXISTS;
1312 wvalue.name = form->form_name;
1314 blob = data_blob_talloc(tmp_ctx, NULL, 32);
1315 SIVAL(blob.data, 0, form->size.width);
1316 SIVAL(blob.data, 4, form->size.height);
1317 SIVAL(blob.data, 8, form->area.left);
1318 SIVAL(blob.data, 12, form->area.top);
1319 SIVAL(blob.data, 16, form->area.right);
1320 SIVAL(blob.data, 20, form->area.bottom);
1321 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
1322 SIVAL(blob.data, 28, form->flags);
1324 status = rpccli_winreg_SetValue(winreg_pipe,
1332 if (!NT_STATUS_IS_OK(status)) {
1333 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
1334 wvalue.name, nt_errstr(status)));
1335 if (!W_ERROR_IS_OK(result)) {
1338 result = ntstatus_to_werror(status);
1344 if (winreg_pipe != NULL) {
1345 if (is_valid_policy_hnd(&key_hnd)) {
1346 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1348 if (is_valid_policy_hnd(&hive_hnd)) {
1349 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1354 TALLOC_FREE(tmp_ctx);
1358 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
1359 struct auth_serversupplied_info *server_info,
1360 uint32_t *pnum_info,
1361 union spoolss_FormInfo **pinfo)
1363 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1364 struct rpc_pipe_client *winreg_pipe = NULL;
1365 struct policy_handle hive_hnd, key_hnd;
1366 union spoolss_FormInfo *info;
1367 struct spoolss_PrinterEnumValues *enum_values = NULL;
1368 uint32_t num_values = 0;
1369 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
1372 TALLOC_CTX *tmp_ctx;
1374 tmp_ctx = talloc_new(mem_ctx);
1375 if (tmp_ctx == NULL) {
1379 ZERO_STRUCT(hive_hnd);
1380 ZERO_STRUCT(key_hnd);
1382 result = winreg_printer_openkey(tmp_ctx,
1385 TOP_LEVEL_CONTROL_FORMS_KEY,
1391 if (!W_ERROR_IS_OK(result)) {
1392 /* key doesn't exist */
1393 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1398 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
1399 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
1403 result = winreg_printer_enumvalues(tmp_ctx,
1408 if (!W_ERROR_IS_OK(result)) {
1409 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
1410 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
1414 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
1416 result = WERR_NOMEM;
1420 /* Enumerate BUILTIN forms */
1421 for (i = 0; i < num_builtin; i++) {
1422 info[i].info1 = builtin_forms1[i];
1425 /* Enumerate registry forms */
1426 for (i = 0; i < num_values; i++) {
1427 union spoolss_FormInfo val;
1429 if (enum_values[i].type != REG_BINARY ||
1430 enum_values[i].data_length != 32) {
1434 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
1435 if (val.info1.form_name == NULL) {
1436 result = WERR_NOMEM;
1440 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
1441 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
1442 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
1443 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
1444 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
1445 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
1446 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
1447 val.info1.flags = IVAL(enum_values[i].data->data, 28);
1449 info[i + num_builtin] = val;
1452 *pnum_info = num_builtin + num_values;
1454 *pinfo = talloc_move(mem_ctx, &info);
1458 if (winreg_pipe != NULL) {
1459 if (is_valid_policy_hnd(&key_hnd)) {
1460 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1462 if (is_valid_policy_hnd(&hive_hnd)) {
1463 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1467 TALLOC_FREE(enum_values);
1468 TALLOC_FREE(tmp_ctx);
1472 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
1473 struct auth_serversupplied_info *server_info,
1474 const char *form_name)
1476 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1477 struct rpc_pipe_client *winreg_pipe = NULL;
1478 struct policy_handle hive_hnd, key_hnd;
1479 struct winreg_String wvalue;
1480 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
1482 WERROR result = WERR_OK;
1484 TALLOC_CTX *tmp_ctx;
1486 for (i = 0; i < num_builtin; i++) {
1487 if (strequal(builtin_forms1[i].form_name, form_name)) {
1488 return WERR_INVALID_PARAMETER;
1492 tmp_ctx = talloc_new(mem_ctx);
1493 if (tmp_ctx == NULL) {
1497 ZERO_STRUCT(hive_hnd);
1498 ZERO_STRUCT(key_hnd);
1500 result = winreg_printer_openkey(tmp_ctx,
1503 TOP_LEVEL_CONTROL_FORMS_KEY,
1509 if (!W_ERROR_IS_OK(result)) {
1510 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
1511 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
1512 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1513 result = WERR_INVALID_FORM_NAME;
1518 wvalue.name = form_name;
1519 status = rpccli_winreg_DeleteValue(winreg_pipe,
1524 if (!NT_STATUS_IS_OK(status)) {
1525 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
1526 wvalue.name, nt_errstr(status)));
1527 if (!W_ERROR_IS_OK(result)) {
1530 result = ntstatus_to_werror(status);
1536 if (winreg_pipe != NULL) {
1537 if (is_valid_policy_hnd(&key_hnd)) {
1538 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1540 if (is_valid_policy_hnd(&hive_hnd)) {
1541 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1545 TALLOC_FREE(tmp_ctx);
1549 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
1550 struct auth_serversupplied_info *server_info,
1551 const char *form_name,
1552 struct spoolss_AddFormInfo1 *form)
1554 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1555 struct rpc_pipe_client *winreg_pipe = NULL;
1556 struct policy_handle hive_hnd, key_hnd;
1557 struct winreg_String wvalue;
1559 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
1563 TALLOC_CTX *tmp_ctx = NULL;
1565 for (i = 0; i < num_builtin; i++) {
1566 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
1567 result = WERR_INVALID_PARAM;
1572 tmp_ctx = talloc_new(mem_ctx);
1573 if (tmp_ctx == NULL) {
1577 ZERO_STRUCT(hive_hnd);
1578 ZERO_STRUCT(key_hnd);
1580 result = winreg_printer_openkey(tmp_ctx,
1583 TOP_LEVEL_CONTROL_FORMS_KEY,
1589 if (!W_ERROR_IS_OK(result)) {
1590 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
1591 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
1595 /* If form_name != form->form_name then we renamed the form */
1596 if (strequal(form_name, form->form_name)) {
1597 result = winreg_printer_deleteform1(tmp_ctx, server_info, form_name);
1598 if (!W_ERROR_IS_OK(result)) {
1599 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
1600 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
1605 wvalue.name = form->form_name;
1607 blob = data_blob_talloc(tmp_ctx, NULL, 32);
1608 SIVAL(blob.data, 0, form->size.width);
1609 SIVAL(blob.data, 4, form->size.height);
1610 SIVAL(blob.data, 8, form->area.left);
1611 SIVAL(blob.data, 12, form->area.top);
1612 SIVAL(blob.data, 16, form->area.right);
1613 SIVAL(blob.data, 20, form->area.bottom);
1614 SIVAL(blob.data, 24, 42);
1615 SIVAL(blob.data, 28, form->flags);
1617 status = rpccli_winreg_SetValue(winreg_pipe,
1625 if (!NT_STATUS_IS_OK(status)) {
1626 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
1627 wvalue.name, nt_errstr(status)));
1628 if (!W_ERROR_IS_OK(result)) {
1631 result = ntstatus_to_werror(status);
1637 if (winreg_pipe != NULL) {
1638 if (is_valid_policy_hnd(&key_hnd)) {
1639 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1641 if (is_valid_policy_hnd(&hive_hnd)) {
1642 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1646 TALLOC_FREE(tmp_ctx);
1650 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
1651 struct auth_serversupplied_info *server_info,
1652 const char *form_name,
1653 struct spoolss_FormInfo1 *r)
1655 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1656 struct rpc_pipe_client *winreg_pipe = NULL;
1657 struct policy_handle hive_hnd, key_hnd;
1658 struct winreg_String wvalue;
1659 enum winreg_Type type_in;
1661 uint32_t data_in_size = 0;
1662 uint32_t value_len = 0;
1663 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
1667 TALLOC_CTX *tmp_ctx;
1669 /* check builtin forms first */
1670 for (i = 0; i < num_builtin; i++) {
1671 if (strequal(builtin_forms1[i].form_name, form_name)) {
1672 *r = builtin_forms1[i];
1677 tmp_ctx = talloc_new(mem_ctx);
1678 if (tmp_ctx == NULL) {
1682 ZERO_STRUCT(hive_hnd);
1683 ZERO_STRUCT(key_hnd);
1685 result = winreg_printer_openkey(tmp_ctx,
1688 TOP_LEVEL_CONTROL_FORMS_KEY,
1694 if (!W_ERROR_IS_OK(result)) {
1695 DEBUG(0, ("winreg_printer_getform1: Could not open key %s: %s\n",
1696 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
1700 wvalue.name = form_name;
1703 * call QueryValue once with data == NULL to get the
1704 * needed memory size to be allocated, then allocate
1705 * data buffer and call again.
1707 status = rpccli_winreg_QueryValue(winreg_pipe,
1716 if (!NT_STATUS_IS_OK(status)) {
1717 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
1718 wvalue.name, nt_errstr(status)));
1719 if (!W_ERROR_IS_OK(result)) {
1722 result = ntstatus_to_werror(status);
1726 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
1727 if (data_in == NULL) {
1728 result = WERR_NOMEM;
1733 status = rpccli_winreg_QueryValue(winreg_pipe,
1742 if (!NT_STATUS_IS_OK(status)) {
1743 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
1744 wvalue.name, nt_errstr(status)));
1745 if (!W_ERROR_IS_OK(result)) {
1748 result = ntstatus_to_werror(status);
1752 r->form_name = talloc_strdup(mem_ctx, form_name);
1753 if (r->form_name == NULL) {
1754 result = WERR_NOMEM;
1758 r->size.width = IVAL(data_in, 0);
1759 r->size.height = IVAL(data_in, 4);
1760 r->area.left = IVAL(data_in, 8);
1761 r->area.top = IVAL(data_in, 12);
1762 r->area.right = IVAL(data_in, 16);
1763 r->area.bottom = IVAL(data_in, 20);
1764 /* skip index IVAL(data_in, 24)));*/
1765 r->flags = IVAL(data_in, 28);
1769 if (winreg_pipe != NULL) {
1770 if (is_valid_policy_hnd(&key_hnd)) {
1771 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1773 if (is_valid_policy_hnd(&hive_hnd)) {
1774 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1778 TALLOC_FREE(tmp_ctx);