Skip to content

Commit

Permalink
allow to override smartdns config. introduce config path helper
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.dd-wrt.com/DD-WRT@43979 52c4871e-980c-0410-b1e0-e73912ce01f8
  • Loading branch information
BrainSlayer committed Jul 27, 2020
1 parent 98822ee commit 6b34c7f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 56 deletions.
11 changes: 11 additions & 0 deletions src/router/libutils/libutils/bcmutils.c
Expand Up @@ -384,6 +384,17 @@ int weekday(int month, int day, int year)

}

const char *_getdefaultconfig(char *path, char *configname) {
sprintf(path, "/jffs/etc/%s", configname);
FILE *fp = fopen(path, "r"); //test if custom config is available
if (fp != NULL) {
fclose(fp);
} else {
sprintf(path, "/tmp/%s", configname);
}
return path;
}

char *get_ipfrominterface(char *ifname, char *ip)
{
int fd;
Expand Down
10 changes: 1 addition & 9 deletions src/router/services/services/dnsmasq.c
Expand Up @@ -503,15 +503,7 @@ void start_dnsmasq(void)

chmod("/etc/lease_update.sh", 0700);

FILE *conf = NULL;
conf = fopen("/jffs/etc/dnsmasq.conf", "r"); //test if custom config is available

if (conf != NULL) {
eval("dnsmasq", "-u", "root", "-g", "root", "--conf-file=/jffs/etc/dnsmasq.conf");
fclose(conf);
} else {
eval("dnsmasq", "-u", "root", "-g", "root", "--conf-file=/tmp/dnsmasq.conf");
}
eval("dnsmasq", "-u", "root", "-g", "root", "-C", getdefaultconfig("dnsmasq.conf"));

dd_loginfo("dnsmasq", "daemon successfully started\n");

Expand Down
8 changes: 1 addition & 7 deletions src/router/services/services/lighttpd.c
Expand Up @@ -131,13 +131,7 @@ void start_lighttpd(void)
fclose(fp);
}

fp = fopen("/jffs/etc/lighttpd.conf", "r"); //test if custom config is available
if (fp != NULL) {
eval("lighttpd", "-f", "/jffs/etc/lighttpd.conf");
fclose(fp);
} else {
eval("lighttpd", "-f", "/tmp/lighttpd.conf");
}
eval("lighttpd", "-f", getdefaultconfig("lighttpd.conf"));

dd_loginfo("lighttpd", "lighttpd started\n");
return;
Expand Down
8 changes: 1 addition & 7 deletions src/router/services/services/minidlna.c
Expand Up @@ -125,13 +125,7 @@ void start_dlna(void)
fprintf(fp, "notify_interval=300\n");
fprintf(fp, "serial=12345678\nmodel_number=AllShare1.0\n");
fclose(fp);
fp = fopen("/jffs/etc/minidlna.conf", "r"); //test if custom config is available
if (fp != NULL) {
eval("minidlna", "-f", "/jffs/etc/minidlna.conf");
fclose(fp);
} else {
eval("minidlna", "-f", "/tmp/minidlna.conf");
}
eval("minidlna", "-f", getdefaultconfig("minidlna.conf"));
dd_loginfo("minidlna", "DLNA Media Server successfully started\n");

return;
Expand Down
29 changes: 8 additions & 21 deletions src/router/services/services/samba3.c
Expand Up @@ -227,30 +227,22 @@ void start_samba3(void)
#ifndef HAVE_SMBD
char conffile[64];

fp = fopen("/jffs/etc/smb.conf", "r"); //test if custom config is available
if (fp != NULL) {
strcpy(conffile, "--configfile=/jffs/etc/smb.conf");
fclose(fp);
} else {
strcpy(conffile, "--configfile=/tmp/smb.conf");
}

