The script, createuser, will accept user names that CREATE USER will
reject, and that cannot be named in a GRANT command.
I would still prefer it if CREATE USER and GRANT would accept any valid
Unix login name, including some punctuation characters and mixed-case,
but here is a patch to make things consistent with their current
behaviour.
This patch to createuser rejects user names that contain any characters
apart from alphanumerics and '_' and it converts upper- to lower-case,
warning the user that it is doing so. It uses tr to do this; I am using
the GNU version; if other versions don't support the character classes
that I have used, the classes should be changed to more long-winded lists
of characters.
The patch also changes `done', used as a variable name, to `isdone',
because my colour-coded vim editor was complaining of invalid syntax.
This is the patch:
diff -cr postgresql-6.3.2.orig/src/bin/createuser/createuser.sh
postgresql-6.3.2/src/bin/createuser/createuser.sh
*** postgresql-6.3.2.orig/src/bin/createuser/createuser.sh Wed Feb 25 13:08:37
1998
--- postgresql-6.3.2/src/bin/createuser/createuser.sh Tue Apr 28 11:28:40 1998
***************
*** 94,103 ****
# get the user name of the new user. Make sure it doesn't already exist.
#
! if [ -z "$NEWUSER" ]
! then
echo _fUnKy_DASH_N_sTuFf_ "Enter name of user to add --->
_fUnKy_BACKSLASH_C_sTuFf_"
read NEWUSER
fi
QUERY="select usesysid from pg_user where usename = '$NEWUSER' "
--- 94,119 ----
# get the user name of the new user. Make sure it doesn't already exist.
#
! while [ -z "$NEWUSER" ]
! do
echo _fUnKy_DASH_N_sTuFf_ "Enter name of user to add --->
_fUnKy_BACKSLASH_C_sTuFf_"
read NEWUSER
+ done
+
+ # Check username conforms to allowed patterns
+ x=`echo _fUnKy_DASH_N_sTuFf_ $NEWUSER _fUnKy_BACKSLASH_C_sTuFf_ | tr -d
'[:alnum:]_'`
+ if [ ! -z "$x" ]
+ then
+ echo $CMDNAME: invalid characters in username \'$NEWUSER\' >&2
+ exit 1
+ fi
+ x=`echo _fUnKy_DASH_N_sTuFf_ $NEWUSER _fUnKy_BACKSLASH_C_sTuFf_ |
+ tr '[:upper:]' '[:lower:]'`
+
+ if [ $x != $NEWUSER ]
+ then
+ echo $CMDNAME: upper-case characters in username \'$NEWUSER\' folded
to lower-case >&2
+ NEWUSER=$x
fi
QUERY="select usesysid from pg_user where usename = '$NEWUSER' "
***************
*** 116,128 ****
exit 1
fi
! done=0
#
# get the system id of the new user. Make sure it is unique.
#
! while [ $done -ne 1 ]
do
SYSID=
DEFSYSID=`pg_id $NEWUSER 2>/dev/null`
--- 132,144 ----
exit 1
fi
! isdone=0
#
# get the system id of the new user. Make sure it is unique.
#
! while [ $isdone -ne 1 ]
do
SYSID=
DEFSYSID=`pg_id $NEWUSER 2>/dev/null`
***************
*** 156,162 ****
echo "$CMDNAME: $SYSID already belongs to $RES, pick another"
DEFMSG= DEFSYSID= SYSID=
else
! done=1
fi
done
done
--- 172,178 ----
echo "$CMDNAME: $SYSID already belongs to $RES, pick another"
DEFMSG= DEFSYSID= SYSID=
else
! isdone=1
fi
done
done
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP key from public servers; key ID 32B8FAA1
========================================
Come to me, all you who labour and are heavily laden, and I will
give you rest. Take my yoke upon you, and learn from me; for I am
meek and lowly in heart, and you shall find rest for your souls.
For my yoke is easy and my burden is light. (Matthew 11: 28-30)