28#include "core/or/channelpadding.h"
84#include <event2/event.h>
97# if defined(__COVERITY__) && !defined(__INCLUDE_LEVEL__)
101# define __INCLUDE_LEVEL__ 2
103#include <systemd/sd-daemon.h>
119 log_notice(
LD_GENERAL,
"Received reload signal (hup). Reloading config and "
120 "resetting internal state.");
131 log_err(
LD_CONFIG,
"Reading config failed--see warnings above. "
132 "For usage, try -h.");
134 }
else if (BUG(init_rv > 0)) {
149 log_notice(
LD_GENERAL,
"Not reloading config file: the controller told "
154 msg = tor_strdup(
"Unknown error");
155 log_warn(
LD_GENERAL,
"Unable to re-set previous options: %s", msg);
159 if (authdir_mode(options)) {
163 log_info(
LD_GENERAL,
"Error reloading fingerprints. "
164 "Continuing with old list.");
186 if (server_mode(options)) {
190 int new_signing_key = load_ed_keys(options, now);
191 if (new_signing_key < 0 ||
192 generate_ed_link_cert(options, now, new_signing_key > 0)) {
193 log_warn(
LD_OR,
"Problem reloading Ed25519 keys; still using old keys.");
195 if (load_family_id_keys(options,
197 log_warn(
LD_OR,
"Problem reloading family ID keys; "
198 "still using old keys.");
214 const int *sigptr = arg;
215 const int sig = *sigptr;
230 log_notice(
LD_GENERAL,
"Catching signal TERM, exiting cleanly.");
235 log_notice(
LD_GENERAL,
"Interrupt: exiting cleanly.");
240 sd_notify(0,
"STOPPING=1");
246 log_debug(
LD_GENERAL,
"Caught SIGPIPE. Ignoring.");
256 log_debug(
LD_GENERAL,
"Caught USR2, going to loglevel debug. "
257 "Send HUP to change back.");
262 sd_notify(0,
"RELOADING=1");
265 log_warn(
LD_CONFIG,
"Restart failed (config error?). Exiting.");
270 sd_notify(0,
"READY=1");
283 case SIGCLEARDNSCACHE:
298 log_notice(
LD_GENERAL,
"Going dormant because of controller request.");
310process_win32_console_ctrl(DWORD ctrl_type)
315 activate_signal(SIGINT);
331 dump_dns_mem_usage(severity);
339 time_t now = time(NULL);
341 size_t rbuf_cap, wbuf_cap, rbuf_len, wbuf_len;
348 "Conn %d (socket %d) is a %s, created %d secs ago",
351 (
int)(now - conn->timestamp_created));
354 "Conn %d: %d bytes waiting on inbuf (len %d, last read %d secs ago)",
356 (
int)connection_get_inbuf_len(conn),
358 (
int)(now - conn->timestamp_last_read_allowed));
360 "Conn %d: %d bytes waiting on outbuf "
361 "(len %d, last written %d secs ago)",i,
362 (
int)connection_get_outbuf_len(conn),
364 (
int)(now - conn->timestamp_last_write_allowed));
369 &wbuf_cap, &wbuf_len) == 0) {
371 "Conn %d: %d/%d bytes used on OpenSSL read buffer; "
372 "%d/%d bytes used on write buffer.",
373 i, (
int)rbuf_len, (
int)rbuf_cap, (
int)wbuf_len, (
int)wbuf_cap);
380 } SMARTLIST_FOREACH_END(conn);
387 "Cells processed: %"PRIu64
" padding\n"
388 " %"PRIu64
" create\n"
389 " %"PRIu64
" created\n"
391 " (%"PRIu64
" relayed)\n"
392 " (%"PRIu64
" delivered)\n"
393 " %"PRIu64
" destroy",
402 tor_log(severity,
LD_NET,
"Average packaged cell fullness: %2.3f%%",
406 tor_log(severity,
LD_NET,
"Average delivered cell fullness: %2.3f%%",
420 "Average bandwidth: %"PRIu64
"/%d = %d bytes/sec reading",
425 "Average bandwidth: %"PRIu64
"/%d = %d bytes/sec writing",
431 tor_log(severity,
LD_NET,
"--------------- Dumping memory information:");
453} signal_handlers[] = {
455 { SIGINT, UNIX_ONLY, NULL },
458 { SIGTERM, UNIX_ONLY, NULL },
461 { SIGPIPE, UNIX_ONLY, NULL },
464 { SIGUSR1, UNIX_ONLY, NULL },
467 { SIGUSR2, UNIX_ONLY, NULL },
470 { SIGHUP, UNIX_ONLY, NULL },
473 { SIGXFSZ, UNIX_ONLY, NULL },
476 { SIGCHLD, UNIX_ONLY, NULL },
479 { SIGNEWNYM, 0, NULL },
480 { SIGCLEARDNSCACHE, 0, NULL },
481 { SIGHEARTBEAT, 0, NULL },
482 { SIGACTIVE, 0, NULL },
483 { SIGDORMANT, 0, NULL },
495 for (i = 0; signal_handlers[i].signal_value >= 0; ++i) {
502 signal_handlers[i].signal_event =
508 log_warn(
LD_BUG,
"Error from libevent when adding "
509 "event for signal %d",
512 signal_handlers[i].signal_event =
523 if (enabled) SetConsoleCtrlHandler(process_win32_console_ctrl, TRUE);
529activate_signal(
int signal_num)
532 for (i = 0; signal_handlers[i].signal_value >= 0; ++i) {
534 event_active(signal_handlers[i].
signal_event, EV_SIGNAL, 1);
548 bool running_tor =
false;
575 parsed_cmdline_free(cmdline);
585 log_notice(
LD_GENERAL,
"Tor %s running on %s with Libevent %s, "
586 "%s %s, Zlib %s, Liblzma %s, Libzstd %s and %s %s as libc.",
602 log_notice(
LD_GENERAL,
"Tor can't help you if you use it wrong! "
603 "Learn how to be safe at "
604 "https://support.torproject.org/faq/staying-anonymous/");
606 if (strstr(version,
"alpha") || strstr(version,
"beta"))
607 log_notice(
LD_GENERAL,
"This version is not a stable Tor release. "
608 "Expect more bugs than usual.");
611 log_warn(
LD_GENERAL,
"This build of Tor has been compiled with one "
612 "or more options that might make it less reliable or secure! "
620 tracing_log_warning();
624 log_err(
LD_CONFIG,
"Reading config failed--see warnings above.");
626 }
else if (init_rv > 0) {
647 predicted_ports_init();
651 log_warn(
LD_GENERAL,
"You are running Tor as root. You don't need to, "
652 "and you probably shouldn't.");
677 char *fname = options_get_datadir_fname(options,
"lock");
678 int already_locked = 0;
682 if (err_if_locked && already_locked) {
684 log_warn(
LD_GENERAL,
"It looks like another Tor process is running "
685 "with the same data directory. Waiting 5 seconds to see "
694 log_err(
LD_GENERAL,
"No, it's still there. Exiting.");
730 if (filename && tor_unlink(filename) != 0 && errno != ENOENT) {
731 log_warn(
LD_FS,
"Couldn't unlink %s: %s",
732 filename, strerror(errno));
745 const char *nickname = options->
Nickname;
746 sandbox_disable_getaddrinfo_cache();
748 bool show_rsa = !strcmp(arg,
"") || !strcmp(arg,
"rsa");
749 bool show_ed25519 = !strcmp(arg,
"ed25519");
750 if (!show_rsa && !show_ed25519) {
752 "If you give a key type, you must specify 'rsa' or 'ed25519'. Exiting.");
756 if (!server_mode(options)) {
758 "Clients don't have long-term identity keys. Exiting.");
763 log_err(
LD_GENERAL,
"Error initializing keys; exiting.");
766 if (!(k = get_server_identity_key())) {
767 log_err(
LD_GENERAL,
"Error: missing RSA identity key.");
771 log_err(
LD_BUG,
"Error computing RSA fingerprint");
774 if (!(edkey = get_master_identity_key())) {
775 log_err(
LD_GENERAL,
"Error: missing ed25519 identity key.");
779 printf(
"%s %s\n", nickname, rsa);
784 printf(
"%s %s\n", nickname, ed25519);
804 printf(
"16:%s\n",output);
817 if (!strcmp(arg,
"short")) {
818 how = OPTIONS_DUMP_MINIMAL;
819 }
else if (!strcmp(arg,
"non-builtin")) {
821 fprintf(stderr,
"'non-builtin' is deprecated; use 'short' instead.\n");
822 how = OPTIONS_DUMP_MINIMAL;
823 }
else if (!strcmp(arg,
"full")) {
824 how = OPTIONS_DUMP_ALL;
826 fprintf(stderr,
"No valid argument to --dump-config found!\n");
827 fprintf(stderr,
"Please select 'short' or 'full'.\n");
845 char *fname_key = NULL, *fname_id = NULL, *id_contents = NULL;
848 if (BUG(!fname_base))
851 tor_asprintf(&fname_key,
"%s.secret_family_key", fname_base);
852 tor_asprintf(&fname_id,
"%s.public_family_id", fname_base);
854 if (create_family_id_key(fname_key, &pk) < 0)
857 if (write_str_to_file(fname_id, id_contents, 0) < 0)
860 printf(
"# Generated %s\n", fname_key);
891 printf(
"Saved new Onion Key in file: %s\n", fname);
897 memwipe(&keys, 0,
sizeof(keys));
913 gethostname(hname,
sizeof(hname));
914 tor_add_addrinfo(hname);
918sandbox_init_filter(
void)
924 get_cachedir_fname(
"cached-status"));
927 sandbox_cfg_allow_open_filename(&cfg, tor_strdup(name))
929#define OPENDIR(dir) \
930 sandbox_cfg_allow_opendir_dirname(&cfg, tor_strdup(dir))
932#define OPEN_DATADIR(name) \
933 sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname(name))
935#define OPEN_DATADIR2(name, name2) \
936 sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname2((name), (name2)))
938#define OPEN_DATADIR_SUFFIX(name, suffix) do { \
939 OPEN_DATADIR(name); \
940 OPEN_DATADIR(name suffix); \
943#define OPEN_DATADIR2_SUFFIX(name, name2, suffix) do { \
944 OPEN_DATADIR2(name, name2); \
945 OPEN_DATADIR2(name, name2 suffix); \
950#define OPEN_KEY_DIRECTORY() \
951 OPEN(options->KeyDirectory)
952#define OPEN_CACHEDIR(name) \
953 sandbox_cfg_allow_open_filename(&cfg, get_cachedir_fname(name))
954#define OPEN_CACHEDIR_SUFFIX(name, suffix) do { \
955 OPEN_CACHEDIR(name); \
956 OPEN_CACHEDIR(name suffix); \
958#define OPEN_KEYDIR(name) \
959 sandbox_cfg_allow_open_filename(&cfg, get_keydir_fname(name))
960#define OPEN_KEYDIR_SUFFIX(name, suffix) do { \
962 OPEN_KEYDIR(name suffix); \
968 OPEN_KEY_DIRECTORY();
970 OPEN_CACHEDIR_SUFFIX(
"cached-certs",
".tmp");
971 OPEN_CACHEDIR_SUFFIX(
"cached-consensus",
".tmp");
972 OPEN_CACHEDIR_SUFFIX(
"unverified-consensus",
".tmp");
973 OPEN_CACHEDIR_SUFFIX(
"unverified-microdesc-consensus",
".tmp");
974 OPEN_CACHEDIR_SUFFIX(
"cached-microdesc-consensus",
".tmp");
975 OPEN_CACHEDIR_SUFFIX(
"cached-microdescs",
".tmp");
976 OPEN_CACHEDIR_SUFFIX(
"cached-microdescs.new",
".tmp");
977 OPEN_CACHEDIR_SUFFIX(
"cached-descriptors",
".tmp");
978 OPEN_CACHEDIR_SUFFIX(
"cached-descriptors.new",
".tmp");
979 OPEN_CACHEDIR(
"cached-descriptors.tmp.tmp");
980 OPEN_CACHEDIR_SUFFIX(
"cached-extrainfo",
".tmp");
981 OPEN_CACHEDIR_SUFFIX(
"cached-extrainfo.new",
".tmp");
982 OPEN_CACHEDIR(
"cached-extrainfo.tmp.tmp");
984 OPEN_DATADIR_SUFFIX(
"state",
".tmp");
985 OPEN_DATADIR_SUFFIX(
"sr-state",
".tmp");
986 OPEN_DATADIR_SUFFIX(
"unparseable-desc",
".tmp");
987 OPEN_DATADIR_SUFFIX(
"v3-status-votes",
".tmp");
988 OPEN_DATADIR(
"key-pinning-journal");
989 OPEN(
"/dev/srandom");
990 OPEN(
"/dev/urandom");
993 OPEN(
"/proc/meminfo");
995#ifdef HAVE_MODULE_RELAY
1004 smartlist_free(family_id_files);
1009 OPEN_DATADIR_SUFFIX(
"networkstatus-bridges",
".tmp");
1011 if (authdir_mode(options)) {
1012 OPEN_DATADIR(
"approved-routers");
1013 OPEN_DATADIR_SUFFIX(
"my-consensus-microdesc",
".tmp");
1014 OPEN_DATADIR_SUFFIX(
"my-consensus-ns",
".tmp");
1016 log_notice(
LD_GENERAL,
"Adding V3BandwidthsFile %s to sandboxing set.",
1036 char *torrc_bck = NULL;
1038 sandbox_cfg_allow_rename(&cfg, tor_strdup(
torrc_fname), torrc_bck);
1039 char *torrc_tmp = NULL;
1041 sandbox_cfg_allow_rename(&cfg, torrc_tmp, tor_strdup(
torrc_fname));
1048 if (file_status(f) == FN_DIR) {
1055#define RENAME_SUFFIX(name, suffix) \
1056 sandbox_cfg_allow_rename(&cfg, \
1057 get_datadir_fname(name suffix), \
1058 get_datadir_fname(name))
1060#define RENAME_SUFFIX2(prefix, name, suffix) \
1061 sandbox_cfg_allow_rename(&cfg, \
1062 get_datadir_fname2(prefix, name suffix), \
1063 get_datadir_fname2(prefix, name))
1065#define RENAME_CACHEDIR_SUFFIX(name, suffix) \
1066 sandbox_cfg_allow_rename(&cfg, \
1067 get_cachedir_fname(name suffix), \
1068 get_cachedir_fname(name))
1070#define RENAME_KEYDIR_SUFFIX(name, suffix) \
1071 sandbox_cfg_allow_rename(&cfg, \
1072 get_keydir_fname(name suffix), \
1073 get_keydir_fname(name))
1075 RENAME_CACHEDIR_SUFFIX(
"cached-certs",
".tmp");
1076 RENAME_CACHEDIR_SUFFIX(
"cached-consensus",
".tmp");
1077 RENAME_CACHEDIR_SUFFIX(
"unverified-consensus",
".tmp");
1078 RENAME_CACHEDIR_SUFFIX(
"unverified-microdesc-consensus",
".tmp");
1079 RENAME_CACHEDIR_SUFFIX(
"cached-microdesc-consensus",
".tmp");
1080 RENAME_CACHEDIR_SUFFIX(
"cached-microdescs",
".tmp");
1081 RENAME_CACHEDIR_SUFFIX(
"cached-microdescs",
".new");
1082 RENAME_CACHEDIR_SUFFIX(
"cached-microdescs.new",
".tmp");
1083 RENAME_CACHEDIR_SUFFIX(
"cached-descriptors",
".tmp");
1084 RENAME_CACHEDIR_SUFFIX(
"cached-descriptors",
".new");
1085 RENAME_CACHEDIR_SUFFIX(
"cached-descriptors.new",
".tmp");
1086 RENAME_CACHEDIR_SUFFIX(
"cached-extrainfo",
".tmp");
1087 RENAME_CACHEDIR_SUFFIX(
"cached-extrainfo",
".new");
1088 RENAME_CACHEDIR_SUFFIX(
"cached-extrainfo.new",
".tmp");
1090 RENAME_SUFFIX(
"state",
".tmp");
1091 RENAME_SUFFIX(
"sr-state",
".tmp");
1092 RENAME_SUFFIX(
"unparseable-desc",
".tmp");
1093 RENAME_SUFFIX(
"v3-status-votes",
".tmp");
1096 RENAME_SUFFIX(
"networkstatus-bridges",
".tmp");
1098 if (authdir_mode(options)) {
1099 RENAME_SUFFIX(
"my-consensus-microdesc",
".tmp");
1100 RENAME_SUFFIX(
"my-consensus-ns",
".tmp");
1102 sandbox_cfg_allow_rename(&cfg,
1103 get_datadir_fname(
"my-consensus-microdesc"),
1104 get_datadir_fname(
"consensus-transparency-microdesc"));
1105 sandbox_cfg_allow_rename(&cfg,
1106 get_datadir_fname(
"my-consensus-ns"),
1107 get_datadir_fname(
"consensus-transparency-ns"));
1110#define STAT_DATADIR(name) \
1111 sandbox_cfg_allow_stat_filename(&cfg, get_datadir_fname(name))
1113#define STAT_CACHEDIR(name) \
1114 sandbox_cfg_allow_stat_filename(&cfg, get_cachedir_fname(name))
1116#define STAT_DATADIR2(name, name2) \
1117 sandbox_cfg_allow_stat_filename(&cfg, get_datadir_fname2((name), (name2)))
1119#define STAT_KEY_DIRECTORY() \
1120 sandbox_cfg_allow_stat_filename(&cfg, tor_strdup(options->KeyDirectory))
1123 STAT_DATADIR(
"lock");
1124 STAT_DATADIR(
"state");
1125 STAT_DATADIR(
"router-stability");
1127 STAT_CACHEDIR(
"cached-extrainfo.new");
1136 smartlist_free(files);
1144 char *tmp_name = NULL;
1146 sandbox_cfg_allow_rename(&cfg,
1147 tor_strdup(tmp_name), tor_strdup(file_name));
1156 smartlist_free(files);
1157 smartlist_free(dirs);
1165 if ((fname = get_ext_or_auth_cookie_file_name())) {
1171 if (!port->is_unix_addr)
1175 char *dirname = tor_strdup(port->unix_addr);
1180 sandbox_cfg_allow_chmod_filename(&cfg, tor_strdup(port->unix_addr));
1181 sandbox_cfg_allow_chown_filename(&cfg, tor_strdup(port->unix_addr));
1182 } SMARTLIST_FOREACH_END(port);
1192 OPEN_KEYDIR_SUFFIX(
"secret_id_key",
".tmp");
1193 OPEN_KEYDIR_SUFFIX(
"secret_onion_key",
".tmp");
1194 OPEN_KEYDIR_SUFFIX(
"secret_onion_key_ntor",
".tmp");
1195 OPEN_KEYDIR(
"secret_id_key.old");
1196 OPEN_KEYDIR(
"secret_onion_key.old");
1197 OPEN_KEYDIR(
"secret_onion_key_ntor.old");
1199 OPEN_KEYDIR_SUFFIX(
"ed25519_master_id_secret_key",
".tmp");
1200 OPEN_KEYDIR_SUFFIX(
"ed25519_master_id_secret_key_encrypted",
".tmp");
1201 OPEN_KEYDIR_SUFFIX(
"ed25519_master_id_public_key",
".tmp");
1202 OPEN_KEYDIR_SUFFIX(
"ed25519_signing_secret_key",
".tmp");
1203 OPEN_KEYDIR_SUFFIX(
"ed25519_signing_secret_key_encrypted",
".tmp");
1204 OPEN_KEYDIR_SUFFIX(
"ed25519_signing_public_key",
".tmp");
1205 OPEN_KEYDIR_SUFFIX(
"ed25519_signing_cert",
".tmp");
1207 OPEN_DATADIR2_SUFFIX(
"stats",
"bridge-stats",
".tmp");
1208 OPEN_DATADIR2_SUFFIX(
"stats",
"dirreq-stats",
".tmp");
1210 OPEN_DATADIR2_SUFFIX(
"stats",
"entry-stats",
".tmp");
1211 OPEN_DATADIR2_SUFFIX(
"stats",
"exit-stats",
".tmp");
1212 OPEN_DATADIR2_SUFFIX(
"stats",
"buffer-stats",
".tmp");
1213 OPEN_DATADIR2_SUFFIX(
"stats",
"conn-stats",
".tmp");
1214 OPEN_DATADIR2_SUFFIX(
"stats",
"hidserv-stats",
".tmp");
1215 OPEN_DATADIR2_SUFFIX(
"stats",
"hidserv-v3-stats",
".tmp");
1217 OPEN_DATADIR(
"approved-routers");
1218 OPEN_DATADIR_SUFFIX(
"fingerprint",
".tmp");
1219 OPEN_DATADIR_SUFFIX(
"fingerprint-ed25519",
".tmp");
1220 OPEN_DATADIR_SUFFIX(
"hashed-fingerprint",
".tmp");
1221 OPEN_DATADIR_SUFFIX(
"router-stability",
".tmp");
1223 OPEN(
"/etc/resolv.conf");
1225 RENAME_SUFFIX(
"fingerprint",
".tmp");
1226 RENAME_SUFFIX(
"fingerprint-ed25519",
".tmp");
1227 RENAME_KEYDIR_SUFFIX(
"secret_onion_key_ntor",
".tmp");
1229 RENAME_KEYDIR_SUFFIX(
"secret_id_key",
".tmp");
1230 RENAME_KEYDIR_SUFFIX(
"secret_id_key.old",
".tmp");
1231 RENAME_KEYDIR_SUFFIX(
"secret_onion_key",
".tmp");
1232 RENAME_KEYDIR_SUFFIX(
"secret_onion_key.old",
".tmp");
1234 RENAME_SUFFIX2(
"stats",
"bridge-stats",
".tmp");
1235 RENAME_SUFFIX2(
"stats",
"dirreq-stats",
".tmp");
1236 RENAME_SUFFIX2(
"stats",
"entry-stats",
".tmp");
1237 RENAME_SUFFIX2(
"stats",
"exit-stats",
".tmp");
1238 RENAME_SUFFIX2(
"stats",
"buffer-stats",
".tmp");
1239 RENAME_SUFFIX2(
"stats",
"conn-stats",
".tmp");
1240 RENAME_SUFFIX2(
"stats",
"hidserv-stats",
".tmp");
1241 RENAME_SUFFIX2(
"stats",
"hidserv-v3-stats",
".tmp");
1242 RENAME_SUFFIX(
"hashed-fingerprint",
".tmp");
1243 RENAME_SUFFIX(
"router-stability",
".tmp");
1245 RENAME_KEYDIR_SUFFIX(
"ed25519_master_id_secret_key",
".tmp");
1246 RENAME_KEYDIR_SUFFIX(
"ed25519_master_id_secret_key_encrypted",
".tmp");
1247 RENAME_KEYDIR_SUFFIX(
"ed25519_master_id_public_key",
".tmp");
1248 RENAME_KEYDIR_SUFFIX(
"ed25519_signing_secret_key",
".tmp");
1249 RENAME_KEYDIR_SUFFIX(
"ed25519_signing_cert",
".tmp");
1251 sandbox_cfg_allow_rename(&cfg,
1252 get_keydir_fname(
"secret_onion_key"),
1253 get_keydir_fname(
"secret_onion_key.old"));
1254 sandbox_cfg_allow_rename(&cfg,
1255 get_keydir_fname(
"secret_onion_key_ntor"),
1256 get_keydir_fname(
"secret_onion_key_ntor.old"));
1258 STAT_KEY_DIRECTORY();
1259 OPEN_DATADIR(
"stats");
1260 STAT_DATADIR(
"stats");
1261 STAT_DATADIR2(
"stats",
"dirreq-stats");
1272run_tor_main_loop(
void)
1282 log_err(
LD_OR,
"Error initializing keys; exiting");
1295 char *fname = get_datadir_fname(
"key-pinning-journal");
1298 log_err(
LD_DIR,
"Error loading key-pinning journal: %s",strerror(errno));
1302 log_err(
LD_DIR,
"Error opening key-pinning journal: %s",strerror(errno));
1316 char *fname = get_datadir_fname(
"key-pinning-entries");
1323 "Couldn't load all cached v3 certificates. Starting anyway.");
1335 const time_t now = time(NULL);
1353 if (dns_init() < 0) {
1355 log_warn(
LD_GENERAL,
"Couldn't set up any working nameservers. "
1356 "Network not up yet? Will try again soon.");
1358 log_err(
LD_GENERAL,
"Error initializing dns subsystem; exiting. To "
1359 "retry instead, set the ServerDNSAllowBrokenResolvConf option.");
1365 const int r = sd_notify(0,
"READY=1");
1367 log_warn(
LD_GENERAL,
"Unable to send readiness to systemd: %s",
1370 log_notice(
LD_GENERAL,
"Signaled readiness to systemd");
1372 log_info(
LD_GENERAL,
"Systemd NOTIFY_SOCKET not present.");
1413#ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
1422 char **argv = tor_calloc(argc,
sizeof(
char*));
1423 memcpy(argv, tor_cfg->
argv, tor_cfg->
argc*
sizeof(
char*));
1429 result = nt_service_parse_options(argc, argv, &done);
1436 int init_rv =
tor_init(argc, argv);
1439 result = (init_rv < 0) ? -1 : 0;
1447#ifdef ENABLE_FRAGILE_HARDENING
1448 log_warn(
LD_CONFIG,
"Sandbox is enabled but this Tor was built using "
1449 "fragile compiler hardening. The sandbox may be unable to filter "
1450 "requests to open files and directories and its overall "
1451 "effectiveness will be reduced.");
1458 log_err(
LD_BUG,
"Failed to create syscall sandbox filter");
1462 tor_make_getaddrinfo_cache_active();
1465#ifdef HAVE_EVUTIL_SECURE_RNG_SET_URANDOM_DEVICE_FILE
1466 evutil_secure_rng_set_urandom_device_file(
1473 nt_service_set_state(SERVICE_RUNNING);
1474 result = run_tor_main_loop();
1477 result = load_ed_keys(
get_options(), time(NULL)) < 0;
1487 result = log_cert_expiration();
1498 printf(
"Configuration was valid\n");
1507 log_warn(
LD_BUG,
"Illegal command number %d: internal error.",
void addressmap_init(void)
void addressmap_clear_transient(void)
int trusted_dirs_reload_certs(void)
Header file for authcert.c.
Header file for directory authority mode.
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
size_t buf_allocation(const buf_t *buf)
Header file for buffers.c.
Header for feature/stats/bwhist.c.
void channel_dumpstats(int severity)
void channel_listener_dumpstats(int severity)
Header file for channel.c.
void channelpadding_new_consensus_params(const networkstatus_t *ns)
uint64_t stats_n_padding_cells_processed
void circuit_mark_all_dirty_circs_as_unusable(void)
void circuit_dump_by_conn(connection_t *conn, int severity)
Header file for circuitlist.c.
void circpad_machines_init(void)
void circpad_new_consensus_params(const networkstatus_t *ns)
Header file for circuitpadding.c.
uint64_t stats_n_created_cells_processed
uint64_t stats_n_destroy_cells_processed
uint64_t stats_n_relay_cells_processed
uint64_t stats_n_create_cells_processed
Header file for command.c.
const char * tor_libevent_get_version_str(void)
struct event_base * tor_libevent_get_base(void)
Header for compat_libevent.c.
const char * tor_compress_version_str(compress_method_t method)
int tor_compress_supports_method(compress_method_t method)
void tor_compress_log_init_warnings(void)
const char * get_torrc_fname(int defaults_fname)
const smartlist_t * get_configured_ports(void)
int options_init_from_torrc(int argc, char **argv)
static char * torrc_defaults_fname
void init_protocol_warning_severity_level(void)
char * options_dump(const or_options_t *options, int how_to_dump)
static char * torrc_fname
const or_options_t * get_options(void)
int set_options(or_options_t *new_val, char **msg)
tor_cmdline_mode_t command
parsed_cmdline_t * config_parse_commandline(int argc, char **argv, int ignore_errors)
Header file for config.c.
#define CONFIG_BACKUP_PATTERN
void congestion_control_new_consensus_params(const networkstatus_t *ns)
Public APIs for congestion control.
void flow_control_new_consensus_params(const networkstatus_t *ns)
APIs for stream flow control on congestion controlled circuits.
int connection_is_listener(connection_t *conn)
void connection_dump_buffer_mem_stats(int severity)
void connection_bucket_init(void)
const char * connection_describe(const connection_t *conn)
Header file for connection.c.
or_connection_t * TO_OR_CONN(connection_t *c)
Header file for connection_or.c.
void consdiffmgr_enable_background_compression(void)
int consdiffmgr_register_with_sandbox(struct sandbox_cfg_elem_t **cfg)
Header for consdiffmgr.c.
Header file for control.c.
char * get_controller_cookie_file_name(void)
Header file for control_auth.c.
void control_event_bootstrap(bootstrap_status_t status, int progress)
int control_event_signal(uintptr_t signal_num)
Header file for control_events.c.
void cpuworker_log_onionskin_overhead(int severity, int onionskin_type, const char *onionskin_type_name)
void cpuworkers_rotate_keyinfo(void)
Header file for cpuworker.c.
int curve25519_keypair_write_to_file(const curve25519_keypair_t *keypair, const char *fname, const char *tag)
int curve25519_keypair_generate(curve25519_keypair_t *keypair_out, int extra_strong)
const char * crypto_get_library_version_string(void)
const char * crypto_get_library_name(void)
Headers for crypto_init.c.
void crypto_rand(char *to, size_t n)
Common functions for using (pseudo-)random number generators.
int crypto_pk_get_fingerprint(crypto_pk_t *pk, char *fp_out, int add_space)
void secret_to_key_rfc2440(char *key_out, size_t key_out_len, const char *secret, size_t secret_len, const char *s2k_specifier)
#define S2K_RFC2440_SPECIFIER_LEN
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
void router_reset_status_download_failures(void)
int accounting_record_bandwidth_usage(time_t now, or_state_t *state)
int accounting_is_enabled(const or_options_t *options)
void hibernate_begin_shutdown(void)
Header file for hibernate.c.
Header file containing denial of service defenses for the HS subsystem for all versions.
void hs_service_lists_fnames_for_sandbox(smartlist_t *file_list, smartlist_t *dir_list)
void hs_service_dump_stats(int severity)
Header file containing service data for the HS subsystem.
int keypin_load_journal(const char *fname)
int keypin_open_journal(const char *fname)
const char * tor_libc_get_version_str(void)
const char * tor_libc_get_name(void)
Header for lib/osinfo/libc.c.
tor_lockfile_t * tor_lockfile_lock(const char *filename, int blocking, int *locked_out)
void tor_lockfile_unlock(tor_lockfile_t *lockfile)
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
void switch_logs_debug(void)
int get_min_log_level(void)
void log_set_application_name(const char *name)
void tor_log_get_logfile_names(smartlist_t *out)
static tor_lockfile_t * lockfile
int tor_run_main(const tor_main_configuration_t *tor_cfg)
static int do_keygen_onion_key(const char *fname)
static int do_dump_config(void)
static int do_list_fingerprint(void)
struct event * signal_event
void release_lockfile(void)
static void do_hash_password(void)
int tor_init(int argc, char *argv[])
int try_locking(const or_options_t *options, int err_if_locked)
static int do_keygen_family(const char *fname_base)
static void process_signal(int sig)
static void dumpstats(int severity)
static void dumpmemusage(int severity)
static void signal_callback(evutil_socket_t fd, short events, void *arg)
void tor_remove_file(const char *filename)
void handle_signals(void)
void pubsub_install(void)
void pubsub_connect(void)
uint64_t get_bytes_read(void)
void update_current_time(time_t now)
void do_signewnym(time_t now)
void initialize_mainloop_events(void)
void schedule_rescan_periodic_events(void)
smartlist_t * get_connection_array(void)
void tor_shutdown_event_loop_and_exit(int exitcode)
void tor_init_connection_lists(void)
void directory_info_has_arrived(time_t now, int from_cache, int suppress_logs)
uint64_t get_bytes_written(void)
time_t time_of_process_start
Header file for mainloop.c.
int tor_mainloop_connect_pubsub(struct pubsub_builder_t *builder)
void tor_mainloop_connect_pubsub_events(void)
int tor_mainloop_set_delivery_strategy(const char *msg_channel_name, deliv_strategy_t strategy)
Header for mainloop_pubsub.c.
void tor_free_(void *mem)
void * tor_malloc_(size_t size)
void * tor_realloc_(void *ptr, size_t size)
int net_is_disabled(void)
void set_network_participation(bool participation)
void reset_user_activity(time_t now)
void note_user_activity(time_t now)
void update_networkstatus_downloads(time_t now)
networkstatus_t * networkstatus_get_latest_consensus(void)
int router_reload_consensus_networkstatus(void)
Header file for networkstatus.c.
Header file for ntmain.c.
Master header file for Tor-specific functionality.
#define RELAY_PAYLOAD_SIZE_MAX
int get_parent_directory(char *fname)
Listener port configuration structure.
Header file for predict_ports.c.
int tor_asprintf(char **strp, const char *fmt,...)
int tor_snprintf(char *str, size_t size, const char *format,...)
int dirserv_load_fingerprint_file(void)
Header file for process_descs.c.
pubsub_builder_t * pubsub_builder_new(void)
Header used for constructing the OO publish-subscribe facility.
struct pubsub_builder_t pubsub_builder_t
quiet_level_t quiet_level
void add_default_log_for_quiet_level(quiet_level_t quiet)
Declare the quiet_level enumeration and global.
uint64_t stats_n_data_cells_received
void dump_cell_pool_usage(int severity)
uint64_t stats_n_relay_cells_relayed
uint64_t stats_n_data_cells_packaged
uint64_t stats_n_data_bytes_received
uint64_t stats_n_relay_cells_delivered
uint64_t stats_n_data_bytes_packaged
uint64_t rephist_total_alloc
void rep_hist_dump_stats(time_t now, int severity)
uint32_t rephist_total_num
Header file for rephist.c.
const char risky_option_list[]
Header for risky_options.c.
void router_reset_warnings(void)
void router_reload_manual_onion_keys(void)
int client_identity_key_is_set(void)
smartlist_t * list_family_key_files(const or_options_t *options, const char *keydir)
void dump_routerlist_mem_usage(int severity)
int router_reload_router_list(void)
void routerlist_reset_warnings(void)
void router_reset_descriptor_download_failures(void)
Header file for routerlist.c.
Header file for routermode.c.
void routerparse_init(void)
Header file for routerparse.c.
int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file)
int sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file)
sandbox_cfg_t * sandbox_cfg_new(void)
int sandbox_init(sandbox_cfg_t *cfg)
int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file)
Header file for sandbox.c.
struct sandbox_cfg_elem_t sandbox_cfg_t
#define sandbox_intern_string(s)
int sr_init(int save_to_disk)
This file contains ABI/API of the shared random protocol defined in proposal #250....
void tor_free_all(int postfork)
Header file for shutdown.c.
smartlist_t * smartlist_new(void)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
or_state_t * get_or_state(void)
int log_heartbeat(time_t now)
int DisableSignalHandlers
char * ServerDNSResolvConfFile
char * FamilyKeyDirectory
int ManualOnionKeyRotation
struct smartlist_t * FilesOpenedByIncludes
int BridgeAuthoritativeDir
quiet_level_t quiet_level
tor_cmdline_mode_t command
int subsystems_add_pubsub(pubsub_builder_t *builder)
int subsystems_init(void)
void timers_initialize(void)
Public C API for the Tor network service.
Internal declarations for in-process Tor API.
int tor_tls_get_buffer_sizes(tor_tls_t *tls, size_t *rbuf_capacity, size_t *rbuf_bytes, size_t *wbuf_capacity, size_t *wbuf_bytes)
const char * get_version(void)
const char * get_uname(void)
void notify_pending_waitpid_callbacks(void)
#define ED25519_BASE64_LEN