Statements for managing privilege-based users and privileges

xfODBC supports the following SQL statements, which manage privilege-based users and the privileges associated with them. For more information, see Managing privilege-based users and privileges.

Note

GRANT, REVOKE, and SET PASSWORD are available only if the system catalog supports privilege-based users — i.e., only if the system catalog was generated using dbcreate with the -c and -a options and has the GENESIS_AUTHS and GENESIS_USERS tables and files. See Managing access with users, groups, and table settings for more information on privilege-based users.

For links to more information on xfODBC’s support for SQL, see Appendix B: SQL Support.

GRANT (database privileges)

The following form of the GRANT statement enables DBA users (users with the DBA database privilege) to add privilege-based users and to grant database privileges to privilege-based users.

GRANT privilege[,...] TO user [IDENTIFIED BY password]

where

privilege is a database privilege (CONNECT, RESOURCE, or DBA).

user is the user that the privileges will be granted to. A new privilege-based user is added if the “IDENTIFIED BY password” clause is used (and user does not already exist). The “IDENTIFIED BY password” clause is required to create a new user.

password is the password for a new user.

A GRANT statement can grant one or more of the following database privileges:

User name (user) is not case sensitive when logging in or when used in a GRANT, REVOKE, or SET PASSWORD statement. If user is not in quotation marks when a user is created, the user name will be saved to the system catalog in all uppercase characters (but it can still be used in any combination of uppercase and lowercase characters to log in or with GRANT, REVOKE, or SET PASSWORD).

Password is case sensitive. If password is enclosed in quotation marks, case is preserved. If a password is not enclosed in quotation marks, it will be stored in all uppercase characters. Passwords enclosed in quotation marks can contain some special characters (e.g., “N#e-Wpas%”). For more information on passwords, see SET PASSWORD below.

Important

Do not use colons (:) in passwords. If a password contains a colon, the user will not be able to log in until the password is changed to a valid password (with SET PASSWORD).

The following example adds a user (user3), assigns it a password (some_password), and assigns it the CONNECT and RESOURCE database privileges. Because “some_password” is quoted, case will be preserved.

GRANT CONNECT,RESOURCE TO user3 IDENTIFIED BY "some_password"

The next example grants the DBA database privilege to the user (user3) created with the previous example GRANT statement:

GRANT DBA TO user3

GRANT (object privileges)

The following form of the GRANT statement enables a DBA user (user with the DBA database privilege) to grant object privileges to one or more privilege-based users.

GRANT privilege[,...]|ALL PRIVILEGES ON object TO user[,...]|PUBLIC

where

privilege is the type of object privilege to grant (the SQL statement that user can use with the specified table or view): SELECT, INSERT, UPDATE, or DELETE. To grant all privileges, specify ALL PRIVILEGES.

object is the name of the object (table or view) that granted privileges apply to. If you do not own the object, you must include the owner’s name: owner_name.object.

user is the user that the privileges will be assigned to. PUBLIC denotes all users, present and future.

Privileges can cascade up — i.e., if you grant privileges for an object, those privileges may be granted automatically for other objects, as follows:

See CREATE VIEW for more information on views.

For each privilege that is granted, an entry is made in the GENESIS_AUTHS table in the system catalog. The entry includes the following information:

The following example assigns all object privileges for a table (mytable) to a user (user3):

GRANT ALL PRIVILEGES ON mytable TO user3 

The next example grants the SELECT object privilege for a table (sometable, which is owned by user3) to all users:

GRANT SELECT ON user3.sometable TO PUBLIC

REVOKE (database privileges)

The following form of the REVOKE statement enables a DBA user (a user with the DBA database privilege) to rescind database privileges that have been granted to a privilege-based user.

REVOKE privilege[,...] FROM user

where

privilege is CONNECT, RESOURCE, or DBA.

user is the user-based user that will lose the specified database privileges.

See GRANT (database privileges) for more information on these privileges, and note the following:

Important

Be careful removing the DBA privilege. If there are no DBAs, the GRANT and REVOKE statements can no longer be used (so users can no longer be managed).

We recommend against changing the permissions for the initial users (DBA and DBADMIN).

The following statement removes the DBA privilege from a user (user2), which may leave the user with no privileges at all.

REVOKE DBA FROM user2

REVOKE (object privileges)

The following form of the REVOKE statement enables a DBA user (a user with the DBA database privilege) to rescind object privileges granted to one or more privilege-based users. See GRANT (object privileges) for more information on these privileges.

REVOKE privilege[,...] ON object_name FROM PUBLIC|user[,...]

where

privilege is SELECT, INSERT, UPDATE, DELETE, or ALL PRIVILEGES (see the discussion below).

object is the name of the object (table or view) that the privileges apply to.

user is the user that the specified database privileges will be taken from. PUBLIC specifies all users, present and future.

Note that when a privilege is revoked, dependent privileges may also be revoked.

SET PASSWORD

The SET PASSWORD statement enables a privilege-based user to change his or her password and enables a DBA user (a user with the DBA database privilege) to change another user’s password.

SET PASSWORD new_password old_password

or

SET PASSWORD new_password FOR user

where

new_password is the new password for the user.

old_password is the current password for the logged-in user.

user is a privilege-based user.

Passwords for privilege-based users can have a maximum of 30 characters. If they are unquoted, they will be stored as all uppercase characters, and they must follow the rules for identifiers (see Conventions, names, and identifier case). If they are quoted, they can contain special characters, except the colon (:) and the at sign (@), though they must still start with a letter. Note the following:

For example, the following changes the password for the currently logged-in user. The new password (mynewpassword) will be saved in all uppercase characters (MYNEWPASSWORD) because it is unquoted.

SET PASSWORD mynewpassword MYOLDPASSWORD

The next example changes the password for user2 to NewPasswordForUser. Because the password is quoted, it will retain its mixed case. For this statement, the logged-in user would need to have the DBA database privilege.

SET PASSWORD "NewPasswordForUser2" FOR user2