X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fhostname-setup.c;h=2c2f10cfd15486b872cbea6185becbbcb0496b4a;hp=e9869bb4dff4d64f6d8d1500bd956815fc38cd26;hb=4b562198c79e4ebfc3d84b69a1dae374bc6cf9f5;hpb=9bec0b1e8d4a0cf971c113fe880deba2f9feae24 diff --git a/src/hostname-setup.c b/src/hostname-setup.c index e9869bb4d..2c2f10cfd 100644 --- a/src/hostname-setup.c +++ b/src/hostname-setup.c @@ -30,9 +30,9 @@ #include "util.h" #include "log.h" -#if defined(TARGET_FEDORA) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) +#if defined(TARGET_FEDORA) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) || defined(TARGET_MEEGO) || defined(TARGET_MAGEIA) #define FILENAME "/etc/sysconfig/network" -#elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE) || defined(TARGET_FRUGALWARE) +#elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE) #define FILENAME "/etc/HOSTNAME" #elif defined(TARGET_ARCH) #define FILENAME "/etc/rc.conf" @@ -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,27 +50,21 @@ 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; } static int read_distro_hostname(char **hn) { -#if defined(TARGET_FEDORA) || defined(TARGET_ARCH) || defined(TARGET_GENTOO) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) +#if defined(TARGET_FEDORA) || defined(TARGET_ARCH) || defined(TARGET_GENTOO) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) || defined(TARGET_MEEGO) || defined(TARGET_MAGEIA) int r; FILE *f; @@ -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; @@ -137,7 +114,7 @@ finish: fclose(f); return r; -#elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE) || defined(TARGET_FRUGALWARE) +#elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE) return read_and_strip_hostname(FILENAME, hn); #else return -ENOENT;