escaped rolenames in pg_has_role

Поиск
Список
Период
Сортировка
От Willy-Bas Loos
Тема escaped rolenames in pg_has_role
Дата
Msg-id 1dd6057e0706260744t59d3741eje082d07fcd7f38a8@mail.gmail.com
обсуждение исходный текст
Ответы Re: escaped rolenames in pg_has_role  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Dear General,

I have stolen some code from information_schema.applicable_roles, so that i can query the roles for a user, without having to become that user (a superuser executes this).
The problem is that pg_has_role does not recognize the usernames when they are escaped by quote_literal or quote_ident.
I allow a period "." as a character in usernames in the front-end, so escaping is necessary in most cases. Also, it´s a principle that all user-typed text is escaped to prevent SQL inserts, even through user names.

I think that the authorization of PostgreSQL has been designed with great care, so i´m not sure if this might be called a "bug".
But it seems that i can´t use this function.
Does anyone have the surrogate SQL statement lying around? (from before pg_has_role was born)

here´s my code:
-------------------------------------
CREATE OR REPLACE FUNCTION contacts.user_roles(p_role name)
RETURNS SETOF text
AS
$body$
DECLARE
--non-existant roles will result in an error.
arecord record;
t_role name;
BEGIN
t_role := quote_ident(trim(both '\'' from trim(both '\"' from p_role)));--'"--quotes might allready have been added by a calling function
--RAISE NOTICE 'getting roles for role: %', t_role;
  FOR arecord IN
    (SELECT b.rolname::information_schema.sql_identifier AS role_name
    FROM pg_auth_members m
    JOIN pg_authid a ON m.member = a.oid
    JOIN pg_authid b ON m.roleid = b.oid
    WHERE pg_has_role(t_role, a.oid, 'MEMBER'::text))
  LOOP
    RETURN NEXT arecord.role_name;
  END LOOP;
END
$body$
LANGUAGE plpgsql STRICT STABLE;
-------------------------------------

WBL


В списке pgsql-general по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: LC_CTYPE and matching accented chars
Следующее
От: Tom Lane
Дата:
Сообщение: Re: escaped rolenames in pg_has_role