//Sample code file: var/ndk/webBuildengine/tmp/viewable_samples/13851de1-c95e-4306-8a32-63ea5aceba1b/lshtst.c

//Warning: This code has been marked up for HTML

/****************************************************************************
 %name: lshtst.c %
 %version: security#11.1.1 %
 %date_modified: Tue May 17 16:47:19 2005 %
 %version: security#11.1.1 %
 %date_modified: Tue May 17 16:47:19 2005 %

 Copyright (c) 1997-2005 Novell, Inc.  All rights reserved.

 THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
 USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT
 ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK.
 PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER A
 ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN ITS
 PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET,
 DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S
 PRODUCTS. NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S
 CUSTOMERS WITH RESPECT TO THIS CODE.
**************************************************************************/


/***************************************************************
 *** This code is available at "www.developer.novell.com/ndk/ **
 ***************************************************************/

/* Sample LDAP client code for SharedSecret SecretStore Service APIs */

class='cKeyword'>class='cKeyword'>#ifdef N_PLAT_NLM
class='cKeyword'>class='cKeyword'>#ifndef UCHAR
class='cKeyword'>#define UCHAR   unsigned class='cKeyword'>char
class='cKeyword'>#endif
class='cKeyword'>#endif


class='cKeyword'>#include <stdio.h>
class='cKeyword'>#include <stdlib.h>
class='cKeyword'>#include <string.h>
class='cKeyword'>class='cKeyword'>#ifndef N_PLAT_NLM
class='cKeyword'>#include <conio.h>
class='cKeyword'>#else
class='cKeyword'>#include   <signal.h>
class='cKeyword'>#include   <nwthread.h>
class='cKeyword'>#endif

class='cKeyword'>#include <time.h>
class='cKeyword'>#include <ssshs.h>
class='cKeyword'>#include <nssscl.h>


class='cKeyword'>class='cKeyword'>#ifdef N_PLAT_NLM
class='cKeyword'>class='cKeyword'>#ifdef FAST_ALLOC
/* for the fast allocation stuff */
LONG                  sleptFlag;
static   void          *ssLSSCLAllocRTag;

static   struct 
{
   LONG    signature; 
   class='cKeyword'>char    *name; 
   void    **tag;
} ssclAllocTag = {0x54524C41L, "SSLDAPCL Alloc Memory", &ssLSSCLAllocRTag};

void          *ss_GetAllocTag(void);
static int    ss_InitSSAllocTag(void);

class='cKeyword'>#include   "ssmem.h"
class='cKeyword'>#endif /* FAST_ALLOC */
class='cKeyword'>#endif


class='cKeyword'>#include "nssscl.h"
class='cKeyword'>#include "nssbldno.h"



/*
 * Global data
 */
static int         optIdx = 1;            //* index into parent argv vector
static int         optionString = 1;   //* character checked for validity
static class='cKeyword'>char       *optArg = NULL;      //* argument associated with option

class='cKeyword'>#define BADCHAR    (int)'?'
class='cKeyword'>#define ERRMSG     ""

/* interactive flag */
static int   aFlag = 1;




/*  */
/*
 * NAME - sss_GetOpt
 *
 * DESCRIPTION
 *   An implementation of the Unix getopt() function.
 *
 */

int   sss_GetOpt
      (
         int       nArgc, 
         class='cKeyword'>char       **nArgv, 
         class='cKeyword'>char       *optStr
      )
{ /* beginning of the call */
/* ########################## DECLARATIONS START HERE ######################### */

   static      class='cKeyword'>char      *place = ERRMSG;
             class='cKeyword'>char      *nxtOpt;

/* ############################## CODE STARTS HERE ############################ */

   if(!*place)  
   {
      if((optIdx >= nArgc) ||
         ((*(place = nArgv[optIdx]) != '-')
            && (*(place = nArgv[optIdx]) != '/')) ||
               (!*++place))
      {
         return(-1);
      }

      if((*place == '-') || (*place == '/'))
      {
         ++optIdx;
         return(-1);
      }
   }

   if((optionString = (int)*place++) == (int)'=' || 
         !(nxtOpt = strchr(optStr, optionString))) 
   {
      if(!*place) 
      {
         ++optIdx;
      }

      return(BADCHAR);
   }

   if(*++nxtOpt != '=') 
   {
      optArg = NULL;
      if(!*place) 
      {
         ++optIdx;
      }
   }
   else 
   {
      if(*place)
      {
         optArg = place + 1;
      }
      else if(nArgc <= ++optIdx) 
      {
         place = ERRMSG;
         return(BADCHAR);
      }
       else 
      {
          optArg = nArgv[optIdx];
      }

      place = ERRMSG;
      ++optIdx;
   }

   return(optionString);

/* ########################## CODE ENDS HERE ######################### */
} /* end of GetOPt */




void Pause()
{ /* beginning of the call */
/* ############################## CODE STARTS HERE ############################ */

   if(aFlag)
   {
      printf("\nPress a key ==>\n");
      getch();
   }
/* ########################## CODE ENDS HERE ######################### */
} /* end of Pause */



/*  */
/*
 * NAME - PrintFlags
 *
 * DESCRIPTION
 *   This function will print the 
 *   status flags read form a secret.         
 *         
 */
void PrintFlags(class='cKeyword'>char *msg, unsigned long   statFlags)
{ /* beginning of the call */
/* ############################## CODE STARTS HERE ############################ */

   if(aFlag)
   {
      printf("\n%s", msg);

      if(statFlags & NSSS_ENHANCED_PROTECT_INFO_F)
         printf("\tENHANCED PROTECTION...\n");

      if(statFlags & NSSS_STORE_NOT_SYNCED_F)
         printf("\tSTORE NOT SYNCED...\n");

      if(statFlags & NSSS_SECRET_NOT_INITIALIZED_F)
         printf("\tSECRET NOT INITIALIZED...\n");

      if(statFlags & NSSS_SECRET_LOCKED_F)
         printf("\tSECRET LOCKED...\n");

      /* doesn't apply to the server */
      if(strcmp(msg, "SecretStore Flags:\n"))
      {
         if(statFlags & NSSS_ADMIN_LAST_MOD_F)
            printf("\tADMIN MODIFIED LAST...\n");
         else
            printf("\tOWNER MODIFIED LAST...\n");
      }

      if(statFlags & NSSS_EP_PWORD_PRESENT_F)
         printf("\tEP PWORD PRESENT...\n");

      if(statFlags & NSSS_EP_MASTER_PWORD_PRESENT_F)
         printf("\tMASTER PWORD PRESENT...\n");
      
      if(statFlags & NSSS_MP_NOT_ALLOWED_F)
         printf("\tMASTER PWORD NOT ALLOWED...\n");

      if(statFlags & NSSS_HIDDEN_SECRET_F)
         printf("\tHIDDEN SECRET IN SECRETSTORE...\n");

      if(statFlags & NSSS_ADMIN_UNLOCKED_F)
         printf("\tADMIN LAST UNLOCKED THE SECRETSTORE...\n");
   }

/* ########################## CODE ENDS HERE ######################### */
} /* end of PrintFlags */






class='cKeyword'>class='cKeyword'>#ifdef N_PLAT_NLM

/* ########################################################################### */
/* ############################ NetWare  SPECIFICS ########################### */
/* ########################################################################### */

/* 
 **   These prototypes added here because no NWSDK
 **    header file contains them anymore.
 */
