⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmtinit.c

📁 安全开发库。含客户端建立ssl连接、签名、证书验证、证书发布和撤销等。编译用到nss
💻 C
📖 第 1 页 / 共 2 页
字号:
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- *//*  * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ *  * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. *  * The Original Code is the Netscape security libraries. *  * The Initial Developer of the Original Code is Netscape * Communications Corporation.  Portions created by Netscape are  * Copyright (C) 1994-2000 Netscape Communications Corporation.  All * Rights Reserved. *  * Contributor(s): *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL"), in which case the provisions of the GPL are applicable  * instead of those above.  If you wish to allow use of your  * version of this file only under the terms of the GPL and not to * allow others to use your version of this file under the MPL, * indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by * the GPL.  If you do not delete the provisions above, a recipient * may use your version of this file under either the MPL or the * GPL. */#ifdef XP_UNIX#include <sys/time.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <sys/un.h>#include <sys/stat.h>#include <netinet/tcp.h>#else#ifdef XP_MAC#else /* Windows */#include <windows.h>#include <winsock.h>#include <direct.h>#include <sys/stat.h>#endif#endif#include "messages.h"#include "cmtcmn.h"#include "cmtutils.h"#include "obscure.h"#include <string.h>#ifdef XP_UNIX#define DIRECTORY_SEPARATOR '/'#elif defined WIN32#define DIRECTORY_SEPARATOR '\\'#elif defined XP_MAC#define DIRECTORY_SEPARATOR ':'#endif/* Local defines */#define CARTMAN_PORT	11111#define MAX_PATH_LEN    256/* * This is the table that will ultimately get patched by * the patcher. *//* Mac compiler wants string constants to be null terminated. */#ifdef XP_MAC#define SVRPLCY_UTILITY_MARKER "f107ecde37980a6d899cc271db73541"#else#define SVRPLCY_UTILITY_MARKER "f107ecde37980a6d899cc271db735411"#endif#define ENDMARKER 0#define SVRPLCY_MARKERLEN 32#define SVRPLCY_TABLESIZE 50#define SVRPLCY_MACLEN 4/* * SVRPLCYPolicyEntry - contains policy type, key, and value for policy *   definitions. */typedef struct SVRPLCYPolicyEntry SVRPLCYPolicyEntry;struct SVRPLCYPolicyEntry{  CMInt32 policy;  CMInt32 key;  CMInt32 value;};typedef struct SVRPLCYPolicyTable SVRPLCYPolicyTable;struct SVRPLCYPolicyTable{  unsigned char marker[SVRPLCY_MARKERLEN];  SVRPLCYPolicyEntry table[SVRPLCY_TABLESIZE];  unsigned char mac[SVRPLCY_MACLEN];};/* * SVRPLCY_UtilityPolicyTable */static const SVRPLCYPolicyTable SVRPLCY_UtilityPolicyTable ={  SVRPLCY_UTILITY_MARKER,  {    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },    { ENDMARKER, 0, 0 }, { ENDMARKER, 0, 0 },  },  { 0, 0, 0, 0 }};/* write to the cmnav.log */#if 0#define LOG(x); do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \   fprintf(f, x); fclose(f); } } while(0);#define LOG_S(x); do { FILE *f; f=fopen("cmnav.log","a+"); if (f) { \   fprintf(f, "%s", x); fclose(f); } } while(0);#define ASSERT(x); if (!(x)) { LOG("ASSERT:"); LOG(#x); LOG("\n"); exit(-1); }#else#define LOG(x); ;#define LOG_S(x); ;#define ASSERT(x); ;#endif/* On error, returns -1.** On success, returns non-negative number of unobscured bytes in buf */intRecvInitObscureData(CMT_SocketFuncs *sockFuncs, CMTSocket sock,                     SSMObscureObject * obj, void * buf, int bufSize ){    SSMObscureBool done = 0;    int rv = -1;    do {        int cc;        cc = sockFuncs->recv(sock, buf, bufSize);        if (cc <= 0)            return -1;	    rv = SSMObscure_RecvInit(obj, buf, cc, &done);    } while (!done);    return rv;}/* returns -1 on error, 0 on success. */intSendInitObscureData(CMT_SocketFuncs *sockFuncs, CMTSocket sock,                     SSMObscureObject * obj){    unsigned char * initBuf = NULL;    int             rv      = -1;    do {	int bufLen;	int len;	int cc;	bufLen = SSMObscure_SendInit(obj, NULL);	if (bufLen <= 0)	    break;	initBuf = (unsigned char *) malloc(bufLen);	if (!initBuf)	    break;	len = SSMObscure_SendInit(obj, initBuf);	if (len != bufLen)	    break;	cc = sockFuncs->send(sock, initBuf, len);	/* Note, this code assumes a blocking socket, 	** and hence doesn't deal with short writes.	*/	if (cc < len) 	    break;    	rv = 0;    } while (0);    if (initBuf) {	free(initBuf);    	initBuf = NULL;    }    return rv;}SSMObscureObject * InitClientObscureObject(CMT_SocketFuncs *sockFuncs,                                            CMTSocket sock){    SSMObscureObject * sobj = NULL;    unsigned char buf[512];    int rv = -1;    /* Create the obscuring object */    sobj = SSMObscure_Create(0);    if (!sobj) {        goto loser;    }    /* Send the initialization data */    rv = SendInitObscureData(sockFuncs, sock, sobj);    if (rv < 0) {        goto loser;    }    /* Receive the obscuring initialization data */    rv = RecvInitObscureData(sockFuncs, sock, sobj, buf, sizeof(buf));    if (rv < 0) {        goto loser;    }    return sobj;loser:    if (sobj) {        SSMObscure_Destroy(sobj);    }    return NULL;}static char*getCurrWorkDir(char *buf, int maxLen){#if defined WIN32    return _getcwd(buf, maxLen);#elif defined XP_UNIX    return getcwd(buf, maxLen);#else    return NULL;#endif}static voidsetWorkingDir(char *path){#if defined WIN32    _chdir(path);#elif defined XP_UNIX    chdir(path);#else    return;#endif}static CMTStatuslaunch_psm(char *executable){    char command[MAX_PATH_LEN];#ifdef WIN32    STARTUPINFO sui;    PROCESS_INFORMATION pi;    UNALIGNED long *posfhnd;    int i;    char *posfile;    sprintf(command,"%s > psmlog", executable);    ZeroMemory( &sui, sizeof(sui) );    sui.cb = sizeof(sui);    sui.cbReserved2 = (WORD)(sizeof( int ) + (3 * (sizeof( char ) +                                                    sizeof( long ))));    sui.lpReserved2 = calloc( sui.cbReserved2, 1 );    *((UNALIGNED int *)(sui.lpReserved2)) = 3;    posfile = (char *)(sui.lpReserved2 + sizeof( int ));    posfhnd = (UNALIGNED long *)(sui.lpReserved2 + sizeof( int ) +                                  (3 * sizeof( char )));        for ( i = 0, posfile = (char *)(sui.lpReserved2 + sizeof( int )),              posfhnd = (UNALIGNED long *)(sui.lpReserved2 + sizeof( int ) + (3 * sizeof( char ))) ;          i < 3 ; i++, posfile++, posfhnd++ ) {                *posfile = 0;        *posfhnd = (long)INVALID_HANDLE_VALUE;    }    /* Now, fire up PSM */    if (!CreateProcess(NULL, command, NULL, NULL, TRUE, DETACHED_PROCESS,                        NULL, NULL, &sui, &pi)) {        goto loser;    }    return CMTSuccess; loser:    return CMTFailure;#elif defined XP_UNIX    sprintf(command,"./%s &", executable);    if (system(command) == -1) {        goto loser;    }    return CMTSuccess; loser:    return CMTFailure;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -