当前位置: 首页>>代码示例>>C++>>正文


C++ UserInfo::getUserName方法代码示例

本文整理汇总了C++中UserInfo::getUserName方法的典型用法代码示例。如果您正苦于以下问题:C++ UserInfo::getUserName方法的具体用法?C++ UserInfo::getUserName怎么用?C++ UserInfo::getUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserInfo的用法示例。


在下文中一共展示了UserInfo::getUserName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main ()
{
	try {
		Connection connection("hostname", 22, true);
//		connection.setCredentials("", "");
//		connection.setKeyPath("");

		UserInfo ui = connection.getUserInfo();

		cout 	<< "User infos:\n"
				<< "   login: " << ui.getUserName() << endl
				<< "    home: " << ui.getHomeDir() << endl
				<< "   shell: " << ui.getUserShell() << endl;

		connection.mkConnection();

		if (connection.isSessionValid())
			cout << "Connection OK" << endl;

		connection 	>> "whoami"
					>> "id"
					>> "echo 'test' > msg"
					>> "cat msg";

		string received_out = connection.getLastOutput();
		cout << "Received output: " << endl << received_out << endl;

	} catch (Exception & e) {
		cout << "Exception caught: " << e.what() << endl;
	}

	return 0;
}
开发者ID:massix,项目名称:libssh2Wrapper,代码行数:33,代码来源:main.cpp

示例2: lns

bool
SimpleAuthorizer2::checkAccess(const String& opType, const String& ns,
	const ServiceEnvironmentIFCRef& env, OperationContext& context)
{
	OW_ASSERT(opType == ACCESS_READ || opType == ACCESS_WRITE
		|| opType == ACCESS_READWRITE);

	UserInfo userInfo = context.getUserInfo();
	if (userInfo.getInternal())
	{
		return true;
	}

	CIMOMHandleIFCRef lch = env->getCIMOMHandle(context,
		ServiceEnvironmentIFC::E_USE_PROVIDERS);

	LoggerRef lgr = env->getLogger(COMPONENT_NAME);

	if (!userInfo.getUserName().empty())
	{
		String superUser =
			env->getConfigItem(ConfigOpts::ACL_SUPERUSER_opt);
		if (superUser.equalsIgnoreCase(userInfo.getUserName()))
		{
			OW_LOG_DEBUG(lgr, "User is SuperUser: checkAccess returning.");
			return true;
		}
	}

	String lns(ns);
	while (lns.startsWith('/'))
	{
		lns = lns.substring(1);
	}
	lns.toLowerCase();
	for (;;)
	{
		if (!userInfo.getUserName().empty())
		{
			try
			{
				CIMClass cc = lch->getClass("root/security",
					"OpenWBEM_UserACL", E_NOT_LOCAL_ONLY, E_INCLUDE_QUALIFIERS,
					E_INCLUDE_CLASS_ORIGIN, NULL);
			}
			catch(CIMException&)
			{
				OW_LOG_DEBUG(lgr, "OpenWBEM_UserACL class non-existent in"
					" /root/security. ACLs disabled");
				return true;
			}
			
			CIMObjectPath cop("OpenWBEM_UserACL");
			cop.setKeyValue("username", CIMValue(userInfo.getUserName()));
			cop.setKeyValue("nspace", CIMValue(lns));
			CIMInstance ci(CIMNULL);
			try
			{
				ci = lch->getInstance("root/security", cop,
					E_NOT_LOCAL_ONLY, E_INCLUDE_QUALIFIERS,
					E_INCLUDE_CLASS_ORIGIN, NULL);
			}
			catch(const CIMException&)
			{
				ci.setNull();
			}
			if (ci)
			{
				String capability;
				CIMProperty capabilityProp = ci.getProperty("capability");
				if (capabilityProp)
				{
					CIMValue cv = capabilityProp.getValue();
					if (cv)
					{
						capability = cv.toString();
					}
				}

				capability.toLowerCase();
				if (opType.length() == 1)
				{
					if (capability.indexOf(opType) == String::npos)
					{
					    // Access to namespace denied for user
						OW_THROWCIM(CIMException::ACCESS_DENIED);
					}
				}
				else
				{
					if (!capability.equals("rw") && !capability.equals("wr"))
					{
						// Access to namespace denied for user
						OW_THROWCIM(CIMException::ACCESS_DENIED);
					}
				}

				// Access to namespace granted for user
				return true;
			}
//.........这里部分代码省略.........
开发者ID:kkaempf,项目名称:openwbem,代码行数:101,代码来源:OW_SimpleAuthorizer2.cpp


注:本文中的UserInfo::getUserName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。