This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "python/py_spoolss.h"
#include "python/py_conv.h"
struct pyconv py_PRINTER_INFO_0[] = {
- { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_0, printername) },
+ { "name", PY_UNISTR, offsetof(PRINTER_INFO_0, printername) },
{ "server_name", PY_UNISTR, offsetof(PRINTER_INFO_0, servername) },
{ "cjobs", PY_UINT32, offsetof(PRINTER_INFO_0, cjobs) },
};
struct pyconv py_PRINTER_INFO_1[] = {
- { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_1, name) },
+ { "name", PY_UNISTR, offsetof(PRINTER_INFO_1, name) },
{ "description", PY_UNISTR, offsetof(PRINTER_INFO_1, description) },
{ "comment", PY_UNISTR, offsetof(PRINTER_INFO_1, comment) },
{ "flags", PY_UINT32, offsetof(PRINTER_INFO_1, flags) },
struct pyconv py_PRINTER_INFO_2[] = {
{ "server_name", PY_UNISTR, offsetof(PRINTER_INFO_2, servername) },
- { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_2, printername) },
+ { "name", PY_UNISTR, offsetof(PRINTER_INFO_2, printername) },
{ "share_name", PY_UNISTR, offsetof(PRINTER_INFO_2, sharename) },
{ "port_name", PY_UNISTR, offsetof(PRINTER_INFO_2, portname) },
{ "driver_name", PY_UNISTR, offsetof(PRINTER_INFO_2, drivername) },
{ NULL }
};
-/* Convert a security descriptor to a Python dict */
-
-BOOL py_from_SID(PyObject **obj, DOM_SID *sid)
-{
- fstring sidstr;
-
- if (!sid) {
- Py_INCREF(Py_None);
- *obj = Py_None;
- return True;
- }
-
- if (!sid_to_string(sidstr, sid))
- return False;
-
- *obj = PyString_FromString(sidstr);
-
- return True;
-}
-
-BOOL py_to_SID(DOM_SID *sid, PyObject *dict)
-{
- return False;
-}
-
-BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace)
-{
- PyObject *obj;
-
- if (!ace) {
- Py_INCREF(Py_None);
- *dict = Py_None;
- return True;
- }
-
- *dict = PyDict_New();
-
- PyDict_SetItemString(*dict, "type", PyInt_FromLong(ace->type));
- PyDict_SetItemString(*dict, "flags", PyInt_FromLong(ace->flags));
- PyDict_SetItemString(*dict, "mask", PyInt_FromLong(ace->info.mask));
-
- if (py_from_SID(&obj, &ace->trustee))
- PyDict_SetItemString(*dict, "trustee", obj);
-
- return True;
-}
-
-BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict)
-{
- return False;
-}
-
-BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl)
-{
- PyObject *ace_list;
- int i;
-
- if (!acl) {
- Py_INCREF(Py_None);
- *dict = Py_None;
- return True;
- }
-
- *dict = PyDict_New();
-
- PyDict_SetItemString(*dict, "revision", PyInt_FromLong(acl->revision));
-
- ace_list = PyList_New(acl->num_aces);
-
- for (i = 0; i < acl->num_aces; i++) {
- PyObject *obj;
-
- if (py_from_ACE(&obj, &acl->ace[i]))
- PyList_SetItem(ace_list, i, obj);
- }
-
- PyDict_SetItemString(*dict, "ace_list", ace_list);
-
- return True;
-}
-
-BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict)
-{
- return False;
-}
-
-BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd)
-{
- PyObject *obj;
-
- *dict = PyDict_New();
-
- PyDict_SetItemString(*dict, "revision", PyInt_FromLong(sd->revision));
- PyDict_SetItemString(*dict, "type", PyInt_FromLong(sd->type));
-
- if (py_from_SID(&obj, sd->owner_sid))
- PyDict_SetItemString(*dict, "owner_sid", obj);
-
- if (py_from_SID(&obj, sd->grp_sid))
- PyDict_SetItemString(*dict, "group_sid", obj);
-
- if (py_from_ACL(&obj, sd->dacl))
- PyDict_SetItemString(*dict, "dacl", obj);
-
- if (py_from_ACL(&obj, sd->sacl))
- PyDict_SetItemString(*dict, "sacl", obj);
-
- return True;
-}
-
-BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict)
-{
- return False;
-}
-
/*
* Convert between DEVICEMODE and Python
*/
PyDict_SetItemString(*dict, "private",
PyString_FromStringAndSize(
- devmode->private, devmode->driverextra));
+ devmode->dev_private, devmode->driverextra));
return True;
}
BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict)
{
- PyObject *obj;
+ PyObject *obj, *dict_copy = PyDict_Copy(dict);
+ BOOL result = False;
- to_struct(devmode, dict, py_DEVICEMODE);
+ if (!(obj = PyDict_GetItemString(dict_copy, "private")))
+ goto done;
- obj = PyDict_GetItemString(dict, "private");
+ if (!PyString_Check(obj))
+ goto done;
- if (!obj)
- return False;
-
- devmode->private = PyString_AsString(obj);
+ devmode->dev_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;
}
/*
BOOL py_from_PRINTER_INFO_0(PyObject **dict, PRINTER_INFO_0 *info)
{
*dict = from_struct(info, py_PRINTER_INFO_0);
+ PyDict_SetItemString(*dict, "level", PyInt_FromLong(0));
return True;
}
BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info)
{
*dict = from_struct(info, py_PRINTER_INFO_1);
+ PyDict_SetItemString(*dict, "level", PyInt_FromLong(1));
return True;
}
BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict)
{
- return False;
+ PyObject *obj, *dict_copy = PyDict_Copy(dict);
+ BOOL result = False;
+
+ if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
+ !PyInt_Check(obj))
+ goto done;
+
+ PyDict_DelItemString(dict_copy, "level");
+
+ if (!to_struct(info, dict_copy, py_PRINTER_INFO_1))
+ goto done;
+
+ result = True;
+
+done:
+ Py_DECREF(dict_copy);
+ return result;
}
/*
*dict = from_struct(info, py_PRINTER_INFO_2);
- if (py_from_SECDESC(&obj, info->secdesc))
- PyDict_SetItemString(*dict, "security_descriptor", obj);
+ /* The security descriptor could be NULL */
+
+ if (info->secdesc) {
+ if (py_from_SECDESC(&obj, info->secdesc))
+ PyDict_SetItemString(*dict, "security_descriptor", obj);
+ }
+
+ /* Bong! The devmode could be NULL */
+
+ if (info->devmode)
+ py_from_DEVICEMODE(&obj, info->devmode);
+ else
+ obj = PyDict_New();
+
+ PyDict_SetItemString(*dict, "device_mode", obj);
- if (py_from_DEVICEMODE(&obj, info->devmode))
- PyDict_SetItemString(*dict, "device_mode", obj);
+ PyDict_SetItemString(*dict, "level", PyInt_FromLong(2));
return True;
}
-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)
{
- return False;
+ PyObject *obj, *dict_copy = PyDict_Copy(dict);
+ BOOL result = False;
+
+ /* Convert security descriptor - may be NULL */
+
+ info->secdesc = NULL;
+
+ if ((obj = PyDict_GetItemString(dict_copy, "security_descriptor"))) {
+
+ if (!PyDict_Check(obj))
+ goto done;
+
+ if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx))
+ goto done;
+
+ PyDict_DelItemString(dict_copy, "security_descriptor");
+ }
+
+ /* Convert device mode */
+
+ if (!(obj = PyDict_GetItemString(dict_copy, "device_mode"))
+ || !PyDict_Check(obj))
+ goto done;
+
+ info->devmode = _talloc(mem_ctx, sizeof(DEVICEMODE));
+
+ if (!py_to_DEVICEMODE(info->devmode, obj))
+ goto done;
+
+ PyDict_DelItemString(dict_copy, "device_mode");
+
+ /* Check info level */
+
+ if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
+ !PyInt_Check(obj))
+ goto done;
+
+ PyDict_DelItemString(dict_copy, "level");
+
+ /* 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;
}
/*
BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info)
{
- PyObject *obj;
+ PyObject *obj;
*dict = from_struct(info, py_PRINTER_INFO_3);
if (py_from_SECDESC(&obj, info->secdesc))
PyDict_SetItemString(*dict, "security_descriptor", obj);
+ PyDict_SetItemString(*dict, "level", PyInt_FromLong(3));
+
return True;
}
-BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict)
+BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict,
+ TALLOC_CTX *mem_ctx)
{
- return False;
+ PyObject *obj;
+
+ if (!to_struct(info, dict, py_PRINTER_INFO_3))
+ return False;
+
+ if (!(obj = PyDict_GetItemString(dict, "security_descriptor")))
+ return False;
+
+ if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx))
+ return False;
+
+ return True;
}