| 1 | /*
|
|---|
| 2 | Python wrappers for DCERPC/SMB client routines.
|
|---|
| 3 |
|
|---|
| 4 | Copyright (C) Tim Potter, 2002
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #include "python/py_spoolss.h"
|
|---|
| 22 |
|
|---|
| 23 | /* Add a form */
|
|---|
| 24 |
|
|---|
| 25 | PyObject *spoolss_hnd_addform(PyObject *self, PyObject *args, PyObject *kw)
|
|---|
| 26 | {
|
|---|
| 27 | spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
|
|---|
| 28 | WERROR werror;
|
|---|
| 29 | PyObject *info;
|
|---|
| 30 | FORM form;
|
|---|
| 31 | int level;
|
|---|
| 32 | static char *kwlist[] = {"form", NULL};
|
|---|
| 33 |
|
|---|
| 34 | /* Parse parameters */
|
|---|
| 35 |
|
|---|
| 36 | if (!PyArg_ParseTupleAndKeywords(
|
|---|
| 37 | args, kw, "O!", kwlist, &PyDict_Type, &info))
|
|---|
| 38 | return NULL;
|
|---|
| 39 |
|
|---|
| 40 | /* Call rpc function */
|
|---|
| 41 |
|
|---|
| 42 | if (!py_to_FORM(&form, info)) {
|
|---|
| 43 | PyErr_SetString(spoolss_error, "invalid form");
|
|---|
| 44 | return NULL;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | if (!get_level_value(info, &level)) {
|
|---|
| 48 | PyErr_SetString(spoolss_error, "invalid info level");
|
|---|
| 49 | return NULL;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | if (level != 1) {
|
|---|
| 53 | PyErr_SetString(spoolss_error, "unsupported info level");
|
|---|
| 54 | return NULL;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | switch (level) {
|
|---|
| 58 | case 1: {
|
|---|
| 59 | PyObject *obj = PyDict_GetItemString(info, "name");
|
|---|
| 60 | char *form_name = PyString_AsString(obj);
|
|---|
| 61 |
|
|---|
| 62 | init_unistr2(&form.name, form_name, UNI_STR_TERMINATE);
|
|---|
| 63 | break;
|
|---|
| 64 | }
|
|---|
| 65 | default:
|
|---|
| 66 | PyErr_SetString(spoolss_error, "unsupported info level");
|
|---|
| 67 | return NULL;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | werror = rpccli_spoolss_addform(hnd->cli, hnd->mem_ctx, &hnd->pol,
|
|---|
| 71 | level, &form);
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | if (!W_ERROR_IS_OK(werror)) {
|
|---|
| 75 | PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
|
|---|
| 76 | return NULL;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | Py_INCREF(Py_None);
|
|---|
| 80 | return Py_None;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | /* Get form properties */
|
|---|
| 84 |
|
|---|
| 85 | PyObject *spoolss_hnd_getform(PyObject *self, PyObject *args, PyObject *kw)
|
|---|
| 86 | {
|
|---|
| 87 | spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
|
|---|
| 88 | WERROR werror;
|
|---|
| 89 | PyObject *result;
|
|---|
| 90 | char *form_name;
|
|---|
| 91 | int level = 1;
|
|---|
| 92 | static char *kwlist[] = {"form_name", "level", NULL};
|
|---|
| 93 | FORM_1 form;
|
|---|
| 94 |
|
|---|
| 95 | /* Parse parameters */
|
|---|
| 96 |
|
|---|
| 97 | if (!PyArg_ParseTupleAndKeywords(
|
|---|
| 98 | args, kw, "s|i", kwlist, &form_name, &level))
|
|---|
| 99 | return NULL;
|
|---|
| 100 |
|
|---|
| 101 | /* Call rpc function */
|
|---|
| 102 |
|
|---|
| 103 | werror = rpccli_spoolss_getform(
|
|---|
| 104 | hnd->cli, hnd->mem_ctx, &hnd->pol, form_name, level, &form);
|
|---|
| 105 |
|
|---|
| 106 | if (!W_ERROR_IS_OK(werror)) {
|
|---|
| 107 | PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
|
|---|
| 108 | return NULL;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | result = Py_None;
|
|---|
| 112 |
|
|---|
| 113 | switch(level) {
|
|---|
| 114 | case 1:
|
|---|
| 115 | py_from_FORM_1(&result, &form);
|
|---|
| 116 | break;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | Py_INCREF(result);
|
|---|
| 120 | return result;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | /* Set form properties */
|
|---|
| 124 |
|
|---|
| 125 | PyObject *spoolss_hnd_setform(PyObject *self, PyObject *args, PyObject *kw)
|
|---|
| 126 | {
|
|---|
| 127 | spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
|
|---|
| 128 | WERROR werror;
|
|---|
| 129 | PyObject *info, *form_name;
|
|---|
| 130 | int level;
|
|---|
| 131 | static char *kwlist[] = { "form", NULL};
|
|---|
| 132 | FORM form;
|
|---|
| 133 |
|
|---|
| 134 | /* Parse parameters */
|
|---|
| 135 |
|
|---|
| 136 | if (!PyArg_ParseTupleAndKeywords(
|
|---|
| 137 | args, kw, "O!", kwlist, &PyDict_Type, &info))
|
|---|
| 138 | return NULL;
|
|---|
| 139 |
|
|---|
| 140 | if (!get_level_value(info, &level)) {
|
|---|
| 141 | PyErr_SetString(spoolss_error, "invalid info level");
|
|---|
| 142 | return NULL;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | if (level != 1) {
|
|---|
| 146 | PyErr_SetString(spoolss_error, "unsupported info level");
|
|---|
| 147 | return NULL;
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | /* Call rpc function */
|
|---|
| 151 |
|
|---|
| 152 | if (!py_to_FORM(&form, info)) {
|
|---|
| 153 | PyErr_SetString(spoolss_error, "invalid form");
|
|---|
| 154 | return NULL;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | form_name = PyDict_GetItemString(info, "name");
|
|---|
| 158 |
|
|---|
| 159 | werror = rpccli_spoolss_setform(
|
|---|
| 160 | hnd->cli, hnd->mem_ctx, &hnd->pol, level,
|
|---|
| 161 | PyString_AsString(form_name), &form);
|
|---|
| 162 |
|
|---|
| 163 | if (!W_ERROR_IS_OK(werror)) {
|
|---|
| 164 | PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
|
|---|
| 165 | return NULL;
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | Py_INCREF(Py_None);
|
|---|
| 169 | return Py_None;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | /* Delete a form */
|
|---|
| 173 |
|
|---|
| 174 | PyObject *spoolss_hnd_deleteform(PyObject *self, PyObject *args, PyObject *kw)
|
|---|
| 175 | {
|
|---|
| 176 | spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
|
|---|
| 177 | WERROR werror;
|
|---|
| 178 | static char *kwlist[] = {"form_name", NULL};
|
|---|
| 179 | char *form_name;
|
|---|
| 180 |
|
|---|
| 181 | /* Parse parameters */
|
|---|
| 182 |
|
|---|
| 183 | if (!PyArg_ParseTupleAndKeywords(
|
|---|
| 184 | args, kw, "s", kwlist, &form_name))
|
|---|
| 185 | return NULL;
|
|---|
| 186 |
|
|---|
| 187 | /* Call rpc function */
|
|---|
| 188 |
|
|---|
| 189 | werror = rpccli_spoolss_deleteform(
|
|---|
| 190 | hnd->cli, hnd->mem_ctx, &hnd->pol, form_name);
|
|---|
| 191 |
|
|---|
| 192 | if (!W_ERROR_IS_OK(werror)) {
|
|---|
| 193 | PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
|
|---|
| 194 | return NULL;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | Py_INCREF(Py_None);
|
|---|
| 198 | return Py_None;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | /* Enumerate forms */
|
|---|
| 202 |
|
|---|
| 203 | PyObject *spoolss_hnd_enumforms(PyObject *self, PyObject *args, PyObject *kw)
|
|---|
| 204 | {
|
|---|
| 205 | PyObject *result;
|
|---|
| 206 | spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
|
|---|
| 207 | WERROR werror;
|
|---|
| 208 | uint32 level = 1, num_forms, i;
|
|---|
| 209 | static char *kwlist[] = {"level", NULL};
|
|---|
| 210 | FORM_1 *forms;
|
|---|
| 211 |
|
|---|
| 212 | /* Parse parameters */
|
|---|
| 213 |
|
|---|
| 214 | if (!PyArg_ParseTupleAndKeywords(
|
|---|
| 215 | args, kw, "|i", kwlist, &level))
|
|---|
| 216 | return NULL;
|
|---|
| 217 |
|
|---|
| 218 | /* Call rpc function */
|
|---|
| 219 |
|
|---|
| 220 | werror = rpccli_spoolss_enumforms(
|
|---|
| 221 | hnd->cli, hnd->mem_ctx, &hnd->pol, level, &num_forms, &forms);
|
|---|
| 222 |
|
|---|
| 223 | if (!W_ERROR_IS_OK(werror)) {
|
|---|
| 224 | PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
|
|---|
| 225 | return NULL;
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | switch(level) {
|
|---|
| 229 | case 1:
|
|---|
| 230 | result = PyDict_New();
|
|---|
| 231 |
|
|---|
| 232 | for (i = 0; i < num_forms; i++) {
|
|---|
| 233 | PyObject *value;
|
|---|
| 234 | fstring name;
|
|---|
| 235 |
|
|---|
| 236 | rpcstr_pull(name, forms[i].name.buffer,
|
|---|
| 237 | sizeof(fstring), -1, STR_TERMINATE);
|
|---|
| 238 |
|
|---|
| 239 | py_from_FORM_1(&value, &forms[i]);
|
|---|
| 240 |
|
|---|
| 241 | PyDict_SetItemString(
|
|---|
| 242 | value, "level", PyInt_FromLong(1));
|
|---|
| 243 |
|
|---|
| 244 | PyDict_SetItemString(result, name, value);
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | break;
|
|---|
| 248 | default:
|
|---|
| 249 | PyErr_SetString(spoolss_error, "unknown info level");
|
|---|
| 250 | return NULL;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | return result;
|
|---|
| 254 | }
|
|---|