The branch, master has been updated via 1c818d6 test_smbclient_tarmode.pl: remove unneccesary arg defaults via 1424c61 test_smbclient_tarmode.pl: depend only on perl v5.10 via 2ceda6a test_smbclient_tarmode.pl: remove all ./ prefix when dealing with remote files via 7088302 test_smbclient_tarmode.pl: sanitize $DIR + whitespace via 977c26d test_smbclient_tarmode.pl: use -n flag for specifiying hostname (was ambiguous with help) via f637463 test_smbclient_tarmode.pl: enable create with exclude tests via 743593a test_smbclient_tarmode.pl: add subunit output flag via 0ebc84a test_smbclient_tarmode.pl: add test for interactive session via e236d5d test_smbclient_tarmode.pl: add extraction regex tests, verbose flag via 24067dc test_smbclient_tarmode.pl: test regex flag behaviour via 4eecb46 test_smbclient_tarmode.pl: add large file and long path tests via bd4cde8 test_smbclient_tarmode.pl: add simple wildcard test via f77f63e test_smbclient_tarmode.pl: test interactive command via 70e8053 test_smbclient_tarmode.pl: whitespace via 363601e test_smbclient_tarmode.pl: let --test run multiple tests via 45bee99 test_smbclient_tarmode.pl: sanitize input, use File::Temp instead of hardcoding temp dir via 2f30482 test_smbclient_tarmode.pl: cosmetic changes via 8540032 test_smbclient_tarmode.pl: add copyright header via 98fa4bc test_smbclient_tarmode.pl: samba 3.6.9 can print a empty attribute string via 03e1557 test_smbclient_tarmode.pl: disable failing tests for now via 97c34f3 test_smbclient_tarmode.pl: make script work on older Perl (now only need 5.14) via e879580 test_smbclient_tarmode.pl: fix a few minor typos via bfd6b7b test_smbclient_tarmode.pl: refactor, cleanup and document in POD via 60edcc7 test_smbclient_tarmode.pl: add tests for wildcard pattern (cI, cX, cF, xF). via 581d128 test_smbclient_tarmode.pl: add a first simple wildcard test via a8b1d58 test_smbclient_tarmode.pl: add a clean option to erase the local path via ea04ae3 test_smbclient_tarmode.pl: add test for xF via aaf59c9 test_smbclient_tarmode.pl: add test for creation w/ filelist via fa067e8 test_smbclient_tarmode.pl: add extraction test for I and X. via f764c39 test_smbclient_tarmode.pl: add tests for X and I. via 3a10b88 test_smbclient_tarmode.pl: add option to choose and run a single test via cb08034 test_smbclient_tarmode.pl: add first extraction test via c5ae61f test_smbclient_tarmode.pl: remove unused functions via d07d89a test_smbclient_tarmode.pl: add nested dirs test via 1624382 test_smbclient_tarmode.pl: refactored file related function to a File package via e70b6de test_smbclient_tarmode.pl: add test for "newer than" (`N` flag) via 2ef7909 test_smbclient_tarmode.pl: add test for reset mode via be54395 test_smbclient_tarmode.pl: improve incremental test via 947775e test_smbclient_tarmode.pl: add proper argument parsing for configuration. via f5325f5 initial commit of the new tarmode test script. from 6588215 Add regression test for bug #10229 - No access check verification on stream files.
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 1c818d6927549a1e0f18ea9a9810dc6de97d5cd1 Author: David Disseldorp <dd...@samba.org> Date: Tue Oct 29 12:08:57 2013 +0100 test_smbclient_tarmode.pl: remove unneccesary arg defaults The host, share and localpath arguments should not take default values. Check that these required arguments are specified. Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> Autobuild-User(master): Jim McDonough <j...@samba.org> Autobuild-Date(master): Tue Nov 5 16:40:20 CET 2013 on sn-devel-104 commit 1424c61a1a42abd34d71b0b48ea56be4b7fe5a9c Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Aug 12 16:29:41 2013 +0200 test_smbclient_tarmode.pl: depend only on perl v5.10 Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 2ceda6a730f7c9354cd6ac80f755992cc2a1d3e4 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Aug 5 18:58:39 2013 +0200 test_smbclient_tarmode.pl: remove all ./ prefix when dealing with remote files Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 7088302d2469a0191f7b3e7d396575e7f688dde3 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Aug 5 18:57:54 2013 +0200 test_smbclient_tarmode.pl: sanitize $DIR + whitespace Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 977c26d8b0e978ac27273161c87918b467fe8672 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Aug 5 18:56:04 2013 +0200 test_smbclient_tarmode.pl: use -n flag for specifiying hostname (was ambiguous with help) Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit f637463edd486fc2244ae9354f8fd7773cdceb5c Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Oct 28 18:07:25 2013 +0100 test_smbclient_tarmode.pl: enable create with exclude tests [dd...@samba.org: split from clitar implementation commit] Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 743593a6dfee139ea79ab89ad37654c2e298cd22 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Aug 5 18:55:25 2013 +0200 test_smbclient_tarmode.pl: add subunit output flag Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 0ebc84ad6daafb5ceb73553e5c569d26274a41fb Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Wed Jul 24 16:49:06 2013 +0200 test_smbclient_tarmode.pl: add test for interactive session Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit e236d5df132842974b2e8b5b244aa0896dcc56cf Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Jul 22 18:49:51 2013 +0200 test_smbclient_tarmode.pl: add extraction regex tests, verbose flag * reset_remote() now removes the whole share content * verbose flag to control stdout of each test * extraction with regex test Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 24067dc243e189ea9d25465105bfe67f852f35f7 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Fri Oct 25 15:12:27 2013 +0200 test_smbclient_tarmode.pl: test regex flag behaviour [dd...@samba.org: split from clitar implementation commit] Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 4eecb46bcec8e093990b4b4a4397e4aba048ad55 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Wed Jul 17 18:54:07 2013 +0200 test_smbclient_tarmode.pl: add large file and long path tests Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit bd4cde803cb1c5941053e3e5b6310b6d218c1825 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Wed Jul 17 16:27:01 2013 +0200 test_smbclient_tarmode.pl: add simple wildcard test Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit f77f63ed285fb4895a80c70f41ddc32b4e56bc6b Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Fri Oct 25 14:55:47 2013 +0200 test_smbclient_tarmode.pl: test interactive command [dd...@samba.org: split from clitar implementation commit] Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 70e80532b0a2646a91a042f077af7098d7f54ebf Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Tue Jul 16 15:52:51 2013 +0200 test_smbclient_tarmode.pl: whitespace Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 363601e277b71131bbd4fa0169d6fc7424c5ce04 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Tue Jul 16 14:46:02 2013 +0200 test_smbclient_tarmode.pl: let --test run multiple tests Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 45bee9901b94e68b86ff50f0e0629522d5b5800a Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Tue Jul 16 00:34:41 2013 +0200 test_smbclient_tarmode.pl: sanitize input, use File::Temp instead of hardcoding temp dir Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 2f30482e7bb94a1ceb96d337b304bc3eadcd6a45 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Tue Jul 16 00:10:09 2013 +0200 test_smbclient_tarmode.pl: cosmetic changes - Add whitespace around paren in if/for/while/... blocks - Don't split if/elsif/else cascade Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 85400325276b37d4e3086bbfc8190d27f52d5671 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Jul 15 23:41:15 2013 +0200 test_smbclient_tarmode.pl: add copyright header Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 98fa4bc03e52368d3542ceb408a26af54f815989 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Jul 15 19:04:43 2013 +0200 test_smbclient_tarmode.pl: samba 3.6.9 can print a empty attribute string While changing my setup, I discovered that for some unknown reasons samba (serv/client) doesn't print any attributes for normal files. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 03e155772877d03b9cde8a54fcd8492231cb2b77 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Jul 15 19:04:07 2013 +0200 test_smbclient_tarmode.pl: disable failing tests for now Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 97c34f3e6f2a954a267624c9059de35d74e7c3dc Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Jul 15 19:01:58 2013 +0200 test_smbclient_tarmode.pl: make script work on older Perl (now only need 5.14) Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit e879580f1cfd73fa62036316485cd30d011b8392 Author: David Disseldorp <dd...@samba.org> Date: Sun Jul 14 15:22:36 2013 +0200 test_smbclient_tarmode.pl: fix a few minor typos Signed-off-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit bfd6b7bf096b1c29890e0c83ac9db90118191690 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Thu Jul 4 17:54:43 2013 +0200 test_smbclient_tarmode.pl: refactor, cleanup and document in POD Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 60edcc790510b4c14044dd96a00dbe7368dfdc6f Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Wed Jul 3 16:09:03 2013 +0200 test_smbclient_tarmode.pl: add tests for wildcard pattern (cI, cX, cF, xF). * add some test for wildcard pattern and r switch, when possible (-r is very buggy) * change default DIR to "tar_test_dir" * add tests for attributes (nohidden, nosystem which are undocumented) Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 581d128ef3369868d82388fa8d6cd68d92127f53 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Tue Jul 2 23:22:24 2013 +0200 test_smbclient_tarmode.pl: add a first simple wildcard test * File::list() now takes an absolute path * check_remote() now takes the dir to check * added an optional File destructor * added cleanpath() to remove unecessary slashes * File::new_remote() can take an absolute path * File->{dir} is now absolute from the localpath Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit a8b1d58edb2e59d6dd90b528cb6e142ce127458f Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Tue Jul 2 23:20:53 2013 +0200 test_smbclient_tarmode.pl: add a clean option to erase the local path Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit ea04ae30e12ef13b7fe49db7975e042095184321 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Tue Jul 2 11:16:13 2013 +0200 test_smbclient_tarmode.pl: add test for xF Add test for extracting from a file list. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit aaf59c9db6e571b8d05f0e62a717be995c16285f Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Jul 1 18:01:50 2013 +0200 test_smbclient_tarmode.pl: add test for creation w/ filelist * add test_creation_list() * add parameter to File::new_local() to provide file content Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit fa067e8e2d469fcead649cf8a761e5c66f0768e5 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Jul 1 17:44:54 2013 +0200 test_smbclient_tarmode.pl: add extraction test for I and X. * add test for xI and xX * fix bug in check_remote(): print filename instead of ref * replace hash by list in test_extraction_normal() Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit f764c39a59551ef5ac849b8f3012a28953c7ee8a Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Mon Jul 1 17:25:29 2013 +0200 test_smbclient_tarmode.pl: add tests for X and I. Found a bug while doing so. X doesn't exclude file path. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 3a10b8803a0e2d4238d01926cb9226d5969852a2 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Fri Jun 28 18:36:22 2013 +0200 test_smbclient_tarmode.pl: add option to choose and run a single test Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit cb0803444a1f932ea1e422984678da6b7948adb6 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Fri Jun 28 18:10:56 2013 +0200 test_smbclient_tarmode.pl: add first extraction test * add normal extraction test * add (or bring back) - File::list() -- return list of File in a path - File::tree() -- same but recursive - File::walk() -- high order function to iterate on a File hierarchy * compute md5 sum when not cached * add check_remote(), will be useful for all extraction tests * fix consecutive slashes bug in some File::xxxpath() At this point, the script can replace the old test_smbclient_tarmode.sh in terms of features. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit c5ae61f3eb44b7b7b7743e798a41e5a985d349a4 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Fri Jun 28 03:35:21 2013 +0200 test_smbclient_tarmode.pl: remove unused functions Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit d07d89a11e21e51ec92a1743fb7e54a823ce4453 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Fri Jun 28 03:30:06 2013 +0200 test_smbclient_tarmode.pl: add nested dirs test add a test to check that the backup handles nested directories. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 1624382c98aa563ff1b44da66c31a2867949d129 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Fri Jun 28 03:16:29 2013 +0200 test_smbclient_tarmode.pl: refactored file related function to a File package all the localpath(), remotepath() and all file related functions were getting out of hand. The tests are now simpler to write. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit e70b6dead7ae52ce12f7534221a8fcee4651c89e Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Thu Jun 27 20:30:44 2013 +0200 test_smbclient_tarmode.pl: add test for "newer than" (`N` flag) add test for the N FILE flag which makes smbclient only backup files newer or as new as FILE. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 2ef7909dd0db75db64a611c57b33f103be07a940 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Thu Jun 27 18:53:34 2013 +0200 test_smbclient_tarmode.pl: add test for reset mode add a new test for the reset mode which can be triggered via `-a` or `tarmode reset`. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit be54395832f9c79180a2228c5d7099ddae0fa37f Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Thu Jun 27 15:07:42 2013 +0200 test_smbclient_tarmode.pl: improve incremental test instead of using archived and non-archived files for the test, use archive and various flags (system, hidden, readonly). Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit 947775ee00632a67b8b088a544bc3474b7e2f8df Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Thu Jun 27 15:00:24 2013 +0200 test_smbclient_tarmode.pl: add proper argument parsing for configuration. documentation is included in the script in POD format. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> commit f5325f5e3e1c825e8b5415d2e17ab703ec5fab40 Author: Aurélien Aptel <aurelien.ap...@gmail.com> Date: Wed Jun 26 20:41:22 2013 +0200 initial commit of the new tarmode test script. This script will hopefully replace and improve test_smbclient_tarmode.sh. Right now it only does normal and incremental tests. Signed-off-by: Aurélien Aptel <aurelien.ap...@gmail.com> Reviewed-by: David Disseldorp <dd...@samba.org> Reviewed-by: Jim McDonough <j...@samba.org> ----------------------------------------------------------------------- Summary of changes: source3/script/tests/test_smbclient_tarmode.pl | 1675 ++++++++++++++++++++++++ 1 files changed, 1675 insertions(+), 0 deletions(-) create mode 100755 source3/script/tests/test_smbclient_tarmode.pl Changeset truncated at 500 lines: diff --git a/source3/script/tests/test_smbclient_tarmode.pl b/source3/script/tests/test_smbclient_tarmode.pl new file mode 100755 index 0000000..663f02f --- /dev/null +++ b/source3/script/tests/test_smbclient_tarmode.pl @@ -0,0 +1,1675 @@ +#!/usr/bin/perl + +# Unix SMB/CIFS implementation. +# Test suite for the tar backup mode of smbclient. +# Copyright (C) Aurélien Aptel 2013 + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +=head1 NAME + +C<test_smbclient_tarmode.pl> - Test for smbclient tar backup feature + +=cut + +use v5.10; +use strict; +use warnings; + +use Archive::Tar; +use Data::Dumper; +use Digest::MD5 qw/md5_hex/; +use File::Path qw/make_path remove_tree/; +use File::Spec; +use File::Temp; +use Getopt::Long; +use Pod::Usage; +use Term::ANSIColor; + +sub d {print Dumper @_;} + +# DEFAULTS +# 'our' to make them available in the File package +our $USER = ''; +our $PW = ''; +our $HOST = ''; +our $IP = ''; +our $SHARE = ''; +our $DIR = 'tar_test_dir'; +our $LOCALPATH = ''; +our $TMP = File::Temp->newdir(); +our $BIN = 'smbclient'; +our $SUBUNIT = 0; + +my $SELECTED_TEST = ''; +my $LIST_TEST = 0; + +my @SMBARGS = (); + +our $DEBUG = 0; +our $VERBOSE = 0; +my $MAN = 0; +my $HELP = 0; +my $CLEAN = 0; + +# all tests +my @TESTS = ( +# ['test helper', \&test_helper], + ['create, normal files (no attributes)', \&test_creation_normal, 'normal'], + ['create, normal nested files (no attributes)', \&test_creation_normal, 'nested'], + ['create, normal files (interactive)', \&test_creation_normal, 'inter'], + ['create, large file', \&test_creation_large_file], + ['create, long path', \&test_creation_long_path], + ['create, incremental with -g', \&test_creation_incremental, '-g'], + ['create, incremental with tarmode', \&test_creation_incremental, 'tarmode inc'], + ['create, reset archived files with -a', \&test_creation_reset, '-a'], + ['create, reset archived files with tarmode', \&test_creation_reset, 'tarmode reset'], + ['create, files newer than a file', \&test_creation_newer], + ['create, combination of tarmode filter', \&test_creation_attr], + ['create, explicit include', \&test_creation_include], + ['create, explicit exclude', \&test_creation_exclude], + ['create, include w/ filelist (F)', \&test_creation_list], + ['create, wildcard simple', \&test_creation_wildcard_simple], + ['create, regex', \&test_creation_regex], + ['create, multiple backup in session', \&test_creation_multiple], + ['extract, normal files', \&test_extraction_normal], + ['extract, explicit include', \&test_extraction_include], + ['extract, explicit exclude', \&test_extraction_exclude], + ['extract, include w/ filelist (F)', \&test_extraction_list], + ['extract, regex', \&test_extraction_regex], +); + +=head1 SYNOPSIS + + test_smbclient_tarmode.pl [options] -- [smbclient options] + + Options: + -h, --help brief help message + --man full documentation + + Environment: + -u, --user USER + -p, --password PW + -n, --name HOST (required) + -i, --ip IP + -s, --share SHARE (required) + -d, --dir PATH + sub-path to use on the share + + -l, --local-path PATH (required) + path to the root of the samba share on the machine. + + -b, --bin BIN + path to the smbclient binary to use + + Test: + --list + list tests + + --test N + --test A-B + --test A,B,D-F + only run certain tests (accept list and intervals of numbers) + + -v, --verbose + be more verbose + + --debug + print command and their output (also set -v) + + --subunit + print output in subunit format + +=cut + +GetOptions('u|user=s' => \$USER, + 'p|password=s' => \$PW, + 'n|name=s' => \$HOST, + 'i|ip=s' => \$IP, + 's|share=s' => \$SHARE, + 'd|dir=s' => \$DIR, + 'l|local-path=s' => \$LOCALPATH, + 'b|bin=s' => \$BIN, + + 'test=s' => \$SELECTED_TEST, + 'list' => \$LIST_TEST, + + 'clean' => \$CLEAN, + 'subunit' => \$SUBUNIT, + 'debug' => \$DEBUG, + 'v|verbose' => \$VERBOSE, + 'h|help' => \$HELP, + 'man' => \$MAN) or pod2usage(2); + +pod2usage(0) if $HELP; +pod2usage(-exitval => 0, -verbose => 2) if $MAN; +list_test(), exit 0 if $LIST_TEST; +pod2usage(1) unless $HOST; +pod2usage(1) unless $SHARE; +pod2usage(1) unless $LOCALPATH; + +if ($USER xor $PW) { + die "Need both user and password when one is provided\n"; +} +elsif ($USER and $PW) { + push @SMBARGS, '-U'.$USER.'%'.$PW; +} +else { + push @SMBARGS, '-N'; +} + +if ($IP) { + push @SMBARGS, '-I', $IP; +} + +# remaining arguments are passed to smbclient +push @SMBARGS, @ARGV; + +# path to store the downloaded tarball +my $TAR = "$TMP/tarmode.tar"; + +##### + +# SANITIZATION + +# remove all final slashes from input paths +$LOCALPATH =~ s{[/\\]+$}{}g; +$SHARE =~ s{[/\\]+$}{}g; +$HOST =~ s{[/\\]+$}{}g; +$DIR =~ s{^\.[/\\]+$}{}g; +$DIR =~ s{[/\\]+$}{}g; + +if (!-d $LOCALPATH) { + die "Local path '$LOCALPATH' is not a directory.\n"; +} + +if ($CLEAN) { + # clean the whole root first + remove_tree($LOCALPATH, { keep_root => 1 }); +} + +if ($DEBUG) { + $VERBOSE = 1; +} + +##### + +# RUN TESTS + +my @selection = parse_test_string($SELECTED_TEST); + +if ($SELECTED_TEST eq '') { + run_test(@TESTS); +} elsif (@selection > 0) { + run_test(@selection); +} else { + die "Test selection '$SELECTED_TEST' is invalid\n"; +} + +################################# + +=head1 DOCUMENTATION + +=head2 Defining a test + +=over + +=item * Create a function C<test_yourtest> + +=item * Use the File module, documented below + +=item * Use C<smb_tar>, C<smb_client>, C<check_tar> or C<check_remote> + +=item * Return number of error + +=item * Add function to C<@TESTS> + +=back + +The function must be placed in the C<@TESTS> list along with a short +description and optional arguments. + +=cut + +sub test_creation_newer { + my @files; + my $dt = 3000; + + # create oldest file at - DT + my $oldest = File->new_remote('oldest'); + $oldest->set_time(time - $dt); + + # create limit file + my $limit = File->new_local("$TMP/limit"); + + # create newA file at + DT + my $newA = File->new_remote('newA'); + $newA->set_time(time + $dt); + + # create newB file at + DT + my $newB = File->new_remote('newB'); + $newB->set_time(time + $dt); + + # get files newer than limit_file + push @files, $newA, $newB; + + smb_tar('', '-TcN', $limit->localpath, $TAR, $DIR); + return check_tar($TAR, \@files); +} + +sub test_creation_attr { + my @attr = qw/r h s a/; + my @all; + my @inc; + my $err = 0; + + # one normal file + my $f = File->new_remote("file-n.txt"); + push @all, $f; + + # combinations of attributes + for my $n (1..@attr) { + for (combine(\@attr, $n)) { + my @t = @$_; + my $fn = "file-" . join('+', @t) . ".txt"; + my $f = File->new_remote($fn); + $f->set_attr(@t); + push @all, $f; + } + } + + @inc = grep { !$_->attr('s') } @all; + smb_tar('tarmode nosystem', '-Tc', $TAR, $DIR); + $err += check_tar($TAR, \@inc); + + @inc = grep { !$_->attr('h') } @all; + smb_tar('tarmode nohidden', '-Tc', $TAR, $DIR); + $err += check_tar($TAR, \@inc); + + @inc = grep { !$_->attr_any('h', 's') } @all; + smb_tar('tarmode nohidden nosystem', '-Tc', $TAR, $DIR); + $err += check_tar($TAR, \@inc); + + @inc = grep { $_->attr('a') && !$_->attr_any('h', 's') } @all; + smb_tar('tarmode inc nohidden nosystem', '-Tc', $TAR, $DIR); + $err += check_tar($TAR, \@inc); + + $err; +} + +sub test_creation_reset { + my ($mode) = @_; + + my @files; + my $n = 3; + for (1..$n) { + my $f = File->new_remote("file-$_"); + $f->set_attr('a'); + push @files, $f; + } + + if ($mode =~ /reset/) { + smb_tar('tarmode full reset', '-Tc', $TAR, $DIR); + } else { + smb_tar('', '-Tca', $TAR, $DIR); + } + + my $err = check_tar($TAR, \@files); + return $err if ($err > 0); + + for my $f (File::list($DIR)) { + if ($f->{attr}{a}) { + printf " ! %s %s\n", $f->attr_str, $f->remotepath; + $err++; + } + } + return $err; +} + +sub test_creation_large_file { + my $size = int(15e6); # 15MB + my $f = File->new_remote("fat.jpg", 0, $size); + + smb_tar('', '-Tc', $TAR, $DIR); + return check_tar($TAR, [$f]); +} + +sub test_creation_long_path { + my $d = "a"x130; + my @all; + + for (qw( foo/a bar/b )) { + push @all, File->new_remote("$d/$_"); + } + + smb_tar('', '-Tc', $TAR, $DIR); + return check_tar($TAR, \@all); +} + +sub test_creation_normal { + my ($mode) = @_; + + my $prefix = ($mode =~ /nest/) ? "/foo/bar/bar/" : ''; + my @files; + my $n = 5; + for (1..$n) { + my $f = File->new_remote($prefix."file-$_"); + push @files, $f; + } + + if ($mode =~ /inter/) { + smb_tar("tar c $TAR $DIR", ''); + } else { + smb_tar('tarmode full', '-Tc', $TAR, $DIR); + } + return check_tar($TAR, \@files); +} + +sub test_creation_incremental { + my ($mode) = @_; + + my @files; + my $n = 10; + for (1..$n) { + my $f = File->new_remote("file-$_"); + + # set archive bit on ~half of them + if ($_ < $n/2) { + $f->set_attr('a'); + push @files, $f; + } + else { + $f->set_attr((qw/n r s h/)[$_ % 4]); + } + } + + if ($mode =~ /inc/) { + smb_tar('tarmode inc', '-Tc', $TAR, $DIR); + } else { + smb_tar('', '-Tcg', $TAR, $DIR); + } + return check_tar($TAR, \@files); +} + + +sub test_extraction_normal { + my @files; + my $n = 5; + for (1..$n) { + my $f = File->new_remote("file-$_"); + push @files, $f; + } + + # store + smb_tar('', '-Tc', $TAR, $DIR); + my $err = check_tar($TAR, \@files); + return $err if $err > 0; + + reset_remote(); + + smb_tar('', '-Tx', $TAR); + check_remote($DIR, \@files); +} + +sub test_extraction_include { + my @all_files; + my @inc_files; + + for (qw(file_inc inc/b inc/c inc/dir/foo dir_ex/d zob)) { + my $f = File->new_remote($_); + push @all_files, $f; + push @inc_files, $f if /inc/; + } + + # store + smb_tar('', '-Tc', $TAR, $DIR); + my $err = check_tar($TAR, \@all_files); + return $err if $err > 0; + + reset_remote(); + + smb_tar('', '-TxI', $TAR, "$DIR/file_inc", "$DIR/inc"); + check_remote($DIR, \@inc_files); +} + +sub test_extraction_exclude { + my @all_files; + my @inc_files; + + for (qw(file_exc exc/b exc/c exc/dir/foo dir_ex/d zob)) { + my $f = File->new_remote($_); + push @all_files, $f; + push @inc_files, $f if !/exc/; + } + + # store + smb_tar('', '-Tc', $TAR, $DIR); + my $err = check_tar($TAR, \@all_files); + return $err if $err > 0; + + reset_remote(); + + smb_tar('', '-TxX', $TAR, "$DIR/file_exc", "$DIR/exc"); + check_remote($DIR, \@inc_files); +} + + +sub test_creation_include { + my @files; + + for (qw(file_inc inc/b inc/c inc/dir/foo dir_ex/d zob)) { + my $f = File->new_remote($_); + push @files, $f if /inc/; + } + + smb_tar('', '-TcI', $TAR, "$DIR/file_inc", "$DIR/inc"); + return check_tar($TAR, \@files); +} + +sub test_creation_exclude { + my @files; + + for (qw(file_ex ex/b ex/c ex/dir/foo foo/bar zob)) { + my $f = File->new_remote($_); + push @files, $f if !/ex/; + } + + smb_tar('', '-TcX', $TAR, "$DIR/file_ex", "$DIR/ex"); + return check_tar($TAR, \@files); +} + +sub test_creation_list { + my @inc_files; + -- Samba Shared Repository