//N_EXTERN_LIBRARY(NWCCODE)
extern int
NWCallsInit
(
   nptr reserved1,
   nptr reserved2
);

//N_EXTERN_LIBRARY(NWCCODE)
extern int
NWCallsTerm
(
   nptr reserved
);


/* ###################################################################### */
/* ############################  COMMON DECLS ########################### */
/* ###################################################################### */


void         UnloadLDAPSSCLMain(int   sigNbr);

static   int      ssLSSCLThreadGroupID = 0;
unsigned    int      ssLSSCLModuleHandle = 0;

class='cKeyword'>#endif


int   ss_GetLoginInfo
      (
         class='cKeyword'>char             *targetDN,
         SSS_CONTEXT_T      *ctx
      )
{ /* beginning of the call */
/* ########################## DECLARATIONS START HERE ######################### */
       
   class='cKeyword'>char               portStr[256];
   int                  rc = NSSS_SUCCESS;
   SS_LDAPBIND_INFO_T      *ldapBindInfo = NULL;


/* ############################## CODE STARTS HERE ############################ */

   ldapBindInfo = (SS_LDAPBIND_INFO_T *)ctx->bindInfo;

   printf("\n Enter the following sequence to login to an LDAP server:");
   printf("\n (For default values press ENTER at the prompt)");
   printf("\n <LDAP Host Name> <Port No.> <Login DN> <Target DN> <Password> <Root Cert File Name>");
   printf("\n Example:\n lshtst nsd19.provo.novell.com 636 cn=janedoe,o=novell password\n\n");
   printf("\nc or: ");
   printf("\n Example:\n lshtst 151.155.160.85 636 cn=admin,o=novell cn=johndoe,o=novell password myKey.der\n\n");

   /* LDAP host name
      ============== */
   printf("Enter the LDAP Server DNS Name/IP Address: ");
   gets(ldapBindInfo->lHostName);
   if(strlen(ldapBindInfo->lHostName) == 0)
   {
      printf("Server Name required!!\n");
      return(NSSS_E_INVALID_PARAM);
   }

   printf("LDAP Host = [%s]\n", ldapBindInfo->lHostName);
   printf( "\n" );

   /* LDAP port number
      ================ */
   memset(portStr, 0, 256);
   printf("Enter LDAP Port Number (636-default): ");
   gets(portStr);

   if(strlen(portStr))
   {
      ldapBindInfo->portNum = atoi(portStr);
   }
   else
   {
      ldapBindInfo->portNum = 636L;
   }

   printf("LDAP Port = [%d]\n", ldapBindInfo->portNum);
   printf( "\n" );

   /* LDAP login DN
      ============= */
   printf("Enter Login DN in LDAP Format (\"cn=johndoe, o=novell\"): ");
   gets(ctx->callerDN.id);

   if((ctx->callerDN.len = strlen(ctx->callerDN.id)) == 0)
   {
      printf("Login DN required!!\n");
      return(NSSS_E_INVALID_PARAM);
   }
   ctx->callerDN.len++;

   printf("Login DN = [%s]\n", ctx->callerDN.id);
   printf( "\n" );

   /* LDAP target DN
      ============= */
   memset(targetDN, 0, 256);
   printf("Enter LDAP Target DN (\"cn=janedoe, o=novell\"): ");
   gets(targetDN);

   if(strlen(targetDN) == 0)
   {
      strcpy(targetDN, ctx->callerDN.id);
   }

   printf("Target DN = [%s]\n", targetDN);
   printf( "\n" );

   /* LDAP login password
      =================== */
   printf("Enter the LDAP Login Password: ");
   gets(ldapBindInfo->loginPword);

   printf("Enter Root Certificate File Name: (<Enter for Auto-retrieval>)");
   gets(ldapBindInfo->trustedRootCert);
   printf( "\n" );

   if(strlen(ldapBindInfo->trustedRootCert))
   {
      printf("Trusted Root Certificate = [%s]\n", ldapBindInfo->trustedRootCert);
   }

   return(NSSS_SUCCESS);

/* ########################## CODE ENDS HERE ######################### */
} /* end of ss_GetLoginInfo */










/*  */
/*
 * NAME - main
 *
 * DESCRIPTION
 *   SecretStore LDAP test program.         
 *         
 */
void   main
      (
         int       argc, 
         class='cKeyword'>char       **argv
      )
{ /* beginning of the call */
/* ########################## DECLARATIONS START HERE ######################### */

   SS_LDAPBIND_INFO_T      lbInfo = {0};
   SSS_CONTEXT_T         ctx = {0};
   SSS_GSINFOEXT_T         gsInfo = {0};
   SSS_READEXT_T         rInfo = {0};
   SS_SECRET_T            secretIDList = {0};
   class='cKeyword'>char               srchStr[] = "*";
   SS_OBJECT_DN_T         targetObjDN = {0};
//   class='cKeyword'>char               *nameStr;

   int                  bAppTest = 0, bMultiCredTest = 0, bMultiEntryTest = 0, bUTF8Test;
   class='cKeyword'>char               *pSecret = NULL;
   class='cKeyword'>char               *tempSecretID;
   class='cKeyword'>char               multiCredApp[] = "SharedSecret Multiple CredSet Application Test";
   class='cKeyword'>char               multiEntryCredSet[] = "SharedSecret Multiple Entry CredSet Test";
   unsigned class='cKeyword'>char         UTF8Key[] = {0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x64, 00};
   unsigned class='cKeyword'>char         UTF8Value[] = {0xED, 0x98, 0x9C, 0xED, 0x98, 0xA4, 0xED, 0x95, 0xAB, 0xED, 0x9B, 0xA7, 0xED, 0x9D, 0x8F, 00};
   class='cKeyword'>char               UTF8TestID[] = "UFT8Test";


   class='cKeyword'>char         *keyEntries[5] =
               {
                  "username01",
                  "username02",
                  "username03", 
                  "username04",
                  "username05" 
               };
   class='cKeyword'>char         *valEntries[5] =
               {
class='cKeyword'>class='cKeyword'>#ifdef LONG_VAL_TEST
"passwordpasswordpasswordpasswordpasswordpasswordpasswordpasswordpasswordpasswordpasswordpassword\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000",
"usernameusernameusernameusernameusernameusernameusernameusernameusernameusernameusernameusername\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000",
"usernameusernameusernameusernameusernameusernameusernameusernameusernameusernameusernameusername\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000",
"usernameusernameusernameusernameusernameusernameusernameusernameusernameusernameusernameusername\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000",
"usernameusernameusernameusernameusernameusernameusernameusernameusernameusernameusernameusername\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\
1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000"
class='cKeyword'>#else
                  "password01",
                  "password02",
                  "password03",
                  "password04",
                  "password05" 
class='cKeyword'>#endif
               };

   class='cKeyword'>char         *mKeyEntries[5] =
               {
                  "company",
                  "description",
                  "username", 
                  "password",
                  "pin number" 
               };
   class='cKeyword'>char         *mValEntries[5] =
               {
                  "Novell, Inc.",
                  "SharedSecret Test Utility",
                  "John Doe", 
                  "novell",
                  "000000000" 
               };

   class='cKeyword'>char         *appNames[5] =
               {
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.01CN=AppTest/O=novell", 
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.02CN=AppTest/O=novell",
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.03CN=AppTest/O=novell", 
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.04CN=AppTest/O=novell", 
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.05CN=AppTest/O=novell"
               };

   class='cKeyword'>char         *credSetNames[5] =
               {
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.01CN=CredSet/O=novell", 
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.02CN=CredSet/O=novell",
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.03CN=CredSet/O=novell", 
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.04CN=CredSet/O=novell", 
                  "\\SharedLDAPSecret:E:\\Novell\\ssshsTest.05CN=CredSet/O=novell"
               };

   int                  rcode = NSSS_SUCCESS;
   int                  exCount = 1, i, j, remLock = 0, unlock = 0,
                     master = 0, rCount = 1;
   long               opCount, bufSize = NSSS_MAX_SECRET_BUF_LEN;
   unsigned long         startTime, endTime, pFlag = 0L, count = 0;
   int                  c;

   SS_SECRET_ID_T         secretID = {0};

   // SharedSecret data
   void            *handle;   // handle for passing to functions
   SS_SH_SECRET_ID_T   shSecret;   // SharedSecret struct
   class='cKeyword'>char            *key = NULL;
   class='cKeyword'>char            *value = NULL;
   int               kLen = 0;
   int               vLen = 0;

/* ############################## CODE STARTS HERE ############################ */

   if(!(key = malloc(NSSS_MAX_SECRET_ID_LEN)))
   {
      exit(-1);
   }

   if(!(value = malloc(NSSS_MAX_SECRET_BUF_LEN)))
   {
      free(key);
      exit(-1);
   }

   if(!(pSecret = malloc(NSSS_MAX_SECRET_BUF_LEN)))
   {
      free(key);
      free(value);
      exit(-1);
   }
   
   if(!(tempSecretID = malloc(NSSS_MAX_SECRET_BUF_LEN)))
   {
      free(key);
      free(value);
      free(pSecret);
      exit(-1);
   }

   memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
   memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);
   memset(pSecret, 0, NSSS_MAX_SECRET_BUF_LEN);
   memset(tempSecretID, 0, NSSS_MAX_SECRET_BUF_LEN);


   printf("\nSharedSecret LDAP Test Program version %s ...\n\n", GSS_BLD_STR);

