/* * INTEL CONFIDENTIAL * Copyright (c) 2007 Intel Corporation. All Rights Reserved. * The source code contained or described herein and all documents related * to the source code ("Material") are owned by Intel Corporation or its * suppliers or licensors. Title to the Material remains with Intel Corporation * or its suppliers and licensors. The Material contains trade secrets and * proprietary and confidential information of Intel or its suppliers and l * icensors. The Material is protected by worldwide copyright and trade secret * laws and treaty provisions. No part of the Material may be used, copied, * reproduced, modified, published, uploaded, posted, transmitted, distributed, * or disclosed in any way without Intel's prior express written permission. * * No license under any patent, copyright, trade secret or other intellectual * property right is granted to or conferred upon you by disclosure or delivery * of the Materials, either expressly, by implication, inducement, estoppel or * otherwise. Any license under such intellectual property rights must be * expressed and approved by Intel in writing. */ //---------------------------------------------------------------------------- // // Copyright (C) Intel Corporation, 2004 - 2007. // // File: SOAPAuthentication.cpp // // Notes: This file contains the implementation of the SOAP Authentication // // //---------------------------------------------------------------------------- #include #include #include #define _WINSOCKAPI_ #include #include "SOAPAuthentication.h" #include "CommonDefinitions.h" #include "SoapCommonDefinitions.h" #include "MPSAuthenticationSoapBinding.nsmap" #include "Options.h" #include "gSoapGeneratedCode\soapStub.h" #include using namespace std; /* * Constants for the common use */ static const char * CMD_TLS = "tls"; static const char * CMD_TARGET = "target"; static const char * CMD_KRB = "krb"; static const char * CMD_VERBOSE = "verbose"; static const char * CMD_USER = "user"; static const char * CMD_PASS = "pass"; static const char * CMD_CERT_NAME= "cert"; static const char * CMD_PROXY = "proxy"; static const char * CMD_PROXY_USER_NAME = "proxyUserName"; static const char * CMD_PROXY_PASS = "proxyPass"; #define TRUE 1 #define FALSE 0 /* * Print usage information for the user. * Arguments: * cmd - pointer to the string that holds the application name */ void Usage(string& errStr) { errStr= "Parse connection string error:\nUsage:\n\t -target [-krb] [-user -pass ] [-cert ][-tls][-proxy -proxyUserName -proxyPass ] \n\nExample: -target http://hostname:7792/MPSAuthenticationService -user admin -pass Admin!123\n"; } bool returnDll(string err_str, char* err, UINT32 err_len, bool ret) { //copy error string if ((err_str.length() != 0 ) && (err_str.length() < err_len)) { strcpy_s(err, err_len, err_str.c_str()); } return ret; } // parse the commnad line arguments and set them in the options Map bool Parse(int argc, char* argv[], Options* options) { const Options::FormatNode format[] = { {CMD_VERBOSE,true}, {CMD_USER,true}, {CMD_PASS,true}, {CMD_CERT_NAME,true}, {CMD_TARGET,true}, {CMD_TLS,false}, {CMD_KRB,false}, {CMD_PROXY,true} , {CMD_PROXY_USER_NAME,true}, {CMD_PROXY_PASS,true}}; if (!options->Parse(argc, const_cast(argv), format, sizeof(format)/sizeof(Options::FormatNode))) { return false; } //must have either userName & Password or must be Kerberose if((!(options->OptionExists(CMD_USER) && options->OptionExists(CMD_PASS))) && (!options->OptionExists(CMD_KRB))) { return false; } // must have target if (!options->OptionExists(CMD_TARGET)) { return false; } // check that if proxy username or proxy password is given, than the other one is also available // and that both are given only if proxy is available int numOfProxyCount = 0; if (options->OptionExists(CMD_PROXY_USER_NAME)) { ++numOfProxyCount; } if (options->OptionExists(CMD_PROXY_PASS)) { ++numOfProxyCount; } if ((numOfProxyCount == 1) || ((numOfProxyCount == 2) && (!options->OptionExists(CMD_PROXY)))) { return false; } return true; } #ifdef _MANAGED #pragma managed(push, off) #endif BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } #ifdef _MANAGED #pragma managed(pop) #endif void delimitStringToVec(vector& vec, const char * strToDelim) { const char delimit = '-'; stringstream s(strToDelim); string strBuffer = ""; do{ string curWord; s >> curWord; if(curWord.length() != 0) { if (curWord.at(0) == delimit) { if (strBuffer.length() != 0) { vec.push_back(strBuffer); } vec.push_back(curWord); strBuffer = ""; } else { if (strBuffer.length() != 0) { strBuffer +=" "; } strBuffer +=curWord; } } }while (s); if (strBuffer.length() != 0) { vec.push_back(strBuffer); } } UINT8 Authenticate(const char* user_name ,const char* user_password , const char* dll_params ,char* err_str, UINT32 err_len) { Options options; int argc = 0; char** argv ; Soap* soap; string user = user_name; string pwd = user_password; string tmp_err; stringstream s(dll_params); vector vec; delimitStringToVec(vec, dll_params); argc =(int) vec.size()+1; argv = new char*[argc]; argv[0] = "connection string"; for (int i = 1;iInit(namespaces); //Validating user-name and password parameters. if (strnlen_s(user_name, USER_MAX_LEN + 1) > USER_MAX_LEN) { printf("Invalid parameter: user-name can contain up to %u characters.\n", USER_MAX_LEN); return returnDll(tmp_err, err_str, err_len, FALSE); } if(strnlen_s(user_password, PASS_MAX_LEN + 1) > PASS_MAX_LEN || (strnlen_s(user_password, PASS_MIN_LEN) < PASS_MIN_LEN && strnlen_s(user_password, PASS_MIN_LEN) != 0)) { printf("Invalid parameter: password can contain between %u to %u characters.\n", PASS_MIN_LEN, PASS_MAX_LEN); } _mpa__AuthenticateRequest request; request.AuthenticateId = user; request.AuthenticatePassword = pwd; _mpa__AuthenticateResponse response; if(soap_call___mpa__Authenticate(soap->GetSoap(),soap->GetIp(), NULL,&request,response)) { tmp_err = "SOAP failure"; delete [] argv; delete soap; return returnDll(tmp_err,err_str, err_len,FALSE); } UINT8 res = (response.AuthenticateResult)? TRUE:FALSE; delete [] argv; delete soap; return returnDll(tmp_err,err_str, err_len,res); }