mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-07 17:17:44 +03:00
hostname-util: drop GET_HOSTNAME_ALLOW_NONE flag and always refuse "(none)"
The flag is now only used in test-sysctl-util.c, and it should be
replaced with uname(), because of the same reason as the previous
commit.
(cherry picked from commit 9383fa08bd
)
This commit is contained in:
parent
7c78994860
commit
9f5372ce4c
@ -46,8 +46,7 @@ int gethostname_full(GetHostnameFlags flags, char **ret) {
|
|||||||
assert_se(uname(&u) >= 0);
|
assert_se(uname(&u) >= 0);
|
||||||
|
|
||||||
s = u.nodename;
|
s = u.nodename;
|
||||||
if (isempty(s) ||
|
if (isempty(s) || streq(s, "(none)") ||
|
||||||
(!FLAGS_SET(flags, GET_HOSTNAME_ALLOW_NONE) && streq(s, "(none)")) ||
|
|
||||||
(!FLAGS_SET(flags, GET_HOSTNAME_ALLOW_LOCALHOST) && is_localhost(s)) ||
|
(!FLAGS_SET(flags, GET_HOSTNAME_ALLOW_LOCALHOST) && is_localhost(s)) ||
|
||||||
(FLAGS_SET(flags, GET_HOSTNAME_SHORT) && s[0] == '.')) {
|
(FLAGS_SET(flags, GET_HOSTNAME_SHORT) && s[0] == '.')) {
|
||||||
if (!FLAGS_SET(flags, GET_HOSTNAME_FALLBACK_DEFAULT))
|
if (!FLAGS_SET(flags, GET_HOSTNAME_FALLBACK_DEFAULT))
|
||||||
|
@ -9,10 +9,9 @@
|
|||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
|
|
||||||
typedef enum GetHostnameFlags {
|
typedef enum GetHostnameFlags {
|
||||||
GET_HOSTNAME_ALLOW_NONE = 1 << 0, /* accepts "(none)". */
|
GET_HOSTNAME_ALLOW_LOCALHOST = 1 << 0, /* accepts "localhost" or friends. */
|
||||||
GET_HOSTNAME_ALLOW_LOCALHOST = 1 << 1, /* accepts "localhost" or friends. */
|
GET_HOSTNAME_FALLBACK_DEFAULT = 1 << 1, /* use default hostname if no hostname is set. */
|
||||||
GET_HOSTNAME_FALLBACK_DEFAULT = 1 << 2, /* use default hostname if no hostname is set. */
|
GET_HOSTNAME_SHORT = 1 << 2, /* kills the FQDN part if present. */
|
||||||
GET_HOSTNAME_SHORT = 1 << 3, /* kills the FQDN part if present. */
|
|
||||||
} GetHostnameFlags;
|
} GetHostnameFlags;
|
||||||
|
|
||||||
int gethostname_full(GetHostnameFlags flags, char **ret);
|
int gethostname_full(GetHostnameFlags flags, char **ret);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
#include "sd-id128.h"
|
#include "sd-id128.h"
|
||||||
|
|
||||||
#include "errno-util.h"
|
#include "errno-util.h"
|
||||||
@ -38,7 +40,8 @@ TEST(sysctl_normalize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(sysctl_read) {
|
TEST(sysctl_read) {
|
||||||
_cleanup_free_ char *s = NULL, *h = NULL;
|
_cleanup_free_ char *s = NULL;
|
||||||
|
struct utsname u;
|
||||||
sd_id128_t a, b;
|
sd_id128_t a, b;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -63,8 +66,8 @@ TEST(sysctl_read) {
|
|||||||
s = mfree(s);
|
s = mfree(s);
|
||||||
|
|
||||||
assert_se(sysctl_read("kernel/hostname", &s) >= 0);
|
assert_se(sysctl_read("kernel/hostname", &s) >= 0);
|
||||||
assert_se(gethostname_full(GET_HOSTNAME_ALLOW_NONE|GET_HOSTNAME_ALLOW_LOCALHOST, &h) >= 0);
|
assert_se(uname(&u) >= 0);
|
||||||
assert_se(streq(s, h));
|
assert_se(streq_ptr(s, u.nodename));
|
||||||
|
|
||||||
r = sysctl_write("kernel/hostname", s);
|
r = sysctl_write("kernel/hostname", s);
|
||||||
assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS);
|
assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS);
|
||||||
|
Loading…
Reference in New Issue
Block a user