class='cKeyword'>class='cKeyword'>#ifdef   N_PLAT_NLM
   AtUnload(UnloadLDAPSSCLMain);
   atexit(UnloadLDAPSSCLMain);

   ssLSSCLModuleHandle = GetNLMHandle();

class='cKeyword'>class='cKeyword'>#ifdef FAST_ALLOC
       if(ss_InitSSAllocTag())
      {
         goto ERROR_1;
      }
class='cKeyword'>#endif /* FAST_ALLOC */

   ssLSSCLThreadGroupID = GetThreadGroupID();

   if((rcode = NWCallsInit(NULL, NULL)))
   {
      printf("CLIB Initialization Failed [%d]!!\n", rcode);
      goto ERROR_1;
   }

   signal(SIGTERM, UnloadLDAPSSCLMain);

class='cKeyword'>#endif

   printf("\nSecretStore NDK SharedSecret Test Program version %s ...\n\n", GSS_BLD_STR);

   //** Process command-line arguments.
   if(argc > 1)
   {
      while ((c = sss_GetOpt(argc, argv, "bBmMsSc=C=?hH")) != -1)
      {
         switch(c)
         {
            class='cKeyword'>case 'b':
            class='cKeyword'>case 'B':

               /* Big secret buffer */
               bufSize = NSSS_MAX_SECRET_BUF_LEN;
               class='cKeyword'>break;

            class='cKeyword'>case 'm':
            class='cKeyword'>case 'M':

               /* Medium secret buffer */
               bufSize = NSSS_MID_SECRET_BUF_LEN; 
               class='cKeyword'>break;

            class='cKeyword'>case 's':
            class='cKeyword'>case 'S':

               /* set active flag to FALSE */
               aFlag = 0;
               printf("Silent Running Mode Active...\n");
               class='cKeyword'>break;

            class='cKeyword'>case 'c':
            class='cKeyword'>case 'C':

               /* Run count */
               exCount = atoi(optArg);
               class='cKeyword'>break;

            default:

               //* class='cKeyword'>case '?':
               //* class='cKeyword'>case 'h':
               //*class='cKeyword'>case 'H':

               printf("\nUsage: lshtst [/m]|[/b][/s /c=[count] /r=[rcount] | /? | /h ]\n");
               printf("\tOptions: [ /m | /M ] for 4k Secret Buffer Size.\n");
               printf("\tOptions: [ /b | /B ] for 59k Secret Buffer Size.\n");
               printf("\tOptions: [ /s | /S ] for Silent Running.\n");
               printf("\t\tSilent sub-Option [ /c | /C ] for number of times to run.\n");
               printf("\tExample: lshtst /s /c=1000\n");
               printf("\tOption: [ /h | /H  | /? ] for Help.\n");
               printf("\tNo command line options will activate interactive running.\n\n");
               printf("\tFor options \"/\" and \"-\" are interchangeable.\n\n");
               exit(0);
         }
      } 
   }
   else
   {
       printf("Full Interactive Running Mode Active...\n");
   }


   printf("[%d]k secret size buffer chosen...\n", bufSize);
   printf("Execution Count Set to: [%d]\n", exCount);
   printf("Read Count Set to: [%d]\n", rCount);

   ctx.bindInfo = &lbInfo;
   targetObjDN.len = strlen(targetObjDN.id)+1;

   printf("Initializing...\n");

   /* allocate and initialize the enumSecIDBuf for ENUM */
   if(!(secretIDList.data = (class='cKeyword'>char *)malloc(NSSS_MAX_IDLIST_BUF_LEN)))
   {
      printf("Error: secretIDList MALLOC FAILED!\n");
      goto ERROR_1;
   }

   secretIDList.len = NSSS_MAX_IDLIST_BUF_LEN;

   startTime = time(NULL);
   printf("Done...\n");
   Pause();

   if(ss_GetLoginInfo(targetObjDN.id, &ctx))
   {
      printf("Error: Getting LDAP Login Info FAILED!\n");
      goto ERROR_1;
   }

   targetObjDN.len = strlen(targetObjDN.id)+1;

