/* * 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: Authentication.cpp // // Notes: This file contains the implementation of the DSGI Authentication // // //---------------------------------------------------------------------------- #include #include #include #include #include #include #include #include #include "Authentication.h" #include "Options.h" using namespace std; /* * Constants for the common use */ static const char * CMD_FILE = "file"; #define TRUE 1 #define FALSE 0 #define MAX_STRING_LEN 1024 #define DELIMITER ':' /** * Description - removes trailing '\n' or '\r''\n' from char* * IN toChomp - string to chomp * Max string size is MAX_STRING_LEN * return: void */ void Chomp(char * toChomp) { size_t toChompLen = strnlen_s(toChomp, MAX_STRING_LEN); if ((toChompLen > 0) && (toChomp[toChompLen-1] == '\n')) { if ((toChompLen-1 > 0) && (toChomp[toChompLen-2] == '\r')) { toChomp[toChompLen-2] = '\0'; } else { toChomp[toChompLen-1] = '\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 -file \n\nExample: -file AuthFile.txt"; } // parse the command line arguments and set them in the options Map bool Parse(int argc, char* argv[], Options* options) { const Options::FormatNode format[] = {{CMD_FILE,true}}; if (!options->Parse(argc, const_cast(argv), format, sizeof(format)/sizeof(Options::FormatNode))) { return false; } // must have file if (!options->OptionExists(CMD_FILE)) { 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 = NULL ; string user = user_name; string pwd = user_password; string tmp_err; vector vec; UINT8 status = FALSE; do{ delimitStringToVec(vec, dll_params); argc =(int) vec.size() + 1; argv = new char*[argc]; if (argv == NULL) { tmp_err = "Memory allocation error"; break; } argv[0] = "connection string"; for (int i = 1;i