]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/setup/hostname.c
OpenVPN: Added 'valid til (days)' field for N2N.
[people/pmueller/ipfire-2.x.git] / src / setup / hostname.c
1 /* SmoothWall setup program.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * (c) Lawrence Manning, 2001
7 * Stuff for setting the hostname.
8 *
9 * $Id: hostname.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $
10 *
11 */
12
13 // Translation
14 #include <libintl.h>
15 #define _(x) dgettext("setup", x)
16
17 #include "setup.h"
18
19 extern FILE *flog;
20 extern char *mylog;
21
22 extern int automode;
23
24 int handlehostname(void)
25 {
26 char hostname[STRING_SIZE] = "";
27 struct keyvalue *kv = initkeyvalues();
28 char *values[] = { hostname, NULL }; /* pointers for the values. */
29 struct newtWinEntry entries[] =
30 { { "", &values[0], 0,}, { NULL, NULL, 0 } };
31 int rc;
32 int result;
33
34 if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
35 {
36 freekeyvalues(kv);
37 errorbox(_("Unable to open settings file"));
38 return 0;
39 }
40
41 strcpy(hostname, SNAME);
42 findkey(kv, "HOSTNAME", hostname);
43
44 for (;;)
45 {
46 rc = newtWinEntries(_("Hostname"), _("Enter the machine's hostname."),
47 50, 5, 5, 40, entries, _("OK"), _("Cancel"), NULL);
48
49 if (rc == 1)
50 {
51 strcpy(hostname, values[0]);
52 if (!(strlen(hostname)))
53 errorbox(_("Hostname cannot be empty."));
54 else if (strchr(hostname, ' '))
55 errorbox(_("Hostname cannot contain spaces."));
56 else if (strlen(hostname) != strspn(hostname,
57 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"))
58 errorbox(_("Hostname may only contain letters, numbers and hyphens."));
59 else
60 {
61 replacekeyvalue(kv, "HOSTNAME", hostname);
62 writekeyvalues(kv, CONFIG_ROOT "/main/settings");
63 writehostsfiles();
64 result = 1;
65 break;
66 }
67 }
68 else
69 {
70 result = 0;
71 break;
72 }
73 }
74 free(values[0]);
75 freekeyvalues(kv);
76
77 return result;
78 }