Example #1
0
static void
outputKEYVALUE(ostream& ostr, const CIMProperty& cp)
{
	CIMDataType dtype = cp.getDataType();
	String type;
	if (dtype.isArrayType())
	{
		OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
			"An array cannot be a KEY");
	}
	if (dtype.isReferenceType())
	{
		CIMProperty lcp(cp);
		// This is sort of a bad thing to do, basically we are taking advantage
		// of a side effect of setDataType.  If the type isn't correct then
		// the value will be cast to the correct type.	This is to work around
		// a problem that may happen if a provider writer sets the value of a
		// reference property to a String instead of an CIMObjectPath.
		// If the value is a string, the xml that is output will be malformed,
		// and the client will throw an exception.
		lcp.setDataType(lcp.getDataType());
		CIMtoXML(lcp.getValue(), ostr);
		return;
	}
	//
	// Regular key value
	switch (dtype.getType())
	{
		case CIMDataType::CHAR16:
		case CIMDataType::DATETIME:
		case CIMDataType::STRING:
			type = "string";
			break;
		case CIMDataType::BOOLEAN:
			type = "boolean";
			break;
		default:
			type = "numeric";
	}
	CIMValue keyValue = cp.getValue();
	if (!keyValue)
	{
		OW_THROWCIMMSG(CIMException::FAILED, "No key value");
	}
	ostr
		<< "<KEYVALUE VALUETYPE=\""
		<<  type
		<< "\">"
		<< XMLEscape(keyValue.toString())
		<< "</KEYVALUE>";
}
Example #2
0
void _getProperty(CIMClient & client)
{
    try
    {
        value = client.getProperty(
                    SOURCE_NAMESPACE,
                    objectNames[0],
                    CIMName("FileSize"));
        if (verbose)
        {
            PEGASUS_STD (cout) << "+++++ getProperty completed successfully, "
                               << "FileSize is: " << value.toString()
                               << PEGASUS_STD (endl);
        }
    }
    catch (Exception & e)
    {
        PEGASUS_STD (cerr) << "getProperty failed: " << e.getMessage ()
                           << PEGASUS_STD (endl);
        exit (-1);
    }
}
Example #3
0
CIMKeyBinding::CIMKeyBinding(const CIMName& name, const CIMValue& value)
{
    if (value.isArray())
    {
        throw TypeMismatchException();
    }

    String kbValue = value.toString();
    Type kbType;

    switch (value.getType())
    {
    case CIMTYPE_BOOLEAN:
        kbType = BOOLEAN;
        break;
    case CIMTYPE_CHAR16:
    case CIMTYPE_STRING:
    case CIMTYPE_DATETIME:
        kbType = STRING;
        break;
    case CIMTYPE_REFERENCE:
        kbType = REFERENCE;
        break;
//  case CIMTYPE_REAL32:
//  case CIMTYPE_REAL64:
    case CIMTYPE_OBJECT:
    case CIMTYPE_INSTANCE:
        // From PEP 194: EmbeddedObjects cannot be keys.
        throw TypeMismatchException();
        break;
    default:
        kbType = NUMERIC;
        break;
    }

    _rep = new CIMKeyBindingRep(name, kbValue, kbType);
}
Example #4
0
Boolean _applyProjection(QueryExpression& qe,
                         Array<CIMInstance>& _instances,
                         String testOption,
                         String lang)
{
    if(testOption == String::EMPTY || testOption == "2")
    {
        cout << endl << lang << " ========Apply Projection Results========" << endl;
        cout << qe.getQuery() << endl;

        for(Uint32 j = 0; j < _instances.size(); j++)
        {
            cout << "Instance of class " << _instances[j].getClassName().getString() << endl;

            try
            {
                CIMInstance projInst = _instances[j].clone();

                Boolean gotPropExc = false;
                try
                {
                    qe.applyProjection(projInst, false);
                }
                catch (QueryRuntimePropertyException & qrpe)
                {
                    // Got a missing property exception.
                    cout << "-----" << qrpe.getMessage() << endl;
                    gotPropExc = true;
                }

                if (gotPropExc)
                {
                    // Got a missing property exception.
                    // Try again, allowing missing properties.
                    // Need to use a cloned instance because the original instance
                    // was partially projected.
                    cout << "Instance of class " << _instances[j].getClassName().getString()
                         << ".  Allow missing properties." << endl;
                    projInst = _instances[j].clone();
                    qe.applyProjection(projInst, true);
                }

                Uint32 cnt = projInst.getPropertyCount();
                if (cnt == 0)
                {
                    cout << "-----No properties left after projection" << endl;
                }

                if (cnt > 10)
                {
                    // If more than 10 props, just print the count to keep
                    // the output file short
                    cout << "Instance has " << cnt << " properties" << endl;
                }
                else
                {
                    for (Uint32 n = 0; n < cnt; n++)
                    {
                        CIMProperty prop = projInst.getProperty(n);
                        CIMValue val = prop.getValue();
                        cout << "-----Prop #" << n << " Name = " << prop.getName().getString();
                        if (val.isNull())
                        {
                            cout << " Value = NULL" << endl;
                        }
                        else
                        {
                            cout << " Value = " << val.toString() << endl;
                        }
                    }
                }
            }
            catch(Exception& e) {
                cout << "-----" << e.getMessage() << endl;
            }
            catch(...) {
                cout << "Unknown Exception" << endl;
            }

        }
    }

    return true;
}
String IndicationFormatter::_getIndPropertyValue(
    const String & specifiedPropertyName,
    const String & arrayIndexStr,
    const CIMInstance & indication,
    const ContentLanguages & contentLangs)
{
    PEG_METHOD_ENTER (TRC_IND_FORMATTER,
        "IndicationFormatter::_getIndPropertyValue");

    CIMInstance indicationInstance = indication.clone();
    String propertyName;

    Boolean canLocalize = false;

#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
    Locale locale;
    canLocalize = _canLocalize(contentLangs, locale);
#endif

    for (Uint32 i=0; i < indicationInstance.getPropertyCount(); i++)
    {
        CIMProperty property = indicationInstance.getProperty(i);
        propertyName = property.getName().getString();

        // get specified property value
        if (String::equalNoCase(propertyName, specifiedPropertyName))
        {
            CIMValue propertyValue = property.getValue();
            Boolean valueIsNull = propertyValue.isNull();
	    CIMType type = propertyValue.getType();

            if (!valueIsNull)
            {
                Boolean isArray = propertyValue.isArray();

                if (isArray)
                {
                    PEG_METHOD_EXIT();
		    return (_getArrayValues(propertyValue, arrayIndexStr,
			                    contentLangs));
                }
                else // value is not an array
                {
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
		    if (canLocalize)
		    {
                        if (type == CIMTYPE_DATETIME)
		        {
			    CIMDateTime dateTimeValue;
			    propertyValue.get(dateTimeValue);
                            PEG_METHOD_EXIT();
			    return(_localizeDateTime(dateTimeValue, locale));
		        }
                        else if (type == CIMTYPE_BOOLEAN)
		        {
			    Boolean booleanValue;
			    propertyValue.get(booleanValue);
                            PEG_METHOD_EXIT();
			    return(_localizeBooleanStr(booleanValue, locale));
		        }
                        else
                        {
                            PEG_METHOD_EXIT();
                            return (propertyValue.toString());
                        }
		    }
		    else
		    {
			if (type == CIMTYPE_BOOLEAN)
			{
                            PEG_METHOD_EXIT();
                            return (_getBooleanStr(propertyValue));
			}
			else
			{
                            PEG_METHOD_EXIT();
                            return (propertyValue.toString());
			}
		    }
#else
		    if (type == CIMTYPE_BOOLEAN)
		    {
                        PEG_METHOD_EXIT();
                        return (_getBooleanStr(propertyValue));
		    }
		    else
		    {
                        PEG_METHOD_EXIT();
                        return (propertyValue.toString());
		    }
#endif
                }

            }
            else // value is NULL
            {
                PEG_METHOD_EXIT();
                return ("NULL");
            }

        }
        propertyName.clear();
    }

    PEG_METHOD_EXIT();

    return ("UNKNOWN");
}
String IndicationFormatter::_formatDefaultIndicationText(
    const CIMInstance & indication,
    const ContentLanguages & contentLangs)
{
    PEG_METHOD_ENTER (TRC_IND_FORMATTER,
        "IndicationFormatter::_formatDefaultIndicationText");

    CIMInstance indicationInstance = indication.clone();
    String propertyName;
    String indicationStr;
    Uint32 propertyCount = indicationInstance.getPropertyCount();

    indicationStr.append("Indication (default format):");

    Boolean canLocalize = false;

#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
    Locale locale;
    canLocalize = _canLocalize(contentLangs, locale);
#endif

    for (Uint32 i=0; i < propertyCount; i++)
    {
        CIMProperty property = indicationInstance.getProperty(i);
        propertyName = property.getName().getString();
        CIMValue propertyValue = property.getValue();
        Boolean valueIsNull = propertyValue.isNull();
        Boolean isArray = propertyValue.isArray();

        indicationStr.append(propertyName);
        indicationStr.append(" = ");

	CIMType type = propertyValue.getType();

        if (!valueIsNull)
        {
            if (isArray)
            {
		indicationStr.append(_getArrayValues(propertyValue, "",
		    contentLangs));
            }
            else // value is not an array
            {
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
		if (canLocalize)
		{
		    if (type == CIMTYPE_DATETIME)
		    {
			CIMDateTime dateTimeValue;
			propertyValue.get(dateTimeValue);
		        indicationStr.append(_localizeDateTime(dateTimeValue,
		    	    locale));
		    }
		    else if (type == CIMTYPE_BOOLEAN)
		    {
			Boolean booleanValue;
			propertyValue.get(booleanValue);
		        indicationStr.append(_localizeBooleanStr(booleanValue,
		    	    locale));
		    }
		    else
		    {
			indicationStr.append(propertyValue.toString());
		    }
		}
		else
		{
		    if (type == CIMTYPE_BOOLEAN)
		    {
                        indicationStr.append(_getBooleanStr(propertyValue));
		    }
		    else
		    {
                        indicationStr.append(propertyValue.toString());
		    }
		}
#else
		if (type == CIMTYPE_BOOLEAN)
		{
                    indicationStr.append(_getBooleanStr(propertyValue));
		}
		else
		{
                    indicationStr.append(propertyValue.toString());
		}
#endif
            }
        }
	else
	{
	    indicationStr.append("NULL");
	}

        if (i < propertyCount -1)
        {
            indicationStr.append(", ");
        }

        propertyName.clear();
    }

    PEG_METHOD_EXIT();

    return (indicationStr);
}
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;
			}
		}

		// use default policy for namespace
		try
		{
			CIMClass cc = lch->getClass("root/security",
				"OpenWBEM_NamespaceACL", E_NOT_LOCAL_ONLY, E_INCLUDE_QUALIFIERS,
				E_INCLUDE_CLASS_ORIGIN, NULL);
		}
		catch(CIMException&)
		{
			// OpenWBEM_NamespaceACL class non-existent in /root/security.
			// namespace ACLs disabled
			return true;
		}
		CIMObjectPath cop("OpenWBEM_NamespaceACL");
		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& ce)
		{
			OW_LOG_DEBUG(lgr, Format("Caught exception: %1 in"
				" AccessMgr::checkAccess. line=%2", ce, __LINE__));
			ci.setNull();
		}
	
		if (ci)
		{
			String capability;
			CIMProperty capabilityProp = ci.getProperty("capability");
			if (capabilityProp)
			{
				CIMValue v = capabilityProp.getValue();
				if (v)
				{
					capability = v.toString();
				}
			}

			capability.toLowerCase();
			if (opType.length() == 1)
			{
				if (capability.indexOf(opType) == String::npos)
				{
					// Access 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;
		}
		size_t idx = lns.lastIndexOf('/');
		if (idx == 0 || idx == String::npos)
		{
			break;
		}
		lns = lns.substring(0, idx);
	}

	// Access to namespace denied for user
   	OW_THROWCIM(CIMException::ACCESS_DENIED);
	return false;
}
Example #8
0
void CIMtoXML(CIMValue const& cv, ostream& out)
{
	if (!cv)
	{
		OW_THROWCIMMSG(CIMException::FAILED, "CIM value is NULL");
	}
	if (cv.isArray())
	{
		switch (cv.getType())
		{
			case CIMDataType::BOOLEAN:
			{
				BoolArray a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::UINT8:
			{
				UInt8Array a;
				cv.get(a);
				raToXmlNumeric(out, a);
				break;
			}
			case CIMDataType::SINT8:
			{
				Int8Array a;
				cv.get(a);
				raToXmlNumeric(out, a);
				break;
			}
			// ATTN: UTF8
			case CIMDataType::CHAR16:
			{
				Char16Array a;
				cv.get(a);
				raToXmlChar16(out, a);
				break;
			}
			case CIMDataType::UINT16:
			{
				UInt16Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::SINT16:
			{
				Int16Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::UINT32:
			{
				UInt32Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::SINT32:
			{
				Int32Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::UINT64:
			{
				UInt64Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::SINT64:
			{
				Int64Array a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::REAL32:
			{
				Real32Array a;
				cv.get(a);
				realArrayToXml(out, a);
				break;
			}
			case CIMDataType::REAL64:
			{
				Real64Array a;
				cv.get(a);
				realArrayToXml(out, a);
				break;
			}
			case CIMDataType::STRING:
			{
				StringArray a;
				cv.get(a);
				raToXmlSA(out, a);
				break;
			}
			case CIMDataType::DATETIME:
			{
				CIMDateTimeArray a;
				cv.get(a);
				raToXml(out, a);
				break;
			}
			case CIMDataType::REFERENCE:
			{
				CIMObjectPathArray a;
				cv.get(a);
				raToXmlCOP(out, a);
				break;
			}
			
			case CIMDataType::EMBEDDEDCLASS:
			{
				CIMClassArray ca;
				cv.get(ca);
				StringArray sa;
				for (size_t i = 0; i < ca.size(); ++i)
				{
					OStringStream ss;
					CIMtoXML(ca[i], ss);
					sa.push_back(ss.toString());
				}
				raToXmlSA(out, sa);
				break;
			}
			
			case CIMDataType::EMBEDDEDINSTANCE:
			{
				CIMInstanceArray ia;
				cv.get(ia);
				StringArray sa;
				for (size_t i = 0; i < ia.size(); ++i)
				{
					OStringStream ss;
					CIMInstancetoXML(ia[i],ss);
					sa.push_back(ss.toString());
				}
				raToXmlSA(out, sa);
				break;
			}
			default:
				OW_ASSERT(0);
		}
	}
	else if (cv.getType() == CIMDataType::REFERENCE)
	{
		out << "<VALUE.REFERENCE>";
		CIMObjectPath a(CIMNULL);
		cv.get(a);
		if (a.getFullNameSpace().isLocal())
		{
			if (a.getNameSpace().empty())
			{
				CIMInstanceNametoXML(a, out);
			}
			else
			{
				CIMLocalInstancePathtoXML(a, out);
			}
		}
		else
		{
			CIMInstancePathtoXML(a, out);
		}
		out << "</VALUE.REFERENCE>";
	}
	else
	{
		out << "<VALUE>";
		switch (cv.getType())
		{
			case CIMDataType::BOOLEAN:
			case CIMDataType::UINT8:
			case CIMDataType::SINT8:
			case CIMDataType::UINT16:
			case CIMDataType::SINT16:
			case CIMDataType::UINT32:
			case CIMDataType::SINT32:
			case CIMDataType::UINT64:
			case CIMDataType::SINT64:
			case CIMDataType::DATETIME:
			{
				out << cv.toString();
				break;
			}
			case CIMDataType::REAL32:
			{
				char tmpbuf[128];
#if FLT_RADIX == 2
#if defined(OW_REAL32_IS_FLOAT)
				::SNPRINTF(tmpbuf, sizeof(tmpbuf), "%.*e", FLT_MANT_DIG * 3 / 10 + 1, static_cast<double>(cv.toReal32()));
#elif defined(OW_REAL32_IS_DOUBLE)
				::SNPRINTF(tmpbuf, sizeof(tmpbuf), "%.*e", DBL_MANT_DIG * 3 / 10 + 1, cv.toReal32());
#endif
#else
#error "The formula for computing the number of digits of precision for a floating point needs to be implmented. It's ceiling(bits * log(FLT_RADIX) / log(10))"
#endif
				out << tmpbuf;
				break;
			}
			case CIMDataType::REAL64:
			{
				char tmpbuf[128];
#if FLT_RADIX == 2
#if defined(OW_REAL64_IS_DOUBLE)
				::SNPRINTF(tmpbuf, sizeof(tmpbuf), "%.*e", DBL_MANT_DIG * 3 / 10 + 1, cv.toReal64());
#elif defined(OW_REAL64_IS_LONG_DOUBLE)
				::SNPRINTF(tmpbuf, sizeof(tmpbuf), "%.*Le", LDBL_MANT_DIG * 3 / 10 + 1, cv.toReal64());
#endif
#else
#error "The formula for computing the number of digits of precision for a floating point needs to be implmented. It's ceiling(bits * log(FLT_RADIX) / log(10))"
#endif
				out << tmpbuf;
				break;
			}
			case CIMDataType::CHAR16:
			case CIMDataType::STRING:
			{
				out << XMLEscape(cv.toString());
				break;
			}
			
			case CIMDataType::EMBEDDEDCLASS:
			{
				CIMClass cc(CIMNULL);
				cv.get(cc);
				String s;
				OStringStream ss;
				CIMtoXML(cc, ss);
				out << XMLEscape(ss.toString());
				break;
			}
			
			case CIMDataType::EMBEDDEDINSTANCE:
			{
				CIMInstance i(CIMNULL);
				cv.get(i);
				String s;
				OStringStream ss;
				CIMInstancetoXML(i,ss);
				out << XMLEscape(ss.toString());
				break;
			}
			default:
				OW_ASSERT(0);
		}
		out << "</VALUE>";
	}
}