X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 96C82CD11F for ; Sun, 20 Jul 2003 05:06:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 83185-10 for ; Sun, 20 Jul 2003 05:07:35 +0000 (GMT) Received: from mail.travelamericas.com (dsl231-059-037.sea1.dsl.speakeasy.net [216.231.59.37]) by svr1.postgresql.org (Postfix) with SMTP id 35E58CD144 for ; Sun, 20 Jul 2003 02:06:57 -0300 (ADT) Received: (qmail 4998 invoked from network); 20 Jul 2003 05:07:34 -0000 Received: from unknown (HELO travelamericas.com) (127.0.0.1) by localhost with SMTP; 20 Jul 2003 05:07:34 -0000 Message-ID: <3F1A2396.4050907@travelamericas.com> Date: Sat, 19 Jul 2003 22:07:34 -0700 From: Chris Travers User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: SECURITY DEFINER changes CURRENT_USER? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/291 X-Sequence-Number: 14405 Hi all; I found an unexpected behavior while trying to write a function to allow users to change their own passwords. The function is as follows: CREATE OR REPLACE FUNCTION change_password(VARCHAR) RETURNS BOOL AS ' DECLARE username VARCHAR; CMD VARCHAR; password ALIAS FOR $1; BEGIN SELECT INTO username CURRENT_USER; CMD := ''ALTER USER '' || username || '' WITH PASSWORD ''; CMD := CMD || '''''''' || password || ''''''''; EXECUTE CMD; RETURN TRUE; end; ' LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER I would expect this to change the password of the user currently logged in but instead it changes MY password. Evidently when a function is called which is set to SECURITY DEFINER, it changes the context of the current user. The CURRENT_USER then returns the name of the definer rather than the invoker of the function. So this being said-- are there any workarounds that don't allow anyone to change anyone else's password? Best Wishes, Chris Travers