dns_conf: fix server-https options issue.
This commit is contained in:
@@ -18,7 +18,9 @@ Checks: >
|
||||
-bugprone-suspicious-memory-comparison,
|
||||
-bugprone-not-null-terminated-result,
|
||||
-bugprone-signal-handler,
|
||||
-bugprone-assignment-in-if-condition,
|
||||
-concurrency-mt-unsafe,
|
||||
-modernize-macro-to-enum,
|
||||
-misc-unused-parameters,
|
||||
-misc-misplaced-widening-cast,
|
||||
-misc-no-recursion,
|
||||
|
||||
@@ -93,7 +93,7 @@ struct dns_server_info {
|
||||
/* server ping handle */
|
||||
struct ping_host_struct *ping_host;
|
||||
|
||||
char ip[DNS_HOSTNAME_LEN];
|
||||
char ip[DNS_MAX_HOSTNAME];
|
||||
int port;
|
||||
char proxy_name[DNS_HOSTNAME_LEN];
|
||||
/* server type */
|
||||
@@ -3327,6 +3327,7 @@ static int _dns_client_send_https(struct dns_server_info *server_info, void *pac
|
||||
http_len = snprintf((char *)inpacket, DNS_IN_PACKSIZE,
|
||||
"POST %s HTTP/1.1\r\n"
|
||||
"Host: %s\r\n"
|
||||
"User-Agent: smartdns\r\n"
|
||||
"content-type: application/dns-message\r\n"
|
||||
"Content-Length: %d\r\n"
|
||||
"\r\n",
|
||||
|
||||
@@ -504,7 +504,9 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
|
||||
unsigned char *spki = NULL;
|
||||
int drop_packet_latency_ms = 0;
|
||||
int is_bootstrap_dns = 0;
|
||||
int is_hostip_set = 0;
|
||||
char host_ip[DNS_MAX_IPLEN] = {0};
|
||||
int no_tls_host_name = 0;
|
||||
int no_tls_host_verify = 0;
|
||||
|
||||
int ttl = 0;
|
||||
/* clang-format off */
|
||||
@@ -576,14 +578,6 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
|
||||
}
|
||||
}
|
||||
|
||||
if (type == DNS_SERVER_HTTPS) {
|
||||
safe_strncpy(server->hostname, server->server, sizeof(server->hostname));
|
||||
safe_strncpy(server->httphost, server->server, sizeof(server->httphost));
|
||||
if (server->path[0] == 0) {
|
||||
safe_strncpy(server->path, "/", sizeof(server->path));
|
||||
}
|
||||
}
|
||||
|
||||
/* if port is not defined, set port to default 53 */
|
||||
if (port == PORT_NOT_DEFINED) {
|
||||
port = default_port;
|
||||
@@ -624,6 +618,7 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
|
||||
|
||||
case 'k': {
|
||||
server->skip_check_cert = 1;
|
||||
no_tls_host_verify = 1;
|
||||
break;
|
||||
}
|
||||
case 'b': {
|
||||
@@ -655,10 +650,10 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
|
||||
break;
|
||||
}
|
||||
case 258: {
|
||||
if (check_is_ipaddr(server->server) != 0) {
|
||||
_conf_domain_rule_address(server->server, optarg);
|
||||
is_hostip_set = 1;
|
||||
if (check_is_ipaddr(optarg) != 0) {
|
||||
goto errout;
|
||||
}
|
||||
safe_strncpy(host_ip, optarg, DNS_MAX_IPLEN);
|
||||
break;
|
||||
}
|
||||
case 259: {
|
||||
@@ -669,6 +664,7 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
|
||||
safe_strncpy(server->hostname, optarg, DNS_MAX_CNAME_LEN);
|
||||
if (strncmp(server->hostname, "-", 2) == 0) {
|
||||
server->hostname[0] = '\0';
|
||||
no_tls_host_name = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -678,6 +674,10 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
|
||||
}
|
||||
case 262: {
|
||||
safe_strncpy(server->tls_host_verify, optarg, DNS_MAX_CNAME_LEN);
|
||||
if (strncmp(server->tls_host_verify, "-", 2) == 0) {
|
||||
server->tls_host_verify[0] = '\0';
|
||||
no_tls_host_verify = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -686,21 +686,28 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
|
||||
}
|
||||
}
|
||||
|
||||
/* if server is domain name, then verify domain */
|
||||
if (server->tls_host_verify[0] == '\0' && check_is_ipaddr(server->server) != 0) {
|
||||
safe_strncpy(server->tls_host_verify, server->server, DNS_MAX_CNAME_LEN);
|
||||
if (check_is_ipaddr(server->server) != 0) {
|
||||
/* if server is domain name, then verify domain */
|
||||
if (server->tls_host_verify[0] == '\0' && no_tls_host_verify == 0) {
|
||||
safe_strncpy(server->tls_host_verify, server->server, DNS_MAX_CNAME_LEN);
|
||||
}
|
||||
|
||||
if (server->hostname[0] == '\0' && no_tls_host_name == 0) {
|
||||
safe_strncpy(server->hostname, server->server, DNS_MAX_CNAME_LEN);
|
||||
}
|
||||
|
||||
if (server->httphost[0] == '\0') {
|
||||
safe_strncpy(server->httphost, server->server, DNS_MAX_CNAME_LEN);
|
||||
}
|
||||
|
||||
if (host_ip[0] != '\0') {
|
||||
safe_strncpy(server->server, host_ip, DNS_MAX_IPLEN);
|
||||
}
|
||||
}
|
||||
|
||||
/* update address rules for host-ip */
|
||||
if (is_hostip_set == 1) {
|
||||
struct dns_domain_rule *rule = _config_domain_rule_get(server->server);
|
||||
if (rule) {
|
||||
if (rule->rules[DOMAIN_RULE_ADDRESS_IPV4] != NULL && rule->rules[DOMAIN_RULE_ADDRESS_IPV6] == NULL) {
|
||||
_conf_domain_rule_address(server->server, "#6");
|
||||
} else if (rule->rules[DOMAIN_RULE_ADDRESS_IPV4] == NULL && rule->rules[DOMAIN_RULE_ADDRESS_IPV6] != NULL) {
|
||||
_conf_domain_rule_address(server->server, "#4");
|
||||
}
|
||||
}
|
||||
/* if server is domain name, then verify domain */
|
||||
if (server->tls_host_verify[0] == '\0' && server->hostname[0] != '\0' && no_tls_host_verify == 0) {
|
||||
safe_strncpy(server->tls_host_verify, server->hostname, DNS_MAX_CNAME_LEN);
|
||||
}
|
||||
|
||||
/* add new server */
|
||||
@@ -915,7 +922,7 @@ static int _config_setup_domain_key(const char *domain, char *domain_key, int do
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct dns_domain_rule *_config_domain_rule_get(const char *domain)
|
||||
static __attribute__((unused)) struct dns_domain_rule *_config_domain_rule_get(const char *domain)
|
||||
{
|
||||
char domain_key[DNS_MAX_CONF_CNAME_LEN];
|
||||
int len = 0;
|
||||
|
||||
@@ -323,7 +323,7 @@ struct dns_edns_client_subnet {
|
||||
};
|
||||
|
||||
struct dns_servers {
|
||||
char server[DNS_MAX_IPLEN];
|
||||
char server[DNS_MAX_CNAME_LEN];
|
||||
unsigned short port;
|
||||
unsigned int result_flag;
|
||||
unsigned int server_flag;
|
||||
|
||||
@@ -2887,7 +2887,7 @@ static int _dns_server_process_ip_alias(struct dns_request *request, struct dns_
|
||||
{
|
||||
int addr_num = 0;
|
||||
|
||||
if (alias == 0) {
|
||||
if (alias == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
#include "hashtable.h"
|
||||
#include "list.h"
|
||||
#include "rbtree.h"
|
||||
#include "timer.h"
|
||||
#include "tlog.h"
|
||||
#include "util.h"
|
||||
#include "timer.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
@@ -157,7 +157,7 @@ static void _help(void)
|
||||
" -v display version.\n"
|
||||
" -h show this help message.\n"
|
||||
|
||||
"Online help: http://pymumu.github.io/smartdns\n"
|
||||
"Online help: https://pymumu.github.io/smartdns\n"
|
||||
"Copyright (C) Nick Peng <pymumu@gmail.com>\n"
|
||||
;
|
||||
/* clang-format on */
|
||||
@@ -773,7 +773,7 @@ int main(int argc, char *argv[])
|
||||
struct stat sb;
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"cache-print", required_argument, 0, 256}, {"help", no_argument, 0, 'h'}, {NULL, 0, 0, 0}};
|
||||
{"cache-print", required_argument, NULL, 256}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}};
|
||||
|
||||
safe_strncpy(config_file, SMARTDNS_CONF_FILE, MAX_LINE_LEN);
|
||||
|
||||
@@ -788,7 +788,7 @@ int main(int argc, char *argv[])
|
||||
sigprocmask(SIG_SETMASK, &empty_sigblock, NULL);
|
||||
smartdns_close_allfds();
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "fhc:p:SvxN:", long_options, 0)) != -1) {
|
||||
while ((opt = getopt_long(argc, argv, "fhc:p:SvxN:", long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'f':
|
||||
is_run_as_daemon = 0;
|
||||
|
||||
Reference in New Issue
Block a user