Remove dns_name element
[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 {
34         PyObject *provision_mod, *provision_dict, *provision_fn, *result, *parameters;
35         
36         DEBUG(0,("Provision for Become-DC test using python\n"));
37
38         py_load_samba_modules();
39         Py_Initialize();
40         py_update_path("bin"); /* FIXME: Can't assume this is always the case */
41
42         provision_mod = PyImport_Import(PyString_FromString("samba.provision"));
43
44         if (provision_mod == NULL) {
45                 PyErr_Print();
46                 DEBUG(0, ("Unable to import provision Python module.\n"));
47                 return NT_STATUS_UNSUCCESSFUL;
48         }
49
50         provision_dict = PyModule_GetDict(provision_mod);
51
52         if (provision_dict == NULL) {
53                 DEBUG(0, ("Unable to get dictionary for provision module\n"));
54                 return NT_STATUS_UNSUCCESSFUL;
55         }
56
57         provision_fn = PyDict_GetItemString(provision_dict, "provision_become_dc");
58         if (provision_fn == NULL) {
59                 PyErr_Print();
60                 DEBUG(0, ("Unable to get provision_become_dc function\n"));
61                 return NT_STATUS_UNSUCCESSFUL;
62         }
63         
64         DEBUG(0,("New Server in Site[%s]\n", 
65                  settings->site_name));
66
67         DEBUG(0,("DSA Instance [%s]\n"
68                 "\tobjectGUID[%s]\n"
69                 "\tinvocationId[%s]\n",
70                 settings->ntds_dn_str,
71                 settings->ntds_guid == NULL?"None":GUID_string(mem_ctx, settings->ntds_guid),
72                 settings->invocation_id == NULL?"None":GUID_string(mem_ctx, settings->invocation_id)));
73
74         DEBUG(0,("Pathes under targetdir[%s]\n",
75                  settings->targetdir));
76         parameters = PyDict_New();
77
78         PyDict_SetItemString(parameters, "rootdn", 
79                                                  PyString_FromString(settings->root_dn_str));
80         if (settings->targetdir != NULL)
81                 PyDict_SetItemString(parameters, "targetdir", 
82                                                          PyString_FromString(settings->targetdir));
83         PyDict_SetItemString(parameters, "setup_dir", 
84                              PyString_FromString("setup"));
85         PyDict_SetItemString(parameters, "hostname", 
86                                                  PyString_FromString(settings->netbios_name));
87         PyDict_SetItemString(parameters, "domain", 
88                                                  PyString_FromString(settings->domain));
89         PyDict_SetItemString(parameters, "realm", 
90                                                  PyString_FromString(settings->realm));
91         if (settings->root_dn_str)
92                 PyDict_SetItemString(parameters, "rootdn", 
93                                      PyString_FromString(settings->root_dn_str));
94
95         if (settings->domain_dn_str) 
96                 PyDict_SetItemString(parameters, "domaindn", 
97                                      PyString_FromString(settings->domain_dn_str));
98
99         if (settings->schema_dn_str) 
100                 PyDict_SetItemString(parameters, "schemadn", 
101                                      PyString_FromString(settings->schema_dn_str));
102         
103         if (settings->config_dn_str) 
104                 PyDict_SetItemString(parameters, "configdn", 
105                                      PyString_FromString(settings->config_dn_str));
106         
107         if (settings->server_dn_str) 
108                 PyDict_SetItemString(parameters, "serverdn", 
109                                      PyString_FromString(settings->server_dn_str));
110         
111         if (settings->site_name) 
112                 PyDict_SetItemString(parameters, "sitename", 
113                                      PyString_FromString(settings->site_name));
114
115         PyDict_SetItemString(parameters, "machinepass", 
116                              PyString_FromString(settings->machine_password));
117
118         result = PyEval_CallObjectWithKeywords(provision_fn, NULL, parameters);
119
120         Py_DECREF(parameters);
121
122         if (result == NULL) {
123                 PyErr_Print();
124                 PyErr_Clear();
125                 return NT_STATUS_UNSUCCESSFUL;
126         }
127
128         return NT_STATUS_OK;
129 }