Skip to content

Commit 569b8a3

Browse files
authored
🧹 Fix logindefs resource, allow for trailing comments (#5536)
* fix logindefs, allow for trailing comments Signed-off-by: Manuel Weber <manuel@mondoo.com> * update testdata Signed-off-by: Manuel Weber <manuel@mondoo.com> * update testdata Signed-off-by: Manuel Weber <manuel@mondoo.com> * updated test Signed-off-by: Manuel Weber <manuel@mondoo.com> --------- Signed-off-by: Manuel Weber <manuel@mondoo.com>
1 parent 6456d8b commit 569b8a3

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

providers/os/resources/logindefs/logindefs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
func Parse(r io.Reader) map[string]string {
1414
res := map[string]string{}
1515

16-
// ignore line if it starts with a comment
17-
logindefEntry := regexp.MustCompile(`^\s*([^#]\S+)\s+(\S+)\s*$`)
16+
// ignore line if it starts with a comment, allow trailing comments though
17+
logindefEntry := regexp.MustCompile(`^\s*([^#]\S+)\s+(\S+)\s*(?:#.*)?$`)
1818

1919
scanner := bufio.NewScanner(r)
2020
for scanner.Scan() {

providers/os/resources/logindefs/logindefs_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestLoginDefsParser(t *testing.T) {
2525

2626
assert.Equal(t, "tty", entries["TTYGROUP"])
2727
assert.Equal(t, "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games", entries["ENV_PATH"])
28+
assert.Equal(t, "1", entries["PASS_MIN_DAYS"])
2829

2930
_, ok := entries["SHA_CRYPT_MIN_ROUNDS"]
3031
assert.False(t, ok)

providers/os/resources/logindefs/testdata/debian.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ UMASK 022
160160
# PASS_WARN_AGE Number of days warning given before a password expires.
161161
#
162162
PASS_MAX_DAYS 99999
163-
PASS_MIN_DAYS 0
163+
PASS_MIN_DAYS 1 # Updated automatically
164164
PASS_WARN_AGE 7
165165
166166
#

0 commit comments

Comments
 (0)