X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 5996B475ECE for ; Mon, 24 Mar 2003 04:54:43 -0500 (EST) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id 41498475A80 for ; Mon, 24 Mar 2003 04:54:40 -0500 (EST) Received: from klaster.net (pq111.krakow.cvx.ppp.tpnet.pl [213.76.41.111]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 87D186A222 for ; Mon, 24 Mar 2003 10:54:30 +0100 (CET) Message-ID: <3E7ED5EE.9090104@klaster.net> Date: Mon, 24 Mar 2003 10:54:54 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.3) Gecko/20030312 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: "'pgsql-sql@postgresql.org'" Subject: function with security definer Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-10.9 required=5.0 tests=BAYES_10,RCVD_IN_RFCI,USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/538 X-Sequence-Number: 12576 Hi I have a lot of users for my database, but I don't want to create each of them as postgres user, so I tried to do this: 1. Create only postgres 3 users: admin,user,nobody 2. Login into database _only_ as nobody and execute only 1 function - make_login. 3. This function checks user login and password 4. If everything is ok, function switches from nobody to either user or admin. Here is a body of function: CREATE OR REPLACE FUNCTION make_login(varchar,varchar) returns integer AS' DECLARE login_ ALIAS for $1; passwd_ ALIAS for $2; access_level integer; BEGIN select into access_level access_level from users where login=login_ and passwd=passwd_; if not found then return -1; end if; if access_level=1 then set session authorization ''user''; end if; if access_level=2 then set session authorization ''admin''; end if; return 1; END; ' LANGUAGE 'plpgsql' SECURITY DEFINER; Well, it doesn't work :-( ERROR: permission denied Why? Everything looks ok. User nobody has acl to execute this function. Function is created by database owner. What else do I need? Regards, Tomasz Myrta