allow underscore in hostname

This commit is contained in:
h30032433 2024-02-18 11:25:14 +08:00
parent df1bd60fd4
commit de01380543
3 changed files with 77 additions and 53 deletions

View File

@ -25,7 +25,7 @@
Name: systemd
Url: https://www.freedesktop.org/wiki/Software/systemd
Version: 255
Release: 1
Release: 2
License: MIT and LGPLv2+ and GPLv2+
Summary: System and Service Manager
@ -93,7 +93,7 @@ Patch9042: systemd-core-Add-new-rules-for-lower-priority-events.patch
Patch9043: bugfix-also-stop-machine-when-a-machine-un.patch
Patch9044: print-the-process-status-to-console-when-shutdown.patch
Patch9045: Retry-to-handle-the-uevent-when-worker-is-terminated.patch
Patch9046: treat-hyphen-as-valid-hostname-char.patch
Patch9046: treat-underscore-as-valid-hostname-char.patch
Patch9047: process-util-log-more-information-when-runnin.patch
Patch9048: fuser-print-umount-message-to-reboot-umount-msg.patch
Patch9049: shutdown-reboot-when-recieve-crash-signal.patch
@ -1627,6 +1627,9 @@ fi
%{_libdir}/security/pam_systemd_loadkey.so
%changelog
* Sun Feb 18 2024 huyubiao <huyubiao@huawei.com> - 255-2
- allow underscore in hostname
* Mon Jan 22 2024 huyubiao <huyubiao@huawei.com> - 255-1
- update systemd to v255

View File

@ -1,51 +0,0 @@
From c04904a4f54f8949a6a7821a0859e2732366259b Mon Sep 17 00:00:00 2001
From: licunlong <licunlong1@huawei.com>
Date: Tue, 24 Nov 2020 19:57:38 +0800
Subject: [PATCH] treat hyphen as valid hostname char
---
src/basic/hostname-util.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c
index 5bfa028..b80a2b8 100644
--- a/src/basic/hostname-util.c
+++ b/src/basic/hostname-util.c
@@ -77,6 +77,16 @@ bool valid_ldh_char(char c) {
c == '-';
}
+static bool hostname_valid_char(char c) {
+ return
+ (c >= 'a' && c <= 'z') ||
+ (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') ||
+ c == '-' ||
+ c == '_' ||
+ c == '.';
+}
+
bool hostname_is_valid(const char *s, ValidHostnameFlags flags) {
unsigned n_dots = 0;
const char *p;
@@ -117,7 +127,7 @@ bool hostname_is_valid(const char *s, bool allow_trailing_dot) {
hyphen = true;
} else {
- if (!valid_ldh_char(*p))
+ if (!hostname_valid_char(*p))
return false;
dot = false;
@@ -160,7 +170,7 @@ char* hostname_cleanup(char *s) {
dot = false;
hyphen = true;
- } else if (valid_ldh_char(*p)) {
+ } else if (hostname_valid_char(*p)) {
*(d++) = *p;
dot = false;
hyphen = false;
--
2.23.0

View File

@ -0,0 +1,72 @@
From c04904a4f54f8949a6a7821a0859e2732366259b Mon Sep 17 00:00:00 2001
From: licunlong <licunlong1@huawei.com>
Date: Tue, 24 Nov 2020 19:57:38 +0800
Subject: [PATCH] treat underscore as valid hostname char
---
src/basic/hostname-util.c | 14 ++++++++++++--
test/test-network-generator-conversion.sh | 2 +-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c
index e743033..8464164 100644
--- a/src/basic/hostname-util.c
+++ b/src/basic/hostname-util.c
@@ -80,6 +80,16 @@ bool valid_ldh_char(char c) {
c == '-';
}
+static bool hostname_valid_char(char c) {
+ return
+ (c >= 'a' && c <= 'z') ||
+ (c >= 'A' && c <= 'Z') ||
+ (c >= '0' && c <= '9') ||
+ c == '-' ||
+ c == '_' ||
+ c == '.';
+}
+
bool hostname_is_valid(const char *s, ValidHostnameFlags flags) {
unsigned n_dots = 0;
const char *p;
@@ -116,7 +126,7 @@ bool hostname_is_valid(const char *s, ValidHostnameFlags flags) {
hyphen = true;
} else {
- if (!valid_ldh_char(*p))
+ if (!hostname_valid_char(*p))
return false;
dot = false;
@@ -158,7 +168,7 @@ char* hostname_cleanup(char *s) {
dot = false;
hyphen = true;
- } else if (valid_ldh_char(*p)) {
+ } else if (hostname_valid_char(*p)) {
*(d++) = *p;
dot = false;
hyphen = false;
diff --git a/test/test-network-generator-conversion.sh b/test/test-network-generator-conversion.sh
index 6224a4d..05ef833 100755
--- a/test/test-network-generator-conversion.sh
+++ b/test/test-network-generator-conversion.sh
@@ -283,6 +283,7 @@ COMMAND_LINES=(
"ip=:::::dhcp99:dhcp6:10.0.0.128:[fdef:c400:bd01:1096::bbbb]"
"ip=::::::any"
"ip=::::::ibft"
+ "ip=10.0.0.1:::255.255.255.0:valid_hostname:foo99:off"
)
for cmdline in "${COMMAND_LINES[@]}"; do
check_one_long "$cmdline"
@@ -294,7 +295,6 @@ INVALID_COMMAND_LINES=(
"ip=:::::::foo"
"ip=10.0.0:::255.255.255.0::foo99:off"
"ip=10.0.0.1:::255.255.255::foo99:off"
- "ip=10.0.0.1:::255.255.255.0:invalid_hostname:foo99:off"
"ip=10.0.0.1:::255.255.255.0::verylonginterfacename:off"
"ip=:::::dhcp99:dhcp6:0"
"ip=:::::dhcp99:dhcp6:-1"
--
2.39.1