From edcc9412a86d02ec441b24222b270375565c327f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 24 Feb 2025 05:57:49 +0100 Subject: [PATCH] Assume DHCP_LEASETIME is in hours if imported from setupVars.conf (e.g., via Teleporter or during migration) Signed-off-by: DL6ER --- src/config/setupVars.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/config/setupVars.c b/src/config/setupVars.c index 4cf37cb65..537cb9ea6 100644 --- a/src/config/setupVars.c +++ b/src/config/setupVars.c @@ -39,10 +39,25 @@ static void get_conf_string_from_setupVars(const char *key, struct conf_item *co return; } + // If the lease time is a raw value (no unit), we assume it is in hours + // as this was the standard convention in the past + char *new = strdup(setupVarsValue); + if(strcmp(key, "DHCP_LEASETIME") == 0 && strchr(new, 'h') == NULL) + { + int leaseTimeInHours = atoi(new); + free(new); + if((new = calloc(10, sizeof(char))) == NULL) + { + log_warn("get_conf_string_from_setupVars(%s) failed: Could not allocate memory for new", key); + return; + } + snprintf(new, 10, "%dh", leaseTimeInHours); + } + // Free previously allocated memory (if applicable) if(conf_item->t == CONF_STRING_ALLOCATED) free(conf_item->v.s); - conf_item->v.s = strdup(setupVarsValue); + conf_item->v.s = new; conf_item->t = CONF_STRING_ALLOCATED; conf_item->f |= FLAG_CONF_IMPORTED;