djbdnscurve6 45
djbdnscurve6
Loading...
Searching...
No Matches
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
9extern void hier();
10
11#define WHO "install"
12
13int fdsourcedir = -1;
14
15void h(home,uid,gid,mode)
16char *home;
17int uid;
18int gid;
19int 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
30void d(home,subdir,uid,gid,mode)
31char *home;
32char *subdir;
33int uid;
34int gid;
35int 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
48char inbuf[BUFFER_INSIZE];
49char outbuf[BUFFER_OUTSIZE];
50buffer ssin;
51buffer ssout;
52
53void c(home,subdir,file,uid,gid,mode)
54char *home;
55char *subdir;
56char *file;
57int uid;
58int gid;
59int 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
103void z(home,subdir,file,len,uid,gid,mode)
104char *home;
105char *subdir;
106char *file;
107int len;
108int uid;
109int gid;
110int 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
141int 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:319
void c(const char *home, const char *subdir, const char *file, int uid, int gid, int mode)
void d(const char *home, const char *subdir, int uid, int gid, int mode)
buffer ssout
Definition: install.c:51
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:45