#ifdef HAVE_SMP
if (eval("/usr/bin/taskset", "0x2", "/usr/sbin/smbd", "-D", conffile))
if (eval("/usr/bin/taskset", "0x2", "/usr/sbin/smbd", "-D", "-s",getdefaultconfig("smb.conf")))
#endif
eval("/usr/sbin/smbd", "-D", conffile);
eval("/usr/sbin/nmbd", "-D", conffile);
eval("/usr/sbin/smbd", "-D", "-s",getdefaultconfig("smb.conf"));
eval("/usr/sbin/nmbd", "-D", "-s",getdefaultconfig("smb.conf"));
if (pidof("nmbd") <= 0) {
eval("/usr/sbin/nmbd", "-D", conffile);
eval("/usr/sbin/nmbd", "-D", "-s",getdefaultconfig("smb.conf"));
}
if (pidof("smbd") <= 0) {
#ifdef HAVE_SMP
if (eval("/usr/bin/taskset", "0x2", "/usr/sbin/smbd", "-D", conffile))
if (eval("/usr/bin/taskset", "0x2", "/usr/sbin/smbd", "-D", "-s",getdefaultconfig("smb.conf")))
#endif
eval("/usr/sbin/smbd", "-D", conffile);
eval("/usr/sbin/smbd", "-D", "-s",getdefaultconfig("smb.conf"));
}
#ifdef HAVE_SAMBA4
eval("/usr/sbin/winbindd", "-D", conffile);
eval("/usr/sbin/winbindd", "-D", "-s",getdefaultconfig("smb.conf"));
#endif
#else
insmod("nls_base nls_utf8 crypto_hash crypto_null aead aead2 sha256_generic sha512_generic seqiv arc4 ecb" //
Expand All @@ -270,12 +262,7 @@ void start_samba3(void)
sprintf(parm, "vendor:dd-wrt,model:%s,sku:%s", nvram_safe_get("DD_BOARD"), nvram_safe_get("os_version"));
eval("wsdd2", "-d", "-N", nbname, "-G", wgname, "-b", parm);
}
fp = fopen("/jffs/etc/smb.conf", "r"); //test if custom config is available
if (fp != NULL) {
fclose(fp);
eval("ksmbd.mountd", "-c", "/jffs/etc/smb.conf", "-u", "/jffs/etc/smb.db");
} else
eval("ksmbd.mountd", "-c", "/tmp/smb.conf", "-u", "/tmp/smb.db");
eval("ksmbd.mountd", "-c", getdefaultconfig("smb.conf"), "-u", getdefaultconfig("smb.db"));
#endif

dd_loginfo("smbd", "samba started\n");
Expand Down
3 changes: 2 additions & 1 deletion src/router/services/services/smartdns.c
Expand Up @@ -83,7 +83,8 @@ void start_smartdns(void)
}
}
fclose(fp);
eval("smartdns", "-c", "/tmp/smartdns.conf");

eval("smartdns", "-c", getdefaultconfig("smartdns.conf"));
dd_loginfo("smartdns", "daemon successfully started\n");
}

Expand Down
10 changes: 1 addition & 9 deletions src/router/services/services/unbound.c
Expand Up @@ -154,15 +154,7 @@ void start_unbound(void)
if (nvram_matchi("recursive_dns", 1)) {
update_timezone();
unbound_config();

fp = fopen("/jffs/etc/unbound.conf", "r"); //test if custom config is available

if (fp != NULL) {
fclose(fp);
eval("unbound", "-c", "/jffs/etc/unbound.conf");
} else {
eval("unbound", "-c", "/tmp/unbound.conf");
}
eval("unbound", "-c", getdefaultconfig("unbound.conf"));

dd_loginfo("unbound", "recursive dns resolver daemon successfully started\n");
}
Expand Down
23 changes: 21 additions & 2 deletions src/router/shared/utils.h
Expand Up @@ -967,8 +967,8 @@ enum { FIRST, SECOND };

#define ACTION(cmd) buf_to_file(ACTION_FILE, cmd)
struct dns_entry {
int type; //0 = isp, 1 = user defined
int ipv6; // 0 = ipv4, 1 = ipv6
int type; //0 = isp, 1 = user defined
int ipv6; // 0 = ipv4, 1 = ipv6
char *ip;
};

Expand Down Expand Up @@ -1139,10 +1139,12 @@ static inline int is_ath5k(const char *prefix)
{
return 0;
}

static inline int is_ath5k_pci(const char *prefix)
{
return 0;
}

static inline int is_ath5k_ahb(const char *prefix)
{
return 0;
Expand Down Expand Up @@ -1182,22 +1184,27 @@ static inline int has_spectralscanning(char *prefix)
{
return 0;
}

static inline int has_qboost(char *prefix)
{
return 0;
}

static inline int has_nolivesurvey(char *prefix)
{
return 0;
}

static inline int has_qboost_tdma(char *prefix)
{
return 0;
}

static inline int has_beacon_limit(char *prefix)
{
return 0;
}

static inline int has_channelsurvey(char *prefix)
{
return 0;
Expand Down Expand Up @@ -1347,6 +1354,18 @@ int nvram_backup(char *filename);

int nvram_restore(char *filename, int force);

const char *_getdefaultconfig(char *path, char *configname);

#define getdefaultconfig(configname) \
({ \
const char *__ret = NULL; \
do { \
char def_path[64]; \
__ret = _getdefaultconfig(def_path, configname); \
} while(0); \
__ret; \
})

void nvram_clear(void);
int nvram_critical(char *name);
void getSystemMac(char *mac);
Expand Down

0 comments on commit 6b34c7f

Please sign in to comment.