Обсуждение: about permissions
hi! First short explanation: I create application in php. In scripts I need sometimes check if user has permissions to for example update values in some table So question: How should looks my queryi like? I mean something like select pg_class.relacl where relname='cust' and pg_class.relacl[2]='my_user=arwR'; (this query doesn't work) and another difficult problem: I don't know what place in relacl array is occupied by permissions for my user and of course can't check for string 'myuser=arwR' cause permissions could be 'arw', 'ar', 'r'. Naturally I can solve this by taking whole array and processing data in php, but I could be really fine to solve this inside postgresTIARem -------------------------------------------------------------------*------------ Remigiusz Sokolowski e-mail: rems@gdansk.sprint.pl * * -----------------------------------------------------------------*****----------
Remigiusz Sokolowski wrote:
>
> hi!
> First short explanation:
> I create application in php. In scripts I need sometimes check if user has
> permissions to for example update values in some table
>
> So question:
> How should looks my queryi like?
>
> I mean something like
> select pg_class.relacl where relname='cust' and
> pg_class.relacl[2]='my_user=arwR'; (this query doesn't work)
>
> and another difficult problem:
> I don't know what place in relacl array is occupied by permissions for my
> user and of course can't check for string 'myuser=arwR' cause permissions
> could be 'arw', 'ar', 'r'.
> Naturally I can solve this by taking whole array and processing data in
> php, but
> I could be really fine to solve this inside postgres
You can compile+install PL/Tcl in your database and use the
function I've included at the end. It's usage is:
--
-- PL/Tcl function to verify if a user has specific permissions
-- on a relation.
--
-- Usage: check_permission(relname,username,perms)
--
-- perms is a string consisting of any combination of the
-- characters a,r,w and R (R means RULE permission).
--
-- Returns: true if user has ALL permissions
-- false if at least one permission is missing
--
-- Exceptions: generates an error if the relation or it's owner
-- aren't found in the system catalogs
--
The perms string can be given in any order, so 'awr' is equal
to 'raw'. It follows the PostgreSQL semantics where
superusers bypass all access restrictions, a user not
explicitly listed in the acl has the rights of the public
entry and if there is no acl at all, only the owner has full
rights.
It does NOT handle group permissions up to now. You didn't
told that you need this functionality too.
Hope that solves your problem.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #
I wrote:
> You can compile+install PL/Tcl in your database and use the
> function I've included at the end. It's usage is:
But forgot to include it :-)
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #
begin 644 chkperm.sql
M+2T*+2T@4$PO5&-L(&9U;F-T:6]N('1O('9E<FEF>2!I9B!A('5S97(@:&%S
M('-P96-I9FEC('!E<FUI<W-I;VYS"BTM(&]N(&$@<F5L871I;VXN"BTM"BTM
M(%5S86=E.B`@("`@(&-H96-K7W!E<FUI<W-I;VXH<F5L;F%M92QU<V5R;F%M
M92QP97)M<RD*+2T@("`@("`@(`HM+2`@("`@("`@("`@("!P97)M<R!I<R!A
M('-T<FEN9R!C;VYS:7-T:6YG(&]F(&%N>2!C;VUB:6YA=&EO;B!O9B!T:&4*
M+2T@("`@("`@("`@("`@8VAA<F%C=&5R<R!A+'(L=R!A;F0@4B`H4B!M96%N
M<R!254Q%('!E<FUI<W-I;VXI+@HM+0HM+2!2971U<FYS.B`@("!T<G5E(&EF
M('5S97(@:&%S($%,3"!P97)M:7-S:6]N<PHM+2`@("`@("`@("`@("!F86QS
M92!I9B!A="!L96%S="!O;F4@<&5R;6ES<VEO;B!I<R!M:7-S:6YG"BTM"BTM
M($5X8V5P=&EO;G,Z(&=E;F5R871E<R!A;B!E<G)O<B!I9B!T:&4@<F5L871I
M;VX@;W(@:70G<R!O=VYE<@HM+2`@("`@("`@("`@("!A<F5N)W0@9F]U;F0@
M:6X@=&AE('-Y<W1E;2!C871A;&]G<PHM+0I#4D5!5$4@1E5.0U1)3TX@8VAE
M8VM?<&5R;6ES<VEO;B`H;F%M92P@;F%M92P@=&5X="D@4D5455).4R!B;V]L
M($%3("<*"2,*"2,@3VX@9FER<W0@8V%L;"!C<F5A=&4@82!P<F5P87)E9"!P
M;&%N(&9O<B!T:&4@;&]O:W5P"@DC"@EI9B![(5MI;F9O(&5X:7-T<R!'1%U]
M('L*"0ES970@1T0H<&QA;BD@6W-P:5]P<F5P87)E"0D)"0D)"5Q<"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ile+install PL/Tcl in your database and use the > > function I've included at the end. It's usage is: > > But forgot to include it :-) > > > Jan > thanks - I'll try it. You mention about checking also group permissions - here question, cause I need it also. When postgres checks permissions of any user, I mean, it checks for example firstly if this user has permissions to table and after searches for groups in which this user is listed and checks permissions of this groups - are there any functions to do this? Sorry for querying You about simple things, but I really know very little about programmingRem -------------------------------------------------------------------*------------ Remigiusz Sokolowski e-mail: rems@gdansk.sprint.pl * * -----------------------------------------------------------------*****----------
> > You can compile+install PL/Tcl in your database and use the > function I've included at the end. It's usage is: > Could You point me where to find sources of PL/Tcl? I search for it, but without result (I need it for 6.3.2 ver) I don't look at distribution - is there those ?TIARem -------------------------------------------------------------------*------------ Remigiusz Sokolowski e-mail: rems@gdansk.sprint.pl * * -----------------------------------------------------------------*****----------