2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-07-31 18:19:40 +00:00

refactor(kea): centralize service account lookup

This commit is contained in:
Vinícius Ferrão
2026-07-18 13:59:15 -03:00
parent 5c3bb1d9fa
commit a44e9fd819
+18 -13
View File
@@ -17,6 +17,7 @@ my %KEA_SERVICE_CANDIDATES = (
'kea-dhcp-ddns' => [ 'kea-dhcp-ddns', 'kea-dhcp-ddns-server' ],
'kea-ctrl-agent' => [ 'kea-ctrl-agent' ],
);
my @KEA_ACCOUNT_CANDIDATES = ( 'kea', '_kea' );
sub new {
my ( $class, %args ) = @_;
@@ -57,6 +58,19 @@ sub control_socket_path {
return $self->_kea_socket_dir() . "/$socket_name";
}
sub service_account {
foreach my $user (@KEA_ACCOUNT_CANDIDATES) {
my @entry = getpwnam($user);
return {
name => $entry[0],
uid => $entry[2],
gid => $entry[3],
} if @entry;
}
return;
}
sub render_dhcp4_config {
my ( $self, $intent ) = @_;
@@ -485,12 +499,12 @@ sub _validate_config_with {
my $prefix = '';
if ( $> == 0 ) {
my $kea_user = _kea_user();
my $service_account = $self->service_account();
my $runuser = _command_path('runuser');
# Validate as the daemon user when possible so root does not hide
# packaged Kea runtime-directory or config-readability failures.
$prefix = _shell_quote($runuser) . ' -u ' . _shell_quote($kea_user) . ' -- '
if $kea_user && $runuser;
$prefix = _shell_quote($runuser) . ' -u ' . _shell_quote( $service_account->{name} ) . ' -- '
if $service_account && $runuser;
}
my $cmd = $prefix . _shell_quote($kea) . " -t " . _shell_quote($path) . " 2>&1";
@@ -998,7 +1012,7 @@ sub _set_config_permissions {
}
sub _kea_group {
foreach my $group ( 'kea', '_kea' ) {
foreach my $group (@KEA_ACCOUNT_CANDIDATES) {
my @entry = getgrnam($group);
return ( $entry[0], $entry[2] ) if @entry;
}
@@ -1006,15 +1020,6 @@ sub _kea_group {
return;
}
sub _kea_user {
foreach my $user ( 'kea', '_kea' ) {
my @entry = getpwnam($user);
return $entry[0] if @entry;
}
return;
}
sub _kea_service {
my ( $self, $service ) = @_;