/*******************************************************************************
**
** Source File Name = dbinst.c 1.5
**
** Licensed Materials - Property of IBM
**
** (C) COPYRIGHT International Business Machines Corp. 1995, 1999
** All Rights Reserved.
**
** US Government Users Restricted Rights - Use, duplication or
** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
**
**
** PURPOSE :
** an example showing how to use DATABASE INSTANCE APIs in order to:
** - Attach to an instance
** - Retrieve the instance
** - Change the password
** - Reset the password
** - Detach from the instance.
**
** APIs USED :
** ATTACH TO INSTANCE sqleatin
** GET INSTANCE sqlegins
** ATTACH AND CHANGE PASSWORD sqleatcp
** DETACH FROM INSTANCE sqledtin
**
** STRUCTURES USED :
** sqlca
**
** OTHER FUNCTIONS DECLARED :
** 'C' COMPILER LIBRARY :
** stdio.h - printf
**
** external :
** check_error : Checks for SQLCODE error, and prints out any
** [in util.c] related information available.
** This procedure is located in the util.c file.
**
** EXTERNAL DEPENDENCIES :
** - 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 <string.h>
#include <stdio.h>
#include <sqlenv.h>
#include "util.h"
#ifdef DB268K
/* Need to include ASLM for 68K applications */
#include <LibraryManager.h>
#endif
#define CHECKERR(CE_STR) if (check_error (CE_STR, &sqlca) != 0) return 1;
int main (int argc, char *argv[]) {
struct sqlca sqlca;
char input[]="";
char instName[SQL_INSTNAME_SZ + 1];
char newPassword[]="NewPassword";
#ifdef DB268K
/* Before making any API calls for 68K environment,
need to initial the Library Manager */
InitLibraryManager(0,kCurrentZone,kNormalMemory);
atexit(CleanupLibraryManager);
#endif
/*********************************************
the first argument is the instance name
the second argument is the user name
the third argument is the password
*********************************************/
if (argc != 4) {
printf ("\n\nUSAGE: dbinst instance_name user_name password\n\n");
return 1;
}
printf ("sample program : dbinst.c\n");
printf ("\nATTACH TO INSTANCE API called\n");
printf ("for instance :%s\n", argv[1]);
/*******************************\
* ATTACH TO INSTANCE API called *
\*******************************/
sqleatin (argv[1], argv[2], argv[3], &sqlca);
CHECKERR ("attach to instance");
printf ("\nGET INSTANCE API called\n");
/*************************\
* GET INSTANCE API called *
\*************************/
sqlegins (instName, &sqlca);
CHECKERR ("get instance name");
printf ("current instance = %s\n", instName);
printf ("\n\tATTACH AND CHANGE PASSWORD API\n");
printf ("\nWarning: This API will attempt to change the instance password,\n");
printf ("and then change back to the original password. Some systems\n");
printf ("do not allow a change back to a recent old password and/or require\n");
printf ("certain restrictions on password format that may not be reflected\n");
printf ("in the new password provided. You can alter the source code to\n");
printf ("comply with these restrictions, if they apply to your system.\n");
printf ("\nWould you like to run this API?\ty/n\n");
fflush(stdin);
scanf("%s", &input);
if (strncmp(input,"y",1))
return 0;
else
{
printf ("\nATTACH AND CHANGE PASSWORD API called\n");
printf ("the old password is :%s\n", argv[3]);
printf ("the new password is :%s\n", newPassword);
/***************************************\
* ATTACH AND CHANGE PASSWORD API called *
\***************************************/
sqleatcp (argv[1], argv[2], argv[3], newPassword, &sqlca);
CHECKERR ("change password");
printf ("\nATTACH AND CHANGE PASSWORD API called\n");
printf ("the password is reset to :%s\n", argv[3]);
/***************************************\
* ATTACH AND CHANGE PASSWORD API called *
\***************************************/
sqleatcp (argv[1], argv[2], newPassword, argv[3], &sqlca);
CHECKERR ("reset password");
printf ("\nDETACH FROM INSTANCE API called\n", instName);
/*********************************\
* DETACH FROM INSTANCE API called *
\*********************************/
sqledtin (&sqlca);
CHECKERR ("detach from instance");
return 0;
}
}
/* end of program : dbinst.c */