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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "python/py_spoolss.h"
25 PyObject
*spoolss_hnd_addform(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
27 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
32 static char *kwlist
[] = {"form", NULL
};
34 /* Parse parameters */
36 if (!PyArg_ParseTupleAndKeywords(
37 args
, kw
, "O!", kwlist
, &PyDict_Type
, &info
))
40 /* Call rpc function */
42 if (!py_to_FORM(&form
, info
)) {
43 PyErr_SetString(spoolss_error
, "invalid form");
47 if (!get_level_value(info
, &level
)) {
48 PyErr_SetString(spoolss_error
, "invalid info level");
53 PyErr_SetString(spoolss_error
, "unsupported info level");
59 PyObject
*obj
= PyDict_GetItemString(info
, "name");
60 char *form_name
= PyString_AsString(obj
);
62 init_unistr2(&form
.name
, form_name
, UNI_STR_TERMINATE
);
66 PyErr_SetString(spoolss_error
, "unsupported info level");
70 werror
= cli_spoolss_addform(hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
,
74 if (!W_ERROR_IS_OK(werror
)) {
75 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
83 /* Get form properties */
85 PyObject
*spoolss_hnd_getform(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
87 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
92 static char *kwlist
[] = {"form_name", "level", NULL
};
96 /* Parse parameters */
98 if (!PyArg_ParseTupleAndKeywords(
99 args
, kw
, "s|i", kwlist
, &form_name
, &level
))
102 /* Call rpc function */
104 werror
= cli_spoolss_getform(hnd
->cli
, hnd
->mem_ctx
, 0, &needed
,
105 &hnd
->pol
, form_name
, level
, &form
);
107 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
108 werror
= cli_spoolss_getform(
109 hnd
->cli
, hnd
->mem_ctx
, needed
, NULL
, &hnd
->pol
,
110 form_name
, 1, &form
);
112 if (!W_ERROR_IS_OK(werror
)) {
113 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
121 py_from_FORM_1(&result
, &form
);
129 /* Set form properties */
131 PyObject
*spoolss_hnd_setform(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
133 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
135 PyObject
*info
, *form_name
;
137 static char *kwlist
[] = { "form", NULL
};
140 /* Parse parameters */
142 if (!PyArg_ParseTupleAndKeywords(
143 args
, kw
, "O!", kwlist
, &PyDict_Type
, &info
))
146 if (!get_level_value(info
, &level
)) {
147 PyErr_SetString(spoolss_error
, "invalid info level");
152 PyErr_SetString(spoolss_error
, "unsupported info level");
156 /* Call rpc function */
158 if (!py_to_FORM(&form
, info
)) {
159 PyErr_SetString(spoolss_error
, "invalid form");
163 form_name
= PyDict_GetItemString(info
, "name");
165 werror
= cli_spoolss_setform(
166 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, level
,
167 PyString_AsString(form_name
), &form
);
169 if (!W_ERROR_IS_OK(werror
)) {
170 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
180 PyObject
*spoolss_hnd_deleteform(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
182 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
184 static char *kwlist
[] = {"form_name", NULL
};
187 /* Parse parameters */
189 if (!PyArg_ParseTupleAndKeywords(
190 args
, kw
, "s", kwlist
, &form_name
))
193 /* Call rpc function */
195 werror
= cli_spoolss_deleteform(
196 hnd
->cli
, hnd
->mem_ctx
, &hnd
->pol
, form_name
);
198 if (!W_ERROR_IS_OK(werror
)) {
199 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
207 /* Enumerate forms */
209 PyObject
*spoolss_hnd_enumforms(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
212 spoolss_policy_hnd_object
*hnd
= (spoolss_policy_hnd_object
*)self
;
214 uint32 level
= 1, num_forms
, needed
, i
;
215 static char *kwlist
[] = {"level", NULL
};
218 /* Parse parameters */
220 if (!PyArg_ParseTupleAndKeywords(
221 args
, kw
, "|i", kwlist
, &level
))
224 /* Call rpc function */
226 werror
= cli_spoolss_enumforms(
227 hnd
->cli
, hnd
->mem_ctx
, 0, &needed
, &hnd
->pol
, level
,
230 if (W_ERROR_V(werror
) == ERRinsufficientbuffer
)
231 werror
= cli_spoolss_enumforms(
232 hnd
->cli
, hnd
->mem_ctx
, needed
, NULL
, &hnd
->pol
, level
,
235 if (!W_ERROR_IS_OK(werror
)) {
236 PyErr_SetObject(spoolss_werror
, py_werror_tuple(werror
));
242 result
= PyDict_New();
244 for (i
= 0; i
< num_forms
; i
++) {
248 rpcstr_pull(name
, forms
[i
].name
.buffer
,
249 sizeof(fstring
), -1, STR_TERMINATE
);
251 py_from_FORM_1(&value
, &forms
[i
]);
253 PyDict_SetItemString(
254 value
, "level", PyInt_FromLong(1));
256 PyDict_SetItemString(result
, name
, value
);
261 PyErr_SetString(spoolss_error
, "unknown info level");