1#!/bin/sh 2# 3# 4TestName="allowed-jobcommand-test" 5JobName=BackupClient1 6. scripts/functions 7 8scripts/cleanup 9scripts/copy-test-confs 10 11 12# create the run before job script 13echo "#!/bin/sh 14echo allowed job command: runbeforejob 15" > $working/runbeforejob.sh 16chmod +x $working/runbeforejob.sh 17 18rm -f bin/bareos-dir.conf 19/bin/cp -f ${rconfigs}/${TestName}/bareos-dir.conf.allowed-jobcommand-test bin/bareos-dir.conf 20/bin/cp -f ${rconfigs}/${TestName}/bareos-fd.conf.allowed-jobcommand-test bin/bareos-fd.conf 21/bin/cp -f ${rconfigs}/${TestName}/bareos-fd.conf.allowed-jobcommand-test bin/bareos-fd.conf.orig 22 23# create test data 24dd if=/dev/zero of=${cwd}/tmp/testdata bs=400k count=1 25 26echo "${cwd}/tmp/testdata" >${cwd}/tmp/file-list 27 28cp ${cwd}/tmp/file-list ${cwd}/tmp/restore-list 29 30 31start_test 32 33cat >${cwd}/tmp/bconcmds <<END_OF_DATA 34messages 35@$out ${cwd}/tmp/backup.log 36label storage=File volume=TestVolume001 37run job=$JobName Level=Full yes 38wait 39messages 40 41@$out ${cwd}/tmp/estimate.log 42estimate job=$JobName yes 43wait 44messages 45 46@$out ${cwd}/tmp/restore.log 47restore where=${cwd}/tmp/bareos-restores storage=File 487 49<${cwd}/tmp/restore-list 50 51yes 52wait 53messages 54 55END_OF_DATA 56 57run_bareos 58#check_for_zombie_jobs storage=File 59stop_bareos 60 61 62grep "Termination: Backup OK" ${tmp}/backup.log 2>&1 >/dev/null 63if test $? -eq 0; then 64 print_debug "Backup was OK" 65else 66 estat=1 67fi 68 69grep "2000 OK estimate files=1 bytes=" ${tmp}/estimate.log 2>&1 >/dev/null 70if test $? -eq 0; then 71 print_debug "estimate OK" 72else 73 estat=2 74fi 75 76grep "Termination: Restore OK" ${tmp}/restore.log 2>&1 >/dev/null 77if test $? -eq 0; then 78 print_debug "Restore OK" 79else 80 estat=3 81fi 82 83 84 85 86 87# remove the runscript command from allowed commands 88sed 's@Allowed Job Command = runscript@# Allowed Job Command = runscript@g' >bin/bareos-fd.conf <bin/bareos-fd.conf.orig 89 90# retry to run backup, estimate and restore 91 92cat >${cwd}/tmp/bconcmds <<END_OF_DATA 93messages 94@$out ${cwd}/tmp/backup2.log 95run job=$JobName Level=Full yes 96wait 97messages 98 99@$out ${cwd}/tmp/estimate2.log 100estimate job=$JobName yes 101wait 102messages 103 104@$out ${cwd}/tmp/restore2.log 105restore where=${cwd}/tmp/bareos-restores storage=File 1067 107<${cwd}/tmp/restore-list 108 109yes 110wait 111messages 112 113END_OF_DATA 114 115run_bareos 116#check_for_zombie_jobs storage=File 117stop_bareos 118 119 120grep "Fatal error: Illegal runscript command not allowed " ${tmp}/backup2.log 2>&1 >/dev/null 121if test $? -eq 0; then 122 print_debug "runscript was blocked : OK" 123else 124 estat=4 125fi 126 127grep "2000 OK estimate files=1 bytes=" ${tmp}/estimate2.log 2>&1 >/dev/null 128if test $? -eq 0; then 129 print_debug "estimate OK" 130else 131 estat=5 132fi 133 134grep "Termination: Restore OK" ${tmp}/restore2.log 2>&1 >/dev/null 135if test $? -eq 0; then 136 print_debug "Restore OK" 137else 138 estat=6 139fi 140 141 142 143 144# remove the estimate command from allowed commands 145sed 's@Allowed Job Command = estimate@# Allowed Job Command = estimate@g' >bin/bareos-fd.conf <bin/bareos-fd.conf.orig 146 147# retry to run backup, estimate and restore 148 149cat >${cwd}/tmp/bconcmds <<END_OF_DATA 150messages 151@$out ${cwd}/tmp/backup3.log 152run job=$JobName Level=Full yes 153wait 154messages 155 156@$out ${cwd}/tmp/estimate3.log 157estimate job=$JobName yes 158wait 159messages 160 161@$out ${cwd}/tmp/restore3.log 162restore where=${cwd}/tmp/bareos-restores storage=File 1637 164<${cwd}/tmp/restore-list 165 166yes 167wait 168messages 169 170END_OF_DATA 171 172run_bareos 173#check_for_zombie_jobs storage=File 174stop_bareos 175 176grep "Termination: Backup OK" ${tmp}/backup3.log 2>&1 >/dev/null 177if test $? -eq 0; then 178 print_debug "Backup was OK" 179else 180 estat=7 181fi 182 183 184grep "Illegal estimate command not allowed by Allowed Job Cmds setting of this filed." ${tmp}/estimate3.log 2>&1 >/dev/null 185if test $? -eq 0; then 186 print_debug "estimate blocked : OK" 187else 188 estat=8 189fi 190 191grep "Termination: Restore OK" ${tmp}/restore3.log 2>&1 >/dev/null 192if test $? -eq 0; then 193 print_debug "Restore OK" 194else 195 estat=9 196fi 197 198 199 200 201 202 203 204# remove the restore command from allowed commands 205sed 's@Allowed Job Command = restore@# Allowed Job Command = restore@g' >bin/bareos-fd.conf <bin/bareos-fd.conf.orig 206 207# retry to run backup, estimate and restore 208 209cat >${cwd}/tmp/bconcmds <<END_OF_DATA 210messages 211@$out ${cwd}/tmp/backup4.log 212run job=$JobName Level=Full yes 213wait 214messages 215 216@$out ${cwd}/tmp/estimate4.log 217estimate job=$JobName yes 218wait 219messages 220 221@$out ${cwd}/tmp/restore4.log 222restore where=${cwd}/tmp/bareos-restores storage=File 2237 224<${cwd}/tmp/restore-list 225 226yes 227wait 228messages 229 230END_OF_DATA 231 232run_bareos 233#check_for_zombie_jobs storage=File 234stop_bareos 235 236grep "Termination: Backup OK" ${tmp}/backup4.log 2>&1 >/dev/null 237if test $? -eq 0; then 238 print_debug "Backup was OK" 239else 240 estat=10 241fi 242 243grep "2000 OK estimate files=1 bytes=" ${tmp}/estimate4.log 2>&1 >/dev/null 244if test $? -eq 0; then 245 print_debug "estimate OK" 246else 247 estat=11 248fi 249 250grep "Fatal error: Illegal \"restore\" command not allowed by Allowed Job Cmds setting of this filed." ${tmp}/restore4.log 2>&1 >/dev/null 251if test $? -eq 0; then 252 print_debug "Restore Blocked: OK" 253else 254 estat=12 255fi 256 257end_test 258