dns_conf: fix relative path issue
This commit is contained in:
@@ -2957,7 +2957,7 @@ int config_additional_file(void *data, int argc, char *argv[])
|
|||||||
conf_file = argv[1];
|
conf_file = argv[1];
|
||||||
if (conf_file[0] != '/') {
|
if (conf_file[0] != '/') {
|
||||||
safe_strncpy(file_path_dir, conf_get_conf_file(), DNS_MAX_PATH);
|
safe_strncpy(file_path_dir, conf_get_conf_file(), DNS_MAX_PATH);
|
||||||
dirname(file_path_dir);
|
dir_name(file_path_dir);
|
||||||
if (strncmp(file_path_dir, conf_get_conf_file(), sizeof(file_path_dir)) == 0) {
|
if (strncmp(file_path_dir, conf_get_conf_file(), sizeof(file_path_dir)) == 0) {
|
||||||
if (snprintf(file_path, DNS_MAX_PATH, "%s", conf_file) < 0) {
|
if (snprintf(file_path, DNS_MAX_PATH, "%s", conf_file) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -32,6 +32,16 @@ const char *conf_get_conf_file(void)
|
|||||||
return current_conf_file;
|
return current_conf_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *get_dir_name(char *path)
|
||||||
|
{
|
||||||
|
if (strstr(path, "/") == NULL) {
|
||||||
|
strncpy(path, "./", PATH_MAX);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dirname(path);
|
||||||
|
}
|
||||||
|
|
||||||
const char *conf_get_conf_fullpath(const char *path, char *fullpath, size_t path_len)
|
const char *conf_get_conf_fullpath(const char *path, char *fullpath, size_t path_len)
|
||||||
{
|
{
|
||||||
char file_path_dir[PATH_MAX];
|
char file_path_dir[PATH_MAX];
|
||||||
@@ -47,7 +57,7 @@ const char *conf_get_conf_fullpath(const char *path, char *fullpath, size_t path
|
|||||||
|
|
||||||
strncpy(file_path_dir, conf_get_conf_file(), PATH_MAX - 1);
|
strncpy(file_path_dir, conf_get_conf_file(), PATH_MAX - 1);
|
||||||
file_path_dir[PATH_MAX - 1] = 0;
|
file_path_dir[PATH_MAX - 1] = 0;
|
||||||
dirname(file_path_dir);
|
get_dir_name(file_path_dir);
|
||||||
if (file_path_dir[0] == '\0') {
|
if (file_path_dir[0] == '\0') {
|
||||||
strncpy(fullpath, path, path_len);
|
strncpy(fullpath, path, path_len);
|
||||||
return fullpath;
|
return fullpath;
|
||||||
|
|||||||
@@ -542,7 +542,7 @@ static int _smartdns_create_logdir(void)
|
|||||||
int gid = 0;
|
int gid = 0;
|
||||||
char logdir[PATH_MAX] = {0};
|
char logdir[PATH_MAX] = {0};
|
||||||
safe_strncpy(logdir, _smartdns_log_path(), PATH_MAX);
|
safe_strncpy(logdir, _smartdns_log_path(), PATH_MAX);
|
||||||
dirname(logdir);
|
dir_name(logdir);
|
||||||
|
|
||||||
if (access(logdir, F_OK) == 0) {
|
if (access(logdir, F_OK) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
11
src/util.c
11
src/util.c
@@ -29,6 +29,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <linux/capability.h>
|
#include <linux/capability.h>
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#include <linux/netlink.h>
|
#include <linux/netlink.h>
|
||||||
@@ -109,6 +110,16 @@ unsigned long get_tick_count(void)
|
|||||||
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
return (ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *dir_name(char *path)
|
||||||
|
{
|
||||||
|
if (strstr(path, "/") == NULL) {
|
||||||
|
safe_strncpy(path, "./", PATH_MAX);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dirname(path);
|
||||||
|
}
|
||||||
|
|
||||||
char *get_host_by_addr(char *host, int maxsize, struct sockaddr *addr)
|
char *get_host_by_addr(char *host, int maxsize, struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage *addr_store = (struct sockaddr_storage *)addr;
|
struct sockaddr_storage *addr_store = (struct sockaddr_storage *)addr;
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ void bug_ext(const char *file, int line, const char *func, const char *errfmt, .
|
|||||||
|
|
||||||
unsigned long get_tick_count(void);
|
unsigned long get_tick_count(void);
|
||||||
|
|
||||||
|
char *dir_name(char *path);
|
||||||
|
|
||||||
char *get_host_by_addr(char *host, int maxsize, struct sockaddr *addr);
|
char *get_host_by_addr(char *host, int maxsize, struct sockaddr *addr);
|
||||||
|
|
||||||
int getaddr_by_host(const char *host, struct sockaddr *addr, socklen_t *addr_len);
|
int getaddr_by_host(const char *host, struct sockaddr *addr, socklen_t *addr_len);
|
||||||
|
|||||||
Reference in New Issue
Block a user