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 $
22 int handlehostname(void)
24 char hostname
[STRING_SIZE
] = "";
25 struct keyvalue
*kv
= initkeyvalues();
26 char *values
[] = { hostname
, NULL
}; /* pointers for the values. */
27 struct newtWinEntry entries
[] =
28 { { "", &values
[0], 0,}, { NULL
, NULL
, 0 } };
32 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/main/settings")))
35 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
39 strcpy(hostname
, SNAME
);
40 findkey(kv
, "HOSTNAME", hostname
);
44 rc
= newtWinEntries(ctr
[TR_HOSTNAME
], ctr
[TR_ENTER_HOSTNAME
],
45 50, 5, 5, 40, entries
, ctr
[TR_OK
], ctr
[TR_CANCEL
], NULL
);
49 strcpy(hostname
, values
[0]);
50 if (!(strlen(hostname
)))
51 errorbox(ctr
[TR_HOSTNAME_CANNOT_BE_EMPTY
]);
52 else if (strchr(hostname
, ' '))
53 errorbox(ctr
[TR_HOSTNAME_CANNOT_CONTAIN_SPACES
]);
54 else if (strlen(hostname
) != strspn(hostname
,
55 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"))
56 errorbox(ctr
[TR_HOSTNAME_NOT_VALID_CHARS
]);
59 replacekeyvalue(kv
, "HOSTNAME", hostname
);
60 writekeyvalues(kv
, CONFIG_ROOT
"/main/settings");