예제 #1
0
Boolean ProcessValueObjectElement(CIMRepository& repository, XmlParser& parser)
{
    XmlEntry entry;

    if (!XmlReader::testStartTag(parser, entry, "VALUE.OBJECT"))
	return false;

    CIMClass cimClass;
    CIMQualifierDecl qualifierDecl;

    if (XmlReader::getClassElement(parser, cimClass))
    {
	cout << "Creating: class ";
	cout << cimClass.getClassName() << endl;

	repository.createClass(CIMV2_NAMESPACE, cimClass);
	repository.createClass(ROOT_NAMESPACE, cimClass);
    }
    else if (XmlReader::getQualifierDeclElement(parser, qualifierDecl))
    {
	cout << "Creating: qualifier ";
	cout << qualifierDecl.getName() << endl;

	repository.setQualifier(CIMV2_NAMESPACE, qualifierDecl);
	repository.setQualifier(ROOT_NAMESPACE, qualifierDecl);
    }

    XmlReader::expectEndTag(parser, "VALUE.OBJECT");

    return true;
}
예제 #2
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::performInitialCheck
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::performInitialCheck(const CIMClass& newClass,
										   Boolean updateClass)
{
	PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::performInitialCheck()");
	
	// check if class already exists, just for createClass calls
	if ((classAlreadyExists(newClass.getClassName().getString())) && (!updateClass))
	{
		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
			"WMIClassProvider::performInitialCheck - class already exists, throw CIM_ERR_ALREADY_EXISTS exception");

		throw CIMException(CIM_ERR_ALREADY_EXISTS);
	}

	// check if newClass has a superclass
	if (newClass.getSuperClassName().getString() != String::EMPTY)
	{
		// verifies if the superclass exists
		if (!classAlreadyExists(newClass.getSuperClassName().getString()))
		{
			// superclass doesn't exist, trace and throw error
			String tmp = newClass.getSuperClassName().getString();

			Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
				"WMIClassProvider::performInitialCheck() - the superclass %s wasn't yet registered", tmp.getCString()); 

			throw CIMException(CIM_ERR_INVALID_SUPERCLASS);
		}
	}

	PEG_METHOD_EXIT();

	return;
}
예제 #3
0
CIMClass LocalRepository::getClass(
    const String & nameSpace,
    const String & className,
    Boolean includeQualifiers,
    Boolean includeClassOrigin,
    const CIMPropertyList & propertyList)
{
    // create a duplicate object before modifying
    CIMClass cimClass = context->lookupClass("test_namespace", className).clone();

    if(!includeQualifiers)
    {
        // remove qualifiers from class
        for(Uint32 i = 0, n = cimClass.getQualifierCount(); i < n; i++)
        {
            cimClass.removeQualifier(i);
        }

        // remove qualifiers from properties
        for(Uint32 i = 0, n = cimClass.getPropertyCount(); i < n; i++)
        {
            CIMProperty cimProperty = cimClass.getProperty(i);

            for(Uint32 j = 0, m = cimProperty.getQualifierCount(); j < m; j++)
            {
                cimProperty.removeQualifier(j);
            }
        }
    }

    if(!includeClassOrigin)
    {
        // remove class origin
        for(Uint32 i = 0, n = cimClass.getPropertyCount(); i < n; i++)
        {
            cimClass.getProperty(i).setClassOrigin(CIMName());
        }
    }

    cimClass.setPath(CIMObjectPath("localhost", "test_namespace", cimClass.getClassName()));

    return(cimClass);
}
예제 #4
0
int _getClass(const int argc, const char **argv)
{
  CIMClass cldef;
  try
  {
    cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );
  }
  catch (Exception& e)
  {
    cerr << /* "getClass: " << */ e.getMessage() << endl;
    return 1;
  }

  // Display the class definition
  // without qualifiers, for the moment

  // First the class name and superclass
  cout << "class " << cldef.getClassName().getString() << " : "
    << cldef.getSuperClassName().getString() << endl;
  cout << "{" << endl;
  
  // Now the properties
  // No qualifiers except [key], but specify type, array
  for (int i=0; i<cldef.getPropertyCount(); i++)
  {
    CIMProperty p = cldef.getProperty(i);
    cout << "  ";
    // output key, if required
    if (_isKey(p)) cout << "[ Key ] ";
    // prepare to output type, but
    // first, if type is "reference", find target class
    if (p.getType() == CIMTYPE_REFERENCE)
      cout << p.getReferenceClassName().getString() << " REF ";
    // output type
    else cout << cimTypeToString(p.getType()) << " ";
    // output name
    cout << p.getName().getString();
    // output array, if required
    if (p.isArray()) cout << "[]";
    // final eol
    cout << ";" << endl;
  }
  
  // need to do methods
  for (int i=0; i<cldef.getMethodCount(); i++)
  {
    CIMMethod m = cldef.getMethod(i);
    // output type
    cout << "  " << cimTypeToString(m.getType()) << " ";
    // output name
    cout << m.getName().getString() << "(";
    // output parameters
    // new line if there are any parameters
    for (int j=0; j<m.getParameterCount(); j++)
    {
      CIMParameter p = m.getParameter(j);
      // output IN/OUT qualifiers on a fresh line
      cout << endl << "    [ ";
      // loop through qualifiers looking for IN, OUT
      for (int k=0; k<p.getQualifierCount(); k++)
      {
        // when one found, output its value
        CIMQualifier q = p.getQualifier(k);
        if (q.getName().equal("in") ||
            q.getName().equal("out"))
        {
          cout << q.getName().getString() << " ";
        }
      }
      // Now the type
      cout << "] " << cimTypeToString(p.getType()) << " ";
      // finally the name
      cout << p.getName().getString();
      // array brackets
      if (p.isArray()) cout << "[]";
      // closing , on parameter if not last
      if (j != m.getParameterCount()-1) cout << ",";
    }
    // after last param, indent before closing paren

    // close paren
    cout << ")";
    // if (m.isArray()) cout << "[]";
    // finish output
    cout << ";" << endl;
  }
  
  // final brace and done
  cout << "};" << endl;

  return 0; 
}
예제 #5
0
void test01()
{
    // class MyClass : YourClass
    // {
    //     string message = "Hello";
    // }
    try
    {
        CIMName a = "A_class1";
        CIMName b = "A_class2";
        CIMClass c0(a, b);
        CIMClass c1(a, CIMName("A_class2"));
        CIMClass c2(CIMName("A_class1"), b);
        CIMClass c3(b, a);
    }
    catch (InvalidNameException & ine)
    {
        if (verbose)
        {
        cout << "Caught unexpected exception: " << ine.getMessage() << endl;
        }
    }
    try
    {
        //
        //  Invalid class name
        //
        CIMClass class0(CIMName ("//localhost/root/cimv2:MyClass"),
            CIMName ("YourClass"));

        PEGASUS_TEST_ASSERT(class0.getPath() ==
            CIMObjectPath("//localhost/root/cimv2:MyClass"));
    }
    catch (InvalidNameException & ine)
    {
        if (verbose)
        {
        cout << "Caught expected exception: " << ine.getMessage() << endl;
        }
    }

    CIMClass class1(CIMName ("MyClass"), CIMName ("YourClass"));

    class1
    .addQualifier(CIMQualifier(CIMName ("association"), true))
    .addQualifier(CIMQualifier(CIMName ("q1"), Uint32(55)))
    .addQualifier(CIMQualifier(CIMName ("q2"), String("Hello")))
    .addProperty(CIMProperty(CIMName ("message"), String("Hello")))
    .addProperty(CIMProperty(CIMName ("count"), Uint32(77), 0, CIMName(),
            CIMName("YourClass"), true))
    .addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN)
        .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING))
        .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32)));

    // Test the method count function
    PEGASUS_TEST_ASSERT(class1.getClassName().equal(CIMName ("myclass")));
    PEGASUS_TEST_ASSERT(class1.getSuperClassName() == CIMName ("YourClass"));

    PEGASUS_TEST_ASSERT(class1.getMethodCount() ==1);


    // Test the findMethod and isMethod functions
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);

    // Test the manipulation of an embeddedObjectProperty
    CIMClass embedClass(CIMName ("embedObj"), CIMName ());
    class1.addProperty(CIMProperty(CIMName ("embedObj"),
        CIMObject(embedClass), 0, CIMName(),
            CIMName(), false));

    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("embedObj")) != PEG_NOT_FOUND);
    Uint32  posProp = class1.findProperty(CIMName ("embedObj"));
    CIMConstProperty constprop1 = class1.getProperty(posProp);
    PEGASUS_TEST_ASSERT(constprop1.getClassOrigin() == CIMName());
    PEGASUS_TEST_ASSERT(constprop1.getType() == CIMTYPE_OBJECT);
    class1.removeProperty(posProp);

    // Now add another method and reconfirm.

    class1.addMethod(CIMMethod(CIMName ("makeActive"), CIMTYPE_BOOLEAN)
    .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING))
    .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32)));

    PEGASUS_TEST_ASSERT(class1.getMethodCount() == 2);

    // Test the findMethod and isMethod functions
    // with two methods defined
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("makeActive")) != PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("makeActive")) != PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);


    // Test RemoveMethod function
    Uint32 posMethod;
    posMethod = class1.findMethod(CIMName ("isActive"));
    PEGASUS_TEST_ASSERT(posMethod != PEG_NOT_FOUND);

    class1.removeMethod(posMethod);

    PEGASUS_TEST_ASSERT(class1.findMethod(
                CIMName ("isActive")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.getMethodCount() == 1);

    //ATTN: P3 TODO add tests for different case names

    //Qualifier manipulation tests  (find, remove)

    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("qx")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(
                CIMName ("association")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.isAssociation());

    // Remove middle Qualifier "q2"
    Uint32 posQualifier;
    posQualifier = class1.findQualifier(CIMName ("q2"));
    CIMConstQualifier qconst = class1.getQualifier(posQualifier);

    PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 3);
    PEGASUS_TEST_ASSERT(posQualifier <= class1.getQualifierCount());
    class1.removeQualifier(posQualifier);
    PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 2);

    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.isAssociation());


    // Remove the first parameter "q1"
    posQualifier = class1.findQualifier(CIMName ("q1"));

    PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 2);
    CIMQualifier cq = class1.getQualifier( class1.findQualifier(
                CIMName ("q1")));
    PEGASUS_TEST_ASSERT(posQualifier <= class1.getQualifierCount());
    class1.removeQualifier(posQualifier);
    PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 1);

    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.isAssociation());


    // ATTH: P3 Add tests for try block for outofbounds



    //The property manipulation tests.

    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("count")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("message")) != PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("isActive")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.getPropertyCount() == 2);


    Uint32  posProperty;
    posProperty = class1.findProperty(CIMName ("count"));
    CIMConstProperty constprop = class1.getProperty(posProperty);
    PEGASUS_TEST_ASSERT(constprop.getClassOrigin() == CIMName("YourClass"));
    PEGASUS_TEST_ASSERT(constprop.getPropagated());
    class1.removeProperty(posProperty);
    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("message")) != PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(class1.findProperty(
                CIMName ("count")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(class1.getPropertyCount() == 1);
    CIMProperty cp = class1.getProperty( class1.findProperty
        (CIMName ("message")));
    PEGASUS_TEST_ASSERT(cp.getClassOrigin().isNull());
    PEGASUS_TEST_ASSERT(!cp.getPropagated());

    if(verbose)
    {
        XmlWriter::printClassElement(class1);
        MofWriter::printClassElement(class1);
    }

    Buffer out;
    MofWriter::appendClassElement(out, class1);
    out.clear();
    XmlWriter::appendClassElement(out, class1);

    PEGASUS_TEST_ASSERT(!class1.isAbstract());

    CIMName squal("q1");
    PEGASUS_TEST_ASSERT(class1.findQualifier(squal) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(!class1.hasKeys());

    Array<CIMName> keyNames;
    class1.getKeyNames(keyNames);

    CIMClass c2(CIMName ("MyClass"));

    PEGASUS_TEST_ASSERT(c2.getClassName().equal(CIMName ("myclass")));


    // Error uninitialized handle
    c2.setSuperClassName(CIMName ("CIM_Element"));
    PEGASUS_TEST_ASSERT(c2.getSuperClassName() == CIMName ("CIM_Element"));

    CIMClass c3 = c2.clone();
    c3 = c2;


    try
    {
        CIMMethod cm = c2.getMethod(0);
    }
    catch(IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }

    const CIMClass c4(CIMName ("MyClass"), CIMName ("YourClass"));

    CIMConstClass c5(CIMName ("MyClass"), CIMName ("YourClass"));
    CIMConstClass c6(CIMName ("MyClass"));
    CIMConstClass cc7(c6);
    CIMClass c7 = c5.clone();
    const CIMClass c8(class1);

    // Test the findMethod and isMethod functions
    PEGASUS_TEST_ASSERT(c7.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(c7.findQualifier(CIMName ("dummy")) == PEG_NOT_FOUND);

    try
    {
        CIMConstMethod cm = c8.getMethod(0);
    }
    catch(IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }

    try
    {
        CIMConstProperty ccp = c8.getProperty(c8.findProperty
            (CIMName ("count")));
    }
    catch(IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }

    if(verbose)
    {
    XmlWriter::printClassElement(c5);
    }

    try
    {
        CIMConstMethod cm = cc7.getMethod(0);
    }
    catch(IndexOutOfBoundsException& e)
    {
    if(verbose)
        cout << "Exception: " << e.getMessage() << endl;
    }
    // Test the findMethod and isMethod functions
    PEGASUS_TEST_ASSERT(c4.findMethod(
                CIMName ("DoesNotExist")) == PEG_NOT_FOUND);

    //Qualifier manipulation tests  (find, remove)

    PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("qx")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("q1")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(c4.findQualifier(
                CIMName ("association")) == PEG_NOT_FOUND);

    posProperty = c4.findProperty(CIMName ("count"));

    try
    {
        CIMConstQualifier ccq = c4.getQualifier(c4.findQualifier
            (CIMName ("q1")));
    }
    catch (IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }

    PEGASUS_TEST_ASSERT(c4.findProperty(CIMName ("count")) == PEG_NOT_FOUND);

    PEGASUS_TEST_ASSERT(c4.getClassName() == CIMName ("MyClass"));
    PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("MyClass")));
    PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("MYCLASS")));
    PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("myclass")));
    PEGASUS_TEST_ASSERT(!c4.getClassName().equal(CIMName ("blob")));


    PEGASUS_TEST_ASSERT(c4.getSuperClassName() == CIMName ("YourClass"));

    // test the setSuperClassName function
    /* ATTN KS 29 April.  This test has problems.  Relook later.
      Think test, not code.
    c4.setSuperClassName(CIMName ("JunkClass"));
    PEGASUS_TEST_ASSERT(c4.getSuperClassName() == CIMName ("JunkClass"));
    c4.setSuperClassName(CIMName ("YourClass"));
    */
    PEGASUS_TEST_ASSERT(c5.getSuperClassName() == CIMName ("YourClass"));

    PEGASUS_TEST_ASSERT(c5.getQualifierCount() == 0);
    posQualifier = c5.findQualifier(CIMName ("q2"));

    // throws out of bounds
    try
    {
        CIMConstQualifier qconst1 = c5.getQualifier(posQualifier);
    }
    catch(IndexOutOfBoundsException& e)
    {
        if(verbose)
            cout << "Exception: " << e.getMessage() << endl;
    }
    if(verbose)
    {
        cout << "All tests" << endl;
    }
}
예제 #6
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createProperties creates all properties including keys 
//									  add the qualifiers too
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createProperties(const CIMClass& newClass,
									    IWbemServices *pServices,
										IWbemClassObject *pNewClass)
{
	HRESULT hr;
	
	PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createProperties()");

	// create the properties but don't create the keys again
	CIMProperty prop;

	for (Uint32 i = 0; i < newClass.getPropertyCount(); i++)
	{
		prop = newClass.getProperty(i).clone();

		// create the properties
		try 
		{
			createProperty(prop, pNewClass);
		}
		catch (CIMException&)
		{
			throw;
		}
		
		// get a pointer to work with qualifiers 
		CComPtr<IWbemQualifierSet> pQual;
		CComBSTR bs = prop.getName().getString().getCString();
		
		hr = pNewClass->GetPropertyQualifierSet(bs, &pQual);
		bs.Empty();

		if (FAILED(hr))
		{
			CMyString msg;
			msg.Format("Failed get Qualifier set of [%s]. Error: 0x%X", 255, 
				prop.getName().getString().getCString(), hr);
		
			Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createProperties() - %s", (LPCTSTR)msg);

			if (pQual)
				pQual.Release();
			
			throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); 
		}

		// set the qualifiers to the property
		for (Uint32 j = 0; j < prop.getQualifierCount(); j++)
		{
			WMIQualifier qualifier(prop.getQualifier(j));
			try 
			{
				createQualifier(qualifier, pQual);
			}
			catch (CIMException&)
			{
				if (pQual)
					pQual.Release();

				throw;
			}
		}

		// set the CLASSORIGIN qualifier if it wasn't set yet
		String strClassorigin = prop.getClassOrigin().getString();
		
		if (strClassorigin.size() == 0)
		{
			strClassorigin = newClass.getClassName().getString();
		}

		WMIFlavor flavor(CIMFlavor::DEFAULTS);
		
		/*
		v.vt = VT_BSTR;
		v.bstrVal = strClassorigin.getCString();
		*/
		CComVariant v;
		v = strClassorigin.getCString();
		
		hr = pQual->Put(L"CLASSORIGIN", &v, flavor.getAsWMIValue());
		v.Clear();

		if (pQual)
			pQual.Release();

		if (FAILED(hr))
		{
			CMyString msg;
			msg.Format("Failed to add CLASSORIGIN qualifier in [%s]. Error: 0x%X", 255, 
				prop.getName().getString().getCString(), hr);

			Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createProperties () - %s", (LPCTSTR)msg);
			
			throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
		}
	}

	PEG_METHOD_EXIT();

	return;
}
예제 #7
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createClassNameAndClassQualifiers
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createClassNameAndClassQualifiers(const CIMClass& newClass,
														 IWbemServices *pServices,
														 IWbemClassObject **pNewClass,
														 const bool hasSuperClass)
{
	HRESULT hr;

	PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createClassNameAndClassQualifiers()");

	// if the class has a superclass, we need to spwan a derived
	if (hasSuperClass)
	{
		// get the superclass name
		CComPtr<IWbemClassObject> pSuperClass;
		String tmp = newClass.getSuperClassName().getString();
		CComBSTR bs = tmp.getCString();

		hr = pServices->GetObject(
				bs, 
				NULL, 
				NULL, 
				&pSuperClass, 
				NULL);

		bs.Empty();

		if (FAILED(hr))
		{
			if (pSuperClass)
				pSuperClass.Release();

			CMyString msg;
			msg.Format("Failed to get a pointer to Superclass [%s]. Error: 0x%X", 255, tmp.getCString(), hr);

			Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);

			throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); 
		}

		//Creates the new class
		pSuperClass->SpawnDerivedClass(NULL, pNewClass);
		if (pSuperClass)
			pSuperClass.Release();
	}
	else
	{
		// we are creating a base class
		hr = pServices->GetObject(NULL, 
								  NULL, 
								  NULL, 
								  pNewClass, 
								  NULL);

		if (FAILED(hr))
		{
			CMyString msg;
			msg.Format("Failed to get a pointer to a new class. Error: 0x%X", hr);

			Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);
			
			throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
		}
	}
	
	// create the class name
	CComVariant v;
	v = newClass.getClassName().getString().getCString();
	hr = (*pNewClass)->Put(L"__CLASS", 0, &v, 0);
	
	v.Clear();

	if (FAILED(hr))
	{
		CMyString msg;
		msg.Format("Failed to add class name on class [%s]. Error: 0x%X", 255, 
			newClass.getClassName().getString().getCString(), hr);

		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
			          "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);

		if (*pNewClass)
			(*pNewClass)->Release();
		
		throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
	}

	// get a pointer to work with qualifiers
	CComPtr<IWbemQualifierSet> pNewClassQualifier;
	hr = (*pNewClass)->GetQualifierSet(&pNewClassQualifier);

	if (FAILED(hr))
	{
		CMyString msg;
		msg.Format("Failed to get the Qualifier set pointer of class [%s]. Error: 0x%X", 255, 
			newClass.getClassName().getString().getCString(), hr);

		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
			          "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);
		
		if (*pNewClass)
			(*pNewClass)->Release();

		if (pNewClassQualifier)
			pNewClassQualifier.Release();

		throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
	}
	
	// check the class qualifiers and create them if they are valid
	// we are taking care of the class qualifiers and not methods/properties qualifiers :D
	for (Uint32 i = 0; i < newClass.getQualifierCount(); i++)
	{
		try 
		{
			WMIQualifier qualifier(newClass.getQualifier(i).clone());
			
			createQualifier(qualifier, pNewClassQualifier);
		}
		catch (CIMException&)
		{
			if (*pNewClass)
				(*pNewClass)->Release();

			if (pNewClassQualifier)
				pNewClassQualifier.Release();

			throw;
		}
	}

	if (pNewClassQualifier)
		pNewClassQualifier.Release();

	PEG_METHOD_EXIT();

	return;
}
예제 #8
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::modifyClass
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::modifyClass(const String& nameSpace,
								   const String& userName,
								   const String& password,
								   const CIMClass& modifiedClass)
{

	PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WMIClassProvider::modifyClass()");

	setup(nameSpace, userName, password);

	if (!m_bInitialized)
	{
		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
			"WMIClassProvider::modifyClass - m_bInitilized= %x, throw CIM_ERR_FAILED exception",  
			m_bInitialized);

		throw CIMException(CIM_ERR_FAILED);
	}

	// check if class does exist
	if (!classAlreadyExists(modifiedClass.getClassName().getString()))
	{
		throw CIMException(CIM_ERR_NOT_FOUND);
	}

	// check if superclass does exist
	if (!classAlreadyExists(modifiedClass.getSuperClassName().getString()))
	{
		// superclass doesn't exist
		throw CIMException(CIM_ERR_INVALID_SUPERCLASS);
	}

	//
	// By Jair
	//
	// If the class already has a superclass and it isn't explicitly 
	// defined in the <modifiedClass> definition, we must set it 
	// before changing the control to the createClass method. This way 
	// we don't change the Class definition, as specified in DSP0200.
	//
	CIMClass updatedClass = modifiedClass;

	if ((updatedClass.getSuperClassName().getString()).size() == 0)
	{
		// set the superclass

		CComPtr<IWbemClassObject> pClass;
	
		if (!(_collector->getObject(&pClass, updatedClass.getClassName().getString())))
		{
			if (pClass)
				pClass.Release();

			throw CIMException(CIM_ERR_NOT_FOUND);
		}

		String superClass = _collector->getSuperClass(pClass);
		
		if (0 != superClass.size())
		{	
			CIMName superclassName = superClass;
			updatedClass.setSuperClassName(superclassName);
		}

		if (pClass)
			pClass.Release();
	}
		
	//update the class using createClass
	createClass(nameSpace,
			    userName,
				password,
				updatedClass,
				true);

	PEG_METHOD_EXIT();

	return;
}
예제 #9
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createClass
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createClass(const String& nameSpace,
								   const String& userName,
								   const String& password,
								   const CIMClass& newClass,
								   Boolean updateClass)
{
	
	PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createClass()");

	setup(nameSpace, userName, password);

	if (!m_bInitialized)
	{
		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
			"WMIClassProvider::createClass - m_bInitilized= %x, throw CIM_ERR_FAILED exception",  
			m_bInitialized);

		throw CIMException(CIM_ERR_FAILED);
	}
	
	// Check if the class does not exist and if if has a valid
	// superclass
	performInitialCheck(newClass, updateClass);
	bool hasSuperClass = (newClass.getSuperClassName().getString() != String::EMPTY);

	// gets the pointers
	CComPtr<IWbemServices> pServices;
	CComPtr<IWbemClassObject> pNewClass;

	if (!_collector->Connect(&pServices))
	{
		if (pServices)
			pServices.Release();

		throw CIMException (CIM_ERR_FAILED);
	}

	try 
	{
	    // starts the class creation by name and class qualifiers
		createClassNameAndClassQualifiers(
			newClass, 
			pServices, 
			&pNewClass, 
			hasSuperClass);

		// create properties
		createProperties(
			newClass, 
			pServices, 
			pNewClass);

		// create methods
		createMethods(
			newClass, 
			pServices, 
			pNewClass);
	}
	catch (CIMException&) 
	{
		if (pServices)
			pServices.Release();

		if (pNewClass)
			pNewClass.Release();

		throw;
	}
	
	// Store the new class into WMI
	LONG lFlags = 0L;
	
	//if updateClass is set, we are trying a modifyclass
	if (updateClass) lFlags = WBEM_FLAG_UPDATE_ONLY;

	HRESULT hr = pServices->PutClass(pNewClass, lFlags, NULL, NULL);
	
	if (pServices)
		pServices.Release();
	
	if (pNewClass)
		pNewClass.Release();
	
	if (FAILED(hr))
	{
		CMyString msg;
		msg.Format("It is not possible to create the class [%s]. Error: 0x%X", 255, 
					newClass.getClassName().getString(), hr);

		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createClass() - %s", (LPCTSTR)msg);

		switch(hr)
		{
			case E_ACCESSDENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break;
			case WBEM_E_ACCESS_DENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break;
			case WBEM_E_CLASS_HAS_CHILDREN: throw CIMException(CIM_ERR_CLASS_HAS_CHILDREN); break;
			case WBEM_E_CLASS_HAS_INSTANCES: throw CIMException(CIM_ERR_CLASS_HAS_INSTANCES); break;
			case WBEM_E_NOT_FOUND: throw CIMException(CIM_ERR_NOT_FOUND); break;
			case WBEM_E_INVALID_CLASS: throw CIMException(CIM_ERR_INVALID_PARAMETER); break;
			default: throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
		}
	}

	PEG_METHOD_EXIT();

	return;
}
void WQLSelectStatementRep::validate()
{
    if(_ctx == NULL){
        MessageLoaderParms parms(
            "WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",
            "Trying to process a query with a NULL Query Context.");
      throw QueryValidationException(parms);
   }
    CIMClass fromClass;
    try
   {
     fromClass = _ctx->getClass(_className);

    CIMObjectPath className (String::EMPTY, _ctx->getNamespace (), _className);
     Array<CIMName> whereProps =
        getWherePropertyList(className).getPropertyNameArray();
     Array<CIMName> selectProps =
        getSelectPropertyList(className).getPropertyNameArray();

     // make sure all properties match properties on the from class
     for(Uint32 i = 0; i < whereProps.size(); i++){
         Uint32 index = fromClass.findProperty(whereProps[i]);
            if(index == PEG_NOT_FOUND){
                MessageLoaderParms parms(
                    "WQL.WQLSelectStatementRep.PROP_NOT_FOUND",
                    "The property $0 was not found in the FROM class $1",
                    whereProps[i].getString(),
                    fromClass.getClassName().getString());
            throw QueryMissingPropertyException(parms);
            }
         else
         {
           //
           //  Property exists in class
           //  Verify it is not an array property
           //
           CIMProperty classProperty = fromClass.getProperty(index);
           if (classProperty.isArray ())
           {
             MessageLoaderParms parms(
                 "WQL.WQLSelectStatementRep.WHERE_PROP_IS_ARRAY",
                 "Array property $0 is not supported in the WQL WHERE clause.",
                 whereProps[i].getString());
             throw QueryValidationException(parms);
           }
         }
        }

     for(Uint32 i = 0; i < selectProps.size(); i++){
       if(fromClass.findProperty(selectProps[i]) == PEG_NOT_FOUND){
         MessageLoaderParms parms(
             "WQL.WQLSelectStatementRep.PROP_NOT_FOUND",
             "The property $0 was not found in the FROM class $1",
             selectProps[i].getString(),
             fromClass.getClassName().getString());
         throw QueryMissingPropertyException(parms);
       }
     }
   }
   catch (const CIMException& ce)
   {
     if (ce.getCode() == CIM_ERR_INVALID_CLASS ||
         ce.getCode() == CIM_ERR_NOT_FOUND)
     {
       MessageLoaderParms parms(
           "WQL.WQLSelectStatementRep.CLASSNAME_NOT_IN_REPOSITORY",
           "The class name $0 was not found in the repository.",
           _className.getString());
       throw QueryValidationException(parms);
     }
     else
     {
       throw;
     }
   }
}
예제 #11
0
int main(int argc, char** argv)
{
//   TestCertClient Parameters
//       Parameter 1: Client Certification File
//       Parameter 2: Client Private Key File
//       Parameter 3: Random Key File
//       Parameter 4: User Name
//       Parameter 5: Password
//       Parameter 6: Expected Result
//       Parameter 7: Expected Identity

    if ((argc < 3) || (argc > 8))
    {
        PEGASUS_STD(cout) << "Wrong number of arguments" << PEGASUS_STD(endl);
        exit(1);
    }

    String certpath;
    if (strcmp(argv[1],"NONE") != 0)
    {
        certpath = argv[1];
    }

    String keypath;
    if (strcmp(argv[2],"NONE") != 0)
    {
        keypath = argv[2];
    }

    String randFile;
    if (argc >=4)
    {
        if (strcmp(argv[3],"CONFIG") == 0)
        {
            const char* pegasusHome = getenv("PEGASUS_HOME");
            randFile = FileSystem::getAbsolutePath(
                pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);
        }
        else if (strcmp(argv[3],"NONE") != 0)
        {
            randFile = argv[3];
        }
    }

    String userName;
    if (argc >=  5)
    {
        userName = argv[4];
    }

    String password;
    if (argc >=  6)
    {
        password = argv[5];
    }

    expectedResultType expectedResult = NONE;
    expectedErrorType expectedError = ERROR_TYPE_NONE;
    String expectedUserName;
    if (argc >=  7)
    {
        if (strcmp(argv[6],"PASS") == 0)
        {
            expectedResult = PASS;
            if (argc >= 8)
            {
               if (strcmp(argv[7],"NONE") != 0)
               {
                   expectedUserName = argv[7];
               }
            }
        }
        else if (strcmp(argv[6],"FAIL") == 0)
        {
            expectedResult = FAIL;
            if (argc >= 8)
            {
               if (strcmp(argv[7],"NONE") == 0)
               {
                   expectedError = ERROR_TYPE_NONE;
               }
               else if (strcmp(argv[7],"HTTP_401") == 0)
               {
                   expectedError = ERROR_TYPE_HTTP_401;
               }
               else if (strcmp(argv[7],"CANNOT_CONNECT") == 0)
               {
                   expectedError = ERROR_TYPE_CANNOT_CONNECT;
               }
               else
               {
                   PEGASUS_STD(cout) << "Invalid expectedError parameter: "
                        << argv[7] << PEGASUS_STD(endl);
                   exit(1);
               }
            }
        }
        else if (strcmp(argv[6],"NONE") == 0)
        {
            expectedResult = NONE;
        }
        else
        {
            PEGASUS_STD(cout) << "Invalid expectedResult parameter: "
                << argv[6] << PEGASUS_STD(endl);
            exit(1);
        }
    }

    try
    {
        AutoPtr<SSLContext> pCtx;
        if (certpath != String::EMPTY)
        {
            pCtx.reset(
                new SSLContext(String::EMPTY, certpath, keypath, 0, randFile));
        }
        else
        {
            pCtx.reset(new SSLContext(String::EMPTY, 0, randFile));
        }

        PEGASUS_STD(cout)<< "TestCertClient::Connecting to 127.0.0.1:5989"
          << PEGASUS_STD(endl);
    
        CIMClient client;
        client.connect("127.0.0.1", 5989, *pCtx, userName, password);

        Array<CIMParamValue> inParams;
        Array<CIMParamValue> outParams;
        CIMValue retValue = client.invokeMethod(
            CIMNamespaceName("test/TestProvider"),
            CIMObjectPath("Test_MethodProviderClass"),
            CIMName("getIdentity"),
            inParams,
            outParams);

        if (expectedResult == FAIL)
        {
           throw Exception("Failure: Connection unexpectedly succeeded");
        }

        String retUserName;
        retValue.get(retUserName);

        if (expectedUserName != String::EMPTY)
        {
           if (expectedUserName != retUserName)
           {
              throw Exception("Provider returned unexpected Identity: "
                  + retUserName);
           }
        }
        CIMClass c = client.getClass("root/cimv2",
            "CIM_ComputerSystem", false, false, true);
          
        PEGASUS_STD(cout) << "Result: " <<  c.getClassName().getString()
            << PEGASUS_STD(endl);
    }
    catch (CIMClientHTTPErrorException& httpException)
    {
        if ((expectedResult == FAIL) &&
                (httpException.getCode() == 401) &&
                (expectedError == ERROR_TYPE_HTTP_401))
        {
            PEGASUS_STD(cout) << "+++++ "<< argv[0] <<
                " +++++ passed all tests" << PEGASUS_STD(endl);
            exit(0);
         }
           
         PEGASUS_STD(cout) << "Exception: " << httpException.getMessage()
            << PEGASUS_STD(endl);
         exit(1);
    }
    catch (CannotConnectException& connectException)
    {
        if ((expectedResult == FAIL) &&
                (expectedError == ERROR_TYPE_CANNOT_CONNECT))
        {
            PEGASUS_STD(cout) << "+++++ "<< argv[0] <<
                " +++++ passed all tests" << PEGASUS_STD(endl);
            exit(0);
        }
        PEGASUS_STD(cout) << "Exception: " << connectException.getMessage()
            << PEGASUS_STD(endl);
        exit(1);
    }
    catch (Exception& ex)
    {
        PEGASUS_STD(cout) << "Exception: " << ex.getMessage()
             << PEGASUS_STD(endl);
        exit(1);

    }
    catch (...)
    {
        PEGASUS_STD(cout) << "Unknown exception" << PEGASUS_STD(endl);
        exit(1);
    }
    if (expectedResult == PASS)
    {
        PEGASUS_STD(cout) << "+++++ "<< argv[0] <<
             " +++++ passed all tests" << PEGASUS_STD(endl);
    }
    else
    {
        PEGASUS_STD(cout) << "+++++ "<< "TestCertClient" 
            << " Terminated Normally" << PEGASUS_STD(endl);
    }
    exit(0);
}