/* This will rewrite /etc/hosts, /etc/hosts.*, and the apache ServerName file. */ int writehostsfiles(void) { char address[STRING_SIZE] = ""; char netaddress[STRING_SIZE] = ""; char netmask[STRING_SIZE] = ""; FILE *file; struct keyvalue *kv; char hostname[STRING_SIZE]; char commandstring[STRING_SIZE]; kv = initkeyvalues(); if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } findkey(kv, "GREEN_ADDRESS", address); findkey(kv, "GREEN_NETADDRESS", netaddress); findkey(kv, "GREEN_NETMASK", netmask); freekeyvalues(kv); kv = initkeyvalues(); if (!(readkeyvalues(kv, CONFIG_ROOT "main/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(hostname, "smoothwall"); findkey(kv, "HOSTNAME", hostname); freekeyvalues(kv); if (!(file = fopen(CONFIG_ROOT "main/hostname.conf", "w"))) { errorbox(ctr[TR_UNABLE_TO_WRITE_VAR_SMOOTHWALL_MAIN_HOSTNAMECONF]); return 0; } fprintf(file, "ServerName %s\n", hostname); fclose(file); if (mysystem("/usr/bin/smoothwall/writehosts.pl")) { errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_HOSTS]); return 0; } sprintf(commandstring, "/bin/hostname %s", hostname); if (mysystem(commandstring)) { errorbox(ctr[TR_UNABLE_TO_SET_HOSTNAME]); return 0; } return 1; }
int clear_card_entry(int card) { struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE]; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } strcpy(knics[card].driver, ""); strcpy(knics[card].description, _("Unset")); strcpy(knics[card].macaddr, ""); strcpy(knics[card].colour, ""); sprintf(temp, "%s_DRIVER", ucolourcard[card]); replacekeyvalue(kv, temp, ""); sprintf(temp, "%s_DEV", ucolourcard[card]); replacekeyvalue(kv, temp, ""); sprintf(temp, "%s_MACADDR", ucolourcard[card]); replacekeyvalue(kv, temp, ""); sprintf(temp, "%s_DESCRIPTION", ucolourcard[card]); replacekeyvalue(kv, temp, ""); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); freekeyvalues(kv); return 0; }
int write_configs_netudev(int card , int colour) { char commandstring[STRING_SIZE]; struct keyvalue *kv = initkeyvalues(); char temp1[STRING_SIZE], temp2[STRING_SIZE], temp3[STRING_SIZE]; char ucolour[STRING_SIZE]; sprintf(ucolour, ucolourcard[colour]); strcpy(knics[colour].driver, nics[card].driver); strcpy(knics[colour].description, nics[card].description); strcpy(knics[colour].macaddr, nics[card].macaddr); if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } sprintf(temp1, "%s_DEV", ucolour); sprintf(temp2, "%s_MACADDR", ucolour); sprintf(temp3, "%s0", lcolourcard[colour]); replacekeyvalue(kv, temp1, temp3); replacekeyvalue(kv, temp2, nics[card].macaddr); sprintf(temp1, "%s_DESCRIPTION", ucolour); replacekeyvalue(kv, temp1, nics[card].description); sprintf(temp1, "%s_DRIVER", ucolour); replacekeyvalue(kv, temp1, nics[card].driver); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); freekeyvalues(kv); return 0; }
int get_knic(int card) //returns "0" for zero cards or error and "1" card is found. { struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE], searchstr[STRING_SIZE]; int ret_value; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } sprintf(searchstr, "%s_MACADDR", ucolourcard[card]); strcpy(temp, ""); findkey(kv, searchstr, temp); if (strlen(temp)) { strcpy(knics[ card ].macaddr, temp); strcpy(knics[ card ].colour, ucolourcard[card]); sprintf(searchstr, "%s_DESCRIPTION", ucolourcard[card]); findkey(kv, searchstr, temp); strcpy(knics[ card ].description, temp); sprintf(searchstr, "%s_DRIVER", ucolourcard[card]); findkey(kv, searchstr, temp); strcpy(knics[ card ].driver, temp); ret_value = 1; } else { strcpy(knics[ card ].description, _("Unset")); ret_value = 0; } freekeyvalues(kv); return ret_value; }
// Let user change GREEN address. int greenaddressmenu(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } sprintf(message, _("If you change this IP address, and you are logged in remotely, " "your connection to the %s machine will be broken, and you will have to reconnect " "on the new IP. This is a risky operation, and should only be attempted if you " "have physical access to the machine, should something go wrong."), NAME); rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); writehostsfiles(); } } freekeyvalues(kv); return 0; }
void handleisdnprotocol(char **protocolnames) { int rc; int choice; struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "1"; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "PROTOCOL", temp); choice = atol(temp) - 1; rc = newtWinMenu(ctr[TR_ISDN_PROTOCOL_SELECTION], ctr[TR_CHOOSE_THE_ISDN_PROTOCOL], 50, 5, 5, 6, protocolnames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 2) return; sprintf(temp, "%d", choice + 1); replacekeyvalue(kv, "PROTOCOL", temp); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); freekeyvalues(kv); }
/* Let user change GREEN address. */ int greenaddressmenu(void) { struct keyvalue *kv = initkeyvalues(); int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_WARNING_LONG]); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); writehostsfiles(); } } freekeyvalues(kv); return 0; }
int main(int argc, char *argv[]) { struct keyvalue* kv = NULL; int fd = -1; int r = 0; if (!(initsetuid())) exit(1); if (argc < 2) { fprintf(stderr, "\nNo argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n"); exit(1); } if (strcmp(argv[1], "generate") == 0) { kv = initkeyvalues(); if (!readkeyvalues(kv, CONFIG_ROOT "/qos/settings")) { fprintf(stderr, "Cannot read QoS settings\n"); r = 1; goto END; } char enabled[STRING_SIZE]; if (!findkey(kv, "ENABLED", enabled)) strcpy(enabled, "off"); if (strcmp(enabled, "on") == 0) safe_system("/usr/bin/perl /var/ipfire/qos/bin/makeqosscripts.pl > " QOS_SH); else unlink(QOS_SH); } if ((fd = open(QOS_SH, O_RDONLY)) != -1) { close(fd); } else { // If there is no qos.sh do nothing. goto END; } safe_system("chmod 755 " QOS_SH " &>/dev/null"); if (strcmp(argv[1], "start") == 0) { safe_system(QOS_SH " start"); } else if (strcmp(argv[1], "stop") == 0) { safe_system(QOS_SH " clear"); } else if (strcmp(argv[1], "status") == 0) { safe_system(QOS_SH " status"); } else if (strcmp(argv[1], "restart") == 0) { safe_system(QOS_SH " restart"); } else { if (strcmp(argv[1], "generate") == 0) {exit(0);} fprintf(stderr, "\nBad argument given.\n\nqosctrl (start|stop|restart|status|generate)\n\n"); exit(1); } END: if (kv) freekeyvalues(kv); return r; }
int probeisdncard(void) { int c; char message[STRING_SIZE]; char commandstring[STRING_SIZE]; char moduleparams[STRING_SIZE] = ""; struct keyvalue *kv = initkeyvalues(); int result = -1; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return -1; } findkey(kv, "MODULE_PARAMS", moduleparams); c = 1; while (cards[c].name) { sprintf(message, ctr[TR_CHECKING_FOR], cards[c].name); /* * For USB ISDN.... * just check /proc/bus/usb/devices for our supported device */ if (cards[c].type == 100) { if (probeusbisdncard("Vendor=0483 ProdID=481")) sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=1 %s", moduleparams); else goto CONTINUE; } else { sprintf(commandstring, "/sbin/modprobe hisax type=%d protocol=1 %s", cards[c].type, moduleparams); } if (runcommandwithstatus(commandstring, message) == 0) { mysystem("/etc/ppp/isdn-cleanup"); sprintf(message, ctr[TR_DETECTED], cards[c].name); newtWinMessage(TITLE, ctr[TR_OK], message); result = cards[c].type; goto EXIT; } CONTINUE: c++; } errorbox(ctr[TR_UNABLE_TO_FIND_AN_ISDN_CARD]); EXIT: freekeyvalues(kv); return result; }
int handlehostname(void) { char hostname[STRING_SIZE] = ""; struct keyvalue *kv = initkeyvalues(); char *values[] = { hostname, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; int result; if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } strcpy(hostname, SNAME); findkey(kv, "HOSTNAME", hostname); for (;;) { rc = newtWinEntries(_("Hostname"), _("Enter the machine's hostname."), 50, 5, 5, 40, entries, _("OK"), _("Cancel"), NULL); if (rc == 1) { strcpy(hostname, values[0]); if (!(strlen(hostname))) errorbox(_("Hostname cannot be empty.")); else if (strchr(hostname, ' ')) errorbox(_("Hostname cannot contain spaces.")); else if (strlen(hostname) != strspn(hostname, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-")) errorbox(_("Hostname may only contain letters, numbers and hyphens.")); else { replacekeyvalue(kv, "HOSTNAME", hostname); writekeyvalues(kv, CONFIG_ROOT "/main/settings"); writehostsfiles(); result = 1; break; } } else { result = 0; break; } } free(values[0]); freekeyvalues(kv); return result; }
/* Here they choose general network config, number of nics etc. */ int configtypemenu(void) { struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "1"; char message[1000]; int choise, found; int rc, configtype; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } found = scan_network_cards(); findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp); choise--; sprintf(message, _("Select the network configuration for %s. " "The following configuration types list those interfaces which have ethernet attached. " "If you change this setting, a network restart will be required, and you will have to " "reconfigure the network driver assignments."), NAME); rc = newtWinMenu(_("Network configuration type"), message, 50, 5, 5, 6, configtypenames, &choise, _("OK"), _("Cancel"), NULL); if ( configtypecards[choise] > found ) { sprintf(message, _("Not enough netcards for your choice.\n\nNeeded: %d - Available: %d\n"), configtypecards[choise], found); errorbox(message); } if (rc == 0 || rc == 1) { choise++; sprintf(temp, "%d", choise); replacekeyvalue(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (!HAS_RED) clear_card_entry(_RED_CARD_); if (!HAS_ORANGE) clear_card_entry(_ORANGE_CARD_); if (!HAS_BLUE) clear_card_entry(_BLUE_CARD_); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); netaddresschange = 1; } freekeyvalues(kv); return 0; }
/* Returns 0 if main ISDN setup loop should exit. */ int isdnenabledpressed(void) { struct keyvalue *kv = initkeyvalues(); char protocol[STRING_SIZE] = ""; char type[STRING_SIZE] = ""; char msn[STRING_SIZE] = ""; char moduleparams[STRING_SIZE] = ""; char commandstring[STRING_SIZE]; int result = 0; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } findkey(kv, "PROTOCOL", protocol); findkey(kv, "TYPE", type); findkey(kv, "MSN", msn); findkey(kv, "MODULE_PARAMS", moduleparams); if (strlen(protocol) && strlen(type) && strlen(msn)) { if (!strcmp(type, "100")) { sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=%s %s", protocol, moduleparams); } else { sprintf(commandstring, "/sbin/modprobe hisax protocol=%s type=%s %s", protocol, type, moduleparams); } if (runcommandwithstatus(commandstring, ctr[TR_INITIALISING_ISDN]) != 0) { errorbox(ctr[TR_UNABLE_TO_INITIALISE_ISDN]); replacekeyvalue(kv, "ENABLED", "off"); result = 1; } else replacekeyvalue(kv, "ENABLED", "on"); } else { errorbox(ctr[TR_ISDN_NOT_SETUP]); replacekeyvalue(kv, "ENABLED", "off"); result = 1; } writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); freekeyvalues(kv); return result; }
/* Returns 0 if main ISDN setup loop should exit. */ int isdndisabledpressed(void) { struct keyvalue *kv = initkeyvalues(); if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } replacekeyvalue(kv, "ENABLED", "off"); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); freekeyvalues(kv); return 0; }
/* Shows the main menu and a summary of the current settings. */ int firstmenu(void) { char *sections[] = { _("Network configuration type"), _("Drivers and card assignments"), _("Address settings"), _("DNS and Gateway settings"), NULL }; int rc; static int choice = 0; struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE] = "1"; int x; int result; char networkrestart[STRING_SIZE] = ""; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } if (netaddresschange) strcpy(networkrestart, _("When configuration is complete, a network restart will be required.")); strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp); x--; if (x < 0 || x > 4) x = 0; /* Format heading bit. */ snprintf(message, 1000, _("Current config: %s\n\n%s"), configtypenames[x], networkrestart); rc = newtWinMenu(_("Network configuration menu"), message, 50, 5, 5, 6, sections, &choice, _("OK"), _("Done"), NULL); if (rc == 0 || rc == 1) result = choice + 1; else result = 0; return result; }
/* Shows the main menu and a summary of the current settings. */ int firstmenu(void) { char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE], ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_ADDRESS_SETTINGS], ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL, NULL }; int rc; static int choice = 0; struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE]; int x; int result; char networkrestart[STRING_SIZE] = ""; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } if (netaddresschange) strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]); strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp); if (x < 0 || x > 7) x = 0; /* Format heading bit. */ snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x], networkrestart); rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); if (rc == 0 || rc == 1) result = choice + 1; else result = 0; return result; }
void handleisdnmsn(void) { struct keyvalue *kv = initkeyvalues(); char msn[STRING_SIZE] = ""; const char *values[] = { msn, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "MSN", msn); for (;;) { rc = newtWinEntries(TITLE, ctr[TR_ENTER_THE_LOCAL_MSN], 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 1) { if (!(strlen(values[0]))) errorbox(ctr[TR_PHONENUMBER_CANNOT_BE_EMPTY]); else { strcpy(msn, values[0]); replacekeyvalue(kv, "MSN", msn); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); break; } } else break; } freekeyvalues(kv); free((char *) values[0]); }
/* Here they choose general network config, number of nics etc. */ int configtypemenu(void) { struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "0"; int choice; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp); rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], 50, 5, 5, 6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { runcommandwithstatus("/etc/rc.d/rc.netaddress.down", ctr[TR_PUSHING_NETWORK_DOWN]); sprintf(temp, "%d", choice); replacekeyvalue(kv, "CONFIG_TYPE", temp); replacekeyvalue(kv, "GREEN_DEV", ""); replacekeyvalue(kv, "ORANGE_DEV", ""); replacekeyvalue(kv, "PURPLE_DEV", ""); replacekeyvalue(kv, "RED_DEV", ""); writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); netaddresschange = 1; } freekeyvalues(kv); return 0; }
void handlemoduleparams(void) { struct keyvalue *kv = initkeyvalues(); char moduleparams[STRING_SIZE] = ""; const char *values[] = { moduleparams, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "MODULE_PARAMS", moduleparams); for (;;) { rc = newtWinEntries(TITLE, ctr[TR_ENTER_ADDITIONAL_MODULE_PARAMS], 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 1) { strcpy(moduleparams, values[0]); replacekeyvalue(kv, "MODULE_PARAMS", moduleparams); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); break; } else break; } free((char * ) values[0]); freekeyvalues(kv); }
// They can change BLUE, ORANGE and GREEN too :) int addressesmenu(void) { struct keyvalue *kv = initkeyvalues(); struct keyvalue *mainkv = initkeyvalues(); int rc = 0; char *sections[5]; char *green = "GREEN"; char *orange = "ORANGE"; char *blue = "BLUE"; char *red = "RED"; int c = 0; char greenaddress[STRING_SIZE]; char oldgreenaddress[STRING_SIZE]; char temp[STRING_SIZE]; char temp2[STRING_SIZE]; char message[1000]; int configtype; int done; int choice; char hostname[STRING_SIZE]; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(_("Unable to open settings file")); return 0; } if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(_("Unable to open settings file")); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); sections[c] = green; c++; if (HAS_BLUE) { sections[c] = blue; c++; } if (HAS_ORANGE) { sections[c] = orange; c++; } if (HAS_RED) { sections[c] = red; c++; } sections[c] = NULL; choice = 0; done = 0; while (!done) { rc = newtWinMenu(_("Address settings"), _("Select the interface you wish to reconfigure."), 50, 5, 5, 6, sections, &choice, _("OK"), _("Done"), NULL); if (rc == 0 || rc == 1) { if (strcmp(sections[choice], "GREEN") == 0) { findkey(kv, "GREEN_ADDRESS", oldgreenaddress); sprintf(message, _("If you change this IP address, and you are logged in remotely, " "your connection to the %s machine will be broken, and you will have to reconnect " "on the new IP. This is a risky operation, and should only be attempted if you " "have physical access to the machine, should something go wrong."), NAME); rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); writehostsfiles(); findkey(kv, "GREEN_ADDRESS", greenaddress); snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); } } } if (strcmp(sections[choice], "BLUE") == 0) { if (changeaddress(kv, "BLUE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "ORANGE") == 0) { if (changeaddress(kv, "ORANGE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "RED") == 0) { strcpy(hostname, ""); findkey(mainkv, "HOSTNAME", hostname); if (changeaddress(kv, "RED", 1, hostname)) netaddresschange = 1; } } else done = 1; } writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); freekeyvalues(kv); freekeyvalues(mainkv); return 0; }
int changedrivers(void) { struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE], message[STRING_SIZE]; int configtype; int green = 0, red = 0, blue = 0, orange = 0; char MenuInhalt[10][180]; char *pMenuInhalt[10]; int count = 0, choise = 0, rc; int NicEntry[10]; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } if (automode == 0) runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange", _("Networking"), _("Restarting non-local network..."), NULL); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (configtype == 1) { green = 1; red = 1; } else if (configtype == 2) { green = 1; red = 1; orange = 1; } else if (configtype == 3) { green = 1; red = 1; blue = 1; } else if (configtype == 4) { green = 1; red=1; orange=1; blue = 1; } else if (configtype == "") { green = 1; red = 1; } do { count = 0; strcpy(message, _("Please choose the interface you wish to change.\n\n")); if (green) { strcpy(MenuInhalt[count], "GREEN"); pMenuInhalt[count] = MenuInhalt[count]; NicEntry[_GREEN_CARD_] = count; sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description); strcat(message, temp); if ( strlen(knics[_GREEN_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr); strcat(message, temp); } count++; } if (red) { strcpy(MenuInhalt[count], "RED"); pMenuInhalt[count] = MenuInhalt[count]; NicEntry[_RED_CARD_] = count; sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description); strcat(message, temp); if ( strlen(knics[_RED_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr); strcat(message, temp); } count++; } if (orange) { strcpy(MenuInhalt[count], "ORANGE"); pMenuInhalt[count] = MenuInhalt[count]; NicEntry[_ORANGE_CARD_] = count; sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description); strcat(message, temp); if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr); strcat(message, temp); } count++; } if (blue) { strcpy(MenuInhalt[count], "BLUE"); pMenuInhalt[count] = MenuInhalt[count]; NicEntry[_BLUE_CARD_] = count; sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description); strcat(message, temp); if ( strlen(knics[_BLUE_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr); strcat(message, temp); } count++; } pMenuInhalt[count] = NULL; rc = newtWinMenu(_("Assigned Cards"), message, 70, 5, 5, 6, pMenuInhalt, &choise, _("Select"), _("Remove"), _("Done"), NULL); if ( rc == 0 || rc == 1) { if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_); if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_); if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_); if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_); netaddresschange = 1; } else if (rc == 2) { if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_); if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_); if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_); if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_); netaddresschange = 1; } } while ( rc <= 2); freekeyvalues(kv); return 1; }
/* Driver menu. Choose drivers.. */ int drivermenu(void) { struct keyvalue *kv = initkeyvalues(); char message[STRING_SIZE]; char temp[STRING_SIZE] = "1"; int configtype; int i, rc, kcount = 0, neednics; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } if (findkey(kv, "CONFIG_TYPE", temp)) configtype = atol(temp); else { fprintf(flog,"setting CONFIG_TYPE = %s\n",temp); configtype = atol(temp); replacekeyvalue(kv, "CONFIG_TYPE", temp); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); } strcpy(message, _("Configure network drivers, and which interface each card is assigned to. " "The current configuration is as follows:\n\n")); kcount = 0; neednics = 0; if (HAS_GREEN) { sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description); strcat(message, temp); if (strlen(knics[_GREEN_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr); strcat(message, temp); } neednics++; } if (HAS_RED) { sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description); strcat(message, temp); if (strlen(knics[_RED_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr); strcat(message, temp); } neednics++; } if (HAS_ORANGE) { sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description); strcat(message, temp); if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr); strcat(message, temp); } neednics++; } if (HAS_BLUE) { sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description); strcat(message, temp); if (strlen(knics[_BLUE_CARD_].macaddr)) { sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr); strcat(message, temp); } neednics++; } for ( i=0 ; i<4; i++) if (strcmp(knics[i].macaddr, "")) kcount++; if (neednics = kcount) { strcat(message, "\n"); strcat(message, _("Do you wish to change these settings?")); rc = newtWinChoice(_("Drivers and card assignments"), _("OK"), _("Cancel"), message); if (rc == 0 || rc == 1) { changedrivers(); } } else { changedrivers(); } freekeyvalues(kv); return 1; }
int oktoleave(void) { struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE]; int configtype; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (configtype < 1 || configtype > 4) configtype = 1; if (HAS_GREEN) { strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp); if (!(strlen(temp))) { errorbox(_("No GREEN interface assigned.")); freekeyvalues(kv); return 0; } if (!(interfacecheck(kv, "GREEN"))) { errorbox(_("Missing an IP address on GREEN.")); freekeyvalues(kv); return 0; } } if (HAS_RED) { strcpy(temp, ""); findkey(kv, "RED_DEV", temp); if (!(strlen(temp))) { rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"), _("No RED interface assigned.")); if (rc == 0 || rc == 1) { freekeyvalues(kv); return 0; } } if (!(interfacecheck(kv, "RED"))) { errorbox(_("Missing an IP address on RED.")); freekeyvalues(kv); return 0; } } if (HAS_ORANGE) { strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); if (!(strlen(temp))) { errorbox(_("No ORANGE interface assigned.")); freekeyvalues(kv); return 0; } if (!(interfacecheck(kv, "ORANGE"))) { errorbox(_("Missing an IP address on ORANGE.")); freekeyvalues(kv); return 0; } } if (HAS_BLUE) { strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp); if (!(strlen(temp))) { errorbox(_("No BLUE interface assigned.")); freekeyvalues(kv); return 0; } if (!(interfacecheck(kv, "BLUE"))) { errorbox(_("Missing an IP address on BLUE.")); freekeyvalues(kv); return 0; } } strcpy(temp, ""); findkey(kv, "RED_TYPE", temp); if ((configtype == 0) || (strcmp(temp, "STATIC") == 0)) { strcpy(temp, ""); findkey(kv, "DNS1", temp); if (!(strlen(temp))) { errorbox(_("Missing DNS.")); freekeyvalues(kv); return 0; } strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); if (!(strlen(temp))) { errorbox(_("Missing Default Gateway.")); freekeyvalues(kv); return 0; } } return 1; }
int main(int argc, char *argv[]) { char configtype[STRING_SIZE]; char redtype[STRING_SIZE] = ""; struct keyvalue *kv = NULL; if (argc < 2) { usage(); exit(1); } if (!(initsetuid())) exit(1); FILE *file = NULL; if (strcmp(argv[1], "I") == 0) { safe_system("/usr/sbin/ipsec status"); exit(0); } if (strcmp(argv[1], "R") == 0) { safe_system("/usr/sbin/ipsec reload >/dev/null 2>&1"); exit(0); } /* FIXME: workaround for pclose() issue - still no real idea why * this is happening */ signal(SIGCHLD, SIG_DFL); /* handle operations that doesn't need start the ipsec system */ if (argc == 2) { if (strcmp(argv[1], "D") == 0) { safe_system("/usr/sbin/ipsec stop >/dev/null 2>&1"); ipsec_norules(); exit(0); } } /* read vpn config */ kv=initkeyvalues(); if (!readkeyvalues(kv, CONFIG_ROOT "/vpn/settings")) { fprintf(stderr, "Cannot read vpn settings\n"); exit(1); } /* check is the vpn system is enabled */ { char s[STRING_SIZE]; findkey(kv, "ENABLED", s); freekeyvalues(kv); if (strcmp (s, "on") != 0) exit(0); } /* read interface settings */ kv=initkeyvalues(); if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")) { fprintf(stderr, "Cannot read ethernet settings\n"); exit(1); } if (!findkey(kv, "CONFIG_TYPE", configtype)) { fprintf(stderr, "Cannot read CONFIG_TYPE\n"); exit(1); } findkey(kv, "RED_TYPE", redtype); /* Loop through the config file to find physical interface that will accept IPSEC */ int enable_red=0; // states 0: not used int enable_green=0; // 1: error condition int enable_orange=0; // 2: good int enable_blue=0; char if_red[STRING_SIZE] = ""; char if_green[STRING_SIZE] = ""; char if_orange[STRING_SIZE] = ""; char if_blue[STRING_SIZE] = ""; char s[STRING_SIZE]; // when RED is up, find interface name in special file FILE *ifacefile = NULL; if ((ifacefile = fopen(CONFIG_ROOT "/red/iface", "r"))) { if (fgets(if_red, STRING_SIZE, ifacefile)) { if (if_red[strlen(if_red) - 1] == '\n') if_red[strlen(if_red) - 1] = '\0'; } fclose (ifacefile); if (VALID_DEVICE(if_red)) enable_red++; } // Check if GREEN is enabled. findkey(kv, "GREEN_DEV", if_green); if (VALID_DEVICE(if_green)) enable_green++; // Check if ORANGE is enabled. findkey(kv, "ORANGE_DEV", if_orange); if (VALID_DEVICE(if_orange)) enable_orange++; // Check if BLUE is enabled. findkey(kv, "BLUE_DEV", if_blue); if (VALID_DEVICE(if_blue)) enable_blue++; freekeyvalues(kv); // exit if nothing to do if ((enable_red+enable_green+enable_orange+enable_blue) == 0) exit(0); // open needed ports if (enable_red > 0) open_physical(if_red, 4500); if (enable_green > 0) open_physical(if_green, 4500); if (enable_orange > 0) open_physical(if_orange, 4500); if (enable_blue > 0) open_physical(if_blue, 4500); // start the system if ((argc == 2) && strcmp(argv[1], "S") == 0) { safe_system("/usr/sbin/ipsec restart >/dev/null"); exit(0); } // it is a selective start or stop // second param is only a number 'key' if ((argc == 2) || strspn(argv[2], NUMBERS) != strlen(argv[2])) { fprintf(stderr, "Bad arg: %s\n", argv[2]); usage(); exit(1); } // search the vpn pointed by 'key' if (!(file = fopen(CONFIG_ROOT "/vpn/config", "r"))) { fprintf(stderr, "Couldn't open vpn settings file"); exit(1); } while (fgets(s, STRING_SIZE, file) != NULL) { char *key; char *name; char *type; if (!decode_line(s,&key,&name,&type)) continue; // is it the 'key' requested ? if (strcmp(argv[2], key) != 0) continue; // Start or Delete this Connection if (strcmp(argv[1], "S") == 0) turn_connection_on (name, type); else if (strcmp(argv[1], "D") == 0) turn_connection_off (name); else { fprintf(stderr, "Bad command\n"); exit(1); } } fclose(file); return 0; }
int main(int argc, char *argv[]) { int choice; char *sections[13]; /* need to fill this out AFTER knowing lang */ int rc; struct keyvalue *kv; char selectedshortlang[STRING_SIZE] = "en"; int autook = 0; int doreboot = 0; struct stat statbuf; memset(&statbuf, 0, sizeof(struct stat)); /* Log file/terminal stuff. */ if (argc >= 2) logname = argv[1]; else logname = strdup("/root/setup.log"); if (!(flog = fopen(logname, "w+"))) { printf("Couldn't open log terminal\n"); return 1; } if (argc >= 3) automode = 1; fprintf(flog, "Setup program started.\n"); kv = initkeyvalues(); if (!(readkeyvalues(kv, CONFIG_ROOT "main/settings"))) { printf("SmoothWall is not properly installed.\n"); return 1; } findkey(kv, "LANGUAGE", selectedshortlang); ctr = english_tr; newtInit(); newtCls(); newtDrawRootText(0, 0, " SmoothWall Express 3.0 -- http://smoothwall.org/"); newtPushHelpLine(ctr[TR_HELPLINE]); if (automode == 0) { sections[0] = ctr[TR_RESTORE_CONFIGURATION]; sections[1] = ctr[TR_KEYBOARD_MAPPING]; sections[2] = ctr[TR_HOSTNAME]; sections[3] = ctr[TR_WEB_PROXY]; sections[4] = ctr[TR_DEFAULT_SECURITY_LEVEL]; sections[5] = ctr[TR_ISDN_CONFIGURATION]; sections[6] = ctr[TR_ADSL_CONFIGURATION]; sections[7] = ctr[TR_NETWORKING]; sections[8] = ctr[TR_DHCP_SERVER_CONFIGURATION], sections[9] = ctr[TR_ROOT_PASSWORD]; sections[10] = ctr[TR_SETUP_PASSWORD]; sections[11] = ctr[TR_ADMIN_PASSWORD]; sections[12] = NULL; usbfail = 1; if (!stat("/proc/bus/usb/devices", &statbuf)) usbfail = 0; if (usbfail) fprintf(flog, "USB HCI not detected.\n"); else fprintf(flog, "USB HCI detected.\n"); choice = 0; for (;;) { rc = newtWinMenu(ctr[TR_SECTION_MENU], ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8, sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL); if (rc == 2) break; switch (choice) { case 0: handlerestore(); break; case 1: handlekeymap(); break; case 2: handlehostname(); break; case 3: handlewebproxy(); break; case 4: handledefaults(); break; case 5: handleisdn(); break; case 6: handleadsl(); break; case 7: handlenetworking(); break; case 8: handledhcp(); break; case 9: handlerootpassword(); break; case 10: handlesetuppassword(); break; case 11: handleadminpassword(); break; default: break; } } } else { usbfail = 1; if (!stat("/proc/bus/usb/devices", &statbuf)) usbfail = 0; if (newtWinChoice(TITLE, ctr[TR_NO], ctr[TR_YES], ctr[TR_RESTORE_LONG]) != 1) { if (!(handlerestore())) goto EXIT; } if (!(handlekeymap())) goto EXIT; if (!(handlehostname())) goto EXIT; if (!(handledefaults())) goto EXIT; if (!(handlenetworking())) goto EXIT; if (!performedrestore) { choice = 0; for (;;) { sections[0] = ctr[TR_WEB_PROXY]; sections[1] = ctr[TR_ISDN_CONFIGURATION]; sections[2] = ctr[TR_ADSL_CONFIGURATION]; sections[3] = ctr[TR_DHCP_SERVER_CONFIGURATION], sections[4] = NULL; rc = newtWinMenu(ctr[TR_SECTION_MENU], ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8, sections, &choice, ctr[TR_OK], ctr[TR_FINISHED], NULL); if (rc == 2) break; switch (choice) { case 0: handlewebproxy(); break; case 1: handleisdn(); break; case 2: handleadsl(); break; case 3: handledhcp(); break; default: break; } } } if (!(handleadminpassword())) goto EXIT; if (!(handlerootpassword())) goto EXIT; autook = 1; } EXIT: if (automode != 0) { if (autook) newtWinMessage(TITLE, ctr[TR_OK], ctr[TR_SETUP_FINISHED]); else newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]); } else { if (rebootrequired) { if (newtWinChoice(TITLE, ctr[TR_YES], ctr[TR_NO], ctr[TR_DO_YOU_WANT_TO_REBOOT]) != 2) { doreboot = 1; } } } fprintf(flog, "Setup program ended.\n"); fflush(flog); fclose(flog); newtFinished(); if (doreboot) system("/sbin/shutdown -r now"); return 0; }
int handledhcp(void) { char *results[MAX_BOXES]; char enabledresult; char startenabled; struct newtExitStruct es; newtComponent header; newtComponent labels[MAX_BOXES]; newtComponent ok, cancel; char message[1000]; char *labeltexts[MAX_BOXES] = { _("Start address:"), _("End address:"), _("Primary DNS:"), _("Secondary DNS:"), _("Default lease (mins):"), _("Max lease (mins):"), _("Domain name suffix:") }; char *varnames[MAX_BOXES] = { "START_ADDR_GREEN", "END_ADDR_GREEN", "DNS1_GREEN", "DNS2_GREEN", "DEFAULT_LEASE_TIME_GREEN", "MAX_LEASE_TIME_GREEN", "DOMAIN_NAME_GREEN" }; char defaults[MAX_BOXES][STRING_SIZE]; int result; int c; char temp[STRING_SIZE]; struct keyvalue *mainkv = initkeyvalues(); struct keyvalue *dhcpkv = initkeyvalues(); struct keyvalue *ethernetkv = initkeyvalues(); int error; FILE *file; char greenaddress[STRING_SIZE]; char greennetaddress[STRING_SIZE]; char greennetmask[STRING_SIZE]; memset(defaults, 0, sizeof(char) * STRING_SIZE * MAX_BOXES); if (!(readkeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings"))) { freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); errorbox(_("Unable to open settings file")); return 0; } if (!(readkeyvalues(ethernetkv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); errorbox(_("Unable to open settings file")); return 0; } if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) { freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); freekeyvalues(mainkv); errorbox(_("Unable to open settings file")); return 0; } /* Set default values. */ findkey(ethernetkv, "GREEN_ADDRESS", defaults[PRIMARY_DNS]); findkey(mainkv, "DOMAINNAME", defaults[DOMAIN_NAME_SUFFIX]); strcpy(defaults[DEFAULT_LEASE_TIME], "60"); strcpy(defaults[MAX_LEASE_TIME], "120"); newtCenteredWindow(55, 18, _("DHCP server configuration")); dhcpform = newtForm(NULL, NULL, 0); header = newtTextboxReflowed(1, 1, _("Configure the DHCP server by entering the settings information."), 52, 0, 0, 0); newtFormAddComponent(dhcpform, header); strcpy(temp, ""); findkey(dhcpkv, "ENABLE_GREEN", temp); if (strcmp(temp, "on") == 0) startenabled = '*'; else startenabled = ' '; enabledcheckbox = newtCheckbox(2, TOP + 0, _("Enabled"), startenabled, " *", &enabledresult); newtFormAddComponent(dhcpform, enabledcheckbox); newtComponentAddCallback(enabledcheckbox, dhcpdialogcallbackdhcp, NULL); for (c = 0; c < MAX_BOXES; c++) { labels[c] = newtTextbox(2, TOP + 2 + c, 33, 1, 0); newtTextboxSetText(labels[c], labeltexts[c]); newtFormAddComponent(dhcpform, labels[c]); strcpy(temp, defaults[c]); findkey(dhcpkv, varnames[c], temp); entries[c] = newtEntry(34, TOP + 2 + c, temp, 18, &results[c], 0); newtFormAddComponent(dhcpform, entries[c]); if (startenabled == ' ') newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); } ok = newtButton(10, c + 7, _("OK")); cancel = newtButton(34, c + 7, _("Cancel")); newtFormAddComponents(dhcpform, ok, cancel, NULL); do { error = 0; newtFormRun(dhcpform, &es); if (es.u.co == ok) { /* OK was pressed; verify the contents of each entry. */ if (enabledresult == '*') { strcpy(message, _("The following fields are invalid:\n\n")); if (inet_addr(results[START_ADDRESS]) == INADDR_NONE) { strcat(message, _("Start address")); strcat(message, "\n"); error = 1; } if (inet_addr(results[END_ADDRESS]) == INADDR_NONE) { strcat(message, _("End address")); strcat(message, "\n"); error = 1; } if (strlen(results[SECONDARY_DNS])) { if (inet_addr(results[PRIMARY_DNS]) == INADDR_NONE) { strcat(message, _("Primary DNS")); strcat(message, "\n"); error = 1; } } if (strlen(results[SECONDARY_DNS])) { if (inet_addr(results[SECONDARY_DNS]) == INADDR_NONE) { strcat(message, _("Secondary DNS")); strcat(message, "\n"); error = 1; } } if (!(atol(results[DEFAULT_LEASE_TIME]))) { strcat(message, _("Default lease time")); strcat(message, "\n"); error = 1; } if (!(atol(results[MAX_LEASE_TIME]))) { strcat(message, _("Max. lease time")); strcat(message, "\n"); error = 1; } } if (error) errorbox(message); else { for (c = 0; c < MAX_BOXES; c++) replacekeyvalue(dhcpkv, varnames[c], results[c]); if (enabledresult == '*') { replacekeyvalue(dhcpkv, "ENABLE_GREEN", "on"); fclose(fopen(CONFIG_ROOT "/dhcp/enable_green", "w")); chown(CONFIG_ROOT "/dhcp/enable_green", 99, 99); mysystem(NULL, "/usr/local/bin/dhcpctrl enable"); } else { replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off"); unlink(CONFIG_ROOT "/dhcp/enable_green"); mysystem(NULL, "/usr/local/bin/dhcpctrl disable"); } replacekeyvalue(dhcpkv, "VALID", "yes"); writekeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings"); findkey(ethernetkv, "GREEN_ADDRESS", greenaddress); findkey(ethernetkv, "GREEN_NETADDRESS", greennetaddress); findkey(ethernetkv, "GREEN_NETMASK", greennetmask); file = fopen(CONFIG_ROOT "/dhcp/dhcpd.conf", "w"); fprintf(file, "ddns-update-style none;\n"); fprintf(file, "authoritative;\n"); fprintf(file, "subnet %s netmask %s\n", greennetaddress, greennetmask); fprintf(file, "{\n"); fprintf(file, "\toption subnet-mask %s;\n", greennetmask); fprintf(file, "\toption domain-name \"%s\";\n", results[DOMAIN_NAME_SUFFIX]); fprintf(file, "\toption routers %s;\n", greenaddress); if (strlen(results[PRIMARY_DNS])) { fprintf(file, "\toption domain-name-servers "); fprintf(file, "%s", results[PRIMARY_DNS]); if (strlen(results[SECONDARY_DNS])) fprintf(file, ", %s", results[SECONDARY_DNS]); fprintf(file, ";\n"); } fprintf(file, "\trange %s %s;\n", results[START_ADDRESS], results[END_ADDRESS]); fprintf(file, "\tdefault-lease-time %d;\n", (int) atol(results[DEFAULT_LEASE_TIME]) * 60); fprintf(file, "\tmax-lease-time %d;\n", (int) atol(results[MAX_LEASE_TIME]) * 60); fprintf(file, "}\n"); fclose(file); chown(CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); if (automode == 0) mysystem(NULL, "/usr/local/bin/dhcpctrl enable"); } result = 1; } else result = 0; } while (error); newtFormDestroy(dhcpform); newtPopWindow(); freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); freekeyvalues(mainkv); return result; }
/* DNS and default gateway.... */ int dnsgatewaymenu(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE] = "0"; struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ int error; int configtype; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } entries[DNS1].text = _("Primary DNS:"); strcpy(temp, ""); findkey(kv, "DNS1", temp); values[DNS1] = strdup(temp); entries[DNS1].value = &values[DNS1]; entries[DNS1].flags = 0; entries[DNS2].text = _("Secondary DNS:"); strcpy(temp, ""); findkey(kv, "DNS2", temp); values[DNS2] = strdup(temp); entries[DNS2].value = &values[DNS2]; entries[DNS2].flags = 0; entries[DEFAULT_GATEWAY].text = _("Default gateway:"); strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); values[DEFAULT_GATEWAY] = strdup(temp); entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; entries[DEFAULT_GATEWAY].flags = 0; entries[DNSGATEWAY_TOTAL].text = NULL; entries[DNSGATEWAY_TOTAL].value = NULL; entries[DNSGATEWAY_TOTAL].flags = 0; do { error = 0; rc = newtWinEntries(_("DNS and Gateway settings"), _("Enter the DNS and gateway information. " "These settings are used only with Static IP (and DHCP if DNS set) on the RED interface."), 50, 5, 5, 18, entries, _("OK"), _("Cancel"), NULL); if (rc == 0 || rc == 1) { strcpy(message, _("The following fields are invalid:")); strcpy(message, "\n\n"); if (strlen(values[DNS1])) { if (inet_addr(values[DNS1]) == INADDR_NONE) { strcat(message, _("Primary DNS")); strcat(message, "\n"); error = 1; } } if (strlen(values[DNS2])) { if (inet_addr(values[DNS2]) == INADDR_NONE) { strcat(message, _("Secondary DNS")); strcat(message, "\n"); error = 1; } } if (strlen(values[DEFAULT_GATEWAY])) { if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) { strcat(message, _("Default gateway")); strcat(message, "\n"); error = 1; } } if (!strlen(values[DNS1]) && strlen(values[DNS2])) { strcpy(message, _("Secondary DNS specified without a Primary DNS")); strcat(message, "\n"); error = 1; } if (error) errorbox(message); else { replacekeyvalue(kv, "DNS1", values[DNS1]); replacekeyvalue(kv, "DNS2", values[DNS2]); replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); netaddresschange = 1; free(values[DNS1]); free(values[DNS2]); free(values[DEFAULT_GATEWAY]); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); } } } while (error); freekeyvalues(kv); return 1; }
int main(int argc, char *argv[]) { int choice; char *sections[14]; /* need to fill this out AFTER knowing lang */ int rc; struct keyvalue *kv; char selectedshortlang[STRING_SIZE] = "en"; int autook = 0; int doreboot = 0; struct stat statbuf; memset(&statbuf, 0, sizeof(struct stat)); /* Log file/terminal stuff. */ if (argc >= 2) logname = argv[1]; else logname = strdup("/root/setup.log"); if (!(flog = fopen(logname, "w+"))) { printf("Couldn't open log terminal\n"); return 1; } /* Engage auto operation (run through 'normal' selections automatically) */ if (argc >= 3) { if (strlen(argv[2]) == 12 && strncmp(argv[2], "firstInstall", 12) == 0) { /* This execution only follows the installer; outgoing rules are cleared */ automode = 1; } else if (strlen(argv[2]) == 15 && strncmp(argv[2], "networkingOnly", 15) == 0) { /* This execution only runs during bootup when the NICs have changed */ automode = 2; } else { /* All other values mean generic auto mode during normal operation */ automode = 3; } } fprintf(flog, "Setup program started.\n"); kv = initkeyvalues(); if (!(readkeyvalues(kv, CONFIG_ROOT "main/settings"))) { printf("Smoothwall is not properly installed.\n"); return 1; } findkey(kv, "LANGUAGE", selectedshortlang); ctr = english_tr; newtInit(); newtCls(); newtDrawRootText(0, 0, TITLE " -- http://smoothwall.org/"); newtPushHelpLine(ctr[TR_HELPLINE]); if (automode == 0) { /* Admin selects each menu item individually */ sections[0] = ctr[TR_RESTORE_CONFIGURATION]; sections[1] = ctr[TR_KEYBOARD_MAPPING]; sections[2] = ctr[TR_TIMEZONE]; sections[3] = ctr[TR_HOSTNAME]; sections[4] = ctr[TR_WEB_PROXY]; sections[5] = ctr[TR_DEFAULT_SECURITY_LEVEL]; sections[6] = ctr[TR_ISDN_CONFIGURATION]; sections[7] = ctr[TR_ADSL_CONFIGURATION]; sections[8] = ctr[TR_NETWORKING]; sections[9] = ctr[TR_DHCP_SERVER_CONFIGURATION], sections[10] = ctr[TR_ROOT_PASSWORD]; sections[11] = ctr[TR_SETUP_PASSWORD]; sections[12] = ctr[TR_ADMIN_PASSWORD]; sections[13] = NULL; usbfail = 1; if (!stat("/proc/bus/usb/devices", &statbuf)) usbfail = 0; if (usbfail) fprintf(flog, "USB HCI not detected.\n"); else fprintf(flog, "USB HCI detected.\n"); choice = 0; for (;;) { rc = newtWinMenu(ctr[TR_SECTION_MENU], ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8, sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL); if (rc == 2) break; switch (choice) { case 0: handlerestore(); break; case 1: handlekeymap(); break; case 2: handletimezone(); break; case 3: handlehostname(); break; case 4: handlewebproxy(); break; case 5: handledefaults(); break; case 6: handleisdn(); break; case 7: handleadsl(); break; case 8: handlenetworking(); break; case 9: handledhcp(); break; case 10: handlerootpassword(); break; case 11: handlesetuppassword(); break; case 12: handleadminpassword(); break; default: break; } } } else if (automode == 2) { /* Admin specified networkingOnly as the third arg */ /* This happens when the NIC change and rc.sysint runs setup */ handlenetworking(); autook = 2; } else { /* automode is 1 (firstInstall) or 3 (generic) */ usbfail = 1; if (newtWinChoice(ctr[TR_RESTORE_CONFIGURATION], ctr[TR_NO], ctr[TR_YES], ctr[TR_RESTORE_LONG]) != 1) { if (!(handlerestore())) goto EXIT; } if (!(handlekeymap())) goto EXIT; if (!(handletimezone())) goto EXIT; if (!(handlehostname())) goto EXIT; if (!(handledefaults())) goto EXIT; if (!(handlenetworking())) goto EXIT; if (!performedrestore) { choice = 0; for (;;) { sections[0] = ctr[TR_WEB_PROXY]; sections[1] = ctr[TR_ISDN_CONFIGURATION]; sections[2] = ctr[TR_ADSL_CONFIGURATION]; sections[3] = ctr[TR_DHCP_SERVER_CONFIGURATION], sections[4] = NULL; rc = newtWinMenu(ctr[TR_SECTION_MENU], ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8, sections, &choice, ctr[TR_OK], ctr[TR_FINISHED], NULL); if (rc == 2) break; switch (choice) { case 0: handlewebproxy(); break; case 1: handleisdn(); break; case 2: handleadsl(); break; case 3: handledhcp(); break; default: break; } } } if (!(handleadminpassword())) goto EXIT; if (!(handlerootpassword())) goto EXIT; autook = 1; } EXIT: if (automode == 1 || automode == 3) { if (autook) newtWinMessage("", ctr[TR_OK], ctr[TR_SETUP_FINISHED]); else newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]); } else if (automode == 2) { if (autook == 2) { fprintf(flog, "Setup program ended.\n"); fflush(flog); fclose(flog); newtFinished(); return 0; } else { return -1; } } else { if (rebootrequired) { if (newtWinChoice("", ctr[TR_YES], ctr[TR_NO], ctr[TR_DO_YOU_WANT_TO_REBOOT]) != 2) { doreboot = 1; } } } fprintf(flog, "Setup program ended.\n"); fflush(flog); fclose(flog); newtFinished(); if (doreboot) system("/sbin/shutdown -r now"); return 0; }
/* They can change ORANGE and GREEN too :) */ int addressesmenu(void) { struct keyvalue *kv = initkeyvalues(); struct keyvalue *mainkv = initkeyvalues(); int rc = 0; char *sections[6]; char *green = "GREEN"; char *orange = "ORANGE"; char *purple = "PURPLE"; char *red = "RED"; int c = 0; char temp[STRING_SIZE]; int configtype; int done; int choice; char hostname[STRING_SIZE]; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } if (!(readkeyvalues(mainkv, CONFIG_ROOT "main/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); sections[c] = green; c++; if (CONFIG_TYPE_ORANGE(configtype)) { sections[c] = orange; c++; } if (CONFIG_TYPE_PURPLE(configtype)) { sections[c] = purple; c++; } if (CONFIG_TYPE_RED(configtype)) { sections[c] = red; c++; } sections[c] = NULL; choice = 0; done = 0; while (!done) { rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); if (rc == 0 || rc == 1) { if (strcmp(sections[choice], "GREEN") == 0) { rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_WARNING_LONG]); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); writehostsfiles(); } } } if (strcmp(sections[choice], "ORANGE") == 0) { if (changeaddress(kv, "ORANGE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "PURPLE") == 0) { if (changeaddress(kv, "PURPLE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "RED") == 0) { strcpy(hostname, ""); findkey(mainkv, "HOSTNAME", hostname); if (changeaddress(kv, "RED", 1, hostname)) netaddresschange = 1; } } else done = 1; } writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); freekeyvalues(kv); freekeyvalues(mainkv); return 0; }
int main(void) { char green_dev[STRING_SIZE] = ""; char buffer[STRING_SIZE]; char *index, *ipaddress, *macaddress, *enabled; struct keyvalue *kv = NULL; if (!(initsetuid())) exit(1); /* flush wireless iptables */ safe_system("/sbin/iptables --wait -F WIRELESSINPUT > /dev/null 2> /dev/null"); safe_system("/sbin/iptables --wait -F WIRELESSFORWARD > /dev/null 2> /dev/null"); memset(buffer, 0, STRING_SIZE); /* Init the keyvalue structure */ kv=initkeyvalues(); /* Read in the current values */ if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")) { fprintf(stderr, "Cannot read ethernet settings\n"); exit(1); } /* Read in the firewall values */ if (!readkeyvalues(kv, CONFIG_ROOT "/optionsfw/settings")) { fprintf(stderr, "Cannot read optionsfw settings\n"); exit(1); } /* Get the GREEN interface details */ if (findkey(kv, "GREEN_DEV", green_dev) > 0) { if (!VALID_DEVICE(green_dev)) { fprintf(stderr, "Bad GREEN_DEV: %s\n", green_dev); exit(1); } } /* Get the BLUE interface details */ if (findkey(kv, "BLUE_DEV", blue_dev) > 0) { if ((strlen(blue_dev) > 0) && !VALID_DEVICE(blue_dev)) { fprintf(stderr, "Bad BLUE_DEV: %s\n", blue_dev); exit(1); } } if (strlen(blue_dev) == 0) { exit(0); } if ((fd = fopen(CONFIG_ROOT "/wireless/nodrop", "r"))) return 0; /* register exit handler to ensure the block rule is always present */ atexit(exithandler); if (!(fd = fopen(CONFIG_ROOT "/wireless/config", "r"))) { exit(0); } /* restrict blue access tp the proxy port */ if (findkey(kv, "DROPPROXY", buffer) && strcmp(buffer, "on") == 0) { /* Read the proxy values */ if (!readkeyvalues(kv, CONFIG_ROOT "/proxy/settings") || !(findkey(kv, "PROXY_PORT", buffer))) { fprintf(stderr, "Cannot read proxy settings\n"); exit(1); } snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSFORWARD -i %s -p tcp ! --dport %s -j DROP -m comment --comment 'DROP_Wirelessforward'", blue_dev, buffer); safe_system(command); snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSINPUT -i %s -p tcp ! --dport %s -j DROP -m comment --comment 'DROP_Wirelessinput'", blue_dev, buffer); safe_system(command); } /* not allow blue to acces a samba server running on local fire*/ if (findkey(kv, "DROPSAMBA", buffer) && strcmp(buffer, "on") == 0) { snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSFORWARD -i %s -p tcp -m multiport --ports 135,137,138,139,445,1025 -j DROP -m comment --comment 'DROP_Wirelessforward'", blue_dev); safe_system(command); snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSINPUT -i %s -p tcp -m multiport --ports 135,137,138,139,445,1025 -j DROP -m comment --comment 'DROP_Wirelessinput'", blue_dev); safe_system(command); snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSFORWARD -i %s -p udp -m multiport --ports 135,137,138,139,445,1025 -j DROP -m comment --comment 'DROP_Wirelessforward'", blue_dev); safe_system(command); snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSINPUT -i %s -p udp -m multiport --ports 135,137,138,139,445,1025 -j DROP -m comment --comment 'DROP_Wirelessinput'", blue_dev); safe_system(command); } while (fgets(buffer, STRING_SIZE, fd)) { buffer[strlen(buffer) - 1] = 0; index = strtok(buffer, ","); ipaddress = strtok(NULL, ","); macaddress = strtok(NULL, ","); enabled = strtok(NULL, ","); if (strcmp(enabled, "on") == 0) { /* both specified, added security */ if ((strlen(macaddress) == 17) && (VALID_IP_AND_MASK(ipaddress))) { snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSINPUT -m mac --mac-source %s -s %s -i %s -j ACCEPT", macaddress, ipaddress, blue_dev); safe_system(command); snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSFORWARD -m mac --mac-source %s -s %s -i %s -j RETURN", macaddress, ipaddress, blue_dev); safe_system(command); } else { /* correctly formed mac address is 17 chars */ if (strlen(macaddress) == 17) { snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSINPUT -m mac --mac-source %s -i %s -j ACCEPT", macaddress, blue_dev); safe_system(command); snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSFORWARD -m mac --mac-source %s -i %s -j RETURN", macaddress, blue_dev); safe_system(command); } if (VALID_IP_AND_MASK(ipaddress)) { snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSINPUT -s %s -i %s -j ACCEPT", ipaddress, blue_dev); safe_system(command); snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSFORWARD -s %s -i %s -j RETURN", ipaddress, blue_dev); safe_system(command); } } } } /* with this rule you can disable the logging of the dropped wireless input packets*/ if (findkey(kv, "DROPWIRELESSINPUT", buffer) && strcmp(buffer, "on") == 0) { snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSINPUT -i %s -j LOG --log-prefix 'DROP_Wirelessinput'", blue_dev); safe_system(command); } /* with this rule you can disable the logging of the dropped wireless forward packets*/ if (findkey(kv, "DROPWIRELESSFORWARD", buffer) && strcmp(buffer, "on") == 0) { snprintf(command, STRING_SIZE-1, "/sbin/iptables --wait -A WIRELESSFORWARD -i %s -j LOG --log-prefix 'DROP_Wirelessforward'", blue_dev); safe_system(command); } return 0; }
/* DNS and default gateway.... */ int dnsgatewaymenu(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE] = "0"; struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ int error; int configtype; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (!CONFIG_TYPE_RED(configtype)) { freekeyvalues(kv); errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); return 0; } entries[DNS1].text = ctr[TR_PRIMARY_DNS]; strcpy(temp, ""); findkey(kv, "DNS1", temp); values[DNS1] = strdup(temp); entries[DNS1].value = (const char **) &values[DNS1]; entries[DNS1].flags = 0; entries[DNS2].text = ctr[TR_SECONDARY_DNS]; strcpy(temp, ""); findkey(kv, "DNS2", temp); values[DNS2] = strdup(temp); entries[DNS2].value = (const char **) &values[DNS2]; entries[DNS2].flags = 0; entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); values[DEFAULT_GATEWAY] = strdup(temp); entries[DEFAULT_GATEWAY].value = (const char **) &values[DEFAULT_GATEWAY]; entries[DEFAULT_GATEWAY].flags = 0; entries[DNSGATEWAY_TOTAL].text = NULL; entries[DNSGATEWAY_TOTAL].value = NULL; entries[DNSGATEWAY_TOTAL].flags = 0; do { error = 0; rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { strcpy(message, ctr[TR_INVALID_FIELDS]); if (strlen(values[DNS1])) { if (inet_addr(values[DNS1]) == INADDR_NONE) { strcat(message, ctr[TR_PRIMARY_DNS_CR]); error = 1; } } if (strlen(values[DNS2])) { if (inet_addr(values[DNS2]) == INADDR_NONE) { strcat(message, ctr[TR_SECONDARY_DNS_CR]); error = 1; } } if (strlen(values[DEFAULT_GATEWAY])) { if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) { strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); error = 1; } } if (!strlen(values[DNS1]) && strlen(values[DNS2])) { strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); error = 1; } if (error) errorbox(message); else { replacekeyvalue(kv, "DNS1", values[DNS1]); replacekeyvalue(kv, "DNS2", values[DNS2]); replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); netaddresschange = 1; free((char *) values[DNS1]); free((char *) values[DNS2]); free((char *) values[DEFAULT_GATEWAY]); writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); } } } while (error); freekeyvalues(kv); return 1; }