]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/setup/hostname.c
1 /* SmoothWall setup program.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Stuff for setting the hostname.
9 * $Id: hostname.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $
15 #define _(x) dgettext("setup", x)
24 int handlehostname(void)
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 } };
34 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/main/settings")))
37 errorbox(_("Unable to open settings file"));
41 strcpy(hostname
, SNAME
);
42 findkey(kv
, "HOSTNAME", hostname
);
46 rc
= newtWinEntries(_("Hostname"), _("Enter the machine's hostname."),
47 50, 5, 5, 40, entries
, _("OK"), _("Cancel"), NULL
);
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."));
61 replacekeyvalue(kv
, "HOSTNAME", hostname
);
62 writekeyvalues(kv
, CONFIG_ROOT
"/main/settings");