From 82c7872639d48a2791e409f8cd014978c4aa352f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 9 Apr 2008 03:23:13 +0200 Subject: Move provision C bindings to param/. (This used to be commit 7d45ed0c3ebc57f7131603f768f8e022d7139530) --- source4/param/config.mk | 4 + source4/param/provision.c | 129 ++++++++++++++++++++++++++++++ source4/param/provision.h | 45 +++++++++++ source4/torture/config.mk | 4 +- source4/torture/libnet/libnet_BecomeDC.c | 1 + source4/torture/local/torture.c | 1 + source4/torture/util.h | 23 ------ source4/torture/util_provision.c | 130 ------------------------------- 8 files changed, 182 insertions(+), 155 deletions(-) create mode 100644 source4/param/provision.c create mode 100644 source4/param/provision.h delete mode 100644 source4/torture/util_provision.c diff --git a/source4/param/config.mk b/source4/param/config.mk index eee22cf1b8..064c293fa4 100644 --- a/source4/param/config.mk +++ b/source4/param/config.mk @@ -12,6 +12,10 @@ PRIVATE_PROTO_HEADER = proto.h PUBLIC_HEADERS += param/param.h +[SUBSYSTEM::PROVISION] +OBJ_FILES = provision.o +PRIVATE_DEPENDENCIES = LIBPYTHON + ################################# # Start SUBSYSTEM share [SUBSYSTEM::share] diff --git a/source4/param/provision.c b/source4/param/provision.c new file mode 100644 index 0000000000..5d1f01c59a --- /dev/null +++ b/source4/param/provision.c @@ -0,0 +1,129 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 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 . +*/ + +#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 +#include "scripting/python/modules.h" + +NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, + struct provision_settings *settings) +{ + PyObject *provision_mod, *provision_dict, *provision_fn, *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[%s] in Site[%s]\n", settings->dns_name, + settings->site_name)); + + DEBUG(0,("DSA Instance [%s]\n" + "\tobjectGUID[%s]\n" + "\tinvocationId[%s]\n", + settings->ntds_dn_str, + settings->ntds_guid == NULL?"None":GUID_string(mem_ctx, settings->ntds_guid), + 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, "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)); + + result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters); + + Py_DECREF(parameters); + + if (result == NULL) { + PyErr_Print(); + PyErr_Clear(); + return NT_STATUS_UNSUCCESSFUL; + } + + return NT_STATUS_OK; +} diff --git a/source4/param/provision.h b/source4/param/provision.h new file mode 100644 index 0000000000..323159d417 --- /dev/null +++ b/source4/param/provision.h @@ -0,0 +1,45 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 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 . +*/ + +#ifndef _PROVISION_H_ +#define _PROVISION_H_ + +struct provision_settings { + const char *dns_name; + 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 struct GUID *ntds_guid; + const char *ntds_dn_str; + const char *machine_password; + const char *targetdir; +}; + +NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, + struct provision_settings *settings); + +#endif /* _PROVISION_H_ */ diff --git a/source4/torture/config.mk b/source4/torture/config.mk index 1d09d74f99..7acb1e0792 100644 --- a/source4/torture/config.mk +++ b/source4/torture/config.mk @@ -16,8 +16,8 @@ PUBLIC_DEPENDENCIES = \ PUBLIC_HEADERS += torture/torture.h torture/ui.h [SUBSYSTEM::TORTURE_UTIL] -OBJ_FILES = util_smb.o util_provision.o -PRIVATE_DEPENDENCIES = LIBCLI_RAW LIBPYTHON smbcalls +OBJ_FILES = util_smb.o +PRIVATE_DEPENDENCIES = LIBCLI_RAW LIBPYTHON smbcalls PROVISION PUBLIC_DEPENDENCIES = POPT_CREDENTIALS ################################# diff --git a/source4/torture/libnet/libnet_BecomeDC.c b/source4/torture/libnet/libnet_BecomeDC.c index f8699fe06a..bb5e8fe061 100644 --- a/source4/torture/libnet/libnet_BecomeDC.c +++ b/source4/torture/libnet/libnet_BecomeDC.c @@ -38,6 +38,7 @@ #include "auth/auth.h" #include "param/param.h" #include "torture/util.h" +#include "param/provision.h" struct test_become_dc_state { struct libnet_context *ctx; diff --git a/source4/torture/local/torture.c b/source4/torture/local/torture.c index 9bd60d9620..718bd38aad 100644 --- a/source4/torture/local/torture.c +++ b/source4/torture/local/torture.c @@ -25,6 +25,7 @@ #include "lib/events/events.h" #include "libcli/raw/libcliraw.h" #include "torture/util.h" +#include "param/provision.h" static bool test_tempdir(struct torture_context *tctx) { diff --git a/source4/torture/util.h b/source4/torture/util.h index 72f97e4766..1009fcf9f1 100644 --- a/source4/torture/util.h +++ b/source4/torture/util.h @@ -20,29 +20,6 @@ #ifndef _TORTURE_PROVISION_H_ #define _TORTURE_PROVISION_H_ -struct provision_settings { - const char *dns_name; - 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 struct GUID *ntds_guid; - const char *ntds_dn_str; - const char *machine_password; - const char *targetdir; -}; - -NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, - struct provision_settings *settings); - - /** setup a directory ready for a test */ diff --git a/source4/torture/util_provision.c b/source4/torture/util_provision.c deleted file mode 100644 index 3167a37cdf..0000000000 --- a/source4/torture/util_provision.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Jelmer Vernooij 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 . -*/ - -#include "includes.h" -#include "auth/auth.h" -#include "lib/ldb_wrap.h" -#include "torture/torture.h" -#include "libcli/raw/libcliraw.h" -#include "torture/util.h" -#include "librpc/ndr/libndr.h" - -#include "param/param.h" -#include -#include "scripting/python/modules.h" - -NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, - struct provision_settings *settings) -{ - PyObject *provision_mod, *provision_dict, *provision_fn, *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[%s] in Site[%s]\n", settings->dns_name, - settings->site_name)); - - DEBUG(0,("DSA Instance [%s]\n" - "\tobjectGUID[%s]\n" - "\tinvocationId[%s]\n", - settings->ntds_dn_str, - settings->ntds_guid == NULL?"None":GUID_string(mem_ctx, settings->ntds_guid), - 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, "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)); - - result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters); - - Py_DECREF(parameters); - - if (result == NULL) { - PyErr_Print(); - PyErr_Clear(); - return NT_STATUS_UNSUCCESSFUL; - } - - return NT_STATUS_OK; -} -- cgit