class='cKeyword'>class='cKeyword'>#ifndef LONG_VAL_TEST
   do
   {
class='cKeyword'>#endif
      /* need to get a new context */
      if(pFlag & NSSS_DESTROY_CONTEXT_F)
      {
         pFlag &= ~NSSS_DESTROY_CONTEXT_F;
         pFlag |= NSSS_GET_CONTEXT_F;
         ctx.flags = NSSS_LDAP_CTX_F;
      }
      else
      {
         /* already have context for reuse */
         ctx.flags |= (NSSS_LDAP_CTX_F | NSSS_BINDLDAP_F);
      }

      memset(&gsInfo, 0, sizeof(SSS_GSINFOEXT_T));

      if(rcode = NSSSGetServiceInformation(&ctx, &targetObjDN, (pFlag | NSSS_GET_CONTEXT_F), &gsInfo, NULL))
      {
         //* Call failed.
         printf("\nError [%d] NSSSGetServiceInformation\n", rcode);
         goto ERROR_1;
      }
      else
      { 
         //* Print out service information.
         printf("\nClient Version = [%d.%d.%d]\n",
            ((gsInfo.clientVersion >> 16)  & 0x000000FF) , 
               ((gsInfo.clientVersion >> 8) & 0x000000FF), 
                  (gsInfo.clientVersion & 0x000000FF));

         printf("\nServer Version = [%d.%d.%d]\n",
            ((gsInfo.serverVersion >> 16) & 0x000000FF) , 
               ((gsInfo.serverVersion >> 8) & 0x000000FF), 
                  (gsInfo.serverVersion & 0x000000FF));

         if(gsInfo.serverCryptoStrength == NSSS_NICI_DOMESTIC_ENGINE)
         {
            printf("Server Crypto Strength = DOMESTIC\n");
         }
         else
         {
            printf("Server Crypto Strength = EXPORT\n");
         }
         
         printf("\nSecretStore's NDS Tree = %s\n", ctx.ssServerInfo.treeName);

         if(gsInfo.hintLen)
         {
            printf("\nMaster Password Hint = %s\n", gsInfo.hint);
         }
      }

      //* reset the flag
      pFlag &= ~NSSS_GET_CONTEXT_F;
      if(aFlag)
      {
         printf("\nDo you want to CONTINUE (y/n)? ");

         c = getch();
         putchar(c);
         printf("\n\n");
      }
      else
      {
          c = 'y';
      }

      if(!((c == 'y') || (c == 'Y')))
      {
         aFlag = 0;
         goto ERROR_1;
      }

      //* Run the tests as many times as specified by the user.
      for(j = 0, opCount = 0; j < exCount; j++)
      {
         ///////////////////////////////////////////////////////////
         /// begin the test for UTF8 ///////////////////////////////
         ///////////////////////////////////////////////////////////

class='cKeyword'>class='cKeyword'>#ifndef LONG_VAL_TEST
         ///////////////////////////////////////////
         // run the CREATE a UTF8 Credential Secret
         ///////////////////////////////////////////
         if(aFlag)
         {
            printf("\nDo you want to CREATE a UTF8 Credential Secret(y/n)? ");
            c = getch();
            putchar(c);
            printf("\n\n");
         }
         else
         {
            c = 'y';
         }

         if(c == 'y' || c == 'Y')
         {
            bUTF8Test = 1;
            shSecret.type = SS_CREDENTIAL_TYPE_F;
            strcpy(shSecret.pName, UTF8TestID);
            shSecret.len = strlen(shSecret.pName)+1;
            
            handle = NSSSCreateSHSHandle();  // create a new handle
            if(!handle)
            {
               printf("\n\nFAILED to successfully create a valid handle");
               Pause();
               goto ERROR_1;
            }

            printf("\nCalling NSSSReadSharedSecret\n");
         
            rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
            
            if(rcode != NSSS_SUCCESS)
            {
               if((rcode != NSSS_E_STORE_NOT_FOUND) && (rcode != NSSS_E_INVALID_SECRET_ID))
               {
                  printf("\nNSSSReadSharedSecret returned [%d] in [%s]\n\n", rcode, UTF8TestID);
                  Pause();
                  goto ERROR_1;
               }
            }

            for(i = 1; i < 2; i++)
            {   
               strcpy(key, UTF8Key);
               strcpy(value, UTF8Value);

               printf("\nCalling NSSSAddSHSEntry for [%s]\n", UTF8TestID);   
         
               if(rcode = NSSSAddSHSEntry(handle, key, value, ctx.flags))
               {
                  printf("\nNSSSAddSHSEntry returned [%d] when adding [%s]/[%s]\nto [%s]\n\n", rcode, key, value, "UTF8 Test");
                  Pause();
               }
               else
               {
                  printf("\nAdded [%s]=[%s]\n", key, value);
               }
            }

            printf("\nCalling NSSSWriteSharedSecret\n");
      
            if(rcode = NSSSWriteSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, NULL))
            {
               printf("\n\nNSSSWriteSharedSecret returned [%d] when storing data in\n[%s]\n\n", rcode, UTF8TestID);
               Pause();
               goto ERROR_1;
            }
            else
            {
               printf("\nNSSSWriteSharedSecret SUCCEEDED\n");
            }

            memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
            memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);
            
            NSSSDestroySHSHandle(handle);  // destroy the handle
         }


         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);

         if(bUTF8Test)
         {
            ///////////////////////////////////////////////
            // run the READ the UTF8 Credential Secret test
            ///////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to READ the UTF8 Credential Secret(y/n)? ");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               shSecret.type = SS_CREDENTIAL_TYPE_F;
               strcpy(shSecret.pName, UTF8TestID);
               shSecret.len = strlen(shSecret.pName)+1;

               handle = NSSSCreateSHSHandle();  // create a new handle
               if(!handle)
               {
                  printf("\n\nFAILED to successfully create a valid handle");
                  Pause();
                  goto ERROR_1;
               }
               
               printf("\nCalling NSSSReadSharedSecret\n");
      
               rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
               
               if(rcode != NSSS_SUCCESS)
               {
                  printf("\nNSSSReadSharedSecret returned [%d] in [%s]\n\n", rcode, UTF8TestID);
                  Pause();
                  goto ERROR_1;
               }

               printf("\nCalling NSSSGetNextEntry\n");
      
               if(!(rcode = NSSSGetNextSHSEntry(1, handle, &kLen, key, &vLen, value, ctx.flags)))
               {
                  while(rcode == NSSS_SUCCESS)
                  {
                     if(0 == strlen(key))
                     {
                        class='cKeyword'>break;
                     }

                     strcpy(pSecret, key);
                     strcat(pSecret, "=");
                     strcat(pSecret, value);
                     printf("\nNSSSGetNextSHSEntry returned [%s]:[%s]\n", key, value);
                     
                     // clear the buffers
                     memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
                     memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);
                     memset(pSecret, 0, NSSS_MAX_SECRET_BUF_LEN);

                     rcode = NSSSGetNextSHSEntry(0, handle, &kLen, key, &vLen, value, ctx.flags);
                  }
               }
               
               NSSSDestroySHSHandle(handle);  // destroy the handle
            }
         }
