Skip to content

Commit

Permalink
Fix legacy fact usage and wrong var scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
cruelsmith committed Aug 16, 2023
1 parent 164f16d commit f57fe56
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@
# This should be fixed in FreeRADIUS 2.2.0
# http://lists.freeradius.org/pipermail/freeradius-users/2012-October/063232.html
# Only affects RPM-based systems
if $::osfamily == 'RedHat' {
if $facts['os']['family'] == 'RedHat' {
exec { 'delete-radius-rpmnew':
command => "find ${freeradius::fr_basepath} -name *.rpmnew -delete",
onlyif => "find ${freeradius::fr_basepath} -name *.rpmnew | grep rpmnew",
Expand Down
2 changes: 1 addition & 1 deletion manifests/module/ldap.pp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
# FR3.1 format server = 'ldap1.example.com'
# server = 'ldap2.example.com'
# server = 'ldap3.example.com'
$serverconcatarray = $::freeradius_version ? {
$serverconcatarray = $facts['freeradius_version'] ? {
/^3\.0\./ => any2array(join($server, ',')),
default => $server,
}
Expand Down
44 changes: 22 additions & 22 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Default parameters for freeradius
class freeradius::params {
# Make an educated guess which version of FR we are running, based on the OS
case $::operatingsystem {
case $facts['os']['name'] {
/RedHat|CentOS|Rocky|AlmaLinux/: {
$fr_guessversion = $::operatingsystemmajrelease ? {
$fr_guessversion = $facts['os']['release']['major'] ? {
5 => '2',
6 => '2',
7 => '3',
Expand All @@ -13,7 +13,7 @@
}
}
'Debian': {
$fr_guessversion = $::operatingsystemmajrelease ? {
$fr_guessversion = $facts['os']['release']['major'] ? {
6 => '2',
7 => '2',
8 => '2',
Expand All @@ -22,15 +22,15 @@
}
}
'Fedora': {
$fr_guessversion = $::operatingsystemmajrelease ? {
$fr_guessversion = $facts['os']['release']['major'] ? {
21 => '3',
22 => '3',
23 => '3',
default => '3',
}
}
'Ubuntu': {
$fr_guessversion = $::operatingsystemmajrelease ? {
$fr_guessversion = $facts['os']['release']['major'] ? {
'14.04' => '2',
'14.10' => '2',
'15.04' => '2',
Expand All @@ -42,40 +42,40 @@
}
}
default: {
fail("OS ${::operatingsystem} is not supported")
fail("OS ${facts['os']['name']} is not supported")
}
}

# Use the FR version fact if defined, otherwise use our best estimate from above
if getvar('::freeradius_maj_version') {
$fr_version = $::freeradius_maj_version
if 'freeradius_maj_version' in facts {
$fr_version = $facts['freeradius_maj_version']
} else {
$fr_version = $fr_guessversion
}

# Name of FreeRADIUS package
$fr_package = $::osfamily ? {
$fr_package = $facts['os']['family'] ? {
'RedHat' => 'freeradius',
'Debian' => 'freeradius',
default => 'freeradius',
}

# Name of wpa_supplicant package
$fr_wpa_supplicant = $::osfamily ? {
$fr_wpa_supplicant = $facts['os']['family'] ? {
'RedHat' => 'wpa_supplicant',
'Debian' => 'wpasupplicant',
default => 'wpa_supplicant',
}

# Name of FreeRADIUS service
$fr_service = $::osfamily ? {
$fr_service = $facts['os']['family'] ? {
'RedHat' => 'radiusd',
'Debian' => 'freeradius',
default => 'radiusd',
}

# Whether the FreeRADIUS init.d startup script has a status setting or not
$fr_service_has_status = $::osfamily ? {
$fr_service_has_status = $facts['os']['family'] ? {
'RedHat' => true,
'Debian' => true,
default => false,
Expand All @@ -85,13 +85,13 @@
$fr_pidfile = "/var/run/${fr_service}/${fr_service}.pid"

# Default base path for FreeRADIUS configs
case $::osfamily {
case $facts['os']['family'] {
'RedHat': {
$fr_basepath = '/etc/raddb'
$fr_raddbdir = "\${sysconfdir}/raddb"
}
'Debian': {
$fr_basepath = $::operatingsystemmajrelease ? {
$fr_basepath = $facts['os']['release']['major'] ? {
'9' => '/etc/freeradius/3.0',
'10' => '/etc/freeradius/3.0',
'11' => '/etc/freeradius/3.0',
Expand All @@ -101,7 +101,7 @@
'22.04' => '/etc/freeradius/3.0',
default => '/etc/freeradius',
}
$fr_raddbdir = $::operatingsystemmajrelease ? {
$fr_raddbdir = $facts['os']['release']['major'] ? {
'9' => "\${sysconfdir}/freeradius/3.0",
'10' => "\${sysconfdir}/freeradius/3.0",
'11' => "\${sysconfdir}/freeradius/3.0",
Expand Down Expand Up @@ -139,48 +139,48 @@
$fr_moduleconfigpath = "${fr_basepath}/${fr_modconfigdir}"

# Path for FreeRADIUS logs
$fr_logpath = $::osfamily ? {
$fr_logpath = $facts['os']['family'] ? {
'RedHat' => '/var/log/radius',
'Debian' => '/var/log/freeradius',
default => '/var/log/radius',
}

# FreeRADIUS user
$fr_user = $::osfamily ? {
$fr_user = $facts['os']['family'] ? {
'RedHat' => 'radiusd',
'Debian' => 'freerad',
default => 'radiusd',
}

# FreeRADIUS group
$fr_group = $::osfamily ? {
$fr_group = $facts['os']['family'] ? {
'RedHat' => 'radiusd',
'Debian' => 'freerad',
default => 'radiusd',
}

# Privileged winbind user
$fr_wbpriv_user = $::osfamily ? {
$fr_wbpriv_user = $facts['os']['family'] ? {
'RedHat' => 'wbpriv',
'Debian' => 'winbindd_priv',
default => 'wbpriv',
}

$fr_libdir = $::osfamily ? {
$fr_libdir = $facts['os']['family'] ? {
'RedHat' => '/usr/lib64/freeradius',
'Debian' => '/usr/lib/freeradius',
default => '/usr/lib64/freeradius',
}

$fr_db_dir = $::osfamily ? {
$fr_db_dir = $facts['os']['family'] ? {
'Debian' => "\${raddbdir}",
default => "\${localstatedir}/lib/radiusd",
}

$radacctdir = "\${logdir}/radacct"

# Default radsniff environment file location
$fr_radsniff_envfile = $::osfamily ? {
$fr_radsniff_envfile = $facts['os']['family'] ? {
'RedHat' => '/etc/sysconfig/radsniff',
'Debian' => '/etc/defaults/radsniff',
default => undef,
Expand Down
2 changes: 2 additions & 0 deletions manifests/radsniff.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
String $options = '', # lint:ignore:params_empty_string_assignment
Optional[String] $pidfile = undef,
) inherits freeradius::params {
require freeradius

unless $freeradius::utils_support {
fail('freeradius::radsniff requires freeradius have utils_support enabled')
}
Expand Down
12 changes: 6 additions & 6 deletions manifests/sql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
Optional[Integer] $pool_idle_timeout = 60,
Optional[Float] $pool_connect_timeout = undef,
) {
require freeradius::params
require freeradius

$fr_package = $freeradius::params::fr_package
$fr_service = $freeradius::params::fr_service
Expand Down Expand Up @@ -100,10 +100,10 @@
} else {
if $pool_connect_timeout != undef {
fail(@("FAIL"/L)
The `pool_connect_timeout` parameter requires FreeRADIUS 3.1.x, \
i.e. the experimental branch. You are running \
`${facts['freeradius_version']}`.
|-FAIL
The `pool_connect_timeout` parameter requires FreeRADIUS 3.1.x, \
i.e. the experimental branch. You are running \
`${facts['freeradius_version']}`.
|-FAIL
)
}
}
Expand All @@ -115,7 +115,7 @@
if ($custom_query_file and $custom_query_file != '') {
$custom_query_file_path = "${fr_moduleconfigpath}/${name}-queries.conf"

::freeradius::config { "${name}-queries.conf":
freeradius::config { "${name}-queries.conf":
source => $custom_query_file,
}
}
Expand Down
6 changes: 3 additions & 3 deletions templates/radsniff.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ After=radiusd.target

[Service]
Type=forking
PIDFile=<%=scope['::freeradius::radsniff::final_pidfile']%>
EnvironmentFile=<%=scope['::freeradius::radsniff::final_envfile']%>
ExecStart=/usr/bin/radsniff -P <%=scope['::freeradius::radsniff::final_pidfile']%> -d <%=scope['::freeradius::radsniff::fr_basepath']%> $RADSNIFF_OPTIONS
PIDFile=<%= @final_pidfile %>
EnvironmentFile=<%= @final_envfile %>
ExecStart=/usr/bin/radsniff -P <%= @final_pidfile %> -d <%= @fr_basepath %> $RADSNIFF_OPTIONS

[Install]
WantedBy=multi-user.target

0 comments on commit f57fe56

Please sign in to comment.