tests: Use --configfile instead of -s
[bbaumbach/samba-autobuild/.git] / source4 / setup / tests / blackbox_start_backup.sh
1 #!/bin/sh
2
3 # Simple test that a DB from a backup file cannot be untarred and started
4 # manually (you have to run the samba-tool 'backup restore' command instead).
5
6 if [ $# -lt 1 ]; then
7 cat <<EOF
8 Usage: $0 PREFIX
9 EOF
10 exit 1;
11 fi
12
13 PREFIX="$1"
14 shift 1
15
16 DBPATH=$PREFIX/start-backup
17 mkdir -p $DBPATH
18
19 . `dirname $0`/../../../testprogs/blackbox/subunit.sh
20
21 do_provision()
22 {
23     $PYTHON $BINDIR/samba-tool domain provision \
24            --domain=FOO --realm=foo.example.com --use-ntvfs \
25            --targetdir=$DBPATH --option="pid directory = $DBPATH"
26 }
27
28 add_backup_marker()
29 {
30 # manually add the backup marker that the backup cmd usually adds
31     $BINDIR/ldbmodify \
32        -H tdb://$DBPATH/private/sam.ldb <<EOF
33 dn: @SAMBA_DSDB
34 changetype: modify
35 add: backupDate
36 backupDate: who-knows-when
37 -
38
39 EOF
40 }
41
42 start_backup()
43 {
44     # start samba in interactive mode (if we don't, samba daemonizes and so the
45     # command's exit status is always zero (success), regardless of whether
46     # samba actually starts up or not). However, this means if this assertion
47     # were ever to fail (i.e. samba DOES startup from a backup file), then the
48     # test case would just hang. So we use a max-run-time of 5 secs so that
49     # samba will self-destruct in the bad case (max_runtime_handler() returns
50     # zero/success in this case, which allows us to tell the good case from the
51     # bad case).
52     OPTS="--maximum-runtime=5 -i"
53
54     # redirect logs to stderr (which we'll then redirect to stdout so we can
55     # capture it in a bash variable)
56     OPTS="$OPTS --debug-stderr"
57
58     # start samba and capture the debug output
59     OUTPUT=$($BINDIR/samba --configfile=$DBPATH/etc/smb.conf $OPTS 2>&1)
60     if [ $? -eq 0 ] ; then
61         echo "ERROR: Samba should not have started successfully"
62         return 1
63     fi
64
65     # check the reason we're failing is because prime_ldb_databases() is
66     # detecting that this is a backup DB (and not some other reason)
67     echo "$OUTPUT" | grep "failed to start: Database is a backup"
68 }
69
70 # setup a DB and manually mark it as being a "backup"
71 testit "provision" do_provision
72 testit "add-backup-marker" add_backup_marker
73
74 # check that Samba won't start using this DB (because it's a backup)
75 testit "start-samba-backup" start_backup
76
77 rm -rf $DBPATH
78
79 exit $failed