3 ###########################################################################
5 # Characterization testing netatalks permission model
7 # (c) 2008 by Frank Lahm <franklahm@googlemail.com>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 ###########################################################################
21 ###########################################################################
25 # "permtest.cfg" must be in your CWD. Must be run on a OS X host. Tested
26 # with 10.4.11. Uses Applescript through system("osascript ...") to mount
27 # AFP Volumes. Uses `ssh LOGIN@HOST stat FILE|DIR`. Therefor PKI
28 # authentication must be setup and working!
29 # See "permtest.cfg" for more details, it's pretty much self-explaining.
31 ###########################################################################
37 ###########################################################################
47 my ($sshLogin, $sshResult, %sshStat, @AFPVols, @createFiles, @createDirs, @testFiles, @testDirs);
48 my ($dir, $file, $user, $group, $perms, $mode, $cmd);
61 ###########################################################################
66 open CFG, "permtest.cfg" or die "Config file not found!";
72 $sshLogin =~ s/^sshLogin ?= ?// ;
75 if (/^mountAFPVolume/) {
76 s/^mountAFPVolume ?= ?// ;
77 print "Found AFP Volume Definition \"$_\"\n" if $DEBUG;
82 s/^createFile ?= ?// ;
83 push @createFiles, $_;
107 print "Mounting AFP Volume \"$_\"\n";
108 $cmd = "osascript -e 'tell application \"Finder\"' -e 'mount volume \"$_\"' -e 'end tell' &> /dev/null";
109 print "Going to run the following Applescript:\n" . $cmd . "\n\n" if $DEBUG;
111 if ($? != 0) { die "Error mounting \"$_\"\n"; }
118 foreach (@createFiles) {
119 s/^createFile ?= ?// ;
120 system("rm \"$_\" &> /dev/null");
121 print "Creating file: \"$_\"\n";
122 system("touch \"$_\"");
123 if ($? != 0) { die "Error creating file \"$_\"\n"; }
130 foreach (@createDirs) {
131 s/^createDir ?= ?// ;
132 system("rmdir \"$_\" &> /dev/null");
133 print "Creating dir: \"$_\"\n";
134 system("mkdir \"$_\"");
135 if ($? != 0) { die "Error creating dir \"$_\"\n"; }
139 # Verify files and dirs
142 foreach (@testFiles) {
143 my @line = split(",");
147 $file =~ s/^testFile ?= ?//;
151 $user =~ s/^user ?= ?//;
155 $group =~ s/^group ?= ?//;
159 $mode =~ s/^mode ?= ?//;
162 print "File: $file, User: $user, Group: $group, Perms: $perms\n" if $DEBUG;
164 $sshResult = `ssh $sshLogin stat -c \"user,%U,group,%G,mode,0%a\" \"$file\"`;
165 if ($? != 0) { die "Error stat'ing file \"$file\"\n"; }
167 print "ssh stat $file gave us: $sshResult\n" if $DEBUG;
169 %sshStat = split(",", $sshResult);
170 if ( ($sshStat{user} ne $user) or ($sshStat{group} ne $group) or ($sshStat{mode} ne $mode) ) {
171 print "Creatin error for: \"$file\"!\nExpected:\t$user, $group, $mode.\nGot:\t\t$sshStat{user}, $sshStat{group}, $sshStat{mode}.\n\n";
173 system("rm \"$file\"");
174 if ($? != 0) { die "Couldn't delete \"$file\"\n"; }
180 foreach (@testDirs) {
181 my @line = split(",");
185 $dir =~ s/^testDir ?= ?//;
189 $user =~ s/^user ?= ?//;
193 $group =~ s/^group ?= ?//;
197 $mode =~ s/^mode ?= ?//;
200 print "Dir: $dir, User: $user, Group: $group, Perms: $perms\n" if $DEBUG;
202 $sshResult = `ssh $sshLogin stat -c \"user,%U,group,%G,mode,0%a\" \"$dir\"`;
203 if ($? != 0) { die "Error stat'ing file \"$dir\"\n"; }
205 print "ssh stat $dir gave us: $sshResult\n" if $DEBUG;
207 %sshStat = split(",", $sshResult);
208 if ( ($sshStat{user} ne $user) or ($sshStat{group} ne $group) or ($sshStat{mode} ne $mode) ) {
209 print "Creatin error for: \"$dir\"!\nExpected:\t$user, $group, $mode.\nGot:\t\t$sshStat{user}, $sshStat{group}, $sshStat{mode}.\n\n";
211 system("rmdir \"$dir\""); if ($? != 0) { die "Couldn't delete \"$dir\"\n"; }
218 print "Goint to eject Volume \"$_\"\n";
220 $cmd = "osascript -e 'tell application \"Finder\"' -e 'eject \"$_\"' -e 'end tell' &> /dev/null";
221 print "Going to run the following Applescript:\n" . $cmd . "\n\n" if $DEBUG;