VJSArray buildArrFromUsers(VJSParms_callStaticFunction& ioParms, CUAGUserVector& users, const VString* filter) { VJSArray userArr(ioParms.GetContext()); for (CUAGUserVector::iterator cur = users.begin(), end = users.end(); cur != end; ++cur) { if (filter == nil) { userArr.PushValue((*cur)->CreateJSUserObject(ioParms.GetContext())); } else { VString s; (*cur)->GetName(s); if (s.CompareToSameKind_Like(filter) == CR_EQUAL) userArr.PushValue((*cur)->CreateJSUserObject(ioParms.GetContext())); } } return userArr; }
CUAGDirectory* VRIAServerSolution::_OpenUAGDirectory( VError& outError) { outError = VE_OK; CUAGDirectory *directory = nil; CUAGManager *uag = VComponentManager::RetainComponentOfType<CUAGManager>(); if (uag != NULL) { if (testAssert(fDesignSolution != NULL)) { StUseLogger logger; VMicrosecondsCounter usCounter; VProjectItem *dirItem = fDesignSolution->GetProjectItemFromTag( kUAGDirectoryTag); if (dirItem != NULL) { VFilePath directoryPath; dirItem->GetFilePath( directoryPath); usCounter.Start(); logger.Log( fLoggerID, eL4JML_Information, L"Opening the users and groups directory"); VFile file( directoryPath); directory = uag->RetainDirectory( file, FA_READ_WRITE, NULL, NULL, &outError); } if (directory == NULL && outError == VE_OK) { VFilePath solpath; fDesignSolution->GetSolutionFilePath(solpath); solpath.SetExtension(RIAFileKind::kDirectoryFileExtension); VFile defaultDirFile(solpath); directory = uag->RetainDirectory( defaultDirFile, FA_READ_WRITE, NULL, NULL, &outError, NULL, true); } if (directory != NULL && outError == VE_OK) { // Create an "admin" user if needed CUAGGroup *adminGroup = directory->RetainSpecialGroup( CUAGDirectory::AdminGroup); CUAGGroup *debuggerGroup = directory->RetainSpecialGroup( CUAGDirectory::DebuggerGroup); if ((adminGroup != NULL) && (debuggerGroup != NULL)) { StErrorContextInstaller errorContext( VE_UAG_USERNAME_DOES_NOT_EXIST, VE_OK); CUAGUser *adminUser = directory->RetainUser( L"admin"); if (adminUser == NULL) adminUser = directory->AddOneUser( L"admin", L"", L"", outError); if ((outError == VE_OK) && (adminUser != NULL)) { VUUID adminUserID, userID; adminUser->GetID( adminUserID); CUAGUserVector users; adminGroup->RetainUsers( users); bool hasAdminUser = false; for (CUAGUserVector::iterator userIter = users.begin() ; (userIter != users.end()) && !hasAdminUser ; ++userIter) { (*userIter)->GetID( userID); hasAdminUser = (adminUserID == userID); } if (!hasAdminUser) outError = adminUser->PutIntoGroup( adminGroup); if (outError == VE_OK) { users.clear(); debuggerGroup->RetainUsers( users); hasAdminUser = false; for (CUAGUserVector::iterator userIter = users.begin() ; (userIter != users.end()) && !hasAdminUser ; ++userIter) { (*userIter)->GetID( userID); hasAdminUser = (adminUserID == userID); } if (!hasAdminUser) outError = adminUser->PutIntoGroup( debuggerGroup); } } ReleaseRefCountable( &adminUser); } QuickReleaseRefCountable( adminGroup); QuickReleaseRefCountable( debuggerGroup); } if (directory != NULL && outError == VE_OK) { VString logMsg; logMsg.Printf( "Users and groups directory opened (duration: %i ms)", usCounter.Stop()/1000); logger.Log( fLoggerID, eL4JML_Information, logMsg); } } uag->Release(); } else { outError = ThrowError( VE_RIA_UAG_COMPONENT_NOT_FOUND); } return directory; }