diff options
author | Christian Hesse <mail@eworm.de> | 2016-03-15 15:40:02 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2016-03-15 15:40:02 +0100 |
commit | 0db83386f2effba1be59ed301d9b400b57207b0a (patch) | |
tree | 9932d18d83ff72b2319c60fcb1a76c45d318378f | |
parent | fcd79f550b23182705d86ca3520db5ea60e37453 (diff) | |
download | dyndhcpd-0db83386f2effba1be59ed301d9b400b57207b0a.tar.gz dyndhcpd-0db83386f2effba1be59ed301d9b400b57207b0a.tar.zst |
add built in config for fallback
-rw-r--r-- | config.def.h | 14 | ||||
-rw-r--r-- | dyndhcpd.c | 39 |
2 files changed, 33 insertions, 20 deletions
diff --git a/config.def.h b/config.def.h index 0195c03..43cddc3 100644 --- a/config.def.h +++ b/config.def.h @@ -22,6 +22,20 @@ #define PIDFILE "/run/dhcpd-%s.pid" #define LEASESFILE "/var/lib/dhcp/dhcp-%s.leases" +#define FALLBACKCONFIG \ + "# fallback dhcpd.conf for interface __INTERFACE__\n" \ + "# generated by dyndhcpd/__VERSION__\n" \ + "\n" \ + "authoritative;\n" \ + "option domain-name \"__DOMAINNAME__\";\n" \ + "\n" \ + "subnet __NETADDRESS__ netmask __NETMASK__ {\n" \ + "\toption broadcast-address __BROADCAST__;\n" \ + "\toption routers __ADDRESS__;\n" \ + "\toption domain-name-servers __ADDRESS__;\n" \ + "\trange __MINDHCP__ __MAXDHCP__;\n" \ + "}" + #endif /* _CONFIG_H */ // vim: set syntax=c: @@ -47,7 +47,7 @@ int main(int argc, char ** argv) { char * template = NULL; FILE * templatefile; - const char * templatefilename = NULL; + const char * templatefilename = CONFIG_TEMPLATE; char * config = NULL; FILE * configfile; char * configfilename = NULL; @@ -209,26 +209,25 @@ int main(int argc, char ** argv) { } /* open the template for reading */ - if (templatefilename == NULL) - templatefilename = CONFIG_TEMPLATE; - if ((templatefile = fopen(templatefilename, "r")) == NULL) { - fprintf(stderr, "Failed opening config template for reading.\n"); - goto out; - } - - /* seek to the and so we know the file size */ - fseek(templatefile, 0, SEEK_END); - fsize = ftell(templatefile); - fseek(templatefile, 0, SEEK_SET); - - /* allocate memory and read file */ - template = malloc(fsize + 1); - if ((fread(template, fsize, 1, templatefile)) != 1) { - fprintf(stderr, "Failed reading config template.\n"); - goto out; + if ((templatefile = fopen(templatefilename, "r")) != NULL) { + /* seek to the and so we know the file size */ + fseek(templatefile, 0, SEEK_END); + fsize = ftell(templatefile); + fseek(templatefile, 0, SEEK_SET); + + /* allocate memory and read file */ + template = malloc(fsize + 1); + if ((fread(template, fsize, 1, templatefile)) != 1) { + fprintf(stderr, "Failed reading config template.\n"); + goto out; + } + fclose(templatefile); + template[fsize] = 0; + } else { + fprintf(stderr, "Failed opening config template for reading.\n" + "Using fallback to built in defaults, functionality is limited.\n"); + template = strdup(FALLBACKCONFIG); } - fclose(templatefile); - template[fsize] = 0; /* replace strings with real values */ for (tmp = template; *tmp;) { |