10 #if defined( INC_ALL )
35 int initDispatchODBC(
DBMS_INFO *dbmsInfo );
37 #define initDispatchODBC( dbmsInfo ) CRYPT_ERROR
39 #if defined( USE_DATABASE )
40 int initDispatchDatabase(
DBMS_INFO *dbmsInfo );
42 #define initDispatchDatabase( dbmsInfo ) CRYPT_ERROR
60 assert(
isWritePtr( featureFlags,
sizeof(
int ) ) );
69 status = dbmsInfo->openDatabaseBackend( dbmsStateInfo, name, nameLen,
70 options, featureFlags );
89 dbmsInfo->closeDatabaseBackend( dbmsStateInfo );
101 const int commandLength = ( command != NULL ) ? strlen( command ) : 0;
105 assert( ( command == NULL && commandLength == 0 && \
108 assert( ( boundData == NULL ) || \
113 command == NULL && commandLength == 0 ) || \
127 status = dbmsInfo->performUpdateBackend( dbmsStateInfo, command,
128 commandLength, boundData,
163 const int commandLength = ( command != NULL ) ? strlen( command ) : 0;
167 assert( ( command == NULL && commandLength == 0 && \
171 assert( ( data == NULL && dataLength == NULL ) || \
173 assert( ( boundData == NULL ) || \
179 command == NULL && commandLength == 0 ) || \
185 REQUIRES( ( data == NULL && dataMaxLength == 0 && \
186 dataLength == NULL ) || \
187 ( data != NULL && dataMaxLength >= 16 && \
189 dataLength != NULL ) );
210 memset( data, 0,
min( 16, dataMaxLength ) );
215 status = dbmsInfo->performQueryBackend( dbmsStateInfo, command,
216 commandLength, data, dataMaxLength,
217 dataLength, boundData,
218 queryEntry, queryType );
223 if( dataLength != NULL && \
226 DEBUG_DIAG((
"Database backend return invalid data size" ));
228 memset( data, 0,
min( 16, dataMaxLength ) );
250 return( performQuery( dbmsInfo, command, NULL, 0, NULL, NULL,
251 queryEntry, queryType ) );
287 #define SQL_ESCAPE '\''
298 assert(
isWritePtr( bufPos,
sizeof(
int ) ) );
307 if( ( ch & 0x7F ) <
' ' )
316 if( ( ch ==
'\'' && escapeQuotes ) || \
317 ch ==
'\\' || ch ==
';' || ch ==
'%' )
320 buffer[ position++ ] = SQL_ESCAPE;
321 if( position >= bufMaxLen )
331 if( ch !=
'|' && ch !=
'{' && ch !=
'}' )
339 if( position >= bufMaxLen )
347 static
int copyStringArg(
OUT_BUFFER( bufMaxLen, *bufPos )
char *buffer,
353 int index, position = 0;
356 assert(
isWritePtr( bufPos,
sizeof(
int ) ) );
357 assert(
isReadPtr(
string, stringLen ) );
369 for( index = 0; index < stringLen && \
374 status = copyChar( buffer + position, bufMaxLen - position,
375 &charsWritten,
string[ index ],
TRUE );
378 position += charsWritten;
379 if( position > bufMaxLen )
386 ENSURES( index < FAILSAFE_ITERATIONS_MAX );
403 int inPos, outPos = 0, status =
CRYPT_OK;
406 assert(
isWritePtr( outLength,
sizeof(
int ) ) );
407 assert(
isReadPtr( input, inputLength ) );
413 memset( output, 0,
min( 16, outMaxLength ) );
420 if( input[ inPos ] ==
'$' )
430 static const NAMEMAP_INFO nameMapTbl[] = {
431 {
"C", 1,
"C", 1 }, {
"SP", 2,
"SP", 2 },
432 {
"L", 1,
"L", 1 }, {
"O", 1,
"O", 1 },
433 {
"OU", 2,
"OU", 2 }, {
"CN", 2,
"CN", 2 },
434 {
"email", 5,
"email", 5 }, {
"uri", 3,
"email", 5 },
435 {
"date", 4,
"validTo", 7 },
436 { NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 }
438 const int fieldPos = inPos + 1;
439 const char *fieldName = input + fieldPos;
446 while( inPos < inputLength &&
isAlpha( input[ inPos ] ) )
448 length = inPos - fieldPos;
449 if( length <= 0 || length > 5 )
454 for( i = 0; nameMapTbl[ i ].sourceName != NULL && \
459 !
strCompare( fieldName, nameMapTbl[ i ].sourceName, \
464 if( nameMapTbl[ i ].sourceName == NULL )
471 status = copyStringArg( output + outPos, outMaxLength - outPos,
472 &length, nameMapTbl[ i ].destName,
480 status = copyChar( output + outPos, outMaxLength - outPos,
481 &length, input[ inPos++ ],
FALSE );
487 ENSURES( inPos < FAILSAFE_ITERATIONS_MAX );
490 output[ outPos ] =
'\0';
538 if( ( offset = strFindCh( name, nameLen,
':' ) ) < 0 && \
539 ( offset = strFindCh( name, nameLen,
'@' ) ) < 0 )
542 nameInfo->name = (
char * ) name;
552 memcpy( nameInfo->userBuffer, name, length );
553 nameInfo->user = nameInfo->userBuffer;
554 nameInfo->userLen =
length;
558 ENSURES( name[ offset ] ==
':' || name[ offset ] ==
'@' );
559 if( name[ offset++ ] ==
':' )
561 offset2 = strFindCh( name + offset, nameLen - offset,
'@' );
563 offset2 = nameLen -
offset;
567 memcpy( nameInfo->passwordBuffer, name + offset, length );
568 nameInfo->password = nameInfo->passwordBuffer;
569 nameInfo->passwordLen =
length;
570 offset += offset2 + 1;
571 if( offset >= nameLen )
576 offset2 = strFindCh( name + offset, nameLen - offset,
'/' );
584 memcpy( nameInfo->serverBuffer, name + offset, length );
585 nameInfo->server = nameInfo->serverBuffer;
586 nameInfo->serverLen =
length;
587 offset += offset2 + 1;
591 if( offset < nameLen )
593 length = nameLen -
offset;
596 memcpy( nameInfo->nameBuffer, name + offset, length );
597 nameInfo->name = nameInfo->nameBuffer;
598 nameInfo->nameLen =
length;
610 DBMS_INFO *dbmsInfo = keysetInfoPtr->keysetDBMS;
623 status = initDispatchODBC( dbmsInfo );
628 status = initDispatchDatabase( dbmsInfo );
638 dbmsInfo->openDatabaseFunction = openDatabase;
639 dbmsInfo->closeDatabaseFunction = closeDatabase;
640 dbmsInfo->performUpdateFunction = performUpdate;
641 dbmsInfo->performStaticUpdateFunction = performStaticUpdate;
642 dbmsInfo->performQueryFunction = performQuery;
643 dbmsInfo->performStaticQueryFunction = performStaticQuery;
646 if( ( keysetInfoPtr->keyData = \
651 dbmsInfo->
stateInfo = keysetInfoPtr->keyData;
667 if( keysetInfoPtr->keyData != NULL )
669 memset( keysetInfoPtr->keyData, 0, keysetInfoPtr->keyDataSize );
670 clFree(
"endDbxSession", keysetInfoPtr->keyData );
671 keysetInfoPtr->keyData = NULL;