~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/longpath.sh

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/bash
2
 
# $Id: longpath.sh 61 2006-05-19 18:32:14Z steve-beattie $
3
 
 
4
 
#       Copyright (C) 2002-2005 Novell/SUSE
5
 
#
6
 
#       This program is free software; you can redistribute it and/or
7
 
#       modify it under the terms of the GNU General Public License as
8
 
#       published by the Free Software Foundation, version 2 of the
9
 
#       License.
10
 
 
11
 
#=NAME longpath
12
 
#=DESCRIPTION 
13
 
# Verify handling of long pathnames.
14
 
#=END
15
 
 
16
 
genrandname()
17
 
{
18
 
        _goal=$1
19
 
        _ascii="abcdefghijlkmnopqrstuvwxyz0123456789"
20
 
        _mod=${#_ascii}
21
 
        _i=0
22
 
 
23
 
        for _i in `seq 2 $_goal`
24
 
        do
25
 
                _c=$((RANDOM % $_mod))
26
 
                _s="${_s}${_ascii:$_c:1}"
27
 
        done
28
 
 
29
 
        echo $_s
30
 
}
31
 
pwd=`dirname $0`
32
 
pwd=`cd $pwd ; /bin/pwd`
33
 
 
34
 
bin=$pwd
35
 
 
36
 
. $bin/prologue.inc
37
 
 
38
 
name_max=255 #NAME_MAX
39
 
direlem_max=235 #Length for intermediate dirs, slightly less than name_max
40
 
buf_max=4096 #PAGE
41
 
 
42
 
# generate 255 character filename
43
 
file=`genrandname $name_max`
44
 
file2=`genrandname $name_max`
45
 
 
46
 
settest open
47
 
okperm=rw
48
 
linkperm=rwl
49
 
 
50
 
cd $tmpdir
51
 
 
52
 
mkdir_expected_fail=0
53
 
file_expected_fail=0
54
 
link_expected_fail=0
55
 
 
56
 
iter=1
57
 
while true
58
 
do
59
 
        direlem=`genrandname $direlem_max`
60
 
 
61
 
        _dpath=`pwd`/$direlem
62
 
 
63
 
        if [ ${#_dpath} -lt 4096 ]
64
 
        then
65
 
                dstatus=pass
66
 
        else
67
 
                dstatus=fail
68
 
        fi
69
 
 
70
 
        settest mkdir
71
 
        genprofile $tmpdir/**:$okperm
72
 
        runchecktest "LONGPATH MKDIR ($iter)" $dstatus mkdir $direlem
73
 
 
74
 
        if [ $dstatus = "pass" ]
75
 
        then
76
 
                if [ -d $direlem ]
77
 
                then
78
 
                        #echo "mkdir ($iter) passed at length ${#_dpath}"
79
 
                        cd $direlem
80
 
                else
81
 
                        echo "FAIL: $direlem ($_iter) was not created" >&2
82
 
                fi
83
 
        else
84
 
                if [ -d $direlem ]
85
 
                then
86
 
                        echo "mkdir ($iter) incorrectly generated dir at length ${#_dpath}"
87
 
                else
88
 
                        #echo "mkdir ($iter) failed at length ${#_dpath}"
89
 
                        mkdir_expected_fail=1
90
 
                fi
91
 
                :
92
 
        fi
93
 
 
94
 
        _fpath=`pwd`/$file
95
 
        if [ ${#_fpath} -lt 4096 ]
96
 
        then
97
 
                fstatus=pass
98
 
        else
99
 
                fstatus=fail
100
 
        fi
101
 
 
102
 
        settest open
103
 
        genprofile $tmpdir/**:$okperm
104
 
        runchecktest "LONGPATH CREATE ($iter)" $fstatus $file
105
 
        
106
 
        if [ $fstatus = "pass" ]
107
 
        then
108
 
                if [ -f $file ]
109
 
                then
110
 
                        #echo "file creat ($iter) passed at length ${#_dpath}"
111
 
                        :
112
 
                else
113
 
                        echo "FAIL: $file ($_iter) was not created" >&2
114
 
                fi
115
 
        elif [ $fstatus = "fail" ]
116
 
        then
117
 
                if [ -f $file ]
118
 
                then
119
 
                        echo "file creat ($iter) incorrectly generated file at length ${#_fpath}"
120
 
                else
121
 
                        #echo "file creat ($iter) failed at length ${#_fpath}"
122
 
                        file_expected_fail=1
123
 
                fi
124
 
        fi
125
 
 
126
 
        settest link
127
 
        genprofile $tmpdir/**:$linkperm
128
 
        if [ -f $file ]
129
 
        then
130
 
                _f=$file 
131
 
        elif [ -f ../$file ]
132
 
        then
133
 
                _f=../$file
134
 
        else
135
 
                echo "unable to find file to link" >&2
136
 
                exit 1
137
 
        fi
138
 
 
139
 
        runchecktest "LONGPATH LINK ($iter)" $fstatus $_f $file2
140
 
 
141
 
        if [ $fstatus = "pass" ]
142
 
        then
143
 
                if [ -f $file2 ]
144
 
                then
145
 
                        #echo "file link ($iter) passed at length ${#_dpath}"
146
 
                        :
147
 
                else
148
 
                        echo "FAIL: $file2 ($_iter) was not linked" >&2
149
 
                fi
150
 
        elif [ $fstatus = "fail" ]
151
 
        then
152
 
                if [ -f $file2 ]
153
 
                then
154
 
                        echo "file link ($iter) incorrectly generated file at length ${#_dpath}"
155
 
                else
156
 
                        #echo "file link ($iter) failed at length ${#_fpath}"
157
 
                        link_expected_fail=1
158
 
                fi
159
 
        fi
160
 
                        
161
 
        if [ $mkdir_expected_fail -eq 1 -a \
162
 
             $file_expected_fail -eq 1 -a \
163
 
             $link_expected_fail -eq 1 ]
164
 
        then
165
 
                break
166
 
        fi
167
 
        
168
 
        : $((iter++))
169
 
done