Exemple #1
0
int main(int ac, char **av)
{
  if (ac != 2)
  {
	std::cout << "usage: ./babel_server port" << std::endl;
	return (0);
  }

  try
  {
	SocketManager sm((short) atoi(av[1]));
	ASocket *newConnection;
	UserManager um;

	while (sm.Select() != -1)
	{
	  um.handleSend(sm);
	  um.handleReceive(sm);
	  um.handlePendingAuth(sm);
	  newConnection = sm.tryNewConnection();
	  if (newConnection)
	  {
		um.addPendingAuth(newConnection);
		newConnection = NULL;
	  }
	}
  }
  catch (const std::string &err)
  {
	std::cout << err << std::endl;
	exit(1);
  }
  return (0);
}
Exemple #2
0
void TaskSynch::HandleUserSynch(unsigned __int64 since, bool isResponse, unsigned long ip)
{
	UserManager *pUserMan = m_pDataManager->GetUserManagerInstance();
	User *pUser = pUserMan->FindUserFromIP(ip);
	int len = 0;
	if(pUser)
	{
		IterWrapper<Task> iter(pUser->IterateModifiedOrAssignedTasks(since));
		char *pMsg = NULL;
		Task *pTask = NULL;
		while(iter.Next())
		{
			pTask= iter.Get();
			unsigned long hashLen = 0;
			StringBuffer sb(1024);
			unsigned char *pSegHash = HashTaskTreeSeg(pTask->ToXMLString(sb), &hashLen);
#ifdef DEBUG
			OutputDebugString(_T("Handle User Synch: "));
			OutputDebugString(sb);
			OutputDebugString(_T("\n"));
#endif
			if(pSegHash)
			{
				pMsg = MakeTaskSynchTreeSegMsg(pSegHash, hashLen, pTask->GetID(), pTask->GetModifiedDate(), false, &len);
				m_pNetwork->Send(pMsg, len, ip);
				delete [] pSegHash;
			}
		}
	}
	if(!isResponse)
	{
		char *pMsg = MakeUserTaskSynchReq(0, true, &len);
		m_pNetwork->Send(pMsg, len, ip);
	}
}
// TODO when is this invoked??
/*private static*/ void XN_CALLBACK_TYPE UserManager::onPoseDetected(xn::PoseDetectionCapability& capability, const XnChar* detectedPoseName, XnUserID userId, void* cookie) {
	printf("UserManager.Pose %s detected for user %d\n", detectedPoseName, userId);

	UserManager* tthis = static_cast<UserManager*>(cookie);
	tthis->userGenerator.GetPoseDetectionCap().StopPoseDetection(userId);
	tthis->userGenerator.GetSkeletonCap().RequestCalibration(userId, TRUE);
	tthis->broadcastUserChangeState(userId, USER_STATE_POSE_DETECTED);
}
/*private static*/ void XN_CALLBACK_TYPE UserManager::onUserNew(xn::UserGenerator& generator, XnUserID/*unsigned int*/ userId, void* cookie) {
	printf("UserManager.onNewUser(generator, userId=%d, cookie)\n", userId);

	UserManager* tthis = static_cast<UserManager*>(cookie);
	printf("Requesting calibration for new user.");
	tthis->userGenerator.GetSkeletonCap().RequestCalibration(userId, TRUE);

	tthis->broadcastUserChangeState(userId, USER_STATE_NEW);
}
Exemple #5
0
void TestUMUpdate()
{
	UserManager um;
	User user;
	user.name = "admin";
	user.password = "******";
	user.authority = 1;
	testLog->debug(um.updateCmd(user).toLocal8Bit().data());
	testLog->debug(um.updateCmd(user).toLocal8Bit().data());
	testLog->debug(um.updateCmd(user).toLocal8Bit().data());
	testLog->debug(um.updateCmd(user).toLocal8Bit().data());
}
/*private static*/ void XN_CALLBACK_TYPE UserManager::onCalibrationEnd(xn::SkeletonCapability& capability, XnUserID userId, XnBool successfullyCalibrated, void* cookie) {
	UserManager* tthis = static_cast<UserManager*>(cookie);

	if (successfullyCalibrated) {
		printf("Calibration complete, start tracking user %d\n", userId);
		tthis->userGenerator.GetSkeletonCap().StartTracking(userId);
		tthis->broadcastUserChangeState(userId, USER_STATE_CALIBRATION_ENDED_SUCCESFULLY);
	} else {
		printf("Calibration failed for user %d\n", userId);
		tthis->userGenerator.GetSkeletonCap().RequestCalibration(userId, TRUE);
		tthis->broadcastUserChangeState(userId, USER_STATE_CALIBRATION_ENDED_UNSUCCESFULLY);
	}
}
void CommentWindow::comment()
{
	if (g_umUserManager.Comment(m_mvModel.m_sVideoID, m_qteComment->toPlainText().toStdString()) == SUCCESS)
	{
		g_umUserManager.GetLastVideo(m_mvModel);
		emit updateModel(m_mvModel);

		m_qteComment->clear();
		m_qmbMsg->setText("Comment Successfully");
		m_qmbMsg->setWindowModality(Qt::WindowModal);
		m_qmbMsg->show();
		connect(m_qmbMsg, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(toComment()));
	}
Exemple #8
0
bool MainScene::Init()
{
	// 获得用户
	UserManager* userMgr = UserManager::getInstance();
	// 启动子弹系统
	BulletManager::getInstance()->startUp("Data/bulletConfig.lua");
	// 启动道具系统
	ItemManager::getInstance()->startUp("Data/itemConfig.lua");
	// 启动飞机系统
	PlaneManager::getInstance()->startUp("Data/planeConfig.lua");
	// 启动特效系统
	EffectManager::getInstance()->startUp("Data/effectConfig.lua");

	// 调整摄像机的z轴位置
	Camera::getInstance()->SetCameraPosition(0, 0, -600);

	// 缓存音效
	AudioManager* audioMgr = AudioManager::getInstance();
	audioMgr->loadSoundForCache("Sound/se/beiji.ogg");
	audioMgr->loadSoundForCache("Sound/se/boom.mp3");
	audioMgr->loadSoundForCache("Sound/se/fly.ogg");
	audioMgr->loadSoundForCache("Sound/se/get_item.mp3");
	audioMgr->loadSoundForCache("Sound/se/missile.mp3");
	audioMgr->loadSoundForCache("Sound/se/own_shoot1.ogg");
	audioMgr->loadSoundForCache("Sound/se/own_shoot2.mp3");
	audioMgr->loadSoundForCache("Sound/se/own_shoot3.ogg");
	audioMgr->loadSoundForCache("Sound/se/se_warning.ogg");

	// 初始化主角飞机
	_own = Own::Create(userMgr->GetOwn());
	_own->SetPosition(0, -150, 0);
	Add(_own, LAYER_PLAYER);

	// 分数
	_scoreText = TextSprite::Create("SCORE:0", "微软雅黑", 16);
	Add(_scoreText);

	// 启动关卡系统
	StageManager::getInstance()->startUp("Data/stage" + to_string(userMgr->GetStage()) + ".lua", this);

	// 启动数据更新函数
	AddUpdateFunc(UpdateFunc::Create(CALLBACK_PARAMETER_1(MainScene::UpdateData, this)));
	EventDispatcher::getInstance()->Add(
		KeyboardListener::Create(
		this, KeyboardFunc::Create(
		CALLBACK_PARAMETER_2(MainScene::onkey, this))));

	return true;
}
Exemple #9
0
void Posture::toPosture(const QString &name)
{
	if (modelList.size() == 0)
		m_iListPage = 0;
	if ((m_iListPage >= modelList.size() / MAXATONCE && modelList.size() % MAXATONCE == 0) || 
		(modelList.size() % MAXATONCE != 0 && m_iListPage > modelList.size() / MAXATONCE))
	{
		if (name != "")
			m_pmPageManager.GetModelByUserID(modelList, name.toStdString(), m_iListPage*MAXATONCE);
		else
			m_pmPageManager.GetModelByUserID(modelList, g_umUserManager.GetUsername(), m_iListPage*MAXATONCE);
	}
	int end = (m_iListPage + 1)*MAXATONCE < modelList.size() ? (m_iListPage + 1)*MAXATONCE : modelList.size();
	m_iListPage = (end - 1) / MAXATONCE;
	m_plwPosWin = new PostureListWindow(this, name, m_iListPage*MAXATONCE, end, modelList);
	CloseCurrentWindow();
	m_wtCurrentWin = POSTURELIST;
	this->setCentralWidget(m_plwPosWin);
	connect(m_plwPosWin, SIGNAL(toHome()), this, SLOT(toHomeWin()));
	connect(m_plwPosWin, SIGNAL(toProfileMode(const QString&)), this, SLOT(toProfileMode(const QString&)));
	connect(m_plwPosWin, SIGNAL(toUpload()), this, SLOT(toUploadMode()));
	connect(m_plwPosWin, SIGNAL(logout()), this, SLOT(logout()));
	connect(m_plwPosWin, SIGNAL(display(const ModelVideo&)), this, SLOT(toDisplay(const ModelVideo&)));
	connect(m_plwPosWin, SIGNAL(prev(const QString&)), this, SLOT(prevList(const QString&)));
	connect(m_plwPosWin, SIGNAL(next(const QString&)), this, SLOT(nextList(const QString&)));
}
void DisplayWindow::likeIt()
{
	if (m_qpbLike->text() == "Like")
	{
		if (g_umUserManager.Commend(m_mvModel.m_sVideoID) == SUCCESS)
		{
			g_umUserManager.GetLastVideo(m_mvModel);
			emit updateModel(m_mvModel);

			m_qpbLike->setIcon(QIcon(g_sImgRoot + "liked.png"));
			m_qpbLike->setText("Liked");
		}
		else
		{
			m_qlMsg->setText("Commend Fail, please try again.");
			QTimer *timer = new QTimer();
			timer->start(1000);
			connect(timer, SIGNAL(timeout()), m_qwMessage, SLOT(close()));
			connect(timer, SIGNAL(timeout()), timer, SLOT(stop()));
		}
	}
	else if (m_qpbLike->text() == "Liked")
	{
		if (g_umUserManager.UnCommend(m_mvModel.m_sVideoID) == SUCCESS)
		{
			g_umUserManager.GetLastVideo(m_mvModel);
			emit updateModel(m_mvModel);

			m_qpbLike->setIcon(QIcon(g_sImgRoot + "like.png"));
			m_qpbLike->setText("Like");
		}
		else
		{
			m_qlMsg->setText("Uncommend Fail, please try again.");
			QTimer *timer = new QTimer();
			timer->start(1000);
			connect(timer, SIGNAL(timeout()), m_qwMessage, SLOT(close()));
			connect(timer, SIGNAL(timeout()), timer, SLOT(stop()));
		}
	}
}
Exemple #11
0
int main(int argc, char** argv) {

    User u1("Ruben", "1234");
    User u2("Pablo", "1234");
    User u3("Pepe", "1234");
    User u4("Juan", "1234");

    UserManager userManager;

    userManager.addUser(&u1);
    userManager.addUser(&u2);
    userManager.addUser(&u3);
    userManager.addUser(&u4);

    u1.addFriend(&u2);
    u1.addFriend(&u3);
    u1.addFriend(&u4);


    userManager.showUsers();
    userManager.searchForUser("Ruben", true)->showFriends();


    userManager.addUser(&u3);
    u1.addFriend(&u4);

    
    

    cout << "-------------[ENDING SERVER]-------------" << endl;
    return 0;
}
Exemple #12
0
void Posture::logout()
{
	g_umUserManager.Logout();
	models.clear();
	modelList.clear();
	CloseCurrentWindow();
	m_lwLogWin = new LogWindow(this,LOG);
	this->setCentralWidget(m_lwLogWin);
	connect(m_lwLogWin, SIGNAL(wait()), this, SLOT(message()));
	connect(m_lwLogWin, SIGNAL(regSuccess()), this, SLOT(logout()));
	m_wtCurrentWin = LOG;
	this->setFixedSize(LOGWINDOW_W*xscale, LOGWINDOW_H*yscale);
}
void ProfileEditWindow::InitWidgets()
{
	SourceManager sm;
	UserPro up;
	sm.GetUserProfile(up, g_umUserManager.GetUsername());
	m_qlName = new QLabel("Username", m_qwBottomRight);
	m_qlName->setObjectName("uploadInfo");
	m_qlName->setFixedSize(UPLOADINFO_W*xscale, UPLOADINFO_H*yscale);
	m_qleName = new QLineEdit(m_qwBottomRight);
	m_qleName->setObjectName("editProfile");
	m_qleName->setFixedSize(EDITPROFILE_W*xscale, EDITPROFILE_H*yscale);
	m_qleName->setText(up.m_sUserName.c_str());
	m_qleName->setReadOnly(true);

	m_qlPwd = new QLabel("Password", m_qwBottomRight);
	m_qlPwd->setObjectName("uploadInfo");
	m_qlPwd->setFixedSize(UPLOADINFO_W*xscale, UPLOADINFO_H*yscale);
	m_qlePwd = new QLineEdit(m_qwBottomRight);
	m_qlePwd->setEchoMode(QLineEdit::Password);
	m_qlePwd->setObjectName("editProfile");
	m_qlePwd->setFixedSize(EDITPROFILE_W*xscale, EDITPROFILE_H*yscale);

	m_qlPwdc = new QLabel("Password Confirm", m_qwBottomRight);
	m_qlPwdc->setObjectName("uploadInfo");
	m_qlPwdc->setFixedSize(UPLOADINFO_W*xscale, UPLOADINFO_H*yscale);
	m_qlePwdc = new QLineEdit(m_qwBottomRight);
	m_qlePwdc->setEchoMode(QLineEdit::Password);
	m_qlePwdc->setObjectName("editProfile");
	m_qlePwdc->setFixedSize(EDITPROFILE_W*xscale, EDITPROFILE_H*yscale);

	m_qlEmail = new QLabel("Email", m_qwBottomRight);
	m_qlEmail->setObjectName("uploadInfo");
	m_qlEmail->setFixedSize(UPLOADINFO_W*xscale, UPLOADINFO_H*yscale);
	m_qleEmail = new QLineEdit(m_qwBottomRight);
	m_qleEmail->setText(up.m_sEmail.c_str());
	m_qleEmail->setObjectName("editProfile");
	m_qleEmail->setFixedSize(EDITPROFILE_W*xscale, EDITPROFILE_H*yscale);

	m_qlError = new QLabel(m_qwBottomRight);

	m_qpbCancel = new QPushButton("Cancel", m_qwBottomRight);
	m_qpbCancel->setObjectName("detail");
	m_qpbCancel->setFixedSize(DETAIL_W*xscale, DETAIL_H*yscale);
	m_qpbSubmit = new QPushButton("Submit", m_qwBottomRight);
	m_qpbSubmit->setObjectName("detail");
	m_qpbSubmit->setFixedSize(DETAIL_W*xscale, DETAIL_H*yscale);
	connect(m_qpbCancel, SIGNAL(clicked()), this, SLOT(cancel()));
	connect(m_qpbSubmit, SIGNAL(clicked()), this, SLOT(submit()));
}
void DisplayWindow::forwardIt()
{
	if (g_umUserManager.Share(m_mvModel.m_sVideoID) == SUCCESS)
	{
		m_qmbMsg->setWindowModality(Qt::WindowModal);
		m_qmbMsg->setText("Forward successfully");
		m_qmbMsg->show();
	}
	else
	{
		m_qmbMsg->setWindowModality(Qt::WindowModal);
		m_qmbMsg->setText("Forward fail, please try it again later");
		m_qmbMsg->show();
	}
}
void ProfileEditWindow::submit()
{
	string pwd = m_qlePwd->text().toStdString();
	string pwdc = m_qlePwdc->text().toStdString();
	if (pwd == "" && pwdc == "")
	{
		pwd = g_sPwd.toStdString();
		pwdc = g_sPwd.toStdString();
	}
	string email = m_qleEmail->text().toStdString();

	int result = g_umUserManager.ChangeProfile(pwd, pwdc, email);
	QString error;

	switch (result)
	{
	case SUCCESS:
		emit success("");
		return;
	case PWDNOTCON:
		error = "the password is not Consistent!";
		break;
	case PWDTOOSIM:
		error = "the password is too simple";
		break;
	case EMAILFAIL:
		error = "the email address is not right";
		break;
	case EMPTYINFO:
		error = "the information is empty";
		break;
	case PASSWORD2L:
		error = "the password is too long";
		break;
	}
	m_qlError->setText(error);
	m_qlError->setObjectName("error");
	m_qlError->setAlignment(Qt::AlignCenter);
	m_qlError->show();
}
Exemple #16
0
void CIMOperationRequestAuthorizer::handleEnqueue(Message* request)
{

    PEG_METHOD_ENTER(TRC_SERVER,
        "CIMOperationRequestAuthorizer::handleEnqueue");

    if (!request)
    {
       PEG_METHOD_EXIT();
       return;
    }

    CIMOperationRequestMessage* tmp = 
        dynamic_cast<CIMOperationRequestMessage*>(request);
    AutoPtr<CIMOperationRequestMessage> req(tmp);

    PEGASUS_ASSERT(req.get());

    //
    // Get the HTTPConnection queue id
    //
    QueueIdStack qis = req->queueIds.copyAndPop();

    Uint32 queueId = qis.top();

    // Set the client's requested language into this service thread.
    // This will allow functions in this service to return messages
    // in the correct language.
    req->updateThreadLanguages();

    //
    // If CIMOM is shutting down, return "Service Unavailable" response
    //
    if (_serverTerminating)
    {
        Buffer message;
        message = XmlWriter::formatHttpErrorRspMessage(
            HTTP_STATUS_SERVICEUNAVAILABLE,
            String::EMPTY,
            "CIM Server is shutting down.");

        sendResponse(queueId, message);
        PEG_METHOD_EXIT();
        return;
    }

    String userName = ((IdentityContainer)(req->operationContext.get(
        IdentityContainer::NAME))).getUserName();
    String authType = req->authType;
    CIMNamespaceName nameSpace = req->nameSpace;
    String cimMethodName;

    switch (req->getType())
    {
        case CIM_GET_CLASS_REQUEST_MESSAGE:
            cimMethodName = "GetClass";
            break;

        case CIM_GET_INSTANCE_REQUEST_MESSAGE:
            cimMethodName = "GetInstance";
            break;

        case CIM_DELETE_CLASS_REQUEST_MESSAGE:
            cimMethodName = "DeleteClass";
            break;

        case CIM_DELETE_INSTANCE_REQUEST_MESSAGE:
            cimMethodName = "DeleteInstance";
            break;

        case CIM_CREATE_CLASS_REQUEST_MESSAGE:
            cimMethodName = "CreateClass";
            break;

        case CIM_CREATE_INSTANCE_REQUEST_MESSAGE:
            cimMethodName = "CreateInstance";
            break;

        case CIM_MODIFY_CLASS_REQUEST_MESSAGE:
            cimMethodName = "ModifyClass";
            break;

        case CIM_MODIFY_INSTANCE_REQUEST_MESSAGE:
            cimMethodName = "ModifyInstance";
            break;

        case CIM_ENUMERATE_CLASSES_REQUEST_MESSAGE:
            cimMethodName = "EnumerateClasses";
            break;

        case CIM_ENUMERATE_CLASS_NAMES_REQUEST_MESSAGE:
            cimMethodName = "EnumerateClassNames";
            break;

        case CIM_ENUMERATE_INSTANCES_REQUEST_MESSAGE:
            cimMethodName = "EnumerateInstances";
            break;

        case CIM_ENUMERATE_INSTANCE_NAMES_REQUEST_MESSAGE:
            cimMethodName = "EnumerateInstanceNames";
            break;

        case CIM_EXEC_QUERY_REQUEST_MESSAGE:
            cimMethodName = "ExecQuery";
            break;

        case CIM_ASSOCIATORS_REQUEST_MESSAGE:
            cimMethodName = "Associators";
            break;

        case CIM_ASSOCIATOR_NAMES_REQUEST_MESSAGE:
            cimMethodName = "AssociatorNames";
            break;

        case CIM_REFERENCES_REQUEST_MESSAGE:
            cimMethodName = "References";
            break;

        case CIM_REFERENCE_NAMES_REQUEST_MESSAGE:
            cimMethodName = "ReferenceNames";
            break;

        case CIM_GET_PROPERTY_REQUEST_MESSAGE:
            cimMethodName = "GetProperty";
            break;

        case CIM_SET_PROPERTY_REQUEST_MESSAGE:
            cimMethodName = "SetProperty";
            break;

        case CIM_GET_QUALIFIER_REQUEST_MESSAGE:
            cimMethodName = "GetQualifier";
            break;

        case CIM_SET_QUALIFIER_REQUEST_MESSAGE:
            cimMethodName = "SetQualifier";
            break;

        case CIM_DELETE_QUALIFIER_REQUEST_MESSAGE:
            cimMethodName = "DeleteQualifier";
            break;

        case CIM_ENUMERATE_QUALIFIERS_REQUEST_MESSAGE:
            cimMethodName = "EnumerateQualifiers";
            break;

        case CIM_INVOKE_METHOD_REQUEST_MESSAGE:
            cimMethodName = "InvokeMethod";
            break;

        default:
            PEGASUS_ASSERT(0);
            break;
    }

#ifdef PEGASUS_ZOS_SECURITY
    if (checkRequestTypeAuthorizationZOS(
            req->getType(), userName, nameSpace) == false)
    {
        //
        // user is not authorized, send an
        // error message to the requesting client.
        //
        if (cimMethodName == "InvokeMethod")
        {
            sendMethodError(
                queueId,
                req->getHttpMethod(),
                req->messageId,
                ((CIMInvokeMethodRequestMessage*)req.get())->methodName,
                PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED,
                    MessageLoaderParms(
                        "Server.CIMOperationRequestAuthorizer."
                            "NAMESPACE_AUTHORIZATION_FAILED",
                        "User '$0' is not authorized to run '$1' in the "
                            "namespace '$2'",
                        userName, cimMethodName, nameSpace.getString())));
        }
        else
        {
            sendIMethodError(
                queueId,
                req->getHttpMethod(),
                req->messageId,
                cimMethodName,
                PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED,
                    MessageLoaderParms(
                        "Server.CIMOperationRequestAuthorizer."
                            "NAMESPACE_AUTHORIZATION_FAILED",
                        "User '$0' is not authorized to run '$1' in the "
                            "namespace '$2'",
                        userName, cimMethodName, nameSpace.getString())));
        }
        PEG_METHOD_EXIT();
        return;
    }
