2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "auth/auth.h"
22 #include "lib/ldb_wrap.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "librpc/ndr/libndr.h"
26 #include "param/param.h"
27 #include "param/provision.h"
29 #include "scripting/python/modules.h"
30 #include "lib/ldb/pyldb.h"
31 #include "param/pyparam.h"
33 NTSTATUS
provision_bare(TALLOC_CTX
*mem_ctx
, struct loadparm_context
*lp_ctx
,
34 struct provision_settings
*settings
,
35 struct provision_result
*result
)
38 PyObject
*provision_mod
, *provision_dict
, *provision_fn
, *py_result
, *parameters
;
40 DEBUG(0,("Provision for Become-DC test using python\n"));
42 py_load_samba_modules();
44 py_update_path("bin"); /* FIXME: Can't assume this is always the case */
46 provision_mod
= PyImport_Import(PyString_FromString("samba.provision"));
48 if (provision_mod
== NULL
) {
50 DEBUG(0, ("Unable to import provision Python module.\n"));
51 return NT_STATUS_UNSUCCESSFUL
;
54 provision_dict
= PyModule_GetDict(provision_mod
);
56 if (provision_dict
== NULL
) {
57 DEBUG(0, ("Unable to get dictionary for provision module\n"));
58 return NT_STATUS_UNSUCCESSFUL
;
61 provision_fn
= PyDict_GetItemString(provision_dict
, "provision_become_dc");
62 if (provision_fn
== NULL
) {
64 DEBUG(0, ("Unable to get provision_become_dc function\n"));
65 return NT_STATUS_UNSUCCESSFUL
;
68 DEBUG(0,("New Server in Site[%s]\n",
69 settings
->site_name
));
71 DEBUG(0,("DSA Instance [%s]\n"
72 "\tinvocationId[%s]\n",
73 settings
->ntds_dn_str
,
74 settings
->invocation_id
== NULL
?"None":GUID_string(mem_ctx
, settings
->invocation_id
)));
76 DEBUG(0,("Pathes under targetdir[%s]\n",
77 settings
->targetdir
));
78 parameters
= PyDict_New();
80 configfile
= lp_configfile(lp_ctx
);
81 if (configfile
!= NULL
) {
82 PyDict_SetItemString(parameters
, "smbconf",
83 PyString_FromString(configfile
));
86 PyDict_SetItemString(parameters
, "rootdn",
87 PyString_FromString(settings
->root_dn_str
));
88 if (settings
->targetdir
!= NULL
)
89 PyDict_SetItemString(parameters
, "targetdir",
90 PyString_FromString(settings
->targetdir
));
91 PyDict_SetItemString(parameters
, "setup_dir",
92 PyString_FromString("setup"));
93 PyDict_SetItemString(parameters
, "hostname",
94 PyString_FromString(settings
->netbios_name
));
95 PyDict_SetItemString(parameters
, "domain",
96 PyString_FromString(settings
->domain
));
97 PyDict_SetItemString(parameters
, "realm",
98 PyString_FromString(settings
->realm
));
99 if (settings
->root_dn_str
)
100 PyDict_SetItemString(parameters
, "rootdn",
101 PyString_FromString(settings
->root_dn_str
));
103 if (settings
->domain_dn_str
)
104 PyDict_SetItemString(parameters
, "domaindn",
105 PyString_FromString(settings
->domain_dn_str
));
107 if (settings
->schema_dn_str
)
108 PyDict_SetItemString(parameters
, "schemadn",
109 PyString_FromString(settings
->schema_dn_str
));
111 if (settings
->config_dn_str
)
112 PyDict_SetItemString(parameters
, "configdn",
113 PyString_FromString(settings
->config_dn_str
));
115 if (settings
->server_dn_str
)
116 PyDict_SetItemString(parameters
, "serverdn",
117 PyString_FromString(settings
->server_dn_str
));
119 if (settings
->site_name
)
120 PyDict_SetItemString(parameters
, "sitename",
121 PyString_FromString(settings
->site_name
));
123 PyDict_SetItemString(parameters
, "machinepass",
124 PyString_FromString(settings
->machine_password
));
126 py_result
= PyEval_CallObjectWithKeywords(provision_fn
, NULL
, parameters
);
128 Py_DECREF(parameters
);
130 if (py_result
== NULL
) {
133 return NT_STATUS_UNSUCCESSFUL
;
136 result
->domaindn
= talloc_strdup(mem_ctx
, PyString_AsString(PyObject_GetAttrString(py_result
, "domaindn")));
139 result
->lp_ctx
= lp_from_py_object(PyObject_GetAttrString(py_result
, "lp"));
140 result
->samdb
= PyLdb_AsLdbContext(PyObject_GetAttrString(py_result
, "samdb"));