From 6bcf321bd885dbf0d07ceb48c0fdc3b4d1a95b0f Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 9 Dec 2019 12:42:43 +0100 Subject: [PATCH] improved regex --- CHANGELOG.md | 4 ++++ manifests/cmdalias.pp | 2 +- manifests/defaults.pp | 4 ++-- manifests/sudo.pp | 2 +- manifests/useralias.pp | 6 +++--- metadata.json | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e13b1..0ff10d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.1.31 + +* improved regex for sudoers.d files + ## 0.1.30 * bugfix: sudo files cannot contain dots diff --git a/manifests/cmdalias.pp b/manifests/cmdalias.pp index 14a9a61..4f2bd69 100644 --- a/manifests/cmdalias.pp +++ b/manifests/cmdalias.pp @@ -7,7 +7,7 @@ #TODO: refer per tindre dependencies automatiques include ::sudoers - $cmdname_cleanup = regsubst($cmdname, '[^a-zA-Z]+', '_') + $cmdname_cleanup = regsubst($cmdname, '[^a-zA-Z0-9]+', '_', 'G') file { "/etc/sudoers.d/${order}_00_cmdalias_${cmdname_cleanup}": owner => 'root', diff --git a/manifests/defaults.pp b/manifests/defaults.pp index 834b00d..19fb9c2 100644 --- a/manifests/defaults.pp +++ b/manifests/defaults.pp @@ -7,8 +7,8 @@ include ::sudoers - $username_cleanup = regsubst($username, '[^a-zA-Z]+', '_') - $defaults_cleanup = regsubst($default_name, '[^a-zA-Z]+', '_') + $username_cleanup = regsubst($username, '[^a-zA-Z0-9]+', '_', 'G') + $defaults_cleanup = regsubst($default_name, '[^a-zA-Z0-9]+', '_', 'G') # Defaults:nrpe !requiretty file { "/etc/sudoers.d/${order}_defaults_${defaults_cleanup}_${username_cleanup}": diff --git a/manifests/sudo.pp b/manifests/sudo.pp index ef8bb54..196256c 100644 --- a/manifests/sudo.pp +++ b/manifests/sudo.pp @@ -18,7 +18,7 @@ ) { include ::sudoers - $name_cleanup = regsubst($name, '[^a-zA-Z]+', '_') + $name_cleanup = regsubst($name, '[^a-zA-Z0-9]+', '_', 'G') file { "/etc/sudoers.d/${order}_10_sudo_${name_cleanup}": ensure => $ensure, diff --git a/manifests/useralias.pp b/manifests/useralias.pp index 982210f..54df7da 100644 --- a/manifests/useralias.pp +++ b/manifests/useralias.pp @@ -7,12 +7,12 @@ #TODO: refer per tindre dependencies automatiques include ::sudoers - validate_array($users) - #NAME ::= [A-Z]([A-Z][0-9]_)* validate_re($useraliasname, '[A-Z]([A-Z][0-9]_)*') - file { "/etc/sudoers.d/${order}_00_useralias_${useraliasname}": + $useraliasname_cleanup = regsubst($useraliasname, '[^A-Z0-9]+', '_', 'G') + + file { "/etc/sudoers.d/${order}_00_useralias_${useraliasname_cleanup}": owner => 'root', group => 'root', mode => '0440', diff --git a/metadata.json b/metadata.json index 5d46b9a..3327c63 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "eyp-sudoers", - "version": "0.1.30", + "version": "0.1.31", "author": "eyp", "summary": "manages sudoers", "license": "Apache-2.0",