1*12720SWyllys.Ingersoll@Sun.COM /* 2*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER START 3*12720SWyllys.Ingersoll@Sun.COM * 4*12720SWyllys.Ingersoll@Sun.COM * The contents of this file are subject to the terms of the 5*12720SWyllys.Ingersoll@Sun.COM * Common Development and Distribution License (the "License"). 6*12720SWyllys.Ingersoll@Sun.COM * You may not use this file except in compliance with the License. 7*12720SWyllys.Ingersoll@Sun.COM * 8*12720SWyllys.Ingersoll@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*12720SWyllys.Ingersoll@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*12720SWyllys.Ingersoll@Sun.COM * See the License for the specific language governing permissions 11*12720SWyllys.Ingersoll@Sun.COM * and limitations under the License. 12*12720SWyllys.Ingersoll@Sun.COM * 13*12720SWyllys.Ingersoll@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*12720SWyllys.Ingersoll@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*12720SWyllys.Ingersoll@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*12720SWyllys.Ingersoll@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*12720SWyllys.Ingersoll@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*12720SWyllys.Ingersoll@Sun.COM * 19*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER END 20*12720SWyllys.Ingersoll@Sun.COM */ 21*12720SWyllys.Ingersoll@Sun.COM 22*12720SWyllys.Ingersoll@Sun.COM /* 23*12720SWyllys.Ingersoll@Sun.COM * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 24*12720SWyllys.Ingersoll@Sun.COM */ 25*12720SWyllys.Ingersoll@Sun.COM 26*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentSoapUtilities.h" 27*12720SWyllys.Ingersoll@Sun.COM #include "KMSAgentStringUtilities.h" 28*12720SWyllys.Ingersoll@Sun.COM #include "ApplianceParameters.h" 29*12720SWyllys.Ingersoll@Sun.COM 30*12720SWyllys.Ingersoll@Sun.COM #include "stdsoap2.h" 31*12720SWyllys.Ingersoll@Sun.COM 32*12720SWyllys.Ingersoll@Sun.COM /** 33*12720SWyllys.Ingersoll@Sun.COM * Get the peer's network address 34*12720SWyllys.Ingersoll@Sun.COM */ 35*12720SWyllys.Ingersoll@Sun.COM void GetPeerNetworkAddress (char* const o_psPeerNetworkAddress, 36*12720SWyllys.Ingersoll@Sun.COM struct soap* i_pSoap) 37*12720SWyllys.Ingersoll@Sun.COM { 38*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT(o_psPeerNetworkAddress); 39*12720SWyllys.Ingersoll@Sun.COM 40*12720SWyllys.Ingersoll@Sun.COM if (strlen(i_pSoap->host) > 0) 41*12720SWyllys.Ingersoll@Sun.COM { 42*12720SWyllys.Ingersoll@Sun.COM // IPv4 addresses can appear as ::ffff:a.b.c.d, strip off the prefix 43*12720SWyllys.Ingersoll@Sun.COM if (strncmp(i_pSoap->host, "::ffff:", 7) == 0) 44*12720SWyllys.Ingersoll@Sun.COM { 45*12720SWyllys.Ingersoll@Sun.COM strncpy(o_psPeerNetworkAddress, &i_pSoap->host[7], g_iMAX_PEER_NETWORK_ADDRESS_LENGTH); 46*12720SWyllys.Ingersoll@Sun.COM o_psPeerNetworkAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH-1] = '\0'; 47*12720SWyllys.Ingersoll@Sun.COM return; 48*12720SWyllys.Ingersoll@Sun.COM } 49*12720SWyllys.Ingersoll@Sun.COM strncpy(o_psPeerNetworkAddress, i_pSoap->host, g_iMAX_PEER_NETWORK_ADDRESS_LENGTH); 50*12720SWyllys.Ingersoll@Sun.COM o_psPeerNetworkAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH-1] = '\0'; 51*12720SWyllys.Ingersoll@Sun.COM return; 52*12720SWyllys.Ingersoll@Sun.COM } 53*12720SWyllys.Ingersoll@Sun.COM 54*12720SWyllys.Ingersoll@Sun.COM // i_pSoap->ip == 0 could not represent a valid 55*12720SWyllys.Ingersoll@Sun.COM // Peer Network Address (IPv4), check i_pSoap->session_host 56*12720SWyllys.Ingersoll@Sun.COM // for an IPv6 address 57*12720SWyllys.Ingersoll@Sun.COM if (i_pSoap->ip == 0) 58*12720SWyllys.Ingersoll@Sun.COM { 59*12720SWyllys.Ingersoll@Sun.COM #ifndef METAWARE 60*12720SWyllys.Ingersoll@Sun.COM if (strlen(i_pSoap->session_host) > 0) 61*12720SWyllys.Ingersoll@Sun.COM { 62*12720SWyllys.Ingersoll@Sun.COM // IPv4 addresses can appear as ::ffff:a.b.c.d, strip off the 63*12720SWyllys.Ingersoll@Sun.COM // prefix 64*12720SWyllys.Ingersoll@Sun.COM 65*12720SWyllys.Ingersoll@Sun.COM if (strncmp(i_pSoap->session_host, "::ffff:", 7) == 0) 66*12720SWyllys.Ingersoll@Sun.COM { 67*12720SWyllys.Ingersoll@Sun.COM strncpy(o_psPeerNetworkAddress, &i_pSoap->session_host[7], g_iMAX_PEER_NETWORK_ADDRESS_LENGTH); 68*12720SWyllys.Ingersoll@Sun.COM o_psPeerNetworkAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH-1] = '\0'; 69*12720SWyllys.Ingersoll@Sun.COM return; 70*12720SWyllys.Ingersoll@Sun.COM } 71*12720SWyllys.Ingersoll@Sun.COM 72*12720SWyllys.Ingersoll@Sun.COM strncpy(o_psPeerNetworkAddress, i_pSoap->session_host, g_iMAX_PEER_NETWORK_ADDRESS_LENGTH); 73*12720SWyllys.Ingersoll@Sun.COM o_psPeerNetworkAddress[g_iMAX_PEER_NETWORK_ADDRESS_LENGTH-1] = '\0'; 74*12720SWyllys.Ingersoll@Sun.COM return; 75*12720SWyllys.Ingersoll@Sun.COM } 76*12720SWyllys.Ingersoll@Sun.COM #endif 77*12720SWyllys.Ingersoll@Sun.COM strcpy(o_psPeerNetworkAddress, ""); 78*12720SWyllys.Ingersoll@Sun.COM return; 79*12720SWyllys.Ingersoll@Sun.COM } 80*12720SWyllys.Ingersoll@Sun.COM 81*12720SWyllys.Ingersoll@Sun.COM K_snprintf(o_psPeerNetworkAddress, 82*12720SWyllys.Ingersoll@Sun.COM g_iMAX_PEER_NETWORK_ADDRESS_LENGTH, 83*12720SWyllys.Ingersoll@Sun.COM "%d.%d.%d.%d", 84*12720SWyllys.Ingersoll@Sun.COM (int) (i_pSoap->ip >> 24)&0xFF, 85*12720SWyllys.Ingersoll@Sun.COM (int) (i_pSoap->ip >> 16)&0xFF, 86*12720SWyllys.Ingersoll@Sun.COM (int) (i_pSoap->ip >> 8)&0xFF, 87*12720SWyllys.Ingersoll@Sun.COM (int) (i_pSoap->ip)&0xFF); 88*12720SWyllys.Ingersoll@Sun.COM 89*12720SWyllys.Ingersoll@Sun.COM return; 90*12720SWyllys.Ingersoll@Sun.COM } 91*12720SWyllys.Ingersoll@Sun.COM 92*12720SWyllys.Ingersoll@Sun.COM /** 93*12720SWyllys.Ingersoll@Sun.COM * Get the soap fault code and print it 94*12720SWyllys.Ingersoll@Sun.COM */ 95*12720SWyllys.Ingersoll@Sun.COM void GetSoapFault(char* o_psFaultMessage, 96*12720SWyllys.Ingersoll@Sun.COM struct soap *i_pstSoap) 97*12720SWyllys.Ingersoll@Sun.COM { 98*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT( i_pstSoap ); 99*12720SWyllys.Ingersoll@Sun.COM 100*12720SWyllys.Ingersoll@Sun.COM strncpy (o_psFaultMessage, " SoapFaultCode=",g_iMAX_SOAP_FAULT_MESSAGE_LENGTH); 101*12720SWyllys.Ingersoll@Sun.COM o_psFaultMessage[g_iMAX_SOAP_FAULT_MESSAGE_LENGTH-1] = '\0'; 102*12720SWyllys.Ingersoll@Sun.COM strncat (o_psFaultMessage, GET_SOAP_FAULTCODE(i_pstSoap), 103*12720SWyllys.Ingersoll@Sun.COM g_iMAX_SOAP_FAULT_MESSAGE_LENGTH-strlen(o_psFaultMessage)); 104*12720SWyllys.Ingersoll@Sun.COM strncat (o_psFaultMessage, " SoapFaultString=", 105*12720SWyllys.Ingersoll@Sun.COM g_iMAX_SOAP_FAULT_MESSAGE_LENGTH-strlen(o_psFaultMessage)); 106*12720SWyllys.Ingersoll@Sun.COM strncat (o_psFaultMessage, GET_SOAP_FAULTSTRING(i_pstSoap), 107*12720SWyllys.Ingersoll@Sun.COM g_iMAX_SOAP_FAULT_MESSAGE_LENGTH-strlen(o_psFaultMessage)); 108*12720SWyllys.Ingersoll@Sun.COM strncat (o_psFaultMessage, " SoapFaultDetail=", 109*12720SWyllys.Ingersoll@Sun.COM g_iMAX_SOAP_FAULT_MESSAGE_LENGTH-strlen(o_psFaultMessage)); 110*12720SWyllys.Ingersoll@Sun.COM strncat (o_psFaultMessage, GET_SOAP_FAULTDETAIL(i_pstSoap), 111*12720SWyllys.Ingersoll@Sun.COM g_iMAX_SOAP_FAULT_MESSAGE_LENGTH-strlen(o_psFaultMessage)); 112*12720SWyllys.Ingersoll@Sun.COM 113*12720SWyllys.Ingersoll@Sun.COM return; 114*12720SWyllys.Ingersoll@Sun.COM } 115*12720SWyllys.Ingersoll@Sun.COM 116*12720SWyllys.Ingersoll@Sun.COM bool PutBinaryIntoSoapBinary( 117*12720SWyllys.Ingersoll@Sun.COM struct soap* i_pSoap, 118*12720SWyllys.Ingersoll@Sun.COM const unsigned char* i_pBinary, 119*12720SWyllys.Ingersoll@Sun.COM int i_iBinarySize, 120*12720SWyllys.Ingersoll@Sun.COM unsigned char*& o_pSoapBinary, 121*12720SWyllys.Ingersoll@Sun.COM int& o_iSoapBinarySize ) 122*12720SWyllys.Ingersoll@Sun.COM { 123*12720SWyllys.Ingersoll@Sun.COM FATAL_ASSERT( i_pSoap ); 124*12720SWyllys.Ingersoll@Sun.COM 125*12720SWyllys.Ingersoll@Sun.COM o_pSoapBinary = 0; 126*12720SWyllys.Ingersoll@Sun.COM o_iSoapBinarySize = 0; 127*12720SWyllys.Ingersoll@Sun.COM 128*12720SWyllys.Ingersoll@Sun.COM if ( i_iBinarySize > 0 ) 129*12720SWyllys.Ingersoll@Sun.COM { 130*12720SWyllys.Ingersoll@Sun.COM o_pSoapBinary = 131*12720SWyllys.Ingersoll@Sun.COM (unsigned char*)soap_malloc( 132*12720SWyllys.Ingersoll@Sun.COM i_pSoap, 133*12720SWyllys.Ingersoll@Sun.COM sizeof(unsigned char) * i_iBinarySize); 134*12720SWyllys.Ingersoll@Sun.COM 135*12720SWyllys.Ingersoll@Sun.COM if ( !o_pSoapBinary ) 136*12720SWyllys.Ingersoll@Sun.COM { 137*12720SWyllys.Ingersoll@Sun.COM // No log for out of memory condition 138*12720SWyllys.Ingersoll@Sun.COM 139*12720SWyllys.Ingersoll@Sun.COM return false; 140*12720SWyllys.Ingersoll@Sun.COM } 141*12720SWyllys.Ingersoll@Sun.COM 142*12720SWyllys.Ingersoll@Sun.COM o_iSoapBinarySize = i_iBinarySize; 143*12720SWyllys.Ingersoll@Sun.COM 144*12720SWyllys.Ingersoll@Sun.COM memcpy(o_pSoapBinary, i_pBinary, i_iBinarySize); 145*12720SWyllys.Ingersoll@Sun.COM } 146*12720SWyllys.Ingersoll@Sun.COM 147*12720SWyllys.Ingersoll@Sun.COM return true; 148*12720SWyllys.Ingersoll@Sun.COM } 149