示例#1
0
Pegasus::Boolean CIMClient::verifyCertificate(Pegasus::SSLCertificateInfo &ci, void *data)
{
    if (!ci.getResponseCode()) {
        // Pre-verify of the certificate failed, immediate return
        return false;
    }

    CIMClient *fake_this = reinterpret_cast<CIMClient*>(data);
    Pegasus::String hostname(fake_this->m_url_info.hostname());

    // Verify against DNS names
    Pegasus::Array<Pegasus::String> dnsNames = ci.getSubjectAltNames().getDnsNames();
    for (Pegasus::Uint32 i = 0; i < dnsNames.size(); ++i) {
        if (matchPattern(dnsNames[i], hostname))
            return true;
    }

    // Verify against IP addresses
    Pegasus::Array<Pegasus::String> ipAddresses = ci.getSubjectAltNames().getIpAddresses();
    for (Pegasus::Uint32 i = 0; i < ipAddresses.size(); ++i) {
        if (matchPattern(ipAddresses[i], hostname))
            return true;
    }

    // Verify against Common Name
    return matchPattern(ci.getSubjectCommonName(), hostname);
}
示例#2
0
String CIMValue::decode_values(Pegasus::CIMProperty property)
{
    std::map<String, String> decode;
    Pegasus::Array<Pegasus::String> values;
    Pegasus::Array<Pegasus::String> value_map;
    Pegasus::Uint32 ind = property.findQualifier("Values");
    if (ind == Pegasus::PEG_NOT_FOUND) {
        return "";
    }
    property.getQualifier(ind).getValue().get(values);

    ind = property.findQualifier("ValueMap");
    if (ind == Pegasus::PEG_NOT_FOUND) {
        return "";
    }
    property.getQualifier(ind).getValue().get(value_map);

    for (unsigned int i = 0; i < values.size(); i++) {
        decode.insert(std::pair<String, String>(
                          String(value_map[i].getCString()),
                          String(values[i].getCString())));
    }

    Pegasus::CIMValue cim_value = property.getValue();
    String value = to_string(cim_value);
    if (!cim_value.isArray()) {
        return decode[value];
    } else {
        value.erase(std::remove_if(value.begin(), value.end(), is_not_digit_and_space),
                    value.end());
        String result = "";

        char *str = (char *) malloc((value.length() + 1) * sizeof(char));
        char *token;
        char delim = ' ';

        strcpy(str, value);

        for (int i = 0; ; i++) {
            token = strtok(str, &delim);
            str = NULL;
            if (token == NULL) {
                break;
            } else if (i != 0) {
                result += ", ";
            }

            result += decode[token];
        }
        if (!result.empty()) {
            result = "{" + result + "}";
        }

        return result;
    }

    return "";
}
示例#3
0
void NetworkPlugin::getData(std::vector<void *> *data)
{
    try {
        Pegasus::Array<Pegasus::CIMInstance> device =
            enumerateInstances(
                Pegasus::CIMNamespaceName("root/cimv2"),
                Pegasus::CIMName("LMI_EthernetPort"),
                true,       // deep inheritance
                false,      // local only
                true,       // include qualifiers
                false       // include class origin
            );
        int cnt = device.size();
        for (int i = 0; i < cnt; i++) {
            data->push_back(new Pegasus::CIMInstance(device[i]));
        }

        Pegasus::Array<Pegasus::CIMInstance> stats =
            enumerateInstances(
                Pegasus::CIMNamespaceName("root/cimv2"),
                Pegasus::CIMName("LMI_EthernetPortStatistics"),
                true,       // deep inheritance
                false,      // local only
                true,       // include qualifiers
                false       // include class origin
            );
        cnt = stats.size();
        for (int i = 0; i < cnt; i++) {
            data->push_back(new Pegasus::CIMInstance(stats[i]));
        }

        Pegasus::Array<Pegasus::CIMInstance> network =
            enumerateInstances(
                Pegasus::CIMNamespaceName("root/cimv2"),
                Pegasus::CIMName("LMI_IPNetworkConnection"),
                true,       // deep inheritance
                false,      // local only
                true,       // include qualifiers
                false       // include class origin
            );

        cnt = network.size();
        for (int i = 0; i < cnt; i++) {
            Pegasus::Array<Pegasus::CIMObject> net_assoc =
                associators(
                    Pegasus::CIMNamespaceName("root/cimv2"),
                    network[i].getPath(),
                    Pegasus::CIMName(),
                    Pegasus::CIMName(),
                    Pegasus::String::EMPTY,
                    Pegasus::String::EMPTY,
                    true
                );

            data->push_back(new Pegasus::CIMInstance(network[i]));
            int cnt_assoc = net_assoc.size();
            for (int j = 0; j < cnt_assoc; j++) {
                data->push_back(new Pegasus::CIMInstance(net_assoc[j]));
            }
        }

        Pegasus::Array<Pegasus::CIMInstance> dns =
            enumerateInstances(
                Pegasus::CIMNamespaceName("root/cimv2"),
                Pegasus::CIMName("LMI_DNSSettingData"),
                true,       // deep inheritance
                false,      // local only
                true,       // include qualifiers
                false       // include class origin
            );
        cnt = dns.size();
        for (int i = 0; i < cnt; i++) {
            data->push_back(new Pegasus::CIMInstance(dns[i]));
        }
    } catch (Pegasus::Exception &ex) {
        emit doneFetchingData(NULL, false, CIMValue::to_string(ex.getMessage()));
        return;
    }

    emit doneFetchingData(data);
}