djbdnscurve6 46
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(char *home,int uid,int gid,int mode)
16{
17 if (mkdir(home,0700) == -1)
18 if (errno != EEXIST)
19 logmsg(WHO,111,FATAL,B("unable to mkdir: ",home));
20 if (chown(home,uid,gid) == -1)
21 logmsg(WHO,111,FATAL,B("unable to chown: ",home));
22 if (chmod(home,mode) == -1)
23 logmsg(WHO,111,FATAL,B("unable to chmod: ",home));
24}
25
26void d(char *home,char *subdir,int uid,int gid,int mode)
27{
28 if (chdir(home) == -1)
29 logmsg(WHO,111,FATAL,B("unable to switch to: ",home));
30 if (mkdir(subdir,0700) == -1)
31 if (errno != EEXIST)
32 logmsg(WHO,111,FATAL,B("unable to mkdir: ",home,"/",subdir));
33 if (chown(subdir,uid,gid) == -1)
34 logmsg(WHO,111,FATAL,B("unable to chown: ",home,"/",subdir));
35 if (chmod(subdir,mode) == -1)
36 logmsg(WHO,111,FATAL,B("unable to chmod: ",home,"/",subdir));
37}
38
39char inbuf[BUFFER_INSIZE];
40char outbuf[BUFFER_OUTSIZE];
41buffer ssin;
42buffer ssout;
43
44void c(char *home,char *subdir,char *file,int uid,int gid,int mode)
45{
46 int fdin;
47 int fdout;
48
49 if (fchdir(fdsourcedir) == -1)
50 logmsg(WHO,111,FATAL,"unable to switch back to source directory");
51
52 fdin = open_read(file);
53 if (fdin == -1)
54 logmsg(WHO,111,FATAL,B("unable to read: ",file));
55 buffer_init(&ssin,buffer_unixread,fdin,inbuf,sizeof(inbuf));
56
57 if (chdir(home) == -1)
58 logmsg(WHO,111,FATAL,B("unable to switch to: ",home));
59 if (chdir(subdir) == -1)
60 logmsg(WHO,111,FATAL,B("unable to switch to: ",home,"/",subdir));
61
62 fdout = open_trunc(file);
63 if (fdout == -1)
64 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
65 buffer_init(&ssout,buffer_unixwrite,fdout,outbuf,sizeof(outbuf));
66
67 switch(buffer_copy(&ssout,&ssin)) {
68 case -2:
69 logmsg(WHO,111,FATAL,B("unable to read: ",file));
70 case -3:
71 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
72 }
73
74 close(fdin);
75 if (buffer_flush(&ssout) == -1)
76 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
77 if (fsync(fdout) == -1)
78 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
79 if (close(fdout) == -1) /* NFS silliness */
80 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
81
82 if (chown(file,uid,gid) == -1)
83 logmsg(WHO,111,FATAL,B("unable to chown: .../",subdir,"/",file));
84 if (chmod(file,mode) == -1)
85 logmsg(WHO,111,FATAL,B("unable to chmod: .../",subdir,"/",file));
86}
87
88void z(char *home,char *subdir,char *file,int len,int uid,int gid,int mode)
89{
90 int fdout;
91
92 if (chdir(home) == -1)
93 logmsg(WHO,111,FATAL,B("unable to switch to: ",home));
94 if (chdir(subdir) == -1)
95 logmsg(WHO,111,FATAL,B("unable to switch to: ",home,"/",subdir));
96
97 fdout = open_trunc(file);
98 if (fdout == -1)
99 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
100 buffer_init(&ssout,buffer_unixwrite,fdout,outbuf,sizeof(outbuf));
101
102 while (len-- > 0)
103 if (buffer_put(&ssout,"",1) == -1)
104 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
105
106 if (buffer_flush(&ssout) == -1)
107 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
108 if (fsync(fdout) == -1)
109 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
110 if (close(fdout) == -1) /* NFS silliness */
111 logmsg(WHO,111,FATAL,B("unable to write: .../",subdir,"/",file));
112
113 if (chown(file,uid,gid) == -1)
114 logmsg(WHO,111,FATAL,B("unable to chown: .../",subdir,"/",file));
115 if (chmod(file,mode) == -1)
116 logmsg(WHO,111,FATAL,B("unable to chmod: .../",subdir,"/",file));
117}
118
119int main()
120{
121 fdsourcedir = open_read(".");
122 if (fdsourcedir == -1)
123 logmsg(WHO,111,FATAL,"unable to open current directory");
124
125 umask(077);
126 hier();
127 _exit(0);
128}
#define WHO
Definition axfr-get.c:16
uint16 len
Definition axfrdns.c:319
char inbuf[1024]
Definition dnsfilter.c:40
void d(char *home, char *subdir, int uid, int gid, int mode)
Definition install.c:26
buffer ssout
Definition install.c:42
void c(char *home, char *subdir, char *file, int uid, int gid, int mode)
Definition install.c:44
void hier()
Definition hier.c:7
void z(char *home, char *subdir, char *file, int len, int uid, int gid, int mode)
Definition install.c:88
void h(char *home, int uid, int gid, int mode)
Definition install.c:15
buffer ssin
Definition install.c:41
char outbuf[BUFFER_OUTSIZE]
Definition install.c:40
int main()
Definition install.c:119
int fdsourcedir
Definition install.c:13
char mode