1 GRANT Creates or adds privileges to an entry to the Oracle Rdb access privilege set, called the access control list (ACL), for a database, table, view, column, module, or external routine. Each entry in an ACL consists of an identifier and a list of privileges assigned to the identifier: o Each identifier specifies a user or a set of users. o The list of privileges specifies which operations that user or user group can perform on the database, table, view, column, module, or external routine. When a user tries to perform an operation on a database, SQL reads the associated ACL from top to bottom, comparing the identifier of the user with each entry. As soon as SQL finds the first match, it grants the rights listed in that entry and stops the search. All identifiers that do not match a previous entry "fall through" to the entry [*,*] (equivalent to the SQL keyword PUBLIC). If no entry has the identifier [*,*], then users with unmatched identifiers are denied all access to the database, table, view, column, module, or external routine. For this reason, both the entries and their order in the list are important. Under the Oracle Rdb default protection scheme, when you create a new database, table, view, module, or external routine, you get all access rights to that object, including DBCTRL. All other users of that object are given no access rights to it. For any tables or views created under the Oracle Rdb default protection scheme, the creator of the table or view receives all the access rights to the object, including DBCTRL, and all other users receive no access rights to the object. The DBCTRL access right enables an object's creator to grant DBCTRL to other users. See the Oracle Rdb SQL Reference Manual for information on how you can tailor the default protection for any new tables that you create within a database. To remove privileges from or entirely delete an entry to the Oracle Rdb access privilege set for a database, table, column, module, or external routine, see the REVOKE. 2 Environment You can use the GRANT statement: o In interactive SQL o Embedded in host language programs to be precompiled o As part of a nonstored procedure in a nonstored SQL module o In dynamic SQL as a statement to be dynamically executed 2 Format (B)0GRANT qqqqqqqqqqqqqqqqqqqqqqqqqk    lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj    mwq> db-privs q> ON DATABASE ALIAS qwqwqq> <alias> wqwqqqqqqqqqqqwk   x x mqqqqq , * qqqqqqj   xx  tq> table-privs q> ON qwqqqqqqqqqqwwww> <table-name> qwwwqqqqqqqux   x mq> TABLE qjxxm> <view-name> qqjxx  xx   x xmqqqqqqqq , * qqqqqqqqj   xx  tq> column-privs qqqq> ON COLUMN qqqwq> <column-name> qqwqqqqqqqux   x mqqqqqqq , module-privs qqqq> ON MODULE qqwwq> <module-name> qqwwqqqqqqux   x xmqqqqqqq , * qqqqqqqqqqj xx  tq> ext-routine-privs w> ON FUNCTION qwwwq> <ext-routine-name> wux   x m> ON PROCEDURE jxmqqqqqqqqqqq , * qqqqqqqqqjx  mq> sequence-privs qq> ON SEQUENCE qww> <sequence-name> qwwqqqqqqu   xmqqqqqqqqqqqq , * qqqqqj x lqqqqqqqqqqqqqqqqqqqqqqqqqqq grant-to qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq>  (B)0grant-to =     qq> TO wwq> identifier qqwqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwqqq>   xmq> PUBLIC qqqqqqj tq> AFTER qwq> identifier qqqwqu x   x x mq> PUBLIC qqqqqqqj x x   x mq> POSITION <n> qqqqqqqqqqqqqqj x   mqqqqqqqqqqqqqqqqqqqq , SELECT qqqqqwqwqqqqwq>  x x tq> INSERT qqqqqu x x   x x tq> OPERATOR qqqu x x   x x tq> DELETE qqqqqu x x   x x tq> CREATE qqqqqu x x   x x tq> ALTER qqqqqqu x x   x x tq> DROP qqqqqqqu x x   x x tq> DBCTRL qqqqqu x x   x x tq> DBADM qqqqqqu x x   x x tq> SHOW qqqqqqqu x x   x x tq> REFERENCES qu x x   x x tq> UPDATE qqqqqu x x   x x tq> SECURITY qqqu x x   x x mq> DISTRIBTRAN j x x   x mqqqqqqq , ALL PRIVILEGES qqqqj  (B)0table-privs=    qwqqwqwq> SELECT qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwqwq>  x x tq> INSERT qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> OPERATOR qqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> DELETE qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> CREATE qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> ALTER qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> DROP qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> DBCTRL qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> SHOW qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> REFERENCES wqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x x m> ( w> <column-name> w> ) u x x   x x x mqqqqq , UPDATE wqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x m> ( w> <column-name> qwqqq> ) j x x   x x mqqqqq , ALL PRIVILEGES qqqqqqqqqqqqqqqqqqqqqqqqqqqj  (B)0column-privs=    qqqwqwqwq> UPDATE qqqqqwqwqqwqq>  x x mq> REFERENCES qj x x   x mqqqqqqq , ALL PRIVILEGES qqj  (B)0module-privs =    qwqqwqwq> ALTER qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwqqwqq>  x x tq> DBCTRL qqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> DROP qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> EXECUTE qqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x  x x tq> REFERENCES qqqqqqqqqqqqqqqqqqqqqqqqqu x x    x x mq> SHOW qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x x   x mqqqqqqqqqqqqqqqqqqq , ALL PRIVILEGES qqqqqqqqqqqqqqqqqqqqqqqqqqj  (B)0ext-routine-privs =    qwqqwqwq> ALTER qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwqqwqq>  x x tq> DBCTRL qqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> DROP qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x   x x tq> EXECUTE qqqqqqqqqqqqqqqqqqqqqqqqqqqqu x x  x x tq> REFERENCES qqqqqqqqqqqqqqqqqqqqqqqqqu x x    x x mq> SHOW qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x x   x mqqqqqqqqqqqqqqqqqqq , ALL PRIVILEGES qqqqqqqqqqqqqqqqqqqqqqqqqqj  (B)0sequence-privs =  qwqq> ALL qqwqqqqqqqqqqqqqqqqqwqqqwqq>   x mqq> PRIVILEGES qqj x   mwwq> ALTER qqwqwqqqqqqqqqqqqqqqqj   xtq> DROP qqu x   xmq> SELECT qv x   mqqqqq , user-identifier qqqqwqwq>   x tq> general-identifier qu x   x tq> system-identifier qu x   x mq> role-name qqqqqqqqqqj x   mqqqqqqqqqqqq + GRANT SELECT, INSERT ON EMPLOYEES TO PUBLIC; %RDB-E-NO_PRIV, privilege denied by database facility 3 role-name The name of a role, such as one created with the CREATE ROLE statement or one that can be created automatically. (If the role name exists as an operating system group or rights identifier, then Oracle Rdb will create the role automatically when you issue the GRANT statement. A role that is created automatically always has the attribute of IDENTIFIED EXTERNALLY.) 3 TO Syntax options: TO identifier | TO PUBLIC Specifies the identifiers for the new or modified ACL entry. Specifying PUBLIC is equivalent to a wildcard specification of all user identifiers. You can specify four types of identifiers: o User identifiers o General identifiers o System-defined identifiers o Role names You can specify more than one identifier by combining them with plus signs (+). Such identifiers are called multiple identifiers. They identify only those users who are common to all the groups defined by the individual identifiers. Users who do not match all the identifiers are not controlled by that entry. For instance, the multiple identifier SECRETARIES + INTERACTIVE specifies only members of the group defined by the general identifier SECRETARIES that are interactive processes. It does not identify members of the SECRETARIES group that are not interactive processes. The following arguments briefly describe the three types of identifiers. For more information about identifiers, see your operating system documentation. 3 system-identifier System-defined identifiers are automatically defined by the system when the rights database is created at system installation time. System-defined identifiers are assigned depending on the type of login you execute. The following are all valid system- defined identifiers: BATCH NETWORK INTERACTIVE LOCAL DIALUP REMOTE 3 user-identifier Identifies each user on the system. The user identifier consists of the standard OpenVMS user identification code (UIC), a group name and a member name (user name). The group name is optional. The user identifier can be in either numeric or alphanumeric format. The following are all valid user identifiers that could identify the same user: K_JONES [SYSTEM3, K_JONES] [341,311] You can use the asterisk (*) wildcard character as part of a user identifier. For example, if you want to specify all users in a group, you can enter [system3, *] as the identifier. When Oracle Rdb creates a database, it automatically creates an ACL entry with the identifier [*,*] (also known as PUBLIC), which specifies the privileges given to all users on the system. You cannot use more than one user identifier in a multiple identifier. 2 Examples Example 1: Redeclaring a database to make ACL changes take effect This example illustrates that GRANT and REVOKE statements do not take effect until you attach to the database again. SQL> -- Display the ACL for the EMPLOYEES table: SQL> SHOW PROTECTION ON TABLE EMPLOYEES; Protection on Table EMPLOYEES (IDENTIFIER=[sql,warring],ACCESS=SELECT+INSERT+UPDATE+DELETE+SHOW+CREATE+ ALTER+DROP+DBCTRL+DBADM+REFERENCES) (IDENTIFIER=[*,*],ACCESS=SELECT+INSERT+UPDATE+DELETE+ALTER+DROP) SQL> SQL> -- User warring, the owner of the database, denies SQL> -- herself INSERT access to the EMPLOYEES table: SQL> REVOKE INSERT ON TABLE EMPLOYEES FROM warring; SQL> COMMIT; SQL> SQL> -- The SHOW PROTECTION statement displays the change SQL> -- (INSERT is no longer part of the ACL entry SQL> -- for warring): SQL> SHOW PROTECTION ON TABLE EMPLOYEES; Protection on Table EMPLOYEES (IDENTIFIER=[sql,warring],ACCESS=SELECT+UPDATE+DELETE+SHOW+CREATE+ALTER+ DROP+DBCTRL+DBADM+REFERENCES) (IDENTIFIER=[*,*],ACCESS=SELECT+INSERT+UPDATE+DELETE+ALTER+DROP) SQL> SQL> -- But the change is not yet effective. SQL> -- User warring can still store rows in the EMPLOYEES table: SQL> INSERT INTO EMPLOYEES (EMPLOYEE_ID) VALUES ('99999'); 1 row inserted SQL> SELECT EMPLOYEE_ID cont> FROM EMPLOYEES cont> WHERE EMPLOYEE_ID = '99999'; EMPLOYEE_ID 99999 1 row selected SQL> ROLLBACK; SQL> SQL> -- To make the ACL change take effect, issue another ATTACH statement SQL> -- to override the current declaration: SQL> ATTACH 'FILENAME personnel'; This database context has already been declared. Would you like to override this declaration (No)? Y SQL> SQL> -- Now warring cannot insert new rows into the EMPLOYEES table: SQL> INSERT INTO EMPLOYEES (EMPLOYEE_ID) VALUES ("99999"); %RDB-E-NO_PRIV, privilege denied by database facility SQL> SQL> -- A GRANT statement gives all privileges back to warring: SQL> GRANT ALL ON TABLE EMPLOYEES TO warring; SQL> COMMIT; Example 2: Creating an ACL with an SQL command file The following SQL command file creates an ACL for the default database by specifying the default alias RDB$DBHANDLE. It uses two general guidelines for ordering ACL entries: o The less restrictive the user identifier, the lower on the list that ACL should go. o The more powerful the privilege, the higher on the list that ACL should go. Because SQL reads the list from top to bottom, you should place entries with more specific identifiers earlier, and those with more general ones later. For example, if you place the entry with the most general user identifier, [*,*], first in the list, all users match it, and Oracle Rdb grants or denies all the access rights specified there to all users. Similarly, if you place the general entry [admin,*] before the specific entry [admin,ford], SQL matches user [admin,ford] with [admin,*] and denies the access rights INSERT, UPDATE, and DELETE, which user [admin,ford] needs. -- Database Administrator -- needs all privileges. -- GRANT ALL ON DATABASE ALIAS RDB$DBHANDLE TO [group2,adams] POSITION 1; -- Assistant -- needs to be able to use data definition statements. -- GRANT SELECT,CREATE,ALTER,DROP ON DATABASE ALIAS RDB$DBHANDLE TO [group2,clark] POSITION 2; -- Operator -- needs to be able to perform database maintenance tasks. -- GRANT SELECT, ALTER, DBADM ON DATABASE ALIAS RDB$DBHANDLE TO [group2,lawrence] POSITION 3; -- Security Administrator -- needs to specify and show security events -- audited for a database and review the audit trail. -- GRANT SECURITY ON DATABASE ALIAS RDB$DBHANDLE TO [group2,davis] POSITION 4; -- Manager -- needs to be able to use all data manipulation statements. -- GRANT SELECT,INSERT,UPDATE,DELETE ON DATABASE ALIAS RDB$DBHANDLE TO [admin,smith] POSITION 5; -- Secretary -- needs to be able to read, write, and delete data. -- No access to data definition or maintenance. -- GRANT SELECT,INSERT,UPDATE,DELETE ON DATABASE ALIAS RDB$DBHANDLE TO [admin,ford] POSITION 6; -- Programmers -- need to perform data definition and data manipulation -- on some tables and constraints to test application programs. -- GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,DROP,REFERENCES ON DATABASE ALIAS RDB$DBHANDLE TO PROGRAMMERS POSITION 7; -- Clerks -- need to be able only to read data. No access to modify, erase, -- store, data definition, or maintenance statements. -- GRANT SELECT ON DATABASE ALIAS RDB$DBHANDLE TO [admin,*] POSITION 8; -- Deny access to all users not explicitly granted access to the database. -- REVOKE ALL ON DATABASE ALIAS RDB$DBHANDLE FROM PUBLIC POSITION 9; Example 3: Granting column access and denying table access You need the REFERENCES privilege to define constraints that affect a particular column. You need the UPDATE privilege to update data in a column. A user with the UPDATE privilege for a table automatically receives the UPDATE privilege for all columns in that table. To update a column, you must have the UPDATE privilege either for the column or for the table. However, a database administrator can restrict UPDATE privileges by defining them only for columns users should be able to update, and then removing the UPDATE privilege from the table entry. Because current salary is sensitive information, you might want to restrict the ability to update this amount. The following example prevents user [admin,ford] from updating any column in the SALARY_HISTORY table except SALARY_START and SALARY_END. For instance, user [admin,ford] cannot update the SALARY_AMOUNT column. SQL> GRANT UPDATE ON COLUMN SALARY_HISTORY.SALARY_START cont> TO [admin,ford]; SQL> GRANT UPDATE ON COLUMN SALARY_HISTORY.SALARY_END cont> TO [admin,ford]; SQL> -- SQL> REVOKE UPDATE ON TABLE SALARY_HISTORY FROM [admin,ford]; SQL> -- SQL> COMMIT; SQL> -- SQL> SHOW PROTECTION ON TABLE SALARY_HISTORY; Protection on Table SALARY_HISTORY (IDENTIFIER=[grp2,jones],ACCESS=SELECT+INSERT+UPDATE+DELETE+SHOW+CREATE+ ALTER+DROP+DBCTRL+DBADM+REFERENCES+SECURITY+DISTRIBTRAN) (IDENTIFIER=[*,*],ACCESS=NONE) SQL> -- SQL> SHOW PROTECTION ON COLUMN SALARY_HISTORY.SALARY_START; Protection on Column SALARY_HISTORY.SALARY_START (IDENTIFIER=[admin,ford],ACCESS=UPDATE) (IDENTIFIER=[*,*],ACCESS=NONE) Example 4: Granting SELECT Privilege to All Users for a Sequence SQL> SHOW PROTECTION ON SEQUENCE EMPID Protection on Sequence EMPID (IDENTIFIER=[RDB,STRAUTS],ACCESS=SELECT+SHOW+ALTER+DROP+DBCTRL) (IDENTIFIER=[*,*],ACCESS=NONE) SQL> GRANT SELECT ON SEQUENCE EMPID TO PUBLIC; SQL> SHOW PROTECTION ON SEQUENCE EMPID; Protection on Sequence EMPID (IDENTIFIER=[RDB,STRAUTS],ACCESS=SELECT+SHOW+ALTER+DROP+DBCTRL) (IDENTIFIER=[*,*],ACCESS=SELECT) Example 5: Granting INSERT ON TABLE Privilege to a Role SQL> SHOW PROTECTION ON TABLE JOBS Protection on Table JOBS (IDENTIFIER=[250,254],ACCESS=SELECT+INSERT+UPDATE+DELETE+SHOW+CREATE+ALTER+ DROP+DBCTRL+DBADM+REFERENCES) (IDENTIFIER=PUBLIC,ACCESS=SELECT+INSERT+UPDATE+DELETE+SHOW+CREATE+ALTER+DROP +DBADM+REFERENCES) SQL> CREATE ROLE ADMINISTRATOR; SQL> GRANT INSERT ON TABLE JOBS TO ADMINISTRATOR AFTER [250,254]; SQL> SHOW PROTECTION ON TABLE JOBS Protection on Table JOBS (IDENTIFIER=[250,254],ACCESS=SELECT+INSERT+UPDATE+DELETE+SHOW+CREATE+ALTER+ DROP+DBCTRL+DBADM+REFERENCES) (IDENTIFIER=ADMINISTRATOR,ACCESS=INSERT) (IDENTIFIER=PUBLIC,ACCESS=SELECT+INSERT+UPDATE+DELETE+SHOW+CREATE+ALTER+DROP +DBADM+REFERENCES) Example 6: Allowing All Access to a User SQL> -- Allow all access to user JAIN SQL> GRANT SELECT ON DATABASE ALIAS * to jain; SQL> GRANT SELECT ON TABLE * to jain; SQL> GRANT EXECUTE ON MODULE * to jain; SQL> GRANT EXECUTE ON PROCEDURE * to jain; SQL> GRANT EXECUTE ON FUNCTION * to jain; Example 7: Automatically Creating a User While Granting Privileges SQL> ATTACH 'FILENAME MF_PERSONNEL.RDB'; SQL> SHOW USERS Users in database with filename mf_personnel.rdb tsmith jstuart SQL> GRANT ALL ON DATABASE ALIAS RDB$DBHANDLE TO CDAY; %RDB-W-META_WARN, metadata successfully updated with the reported warning -RDMS-W-PRFCREATED, some users or roles were created SQL> SHOW USERS Users in database with filename mf_personnel.rdb tsmith jstuart cday