class='cKeyword'>#endif
         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);


         //////////////////////////////////////////////////////////////////////////////////////////
         /////////// end of MBCS test for UTF8 ////////////////////////////////////////////////////
         //////////////////////////////////////////////////////////////////////////////////////////

         //////////////////////////////////////////////////////////////////////////////////////////
         // run the CREATE Application SharedSecrets with an associated default Credential Set test
         //////////////////////////////////////////////////////////////////////////////////////////
         if(aFlag)
         {
            printf("\nDo you want to CREATE Application SharedSecrets with\nan associated default Credential Set(y/n)? ");
            c = getch();
            putchar(c);
            printf("\n\n");
         }
         else
         {
            c = 'y';
         }

         if(c == 'y' || c == 'Y')
         {
            bAppTest = 1;

            for(i = 1; i < 6; i++)
            {
               shSecret.type = SS_APPLICATION_TYPE_F;
               strcpy(shSecret.pName, appNames[i-1]);
               shSecret.len = strlen(shSecret.pName)+1;

               // create the App secredID and key/value pair secret data
               handle = NSSSCreateSHSHandle();  // create a new handle
               if(!handle)
               {
                  printf("\n\nFAILED to successfully create a valid handle");
                  Pause();
                  goto ERROR_1;
               }
               
               printf("\nCalling NSSSReadSharedSecret\n");
            
               rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
               
               if(rcode != NSSS_SUCCESS)
               {
                  if((rcode != NSSS_E_STORE_NOT_FOUND) && (rcode != NSSS_E_INVALID_SECRET_ID))
                  {
                     printf("\nNSSSReadSharedSecret returned [%d] when reading [%s]\n\n", rcode, appNames[i-1]);
                     Pause();
                     goto ERROR_1;
                  }
               }

               strcpy(key, "SS_CredSet");
               strcpy(value, credSetNames[i-1]);

               printf("\nCalling NSSSAddSHSEntry\n");
         
               if(rcode = NSSSAddSHSEntry(handle, key, value, ctx.flags))
               {
                  printf("\n\nNSSSAddSHSEntry returned [%d] when adding\n[%s] and [%s]\n\n", rcode, key, value);
                  Pause();
               }
               else
               {
                  printf("\nAdded [%s]:[%s]\n", key, value);
               }

               printf("\nCalling NSSSWriteSharedSecret\n");
            
               if(rcode = NSSSWriteSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, NULL))
               {
                  printf("\nNSSSWriteSharedSecret returned [%d] when storing [%s]:[%s]\nto [%s]\n\n", rcode, key, value, appNames[i-1]);
                  Pause();
                  goto ERROR_1;
               }
               else
               {
                  printf("\nNSSSWriteSharedSecret SUCCEEDED\n");
               }

               NSSSDestroySHSHandle(handle);  // destroy the handle
               
               memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
               memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);



               ////////////////////////////////////////////////////////////////
               // create the CredSet secredID and key/value pair secret data
               handle = NSSSCreateSHSHandle();  // create a new handle
               if(!handle)
               {
                  printf("\n\nFAILED to successfully create a valid handle");
                  Pause();
                  goto ERROR_1;
               }

               shSecret.type = SS_CREDENTIAL_TYPE_F;
               strcpy(shSecret.pName, credSetNames[i-1]);
               shSecret.len = strlen(shSecret.pName)+1;
               
               printf("\nCalling NSSSReadSharedSecret\n");
         
               rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
               
               if(rcode != NSSS_SUCCESS)
               {
                  if((rcode != NSSS_E_STORE_NOT_FOUND) && (rcode != NSSS_E_INVALID_SECRET_ID))
                  {
                     printf("\nNSSSReadSharedSecret returned [%d] when reading [%s]\n\n", rcode, credSetNames[i-1]);
                     Pause();
                     goto ERROR_1;
                  }
               }

               strcpy(key, keyEntries[i-1]);
               strcpy(value, valEntries[i-1]);

               printf("\nCalling NSSSAddSHSEntry\n");   
         
               if(rcode = NSSSAddSHSEntry(handle, key, value, ctx.flags))
               {
                  printf("\nNSSSAddSHSEntry returned [%d] when adding \n[%s]:[%s]\nto [%s]\n\n", rcode, key, value, credSetNames[i-1]);
                  Pause();
               }
               else
               {
                  printf("\nAdded [%s]=[%s]\n", key, value);
               }

               printf("\nCalling NSSSWriteSharedSecret\n");
            
               if(rcode = NSSSWriteSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, NULL))
               {
                  printf("\n\nNSSSWriteSharedSecret returned [%d] when storing\n[%s]:[%s]\nto [%s]\n\n", rcode, key, value, credSetNames[i-1]);
                  Pause();
                  goto ERROR_1;
               }
               else
               {
                  printf("\nNSSSWriteSharedSecret SUCCEEDED\n");
               }

               NSSSDestroySHSHandle(handle);  // destroy the handle
            }
         }

         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);





         if(bAppTest)
         {
            //////////////////////////////////////////////////
            // run the READ the Application SharedSecrets test
            //////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to READ the Application SharedSecrets(y/n)? ");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               shSecret.type = SS_APPLICATION_TYPE_F;

               for(i = 1; i < 6; i++)
               {
                  memset(shSecret.pName, 0, NSSS_MAX_SECRET_ID_LEN);
                  strcpy(shSecret.pName, appNames[i-1]);
                  shSecret.len = strlen(shSecret.pName)+1;
                  handle = NSSSCreateSHSHandle();  // create a new handle
                  if(!handle)
                  {
                     printf("\n\nFAILED to successfully create a valid handle");
                     Pause();
                     goto ERROR_1;
                  }
                  
                  printf("\nCalling NSSSReadSharedSecret\n");

                  rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
                  if(rcode != NSSS_SUCCESS)
                  {
                     printf("\nNSSSReadSharedSecret returned [%d] when reading [%s]\n\n", rcode, appNames[i-1]);
                     Pause();
                     goto ERROR_1;

                  }

                  printf("\nCalling NSSSGetNextSHSEntry\n");
               
                  if(!(rcode = NSSSGetNextSHSEntry(1, handle, &kLen, key, &vLen, value, ctx.flags)))
                  {
                     while(rcode == NSSS_SUCCESS)
                     {
                        if(0 == strlen(key))
                        {
                           class='cKeyword'>break;
                        }

                        strcpy(pSecret, key);
                        strcat(pSecret, ":");
                        strcat(pSecret, value);
                        printf("\nNSSSGetNextSHSEntry returned [%s]:[%s]\n", key, value);
                        
                        // clear the buffers
                        memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
                        memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);
                        memset(pSecret, 0, NSSS_MAX_SECRET_BUF_LEN);

//                        printf("\nCalling NSSSGetNextSHSEntry for retrieving key/value data from [%s]\n", appNames[i-1]);
                        
                        rcode = NSSSGetNextSHSEntry(0, handle, &kLen, key, &vLen, value, ctx.flags);
                     }
                  }
                  
                  NSSSDestroySHSHandle(handle);  // destroy the handle

                  memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
                  memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);



               }
            }
         }

         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);

         ////////////////////////////////////////////////////////////////////////////////////////////
         // run the multiple CREATE Credential Sets for a single Application Secret SharedSecret test
         ////////////////////////////////////////////////////////////////////////////////////////////
         if(aFlag)
         {
            printf("\nDo you want to CREATE multiple Credential Secrets\nfor a single Application Secret(y/n)? ");
            c = getch();
            putchar(c);
            printf("\n\n");
         }
         else
         {
            c = 'y';
         }

         if(c == 'y' || c == 'Y')
         {
            bMultiCredTest = 1;
            shSecret.type = SS_APPLICATION_TYPE_F;
            strcpy(shSecret.pName, multiCredApp);
            shSecret.len = strlen(shSecret.pName)+1;
            
            handle = NSSSCreateSHSHandle();  // create a new handle
            if(!handle)
            {
               printf("\n\nFAILED to successfully create a valid handle");
               Pause();
               goto ERROR_1;
            }

            printf("\nCalling NSSSReadSharedSecret\n");
         
            rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
            
            if(rcode != NSSS_SUCCESS)
            {
               if((rcode != NSSS_E_STORE_NOT_FOUND) && (rcode != NSSS_E_INVALID_SECRET_ID))
               {
                  printf("\nNSSSReadSharedSecret returned [%d] when reading [%s]\n\n", rcode, multiCredApp);
                  Pause();
                  goto ERROR_1;
               }
            }

            for(i = 1; i < 6; i++)
            {   
               strcpy(key, "SS_CredSet");
               strcpy(value, credSetNames[i-1]);

               printf("\nCalling NSSSAddSHSEntry for [%s]\n", multiCredApp);   
         
               if(rcode = NSSSAddSHSEntry(handle, key, value, ctx.flags))
               {
                  printf("\nNSSSAddSHSEntry returned [%d] when adding [%s]/[%s]\nto [%s]\n\n", rcode, key, value, multiCredApp);
                  Pause();
               }
               else
               {
                  printf("\nAdded [%s]:[%s]\n", key, value);
               }
            }

            printf("\nCalling NSSSWriteSharedSecret\n");
      
            if(rcode = NSSSWriteSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, NULL))
            {
               printf("\n\nNSSSWriteSharedSecret returned [%d] when storing data in\n[%s]\n\n", rcode, multiCredApp);
               Pause();
               goto ERROR_1;
            }
            else
            {
               printf("\nNSSSWriteSharedSecret SUCCEEDED\n");
            }

            memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
            memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);
            
            NSSSDestroySHSHandle(handle);  // destroy the handle
         }


         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);

         if(bMultiCredTest)
         {
            /////////////////////////////////////////////////////////////////////////////////
            // run the READ Credential Sets for a single Application Secret SharedSecret test
            /////////////////////////////////////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to READ the multiple Credential Secrets\nfor a single Application Secret(y/n)? ");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               shSecret.type = SS_APPLICATION_TYPE_F;
               strcpy(shSecret.pName, multiCredApp);
               shSecret.len = strlen(shSecret.pName)+1;

               handle = NSSSCreateSHSHandle();  // create a new handle
               if(!handle)
               {
                  printf("\n\nFAILED to successfully create a valid handle");
                  Pause();
                  goto ERROR_1;
               }
               
               printf("\nCalling NSSSReadSharedSecret\n");
      
               rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
               
               if(rcode != NSSS_SUCCESS)
               {
                  printf("\nNSSSReadSharedSecret returned [%d] when reading [%s]\n\n", rcode, multiCredApp);
                  Pause();
                  goto ERROR_1;
               }

               printf("\nCalling NSSSGetNextEntry\n");
      
               if(!(rcode = NSSSGetNextSHSEntry(1, handle, &kLen, key, &vLen, value, ctx.flags)))
               {
                  while(rcode == NSSS_SUCCESS)
                  {
                     if(0 == strlen(key))
                     {
                        class='cKeyword'>break;
                     }

                     strcpy(pSecret, key);
                     strcat(pSecret, ":");
                     strcat(pSecret, value);
                     printf("\nNSSSGetNextSHSEntry returned [%s]:[%s]\n", key, value);
                     
                     // clear the buffers
                     memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
                     memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);
                     memset(pSecret, 0, NSSS_MAX_SECRET_BUF_LEN);

                     rcode = NSSSGetNextSHSEntry(0, handle, &kLen, key, &vLen, value, ctx.flags);
                  }
               }
               
               NSSSDestroySHSHandle(handle);  // destroy the handle
            }
         }

         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);



         ///////////////////////////////////////////////////////////////////
         // run the CREATE multiple entries for a single Credential Set test
         ///////////////////////////////////////////////////////////////////
         if(aFlag)
         {
            printf("\nDo you want to CREATE multiple entries for a single Credential Set(y/n)? ");
            c = getch();
            putchar(c);
            printf("\n\n");
         }
         else
         {
            c = 'y';
         }

         if(c == 'y' || c == 'Y')
         {
            bMultiEntryTest = 1;
            shSecret.type = SS_CREDENTIAL_TYPE_F;
            strcpy(shSecret.pName, multiEntryCredSet);
            shSecret.len = strlen(shSecret.pName)+1;

            handle = NSSSCreateSHSHandle();  // create a new handle
            if(!handle)
            {
               goto ERROR_1;
            }
            
            printf("\nCalling NSSSReadSharedSecret\n");
      
            rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
            
            if(rcode != NSSS_SUCCESS)
            {
               if((rcode != NSSS_E_STORE_NOT_FOUND) && (rcode != NSSS_E_INVALID_SECRET_ID))
               {
                  printf("\nNSSSReadSharedSecret returned [%d] when reading [%s]\n\n", rcode, multiEntryCredSet);
                  Pause();
                  goto ERROR_1;
               }
            }

            for(i = 1; i < 6; i++)
            {   
               strcpy(key, mKeyEntries[i-1]);
               strcpy(value, mValEntries[i-1]);

               printf("\nCalling NSSSAddSHSEntry\n");

               if(!(rcode = NSSSAddSHSEntry(handle, key, value, ctx.flags)))
               {
                  printf("\nAdded [%s]=[%s]\n", key, value);
               }
               else
               {
                  printf("\nNSSSAddSHSEntry returned [%d] when adding [%s]=[%s]\n\n", rcode, key, value);
                  Pause();
               }
            }
            
            printf("\nCalling NSSSWriteSharedSecret\n");
            
            if(rcode = NSSSWriteSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, NULL))
            {
               printf("\nNSSSWriteSharedSecret returned [%d] when storing\n[%s]:[%s]\nto [%s]\n\n", rcode, key, value, multiEntryCredSet);
               Pause();
               goto ERROR_1;
            }
            else
            {
               printf("\nNSSSWriteSharedSecret SUCCEEDED\n");
            }
                     
            NSSSDestroySHSHandle(handle);  // destroy the handle
         }



         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);

         if(bMultiEntryTest)
         {
            /////////////////////////////////////////////////////////////
            // READ the multiple entries in the single Credential Set test
            /////////////////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to READ the multiple entries in the single Credential Set(y/n)? ");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               shSecret.type = SS_CREDENTIAL_TYPE_F;
               strcpy(shSecret.pName, multiEntryCredSet);
               shSecret.len = strlen(shSecret.pName)+1;

               handle = NSSSCreateSHSHandle();  // create a new handle
               if(!handle)
               {
                  goto ERROR_1;
               }
               
               printf("\nCalling NSSSReadSharedSecret\n");
         
               rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
               
               if(rcode != NSSS_SUCCESS)
               {
                  printf("\nNSSSReadSharedSecret returned [%d] when reading [%s]\n\n", rcode, multiEntryCredSet);
                  Pause();
                  goto ERROR_1;
               }

               printf("\nCalling NSSSGetNextSHSEntry\n");
            
               if(!(rcode = NSSSGetNextSHSEntry(1, handle, &kLen, key, &vLen, value, ctx.flags)))
               {
                  while(rcode == NSSS_SUCCESS)
                  {
                     if(0 == strlen(key))
                     {
                        class='cKeyword'>break;
                     }

                     strcpy(pSecret, key);
                     strcat(pSecret, "=");
                     strcat(pSecret, value);
                     printf("\nNSSSGetNextSHSEntry returned [%s]=[%s]\n\n", key, value);
                     
                     // clear the buffers
                     memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
                     memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);
                     memset(pSecret, 0, NSSS_MAX_SECRET_BUF_LEN);


                     rcode = NSSSGetNextSHSEntry(0, handle, &kLen, key, &vLen, value, ctx.flags);
                  }
               }

               NSSSDestroySHSHandle(handle);  // destroy the handle
            }
         }

         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);

         if(bMultiEntryTest)
         {
            ///////////////////////////////////////////////////////////////////////////
            // run the REMOVE the multiple entries from the single Credential Set test
            ///////////////////////////////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to REMOVE the multiple entries from the single Credential Set(y/n)? ");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               shSecret.type = SS_CREDENTIAL_TYPE_F;
               strcpy(shSecret.pName, multiEntryCredSet);
               shSecret.len = strlen(shSecret.pName)+1;

               handle = NSSSCreateSHSHandle();  // create a new handle
               if(!handle)
               {
                  goto ERROR_1;
               }

               printf("\nCalling NSSSReadSharedSecret\n");
         
               rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
               
               if(rcode != NSSS_SUCCESS)
               {
                  if((rcode != NSSS_E_STORE_NOT_FOUND) && (rcode != NSSS_E_INVALID_SECRET_ID))
                  {
                     printf("\nNSSSReadSharedSecret returned [%d] when reading [%s]\n\n", rcode, multiEntryCredSet);
                     Pause();
                     goto ERROR_1;
                  }
               }

               // Remove only the entries we added.
               for(i = 1; i < 6; i++)
               {
                  strcpy(key, mKeyEntries[i-1]);
                  strcpy(value, mValEntries[i-1]);
                  strcpy(shSecret.pName, multiEntryCredSet);
                  shSecret.len = strlen(shSecret.pName)+1;

                  kLen = strlen(key)+1;
                  vLen = strlen(value)+1;
                  printf("\nCalling NSSSRemoveSHSEntry\n");
         
                  if(!(rcode = NSSSRemoveSHSEntry(handle, key, value, ctx.flags)))
                  {
                     printf("Removed [%s]=[%s]\n", key, value);      
                  }
                  else
                  {
                     printf("FAILED to remove [%s]:[%s]\nfrom [%s]\n\n", key, value, multiEntryCredSet);
                  }
                  
                  // clear the buffers
                  memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
                  memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);
               }
               
            
               printf("\nCalling NSSSWriteSharedSecret\n");
               
               if(rcode = NSSSWriteSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, NULL))
               {
                  printf("\nNSSSWriteSharedSecret returned [%d] when storing data in\n[%s]\n\n", rcode, multiEntryCredSet);
                  Pause();
                  goto ERROR_1;
               }
               else
               {
                  printf("\nNSSSWriteSharedSecret SUCCEEDED\n");
               }
               
               rcode = NSSSDestroySHSHandle(handle);
            }            
         }

         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);

         if(bMultiCredTest)
         {
            ///////////////////////////////////////////////////////////////////////////////////////////
            // run the REMOVE the multiple Credential Sets from the single Application Test Secret test
            ///////////////////////////////////////////////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to REMOVE the multiple Credential Sets\nfrom the single Application Test Secret(y/n)? ");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               // Remove only the Cred Sets we added.
               strcpy(shSecret.pName, multiCredApp);
               shSecret.len = strlen(shSecret.pName)+1;
               shSecret.type = SS_APPLICATION_TYPE_F;
               strcpy(key, "SS_CredSet");
               handle = NSSSCreateSHSHandle();  // create a new handle
               if(!handle)
               {
                  goto ERROR_1;
               }
            
               printf("\nCalling NSSSReadSharedSecret\n");
         
               rcode = NSSSReadSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, &rInfo, NULL);
               
               if(rcode != NSSS_SUCCESS)
               {
                  if((rcode != NSSS_E_STORE_NOT_FOUND) && (rcode != NSSS_E_INVALID_SECRET_ID))
                  {
                     printf("\nNSSSReadSharedSecret returned [%d] when reading [%s]\n\n", rcode, multiCredApp);
                     Pause();
                     goto ERROR_1;
                  }
               }               

               for(i = 1; i < 6; i++)
               {
                  strcpy(value, credSetNames[i-1]);
                  printf("\nCalling NSSSRemoveSHSEntry\n");
                  kLen = strlen(key)+1;
                  vLen = strlen(value)+1;   
                  if(!(rcode = NSSSRemoveSHSEntry(handle, key, value, ctx.flags)))
                  {
                     printf("\nRemoved [%s]:[%s]\n", key, value);
                  }
                  else
                  {
                     printf("\nNSSSRemoveSHSEntry returned [%d] when removing [%s]:[%s] from [%s]\n\n", rcode, key, value, credSetNames[i-1]);
                  }
               }
               
               // clear the buffers
               memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
               memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);
            
               printf("\nCalling NSSSWriteSharedSecret\n");
               
               if(rcode = NSSSWriteSharedSecret(handle, &shSecret, &ctx, &targetObjDN, pFlag, NULL, NULL))
               {
                  printf("\nNSSSWriteSharedSecret returned [%d] when storing data in\n[%s]\n\n", rcode, multiCredApp);
                  Pause();
                  goto ERROR_1;
               }
               else
               {
                  printf("\nNSSSWriteSharedSecret SUCCEEDED\n");
               }
               
               rcode = NSSSDestroySHSHandle(handle);
            }
         }

         memset(key, 0, NSSS_MAX_SECRET_ID_LEN);
         memset(value, 0, NSSS_MAX_SECRET_BUF_LEN);

         if(bMultiCredTest)
         {
            //////////////////////////////////////////////////////
            // run the REMOVE the Credential Set Test Secrets test
            //////////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to REMOVE the Credential Set Test Secrets(y/n)?\n");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }


            if(c == 'y' || c == 'Y')
            {
               for(i = 1; i < 6; i++)
               {
                  strcpy(shSecret.pName, credSetNames[i-1]);
                  shSecret.type = SS_CREDENTIAL_TYPE_F; 

                  // remove one secret at a time 
                  if(rcode = NSSSRemoveSharedSecret(&shSecret, &ctx, &targetObjDN, pFlag, NULL))
                  if(rcode = NSSSRemoveSecret(&ctx, &targetObjDN, pFlag, &secretID, NULL))
                  {
                     printf("NSSSRemoveSharedSecret returned [%d] when removing [%s]\n\n", rcode, shSecret.pName);
                     printf("NSSSRemoveSecret returned [%d] when removing [%s]\n\n", rcode, secretID.id);
                     Pause();
                  }
                  else
                  {
                     printf("\nRemoved [%s]\n", credSetNames[i-1]);
                  }
                  
                  memset(shSecret.pName, 0, NSSS_MAX_SECRET_ID_LEN);
               }
            }
         }



         if(bAppTest)
         {
            ///////////////////////////////////////////////////
            // run the REMOVE the Application Test Secrets test
            ///////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to REMOVE the Application Test Secrets(y/n)? ");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               // Remove only the Application SharedSecrets we added.
               for(i = 1; i < 6; i++)
               {
                  strcpy(shSecret.pName, appNames[i-1]);
                  shSecret.type = SS_APPLICATION_TYPE_F; 
                  // remove one secret at a time 
                  if(rcode = NSSSRemoveSharedSecret(&shSecret, &ctx, &targetObjDN, pFlag, NULL))
                  if(rcode = NSSSRemoveSecret(&ctx, &targetObjDN, pFlag, &secretID, NULL))
                  {
                     printf("NSSSRemoveSharedSecret returned [%d] when removing [%s]\n\n", rcode, shSecret.pName);
                     printf("NSSSRemoveSecret returned [%d] when removing [%s]\n\n", rcode, secretID.id);
                     Pause();
                  }

                  else
                  {
                     printf("\nRemoved [%s]\n", appNames[i-1]);
                  }
                  
                  memset(shSecret.pName, 0, NSSS_MAX_SECRET_ID_LEN);
               }
            }
         }



         if(bAppTest)
         {
            ///////////////////////////////////////////////////////////////
            // run the REMOVE the multiple CredSet Application Test Secret
            ///////////////////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to REMOVE the multiple CredSet Application Test Secret(y/n)?\n");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               strcpy(shSecret.pName, multiCredApp);
               shSecret.type = SS_APPLICATION_TYPE_F; 
               // remove one secret at a time 
               if(rcode = NSSSRemoveSharedSecret(&shSecret, &ctx, &targetObjDN, pFlag, NULL))
               if(rcode = NSSSRemoveSecret(&ctx, &targetObjDN, pFlag, &secretID, NULL))
               {
                  printf("NSSSRemoveSharedSecret returned [%d] when removing [%s]\n\n", rcode, shSecret.pName);
                  printf("NSSSRemoveSecret returned [%d] when removing [%s]\n\n", rcode, secretID.id);
                  Pause();
               }
               else
               {
                  printf("\nRemoved [%s]\n", multiCredApp);
               }
               
               memset(shSecret.pName, 0, NSSS_MAX_SECRET_ID_LEN);
            }
         }




         if(bMultiEntryTest)
         {
            /////////////////////////////////////////////////////////////
            // run the REMOVE the multiple entry Application Test Secret
            /////////////////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to REMOVE the multiple entry Application Test Secret(y/n)?\n");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               strcpy(shSecret.pName, multiEntryCredSet);
               shSecret.type = SS_CREDENTIAL_TYPE_F; 
               // remove one secret at a time 
               if(rcode = NSSSRemoveSharedSecret(&shSecret, &ctx, &targetObjDN, pFlag, NULL))
               if(rcode = NSSSRemoveSecret(&ctx, &targetObjDN, pFlag, &secretID, NULL))
               {
                  printf("NSSSRemoveSharedSecret returned [%d] when removing [%s]\n\n", rcode, shSecret.pName);
                  printf("NSSSRemoveSecret returned [%d] when removing [%s]\n\n", rcode, secretID.id);
                  Pause();
               }
               else
               {
                  printf("\nRemoved [%s]\n", multiEntryCredSet);
               }
               
               memset(shSecret.pName, 0, NSSS_MAX_SECRET_ID_LEN);
            }
         }

