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"
24 PyObject
*spoolss_hnd_addform(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
26 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
31 static char *kwlist
[] = {"form", NULL
};
33 /* Parse parameters */
35 if (!PyArg_ParseTupleAndKeywords(
36 args
, kw
, "O!", kwlist
, &PyDict_Type
, &info
))
39 /* Call rpc function */
41 if (!py_to_FORM(&form
, info
)) {
42 PyErr_SetString(spoolss_error
, "invalid form");
46 if (!get_level_value(info
, &level
)) {
47 PyErr_SetString(spoolss_error
, "invalid info level");
52 PyErr_SetString(spoolss_error
, "unsupported info level");
58 PyObject
*obj
= PyDict_GetItemString(info
, "name");
59 char *form_name
= PyString_AsString(obj
);
61 init_unistr2(&form
.name
, form_name
, UNI_STR_TERMINATE
);
65 PyErr_SetString(spoolss_error
, "unsupported info level");
69 werror
= rpccli_spoolss_addform(hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
,
73 if (!W_ERROR_IS_OK(werror
)) {
74 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
82 /* Get form properties */
84 PyObject
*spoolss_hnd_getform(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
86 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
91 static char *kwlist
[] = {"form_name", "level", NULL
};
94 /* Parse parameters */
96 if (!PyArg_ParseTupleAndKeywords(
97 args
, kw
, "s|i", kwlist
, &form_name
, &level
))
100 /* Call rpc function */
102 werror
= rpccli_spoolss_getform(
103 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, form_name
, level
, &form
);
105 if (!W_ERROR_IS_OK(werror
)) {
106 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
114 py_from_FORM_1(&result
, &form
);
122 /* Set form properties */
124 PyObject
*spoolss_hnd_setform(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
126 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
128 PyObject
*info
, *form_name
;
130 static char *kwlist
[] = { "form", NULL
};
133 /* Parse parameters */
135 if (!PyArg_ParseTupleAndKeywords(
136 args
, kw
, "O!", kwlist
, &PyDict_Type
, &info
))
139 if (!get_level_value(info
, &level
)) {
140 PyErr_SetString(spoolss_error
, "invalid info level");
145 PyErr_SetString(spoolss_error
, "unsupported info level");
149 /* Call rpc function */
151 if (!py_to_FORM(&form
, info
)) {
152 PyErr_SetString(spoolss_error
, "invalid form");
156 form_name
= PyDict_GetItemString(info
, "name");
158 werror
= rpccli_spoolss_setform(
159 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, level
,
160 PyString_AsString(form_name
), &form
);
162 if (!W_ERROR_IS_OK(werror
)) {
163 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
173 PyObject
*spoolss_hnd_deleteform(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
175 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
177 static char *kwlist
[] = {"form_name", NULL
};
180 /* Parse parameters */
182 if (!PyArg_ParseTupleAndKeywords(
183 args
, kw
, "s", kwlist
, &form_name
))
186 /* Call rpc function */
188 werror
= rpccli_spoolss_deleteform(
189 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, form_name
);
191 if (!W_ERROR_IS_OK(werror
)) {
192 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
200 /* Enumerate forms */
202 PyObject
*spoolss_hnd_enumforms(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
205 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
207 uint32 level
= 1, num_forms
, i
;
208 static char *kwlist
[] = {"level", NULL
};
211 /* Parse parameters */
213 if (!PyArg_ParseTupleAndKeywords(
214 args
, kw
, "|i", kwlist
, &level
))
217 /* Call rpc function */
219 werror
= rpccli_spoolss_enumforms(
220 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, level
, &num_forms
, &forms
);
222 if (!W_ERROR_IS_OK(werror
)) {
223 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
229 result
= PyDict_New();
231 for (i
= 0; i
< num_forms
; i
++) {
235 rpcstr_pull(name
, forms
[i
].name
.buffer
,
236 sizeof(fstring
), -1, STR_TERMINATE
);
238 py_from_FORM_1(&value
, &forms
[i
]);
240 PyDict_SetItemString(
241 value
, "level", PyInt_FromLong(1));
243 PyDict_SetItemString(result
, name
, value
);
248 PyErr_SetString(spoolss_error
, "unknown info level");