1
/* $Id: syscall_chroot.c 61 2006-05-19 18:32:14Z steve-beattie $ */
4
* Copyright (C) 2002-2005 Novell/SUSE
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
15
#include <sys/types.h>
21
struct dirlist * next;
26
read_directory (char * dirname) {
29
struct dirent * dirent;
30
struct dirlist * dirlist = NULL, * tmp;
32
if (!dirname) return NULL;
33
dir = opendir (dirname);
36
perror ("FAIL: couldn't open directory");
40
while ((dirent = readdir (dir)) != NULL) {
41
tmp = malloc (sizeof (struct dirlist));
43
perror ("FAIL: failed allocation");
47
memcpy (&tmp->dirent, dirent, sizeof (struct dirent));
50
/* printf ("Adding '%s'\n", tmp->dirent.d_name); */
57
contains_dir (struct dirlist * dirlist, char * dirname) {
58
struct dirlist * this;
60
for (this = dirlist; this != NULL; this = this->next)
61
if (strcmp (this->dirent.d_name, dirname) == 0)
68
compare_dirlists (struct dirlist * a, struct dirlist * b) {
69
struct dirlist * this;
71
for (this = a; this != NULL; this = this->next)
72
if (!contains_dir (b, this->dirent.d_name))
75
for (this = b; this != NULL; this = this->next)
76
if (!contains_dir (a, this->dirent.d_name))
83
int main(int argc, char *argv[])
85
struct dirlist * before, * after;
88
fprintf(stderr, "usage: %s <dir>\n",
93
before = read_directory("/");
95
if (chroot(argv[1]) == -1) {
96
perror("FAIL: chroot failed");
100
after = read_directory("/");
102
if (compare_dirlists(before, after) == 0) {
103
fprintf (stderr, "FAIL: root directories are the same\n");