informix
Extending Informix Dynamic Server 2000
Managing a User-Defined Routine

Assigning Execute Privilege to a Routine

The Execute privilege enables users to invoke a user-defined routine. You might invoke the UDR from the EXECUTE or CALL statements or from a function in an expression. By default, the following users have Execute privilege, which enables them to invoke a UDR:

Granting and Revoking the Execute Privilege

To control Execute privilege on a user-defined routine, use the EXECUTE ON clause of the GRANT and REVOKE statements. The database server stores privileges for user-defined routines in the sysprocauth system catalog table.

User-defined routines have the following GRANT and REVOKE requirements for Execute privilege:

A DBA or the routine owner must explicitly grant the Execution privilege to non-DBA users for the following conditions:

An owner can restrict the Execute privilege on a routine even though the database server grants that privilege to public by default. To do so, issue the REVOKE EXECUTE ON...PUBLIC statement. The DBA and owner can still execute the routine and can grant the Execute privilege to specific users, if applicable.

A user might receive the Execute privilege accompanied by the WITH GRANT option authority to grant the Execute privilege to other users. If a user loses the Execute privilege on a routine, the Execute privilege is also revoked from all users to whom that user granted the Execute privilege.

The following example shows an equal() function defined for a user-defined data type and the GRANT statement to enable user mary to execute this variation of the equal() function:

User mary does not have permission to execute any other user-defined routine named equal().

For more information, see the GRANT and REVOKE statements in the Informix Guide to SQL: Syntax.

Privileges on Objects Associated with a UDR

The database server checks the existence of any referenced objects and verifies that the user who invokes the UDR has the necessary privileges to access the referenced objects. For example, if a user executes a UDR that updates data in a table, the user must have the Update privilege for the table or columns referenced in the UDR.

A routine can reference the following objects:

When the owner of a routine grants the Execute privilege, some privileges on objects automatically accompany the Execute privilege. A GRANT EXECUTE ON statement confers to the grantee any table-level privileges that the grantor received from a GRANT statement that contained the WITH GRANT keywords.

In the course of routine execution, the owner of the routine, not the user who runs the routine, owns any unqualified objects that the routine creates.

Figure 12-1 shows an SPL procedure called promo() that creates two tables, hotcatalog and libby.mailers.

Figure 12-1
Create Procedure Example


Suppose the user tony executes the CREATE PROCEDURE statement to register the SPL promo() procedure. The user marty executes the promo() routine with an EXECUTE PROCEDURE statement, which creates the table hotcatalog. Because no owner name qualifies table name hotcatalog, the routine owner (tony) owns hotcatalog. By contrast, the qualified name libby.maillist identifies libby as the owner of maillist.

Executing a UDR as DBA

If a DBA creates a routine using the DBA keyword, the database server automatically grants the Execute privileges only to other users with the DBA privilege. However, a DBA can explicitly grant the Execute privilege on a DBA routine to a non-DBA user.

When a user executes a routine that was registered with the DBA keyword, that user assumes the privileges of a DBA for the duration of the routine. If a user who does not have the DBA privilege runs a DBA routine, the database server implicitly grants a temporary DBA privilege to the invoker. Before the database server exits from a DBA routine, it implicitly revokes the temporary DBA privilege.

Using DBA Privileges with Objects and Nested UDRs

Objects created in the course of running a DBA routine are owned by the user who executes the routine unless a statement in the routine explicitly names someone else as the owner. For example, suppose that tony registers the promo() routine from on page 12-6 with the DBA keyword, as follows:

Although tony owns the routine, if marty runs it, marty owns table hotcatalog. User libby owns libby.maillist because her name qualifies the table name, making her the table owner.

A called routine does not inherit the DBA privilege. If a DBA routine executes a routine that was created without the DBA keyword, the DBA privileges do not affect the called routine.

If a routine that is registered without the DBA keyword calls a DBA routine, the caller must have Execute privileges on the called DBA routine. Statements within the DBA routine execute as they would within any DBA routine.

The following example demonstrates what occurs when a DBA and non-DBA routine interact. Procedure dbspace_cleanup() executes procedure cluster_catalog(). Procedure cluster_catalog() creates an index. The C-language source for cluster_catalog() includes the following statements:

DBA procedure dbspace_cleanup() invokes the other routine with the following statement:

Assume tony registered dbspace_cleanup() as a DBA procedure, and cluster_catalog() is registered without the DBA keyword, as follows:

User marty runs dbpace_cleanup(). Index c_clust_ix is created by a non-DBA routine. Therefore tony, who owns both routines, also owns c_clust_ix. By contrast, marty owns index c_clust_ix if cluster_catalog() is a DBA procedure, as in the follows registering and grant statements:

The dbspace_cleanup() procedure need not be a DBA procedure to call a DBA procedure.


Extending Informix Dynamic Server 2000, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved