-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from jordiprats/master
check datadir compliance
- Loading branch information
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
# puppet managed file | ||
|
||
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" | ||
|
||
USERNAME=postgres | ||
DATADIR="/var/lib/pgsql" | ||
|
||
while getopts 'U:d:w:h' OPT; | ||
do | ||
case $OPT in | ||
U) USERNAME="$OPTARG" | ||
;; | ||
d) DATADIR="$OPTARG" | ||
;; | ||
h) JELP=1 | ||
;; | ||
*) JELP="wtf" | ||
;; | ||
esac | ||
done | ||
|
||
shift $(($OPTIND - 1)) | ||
|
||
if [ -n "$JELP" ]; | ||
then | ||
echo "usage: $0 [-U <USRNAME>] [-d <DATADIR>]" | ||
echo -e "\t-U\t\t user name (default: postgres)" | ||
echo -e "\t-d\t\t datadir (default: /var/lib/pgsql)" | ||
echo -e "\t-h\t\t show help" | ||
exit 1 | ||
fi | ||
|
||
if [[ "$(ls -ld "${DATADIR}" | awk '{ print $1 }' | sed 's/[^a-z]//g')" != "drwx" ]]; | ||
then | ||
echo "CRITICAL: datadir mode is not 0700"; | ||
exit 2 | ||
fi | ||
|
||
ID_POSTGRES="$(id -u ${USERNAME})" | ||
|
||
NOT_POSTGRES_FILES="$(find "${DATADIR}" -type f -not -uid "${ID_POSTGRES}" | wc -l)" | ||
if [ "${NOT_POSTGRES_FILES}" -ne 0 ]; | ||
then | ||
echo "CRITICAL: found files not owned by postgres" | ||
exit 2 | ||
else | ||
echo "OK: datadir in compliance" | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# puppet managed file | ||
|
||
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters