2005-04-21 16:53:53 +02:00
|
|
|
/* Comment on usage and program: ark!/mnt/rene/prac/os/unix/comment.changes */
|
|
|
|
|
|
|
|
/* "const.h", created by Rene Montsma and Menno Wilcke */
|
|
|
|
|
|
|
|
#include <sys/types.h> /* type defs */
|
|
|
|
#include <sys/stat.h> /* struct stat */
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <errno.h> /* the error-numbers */
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <utime.h>
|
|
|
|
#include <stdio.h>
|
2006-02-13 12:07:21 +01:00
|
|
|
#include <limits.h>
|
2010-07-13 14:38:58 +02:00
|
|
|
#include <assert.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
#define NOCRASH 1 /* test11(), 2nd pipe */
|
|
|
|
#define PDPNOHANG 1 /* test03(), write_standards() */
|
2013-04-16 18:04:46 +02:00
|
|
|
int max_error = 2;
|
|
|
|
#include "common.h"
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
#define USER_ID 12
|
|
|
|
#define GROUP_ID 1
|
|
|
|
#define FF 3 /* first free filedes. */
|
|
|
|
#define USER 1 /* uid */
|
|
|
|
#define GROUP 0 /* gid */
|
|
|
|
|
|
|
|
#define ARSIZE 256 /* array size */
|
|
|
|
#define PIPESIZE 3584 /* max number of bytes to be written on pipe */
|
2006-02-13 12:07:21 +01:00
|
|
|
#define MAXOPEN (OPEN_MAX-3) /* maximum number of extra open files */
|
2005-04-21 16:53:53 +02:00
|
|
|
#define MAXLINK 0177 /* maximum number of links per file */
|
|
|
|
#define LINKCOUNT 5
|
|
|
|
#define MASK 0777 /* selects lower nine bits */
|
|
|
|
#define END_FILE 0 /* returned by read-call at eof */
|
|
|
|
|
|
|
|
#define OK 0
|
|
|
|
#define FAIL -1
|
|
|
|
|
|
|
|
#define R 0 /* read (open-call) */
|
|
|
|
#define W 1 /* write (open-call) */
|
|
|
|
#define RW 2 /* read & write (open-call) */
|
|
|
|
|
|
|
|
#define RWX 7 /* read & write & execute (mode) */
|
|
|
|
|
|
|
|
#define NIL ""
|
|
|
|
#define UMASK "umask"
|
|
|
|
#define CREAT "creat"
|
|
|
|
#define WRITE "write"
|
|
|
|
#define READ "read"
|
|
|
|
#define OPEN "open"
|
|
|
|
#define CLOSE "close"
|
|
|
|
#define LSEEK "lseek"
|
|
|
|
#define ACCESS "access"
|
|
|
|
#define CHDIR "chdir"
|
|
|
|
#define CHMOD "chmod"
|
|
|
|
#define LINK "link"
|
|
|
|
#define UNLINK "unlink"
|
|
|
|
#define PIPE "pipe"
|
|
|
|
#define STAT "stat"
|
|
|
|
#define FSTAT "fstat"
|
|
|
|
#define DUP "dup"
|
|
|
|
#define UTIME "utime"
|
|
|
|
|
|
|
|
|
|
|
|
/* "decl.c", created by Rene Montsma and Menno Wilcke */
|
|
|
|
|
|
|
|
/* Used in open_alot, close_alot */
|
2010-07-13 14:38:58 +02:00
|
|
|
char *filenames[MAXOPEN];
|
|
|
|
|
|
|
|
#define MODES 8
|
|
|
|
char *mode_fnames[MODES] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"},
|
|
|
|
*mode_dir[MODES] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", "drw-", "drwx"};
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Needed for easy creating and deleting of directories */
|
|
|
|
|
|
|
|
/* "test.c", created by Rene Montsma and Menno Wilcke */
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
|
2012-03-24 16:16:34 +01:00
|
|
|
int main(int argc, char *argv []);
|
|
|
|
void test(int mask);
|
|
|
|
void test01(void);
|
|
|
|
void test02(void);
|
|
|
|
void test08(void);
|
|
|
|
void test09(void);
|
|
|
|
void test10(void);
|
|
|
|
int link_alot(char *bigboss);
|
|
|
|
int unlink_alot(int number);
|
|
|
|
void get_new(char name []);
|
|
|
|
void test11(void);
|
|
|
|
void nlcr(void);
|
|
|
|
void str(char *s);
|
|
|
|
void test03(void);
|
|
|
|
void put_file_in_dir(char *dirname, int mode);
|
|
|
|
void init_array(char *a);
|
|
|
|
void clear_array(char *b);
|
|
|
|
int comp_array(char *a, char *b, int range);
|
|
|
|
void try_close(int filedes, char *name);
|
|
|
|
void try_unlink(char *fname);
|
|
|
|
void Remove(int fdes, char *fname);
|
|
|
|
int get_mode(char *name);
|
|
|
|
void check(char *scall, int number);
|
|
|
|
void put(int nr);
|
|
|
|
int open_alot(void);
|
|
|
|
int close_alot(int number);
|
|
|
|
void clean_up_the_mess(void);
|
|
|
|
void chmod_8_dirs(int sw);
|
|
|
|
void quit(void);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* TEST *
|
|
|
|
****************************************************************************/
|
|
|
|
int main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
2010-07-13 14:38:58 +02:00
|
|
|
int n, mask, i;
|
2011-12-16 15:45:53 +01:00
|
|
|
pid_t child;
|
|
|
|
|
|
|
|
start(17);
|
2010-07-13 14:38:58 +02:00
|
|
|
|
|
|
|
/* Create filenames for MAXOPEN files, the *filenames[] array. */
|
|
|
|
for(i = 0; i < MAXOPEN; i++) {
|
|
|
|
if(asprintf(&filenames[i], "file%d", i) == -1) {
|
|
|
|
fprintf(stderr, "asprintf failed\n");
|
2011-12-16 15:45:53 +01:00
|
|
|
quit();
|
2010-07-13 14:38:58 +02:00
|
|
|
}
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
mask = (argc == 2 ? atoi(argv[1]) : 0xFFFF);
|
2011-12-16 15:45:53 +01:00
|
|
|
subtest = 0;
|
|
|
|
child = fork();
|
|
|
|
if (child == -1) {
|
|
|
|
e(1);
|
|
|
|
quit();
|
|
|
|
} else if (child == 0) {
|
|
|
|
test(mask);
|
|
|
|
return(0);
|
|
|
|
} else {
|
|
|
|
wait(&n);
|
2005-04-21 16:53:53 +02:00
|
|
|
clean_up_the_mess();
|
|
|
|
quit();
|
|
|
|
}
|
|
|
|
return(-1); /* impossible */
|
|
|
|
}
|
|
|
|
|
|
|
|
void test(mask)
|
|
|
|
int mask;
|
|
|
|
{
|
|
|
|
umask(0); /* not honest, but i always forget */
|
|
|
|
|
|
|
|
if (mask & 00001) test01();
|
2011-12-16 15:45:53 +01:00
|
|
|
if (mask & 00002) test03();
|
2005-04-21 16:53:53 +02:00
|
|
|
if (mask & 00004) test02();
|
|
|
|
if (mask & 00010) test08();
|
|
|
|
if (mask & 00020) test09();
|
|
|
|
if (mask & 00040) test10();
|
|
|
|
if (mask & 00100) test11();
|
|
|
|
umask(022);
|
|
|
|
} /* test */
|
|
|
|
|
|
|
|
/* "t1.c" created by Rene Montsma and Menno Wilcke */
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* test UMASK *
|
|
|
|
****************************************************************************/
|
|
|
|
void test01()
|
|
|
|
{
|
|
|
|
int oldvalue, newvalue, tempvalue;
|
|
|
|
int nr;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
subtest = 1;
|
|
|
|
if ((oldvalue = umask(0777)) != 0) e(1);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Special test: only the lower 9 bits (protection bits) may part- *
|
|
|
|
* icipate. ~0777 means: 111 000 000 000. Giving this to umask must*
|
|
|
|
* not change any value. */
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if ((newvalue = umask(~0777)) != 0777) e(2);
|
|
|
|
if (oldvalue == newvalue) e(3);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if ((tempvalue = umask(0)) != 0) e(4);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Now test all possible modes of umask on a file */
|
|
|
|
for (newvalue = MASK; newvalue >= 0; newvalue -= 0111) {
|
|
|
|
tempvalue = umask(newvalue);
|
|
|
|
if (tempvalue != oldvalue) {
|
2011-12-16 15:45:53 +01:00
|
|
|
e(5);
|
2005-04-21 16:53:53 +02:00
|
|
|
break; /* no use trying more */
|
|
|
|
} else if ((nr = creat("file01", 0777)) < 0)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(6);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
try_close(nr, "'file01'");
|
|
|
|
if (get_mode("file01") != (MASK & ~newvalue))
|
2011-12-16 15:45:53 +01:00
|
|
|
e(7);
|
2005-04-21 16:53:53 +02:00
|
|
|
try_unlink("file01");
|
|
|
|
}
|
|
|
|
oldvalue = newvalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The loop has terminated with umask(0) */
|
|
|
|
if ((tempvalue = umask(0)) != 0)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(8);
|
2005-04-21 16:53:53 +02:00
|
|
|
} /* test01 */
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* test CREAT *
|
|
|
|
****************************************************************************/
|
|
|
|
void test02()
|
|
|
|
{
|
|
|
|
int n, n1, mode;
|
|
|
|
char a[ARSIZE], b[ARSIZE];
|
|
|
|
struct stat stbf1;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
subtest = 2;
|
2005-04-21 16:53:53 +02:00
|
|
|
mode = 0;
|
2011-12-16 15:45:53 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
for (n = 0; n < MAXOPEN; n++) {
|
2010-07-13 14:38:58 +02:00
|
|
|
if (creat(filenames[n], mode) != FF + n)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(1);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
2010-07-13 14:38:58 +02:00
|
|
|
if (get_mode(filenames[n]) != mode)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(2);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Change mode of file to standard mode, we want to *
|
|
|
|
* use a lot (20) of files to be opened later, see *
|
|
|
|
* open_alot(), close_alot(). */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chmod(filenames[n], 0700) != OK) e(3);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
mode = (mode + 0100) % 01000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Already twenty files opened; opening another has to fail */
|
|
|
|
if (creat("file02", 0777) != FAIL)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(4);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EMFILE) e(5);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Close all files: seems blunt, but it isn't because we've *
|
|
|
|
* checked all fd's already */
|
2011-12-16 15:45:53 +01:00
|
|
|
if ((n = close_alot(MAXOPEN)) < MAXOPEN) e(6);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Creat 1 file twice; check */
|
|
|
|
if ((n = creat("file02", 0777)) < 0)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(7);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
init_array(a);
|
2011-12-16 15:45:53 +01:00
|
|
|
if (write(n, a, ARSIZE) != ARSIZE) e(8);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
if ((n1 = creat("file02", 0755)) < 0) /* receate 'file02' */
|
2011-12-16 15:45:53 +01:00
|
|
|
e(9);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
/* Fd should be at the top after recreation */
|
|
|
|
if (lseek(n1, 0L, SEEK_END) != 0)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(10);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
/* Try to write on recreated file */
|
|
|
|
clear_array(b);
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if (lseek(n1, 0L, SEEK_SET) != 0) e(11);
|
|
|
|
if (write(n1, a, ARSIZE) != ARSIZE) e(12);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* In order to read we've to close and open again */
|
|
|
|
try_close(n1, "'file02' (2nd creation)");
|
|
|
|
if ((n1 = open("file02", RW)) < 0)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(13);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Continue */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (lseek(n1, 0L, SEEK_SET) != 0) e(14);
|
|
|
|
if (read(n1, b, ARSIZE) != ARSIZE) e(15);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if (comp_array(a, b, ARSIZE) != OK) e(16);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2011-12-16 15:45:53 +01:00
|
|
|
if (get_mode("file02") != 0777) e(17);
|
2005-04-21 16:53:53 +02:00
|
|
|
try_close(n1, "recreated 'file02'");
|
|
|
|
|
|
|
|
}
|
|
|
|
Remove(n, "file02");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Give 'creat' wrong input: dir not searchable */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (creat("drw-/file02", 0777) != FAIL) e(18);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EACCES) e(19);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Dir not writable */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (creat("dr-x/file02", 0777) != FAIL) e(20);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EACCES) e(21);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* File not writable */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (creat("drwx/r-x", 0777) != FAIL) e(22);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EACCES) e(23);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Try to creat a dir */
|
|
|
|
if ((n = creat("dir", 040777)) != FAIL) {
|
2011-12-16 15:45:53 +01:00
|
|
|
if (fstat(n, &stbf1) != OK) e(24);
|
2005-04-21 16:53:53 +02:00
|
|
|
else if (stbf1.st_mode != (mode_t) 0100777)
|
|
|
|
/* cast because mode is negative :-( */
|
2011-12-16 15:45:53 +01:00
|
|
|
e(25);
|
2005-04-21 16:53:53 +02:00
|
|
|
Remove(n, "dir");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We don't consider it to be a bug when creat * does not accept
|
|
|
|
* tricky modes */
|
|
|
|
|
|
|
|
/* File is an existing dir */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (creat("drwx", 0777) != FAIL) e(26);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EISDIR) e(27);
|
2005-04-21 16:53:53 +02:00
|
|
|
} /* test02 */
|
|
|
|
|
|
|
|
void test08()
|
|
|
|
{
|
2011-12-16 15:45:53 +01:00
|
|
|
subtest = 8;
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Test chdir to searchable dir */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("drwx") != OK) e(1);
|
|
|
|
else if (chdir("..") != OK) e(2);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Check the chdir(".") and chdir("..") mechanism */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("drwx") != OK) e(3);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir(".") != OK) e(4);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* If we still are in 'drwx' , we should be able to access *
|
|
|
|
* file 'rwx'. */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (access("rwx", 0) != OK) e(5);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Try to return to previous dir ('/' !!) */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("././../././d--x/../d--x/././..") != OK) e(6);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Check whether we are back in '/' */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("d--x") != OK) e(7);
|
|
|
|
} /* Return to '..' */
|
|
|
|
if (chdir("..") != OK) e(8);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("././././drwx") != OK) e(9);
|
|
|
|
else if (chdir("././././..") != OK) e(10);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Try giving chdir wrong parameters */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("drwx/rwx") != FAIL) e(11);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != ENOTDIR) e(12);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("drw-") != FAIL) e(13);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EACCES) e(14);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
} /* test08 */
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* test CHMOD *
|
|
|
|
****************************************************************************/
|
|
|
|
void test09()
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
subtest = 9;
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Prepare file09 */
|
2011-12-16 15:45:53 +01:00
|
|
|
if ((n = creat("drwx/file09", 0644)) != FF) e(1);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
try_close(n, "'file09'");
|
|
|
|
|
|
|
|
/* Try to chmod a file, check and restore old values, check */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chmod("drwx/file09", 0700) != OK) e(2);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
/* Check protection */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (get_mode("drwx/file09") != 0700) e(3);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Test if chmod accepts just filenames too */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("drwx") != OK) e(4);
|
|
|
|
else if (chmod("file09", 0177) != OK) e(5);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
|
|
|
/* Check if value has been restored */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (get_mode("../drwx/file09") != 0177) e(6);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try setuid and setgid */
|
|
|
|
if ((chmod("file09", 04777) != OK) || (get_mode("file09") != 04777))
|
2011-12-16 15:45:53 +01:00
|
|
|
e(7);
|
2005-04-21 16:53:53 +02:00
|
|
|
if ((chmod("file09", 02777) != OK) || (get_mode("file09") != 02777))
|
2011-12-16 15:45:53 +01:00
|
|
|
e(8);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Remove testfile */
|
|
|
|
try_unlink("file09");
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("..") != OK) e(9);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Try to chmod directory */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chmod("d---", 0777) != OK) e(10);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
2011-12-16 15:45:53 +01:00
|
|
|
if (get_mode("d---") != 0777) e(11);
|
|
|
|
if (chmod("d---", 0000) != OK) e(12);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Check if old value has been restored */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (get_mode("d---") != 0000) e(13);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to make chmod failures */
|
|
|
|
|
|
|
|
/* We still are in dir root */
|
|
|
|
/* Wrong filename */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chmod("non-file", 0777) != FAIL) e(14);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != ENOENT) e(15);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
} /* test 09 */
|
|
|
|
|
|
|
|
|
|
|
|
/* "t4.c", created by Rene Montsma and Menno Wilcke */
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* test LINK/UNLINK *
|
|
|
|
****************************************************************************/
|
|
|
|
void test10()
|
|
|
|
{
|
|
|
|
int n, n1;
|
|
|
|
char a[ARSIZE], b[ARSIZE], *f, *lf;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
subtest = 10;
|
|
|
|
|
2010-07-13 14:38:58 +02:00
|
|
|
f = "anotherfile10";
|
2005-04-21 16:53:53 +02:00
|
|
|
lf = "linkfile10";
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if ((n = creat(f, 0702)) != FF) e(1); /* no other open files */
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
/* Now link correctly */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (link(f, lf) != OK) e(2);
|
|
|
|
else if ((n1 = open(lf, RW)) < 0) e(3);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
init_array(a);
|
|
|
|
clear_array(b);
|
|
|
|
|
|
|
|
/* Write on 'file10' means being able to * read
|
|
|
|
* through linked filedescriptor */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (write(n, a, ARSIZE) != ARSIZE) e(4);
|
|
|
|
if (read(n1, b, ARSIZE) != ARSIZE) e(5);
|
|
|
|
if (comp_array(a, b, ARSIZE) != OK) e(6);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Clean up: unlink and close (twice): */
|
|
|
|
Remove(n, f);
|
|
|
|
try_close(n1, "'linkfile10'");
|
|
|
|
|
|
|
|
/* Check if "linkfile" exists and the info * on it
|
|
|
|
* is correct ('file' has been deleted) */
|
2011-12-16 15:45:53 +01:00
|
|
|
if ((n1 = open(lf, R)) < 0) e(7);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
/* See if 'linkfile' still contains 0..511 ? */
|
|
|
|
|
|
|
|
clear_array(b);
|
2011-12-16 15:45:53 +01:00
|
|
|
if (read(n1, b, ARSIZE) != ARSIZE) e(8);
|
|
|
|
if (comp_array(a, b, ARSIZE) != OK) e(9);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
try_close(n1, "'linkfile10' 2nd time");
|
|
|
|
try_unlink(lf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try if unlink fails with incorrect parameters */
|
|
|
|
/* File does not exist: */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (unlink("non-file") != FAIL) e(10);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != ENOENT) e(11);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Dir can't be written */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (unlink("dr-x/rwx") != FAIL) e(12);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EACCES) e(13);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Try to unlink a dir being user */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (unlink("drwx") != FAIL) e(14);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EPERM) e(15);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Try giving link wrong input */
|
|
|
|
|
|
|
|
/* First try if link fails with incorrect parameters * name1 does not
|
|
|
|
* exist. */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (link("non-file", "linkfile") != FAIL) e(16);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != ENOENT) e(17);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Name2 exists already */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (link("drwx/rwx", "drwx/rw-") != FAIL) e(18);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EEXIST) e(19);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Directory of name2 not writable: */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (link("drwx/rwx", "dr-x/linkfile") != FAIL) e(20);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EACCES) e(21);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Try to link a dir, being a user */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (link("drwx", "linkfile") != FAIL) e(22);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EPERM) e(23);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* File has too many links */
|
|
|
|
if ((n = link_alot("drwx/rwx")) != LINKCOUNT - 1) /* file already has one
|
|
|
|
* link */
|
2011-12-16 15:45:53 +01:00
|
|
|
e(24);
|
|
|
|
if (unlink_alot(n) != n) e(25);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
} /* test10 */
|
|
|
|
|
|
|
|
int link_alot(bigboss)
|
|
|
|
char *bigboss;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
static char employee[6] = "aaaaa";
|
|
|
|
|
|
|
|
/* Every file has already got 1 link, so link 0176 times */
|
|
|
|
for (i = 1; i < LINKCOUNT; i++) {
|
|
|
|
if (link(bigboss, employee) != OK)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
get_new(employee);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(i - 1); /* number of linked files */
|
|
|
|
} /* link_alot */
|
|
|
|
|
|
|
|
int unlink_alot(number)
|
|
|
|
int number; /* number of files to be unlinked */
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
static char employee[6] = "aaaaa";
|
|
|
|
|
|
|
|
for (j = 0; j < number; j++) {
|
|
|
|
if (unlink(employee) != OK)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
get_new(employee);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(j); /* return number of unlinked files */
|
|
|
|
} /* unlink_alot */
|
|
|
|
|
|
|
|
void get_new(name)
|
|
|
|
char name[];
|
|
|
|
/* Every call changes string 'name' to a string alphabetically *
|
|
|
|
* higher. Start with "aaaaa", next value: "aaaab" . *
|
|
|
|
* N.B. after "aaaaz" comes "aaabz" and not "aaaba" (not needed). *
|
|
|
|
* The last possibility will be "zzzzz". *
|
|
|
|
* Total # possibilities: 26+25*4 = 126 = MAXLINK -1 (exactly needed) */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 4; i >= 0; i--)
|
|
|
|
if (name[i] != 'z') {
|
|
|
|
name[i]++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} /* get_new */
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* test PIPE *
|
|
|
|
****************************************************************************/
|
|
|
|
void test11()
|
|
|
|
{
|
|
|
|
int n, fd[2];
|
|
|
|
char a[ARSIZE], b[ARSIZE];
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
subtest = 11;
|
|
|
|
|
|
|
|
if (pipe(fd) != OK) e(1);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
/* Try reading and writing on a pipe */
|
|
|
|
init_array(a);
|
|
|
|
clear_array(b);
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if (write(fd[1], a, ARSIZE) != ARSIZE) e(2);
|
|
|
|
else if (read(fd[0], b, (ARSIZE / 2)) != (ARSIZE / 2)) e(3);
|
|
|
|
else if (comp_array(a, b, (ARSIZE / 2)) != OK) e(4);
|
|
|
|
else if (read(fd[0], b, (ARSIZE / 2)) != (ARSIZE / 2)) e(5);
|
|
|
|
else if (comp_array(&a[ARSIZE / 2], b, (ARSIZE / 2)) != OK) e(6);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Try to let the pipe make a mistake */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (write(fd[0], a, ARSIZE) != FAIL) e(7);
|
|
|
|
if (read(fd[1], b, ARSIZE) != FAIL) e(8);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
try_close(fd[1], "'fd[1]'");
|
|
|
|
|
|
|
|
/* Now we shouldn't be able to read, because fd[1] has been closed */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (read(fd[0], b, ARSIZE) != END_FILE) e(9);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
try_close(fd[0], "'fd[0]'");
|
|
|
|
}
|
2011-12-16 15:45:53 +01:00
|
|
|
if (pipe(fd) < 0) e(10);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
/* Test lseek on a pipe: should fail */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (write(fd[1], a, ARSIZE) != ARSIZE) e(11);
|
|
|
|
if (lseek(fd[1], 10L, SEEK_SET) != FAIL) e(12);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != ESPIPE) e(13);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Eat half of the pipe: no writing should be possible */
|
|
|
|
try_close(fd[0], "'fd[0]' (2nd time)");
|
|
|
|
|
|
|
|
/* This makes UNIX crash: omit it if pdp or VAX */
|
|
|
|
#ifndef NOCRASH
|
2011-12-16 15:45:53 +01:00
|
|
|
if (write(fd[1], a, ARSIZE) != FAIL) e(14);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EPIPE) e(15);
|
2005-04-21 16:53:53 +02:00
|
|
|
#endif
|
|
|
|
try_close(fd[1], "'fd[1]' (2nd time)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* BUG : *
|
|
|
|
* Here we planned to test if we could write 4K bytes on a pipe. *
|
|
|
|
* However, this was not possible to implement, because the whole *
|
|
|
|
* Monix system crashed when we tried to write more then 3584 bytes *
|
|
|
|
* (3.5K) on a pipe. That's why we try to write only 3.5K in the *
|
|
|
|
* folowing test. */
|
2011-12-16 15:45:53 +01:00
|
|
|
if (pipe(fd) < 0) e(16);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
for (n = 0; n < (PIPESIZE / ARSIZE); n++)
|
2011-12-16 15:45:53 +01:00
|
|
|
if (write(fd[1], a, ARSIZE) != ARSIZE) e(17);
|
2005-04-21 16:53:53 +02:00
|
|
|
try_close(fd[1], "'fd[1]' (3rd time)");
|
|
|
|
|
|
|
|
for (n = 0; n < (PIPESIZE / ARSIZE); n++)
|
2011-12-16 15:45:53 +01:00
|
|
|
if (read(fd[0], b, ARSIZE) != ARSIZE) e(18);
|
2005-04-21 16:53:53 +02:00
|
|
|
try_close(fd[0], "'fd[0]' (3rd time)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test opening a lot of files */
|
2011-12-16 15:45:53 +01:00
|
|
|
if ((n = open_alot()) != MAXOPEN) e(19);
|
|
|
|
if (pipe(fd) != FAIL) e(20);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
2011-12-16 15:45:53 +01:00
|
|
|
if (errno != EMFILE) e(21);
|
|
|
|
if (close_alot(n) != n) e(22);
|
2005-04-21 16:53:53 +02:00
|
|
|
} /* test11 */
|
|
|
|
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
/* Err, test03, init_array, clear_array, comp_array,
|
2005-04-21 16:53:53 +02:00
|
|
|
try_close, try_unlink, Remove, get_mode, check, open_alot,
|
|
|
|
close_alot, clean_up_the_mess.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* *
|
|
|
|
* MAKE_AND_FILL_DIRS *
|
|
|
|
* *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
void test03()
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Create 8 dir.'s: "d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", *
|
|
|
|
* "drw-", "drwx". * Then create 8 files
|
|
|
|
* in "drwx", and some needed files in other dirs. */
|
|
|
|
{
|
|
|
|
int mode, i;
|
2011-12-16 15:45:53 +01:00
|
|
|
subtest = 3;
|
2010-07-13 14:38:58 +02:00
|
|
|
for (i = 0; i < MODES; i++) {
|
|
|
|
mkdir(mode_dir[i], 0700);
|
|
|
|
chown(mode_dir[i], USER_ID, GROUP_ID);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
setuid(USER_ID);
|
|
|
|
setgid(GROUP_ID);
|
|
|
|
|
|
|
|
for (mode = 0; mode < 8; mode++) put_file_in_dir("drwx", mode);
|
|
|
|
|
|
|
|
put_file_in_dir("d-wx", RWX);
|
|
|
|
put_file_in_dir("dr-x", RWX);
|
|
|
|
put_file_in_dir("drw-", RWX);
|
|
|
|
|
|
|
|
chmod_8_dirs(8); /* 8 means; 8 different modes */
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
} /* test03 */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
void put_file_in_dir(dirname, mode)
|
|
|
|
char *dirname;
|
|
|
|
int mode;
|
|
|
|
/* Fill directory 'dirname' with file with mode 'mode'. */
|
|
|
|
{
|
|
|
|
int nr;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir(dirname) != OK) e(1);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
|
|
|
/* Creat the file */
|
2010-07-13 14:38:58 +02:00
|
|
|
assert(mode >= 0 && mode < MODES);
|
2011-12-16 15:45:53 +01:00
|
|
|
if ((nr = creat(mode_fnames[mode], mode * 0100)) < 0) e(2);
|
2010-07-13 14:38:58 +02:00
|
|
|
else {
|
|
|
|
try_close(nr, mode_fnames[mode]);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("..") != OK) e(3);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
} /* put_file_in_dir */
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* *
|
|
|
|
* MISCELLANEOUS *
|
|
|
|
* *
|
|
|
|
*(all about arrays, 'try_close', 'try_unlink', 'Remove', 'get_mode')*
|
|
|
|
* *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
void init_array(a)
|
|
|
|
char *a;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i++ < ARSIZE) *a++ = 'a' + (i % 26);
|
|
|
|
} /* init_array */
|
|
|
|
|
|
|
|
void clear_array(b)
|
|
|
|
char *b;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i++ < ARSIZE) *b++ = '0';
|
|
|
|
|
|
|
|
} /* clear_array */
|
|
|
|
|
|
|
|
int comp_array(a, b, range)
|
|
|
|
char *a, *b;
|
|
|
|
int range;
|
|
|
|
{
|
2011-12-16 15:45:53 +01:00
|
|
|
assert(range >= 0 && range <= ARSIZE);
|
|
|
|
while (range-- && (*a++ == *b++));
|
|
|
|
if (*--a == *--b)
|
|
|
|
return(OK);
|
|
|
|
else
|
2005-04-21 16:53:53 +02:00
|
|
|
return(FAIL);
|
|
|
|
} /* comp_array */
|
|
|
|
|
|
|
|
void try_close(filedes, name)
|
|
|
|
int filedes;
|
|
|
|
char *name;
|
|
|
|
{
|
2011-12-16 15:45:53 +01:00
|
|
|
if (close(filedes) != OK) e(90);
|
2005-04-21 16:53:53 +02:00
|
|
|
} /* try_close */
|
|
|
|
|
|
|
|
void try_unlink(fname)
|
|
|
|
char *fname;
|
|
|
|
{
|
2011-12-16 15:45:53 +01:00
|
|
|
if (unlink(fname) != 0) e(91);
|
2005-04-21 16:53:53 +02:00
|
|
|
} /* try_unlink */
|
|
|
|
|
|
|
|
void Remove(fdes, fname)
|
|
|
|
int fdes;
|
|
|
|
char *fname;
|
|
|
|
{
|
|
|
|
try_close(fdes, fname);
|
|
|
|
try_unlink(fname);
|
|
|
|
} /* Remove */
|
|
|
|
|
|
|
|
int get_mode(name)
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
struct stat stbf1;
|
|
|
|
|
|
|
|
if (stat(name, &stbf1) != OK) {
|
2011-12-16 15:45:53 +01:00
|
|
|
e(92);
|
2005-04-21 16:53:53 +02:00
|
|
|
return(stbf1.st_mode); /* return a mode which will cause *
|
|
|
|
* error in the calling function *
|
|
|
|
* (file/dir bit) */
|
|
|
|
} else
|
|
|
|
return(stbf1.st_mode & 07777); /* take last 4 bits */
|
|
|
|
} /* get_mode */
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* *
|
|
|
|
* ALOT-functions *
|
|
|
|
* *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
int open_alot()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXOPEN; i++)
|
2010-07-13 14:38:58 +02:00
|
|
|
if (open(filenames[i], R) == FAIL) break;
|
2011-12-16 15:45:53 +01:00
|
|
|
if (i == 0) e(93);
|
2005-04-21 16:53:53 +02:00
|
|
|
return(i);
|
|
|
|
} /* open_alot */
|
|
|
|
|
|
|
|
int close_alot(number)
|
|
|
|
int number;
|
|
|
|
{
|
|
|
|
int i, count = 0;
|
|
|
|
|
|
|
|
if (number > MAXOPEN)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(94);
|
2005-04-21 16:53:53 +02:00
|
|
|
else
|
|
|
|
for (i = FF; i < number + FF; i++)
|
|
|
|
if (close(i) != OK) count++;
|
|
|
|
|
|
|
|
return(number - count); /* return number of closed files */
|
|
|
|
} /* close_alot */
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* *
|
|
|
|
* CLEAN UP THE MESS *
|
|
|
|
* *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
void clean_up_the_mess()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char dirname[6];
|
|
|
|
|
|
|
|
/* First remove 'a lot' files */
|
2010-07-13 14:38:58 +02:00
|
|
|
for (i = 0; i < MAXOPEN; i++) {
|
|
|
|
try_unlink(filenames[i]);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Unlink the files in dir 'drwx' */
|
|
|
|
if (chdir("drwx") != OK)
|
2011-12-16 15:45:53 +01:00
|
|
|
e(95);
|
2005-04-21 16:53:53 +02:00
|
|
|
else {
|
2010-07-13 14:38:58 +02:00
|
|
|
for (i = 0; i < MODES; i++) {
|
|
|
|
try_unlink(mode_fnames[i]);
|
|
|
|
}
|
2011-12-16 15:45:53 +01:00
|
|
|
if (chdir("..") != OK) e(96);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Before unlinking files in some dirs, make them writable */
|
|
|
|
chmod_8_dirs(RWX);
|
|
|
|
|
|
|
|
/* Unlink files in other dirs */
|
|
|
|
try_unlink("d-wx/rwx");
|
|
|
|
try_unlink("dr-x/rwx");
|
|
|
|
try_unlink("drw-/rwx");
|
|
|
|
|
|
|
|
/* Unlink dirs */
|
2010-07-13 14:38:58 +02:00
|
|
|
for (i = 0; i < MODES; i++) {
|
2005-04-21 16:53:53 +02:00
|
|
|
strcpy(dirname, "d");
|
2010-07-13 14:38:58 +02:00
|
|
|
strcat(dirname, mode_fnames[i]);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* 'dirname' contains the directoryname */
|
|
|
|
rmdir(dirname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FINISH */
|
|
|
|
} /* clean_up_the_mess */
|
|
|
|
|
|
|
|
void chmod_8_dirs(sw)
|
|
|
|
int sw; /* if switch == 8, give all different
|
|
|
|
* mode,else the same mode */
|
|
|
|
{
|
|
|
|
int mode;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (sw == 8)
|
|
|
|
mode = 0;
|
|
|
|
else
|
|
|
|
mode = sw;
|
|
|
|
|
2010-07-13 14:38:58 +02:00
|
|
|
for (i = 0; i < MODES; i++) {
|
|
|
|
chmod(mode_dir[i], 040000 + mode * 0100);
|
2005-04-21 16:53:53 +02:00
|
|
|
if (sw == 8) mode++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|