#endif

#ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION
    //
    // If the user is not privileged and authorized user group is specified,
    // then perform the user group authorization check.
    //
    try
    {
        if ( ! System::isPrivilegedUser(userName) )
        {
            Uint32 size = _authorizedUserGroups.size();

            if (size > 0)
            {
                Boolean authorized = false;

                //
                // Check if the user name is in the authorized user groups.
                //
                for (Uint32 i = 0; i < size; i++)
                {
                    //
                    // Check if the user is a member of the group
                    //
                    if (System::isGroupMember(userName.getCString(),
                            _authorizedUserGroups[i].getCString()))
                    {
                        authorized = true;
                        break;
                    }
                }

                //
                // If the user is not a member of any of the authorized
                // user groups then generate error response.
                //
                if (!authorized)
                {
                    PEG_TRACE((TRC_SERVER, Tracer::LEVEL1,
                        "Authorization Failed: User '%s' "
                        "is not a member of the authorized groups",
                        (const char*)userName.getCString()));

                    MessageLoaderParms msgLoaderParms(
                        "Server.CIMOperationRequestAuthorizer."
                            "NOT_IN_AUTHORIZED_GRP",
                        "User '$0' is not authorized to access CIM data.",
                        userName);

                    //
                    // user is not in the authorized user groups, send an
                    // error message to the requesting client.
                    //
                    if (cimMethodName == "InvokeMethod")
                    {
                        sendMethodError(
                            queueId,
                            req->getHttpMethod(),
                            req->messageId,
                            ((CIMInvokeMethodRequestMessage*)req.get())->
                                methodName,
                            PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED,
                                msgLoaderParms));
                        PEG_METHOD_EXIT();
                        return;
                    }
                    else
                    {
                        sendIMethodError(
                            queueId,
                            req->getHttpMethod(),
                            req->messageId,
                            cimMethodName,
                            PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED,
                                msgLoaderParms));
                        PEG_METHOD_EXIT();
                        return;
                    }
                }
            }
        }
    }
    catch (InternalSystemError& ise)
    {
        sendIMethodError(
            queueId,
            req->getHttpMethod(),
            req->messageId,
            cimMethodName,
            PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, ise.getMessage()));
        PEG_METHOD_EXIT();
        return;
    }
