The following is a sample program using the VAM API. This program may be found in the VAM directory as VAM_AUTHORIZE.C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ssdef.h>
#include <iodef.h>
#include <starlet.h>
#include <descrip.h>
#include <lib$routines.h>
#include <libclidef.h>
#include <signal.h>
#include "vmsauthenticate.h"
int term_channel;
int qio_efn;
struct
{
short iostat;
short term_offset;
short term;
short term_size;
} iosb;
int exit_val;
void exit_handler(int);
int (*VMSAUTHENTICATE)();
int load_vamshr_shareable(void);
main()
{
int status;
char username[50];
char identifier[50];
$DESCRIPTOR(namdesc, "TT:");
unsigned long ctrl_mask = LIB$M_CLI_CTRLT | LIB$M_CLI_CTRLY;
status = load_vamshr_shareable();
if (!(status & 1))
{
printf("\n\nCan't load VAMSHR sharelable (%x), exiting\n\n", status);
exit(0x10000004);
}
lib$disable_ctrl(&ctrl_mask, 0);
/* open the terminal and get the event flag to use */
sys$assign(&namdesc, &term_channel, 0, 0);
lib$get_ef(&qio_efn);
status = IOCallback("Username: ", username, 0, 32, ALPHA_RESPONSE, 1, 0, 0);
if (!status)
{
printf("\n\nAuthentication aborted, exiting\n\n");
exit(0x10000004);
}
status = VMSAUTHENTICATE("SECURID", username, 0, &IOCallback, &InfoCallback, &TimeoutCallback, &ScreenClearCallback, 0, identifier, 0, 0);
sys$dassgn(term_channel);
printf("\n");
lib$enable_ctrl(&ctrl_mask, 0);
/* all done */
exit((status & 1) ? 1 : 0x10000004);
}
int IOCallback(char *Prompt, char *Response, int MinRespLen, int MaxRespLen,
int RespType, int EchoFlag, int Timeout, int *UserData)
{
int i;
int status;
unsigned int readfunc;
/* display the prompt if needed */
if (Prompt && strlen(Prompt))
printf("\n%s", Prompt);
/* Now read from the terminal */
readfunc = IO$_READVBLK;
if (!EchoFlag)
readfunc |= IO$M_NOECHO;
for (i = 0; i < NSIG; i++)
signal(i, exit_handler);
status = sys$qiow(qio_efn, term_channel, readfunc, &iosb, 0, 0, Response, MaxRespLen, 0, 0, 0, 0);
for (i = 0; i < NSIG; i++)
signal(i, SIG_DFL);
if (getenv("VAM_AUTHORIZE_DEBUG"))
{
printf("\nstatus = %d, iosb.iostat = %d, iosb.term = %d\n\n",
status, iosb.iostat, iosb.term);
}
if (iosb.iostat == SS$_CONTROLY)
exit (0x10000004);
if (!(status & 1) || !(iosb.iostat & 1))
{
if ((status & 1) && (iosb.iostat == SS$_ENDOFFILE))
{
strcpy(Response, "\n");
iosb.term_offset = 1;
}
else
{
printf("\n\nFailed to read response, exiting");
return 0;
}
}
/* null-terminate the input */
Response[iosb.term_offset] = 0;
/* all done */
return 1;
}
int InfoCallback(char *Prompt, int Timeout, int *Userdata)
{
printf("\n%s", Prompt);
return 1;
}
void ScreenClearCallback(int *Userdata)
{
}
void TimeoutCallback(int *UserData)
{
InfoCallback("Timeout exceeded", 5, 0);
}
void exit_handler(int sig)
{
int i;
if (getenv("VAM_AUTHORIZE_DEBUG"))
{
if (sig != SIGINT)
printf("Signal %d caught\n", sig);
else
printf("Abort (CTRL-C or CTRL-Y) caught\n");
}
for (i = 0; i < NSIG; i++)
signal(i, SIG_DFL);
exit (0x10000004);
}
int load_vamshr_shareable(void)
{
$DESCRIPTOR (image_d, "VAMSHR");
$DESCRIPTOR (name_d, "VMSAUTHENTICATE");
int status;
lib$establish(lib$sig_to_ret);
status = lib$find_image_symbol (&image_d, &name_d, &VMSAUTHENTICATE);
return(status);
}