Merge.
authorTim Potter <tpot@samba.org>
Mon, 21 Oct 2002 04:50:32 +0000 (04:50 +0000)
committerTim Potter <tpot@samba.org>
Mon, 21 Oct 2002 04:50:32 +0000 (04:50 +0000)
(This used to be commit d3e88cb96f4140a116067449c73479e15946135d)

source3/python/py_spoolss_drivers.c
source3/python/py_spoolss_forms_conv.c
source3/python/py_spoolss_printers_conv.c

index 0c242d918113253ebb79e5590657a565b9a6891c..f1cf6aca99077df96132090991aa53292c833f5b 100644 (file)
@@ -358,7 +358,8 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args,
        }
 
        ZERO_STRUCT(ctr);
-       
+       ZERO_STRUCT(dinfo);
+
        switch(level) {
        case 3:
                ctr.info3 = &dinfo.driver_3;
index cfeb475b1eb948d08fc488f9203d96de21d66e61..095a318fd243bd27f86d06638562e1bd709e7921 100644 (file)
@@ -74,6 +74,11 @@ BOOL py_to_FORM(FORM *form, PyObject *dict)
        if (!to_struct(form, dict_copy, py_FORM))
                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);
 
        init_unistr2(&form->name, name, strlen(name) + 1);
index 9bef118f2baa4c325f1cc77b1dd73f8be440827b..3e3ef95b125d592fcd81a677a184591b307f086a 100644 (file)
@@ -161,18 +161,28 @@ BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode)
 
 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))
-               return False;
+       if (!(obj = PyDict_GetItemString(dict_copy, "private")))
+               goto done;
 
-       if (!(obj = PyDict_GetItemString(dict, "private")))
-               return False;
+       if (!PyString_Check(obj))
+               goto done;
 
        devmode->private = PyString_AsString(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)
 {
-       PyObject *dict_copy = PyDict_Copy(dict);
-       BOOL result;
+       PyObject *obj, *dict_copy = PyDict_Copy(dict);
+       BOOL result = False;
+
+       if (!(obj = PyDict_GetItemString(dict_copy, "level")))
+               goto done;
+
+       if (!PyInt_Check(obj))
+               goto done;
 
        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);
        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,
                          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))
-               return False;
+       /* Convert security descriptor */
 
-       if (!(obj = PyDict_GetItemString(dict, "security_descriptor")))
-               return False;
+       if (!(obj = PyDict_GetItemString(dict_copy, "security_descriptor")))
+               goto done;
+
+       if (!PyDict_Check(obj))
+               goto done;
 
        if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx))
-               return False;
+               goto done;
 
-       if (!(obj = PyDict_GetItemString(dict, "device_mode")))
-               return False;
+       PyDict_DelItemString(dict_copy, "security_descriptor");
+
+       /* 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));
 
        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;
 }
 
 /*