#endif  // #ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION

    //
    // Get a config manager instance
    //
    ConfigManager* configManager = ConfigManager::getInstance();

    //
    // Do namespace authorization verification
    //
    if (ConfigManager::parseBooleanValue(
        configManager->getCurrentValue("enableNamespaceAuthorization")))
    {
        //
        // If the user is not privileged, perform the authorization check.
        //
        if (!System::isPrivilegedUser(userName))
        {
            UserManager* userManager = UserManager::getInstance();

            if (!userManager ||
                !userManager->verifyAuthorization(
                     userName, nameSpace, cimMethodName))
            {
                if (cimMethodName == "InvokeMethod")
                {
                    sendMethodError(
                      queueId,
                      req->getHttpMethod(),
                      req->messageId,
                      ((CIMInvokeMethodRequestMessage*)req.get())->methodName,
                      PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED,
                          MessageLoaderParms(
                              "Server.CIMOperationRequestAuthorizer."
                                  "NAMESPACE_AUTHORIZATION_FAILED",
                              "User '$0' is not authorized to run '$1' in the "
                                  "namespace '$2'",
                              userName, cimMethodName, nameSpace.getString())));
                }
                else
                {
                    sendIMethodError(
                        queueId,
                        req->getHttpMethod(),
                        req->messageId,
                        cimMethodName,
                        PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED,
                            MessageLoaderParms(
                                "Server.CIMOperationRequestAuthorizer."
                                    "NAMESPACE_AUTHORIZATION_FAILED",
                                "User '$0' is not authorized to run '$1' in "
                                    "the namespace '$2'",
                                userName,
                                cimMethodName,
                                nameSpace.getString())));
                }

                PEG_METHOD_EXIT();
                return;
            }
        }
    }

    //
    // Enqueue the request
    //
    _outputQueue->enqueue(req.release());

    PEG_METHOD_EXIT();
}
/*private static*/ void XN_CALLBACK_TYPE UserManager::onCalibrationStart(xn::SkeletonCapability& capability, XnUserID userId, void* cookie) {
	printf("Calibration started for user %d\n", userId);
	UserManager* tthis = static_cast<UserManager*>(cookie);
	tthis->broadcastUserChangeState(userId, USER_STATE_CALIBRATION_STARTED);
}
/*private static*/ void XN_CALLBACK_TYPE UserManager::onUserLost(xn::UserGenerator& generator, XnUserID userId, void* cookie) {
	printf("UserManager.onUserLost(generator, userId=%d, cookie)\n", userId);

	UserManager* tthis = static_cast<UserManager*>(cookie);
	tthis->broadcastUserChangeState(userId, USER_STATE_LOST);
}
void CIMOperationRequestAuthorizer::handleEnqueue(Message *request)
{

   PEG_METHOD_ENTER(TRC_SERVER, "CIMOperationRequestAuthorizer::handleEnqueue");

   if (!request)
   {
      PEG_METHOD_EXIT();
      return;
   }

   AutoPtr<CIMOperationRequestMessage> 
         req(dynamic_cast<CIMOperationRequestMessage *>(request));

   PEGASUS_ASSERT(req.get());

   //
   // Get the HTTPConnection queue id
   //
   QueueIdStack qis = req->queueIds.copyAndPop();

   Uint32 queueId = qis.top();

// l10n
   // Set the client's requested language into this service thread.
   // This will allow functions in this service to return messages
   // in the correct language.
   if (req->thread_changed())
   {
       AutoPtr<AcceptLanguages> langs(new AcceptLanguages(((AcceptLanguageListContainer)req->operationContext.get
	   (AcceptLanguageListContainer:: NAME)).getLanguages()));	
       Thread::setLanguages(langs.release());   		
   }

   //
   // If CIMOM is shutting down, return "Service Unavailable" response
   //
   if (_serverTerminating)
   {
       Array<char> message;
       message = XmlWriter::formatHttpErrorRspMessage(
           HTTP_STATUS_SERVICEUNAVAILABLE,
           String::EMPTY,
           "CIM Server is shutting down.");

       sendResponse(queueId, message);
       PEG_METHOD_EXIT();
       return;
   }

   String userName = String::EMPTY;
   String authType = String::EMPTY;
   CIMNamespaceName nameSpace;
   String cimMethodName = String::EMPTY;

   // Set the username and namespace.
   nameSpace = req->nameSpace;
   userName = ((IdentityContainer)(req->operationContext.get
			(IdentityContainer::NAME))).getUserName();

   switch (req->getType())
   {
      case CIM_GET_CLASS_REQUEST_MESSAGE:
	 authType = 
	    ((CIMGetClassRequestMessage*)req.get())->authType;
	 cimMethodName = "GetClass";
	 break;

      case CIM_GET_INSTANCE_REQUEST_MESSAGE:
	 authType = 
	    ((CIMGetInstanceRequestMessage*)req.get())->authType;
	 cimMethodName = "GetInstance";
	 break;

      case CIM_DELETE_CLASS_REQUEST_MESSAGE:
	 authType = 
	    ((CIMDeleteClassRequestMessage*)req.get())->authType;
	 cimMethodName = "DeleteClass";
	 break;

      case CIM_DELETE_INSTANCE_REQUEST_MESSAGE:
	 authType = 
	    ((CIMDeleteInstanceRequestMessage*)req.get())->authType;
	 cimMethodName = "DeleteInstance";
	 break;

      case CIM_CREATE_CLASS_REQUEST_MESSAGE:
	 authType = 
	    ((CIMCreateClassRequestMessage*)req.get())->authType;
	 cimMethodName = "CreateClass";
	 break;

      case CIM_CREATE_INSTANCE_REQUEST_MESSAGE:
	 authType = 
	    ((CIMCreateInstanceRequestMessage*)req.get())->authType;
	 cimMethodName = "CreateInstance";
	 break;

      case CIM_MODIFY_CLASS_REQUEST_MESSAGE:
	 authType = 
	    ((CIMModifyClassRequestMessage*)req.get())->authType;
	 cimMethodName = "ModifyClass";
	 break;

      case CIM_MODIFY_INSTANCE_REQUEST_MESSAGE:
	 authType = 
	    ((CIMModifyInstanceRequestMessage*)req.get())->authType;
	 cimMethodName = "ModifyInstance";
	 break;

      case CIM_ENUMERATE_CLASSES_REQUEST_MESSAGE:
	 authType = ((CIMEnumerateClassesRequestMessage*)req.get())->authType;
	 cimMethodName = "EnumerateClasses";
	 break;

      case CIM_ENUMERATE_CLASS_NAMES_REQUEST_MESSAGE:
	 authType = 
	    ((CIMEnumerateClassNamesRequestMessage*)req.get())->authType;
	 cimMethodName = "EnumerateClassNames";
	 break;

      case CIM_ENUMERATE_INSTANCES_REQUEST_MESSAGE:
	 authType = ((CIMEnumerateInstancesRequestMessage*)req.get())->authType;
	 cimMethodName = "EnumerateInstances";
	 break;

      case CIM_ENUMERATE_INSTANCE_NAMES_REQUEST_MESSAGE:
	 authType = ((CIMEnumerateInstanceNamesRequestMessage*)req.get())->authType;
	 cimMethodName = "EnumerateInstanceNames";
	 break;

      case CIM_EXEC_QUERY_REQUEST_MESSAGE:
	 authType = ((CIMExecQueryRequestMessage*)req.get())->authType;
	 cimMethodName = "ExecQuery";
	 break;

      case CIM_ASSOCIATORS_REQUEST_MESSAGE:
	 authType = ((CIMAssociatorsRequestMessage*)req.get())->authType;
	 cimMethodName = "Associators";
	 break;

      case CIM_ASSOCIATOR_NAMES_REQUEST_MESSAGE:
	 authType = ((CIMAssociatorNamesRequestMessage*)req.get())->authType;
	 cimMethodName = "AssociatorNames";
	 break;

      case CIM_REFERENCES_REQUEST_MESSAGE:
	 authType = ((CIMReferencesRequestMessage*)req.get())->authType;
	 cimMethodName = "References";
	 break;

      case CIM_REFERENCE_NAMES_REQUEST_MESSAGE:
	 authType = ((CIMReferenceNamesRequestMessage*)req.get())->authType;
	 cimMethodName = "ReferenceNames";
	 break;

      case CIM_GET_PROPERTY_REQUEST_MESSAGE:
	 authType = ((CIMGetPropertyRequestMessage*)req.get())->authType;
	 cimMethodName = "GetProperty";
	 break;

      case CIM_SET_PROPERTY_REQUEST_MESSAGE:
	 authType = ((CIMSetPropertyRequestMessage*)req.get())->authType;
	 cimMethodName = "SetProperty";
	 break;

      case CIM_GET_QUALIFIER_REQUEST_MESSAGE:
	 authType = ((CIMGetQualifierRequestMessage*)req.get())->authType;
	 cimMethodName = "GetQualifier";
	 break;

      case CIM_SET_QUALIFIER_REQUEST_MESSAGE:
	 authType = ((CIMSetQualifierRequestMessage*)req.get())->authType;
	 cimMethodName = "SetQualifier";
	 break;

      case CIM_DELETE_QUALIFIER_REQUEST_MESSAGE:
	 authType = ((CIMDeleteQualifierRequestMessage*)req.get())->authType;
	 cimMethodName = "DeleteQualifier";
	 break;

      case CIM_ENUMERATE_QUALIFIERS_REQUEST_MESSAGE:
	 authType = ((CIMEnumerateQualifiersRequestMessage*)req.get())->authType;
	 cimMethodName = "EnumerateQualifiers";
	 break;

      case CIM_INVOKE_METHOD_REQUEST_MESSAGE:
	 authType = ((CIMInvokeMethodRequestMessage*)req.get())->authType;
	 cimMethodName = "InvokeMethod";
	 break;

      default:
         PEGASUS_ASSERT(0);
	 break;
   }

#ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION
   //
   // If the user is not privileged and authorized user group is specified, 
   // then perform the user group authorization check.
   //
   try
   {
       if ( ! System::isPrivilegedUser(userName) )
       {
           Uint32 size = _authorizedUserGroups.size();

           if (size > 0)
           {
               Boolean authorized = false;

               //
               // Check if the user name is in the authorized user groups.
               //
               for (Uint32 i = 0; i < size; i++)
               {
                   //
                   // Check if the user is a member of the group
                   //
                   if ( System::isGroupMember(userName.getCString(),
                            _authorizedUserGroups[i].getCString()) )
                   {
                       authorized = true;
                       break;
                   }
               }

               //
               // If the user is not a member of any of the authorized
               // user groups then generate error response.
               //
               if (!authorized)
               {
                   PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL2,
                       "Authorization Failed: User '" + userName +
                       "' is not a member of the authorized groups");

                   MessageLoaderParms msgLoaderParms(
                       "Server.CIMOperationRequestAuthorizer.NOT_IN_AUTHORIZED_GRP",
                       "User '$0' is not authorized to access CIM data.",
                       userName);
                   //
                   // user is not in the authorized user groups, send an
                   // error message to the requesting client.
                   //
                   if (cimMethodName == "InvokeMethod")
                   {
                       // l10n
                       sendMethodError(
                           queueId,
                           req->getHttpMethod(),
                           req->messageId,
                           ((CIMInvokeMethodRequestMessage*)req.get())->methodName,
                           PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, 
                                                   msgLoaderParms));
                       PEG_METHOD_EXIT();
                       return;
                   }
                   else
                   {
                       // l10n
                       sendIMethodError(
                           queueId,
                           req->getHttpMethod(),
                           req->messageId,
                           cimMethodName,
                           PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, 
                                                   msgLoaderParms));
                       PEG_METHOD_EXIT();
                       return;
                   }
               }
           }
       }
   }
   catch (InternalSystemError &ise)
   {
       sendIMethodError(
               queueId,
               req->getHttpMethod(),
               req->messageId,
               cimMethodName,
               PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, ise.getMessage()));
       PEG_METHOD_EXIT();
       return;
   }