class='cKeyword'>class='cKeyword'>#ifndef LONG_VAL_TEST
         if(bUTF8Test)
         {
            /////////////////////////////////////////////////
            // run the REMOVE the UTF8 Credential Test Secret
            /////////////////////////////////////////////////
            if(aFlag)
            {
               printf("\nDo you want to REMOVE the UTF8 Credential Test Secret(y/n)?\n");
               c = getch();
               putchar(c);
               printf("\n\n");
            }
            else
            {
               c = 'y';
            }

            if(c == 'y' || c == 'Y')
            {
               strcpy(shSecret.pName, UTF8TestID);
               shSecret.type = SS_CREDENTIAL_TYPE_F; 
               // remove one secret at a time 
               if(rcode = NSSSRemoveSharedSecret(&shSecret, &ctx, &targetObjDN, pFlag, NULL))
               if(rcode = NSSSRemoveSecret(&ctx, &targetObjDN, pFlag, &secretID, NULL))
               {
                  printf("NSSSRemoveSharedSecret returned [%d] when removing [%s]\n\n", rcode, shSecret.pName);
                  printf("NSSSRemoveSecret returned [%d] when removing [%s]\n\n", rcode, secretID.id);
                  Pause();
               }
               else
               {
                  printf("\nRemoved [%s]\n", UTF8TestID);
               }
               
               memset(shSecret.pName, 0, NSSS_MAX_SECRET_ID_LEN);
            }
         }

      
         opCount++;


         printf("\n\n\n");

         printf("NUMBER OF THE LOOPS = %d\n", j+1);
         printf("NUMBER OF OPERATIONS COMPLETED = %d\n", opCount);
