-/* SmoothWall setup program.\r
- *\r
- * This program is distributed under the terms of the GNU General Public\r
- * Licence. See the file COPYING for details.\r
- *\r
- * (c) Lawrence Manning, 2001\r
- * Stuff for setting the hostname.\r
- * \r
- * $Id: hostname.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $\r
- * \r
- */\r
- \r
-#include "setup.h"\r
- \r
-extern FILE *flog;\r
-extern char *mylog;\r
-\r
-extern char **ctr;\r
-\r
-extern int automode;\r
-\r
-int handlehostname(void)\r
-{\r
- char hostname[STRING_SIZE] = "";\r
- struct keyvalue *kv = initkeyvalues();\r
- char *values[] = { hostname, NULL }; /* pointers for the values. */\r
- struct newtWinEntry entries[] =\r
- { { "", &values[0], 0,}, { NULL, NULL, 0 } };\r
- int rc;\r
- int result;\r
- \r
- if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))\r
- {\r
- freekeyvalues(kv);\r
- errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);\r
- return 0;\r
- } \r
- \r
- strcpy(hostname, SNAME);\r
- findkey(kv, "HOSTNAME", hostname);\r
- \r
- for (;;)\r
- {\r
- rc = newtWinEntries(ctr[TR_HOSTNAME], ctr[TR_ENTER_HOSTNAME],\r
- 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);\r
- \r
- if (rc == 1)\r
- {\r
- strcpy(hostname, values[0]);\r
- if (!(strlen(hostname)))\r
- errorbox(ctr[TR_HOSTNAME_CANNOT_BE_EMPTY]);\r
- else if (strchr(hostname, ' '))\r
- errorbox(ctr[TR_HOSTNAME_CANNOT_CONTAIN_SPACES]);\r
- else if (strlen(hostname) != strspn(hostname,\r
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"))\r
- errorbox(ctr[TR_HOSTNAME_NOT_VALID_CHARS]);\r
- else\r
- {\r
- replacekeyvalue(kv, "HOSTNAME", hostname);\r
- writekeyvalues(kv, CONFIG_ROOT "/main/settings");\r
- writehostsfiles();\r
- result = 1;\r
- break;\r
- }\r
- }\r
- else\r
- {\r
- result = 0;\r
- break;\r
- }\r
- }\r
- free(values[0]);\r
- freekeyvalues(kv);\r
- \r
- return result;\r
-} \r
+/* SmoothWall setup program.
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence. See the file COPYING for details.
+ *
+ * (c) Lawrence Manning, 2001
+ * Stuff for setting the hostname.
+ *
+ * $Id: hostname.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $
+ *
+ */
+
+#include "setup.h"
+
+extern FILE *flog;
+extern char *mylog;
+
+extern char **ctr;
+
+extern int automode;
+
+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(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
+ return 0;
+ }
+
+ strcpy(hostname, SNAME);
+ findkey(kv, "HOSTNAME", hostname);
+
+ for (;;)
+ {
+ rc = newtWinEntries(ctr[TR_HOSTNAME], ctr[TR_ENTER_HOSTNAME],
+ 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
+
+ if (rc == 1)
+ {
+ strcpy(hostname, values[0]);
+ if (!(strlen(hostname)))
+ errorbox(ctr[TR_HOSTNAME_CANNOT_BE_EMPTY]);
+ else if (strchr(hostname, ' '))
+ errorbox(ctr[TR_HOSTNAME_CANNOT_CONTAIN_SPACES]);
+ else if (strlen(hostname) != strspn(hostname,
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"))
+ errorbox(ctr[TR_HOSTNAME_NOT_VALID_CHARS]);
+ 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;
+}