#endif  // #ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION

   //
   // Get a config manager instance
   //
   ConfigManager* configManager = ConfigManager::getInstance();

   //
   // Do namespace authorization verification
   //
   if (String::equalNoCase(
          configManager->getCurrentValue("enableNamespaceAuthorization"),
          "true"))
   {
      //
      // If the user is not privileged, perform the authorization check.
      //
#if !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
      if ( ! System::isPrivilegedUser(userName) )
#else
      // On OS/400, always check authorization if remote user.
      // Always allow local privileged users through.
      // Check authorization for local non-privileged users.
      // (User authorization to providers are checked downstream from here).
      if ( ! String::equalNoCase(authType,"Local") ||
           ! System::isPrivilegedUser(userName) )
#endif
      {
         UserManager* userManager = UserManager::getInstance();

         if ( !userManager || !userManager->verifyAuthorization(
                 userName, nameSpace, cimMethodName) )
         {

	   // l10n
	   
           // String description = "Not authorized to run ";
           // description.append(cimMethodName);
           // description.append(" in the namespace ");
           // description.append(nameSpace.getString());

            if (cimMethodName == "InvokeMethod")
            {
	      // l10n
	      sendMethodError(
                  queueId,
                  req->getHttpMethod(),
                  req->messageId,
                  ((CIMInvokeMethodRequestMessage*)req.get())->methodName,
                  PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, 
			 MessageLoaderParms(
			 "Server.CIMOperationRequestAuthorizer.NOT_AUTHORIZED", 
			 "Not authorized to run $0 in the namespace $1", 
			   cimMethodName, nameSpace.getString())));
            }
            else
            {
	      // l10n
	      sendIMethodError(
		       queueId,
		       req->getHttpMethod(),
		       req->messageId,
		       cimMethodName,
		       PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, 
		       MessageLoaderParms(
		       "Server.CIMOperationRequestAuthorizer.NOT_AUTHORIZED", 
		 	"Not authorized to run $0 in the namespace $1", 
	    		cimMethodName, nameSpace.getString())));
            }

            PEG_METHOD_EXIT();

            return;
         }
      }
   }

   //
   // If the user is privileged, and remote privileged user access is not 
   // enabled and the auth type is not Local then reject access.
   //
   if ( System::isPrivilegedUser(userName) &&
        !String::equalNoCase(authType, "Local") &&
        !String::equalNoCase(
           configManager->getCurrentValue("enableRemotePrivilegedUserAccess"),
           "true") )
   {

      if (cimMethodName == "InvokeMethod")
      {

	// l10n

         sendMethodError(
            queueId,
            req->getHttpMethod(),
            req->messageId,
            ((CIMInvokeMethodRequestMessage*)req.get())->methodName,
           PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms(
                   "Server.CIMOperationRequestAuthorizer.REMOTE_NOT_ENABLED", 
                   "Remote privileged user access is not enabled.")));
      }
      else
      {
	// l10n

         sendIMethodError(
            queueId,
            req->getHttpMethod(),
            req->messageId,
            cimMethodName,
           PEGASUS_CIM_EXCEPTION_L(CIM_ERR_ACCESS_DENIED, MessageLoaderParms(
              "Server.CIMOperationRequestAuthorizer.REMOTE_NOT_ENABLED", 
              "Remote privileged user access is not enabled.")));
      }

      PEG_METHOD_EXIT();

      return;
   }

   //
   // Enqueue the request
   //
   _outputQueue->enqueue(req.release());

   PEG_METHOD_EXIT();

}
Exemple #20
0
void MainScene::UpdateData(const float& delta)
{
	// 关卡数据更新
	StageManager::getInstance()->Update(delta);

	vector<Element*> list = GetElementList();
	for (int i = 0; i < list.size(); ++i)
	{
		list.at(i)->SetPositionZ(-list.at(i)->GetOrder() * 2);

		if (list.at(i)->GetOrder() == LAYER_PLAYER_BULLET ||
			list.at(i)->GetOrder() == LAYER_ENEMY_BULLET)
		{
			RECT viewRect = Director::getInstance()->GetViewRect();
			D3DXVECTOR3 viewPos = Camera::getInstance()->GetViewPosition();
			if (Tools::CheckHit_UnInclude(list.at(i),
				viewPos.x - viewRect.right / 2.0f,
				viewPos.y - viewRect.bottom / 2.0f,
				viewPos.x + viewRect.right / 2.0f,
				viewPos.y + viewRect.bottom / 2.0f))
			{
				list.at(i)->SetVisible(false);
			}
		}
		else if (list.at(i)->GetOrder() == LAYER_ENEMY_1 ||
			list.at(i)->GetOrder() == LAYER_ENEMY_2 ||
			list.at(i)->GetOrder() == LAYER_ENEMY_3)
		{
			RECT viewRect = Director::getInstance()->GetViewRect();
			D3DXVECTOR3 viewPos = Camera::getInstance()->GetViewPosition();
			if (list.at(i)->GetPositionY() + (0.5f - list.at(i)->GetAnchorY()) * list.at(i)->GetHeight() <
				viewPos.y + viewRect.bottom / 2.0f &&
				list.at(i)->GetPositionY() - (0.5f - list.at(i)->GetAnchorY()) * list.at(i)->GetHeight() >
				viewPos.y - viewRect.bottom / 2.0f)
			{
				for (int j = 0; j < list.size(); ++j)
				{
					if (list.at(j)->GetOrder() == LAYER_PLAYER_BULLET)
					{
						if (Tools::CheckHit_Circle(list.at(j), list.at(i)) && ((Enemy*)list.at(i))->GetHp() > 0)
						{
							Bullet* bullet = (Bullet*)list.at(j);
							if (bullet->IsCross() == false)
							{
								bullet->Die();
							}
							Enemy* enemy = (Enemy*)list.at(i);
							enemy->SetHp(enemy->GetHp() - bullet->GetAttack());
							enemy->SetBruiseEnable(true);
							
							if (enemy->GetHp() <= 0)
							{
								enemy->Die();
								//分数更新
								UserManager* userMgr = UserManager::getInstance();
								userMgr->SetScore(userMgr->GetScore() + enemy->GetScore());
								enemy->SetScore(0);
								_scoreText->SetText("SCORE:" + to_string(userMgr->GetScore()));

								if (enemy->GetName().substr(0, 4).compare("boss") == 0)
								{
									if (userMgr->GetStage() < userMgr->GetStageMax())
									{
										userMgr->SetStage(userMgr->GetStage() + 1);
										if (_black == 0)
										{
											_black = Sprite::Create("Res/Login/black.png");
											_black->SetScale(500);
											Add(_black);
											ClearUpdateFunc();
											AddUpdateFunc(UpdateFunc::Create(CALLBACK_PARAMETER_1(MainScene::Fade, this)));
											AudioManager::getInstance()->stopBGM();
											AudioManager::getInstance()->playSoundEffect("Sound/se/clear.mp3");
											return;
										}
									}
									else
									{

									}
								}
							}
							else
							{
								Effect* boom = Effect::Create("fire1");
								boom->SetTextureBlend(true);
								boom->SetPosition(bullet->GetPositionX(), bullet->GetPositionY(), bullet->GetPositionZ());
								boom->SetOrder(LAYER_ENEMY_BOOM);
								Add(boom);
								AudioManager::getInstance()->playSoundEffect("Sound/se/beiji.ogg");
							}
						}
					}
				}
			}
			else if (Tools::CheckHit_UnInclude(list.at(i),
				viewPos.x - viewRect.right / 2.0f - 300,
				viewPos.y - viewRect.bottom / 2.0f - 300,
				viewPos.x + viewRect.right / 2.0f + 300,
				viewPos.y + viewRect.bottom / 2.0f + 300))
			{
				list.at(i)->SetVisible(false);
			}
		}
		else if (list.at(i)->GetOrder() == LAYER_PLAYER)
		{
			for (int j = 0; j < list.size(); ++j)
			{
				if (list.at(j)->GetOrder() == LAYER_ENEMY_BULLET)
				{
					if (Tools::CheckHit_Point(list.at(j), list.at(i)))
					{
						Bullet* bullet = (Bullet*)list.at(j);
						if (bullet->IsCross() == false)
						{
							bullet->Die();
						}
						Own* own = (Own*)list.at(i);
						if (own->GetBulletLevel() > 1)
						{
							if (rand() % 2 == 1)
							{
								own->SetBulletLevel(own->GetBulletLevel() - 1);
							}
						}
						else
						{
							own->SetHp(own->GetHp() - bullet->GetAttack());
						}
						own->SetBruiseEnable(true);
						if (own->GetHp() <= 0)
						{
							//Director::getInstance()->SetPause(true);
						}
					}
				}
				else if (list.at(j)->GetOrder() == LAYER_ITEM)
				{
					if (Tools::CheckHit_Circle(list.at(j), list.at(i)))
					{
						Own* own = (Own*)list.at(i);
						Item* item = (Item*)list.at(j);
						own->UseItem(item);
						item->SetVisible(false);
						AudioManager::getInstance()->playSoundEffect("Sound/se/get_item.mp3");
					}
				}
			}
		}
	}
}
void DisplayWindow::BuildBottomRight()
{
	QHBoxLayout *mainLayout = new QHBoxLayout();
	QVBoxLayout *rightLayout = new QVBoxLayout();
	m_qlOutline = new QLabel(QString(m_mvModel.m_sOutLine.c_str()), this);
	m_qlOutline->setObjectName("displayOutline");
	m_qlOutline->setWordWrap(true);
	m_qlOutline->setMinimumSize(DISPLAYOUTLINE_W*xscale, DISPLAYOUTLINE_H*yscale);
	rightLayout->addStretch();
	rightLayout->addWidget(m_qlOutline);
	rightLayout->addSpacing(SPACE);

	QHBoxLayout *favorLayout = new QHBoxLayout();
	srand(time(NULL));
	m_qpbTag = new QPushButton(m_mvModel.m_sFavor.c_str(), this);//[TODO] change the fixed favor into the info of the video
	m_qpbTag->setObjectName("tag");
	m_qpbTag->setFixedSize(TAG_W*xscale, TAG_H*yscale);
	m_qpbTag->setStyleSheet(QString("background-color:rgba(%1,%2,%3,0.5)")
							.arg(rand() % 255).arg(rand() % 255).arg(rand() % 255));
	if (QString(m_mvModel.m_sFavor.c_str()) == "")
		m_qpbTag->hide();
	favorLayout->addWidget(m_qpbTag);
	favorLayout->addStretch();
	rightLayout->addLayout(favorLayout);

	QHBoxLayout *funcLayout = new QHBoxLayout();
	m_qpbLike = new QPushButton("Like", this);
	m_qpbLike->setObjectName("like");
	m_qpbLike->setFixedSize(LIKE_W*xscale, LIKE_H*yscale);
	if (m_mvModel.ifCommend(g_umUserManager.GetUsername()))
	{
		m_qpbLike->setIcon(QIcon(g_sImgRoot + "liked.png"));
		m_qpbLike->setText("Liked");
	}
	else
		m_qpbLike->setIcon(QIcon(g_sImgRoot + "like.png"));
	m_qpbLike->setIconSize(QSize(ICONWIDTH*xscale/2, ICONHEIGHT*yscale/2));
	m_qpbForward = new QPushButton("Forward", this);
	m_qpbForward->setObjectName("like");
	m_qpbForward->setFixedSize(LIKE_W*xscale, LIKE_H*yscale);
	m_qpbForward->setIcon(QIcon(g_sImgRoot + "forward.png"));
	m_qpbForward->setIconSize(QSize(ICONWIDTH*xscale / 2, ICONHEIGHT*yscale / 2));
	if (m_mvModel.m_sPublisher == g_umUserManager.GetUsername())
		m_qpbForward->hide();
	m_qpbComment = new QPushButton("Comment", this);
	m_qpbComment->setObjectName("like");
	m_qpbComment->setFixedSize(LIKE_W*xscale, LIKE_H*yscale);
	m_qpbComment->setIcon(QIcon(g_sImgRoot + "comment.png"));
	m_qpbComment->setIconSize(QSize(ICONWIDTH*xscale / 2, ICONHEIGHT*yscale / 2));
	
	funcLayout->addStretch();
	funcLayout->addWidget(m_qpbLike);
	funcLayout->addWidget(m_qpbForward);
	funcLayout->addWidget(m_qpbComment);
	funcLayout->addSpacing(SPACE);

	//m_dwDisplay = new DisplayWidget("display/demo.ms3d", "1", m_qwBottomRight);
	m_dwDisplay = new DisplayWidget(g_sModel + QString(m_mvModel.m_sVideoID.c_str()),m_mvModel.m_sMode.c_str(), m_qwBottomRight);
	m_dwDisplay->setObjectName("display");
	m_dwDisplay->setFixedSize(DISPLAY_W*xscale, DISPLAY_H*yscale);
	m_qlUser = new QLabel("Uploader: ", m_qwBottomRight);
	m_qlUser->setObjectName("name");
	m_qlUser->setFixedSize(NAME_W*3*xscale, NAME_H*yscale);
	m_qpbUser = new QPushButton(m_mvModel.m_sPublisher.c_str(), m_qwBottomRight);
	m_qpbUser->setObjectName("toProfile");
	m_qpbUser->setFixedSize(TOPROFILE_W*xscale, TOPROFILE_H*yscale);
	m_qtbDesc = new QTextBrowser(this);
	m_qtbDesc->setObjectName("desc");
	m_qtbDesc->setFixedSize(DESC_W*xscale, DESC_H*yscale);
	m_qtbDesc->setText(QString("Description: ") + m_mvModel.m_sDescribe.c_str());
	QHBoxLayout *nameLayout = new QHBoxLayout();
	nameLayout->addWidget(m_qlUser);
	nameLayout->addWidget(m_qpbUser);
	nameLayout->addStretch();
	rightLayout->addStretch();
	rightLayout->addLayout(nameLayout);
	rightLayout->addWidget(m_qtbDesc);
	rightLayout->addStretch();
	rightLayout->addLayout(funcLayout);
	rightLayout->addStretch();

	mainLayout->addWidget(m_dwDisplay);
	mainLayout->addSpacing(SPACE);
	mainLayout->addLayout(rightLayout);
	m_qwBottomRight->setLayout(mainLayout);
}
Exemple #22
0
void TestUMSearch()
{
	UserManager um;
	testLog->debug(um.searchCmd("admin").toLocal8Bit().data());
}
Exemple #23
0
void TestUMLogin()
{
	UserManager um;
	testLog->debug(um.loginCmd("admin", "12345").toLocal8Bit().data());
}
//
// main
//
int main(int argc, char** argv)
{
    verbose = (getenv ("PEGASUS_TEST_VERBOSE")) ? true : false;
    if (verbose) cout << argv[0] << ": started" << endl;

    CIMNamespaceName nameSpace;
    String testUser = System::getEffectiveUserName();

    // Create a test repository
    const char* tmpDir = getenv ("PEGASUS_TMP");
    String repositoryPath;
    if (tmpDir == NULL)
    {
        repositoryPath = ".";
    }
    else
    {
        repositoryPath = tmpDir;
    }
    repositoryPath.append("/repository");

    FileSystem::removeDirectoryHier(repositoryPath);

    CIMRepository* repository = new CIMRepository(repositoryPath);

    // -- Create a UserManager object:

    UserManager*  userManager = UserManager::getInstance(repository);

    //
    // Test authorization
    //
    try
    {
        nameSpace = BAD_NAMESPACE;
        PEGASUS_TEST_ASSERT(!userManager->verifyNamespace(nameSpace));

        nameSpace = GOOD_NAMESPACE;
        PEGASUS_TEST_ASSERT(!userManager->verifyNamespace(nameSpace));

        userManager->setAuthorization(testUser, nameSpace, "rw");
        userManager->setAuthorization("root", nameSpace, "w");

        String temp = userManager->getAuthorization(testUser, nameSpace);

        if (testUser != "root")
            PEGASUS_TEST_ASSERT(
                String::equal(temp, "rw") || String::equal(temp, "wr"));

        temp = userManager->getAuthorization("root", nameSpace);
        PEGASUS_TEST_ASSERT(String::equal(temp, "w"));

        userManager->removeAuthorization("root", nameSpace);
        temp.clear();
        try
        {
            temp = userManager->getAuthorization("root", nameSpace);
            PEGASUS_TEST_ASSERT(temp.size() == 0);
        }catch(const Exception&) { }

        userManager->setAuthorization("root", nameSpace, "w");

        if (testUser != "root")
            PEGASUS_TEST_ASSERT(userManager->verifyAuthorization(
                testUser, nameSpace, CIMName("GetInstance")));
        PEGASUS_TEST_ASSERT(!userManager->verifyAuthorization(
            "root", nameSpace, CIMName("GetInstance")));

        userManager->setAuthorization("root", nameSpace, "r");

        PEGASUS_TEST_ASSERT(!userManager->verifyAuthorization(
            "root", nameSpace, CIMName("SetProperty")));

        userManager->removeAuthorization("root", nameSpace);
        if (testUser != "root")
           userManager->removeAuthorization(testUser, nameSpace);
    }
    catch(Exception& e)
    {
        cout << argv[0] << " Exception: " << e.getMessage() << endl;
        PEGASUS_TEST_ASSERT(0);
    }

    UserManager::destroy();
    delete repository;
    FileSystem::removeDirectoryHier(repositoryPath);

    cout << argv[0] << " +++++ passed all tests" << endl;

      return 0;
}
Exemple #25
0
int _tmain(int argc, _TCHAR* argv[])
{	
	// Initial manager setup
	UserManager userManager;
	ServerManager serverManager;
	GroupManager groupManager;
	Session session;
	session.userName = NULL;
	session.password = NULL;

	// Plumbing.
	LSA::SetUserManager(&userManager);
	LSA::SetGroupManager(&groupManager);
	LSA::SetServerManager(&serverManager);

	AD::SetUserManager(&userManager);
	AD::SetGroupManager(&groupManager);
	AD::SetServerManager(&serverManager);

	// So apparently we're a bunch of cavemen/cavewomen living in the stone age.
	// As such we have to roll our own UNIX-style command line parsing.
	// This is guaranteed to get ugly fast.
	// TODO: Create an options parsing static class to take care of this for us.

	DWORD i;
	for(i = 1; i < argc; i++) 
	{
		if(argv[i][0] == '-') 
		{
			TCHAR *option = argv[i]+1; 
			// Found a flag that needs an argument.
			if(lstrcmp(option, L"d") == 0) 
			{
				// Is the next argument empty or another flag? If so ya dun goofed.
				if(i+1 >= argc || argv[i+1][0] == '-') 
				{
					Help::Usage(argv[0]);
					exit(1);
				}
				else
				{
					Config::domain = argv[i+1];
				}
			}
			if(lstrcmp(option, L"u") == 0) 
			{
				if(i+1 >= argc || argv[i+1][0] == '-') 
				{
					Help::Usage(argv[0]);
					exit(1);
				}
				else
				{
					session.userName = argv[i+1];
				}
			}
			if(lstrcmp(option, L"p") == 0) 
			{
				if(i+1 >= argc || argv[i+1][0] == '-') 
				{
					Help::Usage(argv[0]);
					exit(1);
				}
				else
				{
					session.password = argv[i+1];
				}
			}
			if(lstrcmp(option, L"t") == 0) 
			{
				if(i+1 >= argc || argv[i+1][0] == '-') 
				{
					Help::Usage(argv[0]);
					exit(1);
				}
				else
				{
					Config::machine = argv[i+1];
				}
			}
			if(lstrcmp(option, L"c") == 0) 
			{
				if(i+1 >= argc || argv[i+1][0] == '-') 
				{
					Help::Usage(argv[0]);
					exit(1);
				}
				else
				{
					Config::csvOutput = true;
					Config::csvFile = argv[i+1];
				}
			}
			if(lstrcmp(option, L"b") == 0) 
			{
				if(i+1 >= argc || argv[i+1][0] == '-') 
				{
					Help::Usage(argv[0]);
					exit(1);
				}
				else
				{
					Config::numBruteTries = _wtoi(argv[i+1]);
				}
			}
			if(lstrcmp(option, L"l") == 0)
			{
				if(i+1 >= argc || argv[i+1][0] == '-')
				{
					Help::Usage(argv[0]);
					exit(1);
				}
				else
				{
					Config::connectLSA = true;

					if(lstrcmpi(argv[i+1], L"group") == 0)
					{
						Config::sidType = SidTypeGroup;
					}
					else if(lstrcmpi(argv[i+1], L"user") == 0)
					{
						Config::sidType = SidTypeUser;
						Config::machineAccountHack = false;
					}
					else if(lstrcmpi(argv[i+1], L"machine") == 0)
					{
						// As far as I can tell enumerable machine accounts
						// through LSA are just regular accounts marked with
						// a dollar sign at the end, so we use SidTypeUser
						// instead of SidTypeComputer, which returns nothing.
						Config::sidType = SidTypeUser;
						// TODO: Fix LSA enumeration so that we don't need this flag.
						Config::machineAccountHack = true;
					}
				}
			}
			if(lstrcmp(option, L"n") == 0)
			{
				Config::connectWNet = true;
			}
			if(lstrcmp(option, L"i") == 0)
			{
				Config::printUserInfo = true;
			}
			if(lstrcmp(option, L"s") == 0)
			{
				Config::printServerInfo = true;
			}
			if(lstrcmp(option, L"g") == 0)
			{
				Config::printGroupInfo = true;
			}
		}
	} 
	// End options parsing.
	//AD::SetHost(L"");
	//AD::GetDN();
	//AD::Login();
	//AD::Enumerate(AD_SEARCH_USER);

	// Console setup
	Util::SetConsoleColor(DEFAULT);

	// Check to make sure run-once conditions have been satisfied.
	if(!Config::printUserNames && !Config::printUserInfo && !Config::printServerInfo && !Config::connectWNet && !Config::connectLSA && !Config::printGroupInfo)
	{
		Help::Usage(argv[0]);
		exit(1);
	}
	//Cosmetic new-line; just makes the output look better.

	wprintf(L"\n");

	// Begin fun non-options-parsing stuff here.
	// Make sure to connect session first if needed.

	if(Config::connectWNet)
	{
		if(!session.userName || !session.password)
		{
			Util::Warn(L"Full NetBIOS credentials unspecified, skipping NetBIOS login.\n");
		}
		else if(lstrlen(Config::machine) <= 0)
		{
			Util::Warn(L"No target IP specified, skipping NetBIOS login.\n");
		}
		else
		{
			Util::Notice(L"Connecting via SMB...\n\n");
			session.ConnectWNet(session.userName, session.password, Config::machine);
		}
	}

	if(Config::connectLSA)
	{
		if(lstrlen(Config::machine) <= 0)
		{
			Util::Warn(L"No target IP specified, skipping LSA SID brute force.\n");
		}
		else if(!Config::sidType)
		{
			Util::Warn(L"Incorrect or no SID type specified, skipping LSA SID brute force.\n");
		}
		else
		{
			Util::Notice(L"Connecting via LSA...\n\n");
			LSA::OpenPolicy(&session, Config::machine);
			LSA::EnumerateSIDs(&session, Config::sidType);

			if(Config::csvOutput && lstrlen(Config::csvFile) > 0)
			{
				switch(Config::sidType)
				{
				case SidTypeUser:
					if(!Config::machineAccountHack)
					{
						userManager.DumpToCSV();
					}
					else
					{
						serverManager.DumpToCSV();
					}
					break;
				case SidTypeGroup:
					groupManager.DumpToCSV();
				default:
					break;
				}
			}
		}
	}

	if(Config::printUserInfo)
	{
		// We send the machine instead of the domain on purpose,
		// since it's faster than sending the name of the domain
		// and the domain name can be a faulty method from time to time.

		if(lstrlen(Config::machine) <= 0)
		{
			Util::Warn(L"No target IP specified, skipping NetBIOS user enumeration.\n");
		}
		else
		{
			Util::Notice(L"Printing user info now\n\n");
			userManager.EnumerateUserInformation(Config::machine); 

			if(Config::csvOutput && lstrlen(Config::csvFile) > 0)
			{
				userManager.DumpToCSV();
			}
		}
	}

	if(Config::printGroupInfo)
	{
		// Fairly sure we do the same as with the user information;
		// which is to say we send directly to the DC instead of using a
		// domain name.

		if(lstrlen(Config::machine) <= 0)
		{
			Util::Warn(L"No Target IP specified, skipping NetBIOS group enumeration.\n");
		}
		else
		{
			Util::Notice(L"Printing group info now\n");
			groupManager.EnumerateGroups(Config::machine);
			if(Config::csvOutput && lstrlen(Config::csvFile) > 0)
			{
				groupManager.DumpToCSV();
			}
		}
	}

	if(Config::printServerInfo)
	{
		// Once again pointing directly at the DC appears to
		// be superior to the option of supplying a domain name.
		if(lstrlen(Config::machine) <= 0)
		{
			Util::Warn(L"No target IP specified, skipping NetBIOS server enumeration.\n");
		}
		else
		{
			Util::Notice(L"Printing server info now...\n\n");
			serverManager.EnumerateServerInformation(Config::machine);
			if(Config::csvOutput && lstrlen(Config::csvFile) > 0)
			{
				serverManager.DumpToCSV();
			}
		}
	}

	if(Config::connectWNet && lstrlen(Config::machine) > 0)
	{
		session.DisconnectWNet(Config::machine);
	}

	Util::SetConsoleColor(SYSTEM_DEFAULT);

	// Be free memory. Be free as a bird.
	userManager.Clear();
	groupManager.Clear();
	serverManager.Clear();
	return 0;
}