X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Fhostname-util.c;h=a5cb62eb661e03eaf16682241f82d830ee952e46;hb=7b4a8335022121d06336eae363f3d7fcbcac1c45;hp=f221c6ff1dc31fb3cf5c922413f42057fc6d6574;hpb=21ecddbbb2c9e06d080b2526a870898a8b90f52a;p=elogind.git
diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c
index f221c6ff1..a5cb62eb6 100644
--- a/src/basic/hostname-util.c
+++ b/src/basic/hostname-util.c
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
/***
This file is part of systemd.
@@ -19,14 +17,20 @@
along with systemd; If not, see .
***/
+#include
+#include
+#include
+#include
#include
-#include
+#include
-#include "util.h"
+//#include "fd-util.h"
+#include "fileio.h"
#include "hostname-util.h"
+//#include "macro.h"
+#include "string-util.h"
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
bool hostname_is_set(void) {
struct utsname u;
@@ -41,10 +45,15 @@ bool hostname_is_set(void) {
return true;
}
+#endif // 0
char* gethostname_malloc(void) {
struct utsname u;
+ /* This call tries to return something useful, either the actual hostname
+ * or it makes something up. The only reason it might fail is OOM.
+ * It might even return "localhost" if that's set. */
+
assert_se(uname(&u) >= 0);
if (isempty(u.nodename) || streq(u.nodename, "(none)"))
@@ -52,6 +61,32 @@ char* gethostname_malloc(void) {
return strdup(u.nodename);
}
+
+#if 0 /// UNNEEDED by elogind
+int gethostname_strict(char **ret) {
+ struct utsname u;
+ char *k;
+
+ /* This call will rather fail than make up a name. It will not return "localhost" either. */
+
+ assert_se(uname(&u) >= 0);
+
+ if (isempty(u.nodename))
+ return -ENXIO;
+
+ if (streq(u.nodename, "(none)"))
+ return -ENXIO;
+
+ if (is_localhost(u.nodename))
+ return -ENXIO;
+
+ k = strdup(u.nodename);
+ if (!k)
+ return -ENOMEM;
+
+ *ret = k;
+ return 0;
+}
#endif // 0
static bool hostname_valid_char(char c) {
@@ -72,7 +107,7 @@ static bool hostname_valid_char(char c) {
* allow_trailing_dot is true and at least two components are present
* in the name. Note that due to the restricted charset and length
* this call is substantially more conservative than
- * dns_domain_is_valid().
+ * dns_name_is_valid().
*/
bool hostname_is_valid(const char *s, bool allow_trailing_dot) {
unsigned n_dots = 0;
@@ -93,7 +128,7 @@ bool hostname_is_valid(const char *s, bool allow_trailing_dot) {
return false;
dot = true;
- n_dots ++;
+ n_dots++;
} else {
if (!hostname_valid_char(*p))
return false;
@@ -113,12 +148,15 @@ bool hostname_is_valid(const char *s, bool allow_trailing_dot) {
return true;
}
+#if 0 /// UNNEEDED by elogind
char* hostname_cleanup(char *s) {
char *p, *d;
bool dot;
assert(s);
+ strshorten(s, HOST_NAME_MAX);
+
for (p = s, d = s, dot = true; *p; p++) {
if (*p == '.') {
if (dot)
@@ -138,27 +176,27 @@ char* hostname_cleanup(char *s) {
else
*d = 0;
- strshorten(s, HOST_NAME_MAX);
-
return s;
}
+#endif // 0
bool is_localhost(const char *hostname) {
assert(hostname);
/* This tries to identify local host and domain names
- * described in RFC6761 plus the redhatism of .localdomain */
+ * described in RFC6761 plus the redhatism of localdomain */
return strcaseeq(hostname, "localhost") ||
strcaseeq(hostname, "localhost.") ||
- strcaseeq(hostname, "localdomain.") ||
- strcaseeq(hostname, "localdomain") ||
+ strcaseeq(hostname, "localhost.localdomain") ||
+ strcaseeq(hostname, "localhost.localdomain.") ||
endswith_no_case(hostname, ".localhost") ||
endswith_no_case(hostname, ".localhost.") ||
- endswith_no_case(hostname, ".localdomain") ||
- endswith_no_case(hostname, ".localdomain.");
+ endswith_no_case(hostname, ".localhost.localdomain") ||
+ endswith_no_case(hostname, ".localhost.localdomain.");
}
+#if 0 /// UNNEEDED by elogind
bool is_gateway_hostname(const char *hostname) {
assert(hostname);
@@ -170,8 +208,6 @@ bool is_gateway_hostname(const char *hostname) {
strcaseeq(hostname, "gateway.");
}
-/// UNNEEDED by elogind
-#if 0
int sethostname_idempotent(const char *s) {
char buf[HOST_NAME_MAX + 1] = {};