Skip to content

Commit

Permalink
Create bash_pam_pwquality_parameter_value macro
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmcanonical committed Dec 1, 2024
1 parent 4db82ac commit b638ab1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions shared/macros/10-bash.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,38 @@ fi
{{%- endmacro -%}}


{{#
Sets PAM pwquality module options and values. The module argument is not removed from pam files
since it is not inserted there in Ubuntu case.
It also assume pam_pwquality.so is added as required module for account.

:param option: pwquality option eg. retry, minlen, dcredit
:type option: str
:param value: value of option
:type value: str

#}}
{{%- macro bash_pam_pwquality_parameter_value(option, value='') -%}}
PWQUALITY_CONF="/etc/security/pwquality.conf"
{{%- if value == '' %}}
regex="^\s*{{{ option }}}"
line="{{{ option }}}"
{{%- else %}}
regex="^\s*{{{ option }}}\s*="
line="{{{ option }}} = {{{ value }}}"
{{%- endif %}}
if ! grep -q $regex $PWQUALITY_CONF; then
echo $line >> $PWQUALITY_CONF
{{%- if value == '' %}}
fi
{{%- else %}}
else
sed -i --follow-symlinks 's|^\s*\({{{ option }}}\s*=\s*\)\(\S\+\)|\1'"{{{ value }}}"'|g' $PWQUALITY_CONF
fi
{{%- endif %}}
{{%- endmacro -%}}


{{#
Print a message to stderr and exit the shell

Expand Down

0 comments on commit b638ab1

Please sign in to comment.