s4:gensec/gssapi: use gensec_gssapi_max_{input,wrapped}_size() for all backends
[Samba.git] / python / samba / provision / common.py
blob03e22789515cb338eaebf2c117d8ee56e7793695
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"
30 import os
31 from samba import read_and_sub_file
32 from samba.param import setup_dir
34 FILL_FULL = "FULL"
35 FILL_SUBDOMAIN = "SUBDOMAIN"
36 FILL_NT4SYNC = "NT4SYNC"
37 FILL_DRS = "DRS"
40 def setup_path(file):
41 """Return an absolute path to the provision tempate file specified by file"""
42 return os.path.join(setup_dir(), file)
45 def setup_add_ldif(ldb, ldif_path, subst_vars=None,controls=["relax:0"]):
46 """Setup a ldb in the private dir.
48 :param ldb: LDB file to import data into
49 :param ldif_path: Path of the LDIF file to load
50 :param subst_vars: Optional variables to subsitute in LDIF.
51 :param nocontrols: Optional list of controls, can be None for no controls
52 """
53 assert isinstance(ldif_path, str)
54 data = read_and_sub_file(ldif_path, subst_vars)
55 ldb.add_ldif(data, controls)
58 def setup_modify_ldif(ldb, ldif_path, subst_vars=None,controls=["relax:0"]):
59 """Modify a ldb in the private dir.
61 :param ldb: LDB object.
62 :param ldif_path: LDIF file path.
63 :param subst_vars: Optional dictionary with substitution variables.
64 """
65 data = read_and_sub_file(ldif_path, subst_vars)
66 ldb.modify_ldif(data, controls)
69 def setup_ldb(ldb, ldif_path, subst_vars):
70 """Import a LDIF a file into a LDB handle, optionally substituting
71 variables.
73 :note: Either all LDIF data will be added or none (using transactions).
75 :param ldb: LDB file to import into.
76 :param ldif_path: Path to the LDIF file.
77 :param subst_vars: Dictionary with substitution variables.
78 """
79 assert ldb is not None
80 ldb.transaction_start()
81 try:
82 setup_add_ldif(ldb, ldif_path, subst_vars)
83 except:
84 ldb.transaction_cancel()
85 raise
86 else:
87 ldb.transaction_commit()