// AuthenticateUser // // The caller gets a reference. status_t SecurityContext::AuthenticateUser(const char* name, const char* password, User** _user) { if (!_user) return B_BAD_VALUE; // find user ContextLocker _(this); User* user = FindUser(name); if (!user) return B_PERMISSION_DENIED; Reference<User> userReference(user, true); // check password if (user->GetPassword()) { if (!password || strcmp(user->GetPassword(), password) != 0) return B_PERMISSION_DENIED; } else if (password) return B_PERMISSION_DENIED; *_user = user; userReference.Detach(); return B_OK; }
bool UserManager::Login( User *pUser, SsapiResponder *pResponder ){ User *pManagedObject; bool isAthenticated = false; bool isCorrectUserName = false; pUser->BuildYourselfFromYourValueSet(); for( U32 index = 0; index < GetManagedObjectCount(); index++ ){ pManagedObject = (User *)GetManagedObject( index ); if( pManagedObject->GetUserName() == pUser->GetUserName() ){ isCorrectUserName = true; if( pManagedObject->GetPassword() == pUser->GetPassword() ){ isAthenticated = true; } else { isAthenticated = false; } break; } } if( !isCorrectUserName ) pResponder->RespondToRequest( SSAPI_EXCEPTION_SECURITY, CTS_SSAPI_USERNAME_PASSWORD_INVALID ); else { if( isAthenticated ){ // username as a parameter LogEvent( CTS_SSAPI_EVENT_USER_LOGGED_IN, pManagedObject->GetUserName() ); UpdateWrongLoginCount( pManagedObject, pResponder, false ); } else UpdateWrongLoginCount( pManagedObject, pResponder, true ); } return true; }
void DialogEidtUser::InitUser() { switch (m_type) { case DialogEidtUser::EDIT: { User user = UserDatabase::SelectUser(m_oldName); m_lineEditName->setText(user.GetName()); m_lineEditPassword->setText(user.GetPassword()); m_lineEditConfirmPassword->setText(user.GetPassword()); m_comboBoxAuthority->setCurrentText(QString::number(user.GetAuthority())); m_comboBoxLanguage->setCurrentText(user.GetLanguage()); /*若编辑对象为自身,则禁止修改名字与权限*/ if (m_oldName==TeachingBoxContext::GetInstance()->GetUser().GetName()) { m_lineEditName->setEnabled(false); m_comboBoxAuthority->setEnabled(false); } }break; default: break; } }
// constructor SecurityContext::SecurityContext(BMessage* archive) : BArchivable(archive), fUsers(new(std::nothrow) UserMap), fShares(new(std::nothrow) ShareMap), fPermissions(new(std::nothrow) PermissionMap), fNode2Path(new(std::nothrow) NodePathMap), fPath2Node(new(std::nothrow) PathNodeMap) { if (InitCheck() != B_OK) return; status_t error = B_OK; // users BMessage userArchive; for (int32 i = 0; archive->FindMessage("users", i, &userArchive) == B_OK; i++) { User tmpUser; error = tmpUser.Unarchive(&userArchive); if (error != B_OK) return; error = AddUser(tmpUser.GetName(), tmpUser.GetPassword()); if (error != B_OK) return; } // shares BMessage shareArchive; for (int32 i = 0; archive->FindMessage("shares", i, &shareArchive) == B_OK; i++) { Share tmpShare; error = tmpShare.Unarchive(&shareArchive); if (error != B_OK) return; error = AddShare(tmpShare.GetName(), tmpShare.GetPath()); if (error != B_OK) return; } // permissions BMessage permissionsArchive; if (archive->FindMessage("permissions", &permissionsArchive) != B_OK) return; #ifdef ANTARES_TARGET_PLATFORM_DANO const char* userName; #else char* userName; #endif type_code type; for (int32 userIndex = 0; permissionsArchive.GetInfo(B_MESSAGE_TYPE, userIndex, &userName, &type) == B_OK; userIndex++) { User* user = FindUser(userName); if (!user) return; Reference<User> userReference(user, true); error = permissionsArchive.FindMessage(userName, &userArchive); if (error != B_OK) return; // got a user: iterate through its permissions #ifdef ANTARES_TARGET_PLATFORM_DANO const char* path; #else char* path; #endif for (int32 i = 0; userArchive.GetInfo(B_INT32_TYPE, i, &path, &type) == B_OK; i++) { uint32 permissions; error = userArchive.FindInt32(path, (int32*)&permissions); if (error == B_OK) error = SetNodePermissions(path, user, permissions); } } }