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

📄 stafhandlemanager.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    rc = gServiceManagerPtr->getAuthenticator(authenticator, service);    if (rc != kSTAFOk)    {        // The authenticator service is not registered        if (authenticateType == kCredentials)        {            // Return an error            return STAFServiceResult(rc, authenticator);        }        else        {   // Authentication data was passed in.            // Don't return an error.  Set the authenticator to "none"            // and the userIdentifier to "anonymous".             authenticator = gNoneString;            userIdentifier = gAnonymousString;            return serviceResult;        }    }    if (authenticateType == kData)    {        // Get cached authentication information, if any, for the remote        // machine's handle.        STAFString theKey = machine.toLowerCase() + ";" + STAFString(handle);        STAFMutexSemLock remoteHandle(fRemoteHandleMapSem);        // If authentication information for remote machine/handle has been        // cached, if it's the same, then there's no need to re-authenticate.        if (fRemoteAuthHandleMap.find(theKey) != fRemoteAuthHandleMap.end())        {            AuthenticationInfo &authInfo = fRemoteAuthHandleMap[theKey];            if ((authInfo.authenticator == authenticator.toUpperCase()) &&                (authInfo.userIdentifier == userIdentifier) &&                (authInfo.authenticationData == authenticationData))            {                   return serviceResult;            }        }    }    // Submit an Authenticate request to the HANDLE service    STAFServiceRequest authRequestInfo;    authRequestInfo.fMachine = "local"; // Must be issued from local system    authRequestInfo.fMachineNickname = *gMachineNicknamePtr;    authRequestInfo.fHandle = gSTAFProcHandle; // A handle on the local system    authRequestInfo.fHandleName = gHandleManagerPtr->name(gSTAFProcHandle);    authRequestInfo.fRequest = "AUTHENTICATE USER " + userIdentifier;    authRequestInfo.fRequestNumber = 0;    authRequestInfo.fDiagEnabled = gDiagManagerPtr->getEnabled();    authRequestInfo.fTrustLevel = 5;    // Authenticate requires trust level 5    authRequestInfo.fAuthenticator = gNoneString;    authRequestInfo.fUserIdentifier = gAnonymousString;    authRequestInfo.fUser = gUnauthenticatedUser;    authRequestInfo.fInterface = "local";    authRequestInfo.fLogicalInterfaceID = "local";    authRequestInfo.fPhysicalInterfaceID = "local";    authRequestInfo.fEndpoint = "local" + gSpecSeparator + "local";    gHandleManagerPtr->variablePool(authRequestInfo.fHandle,                                     authRequestInfo.fRequestVarPool);    authRequestInfo.fSourceSharedVarPool =        STAFVariablePoolPtr(new STAFVariablePool, STAFVariablePoolPtr::INIT);    authRequestInfo.fLocalSharedVarPool = *gSharedVariablePoolPtr;    authRequestInfo.fLocalSystemVarPool = *gGlobalVariablePoolPtr;    if (authenticateType == kCredentials)        authRequestInfo.fRequest += " CREDENTIALS " + authenticationData;    else        authRequestInfo.fRequest += " DATA " + authenticationData;    serviceResult = service->submitRequest(authRequestInfo);    if (serviceResult.fRC == kSTAFOk)    {        // User was successfully authenticated        STAFString authData = authenticationData;        if (authenticateType == kCredentials)        {            // Assign authentication data returned by the Authenticator service            authData = serviceResult.fResult;            // Set handle variable STAF/Handle/User=authenticator://user            STAFVariablePoolPtr handlePool;            rc = variablePool(handle, handlePool);            handlePool->set("STAF/Handle/User",                            authenticator + gSpecSeparator + userIdentifier);        }                rc = gHandleManagerPtr->cacheAuthenticationInfo(machine, handle,             authenticator, userIdentifier, authData);    }    return serviceResult;}// STAFHandleManager::unAuthenticate//// Unauthenticate the local handle//// Parameters://   handle  - handle (Input)//// Returns://   rc 0 if successfully un-authenticate the handle//   Non-zero rc if could not un-authenticate the handle and the handle//       in the result.STAFServiceResult STAFHandleManager::unAuthenticate(const STAFHandle_t handle){    {        STAFMutexSemLock handleLock(fHandleListSem);        if (fHandleList.find(handle) == fHandleList.end())        {            return STAFServiceResult(kSTAFHandleDoesNotExist, handle);        }        HandleData &theHandle = fHandleList[handle];        theHandle.authenticator = gNoneString;        theHandle.userIdentifier = gAnonymousString;        theHandle.authenticationData = "";    }    // Set handle variable STAF/Handle/User=none://anonymous        STAFVariablePoolPtr handlePool;    STAFRC_t rc = variablePool(handle, handlePool);    if (rc == kSTAFOk)        handlePool->set("STAF/Handle/User", gUnauthenticatedUser);    return STAFServiceResult(kSTAFOk);}// STAFHandleManager::cacheAuthenticationInfo//// Cache authentication information for the machine's handle.  If the// machine is local, store the authentication information in the// local Handle List.  If the machine is remote, store the authentication// information in the Remote Authenticated Handle Map. //// Parameters://   machine - machine name (Input)//   handle  - handle (Input)//   authenticator - name of authenticator service (Input)//   userIdentifier - name of the user (Input)//   authenticationData - authentication data (Input)//// Returns://   rc 0 if authentication information was cached successfully//   Non-zero rc if authentication information was not cached successfullySTAFRC_t STAFHandleManager::cacheAuthenticationInfo(                            const STAFString &machine,                            const STAFHandle_t handle,                            const STAFString &authenticator,                            const STAFString &userIdentifier,                            const STAFString &authenticationData){    if (isLocalMachine(machine, 1))    {        STAFMutexSemLock handleLock(fHandleListSem);                if (fHandleList.find(handle) == fHandleList.end())        {            // Should never happen            return kSTAFHandleDoesNotExist;        }        HandleData &theHandle = fHandleList[handle];        theHandle.authenticator = authenticator;        theHandle.userIdentifier = userIdentifier;        theHandle.authenticationData = authenticationData;    }    else    {        // Cache the authentication information for the remote machine/handle        // in the fRemoteAuthHandleMap.        STAFString theKey = machine.toLowerCase() + ";" + STAFString(handle);        AuthenticationInfo authInfo(authenticator, userIdentifier,                                    authenticationData);        STAFMutexSemLock remoteHandleLock(fRemoteHandleMapSem);        fRemoteAuthHandleMap[theKey] = authInfo;        // XXX: Register for garbage collection so that when handle or machine        // is unregistered, it can be removed from the fRemoteAuthHandleMap.    }    return kSTAFOk;}// STAFHandleManager::isAuthenticated//// Check if the local handle is authenticated.//// Parameters://   handle  - handle (Input)//// Returns://   0 if the local handle is not authenticated.//   kSTAFHandleAlreadyAuthenticated if the handle is already authenticated.//   kSTAFHandleDoesNotExist if the local handle does not exist.STAFRC_t STAFHandleManager::isAuthenticated(                            const STAFHandle_t handle){    STAFMutexSemLock handleLock(fHandleListSem);    if (fHandleList.find(handle) == fHandleList.end())    {        // Should never happen        return kSTAFHandleDoesNotExist;    }    HandleData &theHandle = fHandleList[handle];    if (theHandle.authenticator == gNoneString)        return kSTAFOk;    else        return kSTAFHandleAlreadyAuthenticated;}// STAFHandleManager::getAuthenticationInfo//// Get the authentication information for a local handle.//// Parameters://   handle  - handle (Input)//   authenticator - name of authenticator service (Output)//   userIdentifier - name of the user (Output)//   authenticationData - authentication data (Output)//// Returns://   rc 0 if authentication info for a local handle was retrieved successfully//   Non-zero rc if could not get authentication info for a local handleSTAFRC_t STAFHandleManager::getAuthenticationInfo(                            const STAFHandle_t handle,                            STAFString &authenticator,                            STAFString &userIdentifier,                            STAFString &authenticationData){    STAFMutexSemLock handleLock(fHandleListSem);    if (fHandleList.find(handle) == fHandleList.end())    {        // Should never happen        authenticator = gNoneString;        userIdentifier = gAnonymousString;        return kSTAFHandleDoesNotExist;    }    HandleData &theHandle = fHandleList[handle];    authenticator = theHandle.authenticator;    userIdentifier = theHandle.userIdentifier;    authenticationData = theHandle.authenticationData;    return kSTAFOk;}void STAFHandleManager::gcPolling(){    int interval = 60000; // XXX add an operational parameter to override    gThreadManagerPtr->sleepCurrentThread(5000);        try    {         while (1)         {             gGCPollingSem->wait(interval);                          if (!gContinueGCPolling)                 return;                          PollingDataList pollingDataList = getPollingDataListCopy();             PollingDataList::iterator iter;             for (iter = pollingDataList.begin();                  iter != pollingDataList.end(); iter++)             {                 PollingData notifiee(*iter);                 STAFString machine = notifiee.machine;                                  STAFResultPtr result =                      gSTAFProcHandlePtr->submit(machine,                                                "PING",                                                "PING");                 if (result->rc != kSTAFOk)                 {                     STAFString request = "STAF_CALLBACK HANDLEDELETED HANDLE ";                     request += notifiee.handle;                     request += " MACHINE ";                     request += machine;                     request += " UUID ";                     request += notifiee.uuid;                     request += " KEY ";                     request += notifiee.key;                     STAFResultPtr result =                          gSTAFProcHandlePtr->submit("local",                                                    notifiee.notifyService,                                                    request,                                                    kSTAFReqFireAndForget);                                 gHandleManagerPtr->deletePolling(notifiee.handle,                                                      notifiee.machine,                                                      notifiee.uuid,                                                      notifiee.notifyService);                 }             }        }    }    catch (STAFException &se)    {        se.trace("STAFHandleManager::gcPolling()");    }    catch (...)    {        STAFTrace::trace(kSTAFTraceError, "Caught unknown exception in "                         "STAFHandleManager::gcPolling()");    }}unsigned int HandleMonitorThread(void *data){    pHandleManager->gcPolling();    return kSTAFUnknownError;}

⌨️ 快捷键说明

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