s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
install.c
Go to the documentation of this file.
1#include <unistd.h>
2#include <sys/stat.h>
3#include "buffer.h"
4#include "logmsg.h"
5#include "open.h"
6#include "exit.h"
7#include "fifo.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,110,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
39void p(char *home,char *fifo,int uid,int gid,int mode)
40{
41 if (chdir(home) == -1)
42 logmsg(WHO,110,FATAL,B("unable to switch to: ",home));
43 if (fifo_make(fifo,0700) == -1)
44 if (errno != EEXIST)
45 logmsg(WHO,111,FATAL,B("unable to mkfifo: ",home,"/",fifo));
46 if (chown(fifo,uid,gid) == -1)
47 logmsg(WHO,111,FATAL,B("unable to chown: ",home,"/",fifo));
48 if (chmod(fifo,mode) == -1)
49 logmsg(WHO,111,FATAL,B("unable to chmod: ",home,"/",fifo));
50}
51
52char inbuf[BUFFER_INSIZE];
53buffer bi;
54char outbuf[BUFFER_OUTSIZE];
55buffer bo;
56
57void c(char *home,char *subdir,char *file,int uid,int gid,int mode)
58{
59 int fdin;
60 int fdout;
61
62 if (fchdir(fdsourcedir) == -1)
63 logmsg(WHO,110,FATAL,"unable to switch back to source directory: ");
64
65 fdin = open_read(file);
66 if (fdin == -1)
67 logmsg(WHO,111,FATAL,B("unable to read: ",file));
68 buffer_init(&bi,read,fdin,inbuf,sizeof(inbuf));
69
70 if (chdir(home) == -1)
71 logmsg(WHO,110,FATAL,B("unable to switch to: ",home));
72 if (chdir(subdir) == -1)
73 logmsg(WHO,110,FATAL,B("unable to switch to: ",home,"/",subdir));
74
75 fdout = open_trunc(file);
76 if (fdout == -1)
77 logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
78 buffer_init(&bo,write,fdout,outbuf,sizeof(outbuf));
79
80 switch (buffer_copy(&bo,&bi)) {
81 case -2:
82 logmsg(WHO,111,FATAL,B("unable to read: ",file));
83 case -3:
84 logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
85 }
86
87 close(fdin);
88 if (buffer_flush(&bo) == -1)
89 logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
90 if (fsync(fdout) == -1)
91 logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
92 if (close(fdout) == -1) /* NFS silliness */
93 logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
94
95 if (chown(file,uid,gid) == -1)
96 logmsg(WHO,111,FATAL,B("unable to chown .../",subdir,"/",file));
97 if (chmod(file,mode) == -1)
98 logmsg(WHO,111,FATAL,B("unable to chmod .../",subdir,"/",file));
99}
100
101void z(char *home,char *file,int len,int uid,int gid,int mode)
102{
103 int fdout;
104
105 if (chdir(home) == -1)
106 logmsg(WHO,110,FATAL,B("unable to switch to: ",home));
107
108 fdout = open_trunc(file);
109 if (fdout == -1)
110 logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
111 buffer_init(&bo,write,fdout,outbuf,sizeof(outbuf));
112
113 while (len-- > 0)
114 if (buffer_put(&bo,"",1) == -1)
115 logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
116
117 if (buffer_flush(&bo) == -1)
118 logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
119 if (fsync(fdout) == -1)
120 logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
121 if (close(fdout) == -1) /* NFS silliness */
122 logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
123
124 if (chown(file,uid,gid) == -1)
125 logmsg(WHO,111,FATAL,B("unable to chown: ",home,"/",file));
126 if (chmod(file,mode) == -1)
127 logmsg(WHO,111,FATAL,B("unable to chmod: ",home,"/",file));
128}
129
130int main()
131{
132 fdsourcedir = open_read(".");
133 if (fdsourcedir == -1)
134 logmsg(WHO,110,FATAL,"unable to open current directory: ");
135
136 umask(077);
137 hier();
138 _exit(0);
139}
stralloc file
Definition: columnt.c:20
void _exit()
int fifo_make(char *fn, int mode)
Definition: fifo.c:8
void c(char *, char *, char *, int, int, int)
Definition: install.c:57
void p(char *home, char *fifo, int uid, int gid, int mode)
Definition: install.c:39
void hier()
Definition: hier.c:30
char inbuf[BUFFER_INSIZE]
Definition: install.c:52
buffer bi
Definition: install.c:53
void h(char *home, int uid, int gid, int mode)
Definition: install.c:15
void z(char *home, char *file, int len, int uid, int gid, int mode)
Definition: install.c:101
char outbuf[BUFFER_OUTSIZE]
Definition: install.c:54
buffer bo
Definition: install.c:55
#define WHO
Definition: install.c:11
int main()
Definition: install.c:130
int fdsourcedir
Definition: install.c:13
ulongalloc uid
Definition: matchup.c:58
stralloc home
Definition: qmail-pw2u.c:98
struct del * d[CHANNELS]
Definition: qmail-send.c:720
int fdin
Definition: qmail-todo.c:144
int fdout
Definition: qmail-todo.c:143
void write()