summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/config.m48
-rw-r--r--source4/scripting/python/config.mk38
-rw-r--r--source4/scripting/python/misc.i15
-rw-r--r--source4/scripting/python/misc.py50
-rw-r--r--source4/scripting/python/misc_wrap.c97
-rw-r--r--source4/scripting/python/modules.c3
-rw-r--r--source4/scripting/python/pyrpc.h5
-rw-r--r--source4/scripting/python/pytalloc.c11
-rw-r--r--source4/scripting/python/samba/__init__.py10
-rw-r--r--source4/scripting/python/samba/getopt.py15
-rw-r--r--source4/scripting/python/samba/idmap.py2
-rw-r--r--source4/scripting/python/samba/provision.py79
-rw-r--r--source4/scripting/python/samba/samba3.py5
-rw-r--r--source4/scripting/python/samba/samdb.py2
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/registry.py2
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/rpcecho.py2
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/sam.py22
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/unix.py6
-rw-r--r--source4/scripting/python/samba/tests/provision.py2
-rw-r--r--source4/scripting/python/samba/tests/samdb.py8
-rw-r--r--source4/scripting/python/samba/upgrade.py2
-rw-r--r--source4/scripting/python/smbpython.c34
-rw-r--r--source4/scripting/python/uuidmodule.c2
23 files changed, 301 insertions, 119 deletions
diff --git a/source4/scripting/python/config.m4 b/source4/scripting/python/config.m4
index 3790071ba8..b599aaefb0 100644
--- a/source4/scripting/python/config.m4
+++ b/source4/scripting/python/config.m4
@@ -5,7 +5,7 @@ AC_ARG_VAR([PYTHON_VERSION],[The installed Python
will be appended to the Python interpreter
canonical name.])
-AC_PROG_SWIG(1.3.31)
+AC_PROG_SWIG(1.3.35)
AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
if test -z "$PYTHON"; then
@@ -64,10 +64,14 @@ SMB_EXT_LIB(EXT_LIB_PYTHON, [$PYTHON_LDFLAGS], [$PYTHON_CFLAGS])
AC_MSG_CHECKING(working python module support)
if test $working_python = yes; then
SMB_ENABLE(EXT_LIB_PYTHON,YES)
- SMB_ENABLE(smbpython,YES)
SMB_ENABLE(LIBPYTHON,YES)
AC_MSG_RESULT([yes])
else
AC_MSG_ERROR([Python not found. Please install Python 2.x and its development headers/libraries.])
fi
+AC_MSG_CHECKING(python library directory)
+pythondir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(1, 0, '\\${prefix}')"`
+AC_MSG_RESULT($pythondir)
+
+AC_SUBST(pythondir)
diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk
index 59f628fe18..b494ee6e8d 100644
--- a/source4/scripting/python/config.mk
+++ b/source4/scripting/python/config.mk
@@ -1,29 +1,37 @@
-[BINARY::smbpython]
-PRIVATE_DEPENDENCIES = LIBPYTHON
-
-smbpython_OBJ_FILES = scripting/python/smbpython.o
-
[SUBSYSTEM::LIBPYTHON]
PUBLIC_DEPENDENCIES = EXT_LIB_PYTHON
+PRIVATE_DEPENDENCIES = PYTALLOC
INIT_FUNCTION_SENTINEL = { NULL, NULL }
-LIBPYTHON_OBJ_FILES = $(addprefix scripting/python/, modules.o pytalloc.o)
+LIBPYTHON_OBJ_FILES = $(addprefix $(pyscriptsrcdir)/, modules.o)
+
+[SUBSYSTEM::PYTALLOC]
+PUBLIC_DEPENDENCIES = EXT_LIB_PYTHON LIBTALLOC
+
+PYTALLOC_OBJ_FILES = $(addprefix $(pyscriptsrcdir)/, pytalloc.o)
[PYTHON::python_uuid]
PRIVATE_DEPENDENCIES = LIBNDR
-python_uuid_OBJ_FILES = scripting/python/uuidmodule.o
+python_uuid_OBJ_FILES = $(pyscriptsrcdir)/uuidmodule.o
[PYTHON::python_misc]
+LIBRARY_REALNAME = samba/_misc.$(SHLIBEXT)
PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB CREDENTIALS
-SWIG_FILE = misc.i
-python_misc_OBJ_FILES = scripting/python/misc_wrap.o
+python_misc_OBJ_FILES = $(pyscriptsrcdir)/misc_wrap.o
+
+$(python_misc_OBJ_FILES): CFLAGS+=$(CFLAG_NO_UNUSED_MACROS) $(CFLAG_NO_CAST_QUAL)
+
+_PY_FILES = $(shell find $(pyscriptsrcdir)/samba $(pyscriptsrcdir)/subunit -name "*.py")
+
+$(foreach pyfile, $(_PY_FILES),$(eval $(call python_py_module_template,$(patsubst $(pyscriptsrcdir)/%,%,$(pyfile)),$(pyfile))))
+
+$(eval $(call python_py_module_template,samba/misc.py,$(pyscriptsrcdir)/misc.py))
+
+EPYDOC_OPTIONS = --no-private --url http://www.samba.org/ --no-sourcecode
-PYDOCTOR_MODULES=bin/python/ldb.py bin/python/auth.py bin/python/credentials.py bin/python/registry.py bin/python/tdb.py bin/python/security.py bin/python/events.py bin/python/net.py
+epydoc:: pythonmods
+ PYTHONPATH=$(pythonbuilddir) epydoc $(EPYDOC_OPTIONS) samba tdb ldb subunit
-installpython:: pythonmods
- @$(SHELL) $(srcdir)/script/installpython.sh \
- $(INSTALLPERMS) \
- $(DESTDIR)$(PYTHONDIR) \
- scripting/python bin/python
+install:: installpython
diff --git a/source4/scripting/python/misc.i b/source4/scripting/python/misc.i
index 6fa3bc93e3..9a4c124121 100644
--- a/source4/scripting/python/misc.i
+++ b/source4/scripting/python/misc.i
@@ -40,6 +40,15 @@
%rename(random_password) generate_random_str;
char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len);
+%feature("docstring") ldb_set_credentials "S.set_credentials(credentials)\n"
+ "Set credentials to use when connecting.";
+
+%feature("docstring") ldb_set_session_info "S.set_session_info(session_info)\n"
+ "Set session info to use when connecting.";
+
+%feature("docstring") ldb_set_loadparm "S.set_loadparm(session_info)\n"
+ "Set loadparm context to use when connecting.";
+
%inline %{
void ldb_set_credentials(struct ldb_context *ldb, struct cli_credentials *creds)
{
@@ -58,14 +67,20 @@ void ldb_set_loadparm(struct ldb_context *ldb, struct loadparm_context *lp_ctx)
%}
+%feature("docstring") samdb_set_domain_sid "S.set_domain_sid(sid)\n"
+ "Set SID of domain to use.";
bool samdb_set_domain_sid(struct ldb_context *ldb,
const struct dom_sid *dom_sid_in);
WERROR dsdb_attach_schema_from_ldif_file(struct ldb_context *ldb, const char *pf, const char *df);
+%feature("docstring") samba_version_string "version()\n"
+ "Obtain the Samba version.";
%rename(version) samba_version_string;
const char *samba_version_string(void);
int dsdb_set_global_schema(struct ldb_context *ldb);
+%feature("docstring") ldb_register_samba_handlers "register_samba_handlers()\n"
+ "Register Samba-specific LDB modules and schemas.";
int ldb_register_samba_handlers(struct ldb_context *ldb);
%inline %{
diff --git a/source4/scripting/python/misc.py b/source4/scripting/python/misc.py
index f1da4c687a..25e8d2de8c 100644
--- a/source4/scripting/python/misc.py
+++ b/source4/scripting/python/misc.py
@@ -1,5 +1,5 @@
# This file was automatically generated by SWIG (http://www.swig.org).
-# Version 1.3.33
+# Version 1.3.35
#
# Don't modify this file, modify the SWIG interface instead.
@@ -62,14 +62,50 @@ import credentials
import param
import security
random_password = _misc.random_password
-ldb_set_credentials = _misc.ldb_set_credentials
-ldb_set_session_info = _misc.ldb_set_session_info
-ldb_set_loadparm = _misc.ldb_set_loadparm
-samdb_set_domain_sid = _misc.samdb_set_domain_sid
+
+def ldb_set_credentials(*args, **kwargs):
+ """
+ S.set_credentials(credentials)
+ Set credentials to use when connecting.
+ """
+ return _misc.ldb_set_credentials(*args, **kwargs)
+
+def ldb_set_session_info(*args, **kwargs):
+ """
+ S.set_session_info(session_info)
+ Set session info to use when connecting.
+ """
+ return _misc.ldb_set_session_info(*args, **kwargs)
+
+def ldb_set_loadparm(*args, **kwargs):
+ """
+ S.set_loadparm(session_info)
+ Set loadparm context to use when connecting.
+ """
+ return _misc.ldb_set_loadparm(*args, **kwargs)
+
+def samdb_set_domain_sid(*args, **kwargs):
+ """
+ S.set_domain_sid(sid)
+ Set SID of domain to use.
+ """
+ return _misc.samdb_set_domain_sid(*args, **kwargs)
dsdb_attach_schema_from_ldif_file = _misc.dsdb_attach_schema_from_ldif_file
-version = _misc.version
+
+def version(*args):
+ """
+ version()
+ Obtain the Samba version.
+ """
+ return _misc.version(*args)
dsdb_set_global_schema = _misc.dsdb_set_global_schema
-ldb_register_samba_handlers = _misc.ldb_register_samba_handlers
+
+def ldb_register_samba_handlers(*args, **kwargs):
+ """
+ register_samba_handlers()
+ Register Samba-specific LDB modules and schemas.
+ """
+ return _misc.ldb_register_samba_handlers(*args, **kwargs)
dsdb_set_ntds_invocation_id = _misc.dsdb_set_ntds_invocation_id
private_path = _misc.private_path
diff --git a/source4/scripting/python/misc_wrap.c b/source4/scripting/python/misc_wrap.c
index 4944515d15..22a072fc6f 100644
--- a/source4/scripting/python/misc_wrap.c
+++ b/source4/scripting/python/misc_wrap.c
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.33
+ * Version 1.3.35
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
@@ -126,7 +126,7 @@
/* This should only be incremented when either the layout of swig_type_info changes,
or for whatever reason, the runtime changes incompatibly */
-#define SWIG_RUNTIME_VERSION "3"
+#define SWIG_RUNTIME_VERSION "4"
/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
#ifdef SWIG_TYPE_TABLE
@@ -161,6 +161,7 @@
/* Flags for pointer conversions */
#define SWIG_POINTER_DISOWN 0x1
+#define SWIG_CAST_NEW_MEMORY 0x2
/* Flags for new pointer objects */
#define SWIG_POINTER_OWN 0x1
@@ -301,10 +302,10 @@ SWIGINTERNINLINE int SWIG_CheckState(int r) {
extern "C" {
#endif
-typedef void *(*swig_converter_func)(void *);
+typedef void *(*swig_converter_func)(void *, int *);
typedef struct swig_type_info *(*swig_dycast_func)(void **);
-/* Structure to store inforomation on one type */
+/* Structure to store information on one type */
typedef struct swig_type_info {
const char *name; /* mangled name of this type */
const char *str; /* human readable name of this type */
@@ -431,8 +432,8 @@ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) {
Cast a pointer up an inheritance hierarchy
*/
SWIGRUNTIMEINLINE void *
-SWIG_TypeCast(swig_cast_info *ty, void *ptr) {
- return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);
+SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) {
+ return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory);
}
/*
@@ -856,7 +857,7 @@ SWIG_Python_AddErrorMsg(const char* mesg)
Py_DECREF(old_str);
Py_DECREF(value);
} else {
- PyErr_Format(PyExc_RuntimeError, mesg);
+ PyErr_SetString(PyExc_RuntimeError, mesg);
}
}
@@ -1416,7 +1417,7 @@ PySwigObject_dealloc(PyObject *v)
{
PySwigObject *sobj = (PySwigObject *) v;
PyObject *next = sobj->next;
- if (sobj->own) {
+ if (sobj->own == SWIG_POINTER_OWN) {
swig_type_info *ty = sobj->ty;
PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0;
PyObject *destroy = data ? data->destroy : 0;
@@ -1434,12 +1435,13 @@ PySwigObject_dealloc(PyObject *v)
res = ((*meth)(mself, v));
}
Py_XDECREF(res);
- } else {
- const char *name = SWIG_TypePrettyName(ty);
+ }
#if !defined(SWIG_PYTHON_SILENT_MEMLEAK)
- printf("swig/python detected a memory leak of type '%s', no destructor found.\n", name);
-#endif
+ else {
+ const char *name = SWIG_TypePrettyName(ty);
+ printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown"));
}
+#endif
}
Py_XDECREF(next);
PyObject_DEL(v);
@@ -1944,7 +1946,7 @@ SWIG_Python_GetSwigThis(PyObject *pyobj)
SWIGRUNTIME int
SWIG_Python_AcquirePtr(PyObject *obj, int own) {
- if (own) {
+ if (own == SWIG_POINTER_OWN) {
PySwigObject *sobj = SWIG_Python_GetSwigThis(obj);
if (sobj) {
int oldown = sobj->own;
@@ -1965,6 +1967,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
return SWIG_OK;
} else {
PySwigObject *sobj = SWIG_Python_GetSwigThis(obj);
+ if (own)
+ *own = 0;
while (sobj) {
void *vptr = sobj->ptr;
if (ty) {
@@ -1978,7 +1982,15 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
if (!tc) {
sobj = (PySwigObject *)sobj->next;
} else {
- if (ptr) *ptr = SWIG_TypeCast(tc,vptr);
+ if (ptr) {
+ int newmemory = 0;
+ *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
+ if (newmemory == SWIG_CAST_NEW_MEMORY) {
+ assert(own);
+ if (own)
+ *own = *own | SWIG_CAST_NEW_MEMORY;
+ }
+ }
break;
}
}
@@ -1988,7 +2000,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
}
}
if (sobj) {
- if (own) *own = sobj->own;
+ if (own)
+ *own = *own | sobj->own;
if (flags & SWIG_POINTER_DISOWN) {
sobj->own = 0;
}
@@ -2053,8 +2066,13 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
}
if (ty) {
swig_cast_info *tc = SWIG_TypeCheck(desc,ty);
- if (!tc) return SWIG_ERROR;
- *ptr = SWIG_TypeCast(tc,vptr);
+ if (tc) {
+ int newmemory = 0;
+ *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
+ assert(!newmemory); /* newmemory handling not yet implemented */
+ } else {
+ return SWIG_ERROR;
+ }
} else {
*ptr = vptr;
}
@@ -2519,7 +2537,7 @@ static swig_module_info swig_module = {swig_types, 27, 0, 0, 0, 0};
#define SWIG_name "_misc"
-#define SWIGVERSION 0x010333
+#define SWIGVERSION 0x010335
#define SWIG_VERSION SWIGVERSION
@@ -3199,14 +3217,32 @@ fail:
static PyMethodDef SwigMethods[] = {
{ (char *)"random_password", (PyCFunction) _wrap_random_password, METH_VARARGS | METH_KEYWORDS, NULL},
- { (char *)"ldb_set_credentials", (PyCFunction) _wrap_ldb_set_credentials, METH_VARARGS | METH_KEYWORDS, NULL},
- { (char *)"ldb_set_session_info", (PyCFunction) _wrap_ldb_set_session_info, METH_VARARGS | METH_KEYWORDS, NULL},
- { (char *)"ldb_set_loadparm", (PyCFunction) _wrap_ldb_set_loadparm, METH_VARARGS | METH_KEYWORDS, NULL},
- { (char *)"samdb_set_domain_sid", (PyCFunction) _wrap_samdb_set_domain_sid, METH_VARARGS | METH_KEYWORDS, NULL},
+ { (char *)"ldb_set_credentials", (PyCFunction) _wrap_ldb_set_credentials, METH_VARARGS | METH_KEYWORDS, (char *)"\n"
+ "S.set_credentials(credentials)\n"
+ "Set credentials to use when connecting.\n"
+ ""},
+ { (char *)"ldb_set_session_info", (PyCFunction) _wrap_ldb_set_session_info, METH_VARARGS | METH_KEYWORDS, (char *)"\n"
+ "S.set_session_info(session_info)\n"
+ "Set session info to use when connecting.\n"
+ ""},
+ { (char *)"ldb_set_loadparm", (PyCFunction) _wrap_ldb_set_loadparm, METH_VARARGS | METH_KEYWORDS, (char *)"\n"
+ "S.set_loadparm(session_info)\n"
+ "Set loadparm context to use when connecting.\n"
+ ""},
+ { (char *)"samdb_set_domain_sid", (PyCFunction) _wrap_samdb_set_domain_sid, METH_VARARGS | METH_KEYWORDS, (char *)"\n"
+ "S.set_domain_sid(sid)\n"
+ "Set SID of domain to use.\n"
+ ""},
{ (char *)"dsdb_attach_schema_from_ldif_file", (PyCFunction) _wrap_dsdb_attach_schema_from_ldif_file, METH_VARARGS | METH_KEYWORDS, NULL},
- { (char *)"version", (PyCFunction)_wrap_version, METH_NOARGS, NULL},
+ { (char *)"version", (PyCFunction)_wrap_version, METH_NOARGS, (char *)"\n"
+ "version()\n"
+ "Obtain the Samba version.\n"
+ ""},
{ (char *)"dsdb_set_global_schema", (PyCFunction) _wrap_dsdb_set_global_schema, METH_VARARGS | METH_KEYWORDS, NULL},
- { (char *)"ldb_register_samba_handlers", (PyCFunction) _wrap_ldb_register_samba_handlers, METH_VARARGS | METH_KEYWORDS, NULL},
+ { (char *)"ldb_register_samba_handlers", (PyCFunction) _wrap_ldb_register_samba_handlers, METH_VARARGS | METH_KEYWORDS, (char *)"\n"
+ "register_samba_handlers()\n"
+ "Register Samba-specific LDB modules and schemas.\n"
+ ""},
{ (char *)"dsdb_set_ntds_invocation_id", (PyCFunction) _wrap_dsdb_set_ntds_invocation_id, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"private_path", (PyCFunction) _wrap_private_path, METH_VARARGS | METH_KEYWORDS, NULL},
{ NULL, NULL, 0, NULL }
@@ -3225,7 +3261,7 @@ static swig_type_info _swigt__p_ldb_context = {"_p_ldb_context", "struct ldb_con
static swig_type_info _swigt__p_ldb_dn = {"_p_ldb_dn", "struct ldb_dn *|ldb_dn *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_ldb_ldif = {"_p_ldb_ldif", "struct ldb_ldif *|ldb_ldif *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_ldb_message = {"_p_ldb_message", "ldb_msg *|struct ldb_message *", 0, 0, (void*)0, 0};
-static swig_type_info _swigt__p_ldb_message_element = {"_p_ldb_message_element", "struct ldb_message_element *|ldb_msg_element *", 0, 0, (void*)0, 0};
+static swig_type_info _swigt__p_ldb_message_element = {"_p_ldb_message_element", "struct ldb_message_element *|ldb_message_element *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_ldb_result = {"_p_ldb_result", "struct ldb_result *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *|loadparm_context *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0};
@@ -3397,7 +3433,7 @@ SWIGRUNTIME void
SWIG_InitializeModule(void *clientdata) {
size_t i;
swig_module_info *module_head, *iter;
- int found;
+ int found, init;
clientdata = clientdata;
@@ -3407,6 +3443,9 @@ SWIG_InitializeModule(void *clientdata) {
swig_module.type_initial = swig_type_initial;
swig_module.cast_initial = swig_cast_initial;
swig_module.next = &swig_module;
+ init = 1;
+ } else {
+ init = 0;
}
/* Try and load any already created modules */
@@ -3435,6 +3474,12 @@ SWIG_InitializeModule(void *clientdata) {
module_head->next = &swig_module;
}
+ /* When multiple interpeters are used, a module could have already been initialized in
+ a different interpreter, but not yet have a pointer in this interpreter.
+ In this case, we do not want to continue adding types... everything should be
+ set up already */
+ if (init == 0) return;
+
/* Now work on filling in swig_module.types */
#ifdef SWIGRUNTIME_DEBUG
printf("SWIG_InitializeModule: size %d\n", swig_module.size);
diff --git a/source4/scripting/python/modules.c b/source4/scripting/python/modules.c
index 6cd975c1a9..0fe15b2fda 100644
--- a/source4/scripting/python/modules.c
+++ b/source4/scripting/python/modules.c
@@ -19,7 +19,6 @@
#include "includes.h"
#include <Python.h>
-#include "build.h"
extern void init_ldb(void);
extern void init_security(void);
@@ -40,12 +39,10 @@ extern void initdrsuapi(void);
extern void initwinreg(void);
extern void initepmapper(void);
extern void initinitshutdown(void);
-static void initdcerpc_misc(void) {}
extern void initmgmt(void);
extern void initnet(void);
extern void initatsvc(void);
extern void initsamr(void);
-static void initdcerpc_security(void) {}
extern void initlsa(void);
extern void initsvcctl(void);
extern void initwkssvc(void);
diff --git a/source4/scripting/python/pyrpc.h b/source4/scripting/python/pyrpc.h
index f4d0f37c39..93d583c10a 100644
--- a/source4/scripting/python/pyrpc.h
+++ b/source4/scripting/python/pyrpc.h
@@ -17,6 +17,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef _PYRPC_H_
+#define _PYRPC_H_
+
#define PY_CHECK_TYPE(type, var, fail) \
if (!type ## _Check(var)) {\
PyErr_Format(PyExc_TypeError, "Expected type %s", type ## _Type.tp_name); \
@@ -32,3 +35,5 @@
#ifndef PyAPI_DATA
# define PyAPI_DATA(RTYPE) extern RTYPE
#endif
+
+#endif /* _PYRPC_H_ */
diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c
index aa0ae9bf90..ca476e9604 100644
--- a/source4/scripting/python/pytalloc.c
+++ b/source4/scripting/python/pytalloc.c
@@ -24,6 +24,7 @@ void py_talloc_dealloc(PyObject* self)
{
py_talloc_Object *obj = (py_talloc_Object *)self;
talloc_free(obj->talloc_ctx);
+ obj->talloc_ctx = NULL;
PyObject_Del(self);
}
@@ -31,7 +32,13 @@ PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx,
void *ptr)
{
py_talloc_Object *ret = PyObject_New(py_talloc_Object, py_type);
- ret->talloc_ctx = talloc_reference(NULL, mem_ctx);
+ ret->talloc_ctx = talloc_new(NULL);
+ if (ret->talloc_ctx == NULL) {
+ return NULL;
+ }
+ if (talloc_reference(ret->talloc_ctx, mem_ctx) == NULL) {
+ return NULL;
+ }
ret->ptr = ptr;
return (PyObject *)ret;
}
@@ -41,5 +48,5 @@ PyObject *py_talloc_default_repr(PyObject *py_obj)
py_talloc_Object *obj = (py_talloc_Object *)py_obj;
PyTypeObject *type = (PyTypeObject*)PyObject_Type((PyObject *)obj);
- return PyString_FromFormat("<%s>", type->tp_name);
+ return PyString_FromFormat("<%s talloc object at 0x%x>", type->tp_name, (intptr_t)py_obj);
}
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index b9d81c6c3c..94f9e4d005 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -20,6 +20,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+__docformat__ = "restructuredText"
+
import os
def _in_source_tree():
@@ -33,6 +35,8 @@ if _in_source_tree():
srcdir = "%s/../../.." % os.path.dirname(__file__)
sys.path.append("%s/bin/python" % srcdir)
default_ldb_modules_dir = "%s/bin/modules/ldb" % srcdir
+else:
+ default_ldb_modules_dir = None
import ldb
@@ -69,15 +73,15 @@ class Ldb(ldb.Ldb):
self.set_modules_dir(default_ldb_modules_dir)
if credentials is not None:
- self.set_credentials(self, credentials)
+ self.set_credentials(credentials)
if session_info is not None:
- self.set_session_info(self, session_info)
+ self.set_session_info(session_info)
assert misc.ldb_register_samba_handlers(self) == 0
if lp is not None:
- self.set_loadparm(self, lp)
+ self.set_loadparm(lp)
def msg(l,text):
print text
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index 7ec684a9d6..9ecb66e21c 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -17,10 +17,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+"""Support for parsing Samba-related command-line options."""
+
import optparse
from credentials import Credentials, AUTO_USE_KERBEROS, DONT_USE_KERBEROS, MUST_USE_KERBEROS
+__docformat__ = "restructuredText"
+
class SambaOptions(optparse.OptionGroup):
+ """General Samba-related command line options."""
def __init__(self, parser):
optparse.OptionGroup.__init__(self, parser, "Samba Common Options")
self.add_option("-s", "--configfile", action="callback",
@@ -29,12 +34,14 @@ class SambaOptions(optparse.OptionGroup):
self._configfile = None
def get_loadparm_path(self):
+ """Return the path to the smb.conf file specified on the command line. """
return self._configfile
def _load_configfile(self, option, opt_str, arg, parser):
self._configfile = arg
def get_loadparm(self):
+ """Return a loadparm object with data specified on the command line. """
import os, param
lp = param.LoadParm()
if self._configfile is not None:
@@ -45,12 +52,15 @@ class SambaOptions(optparse.OptionGroup):
lp.load_default()
return lp
+
class VersionOptions(optparse.OptionGroup):
+ """Command line option for printing Samba version."""
def __init__(self, parser):
optparse.OptionGroup.__init__(self, parser, "Version Options")
class CredentialsOptions(optparse.OptionGroup):
+ """Command line options for specifying credentials."""
def __init__(self, parser):
self.no_pass = False
optparse.OptionGroup.__init__(self, parser, "Credentials Options")
@@ -91,6 +101,11 @@ class CredentialsOptions(optparse.OptionGroup):
self.creds.set_bind_dn(arg)
def get_credentials(self, lp):
+ """Obtain the credentials set on the command-line.
+
+ :param lp: Loadparm object to use.
+ :return: Credentials object
+ """
self.creds.guess(lp)
if not self.no_pass:
self.creds.set_cmdline_callbacks()
diff --git a/source4/scripting/python/samba/idmap.py b/source4/scripting/python/samba/idmap.py
index 16efcd0470..755ec52c7b 100644
--- a/source4/scripting/python/samba/idmap.py
+++ b/source4/scripting/python/samba/idmap.py
@@ -20,6 +20,8 @@
"""Convenience functions for using the idmap database."""
+__docformat__ = "restructuredText"
+
import samba
import misc
import ldb
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index 0e8840646c..68b43eff40 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -43,6 +43,8 @@ from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \
"""Functions for setting up a Samba configuration."""
+__docformat__ = "restructuredText"
+
DEFAULTSITE = "Default-First-Site-Name"
class InvalidNetbiosName(Exception):
@@ -236,6 +238,8 @@ def provision_paths_from_lp(lp, dnsdomain):
paths.secrets = os.path.join(paths.private_dir, lp.get("secrets database") or "secrets.ldb")
paths.templates = os.path.join(paths.private_dir, "templates.ldb")
paths.dns = os.path.join(paths.private_dir, dnsdomain + ".zone")
+ paths.namedconf = os.path.join(paths.private_dir, "named.conf")
+ paths.krb5conf = os.path.join(paths.private_dir, "krb5.conf")
paths.winsdb = os.path.join(paths.private_dir, "wins.ldb")
paths.s4_ldapi_path = os.path.join(paths.private_dir, "ldapi")
paths.phpldapadminconfig = os.path.join(paths.private_dir,
@@ -689,6 +693,7 @@ def setup_self_join(samdb, names,
domainsid, invocationid, setup_path,
policyguid):
"""Join a host to its own domain."""
+ assert isinstance(invocationid, str)
setup_add_ldif(samdb, setup_path("provision_self_join.ldif"), {
"CONFIGDN": names.configdn,
"SCHEMADN": names.schemadn,
@@ -910,7 +915,7 @@ def provision(setup_dir, message, session_info,
domainsid = security.Sid(domainsid)
if policyguid is None:
- policyguid = uuid.random()
+ policyguid = str(uuid.uuid4())
if adminpass is None:
adminpass = misc.random_password(12)
if krbtgtpass is None:
@@ -960,7 +965,7 @@ def provision(setup_dir, message, session_info,
assert serverrole in ("domain controller", "member server", "standalone")
if invocationid is None and serverrole == "domain controller":
- invocationid = uuid.random()
+ invocationid = str(uuid.uuid4())
if not os.path.exists(paths.private_dir):
os.mkdir(paths.private_dir)
@@ -1057,14 +1062,23 @@ def provision(setup_dir, message, session_info,
expression="(&(objectClass=computer)(cn=%s))" % names.hostname,
scope=SCOPE_SUBTREE)
assert isinstance(hostguid, str)
-
- create_zone_file(paths.dns, setup_path, samdb,
- hostname=names.hostname, hostip=hostip,
- hostip6=hostip6, dnsdomain=names.dnsdomain,
- domaindn=names.domaindn, dnspass=dnspass, realm=names.realm,
+
+ create_zone_file(paths.dns, setup_path, dnsdomain=names.dnsdomain,
+ domaindn=names.domaindn, hostip=hostip,
+ hostip6=hostip6, hostname=names.hostname,
+ dnspass=dnspass, realm=names.realm,
domainguid=domainguid, hostguid=hostguid)
message("Please install the zone located in %s into your DNS server" % paths.dns)
-
+
+ create_named_conf(paths.namedconf, setup_path, realm=names.realm,
+ dnsdomain=names.dnsdomain, private_dir=paths.private_dir,
+ keytab_name=paths.dns_keytab)
+ message("See %s for example configuration statements for secure GSS-TSIG updates" % paths.namedconf)
+
+ create_krb5_conf(paths.krb5conf, setup_path, dnsdomain=names.dnsdomain,
+ hostname=names.hostname, realm=names.realm)
+ message("A Kerberos configuration suitable for Samba 4 has been generated at %s" % paths.krb5conf)
+
create_phpldapadmin_config(paths.phpldapadminconfig, setup_path,
ldapi_url)
@@ -1280,13 +1294,12 @@ def create_phpldapadmin_config(path, setup_path, ldapi_uri):
{"S4_LDAPI_URI": ldapi_uri})
-def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn,
- hostip, hostip6, hostname, dnspass, realm, domainguid, hostguid):
+def create_zone_file(path, setup_path, dnsdomain, domaindn,
+ hostip, hostip6, hostname, dnspass, realm, domainguid, hostguid):
"""Write out a DNS zone file, from the info in the current database.
-
- :param path: Path of the new file.
- :param setup_path": Setup path function.
- :param samdb: SamDB object
+
+ :param path: Path of the new zone file.
+ :param setup_path: Setup path function.
:param dnsdomain: DNS Domain name
:param domaindn: DN of the Domain
:param hostip: Local IPv4 IP
@@ -1320,6 +1333,44 @@ def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn,
"HOSTIP6_HOST_LINE": hostip6_host_line,
})
+def create_named_conf(path, setup_path, realm, dnsdomain,
+ private_dir, keytab_name):
+ """Write out a file containing zone statements suitable for inclusion in a
+ named.conf file (including GSS-TSIG configuration).
+
+ :param path: Path of the new named.conf file.
+ :param setup_path: Setup path function.
+ :param realm: Realm name
+ :param dnsdomain: DNS Domain name
+ :param private_dir: Path to private directory
+ :param keytab_name: File name of DNS keytab file
+ """
+
+ setup_file(setup_path("named.conf"), path, {
+ "DNSDOMAIN": dnsdomain,
+ "REALM": realm,
+ "REALM_WC": "*." + ".".join(realm.split(".")[1:]),
+ "DNS_KEYTAB": keytab_name,
+ "DNS_KEYTAB_ABS": os.path.join(private_dir, keytab_name),
+ })
+
+def create_krb5_conf(path, setup_path, dnsdomain, hostname, realm):
+ """Write out a file containing zone statements suitable for inclusion in a
+ named.conf file (including GSS-TSIG configuration).
+
+ :param path: Path of the new named.conf file.
+ :param setup_path: Setup path function.
+ :param dnsdomain: DNS Domain name
+ :param hostname: Local hostname
+ :param realm: Realm name
+ """
+
+ setup_file(setup_path("krb5.conf"), path, {
+ "DNSDOMAIN": dnsdomain,
+ "HOSTNAME": hostname,
+ "REALM": realm,
+ })
+
def load_schema(setup_path, samdb, schemadn, netbiosname, configdn, sitename):
"""Load schema for the SamDB.
diff --git a/source4/scripting/python/samba/samba3.py b/source4/scripting/python/samba/samba3.py
index cffedb54af..c1340b7760 100644
--- a/source4/scripting/python/samba/samba3.py
+++ b/source4/scripting/python/samba/samba3.py
@@ -19,6 +19,8 @@
"""Support for reading Samba 3 data files."""
+__docformat__ = "restructuredText"
+
REGISTRY_VALUE_PREFIX = "SAMBA_REGVAL"
REGISTRY_DB_VERSION = 1
@@ -307,6 +309,7 @@ class ShareInfoDatabase(TdbDatabase):
class Shares:
+ """Container for share objects."""
def __init__(self, lp, shareinfo):
self.lp = lp
self.shareinfo = shareinfo
@@ -492,6 +495,7 @@ class TdbSam(TdbDatabase):
assert self.version in (0, 1, 2)
def usernames(self):
+ """Iterate over the usernames in this Tdb database."""
for k in self.tdb.keys():
if k.startswith(TDBSAM_USER_PREFIX):
yield k[len(TDBSAM_USER_PREFIX):].rstrip("\0")
@@ -633,6 +637,7 @@ class WinsDatabase:
return iter(self.entries)
def items(self):
+ """Return the entries in this WINS database."""
return self.entries.items()
def close(self): # for consistency
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index 198d1e9f5c..6465f49519 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -28,6 +28,8 @@ import ldb
from samba.idmap import IDmapDB
import pwd
+__docformat__ = "restructuredText"
+
class SamDB(samba.Ldb):
"""The SAM database."""
diff --git a/source4/scripting/python/samba/tests/dcerpc/registry.py b/source4/scripting/python/samba/tests/dcerpc/registry.py
index 1afdc582a7..81133ff641 100644
--- a/source4/scripting/python/samba/tests/dcerpc/registry.py
+++ b/source4/scripting/python/samba/tests/dcerpc/registry.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import winreg
+from samba.dcerpc import winreg
import unittest
from samba.tests import RpcInterfaceTestCase
diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
index 6c43632d97..3b37f8a9bc 100644
--- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
+++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import echo
+from samba.dcerpc import echo
import unittest
from samba.tests import RpcInterfaceTestCase
diff --git a/source4/scripting/python/samba/tests/dcerpc/sam.py b/source4/scripting/python/samba/tests/dcerpc/sam.py
index 8ef12dad86..50e00a3f9e 100644
--- a/source4/scripting/python/samba/tests/dcerpc/sam.py
+++ b/source4/scripting/python/samba/tests/dcerpc/sam.py
@@ -1,7 +1,8 @@
#!/usr/bin/python
+# -*- coding: utf-8 -*-
# Unix SMB/CIFS implementation.
-# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+# Copyright © Jelmer Vernooij <jelmer@samba.org> 2008
#
# 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
@@ -17,12 +18,29 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import samr
+from samba.dcerpc import samr, security
from samba.tests import RpcInterfaceTestCase
+# FIXME: Pidl should be doing this for us
+def toArray((handle, array, num_entries)):
+ ret = []
+ for x in range(num_entries):
+ ret.append((array.entries[x].idx, array.entries[x].name))
+ return ret
+
+
class SamrTests(RpcInterfaceTestCase):
def setUp(self):
self.conn = samr.samr("ncalrpc:", self.get_loadparm())
def test_connect5(self):
(level, info, handle) = self.conn.Connect5(None, 0, 1, samr.ConnectInfo1())
+
+ def test_connect2(self):
+ handle = self.conn.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED)
+
+ def test_EnumDomains(self):
+ handle = self.conn.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED)
+ domains = toArray(self.conn.EnumDomains(handle, 0, -1))
+ self.conn.Close(handle)
+
diff --git a/source4/scripting/python/samba/tests/dcerpc/unix.py b/source4/scripting/python/samba/tests/dcerpc/unix.py
index 43978ac9dc..aa47b71b16 100644
--- a/source4/scripting/python/samba/tests/dcerpc/unix.py
+++ b/source4/scripting/python/samba/tests/dcerpc/unix.py
@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import unixinfo
+from samba.dcerpc import unixinfo
from samba.tests import RpcInterfaceTestCase
class UnixinfoTests(RpcInterfaceTestCase):
@@ -27,8 +27,8 @@ class UnixinfoTests(RpcInterfaceTestCase):
def test_getpwuid(self):
infos = self.conn.GetPWUid(range(512))
self.assertEquals(512, len(infos))
- self.assertEquals("", infos[0].shell)
- self.assertEquals("", infos[0].homedir)
+ self.assertEquals("/bin/false", infos[0].shell)
+ self.assertTrue(isinstance(infos[0].homedir, unicode))
def test_gidtosid(self):
self.conn.GidToSid(1000)
diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py
index b9e0e16d3c..76c10145f0 100644
--- a/source4/scripting/python/samba/tests/provision.py
+++ b/source4/scripting/python/samba/tests/provision.py
@@ -21,7 +21,7 @@ import os
from samba.provision import setup_secretsdb, secretsdb_become_dc, findnss
import samba.tests
from ldb import Dn
-import param
+from samba import param
import unittest
lp = samba.tests.cmdline_loadparm
diff --git a/source4/scripting/python/samba/tests/samdb.py b/source4/scripting/python/samba/tests/samdb.py
index 0e175bf936..0d4f7bde0e 100644
--- a/source4/scripting/python/samba/tests/samdb.py
+++ b/source4/scripting/python/samba/tests/samdb.py
@@ -29,18 +29,18 @@ import uuid
class SamDBTestCase(TestCaseInTempDir):
def setUp(self):
super(SamDBTestCase, self).setUp()
- invocationid = uuid.random()
+ invocationid = str(uuid.uuid4())
domaindn = "DC=COM,DC=EXAMPLE"
self.domaindn = domaindn
configdn = "CN=Configuration," + domaindn
schemadn = "CN=Schema," + configdn
- domainguid = uuid.random()
- policyguid = uuid.random()
+ domainguid = str(uuid.uuid4())
+ policyguid = str(uuid.uuid4())
setup_path = lambda x: os.path.join("setup", x)
creds = Credentials()
creds.set_anonymous()
domainsid = security.random_sid()
- hostguid = uuid.random()
+ hostguid = str(uuid.uuid4())
path = os.path.join(self.tempdir, "samdb.ldb")
self.samdb = setup_samdb(path, setup_path, system_session(), creds,
cmdline_loadparm, schemadn, configdn,
diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py
index f40f2cffe7..0c83604e82 100644
--- a/source4/scripting/python/samba/upgrade.py
+++ b/source4/scripting/python/samba/upgrade.py
@@ -7,6 +7,8 @@
"""Support code for upgrading from Samba 3 to Samba 4."""
+__docformat__ = "restructuredText"
+
from provision import findnss, provision, FILL_DRS
import grp
import ldb
diff --git a/source4/scripting/python/smbpython.c b/source4/scripting/python/smbpython.c
deleted file mode 100644
index c5de53fd60..0000000000
--- a/source4/scripting/python/smbpython.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Samba utility functions
- Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
-
- 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 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- 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, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include <Python.h>
-#include "scripting/python/modules.h"
-
-int main(int argc, char **argv)
-{
- py_load_samba_modules();
- Py_Initialize();
- if (strchr(argv[0], '/') != NULL) {
- char *bindir = strndup(argv[0], strrchr(argv[0], '/')-argv[0]);
- py_update_path(bindir);
- free(bindir);
- }
- return Py_Main(argc,argv);
-}
diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c
index 18cfb6ce32..98ef9adaa9 100644
--- a/source4/scripting/python/uuidmodule.c
+++ b/source4/scripting/python/uuidmodule.c
@@ -46,7 +46,7 @@ static PyObject *uuid_random(PyObject *self, PyObject *args)
}
static PyMethodDef methods[] = {
- { "random", (PyCFunction)uuid_random, METH_VARARGS, NULL},
+ { "uuid4", (PyCFunction)uuid_random, METH_VARARGS, NULL},
{ NULL, NULL }
};