install-ds.c

来自「支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS」· C语言 代码 · 共 1,542 行 · 第 1/3 页

C
1,542
字号
/* * 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. */#include "install-ds.h"#include <prmem.h>#include <plstr.h>#include <prprf.h>#include <string.h>#define PORT_Strcasecmp PL_strcasecmp#define MODULE_FILE_STRING "ModuleFile"#define MODULE_NAME_STRING "ModuleName"#define MECH_FLAGS_STRING "DefaultMechanismFlags"#define CIPHER_FLAGS_STRING "DefaultCipherFlags"#define FILES_STRING "Files"#define FORWARD_COMPATIBLE_STRING "ForwardCompatible"#define PLATFORMS_STRING "Platforms"#define RELATIVE_DIR_STRING "RelativePath"#define ABSOLUTE_DIR_STRING "AbsolutePath"#define FILE_PERMISSIONS_STRING "FilePermissions"#define EQUIVALENT_PLATFORM_STRING "EquivalentPlatform"#define EXECUTABLE_STRING "Executable"#define DEFAULT_PERMISSIONS 0777#define PLATFORM_SEPARATOR_CHAR ':'/* Error codes */enum {	BOGUS_RELATIVE_DIR=0,	BOGUS_ABSOLUTE_DIR,	BOGUS_FILE_PERMISSIONS,	NO_RELATIVE_DIR,	NO_ABSOLUTE_DIR,	EMPTY_PLATFORM_STRING,	BOGUS_PLATFORM_STRING,	REPEAT_MODULE_FILE,	REPEAT_MODULE_NAME,	BOGUS_MODULE_FILE,	BOGUS_MODULE_NAME,	REPEAT_MECH,	BOGUS_MECH_FLAGS,	REPEAT_CIPHER,	BOGUS_CIPHER_FLAGS,	REPEAT_FILES,	REPEAT_EQUIV,	BOGUS_EQUIV,	EQUIV_TOO_MUCH_INFO,	NO_FILES,	NO_MODULE_FILE,	NO_MODULE_NAME,	NO_PLATFORMS,	EQUIV_LOOP,	UNKNOWN_MODULE_FILE};/* Indexed by the above error codes */static const char *errString[] = {	"%s: Invalid relative directory",	"%s: Invalid absolute directory",	"%s: Invalid file permissions",	"%s: No relative directory specified",	"%s: No absolute directory specified",	"Empty string given for platform name",	"%s: invalid platform string",	"More than one ModuleFile entry given for platform %s",	"More than one ModuleName entry given for platform %s",	"Invalid ModuleFile specification for platform %s",	"Invalid ModuleName specification for platform %s",	"More than one DefaultMechanismFlags entry given for platform %s",	"Invalid DefaultMechanismFlags specification for platform %s",	"More than one DefaultCipherFlags entry given for platform %s",	"Invalid DefaultCipherFlags entry given for platform %s",	"More than one Files entry given for platform %s",	"More than one EquivalentPlatform entry given for platform %s",	"Invalid EquivalentPlatform specification for platform %s",	"Module %s uses an EquivalentPlatform but also specifies its own"		" information",	"No Files specification in module %s",	"No ModuleFile specification in module %s",	"No ModuleName specification in module %s",	"No Platforms specification in installer script",	"Platform %s has an equivalency loop",	"Module file \"%s\" in platform \"%s\" does not exist"};static char* PR_Strdup(const char* str);#define PAD(x)  {int i; for(i=0;i<x;i++) printf(" ");}#define PADINC 4Pk11Install_File*Pk11Install_File_new(){	Pk11Install_File* new_this;	new_this = (Pk11Install_File*)PR_Malloc(sizeof(Pk11Install_File));	Pk11Install_File_init(new_this);	return new_this;}voidPk11Install_File_init(Pk11Install_File* _this){	_this->jarPath=NULL;	_this->relativePath=NULL;	_this->absolutePath=NULL;	_this->executable=PR_FALSE;	_this->permissions=0;}/*//////////////////////////////////////////////////////////////////////////// Method:	~Pk11Install_File// Class:	Pk11Install_File// Notes:	Destructor.*/voidPk11Install_File_delete(Pk11Install_File* _this){	Pk11Install_File_Cleanup(_this);}/*//////////////////////////////////////////////////////////////////////////// Method:	Cleanup// Class:	Pk11Install_File*/voidPk11Install_File_Cleanup(Pk11Install_File* _this){	if(_this->jarPath) {		PR_Free(_this->jarPath);		_this->jarPath = NULL;	}	if(_this->relativePath) {		PR_Free(_this->relativePath);		_this->relativePath = NULL;	}	if(_this->absolutePath) {		PR_Free(_this->absolutePath);		_this->absolutePath = NULL;	}	_this->permissions = 0;	_this->executable = PR_FALSE;}/*//////////////////////////////////////////////////////////////////////////// Method:	Generate// Class:	Pk11Install_File// Notes:	Creates a file data structure from a syntax tree.// Returns:	NULL for success, otherwise an error message.*/char*Pk11Install_File_Generate(Pk11Install_File* _this,                          const Pk11Install_Pair *pair){	Pk11Install_ListIter *iter;	Pk11Install_Value *val;	Pk11Install_Pair *subpair;	Pk11Install_ListIter *subiter;	Pk11Install_Value *subval;	char* errStr;	char *endp;	PRBool gotPerms;	iter=NULL;	subiter=NULL;	errStr=NULL;	gotPerms=PR_FALSE;	/* Clear out old values */	Pk11Install_File_Cleanup(_this);	_this->jarPath = PR_Strdup(pair->key);	/* Go through all the pairs under this file heading */	iter = Pk11Install_ListIter_new(pair->list);	for( ; (val = iter->current); Pk11Install_ListIter_nextItem(iter)) {		if(val->type == PAIR_VALUE) {			subpair = val->pair;			/* Relative directory */			if(!PORT_Strcasecmp(subpair->key, RELATIVE_DIR_STRING)) {				subiter = Pk11Install_ListIter_new(subpair->list);				subval = subiter->current;				if(!subval || (subval->type != STRING_VALUE)){					errStr = PR_smprintf(errString[BOGUS_RELATIVE_DIR],                                     _this->jarPath);					goto loser;				}				_this->relativePath = PR_Strdup(subval->string);				Pk11Install_ListIter_delete(subiter);				subiter = NULL;				/* Absolute directory */			} else if( !PORT_Strcasecmp(subpair->key, ABSOLUTE_DIR_STRING)) {				subiter = Pk11Install_ListIter_new(subpair->list);				subval = subiter->current;				if(!subval || (subval->type != STRING_VALUE)){					errStr = PR_smprintf(errString[BOGUS_ABSOLUTE_DIR],                                     _this->jarPath);					goto loser;				}				_this->absolutePath = PR_Strdup(subval->string);				Pk11Install_ListIter_delete(subiter);				subiter = NULL;			/* file permissions */			} else if( !PORT_Strcasecmp(subpair->key,                                     FILE_PERMISSIONS_STRING)) {				subiter = Pk11Install_ListIter_new(subpair->list);				subval = subiter->current;				if(!subval || (subval->type != STRING_VALUE)){					errStr = PR_smprintf(errString[BOGUS_FILE_PERMISSIONS],                                    _this->jarPath);					goto loser;				}				_this->permissions = (int) strtol(subval->string, &endp, 8);				if(*endp != '\0' || subval->string == "\0") {					errStr = PR_smprintf(errString[BOGUS_FILE_PERMISSIONS],                                    _this->jarPath);					goto loser;				}				gotPerms = PR_TRUE;				Pk11Install_ListIter_delete(subiter);				subiter = NULL;			}		} else {			if(!PORT_Strcasecmp(val->string, EXECUTABLE_STRING)) {				_this->executable = PR_TRUE;			}		}	}	/* Default permission value */	if(!gotPerms) {		_this->permissions = DEFAULT_PERMISSIONS;	}	/* Make sure we got all the information */	if(!_this->relativePath && !_this->absolutePath) {		errStr = PR_smprintf(errString[NO_ABSOLUTE_DIR], _this->jarPath);		goto loser;	}#if 0	if(!_this->relativePath ) {		errStr = PR_smprintf(errString[NO_RELATIVE_DIR], _this->jarPath);		goto loser;	}	if(!_this->absolutePath) {		errStr = PR_smprintf(errString[NO_ABSOLUTE_DIR], _this->jarPath);		goto loser;	}#endifloser:	if(iter) {		Pk11Install_ListIter_delete(iter);		PR_Free(iter);	}	if(subiter) {		Pk11Install_ListIter_delete(subiter);		PR_Free(subiter);	}	return errStr;}/*//////////////////////////////////////////////////////////////////////////// Method:	Print// Class:	Pk11Install_File*/voidPk11Install_File_Print(Pk11Install_File* _this, int pad){	PAD(pad); printf("jarPath: %s\n",                     _this->jarPath ? _this->jarPath : "<NULL>");	PAD(pad); printf("relativePath: %s\n",				_this->relativePath ? _this->relativePath: "<NULL>");	PAD(pad); printf("absolutePath: %s\n",				_this->absolutePath ? _this->absolutePath: "<NULL>");	PAD(pad); printf("permissions: %o\n", _this->permissions);}Pk11Install_PlatformName*Pk11Install_PlatformName_new(){	Pk11Install_PlatformName* new_this;	new_this = (Pk11Install_PlatformName*)               PR_Malloc(sizeof(Pk11Install_PlatformName));	Pk11Install_PlatformName_init(new_this);	return new_this;}voidPk11Install_PlatformName_init(Pk11Install_PlatformName* _this){	_this->OS = NULL;	_this->verString = NULL;	_this->numDigits = 0;	_this->arch = NULL;}/*//////////////////////////////////////////////////////////////////////////// Method:	~Pk11Install_PlatformName// Class:	Pk11Install_PlatformName*/voidPk11Install_PlatformName_delete(Pk11Install_PlatformName* _this){	Pk11Install_PlatformName_Cleanup(_this);}/*//////////////////////////////////////////////////////////////////////////// Method:	Cleanup// Class:	Pk11Install_PlatformName*/voidPk11Install_PlatformName_Cleanup(Pk11Install_PlatformName* _this){	if(_this->OS) {		PR_Free(_this->OS);		_this->OS = NULL;	}	if(_this->verString) {		int i;		for (i=0; i<_this->numDigits; i++) {			PR_Free(_this->verString[i]);		}		PR_Free(_this->verString);		_this->verString = NULL;	}	if(_this->arch) {		PR_Free(_this->arch);		_this->arch = NULL;	}	_this->numDigits = 0;}/*//////////////////////////////////////////////////////////////////////////// Method:	Generate// Class:	Pk11Install_PlatformName// Notes:	Extracts the information from a platform string.*/char*Pk11Install_PlatformName_Generate(Pk11Install_PlatformName* _this,                                  const char *str){	char *errStr;	char *copy;	char *end, *start; /* start and end of a section (OS, version, arch)*/	char *pend, *pstart; /* start and end of one portion of version*/	char *endp; /* used by strtol*/	int periods, i;	errStr=NULL;	copy=NULL;	if(!str) {		errStr = PR_smprintf(errString[EMPTY_PLATFORM_STRING]);		goto loser;	}	copy = PR_Strdup(str);	/*	// Get the OS	*/	end = strchr(copy, PLATFORM_SEPARATOR_CHAR);	if(!end || end==copy) {		errStr = PR_smprintf(errString[BOGUS_PLATFORM_STRING], str);		goto loser;	}	*end = '\0';	_this->OS = PR_Strdup(copy);	/*	// Get the digits of the version of form: x.x.x (arbitrary number of digits)	*/	start = end+1;	end = strchr(start, PLATFORM_SEPARATOR_CHAR);	if(!end) {		errStr = PR_smprintf(errString[BOGUS_PLATFORM_STRING], str);		goto loser;	}	*end = '\0';	if(end!=start) { 		/* Find out how many periods*/		periods = 0;		pstart = start;		while( (pend=strchr(pstart, '.')) ) {			periods++;			pstart = pend+1;		}		_this->numDigits= 1+ periods;		_this->verString = (char**)PR_Malloc(sizeof(char*)*_this->numDigits);		pstart = start;		i = 0;		/* Get the digits before each period*/		while( (pend=strchr(pstart, '.')) ) {			if(pend == pstart) {				errStr = PR_smprintf(errString[BOGUS_PLATFORM_STRING], str);				goto loser;			}			*pend = '\0';			_this->verString[i] = PR_Strdup(pstart);			endp = pend;		if(endp==pstart || (*endp != '\0')) {				errStr = PR_smprintf(errString[BOGUS_PLATFORM_STRING], str);				goto loser;			}			pstart = pend+1;			i++;		}		/* Last digit comes after the last period*/		if(*pstart == '\0') {			errStr = PR_smprintf(errString[BOGUS_PLATFORM_STRING], str);			goto loser;		}		_this->verString[i] = PR_Strdup(pstart);		/*		if(endp==pstart || (*endp != '\0')) {			errStr = PR_smprintf(errString[BOGUS_PLATFORM_STRING], str);			goto loser;		}		*/	} else {		_this->verString = NULL;		_this->numDigits = 0;	}	/*	// Get the architecture	*/	start = end+1;	if( strchr(start, PLATFORM_SEPARATOR_CHAR) ) {		errStr = PR_smprintf(errString[BOGUS_PLATFORM_STRING], str);		goto loser;	}	_this->arch = PR_Strdup(start);	if(copy) {		PR_Free(copy);	}	return NULL;loser:	if(_this->OS) {		PR_Free(_this->OS);		_this->OS = NULL;	}	if(_this->verString) {		for (i=0; i<_this->numDigits; i++) {			PR_Free(_this->verString[i]);		}		PR_Free(_this->verString);		_this->verString = NULL;	}	_this->numDigits = 0;	if(_this->arch) {		PR_Free(_this->arch);		_this->arch = NULL;	}	return errStr;}/*//////////////////////////////////////////////////////////////////////////// Method:	operator ==// Class:	Pk11Install_PlatformName// Returns:	PR_TRUE if the platform have the same OS, arch, and version*/PRBoolPk11Install_PlatformName_equal(Pk11Install_PlatformName* _this,                               Pk11Install_PlatformName* cmp) 

⌨️ 快捷键说明

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