Skip site navigation (1) Skip section navigation (2)

Patch for createuser to make it consistent with CREATE USER

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Patch for createuser to make it consistent with CREATE USER
Date: 1998-04-28 10:04:42
Message-ID: 199804281104.MAA21803@linda.lfix.co.uk (view raw or flat)
Thread:
Lists: pgsql-hackers
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(dot)Elphick(at)lfix(dot)co(dot)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)



pgsql-hackers by date

Next:From: Oliver ElphickDate: 1998-04-28 10:04:43
Subject: Re: Bug#21681: postgresql: Doesn't allow granting to www-data
Previous:From: Ralf BergerDate: 1998-04-28 09:30:50
Subject: Re: [QUESTIONS] Postgres still dying on insert

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group