Пример #1
0
CIMObjectPath
OperatingSystemProvider::_fill_reference(const CIMNamespaceName &nameSpace,
				         const CIMName &className)
{
    Array<CIMKeyBinding> keys;
    OperatingSystem os;
    String csName;
    String name;

    if (!os.getCSName(csName))
    {
        throw CIMOperationFailedException("OperatingSystemProvider "
                  "can't determine name of computer system");
    }

    if (!os.getName(name))
    {
        throw CIMOperationFailedException("OperatingSystemProvider "
                  "can't determine name of Operating System");
    }

    keys.append(CIMKeyBinding("CSCreationClassName",
 	                   CSCREATIONCLASSNAME.getString(),
			   CIMKeyBinding::STRING));
    keys.append(CIMKeyBinding("CSName", csName, CIMKeyBinding::STRING));
    keys.append(CIMKeyBinding("CreationClassName",
                              STANDARDOPERATINGSYSTEMCLASS.getString(),
                              CIMKeyBinding::STRING));
    keys.append(CIMKeyBinding("Name", name, CIMKeyBinding::STRING));

    return CIMObjectPath(csName, nameSpace, className, keys);
}
Пример #2
0
void DefaultInstanceProvider::_copyNameSpace(const String & nameSpace,
                                             const String & className)
{
    try
    {
        // create the new name space
        _repository->createNameSpace(nameSpace);
    }
    catch( Exception& ex )
    {
        const String msg = "Failed to create namespace: " + ex.getMessage();
        throw CIMOperationFailedException( msg );
    }
        
    CIMClient client;

    try 
    {
        // connect to the CIM server as a client
        client.connectLocal();
    }
    catch( Exception& ex )
    {
        const String msg = "Connect failed. " + ex.getMessage();
        throw CIMOperationFailedException( msg );
    }

    //
    // copy the qualifiers from the specified namespace to the new one
    //
    try
    {
        Array<CIMQualifierDecl> quals = client.enumerateQualifiers( nameSpace );

        int size = quals.size();
        for( int i = 0; i < size; ++i )
        {
            try 
            {
                _repository->setQualifier( nameSpace, quals[i] );
            } 
            catch( Exception& ex ) 
            {
                const String msg = "Failed to copy qualifiers. " + ex.getMessage();
                throw CIMOperationFailedException( msg );
            }
        }

        // disconnect from the server
        client.disconnect();
    }
    catch( Exception& ex )
    {
        const String msg = "Copy class failed. " + ex.getMessage();
        throw CIMOperationFailedException( msg );
    }
}
Пример #3
0
void RT_IndicationProvider::_checkOperationContext(const OperationContext& context,
                                                  const String &  funcName)
{
	 //
	 // Test the filter query container
	 //
	 SubscriptionFilterQueryContainer qContainer = context.get(SubscriptionFilterQueryContainer::NAME);
    if (qContainer.getFilterQuery() == String::EMPTY)
    {
      PEGASUS_STD(cout) << funcName << "- empty filter query" << PEGASUS_STD(endl);
      throw CIMOperationFailedException(funcName + "- empty filter query");
    }
    if (qContainer.getQueryLanguage() == String::EMPTY)
    {
      PEGASUS_STD(cout) << funcName << "- empty filter query lang" << PEGASUS_STD(endl);
      throw CIMOperationFailedException(funcName + "- empty filter query lang");
    }

    CIMNamespaceName tst("root/SampleProvider");
    if (!qContainer.getSourceNameSpace().equal(tst))
    {
      PEGASUS_STD(cout) << funcName << "- incorrect source namespace" << PEGASUS_STD(endl);
      throw CIMOperationFailedException(funcName + "- incorrect source namespace");
    }

    try
    {
      //
      // Try to parse the filter query from the filter query container
      //
      CIMOMHandleQueryContext ctx(qContainer.getSourceNameSpace(), _cimom);
      QueryExpression qe(qContainer.getQueryLanguage(),
                         qContainer.getFilterQuery(),
                         ctx);

      // Exercise the QueryExpression...this will cause repository access through
      // the CIMOMHandleQueryContext.
      qe.validate();
    }
    catch (Exception & e)
    {
      PEGASUS_STD(cout) << funcName << "- parse error: " << e.getMessage() << PEGASUS_STD(endl);
      throw CIMOperationFailedException(funcName + "- parse error: " + e.getMessage());
    }

    //
    // Test the filter condition container.
    // Note:  since this only contains the WHERE clause, the condition could be empty (and will
    // be for some testcases)
    //
    SubscriptionFilterConditionContainer cContainer = context.get(SubscriptionFilterConditionContainer::NAME);
	 if (cContainer.getQueryLanguage() == String::EMPTY)
    {
      PEGASUS_STD(cout) << funcName << "- empty filter condition lang" << PEGASUS_STD(endl);
      throw CIMOperationFailedException(funcName + "- empty filter condition lang");
    }
}
Пример #4
0
void DefaultInstanceProvider::_copyClass(
    const String & nameSpace,
    const String & className)
{
    CIMClient client;
    try 
    {
        // connect to the CIM server as a client
        client.connectLocal();
    }
    catch( Exception& ex )
    {
        const String msg = "Connect failed. " + ex.getMessage();
        throw CIMOperationFailedException( msg );
    }

    // get the class
    CIMClass cimClass;
    Boolean deepInheritance = true;
    Boolean localOnly = false;
    Boolean includeQualifiers = true;
    Boolean includeClassOrigin = false;

    try
    {
        cimClass = client.getClass(nameSpace, CIMName(className),
                                   localOnly, includeQualifiers,
                                   includeClassOrigin);
    }
    catch( Exception& ex )
    {
        const String msg = "Get Class failed. " + ex.getMessage();
        throw CIMOperationFailedException( msg );
    }

    // copy the super classes
    Array<CIMClass> superClasses;
    _copySuperClasses(client, nameSpace, cimClass, superClasses);

    // disconnect from the server
    client.disconnect();

    // now we can copy the base class
    try
    {
        _repository->createClass( nameSpace, cimClass );
    }
    catch( Exception& ex )
    {
        const String msg = "Create Class failed. " + ex.getMessage();
        throw CIMOperationFailedException( msg );
    }
}
Пример #5
0
bool
LinuxNetworkAdapterProvider::interface_is_my_type(
                                    enum network_provider_types classType,
      				    NetworkAdapterData const *adapter) const
{
   enum network_provider_types must_match = NETWORK_ADAPTER_PROVIDER_INVALID;

   /* Sanity check on the data. */
   if (classType == NETWORK_ADAPTER_PROVIDER_INVALID ||
       adapter->data_type() == NETWORK_ADAPTER_INVALID)
      // ATTN: Add more useful failure explanation
      throw CIMOperationFailedException("Invalid network adapter");

   switch (adapter->data_type()) {
   case NETWORK_ADAPTER_ETHERNET:
      must_match = NETWORK_ADAPTER_PROVIDER_ETHERNET;
      break;
   case NETWORK_ADAPTER_TOKENRING:
   case NETWORK_ADAPTER_FIBRECHANNEL:
   case NETWORK_ADAPTER_LO:
      must_match = NETWORK_ADAPTER_PROVIDER_OTHER;
      break;
   }
  
   return (classType == must_match);
}
Пример #6
0
Boolean ComputerSystem::getInitialLoadInfo(CIMProperty& p)
{
  // get from /stand/bootconf
  // perhaps this can change dynamically, so don't do it
  // in initialize()
  FILE *s = fopen("/stand/bootconf","r");
  if (s == 0) throw CIMOperationFailedException("/stand/bootconf: can't open");
  char buf[100];
  if (fgets(buf,100,s) == 0)
    throw CIMOperationFailedException("/stand/bootconf: can't read");
  fclose(s);
  Array<String> res;
  res.append(String(buf));
  p = CIMProperty(PROPERTY_INITIAL_LOAD_INFO,res);
  return true;
}
Пример #7
0
void DefaultInstanceProvider::enumerateInstanceNames(
	const OperationContext & context,
	const CIMObjectPath & classReference,
	ObjectPathResponseHandler & handler)
{
        CIMNamespaceName nameSpace = classReference.getNameSpace();
        CIMName className = classReference.getClassName();
        
        // create the namespace if necessary
        if (!_nameSpaceExists(nameSpace))
        {
            _copyNameSpace(nameSpace.getString(), className.getString());
        }

        // check to see if class already exists
        // if not, copy the class
        //
        try
        {
            CIMClass cimClass = _repository->getClass(nameSpace, className);
        }
        catch (Exception&)
        {
            // class does not exist

            //
            // copy the class
            //
            _copyClass(nameSpace.getString(), className.getString()); 
        }

        Array<CIMObjectPath> instanceNames;

        try
        {
            instanceNames = _repository->enumerateInstanceNamesForClass(
                                               nameSpace, className, true);
        }
        catch (Exception & ex)
        {
            const String msg = "Enumerate InstanceNames failed. " + ex.getMessage();
            throw CIMOperationFailedException( msg );
        }
    
	// begin processing the request
	handler.processing();

	for(Uint32 i = 0, n = instanceNames.size(); i < n; i++)
	{
		// deliver reference
		handler.deliver(instanceNames[i]);
	}

	// complete processing the request
	handler.complete();
}
Пример #8
0
void DefaultInstanceProvider::createInstance(
	const OperationContext & context,
	const CIMObjectPath & instanceReference,
	const CIMInstance & instanceObject,
	ObjectPathResponseHandler & handler)
{
        CIMNamespaceName nameSpace = instanceReference.getNameSpace();

        // get the class name
        CIMName className = instanceReference.getClassName();

        // create the namespace if necessary
        if (!_nameSpaceExists(nameSpace))
        {
            _copyNameSpace(nameSpace.getString(), className.getString());
        }

        // check to see if class already exists
        // if not, copy the class
        //
        try
        {
            CIMClass cimClass = _repository->getClass(nameSpace, className);
        }
        catch (Exception&)
        {
            // class does not exist

            //
            // copy the class
            //
            _copyClass(nameSpace.getString(), className.getString()); 
        }

        CIMObjectPath cimRef;

	// begin processing the request
	handler.processing();

        try
        {
            cimRef = _repository->createInstance(nameSpace, instanceObject);
        }
        catch (Exception & ex)
        {
            const String msg = "create Instance failed. " + ex.getMessage();
            throw CIMOperationFailedException( msg );
        }

	// deliver the new instance
	handler.deliver(cimRef);

	// complete processing the request
	handler.complete();
}
Пример #9
0
void DefaultInstanceProvider::deleteInstance(
	const OperationContext & context,
	const CIMObjectPath & instanceReference,
	ResponseHandler & handler)
{
        CIMNamespaceName nameSpace = instanceReference.getNameSpace();

        // get the class name
        CIMName className = instanceReference.getClassName();

        // create the namespace if necessary
        if (!_nameSpaceExists(nameSpace))
        {
            _copyNameSpace(nameSpace.getString(), className.getString());
        }

        // check to see if class already exists
        // if not, copy the class
        //
        try
        {
            CIMClass cimClass = _repository->getClass(nameSpace, className);
        }
        catch (Exception&)
        {
            // Class does not exist.  Copy the class.
            //
            _copyClass(nameSpace.getString(), className.getString()); 
        }

	// convert a potential fully qualified reference into a local reference
	// (class name and keys only).
	CIMObjectPath localReference = CIMObjectPath(
		String(),
		String(),
		instanceReference.getClassName(),
		instanceReference.getKeyBindings());
	
	// begin processing the request
	handler.processing();

        try
        {
           _repository->deleteInstance(nameSpace, localReference);
        }
        catch (Exception & ex)
        {
            const String msg = "delete Instance failed. " + ex.getMessage();
            throw CIMOperationFailedException( msg );
        }

	// complete processing the request
	handler.complete();
}
Boolean OperatingSystem::getCurrentTimeZone(Sint16& currentTimeZone)
{
    currentTimeZone = 0;

    TIME_ZONE_INFORMATION timezone;

    ::memset(&timezone, 0, sizeof(timezone));

    switch(::GetTimeZoneInformation(&timezone)) {
    case TIME_ZONE_ID_UNKNOWN:
        currentTimeZone = (Sint16)timezone.Bias;
        break;
    case TIME_ZONE_ID_STANDARD:
        currentTimeZone = (Sint16)timezone.Bias + (Sint16)timezone.StandardBias;
        break;
    case TIME_ZONE_ID_DAYLIGHT:
        currentTimeZone = (Sint16)timezone.Bias + (Sint16)timezone.DaylightBias;
        break;
    case TIME_ZONE_ID_INVALID:
    {
        char exceptionMsg[100] = "";
        sprintf (
            exceptionMsg,
            "Invalid time zone information : %d",
            GetLastError());
        throw CIMOperationFailedException(exceptionMsg);
    }
    default:
        break;
    }

    // the bias used to calculate the time zone is a factor that is used to
    // determine the UTC time from the local time. to get the UTC offset from
    // the local time, use the inverse.
    if(currentTimeZone != 0)
    {
        currentTimeZone *= -1;
    }

    return true;
}
Пример #11
0
void ANHProvider::_createAssociationInstances(
    Array<CIMInstance> nhrInst,
    Array<CIMInstance> rsapInst)
{
    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,
        "ANHProvider::_createAssociationInstances()");

    for (Uint16 i = 0; i<nhrInst.size(); i++)  // Routes loop.
    {
        CIMInstance _nhrInst = nhrInst[i];

        for (Uint16 j = 0; j<rsapInst.size(); j++)  // Remote Services loop.
        {
            CIMInstance _rsapInst = rsapInst[j];

            String _accessInfo,
                _address,
                _destAddress;
            CIMProperty _rsapAccessInfo = _rsapInst.getProperty(
                _rsapInst.findProperty(PROPERTY_ACCESS_INFO));
            _rsapAccessInfo.getValue().get(_accessInfo);

            Uint32 index = _accessInfo.find('/');

            if (index == PEG_NOT_FOUND)
            {
                PEG_METHOD_EXIT();
                throw CIMOperationFailedException(
                    String("Property AccessInfo is not in the expected ") +
                    String("\"Address/DestinationAddress\" format."));
            }
            else
            {
                _address = _accessInfo.subString(0,index-1);
                _destAddress = _accessInfo.subString(
                    index+1,
                    _accessInfo.size()-1);
            }

            CIMProperty _nhrDestinationAddress = _nhrInst.getProperty(
                _nhrInst.findProperty(PROPERTY_DESTINATION_ADDRESS));

            if (!_nhrDestinationAddress.getValue().equal(
                CIMValue(_destAddress)))
            {
                continue;
            }

            // Build the CIMObjectPath from the instances matching
            CIMObjectPath _rsapObj = _rsapInst.getPath();
            CIMObjectPath _nhrObj = _nhrInst.getPath();

            CIMInstance assocInst(CLASS_PG_ASSOCIATED_NEXT_HOP);
            assocInst.addProperty(
                CIMProperty(
                    CIMName("Antecedent"),
                    _rsapObj,
                    0,
                    CLASS_CIM_REMOTE_SERVICE_ACCESS_POINT));
            assocInst.addProperty(
                CIMProperty(
                    CIMName("Dependent"),
                    _nhrObj,
                    0,
                    CLASS_CIM_NEXT_HOP_ROUTE));

            // Build CIMObjectPath from keybindings
            Array<CIMKeyBinding> keyBindings;
            CIMKeyBinding _rsapBinding(
                CIMName("Antecedent"),
                _rsapObj.toString(),
                CIMKeyBinding::REFERENCE);
            CIMKeyBinding _nhrBinding(
                CIMName("Dependent"),
                _nhrObj.toString(),
                CIMKeyBinding::REFERENCE);
            keyBindings.append (_rsapBinding);
            keyBindings.append (_nhrBinding);

            CIMObjectPath path(
                String::EMPTY,
                CIMNamespaceName(),
                CLASS_PG_ASSOCIATED_NEXT_HOP,
                keyBindings);

            assocInst.setPath(path);
            _AssociationInstances.append(assocInst);
            break;

        }  // Remote Services loop end.

    }  // Routes loop end.

    PEG_METHOD_EXIT();
}
Пример #12
0
void DefaultInstanceProvider::_copySuperClasses(
    CIMClient & client,
    const String & nameSpace,
    const CIMClass & cimClass,
    Array<CIMClass> & superClasses)
{
    // get the super class name
    CIMName superClassName = cimClass.getSuperClassName();

    if (superClassName.isNull())
    {
        Uint32 numSuperClasses = superClasses.size();
        if (numSuperClasses == 0)
        {
            // No super class, just return
            return;
        }

        // copy the super classes
        for (Uint32 i = numSuperClasses; i > 0; i--)
        {
            // check to see if class already exists
            //
            CIMClass cimClass;
            try
            {
                cimClass = _repository->getClass(nameSpace, 
                                          superClasses[i-1].getClassName());
            }
            catch (Exception&)
            {
                //
                // Super class does not exist, create the super class
                //
                try
                {
                    _repository->createClass( nameSpace, superClasses[i-1] );
                }
                catch( Exception& ex )
                {
                    const String msg  = "Create superClass failed. " + ex.getMessage();
                    throw CIMOperationFailedException( msg );
                }
            }
        }
        return;
    }

    // get the super class 
    CIMClass superClass;
    Boolean localOnly = false;
    Boolean includeQualifiers = true;
    Boolean includeClassOrigin = false;

    try
    {
        superClass = client.getClass(nameSpace, superClassName,
                                     localOnly, includeQualifiers,
                                     includeClassOrigin);

        // add superclass to array
        superClasses.append(superClass);
    }
    catch( Exception& ex )
    {
        const String msg = "Get Super Class failed. " + ex.getMessage();
        throw CIMOperationFailedException( msg );
    }

    // recursive call.  copy superclasses of this class
    _copySuperClasses( client, nameSpace, superClass, superClasses); 
}
Пример #13
0
void DefaultInstanceProvider::getInstance(
	const OperationContext & context,
	const CIMObjectPath & instanceReference,
	const Boolean includeQualifiers,
	const Boolean includeClassOrigin,
	const CIMPropertyList & propertyList,
	InstanceResponseHandler & handler)
{
        CIMNamespaceName nameSpace = instanceReference.getNameSpace();

        // get the class name
        CIMName className = instanceReference.getClassName();

        Boolean localOnly = true;
        CIMInstance cimInstance;

        // create the namespace if necessary
        if (!_nameSpaceExists(nameSpace))
        {
            _copyNameSpace(nameSpace.getString(), className.getString());
        }

        // check to see if class already exists
        // if not, copy the class
        //
        try
        {
            CIMClass cimClass = _repository->getClass(nameSpace, className);
        }
        catch (Exception&)
        {
            // class does not exist

            //
            // copy the class
            //
            _copyClass(nameSpace.getString(), className.getString()); 
        }

	// convert a potential fully qualified reference into a local reference
	// (class name and keys only).
	CIMObjectPath localReference = CIMObjectPath(
		String(),
		String(),
		instanceReference.getClassName(),
		instanceReference.getKeyBindings());
	
        try
        {
           cimInstance = _repository->getInstance(
             nameSpace,
             localReference,
             localOnly,
             includeQualifiers,
             includeClassOrigin,
             propertyList);
        }
        catch( Exception& ex )
        {
            const String msg = "Get Instance failed. " + ex.getMessage();
            throw CIMOperationFailedException( msg );
        }

        // begin processing the request
        handler.processing();

        // deliver requested instance
        handler.deliver(cimInstance);

	// complete processing the request
	handler.complete();
}
Пример #14
0
// Read domain name, addresses e search list from /etc/resolv.conf
Boolean
DNSService::getDNSInfo()
{
#ifdef DNSPROVIDER_DEBUG
    cout << "DNSService::getDNSInfo()" << endl;
#endif

    FILE *fp;
    int count = 0, ind = 0;
    char buffer[512];
    Boolean ok = false;
    String strBuffer;
    // Open file DNS Configuration File
    if ((fp = fopen(DNS_FILE_CONFIG.getCString(), "r")) == NULL)
    {
        throw CIMOperationFailedException(
            "DNSService: can't open configuration file.");
    }

    // Check configuration file contents.
    while (!feof(fp))
    {
        memset(buffer, 0, sizeof(buffer));
        fscanf(fp, "%511s", buffer);
        strBuffer.assign(buffer);

        // Verify if keys exist
        if(String::equalNoCase(strBuffer, DNS_ROLE_DOMAIN) ||
           String::equalNoCase(strBuffer, DNS_ROLE_SEARCH) ||
           String::equalNoCase(strBuffer, DNS_ROLE_NAMESERVER) )
             count++;
        //A minimum of one key should exist
        if (count >= 1)
        {
            ok = true;
            break;
        }
    }
    if(!ok)
    {
        fclose(fp);
        throw CIMOperationFailedException
                  ("DNSService: configuration file is corrupt.");
    }

    // Clear all attributes
    rewind(fp);
    dnsName.clear();
    dnsSearchList.clear();
    dnsAddresses.clear();

    // Retrieve DNS informations from file
    while(!feof(fp)) {
        memset(buffer, 0, sizeof(buffer));
        fscanf(fp, "%511s", buffer);
        if(!strlen(buffer))
            continue; 
        if( buffer[0] == '#' )
        {
            // If it is a comment line then read the whole line and continue
            fgets(buffer,512,fp);
            continue;
        }
        strBuffer.assign(buffer);

        // Verify if key is domain name
        if(String::equalNoCase(strBuffer, DNS_ROLE_DOMAIN)) {
            fscanf(fp, "%511s", buffer);
            dnsName.assign(buffer);
#ifdef DNSPROVIDER_DEBUG
    cout << "DNSService::getDNSInfo() - buffer = `" << buffer << "'" << endl;
    cout << "DNSService::getDNSInfo() - dnsName = `" <<
         dnsName.getCString() << endl;
#endif
        }
        else
        {
            // Verify if key is search list
            if(String::equalNoCase(strBuffer, DNS_ROLE_SEARCH)) {
                ind = SEARCHLIST;
                continue;
            }
            // Verify if key is address (DNS server)
            else if(String::equalNoCase(strBuffer, DNS_ROLE_NAMESERVER)) {
                ind = ADDRESSES;
                continue;
            }
            else
            {
                switch (ind) 
                {
                    case SEARCHLIST:
                        // Make sure not to add multiple identical entries
                        if (!FindInArray(dnsSearchList, strBuffer))
                        {
                            dnsSearchList.append(strBuffer);
                            // if there's not already a Domain Name, use
                            // the first Search entry.
                            if (dnsName.size() == 0)
                                dnsName.assign(strBuffer);
                        }
                        break;

                    case ADDRESSES:
                        if(!FindInArray(dnsAddresses, String(buffer)))
                            dnsAddresses.append(strBuffer);
                        break;

                    default:
                        ok = false;
                        break;
                }
            }
        }
        if(!ok)
            break;
    }
    fclose(fp);
    return ok;
}
Пример #15
0
/*
================================================================================
NAME              : RouteList Constructor
DESCRIPTION       : Build the list of IP Routes
ASSUMPTIONS       : None
PRE-CONDITIONS    :
POST-CONDITIONS   : 
NOTES             : 
================================================================================
*/
RouteList::RouteList()
{
  int fd,                      // file descriptor
      i,                       // general purpose indicies
      count;                   // number of raw IP Routes
  struct nmparms parms;        // get_mib_info() arguments
  mib_ipRouteEnt * route_buf;  // IP Route Buffer
  unsigned int len;            // length of get_mib_info() buffer
  struct in_addr t;            // temporary variable for extracting
			       //   IP route buffer contents

#ifdef DEBUG
  cout << "RouteList::RouteList()" << endl;
#endif

  // Load the interface name structures.

  if ((fd = open_mib("/dev/ip", O_RDONLY, 0, 0)) < 0) {
	throw CIMOperationFailedException("Can't open /dev/ip: " +
				String(strerror(errno)));
  }

  parms.objid = ID_ipRouteNumEnt;
  parms.buffer = (char *) &count;
  len = sizeof(count);
  parms.len = (unsigned int *) &len;

  if (get_mib_info (fd, &parms) < 0) {
	throw CIMOperationFailedException(
	    "Can't get ID_ipRouteNumEnt from get_mib_info(): " +
	    String(strerror(errno)));
  }

  route_buf = (mib_ipRouteEnt *)malloc(count*sizeof(mib_ipRouteEnt));

  if (route_buf == 0)
  {
	free (route_buf);
	throw CIMOperationFailedException(
	    "Error in allocating space for the kernel interface table: " +
	    String(strerror(errno)));
  }

  parms.objid = ID_ipRouteTable;
  parms.buffer = (char *) route_buf;
  len = count * sizeof(mib_ipRouteEnt);
  parms.len = &len;

  if (get_mib_info (fd, &parms) < 0) {
	free (route_buf);
	throw CIMOperationFailedException(
	    "Can't get ID_ipRouteTable from get_mib_info(): " +
	    String(strerror(errno)));
  }

  // Create the IP Route List entries

  for (i=0; i < count ; i++)
  {

    IPRoute _ipr;

    // check to see that this is a valid type to represent
    if (route_buf[i].Type == 3 || route_buf[i].Type == 4)
    {
        t.s_addr = route_buf[i].Dest;
	_ipr.set_destAddr(inet_ntoa(t));

	t.s_addr = route_buf[i].Mask;
	_ipr.set_destMask(inet_ntoa(t));

	t.s_addr = route_buf[i].NextHop;
	_ipr.set_nextHop(inet_ntoa(t));

        // ATTN-LEW-2002-09-13: Enhance this to deal with IPv6 too.
	_ipr.set_protocolType(PROTOCOL_IPV4);

        _iprl.push_back(_ipr);   // Add another IP Route to the list
    }

  } /* for */

  close_mib(fd);
  free (route_buf);

#ifdef DEBUG
  cout << "RouteList::RouteList() -- done" << endl;
#endif

}
Пример #16
0
/*
================================================================================
NAME              : InterfaceList Constructor
DESCRIPTION       : Build the list IP Interfaces
ASSUMPTIONS       : None
PRE-CONDITIONS    :
POST-CONDITIONS   : 
NOTES             : 
================================================================================
*/
InterfaceList::InterfaceList()
{
  int fd,                      // file descriptor
      i, j,                    // general purpose indicies
      numif,                   // number of interfaces
      numip;                   // number of IP addresses
  struct ifconf ifconf;        // interface configuration
  unsigned int len;            // length of get_mib_info() buffer
  struct nmparms parms;        // get_mib_info() arguments
  mib_ipAdEnt * addr_buf;      // IP Address Buffer
  struct in_addr t;            // temporary variable for extracting
			       //     IP Address Buffer contents
  struct sockaddr_in *sin;     // temporary variable for extracting
                               //     interface name

#ifdef DEBUG
  cout << "InterfaceList::InterfaceList()" << endl;
#endif

  // Load the interface name structures.

  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
	throw CIMOperationFailedException("Error in opening socket: " +
				String(strerror(errno)));
  }

  if (ioctl(fd, SIOCGIFNUM, &numif) < 0) {
      throw CIMOperationFailedException
          ("Error in ioctl() request SIOCGIFNUM: " + String(strerror(errno)));
  }

  ifconf.ifc_len = numif * sizeof (struct ifreq);
  ifconf.ifc_req = (struct ifreq *) calloc(numif, sizeof (struct ifreq));

  if (ioctl (fd, SIOCGIFCONF, &ifconf) < 0) {
	free (ifconf.ifc_req);
	throw CIMOperationFailedException
            ("Error in ioctl() request SIOCGIFCONF: " +
				String(strerror(errno)));
  }

  close(fd);

  if ((fd = open_mib("/dev/ip", O_RDONLY, 0, 0)) < 0) {
	free (ifconf.ifc_req);
	throw CIMOperationFailedException("Can't open /dev/ip: " +
				String(strerror(errno)));
  }

  parms.objid = ID_ipAddrNumEnt;
  parms.buffer = (char *) &numip;
  len = sizeof(numip);
  parms.len = &len;

  if (get_mib_info (fd, &parms) < 0) {
	free (ifconf.ifc_req);
	throw CIMOperationFailedException(
	    "Can't get ID_ipAddrNumEnt from get_mib_info(): " +
	    String(strerror(errno)));
  }

  addr_buf = (mib_ipAdEnt *)malloc(numip*sizeof(mib_ipAdEnt));

  if (addr_buf == 0)
  {
	free (ifconf.ifc_req);
	free (addr_buf);
	throw CIMOperationFailedException(
	    "Error in allocating space for the kernel interface table: " +
	    String(strerror(errno)));
  }

  parms.objid = ID_ipAddrTable;
  parms.buffer = (char *) addr_buf;
  len = numip * sizeof(mib_ipAdEnt);
  parms.len = &len;

  if (get_mib_info (fd, &parms) < 0) {
	free (ifconf.ifc_req);
	free (addr_buf);
	throw CIMOperationFailedException(
	    "Can't get ID_ipAddrTable from get_mib_info(): " +
	    String(strerror(errno)));
  }

  // Create the interface list entries

  for (i=0; i < numip ; i++) {

    IPInterface _ipif;

    t.s_addr = addr_buf[i].Addr;
    _ipif.set_address(inet_ntoa(t));

    // ATTN-LEW-2002-07-30: Enhance this to deal with IPv6 too.
    _ipif.set_protocol(PROTOCOL_IPV4);

    for (j = 0; j < (int)(numif-1); j++) {
	sin = reinterpret_cast<struct sockaddr_in*>(
            &ifconf.ifc_req[j].ifr_addr);
	if (sin->sin_addr.s_addr == t.s_addr)
	{
	    _ipif.set_simpleIfName(ifconf.ifc_req[j].ifr_name);
        }
    } /* for */

    t.s_addr = addr_buf[i].NetMask;
    _ipif.set_subnetMask(inet_ntoa(t));

    _ifl.push_back(_ipif);   // Add another IP interface to the list

  } /* for */

  close_mib(fd);
  free (ifconf.ifc_req);
  free (addr_buf);

