File: copy.devs.c

package info (click to toggle)
maradns 1.2.12.04-1etch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 6,676 kB
  • ctags: 2,176
  • sloc: ansic: 26,137; sh: 3,657; perl: 703; makefile: 622; python: 593; sql: 106; awk: 11
file content (49 lines) | stat: -rw-r--r-- 1,347 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Solaris requires that /dev/tcp, /dev/udp, and /dev/zero are copied to
   the /etc/maradns directory.  This program does just that (alas, a 
   shell script which simply does a "mkdir /etc/maradns/dev; cd /dev;
   cp tcp udp zero /etc/maradns/dev" does not work). 
*/

/* Some locations */
#define DEV_DIRECTORY "/dev"
#define CHROOT_DEV_DIRECTORY "/etc/maradns/dev"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

/* Copy a device special file from DEV_DIRECTORY to CHROOT_DEV_DIRECTORY
   input: The name of the device (e.g. "zero", "null", "tcp", or "udp")
   output: 1; exit program on error
*/

int copy_device(char *devname) {
    struct stat buf;
    if(chdir(DEV_DIRECTORY) != 0) {
        printf("Can not go to dev directory %s\n",DEV_DIRECTORY);
	exit(1);
	}
    if(stat(devname,&buf) != 0) {
        printf("Can not stat %s/%s\n",DEV_DIRECTORY,devname);
	exit(1);
	}
    if(chdir(CHROOT_DEV_DIRECTORY) != 0) {
        printf("Can not go to MaraDNS chroot dev directory %s\n",
	       CHROOT_DEV_DIRECTORY);
        exit(1);
	}
    if(mknod(devname,buf.st_mode,buf.st_rdev) != 0) {
        printf("Can not mknod device %s/%s\n",CHROOT_DEV_DIRECTORY,
	       DEV_DIRECTORY);
	exit(2);
	}
    return 1;
    }

main() {
    copy_device("zero");
    copy_device("tcp");
    copy_device("udp");
    }