Mail Archives: djgpp-workers/1999/02/22/18:18:41
Here's my first try at implementing chroot. I've modified putpath.c and
unistd.h. New is chroot.c.
Without a reference I can check, I'm assuming in these patches that
chroot is POSIX. Let me know if my assumption was wrong. With the
patches.
These patches allow code like this to print "0" assuming you have gcc
installed:
int status;
chroot ("c:/djgpp");
status = access ("bin/gcc.exe");
printf("status = %i\n", status);
I'll post my first cut at documenting 'chroot' tommorrow.
Mark
*** include/unistd.h.orig Mon Jun 29 00:02:48 1998
--- include/unistd.h Mon Feb 22 17:59:00 1999
***************
*** 76,81 ****
--- 76,82 ----
unsigned int alarm(unsigned int _seconds);
int chdir(const char *_path);
int chown(const char *_path, uid_t _owner, gid_t _group);
+ int chroot(const char *_path);
int close(int _fildes);
char * ctermid(char *_s);
int dup(int _fildes);
*** src/libc/dos/io/putpath.c.orig Thu Oct 29 10:24:44 1998
--- src/libc/dos/io/putpath.c Mon Feb 22 18:02:02 1999
***************
*** 7,12 ****
--- 7,15 ----
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+ #include <unistd.h>
+
+ extern char _djgpp_root[];
void
_put_path(const char *path)
***************
*** 49,54 ****
--- 52,78 ----
}
else if (p[5])
path = p + 5;
+ }
+ /* If the path is absolute and a root path is set,
+ then add the root path to the output. */
+ else if (path[0] == '/' && _djgpp_root[0] != '\0')
+ {
+ char *root = _djgpp_root;
+ char *abs_root = _djgpp_root;
+ if (abs_root[0] && abs_root[1] == ':')
+ abs_root += 2;
+ if (strncmp (abs_root, "/dev/", 5) == 0)
+ {
+ _farnspokeb (o++, abs_root[5]);
+ _farnspokeb (o++, ':');
+ space -= 2;
+ root = abs_root + 6;
+ }
+ for ( ; *root; root++)
+ {
+ _farnspokeb (o++, *root);
+ space -= 1;
+ }
}
/* collapse multiple slashes to a single slash */
*** chroot.c Mon Feb 22 18:05:28 1999
--- src/libc/posix/unistd/chroot.c Mon Feb 22 17:53:42 1999
***************
*** 0 ****
--- 1,22 ----
+
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <limits.h>
+ #include <sys/stat.h>
+
+ char _djgpp_root [PATH_MAX+1] = { '\0' };
+
+ int
+ chroot (const char *path)
+ {
+ if (path == NULL || *path == '\0')
+ {
+ _djgpp_root[0] = '\0';
+ return 0;
+ }
+
+ _fixpath (path, _djgpp_root);
+
+ return 0;
+ }
+
---
Mark Elbrecht
snowball3 AT usa DOT net http://members.xoom.com/snowball3/
- Raw text -