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