@ -6,7 +6,7 @@
* Portions Copyright ( c ) 1996 - 2001 , PostgreSQL Global Development Group
* Portions Copyright ( c ) 1994 , Regents of the University of California
*
* $ Header : / cvsroot / pgsql / src / backend / commands / user . c , v 1.79 2001 / 07 / 12 18 : 02 : 59 tgl Exp $
* $ Header : / cvsroot / pgsql / src / backend / commands / user . c , v 1.80 2001 / 08 / 15 18 : 42 : 14 momjian Exp $
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
@ -25,6 +25,7 @@
# include "catalog/indexing.h"
# include "commands/user.h"
# include "libpq/crypt.h"
# include "libpq/md5.h"
# include "miscadmin.h"
# include "utils/array.h"
# include "utils/builtins.h"
@ -34,7 +35,7 @@
static void CheckPgUserAclNotNull ( void ) ;
extern bool Password_encryption ;
/*---------------------------------------------------------------------
* write_password_file / update_pg_pwd
@ -201,6 +202,8 @@ CreateUser(CreateUserStmt *stmt)
int max_id = - 1 ;
List * item , * option ;
char * password = NULL ; /* PostgreSQL user password */
bool encrypt_password = Password_encryption ; /* encrypt password? */
char encrypted_password [ MD5_PASSWD_LEN + 1 ] ;
int sysid = 0 ; /* PgSQL system id (valid if havesysid) */
bool createdb = false ; /* Can the user create databases? */
bool createuser = false ; /* Can this user create users? */
@ -218,10 +221,16 @@ CreateUser(CreateUserStmt *stmt)
{
DefElem * defel = ( DefElem * ) lfirst ( option ) ;
if ( strcasecmp ( defel - > defname , " password " ) = = 0 ) {
if ( strcasecmp ( defel - > defname , " password " ) = = 0 | |
strcasecmp ( defel - > defname , " encryptedPassword " ) = = 0 | |
strcasecmp ( defel - > defname , " unencryptedPassword " ) = = 0 ) {
if ( dpassword )
elog ( ERROR , " CREATE USER: conflicting options " ) ;
dpassword = defel ;
if ( strcasecmp ( defel - > defname , " encryptedPassword " ) = = 0 )
encrypt_password = true ;
else if ( strcasecmp ( defel - > defname , " unencryptedPassword " ) = = 0 )
encrypt_password = false ;
}
else if ( strcasecmp ( defel - > defname , " sysid " ) = = 0 ) {
if ( dsysid )
@ -337,8 +346,18 @@ CreateUser(CreateUserStmt *stmt)
new_record [ Anum_pg_shadow_usecatupd - 1 ] = BoolGetDatum ( createuser ) ;
if ( password )
{
if ( ! encrypt_password | | isMD5 ( password ) )
new_record [ Anum_pg_shadow_passwd - 1 ] =
DirectFunctionCall1 ( textin , CStringGetDatum ( password ) ) ;
else
{
if ( ! EncryptMD5 ( password , stmt - > user , encrypted_password ) )
elog ( ERROR , " CREATE USER: password encryption failed " ) ;
new_record [ Anum_pg_shadow_passwd - 1 ] =
DirectFunctionCall1 ( textin , CStringGetDatum ( encrypted_password ) ) ;
}
}
if ( validUntil )
new_record [ Anum_pg_shadow_valuntil - 1 ] =
DirectFunctionCall1 ( nabstimein , CStringGetDatum ( validUntil ) ) ;
@ -418,6 +437,8 @@ AlterUser(AlterUserStmt *stmt)
bool null ;
List * option ;
char * password = NULL ; /* PostgreSQL user password */
bool encrypt_password = Password_encryption ; /* encrypt password? */
char encrypted_password [ MD5_PASSWD_LEN + 1 ] ;
int createdb = - 1 ; /* Can the user create databases? */
int createuser = - 1 ; /* Can this user create users? */
char * validUntil = NULL ; /* The time the login is valid until */
@ -431,10 +452,16 @@ AlterUser(AlterUserStmt *stmt)
{
DefElem * defel = ( DefElem * ) lfirst ( option ) ;
if ( strcasecmp ( defel - > defname , " password " ) = = 0 ) {
if ( strcasecmp ( defel - > defname , " password " ) = = 0 | |
strcasecmp ( defel - > defname , " encryptedPassword " ) = = 0 | |
strcasecmp ( defel - > defname , " unencryptedPassword " ) = = 0 ) {
if ( dpassword )
elog ( ERROR , " ALTER USER: conflicting options " ) ;
dpassword = defel ;
if ( strcasecmp ( defel - > defname , " encryptedPassword " ) = = 0 )
encrypt_password = true ;
else if ( strcasecmp ( defel - > defname , " unencryptedPassword " ) = = 0 )
encrypt_password = false ;
}
else if ( strcasecmp ( defel - > defname , " createdb " ) = = 0 ) {
if ( dcreatedb )
@ -552,8 +579,16 @@ AlterUser(AlterUserStmt *stmt)
/* password */
if ( password )
{
if ( ! encrypt_password | | isMD5 ( password ) )
new_record [ Anum_pg_shadow_passwd - 1 ] =
DirectFunctionCall1 ( textin , CStringGetDatum ( password ) ) ;
else
{
if ( ! EncryptMD5 ( password , stmt - > user , encrypted_password ) )
elog ( ERROR , " CREATE USER: password encryption failed " ) ;
new_record [ Anum_pg_shadow_passwd - 1 ] =
DirectFunctionCall1 ( textin , CStringGetDatum ( encrypted_password ) ) ;
}
new_record_nulls [ Anum_pg_shadow_passwd - 1 ] = ' ' ;
}
else