class='cKeyword'>#endif

      } /* end for */

class='cKeyword'>class='cKeyword'>#ifndef LONG_VAL_TEST
   }
   while(c == 'y' || c == 'Y');
class='cKeyword'>#endif

   endTime = time(NULL);

   printf("ELAPSED TIME IN SECONDS = [%ld]\n\n", (endTime - startTime));

/* ########################## CODE EXITS HERE ##################### */

ERROR_1:

   NSSSGetServiceInformation(&ctx, NULL, (pFlag | NSSS_DESTROY_CONTEXT_F), &gsInfo, NULL);

class='cKeyword'>class='cKeyword'>#ifdef N_PLAT_NLM
   NWCallsTerm(NULL);
class='cKeyword'>#endif

   if(secretIDList.data)
   {
      free(secretIDList.data);
   }

   if(key)   free(key);
   if(value) free(value);
   if(pSecret)   free(pSecret);
   if(tempSecretID)   free(tempSecretID);

   Pause();


/* ########################## CODE ENDS HERE ##################### */
}  




class='cKeyword'>class='cKeyword'>#ifdef N_PLAT_NLM
class='cKeyword'>class='cKeyword'>#ifdef FAST_ALLOC

/*  */
/*
 * NAME - ss_InitSSAllocTag
 *
 * DESCRIPTION
 *         
 */
