summaryrefslogtreecommitdiff
path: root/source4/setup
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2011-08-25 17:20:05 +1000
committerAndrew Bartlett <abartlet@samba.org>2011-08-26 10:06:33 +1000
commitd8465f2a918deb9fb94f4dc5ad85bc07c073bd05 (patch)
tree0a13ff027cf22607c0a3e3b2d672455a9a2fdd5b /source4/setup
parentd2536b31200106ad0bbea60abd3e654c23540e6d (diff)
downloadsamba-d8465f2a918deb9fb94f4dc5ad85bc07c073bd05.tar.gz
samba-d8465f2a918deb9fb94f4dc5ad85bc07c073bd05.tar.bz2
samba-d8465f2a918deb9fb94f4dc5ad85bc07c073bd05.zip
s3_upgrade: Update commandline options and use updated samba3 python module
upgrade_from_s3 script now requires samba3 configuration file and target directory for samba4 database. In addition, it either uses --libdir option or --testparm option to correctly guess the paths for samba3 databases (private dir and state directory). Usage: upgrade_from_s3 [options] <configuration_file> <targetdir> Input arguments are: <configuration_file> - path to existing smb.conf <targetdir> - directory in which samba4 database will be created In addition, specify either samba3 database directory (with --libdir) or samba3 testparm utility (with --testparm). Before using passdb interface, initialize s3 loadparm context using correct path settings for private dir and state directory. Export account policy from s3 to s4. Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/setup')
-rwxr-xr-xsource4/setup/tests/blackbox_s3upgrade.sh4
-rwxr-xr-xsource4/setup/upgrade_from_s383
2 files changed, 65 insertions, 22 deletions
diff --git a/source4/setup/tests/blackbox_s3upgrade.sh b/source4/setup/tests/blackbox_s3upgrade.sh
index 5fa33a3ec6..08ac7900f3 100755
--- a/source4/setup/tests/blackbox_s3upgrade.sh
+++ b/source4/setup/tests/blackbox_s3upgrade.sh
@@ -35,7 +35,7 @@ cat - > $PREFIX/samba3-upgrade/samba3/smb1.conf <<EOF
debug level = 0
EOF
-testit "samba3-upgrade-member" $PYTHON $SRCDIR/source4/setup/upgrade_from_s3 --targetdir=$PREFIX/samba3-upgrade/s4_1 --configfile=$PREFIX/samba3-upgrade/samba3/smb1.conf $PREFIX/samba3-upgrade/samba3
+testit "samba3-upgrade-member" $PYTHON $SRCDIR/source4/setup/upgrade_from_s3 $PREFIX/samba3-upgrade/samba3/smb1.conf $PREFIX/samba3-upgrade/s4_1 --libdir=$PREFIX/samba3-upgrade/samba3
# Test 2 (s3 dc)
cat - > $PREFIX/samba3-upgrade/samba3/smb2.conf <<EOF
@@ -55,7 +55,7 @@ cat - > $PREFIX/samba3-upgrade/samba3/smb2.conf <<EOF
domain logons = yes
EOF
-testit "samba3-upgrade-dc" $PYTHON $SRCDIR/source4/setup/upgrade_from_s3 --targetdir=$PREFIX/samba3-upgrade/s4_2 --configfile=$PREFIX/samba3-upgrade/samba3/smb2.conf $PREFIX/samba3-upgrade/samba3
+testit "samba3-upgrade-dc" $PYTHON $SRCDIR/source4/setup/upgrade_from_s3 $PREFIX/samba3-upgrade/samba3/smb2.conf $PREFIX/samba3-upgrade/s4_2 --libdir=$PREFIX/samba3-upgrade/samba3
rm -rf $PREFIX/samba3-upgrade
diff --git a/source4/setup/upgrade_from_s3 b/source4/setup/upgrade_from_s3
index 6d7862171f..c7a4b97ef4 100755
--- a/source4/setup/upgrade_from_s3
+++ b/source4/setup/upgrade_from_s3
@@ -28,16 +28,57 @@ import samba.getopt as options
from samba.auth import system_session
from samba.upgrade import upgrade_from_samba3
from samba.samba3 import Samba3
-parser = optparse.OptionParser("upgrade_from_s3 [options] <libdir>")
-sambaopts = options.SambaOptions(parser)
-parser.add_option_group(sambaopts)
+from samba.samba3 import param as s3param
+
+def get_testparm_var(testparm, varname):
+ cmd = "%s -s -l --parameter-name='%s' 2>/dev/null" % (testparm, varname)
+ output = os.popen(cmd, 'r').readline()
+ return output.strip()
+
+cmd_help = """upgrade_from_s3 [options] <configuration_file> <targetdir>
+
+Input arguments are:
+ <configuration_file> - path to existing smb.conf
+ <targetdir> - directory in which samba4 database will be created
+
+In addition, specify either samba3 database directory (with --libdir) or
+samba3 testparm utility (with --testparm). """
+
+parser = optparse.OptionParser(cmd_help)
parser.add_option_group(options.VersionOptions(parser))
parser.add_option("--quiet", help="Be quiet")
-parser.add_option("--targetdir", type="string", metavar="DIR",
- help="Set target directory")
+parser.add_option("--libdir", type="string", metavar="DIR",
+ help="samba3 database directory")
+parser.add_option("--testparm", type="string", metavar="PATH",
+ help="samba3 testparm utility")
opts, args = parser.parse_args()
+if len(args) < 2:
+ parser.print_usage()
+ sys.exit(1)
+
+smbconf = args[0]
+if not os.path.exists(smbconf):
+ print("error: %s does not exist" % smbconf)
+ sys.exit(1)
+
+targetdir = args[1]
+if not os.path.isdir(targetdir):
+ print("error: %s is not a directory" % targetdir)
+ sys.exit(1)
+
+libdir = opts.libdir
+testparm = opts.testparm
+
+if not libdir and not testparm:
+ print("error: please specify either libdir or testparm")
+ sys.exit(1)
+
+if libdir and testparm:
+ print("warning: both libdir and testparm specified, libdir will be ignored.")
+ libdir = None
+
logger = logging.getLogger("upgrade")
logger.addHandler(logging.StreamHandler(sys.stdout))
if opts.quiet:
@@ -45,23 +86,25 @@ if opts.quiet:
else:
logger.setLevel(logging.INFO)
-if len(args) < 1:
- parser.print_usage()
- sys.exit(1)
-
-logger.info("Reading Samba3 databases and smb.conf")
+s3conf = s3param.get_context()
+#s3conf.load_default()
-libdir = args[0]
-if not os.path.isdir(libdir):
- print "error: %s is not a directory"
- sys.exit(1)
+# Set correct default values from libdir or testparm
+paths = {}
+if libdir:
+ paths["state directory"] = libdir
+ paths["private dir"] = libdir
+else:
+ paths["state directory"] = get_testparm_var(testparm, "state directory")
+ paths["private dir"] = get_testparm_var(testparm, "private dir")
-lp = sambaopts.get_loadparm()
-smbconf = lp.configfile
+for p in paths:
+ s3conf.set(p, paths[p])
-samba3 = Samba3(libdir, smbconf)
+# load smb.conf parameters
+logger.info("Reading smb.conf")
+s3conf.load(smbconf)
+samba3 = Samba3(smbconf, s3conf)
logger.info("Provisioning")
-
-upgrade_from_samba3(samba3, logger, session_info=system_session(),
- smbconf=smbconf, targetdir=opts.targetdir)
+upgrade_from_samba3(samba3, logger, targetdir, session_info=system_session())