Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare support for other backends #737

Merged
merged 33 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d43e49a
DBusStructures: Add new file system enum and partition usage struct
meisenzahl Nov 9, 2023
ff2b6d0
DBusStructures: Add to_string method to FileSystem enum
meisenzahl Nov 9, 2023
5853498
Update file system types to use InstallerDaemon
meisenzahl Nov 9, 2023
8c137fe
Daemon: Convert file system and partition usage to common format
meisenzahl Nov 9, 2023
3e041ce
Add PartitionTable enum and update
meisenzahl Nov 9, 2023
3a2ed8d
Add new enums and struct for InstallerDaemon and update flags in Daem…
meisenzahl Nov 9, 2023
c1e4fa9
Refactor to_common_usage_bootloader method in Daemon class
meisenzahl Nov 9, 2023
7cdde6a
Add InstallerDaemon.LogLevel and InstallerDaemon.Error to InstallerDa…
meisenzahl Nov 9, 2023
08a0147
Utils: Remove distinst specific code
meisenzahl Nov 9, 2023
dd09a4b
Refactor file common/DBusStructures.vala to handle FileSystem.NONE ca…
meisenzahl Nov 9, 2023
82c20cd
Remove distinst_dep from gui_dependencies
meisenzahl Nov 9, 2023
2d382d2
Add support for Distinst installer backend in
meisenzahl Nov 9, 2023
400d567
Satisfy linter
meisenzahl Nov 9, 2023
a27bda7
DBusStructures: Refactor to unowned reference
meisenzahl Nov 11, 2023
c69236b
Merge branch 'main' into prepare-backends
meisenzahl Sep 25, 2024
3ad086a
Merge main
meisenzahl Sep 25, 2024
aab202c
Improve logging
meisenzahl Sep 25, 2024
421e636
update
meisenzahl Sep 26, 2024
490bdb4
Revert "Improve logging"
meisenzahl Sep 26, 2024
5e67070
Merge branch 'main' into prepare-backends
meisenzahl Sep 26, 2024
93b8f5c
Refactor
meisenzahl Sep 26, 2024
1592f73
Merge branch 'main' into prepare-backends
meisenzahl Sep 28, 2024
64ef863
Merge branch 'main' into prepare-backends
danirabbit Oct 1, 2024
fff2b00
Utils: Port hostname validation from distinst and add tests
meisenzahl Oct 1, 2024
8e92a87
Merge branch 'main' into prepare-backends
meisenzahl Oct 1, 2024
cb012db
Merge branch 'main' into prepare-backends
meisenzahl Oct 1, 2024
81151c8
HostnameValidator: Refactor to use char.isalnum
meisenzahl Oct 2, 2024
c4eec26
HostnameValidator: Add comment
meisenzahl Oct 2, 2024
56d4d19
HostnameValidator: Update copyright and license
meisenzahl Oct 2, 2024
216cc98
Merge branch 'main' into prepare-backends
meisenzahl Oct 2, 2024
267e11d
Merge branch 'main' into prepare-backends
meisenzahl Oct 2, 2024
6b9abce
Merge branch 'main' into prepare-backends
meisenzahl Oct 2, 2024
0130ff3
Merge branch 'main' into prepare-backends
meisenzahl Oct 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
run: |
meson setup build
ninja -C build install
ninja -C build test

lint:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ subdir('common')
subdir('daemon')
subdir('src')
subdir('data')
subdir('test')
47 changes: 47 additions & 0 deletions src/HostnameValidator.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
/*-
* Copyright 2024 elementary, Inc. (https://elementary.io)
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Marius Meisenzahl <[email protected]>
*/
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved

namespace Utils {
private bool hostname_is_valid_char (char c) {
return ((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
c == '-' ||
c == '.');
}

// Based on https://github.com/pop-os/hostname-validator/blob/458fa5a1df98cb663f0456dffb542e1a907861c9/src/lib.rs#L29
public bool hostname_is_valid (string hostname) {
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < hostname.char_count (); i++) {
char c = hostname[i];
if (!hostname_is_valid_char (c)) {
return false;
}
}

string[] labels = hostname.split (".", -1);
foreach (string label in labels) {
if (label.char_count () == 0 || label.length > 63 || label[0] == '-' || label[label.length - 1] == '-') {
return false;
}
}

return !(hostname.char_count () == 0 || hostname.length > 253);
}
}
7 changes: 7 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ namespace Utils {
string hostname = get_ubiquity_compatible_hostname () ?? ("elementary-os" + "-" + get_chassis ());
hostname += "-" + get_machine_id ().substring (0, 8);

// If the automatic hostname logic fails in some way, it's possible we may generate an invalid
// hostname. We could fix this by trimming traling/leading hyphens or other invalid characters.
// But it's probably a bad hostname anyway, so just fallback
if (!hostname_is_valid (hostname)) {
hostname = "elementary-os";
}

return hostname;
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vala_files = [
'Application.vala',
'HostnameValidator.vala',
'MainWindow.vala',
'Utils.vala',
'Helpers/InstallerDaemon.vala',
Expand Down
24 changes: 24 additions & 0 deletions test/HostnameValidatorTest.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
void add_hostname_validator_tests () {
Test.add_func ("/valid", () => {
assert (Utils.hostname_is_valid ("VaLiD-HoStNaMe"));
assert (Utils.hostname_is_valid ("50-name"));
assert (Utils.hostname_is_valid ("235235"));
assert (Utils.hostname_is_valid ("example.com"));
assert (Utils.hostname_is_valid ("VaLid.HoStNaMe"));
assert (Utils.hostname_is_valid ("123.456"));
});

Test.add_func ("/invalid", () => {
assert (!Utils.hostname_is_valid ("-invalid-name"));
assert (!Utils.hostname_is_valid ("also-invalid-"));
assert (!Utils.hostname_is_valid ("asdf@fasd"));
assert (!Utils.hostname_is_valid ("@asdfl"));
assert (!Utils.hostname_is_valid ("asd f@"));
assert (!Utils.hostname_is_valid (".invalid"));
assert (!Utils.hostname_is_valid ("invalid.name."));
assert (!Utils.hostname_is_valid ("foo.label-is-way-to-longgggggggggggggggggggggggggggggggggggggggggggg.org"));
assert (!Utils.hostname_is_valid ("invalid.-starting.char"));
assert (!Utils.hostname_is_valid ("invalid.ending-.char"));
assert (!Utils.hostname_is_valid ("empty..label"));
});
}
5 changes: 5 additions & 0 deletions test/Test.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void main (string[] args) {
Test.init (ref args);
add_hostname_validator_tests ();
Test.run ();
}
13 changes: 13 additions & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_dependencies = [
glib_dep,
]

tests = executable(
meson.project_name() + '-tests',
'HostnameValidatorTest.vala',
'Test.vala',
meson.project_source_root() + '/src/HostnameValidator.vala',
dependencies: test_dependencies
)

test('Test', tests)