-
Notifications
You must be signed in to change notification settings - Fork 1
/
twoftpd-conf.c
105 lines (93 loc) · 3.16 KB
/
twoftpd-conf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* twoftpd-conf.c - Configure a new instance of twoftpd auth/xfer
* Copyright (C) 2008 Bruce Guenter <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "conf.h"
#include "conf_bin.c"
#include <bglibs/iobuf.h>
#include <bglibs/msg.h>
const char program[] = "twoftpd-conf";
static const char usage_str[] =
"usage: twoftpd-conf logacct /twoftpd /var/log/twoftpd cvm [ip [chroot]]\n";
void usage(const char* msg)
{
if (msg)
obuf_put4s(&outbuf, program, ": ", msg, ".\n");
obuf_puts(&outbuf, usage_str);
obuf_flush(&outbuf);
exit(1);
}
static struct passwd* logacct;
static const char* maindir;
static const char* logdir;
static const char* cvmpath;
static const char* ip = "0.0.0.0";
static const char* dochroot;
int main(int argc, char* argv[])
{
if (argc < 5) usage("Too few parameters");
if (argc > 7) usage("Too many parameters");
logacct = getpwnam(argv[1]);
maindir = argv[2];
logdir = argv[3];
if (maindir[0] != '/' || logdir[0] != '/')
die1(1, "Directory names must start with /.");
cvmpath = argv[4];
if (argc > 5) {
ip = argv[5];
if (argc > 6) dochroot = argv[6];
}
if (!logacct) die1(1, "Unknown logacct user name");
umask(0);
if (mkdir(maindir, 0755) == -1) die1sys(1, "Error creating main directory");
if (chmod(maindir, 01755) == -1)
die1sys(1, "Error setting permissions on main directory");
if (mkdir(logdir, 0700) == -1) die1sys(1, "Error creating log directory");
if (chown(logdir, logacct->pw_uid, logacct->pw_gid) == -1)
die1sys(1, "Error setting owner on log directory");
if (chdir(maindir) == -1) die1sys(1, "Error changing to main directory");
if (mkdir("log", 0755) == -1)
die1sys(1, "Error creating log service directory");
if (mkdir("env", 0755) == -1)
die1sys(1, "Error creating env directory");
start_file("run", 0755);
obuf_put5s(&conf_out,
"#!/bin/sh\n"
"exec 2>&1\n"
"umask 022\n"
"exec \\\n"
"tcpserver -DRHv -llocalhost ", ip, " 21 \\\n"
"envdir ", maindir, "/env \\\n");
obuf_put7s(&conf_out,
"softlimit -m 2000000 \\\n",
conf_bin, "/twoftpd-auth \\\n",
cvmpath, " \\\n",
conf_bin, "/twoftpd-xfer");
end_file();
make_file("log/run", 0755,
"#!/bin/sh\n"
"exec \\\n"
"setuidgid ", logacct->pw_name, " \\\n"
"multilog t ", logdir, 0, 0, 0);
if (dochroot) make_fileu("env/CHROOT", 1);
return 0;
}