diff options
author | Tim Potter <tpot@samba.org> | 2002-04-18 03:35:05 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2002-04-18 03:35:05 +0000 |
commit | b0fbd72b41dda039d4fd1036998721ee7387cd45 (patch) | |
tree | aba55f37665e6389cc443023f86f00a55aacf829 /source3 | |
parent | eaf7e2b374d6a77e573195da1d7617bea97b1a94 (diff) | |
download | samba-b0fbd72b41dda039d4fd1036998721ee7387cd45.tar.gz samba-b0fbd72b41dda039d4fd1036998721ee7387cd45.tar.bz2 samba-b0fbd72b41dda039d4fd1036998721ee7387cd45.zip |
Started working on setprinter code.
(This used to be commit 38d2b1794a0942ac4c2787f06bc5e546508c2515)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/python/py_common_proto.h | 6 | ||||
-rw-r--r-- | source3/python/py_ntsec.c | 151 | ||||
-rw-r--r-- | source3/python/py_spoolss_printers.c | 42 | ||||
-rw-r--r-- | source3/python/py_spoolss_printers_conv.c | 27 | ||||
-rw-r--r-- | source3/python/py_spoolss_proto.h | 15 | ||||
-rw-r--r-- | source3/python/samba-head.patch | 15 |
6 files changed, 197 insertions, 59 deletions
diff --git a/source3/python/py_common_proto.h b/source3/python/py_common_proto.h index 0c227ffef8..bca59689a4 100644 --- a/source3/python/py_common_proto.h +++ b/source3/python/py_common_proto.h @@ -19,12 +19,12 @@ struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, /* The following definitions come from python/py_ntsec.c */ BOOL py_from_SID(PyObject **obj, DOM_SID *sid); -BOOL py_to_SID(DOM_SID *sid, PyObject *dict); +BOOL py_to_SID(DOM_SID *sid, PyObject *obj); BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace); BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict); BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl); -BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict); +BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict, TALLOC_CTX *mem_ctx); BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd); -BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict); +BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx); #endif /* _PY_COMMON_PROTO_H */ diff --git a/source3/python/py_ntsec.c b/source3/python/py_ntsec.c index d97bbb6f8c..d8ed50379f 100644 --- a/source3/python/py_ntsec.c +++ b/source3/python/py_ntsec.c @@ -43,9 +43,19 @@ BOOL py_from_SID(PyObject **obj, DOM_SID *sid) return True; } -BOOL py_to_SID(DOM_SID *sid, PyObject *dict) +BOOL py_to_SID(DOM_SID *sid, PyObject *obj) { - return False; + BOOL result; + + if (!PyString_Check(obj)) + return False; + + result = string_to_sid(sid, PyString_AsString(obj)); + + if (result) + DEBUG(0, ("py: got sid %s\n", PyString_AsString(obj))); + + return result; } BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace) @@ -72,7 +82,50 @@ BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace) BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict) { - return False; + PyObject *obj; + uint8 ace_type, ace_flags; + DOM_SID trustee; + SEC_ACCESS sec_access; + + if (!PyDict_Check(dict)) + return False; + + if (!(obj = PyDict_GetItemString(dict, "type")) || + !PyInt_Check(obj)) + return False; + + ace_type = PyInt_AsLong(obj); + + DEBUG(0, ("py: got ace_type %d\n", ace_type)); + + if (!(obj = PyDict_GetItemString(dict, "flags")) || + !PyInt_Check(obj)) + return False; + + ace_flags = PyInt_AsLong(obj); + + DEBUG(0, ("py: got ace_flags %d\n", ace_flags)); + + if (!(obj = PyDict_GetItemString(dict, "trustee")) || + !PyString_Check(obj)) + return False; + + if (!py_to_SID(&trustee, obj)) + return False; + + DEBUG(0, ("py: got trustee\n")); + + if (!(obj = PyDict_GetItemString(dict, "mask")) || + !PyInt_Check(obj)) + return False; + + sec_access.mask = PyInt_AsLong(obj); + + DEBUG(0, ("py: got mask 0x%08x\n", sec_access.mask)); + + init_sec_ace(ace, &trustee, ace_type, sec_access, ace_flags); + + return True; } BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl) @@ -104,9 +157,39 @@ BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl) return True; } -BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict) +BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict, TALLOC_CTX *mem_ctx) { - return False; + PyObject *obj; + uint32 i; + + if (!(obj = PyDict_GetItemString(dict, "revision")) || + !PyInt_Check(obj)) + return False; + + acl->revision = PyInt_AsLong(obj); + + DEBUG(0, ("py: got revision %d\n", acl->revision)); + + if (!(obj = PyDict_GetItemString(dict, "ace_list")) || + !PyList_Check(obj)) + return False; + + acl->num_aces = PyList_Size(obj); + + DEBUG(0, ("py: got num_aces %d\n", acl->num_aces)); + + acl->ace = talloc(mem_ctx, acl->num_aces * sizeof(SEC_ACE)); + + for (i = 0; i < acl->num_aces; i++) { + PyObject *py_ace = PyList_GetItem(obj, i); + + if (!py_to_ACE(acl->ace, py_ace)) + return False; + + DEBUG(0, ("py: got ace %d\n", i)); + } + + return True; } BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd) @@ -116,7 +199,6 @@ BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd) *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); @@ -133,7 +215,60 @@ BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd) return True; } -BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict) +BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx) { - return False; + PyObject *obj; + uint16 revision; + DOM_SID owner_sid, group_sid; + SEC_ACL sacl, dacl; + size_t sd_size; + BOOL got_dacl = False, got_sacl = False; + + ZERO_STRUCT(dacl); ZERO_STRUCT(sacl); + ZERO_STRUCT(owner_sid); ZERO_STRUCT(group_sid); + + if (!(obj = PyDict_GetItemString(dict, "revision"))) + return False; + + revision = PyInt_AsLong(obj); + + if (!(obj = PyDict_GetItemString(dict, "owner_sid"))) + return False; + + if (!py_to_SID(&owner_sid, obj)) + return False; + + if (!(obj = PyDict_GetItemString(dict, "group_sid"))) + return False; + + if (!py_to_SID(&group_sid, obj)) + return False; + + if ((obj = PyDict_GetItemString(dict, "dacl"))) { + + if (!py_to_ACL(&dacl, obj, mem_ctx)) + return False; + + got_dacl = True; + } + + DEBUG(0, ("py: got dacl\n")); + + if ((obj = PyDict_GetItemString(dict, "sacl"))) { + if (obj != Py_None) { + + if (!py_to_ACL(&sacl, obj, mem_ctx)) + return False; + + got_sacl = True; + } + } + + DEBUG(0, ("py: got sacl\n")); + + *sd = make_sec_desc(mem_ctx, revision, &owner_sid, &group_sid, + got_sacl ? &sacl : NULL, + got_dacl ? &dacl : NULL, &sd_size); + + return True; } diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 69b2733cfb..48321500e7 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -181,12 +181,8 @@ PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) uint32 level; static char *kwlist[] = {"dict", NULL}; union { - PRINTER_INFO_0 printers_0; - PRINTER_INFO_1 printers_1; PRINTER_INFO_2 printers_2; PRINTER_INFO_3 printers_3; - PRINTER_INFO_4 printers_4; - PRINTER_INFO_5 printers_5; } pinfo; /* Parse parameters */ @@ -199,12 +195,22 @@ PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) if ((level_obj = PyDict_GetItemString(info, "level"))) { - if (!PyInt_Check(level_obj)) + if (!PyInt_Check(level_obj)) { + DEBUG(0, ("** level not an integer\n")); goto error; + } level = PyInt_AsLong(level_obj); + /* Only level 2, 3 supported by NT */ + + if (level != 2 && level != 3) { + DEBUG(0, ("** unsupported info level\n")); + goto error; + } + } else { + DEBUG(0, ("** no level info\n")); error: PyErr_SetString(spoolss_error, "invalid info"); return NULL; @@ -215,34 +221,14 @@ PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) ZERO_STRUCT(ctr); switch (level) { - case 2: { - PyObject *devmode_obj; - + case 2: ctr.printers_2 = &pinfo.printers_2; - if (!py_to_PRINTER_INFO_2(&pinfo.printers_2, info)) + if (!py_to_PRINTER_INFO_2(&pinfo.printers_2, info, + hnd->mem_ctx)) goto error; -#if 0 - devmode_obj = PyDict_GetItemString(info, "device_mode"); - - pinfo.printers_2.devmode = talloc( - hnd->mem_ctx, sizeof(DEVICEMODE)); - - PyDEVICEMODE_AsDEVICEMODE(pinfo.printers_2.devmode, - devmode_obj); - -#else - - /* FIXME: can we actually set the security descriptor using - a setprinter level 2? */ - - pinfo.printers_2.secdesc = NULL; - pinfo.printers_2.secdesc = NULL; - -#endif break; - } default: PyErr_SetString(spoolss_error, "unsupported info level"); return NULL; diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index 84b36ddbb2..4b78f087e6 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -165,9 +165,7 @@ BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict) to_struct(devmode, dict, py_DEVICEMODE); - obj = PyDict_GetItemString(dict, "private"); - - if (!obj) + if (!(obj = PyDict_GetItemString(dict, "private"))) return False; devmode->private = PyString_AsString(obj); @@ -225,9 +223,28 @@ BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info) 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; + + to_struct(info, dict, py_PRINTER_INFO_2); + + if (!(obj = PyDict_GetItemString(dict, "security_descriptor"))) + return False; + + if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx)) + return False; + + if (!(obj = PyDict_GetItemString(dict, "device_mode"))) + return False; + + info->devmode = talloc(mem_ctx, sizeof(DEVICEMODE)); + + if (!py_to_DEVICEMODE(info->devmode, obj)) + return False; + + return True; } /* diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 3e3e5ef6ee..47602d175d 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -6,8 +6,8 @@ /* The following definitions come from python/py_spoolss.c */ -PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol); +PyObject *new_spoolss_policy_hnd_object(struct cli_state *cli, + TALLOC_CTX *mem_ctx, POLICY_HND *pol); void initspoolss(void); /* The following definitions come from python/py_spoolss_drivers.c */ @@ -66,14 +66,6 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw); /* The following definitions come from python/py_spoolss_printers_conv.c */ -BOOL py_from_SID(PyObject **obj, DOM_SID *sid); -BOOL py_to_SID(DOM_SID *sid, PyObject *dict); -BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace); -BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict); -BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl); -BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict); -BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd); -BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict); BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode); BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict); BOOL py_from_PRINTER_INFO_0(PyObject **dict, PRINTER_INFO_0 *info); @@ -81,7 +73,8 @@ BOOL py_to_PRINTER_INFO_0(PRINTER_INFO_0 *info, PyObject *dict); 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_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); BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info); BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict); diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch index 223e0179fb..c8089934b8 100644 --- a/source3/python/samba-head.patch +++ b/source3/python/samba-head.patch @@ -4,8 +4,8 @@ RCS file: /data/cvs/samba/source/Makefile.in,v retrieving revision 1.470 diff -u -r1.470 Makefile.in --- Makefile.in 2002/04/13 11:45:33 1.470 -+++ Makefile.in 2002/04/14 01:01:05 -@@ -787,6 +787,36 @@ ++++ Makefile.in 2002/04/18 03:34:05 +@@ -787,6 +787,43 @@ -$(INSTALLCMD) -d ${prefix}/include -$(INSTALLCMD) include/libsmbclient.h ${prefix}/include @@ -22,7 +22,9 @@ diff -u -r1.470 Makefile.in + +PY_LSA_PROTO_OBJ = python/py_lsa.o + -+python_proto: python_spoolss_proto python_lsa_proto ++PY_COMMON_PROTO_OBJ = python/py_common.c python/py_ntsec.c ++ ++python_proto: python_spoolss_proto python_lsa_proto python_common_proto + +python_spoolss_proto: + @cd $(srcdir) && $(SHELL) script/mkproto.sh $(AWK) \ @@ -34,6 +36,11 @@ diff -u -r1.470 Makefile.in + -h _PY_LSA_PROTO_H python/py_lsa_proto.h \ + $(PY_LSA_PROTO_OBJ) + ++python_common_proto: ++ @cd $(srcdir) && $(SHELL) script/mkproto.sh $(AWK) \ ++ -h _PY_COMMON_PROTO_H python/py_common_proto.h \ ++ $(PY_COMMON_PROTO_OBJ) ++ +python_ext: $(PYTHON_OBJS) + @echo python python/setup.py build + @PYTHON_OBJS="$(PYTHON_OBJS)" PYTHON_CFLAGS="$(CFLAGS) $(CPPFLAGS)" \ @@ -48,7 +55,7 @@ RCS file: /data/cvs/samba/source/configure.in,v retrieving revision 1.300 diff -u -r1.300 configure.in --- configure.in 2002/04/11 15:26:58 1.300 -+++ configure.in 2002/04/14 01:01:08 ++++ configure.in 2002/04/18 03:34:05 @@ -2716,7 +2716,7 @@ builddir=`pwd` AC_SUBST(builddir) |