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