Granting SELECT on all tables to a user in Firebird 2.1

折月煮酒 提交于 2019-12-14 03:08:42

问题


I've added a user to a Firebird 2.1 instance using gsec, but now I wanted to grant SELECT on all tables to this new user. I could find how to grant this permission on specific tables, but not to them all:

GRANT SELECT ON TABLE table TO USER user;

If I try to use the new user I get the following error on isql:

no permission for read/select access to TABLE table

Is there a way to do that on Firebird 2.1?


回答1:


Something like this:

EXECUTE BLOCK
AS
  DECLARE VARIABLE tablename VARCHAR(32);
BEGIN
  FOR SELECT rdb$relation_name
  FROM rdb$relations
  WHERE rdb$view_blr IS NULL
  AND (rdb$system_flag IS NULL OR rdb$system_flag = 0)
  INTO :tablename DO
  BEGIN
    EXECUTE STATEMENT ('GRANT SELECT ON TABLE ' || :tablename || ' TO USER TEST');
  END
END



回答2:


I could find how to grant this permission on specific tables, but not to them all

You can grant specific privileges to all users, already existing and yet to be created. That is made by granting privilege to "PUBLIC" pseudo-user. Or you could grant privileges to some ROLE, then grant this ROLE to given users, then during database connection specify the option, that the user impersonate this ROLE in this session.

However there is no syntax to grant privileges to all generators or all procedures or all views or all tables, etc.

See the GRANT statement syntax in documentation.

What you can do though, is creating a simple script (anonymous and volatile aka EXECUTE BLOCK or persistent and named as STORED PROCEDURE) and that script of yours would be querying system tables to list all non-system ( COALESCE(RDB$SYSTEM_FLAG,0)=0 ) tables (together with views, or tables but not views: check if RDB$RELATION_TYPE is 0 or is 0 or 1) and then form a sequence of GRANT statements and execute them one by one.

See documentation about EXECUTE BLOCK and FOR SELECT ... INTO ... DO ... and EXECUTE STATEMENT ( or maybe FOR EXECUTE STATEMENT also, but I do not think it already was there in FB 2.1. There is unofficial wiki tracking which statements were available since which FB versions, but it is not thorough and may contain errors: http://firebirdsql.su/doku.php ).

  • https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-security-privs.html#fblangref25-security-privs-grant
  • https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref-appx04-relations.html
  • https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-psql-coding.html#fblangref25-psql-execstmt
  • https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-dml-execblock.html


来源:https://stackoverflow.com/questions/45445511/granting-select-on-all-tables-to-a-user-in-firebird-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!