| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #include "config.hh" |
|---|
| 21 | |
|---|
| 22 | #include <cerrno> |
|---|
| 23 | #include <cstdlib> |
|---|
| 24 | #include <fstream> |
|---|
| 25 | #include <iostream> |
|---|
| 26 | #include <sys/resource.h> |
|---|
| 27 | #include <sys/utsname.h> |
|---|
| 28 | #include <unistd.h> |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | boost::program_options::variables_map config; |
|---|
| 32 | |
|---|
| 33 | void configure(int argc, char *argv[], rlimit &rlim) |
|---|
| 34 | { |
|---|
| 35 | namespace po = boost::program_options; |
|---|
| 36 | |
|---|
| 37 | if (getrlimit(RLIMIT_AS, &rlim) == -1) |
|---|
| 38 | { |
|---|
| 39 | std::cerr << "getrlimit failed: " << strerror(errno) |
|---|
| 40 | << std::endl; |
|---|
| 41 | std::exit(1); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | struct utsname uts; |
|---|
| 45 | if (uname(&uts) == -1) |
|---|
| 46 | { |
|---|
| 47 | std::cerr << "uname failed: " << strerror(errno) << std::endl; |
|---|
| 48 | std::exit(1); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | po::options_description opts; |
|---|
| 53 | opts.add_options() |
|---|
| 54 | ( "help", "show this help message") |
|---|
| 55 | ( "executable", |
|---|
| 56 | po::value<std::string>()->default_value(argv[0]), |
|---|
| 57 | "the location of a debuggable executable (for backtraces)" ) |
|---|
| 58 | ( "daemon", |
|---|
| 59 | po::value<bool>()->default_value(true), |
|---|
| 60 | "create a daemon process and exit immediately afterward") |
|---|
| 61 | ( "user", po::value<std::string>(), |
|---|
| 62 | "the user to run as (if started as root)") |
|---|
| 63 | ( "canonical-name", |
|---|
| 64 | po::value<std::string>()->default_value(uts.nodename), |
|---|
| 65 | "the canonical name of this host" ) |
|---|
| 66 | ("nntp-port", |
|---|
| 67 | po::value<std::string>()->default_value("119"), |
|---|
| 68 | "the port to listen on for NNTP clients") |
|---|
| 69 | ("nntps-port", |
|---|
| 70 | po::value<std::string>()->default_value("563"), |
|---|
| 71 | "the port to listen on for NNTP/SSL clients") |
|---|
| 72 | ("https-port", |
|---|
| 73 | po::value<std::string>()->default_value("443"), |
|---|
| 74 | "the port to listen on for HTTPS clients") |
|---|
| 75 | ("unix-socket", |
|---|
| 76 | po::value<std::string>()->default_value("alue-socket"), |
|---|
| 77 | "the Unix socket (in the home directory) to listen for" |
|---|
| 78 | " email injections") |
|---|
| 79 | ("key-file", |
|---|
| 80 | po::value<std::string>()->default_value("key.pem"), |
|---|
| 81 | "the file containing the SSL/TLS private key") |
|---|
| 82 | ("cert-file", |
|---|
| 83 | po::value<std::string>()->default_value("cert.pem"), |
|---|
| 84 | "the file containing the SSL/TLS certificate") |
|---|
| 85 | ("log-smtp", |
|---|
| 86 | po::value<bool>()->default_value(false), |
|---|
| 87 | "log SMTP extensively") |
|---|
| 88 | ("log-http", |
|---|
| 89 | po::value<bool>()->default_value(false), |
|---|
| 90 | "log HTTP extensively (warning - user privacy invasive)") |
|---|
| 91 | ("log-nntp", |
|---|
| 92 | po::value<bool>()->default_value(false), |
|---|
| 93 | "log HTTP extensively (warning - user privacy invasive)") |
|---|
| 94 | ("logfile", |
|---|
| 95 | po::value<std::string>()->default_value("alue.log"), |
|---|
| 96 | "the name of the logfile") |
|---|
| 97 | ("vm-limit", |
|---|
| 98 | po::value<rlim_t>(&rlim.rlim_cur)->default_value(rlim.rlim_cur), |
|---|
| 99 | "the AS (virtual memory) resource limit for this process") |
|---|
| 100 | ("include-dir", |
|---|
| 101 | po::value<std::string>()->default_value("templates/"), |
|---|
| 102 | "include directory name") |
|---|
| 103 | ("files-dir", |
|---|
| 104 | po::value<std::string>()->default_value("templates/"), |
|---|
| 105 | "verbatim HTTPS file directory name") |
|---|
| 106 | ("config-file", |
|---|
| 107 | po::value<std::string>()->default_value(CONFFILE), |
|---|
| 108 | "name of the the configuration file") |
|---|
| 109 | ("db-file", |
|---|
| 110 | po::value<std::string>()->default_value("alue.db2"), |
|---|
| 111 | "name of the database file") |
|---|
| 112 | ("pw-file", |
|---|
| 113 | po::value<std::string>()->default_value("passwds"), |
|---|
| 114 | "name of the passwords file") |
|---|
| 115 | ("home", |
|---|
| 116 | po::value<std::string>()->default_value("/"), |
|---|
| 117 | "name of the daemon home directory") |
|---|
| 118 | ("alue-name", |
|---|
| 119 | po::value<std::string>()->default_value("Alue"), |
|---|
| 120 | "the 'real name' Alue should use of itself") |
|---|
| 121 | ("operator-email", |
|---|
| 122 | po::value<std::string>(), |
|---|
| 123 | "a human operator's email address"); |
|---|
| 124 | po::store(po::parse_command_line(argc, argv, opts), config); |
|---|
| 125 | { |
|---|
| 126 | std::string config_file_name = |
|---|
| 127 | config["config-file"].as<std::string>(); |
|---|
| 128 | std::ifstream config_file(config_file_name.c_str()); |
|---|
| 129 | if (config_file) |
|---|
| 130 | po::store(po::parse_config_file(config_file, opts), |
|---|
| 131 | config); |
|---|
| 132 | } |
|---|
| 133 | po::notify(config); |
|---|
| 134 | |
|---|
| 135 | if (config.count("help") > 0) |
|---|
| 136 | { |
|---|
| 137 | std::cout << opts << std::endl; |
|---|
| 138 | std::exit(0); |
|---|
| 139 | } |
|---|
| 140 | } |
|---|