pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Users and groups
5+ messages / 4 participants
[nested] [flat]

* Users and groups
@ 2003-02-14 03:51  Raj Mathur <raju@linux-delhi.org>
  0 siblings, 1 reply; 5+ messages in thread

From: Raj Mathur @ 2003-02-14 03:51 UTC (permalink / raw)
  To: pgsql-admin

Hi,

Using PostgreSQL 7.2.3 on a Linux box and facing some minor issues
with determining which groups users belong to.

I have created a PgSQL group called `administrators'.  Now when I need
to check whether user X is a member of that group, I use the
contrib/array_iterator operator to do something like,

select groname from pg_group where grolist **=
       ( select usesysid from pg_user where usename = 'X' ) ;

This works just fine.  However, the complementary process, determining
all the users in group administrators, isn't so clean.  Currently I'm
brute-forcing it, getting each user in turn and then checking whether
she belongs to group administrators using the construct above.

Is there a simpler way?

Also, are there any caveats attached to using the pg_ system tables
directly?  I prefer to do that to prevent duplication of user status:
let PgSQL store whether the user is an administrator or not rather
than have another table keeping that information.  However, I'd change
that if the structure of the pg_ tables is subject to change from time
to time.

Regards,

-- Raju
-- 
Raj Mathur                raju@kandalaya.org      http://kandalaya.org/
                      It is the mind that moves



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Users and groups
@ 2003-02-14 04:16  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Raj Mathur <raju@linux-delhi.org>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2003-02-14 04:16 UTC (permalink / raw)
  To: Raj Mathur <raju@linux-delhi.org>; +Cc: pgsql-admin

Raj Mathur <raju@linux-delhi.org> writes:
> ...  However, the complementary process, determining
> all the users in group administrators, isn't so clean.

Doesn't
	select grolist from pg_group where groname = 'administrators'
do it for you?  I suppose you might want the thing to map sysids
back to usernames ...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Users and groups
@ 2003-02-14 13:58  Raj Mathur <raju@linux-delhi.org>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Raj Mathur @ 2003-02-14 13:58 UTC (permalink / raw)
  To: pgsql-admin

>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:

    Tom> Raj Mathur <raju@linux-delhi.org> writes:
    >> ...  However, the complementary process, determining all the
    >> users in group administrators, isn't so clean.

    Tom> Doesn't select grolist from pg_group where groname =
    Tom> 'administrators' do it for you?  I suppose you might want the
    Tom> thing to map sysids back to usernames ...

Ah, maybe I should have been more explicit: need a list of usename's
of users who are admins.  Any simple command (set) to do that?

Regards,

-- Raju
-- 
Raj Mathur                raju@kandalaya.org      http://kandalaya.org/
                      It is the mind that moves



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Users and groups
@ 2003-02-21 22:37  Teddy <epalo@ono.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Teddy @ 2003-02-21 22:37 UTC (permalink / raw)
  To: pgsql-admin; pgsql-general@postgresql.org; pgsql-sql@postgresql.org

How can i list the users of a group?

Thanks.





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Users and groups
@ 2003-03-01 13:02  Oliver Elphick <olly@lfix.co.uk>
  parent: Teddy <epalo@ono.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Oliver Elphick @ 2003-03-01 13:02 UTC (permalink / raw)
  To: Teddy <epalo@ono.com>; +Cc: pgsql-admin; pgsql-general@postgresql.org; pgsql-sql@postgresql.org

On Fri, 2003-02-21 at 22:37, Teddy wrote:
> How can i list the users of a group?

Someone posted this function a while back.  (It's a multi-row function,
so it needs 7.3):


CREATE OR REPLACE TYPE group_view AS (grosysid int4, groname name, usesysid int4, usename name);
                                                                                                                              
CREATE OR REPLACE FUNCTION expand_groups() RETURNS SETOF group_view AS '
DECLARE
  rec record;
  groview record;
  low int;
  high int;
BEGIN
  FOR rec IN SELECT grosysid FROM pg_group LOOP
    SELECT INTO low
      replace(split_part(array_dims(grolist),'':'',1),''['','''')::int
      FROM pg_group WHERE grosysid = rec.grosysid;
    SELECT INTO high
      replace(split_part(array_dims(grolist),'':'',2),'']'','''')::int
      FROM pg_group WHERE grosysid = rec.grosysid;
                                                                                                                              
    FOR i IN low..high LOOP
      SELECT INTO groview g.grosysid, g.groname, s.usesysid, s.usename
        FROM pg_shadow s join pg_group g on s.usesysid = g.grolist[i]
        WHERE grosysid = rec.grosysid;
      RETURN NEXT groview;
    END LOOP;
  END LOOP;
  RETURN;
END;
' LANGUAGE 'plpgsql';
                                                                                                                              
CREATE OR REPLACE VIEW public.pg_groupview AS SELECT * FROM expand_groups();
                                                                                                                              


-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "The LORD is my shepherd; I shall not want. He maketh 
      me to lie down in green pastures: he leadeth me beside
      the still waters, he restoreth my soul...Surely
      goodness and mercy shall follow me all the days of my
      life; and I will dwell in the house of the LORD for
      ever."                    Psalms 23:1,2,6 




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2003-03-01 13:02 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-14 03:51 Users and groups Raj Mathur <raju@linux-delhi.org>
2003-02-14 04:16 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-14 13:58   ` Raj Mathur <raju@linux-delhi.org>
2003-02-21 22:37 Users and groups Teddy <epalo@ono.com>
2003-03-01 13:02 ` Oliver Elphick <olly@lfix.co.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox