static int options_apply(ProxyContext * const proxy_context) { if (proxy_context->resolver_ip == NULL || *proxy_context->resolver_ip == 0) { logger_noformat(proxy_context, LOG_ERR, "Resolver IP address required"); #ifdef _WIN32 logger_noformat(proxy_context, LOG_ERR, "Consult http://dnscrypt.org for details."); #else logger_noformat(proxy_context, LOG_ERR, "Please consult the dnscrypt-proxy(8) man page for details."); #endif exit(1); } if (proxy_context->provider_name == NULL || *proxy_context->provider_name == 0) { logger_noformat(proxy_context, LOG_ERR, "Provider name required"); exit(1); } if (options_check_protocol_versions(proxy_context->provider_name) != 0) { logger_noformat(proxy_context, LOG_ERR, "Unsupported server protocol version"); exit(1); } if (proxy_context->provider_publickey_s == NULL) { logger_noformat(proxy_context, LOG_ERR, "Provider key required"); exit(1); } if (dnscrypt_fingerprint_to_key(proxy_context->provider_publickey_s, proxy_context->provider_publickey) != 0) { logger_noformat(proxy_context, LOG_ERR, "Invalid provider key"); exit(1); } if (proxy_context->daemonize) { do_daemonize(); } #ifndef _WIN32 if (proxy_context->pid_file != NULL && pid_file_create(proxy_context->pid_file, proxy_context->user_id != (uid_t) 0) != 0) { logger_error(proxy_context, "Unable to create pid file"); } #endif if (proxy_context->log_file != NULL && (proxy_context->log_fd = open(proxy_context->log_file, O_WRONLY | O_APPEND | O_CREAT, (mode_t) 0600)) == -1) { logger_error(proxy_context, "Unable to open log file"); exit(1); } if (proxy_context->log_fd == -1 && proxy_context->daemonize) { logger_open_syslog(proxy_context); } return 0; }
static void initial_setup() { #ifdef OPENWRT OOR_LOG(LINF,"Open Overlay Router %s compiled for openWRT\n", OOR_VERSION); #else #ifdef ANDROID #ifdef VPNAPI OOR_LOG(LINF,"Open Overlay Router %s compiled for not rooted Android\n", OOR_VERSION); #else OOR_LOG(LINF,"Open Overlay Router %s compiled for rooted Android\n", OOR_VERSION); #endif #else OOR_LOG(LINF,"Open Overlay Router %s compiled for Linux\n", OOR_VERSION); #endif #endif #if UINTPTR_MAX == 0xffffffff OOR_LOG(LDBG_1,"x32 system"); #elif UINTPTR_MAX == 0xffffffffffffffff OOR_LOG(LDBG_1,"x64 system"); #else OOR_LOG(LERR,"Unknow system. Please contact the Open Overlay Router team providing your hardware"); #endif #ifndef VPNAPI if (check_capabilities() != GOOD){ exit(EXIT_SUCCESS); } if(pid_file_check_not_exist() == BAD){ exit(EXIT_SUCCESS); } pid_file_create(); #endif /* Initialize the random number generator */ iseed = (unsigned int) time(NULL); srandom(iseed); setup_signal_handlers(); /* Initialize hash table that control timers */ nonces_ht = htable_nonces_new(); ptrs_to_timers_ht = htable_ptrs_new(); }
static int options_apply(ProxyContext * const proxy_context) { if (proxy_context->resolver_ip == NULL) { options_usage(); exit(1); } if (proxy_context->provider_name == NULL || *proxy_context->provider_name == 0) { logger_noformat(proxy_context, LOG_ERR, "Provider name required"); exit(1); } if (proxy_context->provider_publickey_s == NULL) { logger_noformat(proxy_context, LOG_ERR, "Provider key required"); exit(1); } if (dnscrypt_fingerprint_to_key(proxy_context->provider_publickey_s, proxy_context->provider_publickey) != 0) { logger_noformat(proxy_context, LOG_ERR, "Invalid provider key"); exit(1); } if (proxy_context->daemonize) { do_daemonize(); } #ifndef _WIN32 if (proxy_context->pid_file != NULL && pid_file_create(proxy_context->pid_file, proxy_context->user_id != (uid_t) 0) != 0) { logger_error(proxy_context, "Unable to create pid file"); } #endif if (proxy_context->log_file != NULL && (proxy_context->log_fd = open(proxy_context->log_file, O_WRONLY | O_APPEND | O_CREAT, (mode_t) 0600)) == -1) { logger_error(proxy_context, "Unable to open log file"); exit(1); } if (proxy_context->log_fd == -1 && proxy_context->daemonize) { logger_open_syslog(proxy_context); } return 0; }
static int options_apply(ProxyContext * const proxy_context) { if (proxy_context->client_key_file != NULL) { if (proxy_context->ephemeral_keys != 0) { logger_noformat(proxy_context, LOG_ERR, "--client-key and --ephemeral-keys are mutually exclusive"); exit(1); } if (options_use_client_key_file(proxy_context) != 0) { logger(proxy_context, LOG_ERR, "Client key file [%s] could not be used", proxy_context->client_key_file); exit(1); } } if (proxy_context->resolver_name != NULL) { if (proxy_context->resolvers_list == NULL) { logger_noformat(proxy_context, LOG_ERR, "Resolvers list (-L command-line switch) required"); exit(1); } if (options_use_resolver_name(proxy_context) != 0) { logger(proxy_context, LOG_ERR, "Resolver name (-R command-line switch) required. " "See [%s] for a list of public resolvers.", proxy_context->resolvers_list); exit(1); } } if (proxy_context->resolver_ip == NULL || *proxy_context->resolver_ip == 0 || proxy_context->provider_name == NULL || *proxy_context->provider_name == 0 || proxy_context->provider_publickey_s == NULL || *proxy_context->provider_publickey_s == 0) { logger_noformat(proxy_context, LOG_ERR, "Resolver information required."); logger_noformat(proxy_context, LOG_ERR, "The easiest way to do so is to provide a resolver name."); logger_noformat(proxy_context, LOG_ERR, "Example: dnscrypt-proxy -R mydnsprovider"); logger(proxy_context, LOG_ERR, "See the file [%s] for a list of compatible public resolvers", proxy_context->resolvers_list); logger_noformat(proxy_context, LOG_ERR, "The name is the first column in this table."); logger_noformat(proxy_context, LOG_ERR, "Alternatively, an IP address, a provider name " "and a provider key can be supplied."); #ifdef _WIN32 logger_noformat(proxy_context, LOG_ERR, "Consult https://dnscrypt.org " "and https://github.com/jedisct1/dnscrypt-proxy/blob/master/README-WINDOWS.markdown " "for details."); #else logger_noformat(proxy_context, LOG_ERR, "Please consult https://dnscrypt.org " "and the dnscrypt-proxy(8) man page for details."); #endif exit(1); } if (proxy_context->provider_name == NULL || *proxy_context->provider_name == 0) { logger_noformat(proxy_context, LOG_ERR, "Provider name required"); exit(1); } if (options_check_protocol_versions(proxy_context->provider_name) != 0) { logger_noformat(proxy_context, LOG_ERR, "Unsupported server protocol version"); exit(1); } if (proxy_context->provider_publickey_s == NULL) { logger_noformat(proxy_context, LOG_ERR, "Provider key required"); exit(1); } if (dnscrypt_fingerprint_to_key(proxy_context->provider_publickey_s, proxy_context->provider_publickey) != 0) { logger_noformat(proxy_context, LOG_ERR, "Invalid provider key"); exit(1); } if (proxy_context->daemonize != 0) { if (proxy_context->log_file == NULL) { proxy_context->syslog = 1; } do_daemonize(); } #ifndef _WIN32 if (proxy_context->pid_file != NULL && pid_file_create(proxy_context->pid_file, proxy_context->user_id != (uid_t) 0) != 0) { logger_error(proxy_context, "Unable to create pid file"); exit(1); } #endif if (proxy_context->log_file != NULL && proxy_context->syslog != 0) { logger_noformat(proxy_context, LOG_ERR, "--logfile and --syslog are mutually exclusive"); exit(1); } if (proxy_context->log_file != NULL && (proxy_context->log_fp = fopen(proxy_context->log_file, "a")) == NULL) { logger_error(proxy_context, "Unable to open log file"); exit(1); } if (proxy_context->syslog != 0) { assert(proxy_context->log_fp == NULL); logger_open_syslog(proxy_context); } return 0; }