Skip to content
This repository was archived by the owner on Nov 29, 2020. It is now read-only.

Commit 6d47bc6

Browse files
committed
Implemented dnsmasq.postconf scripts
1 parent 9c3582a commit 6d47bc6

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

release/src/router/rc/services.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,10 +1672,12 @@ void start_dnsmasq(void)
16721672
#elif (defined(RTCONFIG_TR069) && !defined(RTCONFIG_TR181))
16731673
fprintf(fp, "dhcp-script=/sbin/dhcpc_lease\n");
16741674
#endif
1675-
1675+
append_custom_config("dnsmasq.conf", fp);
16761676
/* close fp move to the last */
16771677
fclose(fp);
1678-
1678+
use_custom_config("dnsmasq.conf", "/etc/dnsmasq.conf");
1679+
run_postconf("dnsmasq", "/etc/dnsmasq.conf");
1680+
chmod("/etc/dnsmasq.conf", 0644);
16791681
/* Create resolv.conf with empty nameserver list */
16801682
f_write(dmresolv, NULL, 0, FW_APPEND, 0666);
16811683
/* Create resolv.dnsmasq with empty server list */

release/src/router/shared/shared.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,8 @@ extern int discover_interface(const char *current_wan_ifname, int dhcp_det);
16861686
extern int discover_all(int wan_unit);
16871687

16881688
// strings.c
1689+
extern int replace_char(char *str, const char from, const char to);
1690+
extern int str_escape_quotes(const char *output, const char *input, int outsize);
16891691
extern int char_to_ascii_safe(const char *output, const char *input, int outsize);
16901692
extern void char_to_ascii(const char *output, const char *input);
16911693
#if defined(RTCONFIG_UTF8_SSID)
@@ -1844,7 +1846,6 @@ void set_macfilter_all(FILE *fp);
18441846
#else
18451847
static inline char *get_wsup_drvname(__attribute__ ((unused)) int band) { return ""; }
18461848
#endif
1847-
extern int replace_char(char *str, const char from, const char to);
18481849
#ifdef RTCONFIG_TRAFFIC_LIMITER
18491850
extern unsigned int traffic_limiter_read_bit(const char *type);
18501851
extern void traffic_limiter_set_bit(const char *type, int unit);

release/src/router/shared/strings.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@
1717
#include "shutils.h"
1818
#include "shared.h"
1919

20-
int replace_char(char *str, const char from, const char to)
21-
{
22-
char *p = str;
23-
while (*p) {
24-
if (*p == from)
25-
*p = to;
26-
p++;
27-
}
28-
return 1;
29-
}
30-
3120
#if defined(RTCONFIG_UTF8_SSID)
3221
int is_utf8(const char * string)
3322
{
@@ -327,6 +316,44 @@ int remove_word(char *buffer, const char *word)
327316
return 1;
328317
}
329318

319+
int replace_char(char *str, const char from, const char to)
320+
{
321+
char *p = str;
322+
while (*p) {
323+
if (*p == from)
324+
*p = to;
325+
p++;
326+
}
327+
return 1;
328+
}
329+
330+
/* Escape characters that could break a Javascript array */
331+
int str_escape_quotes(const char *output, const char *input, int outsize)
332+
{
333+
char *src = (char *)input;
334+
char *dst = (char *)output;
335+
char *end = (char *)output + outsize - 1;
336+
char *escape = "'\"\\";
337+
338+
if (src == NULL || dst == NULL || outsize <= 0)
339+
return 0;
340+
341+
for ( ; *src && dst < end; src++) {
342+
if (strchr(escape, *src)) {
343+
if (dst + 2 > end)
344+
break;
345+
*dst++ = '\\';
346+
*dst++ = *src;
347+
} else {
348+
*dst++ = *src;
349+
}
350+
}
351+
if (dst <= end)
352+
*dst = '\0';
353+
354+
return dst - output;
355+
}
356+
330357
void trim_space(char *str)
331358
{
332359
char *pt;

0 commit comments

Comments
 (0)