#ifdef DEBUG
  cout << "InterfaceList::InterfaceList() -- done" << endl;
#endif

}
Пример #17
0
void ComputerSystem::initialize(void)
{
  // fills in the values of all properties that are not
  // hardcoded (i.e., are obtained from the system) but not
  // going to change dynamically (which is most, for this
  // provider)
  
  // _hostName
  struct hostent *he;
  char hn[PEGASUS_MAXHOSTNAMELEN];
  // fill hn with what this system thinks is name
  gethostname(hn,PEGASUS_MAXHOSTNAMELEN);
  // find out what nameservices think is full name
  if (he=gethostbyname(hn)) _hostName = he->h_name;
  else _hostName = hn;

  size_t bufSize;

  // get serial number using confstr  
  bufSize = confstr(_CS_MACHINE_SERIAL, NULL, 0);
  if (bufSize != 0)
  {
      char* serialNumber = new char[bufSize];
      try
      {
          if (confstr(_CS_MACHINE_SERIAL, serialNumber, bufSize) != 0)
          {
              _serialNumber.set(String(serialNumber));
          }
      }
      catch(...)
      {
          delete [] serialNumber;
          throw;
      }
      delete [] serialNumber;
  }

  // get model using command
  FILE *s = popen("/usr/bin/model","r");
  if (s == 0) throw CIMOperationFailedException("/usr/bin/model: command not found");
  char buf[100];
  if (fgets(buf,100,s) == 0)
    throw CIMOperationFailedException("/usr/bin/model: no output");
  pclose(s);
  _model = String(buf);

  // get system UUID using confstr.  
  bufSize = confstr(_CS_MACHINE_IDENT, NULL, 0);
  if (bufSize != 0)
  {
      char* uuid = new char[bufSize];
      try
      {
          if (confstr(_CS_MACHINE_IDENT, uuid, bufSize) != 0)
          {
              _uuid.set(String(uuid));
          }
      }
      catch(...)
      {
          delete [] uuid;
          throw;
      }
      delete [] uuid;
  }

  // InstallDate
  /*
    A CIM date has the following form:
	yyyymmddhhmmss.mmmmmmsutc

    Where

	yyyy = year (0-1999)
	mm = month (1-12)
	dd = day (1-31)
	hh = hour (0-23)
	mm = minute (0-59)
	ss = second (0-59)
	mmmmmm = microseconds.
	s = '+' or '-' to represent the UTC sign.
	utc = UTC offset (same as GMT offset).
  */
  // creation date of /stand/vmunix
  struct stat st;
  // get get modification time of file
  if (0 != stat("/stand/vmunix", &st))
    throw CIMOperationFailedException("/stand/vmunix: can't access");
  // convert to a usable format
  struct tm tmBuffer;
  struct tm *t = localtime_r(&st.st_mtime, &tmBuffer);
  // convert to CIMDateTime format
  char timstr[26];
  sprintf(timstr,"%04d%02d%02d%02d%02d%02d.000000%c%03d",t->tm_year+1900,
                       t->tm_mon+1,
                       t->tm_mday,
                       t->tm_hour,
                       t->tm_min,
                       t->tm_sec,
                       (timezone>0)?'-':'+',
                       labs (timezone/60 - (t->tm_isdst? 60:0)));
  _installDate = CIMDateTime (timstr);

  // ----------------------------------------------------------
  // Now set properties obtained from DMI
  // ----------------------------------------------------------

  typedef enum
  {
    GenInfoSysName_E       =  1,
    GenInfoSysLoc_E        =  2,
    GenInfoSysPUser_E      =  3,
    GenInfoSysPPhone_E     =  4,
    GenInfoSysUpTime_E     =  5,
    GenInfoSysDate_E       =  6,
    GenInfoSysSUser_E      =  7,
    GenInfoSysSPhone_E     =  8,
    GenInfoSysPPager_E     =  9,
    GenInfoSysSPager_E     = 10,
    GenInfoSecurity_E      = 11,
    GenInfoModel_E         = 12,
    GenInfoSerialNumber_E  = 13,
    GenInfoSoftwareID_E    = 14
  } GenInfoEnumList;

  char                  inLine[1024];
  char                 *tmpGroupId = NULL;
  char                 *tmpAttrId = NULL;
  char                 *value = NULL;
  int                   groupId;
  int                   attrId;
  char                 *tokp = NULL;

  // open file
  ifstream mParmStream(DMI_FILE);
  // Values will be left blank if can't access file
  if (mParmStream == 0) return;

  while (mParmStream.getline(inLine, sizeof(inLine)))
  {
    /* Parse out the line to get the DMI group Id, attribute Id */
    /* and value.                                               */
    tmpGroupId = strtok_r(inLine, "|", &tokp);
    tmpAttrId = strtok_r(NULL, "|", &tokp);
    value = strtok_r(NULL, "\n", &tokp);

    if (NULL != tmpGroupId)
    {
      groupId = atoi(tmpGroupId);
    }
    else
    {
      continue;
    }

    if (NULL != tmpAttrId)
    {
      attrId = atoi(tmpAttrId);
    }
    else
    {
      continue;
    }

    /* Make sure information read in is the right DMI group. */
    if ((groupId != GEN_INFO_GROUP_ID) || (NULL == value))
    {
      continue;
    }
    
    if (attrId == GenInfoSysPUser_E)
    {
      _primaryOwnerName = value;
    }
    else if (attrId == GenInfoSysPPhone_E)
    {
      _primaryOwnerContact = value;
    }
    else if (attrId == GenInfoSysSUser_E)
    {
      _secondaryOwnerName = value;
    }
    else if (attrId == GenInfoSysSPhone_E)
    {
      _secondaryOwnerContact = value;
    }
    else if (attrId == GenInfoSysPPager_E)
    {
      _primaryOwnerPager = value;
    }
    else if (attrId == GenInfoSysSPager_E)
    {
      _secondaryOwnerPager = value;
    }
  }  /* while */

  return;
}
Пример #18
0
void DefaultInstanceProvider::enumerateInstances(
	const OperationContext & context,
	const CIMObjectPath & classReference,
	const Boolean includeQualifiers,
	const Boolean includeClassOrigin,
	const CIMPropertyList & propertyList,
	InstanceResponseHandler & handler)
{
        CIMNamespaceName nameSpace = classReference.getNameSpace();

        // get the class name
        CIMName className = classReference.getClassName();

        // create the namespace if necessary
        if (!_nameSpaceExists(nameSpace))
        {
            _copyNameSpace(nameSpace.getString(), className.getString());
        }

        // check to see if class already exists
        // if not, copy the class
        //
        try
        {
            CIMClass cimClass = _repository->getClass(nameSpace, className);
        }
        catch (Exception&)
        {
            // class does not exist

            //
            // copy the class
            //
            _copyClass(nameSpace.getString(), className.getString()); 
        }

        Array<CIMInstance> cimNamedInstances;

        Boolean localOnly = true;
        Boolean deepInheritance = true;

        try
        {
           cimNamedInstances = _repository->enumerateInstancesForClass(
              nameSpace,
              className,
              deepInheritance,
              localOnly,
              includeQualifiers,
              includeClassOrigin,
              false,
              propertyList);
        }
        catch( Exception& ex )
        {
            const String msg = "Enumerate Instances failed. " + ex.getMessage();
            throw CIMOperationFailedException( msg );
        }

	// begin processing the request
	handler.processing();

        for (Uint32 i = 0, n = cimNamedInstances.size(); i < n; i++)
	{
	    // deliver instance
	    handler.deliver(cimNamedInstances[i]);
	}

	// complete processing the request
	handler.complete();
}
Пример #19
0
Array<CIMInstance> ANHProvider::_NextHopRouteInstances()
{
    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,
        "ANHProvider::_NextHopRouteInstances()");

    Array<CIMInstance> _retInstances;
    NextHopRouteList _nhrl;

    for (Uint16 i = 0; i<_nhrl.size(); i++)
    {
        NextHopIPRoute _nhipr = _nhrl.getRoute(i);

        if (!_nhipr.isRouteLocal())
        {
            CIMInstance instance(CLASS_CIM_NEXT_HOP_ROUTE);
            String _destAddr, _destMask, _instanceID;
            Uint16 _addrType;
            Uint8 _prefLength;

            if (!_nhipr.getInstanceID(_instanceID))
            {
                PEG_METHOD_EXIT();
                throw CIMOperationFailedException(
                    "Can't determine InstanceID in: " +
                    String("ANHProvider::_NextHopRouteInstances()"));
            }
            instance.addProperty(CIMProperty(PROPERTY_INSTANCE_ID, _destAddr));

            if (!_nhipr.getDestinationAddress(_destAddr))
            {
                PEG_METHOD_EXIT();
                throw CIMOperationFailedException(
                    "Can't determine destination address in: " + 
                    String("ANHProvider::_NextHopRouteInstances()"));
            }
            instance.addProperty(CIMProperty(
                PROPERTY_DESTINATION_ADDRESS, 
                _destAddr));

            if (_nhipr.getAddressType(_addrType))
            {
                instance.addProperty(CIMProperty(
                    PROPERTY_ADDRESS_TYPE, 
                    _addrType));

                if (_addrType == 1)  // IPv4 address.
                {
                    if (!_nhipr.getDestinationMask(_destMask))
                    {
                        PEG_METHOD_EXIT();
                        throw CIMOperationFailedException(
                            "Can't determine destination mask in: " +
                            String("ANHProvider::_NextHopRouteInstances()"));
                    }
                    instance.addProperty(CIMProperty(
                        PROPERTY_DESTINATION_MASK, 
                        _destMask));
                }
                else
                {
                    if (_addrType == 2)  // IPv6 address.
                    {
                        if (!_nhipr.getPrefixLength(_prefLength))
                        {
                            PEG_METHOD_EXIT();
                            throw CIMOperationFailedException(
                                "Can't determine prefix length for route in: " +
                               String("ANHProvider::_NextHopRouteInstances()"));
                        }
                        instance.addProperty(CIMProperty(
                            PROPERTY_PREFIX_LENGTH, 
                            _prefLength));
                    }
                }
            }
            else
            {
                PEG_METHOD_EXIT();
                throw CIMOperationFailedException(
                    "Can't determine address type in: " +
                    String("ANHProvider::_NextHopRouteInstances()"));
            }

            // Build CIMObjectPath from keybindings
            Array<CIMKeyBinding> keyBindings;
            keyBindings.append(
            CIMKeyBinding(
                PROPERTY_INSTANCE_ID, 
                _destAddr, 
                CIMKeyBinding::STRING));

            CIMObjectPath path(
            String::EMPTY, 
            CIMNamespaceName(),
            CLASS_CIM_NEXT_HOP_ROUTE, 
            keyBindings);

            instance.setPath(path);
            _nhrInstances.append(instance);
            _retInstances.append(instance);
        }
    }  // Loop over next hop routes.

    PEG_METHOD_EXIT();
    return _retInstances;
}
Пример #20
0
Array<CIMInstance> ANHProvider::_RSApInstances()
{

    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,
        "ANHProvider::_RSApInstances()");

    Array<CIMInstance> _retInstances;

    RSApList _rsapl;

    for (Uint16 i = 0; i<_rsapl.size(); i++)
    {
        CIMInstance instance(CLASS_CIM_REMOTE_SERVICE_ACCESS_POINT);
        RSAp _rsap = _rsapl.getService(i);

        String _accessInfo;
        Uint16 _infoFormat;

        if (_rsap.getAccessInfo(_accessInfo))
        {
            instance.addProperty(CIMProperty(
                PROPERTY_ACCESS_INFO, 
                _accessInfo));
        }
        else 
        {
            PEG_METHOD_EXIT();
            throw CIMOperationFailedException(
                "Can't determine property AccessInfo in: " +
                String("ANHProvider::_RSApInstances()"));
        }

        if (_rsap.getInfoFormat(_infoFormat))
        {
            instance.addProperty(CIMProperty(
                PROPERTY_INFO_FORMAT, 
                _infoFormat));
        }
        else 
        {
            PEG_METHOD_EXIT();
            throw CIMOperationFailedException(
                "Can't determine property InfoFormat in: " +
                String("ANHProvider::_RSApInstances()"));
        }

        // Build CIMObjectPath from keybindings
        Array<CIMKeyBinding> keyBindings;
        keyBindings.append(
            CIMKeyBinding(
                PROPERTY_ACCESS_INFO,
                _accessInfo,
                CIMKeyBinding::STRING));

        CIMObjectPath path(
            String::EMPTY,
            CIMNamespaceName(),
            CLASS_CIM_REMOTE_SERVICE_ACCESS_POINT,
            keyBindings);

         instance.setPath(path);
         _rsapInstances.append(instance);
         _retInstances.append(instance);
    }

    PEG_METHOD_EXIT();
    return _retInstances;
}
Пример #21
0
void RUEpProvider::_createAssociationInstances(
    Array<CIMInstance> nhrInst,
    Array<CIMInstance> ipifInst)
{
    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,
        "RUEpProvider::_createAssociationInstances()");

    Uint16 nhrInstSize = nhrInst.size();
    Uint16 ipifInstSize = ipifInst.size();

    for (Uint16 i = 0; i < nhrInstSize; i++)  // Routes loop.
    {
        CIMInstance _nhrInstRet, _ipifInstRet;
        CIMInstance _nhrInst = nhrInst[i];

        CIMProperty _ipifAddress;
        CIMProperty _ipifSubnetMask_PrefixLength;
        CIMProperty _ipifProtocolIFType;
        CIMProperty _nhrInstanceID = _nhrInst.getProperty(
            _nhrInst.findProperty(PROPERTY_INSTANCE_ID));
        CIMProperty _nhrAddrType;
        CIMProperty _nhrDestMask_PrefixLength;


        for (Uint16 j = 0; j<ipifInstSize; j++)  // Interfaces loop.
        {
            CIMInstance _ipifInst = ipifInst[j];

            _ipifProtocolIFType = _ipifInst.getProperty(
                _ipifInst.findProperty(PROPERTY_PROTOCOL_IF_TYPE));

            Uint16 _pift;
            CIMValue _piftCIMValue = _ipifProtocolIFType.getValue();
            if ((_piftCIMValue.getType() == CIMTYPE_UINT16) &&
                (!_piftCIMValue.isNull ()))
            {
                _piftCIMValue.get(_pift);
            }
            else
            {
                throw CIMOperationFailedException(
                    "Can't determine CIMValue::TYPE of ProtocolIFType:" +
                    String(cimTypeToString(_piftCIMValue.getType())));
            }

            if (_pift == 4096)  // IPv4 address.
            {
                _ipifAddress = _ipifInst.getProperty(
                    _ipifInst.findProperty(
                        PROPERTY_IPV4ADDRESS));
                _ipifSubnetMask_PrefixLength = _ipifInst.getProperty(
                    _ipifInst.findProperty(
                    PROPERTY_SUBNET_MASK));
            }
            else
            {
                if (_pift == 4097)  // IPv6 address.
                {
                    _ipifAddress = _ipifInst.getProperty(
                        _ipifInst.findProperty(
                            PROPERTY_IPV6ADDRESS));
                    _ipifSubnetMask_PrefixLength = _ipifInst.getProperty(
                        _ipifInst.findProperty(
                            PROPERTY_IPV6ADDRESS));
                }
                else
                {
                    char buffer[22];
                    Uint32 sz;
                    String _piftStr = Uint16ToString(buffer, _pift, sz);
                    throw CIMOperationFailedException(
                        "ProtocolIFType == " +  _piftStr );
                }
            }

            // In this implementation, we choose InstanceID to be
            // equal DestinationAddress. So, if Address of interface
            // and InstanceID of route doesn't match, check if SubnetMask
            // of interface and DestinationMask route does.
            if (!_nhrInstanceID.getValue().equal(_ipifAddress.getValue()))
            {
                _nhrAddrType = _nhrInst.getProperty(
                    _nhrInst.findProperty(
                        PROPERTY_ADDRESS_TYPE));
                Uint16 _addrt;
                CIMValue _nhratCIMValue = _nhrAddrType.getValue();
                if ((_nhratCIMValue.getType() == CIMTYPE_UINT16) &&
                    (!_nhratCIMValue.isNull()))
                {
                    _nhratCIMValue.get(_addrt);
                }
                else
                {
                    throw CIMOperationFailedException(
                        "Can't determine CIMValue::TYPE of AddressType: " +
                        String(cimTypeToString(_piftCIMValue.getType())));
                }

                if (_addrt == 1)  // IPv4 address.
                {
                    _nhrDestMask_PrefixLength = _nhrInst.getProperty(
                       _nhrInst.findProperty(
                           PROPERTY_DESTINATION_MASK));
                }
                else
                {
                    if (_addrt == 2)  // IPv6 address.
                    {
                         _nhrDestMask_PrefixLength = _nhrInst.getProperty(
                             _nhrInst.findProperty(
                                 PROPERTY_PREFIX_LENGTH));
                    }
                    else
                    {
                        char buffer[22];
                        Uint32 sz;
                        String _addrtStr = Uint16ToString(buffer, _addrt, sz);
                        throw CIMOperationFailedException(
                            "Unknown AddressType = " + _addrtStr);
                    }
                }

                // If SubnetMask of interface and DestinationMask route
                // doesn't match, these instances are unrelated. So,
                // proceed to the next pair.
                if (!_nhrDestMask_PrefixLength.getValue().equal(
                    _ipifSubnetMask_PrefixLength.getValue()))
                {
                    continue;
                }
            }

            // Build the CIMObjectPath from the instances matching
            CIMObjectPath _ipifObj = _ipifInst.getPath();
            CIMObjectPath _nhrObj = _nhrInst.getPath();

            CIMInstance assocInst(CLASS_PG_ROUTE_USES_ENDPOINT);
            assocInst.addProperty(
                CIMProperty(
                    CIMName("Antecedent"),
                    _ipifObj,
                    0,
                    CLASS_CIM_PROTOCOL_ENDPOINT));
            assocInst.addProperty(
                CIMProperty(
                    CIMName("Dependent"),
                    _nhrObj,
                    0,
                    CLASS_CIM_NEXT_HOP_ROUTE));

            // Build CIMObjectPath from keybindings
            Array<CIMKeyBinding> keyBindings;
            CIMKeyBinding _ipifBinding(
                CIMName("Antecedent"),
                _ipifObj.toString(),
                CIMKeyBinding::REFERENCE);
            CIMKeyBinding _nhrBinding(
                CIMName("Dependent"),
                _nhrObj.toString(),
                CIMKeyBinding::REFERENCE);
            keyBindings.append (_ipifBinding);
            keyBindings.append (_nhrBinding);

            CIMObjectPath path(
                String::EMPTY,
                CIMNamespaceName(),
                CLASS_PG_ROUTE_USES_ENDPOINT,
                keyBindings);

            assocInst.setPath(path);
            _AssociationInstances.append(assocInst);
            break;
        }  // Interfaces loop end.

    }  // Routes loop end.

    PEG_METHOD_EXIT();
}
Пример #22
0
void
OperatingSystemProvider::getInstance(const OperationContext& context,
				     const CIMObjectPath& ref,
				     const Boolean includeQualifiers,
				     const Boolean includeClassOrigin,
				     const CIMPropertyList& propertyList,
				     InstanceResponseHandler &handler)
{
    Array<CIMKeyBinding> keys;
    CIMInstance instance;
    OperatingSystem os;
    CIMName className;
    String csName;
    String name;


    //-- make sure we're working on the right class
    className = ref.getClassName();
    if (!(className.equal (STANDARDOPERATINGSYSTEMCLASS)) &&
        !(className.equal (EXTENDEDOPERATINGSYSTEMCLASS)))
        throw CIMNotSupportedException("OperatingSystemProvider does not support class " + className.getString());

    //-- make sure we're the right instance
    int keyCount;
    CIMName keyName;

    keyCount = 4;
    keys = ref.getKeyBindings();

    if ((unsigned int)keys.size() != (unsigned int)keyCount)
        throw CIMInvalidParameterException("Wrong number of keys");

    // doesn't seem as though this code will handle duplicate keys,
    // but it appears as though the CIMOM strips those out for us.
    // Despite test cases, don't get invoked with 2 keys of the same
    // name.

    if (!os.getCSName(csName))
    {
        throw CIMOperationFailedException("OperatingSystemProvider "
                       "Can't determine name of computer system");
    }

    if (!os.getName(name))
    {
        throw CIMOperationFailedException("OperatingSystemProvider "
                       "Can't determine name of Operating System");
    }

    for (unsigned int ii = 0; ii < keys.size(); ii++)
    {
         keyName = keys[ii].getName();

         if ((keyName.equal ("CSCreationClassName")) &&
       	    String::equalNoCase(keys[ii].getValue(),
                                CSCREATIONCLASSNAME.getString()))
         {
              keyCount--;
         }
         else if ((keyName.equal ("CSName")) &&
  	         String::equalNoCase(keys[ii].getValue(), csName))
         {
              keyCount--;
         }
         else if ((keyName.equal ("CreationClassName")) &&
 	         String::equalNoCase(keys[ii].getValue(),
                                     STANDARDOPERATINGSYSTEMCLASS.getString()))
         {
              keyCount--;
         }
         else if ((keyName.equal ("Name")) &&
 	         String::equalNoCase(keys[ii].getValue(), name))
         {
              keyCount--;
         }
         else
         {
              throw CIMInvalidParameterException("OperatingSystemProvider"
                             " unrecognized key " + keyName.getString());
         }
     }

     if (keyCount)
     {
        throw CIMInvalidParameterException("Wrong keys");
     }

    OSP_DEBUG("losp-> getInstance got the right keys");

    handler.processing();

    //-- fill 'er up...
    instance = _build_instance(ref);
    instance.setPath(ref);

    OSP_DEBUG("losp-> getInstance built an instance");

    handler.deliver(instance);
    handler.complete();

    OSP_DEBUG("losp-> getInstance done");
    return;
}
Пример #23
0
Array<CIMInstance> RUEpProvider::_IPInterfaceInstances()
{
    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,
        "RUEpProvider::_IPInterfaceInstances()");

    Array<CIMInstance> _retInstances;
    InterfaceList _ifl;

    for (Uint16 i = 0; i<_ifl.size(); i++)
    {
        CIMInstance instance(CLASS_CIM_PROTOCOL_ENDPOINT);
        IPInterface _ipif = _ifl.getInterface(i);

        String _addr, _subnetMask;
        Uint16 _protocolIFType;
        Uint8 _prefLength;

        if (_ipif.getProtocolIFType(_protocolIFType))
        {
            instance.addProperty(CIMProperty(
                PROPERTY_PROTOCOL_IF_TYPE,
                _protocolIFType));

            if (_protocolIFType == 4096)  // IPv4 address.
            {
                if (!_ipif.getIPv4Address(_addr))
                {
                    throw CIMOperationFailedException(
                        "Can't determine IPv4 address in: " +
                        String("RUEpProvider::_IPInterfaceInstances()"));
                }
                instance.addProperty(CIMProperty(PROPERTY_IPV4ADDRESS, _addr));

                if (!_ipif.getSubnetMask(_subnetMask))
                {
                    throw CIMOperationFailedException(
                        "Can't determine subnet mask in: " +
                        String("RUEpProvider::_IPInterfaceInstances()"));
                }
                instance.addProperty(CIMProperty(
                    PROPERTY_SUBNET_MASK,
                    _subnetMask));
            }
            else
            {
                if (_protocolIFType == 4097)  // IPv6 address.
                {
                    if (!_ipif.getIPv6Address(_addr))
                    {
                        throw CIMOperationFailedException(
                            "Can't determine IPv6 address in: " +
                            String("RUEpProvider::_IPInterfaceInstances()"));
                    }
                    instance.addProperty(CIMProperty(
                        PROPERTY_IPV6ADDRESS,
                        _addr));

                    if (!_ipif.getPrefixLength(_prefLength))
                    {
                        throw CIMOperationFailedException(
                            "Can't determine prefix length for interface in: " +
                            String("RUEpProvider::_IPInterfaceInstances()"));
                    }
                    instance.addProperty(CIMProperty(
                        PROPERTY_PREFIX_LENGTH,
                        _prefLength));
                }
            }
        }
        else
        {
            throw CIMOperationFailedException(
                "Can't determine instance protocol type in: " +
                String("RUEpProvider::_IPInterfaceInstances()"));
        }

        // Build CIMObjectPath from keybindings
        Array<CIMKeyBinding> keyBindings;
        keyBindings.append(
            CIMKeyBinding(
                PROPERTY_ADDRESS,
                _addr,
                CIMKeyBinding::STRING));

        CIMObjectPath path(
            String::EMPTY,
            CIMNamespaceName(),
            CLASS_CIM_PROTOCOL_ENDPOINT,
            keyBindings);

         instance.setPath(path);
         _ipifInstances.append(instance);
         _retInstances.append(instance);
    }

    PEG_METHOD_EXIT();
    return _retInstances;
}