summaryrefslogtreecommitdiff
path: root/src/hostname-setup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-04-16 01:57:23 +0200
committerLennart Poettering <lennart@poettering.net>2011-04-16 02:03:35 +0200
commit9beb3f4d5c527f995e0e44308d7372fa4ea5470f (patch)
tree09c81142ac28e90e330caf0987dce341b93a5966 /src/hostname-setup.c
parentf653f683d8994ca4b33f48d6adf2c6ee3c58e13e (diff)
hostname: split out hostname validation into util.c
Diffstat (limited to 'src/hostname-setup.c')
-rw-r--r--src/hostname-setup.c37
1 files changed, 7 insertions, 30 deletions
diff --git a/src/hostname-setup.c b/src/hostname-setup.c
index e9869bb4df..ab49767045 100644
--- a/src/hostname-setup.c
+++ b/src/hostname-setup.c
@@ -40,25 +40,8 @@
#define FILENAME "/etc/conf.d/hostname"
#endif
-static char* strip_bad_chars(char *s) {
- char *p, *d;
-
- for (p = s, d = s; *p; p++)
- if ((*p >= 'a' && *p <= 'z') ||
- (*p >= 'A' && *p <= 'Z') ||
- (*p >= '0' && *p <= '9') ||
- *p == '-' ||
- *p == '_' ||
- *p == '.')
- *(d++) = *p;
-
- *d = 0;
-
- return s;
-}
-
static int read_and_strip_hostname(const char *path, char **hn) {
- char *s, *k;
+ char *s;
int r;
assert(path);
@@ -67,20 +50,14 @@ static int read_and_strip_hostname(const char *path, char **hn) {
if ((r = read_one_line_file(path, &s)) < 0)
return r;
- k = strdup(strstrip(s));
- free(s);
-
- if (!k)
- return -ENOMEM;
-
- strip_bad_chars(k);
+ hostname_cleanup(s);
- if (k[0] == 0) {
- free(k);
+ if (isempty(s)) {
+ free(s);
return -ENOENT;
}
- *hn = k;
+ *hn = s;
return 0;
}
@@ -118,9 +95,9 @@ static int read_distro_hostname(char **hn) {
goto finish;
}
- strip_bad_chars(k);
+ hostname_cleanup(k);
- if (k[0] == 0) {
+ if (isempty(k)) {
free(k);
r = -ENOENT;
goto finish;