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

Test KRNL-5622 what about SO without systemd (systemctl) - for example Slackware? #1544

Closed
teoberi opened this issue Sep 27, 2024 · 7 comments

Comments

@teoberi
Copy link
Contributor

teoberi commented Sep 27, 2024

Describe the bug

if [ $(${SYSTEMCTLBINARY} get-default) ]; then

Version

  • Distribution: Slackware64-current
  • Lynis version: 3.1.2

Expected behavior
If it does not exist, the command should not be run:
systemctl get-default

Output

[+] Kernel

/root/lynis/include/tests_kernel: line 44: get-default: command not found

@teoberi
Copy link
Contributor Author

teoberi commented Sep 27, 2024

A possible solution:
if [ $([ ! -z ${SYSTEMCTLBINARY} ] && ${SYSTEMCTLBINARY} get-default) ]; then

@teoberi
Copy link
Contributor Author

teoberi commented Sep 30, 2024

Can it be accepted?

@mboelen
Copy link
Member

mboelen commented Sep 30, 2024

Added a slightly different if-statement to allow also for proper logging. See commit 0316811

Can you test if it works for you?

@teoberi
Copy link
Contributor Author

teoberi commented Sep 30, 2024

With my modification, the runlevel is also displayed in the case without systemd. With your modification, the runlevel display is missing if systemd is missing!
I tested in my version with -n instead of ! -z and it doesn't work!

The if block for inittab is out of place!

2024-09-30 15:23:28 Performing test ID KRNL-5622 (Determine Linux default run level)
2024-09-30 15:23:28 Result: test skipped, as systemctl binary could not be found

@mboelen
Copy link
Member

mboelen commented Sep 30, 2024

You are right, your solution might be better suited for a wider range of Linux distributions. Want to create a pull request for it?

@teoberi
Copy link
Contributor Author

teoberi commented Sep 30, 2024

I can create a pull request, but I would like to study a little more the two code variants.

@teoberi
Copy link
Contributor Author

teoberi commented Sep 30, 2024

After a bit of study, I finally stuck with my solution.
I also studied the documentation and the examples from here, after which I tested the versions with -n and -z both in Slackware64-current and in Ubuntu 24.04.01.

Option\Value non-empty empty not declared/not set
-v true true false
-z false true true
-n true false false

The only option that worked for both OSes is ! -z
I will test everything again tomorrow after which I will add a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants