/****************************************************************************** ** ** Source File Name = dbauth.sqc ** ** Licensed Materials - Property of IBM ** ** (C) COPYRIGHT International Business Machines Corp. 1995, 2000 ** All Rights Reserved. ** ** US Government Users Restricted Rights - Use, duplication or ** disclosure restricted by GSA ADP Schedule Contract with IBM Corp. ** ** ** PURPOSE : ** This program is an example of how APIs are implemented in order to ** obtain and print out authorization information of the current user ** to the currenlty attached database. ** This program needs the embedded SQL calls in order to connect to ** an existing database, then to create a temporary table to work with. ** ** STRUCTURES USED : ** sql_authorizations ** sqlca ** ** APIs USED : ** GET AUTHORIZATION sqluadau ** ** FUNCTIONS DECLARED : ** 'C' COMPILER LIBRARY : ** stdio.h - printf ** ** DBMS LIBRARY : ** sqlenv.h - see "APIs USED" above ** ** OTHER : ** internal : ** list_auth : Displays the authorization rights of the ** current user ** ** external : ** check_error : Checks for SQLCODE error, and prints out any ** [in UTIL.C] related information available. ** ** EXTERNAL DEPENDENCIES : ** - Ensure existence of database for precompile purposes. ** - Precompile with the SQL precompiler (PREP in DB2) ** - Bind to a database (BIND in DB2) ** - Compile and link with the IBM Cset++ compiler (AIX and OS/2) ** or the Microsoft Visual C++ compiler (Windows) ** or the compiler supported on your platform. ** ** For more information about these samples see the README file. ** ** For more information on programming in C, see the: ** - "Programming in C and C++" section of the Application Development Guide ** For more information on Building C Applications, see the: ** - "Building C Applications" section of the Application Building Guide. ** ** For more information on the SQL language see the SQL Reference. ** *******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sqlutil.h> #include "utilemb.h" EXEC SQL INCLUDE SQLCA; int list_auth (struct sql_authorizations); int main (int argc, char *argv[]) { int rc; struct sql_authorizations authorization_list; EXEC SQL BEGIN DECLARE SECTION; char userid[9]; char passwd[19]; EXEC SQL END DECLARE SECTION; authorization_list.sql_authorizations_len = SQL_AUTHORIZATION_SIZE; if (argc == 1) { EXEC SQL CONNECT TO sample; EMB_SQL_CHECK("CONNECT TO SAMPLE"); } else if (argc == 3) { strcpy (userid, argv[1]); strcpy (passwd, argv[2]); EXEC SQL CONNECT TO sample USER :userid USING :passwd; EMB_SQL_CHECK("CONNECT TO SAMPLE"); } else { printf ("\nUSAGE: dbauth [userid passwd]\n\n"); return 1; } /* endif */ authorization_list.sql_authorizations_len = SQL_AUTHORIZATION_SIZE; printf ("Administrative Authorizations for Current User\n\n"); /*******************************\ * GET AUTHORIZATIONS API called * \*******************************/ sqluadau (&authorization_list, &sqlca); EMB_SQL_CHECK("getting authorization list"); rc = list_auth (authorization_list); EXEC SQL CONNECT RESET; EMB_SQL_CHECK("CONNECT RESET"); return 0; } int list_auth (struct sql_authorizations authorization_list) { printf ("Direct SYSADM authority = "); if (authorization_list.sql_sysadm_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Direct SYSCTRL authority = "); if (authorization_list.sql_sysctrl_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Direct SYSMAINT authority = "); if (authorization_list.sql_sysmaint_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Direct DBADM authority = "); if (authorization_list.sql_dbadm_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Direct CREATETAB authority = "); if (authorization_list.sql_createtab_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Direct BINDADD authority = "); if (authorization_list.sql_bindadd_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Direct CONNECT authority = "); if (authorization_list.sql_connect_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Direct CREATE_NOT_FENC authority = "); if (authorization_list.sql_create_not_fenc_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Direct LOAD authority = "); if (authorization_list.sql_load_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("\nIndirect SYSADM authority = "); if (authorization_list.sql_sysadm_grp_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Indirect SYSCTRL authority = "); if (authorization_list.sql_sysctrl_grp_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Indirect SYSMAINT authority = "); if (authorization_list.sql_sysmaint_grp_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Indirect DBADM authority = "); if (authorization_list.sql_dbadm_grp_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Indirect CREATETAB authority = "); if (authorization_list.sql_createtab_grp_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Indirect BINDADD authority = "); if (authorization_list.sql_bindadd_grp_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Indirect CONNECT authority = "); if (authorization_list.sql_connect_grp_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Indirect CREATE_NOT_FENC authority = "); if (authorization_list.sql_create_not_fenc_grp_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } printf ("Indirect LOAD authority = "); if (authorization_list.sql_load_grp_auth == 1) { printf ("YES\n"); } else { printf ("NO\n"); } return 0; } /* end of program : dbauth.sqc */