X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fhostname-setup.c;h=ab497670453e82542110c3d0fc588b3b171297b7;hb=9beb3f4d5c527f995e0e44308d7372fa4ea5470f;hp=e9869bb4dff4d64f6d8d1500bd956815fc38cd26;hpb=f653f683d8994ca4b33f48d6adf2c6ee3c58e13e;p=elogind.git diff --git a/src/hostname-setup.c b/src/hostname-setup.c index e9869bb4d..ab4976704 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;