static int ss_InitSSAllocTag(void)
{ /* beginning of the call */
/* ############################## CODE STARTS HERE ############################ */

   if (!(*ssclAllocTag.tag = (void *)AllocateResourceTag((void *)ssLSSCLModuleHandle,
            ssclAllocTag.name, ssclAllocTag.signature)))
   {
      return(NSSS_E_SYSTEM_FAILURE);
   }
   else
   {
      return(NSSS_SUCCESS);
   }

/* ########################## CODE ENDS HERE ##################### */
} /* end of ss_InitSSAllocTag */




/*
 * NAME - ss_GetAllocTag
 *
 * DESCRIPTION
 *         
 */
void    *ss_GetAllocTag(void)
{
   return (ssLSSCLAllocRTag);
}


class='cKeyword'>#endif /* FAST_ALLOC */



/*  */
/*
 * NAME - SSPINCanIUnload
 *
 * DESCRIPTION
 *         
 *         
 */
int    SSLDAPCLCanIUnload(void)
{
   return (NSSS_SUCCESS);   /*   For now   */
}



/*   Object modules compiled with bt=NETWARE in the WatCom IDE   */
/*   reference this symbol.  Make it a dummy routine so that it   */
/*   is resolved in the link.                                    */

void __WATCOM_Prelude(void){}





/*  */
/*
 * NAME - ss_GetLDAPPINThreadGroupID
 *
 * DESCRIPTION
 *         
 */
int   ss_GetLDAPCLThreadGroupID(void)
{
   return (ssLSSCLThreadGroupID);
}


/*  */
/*
 * NAME - ss_GetLDAPCLModuleHandle
 *
 * DESCRIPTION
 *         
 */
unsigned int   ss_GetLDAPCLModuleHandle(void)
{
   return (ssLSSCLModuleHandle);
}



/*  */
/*
 * NAME - UnloadLDAPSSCLMain
 *
 * DESCRIPTION
 *         
 *         
 */
void   UnloadLDAPSSCLMain(int   sigNbr)
{ /* beginning of the call */
/* ########################## DECLARATIONS START HERE ######################### */

   int      tgid;

/* ############################## CODE STARTS HERE ############################ */

   sigNbr = sigNbr;
   tgid = SetThreadGroupID(ssLSSCLThreadGroupID);

   NWCallsTerm(NULL);

   SetThreadGroupID(tgid);

/* ############################### CODE ENDS HERE ############################# */
} /* end of UnloadLDAPSSPINMain */



class='cKeyword'>#endif