Commit | Line | Data |
---|---|---|
dc0d77d7 CE |
1 | #include <unistd.h> |
2 | #include <sys/types.h> | |
3 | #include <sys/stat.h> | |
4 | #include "buffer.h" | |
5 | #include "strerr.h" | |
6 | #include "error.h" | |
7 | #include "open.h" | |
8 | #include "exit.h" | |
9 | ||
10 | extern void hier(); | |
11 | ||
12 | #define FATAL "install: fatal: " | |
13 | ||
14 | int fdsourcedir = -1; | |
15 | ||
16 | void h(home,uid,gid,mode) | |
17 | char *home; | |
18 | int uid; | |
19 | int gid; | |
20 | int mode; | |
21 | { | |
22 | if (mkdir(home,0700) == -1) | |
23 | if (errno != error_exist) | |
24 | strerr_die4sys(111,FATAL,"unable to mkdir ",home,": "); | |
25 | if (chown(home,uid,gid) == -1) | |
26 | strerr_die4sys(111,FATAL,"unable to chown ",home,": "); | |
27 | if (chmod(home,mode) == -1) | |
28 | strerr_die4sys(111,FATAL,"unable to chmod ",home,": "); | |
29 | } | |
30 | ||
31 | void d(home,subdir,uid,gid,mode) | |
32 | char *home; | |
33 | char *subdir; | |
34 | int uid; | |
35 | int gid; | |
36 | int mode; | |
37 | { | |
38 | if (chdir(home) == -1) | |
39 | strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); | |
40 | if (mkdir(subdir,0700) == -1) | |
41 | if (errno != error_exist) | |
42 | strerr_die6sys(111,FATAL,"unable to mkdir ",home,"/",subdir,": "); | |
43 | if (chown(subdir,uid,gid) == -1) | |
44 | strerr_die6sys(111,FATAL,"unable to chown ",home,"/",subdir,": "); | |
45 | if (chmod(subdir,mode) == -1) | |
46 | strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",subdir,": "); | |
47 | } | |
48 | ||
49 | char inbuf[BUFFER_INSIZE]; | |
50 | char outbuf[BUFFER_OUTSIZE]; | |
51 | buffer ssin; | |
52 | buffer ssout; | |
53 | ||
54 | void c(home,subdir,file,uid,gid,mode) | |
55 | char *home; | |
56 | char *subdir; | |
57 | char *file; | |
58 | int uid; | |
59 | int gid; | |
60 | int mode; | |
61 | { | |
62 | int fdin; | |
63 | int fdout; | |
64 | ||
65 | if (fchdir(fdsourcedir) == -1) | |
66 | strerr_die2sys(111,FATAL,"unable to switch back to source directory: "); | |
67 | ||
68 | fdin = open_read(file); | |
69 | if (fdin == -1) | |
70 | strerr_die4sys(111,FATAL,"unable to read ",file,": "); | |
71 | buffer_init(&ssin,buffer_unixread,fdin,inbuf,sizeof inbuf); | |
72 | ||
73 | if (chdir(home) == -1) | |
74 | strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); | |
75 | if (chdir(subdir) == -1) | |
76 | strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); | |
77 | ||
78 | fdout = open_trunc(file); | |
79 | if (fdout == -1) | |
80 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
81 | buffer_init(&ssout,buffer_unixwrite,fdout,outbuf,sizeof outbuf); | |
82 | ||
83 | switch(buffer_copy(&ssout,&ssin)) { | |
84 | case -2: | |
85 | strerr_die4sys(111,FATAL,"unable to read ",file,": "); | |
86 | case -3: | |
87 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
88 | } | |
89 | ||
90 | close(fdin); | |
91 | if (buffer_flush(&ssout) == -1) | |
92 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
93 | if (fsync(fdout) == -1) | |
94 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
95 | if (close(fdout) == -1) /* NFS silliness */ | |
96 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
97 | ||
98 | if (chown(file,uid,gid) == -1) | |
99 | strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": "); | |
100 | if (chmod(file,mode) == -1) | |
101 | strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": "); | |
102 | } | |
103 | ||
104 | void z(home,subdir,file,len,uid,gid,mode) | |
105 | char *home; | |
106 | char *subdir; | |
107 | char *file; | |
108 | int len; | |
109 | int uid; | |
110 | int gid; | |
111 | int mode; | |
112 | { | |
113 | int fdout; | |
114 | ||
115 | if (chdir(home) == -1) | |
116 | strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); | |
117 | if (chdir(subdir) == -1) | |
118 | strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); | |
119 | ||
120 | fdout = open_trunc(file); | |
121 | if (fdout == -1) | |
122 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
123 | buffer_init(&ssout,buffer_unixwrite,fdout,outbuf,sizeof outbuf); | |
124 | ||
125 | while (len-- > 0) | |
126 | if (buffer_put(&ssout,"",1) == -1) | |
127 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
128 | ||
129 | if (buffer_flush(&ssout) == -1) | |
130 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
131 | if (fsync(fdout) == -1) | |
132 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
133 | if (close(fdout) == -1) /* NFS silliness */ | |
134 | strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": "); | |
135 | ||
136 | if (chown(file,uid,gid) == -1) | |
137 | strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": "); | |
138 | if (chmod(file,mode) == -1) | |
139 | strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": "); | |
140 | } | |
141 | ||
142 | int main() | |
143 | { | |
144 | fdsourcedir = open_read("."); | |
145 | if (fdsourcedir == -1) | |
146 | strerr_die2sys(111,FATAL,"unable to open current directory: "); | |
147 | ||
148 | umask(077); | |
149 | hier(); | |
150 | _exit(0); | |
151 | } |