sl@0: /* sl@0: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "clientsession.h" sl@0: #include sl@0: #include sl@0: #include "clientutils.h" sl@0: #include "fstokenservername.h" sl@0: sl@0: #ifdef SYMBIAN_AUTH_SERVER sl@0: sl@0: #ifdef __WINS__ sl@0: #include sl@0: #endif //__WINS__ sl@0: sl@0: #include sl@0: #endif // SYMBIAN_AUTH_SERVER sl@0: sl@0: // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ sl@0: // Tokentype session class for file based certificate store sl@0: // Connects and passes messages to the file store tokentype server sl@0: // Coded specifically for file store token type sl@0: // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ sl@0: sl@0: _LIT(KFSTokenServerImg,"fstokenserver"); sl@0: #ifdef SYMBIAN_AUTH_SERVER sl@0: #ifdef __WINS__ sl@0: _LIT(KFSNewTokenServerImg,"fstokenserver_useauth"); sl@0: #endif // __WINS__ sl@0: #endif // SYMBIAN_AUTH_SERVER sl@0: sl@0: RFileStoreClientSession::RFileStoreClientSession() sl@0: {} sl@0: sl@0: TInt RFileStoreClientSession::SendRequest(TFSTokenMessages aRequest, const TIpcArgs& aArgs) const sl@0: { sl@0: return SendReceive(aRequest, aArgs); sl@0: } sl@0: sl@0: void RFileStoreClientSession::SendAsyncRequest(TFSTokenMessages aRequest, const TIpcArgs& aArgs, TRequestStatus* aStatus) const sl@0: { sl@0: __ASSERT_ALWAYS(aStatus, FSTokenPanic(EBadArgument)); sl@0: sl@0: if (aStatus) sl@0: { sl@0: *aStatus = KRequestPending; sl@0: SendReceive(aRequest, aArgs, *aStatus); sl@0: } sl@0: } sl@0: sl@0: sl@0: // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ sl@0: // Client-server startup code sl@0: // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ sl@0: sl@0: static TInt StartServer(); // Forward declaration sl@0: // sl@0: // Connect to the server, attempting to start it if necessary sl@0: // sl@0: sl@0: #ifdef SYMBIAN_AUTH_SERVER sl@0: #ifdef __WINS__ sl@0: sl@0: static bool UseAuthServer(void); sl@0: sl@0: #endif // SYMBIAN_AUTH_SERVER sl@0: #endif // __WINS__ sl@0: sl@0: TInt RFileStoreClientSession::Connect(ETokenEnum aToken) sl@0: { sl@0: // The version is made up of three pieces of information: sl@0: // 1. iMajor - The token we want to talk to sl@0: // 2. iMinor - The protocol version number sl@0: // 3. iBuild - unused sl@0: TVersion version(aToken, KFSProtolVersion, 0); sl@0: sl@0: TInt retry=2; sl@0: for (;;) sl@0: { sl@0: TInt err = KErrNone; sl@0: #ifdef SYMBIAN_AUTH_SERVER sl@0: #ifdef __WINS__ sl@0: if(UseAuthServer()) sl@0: { sl@0: err = CreateSession(KFSNewTokenServerName, version, 1); sl@0: } sl@0: else sl@0: #endif // __WINS__ sl@0: #endif // SYMBIAN_AUTH_SERVER sl@0: { sl@0: err = CreateSession(KFSTokenServerName, version, 1); sl@0: } sl@0: sl@0: if (err!=KErrNotFound && err!=KErrServerTerminated) sl@0: return err; sl@0: if (--retry==0) sl@0: return err; sl@0: err=StartServer(); sl@0: if (err!=KErrNone && err!=KErrAlreadyExists) sl@0: return err; sl@0: } sl@0: } sl@0: sl@0: #ifdef SYMBIAN_AUTH_SERVER sl@0: #ifdef __WINS__ sl@0: sl@0: /*static*/ bool UseAuthServer(void) sl@0: { sl@0: bool useAuthServer = false; sl@0: sl@0: TUint32 useAuth = 0; sl@0: // For the emulator allow the constant to be patched via epoc.ini sl@0: UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty, sl@0: (TAny*)"KKeyStoreUseAuthServer", &useAuth); // read emulator property (if present) sl@0: if(useAuth) sl@0: { sl@0: useAuthServer = true; sl@0: } sl@0: return useAuthServer; sl@0: } sl@0: #endif // __WINS__ sl@0: #endif // SYMBIAN_AUTH_SERVER sl@0: sl@0: TInt StartServer() sl@0: { sl@0: // Server startup is different for WINS in EKA1 mode ONLY (lack of process sl@0: // emulation - we load the library in this instance sl@0: const TUidType serverUid(KNullUid, KNullUid, KUidFSTokenServer); sl@0: sl@0: RProcess server; sl@0: TInt error = KErrNone; sl@0: sl@0: #ifdef SYMBIAN_AUTH_SERVER sl@0: #ifdef __WINS__ sl@0: if(UseAuthServer()) sl@0: { sl@0: error = server.Create(KFSNewTokenServerImg, KNullDesC, serverUid); sl@0: } sl@0: else sl@0: #endif // __WINS__ sl@0: #endif // SYMBIAN_AUTH_SERVER sl@0: { sl@0: error = server.Create(KFSTokenServerImg, KNullDesC, serverUid); sl@0: } sl@0: sl@0: if (error != KErrNone) sl@0: { sl@0: return error; sl@0: } sl@0: sl@0: // Synchronise with the process to make sure it hasn't died straight away sl@0: TRequestStatus stat; sl@0: server.Rendezvous(stat); sl@0: if (stat != KRequestPending) sl@0: { sl@0: // logon failed - server is not yet running, so cannot have terminated sl@0: server.Kill(0); // Abort startup sl@0: } sl@0: else sl@0: { sl@0: // logon OK - start the server sl@0: server.Resume(); sl@0: } sl@0: sl@0: // Wait to synchronise with server - if it dies in the meantime, it sl@0: // also gets completed sl@0: User::WaitForRequest(stat); sl@0: sl@0: // We can't use the 'exit reason' if the server panicked as this sl@0: // is the panic 'reason' and may be '0' which cannot be distinguished sl@0: // from KErrNone sl@0: error = (server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); sl@0: server.Close(); sl@0: return (error); sl@0: } sl@0: