2 Python wrappers for DCERPC/SMB client routines.
4 Copyright (C) Tim Potter, 2002
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/>.
20 #include "python/py_spoolss.h"
21 #include "python/py_conv.h"
23 struct pyconv py_PRINTER_INFO_0
[] = {
24 { "name", PY_UNISTR
, offsetof(PRINTER_INFO_0
, printername
) },
25 { "server_name", PY_UNISTR
, offsetof(PRINTER_INFO_0
, servername
) },
27 { "cjobs", PY_UINT32
, offsetof(PRINTER_INFO_0
, cjobs
) },
28 { "total_jobs", PY_UINT32
, offsetof(PRINTER_INFO_0
, total_jobs
) },
29 { "total_bytes", PY_UINT32
, offsetof(PRINTER_INFO_0
, total_bytes
) },
31 { "year", PY_UINT16
, offsetof(PRINTER_INFO_0
, year
) },
32 { "month", PY_UINT16
, offsetof(PRINTER_INFO_0
, month
) },
33 { "day_of_week", PY_UINT16
, offsetof(PRINTER_INFO_0
, dayofweek
) },
34 { "day", PY_UINT16
, offsetof(PRINTER_INFO_0
, day
) },
35 { "hour", PY_UINT16
, offsetof(PRINTER_INFO_0
, hour
) },
36 { "minute", PY_UINT16
, offsetof(PRINTER_INFO_0
, minute
) },
37 { "second", PY_UINT16
, offsetof(PRINTER_INFO_0
, second
) },
38 { "milliseconds", PY_UINT16
, offsetof(PRINTER_INFO_0
, milliseconds
) },
40 { "global_counter", PY_UINT32
, offsetof(PRINTER_INFO_0
, global_counter
) },
41 { "total_pages", PY_UINT32
, offsetof(PRINTER_INFO_0
, total_pages
) },
43 { "major_version", PY_UINT16
, offsetof(PRINTER_INFO_0
, major_version
) },
44 { "build_version", PY_UINT16
, offsetof(PRINTER_INFO_0
, build_version
) },
46 { "unknown7", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown7
) },
47 { "unknown8", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown8
) },
48 { "unknown9", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown9
) },
49 { "session_counter", PY_UINT32
, offsetof(PRINTER_INFO_0
, session_counter
)},
50 { "unknown11", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown11
) },
51 { "printer_errors", PY_UINT32
, offsetof(PRINTER_INFO_0
, printer_errors
) },
52 { "unknown13", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown13
) },
53 { "unknown14", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown14
) },
54 { "unknown15", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown15
) },
55 { "unknown16", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown16
) },
56 { "change_id", PY_UINT32
, offsetof(PRINTER_INFO_0
, change_id
) },
57 { "unknown18", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown18
) },
58 { "status", PY_UINT32
, offsetof(PRINTER_INFO_0
, status
) },
59 { "unknown20", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown20
) },
60 { "c_setprinter", PY_UINT32
, offsetof(PRINTER_INFO_0
, c_setprinter
) },
61 { "unknown22", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown22
) },
62 { "unknown23", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown23
) },
63 { "unknown24", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown24
) },
64 { "unknown25", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown25
) },
65 { "unknown26", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown26
) },
66 { "unknown27", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown27
) },
67 { "unknown28", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown28
) },
68 { "unknown29", PY_UINT32
, offsetof(PRINTER_INFO_0
, unknown29
) },
73 struct pyconv py_PRINTER_INFO_1
[] = {
74 { "name", PY_UNISTR
, offsetof(PRINTER_INFO_1
, name
) },
75 { "description", PY_UNISTR
, offsetof(PRINTER_INFO_1
, description
) },
76 { "comment", PY_UNISTR
, offsetof(PRINTER_INFO_1
, comment
) },
77 { "flags", PY_UINT32
, offsetof(PRINTER_INFO_1
, flags
) },
81 struct pyconv py_PRINTER_INFO_2
[] = {
82 { "server_name", PY_UNISTR
, offsetof(PRINTER_INFO_2
, servername
) },
83 { "name", PY_UNISTR
, offsetof(PRINTER_INFO_2
, printername
) },
84 { "share_name", PY_UNISTR
, offsetof(PRINTER_INFO_2
, sharename
) },
85 { "port_name", PY_UNISTR
, offsetof(PRINTER_INFO_2
, portname
) },
86 { "driver_name", PY_UNISTR
, offsetof(PRINTER_INFO_2
, drivername
) },
87 { "comment", PY_UNISTR
, offsetof(PRINTER_INFO_2
, comment
) },
88 { "location", PY_UNISTR
, offsetof(PRINTER_INFO_2
, location
) },
89 { "datatype", PY_UNISTR
, offsetof(PRINTER_INFO_2
, datatype
) },
90 { "sepfile", PY_UNISTR
, offsetof(PRINTER_INFO_2
, sepfile
) },
91 { "print_processor", PY_UNISTR
, offsetof(PRINTER_INFO_2
, printprocessor
) },
92 { "parameters", PY_UNISTR
, offsetof(PRINTER_INFO_2
, parameters
) },
93 { "attributes", PY_UINT32
, offsetof(PRINTER_INFO_2
, attributes
) },
94 { "default_priority", PY_UINT32
, offsetof(PRINTER_INFO_2
, defaultpriority
) },
95 { "priority", PY_UINT32
, offsetof(PRINTER_INFO_2
, priority
) },
96 { "start_time", PY_UINT32
, offsetof(PRINTER_INFO_2
, starttime
) },
97 { "until_time", PY_UINT32
, offsetof(PRINTER_INFO_2
, untiltime
) },
98 { "status", PY_UINT32
, offsetof(PRINTER_INFO_2
, status
) },
99 { "cjobs", PY_UINT32
, offsetof(PRINTER_INFO_2
, cjobs
) },
100 { "average_ppm", PY_UINT32
, offsetof(PRINTER_INFO_2
, averageppm
) },
104 struct pyconv py_PRINTER_INFO_3
[] = {
105 { "flags", PY_UINT32
, offsetof(PRINTER_INFO_3
, flags
) },
109 struct pyconv py_DEVICEMODE
[] = {
110 { "device_name", PY_UNISTR
, offsetof(DEVICEMODE
, devicename
) },
111 { "spec_version", PY_UINT16
, offsetof(DEVICEMODE
, specversion
) },
112 { "driver_version", PY_UINT16
, offsetof(DEVICEMODE
, driverversion
) },
113 { "size", PY_UINT16
, offsetof(DEVICEMODE
, size
) },
114 { "fields", PY_UINT16
, offsetof(DEVICEMODE
, fields
) },
115 { "orientation", PY_UINT16
, offsetof(DEVICEMODE
, orientation
) },
116 { "paper_size", PY_UINT16
, offsetof(DEVICEMODE
, papersize
) },
117 { "paper_width", PY_UINT16
, offsetof(DEVICEMODE
, paperwidth
) },
118 { "paper_length", PY_UINT16
, offsetof(DEVICEMODE
, paperlength
) },
119 { "scale", PY_UINT16
, offsetof(DEVICEMODE
, scale
) },
120 { "copies", PY_UINT16
, offsetof(DEVICEMODE
, copies
) },
121 { "default_source", PY_UINT16
, offsetof(DEVICEMODE
, defaultsource
) },
122 { "print_quality", PY_UINT16
, offsetof(DEVICEMODE
, printquality
) },
123 { "color", PY_UINT16
, offsetof(DEVICEMODE
, color
) },
124 { "duplex", PY_UINT16
, offsetof(DEVICEMODE
, duplex
) },
125 { "y_resolution", PY_UINT16
, offsetof(DEVICEMODE
, yresolution
) },
126 { "tt_option", PY_UINT16
, offsetof(DEVICEMODE
, ttoption
) },
127 { "collate", PY_UINT16
, offsetof(DEVICEMODE
, collate
) },
128 { "form_name", PY_UNISTR
, offsetof(DEVICEMODE
, formname
) },
129 { "log_pixels", PY_UINT16
, offsetof(DEVICEMODE
, logpixels
) },
130 { "bits_per_pel", PY_UINT32
, offsetof(DEVICEMODE
, bitsperpel
) },
131 { "pels_width", PY_UINT32
, offsetof(DEVICEMODE
, pelswidth
) },
132 { "pels_height", PY_UINT32
, offsetof(DEVICEMODE
, pelsheight
) },
133 { "display_flags", PY_UINT32
, offsetof(DEVICEMODE
, displayflags
) },
134 { "display_frequency", PY_UINT32
, offsetof(DEVICEMODE
, displayfrequency
) },
135 { "icm_method", PY_UINT32
, offsetof(DEVICEMODE
, icmmethod
) },
136 { "icm_intent", PY_UINT32
, offsetof(DEVICEMODE
, icmintent
) },
137 { "media_type", PY_UINT32
, offsetof(DEVICEMODE
, mediatype
) },
138 { "dither_type", PY_UINT32
, offsetof(DEVICEMODE
, dithertype
) },
139 { "reserved1", PY_UINT32
, offsetof(DEVICEMODE
, reserved1
) },
140 { "reserved2", PY_UINT32
, offsetof(DEVICEMODE
, reserved2
) },
141 { "panning_width", PY_UINT32
, offsetof(DEVICEMODE
, panningwidth
) },
142 { "panning_height", PY_UINT32
, offsetof(DEVICEMODE
, panningheight
) },
147 * Convert between DEVICEMODE and Python
150 BOOL
py_from_DEVICEMODE(PyObject
**dict
, DEVICEMODE
*devmode
)
152 *dict
= from_struct(devmode
, py_DEVICEMODE
);
154 PyDict_SetItemString(*dict
, "private",
155 PyString_FromStringAndSize(
156 devmode
->dev_private
, devmode
->driverextra
));
161 BOOL
py_to_DEVICEMODE(DEVICEMODE
*devmode
, PyObject
*dict
)
163 PyObject
*obj
, *dict_copy
= PyDict_Copy(dict
);
166 if (!(obj
= PyDict_GetItemString(dict_copy
, "private")))
169 if (!PyString_Check(obj
))
172 devmode
->dev_private
= PyString_AsString(obj
);
173 devmode
->driverextra
= PyString_Size(obj
);
175 PyDict_DelItemString(dict_copy
, "private");
177 if (!to_struct(devmode
, dict_copy
, py_DEVICEMODE
))
183 Py_DECREF(dict_copy
);
188 * Convert between PRINTER_INFO_0 and Python
191 BOOL
py_from_PRINTER_INFO_0(PyObject
**dict
, PRINTER_INFO_0
*info
)
193 *dict
= from_struct(info
, py_PRINTER_INFO_0
);
194 PyDict_SetItemString(*dict
, "level", PyInt_FromLong(0));
198 BOOL
py_to_PRINTER_INFO_0(PRINTER_INFO_0
*info
, PyObject
*dict
)
204 * Convert between PRINTER_INFO_1 and Python
207 BOOL
py_from_PRINTER_INFO_1(PyObject
**dict
, PRINTER_INFO_1
*info
)
209 *dict
= from_struct(info
, py_PRINTER_INFO_1
);
210 PyDict_SetItemString(*dict
, "level", PyInt_FromLong(1));
214 BOOL
py_to_PRINTER_INFO_1(PRINTER_INFO_1
*info
, PyObject
*dict
)
216 PyObject
*obj
, *dict_copy
= PyDict_Copy(dict
);
219 if (!(obj
= PyDict_GetItemString(dict_copy
, "level")) ||
223 PyDict_DelItemString(dict_copy
, "level");
225 if (!to_struct(info
, dict_copy
, py_PRINTER_INFO_1
))
231 Py_DECREF(dict_copy
);
236 * Convert between PRINTER_INFO_2 and Python
239 BOOL
py_from_PRINTER_INFO_2(PyObject
**dict
, PRINTER_INFO_2
*info
)
243 *dict
= from_struct(info
, py_PRINTER_INFO_2
);
245 /* The security descriptor could be NULL */
248 if (py_from_SECDESC(&obj
, info
->secdesc
))
249 PyDict_SetItemString(*dict
, "security_descriptor", obj
);
252 /* Bong! The devmode could be NULL */
255 py_from_DEVICEMODE(&obj
, info
->devmode
);
259 PyDict_SetItemString(*dict
, "device_mode", obj
);
261 PyDict_SetItemString(*dict
, "level", PyInt_FromLong(2));
266 BOOL
py_to_PRINTER_INFO_2(PRINTER_INFO_2
*info
, PyObject
*dict
,
269 PyObject
*obj
, *dict_copy
= PyDict_Copy(dict
);
272 /* Convert security descriptor - may be NULL */
274 info
->secdesc
= NULL
;
276 if ((obj
= PyDict_GetItemString(dict_copy
, "security_descriptor"))) {
278 if (!PyDict_Check(obj
))
281 if (!py_to_SECDESC(&info
->secdesc
, obj
, mem_ctx
))
284 PyDict_DelItemString(dict_copy
, "security_descriptor");
287 /* Convert device mode */
289 if (!(obj
= PyDict_GetItemString(dict_copy
, "device_mode"))
290 || !PyDict_Check(obj
))
293 info
->devmode
= _talloc(mem_ctx
, sizeof(DEVICEMODE
));
295 if (!py_to_DEVICEMODE(info
->devmode
, obj
))
298 PyDict_DelItemString(dict_copy
, "device_mode");
300 /* Check info level */
302 if (!(obj
= PyDict_GetItemString(dict_copy
, "level")) ||
306 PyDict_DelItemString(dict_copy
, "level");
308 /* Convert remaining elements of dictionary */
310 if (!to_struct(info
, dict_copy
, py_PRINTER_INFO_2
))
316 Py_DECREF(dict_copy
);
321 * Convert between PRINTER_INFO_1 and Python
324 BOOL
py_from_PRINTER_INFO_3(PyObject
**dict
, PRINTER_INFO_3
*info
)
328 *dict
= from_struct(info
, py_PRINTER_INFO_3
);
330 if (py_from_SECDESC(&obj
, info
->secdesc
))
331 PyDict_SetItemString(*dict
, "security_descriptor", obj
);
333 PyDict_SetItemString(*dict
, "level", PyInt_FromLong(3));
338 BOOL
py_to_PRINTER_INFO_3(PRINTER_INFO_3
*info
, PyObject
*dict
,
343 if (!to_struct(info
, dict
, py_PRINTER_INFO_3
))
346 if (!(obj
= PyDict_GetItemString(dict
, "security_descriptor")))
349 if (!py_to_SECDESC(&info
->secdesc
, obj
, mem_ctx
))