2008-02-15 01:28:31 +03:00
/*
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"
2008-02-15 02:23:56 +03:00
# include "auth/auth.h"
2008-02-15 03:16:12 +03:00
# include "lib/ldb_wrap.h"
2008-03-28 11:40:08 +03:00
# include "libcli/raw/libcliraw.h"
2008-04-02 06:53:27 +04:00
# include "librpc/ndr/libndr.h"
2008-02-15 01:28:31 +03:00
# include "param/param.h"
2008-04-09 05:23:13 +04:00
# include "param/provision.h"
2008-02-15 01:28:31 +03:00
# include <Python.h>
# include "scripting/python/modules.h"
2008-12-19 19:08:35 +03:00
# include "lib/ldb/pyldb.h"
2008-12-22 06:38:57 +03:00
# include "param/pyparam.h"
2008-02-15 01:28:31 +03:00
Make Samba4 pass the NET-API-BECOMEDC test against Win2k3 (again).
To make Samba4, using the python provision system, pass this test
required some major rework. Untested code is broken code, and some of
the refactoring for a seperate provision test (which also now passes)
broke things.
Similarly, the iconv work has compiled, but these codepaths have never
been run (NULL pointer de-reference).
In working to use a local, rather than global, loadparm context, and
to support using a target directory, a few things needed to be
reworked, particularly around path handling.
Andrew Bartlett
(This used to be commit 1169e8d7bee20477b0efbfea3534ac63c83fb3d6)
2008-03-06 13:55:26 +03:00
NTSTATUS provision_bare ( TALLOC_CTX * mem_ctx , struct loadparm_context * lp_ctx ,
2008-04-10 07:23:17 +04:00
struct provision_settings * settings ,
struct provision_result * result )
2008-02-15 01:28:31 +03:00
{
2009-03-04 05:58:07 +03:00
char * configfile ;
2008-04-10 07:23:17 +04:00
PyObject * provision_mod , * provision_dict , * provision_fn , * py_result , * parameters ;
Make Samba4 pass the NET-API-BECOMEDC test against Win2k3 (again).
To make Samba4, using the python provision system, pass this test
required some major rework. Untested code is broken code, and some of
the refactoring for a seperate provision test (which also now passes)
broke things.
Similarly, the iconv work has compiled, but these codepaths have never
been run (NULL pointer de-reference).
In working to use a local, rather than global, loadparm context, and
to support using a target directory, a few things needed to be
reworked, particularly around path handling.
Andrew Bartlett
(This used to be commit 1169e8d7bee20477b0efbfea3534ac63c83fb3d6)
2008-03-06 13:55:26 +03:00
2008-02-15 17:14:55 +03:00
DEBUG ( 0 , ( " Provision for Become-DC test using python \n " ) ) ;
2008-02-15 01:28:31 +03:00
py_load_samba_modules ( ) ;
Py_Initialize ( ) ;
2008-02-15 04:12:37 +03:00
py_update_path ( " bin " ) ; /* FIXME: Can't assume this is always the case */
2008-02-15 01:28:31 +03:00
2008-02-15 04:12:37 +03:00
provision_mod = PyImport_Import ( PyString_FromString ( " samba.provision " ) ) ;
2008-02-15 01:28:31 +03:00
2008-02-15 04:12:37 +03:00
if ( provision_mod = = NULL ) {
PyErr_Print ( ) ;
2008-02-15 01:28:31 +03:00
DEBUG ( 0 , ( " Unable to import provision Python module. \n " ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2008-02-15 04:12:37 +03:00
provision_dict = PyModule_GetDict ( provision_mod ) ;
if ( provision_dict = = NULL ) {
DEBUG ( 0 , ( " Unable to get dictionary for provision module \n " ) ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
Make Samba4 pass the NET-API-BECOMEDC test against Win2k3 (again).
To make Samba4, using the python provision system, pass this test
required some major rework. Untested code is broken code, and some of
the refactoring for a seperate provision test (which also now passes)
broke things.
Similarly, the iconv work has compiled, but these codepaths have never
been run (NULL pointer de-reference).
In working to use a local, rather than global, loadparm context, and
to support using a target directory, a few things needed to be
reworked, particularly around path handling.
Andrew Bartlett
(This used to be commit 1169e8d7bee20477b0efbfea3534ac63c83fb3d6)
2008-03-06 13:55:26 +03:00
provision_fn = PyDict_GetItemString ( provision_dict , " provision_become_dc " ) ;
2008-02-15 04:12:37 +03:00
if ( provision_fn = = NULL ) {
PyErr_Print ( ) ;
Make Samba4 pass the NET-API-BECOMEDC test against Win2k3 (again).
To make Samba4, using the python provision system, pass this test
required some major rework. Untested code is broken code, and some of
the refactoring for a seperate provision test (which also now passes)
broke things.
Similarly, the iconv work has compiled, but these codepaths have never
been run (NULL pointer de-reference).
In working to use a local, rather than global, loadparm context, and
to support using a target directory, a few things needed to be
reworked, particularly around path handling.
Andrew Bartlett
(This used to be commit 1169e8d7bee20477b0efbfea3534ac63c83fb3d6)
2008-03-06 13:55:26 +03:00
DEBUG ( 0 , ( " Unable to get provision_become_dc function \n " ) ) ;
2008-02-15 04:12:37 +03:00
return NT_STATUS_UNSUCCESSFUL ;
}
2008-02-15 01:28:31 +03:00
2008-04-09 08:55:01 +04:00
DEBUG ( 0 , ( " New Server in Site[%s] \n " ,
settings - > site_name ) ) ;
2008-02-15 01:28:31 +03:00
DEBUG ( 0 , ( " DSA Instance [%s] \n "
" \t invocationId[%s] \n " ,
2008-02-15 17:14:55 +03:00
settings - > ntds_dn_str ,
settings - > invocation_id = = NULL ? " None " : GUID_string ( mem_ctx , settings - > invocation_id ) ) ) ;
2008-02-15 01:28:31 +03:00
Make Samba4 pass the NET-API-BECOMEDC test against Win2k3 (again).
To make Samba4, using the python provision system, pass this test
required some major rework. Untested code is broken code, and some of
the refactoring for a seperate provision test (which also now passes)
broke things.
Similarly, the iconv work has compiled, but these codepaths have never
been run (NULL pointer de-reference).
In working to use a local, rather than global, loadparm context, and
to support using a target directory, a few things needed to be
reworked, particularly around path handling.
Andrew Bartlett
(This used to be commit 1169e8d7bee20477b0efbfea3534ac63c83fb3d6)
2008-03-06 13:55:26 +03:00
DEBUG ( 0 , ( " Pathes under targetdir[%s] \n " ,
settings - > targetdir ) ) ;
2008-02-15 01:28:31 +03:00
parameters = PyDict_New ( ) ;
2009-03-04 05:58:07 +03:00
configfile = lp_configfile ( lp_ctx ) ;
if ( configfile ! = NULL ) {
PyDict_SetItemString ( parameters , " smbconf " ,
PyString_FromString ( configfile ) ) ;
}
2008-04-14 18:01:15 +04:00
2008-02-15 17:14:55 +03:00
PyDict_SetItemString ( parameters , " rootdn " ,
PyString_FromString ( settings - > root_dn_str ) ) ;
Make Samba4 pass the NET-API-BECOMEDC test against Win2k3 (again).
To make Samba4, using the python provision system, pass this test
required some major rework. Untested code is broken code, and some of
the refactoring for a seperate provision test (which also now passes)
broke things.
Similarly, the iconv work has compiled, but these codepaths have never
been run (NULL pointer de-reference).
In working to use a local, rather than global, loadparm context, and
to support using a target directory, a few things needed to be
reworked, particularly around path handling.
Andrew Bartlett
(This used to be commit 1169e8d7bee20477b0efbfea3534ac63c83fb3d6)
2008-03-06 13:55:26 +03:00
if ( settings - > targetdir ! = NULL )
PyDict_SetItemString ( parameters , " targetdir " ,
PyString_FromString ( settings - > targetdir ) ) ;
PyDict_SetItemString ( parameters , " setup_dir " ,
PyString_FromString ( " setup " ) ) ;
2008-02-15 17:14:55 +03:00
PyDict_SetItemString ( parameters , " hostname " ,
PyString_FromString ( settings - > netbios_name ) ) ;
Make Samba4 pass the NET-API-BECOMEDC test against Win2k3 (again).
To make Samba4, using the python provision system, pass this test
required some major rework. Untested code is broken code, and some of
the refactoring for a seperate provision test (which also now passes)
broke things.
Similarly, the iconv work has compiled, but these codepaths have never
been run (NULL pointer de-reference).
In working to use a local, rather than global, loadparm context, and
to support using a target directory, a few things needed to be
reworked, particularly around path handling.
Andrew Bartlett
(This used to be commit 1169e8d7bee20477b0efbfea3534ac63c83fb3d6)
2008-03-06 13:55:26 +03:00
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 ) ) ;
2008-04-04 05:55:45 +04:00
if ( settings - > server_dn_str )
PyDict_SetItemString ( parameters , " serverdn " ,
PyString_FromString ( settings - > server_dn_str ) ) ;
Make Samba4 pass the NET-API-BECOMEDC test against Win2k3 (again).
To make Samba4, using the python provision system, pass this test
required some major rework. Untested code is broken code, and some of
the refactoring for a seperate provision test (which also now passes)
broke things.
Similarly, the iconv work has compiled, but these codepaths have never
been run (NULL pointer de-reference).
In working to use a local, rather than global, loadparm context, and
to support using a target directory, a few things needed to be
reworked, particularly around path handling.
Andrew Bartlett
(This used to be commit 1169e8d7bee20477b0efbfea3534ac63c83fb3d6)
2008-03-06 13:55:26 +03:00
if ( settings - > site_name )
PyDict_SetItemString ( parameters , " sitename " ,
PyString_FromString ( settings - > site_name ) ) ;
2008-02-15 17:14:55 +03:00
PyDict_SetItemString ( parameters , " machinepass " ,
Make Samba4 pass the NET-API-BECOMEDC test against Win2k3 (again).
To make Samba4, using the python provision system, pass this test
required some major rework. Untested code is broken code, and some of
the refactoring for a seperate provision test (which also now passes)
broke things.
Similarly, the iconv work has compiled, but these codepaths have never
been run (NULL pointer de-reference).
In working to use a local, rather than global, loadparm context, and
to support using a target directory, a few things needed to be
reworked, particularly around path handling.
Andrew Bartlett
(This used to be commit 1169e8d7bee20477b0efbfea3534ac63c83fb3d6)
2008-03-06 13:55:26 +03:00
PyString_FromString ( settings - > machine_password ) ) ;
2008-02-15 01:28:31 +03:00
2008-04-10 07:23:17 +04:00
py_result = PyEval_CallObjectWithKeywords ( provision_fn , NULL , parameters ) ;
2008-02-15 01:28:31 +03:00
Py_DECREF ( parameters ) ;
2008-04-10 07:23:17 +04:00
if ( py_result = = NULL ) {
2008-02-15 01:28:31 +03:00
PyErr_Print ( ) ;
PyErr_Clear ( ) ;
return NT_STATUS_UNSUCCESSFUL ;
}
2008-04-10 07:23:17 +04:00
result - > domaindn = talloc_strdup ( mem_ctx , PyString_AsString ( PyObject_GetAttrString ( py_result , " domaindn " ) ) ) ;
2008-04-11 02:43:23 +04:00
/* FIXME paths */
result - > lp_ctx = lp_from_py_object ( PyObject_GetAttrString ( py_result , " lp " ) ) ;
2008-12-19 19:08:35 +03:00
result - > samdb = PyLdb_AsLdbContext ( PyObject_GetAttrString ( py_result , " samdb " ) ) ;
2008-04-11 02:43:23 +04:00
2008-02-15 01:28:31 +03:00
return NT_STATUS_OK ;
}