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/ndr_spoolss.h"
25 #include "../librpc/gen_ndr/srv_winreg.h"
26 #include "../librpc/gen_ndr/cli_winreg.h"
27 #include "../librpc/gen_ndr/ndr_security.h"
29 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
30 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
31 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
32 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
34 #define EMPTY_STRING ""
35 static const char *empty_string_array
[1] = { NULL
};
36 #define EMPTY_STRING_ARRAY empty_string_array
38 #define CHECK_ERROR(result) \
39 if (W_ERROR_IS_OK(result)) continue; \
40 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
41 if (!W_ERROR_IS_OK(result)) break
43 /* FLAGS, NAME, with, height, left, top, right, bottom */
44 static const struct spoolss_FormInfo1 builtin_forms1
[] = {
45 { SPOOLSS_FORM_BUILTIN
, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
46 { SPOOLSS_FORM_BUILTIN
, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
47 { SPOOLSS_FORM_BUILTIN
, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
48 { SPOOLSS_FORM_BUILTIN
, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
49 { SPOOLSS_FORM_BUILTIN
, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
50 { SPOOLSS_FORM_BUILTIN
, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
51 { SPOOLSS_FORM_BUILTIN
, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
52 { SPOOLSS_FORM_BUILTIN
, "A0", {0xcd528,0x122488},{0x0,0x0,0xcd528,0x122488} },
53 { SPOOLSS_FORM_BUILTIN
, "A1", {0x91050,0xcd528}, {0x0,0x0,0x91050,0xcd528} },
54 { SPOOLSS_FORM_BUILTIN
, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
55 { SPOOLSS_FORM_BUILTIN
, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
56 { SPOOLSS_FORM_BUILTIN
, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
57 { SPOOLSS_FORM_BUILTIN
, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
58 { SPOOLSS_FORM_BUILTIN
, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
59 { SPOOLSS_FORM_BUILTIN
, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
60 { SPOOLSS_FORM_BUILTIN
, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
61 { SPOOLSS_FORM_BUILTIN
, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
62 { SPOOLSS_FORM_BUILTIN
, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
63 { SPOOLSS_FORM_BUILTIN
, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
64 { SPOOLSS_FORM_BUILTIN
, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
65 { SPOOLSS_FORM_BUILTIN
, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
66 { SPOOLSS_FORM_BUILTIN
, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
67 { SPOOLSS_FORM_BUILTIN
, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
68 { SPOOLSS_FORM_BUILTIN
, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
69 { SPOOLSS_FORM_BUILTIN
, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
70 { SPOOLSS_FORM_BUILTIN
, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
71 { SPOOLSS_FORM_BUILTIN
, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
72 { SPOOLSS_FORM_BUILTIN
, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
73 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
74 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
75 { SPOOLSS_FORM_BUILTIN
, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
76 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
77 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
78 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
79 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
80 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
81 { SPOOLSS_FORM_BUILTIN
, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
82 { SPOOLSS_FORM_BUILTIN
, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
83 { SPOOLSS_FORM_BUILTIN
, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
84 { SPOOLSS_FORM_BUILTIN
, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
85 { SPOOLSS_FORM_BUILTIN
, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
86 { SPOOLSS_FORM_BUILTIN
, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
87 { SPOOLSS_FORM_BUILTIN
, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
88 { SPOOLSS_FORM_BUILTIN
, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
89 { SPOOLSS_FORM_BUILTIN
, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
90 { SPOOLSS_FORM_BUILTIN
, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
91 { SPOOLSS_FORM_BUILTIN
, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
92 { SPOOLSS_FORM_BUILTIN
, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
93 { SPOOLSS_FORM_BUILTIN
, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
94 { SPOOLSS_FORM_BUILTIN
, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
95 { SPOOLSS_FORM_BUILTIN
, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
96 { SPOOLSS_FORM_BUILTIN
, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
97 { SPOOLSS_FORM_BUILTIN
, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
98 { SPOOLSS_FORM_BUILTIN
, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
99 { SPOOLSS_FORM_BUILTIN
, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
100 { SPOOLSS_FORM_BUILTIN
, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
101 { SPOOLSS_FORM_BUILTIN
, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
102 { SPOOLSS_FORM_BUILTIN
, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
103 { SPOOLSS_FORM_BUILTIN
, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
104 { SPOOLSS_FORM_BUILTIN
, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
105 { SPOOLSS_FORM_BUILTIN
, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
106 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
107 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
108 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
109 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
110 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
111 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
112 { SPOOLSS_FORM_BUILTIN
, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
113 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
114 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
115 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
116 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
117 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
118 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
119 { SPOOLSS_FORM_BUILTIN
, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
120 { SPOOLSS_FORM_BUILTIN
, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
121 { SPOOLSS_FORM_BUILTIN
, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
122 { SPOOLSS_FORM_BUILTIN
, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
123 { SPOOLSS_FORM_BUILTIN
, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
124 { SPOOLSS_FORM_BUILTIN
, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
125 { SPOOLSS_FORM_BUILTIN
, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
126 { SPOOLSS_FORM_BUILTIN
, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
127 { SPOOLSS_FORM_BUILTIN
, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
128 { SPOOLSS_FORM_BUILTIN
, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
129 { SPOOLSS_FORM_BUILTIN
, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
130 { SPOOLSS_FORM_BUILTIN
, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
131 { SPOOLSS_FORM_BUILTIN
, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
132 { SPOOLSS_FORM_BUILTIN
, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
133 { SPOOLSS_FORM_BUILTIN
, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
134 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
135 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
136 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
137 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
138 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} },
139 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
140 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
141 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
142 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
143 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
144 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
145 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
146 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
147 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
148 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
149 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
150 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
151 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
152 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
153 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
154 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
155 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
156 { SPOOLSS_FORM_BUILTIN
, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
157 { SPOOLSS_FORM_BUILTIN
, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
158 { SPOOLSS_FORM_BUILTIN
, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
159 { SPOOLSS_FORM_BUILTIN
, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
160 { SPOOLSS_FORM_BUILTIN
, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
161 { SPOOLSS_FORM_BUILTIN
, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
162 { SPOOLSS_FORM_BUILTIN
, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
163 { SPOOLSS_FORM_BUILTIN
, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
164 { SPOOLSS_FORM_BUILTIN
, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} }
167 /********************************************************************
168 static helper functions
169 ********************************************************************/
171 /****************************************************************************
172 Update the changeid time.
173 ****************************************************************************/
177 * @brief Update the ChangeID time of a printer.
179 * This is SO NASTY as some drivers need this to change, others need it
180 * static. This value will change every second, and I must hope that this
181 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
184 * @return The ChangeID.
186 static uint32_t winreg_printer_rev_changeid(void)
190 get_process_uptime(&tv
);
193 /* Return changeid as msec since spooler restart */
194 return tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
197 * This setting seems to work well but is too untested
198 * to replace the above calculation. Left in for experiementation
199 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
201 return tv
.tv_sec
* 10 + tv
.tv_usec
/ 100000;
208 * @brief Connect to the interal winreg server and open the given printer key.
210 * The function will create the needed subkeys if they don't exist.
212 * @param[in] mem_ctx The memory context to use.
214 * @param[in] server_info The supplied server info.
216 * @param[out] winreg_pipe A pointer for the winreg rpc client pipe.
218 * @param[in] path The path to the key to open.
220 * @param[in] key The key to open.
222 * @param[in] create_key Set to true if the key should be created if it
225 * @param[in] access_mask The access mask to open the key.
227 * @param[out] hive_handle A policy handle for the opened hive.
229 * @param[out] key_handle A policy handle for the opened key.
231 * @return WERR_OK on success, the corresponding DOS error
232 * code if something gone wrong.
234 static WERROR
winreg_printer_openkey(TALLOC_CTX
*mem_ctx
,
235 struct auth_serversupplied_info
*server_info
,
236 struct rpc_pipe_client
**winreg_pipe
,
240 uint32_t access_mask
,
241 struct policy_handle
*hive_handle
,
242 struct policy_handle
*key_handle
)
244 struct rpc_pipe_client
*pipe_handle
;
245 struct winreg_String wkey
, wkeyclass
;
248 WERROR result
= WERR_OK
;
250 /* create winreg connection */
251 status
= rpc_pipe_open_internal(mem_ctx
,
252 &ndr_table_winreg
.syntax_id
,
256 if (!NT_STATUS_IS_OK(status
)) {
257 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg_pipe: %s\n",
259 return ntstatus_to_werror(status
);
262 status
= rpccli_winreg_OpenHKLM(pipe_handle
,
268 if (!NT_STATUS_IS_OK(status
)) {
269 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
271 talloc_free(pipe_handle
);
272 if (!W_ERROR_IS_OK(result
)) {
275 return ntstatus_to_werror(status
);
279 keyname
= talloc_asprintf(mem_ctx
, "%s\\%s", path
, key
);
281 keyname
= talloc_strdup(mem_ctx
, path
);
283 if (keyname
== NULL
) {
284 talloc_free(pipe_handle
);
292 enum winreg_CreateAction action
= REG_ACTION_NONE
;
294 ZERO_STRUCT(wkeyclass
);
297 status
= rpccli_winreg_CreateKey(pipe_handle
,
309 case REG_ACTION_NONE
:
310 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
312 case REG_CREATED_NEW_KEY
:
313 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname
));
315 case REG_OPENED_EXISTING_KEY
:
316 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname
));
320 status
= rpccli_winreg_OpenKey(pipe_handle
,
329 if (!NT_STATUS_IS_OK(status
)) {
330 talloc_free(pipe_handle
);
331 if (!W_ERROR_IS_OK(result
)) {
334 return ntstatus_to_werror(status
);
337 *winreg_pipe
= pipe_handle
;
343 * @brief Create the registry keyname for the given printer.
345 * @param[in] mem_ctx The memory context to use.
347 * @param[in] printer The name of the printer to get the registry key.
349 * @return The registry key or NULL on error.
351 static char *winreg_printer_data_keyname(TALLOC_CTX
*mem_ctx
, const char *printer
) {
352 return talloc_asprintf(mem_ctx
, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY
, printer
);
358 * @brief Enumerate values of an opened key handle and retrieve the data.
360 * @param[in] mem_ctx The memory context to use.
362 * @param[in] pipe_handle The pipe handle for the rpc connection.
364 * @param[in] key_hnd The opened key handle.
366 * @param[out] pnum_values A pointer to store he number of values found.
368 * @param[out] pnum_values A pointer to store the number of values we found.
370 * @return WERR_OK on success, the corresponding DOS error
371 * code if something gone wrong.
373 static WERROR
winreg_printer_enumvalues(TALLOC_CTX
*mem_ctx
,
374 struct rpc_pipe_client
*pipe_handle
,
375 struct policy_handle
*key_hnd
,
376 uint32_t *pnum_values
,
377 struct spoolss_PrinterEnumValues
**penum_values
)
380 uint32_t num_subkeys
, max_subkeylen
, max_classlen
;
381 uint32_t num_values
, max_valnamelen
, max_valbufsize
;
382 uint32_t secdescsize
;
384 NTTIME last_changed_time
;
385 struct winreg_String classname
;
387 struct spoolss_PrinterEnumValues
*enum_values
;
389 WERROR result
= WERR_OK
;
392 tmp_ctx
= talloc_new(mem_ctx
);
393 if (tmp_ctx
== NULL
) {
397 ZERO_STRUCT(classname
);
399 status
= rpccli_winreg_QueryInfoKey(pipe_handle
,
412 if (!NT_STATUS_IS_OK(status
)) {
413 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
415 if (!W_ERROR_IS_OK(result
)) {
418 result
= ntstatus_to_werror(status
);
422 if (num_values
== 0) {
424 TALLOC_FREE(tmp_ctx
);
428 enum_values
= TALLOC_ARRAY(tmp_ctx
, struct spoolss_PrinterEnumValues
, num_values
);
429 if (enum_values
== NULL
) {
434 for (i
= 0; i
< num_values
; i
++) {
435 struct spoolss_PrinterEnumValues val
;
436 struct winreg_ValNameBuf name_buf
;
437 enum winreg_Type type
= REG_NONE
;
438 uint8_t *data
= NULL
;
444 name_buf
.size
= max_valnamelen
+ 2;
447 data_size
= max_valbufsize
;
448 data
= (uint8_t *) TALLOC(tmp_ctx
, data_size
);
451 status
= rpccli_winreg_EnumValue(pipe_handle
,
461 if (W_ERROR_EQUAL(result
, WERR_NO_MORE_ITEMS
) ) {
463 status
= NT_STATUS_OK
;
467 if (!NT_STATUS_IS_OK(status
)) {
468 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
470 if (!W_ERROR_IS_OK(result
)) {
473 result
= ntstatus_to_werror(status
);
477 if (name_buf
.name
== NULL
) {
478 result
= WERR_INVALID_PARAMETER
;
482 val
.value_name
= talloc_strdup(enum_values
, name_buf
.name
);
483 if (val
.value_name
== NULL
) {
487 val
.value_name_len
= strlen_m_term(val
.value_name
) * 2;
490 val
.data_length
= data_size
;
492 if (val
.data_length
) {
493 val
.data
= talloc(enum_values
, DATA_BLOB
);
494 if (val
.data
== NULL
) {
498 *val
.data
= data_blob_talloc(enum_values
, data
, data_size
);
501 enum_values
[i
] = val
;
504 *pnum_values
= num_values
;
506 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
512 TALLOC_FREE(tmp_ctx
);
519 * @brief Enumerate subkeys of an opened key handle and get the names.
521 * @param[in] mem_ctx The memory context to use.
523 * @param[in] pipe_handle The pipe handle for the rpc connection.
525 * @param[in] key_hnd The opened key handle.
527 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
529 * @param[in] psubkeys A pointer to an array to store the found names of
532 * @return WERR_OK on success, the corresponding DOS error
533 * code if something gone wrong.
535 static WERROR
winreg_printer_enumkeys(TALLOC_CTX
*mem_ctx
,
536 struct rpc_pipe_client
*pipe_handle
,
537 struct policy_handle
*key_hnd
,
538 uint32_t *pnum_subkeys
,
539 const char ***psubkeys
)
542 const char **subkeys
;
543 uint32_t num_subkeys
, max_subkeylen
, max_classlen
;
544 uint32_t num_values
, max_valnamelen
, max_valbufsize
;
546 NTTIME last_changed_time
;
547 uint32_t secdescsize
;
548 struct winreg_String classname
;
549 WERROR result
= WERR_OK
;
552 tmp_ctx
= talloc_new(mem_ctx
);
553 if (tmp_ctx
== NULL
) {
557 ZERO_STRUCT(classname
);
559 status
= rpccli_winreg_QueryInfoKey(pipe_handle
,
572 if (!NT_STATUS_IS_OK(status
)) {
573 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
575 if (!W_ERROR_IS_OK(result
)) {
578 result
= ntstatus_to_werror(status
);
582 subkeys
= talloc_zero_array(tmp_ctx
, const char *, num_subkeys
+ 2);
583 if (subkeys
== NULL
) {
588 if (num_subkeys
== 0) {
589 subkeys
[0] = talloc_strdup(subkeys
, "");
590 if (subkeys
[0] == NULL
) {
596 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
599 TALLOC_FREE(tmp_ctx
);
603 for (i
= 0; i
< num_subkeys
; i
++) {
607 struct winreg_StringBuf class_buf
;
608 struct winreg_StringBuf name_buf
;
612 class_buf
.size
= max_classlen
+ 2;
613 class_buf
.length
= 0;
616 name_buf
.size
= max_subkeylen
+ 2;
619 ZERO_STRUCT(modtime
);
621 status
= rpccli_winreg_EnumKey(pipe_handle
,
629 if (W_ERROR_EQUAL(result
, WERR_NO_MORE_ITEMS
) ) {
631 status
= NT_STATUS_OK
;
635 if (!NT_STATUS_IS_OK(status
)) {
636 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
638 if (!W_ERROR_IS_OK(result
)) {
641 result
= ntstatus_to_werror(status
);
645 if (name_buf
.name
== NULL
) {
646 result
= WERR_INVALID_PARAMETER
;
650 name
= talloc_strdup(subkeys
, name_buf
.name
);
659 *pnum_subkeys
= num_subkeys
;
661 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
665 TALLOC_FREE(tmp_ctx
);
672 * @brief A function to delete a key and its subkeys recurively.
674 * @param[in] mem_ctx The memory context to use.
676 * @param[in] pipe_handle The pipe handle for the rpc connection.
678 * @param[in] hive_handle A opened hive handle to the key.
680 * @param[in] access_mask The access mask to access the key.
682 * @param[in] key The key to delete
684 * @return WERR_OK on success, the corresponding DOS error
685 * code if something gone wrong.
687 static WERROR
winreg_printer_delete_subkeys(TALLOC_CTX
*mem_ctx
,
688 struct rpc_pipe_client
*pipe_handle
,
689 struct policy_handle
*hive_handle
,
690 uint32_t access_mask
,
693 const char **subkeys
= NULL
;
694 uint32_t num_subkeys
= 0;
695 struct policy_handle key_hnd
;
696 struct winreg_String wkey
;
697 WERROR result
= WERR_OK
;
701 ZERO_STRUCT(key_hnd
);
704 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key
));
706 status
= rpccli_winreg_OpenKey(pipe_handle
,
714 if (!NT_STATUS_IS_OK(status
)) {
715 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
716 wkey
.name
, nt_errstr(status
)));
717 if (!W_ERROR_IS_OK(result
)) {
720 return ntstatus_to_werror(status
);
723 result
= winreg_printer_enumkeys(mem_ctx
,
728 if (!W_ERROR_IS_OK(result
)) {
732 for (i
= 0; i
< num_subkeys
; i
++) {
733 /* create key + subkey */
734 char *subkey
= talloc_asprintf(mem_ctx
, "%s\\%s", key
, subkeys
[i
]);
735 if (subkey
== NULL
) {
739 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey
));
740 result
= winreg_printer_delete_subkeys(mem_ctx
,
745 if (!W_ERROR_IS_OK(result
)) {
750 if (is_valid_policy_hnd(&key_hnd
)) {
751 rpccli_winreg_CloseKey(pipe_handle
, mem_ctx
, &key_hnd
, NULL
);
756 status
= rpccli_winreg_DeleteKey(pipe_handle
,
763 if (is_valid_policy_hnd(&key_hnd
)) {
764 rpccli_winreg_CloseKey(pipe_handle
, mem_ctx
, &key_hnd
, NULL
);
770 static WERROR
winreg_printer_write_sz(TALLOC_CTX
*mem_ctx
,
771 struct rpc_pipe_client
*pipe_handle
,
772 struct policy_handle
*key_handle
,
776 struct winreg_String wvalue
;
778 WERROR result
= WERR_OK
;
783 blob
= data_blob_string_const("");
785 if (!push_reg_sz(mem_ctx
, &blob
, data
)) {
786 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
791 status
= rpccli_winreg_SetValue(pipe_handle
,
799 if (!NT_STATUS_IS_OK(status
)) {
800 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
801 wvalue
.name
, win_errstr(result
)));
802 if (!W_ERROR_IS_OK(result
)) {
803 result
= ntstatus_to_werror(status
);
810 static WERROR
winreg_printer_write_dword(TALLOC_CTX
*mem_ctx
,
811 struct rpc_pipe_client
*pipe_handle
,
812 struct policy_handle
*key_handle
,
816 struct winreg_String wvalue
;
818 WERROR result
= WERR_OK
;
822 blob
= data_blob_talloc(mem_ctx
, NULL
, 4);
823 SIVAL(blob
.data
, 0, data
);
825 status
= rpccli_winreg_SetValue(pipe_handle
,
833 if (!NT_STATUS_IS_OK(status
)) {
834 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
835 wvalue
.name
, win_errstr(result
)));
836 if (!W_ERROR_IS_OK(result
)) {
837 result
= ntstatus_to_werror(status
);
844 static WERROR
winreg_printer_write_binary(TALLOC_CTX
*mem_ctx
,
845 struct rpc_pipe_client
*pipe_handle
,
846 struct policy_handle
*key_handle
,
850 struct winreg_String wvalue
;
851 WERROR result
= WERR_OK
;
855 status
= rpccli_winreg_SetValue(pipe_handle
,
863 if (!NT_STATUS_IS_OK(status
)) {
864 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
865 wvalue
.name
, win_errstr(result
)));
866 if (!W_ERROR_IS_OK(result
)) {
867 result
= ntstatus_to_werror(status
);
874 static WERROR
winreg_printer_query_binary(TALLOC_CTX
*mem_ctx
,
875 struct rpc_pipe_client
*pipe_handle
,
876 struct policy_handle
*key_handle
,
880 struct winreg_String wvalue
;
881 enum winreg_Type type
;
882 WERROR result
= WERR_OK
;
883 uint32_t value_len
= 0;
884 uint32_t data_size
= 0;
889 status
= rpccli_winreg_QueryValue(pipe_handle
,
898 if (!NT_STATUS_IS_OK(status
)) {
899 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
900 wvalue
.name
, nt_errstr(status
)));
901 if (!W_ERROR_IS_OK(result
)) {
904 result
= ntstatus_to_werror(status
);
908 if (type
!= REG_BINARY
) {
909 result
= WERR_INVALID_DATATYPE
;
912 blob
= data_blob_talloc(mem_ctx
, NULL
, data_size
);
913 if (blob
.data
== NULL
) {
919 status
= rpccli_winreg_QueryValue(pipe_handle
,
928 if (!NT_STATUS_IS_OK(status
)) {
929 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
930 wvalue
.name
, nt_errstr(status
)));
931 if (!W_ERROR_IS_OK(result
)) {
932 result
= ntstatus_to_werror(status
);
938 data
->data
= blob
.data
;
939 data
->length
= blob
.length
;
945 static WERROR
winreg_printer_query_dword(TALLOC_CTX
*mem_ctx
,
946 struct rpc_pipe_client
*pipe_handle
,
947 struct policy_handle
*key_handle
,
951 struct winreg_String wvalue
;
952 enum winreg_Type type
;
953 WERROR result
= WERR_OK
;
954 uint32_t value_len
= 0;
955 uint32_t data_size
= 0;
960 status
= rpccli_winreg_QueryValue(pipe_handle
,
969 if (!NT_STATUS_IS_OK(status
)) {
970 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
971 wvalue
.name
, nt_errstr(status
)));
972 if (!W_ERROR_IS_OK(result
)) {
975 result
= ntstatus_to_werror(status
);
979 if (type
!= REG_DWORD
) {
980 result
= WERR_INVALID_DATATYPE
;
984 if (data_size
!= 4) {
985 result
= WERR_INVALID_DATA
;
989 blob
= data_blob_talloc(mem_ctx
, NULL
, data_size
);
990 if (blob
.data
== NULL
) {
996 status
= rpccli_winreg_QueryValue(pipe_handle
,
1005 if (!NT_STATUS_IS_OK(status
)) {
1006 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1007 wvalue
.name
, nt_errstr(status
)));
1008 if (!W_ERROR_IS_OK(result
)) {
1009 result
= ntstatus_to_werror(status
);
1015 *data
= IVAL(blob
.data
, 0);
1021 static WERROR
winreg_printer_write_multi_sz(TALLOC_CTX
*mem_ctx
,
1022 struct rpc_pipe_client
*pipe_handle
,
1023 struct policy_handle
*key_handle
,
1027 struct winreg_String wvalue
;
1029 WERROR result
= WERR_OK
;
1032 wvalue
.name
= value
;
1033 if (!push_reg_multi_sz(mem_ctx
, &blob
, data
)) {
1036 status
= rpccli_winreg_SetValue(pipe_handle
,
1044 if (!NT_STATUS_IS_OK(status
)) {
1045 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1046 wvalue
.name
, win_errstr(result
)));
1047 if (!W_ERROR_IS_OK(result
)) {
1048 result
= ntstatus_to_werror(status
);
1055 static WERROR
winreg_printer_opendriver(TALLOC_CTX
*mem_ctx
,
1056 struct auth_serversupplied_info
*server_info
,
1057 const char *drivername
,
1058 const char *architecture
,
1060 uint32_t access_mask
,
1062 struct rpc_pipe_client
**winreg_pipe
,
1063 struct policy_handle
*hive_hnd
,
1064 struct policy_handle
*key_hnd
)
1069 key_name
= talloc_asprintf(mem_ctx
, "%s\\Environments\\%s\\Drivers\\Version-%u",
1070 TOP_LEVEL_CONTROL_KEY
,
1071 architecture
, version
);
1076 result
= winreg_printer_openkey(mem_ctx
,
1088 static WERROR
winreg_enumval_to_dword(TALLOC_CTX
*mem_ctx
,
1089 struct spoolss_PrinterEnumValues
*v
,
1090 const char *valuename
, uint32_t *dw
)
1092 /* just return if it is not the one we are looking for */
1093 if (strcmp(valuename
, v
->value_name
) != 0) {
1094 return WERR_NOT_FOUND
;
1097 if (v
->type
!= REG_DWORD
) {
1098 return WERR_INVALID_DATATYPE
;
1101 *dw
= IVAL(v
->data
->data
, 0);
1105 static WERROR
winreg_enumval_to_sz(TALLOC_CTX
*mem_ctx
,
1106 struct spoolss_PrinterEnumValues
*v
,
1107 const char *valuename
, const char **_str
)
1109 /* just return if it is not the one we are looking for */
1110 if (strcmp(valuename
, v
->value_name
) != 0) {
1111 return WERR_NOT_FOUND
;
1114 if (v
->type
!= REG_SZ
) {
1115 return WERR_INVALID_DATATYPE
;
1118 if (!pull_reg_sz(mem_ctx
, v
->data
, _str
)) {
1125 static WERROR
winreg_enumval_to_multi_sz(TALLOC_CTX
*mem_ctx
,
1126 struct spoolss_PrinterEnumValues
*v
,
1127 const char *valuename
,
1128 const char ***array
)
1130 /* just return if it is not the one we are looking for */
1131 if (strcmp(valuename
, v
->value_name
) != 0) {
1132 return WERR_NOT_FOUND
;
1135 if (v
->type
!= REG_MULTI_SZ
) {
1136 return WERR_INVALID_DATATYPE
;
1139 if (!pull_reg_multi_sz(mem_ctx
, v
->data
, array
)) {
1146 static WERROR
winreg_printer_write_date(TALLOC_CTX
*mem_ctx
,
1147 struct rpc_pipe_client
*pipe_handle
,
1148 struct policy_handle
*key_handle
,
1152 struct winreg_String wvalue
;
1154 WERROR result
= WERR_OK
;
1160 t
= nt_time_to_unix(data
);
1162 str
= talloc_asprintf(mem_ctx
, "%02d/%02d/%04d",
1163 tm
->tm_mon
+ 1, tm
->tm_mday
, tm
->tm_year
+ 1900);
1168 wvalue
.name
= value
;
1169 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
1172 status
= rpccli_winreg_SetValue(pipe_handle
,
1180 if (!NT_STATUS_IS_OK(status
)) {
1181 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1182 wvalue
.name
, win_errstr(result
)));
1183 if (!W_ERROR_IS_OK(result
)) {
1184 result
= ntstatus_to_werror(status
);
1191 static WERROR
winreg_printer_date_to_NTTIME(const char *str
, NTTIME
*data
)
1198 if (sscanf(str
, "%d/%d/%d",
1199 &tm
.tm_mon
, &tm
.tm_mday
, &tm
.tm_year
) != 3) {
1200 return WERR_INVALID_PARAMETER
;
1207 unix_to_nt_time(data
, t
);
1212 static WERROR
winreg_printer_write_ver(TALLOC_CTX
*mem_ctx
,
1213 struct rpc_pipe_client
*pipe_handle
,
1214 struct policy_handle
*key_handle
,
1218 struct winreg_String wvalue
;
1220 WERROR result
= WERR_OK
;
1224 /* FIXME: check format is right,
1225 * this needs to be something like: 6.1.7600.16385 */
1226 str
= talloc_asprintf(mem_ctx
, "%u.%u.%u.%u",
1227 (unsigned)((data
>> 48) & 0xFFFF),
1228 (unsigned)((data
>> 32) & 0xFFFF),
1229 (unsigned)((data
>> 16) & 0xFFFF),
1230 (unsigned)(data
& 0xFFFF));
1235 wvalue
.name
= value
;
1236 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
1239 status
= rpccli_winreg_SetValue(pipe_handle
,
1247 if (!NT_STATUS_IS_OK(status
)) {
1248 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1249 wvalue
.name
, win_errstr(result
)));
1250 if (!W_ERROR_IS_OK(result
)) {
1251 result
= ntstatus_to_werror(status
);
1258 static WERROR
winreg_printer_ver_to_dword(const char *str
, uint64_t *data
)
1260 unsigned int v1
, v2
, v3
, v4
;
1262 if (sscanf(str
, "%u.%u.%u.%u", &v1
, &v2
, &v3
, &v4
) != 4) {
1263 return WERR_INVALID_PARAMETER
;
1266 *data
= ((uint64_t)(v1
& 0xFFFF) << 48) +
1267 ((uint64_t)(v2
& 0xFFFF) << 32) +
1268 ((uint64_t)(v3
& 0xFFFF) << 16) +
1269 (uint64_t)(v2
& 0xFFFF);
1274 /********************************************************************
1275 Public winreg function for spoolss
1276 ********************************************************************/
1278 WERROR
winreg_create_printer(TALLOC_CTX
*mem_ctx
,
1279 struct auth_serversupplied_info
*server_info
,
1280 const char *servername
,
1281 const char *sharename
)
1283 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1284 struct rpc_pipe_client
*winreg_pipe
= NULL
;
1285 struct policy_handle hive_hnd
, key_hnd
;
1286 struct spoolss_SetPrinterInfo2
*info2
;
1287 struct security_descriptor
*secdesc
;
1288 struct winreg_String wkey
, wkeyclass
;
1290 const char *subkeys
[] = { SPOOL_DSDRIVER_KEY
, SPOOL_DSSPOOLER_KEY
, SPOOL_PRINTERDATA_KEY
};
1291 uint32_t i
, count
= ARRAY_SIZE(subkeys
);
1292 uint32_t info2_mask
= 0;
1293 WERROR result
= WERR_OK
;
1294 TALLOC_CTX
*tmp_ctx
;
1296 tmp_ctx
= talloc_new(mem_ctx
);
1297 if (tmp_ctx
== NULL
) {
1301 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1303 TALLOC_FREE(tmp_ctx
);
1307 ZERO_STRUCT(hive_hnd
);
1308 ZERO_STRUCT(key_hnd
);
1310 result
= winreg_printer_openkey(tmp_ctx
,
1319 if (W_ERROR_IS_OK(result
)) {
1320 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path
));
1322 } else if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1323 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path
));
1324 } else if (!W_ERROR_IS_OK(result
)) {
1325 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1326 path
, win_errstr(result
)));
1330 /* Create the main key */
1331 result
= winreg_printer_openkey(tmp_ctx
,
1340 if (!W_ERROR_IS_OK(result
)) {
1341 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1342 path
, win_errstr(result
)));
1346 if (is_valid_policy_hnd(&key_hnd
)) {
1347 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
1350 /* Create subkeys */
1351 for (i
= 0; i
< count
; i
++) {
1353 enum winreg_CreateAction action
= REG_ACTION_NONE
;
1355 ZERO_STRUCT(key_hnd
);
1358 wkey
.name
= talloc_asprintf(tmp_ctx
, "%s\\%s", path
, subkeys
[i
]);
1359 if (wkey
.name
== NULL
) {
1360 result
= WERR_NOMEM
;
1364 ZERO_STRUCT(wkeyclass
);
1365 wkeyclass
.name
= "";
1367 status
= rpccli_winreg_CreateKey(winreg_pipe
,
1378 if (!NT_STATUS_IS_OK(status
)) {
1379 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1380 wkey
.name
, win_errstr(result
)));
1381 if (!W_ERROR_IS_OK(result
)) {
1382 result
= ntstatus_to_werror(status
);
1389 const char *dnssuffix
;
1390 const char *longname
;
1391 const char *uncname
;
1393 result
= winreg_printer_write_sz(tmp_ctx
,
1396 SPOOL_REG_PRINTERNAME
,
1398 if (!W_ERROR_IS_OK(result
)) {
1402 result
= winreg_printer_write_sz(tmp_ctx
,
1405 SPOOL_REG_SHORTSERVERNAME
,
1407 if (!W_ERROR_IS_OK(result
)) {
1411 /* We make the assumption that the netbios name
1412 * is the same as the DNS name since the former
1413 * will be what we used to join the domain
1415 dnssuffix
= get_mydnsdomname(tmp_ctx
);
1416 if (dnssuffix
!= NULL
&& dnssuffix
[0] != '\0') {
1417 longname
= talloc_asprintf(tmp_ctx
, "%s.%s", global_myname(), dnssuffix
);
1419 longname
= talloc_strdup(tmp_ctx
, global_myname());
1421 if (longname
== NULL
) {
1422 result
= WERR_NOMEM
;
1426 result
= winreg_printer_write_sz(tmp_ctx
,
1429 SPOOL_REG_SERVERNAME
,
1431 if (!W_ERROR_IS_OK(result
)) {
1435 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
1436 longname
, sharename
);
1437 if (uncname
== NULL
) {
1438 result
= WERR_NOMEM
;
1442 result
= winreg_printer_write_sz(tmp_ctx
,
1447 if (!W_ERROR_IS_OK(result
)) {
1451 result
= winreg_printer_write_dword(tmp_ctx
,
1454 SPOOL_REG_VERSIONNUMBER
,
1456 if (!W_ERROR_IS_OK(result
)) {
1460 result
= winreg_printer_write_dword(tmp_ctx
,
1463 SPOOL_REG_PRINTSTARTTIME
,
1465 if (!W_ERROR_IS_OK(result
)) {
1469 result
= winreg_printer_write_dword(tmp_ctx
,
1472 SPOOL_REG_PRINTENDTIME
,
1474 if (!W_ERROR_IS_OK(result
)) {
1478 result
= winreg_printer_write_dword(tmp_ctx
,
1483 if (!W_ERROR_IS_OK(result
)) {
1487 result
= winreg_printer_write_dword(tmp_ctx
,
1490 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
1492 if (!W_ERROR_IS_OK(result
)) {
1500 if (is_valid_policy_hnd(&key_hnd
)) {
1501 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
1504 info2
= talloc_zero(tmp_ctx
, struct spoolss_SetPrinterInfo2
);
1505 if (info2
== NULL
) {
1506 result
= WERR_NOMEM
;
1510 if (servername
!= NULL
) {
1511 info2
->printername
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
1512 servername
, sharename
);
1514 info2
->printername
= sharename
;
1516 if (info2
->printername
== NULL
) {
1517 result
= WERR_NOMEM
;
1520 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTERNAME
;
1522 info2
->sharename
= sharename
;
1523 info2_mask
|= SPOOLSS_PRINTER_INFO_SHARENAME
;
1525 info2
->portname
= SAMBA_PRINTER_PORT_NAME
;
1526 info2_mask
|= SPOOLSS_PRINTER_INFO_PORTNAME
;
1528 info2
->printprocessor
= "winprint";
1529 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
;
1531 info2
->datatype
= "RAW";
1532 info2_mask
|= SPOOLSS_PRINTER_INFO_DATATYPE
;
1534 info2
->comment
= "";
1535 info2_mask
|= SPOOLSS_PRINTER_INFO_COMMENT
;
1537 info2
->attributes
= PRINTER_ATTRIBUTE_SAMBA
;
1538 info2_mask
|= SPOOLSS_PRINTER_INFO_ATTRIBUTES
;
1540 info2
->starttime
= 0; /* Minutes since 12:00am GMT */
1541 info2_mask
|= SPOOLSS_PRINTER_INFO_STARTTIME
;
1543 info2
->untiltime
= 0; /* Minutes since 12:00am GMT */
1544 info2_mask
|= SPOOLSS_PRINTER_INFO_UNTILTIME
;
1546 info2
->priority
= 1;
1547 info2_mask
|= SPOOLSS_PRINTER_INFO_PRIORITY
;
1549 info2
->defaultpriority
= 1;
1550 info2_mask
|= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
;
1552 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1553 if (!W_ERROR_IS_OK(result
)) {
1556 info2_mask
|= SPOOLSS_PRINTER_INFO_SECDESC
;
1559 * Don't write a default Device Mode to the registry! The Device Mode is
1560 * only written to disk with a SetPrinter level 2 or 8.
1563 result
= winreg_update_printer(tmp_ctx
,
1572 if (winreg_pipe
!= NULL
) {
1573 if (is_valid_policy_hnd(&key_hnd
)) {
1574 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
1576 if (is_valid_policy_hnd(&hive_hnd
)) {
1577 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
1581 talloc_free(tmp_ctx
);
1585 WERROR
winreg_update_printer(TALLOC_CTX
*mem_ctx
,
1586 struct auth_serversupplied_info
*server_info
,
1587 const char *sharename
,
1588 uint32_t info2_mask
,
1589 struct spoolss_SetPrinterInfo2
*info2
,
1590 struct spoolss_DeviceMode
*devmode
,
1591 struct security_descriptor
*secdesc
)
1593 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1594 struct rpc_pipe_client
*winreg_pipe
= NULL
;
1595 struct policy_handle hive_hnd
, key_hnd
;
1596 int snum
= lp_servicenumber(sharename
);
1597 enum ndr_err_code ndr_err
;
1600 WERROR result
= WERR_OK
;
1601 TALLOC_CTX
*tmp_ctx
;
1603 tmp_ctx
= talloc_new(mem_ctx
);
1604 if (tmp_ctx
== NULL
) {
1608 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1610 TALLOC_FREE(tmp_ctx
);
1614 ZERO_STRUCT(hive_hnd
);
1615 ZERO_STRUCT(key_hnd
);
1617 result
= winreg_printer_openkey(tmp_ctx
,
1626 if (!W_ERROR_IS_OK(result
)) {
1627 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1628 path
, win_errstr(result
)));
1632 if (info2_mask
& SPOOLSS_PRINTER_INFO_ATTRIBUTES
) {
1633 result
= winreg_printer_write_dword(tmp_ctx
,
1638 if (!W_ERROR_IS_OK(result
)) {
1644 if (info2_mask
& SPOOLSS_PRINTER_INFO_AVERAGEPPM
) {
1645 result
= winreg_printer_write_dword(tmp_ctx
,
1650 if (!W_ERROR_IS_OK(result
)) {
1656 if (info2_mask
& SPOOLSS_PRINTER_INFO_COMMENT
) {
1657 result
= winreg_printer_write_sz(tmp_ctx
,
1662 if (!W_ERROR_IS_OK(result
)) {
1667 if (info2_mask
& SPOOLSS_PRINTER_INFO_DATATYPE
) {
1668 result
= winreg_printer_write_sz(tmp_ctx
,
1673 if (!W_ERROR_IS_OK(result
)) {
1678 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
) {
1679 result
= winreg_printer_write_dword(tmp_ctx
,
1683 info2
->defaultpriority
);
1684 if (!W_ERROR_IS_OK(result
)) {
1689 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEVMODE
) {
1691 * Some client drivers freak out if there is a NULL devmode
1692 * (probably the driver is not checking before accessing
1693 * the devmode pointer) --jerry
1695 if (devmode
== NULL
&& lp_default_devmode(snum
) && info2
!= NULL
) {
1696 result
= spoolss_create_default_devmode(tmp_ctx
,
1699 if (!W_ERROR_IS_OK(result
)) {
1703 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, devmode
,
1704 (ndr_push_flags_fn_t
) ndr_push_spoolss_DeviceMode
);
1705 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1706 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1707 result
= WERR_NOMEM
;
1711 result
= winreg_printer_write_binary(tmp_ctx
,
1716 if (!W_ERROR_IS_OK(result
)) {
1721 if (info2_mask
& SPOOLSS_PRINTER_INFO_DRIVERNAME
) {
1722 result
= winreg_printer_write_sz(tmp_ctx
,
1727 if (!W_ERROR_IS_OK(result
)) {
1732 if (info2_mask
& SPOOLSS_PRINTER_INFO_LOCATION
) {
1733 result
= winreg_printer_write_sz(tmp_ctx
,
1738 if (!W_ERROR_IS_OK(result
)) {
1743 if (info2_mask
& SPOOLSS_PRINTER_INFO_PARAMETERS
) {
1744 result
= winreg_printer_write_sz(tmp_ctx
,
1749 if (!W_ERROR_IS_OK(result
)) {
1754 if (info2_mask
& SPOOLSS_PRINTER_INFO_PORTNAME
) {
1755 result
= winreg_printer_write_sz(tmp_ctx
,
1760 if (!W_ERROR_IS_OK(result
)) {
1765 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTERNAME
) {
1767 * in addprinter: no servername and the printer is the name
1768 * in setprinter: servername is \\server
1769 * and printer is \\server\\printer
1771 * Samba manages only local printers.
1772 * we currently don't support things like i
1773 * path=\\other_server\printer
1775 * We only store the printername, not \\server\printername
1777 const char *p
= strrchr(info2
->printername
, '\\');
1779 p
= info2
->printername
;
1783 result
= winreg_printer_write_sz(tmp_ctx
,
1788 if (!W_ERROR_IS_OK(result
)) {
1793 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
) {
1794 result
= winreg_printer_write_sz(tmp_ctx
,
1798 info2
->printprocessor
);
1799 if (!W_ERROR_IS_OK(result
)) {
1804 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRIORITY
) {
1805 result
= winreg_printer_write_dword(tmp_ctx
,
1810 if (!W_ERROR_IS_OK(result
)) {
1815 if (info2_mask
& SPOOLSS_PRINTER_INFO_SECDESC
) {
1817 * We need a security descriptor, if it isn't specified by
1818 * AddPrinter{Ex} then create a default descriptor.
1820 if (secdesc
== NULL
) {
1821 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1822 if (!W_ERROR_IS_OK(result
)) {
1826 result
= winreg_set_printer_secdesc(tmp_ctx
,
1830 if (!W_ERROR_IS_OK(result
)) {
1835 if (info2_mask
& SPOOLSS_PRINTER_INFO_SEPFILE
) {
1836 result
= winreg_printer_write_sz(tmp_ctx
,
1841 if (!W_ERROR_IS_OK(result
)) {
1846 if (info2_mask
& SPOOLSS_PRINTER_INFO_SHARENAME
) {
1847 result
= winreg_printer_write_sz(tmp_ctx
,
1852 if (!W_ERROR_IS_OK(result
)) {
1857 if (info2_mask
& SPOOLSS_PRINTER_INFO_STARTTIME
) {
1858 result
= winreg_printer_write_dword(tmp_ctx
,
1863 if (!W_ERROR_IS_OK(result
)) {
1868 if (info2_mask
& SPOOLSS_PRINTER_INFO_STATUS
) {
1869 result
= winreg_printer_write_dword(tmp_ctx
,
1874 if (!W_ERROR_IS_OK(result
)) {
1879 if (info2_mask
& SPOOLSS_PRINTER_INFO_UNTILTIME
) {
1880 result
= winreg_printer_write_dword(tmp_ctx
,
1885 if (!W_ERROR_IS_OK(result
)) {
1890 result
= winreg_printer_write_dword(tmp_ctx
,
1894 winreg_printer_rev_changeid());
1895 if (!W_ERROR_IS_OK(result
)) {
1901 if (winreg_pipe
!= NULL
) {
1902 if (is_valid_policy_hnd(&key_hnd
)) {
1903 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
1905 if (is_valid_policy_hnd(&hive_hnd
)) {
1906 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
1910 TALLOC_FREE(tmp_ctx
);
1914 WERROR
winreg_get_printer(TALLOC_CTX
*mem_ctx
,
1915 struct auth_serversupplied_info
*server_info
,
1916 const char *servername
,
1917 const char *printer
,
1918 struct spoolss_PrinterInfo2
**pinfo2
)
1920 struct spoolss_PrinterInfo2
*info2
;
1921 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1922 struct rpc_pipe_client
*winreg_pipe
= NULL
;
1923 struct policy_handle hive_hnd
, key_hnd
;
1924 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
1925 struct spoolss_PrinterEnumValues
*v
;
1926 enum ndr_err_code ndr_err
;
1928 int snum
= lp_servicenumber(printer
);
1929 uint32_t num_values
= 0;
1932 WERROR result
= WERR_OK
;
1933 TALLOC_CTX
*tmp_ctx
;
1935 tmp_ctx
= talloc_new(mem_ctx
);
1936 if (tmp_ctx
== NULL
) {
1940 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1942 TALLOC_FREE(tmp_ctx
);
1946 result
= winreg_printer_openkey(tmp_ctx
,
1955 if (!W_ERROR_IS_OK(result
)) {
1956 DEBUG(0, ("winreg_get_printer: Could not open key %s: %s\n",
1957 path
, win_errstr(result
)));
1961 result
= winreg_printer_enumvalues(tmp_ctx
,
1966 if (!W_ERROR_IS_OK(result
)) {
1967 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1968 path
, win_errstr(result
)));
1972 info2
= talloc_zero(tmp_ctx
, struct spoolss_PrinterInfo2
);
1973 if (info2
== NULL
) {
1974 result
= WERR_NOMEM
;
1978 info2
->servername
= EMPTY_STRING
;
1979 info2
->printername
= EMPTY_STRING
;
1980 info2
->sharename
= EMPTY_STRING
;
1981 info2
->portname
= EMPTY_STRING
;
1982 info2
->drivername
= EMPTY_STRING
;
1983 info2
->comment
= EMPTY_STRING
;
1984 info2
->location
= EMPTY_STRING
;
1985 info2
->sepfile
= EMPTY_STRING
;
1986 info2
->printprocessor
= EMPTY_STRING
;
1987 info2
->datatype
= EMPTY_STRING
;
1988 info2
->parameters
= EMPTY_STRING
;
1990 if (servername
!= NULL
&& servername
[0] != '\0') {
1991 info2
->servername
= talloc_asprintf(info2
, "\\\\%s", servername
);
1992 if (info2
->servername
== NULL
) {
1993 result
= WERR_NOMEM
;
1998 for (i
= 0; i
< num_values
; i
++) {
1999 v
= &enum_values
[i
];
2001 result
= winreg_enumval_to_sz(info2
,
2004 &info2
->printername
);
2005 CHECK_ERROR(result
);
2007 result
= winreg_enumval_to_sz(info2
,
2011 CHECK_ERROR(result
);
2013 result
= winreg_enumval_to_sz(info2
,
2017 CHECK_ERROR(result
);
2019 result
= winreg_enumval_to_sz(info2
,
2023 CHECK_ERROR(result
);
2025 result
= winreg_enumval_to_sz(info2
,
2029 CHECK_ERROR(result
);
2031 result
= winreg_enumval_to_sz(info2
,
2035 CHECK_ERROR(result
);
2037 result
= winreg_enumval_to_sz(info2
,
2040 &info2
->printprocessor
);
2041 CHECK_ERROR(result
);
2043 result
= winreg_enumval_to_sz(info2
,
2047 CHECK_ERROR(result
);
2049 result
= winreg_enumval_to_sz(info2
,
2052 &info2
->parameters
);
2053 CHECK_ERROR(result
);
2055 result
= winreg_enumval_to_sz(info2
,
2058 &info2
->drivername
);
2059 CHECK_ERROR(result
);
2061 result
= winreg_enumval_to_dword(info2
,
2064 &info2
->attributes
);
2065 CHECK_ERROR(result
);
2067 result
= winreg_enumval_to_dword(info2
,
2071 CHECK_ERROR(result
);
2073 result
= winreg_enumval_to_dword(info2
,
2076 &info2
->defaultpriority
);
2077 CHECK_ERROR(result
);
2079 result
= winreg_enumval_to_dword(info2
,
2083 CHECK_ERROR(result
);
2085 result
= winreg_enumval_to_dword(info2
,
2089 CHECK_ERROR(result
);
2091 result
= winreg_enumval_to_dword(info2
,
2095 CHECK_ERROR(result
);
2097 result
= winreg_enumval_to_dword(info2
,
2101 CHECK_ERROR(result
);
2104 if (!W_ERROR_IS_OK(result
)) {
2105 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2108 win_errstr(result
)));
2112 /* Create the printername */
2113 if (info2
->servername
[0] != '\0') {
2114 if (lp_force_printername(snum
)) {
2115 const char *p
= talloc_asprintf(info2
, "%s\\%s",
2119 result
= WERR_NOMEM
;
2122 info2
->printername
= p
;
2124 char *p
= talloc_asprintf(info2
, "%s\\%s",
2126 info2
->printername
);
2128 result
= WERR_NOMEM
;
2131 info2
->printername
= p
;
2135 /* Construct the Device Mode */
2136 result
= winreg_printer_query_binary(tmp_ctx
,
2141 if (W_ERROR_IS_OK(result
)) {
2142 info2
->devmode
= talloc_zero(info2
, struct spoolss_DeviceMode
);
2143 if (info2
->devmode
== NULL
) {
2144 result
= WERR_NOMEM
;
2147 ndr_err
= ndr_pull_struct_blob(&blob
,
2150 (ndr_pull_flags_fn_t
) ndr_pull_spoolss_DeviceMode
);
2151 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2152 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2153 result
= WERR_NOMEM
;
2158 if (info2
->devmode
== NULL
&& lp_default_devmode(snum
)) {
2159 result
= spoolss_create_default_devmode(info2
,
2162 if (!W_ERROR_IS_OK(result
)) {
2167 if (info2
->devmode
!= NULL
) {
2168 info2
->devmode
->devicename
= talloc_strdup(info2
->devmode
,
2169 info2
->printername
);
2170 if (info2
->devmode
->devicename
== NULL
) {
2171 DEBUG(0, ("winreg_get_printer: Failed to set devicename\n"));
2172 result
= WERR_NOMEM
;
2177 result
= winreg_get_printer_secdesc(info2
,
2181 if (!W_ERROR_IS_OK(result
)) {
2185 /* Fix for OS/2 drivers. */
2186 if (get_remote_arch() == RA_OS2
) {
2187 spoolss_map_to_os2_driver(info2
, &info2
->drivername
);
2191 *pinfo2
= talloc_move(mem_ctx
, &info2
);
2196 if (winreg_pipe
!= NULL
) {
2197 if (is_valid_policy_hnd(&key_hnd
)) {
2198 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
2200 if (is_valid_policy_hnd(&hive_hnd
)) {
2201 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
2205 TALLOC_FREE(tmp_ctx
);
2209 WERROR
winreg_get_printer_secdesc(TALLOC_CTX
*mem_ctx
,
2210 struct auth_serversupplied_info
*server_info
,
2211 const char *sharename
,
2212 struct spoolss_security_descriptor
**psecdesc
)
2214 struct spoolss_security_descriptor
*secdesc
;
2215 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2216 struct rpc_pipe_client
*winreg_pipe
= NULL
;
2217 struct policy_handle hive_hnd
, key_hnd
;
2218 enum ndr_err_code ndr_err
;
2221 TALLOC_CTX
*tmp_ctx
;
2224 tmp_ctx
= talloc_new(mem_ctx
);
2225 if (tmp_ctx
== NULL
) {
2229 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
2231 talloc_free(tmp_ctx
);
2235 ZERO_STRUCT(hive_hnd
);
2236 ZERO_STRUCT(key_hnd
);
2238 result
= winreg_printer_openkey(tmp_ctx
,
2247 if (!W_ERROR_IS_OK(result
)) {
2248 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2249 goto create_default
;
2254 result
= winreg_printer_query_binary(tmp_ctx
,
2259 if (!W_ERROR_IS_OK(result
)) {
2260 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2261 goto create_default
;
2266 secdesc
= talloc_zero(tmp_ctx
, struct spoolss_security_descriptor
);
2267 if (secdesc
== NULL
) {
2268 result
= WERR_NOMEM
;
2271 ndr_err
= ndr_pull_struct_blob(&blob
,
2274 (ndr_pull_flags_fn_t
) ndr_pull_security_descriptor
);
2275 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2276 DEBUG(0, ("winreg_get_secdesc: Failed to unmarshall security descriptor\n"));
2277 result
= WERR_NOMEM
;
2282 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
2289 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
2290 if (!W_ERROR_IS_OK(result
)) {
2294 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
2295 this security descriptor has been created when winbindd was
2296 down. Take ownership of security descriptor. */
2297 if (sid_equal(secdesc
->owner_sid
, &global_sid_World
)) {
2298 struct dom_sid owner_sid
;
2300 /* Change sd owner to workgroup administrator */
2302 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid
)) {
2303 struct spoolss_security_descriptor
*new_secdesc
;
2307 sid_append_rid(&owner_sid
, DOMAIN_RID_ADMINISTRATOR
);
2309 new_secdesc
= make_sec_desc(tmp_ctx
,
2318 if (new_secdesc
== NULL
) {
2319 result
= WERR_NOMEM
;
2323 /* Swap with other one */
2324 secdesc
= new_secdesc
;
2328 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, secdesc
,
2329 (ndr_push_flags_fn_t
) ndr_push_security_descriptor
);
2330 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2331 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2332 result
= WERR_NOMEM
;
2336 result
= winreg_printer_write_binary(tmp_ctx
,
2341 if (!W_ERROR_IS_OK(result
)) {
2346 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
2351 if (winreg_pipe
!= NULL
) {
2352 if (is_valid_policy_hnd(&key_hnd
)) {
2353 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
2355 if (is_valid_policy_hnd(&hive_hnd
)) {
2356 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
2360 talloc_free(tmp_ctx
);
2364 WERROR
winreg_set_printer_secdesc(TALLOC_CTX
*mem_ctx
,
2365 struct auth_serversupplied_info
*server_info
,
2366 const char *sharename
,
2367 const struct spoolss_security_descriptor
*secdesc
)
2369 const struct spoolss_security_descriptor
*new_secdesc
= secdesc
;
2370 struct spoolss_security_descriptor
*old_secdesc
;
2371 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2372 struct rpc_pipe_client
*winreg_pipe
= NULL
;
2373 struct policy_handle hive_hnd
, key_hnd
;
2374 enum ndr_err_code ndr_err
;
2377 TALLOC_CTX
*tmp_ctx
;
2380 tmp_ctx
= talloc_new(mem_ctx
);
2381 if (tmp_ctx
== NULL
) {
2385 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
2387 talloc_free(tmp_ctx
);
2392 * The old owner and group sids of the security descriptor are not
2393 * present when new ACEs are added or removed by changing printer
2394 * permissions through NT. If they are NULL in the new security
2395 * descriptor then copy them over from the old one.
2397 if (!secdesc
->owner_sid
|| !secdesc
->group_sid
) {
2398 struct dom_sid
*owner_sid
, *group_sid
;
2399 struct security_acl
*dacl
, *sacl
;
2402 result
= winreg_get_printer_secdesc(tmp_ctx
,
2406 if (!W_ERROR_IS_OK(result
)) {
2407 talloc_free(tmp_ctx
);
2411 /* Pick out correct owner and group sids */
2412 owner_sid
= secdesc
->owner_sid
?
2413 secdesc
->owner_sid
:
2414 old_secdesc
->owner_sid
;
2416 group_sid
= secdesc
->group_sid
?
2417 secdesc
->group_sid
:
2418 old_secdesc
->group_sid
;
2420 dacl
= secdesc
->dacl
?
2424 sacl
= secdesc
->sacl
?
2428 /* Make a deep copy of the security descriptor */
2429 new_secdesc
= make_sec_desc(tmp_ctx
,
2437 if (new_secdesc
== NULL
) {
2438 talloc_free(tmp_ctx
);
2443 ZERO_STRUCT(hive_hnd
);
2444 ZERO_STRUCT(key_hnd
);
2446 result
= winreg_printer_openkey(tmp_ctx
,
2455 if (!W_ERROR_IS_OK(result
)) {
2459 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, new_secdesc
,
2460 (ndr_push_flags_fn_t
) ndr_push_security_descriptor
);
2461 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2462 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2463 result
= WERR_NOMEM
;
2467 result
= winreg_printer_write_binary(tmp_ctx
,
2474 if (winreg_pipe
!= NULL
) {
2475 if (is_valid_policy_hnd(&key_hnd
)) {
2476 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
2478 if (is_valid_policy_hnd(&hive_hnd
)) {
2479 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
2483 talloc_free(tmp_ctx
);
2487 /* Set printer data over the winreg pipe. */
2488 WERROR
winreg_set_printer_dataex(TALLOC_CTX
*mem_ctx
,
2489 struct auth_serversupplied_info
*server_info
,
2490 const char *printer
,
2493 enum winreg_Type type
,
2497 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2498 struct rpc_pipe_client
*winreg_pipe
= NULL
;
2499 struct policy_handle hive_hnd
, key_hnd
;
2500 struct winreg_String wvalue
;
2502 WERROR result
= WERR_OK
;
2504 TALLOC_CTX
*tmp_ctx
;
2506 tmp_ctx
= talloc_new(mem_ctx
);
2507 if (tmp_ctx
== NULL
) {
2511 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2513 TALLOC_FREE(tmp_ctx
);
2517 ZERO_STRUCT(hive_hnd
);
2518 ZERO_STRUCT(key_hnd
);
2520 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2521 key
, value
, access_mask
, printer
));
2522 result
= winreg_printer_openkey(tmp_ctx
,
2531 if (!W_ERROR_IS_OK(result
)) {
2532 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2533 key
, win_errstr(result
)));
2537 wvalue
.name
= value
;
2538 status
= rpccli_winreg_SetValue(winreg_pipe
,
2546 if (!NT_STATUS_IS_OK(status
)) {
2547 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2548 value
, nt_errstr(status
)));
2549 if (!W_ERROR_IS_OK(result
)) {
2552 result
= ntstatus_to_werror(status
);
2558 if (winreg_pipe
!= NULL
) {
2559 if (is_valid_policy_hnd(&key_hnd
)) {
2560 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
2562 if (is_valid_policy_hnd(&hive_hnd
)) {
2563 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
2567 TALLOC_FREE(tmp_ctx
);
2571 /* Get printer data over a winreg pipe. */
2572 WERROR
winreg_get_printer_dataex(TALLOC_CTX
*mem_ctx
,
2573 struct auth_serversupplied_info
*server_info
,
2574 const char *printer
,
2577 enum winreg_Type
*type
,
2579 uint32_t *data_size
)
2581 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2582 struct rpc_pipe_client
*winreg_pipe
= NULL
;
2583 struct policy_handle hive_hnd
, key_hnd
;
2584 struct winreg_String wvalue
;
2585 enum winreg_Type type_in
;
2588 uint32_t data_in_size
= 0;
2589 uint32_t value_len
= 0;
2590 WERROR result
= WERR_OK
;
2592 TALLOC_CTX
*tmp_ctx
;
2594 tmp_ctx
= talloc_new(mem_ctx
);
2595 if (tmp_ctx
== NULL
) {
2599 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2601 TALLOC_FREE(tmp_ctx
);
2605 ZERO_STRUCT(hive_hnd
);
2606 ZERO_STRUCT(key_hnd
);
2608 result
= winreg_printer_openkey(tmp_ctx
,
2617 if (!W_ERROR_IS_OK(result
)) {
2618 DEBUG(0, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2619 key
, win_errstr(result
)));
2623 wvalue
.name
= value
;
2626 * call QueryValue once with data == NULL to get the
2627 * needed memory size to be allocated, then allocate
2628 * data buffer and call again.
2630 status
= rpccli_winreg_QueryValue(winreg_pipe
,
2639 if (!NT_STATUS_IS_OK(status
)) {
2640 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2641 value
, nt_errstr(status
)));
2642 if (!W_ERROR_IS_OK(result
)) {
2645 result
= ntstatus_to_werror(status
);
2649 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
2650 if (data_in
== NULL
) {
2651 result
= WERR_NOMEM
;
2656 status
= rpccli_winreg_QueryValue(winreg_pipe
,
2665 if (!NT_STATUS_IS_OK(status
)) {
2666 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2667 value
, nt_errstr(status
)));
2668 if (!W_ERROR_IS_OK(result
)) {
2669 result
= ntstatus_to_werror(status
);
2675 *data_size
= data_in_size
;
2677 *data
= talloc_move(mem_ctx
, &data_in
);
2682 if (winreg_pipe
!= NULL
) {
2683 if (is_valid_policy_hnd(&key_hnd
)) {
2684 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
2686 if (is_valid_policy_hnd(&hive_hnd
)) {
2687 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
2691 TALLOC_FREE(tmp_ctx
);
2695 /* Enumerate on the values of a given key and provide the data. */
2696 WERROR
winreg_enum_printer_dataex(TALLOC_CTX
*mem_ctx
,
2697 struct auth_serversupplied_info
*server_info
,
2698 const char *printer
,
2700 uint32_t *pnum_values
,
2701 struct spoolss_PrinterEnumValues
**penum_values
)
2703 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2704 struct rpc_pipe_client
*winreg_pipe
= NULL
;
2705 struct policy_handle hive_hnd
, key_hnd
;
2707 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2708 uint32_t num_values
= 0;
2710 WERROR result
= WERR_OK
;
2712 TALLOC_CTX
*tmp_ctx
;
2714 tmp_ctx
= talloc_new(mem_ctx
);
2715 if (tmp_ctx
== NULL
) {
2719 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2721 TALLOC_FREE(tmp_ctx
);
2725 result
= winreg_printer_openkey(tmp_ctx
,
2734 if (!W_ERROR_IS_OK(result
)) {
2735 DEBUG(0, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2736 key
, win_errstr(result
)));
2740 result
= winreg_printer_enumvalues(tmp_ctx
,
2745 if (!W_ERROR_IS_OK(result
)) {
2746 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2747 key
, win_errstr(result
)));
2751 *pnum_values
= num_values
;
2753 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
2758 if (winreg_pipe
!= NULL
) {
2759 if (is_valid_policy_hnd(&key_hnd
)) {
2760 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
2762 if (is_valid_policy_hnd(&hive_hnd
)) {
2763 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
2767 TALLOC_FREE(tmp_ctx
);
2771 /* Delete printer data over a winreg pipe. */
2772 WERROR
winreg_delete_printer_dataex(TALLOC_CTX
*mem_ctx
,
2773 struct auth_serversupplied_info
*server_info
,
2774 const char *printer
,
2778 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2779 struct rpc_pipe_client
*winreg_pipe
= NULL
;
2780 struct policy_handle hive_hnd
, key_hnd
;
2781 struct winreg_String wvalue
;
2783 WERROR result
= WERR_OK
;
2786 TALLOC_CTX
*tmp_ctx
;
2788 tmp_ctx
= talloc_new(mem_ctx
);
2789 if (tmp_ctx
== NULL
) {
2793 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2795 TALLOC_FREE(tmp_ctx
);
2799 ZERO_STRUCT(hive_hnd
);
2800 ZERO_STRUCT(key_hnd
);
2802 result
= winreg_printer_openkey(tmp_ctx
,
2811 if (!W_ERROR_IS_OK(result
)) {
2812 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2813 key
, win_errstr(result
)));
2817 wvalue
.name
= value
;
2818 status
= rpccli_winreg_DeleteValue(winreg_pipe
,
2823 if (!NT_STATUS_IS_OK(status
)) {
2824 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2825 value
, nt_errstr(status
)));
2826 if (!W_ERROR_IS_OK(result
)) {
2829 result
= ntstatus_to_werror(status
);
2835 if (winreg_pipe
!= NULL
) {
2836 if (is_valid_policy_hnd(&key_hnd
)) {
2837 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
2839 if (is_valid_policy_hnd(&hive_hnd
)) {
2840 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
2844 TALLOC_FREE(tmp_ctx
);
2848 /* Enumerate on the subkeys of a given key and provide the data. */
2849 WERROR
winreg_enum_printer_key(TALLOC_CTX
*mem_ctx
,
2850 struct auth_serversupplied_info
*server_info
,
2851 const char *printer
,
2853 uint32_t *pnum_subkeys
,
2854 const char ***psubkeys
)
2856 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2857 struct rpc_pipe_client
*winreg_pipe
= NULL
;
2858 struct policy_handle hive_hnd
, key_hnd
;
2860 const char **subkeys
= NULL
;
2861 uint32_t num_subkeys
= -1;
2863 WERROR result
= WERR_OK
;
2865 TALLOC_CTX
*tmp_ctx
;
2867 tmp_ctx
= talloc_new(mem_ctx
);
2868 if (tmp_ctx
== NULL
) {
2872 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2874 TALLOC_FREE(tmp_ctx
);
2878 ZERO_STRUCT(hive_hnd
);
2879 ZERO_STRUCT(key_hnd
);
2881 result
= winreg_printer_openkey(tmp_ctx
,
2890 if (!W_ERROR_IS_OK(result
)) {
2891 DEBUG(0, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2892 key
, win_errstr(result
)));
2896 result
= winreg_printer_enumkeys(tmp_ctx
,
2901 if (!W_ERROR_IS_OK(result
)) {
2902 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2903 key
, win_errstr(result
)));
2907 *pnum_subkeys
= num_subkeys
;
2909 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
2914 if (winreg_pipe
!= NULL
) {
2915 if (is_valid_policy_hnd(&key_hnd
)) {
2916 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
2918 if (is_valid_policy_hnd(&hive_hnd
)) {
2919 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
2923 TALLOC_FREE(tmp_ctx
);
2927 /* Delete a key with subkeys of a given printer. */
2928 WERROR
winreg_delete_printer_key(TALLOC_CTX
*mem_ctx
,
2929 struct auth_serversupplied_info
*server_info
,
2930 const char *printer
,
2933 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2934 struct rpc_pipe_client
*winreg_pipe
= NULL
;
2935 struct policy_handle hive_hnd
, key_hnd
;
2939 TALLOC_CTX
*tmp_ctx
;
2941 tmp_ctx
= talloc_new(mem_ctx
);
2942 if (tmp_ctx
== NULL
) {
2946 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2948 TALLOC_FREE(tmp_ctx
);
2952 result
= winreg_printer_openkey(tmp_ctx
,
2961 if (!W_ERROR_IS_OK(result
)) {
2962 /* key doesn't exist */
2963 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2968 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2969 key
, win_errstr(result
)));
2973 if (is_valid_policy_hnd(&key_hnd
)) {
2974 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
2977 if (key
== NULL
|| key
[0] == '\0') {
2980 keyname
= talloc_asprintf(tmp_ctx
,
2984 if (keyname
== NULL
) {
2985 result
= WERR_NOMEM
;
2990 result
= winreg_printer_delete_subkeys(tmp_ctx
,
2995 if (!W_ERROR_IS_OK(result
)) {
2996 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2997 key
, win_errstr(result
)));
3002 if (winreg_pipe
!= NULL
) {
3003 if (is_valid_policy_hnd(&key_hnd
)) {
3004 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
3006 if (is_valid_policy_hnd(&hive_hnd
)) {
3007 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
3011 TALLOC_FREE(tmp_ctx
);
3015 WERROR
winreg_printer_update_changeid(TALLOC_CTX
*mem_ctx
,
3016 struct auth_serversupplied_info
*server_info
,
3017 const char *printer
)
3019 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3020 struct rpc_pipe_client
*winreg_pipe
= NULL
;
3021 struct policy_handle hive_hnd
, key_hnd
;
3024 TALLOC_CTX
*tmp_ctx
;
3026 tmp_ctx
= talloc_new(mem_ctx
);
3027 if (tmp_ctx
== NULL
) {
3031 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
3033 TALLOC_FREE(tmp_ctx
);
3037 ZERO_STRUCT(hive_hnd
);
3038 ZERO_STRUCT(key_hnd
);
3040 result
= winreg_printer_openkey(tmp_ctx
,
3049 if (!W_ERROR_IS_OK(result
)) {
3050 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
3051 path
, win_errstr(result
)));
3055 result
= winreg_printer_write_dword(tmp_ctx
,
3059 winreg_printer_rev_changeid());
3060 if (!W_ERROR_IS_OK(result
)) {
3066 if (winreg_pipe
!= NULL
) {
3067 if (is_valid_policy_hnd(&key_hnd
)) {
3068 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
3070 if (is_valid_policy_hnd(&hive_hnd
)) {
3071 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
3075 TALLOC_FREE(tmp_ctx
);
3079 WERROR
winreg_printer_get_changeid(TALLOC_CTX
*mem_ctx
,
3080 struct auth_serversupplied_info
*server_info
,
3081 const char *printer
,
3082 uint32_t *pchangeid
)
3084 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3085 struct rpc_pipe_client
*winreg_pipe
= NULL
;
3086 struct policy_handle hive_hnd
, key_hnd
;
3087 uint32_t changeid
= 0;
3090 TALLOC_CTX
*tmp_ctx
;
3092 tmp_ctx
= talloc_new(mem_ctx
);
3093 if (tmp_ctx
== NULL
) {
3097 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
3099 TALLOC_FREE(tmp_ctx
);
3103 ZERO_STRUCT(hive_hnd
);
3104 ZERO_STRUCT(key_hnd
);
3106 result
= winreg_printer_openkey(tmp_ctx
,
3115 if (!W_ERROR_IS_OK(result
)) {
3116 DEBUG(0, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
3117 path
, win_errstr(result
)));
3121 DEBUG(0, ("winreg_printer_get_changeid: get changeid from %s\n", path
));
3122 result
= winreg_printer_query_dword(tmp_ctx
,
3127 if (!W_ERROR_IS_OK(result
)) {
3132 *pchangeid
= changeid
;
3137 if (winreg_pipe
!= NULL
) {
3138 if (is_valid_policy_hnd(&key_hnd
)) {
3139 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
3141 if (is_valid_policy_hnd(&hive_hnd
)) {
3142 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
3146 TALLOC_FREE(tmp_ctx
);
3151 * The special behaviour of the spoolss forms is documented at the website:
3153 * Managing Win32 Printserver Forms
3154 * http://unixwiz.net/techtips/winspooler-forms.html
3157 WERROR
winreg_printer_addform1(TALLOC_CTX
*mem_ctx
,
3158 struct auth_serversupplied_info
*server_info
,
3159 struct spoolss_AddFormInfo1
*form
)
3161 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3162 struct rpc_pipe_client
*winreg_pipe
= NULL
;
3163 struct policy_handle hive_hnd
, key_hnd
;
3164 struct winreg_String wvalue
;
3166 uint32_t num_info
= 0;
3167 union spoolss_FormInfo
*info
= NULL
;
3171 TALLOC_CTX
*tmp_ctx
;
3173 tmp_ctx
= talloc_new(mem_ctx
);
3174 if (tmp_ctx
== NULL
) {
3178 ZERO_STRUCT(hive_hnd
);
3179 ZERO_STRUCT(key_hnd
);
3181 result
= winreg_printer_openkey(tmp_ctx
,
3184 TOP_LEVEL_CONTROL_FORMS_KEY
,
3190 if (!W_ERROR_IS_OK(result
)) {
3191 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
3192 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3196 result
= winreg_printer_enumforms1(tmp_ctx
, server_info
, &num_info
, &info
);
3197 if (!W_ERROR_IS_OK(result
)) {
3198 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
3199 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3203 /* If form name already exists or is builtin return ALREADY_EXISTS */
3204 for (i
= 0; i
< num_info
; i
++) {
3205 if (strequal(info
[i
].info1
.form_name
, form
->form_name
)) {
3206 result
= WERR_FILE_EXISTS
;
3211 wvalue
.name
= form
->form_name
;
3213 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
3214 SIVAL(blob
.data
, 0, form
->size
.width
);
3215 SIVAL(blob
.data
, 4, form
->size
.height
);
3216 SIVAL(blob
.data
, 8, form
->area
.left
);
3217 SIVAL(blob
.data
, 12, form
->area
.top
);
3218 SIVAL(blob
.data
, 16, form
->area
.right
);
3219 SIVAL(blob
.data
, 20, form
->area
.bottom
);
3220 SIVAL(blob
.data
, 24, num_info
+ 1); /* FIXME */
3221 SIVAL(blob
.data
, 28, form
->flags
);
3223 status
= rpccli_winreg_SetValue(winreg_pipe
,
3231 if (!NT_STATUS_IS_OK(status
)) {
3232 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3233 wvalue
.name
, nt_errstr(status
)));
3234 if (!W_ERROR_IS_OK(result
)) {
3237 result
= ntstatus_to_werror(status
);
3243 if (winreg_pipe
!= NULL
) {
3244 if (is_valid_policy_hnd(&key_hnd
)) {
3245 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
3247 if (is_valid_policy_hnd(&hive_hnd
)) {
3248 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
3253 TALLOC_FREE(tmp_ctx
);
3257 WERROR
winreg_printer_enumforms1(TALLOC_CTX
*mem_ctx
,
3258 struct auth_serversupplied_info
*server_info
,
3259 uint32_t *pnum_info
,
3260 union spoolss_FormInfo
**pinfo
)
3262 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3263 struct rpc_pipe_client
*winreg_pipe
= NULL
;
3264 struct policy_handle hive_hnd
, key_hnd
;
3265 union spoolss_FormInfo
*info
;
3266 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
3267 uint32_t num_values
= 0;
3268 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3271 TALLOC_CTX
*tmp_ctx
;
3273 tmp_ctx
= talloc_new(mem_ctx
);
3274 if (tmp_ctx
== NULL
) {
3278 ZERO_STRUCT(hive_hnd
);
3279 ZERO_STRUCT(key_hnd
);
3281 result
= winreg_printer_openkey(tmp_ctx
,
3284 TOP_LEVEL_CONTROL_FORMS_KEY
,
3290 if (!W_ERROR_IS_OK(result
)) {
3291 /* key doesn't exist */
3292 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3297 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3298 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3302 result
= winreg_printer_enumvalues(tmp_ctx
,
3307 if (!W_ERROR_IS_OK(result
)) {
3308 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3309 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3313 info
= TALLOC_ARRAY(tmp_ctx
, union spoolss_FormInfo
, num_builtin
+ num_values
);
3315 result
= WERR_NOMEM
;
3319 /* Enumerate BUILTIN forms */
3320 for (i
= 0; i
< num_builtin
; i
++) {
3321 info
[i
].info1
= builtin_forms1
[i
];
3324 /* Enumerate registry forms */
3325 for (i
= 0; i
< num_values
; i
++) {
3326 union spoolss_FormInfo val
;
3328 if (enum_values
[i
].type
!= REG_BINARY
||
3329 enum_values
[i
].data_length
!= 32) {
3333 val
.info1
.form_name
= talloc_strdup(info
, enum_values
[i
].value_name
);
3334 if (val
.info1
.form_name
== NULL
) {
3335 result
= WERR_NOMEM
;
3339 val
.info1
.size
.width
= IVAL(enum_values
[i
].data
->data
, 0);
3340 val
.info1
.size
.height
= IVAL(enum_values
[i
].data
->data
, 4);
3341 val
.info1
.area
.left
= IVAL(enum_values
[i
].data
->data
, 8);
3342 val
.info1
.area
.top
= IVAL(enum_values
[i
].data
->data
, 12);
3343 val
.info1
.area
.right
= IVAL(enum_values
[i
].data
->data
, 16);
3344 val
.info1
.area
.bottom
= IVAL(enum_values
[i
].data
->data
, 20);
3345 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3346 val
.info1
.flags
= IVAL(enum_values
[i
].data
->data
, 28);
3348 info
[i
+ num_builtin
] = val
;
3351 *pnum_info
= num_builtin
+ num_values
;
3353 *pinfo
= talloc_move(mem_ctx
, &info
);
3357 if (winreg_pipe
!= NULL
) {
3358 if (is_valid_policy_hnd(&key_hnd
)) {
3359 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
3361 if (is_valid_policy_hnd(&hive_hnd
)) {
3362 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
3366 TALLOC_FREE(enum_values
);
3367 TALLOC_FREE(tmp_ctx
);
3371 WERROR
winreg_printer_deleteform1(TALLOC_CTX
*mem_ctx
,
3372 struct auth_serversupplied_info
*server_info
,
3373 const char *form_name
)
3375 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3376 struct rpc_pipe_client
*winreg_pipe
= NULL
;
3377 struct policy_handle hive_hnd
, key_hnd
;
3378 struct winreg_String wvalue
;
3379 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3381 WERROR result
= WERR_OK
;
3383 TALLOC_CTX
*tmp_ctx
;
3385 for (i
= 0; i
< num_builtin
; i
++) {
3386 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3387 return WERR_INVALID_PARAMETER
;
3391 tmp_ctx
= talloc_new(mem_ctx
);
3392 if (tmp_ctx
== NULL
) {
3396 ZERO_STRUCT(hive_hnd
);
3397 ZERO_STRUCT(key_hnd
);
3399 result
= winreg_printer_openkey(tmp_ctx
,
3402 TOP_LEVEL_CONTROL_FORMS_KEY
,
3408 if (!W_ERROR_IS_OK(result
)) {
3409 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3410 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3411 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3412 result
= WERR_INVALID_FORM_NAME
;
3417 wvalue
.name
= form_name
;
3418 status
= rpccli_winreg_DeleteValue(winreg_pipe
,
3423 if (!NT_STATUS_IS_OK(status
)) {
3424 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3425 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3426 result
= WERR_INVALID_FORM_NAME
;
3429 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3430 wvalue
.name
, nt_errstr(status
)));
3431 if (!W_ERROR_IS_OK(result
)) {
3434 result
= ntstatus_to_werror(status
);
3440 if (winreg_pipe
!= NULL
) {
3441 if (is_valid_policy_hnd(&key_hnd
)) {
3442 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
3444 if (is_valid_policy_hnd(&hive_hnd
)) {
3445 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
3449 TALLOC_FREE(tmp_ctx
);
3453 WERROR
winreg_printer_setform1(TALLOC_CTX
*mem_ctx
,
3454 struct auth_serversupplied_info
*server_info
,
3455 const char *form_name
,
3456 struct spoolss_AddFormInfo1
*form
)
3458 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3459 struct rpc_pipe_client
*winreg_pipe
= NULL
;
3460 struct policy_handle hive_hnd
, key_hnd
;
3461 struct winreg_String wvalue
;
3463 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3467 TALLOC_CTX
*tmp_ctx
= NULL
;
3469 for (i
= 0; i
< num_builtin
; i
++) {
3470 if (strequal(builtin_forms1
[i
].form_name
, form
->form_name
)) {
3471 result
= WERR_INVALID_PARAM
;
3476 tmp_ctx
= talloc_new(mem_ctx
);
3477 if (tmp_ctx
== NULL
) {
3481 ZERO_STRUCT(hive_hnd
);
3482 ZERO_STRUCT(key_hnd
);
3484 result
= winreg_printer_openkey(tmp_ctx
,
3487 TOP_LEVEL_CONTROL_FORMS_KEY
,
3493 if (!W_ERROR_IS_OK(result
)) {
3494 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3495 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3499 /* If form_name != form->form_name then we renamed the form */
3500 if (strequal(form_name
, form
->form_name
)) {
3501 result
= winreg_printer_deleteform1(tmp_ctx
, server_info
, form_name
);
3502 if (!W_ERROR_IS_OK(result
)) {
3503 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3504 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3509 wvalue
.name
= form
->form_name
;
3511 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
3512 SIVAL(blob
.data
, 0, form
->size
.width
);
3513 SIVAL(blob
.data
, 4, form
->size
.height
);
3514 SIVAL(blob
.data
, 8, form
->area
.left
);
3515 SIVAL(blob
.data
, 12, form
->area
.top
);
3516 SIVAL(blob
.data
, 16, form
->area
.right
);
3517 SIVAL(blob
.data
, 20, form
->area
.bottom
);
3518 SIVAL(blob
.data
, 24, 42);
3519 SIVAL(blob
.data
, 28, form
->flags
);
3521 status
= rpccli_winreg_SetValue(winreg_pipe
,
3529 if (!NT_STATUS_IS_OK(status
)) {
3530 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3531 wvalue
.name
, nt_errstr(status
)));
3532 if (!W_ERROR_IS_OK(result
)) {
3535 result
= ntstatus_to_werror(status
);
3541 if (winreg_pipe
!= NULL
) {
3542 if (is_valid_policy_hnd(&key_hnd
)) {
3543 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
3545 if (is_valid_policy_hnd(&hive_hnd
)) {
3546 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
3550 TALLOC_FREE(tmp_ctx
);
3554 WERROR
winreg_printer_getform1(TALLOC_CTX
*mem_ctx
,
3555 struct auth_serversupplied_info
*server_info
,
3556 const char *form_name
,
3557 struct spoolss_FormInfo1
*r
)
3559 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3560 struct rpc_pipe_client
*winreg_pipe
= NULL
;
3561 struct policy_handle hive_hnd
, key_hnd
;
3562 struct winreg_String wvalue
;
3563 enum winreg_Type type_in
;
3565 uint32_t data_in_size
= 0;
3566 uint32_t value_len
= 0;
3567 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3571 TALLOC_CTX
*tmp_ctx
;
3573 /* check builtin forms first */
3574 for (i
= 0; i
< num_builtin
; i
++) {
3575 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3576 *r
= builtin_forms1
[i
];
3581 tmp_ctx
= talloc_new(mem_ctx
);
3582 if (tmp_ctx
== NULL
) {
3586 ZERO_STRUCT(hive_hnd
);
3587 ZERO_STRUCT(key_hnd
);
3589 result
= winreg_printer_openkey(tmp_ctx
,
3592 TOP_LEVEL_CONTROL_FORMS_KEY
,
3598 if (!W_ERROR_IS_OK(result
)) {
3599 DEBUG(0, ("winreg_printer_getform1: Could not open key %s: %s\n",
3600 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3604 wvalue
.name
= form_name
;
3607 * call QueryValue once with data == NULL to get the
3608 * needed memory size to be allocated, then allocate
3609 * data buffer and call again.
3611 status
= rpccli_winreg_QueryValue(winreg_pipe
,
3620 if (!NT_STATUS_IS_OK(status
)) {
3621 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3622 wvalue
.name
, nt_errstr(status
)));
3623 if (!W_ERROR_IS_OK(result
)) {
3626 result
= ntstatus_to_werror(status
);
3630 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
3631 if (data_in
== NULL
) {
3632 result
= WERR_NOMEM
;
3637 status
= rpccli_winreg_QueryValue(winreg_pipe
,
3646 if (!NT_STATUS_IS_OK(status
)) {
3647 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3648 wvalue
.name
, nt_errstr(status
)));
3649 if (!W_ERROR_IS_OK(result
)) {
3652 result
= ntstatus_to_werror(status
);
3656 r
->form_name
= talloc_strdup(mem_ctx
, form_name
);
3657 if (r
->form_name
== NULL
) {
3658 result
= WERR_NOMEM
;
3662 r
->size
.width
= IVAL(data_in
, 0);
3663 r
->size
.height
= IVAL(data_in
, 4);
3664 r
->area
.left
= IVAL(data_in
, 8);
3665 r
->area
.top
= IVAL(data_in
, 12);
3666 r
->area
.right
= IVAL(data_in
, 16);
3667 r
->area
.bottom
= IVAL(data_in
, 20);
3668 /* skip index IVAL(data_in, 24)));*/
3669 r
->flags
= IVAL(data_in
, 28);
3673 if (winreg_pipe
!= NULL
) {
3674 if (is_valid_policy_hnd(&key_hnd
)) {
3675 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
3677 if (is_valid_policy_hnd(&hive_hnd
)) {
3678 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
3682 TALLOC_FREE(tmp_ctx
);
3686 WERROR
winreg_add_driver(TALLOC_CTX
*mem_ctx
,
3687 struct auth_serversupplied_info
*server_info
,
3688 struct spoolss_AddDriverInfoCtr
*r
,
3689 const char **driver_name
,
3690 uint32_t *driver_version
)
3692 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3693 struct rpc_pipe_client
*winreg_pipe
= NULL
;
3694 struct policy_handle hive_hnd
, key_hnd
;
3695 struct spoolss_DriverInfo8 info8
;
3696 TALLOC_CTX
*tmp_ctx
= NULL
;
3699 ZERO_STRUCT(hive_hnd
);
3700 ZERO_STRUCT(key_hnd
);
3703 if (!driver_info_ctr_to_info8(r
, &info8
)) {
3704 result
= WERR_INVALID_PARAMETER
;
3708 tmp_ctx
= talloc_new(mem_ctx
);
3709 if (tmp_ctx
== NULL
) {
3713 result
= winreg_printer_opendriver(tmp_ctx
,
3722 if (!W_ERROR_IS_OK(result
)) {
3723 DEBUG(0, ("winreg_add_driver: "
3724 "Could not open driver key (%s,%s,%d): %s\n",
3725 info8
.driver_name
, info8
.architecture
,
3726 info8
.version
, win_errstr(result
)));
3730 /* TODO: "Attributes" ? */
3732 result
= winreg_printer_write_dword(tmp_ctx
, winreg_pipe
,
3733 &key_hnd
, "Version",
3735 if (!W_ERROR_IS_OK(result
)) {
3739 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3742 if (!W_ERROR_IS_OK(result
)) {
3746 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3747 &key_hnd
, "Data File",
3749 if (!W_ERROR_IS_OK(result
)) {
3753 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3754 &key_hnd
, "Configuration File",
3756 if (!W_ERROR_IS_OK(result
)) {
3760 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3761 &key_hnd
, "Help File",
3763 if (!W_ERROR_IS_OK(result
)) {
3767 result
= winreg_printer_write_multi_sz(tmp_ctx
, winreg_pipe
,
3768 &key_hnd
, "Dependent Files",
3769 info8
.dependent_files
);
3770 if (!W_ERROR_IS_OK(result
)) {
3774 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3775 &key_hnd
, "Monitor",
3776 info8
.monitor_name
);
3777 if (!W_ERROR_IS_OK(result
)) {
3781 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3782 &key_hnd
, "Datatype",
3783 info8
.default_datatype
);
3784 if (!W_ERROR_IS_OK(result
)) {
3788 result
= winreg_printer_write_multi_sz(tmp_ctx
, winreg_pipe
,
3789 &key_hnd
, "Previous Names",
3790 info8
.previous_names
);
3791 if (!W_ERROR_IS_OK(result
)) {
3795 result
= winreg_printer_write_date(tmp_ctx
, winreg_pipe
,
3796 &key_hnd
, "DriverDate",
3798 if (!W_ERROR_IS_OK(result
)) {
3802 result
= winreg_printer_write_ver(tmp_ctx
, winreg_pipe
,
3803 &key_hnd
, "DriverVersion",
3804 info8
.driver_version
);
3805 if (!W_ERROR_IS_OK(result
)) {
3809 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3810 &key_hnd
, "Manufacturer",
3811 info8
.manufacturer_name
);
3812 if (!W_ERROR_IS_OK(result
)) {
3816 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3817 &key_hnd
, "OEM URL",
3818 info8
.manufacturer_url
);
3819 if (!W_ERROR_IS_OK(result
)) {
3823 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3824 &key_hnd
, "HardwareID",
3826 if (!W_ERROR_IS_OK(result
)) {
3830 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3831 &key_hnd
, "Provider",
3833 if (!W_ERROR_IS_OK(result
)) {
3837 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3838 &key_hnd
, "Print Processor",
3839 info8
.print_processor
);
3840 if (!W_ERROR_IS_OK(result
)) {
3844 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3845 &key_hnd
, "VendorSetup",
3846 info8
.vendor_setup
);
3847 if (!W_ERROR_IS_OK(result
)) {
3851 result
= winreg_printer_write_multi_sz(tmp_ctx
, winreg_pipe
,
3852 &key_hnd
, "Color Profiles",
3853 info8
.color_profiles
);
3854 if (!W_ERROR_IS_OK(result
)) {
3858 result
= winreg_printer_write_sz(tmp_ctx
, winreg_pipe
,
3859 &key_hnd
, "InfPath",
3861 if (!W_ERROR_IS_OK(result
)) {
3865 result
= winreg_printer_write_dword(tmp_ctx
, winreg_pipe
, &key_hnd
,
3866 "PrinterDriverAttributes",
3867 info8
.printer_driver_attributes
);
3868 if (!W_ERROR_IS_OK(result
)) {
3872 result
= winreg_printer_write_multi_sz(tmp_ctx
, winreg_pipe
,
3873 &key_hnd
, "CoreDependencies",
3874 info8
.core_driver_dependencies
);
3875 if (!W_ERROR_IS_OK(result
)) {
3879 result
= winreg_printer_write_date(tmp_ctx
, winreg_pipe
,
3880 &key_hnd
, "MinInboxDriverVerDate",
3881 info8
.min_inbox_driver_ver_date
);
3882 if (!W_ERROR_IS_OK(result
)) {
3886 result
= winreg_printer_write_ver(tmp_ctx
, winreg_pipe
, &key_hnd
,
3887 "MinInboxDriverVerVersion",
3888 info8
.min_inbox_driver_ver_version
);
3889 if (!W_ERROR_IS_OK(result
)) {
3893 *driver_name
= info8
.driver_name
;
3894 *driver_version
= info8
.version
;
3897 if (winreg_pipe
!= NULL
) {
3898 if (is_valid_policy_hnd(&key_hnd
)) {
3899 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
3901 if (is_valid_policy_hnd(&hive_hnd
)) {
3902 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
3906 TALLOC_FREE(tmp_ctx
);
3910 WERROR
winreg_get_driver(TALLOC_CTX
*mem_ctx
,
3911 struct auth_serversupplied_info
*server_info
,
3912 const char *architecture
,
3913 const char *driver_name
,
3914 uint32_t driver_version
,
3915 struct spoolss_DriverInfo8
**_info8
)
3917 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3918 struct rpc_pipe_client
*winreg_pipe
= NULL
;
3919 struct policy_handle hive_hnd
, key_hnd
;
3920 struct spoolss_DriverInfo8 i8
, *info8
;
3921 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
3922 struct spoolss_PrinterEnumValues
*v
;
3923 uint32_t num_values
= 0;
3924 TALLOC_CTX
*tmp_ctx
;
3928 ZERO_STRUCT(hive_hnd
);
3929 ZERO_STRUCT(key_hnd
);
3932 tmp_ctx
= talloc_new(mem_ctx
);
3933 if (tmp_ctx
== NULL
) {
3937 if (driver_version
== DRIVER_ANY_VERSION
) {
3938 /* look for Win2k first and then for NT4 */
3939 result
= winreg_printer_opendriver(tmp_ctx
,
3948 if (!W_ERROR_IS_OK(result
)) {
3949 result
= winreg_printer_opendriver(tmp_ctx
,
3960 /* ok normal case */
3961 result
= winreg_printer_opendriver(tmp_ctx
,
3971 if (!W_ERROR_IS_OK(result
)) {
3972 DEBUG(5, ("winreg_get_driver: "
3973 "Could not open driver key (%s,%s,%d): %s\n",
3974 driver_name
, architecture
,
3975 driver_version
, win_errstr(result
)));
3979 result
= winreg_printer_enumvalues(tmp_ctx
,
3984 if (!W_ERROR_IS_OK(result
)) {
3985 DEBUG(0, ("winreg_get_driver: "
3986 "Could not enumerate values for (%s,%s,%d): %s\n",
3987 driver_name
, architecture
,
3988 driver_version
, win_errstr(result
)));
3992 info8
= talloc_zero(tmp_ctx
, struct spoolss_DriverInfo8
);
3993 if (info8
== NULL
) {
3994 result
= WERR_NOMEM
;
3998 info8
->driver_name
= talloc_strdup(info8
, driver_name
);
3999 if (info8
->driver_name
== NULL
) {
4000 result
= WERR_NOMEM
;
4004 info8
->architecture
= talloc_strdup(info8
, architecture
);
4005 if (info8
->architecture
== NULL
) {
4006 result
= WERR_NOMEM
;
4010 info8
->config_file
= EMPTY_STRING
;
4011 info8
->data_file
= EMPTY_STRING
;
4012 info8
->default_datatype
= EMPTY_STRING
;
4013 info8
->driver_path
= EMPTY_STRING
;
4014 info8
->hardware_id
= EMPTY_STRING
;
4015 info8
->help_file
= EMPTY_STRING
;
4016 info8
->inf_path
= EMPTY_STRING
;
4017 info8
->manufacturer_name
= EMPTY_STRING
;
4018 info8
->manufacturer_url
= EMPTY_STRING
;
4019 info8
->monitor_name
= EMPTY_STRING
;
4020 info8
->print_processor
= EMPTY_STRING
;
4021 info8
->provider
= EMPTY_STRING
;
4022 info8
->vendor_setup
= EMPTY_STRING
;
4024 info8
->color_profiles
= empty_string_array
;
4025 info8
->core_driver_dependencies
= EMPTY_STRING_ARRAY
;
4026 info8
->dependent_files
= EMPTY_STRING_ARRAY
;
4027 info8
->previous_names
= EMPTY_STRING_ARRAY
;
4031 for (i
= 0; i
< num_values
; i
++) {
4032 const char *tmp_str
;
4034 v
= &enum_values
[i
];
4036 result
= winreg_enumval_to_dword(info8
, v
,
4039 CHECK_ERROR(result
);
4041 result
= winreg_enumval_to_sz(info8
, v
,
4043 &info8
->driver_path
);
4044 CHECK_ERROR(result
);
4046 result
= winreg_enumval_to_sz(info8
, v
,
4049 CHECK_ERROR(result
);
4051 result
= winreg_enumval_to_sz(info8
, v
,
4052 "Configuration File",
4053 &info8
->config_file
);
4054 CHECK_ERROR(result
);
4056 result
= winreg_enumval_to_sz(info8
, v
,
4059 CHECK_ERROR(result
);
4061 result
= winreg_enumval_to_multi_sz(info8
, v
,
4063 &info8
->dependent_files
);
4064 CHECK_ERROR(result
);
4066 result
= winreg_enumval_to_sz(info8
, v
,
4068 &info8
->monitor_name
);
4069 CHECK_ERROR(result
);
4071 result
= winreg_enumval_to_sz(info8
, v
,
4073 &info8
->default_datatype
);
4074 CHECK_ERROR(result
);
4076 result
= winreg_enumval_to_multi_sz(info8
, v
,
4078 &info8
->previous_names
);
4079 CHECK_ERROR(result
);
4081 result
= winreg_enumval_to_sz(info8
, v
,
4084 if (W_ERROR_IS_OK(result
)) {
4085 result
= winreg_printer_date_to_NTTIME(tmp_str
,
4086 &info8
->driver_date
);
4088 CHECK_ERROR(result
);
4090 result
= winreg_enumval_to_sz(info8
, v
,
4093 if (W_ERROR_IS_OK(result
)) {
4094 result
= winreg_printer_ver_to_dword(tmp_str
,
4095 &info8
->driver_version
);
4097 CHECK_ERROR(result
);
4099 result
= winreg_enumval_to_sz(info8
, v
,
4101 &info8
->manufacturer_name
);
4102 CHECK_ERROR(result
);
4104 result
= winreg_enumval_to_sz(info8
, v
,
4106 &info8
->manufacturer_url
);
4107 CHECK_ERROR(result
);
4109 result
= winreg_enumval_to_sz(info8
, v
,
4111 &info8
->hardware_id
);
4112 CHECK_ERROR(result
);
4114 result
= winreg_enumval_to_sz(info8
, v
,
4117 CHECK_ERROR(result
);
4119 result
= winreg_enumval_to_sz(info8
, v
,
4121 &info8
->print_processor
);
4122 CHECK_ERROR(result
);
4124 result
= winreg_enumval_to_sz(info8
, v
,
4126 &info8
->vendor_setup
);
4127 CHECK_ERROR(result
);
4129 result
= winreg_enumval_to_multi_sz(info8
, v
,
4131 &info8
->color_profiles
);
4132 CHECK_ERROR(result
);
4134 result
= winreg_enumval_to_sz(info8
, v
,
4137 CHECK_ERROR(result
);
4139 result
= winreg_enumval_to_dword(info8
, v
,
4140 "PrinterDriverAttributes",
4141 &info8
->printer_driver_attributes
);
4142 CHECK_ERROR(result
);
4144 result
= winreg_enumval_to_multi_sz(info8
, v
,
4146 &info8
->core_driver_dependencies
);
4147 CHECK_ERROR(result
);
4149 result
= winreg_enumval_to_sz(info8
, v
,
4150 "MinInboxDriverVerDate",
4152 if (W_ERROR_IS_OK(result
)) {
4153 result
= winreg_printer_date_to_NTTIME(tmp_str
,
4154 &info8
->min_inbox_driver_ver_date
);
4156 CHECK_ERROR(result
);
4158 result
= winreg_enumval_to_sz(info8
, v
,
4159 "MinInboxDriverVerVersion",
4161 if (W_ERROR_IS_OK(result
)) {
4162 result
= winreg_printer_ver_to_dword(tmp_str
,
4163 &info8
->min_inbox_driver_ver_version
);
4165 CHECK_ERROR(result
);
4168 if (!W_ERROR_IS_OK(result
)) {
4169 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4170 "for %s: %s\n", v
->value_name
,
4171 win_errstr(result
)));
4175 *_info8
= talloc_steal(mem_ctx
, info8
);
4178 if (winreg_pipe
!= NULL
) {
4179 if (is_valid_policy_hnd(&key_hnd
)) {
4180 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
4182 if (is_valid_policy_hnd(&hive_hnd
)) {
4183 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
4187 TALLOC_FREE(tmp_ctx
);
4191 WERROR
winreg_del_driver(TALLOC_CTX
*mem_ctx
,
4192 struct auth_serversupplied_info
*server_info
,
4193 struct spoolss_DriverInfo8
*info8
,
4196 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4197 struct rpc_pipe_client
*winreg_pipe
= NULL
;
4198 struct policy_handle hive_hnd
, key_hnd
;
4199 TALLOC_CTX
*tmp_ctx
;
4203 ZERO_STRUCT(hive_hnd
);
4204 ZERO_STRUCT(key_hnd
);
4206 tmp_ctx
= talloc_new(mem_ctx
);
4207 if (tmp_ctx
== NULL
) {
4211 /* test that the key exists */
4212 result
= winreg_printer_opendriver(tmp_ctx
,
4215 info8
->architecture
,
4221 if (!W_ERROR_IS_OK(result
)) {
4222 /* key doesn't exist */
4223 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
4228 DEBUG(5, ("winreg_del_driver: "
4229 "Could not open driver (%s,%s,%u): %s\n",
4230 info8
->driver_name
, info8
->architecture
,
4231 version
, win_errstr(result
)));
4236 if (is_valid_policy_hnd(&key_hnd
)) {
4237 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
4240 key_name
= talloc_asprintf(tmp_ctx
,
4241 "%s\\Environments\\%s\\Drivers\\Version-%u",
4242 TOP_LEVEL_CONTROL_KEY
,
4243 info8
->architecture
, version
);
4244 if (key_name
== NULL
) {
4245 result
= WERR_NOMEM
;
4249 result
= winreg_printer_delete_subkeys(tmp_ctx
,
4254 if (!W_ERROR_IS_OK(result
)) {
4255 DEBUG(0, ("winreg_del_driver: "
4256 "Could not open driver (%s,%s,%u): %s\n",
4257 info8
->driver_name
, info8
->architecture
,
4258 version
, win_errstr(result
)));
4264 if (winreg_pipe
!= NULL
) {
4265 if (is_valid_policy_hnd(&key_hnd
)) {
4266 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
4268 if (is_valid_policy_hnd(&hive_hnd
)) {
4269 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
4273 TALLOC_FREE(tmp_ctx
);
4277 WERROR
winreg_get_driver_list(TALLOC_CTX
*mem_ctx
,
4278 struct auth_serversupplied_info
*server_info
,
4279 const char *architecture
,
4281 uint32_t *num_drivers
,
4282 const char ***drivers_p
)
4284 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4285 struct rpc_pipe_client
*winreg_pipe
= NULL
;
4286 struct policy_handle hive_hnd
, key_hnd
;
4287 const char **drivers
;
4288 TALLOC_CTX
*tmp_ctx
;
4294 ZERO_STRUCT(hive_hnd
);
4295 ZERO_STRUCT(key_hnd
);
4297 tmp_ctx
= talloc_new(mem_ctx
);
4298 if (tmp_ctx
== NULL
) {
4302 /* use NULL for the driver name so we open the key that is
4303 * parent of all drivers for this architecture and version */
4304 result
= winreg_printer_opendriver(tmp_ctx
,
4313 if (!W_ERROR_IS_OK(result
)) {
4314 DEBUG(5, ("winreg_get_driver_list: "
4315 "Could not open key (%s,%u): %s\n",
4316 architecture
, version
, win_errstr(result
)));
4321 result
= winreg_printer_enumkeys(tmp_ctx
,
4326 if (!W_ERROR_IS_OK(result
)) {
4327 DEBUG(0, ("winreg_get_driver_list: "
4328 "Could not enumerate drivers for (%s,%u): %s\n",
4329 architecture
, version
, win_errstr(result
)));
4333 *drivers_p
= talloc_steal(mem_ctx
, drivers
);
4337 if (winreg_pipe
!= NULL
) {
4338 if (is_valid_policy_hnd(&key_hnd
)) {
4339 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &key_hnd
, NULL
);
4341 if (is_valid_policy_hnd(&hive_hnd
)) {
4342 rpccli_winreg_CloseKey(winreg_pipe
, tmp_ctx
, &hive_hnd
, NULL
);
4346 TALLOC_FREE(tmp_ctx
);