2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Guenther Deschner 2009.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "../librpc/gen_ndr/ndr_spoolss.h"
22 #include "rpc_client/init_spoolss.h"
23 #include "../libcli/security/security.h"
25 #include "passdb/machine_sid.h"
27 /*******************************************************************
28 ********************************************************************/
30 bool init_systemtime(struct spoolss_Time
*r
,
33 if (!r
|| !unixtime
) {
37 r
->year
= unixtime
->tm_year
+1900;
38 r
->month
= unixtime
->tm_mon
+1;
39 r
->day_of_week
= unixtime
->tm_wday
;
40 r
->day
= unixtime
->tm_mday
;
41 r
->hour
= unixtime
->tm_hour
;
42 r
->minute
= unixtime
->tm_min
;
43 r
->second
= unixtime
->tm_sec
;
49 time_t spoolss_Time_to_time_t(const struct spoolss_Time
*r
)
53 unixtime
.tm_year
= r
->year
- 1900;
54 unixtime
.tm_mon
= r
->month
- 1;
55 unixtime
.tm_wday
= r
->day_of_week
;
56 unixtime
.tm_mday
= r
->day
;
57 unixtime
.tm_hour
= r
->hour
;
58 unixtime
.tm_min
= r
->minute
;
59 unixtime
.tm_sec
= r
->second
;
61 return mktime(&unixtime
);
64 /*******************************************************************
65 ********************************************************************/
67 WERROR
pull_spoolss_PrinterData(TALLOC_CTX
*mem_ctx
,
68 const DATA_BLOB
*blob
,
69 union spoolss_PrinterData
*data
,
70 enum winreg_Type type
)
72 enum ndr_err_code ndr_err
;
73 ndr_err
= ndr_pull_union_blob(blob
, mem_ctx
, data
, type
,
74 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PrinterData
);
75 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
76 return WERR_GENERAL_FAILURE
;
81 /*******************************************************************
82 ********************************************************************/
84 WERROR
push_spoolss_PrinterData(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*blob
,
85 enum winreg_Type type
,
86 union spoolss_PrinterData
*data
)
88 enum ndr_err_code ndr_err
;
89 ndr_err
= ndr_push_union_blob(blob
, mem_ctx
, data
, type
,
90 (ndr_push_flags_fn_t
)ndr_push_spoolss_PrinterData
);
91 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
92 return WERR_GENERAL_FAILURE
;
97 /*******************************************************************
98 ********************************************************************/
100 void spoolss_printerinfo2_to_setprinterinfo2(const struct spoolss_PrinterInfo2
*i
,
101 struct spoolss_SetPrinterInfo2
*s
)
103 s
->servername
= i
->servername
;
104 s
->printername
= i
->printername
;
105 s
->sharename
= i
->sharename
;
106 s
->portname
= i
->portname
;
107 s
->drivername
= i
->drivername
;
108 s
->comment
= i
->comment
;
109 s
->location
= i
->location
;
110 s
->devmode_ptr
= NULL
;
111 s
->sepfile
= i
->sepfile
;
112 s
->printprocessor
= i
->printprocessor
;
113 s
->datatype
= i
->datatype
;
114 s
->parameters
= i
->parameters
;
115 s
->secdesc_ptr
= NULL
;
116 s
->attributes
= i
->attributes
;
117 s
->priority
= i
->priority
;
118 s
->defaultpriority
= i
->defaultpriority
;
119 s
->starttime
= i
->starttime
;
120 s
->untiltime
= i
->untiltime
;
121 s
->status
= i
->status
;
123 s
->averageppm
= i
->averageppm
;
126 /****************************************************************************
127 ****************************************************************************/
129 bool driver_info_ctr_to_info8(struct spoolss_AddDriverInfoCtr
*r
,
130 struct spoolss_DriverInfo8
*_info8
)
132 struct spoolss_DriverInfo8 info8
;
138 info8
.version
= r
->info
.info3
->version
;
139 info8
.driver_name
= r
->info
.info3
->driver_name
;
140 info8
.architecture
= r
->info
.info3
->architecture
;
141 info8
.driver_path
= r
->info
.info3
->driver_path
;
142 info8
.data_file
= r
->info
.info3
->data_file
;
143 info8
.config_file
= r
->info
.info3
->config_file
;
144 info8
.help_file
= r
->info
.info3
->help_file
;
145 info8
.monitor_name
= r
->info
.info3
->monitor_name
;
146 info8
.default_datatype
= r
->info
.info3
->default_datatype
;
147 if (r
->info
.info3
->dependent_files
&& r
->info
.info3
->dependent_files
->string
) {
148 info8
.dependent_files
= r
->info
.info3
->dependent_files
->string
;
152 info8
.version
= r
->info
.info6
->version
;
153 info8
.driver_name
= r
->info
.info6
->driver_name
;
154 info8
.architecture
= r
->info
.info6
->architecture
;
155 info8
.driver_path
= r
->info
.info6
->driver_path
;
156 info8
.data_file
= r
->info
.info6
->data_file
;
157 info8
.config_file
= r
->info
.info6
->config_file
;
158 info8
.help_file
= r
->info
.info6
->help_file
;
159 info8
.monitor_name
= r
->info
.info6
->monitor_name
;
160 info8
.default_datatype
= r
->info
.info6
->default_datatype
;
161 if (r
->info
.info6
->dependent_files
&& r
->info
.info6
->dependent_files
->string
) {
162 info8
.dependent_files
= r
->info
.info6
->dependent_files
->string
;
164 info8
.driver_date
= r
->info
.info6
->driver_date
;
165 info8
.driver_version
= r
->info
.info6
->driver_version
;
166 info8
.manufacturer_name
= r
->info
.info6
->manufacturer_name
;
167 info8
.manufacturer_url
= r
->info
.info6
->manufacturer_url
;
168 info8
.hardware_id
= r
->info
.info6
->hardware_id
;
169 info8
.provider
= r
->info
.info6
->provider
;
172 info8
.version
= r
->info
.info8
->version
;
173 info8
.driver_name
= r
->info
.info8
->driver_name
;
174 info8
.architecture
= r
->info
.info8
->architecture
;
175 info8
.driver_path
= r
->info
.info8
->driver_path
;
176 info8
.data_file
= r
->info
.info8
->data_file
;
177 info8
.config_file
= r
->info
.info8
->config_file
;
178 info8
.help_file
= r
->info
.info8
->help_file
;
179 info8
.monitor_name
= r
->info
.info8
->monitor_name
;
180 info8
.default_datatype
= r
->info
.info8
->default_datatype
;
181 if (r
->info
.info8
->dependent_files
&& r
->info
.info8
->dependent_files
->string
) {
182 info8
.dependent_files
= r
->info
.info8
->dependent_files
->string
;
184 if (r
->info
.info8
->previous_names
&& r
->info
.info8
->previous_names
->string
) {
185 info8
.previous_names
= r
->info
.info8
->previous_names
->string
;
187 info8
.driver_date
= r
->info
.info8
->driver_date
;
188 info8
.driver_version
= r
->info
.info8
->driver_version
;
189 info8
.manufacturer_name
= r
->info
.info8
->manufacturer_name
;
190 info8
.manufacturer_url
= r
->info
.info8
->manufacturer_url
;
191 info8
.hardware_id
= r
->info
.info8
->hardware_id
;
192 info8
.provider
= r
->info
.info8
->provider
;
193 info8
.print_processor
= r
->info
.info8
->print_processor
;
194 info8
.vendor_setup
= r
->info
.info8
->vendor_setup
;
195 if (r
->info
.info8
->color_profiles
&& r
->info
.info8
->color_profiles
->string
) {
196 info8
.color_profiles
= r
->info
.info8
->color_profiles
->string
;
198 info8
.inf_path
= r
->info
.info8
->inf_path
;
199 info8
.printer_driver_attributes
= r
->info
.info8
->printer_driver_attributes
;
200 if (r
->info
.info8
->core_driver_dependencies
&& r
->info
.info8
->core_driver_dependencies
->string
) {
201 info8
.core_driver_dependencies
= r
->info
.info8
->core_driver_dependencies
->string
;
203 info8
.min_inbox_driver_ver_date
= r
->info
.info8
->min_inbox_driver_ver_date
;
204 info8
.min_inbox_driver_ver_version
= r
->info
.info8
->min_inbox_driver_ver_version
;
215 /****************************************************************************
216 Create and allocate a default devicemode.
217 ****************************************************************************/
219 WERROR
spoolss_create_default_devmode(TALLOC_CTX
*mem_ctx
,
220 const char *devicename
,
221 struct spoolss_DeviceMode
**devmode
)
223 struct spoolss_DeviceMode
*dm
;
226 dm
= talloc_zero(mem_ctx
, struct spoolss_DeviceMode
);
231 dname
= talloc_asprintf(dm
, "%s", devicename
);
235 if (strlen(dname
) > MAXDEVICENAME
) {
236 dname
[MAXDEVICENAME
] = '\0';
238 dm
->devicename
= dname
;
240 dm
->formname
= talloc_strdup(dm
, "Letter");
241 if (dm
->formname
== NULL
) {
245 dm
->specversion
= DMSPEC_NT4_AND_ABOVE
;
246 dm
->driverversion
= 0x0400;
248 dm
->__driverextra_length
= 0;
249 dm
->fields
= DEVMODE_FORMNAME
|
251 DEVMODE_PRINTQUALITY
|
252 DEVMODE_DEFAULTSOURCE
|
257 dm
->orientation
= DMORIENT_PORTRAIT
;
258 dm
->papersize
= DMPAPER_LETTER
;
263 dm
->defaultsource
= DMBIN_FORMSOURCE
;
264 dm
->printquality
= DMRES_HIGH
; /* 0x0258 */
265 dm
->color
= DMRES_MONOCHROME
;
266 dm
->duplex
= DMDUP_SIMPLEX
;
268 dm
->ttoption
= DMTT_SUBDEV
;
269 dm
->collate
= DMCOLLATE_FALSE
;
279 dm
->displayflags
= 0;
280 dm
->displayfrequency
= 0;
283 dm
->panningwidth
= 0;
284 dm
->panningheight
= 0;
286 dm
->driverextra_data
.data
= NULL
;
287 dm
->driverextra_data
.length
= 0;
293 WERROR
spoolss_create_default_secdesc(TALLOC_CTX
*mem_ctx
,
294 struct spoolss_security_descriptor
**secdesc
)
296 struct security_ace ace
[7]; /* max number of ace entries */
299 struct security_acl
*psa
= NULL
;
300 struct security_descriptor
*psd
= NULL
;
301 struct dom_sid adm_sid
;
304 /* Create an ACE where Everyone is allowed to print */
306 sa
= PRINTER_ACE_PRINT
;
307 init_sec_ace(&ace
[i
++], &global_sid_World
, SEC_ACE_TYPE_ACCESS_ALLOWED
,
308 sa
, SEC_ACE_FLAG_CONTAINER_INHERIT
);
310 /* Add the domain admins group if we are a DC */
313 struct dom_sid domadmins_sid
;
315 sid_compose(&domadmins_sid
, get_global_sam_sid(),
318 sa
= PRINTER_ACE_FULL_CONTROL
;
319 init_sec_ace(&ace
[i
++], &domadmins_sid
,
320 SEC_ACE_TYPE_ACCESS_ALLOWED
, sa
,
321 SEC_ACE_FLAG_OBJECT_INHERIT
| SEC_ACE_FLAG_INHERIT_ONLY
);
322 init_sec_ace(&ace
[i
++], &domadmins_sid
, SEC_ACE_TYPE_ACCESS_ALLOWED
,
323 sa
, SEC_ACE_FLAG_CONTAINER_INHERIT
);
325 else if (secrets_fetch_domain_sid(lp_workgroup(), &adm_sid
)) {
326 sid_append_rid(&adm_sid
, DOMAIN_RID_ADMINISTRATOR
);
328 sa
= PRINTER_ACE_FULL_CONTROL
;
329 init_sec_ace(&ace
[i
++], &adm_sid
,
330 SEC_ACE_TYPE_ACCESS_ALLOWED
, sa
,
331 SEC_ACE_FLAG_OBJECT_INHERIT
| SEC_ACE_FLAG_INHERIT_ONLY
);
332 init_sec_ace(&ace
[i
++], &adm_sid
, SEC_ACE_TYPE_ACCESS_ALLOWED
,
333 sa
, SEC_ACE_FLAG_CONTAINER_INHERIT
);
336 /* add BUILTIN\Administrators as FULL CONTROL */
338 sa
= PRINTER_ACE_FULL_CONTROL
;
339 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Administrators
,
340 SEC_ACE_TYPE_ACCESS_ALLOWED
, sa
,
341 SEC_ACE_FLAG_OBJECT_INHERIT
| SEC_ACE_FLAG_INHERIT_ONLY
);
342 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Administrators
,
343 SEC_ACE_TYPE_ACCESS_ALLOWED
,
344 sa
, SEC_ACE_FLAG_CONTAINER_INHERIT
);
346 /* add BUILTIN\Print Operators as FULL CONTROL */
348 sa
= PRINTER_ACE_FULL_CONTROL
;
349 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Print_Operators
,
350 SEC_ACE_TYPE_ACCESS_ALLOWED
, sa
,
351 SEC_ACE_FLAG_OBJECT_INHERIT
| SEC_ACE_FLAG_INHERIT_ONLY
);
352 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Print_Operators
,
353 SEC_ACE_TYPE_ACCESS_ALLOWED
,
354 sa
, SEC_ACE_FLAG_CONTAINER_INHERIT
);
356 /* Make the security descriptor owned by the BUILTIN\Administrators */
358 /* The ACL revision number in rpc_secdesc.h differs from the one
359 created by NT when setting ACE entries in printer
360 descriptors. NT4 complains about the property being edited by a
363 if ((psa
= make_sec_acl(mem_ctx
, NT4_ACL_REVISION
, i
, ace
)) != NULL
) {
364 psd
= make_sec_desc(mem_ctx
,
366 SEC_DESC_SELF_RELATIVE
,
367 &global_sid_Builtin_Administrators
,
368 &global_sid_Builtin_Administrators
,
375 DEBUG(0,("construct_default_printer_sd: Failed to make SEC_DESC.\n"));
379 DEBUG(4,("construct_default_printer_sdb: size = %u.\n",
380 (unsigned int)sd_size
));