1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-04 08:22:08 +03:00

More cleanups of validation functions.

(This used to be commit a4790ba42c)
This commit is contained in:
Tim Potter
2002-10-21 04:47:29 +00:00
parent d897c63fb5
commit 771fc528eb
2 changed files with 66 additions and 19 deletions

View File

@ -74,6 +74,11 @@ BOOL py_to_FORM(FORM *form, PyObject *dict)
if (!to_struct(form, dict_copy, py_FORM)) if (!to_struct(form, dict_copy, py_FORM))
goto done; goto done;
/* Careful! We can't call PyString_AsString(obj) then delete
obj and still expect to have our pointer pointing somewhere
useful. */
obj = PyDict_GetItemString(dict, "name");
name = PyString_AsString(obj); name = PyString_AsString(obj);
init_unistr2(&form->name, name, strlen(name) + 1); init_unistr2(&form->name, name, strlen(name) + 1);

View File

@ -161,18 +161,28 @@ BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode)
BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict) BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict)
{ {
PyObject *obj; PyObject *obj, *dict_copy = PyDict_Copy(dict);
BOOL result = False;
if (!to_struct(devmode, dict, py_DEVICEMODE)) if (!(obj = PyDict_GetItemString(dict_copy, "private")))
return False; goto done;
if (!(obj = PyDict_GetItemString(dict, "private"))) if (!PyString_Check(obj))
return False; goto done;
devmode->private = PyString_AsString(obj); devmode->private = PyString_AsString(obj);
devmode->driverextra = PyString_Size(obj); devmode->driverextra = PyString_Size(obj);
return True; PyDict_DelItemString(dict_copy, "private");
if (!to_struct(devmode, dict_copy, py_DEVICEMODE))
goto done;
result = True;
done:
Py_DECREF(dict_copy);
return result;
} }
/* /*
@ -204,12 +214,23 @@ BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info)
BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict) BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict)
{ {
PyObject *dict_copy = PyDict_Copy(dict); PyObject *obj, *dict_copy = PyDict_Copy(dict);
BOOL result; BOOL result = False;
if (!(obj = PyDict_GetItemString(dict_copy, "level")))
goto done;
if (!PyInt_Check(obj))
goto done;
PyDict_DelItemString(dict_copy, "level"); PyDict_DelItemString(dict_copy, "level");
result = to_struct(info, dict_copy, py_PRINTER_INFO_1);
if (!to_struct(info, dict_copy, py_PRINTER_INFO_1))
goto done;
result = True;
done:
Py_DECREF(dict_copy); Py_DECREF(dict_copy);
return result; return result;
} }
@ -248,26 +269,47 @@ BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info)
BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict, BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict,
TALLOC_CTX *mem_ctx) TALLOC_CTX *mem_ctx)
{ {
PyObject *obj; PyObject *obj, *dict_copy = PyDict_Copy(dict);
BOOL result = False;
if (!to_struct(info, dict, py_PRINTER_INFO_2)) /* Convert security descriptor */
return False;
if (!(obj = PyDict_GetItemString(dict, "security_descriptor"))) if (!(obj = PyDict_GetItemString(dict_copy, "security_descriptor")))
return False; goto done;
if (!PyDict_Check(obj))
goto done;
if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx)) if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx))
return False; goto done;
if (!(obj = PyDict_GetItemString(dict, "device_mode"))) PyDict_DelItemString(dict_copy, "security_descriptor");
return False;
/* Convert device mode */
if (!(obj = PyDict_GetItemString(dict_copy, "device_mode")))
goto done;
if (!PyDict_Check(obj))
goto done;
info->devmode = talloc(mem_ctx, sizeof(DEVICEMODE)); info->devmode = talloc(mem_ctx, sizeof(DEVICEMODE));
if (!py_to_DEVICEMODE(info->devmode, obj)) if (!py_to_DEVICEMODE(info->devmode, obj))
return False; goto done;
return True; PyDict_DelItemString(dict_copy, "device_mode");
/* Convert remaining elements of dictionary */
if (!to_struct(info, dict_copy, py_PRINTER_INFO_2))
goto done;
result = True;
done:
Py_DECREF(dict_copy);
return result;
} }
/* /*