diff options
Diffstat (limited to 'source4/param')
-rw-r--r-- | source4/param/config.mk | 16 | ||||
-rw-r--r-- | source4/param/param.i | 9 | ||||
-rw-r--r-- | source4/param/param.py | 6 | ||||
-rw-r--r-- | source4/param/param_wrap.c | 76 | ||||
-rw-r--r-- | source4/param/provision.c | 139 | ||||
-rw-r--r-- | source4/param/provision.h | 51 | ||||
-rw-r--r-- | source4/param/share.c | 3 | ||||
-rw-r--r-- | source4/param/share.h | 5 | ||||
-rw-r--r-- | source4/param/share_classic.c | 1 | ||||
-rw-r--r-- | source4/param/share_ldb.c | 6 | ||||
-rw-r--r-- | source4/param/tests/share.c | 4 |
11 files changed, 284 insertions, 32 deletions
diff --git a/source4/param/config.mk b/source4/param/config.mk index bc8f7a5dc7..3e6758db8a 100644 --- a/source4/param/config.mk +++ b/source4/param/config.mk @@ -1,9 +1,14 @@ [LIBRARY::LIBSAMBA-HOSTCONFIG] -VERSION = 0.0.1 -SO_VERSION = 1 PUBLIC_DEPENDENCIES = LIBSAMBA-UTIL PRIVATE_DEPENDENCIES = DYNCONFIG LIBREPLACE_EXT CHARSET -PRIVATE_PROTO_HEADER = proto.h + +LIBSAMBA-HOSTCONFIG_VERSION = 0.0.1 +LIBSAMBA-HOSTCONFIG-SOVERSION = 0 + +LIBSAMBA-HOSTCONFIG_OBJ_FILES = param/loadparm.o \ + param/generic.o \ + param/util.o \ + lib/version.o LIBSAMBA-CONFIG_OBJ_FILES = param/loadparm.o \ param/params.o \ @@ -15,6 +20,11 @@ PUBLIC_HEADERS += param/param.h PC_FILES += param/samba-hostconfig.pc +[SUBSYSTEM::PROVISION] +PRIVATE_DEPENDENCIES = LIBPYTHON + +PROVISION_OBJ_FILES = param/provision.o + ################################# # Start SUBSYSTEM share [SUBSYSTEM::share] diff --git a/source4/param/param.i b/source4/param/param.i index 77d781d6ff..2f62cb2f16 100644 --- a/source4/param/param.i +++ b/source4/param/param.i @@ -307,6 +307,15 @@ struct loadparm_context *lp_from_py_object(PyObject *py_obj) return lp_ctx; } + if (py_obj == Py_None) { + lp_ctx = loadparm_init(NULL); + if (!lp_load_default(lp_ctx)) { + talloc_free(lp_ctx); + return NULL; + } + return lp_ctx; + } + if (SWIG_ConvertPtr(py_obj, (void *)&lp_ctx, SWIGTYPE_p_loadparm_context, 0 | 0 ) < 0) return NULL; return lp_ctx; diff --git a/source4/param/param.py b/source4/param/param.py index 025acc6be1..0419c75bfa 100644 --- a/source4/param/param.py +++ b/source4/param/param.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. @@ -79,7 +79,7 @@ LoadParm_swigregister(LoadParm) class loadparm_service(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - def __init__(self): raise AttributeError, "No constructor defined" + def __init__(self, *args, **kwargs): raise AttributeError, "No constructor defined" __repr__ = _swig_repr loadparm_service.volume_label = new_instancemethod(_param.loadparm_service_volume_label,None,loadparm_service) loadparm_service.printername = new_instancemethod(_param.loadparm_service_printername,None,loadparm_service) @@ -137,7 +137,7 @@ ParamFile_swigregister(ParamFile) class param_opt(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - def __init__(self): raise AttributeError, "No constructor defined" + def __init__(self, *args, **kwargs): raise AttributeError, "No constructor defined" __repr__ = _swig_repr key = _swig_property(_param.param_opt_key_get) value = _swig_property(_param.param_opt_value_get) diff --git a/source4/param/param_wrap.c b/source4/param/param_wrap.c index e74f902645..d07be04a66 100644 --- a/source4/param/param_wrap.c +++ b/source4/param/param_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; } @@ -2504,7 +2522,7 @@ static swig_module_info swig_module = {swig_types, 15, 0, 0, 0, 0}; #define SWIG_name "_param" -#define SWIGVERSION 0x010333 +#define SWIGVERSION 0x010335 #define SWIG_VERSION SWIGVERSION @@ -2776,6 +2794,15 @@ struct loadparm_context *lp_from_py_object(PyObject *py_obj) return lp_ctx; } + if (py_obj == Py_None) { + lp_ctx = loadparm_init(NULL); + if (!lp_load_default(lp_ctx)) { + talloc_free(lp_ctx); + return NULL; + } + return lp_ctx; + } + if (SWIG_ConvertPtr(py_obj, (void *)&lp_ctx, SWIGTYPE_p_loadparm_context, 0 | 0 ) < 0) return NULL; return lp_ctx; @@ -4073,7 +4100,7 @@ SWIGINTERN PyObject *_wrap_new_param_section(PyObject *SWIGUNUSEDPARM(self), PyO param_section *result = 0 ; if (!SWIG_Python_UnpackTuple(args,"new_param_section",0,0,0)) SWIG_fail; - result = (param_section *)(param_section *) calloc(1, sizeof(param_section)); + result = (param_section *)calloc(1, sizeof(param_section)); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_section, SWIG_POINTER_NEW | 0 ); return resultobj; fail: @@ -4325,7 +4352,7 @@ SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { size_t i; swig_module_info *module_head, *iter; - int found; + int found, init; clientdata = clientdata; @@ -4335,6 +4362,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 */ @@ -4363,6 +4393,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/param/provision.c b/source4/param/provision.c new file mode 100644 index 0000000000..0e54acf9e4 --- /dev/null +++ b/source4/param/provision.c @@ -0,0 +1,139 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) 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 + 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 "auth/auth.h" +#include "lib/ldb_wrap.h" +#include "libcli/raw/libcliraw.h" +#include "librpc/ndr/libndr.h" + +#include "param/param.h" +#include "param/provision.h" +#include <Python.h> +#include "scripting/python/modules.h" + +NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, + struct provision_settings *settings, + struct provision_result *result) +{ + extern struct loadparm_context *lp_from_py_object(PyObject *py_obj); + struct ldb_context *ldb_context_from_py_object(PyObject *py_obj); + PyObject *provision_mod, *provision_dict, *provision_fn, *py_result, *parameters; + + DEBUG(0,("Provision for Become-DC test using python\n")); + + py_load_samba_modules(); + Py_Initialize(); + py_update_path("bin"); /* FIXME: Can't assume this is always the case */ + + provision_mod = PyImport_Import(PyString_FromString("samba.provision")); + + if (provision_mod == NULL) { + PyErr_Print(); + DEBUG(0, ("Unable to import provision Python module.\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + provision_dict = PyModule_GetDict(provision_mod); + + if (provision_dict == NULL) { + DEBUG(0, ("Unable to get dictionary for provision module\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + provision_fn = PyDict_GetItemString(provision_dict, "provision_become_dc"); + if (provision_fn == NULL) { + PyErr_Print(); + DEBUG(0, ("Unable to get provision_become_dc function\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + DEBUG(0,("New Server in Site[%s]\n", + settings->site_name)); + + DEBUG(0,("DSA Instance [%s]\n" + "\tinvocationId[%s]\n", + settings->ntds_dn_str, + settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id))); + + DEBUG(0,("Pathes under targetdir[%s]\n", + settings->targetdir)); + parameters = PyDict_New(); + + PyDict_SetItemString(parameters, "smbconf", + PyString_FromString(lp_configfile(lp_ctx))); + + PyDict_SetItemString(parameters, "rootdn", + PyString_FromString(settings->root_dn_str)); + if (settings->targetdir != NULL) + PyDict_SetItemString(parameters, "targetdir", + PyString_FromString(settings->targetdir)); + PyDict_SetItemString(parameters, "setup_dir", + PyString_FromString("setup")); + PyDict_SetItemString(parameters, "hostname", + PyString_FromString(settings->netbios_name)); + PyDict_SetItemString(parameters, "domain", + PyString_FromString(settings->domain)); + PyDict_SetItemString(parameters, "realm", + PyString_FromString(settings->realm)); + if (settings->root_dn_str) + PyDict_SetItemString(parameters, "rootdn", + PyString_FromString(settings->root_dn_str)); + + if (settings->domain_dn_str) + PyDict_SetItemString(parameters, "domaindn", + PyString_FromString(settings->domain_dn_str)); + + if (settings->schema_dn_str) + PyDict_SetItemString(parameters, "schemadn", + PyString_FromString(settings->schema_dn_str)); + + if (settings->config_dn_str) + PyDict_SetItemString(parameters, "configdn", + PyString_FromString(settings->config_dn_str)); + + if (settings->server_dn_str) + PyDict_SetItemString(parameters, "serverdn", + PyString_FromString(settings->server_dn_str)); + + if (settings->site_name) + PyDict_SetItemString(parameters, "sitename", + PyString_FromString(settings->site_name)); + + PyDict_SetItemString(parameters, "machinepass", + PyString_FromString(settings->machine_password)); + + py_result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters); + + Py_DECREF(parameters); + + if (py_result == NULL) { + PyErr_Print(); + PyErr_Clear(); + return NT_STATUS_UNSUCCESSFUL; + } + + result->domaindn = talloc_strdup(mem_ctx, PyString_AsString(PyObject_GetAttrString(py_result, "domaindn"))); + + /* FIXME paths */ + result->lp_ctx = lp_from_py_object(PyObject_GetAttrString(py_result, "lp")); + result->samdb = ldb_context_from_py_object(PyObject_GetAttrString(py_result, "samdb")); + + return NT_STATUS_OK; +} diff --git a/source4/param/provision.h b/source4/param/provision.h new file mode 100644 index 0000000000..af9685d292 --- /dev/null +++ b/source4/param/provision.h @@ -0,0 +1,51 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) 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 + 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/>. +*/ + +#ifndef _PROVISION_H_ +#define _PROVISION_H_ + +struct provision_settings { + const char *site_name; + const char *root_dn_str; + const char *domain_dn_str; + const char *config_dn_str; + const char *schema_dn_str; + const char *server_dn_str; + const struct GUID *invocation_id; + const char *netbios_name; + const char *host_ip; + const char *realm; + const char *domain; + const char *ntds_dn_str; + const char *machine_password; + const char *targetdir; +}; + +/* FIXME: Rename this to hostconfig ? */ +struct provision_result { + const char *domaindn; + struct ldb_context *samdb; + struct loadparm_context *lp_ctx; +}; + +NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, + struct provision_settings *settings, + struct provision_result *result); + +#endif /* _PROVISION_H_ */ diff --git a/source4/param/share.c b/source4/param/share.c index 2727518c05..47aea55751 100644 --- a/source4/param/share.c +++ b/source4/param/share.c @@ -126,6 +126,7 @@ NTSTATUS share_register(const struct share_ops *ops) } NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, const char *backend_name, + struct event_context *event_ctx, struct loadparm_context *lp_ctx, struct share_context **ctx) { @@ -137,7 +138,7 @@ NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, const char *backend_name return NT_STATUS_INTERNAL_ERROR; } - return ops->init(mem_ctx, ops, lp_ctx, ctx); + return ops->init(mem_ctx, ops, event_ctx, lp_ctx, ctx); } /* diff --git a/source4/param/share.h b/source4/param/share.h index 9f9cbdce5b..2a85fd4fbb 100644 --- a/source4/param/share.h +++ b/source4/param/share.h @@ -47,9 +47,12 @@ struct share_info { void *value; }; +struct event_context; + struct share_ops { const char *name; - NTSTATUS (*init)(TALLOC_CTX *, const struct share_ops*, struct loadparm_context *lp_ctx, + NTSTATUS (*init)(TALLOC_CTX *, const struct share_ops*, struct event_context *ev_ctx, + struct loadparm_context *lp_ctx, struct share_context **); const char *(*string_option)(struct share_config *, const char *, const char *); int (*int_option)(struct share_config *, const char *, int); diff --git a/source4/param/share_classic.c b/source4/param/share_classic.c index c3adc4473c..bac1aac2d7 100644 --- a/source4/param/share_classic.c +++ b/source4/param/share_classic.c @@ -25,6 +25,7 @@ static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, + struct event_context *event_ctx, struct loadparm_context *lp_ctx, struct share_context **ctx) { diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index fb40f1e9bf..eba1665cc9 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -27,7 +27,9 @@ #include "param/share.h" #include "param/param.h" -static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct loadparm_context *lp_ctx, +static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, + struct event_context *ev_ctx, + struct loadparm_context *lp_ctx, struct share_context **ctx) { struct ldb_context *sdb; @@ -38,7 +40,7 @@ static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, stru return NT_STATUS_NO_MEMORY; } - sdb = ldb_wrap_connect(*ctx, lp_ctx, + sdb = ldb_wrap_connect(*ctx, ev_ctx, lp_ctx, private_path(*ctx, lp_ctx, "share.ldb"), system_session(*ctx, lp_ctx), NULL, 0, NULL); diff --git a/source4/param/tests/share.c b/source4/param/tests/share.c index 6d03b4e049..c64b5c607a 100644 --- a/source4/param/tests/share.c +++ b/source4/param/tests/share.c @@ -182,12 +182,12 @@ static void tcase_add_share_tests(struct torture_tcase *tcase) static bool setup_ldb(struct torture_context *tctx, void **data) { - return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "ldb", tctx->lp_ctx, (struct share_context **)data)); + return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "ldb", tctx->ev, tctx->lp_ctx, (struct share_context **)data)); } static bool setup_classic(struct torture_context *tctx, void **data) { - return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "classic", tctx->lp_ctx, (struct share_context **)data)); + return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "classic", tctx->ev, tctx->lp_ctx, (struct share_context **)data)); } static bool teardown(struct torture_context *tctx, void *data) |