4 # Copyright Jelmer Vernooij 2005-2007
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.
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.
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/>.
24 # Find right directory when running from source tree
25 sys
.path
.insert(0, "bin/python")
28 import samba
.getopt
as options
29 from samba
.auth
import system_session
30 from samba
.upgrade
import upgrade_from_samba3
31 from samba
.samba3
import Samba3
32 from samba
.samba3
import param
as s3param
33 from samba
.provision
import ProvisioningError
35 def get_testparm_var(testparm
, varname
):
36 cmd
= "%s -s -l --parameter-name='%s' 2>/dev/null" % (testparm
, varname
)
37 output
= os
.popen(cmd
, 'r').readline()
40 cmd_help
= """upgrade_from_s3 [options] <configuration_file> <targetdir>
43 <configuration_file> - path to existing smb.conf
44 <targetdir> - directory in which samba4 database will be created
46 In addition, specify either samba3 database directory (with --libdir) or
47 samba3 testparm utility (with --testparm). """
49 parser
= optparse
.OptionParser(cmd_help
)
50 parser
.add_option_group(options
.VersionOptions(parser
))
51 parser
.add_option("--quiet", help="Be quiet")
52 parser
.add_option("--libdir", type="string", metavar
="DIR",
53 help="samba3 database directory")
54 parser
.add_option("--testparm", type="string", metavar
="PATH",
55 help="samba3 testparm utility")
56 parser
.add_option("--use-xattrs", type="choice", choices
=["yes","no","auto"], help="Define if we should use the native fs capabilities or a tdb file for storing attributes likes ntacl, auto tries to make an inteligent guess based on the user rights and system capabilities", default
="auto")
58 opts
, args
= parser
.parse_args()
65 if not os
.path
.exists(smbconf
):
66 print("error: %s does not exist" % smbconf
)
70 if not os
.path
.isdir(targetdir
):
71 print("error: %s is not a directory" % targetdir
)
75 testparm
= opts
.testparm
77 if not libdir
and not testparm
:
78 print("error: please specify either libdir or testparm")
81 if libdir
and testparm
:
82 print("warning: both libdir and testparm specified, libdir will be ignored.")
85 logger
= logging
.getLogger("upgrade")
86 logger
.addHandler(logging
.StreamHandler(sys
.stdout
))
88 logger
.setLevel(logging
.WARNING
)
90 logger
.setLevel(logging
.INFO
)
92 s3conf
= s3param
.get_context()
95 if opts
.use_xattrs
== "yes":
97 elif opts
.use_xattrs
== "auto" and not s3conf
.get("posix:eadb"):
98 file = tempfile
.NamedTemporaryFile()
100 samba
.ntacls
.setntacl(lp
, file.name
,
101 "O:S-1-5-32G:S-1-5-32", "S-1-5-32", "native")
104 logger
.info("You are not root or your system do not support xattr, using tdb backend for attributes. "
105 "If you intend to use this provision in production, rerun the script as root on a system supporting xattrs.")
108 # Set correct default values from libdir or testparm
111 paths
["state directory"] = libdir
112 paths
["private dir"] = libdir
113 paths
["lock directory"] = libdir
115 paths
["state directory"] = get_testparm_var(testparm
, "state directory")
116 paths
["private dir"] = get_testparm_var(testparm
, "private dir")
117 paths
["lock directory"] = get_testparm_var(testparm
, "lock directory")
120 s3conf
.set(p
, paths
[p
])
122 # load smb.conf parameters
123 logger
.info("Reading smb.conf")
125 samba3
= Samba3(smbconf
, s3conf
)
127 logger
.info("Provisioning")
129 upgrade_from_samba3(samba3
, logger
, targetdir
, session_info
=system_session(), useeadb
=eadb
)
130 except ProvisioningError
, e
: