// Takes ownership of given IdentityProvider(!) TInt CSenBaseIdentityManager::RegisterIdentityProviderL( CSenIdentityProvider* apIdp ) { if(!apIdp) { return KErrArgument; // NULL given! } CleanupStack::PushL(apIdp); // try to register into default identity // null check done, above TInt retVal = IdentityL().RegisterIdentityProviderL(apIdp); CleanupStack::Pop(); // apIdp, ownership elsewhere // check success: if ( retVal == KErrNone) { // ownership taken, pop from stack: // try to serialize owned object TInt notifyLeaveCode(KErrNone); TRAP(notifyLeaveCode, iManager.NotifyFrameworksL(KSenEventRegisterIdentityProvider, apIdp)); if ( WriteDatabase() != KErrNone) { retVal = KErrWrite; } } return retVal; }
TBool CSenBaseIdentityManager::AssociateServiceL( const TDesC8& aServiceID, const TDesC8& aProviderID ) { TBool retVal = IdentityL().AssociateServiceL(aServiceID, aProviderID); if (retVal) { if (KErrNone != WriteDatabase()) { retVal = EFalse; } } return retVal; }
TInt CSenBaseIdentityManager::UpdateIdentityProviderL(CSenIdentityProvider& aIdp) { TInt retVal = IdentityL().UpdateIdentityProviderL(aIdp); // check success: if ( retVal == KErrNone) { // ownership taken, pop from stack: // try to serialize owned object if ( WriteDatabase() != KErrNone) { retVal = KErrWrite; } } return retVal; }
void CSenBaseIdentityManager::LoadFromL(TDesC& aFile, CSenXmlReader& aReader) { RFs fss; User::LeaveIfError(fss.Connect()); CleanupClosePushL(fss); aReader.SetContentHandler(*this); SetReader(aReader); TInt leaveCode(KErrNone); #if defined( EKA2 ) || defined( RD_SECURE_PRIV_DATA ) TBuf<KMaxPath> file; fss.CreatePrivatePath(EDriveC); fss.PrivatePath(file); file.Append(aFile); TRAP(leaveCode, aReader.ParseL(fss, file)); #else TRAP(leaveCode, aReader.ParseL(fss, aFile)); #endif #ifdef _SENDEBUG if(leaveCode == KErrNotFound) { TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"- The senidentities.xml does not exist!"); TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"- New file will be generated."); } else if(leaveCode != KErrNone) { TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("- Parsing of senidentities.xml leaved: %d"), leaveCode)); } else { TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"- Identity database (senidentities.xml) successfully read."); } #else leaveCode=0; // this is a decision: we are not interested // of invalid input in read/parse phase #endif WriteDatabase(); // Always validate by saving CleanupStack::PopAndDestroy(); // fss }
TInt CSenBaseIdentityManager::UnregisterIdentityProviderL( CSenIdentityProvider& aIdp ) { TInt retVal = IdentityL().UnregisterIdentityProviderL( aIdp ); if ( retVal == KErrNone ) { TInt notifyLeaveCode(KErrNone); TRAP(notifyLeaveCode, iManager.NotifyFrameworksL(KSenEventUnregisterIdentityProvider, &aIdp)); // if (KErrNone != WriteDatabase() ) // { // retVal = EFalse; // } retVal = WriteDatabase(); } return retVal; }
void OnBackgroundTimer(time_t) { if (dirty) WriteDatabase(); dirty = false; }
int WriteDatabase(FILE *f, TDbmListEntry *list, int level) { int i; int j; TDbmListEntry *node; int ret; for(i=0; i< list->current_order; i++) { node = list->order[i]; switch(node->entry_type) { case DBM_ENTRY_VAR_INT : if(node->comment!=NULL) { fprintf(f, "\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s", node->comment); } fprintf(f,"\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s = %d\n", node->key, node->value.int_val); break; case DBM_ENTRY_VAR_REAL : if(node->comment!=NULL) { fprintf(f, "\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s", node->comment); } fprintf(f,"\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s = %f\n", node->key, node->value.real_val); break; case DBM_ENTRY_VAR_STRING : if(node->comment!=NULL) { fprintf(f, "\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s", node->comment); } fprintf(f,"\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s = \"%s\"\n", node->key, node->value.str_val); break; case DBM_ENTRY_VAR_IDENT : if(node->comment!=NULL) { fprintf(f, "\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s", node->comment); } fprintf(f,"\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s = %s\n", node->key, node->value.str_val); break; case DBM_ENTRY_VAR_BOOL : if(node->comment!=NULL) { fprintf(f, "\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s", node->comment); } fprintf(f,"\n"); for(j=0;j<level;j++) fprintf(f," "); if(node->value.int_val==1) fprintf(f,"%s = TRUE\n", node->key); else fprintf(f,"%s = FALSE\n", node->key); break; case DBM_ENTRY_LIST : if(node->comment!=NULL) { fprintf(f, "\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s", node->comment); } fprintf(f,"\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"%s {\n", node->key); ret = WriteDatabase(f, node, level+1); if(ret==-1) { RaiseError(DBM_UPDATE_WRITE_ERROR); return(-1); } fprintf(f,"\n"); for(j=0;j<level;j++) fprintf(f," "); fprintf(f,"}\n"); break; default : RaiseError(DBM_UPDATE_WRITE_ERROR); return(-1); } } return(0); }
void GPodDevice::FinishDelete(bool success) { WriteDatabase(success); ConnectedDevice::FinishDelete(success); }
TInt CSenBaseIdentityManager::AuthenticationForL( CSenIdentityProvider& aProvider, TPckgBuf<TSenAuthentication>& aResponse) { TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"CSenBaseIdentityManager::AuthenticationForL"); TPtrC8 user = aProvider.AuthzID(); if (user == KNullDesC8) { user.Set(aProvider.AdvisoryAuthnID()); } if (!iShowPasswordDialog) { TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"Not allowed to show password dialog"); HBufC8* pDecodedPassword = SenXmlUtils::DecodeHttpCharactersLC(aProvider.Password()); TPtrC8 decodedPassword = pDecodedPassword->Des(); aResponse().iUsername.Append((const TUint8*)user.Ptr(), user.Size()); aResponse().iPassword.Append((const TUint8*)decodedPassword.Ptr(), decodedPassword.Size()); CleanupStack::PopAndDestroy(); // delete pDecodedPassword return KErrNone; } RNotifier notifier; User::LeaveIfError(notifier.Connect()); CleanupClosePushL(notifier); TPckgBuf<TAuthenticationDlgRequest>* request = new(ELeave)TPckgBuf<TAuthenticationDlgRequest>(); CleanupStack::PushL(request); // convert username to unicode HBufC* pUserAsUnicode = SenXmlUtils::ToUnicodeLC(user); // push TPtrC username = pUserAsUnicode->Des(); // decode password HBufC8* pDecodedPassword = SenXmlUtils::DecodeHttpCharactersLC(aProvider.Password()); TPtrC8 decodedPassword = pDecodedPassword->Des(); // convert decoded password to unicode HBufC* pPasswordAsUnicode = SenXmlUtils::ToUnicodeLC(decodedPassword); // push TPtrC password = pPasswordAsUnicode->Des(); // set data to request (*request)().SetData(username, password); CleanupStack::PopAndDestroy(3); // delete pPasswordAsUnicode, pDecodedPassword, pUserAsUnicode TPckgBuf<TAuthenticationDlgResponse>* response = new(ELeave)TPckgBuf<TAuthenticationDlgResponse>(); CleanupStack::PushL(response); TRequestStatus reqStatus; notifier.StartNotifierAndGetResponse(reqStatus, KSenNotifierPluginUID, *request, *response); TBool illegalUsername = EFalse; HBufC8* pUsernameUtf8 = NULL; HBufC8* pPasswordUtf8 = NULL; User::WaitForRequest(reqStatus); notifier.Close(); if(reqStatus.Int() == KErrNone) { if((*response)().OkButtonPressed()) { TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,(_L("User pressed OK Button in Password dialog"))); pUsernameUtf8 = SenXmlUtils::ToUtf8LC((*response)().Username()); pPasswordUtf8 = SenXmlUtils::ToUtf8LC((*response)().Password()); TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("Username: %S"), pUsernameUtf8)); TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("Password: %S"), pPasswordUtf8 )); HBufC8* pEncodedUsername = NULL; illegalUsername = SenXmlUtils::EncodeHttpCharactersL(*pUsernameUtf8, pEncodedUsername); if (illegalUsername) { TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,(_L("Username included illegal characters."))); delete pEncodedUsername; pEncodedUsername = NULL; } #ifdef _SENDEBUG else { TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"Username did NOT include illegal characters."); } #endif //Check if iilegal chars are there then return if (!illegalUsername) { if(user != *pUsernameUtf8) { // User modified the username in the dialog prompt(!) // We have to save it right away, because there is // no in-memory/session based member variables in // components calling identity manager (sec mechs and // in ID-WSF AS client! TLSLOG_L(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,"Username changed. Saving new username."); // Use Advisory only if AuthzID is not available if (aProvider.AuthzID() == KNullDesC8 && aProvider.AdvisoryAuthnID() != KNullDesC8) { aProvider.SetUserInfoL(aProvider.AuthzID(), *pUsernameUtf8, aProvider.Password()); } else { // There was at least AuthzID available, and possibly // also advisory value. Any way, if // We have to NULL advisory value (set it to KNullDesC8), // because if both were available, then user was // prompted to allow modification of AuthzID AND // if advisory was changed in service (is no longer // valid), there would NOT be any way for end-user // to change (remove) it(!) CSenElement& element = aProvider.AsElement(); delete element.RemoveElement(KSenIdpAdvisoryAuthnIdLocalname); aProvider.SetUserInfoL(*pUsernameUtf8, KNullDesC8, aProvider.Password()); } // serialize changed username into sensessions.xml database immediately WriteDatabase(); } if (AllowSavePasswordL()) { HBufC8* pEncodedPassword = SenXmlUtils::EncodeHttpCharactersLC(*pPasswordUtf8); #ifdef _SENDEBUG if(pEncodedPassword) { TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8("Encoded password: %S"), pEncodedPassword)); } #endif if(pEncodedPassword) { aProvider.SetUserInfoL(aProvider.AuthzID(), aProvider.AdvisoryAuthnID(), *pEncodedPassword); } WriteDatabase(); CleanupStack::PopAndDestroy(1); // pEncodedPassword } } aResponse().iUsername.Zero(); aResponse().iPassword.Zero(); if (!illegalUsername) { aResponse().iUsername.Copy(pUsernameUtf8->Des()); aResponse().iPassword.Copy(pPasswordUtf8->Des()); } CleanupStack::PopAndDestroy(2); // pPasswordUtf8, pUsernameUtf8 } else { TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,(_L("User pressed Cancel Button in Password dialog"))); } } else if(reqStatus.Int() == KErrNotFound) { TLSLOG(KSenCoreServiceManagerLogChannelBase , KMinLogLevel,(_L("Password dialog plugin notifier impl. was not found"))); } else { TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel, _L8(" Notifier plugin for 'Password' dialog returned an error: %d"), reqStatus.Int())); } CleanupStack::PopAndDestroy(2); // request, response; CleanupStack::Pop(); // notifier if (illegalUsername) return KErrArgument; return reqStatus.Int(); }
void CreateDatabase( struct Connection* conn ) { for ( int i=0; i<MAX_ROWS; i++ ) { struct Address addr = { .id = i, .set = 0 }; conn->db->rows[ i ] = addr; } } void SetDatabase( struct Connection* conn, int id, const char* name, const char* email ) { struct Address* addr = &conn->db->rows[ id ]; if ( addr->set ) { Die( "Already set, delete it first" ); } addr->set = 1; char* res = strncpy( addr->name, name, MAX_DATA ); if ( !res ) { Die( "Name copy failed." ); } res = strncpy( addr->email, email, MAX_DATA ); if ( !res ) { Die( "Email copy failed." ); } } void GetDatabase( struct Connection* conn, int id ) { struct Address* addr = &conn->db->rows[ id ]; if ( addr->set ) { PrintAddress( addr ); } else { Die( "ID is not set." ); } } void DeleteDatabase( struct Connection* conn, int id ) { struct Address addr = { .id = id, .set = 0 }; conn->db->rows[ id ] = addr; } void ListDatabase( struct Connection* conn ) { struct Database* db = conn->db; for ( int i=0; i<MAX_ROWS; i++ ) { struct Address* cur = &db->rows[ i ]; if ( cur->set ) { PrintAddress( cur ); } } } int main( int argc, char* argv[] ) { if ( argc < 3 ) { Die( "USAGE: ex17 <dbfile> <action> [action params]" ); } char* filename = argv[ 1 ]; char action = argv[ 2 ][ 0 ]; struct Connection* conn = OpenDatabase( filename, action ); int id = 0; if ( argc > 3 ) { id = atoi( argv[ 3 ] ); } if ( id>= MAX_ROWS ) { Die( "There is not that many records." ); } if ( action == 'c' ) { CreateDatabase( conn ); WriteDatabase( conn ); } else if ( action == 'g' ) { if ( argc != 4 ) { Die( "Need an id to get" ); } else { GetDatabase( conn, id ); } } else if ( action == 's' ) { if ( argc != 6 ) { Die( "Need id, name, email to set" ); } else { SetDatabase( conn, id, argv[ 4 ], argv[ 5 ] ); WriteDatabase( conn ); } } else if ( action == 'd' ) { if ( argc != 4 ) { Die( "Need id to delete" ); } else { DeleteDatabase( conn, id ); WriteDatabase( conn ); } } else if ( action == 'l' ) { ListDatabase( conn ); } else { Die( "Invalid action, only: c=create, g=get, d=delete, l=list" ); } CloseDatabase( conn ); return 0; }