2 # Unix SMB/CIFS implementation.
3 # utility functions for provisioning a Samba4 server
5 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2010
6 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008-2009
7 # Copyright (C) Oliver Liebel <oliver@itc.li> 2008-2009
9 # Based on the original in EJS:
10 # Copyright (C) Andrew Tridgell <tridge@samba.org> 2005
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 """Functions for setting up a Samba configuration."""
28 __docformat__
= "restructuredText"
31 from samba
import read_and_sub_file
32 from samba
.param
import setup_dir
36 """Return an absolute path to the provision tempate file specified by file"""
37 return os
.path
.join(setup_dir(), file)
40 def setup_add_ldif(ldb
, ldif_path
, subst_vars
=None,controls
=["relax:0"]):
41 """Setup a ldb in the private dir.
43 :param ldb: LDB file to import data into
44 :param ldif_path: Path of the LDIF file to load
45 :param subst_vars: Optional variables to subsitute in LDIF.
46 :param nocontrols: Optional list of controls, can be None for no controls
48 assert isinstance(ldif_path
, str)
49 data
= read_and_sub_file(ldif_path
, subst_vars
)
50 ldb
.add_ldif(data
, controls
)
53 def setup_modify_ldif(ldb
, ldif_path
, subst_vars
=None,controls
=["relax:0"]):
54 """Modify a ldb in the private dir.
56 :param ldb: LDB object.
57 :param ldif_path: LDIF file path.
58 :param subst_vars: Optional dictionary with substitution variables.
60 data
= read_and_sub_file(ldif_path
, subst_vars
)
61 ldb
.modify_ldif(data
, controls
)
64 def setup_ldb(ldb
, ldif_path
, subst_vars
):
65 """Import a LDIF a file into a LDB handle, optionally substituting
68 :note: Either all LDIF data will be added or none (using transactions).
70 :param ldb: LDB file to import into.
71 :param ldif_path: Path to the LDIF file.
72 :param subst_vars: Dictionary with substitution variables.
74 assert ldb
is not None
75 ldb
.transaction_start()
77 setup_add_ldif(ldb
, ldif_path
, subst_vars
)
79 ldb
.transaction_cancel()
82 ldb
.transaction_commit()