Merge branch '__mysql_privileges_fix' into 'master'

__mysql_privileges: fix quoting

See merge request ungleich-public/cdist!843
This commit is contained in:
poljakowski 2020-02-14 16:07:30 +01:00
commit c4f085e739
3 changed files with 10 additions and 4 deletions

View file

@ -30,7 +30,7 @@ host="$( cat "$__object/parameter/host" )"
check_privileges="$(
mysql -B -N -e "show grants for '$user'@'$host'" \
| grep -Ei "^grant $privileges on .$database.\..$table. to " || true )"
| grep -Ei "^grant $privileges on .$database.\..?$table.? to " || true )"
if [ -n "$check_privileges" ]
then

View file

@ -37,13 +37,19 @@ user="$( cat "$__object/parameter/user" )"
host="$( cat "$__object/parameter/host" )"
if [ "$table" != '*' ]
then
# shellcheck disable=SC2016
table="$( printf '`%s`' "$table" )"
fi
case "$state_should" in
present)
echo "mysql -e 'grant $privileges on \`$database\`.\`$table\` to \`$user\`@\`$host\`'"
echo "mysql -e 'grant $privileges on \`$database\`.$table to \`$user\`@\`$host\`'"
echo "grant $privileges on $database.$table to $user@$host" >> "$__messages_out"
;;
absent)
echo "mysql -e 'revoke $privileges on \`$database\`.\`$table\` from \`$user\`@\`$host\`'"
echo "mysql -e 'revoke $privileges on \`$database\`.$table from \`$user\`@\`$host\`'"
echo "revoke $privileges on $database.$table from $user@$host" >> "$__messages_out"
;;
esac

View file

@ -17,7 +17,7 @@ REQUIRED PARAMETERS
database
Name of database.
User
user
Name of user.