Include the smbconf parameter to the provision
[samba.git] / source4 / param / provision.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Samba utility functions
4    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
5    
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.
10    
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.
15    
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/>.
18 */
19
20 #include "includes.h"
21 #include "auth/auth.h"
22 #include "lib/ldb_wrap.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "librpc/ndr/libndr.h"
25
26 #include "param/param.h"
27 #include "param/provision.h"
28 #include <Python.h>
29 #include "scripting/python/modules.h"
30
31 NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
32                         struct provision_settings *settings, 
33                         struct provision_result *result)
34 {
35         extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);
36         struct ldb_context *ldb_context_from_py_object(PyObject *py_obj);
37         PyObject *provision_mod, *provision_dict, *provision_fn, *py_result, *parameters;
38         
39         DEBUG(0,("Provision for Become-DC test using python\n"));
40
41         py_load_samba_modules();
42         Py_Initialize();
43         py_update_path("bin"); /* FIXME: Can't assume this is always the case */
44
45         provision_mod = PyImport_Import(PyString_FromString("samba.provision"));
46
47         if (provision_mod == NULL) {
48                 PyErr_Print();
49                 DEBUG(0, ("Unable to import provision Python module.\n"));
50                 return NT_STATUS_UNSUCCESSFUL;
51         }
52
53         provision_dict = PyModule_GetDict(provision_mod);
54
55         if (provision_dict == NULL) {
56                 DEBUG(0, ("Unable to get dictionary for provision module\n"));
57                 return NT_STATUS_UNSUCCESSFUL;
58         }
59
60         provision_fn = PyDict_GetItemString(provision_dict, "provision_become_dc");
61         if (provision_fn == NULL) {
62                 PyErr_Print();
63                 DEBUG(0, ("Unable to get provision_become_dc function\n"));
64                 return NT_STATUS_UNSUCCESSFUL;
65         }
66         
67         DEBUG(0,("New Server in Site[%s]\n", 
68                  settings->site_name));
69
70         DEBUG(0,("DSA Instance [%s]\n"
71                 "\tinvocationId[%s]\n",
72                 settings->ntds_dn_str,
73                 settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id)));
74
75         DEBUG(0,("Pathes under targetdir[%s]\n",
76                  settings->targetdir));
77         parameters = PyDict_New();
78
79         PyDict_SetItemString(parameters, "smbconf", 
80                              PyString_FromString(lp_configfile(lp_ctx)));
81
82         PyDict_SetItemString(parameters, "rootdn", 
83                                                  PyString_FromString(settings->root_dn_str));
84         if (settings->targetdir != NULL)
85                 PyDict_SetItemString(parameters, "targetdir", 
86                                                          PyString_FromString(settings->targetdir));
87         PyDict_SetItemString(parameters, "setup_dir", 
88                              PyString_FromString("setup"));
89         PyDict_SetItemString(parameters, "hostname", 
90                                                  PyString_FromString(settings->netbios_name));
91         PyDict_SetItemString(parameters, "domain", 
92                                                  PyString_FromString(settings->domain));
93         PyDict_SetItemString(parameters, "realm", 
94                                                  PyString_FromString(settings->realm));
95         if (settings->root_dn_str)
96                 PyDict_SetItemString(parameters, "rootdn", 
97                                      PyString_FromString(settings->root_dn_str));
98
99         if (settings->domain_dn_str) 
100                 PyDict_SetItemString(parameters, "domaindn", 
101                                      PyString_FromString(settings->domain_dn_str));
102
103         if (settings->schema_dn_str) 
104                 PyDict_SetItemString(parameters, "schemadn", 
105                                      PyString_FromString(settings->schema_dn_str));
106         
107         if (settings->config_dn_str) 
108                 PyDict_SetItemString(parameters, "configdn", 
109                                      PyString_FromString(settings->config_dn_str));
110         
111         if (settings->server_dn_str) 
112                 PyDict_SetItemString(parameters, "serverdn", 
113                                      PyString_FromString(settings->server_dn_str));
114         
115         if (settings->site_name) 
116                 PyDict_SetItemString(parameters, "sitename", 
117                                      PyString_FromString(settings->site_name));
118
119         PyDict_SetItemString(parameters, "machinepass", 
120                              PyString_FromString(settings->machine_password));
121
122         py_result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters);
123
124         Py_DECREF(parameters);
125
126         if (py_result == NULL) {
127                 PyErr_Print();
128                 PyErr_Clear();
129                 return NT_STATUS_UNSUCCESSFUL;
130         }
131
132         result->domaindn = talloc_strdup(mem_ctx, PyString_AsString(PyObject_GetAttrString(py_result, "domaindn")));
133
134         /* FIXME paths */
135         result->lp_ctx = lp_from_py_object(PyObject_GetAttrString(py_result, "lp"));
136         result->samdb = ldb_context_from_py_object(PyObject_GetAttrString(py_result, "samdb"));
137
138         return NT_STATUS_OK;
139 }