1
/* $Xorg: checktree.c,v 1.4 2001/02/09 02:03:16 xorgcvs Exp $ */
5
Copyright (c) 1993, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
27
/* $XFree86: xc/config/util/checktree.c,v 1.4 2001/12/14 19:53:22 dawes Exp $ */
32
#include <sys/param.h>
58
#define CHARSALLOWED \
59
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_."
61
#define fmode_bits_minset 0444
62
#define fmode_bits_maxset 0777
63
#define fmode_bits_write 0222
64
#define dmode_bits_minset 0775
66
int dorcs = 1; /* check RCS file */
67
int do83 = 1; /* check for 8+3 clash */
68
int doro = 1; /* disallow writable (checked out) files */
69
int dodot = 1; /* disallow .files */
70
int dotwiddle = 1; /* disallow file~ */
77
if (fn[strlen(fn) - 1] == '~')
79
cp = strrchr(fn, '.');
80
return cp && (!strcmp(cp + 1, "Z") || !strcmp(cp + 1, "PS"));
83
checkfile(fullname, fn, fs)
91
if (dodot && fn[0] == '.') {
92
printf("dot file: %s\n", fullname);
95
for (len = 0, cp = fn; *cp; len++, cp++) {
96
if (!strchr(CHARSALLOWED, *cp)) {
97
if (dotwiddle || *cp != '~' || cp[1])
98
printf ("bad character: %s\n", fullname);
102
if (len > maxlen && !dontcare(fn))
103
printf("too long (%d): %s\n", len, fullname);
105
if ((fs->st_mode & S_IFLNK) == S_IFLNK) {
106
printf("symbolic link: %s\n", fullname);
110
mode = fs->st_mode & (~S_IFMT);
111
if ((fs->st_mode & S_IFDIR) == S_IFDIR) {
113
if ((mode & dmode_bits_minset) != dmode_bits_minset)
114
printf("directory mode 0%o not minimum 0%o: %s\n",
115
mode, dmode_bits_minset, fullname);
116
} else if ((fs->st_mode & S_IFREG) != S_IFREG)
117
printf("not a regular file: %s\n", fullname);
119
if ((mode & fmode_bits_minset) != fmode_bits_minset)
120
printf("file mode 0%o not minimum 0%o: %s\n",
121
fs->st_mode, fmode_bits_minset, fullname);
122
if (fs->st_nlink != 1)
123
printf("%d links instead of 1: %s\n", fs->st_nlink, fullname);
124
if (doro && (mode & fmode_bits_write) && !dontcare(fn))
125
printf("writable: %s\n", fullname);
127
if ((mode & ~fmode_bits_maxset) != 0)
128
printf("mode 0%o outside maximum set 0%o: %s\n",
129
mode, fmode_bits_maxset, fullname);
142
if (!(df = opendir(dir))) {
143
fprintf(stderr, "cannot open: %s\n", dir);
146
while (dp = readdir(df)) {
147
i = strlen(dp->d_name);
148
if (dp->d_name[i - 1] == 'v' && dp->d_name[i - 2] == ',') {
149
strcpy(p, dp->d_name);
151
if (Stat(dir, &fs) < 0) {
153
strcat(p, dp->d_name);
154
printf("not used: %s\n", dir);
168
for (; --n >= 0 && *cp1 && *cp2; cp1++, cp2++) {
172
if (c1 >= 'A' && c1 <= 'Z')
176
if (c2 >= 'A' && c2 <= 'Z')
181
return (int)c1 - (int)c2;
186
return (int)*cp1 - (int)*cp2;
197
i = Strncmp(*n1, *n2, 8);
199
cp1 = strrchr(*n1, '.');
200
cp2 = strrchr(*n2, '.');
206
i = Strncmp(cp1 + 1, cp2 + 1, 3);
223
if (!(df = opendir(dir))) {
224
fprintf(stderr, "cannot open: %s\n", dir);
227
p = dir + strlen(dir);
233
while (dp = readdir(df)) {
234
strcpy(p, dp->d_name);
235
if (Stat(dir, &fs) < 0) {
239
if ((fs.st_mode & S_IFDIR) == S_IFDIR) {
240
if (dp->d_name[0] == '.' &&
241
(dp->d_name[1] == '\0' || (dp->d_name[1] == '.' &&
242
dp->d_name[2] == '\0')))
244
if (!strcmp (dp->d_name, "RCS")) {
249
if (!strcmp (dp->d_name, "SCCS"))
251
if (!strcmp (dp->d_name, "CVS.adm"))
253
checkfile(dir, p, &fs);
257
checkfile(dir, p, &fs);
258
if (dorcs && !dontcare(dp->d_name)) {
260
strcat(p, dp->d_name);
262
if (Stat(dir, &fs) < 0) {
263
strcpy(p, dp->d_name);
264
printf("no RCS: %s\n", dir);
268
s = (char *)malloc(strlen(dp->d_name) + 1);
269
strcpy(s, dp->d_name);
273
names = (char **)realloc((char *)names,
274
(max + 1) * sizeof(char *));
276
names = (char **)malloc((max + 1) * sizeof(char *));
283
qsort((char *)names, i, sizeof(char *), fncomp);
286
for (i = 0; i < max; i++) {
287
if (!fncomp(&names[i], &names[i + 1]))
288
printf("8+3 clash: %s%s and %s\n",
289
dir, names[i], names[i + 1]);
308
if (!strcmp(*argv, "-rcs")) {
312
} else if (!strcmp(*argv, "-83")) {
316
} else if (!strcmp(*argv, "-ro")) {
320
} else if (!strcmp(*argv, "-dot")) {
324
} else if (!strcmp(*argv, "-twiddle")) {
335
while (--argc >= 0) {
336
strcpy(buf, *argv++);