djbdnscurve6 46
djbdnscurve6
Loading...
Searching...
No Matches
generic-conf.c
Go to the documentation of this file.
1#include <unistd.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include "logmsg.h"
5#include "buffer.h"
6#include "open.h"
7#include "generic-conf.h"
8
9static const char *fatal;
10static const char *dir;
11static const char *fn;
12
13static int fd;
14static char buf[1024];
15static buffer ss;
16
17void init(const char *d,const char *f)
18{
19 dir = d;
20 fatal = f;
21 umask(022);
22 if (mkdir(dir,0700) == -1)
23 logmsg(fatal,111,FATAL,B("unable to create: ",dir));
24 if (chmod(dir,03755) == -1)
25 logmsg(fatal,111,FATAL,B("unable to set mode of: ",dir));
26 if (chdir(dir) == -1)
27 logmsg(fatal,111,FATAL,B("unable to switch to: ",dir));
28}
29
30void fail(void)
31{
32 logmsg(fatal,111,FATAL,B("unable to create: ",dir,"/",fn));
33}
34
35void makedir(const char *s)
36{
37 fn = s;
38 if (mkdir(fn,0700) == -1) fail();
39}
40
41void start(const char *s)
42{
43 fn = s;
44 fd = open_trunc(fn);
45 if (fd == -1) fail();
46 buffer_init(&ss,buffer_unixwrite,fd,buf,sizeof(buf));
47}
48
49void outs(const char *s)
50{
51 if (buffer_puts(&ss,s) == -1) fail();
52}
53
54void out(const char *s,unsigned int len)
55{
56 if (buffer_put(&ss,s,len) == -1) fail();
57}
58
59void copyfrom(buffer *b)
60{
61 if (buffer_copy(&ss,b) < 0) fail();
62}
63
64void finish(void)
65{
66 if (buffer_flush(&ss) == -1) fail();
67 if (fsync(fd) == -1) fail();
68 close(fd);
69}
70
71void perm(int mode)
72{
73 if (chmod(fn,mode) == -1) fail();
74}
75
76void owner(int uid,int gid)
77{
78 if (chown(fn,uid,gid) == -1) fail();
79}
80
81void makelog(const char *user,int uid,int gid)
82{
83 makedir("log");
84 perm(02755);
85 makedir("log/main");
86 owner(uid,gid);
87 perm(02755);
88 start("log/status");
89 finish();
90 owner(uid,gid);
91 perm(0644);
92
93 start("log/run");
94 outs("#!/bin/sh\nexec");
95 outs(" setuidgid "); outs(user);
96 outs(" multilog t ./main\n");
97 finish();
98 perm(0755);
99}
buffer b
Definition auto-str.c:5
int fd
Definition axfr-get.c:103
char * fn
Definition axfr-get.c:53
char * user
char * dir
uint16 len
Definition axfrdns.c:319
char buf[MSGSIZE]
Definition axfrdns.c:318
void owner(int uid, int gid)
void outs(const char *s)
void init(const char *d, const char *f)
void start(const char *s)
void copyfrom(buffer *b)
void makedir(const char *s)
void perm(int mode)
void finish(void)
void fail(void)
void out(const char *s, unsigned int len)
void makelog(const char *user, int uid, int gid)
char mode