From f09bf2e90cb9d7de92ba2a0f35ca4e78dfe3236c Mon Sep 17 00:00:00 2001 From: Teemu Toivola Date: Tue, 6 Jan 2015 21:38:22 +0200 Subject: [PATCH] define maximum allowed config value for bandwidth, search config file also from /usr/local/etc/vnstat.conf --- src/cfg.c | 5 ++++- src/common.h | 3 +++ src/ibw.c | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cfg.c b/src/cfg.c index c84ed71..b1ad45e 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -262,6 +262,9 @@ int loadcfg(const char *cfgfile) } else if ((fd=fopen("/etc/vnstat.conf", "r"))!=NULL) { if (debug) printf("Config file: /etc/vnstat.conf\n"); + } else if ((fd=fopen("/usr/local/etc/vnstat.conf", "r"))!=NULL) { + if (debug) + printf("Config file: /usr/local/etc/vnstat.conf\n"); } else { if (debug) printf("Config file: none\n"); @@ -394,7 +397,7 @@ void validatecfg(void) printe(PT_Config); } - if (cfg.maxbw<0 || cfg.maxbw>10000) { + if (cfg.maxbw<0 || cfg.maxbw>BWMAX) { cfg.maxbw = DEFMAXBW; snprintf(errorstring, 512, "Invalid value for MaxBandwidth, resetting to \"%d\".", cfg.maxbw); printe(PT_Config); diff --git a/src/common.h b/src/common.h index 5547628..8a43480 100644 --- a/src/common.h +++ b/src/common.h @@ -111,6 +111,9 @@ and most can be changed later from the config file. /* 0 = feature disabled */ #define DEFMAXBW 100 +/* maximum allowed config value for bandwidth */ +#define BWMAX 10000 + /* how many seconds should sampling take by default */ #define DEFSAMPTIME 5 diff --git a/src/ibw.c b/src/ibw.c index bc50e0b..c8e313d 100644 --- a/src/ibw.c +++ b/src/ibw.c @@ -45,6 +45,9 @@ int ibwloadcfg(const char *cfgfile) } else if ((fd=fopen("/etc/vnstat.conf", "r"))!=NULL) { if (debug) printf("IBW Config file: /etc/vnstat.conf\n"); + } else if ((fd=fopen("/usr/local/etc/vnstat.conf", "r"))!=NULL) { + if (debug) + printf("IBW Config file: /usr/local/etc/vnstat.conf\n"); } else { if (debug) printf("IBW Config file: none\n"); @@ -244,7 +247,7 @@ int ibwcfgread(FILE *fd) /* add interface and limit to list if value is within limits */ ivalue = atoi(value); - if (ivalue<0 || ivalue>10000) { + if (ivalue<0 || ivalue>BWMAX) { snprintf(errorstring, 512, "Invalid value \"%d\" for MaxBW%s, ignoring parameter.", ivalue, name); printe(PT_Config); } else { -- 2.40.0