⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 odm.c

📁 IBM的Linux上的PKCS#11实现
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifdef PKCS64void PrintSlotInfo ( Slot_Info_t_64 *P ) {#elsevoid PrintSlotInfo ( Slot_Info_t *P ) {#endif#ifdef PKCS64  CK_SLOT_INFO_64       *ck = NULL;#else  CK_SLOT_INFO          *ck = NULL;#endif  ck = &(P->pk_slot);  if (! P->present) return;  DbgLog(DL3, "slot_number:             %d",      P->slot_number);  DbgLog(DL3, "present    :             %d",      P->present);  DbgLog(DL3, "pk_slot    :");  DbgLog(DL3, "     slotDescription:    '%.64s'", ck->slotDescription);  DbgLog(DL3, "     manufacturerID :    '%.32s'", ck->manufacturerID);  DbgLog(DL3, "     flags          :    %#x",     ck->flags);  DbgLog(DL3, "     hardwareVersion:    %d.%d",   ck->hardwareVersion.major, ck->hardwareVersion.minor);  DbgLog(DL3, "     firmwareVersion:    %d.%d",   ck->firmwareVersion.major, ck->firmwareVersion.minor);  DbgLog(DL3, "dll_location:            '%s'",    P->dll_location);  DbgLog(DL3, "slot_init_fcn:           '%s'",    P->slot_init_fcn);  DbgLog(DL3, "correlator:              '%s'",    P->correlator);  DbgLog(DL3, "global_sessions:         %#X",     P->global_sessions);  DbgLog(DL3, "************************************************");  return;}static BOOL BlankPadNoNull ( char *Dest, char *Src, u_int32 Len ) {  char *s = NULL;  /* Allocate Len bytes */  if ( (s = (char *) malloc(Len)) == NULL ) {    return FALSE;  }  /* Fill with blanks */  memset(s, ' ', Len);  /* Copy the string, but not the trailing NULL */  memcpy(s, Src, ( ( strlen(Src) < Len ) ? strlen(Src) : Len ) );  /* Copy Len bytes into Dest */  memcpy(Dest, s, Len);  /* Free storage */  free(s);  return TRUE;}BOOL ReadSlotInfoDB ( void ) {  CLASS_SYMBOL           csSlot;  char                   *odm_path = NULL;  struct ck_slot         *p        = NULL;  struct listinfo        lInfo;  u_int32                i;  unsigned char          Index     = 0;  unsigned char          ValidEntries = 0;  char                   StartDir[PATH_MAX + 1];  if ( odm_initialize() != 0 ) {     ErrLog(SLOTD_MSG(ODMFAIL,              "odm_initialize failed (0x%X)\n"), odmerrno);    return FALSE;  }  sprintf(StartDir,"%s",ODM_DIRECTORY);  if ( (odm_path = odm_set_path(StartDir)) == (char *) -1 ) {     ErrLog(SLOTD_MSG(ODMSET,            "Failed to set ODM path (0x%X)"), odmerrno);    return FALSE;  }  DbgLog(DL0, "Set ODM search path from %s to %s", odm_path, StartDir);  if ( (csSlot = odm_open_class( ck_slot_CLASS  )) < (CLASS_SYMBOL) 0 ) {    DbgLog(DL0, "ReadSlotInfoDB: odm_open_class() failed; %s (%d; %#x)", ODMConst(odmerrno), odmerrno, odmerrno);    if ( odm_path != NULL ) { free (odm_path); }    return FALSE;  }  if ( (p = get_ck_slot_list ( csSlot, "", &lInfo, NUMBER_SLOTS_MANAGED, 1) ) == (struct ck_slot *) -1 ) {    DbgLog (DL0, "ReadSlotInfoDB: get_ck_info_list() failed: %s (%d; %#x)", ODMConst(odmerrno), odmerrno, odmerrno);    if ( odm_path != NULL ) { free (odm_path); }    return FALSE;  }    if ( p == NULL ) {    DbgLog ( DL0, "ReadSlotInfoDB: get_ck_info_list() returned NULL");    if ( odm_path != NULL ) { free (odm_path); }    return FALSE;  }    DbgLog (DL0, "ReadSlotInfoDB: %d entries found in database", lInfo.num);  for ( i = 0; i < lInfo.num; i++ ) {    BOOL                   Res      = FALSE;#ifdef PKCS64    CK_SLOT_INFO_64       *pSlot    = NULL;#else    CK_SLOT_INFO          *pSlot    = NULL;#endif    /* Present */    /* Set in sinfo[] later, after we've verified Index */    if ( ! BooleanVal( &(p[i].Present[0]), sizeof(p[i].Present), &Res) ) {      DbgLog(DL0,"ReadSlotInfoDB: BooleanVal() failed for Present.\n");      continue;    }    if ( ! Res ) {      /* The database has this slot marked as not present */      DbgLog(DL2, "ReadSlotInfoDB: Slot '%s' (DB index %d) is marked as not present.  Skipping.", p[i].SlotDescription, i);      continue;    }      /* Verify that we've got space to store this entry */    if ( Index >= NUMBER_SLOTS_MANAGED ) {      DbgLog(DL0,"ReadSlotInfoDB: Database contains entries for at least %d present slots.  We support %d. Ignoring everything after %d.", 	      Index + 1, NUMBER_SLOTS_MANAGED, NUMBER_SLOTS_MANAGED );      break;    }    pSlot = &(sinfo[Index].pk_slot);    /* Check to see that our data structure isn't already in use */    if ( sinfo[Index].present ) {      DbgLog (DL0, "ReadSlotInfoDB: Multiple entries in the database for slot # %d.  Exiting.", Index);      DbgLog ( DL0,"ReadSlotInfoDB: My data structure isn't empty and it should be!");      if ( odm_path != NULL ) { free (odm_path); }      if ( p != NULL )        { free (p); }      return FALSE;    }    DbgLog(DL2, "ReadSlotInfoDB: Reading information for slot %d --> %s", Index, p[i].SlotDescription);    /* SlotNumber */    /* Warn the user that the SlotNumber field in the DB is depricated */#ifdef DEV    if ( p[i].SlotNumber != 0 ) {      WarnLog("ReadSlotInfoDB: The database contains a SlotNumber entry for a '%s' slot", p[i].SlotDescription );      WarnLog("ReadSlotInfoDB: The system ignores this value and assigns the slot number dynamically.");    }#endif    sinfo[Index].slot_number = Index;    /* Present */    /* No test here because we've already passed it above */    sinfo[Index].present = (CK_BOOL) TRUE;    /* Slot Description */     #pragma info(none)     if ( ! BlankPadNoNull ( (char *) &(pSlot->slotDescription[0]),			    &(p[i].SlotDescription[0]), 			    sizeof(pSlot->slotDescription) ) ) {     #pragma info(restore)       ErrLog(SLOTD_MSG(SLOTSKIP,               "ReadSlotInfoDB: Error reading SlotDescription '%s'.  Skipping."),              p[i].SlotDescription);       /* Null out the sinfo struct */      memset( pSlot, '\0', sizeof(*pSlot) );      sinfo[Index].present = (CK_BOOL) FALSE;      continue;    }    /* ManufacturerID */     #pragma info(none)     if ( ! BlankPadNoNull ( (char *) &(pSlot->manufacturerID[0]), 			    &(p[i].ManufacturerID[0]), 			    sizeof(pSlot->manufacturerID) ) ) {     #pragma info(restore)      DbgLog(DL0,"ReadSlotInfoDB: Error reading ManufacturerID '%s'.  Skipping.", p[i].ManufacturerID);      /* Null out the sinfo struct */      memset( pSlot, '\0', sizeof(*pSlot) );      sinfo[Index].present = (CK_BOOL) FALSE;      continue;    }    /* TokenPresent */    if ( ! BooleanVal( &(p[i].TokenPresent[0]), sizeof(p[i].TokenPresent), &Res) ) {      DbgLog(DL0,"ReadSlotInfoDB: BooleanVal() failed for TokenPresent.\n");      memset( pSlot, '\0', sizeof(*pSlot) );      sinfo[Index].present = (CK_BOOL) FALSE;      continue;    }    if ( Res ) { pSlot->flags |= (CKF_TOKEN_PRESENT); }    /* RemovableToken */    if ( ! BooleanVal( &(p[i].RemovableToken[0]), sizeof(p[i].RemovableToken), &Res) ) {      DbgLog(DL0,"ReadSlotInfoDB: BooleanVal() failed for RemovableToken.\n");      memset( pSlot, '\0', sizeof(*pSlot) );      sinfo[Index].present = (CK_BOOL) FALSE;      continue;    }    if ( Res ) { pSlot->flags |= (CKF_REMOVABLE_DEVICE); }    /* HardwareSlot */    if ( ! BooleanVal( &(p[i].HardwareSlot[0]), sizeof(p[i].HardwareSlot), &Res) ) {      DbgLog(DL0,"ReadSlotInfoDB: BooleanVal() failed for HardwareSlot.\n");      memset( pSlot, '\0', sizeof(*pSlot) );      sinfo[Index].present = (CK_BOOL) FALSE;      continue;    }    if ( Res ) { pSlot->flags |= (CKF_HW_SLOT); }     /* HardwareVersion */    pSlot->hardwareVersion.major = (CK_BYTE) p[i].HwVersionMajor;    pSlot->hardwareVersion.minor = (CK_BYTE) p[i].HwVersionMinor;    /* FirmwareVersion */    pSlot->firmwareVersion.major = (CK_BYTE) p[i].FwVersionMajor;    pSlot->firmwareVersion.minor = (CK_BYTE) p[i].FwVersionMinor;    /* DLLLocation */    {      struct stat64 statbuf;      int Err;      strncpy ( &(sinfo[Index].dll_location[0]), p[i].SlotDll, 		( (strlen(p[i].SlotDll) > sizeof(sinfo[Index].dll_location)) 		  ? (sizeof(sinfo[Index].dll_location)) 		  : (strlen(p[i].SlotDll) ) ) );      /* Set the last character in the array to NULL since strncpy may mor may not copy the trailing NULL */      sinfo[Index].dll_location[ sizeof(sinfo[Index].dll_location) - 1] = '\0';      if ( stat64( sinfo[Index].dll_location, &statbuf ) < 0 ) {	/* File not found, or other error */	#pragma info(none)	  Err = errno;	#pragma info(restore)	if ( Err == ENOENT ) {	  WarnLog ( "***** ReadSlotInfoDB: %s: file not found (%s).  Skipping DB entry.", sinfo[Index].dll_location, SysError(Err) );	} else {	  DbgLog (DL0, "***** ReadSlotInfoDB: looking at %s, stat64() returned %s (%d; %#x)", sinfo[Index].dll_location, SysError(Err), Err, Err);	}	memset( pSlot, '\0', sizeof(*pSlot) );	sinfo[Index].present = (CK_BOOL) FALSE;	continue;      }    } /* end DLLLocation unconditional block */    /* SlotInitFcn */    /* FIXME: Make sure this is non-NULL */    strncpy( &(sinfo[Index].slot_init_fcn[0]), &(p[i].SlotInitFcn[0]), 	     ( strlen(p[i].SlotInitFcn) > sizeof(sinfo[Index].slot_init_fcn) )	     ? sizeof(sinfo[Index].slot_init_fcn)	     : strlen(p[i].SlotInitFcn) );    /* Set the last character in the array to NULL since strncpy may mor may not copy the trailing NULL */    sinfo[Index].slot_init_fcn[ sizeof(sinfo[Index].slot_init_fcn) - 1 ] = '\0';    /* Correlator */    /* FIXME: Make sure this is non-NULL */    strncpy( &(sinfo[Index].correlator[0]), &(p[i].Correlator[0]), 	     ( strlen(p[i].Correlator) > sizeof(sinfo[Index].correlator) )	     ? sizeof(sinfo[Index].correlator)	     : strlen(p[i].Correlator) );    /* Set the last character in the array to NULL since strncpy may mor may not copy the trailing NULL */    sinfo[Index].correlator[ sizeof(sinfo[Index].correlator) - 1 ] = '\0';            PrintSlotInfo( &(sinfo[Index]) );    Index++;  } /* end for i */  NumberSlotsInDB = Index;  if ( p != NULL )        { free(p); }  /* Do we have a memory leak here? */  if ( odm_path != NULL ) {     odm_set_path(odm_path);    free (odm_path);  }  return TRUE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -