static void accept_events_call(WsmanMessage *wsman_msg,char* ip_addr) { char *buf = NULL; char *messageid; int len; WsXmlDocH ackdoc = NULL; WsXmlDocH in_doc = wsman_build_inbound_envelope(wsman_msg); WsXmlNodeH header = ws_xml_get_soap_header(in_doc); WsXmlNodeH acknode = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_ACKREQUESTED); if(acknode) { ackdoc = ws_xml_create_envelope(); messageid = ws_xml_get_node_text(ws_xml_get_child(header, 0, XML_NS_ADDRESSING, WSA_MESSAGE_ID)); header = ws_xml_get_soap_header(ackdoc); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_TO, WSA_TO_ANONYMOUS); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_RELATES_TO, messageid); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_ACTION, WSMAN_ACTION_ACK); ws_xml_dump_memory_enc(ackdoc, &buf, &len, wsman_msg->charset); u_buf_set(wsman_msg->response, buf, len); ws_xml_destroy_doc(ackdoc); u_free(buf); } if(listener->eventf) listener->eventf(in_doc, listener->data,ip_addr); ws_xml_destroy_doc(in_doc); }
void wsman_add_fragement_for_header(WsXmlDocH indoc, WsXmlDocH outdoc) { WsXmlNodeH inheader, outheader; WsXmlNodeH fragmentnode; inheader = ws_xml_get_soap_header(indoc); fragmentnode = ws_xml_get_child(inheader, 0, XML_NS_WS_MAN, WSM_FRAGMENT_TRANSFER); if(fragmentnode == NULL) return; outheader = ws_xml_get_soap_header(outdoc); ws_xml_duplicate_tree(outheader, fragmentnode); }
char * wsman_get_option_set(WsContextH cntx, WsXmlDocH doc, const char *op) { char *optval = NULL; int index = 0; WsXmlNodeH node, option; if (doc == NULL) { doc = cntx->indoc; if (!doc) return NULL; } node = ws_xml_get_soap_header(doc); if (node && (node = ws_xml_get_child(node, 0, XML_NS_WS_MAN, WSM_OPTION_SET))) { while ((option = ws_xml_get_child(node, index++, XML_NS_WS_MAN, WSM_OPTION))) { char *attrVal = ws_xml_find_attr_value(option, NULL, WSM_NAME); if (attrVal && strcmp(attrVal, op ) == 0 ) { optval = ws_xml_get_node_text(option); if (optval[0] == 0) optval = "true"; optval = u_strdup(optval); debug("Option: %s=%s", attrVal, optval); break; } } } return optval; }
void wsman_add_namespace_as_selector(WsXmlDocH doc, const char *_namespace) { WsXmlNodeH header = ws_xml_get_soap_header(doc); wsman_add_selector(header, CIM_NAMESPACE_SELECTOR, _namespace); return; }
static void generate_notunderstood_fault(op_t * op, WsXmlNodeH notUnderstoodHeader) { WsXmlNodeH child; WsXmlNodeH header; if (op->in_doc == NULL) return; generate_op_fault(op, SOAP_FAULT_MUSTUNDERSTAND, 0); if (op->out_doc != NULL) { header = ws_xml_get_soap_header(op->out_doc); if (header) { child = ws_xml_add_child(header, XML_NS_SOAP_1_2, "NotUnderstood", NULL); ws_xml_add_qname_attr(child, NULL, "qname", ws_xml_get_node_name_ns (notUnderstoodHeader), ws_xml_get_node_local_name (notUnderstoodHeader)); } } else { error("cant generate fault"); } return; }
char * wsman_get_selector(WsContextH cntx, WsXmlDocH doc, const char *name, int index) { char *val = NULL; if (doc == NULL) doc = cntx->indoc; if (doc) { WsXmlNodeH header = ws_xml_get_soap_header(doc); WsXmlNodeH node = ws_xml_get_child(header, index, XML_NS_WS_MAN, WSM_SELECTOR_SET); if (node) { WsXmlNodeH selector; int index = 0; while ((selector = ws_xml_get_child(node, index++, XML_NS_WS_MAN, WSM_SELECTOR))) { char *attrVal = ws_xml_find_attr_value(selector, XML_NS_WS_MAN, WSM_NAME); if (attrVal == NULL) attrVal = ws_xml_find_attr_value(selector, NULL, WSM_NAME); if (attrVal && !strcmp(attrVal, name)) { val = ws_xml_get_node_text(selector); break; } } } } debug("Selector value for %s: %s", name, val); return val; }
void wsmc_add_selector_from_uri(WsXmlDocH doc, const char *resource_uri) { u_uri_t *uri; WsXmlNodeH header = ws_xml_get_soap_header(doc); hash_t *query; hnode_t *hn; hscan_t hs; if (resource_uri != NULL) { if (u_uri_parse((const char *) resource_uri, &uri) != 0) return; else if (!uri->query) goto cleanup; } query = u_parse_query(uri->query); hash_scan_begin(&hs, query); while ((hn = hash_scan_next(&hs))) { wsman_add_selector(header, (char *) hnode_getkey(hn), (char *) hnode_get(hn)); debug("key=%s value=%s", (char *) hnode_getkey(hn), (char *) hnode_get(hn)); } hash_free_nodes(query); hash_destroy(query); cleanup: if (uri) { u_uri_free(uri); } }
/** * Get SOAP Header * @param doc XML document * @param nsUri Namespace URI * @param name Header element name * @return XML node */ WsXmlNodeH wsman_get_soap_header_element(WsXmlDocH doc, const char *nsUri, const char *name) { WsXmlNodeH node = ws_xml_get_soap_header(doc); if (node && name) { node = ws_xml_find_in_tree(node, nsUri, name, 1); } return node; }
/** * Create a response SOAP envelope * @param rqstDoc The XML document of the request * @param action the Response action * @return Response envelope */ WsXmlDocH wsman_create_response_envelope(WsXmlDocH rqstDoc, const char *action) { WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH dstHeader, srcHeader, srcNode; if (wsman_is_identify_request(rqstDoc)) return doc; if (!doc) return NULL; dstHeader = ws_xml_get_soap_header(doc); srcHeader = ws_xml_get_soap_header(rqstDoc); srcNode = ws_xml_get_child(srcHeader, 0, XML_NS_ADDRESSING, WSA_REPLY_TO); wsman_epr_from_request_to_response(dstHeader, srcNode); if (action != NULL) { ws_xml_add_child(dstHeader, XML_NS_ADDRESSING, WSA_ACTION, action); } else { if ((srcNode = ws_xml_get_child(srcHeader, 0, XML_NS_ADDRESSING, WSA_ACTION)) != NULL) { if ((action = ws_xml_get_node_text(srcNode)) != NULL) { size_t len = strlen(action) + sizeof(WSFW_RESPONSE_STR) + 2; char *tmp = (char *) u_malloc(sizeof(char) * len); if (tmp && action) { sprintf(tmp, "%s%s", action, WSFW_RESPONSE_STR); ws_xml_add_child(dstHeader, XML_NS_ADDRESSING, WSA_ACTION, tmp); u_free(tmp); } } } } if ((srcNode = ws_xml_get_child(srcHeader, 0, XML_NS_ADDRESSING, WSA_MESSAGE_ID)) != NULL) { ws_xml_add_child(dstHeader, XML_NS_ADDRESSING, WSA_RELATES_TO, ws_xml_get_node_text(srcNode)); } return doc; }
int wsman_parse_event_request(WsXmlDocH doc, WsSubscribeInfo * subsInfo, WsmanFaultCodeType *faultcode, WsmanFaultDetailType *detailcode) { WsXmlNodeH node; filter_t *wsman_f = NULL; filter_t *wse_f = NULL; if (!doc) return 0; node = ws_xml_get_soap_body(doc); if (node && (node = ws_xml_get_child(node, 0, XML_NS_EVENTING, WSEVENT_SUBSCRIBE))) { /* See DSP0226 (WS-Management), Section 10.2.2 Filtering * WS-Management defines wsman:Filter as the filter element to wse:Subscribe * but also allows wse:Filter to be compatible with WS-Eventing implementations * R10.2.2-50, R10.2.2-51 to DSP0226 */ wsman_f = filter_deserialize(node, XML_NS_WS_MAN); wse_f = filter_deserialize(node, XML_NS_EVENTING); if (wsman_f && wse_f) { /* return wse:InvalidMessage if wsman:Filter and wse:Filter are given * see R10.2.2-52 of DSP0226 */ *faultcode = WSE_INVALID_MESSAGE; return -1; } /* use the wse:Filter variant if wsman:Filter not given */ if (!wsman_f) wsman_f = wse_f; subsInfo->filter = wsman_f; if (wsman_f) { if (strcmp(wsman_f->dialect, WSM_CQL_FILTER_DIALECT) == 0) subsInfo->flags |= WSMAN_SUBSCRIPTION_CQL; else if (strcmp(wsman_f->dialect, WSM_WQL_FILTER_DIALECT) == 0) subsInfo->flags |= WSMAN_SUBSCRIPTION_WQL; else { *faultcode = WSE_FILTERING_NOT_SUPPORTED; return -1; } } else { if (is_existing_filter_epr(ws_xml_get_soap_header(doc), &wsman_f)) { *faultcode = WSE_FILTERING_NOT_SUPPORTED; return -1; } else { subsInfo->flags |= WSMAN_SUBSCRIPTION_SELECTORSET; } } } return 0; }
static void test_epr_cmp(void) { WsXmlDocH doc1 = ws_xml_read_file("./epr1.xml", "utf-8", 0); WsXmlDocH doc2 = ws_xml_read_file("./epr2.xml", "utf-8", 0); WsXmlDocH doc3 = ws_xml_read_file("./epr3.xml", "utf-8", 0); if(doc1 == NULL || doc2 == NULL || doc3 == NULL) return; WsXmlNodeH node = ws_xml_get_soap_header(doc1); epr_t *epr1 = epr_deserialize(node, NULL, NULL, 0); if(epr1 == NULL) { printf("epr deserialize failed!\n"); return; } node = ws_xml_get_soap_header(doc2); epr_t *epr2 = epr_deserialize(node, NULL, NULL, 0); if(epr2 == NULL) { printf("epr deserialize failed!\n"); return; } node = ws_xml_get_soap_header(doc3); epr_t *epr3 = epr_deserialize(node, NULL, NULL, 0); if(epr3 == NULL) { printf("epr deserialize failed!\n"); return; } ws_xml_destroy_doc(doc1); ws_xml_destroy_doc(doc2); ws_xml_destroy_doc(doc3); if(epr_cmp(epr1, epr2) == 0) printf("\033[22;32mepr1 == epr2\033[m\n\n"); else printf("\033[22;32mepr1 != epr2\033[m\n\n"); if(epr_cmp(epr1, epr3) == 0) printf("\033[22;32mepr1 == epr3\033[m\n\n"); else printf("\033[22;32mepr1 != epr3\033[m\n\n"); epr_destroy(epr1); epr_destroy(epr2); epr_destroy(epr3); }
void wsman_set_estimated_total(WsXmlDocH in_doc, WsXmlDocH out_doc, WsEnumerateInfo * enumInfo) { WsXmlNodeH header = ws_xml_get_soap_header(in_doc); if (ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_REQUEST_TOTAL) != NULL) { if (out_doc) { WsXmlNodeH response_header = ws_xml_get_soap_header(out_doc); if (enumInfo->totalItems >= 0) ws_xml_add_child_format(response_header, XML_NS_WS_MAN, WSM_TOTAL_ESTIMATE, "%d", enumInfo-> totalItems); } } return; }
static void test_epr_delete_selector(void) { WsXmlDocH doc1 = ws_xml_read_file("./epr3.xml", "utf-8", 0); if(doc1 == NULL) return; WsXmlNodeH node = ws_xml_get_soap_header(doc1); epr_t *epr = epr_deserialize(node, NULL, NULL, 0); epr_delete_selector(epr, "Handler"); WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH header = ws_xml_get_soap_header(doc); epr_serialize(header,NULL,NULL,epr,0); ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc1); ws_xml_destroy_doc(doc); epr_destroy(epr); printf("\033[22;32mdelete selector \"Handler\" from EPR\033[m\n\n"); }
static void test_deserialize(void) { WsXmlDocH doc = ws_xml_read_file("./sample.xml", "utf-8", 0); if(doc == NULL) return; WsXmlNodeH node = ws_xml_get_soap_header(doc); epr_t *epr = epr_deserialize(node, NULL, NULL, 0); if(epr == NULL) { printf("epr deserialize failed!\n"); return; } ws_xml_destroy_doc(doc); doc = ws_xml_create_envelope(); node = ws_xml_get_soap_header(doc); epr_serialize(node, NULL, NULL,epr, 0); ws_xml_dump_doc(stdout, doc); epr_destroy(epr); ws_xml_destroy_doc(doc); printf("\033[22;32mtest deserialize epr successfully!\033[m\n\n"); }
char *wsman_get_action(WsContextH cntx, WsXmlDocH doc) { char *val = NULL; if (doc == NULL) { doc = cntx->indoc; } if (doc) { WsXmlNodeH header = ws_xml_get_soap_header(doc); WsXmlNodeH node = ws_xml_get_child(header, 0, XML_NS_ADDRESSING, WSA_ACTION); val = (!node) ? NULL : ws_xml_get_node_text(node); } return val; }
int wsman_is_event_related_request(WsXmlDocH doc) { WsXmlNodeH node = ws_xml_get_soap_header(doc); char *action = NULL; node = ws_xml_get_child(node, 0, XML_NS_ADDRESSING, WSA_ACTION); action = ws_xml_get_node_text(node); if (!action) return 0; if(strcmp(action, EVT_ACTION_UNSUBSCRIBE) ==0 || strcmp(action, EVT_ACTION_RENEW) ==0 || strcmp(action, EVT_ACTION_PULL) == 0) return 1; else return 0; }
hash_t * wsman_get_selector_list(WsContextH cntx, WsXmlDocH doc) { WsXmlNodeH header; hash_t *h = NULL; if (doc == NULL) { doc = cntx->indoc; if (!doc) return NULL; } header = ws_xml_get_soap_header(doc); if (header) { h = wsman_get_selectors_from_epr(cntx, header); } return h; }
void wsmc_add_selector_from_options(WsXmlDocH doc, client_opt_t *options) { WsXmlNodeH header; hnode_t *hn; hscan_t hs; if (!options->selectors || hash_count(options->selectors) == 0) return; header = ws_xml_get_soap_header(doc); hash_scan_begin(&hs, options->selectors); while ((hn = hash_scan_next(&hs))) { wsman_add_selector(header, (char *) hnode_getkey(hn), (char *) hnode_get(hn)); debug("key = %s value=%s", (char *) hnode_getkey(hn), (char *) hnode_get(hn)); } }
char * wsman_get_fragment_string(WsContextH cntx, WsXmlDocH doc) { WsXmlNodeH header, n; char *mu = NULL; if(doc == NULL) doc = cntx->indoc; header = ws_xml_get_soap_header(doc); n = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_FRAGMENT_TRANSFER); if (n != NULL) { mu = ws_xml_find_attr_value(n, XML_NS_SOAP_1_2, SOAP_MUST_UNDERSTAND); if (mu != NULL && strcmp(mu, "true") == 0) { return ws_xml_get_node_text(n); } } return NULL; }
char * wsman_get_resource_uri(WsContextH cntx, WsXmlDocH doc) { char *val = NULL; WsXmlNodeH header, node; if (doc == NULL) { doc = cntx->indoc; if (!doc) return NULL; } header = ws_xml_get_soap_header(doc); node = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_RESOURCE_URI); val = (!node) ? NULL : ws_xml_get_node_text(node); return val; }
unsigned long wsman_get_max_envelope_size(WsContextH cntx, WsXmlDocH doc) { unsigned long size = 0; WsXmlNodeH header, maxsize; char *mu = NULL; if (doc == NULL) doc = cntx->indoc; header = ws_xml_get_soap_header(doc); maxsize = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_MAX_ENVELOPE_SIZE); mu = ws_xml_find_attr_value(maxsize, XML_NS_SOAP_1_2, SOAP_MUST_UNDERSTAND); if (mu != NULL && strcmp(mu, "true") == 0) { size = ws_deserialize_uint32(NULL, header, 0, XML_NS_WS_MAN, WSM_MAX_ENVELOPE_SIZE); } return size; }
static void test_serialize2(void) { epr_t *epr = epr_from_string("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationFilter?Name=OperatingSystemFilter0&CreationClassName=CIM_IndicationFilter&SystemName=localhost.localdomain&SystemCreationClassName=CIM_ComputerSystem"); if(epr == NULL) { printf("test serialize from string failed!\n"); return; } epr_add_selector_text(epr, CIM_NAMESPACE_SELECTOR, "root/interop"); //test epr_add_selector_text WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH header = ws_xml_get_soap_header(doc); epr_serialize(header,NULL,NULL,epr,0); ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc); epr_destroy(epr); printf("\033[22;32mtest create epr from string successfully!\033[m\n\n"); }
static void test_serialize1(void) { hash_t *selectors_filter = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry1 = NULL; entry1 = u_malloc(sizeof(selector_entry)*4); entry1[0].type = 0; entry1[0].entry.text = "OperatingSystemFilter0"; entry1[1].type = 0; entry1[1].entry.text = "localhost.localdomain"; entry1[2].type = 0; entry1[2].entry.text = "CIM_IndicationFilter"; entry1[3].type = 0; entry1[3].entry.text = "CIM_ComputerSystem"; hash_alloc_insert(selectors_filter, "Name", &entry1[0]); hash_alloc_insert(selectors_filter, "SystemName", &entry1[1]); hash_alloc_insert(selectors_filter, "CreationClassName", &entry1[2]); hash_alloc_insert(selectors_filter, "SystemCreationClassName", &entry1[3]); epr_t *epr_filter = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationFilter", selectors_filter, NULL); if(epr_filter == NULL) { printf("epr_create filter failed!\n"); return; } hash_t *selectors_handler = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry2 = u_malloc(sizeof(selector_entry)*4); entry2[0].type = 0; entry2[0].entry.text = "OperatingSystemHandler0"; entry2[1].type = 0; entry2[1].entry.text = "localhost.localdomain"; entry2[2].type = 0; entry2[2].entry.text = "CIM_IndicationHandlerCIMXML"; entry2[3].type = 0; entry2[3].entry.text = "CIM_ComputerSystem"; hash_alloc_insert(selectors_handler, "Name", &entry2[0]); hash_alloc_insert(selectors_handler, "SystemName", &entry2[1]); hash_alloc_insert(selectors_handler, "CreationClassName", &entry2[2]); hash_alloc_insert(selectors_handler, "SystemCreationClassName", &entry2[3]); epr_t *epr_handler = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationHandlerCIMXML", selectors_handler, NULL); if(epr_handler == NULL) { printf("epr_create handler failed!\n"); return; } hash_t *selectors_subscription = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry3 = NULL; entry3 = u_malloc(sizeof(selector_entry)*2); entry3[0].type = 1; entry3[0].entry.eprp = epr_filter; entry3[1].type = 1; entry3[1].entry.eprp = epr_handler; hash_alloc_insert(selectors_subscription, "Filter", &entry3[1]); hash_alloc_insert(selectors_subscription, "Handler", &entry3[1]); epr_t *epr_subscription = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationSubscription", selectors_subscription, NULL); if(epr_subscription == NULL) { printf("epr_create subscription failed!\n"); return; } epr_t *epr_cpy = epr_copy(epr_subscription); //test epr_copy WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH header = ws_xml_get_soap_header(doc); epr_serialize(header,NULL,NULL,epr_cpy,0); ws_xml_dump_doc(stdout, doc); epr_destroy(epr_filter); epr_destroy(epr_handler); epr_destroy(epr_subscription); epr_destroy(epr_cpy); hash_free(selectors_filter); hash_free(selectors_handler); hash_free(selectors_subscription); u_free(entry1); u_free(entry2); u_free(entry3); ws_xml_destroy_doc(doc); printf("\033[22;32mtest serialize epr successfully!\033[m\n\n"); }
/** * Create a Fault * @param rqstDoc Request document (Envelope) * @param code Fault code * @param subCodeNs Namespace of sub code * @param subCode Sub code * @param lang Language for Reason section * @param reason Fault Reason * @param addDetailProc Callback for details * @param addDetailProcData Pointer to callback data * @return XML document of the fault */ WsXmlDocH wsman_create_fault_envelope(WsXmlDocH rqstDoc, const char *code, const char *subCodeNs, const char *subCode, const char *fault_action, const char *lang, const char *reason, const char *faultDetail) { WsXmlDocH doc = NULL; WsXmlNodeH header, body, fault, codeNode, node; char uuidBuf[50]; char *soapNs; if (rqstDoc) { doc = wsman_create_response_envelope(rqstDoc, fault_action); } else { /* FIXME */ doc = ws_xml_create_envelope(); } if (doc == NULL) { return NULL; } header = ws_xml_get_soap_header(doc); body = ws_xml_get_soap_body(doc); soapNs = ws_xml_get_node_name_ns(body); fault = ws_xml_add_child(body, soapNs, SOAP_FAULT, NULL); codeNode = ws_xml_add_child(fault, soapNs, SOAP_CODE, NULL); node = ws_xml_add_child(codeNode, soapNs, SOAP_VALUE, NULL); ws_xml_set_node_qname_val(node, soapNs, code); if (subCode && subCode[0] != 0 ) { node = ws_xml_add_child(codeNode, soapNs, SOAP_SUBCODE, NULL); node = ws_xml_add_child(node, soapNs, SOAP_VALUE, NULL); if (subCodeNs) ws_xml_set_node_qname_val(node, subCodeNs, subCode); else ws_xml_set_node_text(node, subCode); } if (reason) { node = ws_xml_add_child(fault, soapNs, SOAP_REASON, NULL); node = ws_xml_add_child(node, soapNs, SOAP_TEXT, NULL); ws_xml_set_node_text(node, reason); ws_xml_set_node_lang(node, !lang ? "en" : lang); } if (faultDetail) { WsXmlNodeH d = ws_xml_add_child(fault, soapNs, SOAP_DETAIL, NULL); node = ws_xml_add_child_format(d, XML_NS_WS_MAN, SOAP_FAULT_DETAIL, "%s/%s", XML_NS_WSMAN_FAULT_DETAIL, faultDetail); } generate_uuid(uuidBuf, sizeof(uuidBuf), 0); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_MESSAGE_ID, uuidBuf); return doc; }
int wsman_parse_credentials(WsXmlDocH doc, WsSubscribeInfo * subsInfo, WsmanFaultCodeType *faultcode, WsmanFaultDetailType *detailcode) { int i = 0; WsXmlNodeH tnode = NULL, snode = NULL, node = NULL, temp = NULL; char *value = NULL; snode = ws_xml_get_soap_header(doc); snode = ws_xml_get_child(snode, 0, XML_NS_TRUST, WST_ISSUEDTOKENS); if(snode == NULL) return 0; tnode = ws_xml_get_child(snode, i, XML_NS_TRUST, WST_REQUESTSECURITYTOKENRESPONSE); while(tnode) { i++; node = ws_xml_get_child(tnode, 0, XML_NS_POLICY, WSP_APPLIESTO); if(node) { node = ws_xml_get_child(node, 0, XML_NS_ADDRESSING, WSA_EPR); if(node) { node = ws_xml_get_child(node, 0, XML_NS_ADDRESSING, WSA_ADDRESS); if(node) if(strcmp(ws_xml_get_node_text(node), subsInfo->epr_notifyto)) { *faultcode = WSMAN_INVALID_PARAMETER; *detailcode = WSMAN_DETAIL_INVALID_ADDRESS; return -1; } } } node = ws_xml_get_child(tnode, 0, XML_NS_TRUST, WST_TOKENTYPE); value = ws_xml_get_node_text(node); if(strcmp(value, WST_USERNAMETOKEN) == 0) { node = ws_xml_get_child(tnode, 0, XML_NS_TRUST, WST_REQUESTEDSECURITYTOKEN); if(node) { node = ws_xml_get_child(node, 0, XML_NS_SE, WSSE_USERNAMETOKEN); if(node) { temp = ws_xml_get_child(node, 0, XML_NS_SE, WSSE_USERNAME); if(temp) subsInfo->username = u_strdup(ws_xml_get_node_text(temp)); temp = ws_xml_get_child(node, 0, XML_NS_SE, WSSE_PASSWORD); if(temp) subsInfo->password = u_strdup(ws_xml_get_node_text(temp)); } } debug("subsInfo->username = %s, subsInfo->password = %s", subsInfo->username, \ subsInfo->password); } else if(strcmp(value, WST_CERTIFICATETHUMBPRINT) == 0) { node = ws_xml_get_child(tnode, 0, XML_NS_TRUST, WST_REQUESTEDSECURITYTOKEN); if(node) { node = ws_xml_get_child(node, 0, XML_NS_WS_MAN, WSM_CERTIFICATETHUMBPRINT); if(node) subsInfo->certificate_thumbprint = u_strdup(ws_xml_get_node_text(node)); } } else { *faultcode = WSMAN_INVALID_OPTIONS; *detailcode = WST_DETAIL_UNSUPPORTED_TOKENTYPE; return -1; } tnode = ws_xml_get_child(snode, i, XML_NS_TRUST, WST_REQUESTSECURITYTOKENRESPONSE); } return 0; }
int Redirect_Enumerate_EP(WsContextH cntx, WsEnumerateInfo* enumInfo, WsmanStatus *status, void *opaqueData) { WsXmlNodeH r_header=NULL, r_node=NULL, r_body=NULL, r_opt=NULL; WsXmlDocH r_response=NULL; char *resource_uri, *remote_enumContext; int op; WsManClient *cl=NULL; //The redirected Enumeration request must have RequestTotalItemsCountEstimate enabled r_header = ws_xml_get_soap_header(cntx->indoc); if ( (r_node = ws_xml_get_child(r_header,0,XML_NS_WS_MAN, WSM_REQUEST_TOTAL )) == NULL ) ws_xml_add_child(r_header, XML_NS_WS_MAN, WSM_REQUEST_TOTAL, NULL); cl = setup_redirect_client(cntx, enumInfo->auth_data.username, enumInfo->auth_data.password); //Set the enumInfo flags based on the indoc. This is required while handling the response in wsenum_eunmerate_stub r_body=ws_xml_get_soap_body(cntx->indoc); if ( ( r_node = ws_xml_get_child(r_body ,0, XML_NS_ENUMERATION, WSENUM_ENUMERATE )) != NULL ) { if ( (r_opt = ws_xml_get_child(r_node,0,XML_NS_WS_MAN,WSM_OPTIMIZE_ENUM )) != NULL ) enumInfo->flags |= WSMAN_ENUMINFO_OPT ; } wsman_send_request(cl,cntx->indoc); if (wsmc_get_last_error(cl) != WS_LASTERR_OK ){ //CURL or HTTP errors enumInfo->pullResultPtr = NULL; status->fault_code = WSMAN_INTERNAL_ERROR; status->fault_detail_code = 0; status->fault_msg = redirect_fault_msg( wsman_transport_get_last_error_string( wsmc_get_last_error(cl) ) ); return 1; } r_response = ws_xml_duplicate_doc(wsmc_build_envelope_from_response(cl)); if ( wsman_is_fault_envelope(r_response)){ enumInfo->pullResultPtr = NULL; wsman_get_fault_status_from_doc(r_response, status); return 1; } //Get the Estimated Total No.of Items from the response. r_header=ws_xml_get_soap_header(r_response); r_node=ws_xml_get_child(r_header,0,XML_NS_WS_MAN, WSM_TOTAL_ESTIMATE ); enumInfo->totalItems=(!r_node) ? 0: atoi(ws_xml_get_node_text(r_node)); //Get the remote context remote_enumContext = wsmc_get_enum_context(r_response); //Set the pullResultPtr only if some Enum Items are returned, in optimized mode. r_body= ws_xml_get_soap_body(r_response); if ( (r_node = ws_xml_get_child(r_body,0,XML_NS_ENUMERATION, WSENUM_ENUMERATE_RESP )) != NULL && ( ws_xml_get_child(r_node,0,XML_NS_WS_MAN,WSENUM_ITEMS) != NULL) ) { enumInfo->pullResultPtr = r_response; if( strlen(remote_enumContext) != 0 ) strncpy(enumInfo->enumId, remote_enumContext, strlen(remote_enumContext)+1); else // If all the instances are returned, the context will be NULL enumInfo->enumId[0]='\0'; } else{ //If not items are returned, set the context and return. strncpy(enumInfo->enumId, remote_enumContext, strlen(remote_enumContext)+1); ws_xml_destroy_doc(r_response); } wsmc_release(cl); return 0; }
SoapDispatchH wsman_dispatcher(WsContextH cntx, void *data, WsXmlDocH doc) { SoapDispatchH disp = NULL; char *uri = NULL, *action; WsManDispatcherInfo *dispInfo = (WsManDispatcherInfo *) data; WsDispatchEndPointInfo *ep = NULL; WsDispatchEndPointInfo *ep_custom = NULL; WsXmlDocH notdoc = NULL; #ifdef ENABLE_EVENTING_SUPPORT WsXmlNodeH nodedoc = NULL; #endif int i; /*, resUriMatch = 0; */ char *ns = NULL; WsDispatchInterfaceInfo *r = NULL; lnode_t *node = list_first((list_t *) dispInfo->interfaces); if (doc == NULL) { error("doc is null"); u_free(data); goto cleanup; } uri = wsman_get_resource_uri(cntx, doc); action = wsman_get_action(cntx, doc); #ifdef ENABLE_EVENTING_SUPPORT if(wsman_is_event_related_request(doc)) { WsXmlNodeH temp = ws_xml_get_child( ws_xml_get_soap_header(doc), 0, XML_NS_EVENTING, WSEVENT_IDENTIFIER); char *uuid = ws_xml_get_node_text(temp); debug("Request uuid: %s", uuid ? uuid : "NULL"); if(uuid) { lnode_t *t = list_first(cntx->subscriptionMemList); while(t != NULL) { WsSubscribeInfo *subsInfo = (WsSubscribeInfo *)t->list_data; if(!strcmp(uuid+5, subsInfo->subsId)) { uri = subsInfo->uri; break; } else t = list_next(cntx->subscriptionMemList, t); } if(t == NULL) { unsigned char *buf = NULL; int len; if(cntx->soap->subscriptionOpSet->get_subscription(cntx->soap->uri_subsRepository, uuid+5, &buf, &len) == 0) { notdoc = ws_xml_read_memory( (char *)buf, len, "UTF-8", 0); if(notdoc) { nodedoc = ws_xml_get_soap_header(notdoc); if(nodedoc) { nodedoc = ws_xml_get_child(nodedoc, 0, XML_NS_WS_MAN, WSM_RESOURCE_URI); if(nodedoc) { uri = ws_xml_get_node_text(nodedoc); } } } u_free(buf); } } } } #endif debug("uri: %s, action: %s", uri ? uri : "NULL", action ? action : "NULL"); if ((!uri || !action) && !wsman_is_identify_request(doc)) { goto cleanup; } while (node != NULL) { WsDispatchInterfaceInfo *ifc = (WsDispatchInterfaceInfo *) node->list_data; if (wsman_is_identify_request(doc)) { if ((ns = wsman_dispatcher_match_ns(ifc, XML_NS_WSMAN_ID))) { r = ifc; /* resUriMatch = 1; */ break; } debug("ns did not match"); } /* * If Resource URI is null then most likely we are dealing * with a generic plugin supporting a namespace with * multiple Resource URIs (e.g. CIM) **/ else if (ifc->wsmanResourceUri == NULL && (ns = wsman_dispatcher_match_ns(ifc, uri))) { r = ifc; /* resUriMatch = 1; */ break; } else if (ifc->wsmanResourceUri && !strcmp(uri, ifc->wsmanResourceUri)) { r = ifc; /* resUriMatch = 1; */ break; } node = list_next((list_t *) dispInfo->interfaces, node); } if (wsman_is_identify_request(doc) && r != NULL) { ep = &r->endPoints[0]; } else if (r != NULL) { char *ptr = action; /* * See if the action is part of the namespace which means that * we are dealing with a custom action */ if (ns != NULL) { size_t len = strlen(ns); if (!strncmp(action, ns, len) && action[len] == '/') ptr = &action[len + 1]; } for (i = 0; r->endPoints[i].serviceEndPoint != NULL; i++) { if (r->endPoints[i].inAction != NULL && !strcmp(ptr, r->endPoints[i].inAction)) { ep = &r->endPoints[i]; break; } else if (r->endPoints[i].inAction == NULL) { /* * Just store it for later * in case no match is found for above condition */ ep_custom = &r->endPoints[i]; } } } ws_remove_context_val(cntx, WSM_RESOURCE_URI); if (ep != NULL) { for (i = 0; i < dispInfo->mapCount; i++) { if (dispInfo->map[i].ep == ep) { disp = dispInfo->map[i].disp; break; } } } else if (ep_custom != NULL) { for (i = 0; i < dispInfo->mapCount; i++) { if (dispInfo->map[i].ep == ep_custom) { disp = dispInfo->map[i].disp; break; } } } cleanup: if(notdoc) ws_xml_destroy_doc(notdoc); if (ns) u_free(ns); return disp; }
WsXmlDocH wsmc_create_request(WsManClient * cl, const char *resource_uri, client_opt_t *options, filter_t *filter, WsmanAction action, char *method, void *data) { WsXmlDocH request; WsXmlNodeH body; WsXmlNodeH header; WsXmlNodeH node; char *_action = NULL; char buf[20]; if (action == WSMAN_ACTION_IDENTIFY) { request = ws_xml_create_envelope(); } else { if (method) { if (strchr(method, '/')) _action = u_strdup(method); else _action = wsman_make_action((char *)resource_uri, method); } else { _action = wsmc_create_action_str(action); } if (_action) { request = wsmc_build_envelope(cl->serctx, _action, WSA_TO_ANONYMOUS, (char *)resource_uri, cl->data.endpoint, options); } else { return NULL; } u_free(_action); } body = ws_xml_get_soap_body(request); header = ws_xml_get_soap_header(request); if (!body || !header ) return NULL; /* * flags to be passed as <w:OptionSet ...> <w:Option Name="..." ...> > */ if (options && (options->flags & (FLAG_CIM_EXTENSIONS|FLAG_EXCLUDE_NIL_PROPS))) { WsXmlNodeH opset = ws_xml_add_child(header, XML_NS_WS_MAN, WSM_OPTION_SET, NULL); if ((options->flags & FLAG_CIM_EXTENSIONS) == FLAG_CIM_EXTENSIONS) { WsXmlNodeH op = ws_xml_add_child(opset, XML_NS_WS_MAN, WSM_OPTION, NULL); ws_xml_add_node_attr(op, NULL, WSM_NAME, WSMB_SHOW_EXTENSION); } if ((options->flags & FLAG_EXCLUDE_NIL_PROPS) == FLAG_EXCLUDE_NIL_PROPS) { /* ExcludeNilProperties is non-standard, so put it under an openwsman namespace */ WsXmlNodeH op = ws_xml_add_child(opset, XML_NS_OPENWSMAN, WSM_OPTION, NULL); ws_xml_add_node_attr(op, NULL, WSM_NAME, WSMB_EXCLUDE_NIL_PROPS); } } switch (action) { case WSMAN_ACTION_IDENTIFY: case WSMAN_ACTION_ANON_IDENTIFY: ws_xml_add_child(body, XML_NS_WSMAN_ID, WSMID_IDENTIFY, NULL); break; case WSMAN_ACTION_CUSTOM: break; case WSMAN_ACTION_ENUMERATION: case WSMAN_ACTION_ASSOCIATORS: case WSMAN_ACTION_REFERENCES: node = ws_xml_add_child(body, XML_NS_ENUMERATION, WSENUM_ENUMERATE, NULL); wsman_set_enumeration_options(cl, body, resource_uri, options, filter); break; case WSMAN_ACTION_PULL: node = ws_xml_add_child(body, XML_NS_ENUMERATION, WSENUM_PULL, NULL); if (data) { ws_xml_add_child(node, XML_NS_ENUMERATION, WSENUM_ENUMERATION_CONTEXT, (char *) data); } break; case WSMAN_ACTION_RELEASE: node = ws_xml_add_child(body, XML_NS_ENUMERATION, WSENUM_RELEASE, NULL); if (data) { ws_xml_add_child(node, XML_NS_ENUMERATION, WSENUM_ENUMERATION_CONTEXT, (char *) data); } break; case WSMAN_ACTION_SUBSCRIBE: wsman_set_subscribe_options(cl, request, resource_uri, options, filter); break; case WSMAN_ACTION_UNSUBSCRIBE: node = ws_xml_add_child(body, XML_NS_EVENTING, WSEVENT_UNSUBSCRIBE,NULL); if(data) { if(((char *)data)[0] != 0) add_subscription_context(ws_xml_get_soap_header(request), (char *)data); } break; case WSMAN_ACTION_RENEW: node = ws_xml_add_child(body, XML_NS_EVENTING, WSEVENT_RENEW, NULL); sprintf(buf, "PT%fS", options->expires); ws_xml_add_child(node, XML_NS_EVENTING, WSEVENT_EXPIRES, buf); if(data) { if(((char *)data)[0] != 0) add_subscription_context(ws_xml_get_soap_header(request), (char *)data); } break; case WSMAN_ACTION_NONE: case WSMAN_ACTION_TRANSFER_CREATE: case WSMAN_ACTION_TEST: case WSMAN_ACTION_TRANSFER_GET: case WSMAN_ACTION_TRANSFER_PUT: case WSMAN_ACTION_TRANSFER_DELETE: break; } if (action == WSMAN_ACTION_PULL || action == WSMAN_ACTION_ENUMERATION) { if (options->max_elements > 0 ) { node = ws_xml_get_child(body, 0, NULL, NULL); if (action == WSMAN_ACTION_ENUMERATION) { if ((options->flags & FLAG_ENUMERATION_OPTIMIZATION) == FLAG_ENUMERATION_OPTIMIZATION ) { /* wsman:MaxElements is for Enumerate */ ws_xml_add_child_format(node, XML_NS_WS_MAN, WSENUM_MAX_ELEMENTS, "%d", options->max_elements); } } else { /* wsen:MaxElements is for Pull */ ws_xml_add_child_format(node, XML_NS_ENUMERATION, WSENUM_MAX_ELEMENTS, "%d", options->max_elements); } } if ((options->flags & FLAG_ENUMERATION_COUNT_ESTIMATION) == FLAG_ENUMERATION_COUNT_ESTIMATION) { ws_xml_add_child(header, XML_NS_WS_MAN, WSM_REQUEST_TOTAL, NULL); } } if (action != WSMAN_ACTION_TRANSFER_CREATE && action != WSMAN_ACTION_TRANSFER_PUT && action != WSMAN_ACTION_CUSTOM) { if ((options->flags & FLAG_DUMP_REQUEST) == FLAG_DUMP_REQUEST) { ws_xml_dump_node_tree(cl->dumpfile, ws_xml_get_doc_root(request)); } } return request; }
static void wsman_set_subscribe_options(WsManClient * cl, WsXmlDocH request, const char* resource_uri, client_opt_t *options, filter_t *filter) { WsXmlNodeH body = ws_xml_get_soap_body(request); WsXmlNodeH header = ws_xml_get_soap_header(request); WsXmlNodeH node = NULL, temp = NULL, node2 = NULL, node3 = NULL; char buf[32]; if(options->delivery_certificatethumbprint ||options->delivery_password || options->delivery_password) { node = ws_xml_add_child(header, XML_NS_TRUST, WST_ISSUEDTOKENS, NULL); ws_xml_add_node_attr(node, XML_NS_SOAP_1_2, SOAP_MUST_UNDERSTAND, "true"); if(options->delivery_certificatethumbprint) { node2 = ws_xml_add_child(node, XML_NS_TRUST, WST_REQUESTSECURITYTOKENRESPONSE, NULL); ws_xml_add_child(node2, XML_NS_TRUST, WST_TOKENTYPE,WST_CERTIFICATETHUMBPRINT ); node3 = ws_xml_add_child(node2, XML_NS_TRUST, WST_REQUESTEDSECURITYTOKEN, NULL); ws_xml_add_child(node3, XML_NS_WS_MAN, WSM_CERTIFICATETHUMBPRINT, options->delivery_certificatethumbprint); node3 = ws_xml_add_child(node2, XML_NS_POLICY, WSP_APPLIESTO, NULL); node3 = ws_xml_add_child(node3, XML_NS_ADDRESSING, WSA_EPR, NULL); ws_xml_add_child(node3, XML_NS_ADDRESSING, WSA_ADDRESS, options->delivery_uri); } if(options->delivery_username || options->delivery_password) { node2 = ws_xml_add_child(node, XML_NS_TRUST, WST_REQUESTSECURITYTOKENRESPONSE, NULL); ws_xml_add_child(node2, XML_NS_TRUST, WST_TOKENTYPE,WST_USERNAMETOKEN); node3 = ws_xml_add_child(node2, XML_NS_TRUST, WST_REQUESTEDSECURITYTOKEN, NULL); node3 = ws_xml_add_child(node3, XML_NS_SE, WSSE_USERNAMETOKEN, NULL); if(options->delivery_username) ws_xml_add_child(node3, XML_NS_SE, WSSE_USERNAME, options->delivery_username); if(options->delivery_password) ws_xml_add_child(node3, XML_NS_SE, WSSE_PASSWORD, options->delivery_password); node3 = ws_xml_add_child(node2, XML_NS_POLICY, WSP_APPLIESTO, NULL); node3 = ws_xml_add_child(node3, XML_NS_ADDRESSING, WSA_EPR, NULL); ws_xml_add_child(node3, XML_NS_ADDRESSING, WSA_ADDRESS, options->delivery_uri); } } node = ws_xml_add_child(body, XML_NS_EVENTING, WSEVENT_SUBSCRIBE,NULL); temp = ws_xml_add_child(node, XML_NS_EVENTING, WSEVENT_DELIVERY, NULL); if(temp) { ws_xml_add_node_attr(temp, NULL, WSEVENT_DELIVERY_MODE, wsmc_create_delivery_mode_str(options->delivery_mode)); if(options->delivery_uri) { node2 = ws_xml_add_child(temp, XML_NS_EVENTING, WSEVENT_NOTIFY_TO, NULL); ws_xml_add_child(node2, XML_NS_ADDRESSING, WSA_ADDRESS, options->delivery_uri); } if(options->delivery_sec_mode) { temp = ws_xml_add_child(temp, XML_NS_WS_MAN, WSM_AUTH, NULL); ws_xml_add_node_attr(temp, NULL, WSM_PROFILE, wsmc_create_delivery_sec_mode_str(options->delivery_sec_mode)); } if(options->heartbeat_interval) { snprintf(buf, 32, "PT%fS", options->heartbeat_interval); ws_xml_add_child(temp, XML_NS_WS_MAN, WSM_HEARTBEATS, buf); } if(options->reference) { WsXmlDocH doc = ws_xml_read_memory( options->reference, strlen(options->reference), "UTF-8", 0); node3 = ws_xml_get_doc_root(doc); temp = ws_xml_add_child(node2, XML_NS_ADDRESSING, WSA_REFERENCE_PROPERTIES, NULL); if(temp) ws_xml_duplicate_tree(temp, node3); } } if (options->expires) { snprintf(buf, 32, "PT%fS", options->expires); ws_xml_add_child(node, XML_NS_EVENTING, WSEVENT_EXPIRES, buf); } if (filter) { filter_serialize(node, filter, XML_NS_WS_MAN); } if (options->flags & FLAG_EVENT_SENDBOOKMARK) { ws_xml_add_child(node, XML_NS_WS_MAN, WSM_SENDBOOKMARKS, NULL); } }
static WsXmlDocH wsmc_build_envelope(WsSerializerContextH serctx, const char *action, const char *reply_to_uri, const char *resource_uri, const char *to_uri, client_opt_t *options) { WsXmlNodeH node; char uuidBuf[100]; WsXmlNodeH header; WsXmlDocH doc = ws_xml_create_envelope(); if (!doc) { error("Error while creating envelope"); return NULL; } header = ws_xml_get_soap_header(doc); generate_uuid(uuidBuf, sizeof(uuidBuf), 0); if (reply_to_uri == NULL) { reply_to_uri = WSA_TO_ANONYMOUS; } if (to_uri == NULL) { to_uri = WSA_TO_ANONYMOUS; } if (action != NULL) { ws_serialize_str(serctx, header, (char *)action, XML_NS_ADDRESSING, WSA_ACTION, 1); } if (to_uri) { ws_serialize_str(serctx, header, (char *)to_uri, XML_NS_ADDRESSING, WSA_TO, 1); } if (resource_uri) { ws_serialize_str(serctx, header, (char *)resource_uri, XML_NS_WS_MAN, WSM_RESOURCE_URI, 1); } if (uuidBuf[0] != 0) { ws_serialize_str(serctx, header, uuidBuf, XML_NS_ADDRESSING, WSA_MESSAGE_ID, 1); } if (options->timeout) { /* FIXME: see wsman-xml-serialize.c */ char buf[20]; sprintf(buf, "PT%u.%uS", (unsigned int) options->timeout / 1000, (unsigned int) options->timeout % 1000); ws_serialize_str(serctx, header, buf, XML_NS_WS_MAN, WSM_OPERATION_TIMEOUT, 0); } if (options->max_envelope_size) { ws_serialize_uint32(serctx, header, options->max_envelope_size, XML_NS_WS_MAN, WSM_MAX_ENVELOPE_SIZE, options->flags & FLAG_MUND_MAX_ESIZE); } if (options->fragment) { int mu = 0; if ((options->flags & FLAG_MUND_FRAGMENT) == FLAG_MUND_FRAGMENT) mu = 1; ws_serialize_str(serctx, header, options->fragment, XML_NS_WS_MAN, WSM_FRAGMENT_TRANSFER, 1); } node = ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_REPLY_TO, NULL); ws_xml_add_child(node, XML_NS_ADDRESSING, WSA_ADDRESS, (char *)reply_to_uri); /* Do not add the selectors to the header for reference instances */ if ((options->flags & FLAG_CIM_REFERENCES) != FLAG_CIM_REFERENCES) { wsmc_add_selector_from_options(doc, options); if (options->cim_ns) { wsman_add_selector(header, CIM_NAMESPACE_SELECTOR, options->cim_ns); } } return doc; }