Compare commits
4 Commits
NSS_BOB_SH
...
MAPI_TRUNK
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
112cd3f592 | ||
|
|
0e43f0be3f | ||
|
|
2eb83bc94e | ||
|
|
eabbdbd75c |
28
mozilla/mailnews/mapi/makefile.win
Normal file
28
mozilla/mailnews/mapi/makefile.win
Normal file
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
# Krishna Mohan Khandrika <kkhandrika@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
DIRS=mapihook resources mapiDll
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
54
mozilla/mailnews/mapi/mapiDll/Mapi32.DEF
Normal file
54
mozilla/mailnews/mapi/mapiDll/Mapi32.DEF
Normal file
@@ -0,0 +1,54 @@
|
||||
; ***** BEGIN LICENSE BLOCK *****
|
||||
; Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
;
|
||||
; 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 Mozilla.
|
||||
;
|
||||
; The Initial Developer of the Original Code is
|
||||
; Netscape Communications Corp.
|
||||
; Portions created by the Initial Developer are Copyright (C) 2001
|
||||
; the Initial Developer. All Rights Reserved.
|
||||
;
|
||||
; Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
;
|
||||
; Alternatively, the contents of this file may be used under the terms of
|
||||
; either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
; the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
; in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
; of those above. If you wish to allow use of your version of this file only
|
||||
; under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
; use your version of this file under the terms of the MPL, indicate your
|
||||
; decision by deleting the provisions above and replace them with the notice
|
||||
; and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
; the provisions above, a recipient may use your version of this file under
|
||||
; the terms of any one of the MPL, the GPL or the LGPL.
|
||||
;
|
||||
; ***** END LICENSE BLOCK *****
|
||||
|
||||
LIBRARY mozMapi32.dll
|
||||
DESCRIPTION 'Mozilla Simple MAPI Support'
|
||||
|
||||
EXPORTS
|
||||
MAPILogon
|
||||
MAPILogoff
|
||||
MAPISendMail
|
||||
MAPISendDocuments
|
||||
MAPIFindNext
|
||||
MAPIReadMail
|
||||
MAPISaveMail
|
||||
MAPIDeleteMail
|
||||
MAPIAddress
|
||||
MAPIDetails
|
||||
MAPIResolveName
|
||||
MAPIFreeBuffer
|
||||
GetMapiDllVersion
|
||||
|
||||
335
mozilla/mailnews/mapi/mapiDll/MapiDll.cpp
Normal file
335
mozilla/mailnews/mapi/mapiDll/MapiDll.cpp
Normal file
@@ -0,0 +1,335 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
* Contributor(s): Rajiv Dayal (rdayal@netscape.com)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <assert.h>
|
||||
#include <mapidefs.h>
|
||||
#include <mapi.h>
|
||||
#include "msgMapi.h"
|
||||
#include "msgMapiMain.h"
|
||||
|
||||
#define MAX_RECIPS 100
|
||||
#define MAX_FILES 100
|
||||
|
||||
const CLSID CLSID_nsMapiImp = {0x29f458be, 0x8866, 0x11d5,
|
||||
{0xa3, 0xdd, 0x0, 0xb0, 0xd0, 0xf3, 0xba, 0xa7}};
|
||||
const IID IID_nsIMapi = {0x6EDCD38E,0x8861,0x11d5,
|
||||
{0xA3,0xDD,0x00,0xB0,0xD0,0xF3,0xBA,0xA7}};
|
||||
|
||||
DWORD tId = 0;
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE aInstance, DWORD aReason, LPVOID aReserved)
|
||||
{
|
||||
switch (aReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH : tId = TlsAlloc();
|
||||
if (tId == 0xFFFFFFFF)
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH : TlsFree(tId);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL InitMozillaReference(nsIMapi **aRetValue)
|
||||
{
|
||||
// Check wehther this thread has a valid Interface
|
||||
// by looking into thread-specific-data variable
|
||||
|
||||
*aRetValue = (nsIMapi *)TlsGetValue(tId);
|
||||
|
||||
// Check whether the pointer actually resolves to
|
||||
// a valid method call; otherwise mozilla is not running
|
||||
|
||||
if ((*aRetValue) && (*aRetValue)->IsValid() == S_OK)
|
||||
return TRUE;
|
||||
|
||||
HRESULT hRes = CoInitialize(NULL);
|
||||
|
||||
hRes = ::CoCreateInstance(CLSID_nsMapiImp, NULL, CLSCTX_LOCAL_SERVER,
|
||||
IID_nsIMapi, (LPVOID *)aRetValue);
|
||||
|
||||
if (hRes == S_OK && (*aRetValue)->Initialize() == S_OK)
|
||||
if (TlsSetValue(tId, (LPVOID)(*aRetValue)))
|
||||
return TRUE;
|
||||
|
||||
// Either CoCreate or TlsSetValue failed; so return FALSE
|
||||
|
||||
if ((*aRetValue))
|
||||
(*aRetValue)->Release();
|
||||
|
||||
::CoUninitialize();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// The MAPILogon function begins a Simple MAPI session, loading the default message ////
|
||||
// store and address book providers ////
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ULONG FAR PASCAL MAPILogon(ULONG aUIParam, LPTSTR aProfileName,
|
||||
LPTSTR aPassword, FLAGS aFlags,
|
||||
ULONG aReserved, LPLHANDLE aSession)
|
||||
{
|
||||
HRESULT hr = 0;
|
||||
ULONG nSessionId = 0;
|
||||
nsIMapi *pNsMapi = NULL;
|
||||
|
||||
if (!InitMozillaReference(&pNsMapi))
|
||||
return MAPI_E_FAILURE;
|
||||
|
||||
if (!(aFlags & MAPI_UNICODE))
|
||||
{
|
||||
// Need to convert the parameters to Unicode.
|
||||
|
||||
char *pUserName = (char *) aProfileName;
|
||||
char *pPassWord = (char *) aPassword;
|
||||
|
||||
TCHAR ProfileName[MAX_NAME_LEN] = {0};
|
||||
TCHAR PassWord[MAX_PW_LEN] = {0};
|
||||
|
||||
if (pUserName != NULL)
|
||||
{
|
||||
if (!MultiByteToWideChar(CP_ACP, 0, pUserName, -1, ProfileName,
|
||||
MAX_NAME_LEN))
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
if (pPassWord != NULL)
|
||||
{
|
||||
if (!MultiByteToWideChar(CP_ACP, 0, pPassWord, -1, PassWord,
|
||||
MAX_NAME_LEN))
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
hr = pNsMapi->Login(aUIParam, ProfileName, PassWord, aFlags,
|
||||
&nSessionId);
|
||||
}
|
||||
else
|
||||
hr = pNsMapi->Login(aUIParam, aProfileName, aPassword,
|
||||
aFlags, &nSessionId);
|
||||
if (hr == S_OK)
|
||||
(*aSession) = (LHANDLE) nSessionId;
|
||||
else
|
||||
return nSessionId;
|
||||
|
||||
return SUCCESS_SUCCESS;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPILogoff (LHANDLE aSession, ULONG aUIParam,
|
||||
FLAGS aFlags, ULONG aReserved)
|
||||
{
|
||||
nsIMapi *pNsMapi = (nsIMapi *)TlsGetValue(tId);
|
||||
if (pNsMapi != NULL)
|
||||
{
|
||||
if (pNsMapi->Logoff((ULONG) aSession) == S_OK)
|
||||
pNsMapi->Release();
|
||||
pNsMapi = NULL;
|
||||
}
|
||||
|
||||
TlsSetValue(tId, NULL);
|
||||
|
||||
::CoUninitialize();
|
||||
|
||||
return SUCCESS_SUCCESS;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPISendMail (LHANDLE lhSession, ULONG ulUIParam, lpnsMapiMessage lpMessage,
|
||||
FLAGS flFlags, ULONG ulReserved )
|
||||
{
|
||||
HRESULT hr = 0;
|
||||
BOOL bTempSession = FALSE ;
|
||||
nsIMapi *pNsMapi = NULL;
|
||||
|
||||
if (!InitMozillaReference(&pNsMapi))
|
||||
return MAPI_E_FAILURE;
|
||||
|
||||
if (lpMessage->nRecipCount > MAX_RECIPS)
|
||||
return MAPI_E_TOO_MANY_RECIPIENTS ;
|
||||
|
||||
if (lpMessage->nFileCount > MAX_FILES)
|
||||
return MAPI_E_TOO_MANY_FILES ;
|
||||
|
||||
if ( (!(flFlags & MAPI_DIALOG)) && (lpMessage->lpRecips == NULL) )
|
||||
return MAPI_E_UNKNOWN_RECIPIENT ;
|
||||
|
||||
if (!lhSession || pNsMapi->IsValidSession(lhSession) != S_OK)
|
||||
{
|
||||
FLAGS LoginFlag ;
|
||||
if ( (flFlags & MAPI_LOGON_UI) && (flFlags & MAPI_NEW_SESSION) )
|
||||
LoginFlag = MAPI_LOGON_UI | MAPI_NEW_SESSION ;
|
||||
else if (flFlags & MAPI_LOGON_UI)
|
||||
LoginFlag = MAPI_LOGON_UI ;
|
||||
|
||||
hr = MAPILogon (ulUIParam, (LPTSTR) NULL, (LPTSTR) NULL, LoginFlag, 0, &lhSession) ;
|
||||
if (hr != SUCCESS_SUCCESS)
|
||||
return MAPI_E_LOGIN_FAILURE ;
|
||||
bTempSession = TRUE ;
|
||||
}
|
||||
|
||||
// we need to deal with null data passed in by MAPI clients, specially when MAPI_DIALOG is set.
|
||||
// The MS COM type lib code generated by MIDL for the MS COM interfaces checks for these parameters
|
||||
// to be non null, although null is a valid value for them here.
|
||||
nsMapiRecipDesc * lpRecips ;
|
||||
nsMapiFileDesc * lpFiles ;
|
||||
|
||||
nsMapiMessage Message ;
|
||||
memset (&Message, 0, sizeof (nsMapiMessage) ) ;
|
||||
nsMapiRecipDesc Recipient ;
|
||||
memset (&Recipient, 0, sizeof (nsMapiRecipDesc) );
|
||||
nsMapiFileDesc Files ;
|
||||
memset (&Files, 0, sizeof (nsMapiFileDesc) ) ;
|
||||
|
||||
if(!lpMessage)
|
||||
{
|
||||
lpMessage = &Message ;
|
||||
}
|
||||
if(!lpMessage->lpRecips)
|
||||
{
|
||||
lpRecips = &Recipient ;
|
||||
}
|
||||
else
|
||||
lpRecips = lpMessage->lpRecips ;
|
||||
if(!lpMessage->lpFiles)
|
||||
{
|
||||
lpFiles = &Files ;
|
||||
}
|
||||
else
|
||||
lpFiles = lpMessage->lpFiles ;
|
||||
|
||||
hr = pNsMapi->SendMail (lhSession, lpMessage,
|
||||
(short) lpMessage->nRecipCount, lpRecips,
|
||||
(short) lpMessage->nFileCount, lpFiles,
|
||||
flFlags, ulReserved);
|
||||
|
||||
if (bTempSession)
|
||||
MAPILogoff (lhSession, ulUIParam, 0,0) ;
|
||||
|
||||
// we are seeing a problem when using Word, although we return success from the MAPI support
|
||||
// MS COM interface in mozilla, we are getting this error here. This is a temporary hack !!
|
||||
if (hr == 0x800703e6)
|
||||
return SUCCESS_SUCCESS;
|
||||
|
||||
return hr ;
|
||||
}
|
||||
|
||||
|
||||
ULONG FAR PASCAL MAPISendDocuments(ULONG ulUIParam, LPTSTR lpszDelimChar, LPTSTR lpszFilePaths,
|
||||
LPTSTR lpszFileNames, ULONG ulReserved)
|
||||
{
|
||||
LHANDLE lhSession ;
|
||||
nsIMapi *pNsMapi = NULL;
|
||||
|
||||
if (!InitMozillaReference(&pNsMapi))
|
||||
return MAPI_E_FAILURE;
|
||||
|
||||
unsigned long result = MAPILogon (ulUIParam, (LPTSTR) NULL, (LPTSTR) NULL, MAPI_LOGON_UI, 0, &lhSession) ;
|
||||
if (result != SUCCESS_SUCCESS)
|
||||
return MAPI_E_LOGIN_FAILURE ;
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
hr = pNsMapi->SendDocuments(lhSession, (LPTSTR) lpszDelimChar, (LPTSTR) lpszFilePaths,
|
||||
(LPTSTR) lpszFileNames, ulReserved) ;
|
||||
|
||||
MAPILogoff (lhSession, ulUIParam, 0,0) ;
|
||||
|
||||
return hr ;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIFindNext(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageType,
|
||||
LPTSTR lpszSeedMessageID, FLAGS flFlags, ULONG ulReserved,
|
||||
LPTSTR lpszMessageID)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIReadMail(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID,
|
||||
FLAGS flFlags, ULONG ulReserved, lpMapiMessage FAR *lppMessage)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPISaveMail(LHANDLE lhSession, ULONG ulUIParam, lpMapiMessage lpMessage,
|
||||
FLAGS flFlags, ULONG ulReserved, LPTSTR lpszMessageID)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIDeleteMail(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID,
|
||||
FLAGS flFlags, ULONG ulReserved)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIAddress(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszCaption,
|
||||
ULONG nEditFields, LPTSTR lpszLabels, ULONG nRecips,
|
||||
lpMapiRecipDesc lpRecips, FLAGS flFlags,
|
||||
ULONG ulReserved, LPULONG lpnNewRecips,
|
||||
lpMapiRecipDesc FAR *lppNewRecips)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIDetails(LHANDLE lhSession, ULONG ulUIParam, lpMapiRecipDesc lpRecip,
|
||||
FLAGS flFlags, ULONG ulReserved)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIResolveName(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszName,
|
||||
FLAGS flFlags, ULONG ulReserved, lpMapiRecipDesc FAR *lppRecip)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIFreeBuffer(LPVOID pv)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL GetMapiDllVersion()
|
||||
{
|
||||
return 94;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
@@ -12,14 +11,14 @@
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
# The Original Code is Mozilla.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1994-2000
|
||||
# Netscape Communications Corp.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2001
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -33,31 +32,30 @@
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
CORE_DEPTH = ../../..
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
MODULE = nss
|
||||
DEPTH=..\..\..
|
||||
|
||||
LIBRARY_NAME = sqlite
|
||||
LIBRARY_VERSION = 3
|
||||
MAPFILE = $(OBJDIR)/sqlite.def
|
||||
DEFINES += -DTHREADSAFE=1
|
||||
MODULE = mozMapi32
|
||||
EXPORT_LIBRARY = $(MODULE)
|
||||
LIBRARY_NAME = $(MODULE)
|
||||
DEFFILE = Mapi32.def
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
REQUIRES = MapiProxy \
|
||||
msgMapi \
|
||||
xpcom \
|
||||
string \
|
||||
$(NULL)
|
||||
|
||||
PRIVATE_EXPORTS = \
|
||||
sqlite3.h \
|
||||
$(NULL)
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
###############################################################
|
||||
|
||||
LCFLAGS=-DUNICODE -D_UNICODE
|
||||
|
||||
|
||||
CSRCS = \
|
||||
sqlite3.c \
|
||||
$(NULL)
|
||||
OBJS= .\$(OBJDIR)\MapiDll.obj
|
||||
|
||||
WIN_LIBS= ole32.lib
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
# only add module debugging in opt builds if DEBUG_PKCS11 is set
|
||||
ifdef DEBUG_PKCS11
|
||||
DEFINES += -DDEBUG_MODULE
|
||||
endif
|
||||
26
mozilla/mailnews/mapi/mapihook/makefile.win
Normal file
26
mozilla/mailnews/mapi/mapihook/makefile.win
Normal file
@@ -0,0 +1,26 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s): kkhandrika@netscape.com
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
DIRS= build public src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
@@ -11,14 +11,15 @@
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Krishna Mohan Khandrika <kkhandrika@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -34,23 +35,30 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* Library identity and versioning */
|
||||
#include "nsISupports.idl"
|
||||
|
||||
#include "softkver.h"
|
||||
|
||||
#if defined(DEBUG)
|
||||
#define _DEBUG_STRING " (debug)"
|
||||
#else
|
||||
#define _DEBUG_STRING ""
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Version information for the 'ident' and 'what commands
|
||||
*
|
||||
* NOTE: the first component of the concatenated rcsid string
|
||||
* must not end in a '$' to prevent rcs keyword substitution.
|
||||
/**
|
||||
* This interface provides support for registering Mozilla as a COM component
|
||||
* for extending the use of Mail/News through Simple MAPI.
|
||||
*
|
||||
*/
|
||||
const char __nss_softokn_rcsid[] = "$Header: NSS " SOFTOKEN_VERSION _DEBUG_STRING
|
||||
" " __DATE__ " " __TIME__ " $";
|
||||
const char __nss_softokn_sccsid[] = "@(#)NSS " SOFTOKEN_VERSION _DEBUG_STRING
|
||||
" " __DATE__ " " __TIME__;
|
||||
|
||||
[noscript, uuid(8967fed2-c8bb-11d5-a3e9-00b0d0f3baa7)]
|
||||
interface nsIMapiSupport : nsISupports {
|
||||
|
||||
/** Initiates MAPI support
|
||||
*/
|
||||
|
||||
void initializeMAPISupport();
|
||||
|
||||
/** Shuts down the MAPI support
|
||||
*/
|
||||
|
||||
void shutdownMAPISupport();
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_IMAPISUPPORT_CONTRACTID "@mozilla.org/mapisupport;1"
|
||||
#define NS_IMAPISUPPORT_CLASSNAME "Mozilla MAPI Support"
|
||||
%}
|
||||
|
||||
174
mozilla/mailnews/mapi/mapihook/src/nsMapiSupport.cpp
Normal file
174
mozilla/mailnews/mapi/mapihook/src/nsMapiSupport.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsComPtr.h"
|
||||
#include "nsMapiSupport.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsMapiRegistry.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIAppStartupNotifier.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsICategoryManager.h"
|
||||
|
||||
const CLSID CLSID_nsMapiImp = {0x29f458be, 0x8866, 0x11d5, \
|
||||
{0xa3, 0xdd, 0x0, 0xb0, 0xd0, 0xf3, 0xba, 0xa7}};
|
||||
|
||||
/** Implementation of the nsIMapiSupport interface.
|
||||
* Use standard implementation of nsISupports stuff.
|
||||
*/
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(nsMapiSupport, nsIMapiSupport, nsIObserver);
|
||||
|
||||
static NS_METHOD nsMapiRegistrationProc(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath, const char *registryLocation, const char *componentType,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsICategoryManager> categoryManager(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = categoryManager->AddCategoryEntry(APPSTARTUP_CATEGORY, "Mapi Support",
|
||||
"service," NS_IMAPISUPPORT_CONTRACTID, PR_TRUE, PR_TRUE, nsnull);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMapiSupport::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
|
||||
{
|
||||
if (!nsCRT::strcmp(aTopic, "profile-after-change"))
|
||||
return InitializeMAPISupport();
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
|
||||
return ShutdownMAPISupport();
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1", &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = observerService->AddObserver(this,"profile-after-change", PR_FALSE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsMapiSupport::nsMapiSupport()
|
||||
: m_dwRegister(0),
|
||||
m_nsMapiFactory(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsMapiSupport::~nsMapiSupport()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMapiSupport::InitializeMAPISupport()
|
||||
{
|
||||
::CoInitialize(nsnull);
|
||||
if (m_nsMapiFactory == nsnull) // No Registering if already done. Sanity Check!!
|
||||
{
|
||||
m_nsMapiFactory = new nsMapiFactory();
|
||||
|
||||
if (m_nsMapiFactory != nsnull)
|
||||
{
|
||||
HRESULT hr = ::CoRegisterClassObject(CLSID_nsMapiImp, \
|
||||
m_nsMapiFactory, \
|
||||
CLSCTX_LOCAL_SERVER, \
|
||||
REGCLS_MULTIPLEUSE, \
|
||||
&m_dwRegister);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
m_nsMapiFactory->Release() ;
|
||||
m_nsMapiFactory = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMapiSupport::ShutdownMAPISupport()
|
||||
{
|
||||
if (m_dwRegister != 0)
|
||||
::CoRevokeClassObject(m_dwRegister);
|
||||
|
||||
if (m_nsMapiFactory != nsnull)
|
||||
{
|
||||
m_nsMapiFactory->Release();
|
||||
m_nsMapiFactory = nsnull;
|
||||
}
|
||||
|
||||
::CoUninitialize();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMapiRegistry);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMapiSupport);
|
||||
|
||||
// The list of components we register
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{
|
||||
NS_IMAPIREGISTRY_CLASSNAME,
|
||||
NS_IMAPIREGISTRY_CID,
|
||||
NS_IMAPIREGISTRY_CONTRACTID,
|
||||
nsMapiRegistryConstructor
|
||||
},
|
||||
|
||||
{
|
||||
NS_IMAPISUPPORT_CLASSNAME,
|
||||
NS_IMAPISUPPORT_CID,
|
||||
NS_IMAPISUPPORT_CONTRACTID,
|
||||
nsMapiSupportConstructor,
|
||||
nsMapiRegistrationProc,
|
||||
nsnull
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(msgMapiModule, components);
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
* The Original Code is Mozilla
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Red Hat, Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -33,20 +34,34 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _PKCS11NI_H_
|
||||
#define _PKCS11NI_H_
|
||||
#ifndef NS_MAPI_SUPPORT_H_
|
||||
#define NS_MAPI_SUPPORT_H_
|
||||
|
||||
/*
|
||||
* pkcs11ni.h
|
||||
*
|
||||
* This file contains softoken private exports for NSS
|
||||
*/
|
||||
|
||||
/* softoken slot ID's */
|
||||
#define SFTK_MIN_USER_SLOT_ID 4
|
||||
#define SFTK_MAX_USER_SLOT_ID 100
|
||||
#define SFTK_MIN_FIPS_USER_SLOT_ID 101
|
||||
#define SFTK_MAX_FIPS_USER_SLOT_ID 127
|
||||
#include <nsIObserver.h>
|
||||
#include <nsIMapiSupport.h>
|
||||
#include "msgMapiFactory.h"
|
||||
|
||||
|
||||
#endif /* _PKCS11NI_H_ */
|
||||
#define NS_IMAPISUPPORT_CID \
|
||||
{0x8967fed2, 0xc8bb, 0x11d5, \
|
||||
{ 0xa3, 0xe9, 0x00, 0xb0, 0xd0, 0xf3, 0xba, 0xa7 }}
|
||||
|
||||
class nsMapiSupport : public nsIMapiSupport, public nsIObserver
|
||||
{
|
||||
public :
|
||||
|
||||
nsMapiSupport();
|
||||
~nsMapiSupport();
|
||||
|
||||
// Declare all interface methods we must implement.
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSIMAPISUPPORT
|
||||
|
||||
private :
|
||||
|
||||
DWORD m_dwRegister;
|
||||
nsMapiFactory *m_nsMapiFactory;
|
||||
};
|
||||
|
||||
#endif // NS_MAPI_SUPPORT_H_
|
||||
64
mozilla/mailnews/mapi/old/hook/makefile.win
Normal file
64
mozilla/mailnews/mapi/old/hook/makefile.win
Normal file
@@ -0,0 +1,64 @@
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH=..\..\..
|
||||
MODULE=mapiguts
|
||||
|
||||
################################################################################
|
||||
## exports
|
||||
|
||||
#EXPORTS =
|
||||
|
||||
|
||||
################################################################################
|
||||
## library
|
||||
|
||||
LIBNAME = .\$(OBJDIR)\mapiguts
|
||||
|
||||
!ifdef MOZ_STATIC_COMPONENT_LIBS
|
||||
LIB = $(LIBNAME).lib
|
||||
!else
|
||||
DLL = $(LIBNAME).dll
|
||||
!endif
|
||||
|
||||
DEFINES= -NS_DEBUG
|
||||
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\mapihook.obj \
|
||||
.\$(OBJDIR)\mapimail.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= \
|
||||
$(LLIBS) \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\xppref32.lib \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\mapiutils_s.lib \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
!ifdef MOZ_STATIC_COMPONENT_LIBS
|
||||
install:: $(LIb)
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\bin\components
|
||||
!else
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin\components
|
||||
!endif
|
||||
1579
mozilla/mailnews/mapi/old/hook/mapihook.cpp
Normal file
1579
mozilla/mailnews/mapi/old/hook/mapihook.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,52 +1,48 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1994-2000
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* Copyright (C) 1994-1999 RSA Security Inc. Licence to copy this document
|
||||
* is granted provided that it is identified as "RSA Security Inc. Public-Key
|
||||
* Cryptography Standards (PKCS)" in all material mentioning or referencing
|
||||
* this document.
|
||||
*/
|
||||
/*
|
||||
* reset any packing set by pkcs11p.h
|
||||
*/
|
||||
#ifndef _MAPI_HOOK_H_
|
||||
#define _MAPI_HOOK_H_
|
||||
|
||||
#if defined (_WIN32)
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4103)
|
||||
#endif
|
||||
#pragma pack(pop, cryptoki)
|
||||
#endif
|
||||
#include <structs.h> // for MWContext
|
||||
|
||||
//
|
||||
// This is the entry point to the MAPI session manager that lives
|
||||
// inside of Communicator.
|
||||
//
|
||||
LONG ProcessNetscapeMAPIHook(WPARAM wParam, LPARAM lParam);
|
||||
|
||||
#endif // _MAPI_HOOK_H_
|
||||
853
mozilla/mailnews/mapi/old/hook/mapimail.cpp
Normal file
853
mozilla/mailnews/mapi/old/hook/mapimail.cpp
Normal file
@@ -0,0 +1,853 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// More MAPI Hooks for Communicator
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
//
|
||||
#include "windows.h"
|
||||
#include "template.h"
|
||||
#include "msgcom.h"
|
||||
#include "wfemsg.h"
|
||||
#include "compstd.h"
|
||||
#include "compbar.h"
|
||||
#include "compmisc.h"
|
||||
#include "compfrm.h"
|
||||
#include "prefapi.h"
|
||||
#include "intl_csi.h"
|
||||
#include "dlghtmrp.h"
|
||||
#include "dlghtmmq.h"
|
||||
|
||||
// rhp - was breaking the optimized build!
|
||||
//#include "edt.h"
|
||||
//#include "edview.h"
|
||||
//#include "postal.h"
|
||||
//#include "apiaddr.h"
|
||||
//#include "mailmisc.h"
|
||||
|
||||
extern "C" {
|
||||
#include "xpgetstr.h"
|
||||
extern int MK_MSG_MSG_COMPOSITION;
|
||||
};
|
||||
|
||||
#include "mapimail.h"
|
||||
#include "nscpmapi.h"
|
||||
#include "mailpriv.h"
|
||||
#include "nsstrseq.h"
|
||||
|
||||
MWContext
|
||||
*GetUsableContext(void)
|
||||
{
|
||||
CGenericFrame *pFrame = (CGenericFrame * )FEU_GetLastActiveFrame();
|
||||
|
||||
ASSERT(pFrame != NULL);
|
||||
if (pFrame == NULL)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// Now return the context...
|
||||
return((MWContext *) pFrame->GetMainContext());
|
||||
}
|
||||
|
||||
//
|
||||
// This function will create a composition window and either do
|
||||
// a blind send or pop up the compose window for the user to
|
||||
// complete the operation
|
||||
//
|
||||
// Return: appropriate MAPI return code...
|
||||
//
|
||||
//
|
||||
extern "C" LONG
|
||||
DoFullMAPIMailOperation(MAPISendMailType *sendMailPtr,
|
||||
const char *pInitialText,
|
||||
BOOL winShowFlag)
|
||||
{
|
||||
CGenericDoc *pDocument;
|
||||
LPSTR subject;
|
||||
NSstringSeq mailInfoSeq;
|
||||
DWORD stringCount = 6;
|
||||
DWORD i;
|
||||
CString csDefault;
|
||||
|
||||
// Get a context to use for this call...
|
||||
MWContext *pOldContext = GetUsableContext();
|
||||
if (!pOldContext)
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
// Don't allow a compose window to be created if the user hasn't
|
||||
// specified an email address
|
||||
const char *real_addr = FE_UsersMailAddress();
|
||||
if (MISC_ValidateReturnAddress(pOldContext, real_addr) < 0)
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
//
|
||||
// Now, we must build the fields object...
|
||||
//
|
||||
mailInfoSeq = (NSstringSeq) &(sendMailPtr->dataBuf[0]);
|
||||
subject = NSStrSeqGet(mailInfoSeq, 0);
|
||||
|
||||
// We should give it a subject to preven the prompt from coming
|
||||
// up...
|
||||
if ((!subject) || !(*subject))
|
||||
{
|
||||
csDefault.LoadString(IDS_COMPOSE_DEFAULTNOSUBJECT);
|
||||
subject = csDefault.GetBuffer(2);
|
||||
}
|
||||
|
||||
TRACE("MAPI: ProcessMAPISendMail() Subject = [%s]\n", subject);
|
||||
TRACE("MAPI: ProcessMAPISendMail() Text Size = [%d]\n", strlen((const char *)pInitialText));
|
||||
TRACE("MAPI: ProcessMAPISendMail() # of Recipients = [%d]\n", sendMailPtr->MSG_nRecipCount);
|
||||
|
||||
|
||||
char toString[1024] = "";
|
||||
char ccString[1024] = "";
|
||||
char bccString[1024] = "";
|
||||
|
||||
for (i=0; i<sendMailPtr->MSG_nRecipCount; i++)
|
||||
{
|
||||
LPSTR ptr;
|
||||
UCHAR tempString[256];
|
||||
|
||||
ULONG addrType = atoi(NSStrSeqGet(mailInfoSeq, stringCount++));
|
||||
|
||||
// figure which type of address this is?
|
||||
if (addrType == MAPI_CC)
|
||||
ptr = ccString;
|
||||
else if (addrType == MAPI_BCC)
|
||||
ptr = bccString;
|
||||
else
|
||||
ptr = toString;
|
||||
|
||||
LPSTR namePtr = (LPSTR) NSStrSeqGet(mailInfoSeq, stringCount++);
|
||||
LPSTR emailPtr = (LPSTR) NSStrSeqGet(mailInfoSeq, stringCount++);
|
||||
if ( (lstrlen(emailPtr) > 5) && (*(emailPtr + 4) == ':') )
|
||||
{
|
||||
emailPtr += 5;
|
||||
}
|
||||
|
||||
// Now build the temp string to tack on in the format
|
||||
// "Rich Pizzarro" <rhp@netscape.com>
|
||||
wsprintf((LPSTR) tempString, "\"%s\" <%s>", namePtr, emailPtr);
|
||||
|
||||
// add a comma if not the first one
|
||||
if (ptr[0] != '\0')
|
||||
lstrcat(ptr, ",");
|
||||
|
||||
// tack on string!
|
||||
lstrcat(ptr, (LPSTR) tempString);
|
||||
}
|
||||
|
||||
BOOL bEncrypt = FALSE;
|
||||
BOOL bSign = FALSE;
|
||||
|
||||
PREF_GetBoolPref("mail.crypto_sign_outgoing_mail", &bSign);
|
||||
PREF_GetBoolPref("mail.encrypt_outgoing_mail", &bEncrypt);
|
||||
MSG_CompositionFields *fields =
|
||||
MSG_CreateCompositionFields(real_addr, real_addr,
|
||||
toString,
|
||||
ccString,
|
||||
bccString,
|
||||
"", "", "",
|
||||
"", subject, "",
|
||||
"", "", "",
|
||||
"",
|
||||
bEncrypt,
|
||||
bSign);
|
||||
if (!fields)
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
// RICHIE
|
||||
// INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(pOldContext);
|
||||
// int16 win_csid = INTL_GetCSIWinCSID(csi);
|
||||
|
||||
pDocument = (CGenericDoc*)theApp.m_TextComposeTemplate->OpenDocumentFile(NULL, NULL, /*win_csid RICHIE*/ winShowFlag);
|
||||
if ( !pDocument )
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
CWinCX * pContext = (CWinCX*) pDocument->GetContext();
|
||||
if ( !pContext )
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
MSG_CompositionPaneCallbacks Callbacks;
|
||||
Callbacks.CreateRecipientsDialog = CreateRecipientsDialog;
|
||||
Callbacks.CreateAskHTMLDialog = CreateAskHTMLDialog;
|
||||
|
||||
int16 doccsid;
|
||||
MWContext *context = pContext->GetContext();
|
||||
CComposeFrame *pCompose = (CComposeFrame *) pContext->GetFrame()->GetFrameWnd();
|
||||
|
||||
pCompose->SetComposeStuff(context, fields); // squirl away stuff for post-create
|
||||
|
||||
// This needs to be set TRUE if using the old non-HTML text frame
|
||||
// to prevent dropping dragged URLs
|
||||
pContext->m_bDragging = !pCompose->UseHtml();
|
||||
if (!pCompose->UseHtml())
|
||||
{
|
||||
pCompose->SetMsgPane(
|
||||
MSG_CreateCompositionPane(pContext->GetContext(),
|
||||
context,
|
||||
g_MsgPrefs.m_pMsgPrefs,
|
||||
fields,
|
||||
WFE_MSGGetMaster())
|
||||
);
|
||||
}
|
||||
|
||||
ASSERT(pCompose->GetMsgPane());
|
||||
MSG_SetFEData(pCompose->GetMsgPane(),(void *)pCompose);
|
||||
pCompose->UpdateAttachmentInfo();
|
||||
|
||||
// Pass doccsid info to new context for MailToWin conversion
|
||||
doccsid = INTL_GetCSIDocCSID(LO_GetDocumentCharacterSetInfo(context));
|
||||
INTL_SetCSIDocCSID(LO_GetDocumentCharacterSetInfo(context),
|
||||
(doccsid ? doccsid : INTL_DefaultDocCharSetID(context)));
|
||||
|
||||
pCompose->DisplayHeaders(NULL);
|
||||
|
||||
CComposeBar * pBar = pCompose->GetComposeBar();
|
||||
ASSERT(pBar);
|
||||
LPADDRESSCONTROL pIAddressList = pBar->GetAddressWidgetInterface();
|
||||
|
||||
if (!pIAddressList->IsCreated())
|
||||
{
|
||||
pBar->CreateAddressingBlock();
|
||||
}
|
||||
|
||||
// rhp - Deal with addressing the brute force way! This is a
|
||||
// "fix" for bad behavior when creating these windows and not
|
||||
// showing them on the desktop.
|
||||
if (!winShowFlag) // Hack to fix the window not being mapped
|
||||
{
|
||||
pCompose->AppendAddress(MSG_TO_HEADER_MASK, "");
|
||||
pCompose->AppendAddress(MSG_CC_HEADER_MASK, "");
|
||||
pCompose->AppendAddress(MSG_BCC_HEADER_MASK, "");
|
||||
}
|
||||
|
||||
// Always do plain text composition!
|
||||
pCompose->CompleteComposeInitialization();
|
||||
|
||||
// Do this so we don't get popups on "empty" messages
|
||||
if ( (!pInitialText) || (!(*pInitialText)) )
|
||||
pInitialText = " ";
|
||||
|
||||
const char * pBody = pInitialText ? pInitialText : MSG_GetCompBody(pCompose->GetMsgPane());
|
||||
if (pBody)
|
||||
{
|
||||
FE_InsertMessageCompositionText(context,pBody,TRUE);
|
||||
}
|
||||
|
||||
//
|
||||
// Now set the message as being edited!
|
||||
//
|
||||
pCompose->SetModified(TRUE);
|
||||
|
||||
//
|
||||
// Finally deal with the attachments...
|
||||
//
|
||||
if (sendMailPtr->MSG_nFileCount > 0)
|
||||
{
|
||||
// Send this puppy when done with the attachments...
|
||||
if (!winShowFlag)
|
||||
{
|
||||
pCompose->SetMAPISendMode(MAPI_SEND);
|
||||
}
|
||||
|
||||
MSG_AttachmentData *pAttach = (MSG_AttachmentData *)
|
||||
XP_CALLOC((sendMailPtr->MSG_nFileCount + 1),
|
||||
sizeof(MSG_AttachmentData));
|
||||
if (!pAttach)
|
||||
{
|
||||
return(MAPI_E_INSUFFICIENT_MEMORY);
|
||||
}
|
||||
|
||||
memset(pAttach, 0, (sendMailPtr->MSG_nFileCount + 1) *
|
||||
sizeof(MSG_AttachmentData));
|
||||
for (i=0; i<sendMailPtr->MSG_nFileCount; i++)
|
||||
{
|
||||
CString cs;
|
||||
// Create URL from filename...
|
||||
WFE_ConvertFile2Url(cs,
|
||||
(const char *)NSStrSeqGet(mailInfoSeq, stringCount++));
|
||||
pAttach[i].url = XP_STRDUP(cs);
|
||||
|
||||
// Now also include the "display" name...
|
||||
StrAllocCopy(pAttach[i].real_name, NSStrSeqGet(mailInfoSeq, stringCount++));
|
||||
}
|
||||
|
||||
// Set the list!
|
||||
MSG_SetAttachmentList(pCompose->GetMsgPane(), pAttach);
|
||||
|
||||
// Now free everything...
|
||||
for (i=0; i<sendMailPtr->MSG_nFileCount; i++)
|
||||
{
|
||||
if (pAttach[i].url)
|
||||
XP_FREE(pAttach[i].url);
|
||||
|
||||
if (pAttach[i].real_name)
|
||||
XP_FREE(pAttach[i].real_name);
|
||||
}
|
||||
|
||||
XP_FREE(pAttach);
|
||||
}
|
||||
|
||||
//
|
||||
// Now, if we were supposed to do the blind send...do it, otherwise,
|
||||
// just popup the window...
|
||||
//
|
||||
if (winShowFlag)
|
||||
{
|
||||
// Post message to compose window to set the initial focus.
|
||||
pCompose->PostMessage(WM_COMP_SET_INITIAL_FOCUS);
|
||||
}
|
||||
else if (sendMailPtr->MSG_nFileCount <= 0) // Send NOW if no attachments!
|
||||
{
|
||||
pCompose->PostMessage(WM_COMMAND, IDM_SEND);
|
||||
}
|
||||
|
||||
return(SUCCESS_SUCCESS);
|
||||
}
|
||||
|
||||
//
|
||||
// This function will create a composition window and just attach
|
||||
// the attachments of interest and pop up the window...
|
||||
//
|
||||
// Return: appropriate MAPI return code...
|
||||
//
|
||||
//
|
||||
extern "C" LONG
|
||||
DoPartialMAPIMailOperation(MAPISendDocumentsType *sendDocPtr)
|
||||
{
|
||||
CGenericDoc *pDocument;
|
||||
|
||||
// Get a context to use for this call...
|
||||
MWContext *pOldContext = GetUsableContext();
|
||||
if (!pOldContext)
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
// Don't allow a compose window to be created if the user hasn't
|
||||
// specified an email address
|
||||
const char *real_addr = FE_UsersMailAddress();
|
||||
if (MISC_ValidateReturnAddress(pOldContext, real_addr) < 0)
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
//
|
||||
// Now, build the fields object w/o much info...
|
||||
//
|
||||
BOOL bEncrypt = FALSE;
|
||||
BOOL bSign = FALSE;
|
||||
|
||||
PREF_GetBoolPref("mail.crypto_sign_outgoing_mail", &bSign);
|
||||
PREF_GetBoolPref("mail.encrypt_outgoing_mail", &bEncrypt);
|
||||
|
||||
MSG_CompositionFields *fields =
|
||||
MSG_CreateCompositionFields(real_addr, real_addr, NULL,
|
||||
"", "",
|
||||
"", "", "",
|
||||
"", "", "",
|
||||
"", "", "",
|
||||
"",
|
||||
bEncrypt,
|
||||
bSign);
|
||||
if (!fields)
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
// RICHIE - INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(pOldContext);
|
||||
// int16 win_csid = INTL_GetCSIWinCSID(csi);
|
||||
|
||||
pDocument = (CGenericDoc*)theApp.m_TextComposeTemplate->OpenDocumentFile(NULL, NULL, /*RICHIE win_csid,*/ TRUE);
|
||||
if ( !pDocument )
|
||||
{
|
||||
// cleanup fields object
|
||||
MSG_DestroyCompositionFields(fields);
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
CWinCX * pContext = (CWinCX*) pDocument->GetContext();
|
||||
if ( !pContext )
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
MSG_CompositionPaneCallbacks Callbacks;
|
||||
Callbacks.CreateRecipientsDialog = CreateRecipientsDialog;
|
||||
Callbacks.CreateAskHTMLDialog = CreateAskHTMLDialog;
|
||||
|
||||
MWContext *context = pContext->GetContext();
|
||||
CComposeFrame *pCompose = (CComposeFrame *) pContext->GetFrame()->GetFrameWnd();
|
||||
pCompose->SetComposeStuff(context,fields); // squirl away stuff for post-create
|
||||
|
||||
// This needs to be set TRUE if using the old non-HTML text frame
|
||||
// to prevent dropping dragged URLs
|
||||
pContext->m_bDragging = !pCompose->UseHtml();
|
||||
if (!pCompose->UseHtml())
|
||||
{
|
||||
pCompose->SetMsgPane(MSG_CreateCompositionPane(
|
||||
pContext->GetContext(),
|
||||
context,
|
||||
g_MsgPrefs.m_pMsgPrefs, fields,
|
||||
WFE_MSGGetMaster()));
|
||||
}
|
||||
|
||||
ASSERT(pCompose->GetMsgPane());
|
||||
MSG_SetFEData(pCompose->GetMsgPane(),(void *)pCompose);
|
||||
|
||||
pCompose->UpdateAttachmentInfo();
|
||||
|
||||
// Pass doccsid info to new context for MailToWin conversion
|
||||
/***
|
||||
doccsid = INTL_GetCSIDocCSID(LO_GetDocumentCharacterSetInfo(pOldContext));
|
||||
|
||||
INTL_SetCSIDocCSID(LO_GetDocumentCharacterSetInfo(context),
|
||||
(doccsid ? doccsid : INTL_DefaultDocCharSetID(pOldContext)));
|
||||
****/
|
||||
|
||||
pCompose->DisplayHeaders(NULL);
|
||||
|
||||
CComposeBar * pBar = pCompose->GetComposeBar();
|
||||
ASSERT(pBar);
|
||||
LPADDRESSCONTROL pIAddressList = pBar->GetAddressWidgetInterface();
|
||||
|
||||
if (!pIAddressList->IsCreated())
|
||||
{
|
||||
pBar->CreateAddressingBlock();
|
||||
}
|
||||
|
||||
// Always do plain text composition!
|
||||
pCompose->CompleteComposeInitialization();
|
||||
|
||||
//
|
||||
// Finally deal with the attachments...
|
||||
//
|
||||
NSstringSeq mailInfoSeq = (NSstringSeq) &(sendDocPtr->dataBuf[0]);
|
||||
DWORD stringCount = 0;
|
||||
DWORD i;
|
||||
|
||||
TRACE("MAPI: ProcessMAPISendDocuments() # of Attachments = [%d]\n", sendDocPtr->nFileCount);
|
||||
|
||||
if (sendDocPtr->nFileCount > 0)
|
||||
{
|
||||
MSG_AttachmentData *pAttach = (MSG_AttachmentData *)
|
||||
XP_CALLOC((sendDocPtr->nFileCount + 1),
|
||||
sizeof(MSG_AttachmentData));
|
||||
if (!pAttach)
|
||||
{
|
||||
return(MAPI_E_INSUFFICIENT_MEMORY);
|
||||
}
|
||||
|
||||
memset(pAttach, 0, (sendDocPtr->nFileCount + 1) *
|
||||
sizeof(MSG_AttachmentData));
|
||||
for (i=0; i<sendDocPtr->nFileCount; i++)
|
||||
{
|
||||
CString cs;
|
||||
// Create URL from filename...
|
||||
WFE_ConvertFile2Url(cs,
|
||||
(const char *)NSStrSeqGet(mailInfoSeq, stringCount++));
|
||||
pAttach[i].url = XP_STRDUP(cs);
|
||||
|
||||
// Now also include the "display" name...
|
||||
StrAllocCopy(pAttach[i].real_name, NSStrSeqGet(mailInfoSeq, stringCount++));
|
||||
}
|
||||
|
||||
// Set the list!
|
||||
MSG_SetAttachmentList(pCompose->GetMsgPane(), pAttach);
|
||||
|
||||
// Now free everything...
|
||||
for (i=0; i<sendDocPtr->nFileCount; i++)
|
||||
{
|
||||
if (pAttach[i].url)
|
||||
XP_FREE(pAttach[i].url);
|
||||
|
||||
if (pAttach[i].real_name)
|
||||
XP_FREE(pAttach[i].real_name);
|
||||
}
|
||||
|
||||
XP_FREE(pAttach);
|
||||
}
|
||||
|
||||
//
|
||||
// Now some checking for ... well I'm not sure...
|
||||
//
|
||||
if (MSG_GetAttachmentList(pCompose->GetMsgPane()))
|
||||
pCompose->SetModified(TRUE);
|
||||
else
|
||||
pCompose->SetModified(FALSE);
|
||||
|
||||
// Post message to compose window to set the initial focus.
|
||||
pCompose->PostMessage(WM_COMP_SET_INITIAL_FOCUS);
|
||||
|
||||
//
|
||||
// Now, just popup the window...
|
||||
//
|
||||
pCompose->ShowWindow(TRUE);
|
||||
|
||||
// return pCompose->GetMsgPane(); rhp - used to return the MsgPane
|
||||
return(SUCCESS_SUCCESS);
|
||||
}
|
||||
|
||||
static void _GetMailCallback(HWND hwnd, MSG_Pane *pane, void *closure)
|
||||
{
|
||||
if (pane != NULL)
|
||||
{
|
||||
ShowWindow(hwnd, SW_HIDE);
|
||||
MSG_Command( pane, MSG_GetNewMail, NULL, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
static void _GetMailDoneCallback(HWND hwnd, MSG_Pane *pane, void *closure)
|
||||
{
|
||||
for(CGenericFrame * f = theApp.m_pFrameList; f; f = f->m_pNext)
|
||||
f->PostMessage(WM_COMMAND, (WPARAM) ID_DONEGETTINGMAIL, (LPARAM) 0);
|
||||
}
|
||||
|
||||
//
|
||||
// This will fire off a "get mail in background operation" in an
|
||||
// async. fashion.
|
||||
//
|
||||
extern "C" void
|
||||
MAPIGetNewMessagesInBackground(void)
|
||||
{
|
||||
CGenericFrame *pFrame = (CGenericFrame * )FEU_GetLastActiveFrame();
|
||||
|
||||
// rhp - we should not hit the net if we are offline!
|
||||
if (NET_IsOffline())
|
||||
return;
|
||||
|
||||
if (!pFrame)
|
||||
return;
|
||||
|
||||
MWContext *pOldContext = GetUsableContext();
|
||||
if (!pOldContext)
|
||||
return;
|
||||
|
||||
TRACE("MAPI: DOWNLOAD MAIL IN BACKGROUND\n");
|
||||
new CProgressDialog(
|
||||
pFrame->GetFrameWnd(),
|
||||
NULL,
|
||||
_GetMailCallback, NULL, NULL,
|
||||
_GetMailDoneCallback);
|
||||
}
|
||||
|
||||
//
|
||||
// This function will save a message into the Communicator "Drafts"
|
||||
// folder with no UI showing.
|
||||
//
|
||||
// Return: appropriate MAPI return code...
|
||||
//
|
||||
//
|
||||
extern "C" LONG
|
||||
DoMAPISaveMailOperation(MAPISendMailType *sendMailPtr,
|
||||
const char *pInitialText)
|
||||
{
|
||||
CGenericDoc *pDocument;
|
||||
LPSTR subject;
|
||||
NSstringSeq mailInfoSeq;
|
||||
DWORD stringCount = 6;
|
||||
DWORD i;
|
||||
BOOL winShowFlag = FALSE;
|
||||
|
||||
// Get a context to use for this call...
|
||||
MWContext *pOldContext = GetUsableContext();
|
||||
if (!pOldContext)
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
// Don't allow a compose window to be created if the user hasn't
|
||||
// specified an email address
|
||||
const char *real_addr = FE_UsersMailAddress();
|
||||
if (MISC_ValidateReturnAddress(pOldContext, real_addr) < 0)
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
//
|
||||
// Now, we must build the fields object...
|
||||
//
|
||||
mailInfoSeq = (NSstringSeq) &(sendMailPtr->dataBuf[0]);
|
||||
subject = NSStrSeqGet(mailInfoSeq, 0);
|
||||
|
||||
TRACE("MAPI: ProcessMAPISendMail() Subject = [%s]\n", subject);
|
||||
TRACE("MAPI: ProcessMAPISendMail() Text Size = [%d]\n", strlen((const char *)pInitialText));
|
||||
TRACE("MAPI: ProcessMAPISendMail() # of Recipients = [%d]\n", sendMailPtr->MSG_nRecipCount);
|
||||
|
||||
|
||||
char toString[1024] = "";
|
||||
char ccString[1024] = "";
|
||||
char bccString[1024] = "";
|
||||
|
||||
for (i=0; i<sendMailPtr->MSG_nRecipCount; i++)
|
||||
{
|
||||
LPSTR ptr;
|
||||
UCHAR tempString[256];
|
||||
|
||||
ULONG addrType = atoi(NSStrSeqGet(mailInfoSeq, stringCount++));
|
||||
|
||||
// figure which type of address this is?
|
||||
if (addrType == MAPI_CC)
|
||||
ptr = ccString;
|
||||
else if (addrType == MAPI_BCC)
|
||||
ptr = bccString;
|
||||
else
|
||||
ptr = toString;
|
||||
|
||||
LPSTR namePtr = (LPSTR) NSStrSeqGet(mailInfoSeq, stringCount++);
|
||||
LPSTR emailPtr = (LPSTR) NSStrSeqGet(mailInfoSeq, stringCount++);
|
||||
|
||||
if ( (!emailPtr) && (!namePtr))
|
||||
{
|
||||
return(MAPI_E_INVALID_RECIPS);
|
||||
}
|
||||
|
||||
if (!emailPtr)
|
||||
emailPtr = namePtr;
|
||||
|
||||
char *tptr = strchr(emailPtr, ':');
|
||||
if (tptr != NULL)
|
||||
{
|
||||
if ( (*tptr != '\0') && (*(tptr+1) != '\0') )
|
||||
{
|
||||
emailPtr = (tptr + 1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
if ( (lstrlen(emailPtr) > 5) && (*(emailPtr + 4) == ':') )
|
||||
{
|
||||
emailPtr += 5;
|
||||
}
|
||||
**/
|
||||
// Now build the temp string to tack on in the format
|
||||
// "Rich Pizzarro" <rhp@netscape.com>
|
||||
wsprintf((LPSTR) tempString, "\"%s\" <%s>", namePtr, emailPtr);
|
||||
|
||||
// add a comma if not the first one
|
||||
if (ptr[0] != '\0')
|
||||
lstrcat(ptr, ",");
|
||||
|
||||
// tack on string!
|
||||
lstrcat(ptr, (LPSTR) tempString);
|
||||
}
|
||||
|
||||
BOOL bEncrypt = FALSE;
|
||||
BOOL bSign = FALSE;
|
||||
|
||||
PREF_GetBoolPref("mail.crypto_sign_outgoing_mail", &bSign);
|
||||
PREF_GetBoolPref("mail.encrypt_outgoing_mail", &bEncrypt);
|
||||
MSG_CompositionFields *fields =
|
||||
MSG_CreateCompositionFields(real_addr, real_addr,
|
||||
toString,
|
||||
ccString,
|
||||
bccString,
|
||||
"", "", "",
|
||||
"", subject, "",
|
||||
"", "", "",
|
||||
"",
|
||||
bEncrypt,
|
||||
bSign);
|
||||
if (!fields)
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
// RICHIE
|
||||
// INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(pOldContext);
|
||||
// int16 win_csid = INTL_GetCSIWinCSID(csi);
|
||||
|
||||
pDocument = (CGenericDoc*)theApp.m_TextComposeTemplate->OpenDocumentFile(NULL, NULL, /*win_csid RICHIE*/ winShowFlag);
|
||||
if ( !pDocument )
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
CWinCX * pContext = (CWinCX*) pDocument->GetContext();
|
||||
if ( !pContext )
|
||||
{
|
||||
return(MAPI_E_FAILURE);
|
||||
}
|
||||
|
||||
MSG_CompositionPaneCallbacks Callbacks;
|
||||
Callbacks.CreateRecipientsDialog = CreateRecipientsDialog;
|
||||
Callbacks.CreateAskHTMLDialog = CreateAskHTMLDialog;
|
||||
|
||||
int16 doccsid;
|
||||
MWContext *context = pContext->GetContext();
|
||||
CComposeFrame *pCompose = (CComposeFrame *) pContext->GetFrame()->GetFrameWnd();
|
||||
|
||||
pCompose->SetComposeStuff(context, fields); // squirl away stuff for post-create
|
||||
|
||||
// This needs to be set TRUE if using the old non-HTML text frame
|
||||
// to prevent dropping dragged URLs
|
||||
pContext->m_bDragging = !pCompose->UseHtml();
|
||||
if (!pCompose->UseHtml())
|
||||
{
|
||||
pCompose->SetMsgPane(
|
||||
MSG_CreateCompositionPane(pContext->GetContext(),
|
||||
context,
|
||||
g_MsgPrefs.m_pMsgPrefs,
|
||||
fields,
|
||||
WFE_MSGGetMaster())
|
||||
);
|
||||
}
|
||||
|
||||
ASSERT(pCompose->GetMsgPane());
|
||||
MSG_SetFEData(pCompose->GetMsgPane(),(void *)pCompose);
|
||||
pCompose->UpdateAttachmentInfo();
|
||||
|
||||
// Pass doccsid info to new context for MailToWin conversion
|
||||
doccsid = INTL_GetCSIDocCSID(LO_GetDocumentCharacterSetInfo(context));
|
||||
INTL_SetCSIDocCSID(LO_GetDocumentCharacterSetInfo(context),
|
||||
(doccsid ? doccsid : INTL_DefaultDocCharSetID(context)));
|
||||
|
||||
pCompose->DisplayHeaders(NULL);
|
||||
|
||||
CComposeBar * pBar = pCompose->GetComposeBar();
|
||||
ASSERT(pBar);
|
||||
LPADDRESSCONTROL pIAddressList = pBar->GetAddressWidgetInterface();
|
||||
|
||||
if (!pIAddressList->IsCreated())
|
||||
{
|
||||
pBar->CreateAddressingBlock();
|
||||
}
|
||||
|
||||
// rhp - Deal with addressing the brute force way! This is a
|
||||
// "fix" for bad behavior when creating these windows and not
|
||||
// showing them on the desktop.
|
||||
if (!winShowFlag) // Hack to fix the window not being mapped
|
||||
{
|
||||
pCompose->AppendAddress(MSG_TO_HEADER_MASK, "");
|
||||
pCompose->AppendAddress(MSG_CC_HEADER_MASK, "");
|
||||
pCompose->AppendAddress(MSG_BCC_HEADER_MASK, "");
|
||||
}
|
||||
|
||||
// Always do plain text composition!
|
||||
pCompose->CompleteComposeInitialization();
|
||||
|
||||
// Do this so we don't get popups on "empty" messages
|
||||
if ( (!pInitialText) || (!(*pInitialText)) )
|
||||
pInitialText = " ";
|
||||
|
||||
const char * pBody = pInitialText ? pInitialText : MSG_GetCompBody(pCompose->GetMsgPane());
|
||||
if (pBody)
|
||||
{
|
||||
FE_InsertMessageCompositionText(context,pBody,TRUE);
|
||||
}
|
||||
|
||||
//
|
||||
// Now set the message as being edited!
|
||||
//
|
||||
pCompose->SetModified(TRUE);
|
||||
|
||||
//
|
||||
// Finally deal with the attachments...
|
||||
//
|
||||
if (sendMailPtr->MSG_nFileCount > 0)
|
||||
{
|
||||
// Send this puppy when done with the attachments...
|
||||
if (!winShowFlag)
|
||||
{
|
||||
pCompose->SetMAPISendMode(MAPI_SAVE);
|
||||
}
|
||||
|
||||
MSG_AttachmentData *pAttach = (MSG_AttachmentData *)
|
||||
XP_CALLOC((sendMailPtr->MSG_nFileCount + 1),
|
||||
sizeof(MSG_AttachmentData));
|
||||
if (!pAttach)
|
||||
{
|
||||
return(MAPI_E_INSUFFICIENT_MEMORY);
|
||||
}
|
||||
|
||||
memset(pAttach, 0, (sendMailPtr->MSG_nFileCount + 1) *
|
||||
sizeof(MSG_AttachmentData));
|
||||
for (i=0; i<sendMailPtr->MSG_nFileCount; i++)
|
||||
{
|
||||
CString cs;
|
||||
// Create URL from filename...
|
||||
WFE_ConvertFile2Url(cs,
|
||||
(const char *)NSStrSeqGet(mailInfoSeq, stringCount++));
|
||||
pAttach[i].url = XP_STRDUP(cs);
|
||||
|
||||
// Now also include the "display" name...
|
||||
StrAllocCopy(pAttach[i].real_name, NSStrSeqGet(mailInfoSeq, stringCount++));
|
||||
}
|
||||
|
||||
// Set the list!
|
||||
MSG_SetAttachmentList(pCompose->GetMsgPane(), pAttach);
|
||||
|
||||
// Now free everything...
|
||||
for (i=0; i<sendMailPtr->MSG_nFileCount; i++)
|
||||
{
|
||||
if (pAttach[i].url)
|
||||
XP_FREE(pAttach[i].url);
|
||||
|
||||
if (pAttach[i].real_name)
|
||||
XP_FREE(pAttach[i].real_name);
|
||||
}
|
||||
|
||||
XP_FREE(pAttach);
|
||||
}
|
||||
|
||||
//
|
||||
// Now, if we were supposed to do the blind send...do it, otherwise,
|
||||
// just popup the window...
|
||||
//
|
||||
if (winShowFlag)
|
||||
{
|
||||
// Post message to compose window to set the initial focus.
|
||||
pCompose->PostMessage(WM_COMP_SET_INITIAL_FOCUS);
|
||||
}
|
||||
else if (sendMailPtr->MSG_nFileCount <= 0) // Send NOW if no attachments!
|
||||
{
|
||||
pCompose->PostMessage(WM_COMMAND, IDM_SAVEASDRAFT);
|
||||
}
|
||||
|
||||
return(SUCCESS_SUCCESS);
|
||||
}
|
||||
89
mozilla/mailnews/mapi/old/hook/mapimail.h
Normal file
89
mozilla/mailnews/mapi/old/hook/mapimail.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef _MAPI_MAIL_H_
|
||||
#define _MAPI_MAIL_H_
|
||||
|
||||
#include "nscpmapi.h"
|
||||
#include <structs.h> // for MWContext
|
||||
|
||||
//extern "C" {
|
||||
|
||||
//
|
||||
// This function will create a composition window and either do
|
||||
// a blind send or pop up the compose window for the user to
|
||||
// complete the operation
|
||||
//
|
||||
// Return: appropriate MAPI return code...
|
||||
//
|
||||
//
|
||||
extern "C" LONG
|
||||
DoFullMAPIMailOperation(MAPISendMailType *sendMailPtr,
|
||||
const char *pInitialText,
|
||||
BOOL winShowFlag);
|
||||
|
||||
//
|
||||
// This function will create a composition window and just attach
|
||||
// the attachments of interest and pop up the window...
|
||||
//
|
||||
// Return: appropriate MAPI return code...
|
||||
//
|
||||
//
|
||||
extern "C" LONG
|
||||
DoPartialMAPIMailOperation(MAPISendDocumentsType *sendDocPtr);
|
||||
|
||||
//
|
||||
// This function will save a message into the Communicator "Drafts"
|
||||
// folder with no UI showing.
|
||||
//
|
||||
// Return: appropriate MAPI return code...
|
||||
//
|
||||
//
|
||||
extern "C" LONG
|
||||
DoMAPISaveMailOperation(MAPISendMailType *sendMailPtr,
|
||||
const char *pInitialText);
|
||||
|
||||
//
|
||||
// This will fire off a "get mail in background operation" in an
|
||||
// async. fashion.
|
||||
//
|
||||
extern "C" void
|
||||
MAPIGetNewMessagesInBackground(void);
|
||||
|
||||
|
||||
// } // extern "C"
|
||||
|
||||
#endif // _MAPI_MAIL_H_
|
||||
50
mozilla/mailnews/mapi/old/lib/Makefile.win
Normal file
50
mozilla/mailnews/mapi/old/lib/Makefile.win
Normal file
@@ -0,0 +1,50 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..
|
||||
MODULE=mapiutils
|
||||
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
|
||||
################################################################################
|
||||
## exports
|
||||
|
||||
EXPORTS= mapismem.h \
|
||||
nsstrseq.h \
|
||||
$(NULL)
|
||||
|
||||
################################################################################
|
||||
## library
|
||||
|
||||
LIBRARY_NAME=mapiutils_s
|
||||
|
||||
|
||||
CPP_OBJS= .\$(OBJDIR)\mapismem.obj \
|
||||
.\$(OBJDIR)\nsstrseq.obj \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
||||
173
mozilla/mailnews/mapi/old/lib/mapismem.cpp
Normal file
173
mozilla/mailnews/mapi/old/lib/mapismem.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// smem.cpp - This deals with all shared memory functions needed for
|
||||
// the MAPI component of Communicator
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include "mapismem.h"
|
||||
|
||||
|
||||
#ifndef ZeroMemory
|
||||
#include <memory.h>
|
||||
#define ZeroMemory(PTR, SIZE) memset(PTR, 0, SIZE)
|
||||
#endif // ZeroMemory
|
||||
|
||||
//
|
||||
// *create new* shared memory chunk
|
||||
// once this is created, use the pointer
|
||||
// to the segment to to store data
|
||||
// e.g.:
|
||||
// lpString = "string for communicator";
|
||||
// lstrcpy((LPSTR)pData->m_buf[0], lpString);
|
||||
//
|
||||
CSharedMem *
|
||||
NSCreateSharedMemory(DWORD memSize, LPCTSTR memName, HANDLE *hSharedMemory)
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
||||
BOOL bExistedBefore;
|
||||
CSharedMem *pData;
|
||||
|
||||
LPCTSTR szObjectName = memName;
|
||||
DWORD dwSize = sizeof(CSharedMem) + memSize;
|
||||
*hSharedMemory = CreateFileMapping(
|
||||
(HANDLE)0xFFFFFFFF,0,PAGE_READWRITE,0,dwSize,szObjectName);
|
||||
if(*hSharedMemory == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
bExistedBefore = (GetLastError() == ERROR_ALREADY_EXISTS);
|
||||
if(bExistedBefore)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pData = (CSharedMem *)MapViewOfFile(
|
||||
*hSharedMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||
if(pData == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ZeroMemory(pData, dwSize);
|
||||
pData->m_dwSize = memSize;
|
||||
|
||||
return pData;
|
||||
#else
|
||||
CSharedMem *sMemChunk = NULL;
|
||||
DWORD dwSize = memSize = (sizeof(CSharedMem) + memSize);
|
||||
|
||||
if (sMemChunk != NULL)
|
||||
return(sMemChunk);
|
||||
|
||||
sMemChunk = (CSharedMem *) GlobalAllocPtr(GMEM_MOVEABLE, dwSize);
|
||||
ZeroMemory(sMemChunk, (size_t) dwSize);
|
||||
sMemChunk->m_dwSize = dwSize; // Missing in Communicator code!
|
||||
return(sMemChunk);
|
||||
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
//
|
||||
// *open existing* shared memory chunk
|
||||
// once you have the pointer to the new segment
|
||||
// use this pointer to access data, e.g.:
|
||||
//
|
||||
CSharedMem *
|
||||
NSOpenExistingSharedMemory(LPCTSTR memName, HANDLE *hSharedMemory)
|
||||
{
|
||||
#ifdef WIN32
|
||||
CSharedMem *pData;
|
||||
DWORD dwSize;
|
||||
|
||||
LPCTSTR szObjectName = memName;
|
||||
*hSharedMemory = OpenFileMapping(
|
||||
FILE_MAP_WRITE,FALSE,szObjectName);
|
||||
if(*hSharedMemory == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pData = (CSharedMem *)MapViewOfFile(
|
||||
*hSharedMemory,FILE_MAP_ALL_ACCESS,0,0,0);
|
||||
if(pData == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dwSize = pData->m_dwSize;
|
||||
return pData;
|
||||
#else
|
||||
|
||||
return(NULL); // In Win16, this is really meaningless...
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// to close shared memory segment
|
||||
//
|
||||
void
|
||||
NSCloseSharedMemory(CSharedMem *pData, HANDLE hSharedMemory)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if(pData != 0)
|
||||
{
|
||||
UnmapViewOfFile(pData);
|
||||
pData = 0;
|
||||
}
|
||||
|
||||
if(hSharedMemory != 0)
|
||||
{
|
||||
CloseHandle(hSharedMemory);
|
||||
hSharedMemory = 0;
|
||||
}
|
||||
#else
|
||||
|
||||
if (pData != NULL)
|
||||
{
|
||||
GlobalFreePtr(pData);
|
||||
pData = NULL;
|
||||
}
|
||||
|
||||
#endif // WIN32
|
||||
}
|
||||
116
mozilla/mailnews/mapi/old/lib/mapismem.h
Normal file
116
mozilla/mailnews/mapi/old/lib/mapismem.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef __SMEM_HPP__
|
||||
#define __SMEM_HPP__
|
||||
|
||||
//
|
||||
// Need this for Win16 since it is an undocumented message
|
||||
//
|
||||
#ifndef WIN32
|
||||
|
||||
#define WM_COPYDATA 0x004A
|
||||
|
||||
/*
|
||||
* lParam of WM_COPYDATA message points to...
|
||||
*/
|
||||
typedef struct tagCOPYDATASTRUCT {
|
||||
DWORD dwData;
|
||||
DWORD cbData;
|
||||
LPVOID lpData;
|
||||
} COPYDATASTRUCT, *PCOPYDATASTRUCT;
|
||||
|
||||
# ifndef LPCTSTR
|
||||
# define LPCTSTR LPCSTR
|
||||
# endif
|
||||
|
||||
|
||||
#endif // ifndef WIN32
|
||||
|
||||
// The following structure will be stored in the shared memory
|
||||
// and will be used to pass data back and forth
|
||||
|
||||
#pragma pack(4)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DWORD m_dwSize; // size of the shared memory block
|
||||
BYTE m_buf[1]; // this is the buffer of memory to be used
|
||||
} CSharedMem;
|
||||
|
||||
#pragma pack(4)
|
||||
|
||||
// ******************************************************
|
||||
// Public routines...
|
||||
// ******************************************************
|
||||
//
|
||||
//
|
||||
// *create new* shared memory chunk
|
||||
// once this is created, use the pointer
|
||||
// to the segment to to store data
|
||||
// e.g.:
|
||||
// lpString = "string for communicator";
|
||||
// lstrcpy((LPSTR)pData->m_buf[0], lpString);
|
||||
// pData->m_dwBytesUsed = lstrlen(lpString) + 1; // count '\0'
|
||||
//
|
||||
CSharedMem *
|
||||
NSCreateSharedMemory(DWORD memSize, LPCTSTR memName, HANDLE *hSharedMemory);
|
||||
|
||||
//
|
||||
// *open existing* shared memory chunk
|
||||
// once you have the pointer to the new segment
|
||||
// use this pointer to access data, e.g.:
|
||||
//
|
||||
// This will return the pointer to the memory chunk as well as
|
||||
// fill out the hSharedMemory argument that is needed for subsequent
|
||||
// operations.
|
||||
//
|
||||
// if(pData->m_dwBytesUsed > 0)
|
||||
// {
|
||||
// // use pData->m_buf here
|
||||
// }
|
||||
//
|
||||
CSharedMem *
|
||||
NSOpenExistingSharedMemory(LPCTSTR memName, HANDLE *hSharedMemory);
|
||||
|
||||
//
|
||||
// You must pass in the pointer to the memory chunk as well as
|
||||
// the hSharedMemory HANDLE to close shared memory segment
|
||||
//
|
||||
void
|
||||
NSCloseSharedMemory(CSharedMem *pData, HANDLE hSharedMemory);
|
||||
|
||||
#endif // __SMEM_HPP__
|
||||
230
mozilla/mailnews/mapi/old/lib/nsstrseq.cpp
Normal file
230
mozilla/mailnews/mapi/old/lib/nsstrseq.cpp
Normal file
@@ -0,0 +1,230 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// This is a string sequence handling routine to take complex
|
||||
// structures and merge them into a chunk of memory.
|
||||
//
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
//
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include "nsstrseq.h"
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL '\0'
|
||||
#endif
|
||||
|
||||
#define MARKER '\377'
|
||||
|
||||
//
|
||||
// Delete an existing string sequence
|
||||
//
|
||||
void NSStrSeqDelete(NSstringSeq seq)
|
||||
{
|
||||
if (seq != NULL)
|
||||
free(seq);
|
||||
|
||||
seq = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Allocate a new sequence, copying the given strings into it.
|
||||
//
|
||||
NSstringSeq NSStrSeqNew(LPSTR strings[])
|
||||
{
|
||||
int size;
|
||||
if (!strings)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
{
|
||||
int i;
|
||||
for (i=0,size=0; strings[i]; i++)
|
||||
{
|
||||
size+=strlen(strings[i])+1;
|
||||
switch (strings[i][0])
|
||||
{
|
||||
// Need to pad "" or anything starting with 255
|
||||
// to allow for multiple blank strings in a row
|
||||
case 0:
|
||||
case MARKER:
|
||||
size++;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
NSstringSeq s=(NSstringSeq)malloc(size+1);
|
||||
if (!s)
|
||||
{ return NULL;}
|
||||
|
||||
{
|
||||
int i,offset;
|
||||
for (i=0,offset=0; strings[i]; i++)
|
||||
{
|
||||
switch (strings[i][0])
|
||||
{
|
||||
// Need to pad "" or anything starting with 255
|
||||
case 0:
|
||||
case MARKER:
|
||||
s[offset++]=MARKER;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
strcpy(s+offset,strings[i]);
|
||||
offset+=strlen(strings[i])+1;
|
||||
}
|
||||
s[offset]=0;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Get the # of bytes required for the sequence
|
||||
//
|
||||
LONG NSStrSeqSize(NSstringSeq seq)
|
||||
{
|
||||
const char* s;
|
||||
if (!seq)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (s=seq+1; ((*s) || (*(s-1))); s++)
|
||||
;
|
||||
|
||||
// At this point, s points to the second 0
|
||||
// of the double 0 at the end
|
||||
return (s-seq)+1;
|
||||
}
|
||||
|
||||
//
|
||||
// Get the # of strings in the sequence
|
||||
//
|
||||
LONG NSStrSeqNumStrs(NSstringSeq seq)
|
||||
{
|
||||
const char* s;
|
||||
int N;
|
||||
if (!seq)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (s=seq+1,N=0; ((*s) || (*(s-1))); s++)
|
||||
{
|
||||
if (!(*s))
|
||||
N++;
|
||||
}
|
||||
|
||||
return N;
|
||||
}
|
||||
|
||||
static LPSTR correct(LPSTR s)
|
||||
{
|
||||
if (s[0]==MARKER)
|
||||
return s+1;
|
||||
else // Anup , 4/96
|
||||
return s;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract the index'th string in the sequence
|
||||
//
|
||||
LPSTR NSStrSeqGet(NSstringSeq seq, LONG index)
|
||||
{
|
||||
char* s;
|
||||
int N;
|
||||
|
||||
if (!seq)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (index<0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!index)
|
||||
return correct(seq);
|
||||
|
||||
for (s=seq+1,N=0; ((*s) || (*(s-1))) && (N<index); s++)
|
||||
{
|
||||
if (!(*s))
|
||||
N++;
|
||||
}
|
||||
|
||||
if (N==index)
|
||||
return correct(s);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LPSTR * NSStrSeqGetAll(NSstringSeq seq)
|
||||
{
|
||||
LONG N=NSStrSeqNumStrs(seq);
|
||||
if (N<0)
|
||||
return NULL;
|
||||
|
||||
{
|
||||
char** res=(char**)malloc( (size_t) ((N+1)*sizeof(char*)) );
|
||||
int i;
|
||||
|
||||
if (!res)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
for (i=0; i<N; i++)
|
||||
res[i]=NSStrSeqGet(seq,i);
|
||||
res[N]=NULL;
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
68
mozilla/mailnews/mapi/old/lib/nsstrseq.h
Normal file
68
mozilla/mailnews/mapi/old/lib/nsstrseq.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef __SEQUENCES_OF_STRINGS_H_
|
||||
#define __SEQUENCES_OF_STRINGS_H
|
||||
|
||||
|
||||
typedef LPSTR NSstringSeq;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void NSStrSeqDelete(NSstringSeq seq);
|
||||
NSstringSeq NSStrSeqNew(LPSTR strings[]);
|
||||
|
||||
// Get the # of bytes required for the sequence
|
||||
LONG NSStrSeqSize(NSstringSeq seq);
|
||||
|
||||
// Get the # of strings in the sequence
|
||||
LONG NSStrSeqNumStrs(NSstringSeq seq);
|
||||
|
||||
// Extract the index'th string in the sequence
|
||||
LPSTR NSStrSeqGet(NSstringSeq seq, LONG index);
|
||||
|
||||
// Build an array of all the strings in the sequence
|
||||
LPSTR *NSStrSeqGetAll(NSstringSeq seq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // __sequences_of_strings_h_
|
||||
26
mozilla/mailnews/mapi/old/makefile.win
Normal file
26
mozilla/mailnews/mapi/old/makefile.win
Normal file
@@ -0,0 +1,26 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
DIRS=public lib mapi32 tests hook
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
100
mozilla/mailnews/mapi/old/mapi32/maindll.cpp
Normal file
100
mozilla/mailnews/mapi/old/mapi32/maindll.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// DLLMain to get a handle on an hInstance
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
#include <windows.h>
|
||||
|
||||
//
|
||||
// global variables
|
||||
//
|
||||
HINSTANCE hInstance;
|
||||
|
||||
//
|
||||
// DLL entry
|
||||
//
|
||||
#ifdef WIN32
|
||||
/****************************************************************************
|
||||
FUNCTION: DllMain(HANDLE, DWORD, LPVOID)
|
||||
|
||||
PURPOSE: DllMain is called by Windows when
|
||||
the DLL is initialized, Thread Attached, and other times.
|
||||
Refer to SDK documentation, as to the different ways this
|
||||
may be called.
|
||||
|
||||
The DllMain function should perform additional initialization
|
||||
tasks required by the DLL. In this example, no initialization
|
||||
tasks are required. DllMain should return a value of 1 if
|
||||
the initialization is successful.
|
||||
|
||||
*******************************************************************************/
|
||||
BOOL APIENTRY DllMain(HANDLE hInstLocal, DWORD ul_reason_being_called, LPVOID lpReserved)
|
||||
{
|
||||
hInstance = (HINSTANCE)hInstLocal;
|
||||
|
||||
if (hInstance != NULL)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else // WIN16
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// LibMain( hInstance, wDataSegment, wHeapSize, lpszCmdLine ) : WORD
|
||||
//
|
||||
// hInstance library instance handle
|
||||
// wDataSegment library data segment
|
||||
// wHeapSize default heap size
|
||||
// lpszCmdLine command line arguments
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
int CALLBACK LibMain(HINSTANCE hInstLocal, WORD wDataSegment, WORD wHeapSize, LPSTR lpszCmdLine)
|
||||
{
|
||||
hInstance = hInstLocal;
|
||||
/* return result 1 = success; 0 = fail */
|
||||
if (hInstance != NULL)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // WIN16
|
||||
|
||||
70
mozilla/mailnews/mapi/old/mapi32/makefile.win
Normal file
70
mozilla/mailnews/mapi/old/mapi32/makefile.win
Normal file
@@ -0,0 +1,70 @@
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH=..\..\..
|
||||
MODULE=mapi32
|
||||
|
||||
################################################################################
|
||||
## exports
|
||||
|
||||
#EXPORTS =
|
||||
|
||||
|
||||
################################################################################
|
||||
## library
|
||||
|
||||
LIBNAME = .\$(OBJDIR)\mapi32
|
||||
DEFINES= -NS_DEBUG
|
||||
DEFFILE=MAPI32.def
|
||||
|
||||
!ifdef MOZ_STATIC_COMPONENT_LIBS
|
||||
LIB = $(LIBNAME).lib
|
||||
!else
|
||||
DLL = $(LIBNAME).dll
|
||||
!endif
|
||||
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\maindll.obj \
|
||||
.\$(OBJDIR)\mapi32.obj \
|
||||
.\$(OBJDIR)\mapiipc.obj \
|
||||
.\$(OBJDIR)\mapimem.obj \
|
||||
.\$(OBJDIR)\mapiutl.obj \
|
||||
.\$(OBJDIR)\smem.obj \
|
||||
.\$(OBJDIR)\trace.obj \
|
||||
.\$(OBJDIR)\xpapi.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= \
|
||||
$(LLIBS) \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\xppref32.lib \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\mapiutils_s.lib \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
!ifdef MOZ_STATIC_COMPONENT_LIBS
|
||||
install:: $(LIB)
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\bin\components
|
||||
!else
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin\components
|
||||
!endif
|
||||
2291
mozilla/mailnews/mapi/old/mapi32/mapi32.cpp
Normal file
2291
mozilla/mailnews/mapi/old/mapi32/mapi32.cpp
Normal file
File diff suppressed because it is too large
Load Diff
14
mozilla/mailnews/mapi/old/mapi32/mapi32.def
Normal file
14
mozilla/mailnews/mapi/old/mapi32/mapi32.def
Normal file
@@ -0,0 +1,14 @@
|
||||
EXPORTS
|
||||
MAPILogon
|
||||
MAPILogoff
|
||||
MAPISendMail
|
||||
MAPISendDocuments
|
||||
MAPIFreeBuffer
|
||||
MAPIFindNext
|
||||
MAPIReadMail
|
||||
MAPISaveMail
|
||||
MAPIDeleteMail
|
||||
MAPIAddress
|
||||
MAPIDetails
|
||||
MAPIResolveName
|
||||
MAPIGetNetscapeVersion
|
||||
146
mozilla/mailnews/mapi/old/mapi32/mapi32.rc
Normal file
146
mozilla/mailnews/mapi/old/mapi32/mapi32.rc
Normal file
@@ -0,0 +1,146 @@
|
||||
// Insert copyright and license here 1997
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
ID_DIALOG_MAPI DIALOGEX 0, 0, 186, 111
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_TOOLWINDOW
|
||||
CAPTION "Netscape MAPI Support"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,41,95,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,104,95,50,14
|
||||
GROUPBOX "Diagnostic Information",IDC_STATIC,2,2,182,91
|
||||
CTEXT "This window will contain MAPI relative\ninformation for Netscape Communicator",
|
||||
IDC_STATIC,11,14,159,30
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO DISCARDABLE
|
||||
BEGIN
|
||||
ID_DIALOG_MAPI, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 2
|
||||
RIGHTMARGIN, 184
|
||||
TOPMARGIN, 2
|
||||
BOTTOMMARGIN, 109
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 5,0,0,1
|
||||
PRODUCTVERSION 5,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "Simple MAPI DLL\0"
|
||||
VALUE "CompanyName", "Netscape Communications Corporation\0"
|
||||
VALUE "FileDescription", "mapi32\0"
|
||||
VALUE "FileVersion", "5, 0, 0, 1\0"
|
||||
VALUE "InternalName", "mapi32\0"
|
||||
VALUE "LegalCopyright", "Copyright © 1997\0"
|
||||
VALUE "LegalTrademarks", "Netscape and Netscape Navigator are registered trademarks of Netscape Communications Corporation.\0"
|
||||
VALUE "OriginalFilename", "mapi32.dll\0"
|
||||
VALUE "ProductName", "Netscape Communications Simple MAPI\0"
|
||||
VALUE "ProductVersion", "5, 0, 0, 1\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
249
mozilla/mailnews/mapi/old/mapi32/mapiipc.cpp
Normal file
249
mozilla/mailnews/mapi/old/mapi32/mapiipc.cpp
Normal file
@@ -0,0 +1,249 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// MAPI IPC Routines
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <nscpmapi.h> // Should live in Communicator
|
||||
|
||||
#include "resource.h"
|
||||
#include "mapiipc.h"
|
||||
#include "mapismem.h"
|
||||
#include "trace.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Necessary variables...
|
||||
//
|
||||
static LONG instanceCount = 0;
|
||||
HWND hWndMAPI = NULL;
|
||||
char szClassName[] = "NetscapeMAPIClient";
|
||||
char szWindowName[] = "NetscapeMAPI";
|
||||
|
||||
//
|
||||
// External declares...
|
||||
//
|
||||
extern HINSTANCE hInstance;
|
||||
|
||||
void
|
||||
ProcessCommand(HWND hWnd, int id, HWND hCtl, UINT codeNotify)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case IDOK:
|
||||
case IDCANCEL:
|
||||
{
|
||||
ShowWindow(hWnd, SW_HIDE);
|
||||
}
|
||||
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CALLBACK LOADDS
|
||||
MyDlgProc(HWND hWndMain, UINT wMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (wMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
hWndMAPI = hWndMain;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
// DestroyWindow(hWndMain);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
hWndMain = NULL;
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
HANDLE_WM_COMMAND(hWndMAPI, wParam, lParam, ProcessCommand);
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL
|
||||
InitInstance(HINSTANCE hInstance)
|
||||
{
|
||||
//
|
||||
// Create a main window for this application instance.
|
||||
//
|
||||
/* RICHIE - TRY SOME CHANGES!!!
|
||||
hWndMAPI = CreateDialog((HINSTANCE) hInstance,
|
||||
MAKEINTRESOURCE(ID_DIALOG_QAHOOK),
|
||||
(HWND) NULL, (DLGPROC) MyDlgProc);
|
||||
******/
|
||||
hWndMAPI = CreateWindow(
|
||||
szClassName, // pointer to registered class name
|
||||
szWindowName, // pointer to window name
|
||||
WS_CHILD, // window style
|
||||
-10, // horizontal position of window
|
||||
-10, // vertical position of window
|
||||
1, // window width
|
||||
1, // window height
|
||||
GetDesktopWindow(), // handle to parent or owner window
|
||||
NULL, // handle to menu or child-window identifier
|
||||
hInstance, // handle to application instance
|
||||
NULL // pointer to window-creation data
|
||||
);
|
||||
if (!hWndMAPI)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL
|
||||
InitApp(void)
|
||||
{
|
||||
#ifdef WIN32
|
||||
WNDCLASS wc;
|
||||
wc.style = 0;
|
||||
wc.lpfnWndProc = DefDlgProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = DLGWINDOWEXTRA;
|
||||
wc.hInstance = hInstance;
|
||||
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(ID_ICON_APP));
|
||||
wc.hCursor = LoadCursor(0, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = szClassName;
|
||||
|
||||
if(!RegisterClass(&wc))
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
} // end InitApp
|
||||
|
||||
BOOL
|
||||
InitDLL(void)
|
||||
{
|
||||
if (hWndMAPI != NULL)
|
||||
return TRUE;
|
||||
|
||||
if (!InitApp())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!InitInstance(hInstance))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ShowWindow(hWndMAPI, SW_SHOW); Just for jollies
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
//*************************************************************
|
||||
//* Calls exposed for rest of DLL...
|
||||
//*************************************************************
|
||||
//
|
||||
// Purpose: Open the API
|
||||
// Return: 1 on success
|
||||
// 0 on failure
|
||||
//
|
||||
DWORD nsMAPI_OpenAPI(void)
|
||||
{
|
||||
if (instanceCount > 0)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
++instanceCount;
|
||||
return(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Purpose: Close the API
|
||||
//
|
||||
void nsMAPI_CloseAPI(void)
|
||||
{
|
||||
--instanceCount;
|
||||
if (instanceCount <= 0)
|
||||
{
|
||||
instanceCount = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Send the actual request to Communicator
|
||||
//
|
||||
LRESULT
|
||||
SendMAPIRequest(HWND hWnd,
|
||||
DWORD mapiRequestID,
|
||||
MAPIIPCType *ipcInfo)
|
||||
{
|
||||
LRESULT returnVal = 0;
|
||||
COPYDATASTRUCT cds;
|
||||
|
||||
if (!InitDLL())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
cds.dwData = mapiRequestID;
|
||||
cds.cbData = sizeof(MAPIIPCType);
|
||||
cds.lpData = ipcInfo;
|
||||
|
||||
// Make the call into Communicator
|
||||
returnVal = SendMessage(hWnd, WM_COPYDATA, (WPARAM) hWndMAPI, (LPARAM) &cds);
|
||||
|
||||
// Now kill the window...
|
||||
DestroyWindow(hWndMAPI);
|
||||
hWndMAPI = NULL;
|
||||
UnregisterClass(szClassName, hInstance);
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
63
mozilla/mailnews/mapi/old/mapi32/mapiipc.h
Normal file
63
mozilla/mailnews/mapi/old/mapi32/mapiipc.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef __MAPIIPC_HPP__
|
||||
#define __MAPIIPC_HPP__
|
||||
|
||||
#include "port.h"
|
||||
#include <nscpmapi.h>
|
||||
|
||||
//********************************************************
|
||||
// Open and close functions for API
|
||||
//********************************************************
|
||||
// Open the API
|
||||
// Return: 1 on success, 0 on failure
|
||||
//
|
||||
DWORD nsMAPI_OpenAPI(void);
|
||||
|
||||
//
|
||||
// Purpose: Close the API
|
||||
//
|
||||
void nsMAPI_CloseAPI(void);
|
||||
|
||||
//
|
||||
// Send the actual request to Communicator
|
||||
//
|
||||
LRESULT SendMAPIRequest(HWND hWnd,
|
||||
DWORD mapiRequestID,
|
||||
MAPIIPCType *ipcInfo);
|
||||
|
||||
#endif // __MAPIIPC_HPP__
|
||||
363
mozilla/mailnews/mapi/old/mapi32/mapimem.cpp
Normal file
363
mozilla/mailnews/mapi/old/mapi32/mapimem.cpp
Normal file
@@ -0,0 +1,363 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// mem.cpp
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
// This implements various memory management functions for use with
|
||||
// MAPI features of Communicator
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <memory.h>
|
||||
#include <malloc.h>
|
||||
#include "mapimem.h"
|
||||
#include <nscpmapi.h> // lives in communicator winfe
|
||||
#include "nsstrseq.h"
|
||||
#include "trace.h"
|
||||
#include "mapiutl.h"
|
||||
#include "xpapi.h"
|
||||
|
||||
LPSTR
|
||||
CheckNullString(LPSTR inStr)
|
||||
{
|
||||
static UCHAR str[1];
|
||||
|
||||
str[0] = '\0';
|
||||
if (inStr == NULL)
|
||||
return((LPSTR)str);
|
||||
else
|
||||
return(inStr);
|
||||
}
|
||||
|
||||
void
|
||||
FreeMAPIFile(lpMapiFileDesc pv)
|
||||
{
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
if (pv->lpszPathName != NULL)
|
||||
free(pv->lpszPathName);
|
||||
|
||||
if (pv->lpszFileName != NULL)
|
||||
free(pv->lpszFileName);
|
||||
}
|
||||
|
||||
void
|
||||
FreeMAPIMessage(lpMapiMessage pv)
|
||||
{
|
||||
ULONG i;
|
||||
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
if (pv->lpszSubject != NULL)
|
||||
free(pv->lpszSubject);
|
||||
|
||||
if (pv->lpszNoteText)
|
||||
free(pv->lpszNoteText);
|
||||
|
||||
if (pv->lpszMessageType)
|
||||
free(pv->lpszMessageType);
|
||||
|
||||
if (pv->lpszDateReceived)
|
||||
free(pv->lpszDateReceived);
|
||||
|
||||
if (pv->lpszConversationID)
|
||||
free(pv->lpszConversationID);
|
||||
|
||||
if (pv->lpOriginator)
|
||||
FreeMAPIRecipient(pv->lpOriginator);
|
||||
|
||||
for (i=0; i<pv->nRecipCount; i++)
|
||||
{
|
||||
if (&(pv->lpRecips[i]) != NULL)
|
||||
{
|
||||
FreeMAPIRecipient(&(pv->lpRecips[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if (pv->lpRecips != NULL)
|
||||
{
|
||||
free(pv->lpRecips);
|
||||
}
|
||||
|
||||
for (i=0; i<pv->nFileCount; i++)
|
||||
{
|
||||
if (&(pv->lpFiles[i]) != NULL)
|
||||
{
|
||||
FreeMAPIFile(&(pv->lpFiles[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if (pv->lpFiles != NULL)
|
||||
{
|
||||
free(pv->lpFiles);
|
||||
}
|
||||
|
||||
free(pv);
|
||||
pv = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
FreeMAPIRecipient(lpMapiRecipDesc pv)
|
||||
{
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
if (pv->lpszName != NULL)
|
||||
free(pv->lpszName);
|
||||
|
||||
if (pv->lpszAddress != NULL)
|
||||
free(pv->lpszAddress);
|
||||
|
||||
if (pv->lpEntryID != NULL)
|
||||
free(pv->lpEntryID);
|
||||
}
|
||||
|
||||
//
|
||||
// This routine will take an lpMapiMessage structure and "flatten" it into
|
||||
// one contiguous chunk of memory that can be easily passed around. After this
|
||||
// is done, "extract" routines will be written to get complicated string routines
|
||||
// out of the chunk of memory at the end.
|
||||
//
|
||||
LPVOID
|
||||
FlattenMAPIMessageStructure(lpMapiMessage msg, DWORD *totalSize)
|
||||
{
|
||||
MAPISendMailType *mailPtr;
|
||||
LPSTR *strArray;
|
||||
DWORD strCount = 0;
|
||||
DWORD currentString = 0;
|
||||
DWORD arrayBufSize = 0;
|
||||
DWORD i;
|
||||
|
||||
*totalSize = 0;
|
||||
if (!msg)
|
||||
return(NULL);
|
||||
|
||||
//
|
||||
// Allocate the initial structure to hold all of the mail info.
|
||||
//
|
||||
*totalSize = sizeof(MAPISendMailType);
|
||||
mailPtr = (MAPISendMailType *) malloc(sizeof(MAPISendMailType));
|
||||
if (!mailPtr)
|
||||
return(NULL);
|
||||
memset(mailPtr, 0, sizeof(MAPISendMailType));
|
||||
|
||||
//
|
||||
// First, assign all of the easy numeric values...
|
||||
//
|
||||
mailPtr->MSG_flFlags = msg->flFlags; // unread,return receipt
|
||||
mailPtr->MSG_nRecipCount = msg->nRecipCount; // Number of recipients
|
||||
mailPtr->MSG_nFileCount = msg->nFileCount; // # of file attachments
|
||||
if (msg->lpOriginator != NULL)
|
||||
{
|
||||
mailPtr->MSG_ORIG_ulRecipClass = msg->lpOriginator->ulRecipClass; // Recipient class - MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG
|
||||
}
|
||||
|
||||
//
|
||||
// Now, figure out how many string pointers we need...
|
||||
//
|
||||
strCount = 4; // These are the 4 KNOWN strings up front for a message
|
||||
strCount += 2; // This is for the originator name and address
|
||||
|
||||
strCount += msg->nRecipCount * 3; // Name, address & class (cc, bcc) for each recipient
|
||||
strCount += msg->nFileCount * 2; // filename and display name for each attachment
|
||||
|
||||
//
|
||||
// Now allocate a new string sequence...add one entry for NULL at the end
|
||||
//
|
||||
arrayBufSize = sizeof(LPSTR) * (strCount + 1);
|
||||
|
||||
#ifdef WIN16 // Check for max mem allocation...
|
||||
if ((sizeof(MAPISendMailType) + arrayBufSize) > 64000)
|
||||
{
|
||||
free(mailPtr);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Allocate a buffer for the string pointers and if this fails,
|
||||
// cleanup and return.
|
||||
//
|
||||
strArray = (LPSTR *)malloc( (size_t) arrayBufSize);
|
||||
if (!strArray)
|
||||
{
|
||||
free(mailPtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(strArray, 0, (size_t) arrayBufSize); // Set the array to NULL
|
||||
strArray[currentString++] = CheckNullString(msg->lpszSubject); // Message Subject
|
||||
strArray[currentString++] = CheckNullString(msg->lpszNoteText); // Message Text
|
||||
strArray[currentString++] = CheckNullString(msg->lpszDateReceived); // in YYYY/MM/DD HH:MM format
|
||||
strArray[currentString++] = CheckNullString(msg->lpszConversationID); // conversation thread ID
|
||||
|
||||
if (msg->lpOriginator)
|
||||
{
|
||||
strArray[currentString++] = CheckNullString(msg->lpOriginator[0].lpszName);
|
||||
strArray[currentString++] = CheckNullString(msg->lpOriginator[0].lpszAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
strArray[currentString++] = CheckNullString(NULL);
|
||||
strArray[currentString++] = CheckNullString(NULL);
|
||||
}
|
||||
|
||||
//
|
||||
// Assign pointers for the Name and address of each recipient
|
||||
//
|
||||
LPSTR toString = "1";
|
||||
LPSTR ccString = "2";
|
||||
LPSTR bccString = "3";
|
||||
|
||||
for (i=0; i<msg->nRecipCount; i++)
|
||||
{
|
||||
// rhp - need message class
|
||||
if (msg->lpRecips[i].ulRecipClass == MAPI_BCC)
|
||||
strArray[currentString++] = CheckNullString(bccString);
|
||||
else if (msg->lpRecips[i].ulRecipClass == MAPI_CC)
|
||||
strArray[currentString++] = CheckNullString(ccString);
|
||||
else
|
||||
strArray[currentString++] = CheckNullString(toString);
|
||||
|
||||
strArray[currentString++] = CheckNullString(msg->lpRecips[i].lpszName);
|
||||
strArray[currentString++] = CheckNullString(msg->lpRecips[i].lpszAddress);
|
||||
}
|
||||
|
||||
BYTE szNewFileName[_MAX_PATH];
|
||||
|
||||
for (i=0; i<msg->nFileCount; i++)
|
||||
{
|
||||
char *namePtr;
|
||||
// have to copy/create temp files here of office won't work...
|
||||
|
||||
if (
|
||||
(msg->lpFiles[i].lpszFileName != NULL) &&
|
||||
(*msg->lpFiles[i].lpszFileName != '\0')
|
||||
)
|
||||
{
|
||||
namePtr = (char *)msg->lpFiles[i].lpszFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
namePtr = (char *)msg->lpFiles[i].lpszPathName;
|
||||
}
|
||||
|
||||
if (GetTempMailNameWithExtension((char *)szNewFileName, namePtr) == 0)
|
||||
{
|
||||
free(strArray);
|
||||
free(mailPtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!XP_CopyFile((char *)msg->lpFiles[i].lpszPathName, (char *)szNewFileName, TRUE))
|
||||
{
|
||||
free(strArray);
|
||||
free(mailPtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strArray[currentString++] = CheckNullString((char *)szNewFileName);
|
||||
strArray[currentString++] = CheckNullString(msg->lpFiles[i].lpszFileName);
|
||||
|
||||
AddTempFile((LPSTR) szNewFileName);
|
||||
// strArray[currentString++] = CheckNullString(msg->lpFiles[i].lpszPathName);
|
||||
// strArray[currentString++] = CheckNullString(msg->lpFiles[i].lpszFileName);
|
||||
}
|
||||
|
||||
if (currentString != strCount)
|
||||
{
|
||||
TRACE("MAPI PROBLEM!!!!!! FlattenMAPIMessageStructure() currentString != strCount\n");
|
||||
}
|
||||
|
||||
strArray[strCount] = NULL; // terminate at the end
|
||||
NSstringSeq strSeq = NSStrSeqNew(strArray);
|
||||
if (!strSeq)
|
||||
{
|
||||
free(strArray);
|
||||
free(mailPtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Now we need to copy the structure into a big, contiguous chunk of memory
|
||||
//
|
||||
LONG totalArraySize = NSStrSeqSize(strSeq);
|
||||
LONG totalMemSize = sizeof(MAPISendMailType) + totalArraySize;
|
||||
|
||||
#ifdef WIN16
|
||||
if (totalMemSize > 64000)
|
||||
{
|
||||
free(strArray);
|
||||
NSStrSeqDelete(strSeq);
|
||||
free(mailPtr);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
MAPISendMailType *newMailPtr = (MAPISendMailType *)malloc((size_t)totalMemSize);
|
||||
if (!newMailPtr)
|
||||
{
|
||||
free(strArray);
|
||||
NSStrSeqDelete(strSeq);
|
||||
free(mailPtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(newMailPtr, 0, (size_t) totalMemSize);
|
||||
//
|
||||
// Finally do the copy...
|
||||
//
|
||||
memcpy(newMailPtr, mailPtr, sizeof(MAPISendMailType));
|
||||
memcpy(newMailPtr->dataBuf, strSeq, (size_t) totalArraySize);
|
||||
*totalSize = totalMemSize;
|
||||
|
||||
//
|
||||
// Cleanup and scram...
|
||||
//
|
||||
if (strArray)
|
||||
free(strArray);
|
||||
|
||||
if (strSeq)
|
||||
NSStrSeqDelete(strSeq);
|
||||
|
||||
if (mailPtr)
|
||||
free(mailPtr);
|
||||
|
||||
return(newMailPtr);
|
||||
}
|
||||
76
mozilla/mailnews/mapi/old/mapi32/mapimem.h
Normal file
76
mozilla/mailnews/mapi/old/mapi32/mapimem.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef __MY_MEM_HPP__
|
||||
#define __MY_MEM_HPP__
|
||||
|
||||
#ifndef MAPI_OLE // Because MSFT doesn't do this for us :-(
|
||||
#include <mapi.h>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Needed for turning NULL's into ""'s for string sequence routines...
|
||||
//
|
||||
LPSTR CheckNullString(LPSTR inStr);
|
||||
|
||||
//
|
||||
// Memory allocation functions...
|
||||
//
|
||||
|
||||
//
|
||||
// This will free an lpMapiMessage structure allocated by this DLL
|
||||
//
|
||||
void FreeMAPIMessage(lpMapiMessage pv);
|
||||
|
||||
//
|
||||
// This will free an lpMapiRecipDesc structure allocated by this DLL
|
||||
//
|
||||
void FreeMAPIRecipient(lpMapiRecipDesc pv);
|
||||
|
||||
//
|
||||
// Frees a mapi file object...
|
||||
//
|
||||
void FreeMAPIFile(lpMapiFileDesc pv);
|
||||
|
||||
//
|
||||
// This routine will take an lpMapiMessage structure and "flatten" it into
|
||||
// one contiguous chunk of memory that can be easily passed around.
|
||||
//
|
||||
LPVOID FlattenMAPIMessageStructure(lpMapiMessage msg, DWORD *totalSize);
|
||||
|
||||
|
||||
|
||||
#endif // __MY_MEM_HPP__
|
||||
899
mozilla/mailnews/mapi/old/mapi32/mapiutl.cpp
Normal file
899
mozilla/mailnews/mapi/old/mapi32/mapiutl.cpp
Normal file
@@ -0,0 +1,899 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// Various utils needed for the MAPI functions
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <io.h>
|
||||
#include "xpapi.h"
|
||||
#include "trace.h"
|
||||
#include "mapiipc.h"
|
||||
#include "mapiutl.h"
|
||||
|
||||
//
|
||||
// Global variables
|
||||
//
|
||||
BOOL gLoggingEnabled = FALSE;
|
||||
|
||||
void
|
||||
SetLoggingEnabled(BOOL val)
|
||||
{
|
||||
gLoggingEnabled = val;
|
||||
}
|
||||
|
||||
// Log File
|
||||
void
|
||||
LogString(LPCSTR pStr1)
|
||||
{
|
||||
// Off of the declaration line...
|
||||
LPCSTR pStr2 = NULL;
|
||||
BOOL useStr1 = TRUE;
|
||||
|
||||
if (gLoggingEnabled)
|
||||
{
|
||||
char tempPath[_MAX_PATH] = "";
|
||||
if (getenv("TEMP"))
|
||||
{
|
||||
lstrcpy((LPSTR) tempPath, getenv("TEMP")); // environmental variable
|
||||
}
|
||||
|
||||
int len = lstrlen(tempPath);
|
||||
if ((len > 1) && tempPath[len - 1] != '\\')
|
||||
{
|
||||
lstrcat(tempPath, "\\");
|
||||
}
|
||||
lstrcat(tempPath, szMapiLog);
|
||||
HFILE hFile = _lopen(tempPath, OF_WRITE);
|
||||
if (hFile == HFILE_ERROR)
|
||||
{
|
||||
hFile = _lcreat(tempPath, 0);
|
||||
}
|
||||
if (hFile != HFILE_ERROR)
|
||||
{
|
||||
_llseek(hFile, 0, SEEK_END); // seek to the end of the file
|
||||
LPCSTR pTemp = useStr1 ? pStr1 : pStr2;
|
||||
_lwrite(hFile, pTemp, lstrlen(pTemp));
|
||||
_lclose(hFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Find Communicator and return an HWND, if not, start Communicator,
|
||||
// then find an HWND
|
||||
//
|
||||
HWND
|
||||
GetCommunicatorIPCWindow(void)
|
||||
{
|
||||
HWND hWnd = NULL;
|
||||
DWORD timeCount = 0;
|
||||
BOOL launchTry = FALSE;
|
||||
|
||||
//
|
||||
// This will wait for 10 seconds before giving up and failing
|
||||
//
|
||||
while ((hWnd == NULL) && (timeCount < 20))
|
||||
{
|
||||
if ((hWnd = FindWindow("AfxFrameOrView", NULL)) && !FindWindow("aHiddenFrameClass", NULL))
|
||||
return(hWnd);
|
||||
else if ((hWnd = FindWindow("aHiddenFrameClass", NULL)))
|
||||
return(hWnd);
|
||||
|
||||
if (!launchTry)
|
||||
{
|
||||
char szPath[_MAX_PATH] = "";
|
||||
DWORD nMAPIERROR;
|
||||
|
||||
if ((nMAPIERROR = XP_GetInstallLocation(szPath, _MAX_PATH)) != SUCCESS_SUCCESS)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
WORD nReturn = XP_CallProcess(szPath, " -MAPICLIENT");
|
||||
launchTry = TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// Pause for 1/2 a second and try to connect again...
|
||||
//
|
||||
#ifdef WIN32
|
||||
Sleep(500);
|
||||
#else
|
||||
Yield();
|
||||
#endif
|
||||
|
||||
timeCount++;
|
||||
}
|
||||
|
||||
return(hWnd);
|
||||
}
|
||||
|
||||
void
|
||||
BuildMemName(LPSTR name, ULONG winSeed)
|
||||
{
|
||||
static DWORD id = 0;
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
// Seed the random-number generator with current time so that
|
||||
// the numbers will be different every time we run.
|
||||
srand( (unsigned)time( NULL ) );
|
||||
id = rand();
|
||||
}
|
||||
|
||||
wsprintf(name, "MAPI_IPC_SMEM-%d", (winSeed + id++));
|
||||
TRACE("Shared Memory Name = [%s]\n", name);
|
||||
}
|
||||
|
||||
DWORD
|
||||
ValidateFile(LPCSTR szFile)
|
||||
{
|
||||
struct _stat buf;
|
||||
int result;
|
||||
|
||||
result = _stat( szFile, &buf );
|
||||
if (result != 0)
|
||||
return(1);
|
||||
|
||||
if (!(buf.st_mode & S_IREAD))
|
||||
return(2);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
//
|
||||
// return of zero is ok
|
||||
// 1 = MAPI_E_ATTACHMENT_NOT_FOUND
|
||||
// 2 = MAPI_E_ATTACHMENT_OPEN_FAILURE
|
||||
//
|
||||
DWORD
|
||||
SanityCheckAttachmentFiles(lpMapiMessage lpMessage)
|
||||
{
|
||||
ULONG i;
|
||||
DWORD rc;
|
||||
|
||||
for (i=0; i<lpMessage->nFileCount; i++)
|
||||
{
|
||||
if ((rc = ValidateFile(lpMessage->lpFiles[i].lpszPathName)) != 0)
|
||||
{
|
||||
return(rc);
|
||||
}
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
DWORD
|
||||
GetFileCount(LPSTR pFiles, LPSTR delimChar)
|
||||
{
|
||||
DWORD count = 1;
|
||||
if ((!pFiles) || (!*pFiles))
|
||||
return(0);
|
||||
|
||||
for (DWORD i=0; i<strlen(pFiles); i++)
|
||||
{
|
||||
if (pFiles[i] == delimChar[0])
|
||||
{
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return(count);
|
||||
}
|
||||
|
||||
//
|
||||
// Extract a filename from a string
|
||||
// Return TRUE if file found, else FALSE
|
||||
//
|
||||
BOOL
|
||||
ExtractFile(LPSTR pFiles, LPSTR delimChar, DWORD fIndex, LPSTR fName)
|
||||
{
|
||||
LPSTR ptr = pFiles;
|
||||
DWORD loc;
|
||||
DWORD count = 0;
|
||||
|
||||
if ((!pFiles) || (!*pFiles))
|
||||
return(0);
|
||||
|
||||
// Get to the fIndex'th entry
|
||||
for (loc=0; loc<strlen(pFiles); loc++)
|
||||
{
|
||||
if (count == fIndex)
|
||||
break;
|
||||
if (pFiles[loc] == delimChar[0])
|
||||
count++;
|
||||
}
|
||||
|
||||
if (loc >= strlen(pFiles)) // Got to the end of string!
|
||||
return(FALSE);
|
||||
|
||||
lstrcpy(fName, (LPSTR)pFiles + loc);
|
||||
//
|
||||
// Truncate at 2nd delimiter
|
||||
//
|
||||
for (DWORD i=0; i<strlen(fName); i++)
|
||||
{
|
||||
if (fName[i] == delimChar[0])
|
||||
{
|
||||
fName[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
ULONG
|
||||
GetFileSize(LPSTR fName)
|
||||
{
|
||||
struct _stat buf;
|
||||
int result;
|
||||
|
||||
result = _stat( fName, &buf );
|
||||
if (result != 0)
|
||||
return(0);
|
||||
|
||||
return(buf.st_size);
|
||||
}
|
||||
|
||||
LPVOID
|
||||
LoadBlobToMemory(LPSTR fName)
|
||||
{
|
||||
UCHAR *ptr = NULL;
|
||||
ULONG bufSize = GetFileSize(fName);
|
||||
|
||||
if (bufSize == 0)
|
||||
{
|
||||
_unlink(fName);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ptr = (UCHAR *)malloc( (size_t) bufSize);
|
||||
if (!ptr)
|
||||
{
|
||||
_unlink(fName);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
HFILE hFile = _lopen(fName, OF_READ);
|
||||
if (hFile == HFILE_ERROR)
|
||||
{
|
||||
_unlink(fName);
|
||||
free(ptr);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
UINT numRead = _lread(hFile, ptr, (size_t) bufSize);
|
||||
_lclose(hFile);
|
||||
|
||||
if (numRead != bufSize)
|
||||
{
|
||||
_unlink(fName);
|
||||
free(ptr);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
_unlink(fName);
|
||||
return(ptr);
|
||||
}
|
||||
|
||||
LONG
|
||||
WriteMemoryBufferToDisk(LPSTR fName, LONG bufSize, LPSTR buf)
|
||||
{
|
||||
if (!buf)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
HFILE hFile = _lcreat(fName, 0);
|
||||
if (hFile == HFILE_ERROR)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
LONG writeCount = _lwrite(hFile, buf, (size_t) bufSize);
|
||||
_lclose(hFile);
|
||||
|
||||
if (writeCount != bufSize)
|
||||
{
|
||||
_unlink(fName);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
LPSTR
|
||||
GetTheTempDirectoryOnTheSystem(void)
|
||||
{
|
||||
static UCHAR retPath[_MAX_PATH];
|
||||
|
||||
if (getenv("TEMP"))
|
||||
{
|
||||
lstrcpy((LPSTR) retPath, getenv("TEMP")); // environmental variable
|
||||
}
|
||||
else if (getenv("TMP"))
|
||||
{
|
||||
lstrcpy((LPSTR) retPath, getenv("TMP")); // How about this environmental variable?
|
||||
}
|
||||
else
|
||||
{
|
||||
GetWindowsDirectory((LPSTR) retPath, sizeof(retPath));
|
||||
}
|
||||
|
||||
return((LPSTR) &(retPath[0]));
|
||||
}
|
||||
|
||||
#ifdef WIN16
|
||||
int WINAPI EXPORT ISGetTempFileName(LPCSTR a_pDummyPath, LPCSTR a_pPrefix, UINT a_uUnique, LPSTR a_pResultName)
|
||||
{
|
||||
#ifdef GetTempFileName // we need the real thing comming up next...
|
||||
#undef GetTempFileName
|
||||
#endif
|
||||
return GetTempFileName(0, a_pPrefix, a_uUnique, a_pResultName);
|
||||
}
|
||||
#endif
|
||||
|
||||
LONG
|
||||
GetTempAttachmentName(LPSTR fName)
|
||||
{
|
||||
UINT res;
|
||||
static UINT uUnique = 1;
|
||||
|
||||
if (!fName)
|
||||
return(-1);
|
||||
|
||||
LPSTR szTempPath = GetTheTempDirectoryOnTheSystem();
|
||||
|
||||
TRYAGAIN:
|
||||
#ifdef WIN32
|
||||
res = GetTempFileName(szTempPath, "MAPI", uUnique++, fName);
|
||||
#else
|
||||
res = ISGetTempFileName(szTempPath, "MAPI", uUnique++, fName);
|
||||
#endif
|
||||
|
||||
if (ValidateFile(fName) != 1)
|
||||
{
|
||||
if (uUnique < 32000)
|
||||
{
|
||||
goto TRYAGAIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// RICHIE - strip all of the HTML stuff out of the message...
|
||||
int
|
||||
CheckForInlineHTML(char *noteBody, DWORD len, DWORD *curPos, char *newBody, DWORD *realLen)
|
||||
{
|
||||
LPSTR tags[] = {" ", "<", "&", NULL};
|
||||
UCHAR tagsSubst[] = {' ', '<', '&', NULL};
|
||||
int x = 0;
|
||||
|
||||
while (tags[x])
|
||||
{
|
||||
// should we check for first tag
|
||||
if ( (*curPos+strlen(tags[x])) < len)
|
||||
{
|
||||
if (strncmp(tags[x], noteBody, strlen(tags[x])) == 0)
|
||||
{
|
||||
*curPos += strlen(tags[x]) - 1;
|
||||
newBody[*realLen] = tagsSubst[x];
|
||||
*realLen += 1;
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
++x;
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
//
|
||||
// RICHIE - This is also temporary fix for now...
|
||||
//
|
||||
LPSTR
|
||||
StripSignedMessage(LPSTR noteText, DWORD totalCR)
|
||||
{
|
||||
char *newBuf;
|
||||
LPSTR startTag = "<HTML>";
|
||||
LPSTR endTag = "/HTML>";
|
||||
DWORD i;
|
||||
DWORD realLen = 0;
|
||||
DWORD startPos = 0;
|
||||
DWORD len = strlen(noteText);;
|
||||
|
||||
// create a new buffer...
|
||||
newBuf = (char *) malloc((size_t)(len + totalCR));
|
||||
if (!newBuf)
|
||||
return(noteText);
|
||||
|
||||
newBuf[0] = '\0';
|
||||
|
||||
// First, find the start of the HTML for the message...
|
||||
for (i=0; i<len; i++)
|
||||
{
|
||||
// should we check for first tag
|
||||
if ( (i+strlen(startTag)) < len)
|
||||
{
|
||||
if (strncmp(startTag, (noteText + i), strlen(startTag)) == 0)
|
||||
{
|
||||
startPos = i + strlen(startTag);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Didn't find any HTML start tag
|
||||
if (i == len)
|
||||
return(noteText);
|
||||
|
||||
BOOL inHTML = FALSE;
|
||||
BOOL firstChar = FALSE;
|
||||
|
||||
for (i=startPos; i<len; i++)
|
||||
{
|
||||
char *ptr = (noteText + i);
|
||||
|
||||
if ( ((*ptr == 0x0D) || (*ptr == 0x20)) && (!firstChar) )
|
||||
continue;
|
||||
else
|
||||
firstChar = TRUE;
|
||||
|
||||
// First, check for the end /HTML> tag
|
||||
if ( (i+strlen(endTag)) < len)
|
||||
{
|
||||
if (strncmp(endTag, ptr, strlen(endTag)) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If we are in HTML, check for a ">"...
|
||||
if (inHTML)
|
||||
{
|
||||
if (*ptr == '>')
|
||||
{
|
||||
inHTML = FALSE;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for NEW HTML...
|
||||
if (*ptr == '<')
|
||||
{
|
||||
inHTML = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CheckForInlineHTML(ptr, len, &i, newBuf, &realLen))
|
||||
continue;
|
||||
|
||||
newBuf[realLen++] = *ptr;
|
||||
// Tack on a line feed if we hit a CR...
|
||||
if ( *ptr == 0x0D )
|
||||
{
|
||||
newBuf[realLen++] = 0x0A;
|
||||
}
|
||||
}
|
||||
|
||||
// terminate the buffer - reallocate and move on...
|
||||
newBuf[realLen++] = '\0';
|
||||
newBuf = (LPSTR) realloc(newBuf, (size_t) realLen);
|
||||
|
||||
// check if the realloc worked and if so, free old memory and
|
||||
// return...if not, just return the original buffer
|
||||
if (!newBuf)
|
||||
{
|
||||
return(noteText);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(noteText);
|
||||
return(newBuf);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// RICHIE - this is a temporary fix for now to get rid of
|
||||
// html stuff within the text of a message - if there was a
|
||||
// valid noteText buffer coming into this call, we need to
|
||||
// free it on the way out.
|
||||
//
|
||||
LPSTR
|
||||
StripHTML(LPSTR noteText)
|
||||
{
|
||||
char *newBuf;
|
||||
LPSTR signTag = "This is a cryptographically signed message in MIME format.";
|
||||
LPSTR mimeTag = "This is a multi-part message in MIME format.";
|
||||
|
||||
DWORD i;
|
||||
DWORD realLen = 0;
|
||||
DWORD totalCR = 0;
|
||||
|
||||
// do sanity checking...
|
||||
if ((!noteText) || (!(*noteText)))
|
||||
return(noteText);
|
||||
|
||||
// more sanity checking...
|
||||
DWORD len = strlen(noteText) + 1;
|
||||
if (len <= 0)
|
||||
return(noteText);
|
||||
|
||||
// Get the number of CR's in this message and add room for
|
||||
// the LF's
|
||||
for (i=0; i<len; i++)
|
||||
{
|
||||
if ( (*(noteText + i)) == 0x0D )
|
||||
++totalCR;
|
||||
}
|
||||
|
||||
// This is a check for a signed message in the start of a message
|
||||
// check for sign line...
|
||||
if ( strlen(signTag) < len)
|
||||
{
|
||||
if (
|
||||
(strncmp(signTag, noteText, strlen(signTag)) == 0) ||
|
||||
(strncmp(mimeTag, noteText, strlen(mimeTag)) == 0)
|
||||
)
|
||||
{
|
||||
return( StripSignedMessage(noteText, totalCR) );
|
||||
}
|
||||
}
|
||||
|
||||
// create a new buffer...
|
||||
newBuf = (char *) malloc((size_t)(len + totalCR));
|
||||
if (!newBuf)
|
||||
return(noteText);
|
||||
|
||||
newBuf[0] = '\0';
|
||||
|
||||
BOOL firstChar = FALSE;
|
||||
|
||||
// Now do the translation for the body of the note...
|
||||
for (i=0; i<len; i++)
|
||||
{
|
||||
char *ptr = (noteText + i);
|
||||
|
||||
if ( ((*ptr == 0x0D) || (*ptr == 0x20)) && (!firstChar) )
|
||||
continue;
|
||||
else
|
||||
firstChar = TRUE;
|
||||
|
||||
if (CheckForInlineHTML(ptr, len, &i, newBuf, &realLen))
|
||||
continue;
|
||||
|
||||
newBuf[realLen++] = *ptr;
|
||||
if ( *ptr == 0x0D )
|
||||
{
|
||||
newBuf[realLen++] = 0x0A;
|
||||
}
|
||||
}
|
||||
|
||||
// terminate the buffer - reallocate and move on...
|
||||
newBuf[realLen++] = '\0';
|
||||
newBuf = (LPSTR) realloc(newBuf, (size_t) realLen);
|
||||
|
||||
// check if the realloc worked and if so, free old memory and
|
||||
// return...if not, just return the original buffer
|
||||
if (!newBuf)
|
||||
{
|
||||
return(noteText);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(noteText);
|
||||
return(newBuf);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN16
|
||||
|
||||
void
|
||||
GetWin16TempName(LPSTR realFileName, LPSTR tempPath,
|
||||
LPSTR szTempFileName, UINT uUnique)
|
||||
{
|
||||
char *dotPtr = strrchr(realFileName, '.');
|
||||
if (dotPtr != NULL)
|
||||
{
|
||||
*dotPtr = '\0';
|
||||
}
|
||||
|
||||
int nameLen = lstrlen(realFileName);
|
||||
if (dotPtr != NULL)
|
||||
{
|
||||
*dotPtr = '.';
|
||||
}
|
||||
|
||||
if (nameLen <= 7)
|
||||
{
|
||||
wsprintf(szTempFileName, "%s\\%d%s", tempPath, uUnique, realFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(szTempFileName, "%s\\%d%s", tempPath, uUnique, (realFileName + 1));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define MAXTRY 9999 // How many times do we try..
|
||||
|
||||
UINT
|
||||
GetTempMailNameWithExtension(LPSTR szTempFileName,
|
||||
LPSTR origName)
|
||||
{
|
||||
UINT res = 1;
|
||||
UINT uUnique = 0;
|
||||
char *szTempPath = GetTheTempDirectoryOnTheSystem();
|
||||
char *tmpPtr;
|
||||
char *realFileName = NULL;
|
||||
|
||||
if ( (origName != NULL) && (*origName != '\0') )
|
||||
{
|
||||
tmpPtr = origName;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpPtr = szTempFileName;
|
||||
}
|
||||
|
||||
realFileName = strrchr(tmpPtr, '\\');
|
||||
if (!realFileName)
|
||||
realFileName = tmpPtr;
|
||||
else
|
||||
realFileName++;
|
||||
|
||||
TRYAGAIN:
|
||||
|
||||
#ifdef WIN32
|
||||
if (uUnique == 0)
|
||||
{
|
||||
wsprintf(szTempFileName, "%s\\%s", szTempPath, realFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(szTempFileName, "%s\\%d_%s",
|
||||
szTempPath, uUnique, realFileName);
|
||||
}
|
||||
#else // WIN16
|
||||
if ( (uUnique == 0) && (strlen(realFileName) <= 12) )
|
||||
{
|
||||
wsprintf(szTempFileName, "%s\\%s", szTempPath, realFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (uUnique < 10)
|
||||
{
|
||||
GetWin16TempName(realFileName, szTempPath, szTempFileName, uUnique);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = ISGetTempFileName(szTempPath, "ns", uUnique++, szTempFileName);
|
||||
}
|
||||
|
||||
// Now add the correct extension...
|
||||
char *origExt = strrchr(realFileName, '.');
|
||||
if (origExt != NULL)
|
||||
{
|
||||
char *tmpExt = strrchr(szTempFileName, '.');
|
||||
if (tmpExt != NULL)
|
||||
{
|
||||
origExt++;
|
||||
tmpExt++;
|
||||
|
||||
while ( ((tmpExt) && (origExt)) && (*origExt != '\0') )
|
||||
{
|
||||
*tmpExt = *origExt;
|
||||
tmpExt++;
|
||||
origExt++;
|
||||
}
|
||||
|
||||
*tmpExt = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( (ValidateFile(szTempFileName) != 1) && (uUnique < MAXTRY) )
|
||||
{
|
||||
uUnique++;
|
||||
if (uUnique >= MAXTRY)
|
||||
return(1);
|
||||
goto TRYAGAIN;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#define kMaxTempFiles 10
|
||||
#define kMaxListLength (10 * _MAX_PATH)
|
||||
|
||||
void GetTempFiles(LPSTR pBuf, int lenBuf)
|
||||
{
|
||||
if (!GetConfigInfoStr(szMapiSection, szTempFiles, pBuf, lenBuf, HKEY_ROOT))
|
||||
{
|
||||
*pBuf = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void WriteTempFiles(LPSTR pBuf)
|
||||
{
|
||||
SetConfigInfoStr(szMapiSection, szTempFiles, pBuf, HKEY_ROOT);
|
||||
}
|
||||
|
||||
void AddTempFile(LPCSTR pFileName)
|
||||
{
|
||||
if ( (!pFileName) || (pFileName[0] == '\0') )
|
||||
return;
|
||||
|
||||
char *files = (char *)malloc(kMaxListLength);
|
||||
|
||||
if (!files)
|
||||
return;
|
||||
|
||||
GetTempFiles(files, kMaxListLength);
|
||||
if ((lstrlen(files) + lstrlen(pFileName) + 2) >= kMaxListLength)
|
||||
{
|
||||
free(files);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lstrlen(files) != 0)
|
||||
{
|
||||
lstrcat(files, ";");
|
||||
}
|
||||
|
||||
lstrcat(files, pFileName);
|
||||
WriteTempFiles(files);
|
||||
free(files);
|
||||
}
|
||||
|
||||
void DeleteFirstTempFile(LPSTR pFiles)
|
||||
{
|
||||
if (!*pFiles)
|
||||
return;
|
||||
LPSTR pTemp = strchr(pFiles, ';');
|
||||
if (pTemp)
|
||||
{
|
||||
*pTemp = 0;
|
||||
}
|
||||
|
||||
//#ifndef _DEBUG
|
||||
_unlink(pFiles);
|
||||
//#endif
|
||||
|
||||
if (pTemp)
|
||||
{
|
||||
memmove(pFiles, pTemp + 1, lstrlen(pTemp + 1) + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
*pFiles = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RemoveAllTempFiles(void)
|
||||
{
|
||||
char *files = (char *)malloc(kMaxListLength);
|
||||
|
||||
if (!files)
|
||||
return;
|
||||
|
||||
GetTempFiles(files, kMaxListLength);
|
||||
|
||||
while (*files)
|
||||
{
|
||||
DeleteFirstTempFile(files);
|
||||
}
|
||||
|
||||
WriteTempFiles(files);
|
||||
free(files);
|
||||
}
|
||||
|
||||
void CheckAgeTempFiles(void)
|
||||
{
|
||||
char *files = (char *)malloc(kMaxListLength);
|
||||
|
||||
if (!files)
|
||||
return;
|
||||
|
||||
GetTempFiles(files, kMaxListLength);
|
||||
int i = 0;
|
||||
LPSTR pTemp = files;
|
||||
while (TRUE)
|
||||
{
|
||||
pTemp = strchr(pTemp, ';');
|
||||
if (!pTemp)
|
||||
break;
|
||||
++pTemp;
|
||||
++i;
|
||||
}
|
||||
|
||||
if (i >= 10)
|
||||
{
|
||||
DeleteFirstTempFile(files);
|
||||
WriteTempFiles(files);
|
||||
}
|
||||
|
||||
free(files);
|
||||
}
|
||||
|
||||
void
|
||||
CleanupMAPITempFiles(void)
|
||||
{
|
||||
if (Is_16_OR_32_BIT_CommunitorRunning() == 0)
|
||||
{
|
||||
RemoveAllTempFiles(); // if Communicator not running, clean up all the temp files
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckAgeTempFiles();
|
||||
}
|
||||
}
|
||||
|
||||
void *
|
||||
CleanMalloc(size_t mallocSize)
|
||||
{
|
||||
void *ptr = malloc(mallocSize);
|
||||
if (!ptr)
|
||||
return(NULL);
|
||||
|
||||
memset(ptr, 0, mallocSize);
|
||||
return(ptr);
|
||||
}
|
||||
|
||||
void
|
||||
SafeFree(void *ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return;
|
||||
|
||||
free(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
89
mozilla/mailnews/mapi/old/mapi32/mapiutl.h
Normal file
89
mozilla/mailnews/mapi/old/mapi32/mapiutl.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef __UTILS_
|
||||
#define __UTILS_
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef MAPI_OLE // Because MSFT doesn't do this for us :-(
|
||||
#include <mapi.h>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Utility functions...
|
||||
//
|
||||
void SetLoggingEnabled(BOOL val); // Set a logging enabled flag
|
||||
void LogString(LPCSTR pStr1); // Log a string to a file...
|
||||
void BuildMemName(LPSTR name, ULONG winSeed); // Shared memory name
|
||||
HWND GetCommunicatorIPCWindow(void); // Get the IPC window we will use...
|
||||
DWORD SanityCheckAttachmentFiles(lpMapiMessage lpMessage); // Check attachments
|
||||
DWORD ValidateFile(LPCSTR szFile); // Is this a valid file - 0=Yes 1 = NOT_FOUND 2 = OPEN_FAILURE
|
||||
|
||||
DWORD GetFileCount(LPSTR pFiles, LPSTR delimChar); // Get File count from string of file1;file2, etc..
|
||||
BOOL ExtractFile(LPSTR pFiles, LPSTR delimChar, DWORD fIndex, LPSTR fName); // Extract a filename from a string
|
||||
|
||||
LPVOID LoadBlobToMemory(LPSTR fName); // Load the blob into memory!
|
||||
LONG GetTempAttachmentName(LPSTR fName); // Get a temp file name and put it in fName
|
||||
|
||||
UINT GetTempMailNameWithExtension(LPSTR szTempFileName, LPSTR origName);
|
||||
void CleanupMAPITempFiles(void);
|
||||
void AddTempFile(LPCSTR pFileName);
|
||||
|
||||
void *CleanMalloc(size_t mallocSize);
|
||||
void SafeFree(void *ptr);
|
||||
|
||||
//
|
||||
// RICHIE - this is a temporary fix for now to get rid of
|
||||
// html stuff within the text of a message - if there was a
|
||||
// valid noteText buffer coming into this call, we need to
|
||||
// free it on the way out.
|
||||
//
|
||||
LPSTR StripHTML(LPSTR noteText);
|
||||
|
||||
//
|
||||
// Write a buffer to disk
|
||||
// Return 0 on success -1 on failure
|
||||
//
|
||||
LONG WriteMemoryBufferToDisk(LPSTR fName, LONG bufSize, LPSTR buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __UTILS_
|
||||
303
mozilla/mailnews/mapi/old/mapi32/port.h
Normal file
303
mozilla/mailnews/mapi/old/mapi32/port.h
Normal file
@@ -0,0 +1,303 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
|
||||
#ifndef PORT_H
|
||||
#define PORT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*****************************************************************\
|
||||
* *
|
||||
* PORT.H *
|
||||
* *
|
||||
* Win16/Win32 portability stuff *
|
||||
* *
|
||||
* A.Sokolsky *
|
||||
* 3.10.94 distilled into this header *
|
||||
* *
|
||||
\*****************************************************************/
|
||||
|
||||
/*
|
||||
* calling conventions
|
||||
*/
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#ifndef CDECL
|
||||
#define CDECL __cdecl
|
||||
#endif // CDECL
|
||||
|
||||
#ifndef PASCAL
|
||||
#define PASCAL __pascal
|
||||
#endif // PASCAL
|
||||
|
||||
#ifdef FASTCALL
|
||||
#error FASTCALL defined
|
||||
#endif // FASTCALL
|
||||
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define FASTCALL __fastcall
|
||||
#else
|
||||
#define FASTCALL PASCAL
|
||||
#endif // NDEBUG
|
||||
|
||||
|
||||
|
||||
#ifndef HWND2DWORD
|
||||
# ifdef WIN32
|
||||
# define HWND2DWORD(X_hWnd) ( (DWORD)(X_hWnd) )
|
||||
# else // WIN16
|
||||
# define HWND2DWORD(X_hWnd) ( (DWORD)MAKELONG(((WORD)(X_hWnd)), 0) )
|
||||
# endif
|
||||
#endif // HWND2DWORD
|
||||
|
||||
|
||||
/*
|
||||
* WIN16 - WIN32 compatibility stuff
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
# define DLLEXPORT __declspec( dllexport )
|
||||
# define EXPORT
|
||||
# define LOADDS
|
||||
# define HUGE
|
||||
# ifndef FAR
|
||||
# define FAR
|
||||
# endif // FAR
|
||||
# ifndef NEAR
|
||||
# define NEAR
|
||||
# endif // NEAR
|
||||
# ifdef UNICODE
|
||||
# define SIZEOF(x) (sizeof(x)/sizeof(WCHAR))
|
||||
# else
|
||||
# define SIZEOF(x) sizeof(x)
|
||||
# endif
|
||||
|
||||
#else // !WIN32 == WIN16
|
||||
|
||||
# define DLLEXPORT
|
||||
# define EXPORT __export
|
||||
# define LOADDS __loadds
|
||||
# define HUGE __huge
|
||||
# ifndef FAR
|
||||
# define FAR __far
|
||||
# define NEAR __near
|
||||
# endif // FAR
|
||||
# define CONST const
|
||||
# define SIZEOF(x) sizeof(x)
|
||||
# define CHAR char
|
||||
# define TCHAR char
|
||||
# define WCHAR char
|
||||
# ifndef LPTSTR
|
||||
# define LPTSTR LPSTR
|
||||
# endif
|
||||
# ifndef LPCTSTR
|
||||
# define LPCTSTR LPCSTR
|
||||
# endif
|
||||
# define UNREFERENCED_PARAMETER(x) x;
|
||||
# ifndef TEXT
|
||||
# define TEXT(x) x
|
||||
# endif
|
||||
# define GetWindowTextW GetWindowText
|
||||
# define lstrcpyW lstrcpy
|
||||
|
||||
# define BN_DBLCLK BN_DOUBLECLICKED // ~~MRJ needed for custom control.
|
||||
// ~~MRJ begin Win95 backward compat section
|
||||
# define LPWSTR LPSTR
|
||||
# define LPCWSTR LPCSTR
|
||||
|
||||
// button check state for WIN16
|
||||
#ifndef BST_UNCHECKED
|
||||
#define BST_UNCHECKED 0x0000
|
||||
#endif
|
||||
|
||||
#ifndef BST_CHECKED
|
||||
#define BST_CHECKED 0x0001
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WIN95_COMPAT
|
||||
# define WIN95_COMPAT
|
||||
#endif
|
||||
|
||||
// ~~MRJ end Win95 compat section.
|
||||
|
||||
// critical section API stubs
|
||||
typedef DWORD CRITICAL_SECTION;
|
||||
typedef CRITICAL_SECTION FAR * LPCRITICAL_SECTION;
|
||||
#ifdef __cplusplus
|
||||
inline void InitializeCriticalSection(LPCRITICAL_SECTION lpSection) {}
|
||||
inline void DeleteCriticalSection(LPCRITICAL_SECTION lpSection) {}
|
||||
inline void EnterCriticalSection(LPCRITICAL_SECTION lpSection) {}
|
||||
inline void LeaveCriticalSection(LPCRITICAL_SECTION lpSection) {}
|
||||
#endif // __cplusplus
|
||||
|
||||
// Added for nssock16 ---Neeti
|
||||
#ifndef ZeroMemory
|
||||
#include <memory.h>
|
||||
#define ZeroMemory(PTR, SIZE) memset(PTR, 0, SIZE)
|
||||
#endif // ZeroMemory
|
||||
|
||||
#endif // WIN16
|
||||
|
||||
/*
|
||||
* unix - windows compatibility stuff
|
||||
*/
|
||||
typedef DWORD u_int32;
|
||||
typedef WORD u_int16;
|
||||
typedef BYTE u_int8;
|
||||
#ifdef WIN32
|
||||
typedef short int Bool16;
|
||||
#else // WIN16
|
||||
typedef BOOL Bool16;
|
||||
#endif // WIN16
|
||||
|
||||
/*
|
||||
* Cross Platform Compatibility
|
||||
*/
|
||||
#ifndef UNALIGNED
|
||||
# ifdef _M_ALPHA
|
||||
# define UNALIGNED __unaligned
|
||||
# else // !_M_ALPHA
|
||||
# define UNALIGNED
|
||||
# endif // !_M_ALPHA
|
||||
#endif // UNALIGNED
|
||||
|
||||
//
|
||||
// RICHIE - for the Alpha port
|
||||
//
|
||||
#ifdef _M_ALPHA
|
||||
# undef pascal
|
||||
# undef PASCAL
|
||||
# if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
|
||||
# define pascal __stdcall
|
||||
# define PASCAL __stdcall
|
||||
# else
|
||||
# define PASCAL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Useful Types
|
||||
*/
|
||||
typedef char HUGE *HPSTR;
|
||||
typedef const char HUGE *HPCSTR;
|
||||
typedef unsigned char HUGE *HPBYTE;
|
||||
typedef WORD HUGE *HPWORD;
|
||||
typedef UINT FAR *LPUINT;
|
||||
typedef BOOL (CALLBACK *USERABORTPROC)();
|
||||
typedef BOOL (CALLBACK *PROGRESSPROC)(UINT uPos, UINT uRange);
|
||||
typedef int INT; // ~~MRJ a function needed this defined.
|
||||
typedef MINMAXINFO FAR *LPMINMAXINFO; // ~~MRJ
|
||||
|
||||
//
|
||||
// stuff missing from windows.h
|
||||
//
|
||||
#ifndef MAKEWORD
|
||||
#define MAKEWORD(low, high) ((WORD)(((BYTE)(low)) | (((WORD)((BYTE)(high))) << 8)))
|
||||
#endif // MAKEWORD
|
||||
|
||||
#ifdef WIN32
|
||||
# ifndef hmemcpy
|
||||
# define hmemcpy memcpy
|
||||
# endif // !defined(hmemcpy)
|
||||
# define _fmemset memset
|
||||
|
||||
# include <malloc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
inline BOOL IsGDIObject(HGDIOBJ hObj) { return (hObj != 0); }
|
||||
inline void *_halloc(long num, unsigned int size) { return malloc(num * size); }
|
||||
inline void _hfree( void *memblock ) { free(memblock); }
|
||||
/*
|
||||
inline BOOL IsInstance(HINSTANCE hInst) {
|
||||
# ifdef WIN32
|
||||
return (hInst != 0);
|
||||
# else // WIN16
|
||||
return (hInst > HINSTANCE_ERROR);
|
||||
# endif
|
||||
}
|
||||
*/
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
WINUSERAPI HANDLE WINAPI LoadImageA(HINSTANCE, LPCSTR, UINT, int, int, UINT);
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
#ifdef __cplusplus
|
||||
inline BOOL IsInstance(HINSTANCE hInst) {
|
||||
# ifdef WIN32
|
||||
return (hInst != 0);
|
||||
# else // WIN16
|
||||
return (hInst > HINSTANCE_ERROR);
|
||||
# endif
|
||||
}
|
||||
inline void SetWindowSmallIcon(HINSTANCE hInst, HWND hWnd, UINT uIconResourceId) {
|
||||
#ifdef WIN32
|
||||
# ifndef WM_SETICON
|
||||
# define WM_SETICON 0x0080
|
||||
# endif // WM_SETICON
|
||||
# ifndef IMAGE_ICON
|
||||
# define IMAGE_ICON 1
|
||||
# endif
|
||||
assert(IsWindow(hWnd));
|
||||
HICON hIcon = (HICON)LoadImageA(hInst, MAKEINTRESOURCE(uIconResourceId), IMAGE_ICON,
|
||||
16, 16, 0);
|
||||
if(NULL != hIcon) {
|
||||
SendMessage(hWnd, WM_SETICON, FALSE, (LPARAM)hIcon);
|
||||
} else {
|
||||
HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(uIconResourceId));
|
||||
assert(hIcon != 0);
|
||||
SendMessage(hWnd, WM_SETICON, FALSE, (LPARAM)hIcon);
|
||||
}
|
||||
#endif // WIN32
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* PORT_H */
|
||||
@@ -1,54 +1,54 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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/
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1994-2000
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* Copyright (C) 1994-1999 RSA Security Inc. Licence to copy this document
|
||||
* is granted provided that it is identified as "RSA Security Inc. Public-Key
|
||||
* Cryptography Standards (PKCS)" in all material mentioning or referencing
|
||||
* this document.
|
||||
*/
|
||||
/* these data types are platform/implementation dependent. */
|
||||
/*
|
||||
* Packing was removed from the shipped RSA header files, even
|
||||
* though it's still needed. put in a central file to help merging..
|
||||
*/
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by mapi32.rc
|
||||
//
|
||||
#define ID_DIALOG_QAHOOK 101
|
||||
#define ID_DIALOG_MAPI 101
|
||||
#define ID_ICON_APP 102
|
||||
|
||||
#if defined(_WIN32)
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4103)
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 103
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#pragma pack(push, cryptoki, 1)
|
||||
#endif
|
||||
|
||||
172
mozilla/mailnews/mapi/old/mapi32/smem.cpp
Normal file
172
mozilla/mailnews/mapi/old/mapi32/smem.cpp
Normal file
@@ -0,0 +1,172 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// smem.cpp - This deals with all shared memory functions needed for
|
||||
// the MAPI component of Communicator
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include "mapismem.h"
|
||||
|
||||
#ifndef ZeroMemory
|
||||
#include <memory.h>
|
||||
#define ZeroMemory(PTR, SIZE) memset(PTR, 0, SIZE)
|
||||
#endif // ZeroMemory
|
||||
|
||||
//
|
||||
// *create new* shared memory chunk
|
||||
// once this is created, use the pointer
|
||||
// to the segment to to store data
|
||||
// e.g.:
|
||||
// lpString = "string for communicator";
|
||||
// lstrcpy((LPSTR)pData->m_buf[0], lpString);
|
||||
//
|
||||
CSharedMem *
|
||||
NSCreateSharedMemory(DWORD memSize, LPCTSTR memName, HANDLE *hSharedMemory)
|
||||
{
|
||||
#ifdef WIN32
|
||||
|
||||
BOOL bExistedBefore;
|
||||
CSharedMem *pData;
|
||||
|
||||
LPCTSTR szObjectName = memName;
|
||||
DWORD dwSize = sizeof(CSharedMem) + memSize;
|
||||
*hSharedMemory = CreateFileMapping(
|
||||
(HANDLE)0xFFFFFFFF,0,PAGE_READWRITE,0,dwSize,szObjectName);
|
||||
if(*hSharedMemory == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
bExistedBefore = (GetLastError() == ERROR_ALREADY_EXISTS);
|
||||
if(bExistedBefore)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pData = (CSharedMem *)MapViewOfFile(
|
||||
*hSharedMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||
if(pData == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ZeroMemory(pData, dwSize);
|
||||
pData->m_dwSize = memSize;
|
||||
|
||||
return pData;
|
||||
#else
|
||||
CSharedMem *sMemChunk = NULL;
|
||||
DWORD dwSize = memSize = (sizeof(CSharedMem) + memSize);
|
||||
|
||||
if (sMemChunk != NULL)
|
||||
return(sMemChunk);
|
||||
|
||||
sMemChunk = (CSharedMem *) GlobalAllocPtr(GMEM_MOVEABLE, dwSize);
|
||||
ZeroMemory(sMemChunk, (size_t) dwSize);
|
||||
sMemChunk->m_dwSize = dwSize; // Missing in Communicator code!
|
||||
return(sMemChunk);
|
||||
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
//
|
||||
// *open existing* shared memory chunk
|
||||
// once you have the pointer to the new segment
|
||||
// use this pointer to access data, e.g.:
|
||||
//
|
||||
CSharedMem *
|
||||
NSOpenExistingSharedMemory(LPCTSTR memName, HANDLE *hSharedMemory)
|
||||
{
|
||||
#ifdef WIN32
|
||||
CSharedMem *pData;
|
||||
DWORD dwSize;
|
||||
|
||||
LPCTSTR szObjectName = memName;
|
||||
*hSharedMemory = OpenFileMapping(
|
||||
PAGE_READWRITE,FALSE,szObjectName);
|
||||
if(*hSharedMemory == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pData = (CSharedMem *)MapViewOfFile(
|
||||
*hSharedMemory,FILE_MAP_ALL_ACCESS,0,0,0);
|
||||
if(pData == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dwSize = pData->m_dwSize;
|
||||
return pData;
|
||||
#else
|
||||
|
||||
return(NULL); // In Win16, this is really meaningless...
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// to close shared memory segment
|
||||
//
|
||||
void
|
||||
NSCloseSharedMemory(CSharedMem *pData, HANDLE hSharedMemory)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if(pData != 0)
|
||||
{
|
||||
UnmapViewOfFile(pData);
|
||||
pData = 0;
|
||||
}
|
||||
|
||||
if(hSharedMemory != 0)
|
||||
{
|
||||
CloseHandle(hSharedMemory);
|
||||
hSharedMemory = 0;
|
||||
}
|
||||
#else
|
||||
|
||||
if (pData != NULL)
|
||||
{
|
||||
GlobalFreePtr(pData);
|
||||
pData = NULL;
|
||||
}
|
||||
|
||||
#endif // WIN32
|
||||
}
|
||||
68
mozilla/mailnews/mapi/old/mapi32/trace.cpp
Normal file
68
mozilla/mailnews/mapi/old/mapi32/trace.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <tchar.h>
|
||||
#include "trace.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#ifndef WIN16
|
||||
void CDECL AfxTrace(LPCTSTR lpszFormat, ...)
|
||||
#else
|
||||
void CDECL AfxTrace(LPCSTR lpszFormat, ...)
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, lpszFormat);
|
||||
|
||||
int nBuf;
|
||||
TCHAR szBuffer[512];
|
||||
|
||||
nBuf = _vstprintf(szBuffer, lpszFormat, args);
|
||||
va_end(args);
|
||||
OutputDebugString(szBuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL AfxAssertFailedLine(LPCSTR lpszFileName, int nLine)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
81
mozilla/mailnews/mapi/old/mapi32/trace.h
Normal file
81
mozilla/mailnews/mapi/old/mapi32/trace.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
BOOL AfxAssertFailedLine(LPCSTR lpszFileName, int nLine);
|
||||
|
||||
#ifndef WIN16
|
||||
void CDECL AfxTrace(LPCTSTR lpszFormat, ...);
|
||||
#else
|
||||
void CDECL AfxTrace(LPCSTR lpszFormat, ...);
|
||||
#endif
|
||||
|
||||
#define TRACE ::AfxTrace
|
||||
#define THIS_FILE __FILE__
|
||||
#define ASSERT(f) \
|
||||
do \
|
||||
{ \
|
||||
if (!(f) && AfxAssertFailedLine(THIS_FILE, __LINE__)) \
|
||||
AfxDebugBreak(); \
|
||||
} while (0) \
|
||||
|
||||
#define VERIFY(f) ASSERT(f)
|
||||
#define TRACE_FN(name) LogFn __logFn(name)
|
||||
class LogFn
|
||||
{
|
||||
public:
|
||||
LogFn(LPCSTR pFnName) {m_pFnName = pFnName; TRACE("--%s: In--\n", pFnName);}
|
||||
~LogFn() {TRACE("--%s: Out--\n", m_pFnName);}
|
||||
private:
|
||||
LPCSTR m_pFnName;
|
||||
};
|
||||
#else
|
||||
// NDEBUG
|
||||
#define ASSERT(f) ((void)0)
|
||||
#define VERIFY(f) ((void)(f))
|
||||
#define ASSERT_VALID(pOb) ((void)0)
|
||||
#define DEBUG_ONLY(f) ((void)0)
|
||||
#ifdef WIN32
|
||||
inline void CDECL AfxTrace(LPCTSTR, ...) { }
|
||||
#else
|
||||
inline void CDECL AfxTrace(LPCSTR, ...) { }
|
||||
#endif
|
||||
#define TRACE 1 ? (void)0 : ::AfxTrace
|
||||
#define TRACE_FN(name)
|
||||
#endif // _DEBUG
|
||||
|
||||
347
mozilla/mailnews/mapi/old/mapi32/xpapi.cpp
Normal file
347
mozilla/mailnews/mapi/old/mapi32/xpapi.cpp
Normal file
@@ -0,0 +1,347 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// XPAPI.CPP
|
||||
// API implementation file for mapi16.dll and mapi32.dll
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "xpapi.h"
|
||||
#include "mapiutl.h"
|
||||
|
||||
WORD LOAD_DS XP_CallProcess(LPCSTR pPath, LPCSTR pCmdLine)
|
||||
{
|
||||
WORD wReturn = 0;
|
||||
#ifndef WIN16
|
||||
STARTUPINFO startupInfo;
|
||||
PROCESS_INFORMATION processInfo;
|
||||
|
||||
memset(&startupInfo, 0, sizeof(startupInfo));
|
||||
startupInfo.cb = sizeof(startupInfo);
|
||||
if (wReturn = CreateProcess(pPath, (LPTSTR)pCmdLine, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_PROCESS_GROUP, NULL, NULL, &startupInfo, &processInfo))
|
||||
{
|
||||
WaitForInputIdle(processInfo.hProcess, 120000);
|
||||
}
|
||||
#else
|
||||
// char szMsg[80];
|
||||
char szExecute[512];
|
||||
lstrcpy(szExecute, pPath);
|
||||
lstrcat(szExecute, " ");
|
||||
lstrcat(szExecute, pCmdLine);
|
||||
wReturn = WinExec(szExecute,SW_SHOW);
|
||||
|
||||
if (wReturn < 32)
|
||||
{
|
||||
wReturn = 0;
|
||||
}
|
||||
#endif
|
||||
return wReturn;
|
||||
}
|
||||
|
||||
HKEY LOAD_DS RegOpenParent(LPCSTR pSection, HKEY hRootKey, REGSAM access)
|
||||
{
|
||||
HKEY hKey;
|
||||
#ifndef WIN16
|
||||
if (RegOpenKeyEx(hRootKey, pSection, 0, access, &hKey) != ERROR_SUCCESS)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
#else
|
||||
if (RegOpenKey(hRootKey, pSection, &hKey) != ERROR_SUCCESS)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
#endif
|
||||
return(hKey);
|
||||
}
|
||||
|
||||
HKEY LOAD_DS RegCreateParent(LPCSTR pSection, HKEY hMasterKey)
|
||||
{
|
||||
HKEY hKey;
|
||||
if (RegCreateKey(hMasterKey, pSection, &hKey) != ERROR_SUCCESS)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
return(hKey);
|
||||
}
|
||||
|
||||
BOOL LOAD_DS GetConfigInfoStr(LPCSTR pSection, LPCSTR pKey, LPSTR pBuf, int lenBuf, HKEY hMasterKey)
|
||||
{
|
||||
HKEY hKey;
|
||||
hKey = RegOpenParent(pSection, hMasterKey, KEY_QUERY_VALUE);
|
||||
if (!hKey)
|
||||
{
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
DWORD len = (DWORD)lenBuf;
|
||||
#ifndef WIN16
|
||||
BOOL retVal = (RegQueryValueEx(hKey, pKey, NULL, NULL, (LPBYTE)pBuf, &len) == ERROR_SUCCESS);
|
||||
#else
|
||||
BOOL retVal = (RegQueryValue(hKey, pKey, pBuf, (long far*)&len) == ERROR_SUCCESS);
|
||||
#endif
|
||||
RegCloseKey(hKey);
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
BOOL LOAD_DS GetConfigInfoNum(LPCSTR pSection, LPCSTR pKey, DWORD* pVal, HKEY hMasterKey)
|
||||
{
|
||||
HKEY hKey;
|
||||
hKey = RegOpenParent(pSection, hMasterKey, KEY_QUERY_VALUE);
|
||||
if (!hKey)
|
||||
{
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
DWORD len = sizeof(DWORD);
|
||||
#ifndef WIN16
|
||||
BOOL retVal = (RegQueryValueEx(hKey, pKey, NULL, NULL, (LPBYTE)pVal, &len) == ERROR_SUCCESS);
|
||||
#else
|
||||
BOOL retVal = (RegQueryValue(hKey, pKey, (char far*)pVal, (long far*)&len) == ERROR_SUCCESS);
|
||||
#endif
|
||||
RegCloseKey(hKey);
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
BOOL LOAD_DS SetConfigInfoStr(LPCSTR pSection, LPCSTR pKey, LPSTR pStr, HKEY hMasterKey)
|
||||
{
|
||||
HKEY hKey;
|
||||
hKey = RegCreateParent(pSection, hMasterKey);
|
||||
if (!hKey)
|
||||
{
|
||||
return(FALSE);
|
||||
}
|
||||
#ifndef WIN16
|
||||
BOOL retVal = (RegSetValueEx(hKey, pKey, 0, REG_SZ, (LPBYTE)pStr, lstrlen(pStr) + 1) == ERROR_SUCCESS);
|
||||
#else
|
||||
BOOL retVal = (RegSetValue(hKey, pKey, REG_SZ, pStr, lstrlen(pStr) + 1) == ERROR_SUCCESS);
|
||||
#endif
|
||||
RegCloseKey(hKey);
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
|
||||
BOOL LOAD_DS XP_GetInstallDirectory(LPCSTR pcurVersionSection, LPCSTR pInstallDirKey, LPSTR path, UINT nSize, HKEY hKey)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if (!GetConfigInfoStr(pcurVersionSection, pInstallDirKey, path, nSize, hKey))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
if ( 0 < GetPrivateProfileString(pcurVersionSection, pInstallDirKey,"ERROR", path, nSize, szNetscapeINI))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
BOOL LOAD_DS XP_GetVersionInfoString(LPCSTR pNavigatorSection, LPCSTR pCurrentVersionKey, LPSTR pcurVersionStr, UINT nSize, HKEY hKey)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if (!GetConfigInfoStr(pNavigatorSection, pCurrentVersionKey, pcurVersionStr, nSize, HKEY_LOCAL_MACHINE))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
if ( 0 < GetPrivateProfileString(pNavigatorSection, pCurrentVersionKey,"ERROR", pcurVersionStr, nSize, szNetscapeINI))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
DWORD LOAD_DS XP_GetInstallLocation(LPSTR pPath, UINT nSize)
|
||||
{
|
||||
char curVersionStr[256];
|
||||
char curVersionSection[256];
|
||||
|
||||
if (!pPath)
|
||||
return MAPI_E_LOGON_FAILURE;
|
||||
|
||||
#ifdef WIN32
|
||||
if (!XP_GetVersionInfoString(szNavigatorSection, szCurrentVersionKey, curVersionStr,
|
||||
sizeof(curVersionStr), HKEY_LOCAL_MACHINE))
|
||||
{
|
||||
return (MAPI_E_LOGON_FAILURE);
|
||||
}
|
||||
|
||||
wsprintf(curVersionSection, szNavigatorCurVersionSection, curVersionStr);
|
||||
|
||||
if (!XP_GetInstallDirectory(curVersionSection, szInstallDirKey, pPath,
|
||||
nSize, HKEY_LOCAL_MACHINE))
|
||||
{
|
||||
return (MAPI_E_ACCESS_DENIED);
|
||||
|
||||
}
|
||||
|
||||
lstrcat(pPath, "\\");
|
||||
lstrcat(pPath, "Program\\netscape.exe");
|
||||
|
||||
return SUCCESS_SUCCESS;
|
||||
#else
|
||||
if (32 == Is_16_OR_32_BIT_CommunitorRunning())
|
||||
{
|
||||
if (!GetConfigInfoStr("snews\\shell\\open", "command", curVersionStr, sizeof(curVersionStr), HKEY_CLASSES_ROOT))
|
||||
{
|
||||
return (MAPI_E_ACCESS_DENIED);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *pFind = strstr(curVersionStr,"-h");
|
||||
|
||||
if (pFind)
|
||||
{
|
||||
*pFind=0;
|
||||
lstrcpy(pPath,curVersionStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (MAPI_E_ACCESS_DENIED);
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS_SUCCESS;
|
||||
}
|
||||
else //setup up to start navstart since we are a sixteen bit DLL.
|
||||
{
|
||||
if (!XP_GetVersionInfoString(szNavigatorSection, szCurrentVersionKey, curVersionStr, sizeof(curVersionStr), HKEY_LOCAL_MACHINE))
|
||||
{
|
||||
return (MAPI_E_LOGON_FAILURE);
|
||||
}
|
||||
|
||||
wsprintf(curVersionSection, szNavigatorCurVersionSection, curVersionStr);
|
||||
|
||||
if (!XP_GetInstallDirectory(curVersionSection, szInstallDirKey, pPath,nSize, HKEY_LOCAL_MACHINE))
|
||||
{
|
||||
return (MAPI_E_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
lstrcat(pPath, "\\");
|
||||
lstrcat(pPath, "NAVSTART.EXE");
|
||||
return SUCCESS_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int LOAD_DS Is_16_OR_32_BIT_CommunitorRunning()
|
||||
{
|
||||
if (FindWindow("AfxFrameOrView", NULL) && !FindWindow("aHiddenFrameClass", NULL))
|
||||
return(16);
|
||||
else if (FindWindow("aHiddenFrameClass", NULL))
|
||||
return(32);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
// size of buffer to use for copying files.
|
||||
#define COPYBUFSIZE 1024
|
||||
|
||||
#ifdef WIN16
|
||||
|
||||
BOOL Win16CopyFile(LPCSTR a_Src, LPCSTR a_Dest, BOOL a_bOverwrite)
|
||||
{
|
||||
OFSTRUCT ofSrc, ofDest;
|
||||
HFILE hSrc, hDest;
|
||||
BOOL bResult;
|
||||
|
||||
ofDest.cBytes = ofSrc.cBytes = sizeof(OFSTRUCT);
|
||||
hDest = OpenFile(a_Dest, &ofDest, OF_EXIST);
|
||||
if (hDest != HFILE_ERROR && !a_bOverwrite)
|
||||
bResult = FALSE; // file exists but caller doesn't want file overwritten
|
||||
else { // file either doesn't exist, or caller wants it overwritten.
|
||||
hSrc = OpenFile(a_Src, &ofSrc, OF_READ);
|
||||
hDest = OpenFile(a_Dest, &ofDest, OF_WRITE | OF_CREATE);
|
||||
if (hSrc != HFILE_ERROR && hDest != HFILE_ERROR) {
|
||||
unsigned char buf[COPYBUFSIZE];
|
||||
UINT bufsize = COPYBUFSIZE;
|
||||
UINT bytesread;
|
||||
|
||||
bResult = TRUE;
|
||||
while (0 != (bytesread = _lread(hSrc, (LPVOID)buf, bufsize))) {
|
||||
if ((bytesread == HFILE_ERROR) || // check for read error...
|
||||
// and write error
|
||||
(bytesread != _lwrite(hDest, (LPVOID)buf, bytesread))) {
|
||||
bResult = FALSE; // could be out of diskspace
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bResult = FALSE;
|
||||
|
||||
if (hSrc != HFILE_ERROR)
|
||||
_lclose(hSrc);
|
||||
if (hDest != HFILE_ERROR)
|
||||
_lclose(hDest);
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
#endif // WIN16
|
||||
|
||||
BOOL LOAD_DS
|
||||
XP_CopyFile(LPCSTR lpExistingFile, LPCSTR lpNewFile, BOOL bFailifExist)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return CopyFile(lpExistingFile, lpNewFile, bFailifExist);
|
||||
#else
|
||||
return Win16CopyFile(lpExistingFile, lpNewFile, TRUE);
|
||||
#endif
|
||||
}
|
||||
138
mozilla/mailnews/mapi/old/mapi32/xpapi.h
Normal file
138
mozilla/mailnews/mapi/old/mapi32/xpapi.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// Various routines for MAPI functions.
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
// November 1997
|
||||
//
|
||||
#ifndef __XPAPI_H
|
||||
#define __XPAPI_H
|
||||
|
||||
#ifdef WIN16
|
||||
|
||||
#include <string.h>
|
||||
#include <direct.h>
|
||||
#include <shellapi.h>
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#include <winreg.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN16
|
||||
extern "C" {
|
||||
#ifndef MAPI_OLE // Because MSFT doesn't do this for us :-(
|
||||
#include <mapi.h>
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
//#include <mapi.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define MAPI_IMPLEMENT(param) param PASCAL
|
||||
#define LOAD_DS
|
||||
#else
|
||||
#define LOAD_DS __loadds
|
||||
#define MAPI_IMPLEMENT(param) extern "C" param FAR PASCAL
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WIN16
|
||||
#define _MAX_PATH 260 /* max. length of full pathname*/
|
||||
#define MAPI_E_LOGON_FAILURE 3
|
||||
#define MAPI_E_ACCESS_DENIED 6
|
||||
#define INVALID_HANDLE_VALUE (HANDLE)-1
|
||||
#define KEY_QUERY_VALUE 0x0001
|
||||
#define HKEY_LOCAL_MACHINE ((HKEY)0x80000002)
|
||||
#define HKEY_ROOT HKEY_CLASSES_ROOT
|
||||
#else
|
||||
#define HKEY_ROOT ((HKEY)0x80000002)
|
||||
#endif
|
||||
|
||||
//
|
||||
// registry keys
|
||||
//
|
||||
#ifdef WIN32
|
||||
static char szNavigatorSection[] = "Software\\Netscape\\Netscape Navigator";
|
||||
static char szNavigatorCurVersionSection[] = "Software\\Netscape\\Netscape Navigator\\%s\\Main";
|
||||
static char szCurrentVersionKey[] = "CurrentVersion";
|
||||
static char szInstallDirKey[] = "Install Directory";
|
||||
static char szMapiSection[] = "Software\\Netscape\\Netscape Navigator\\MAPI";
|
||||
static char szTempFiles[] = "TempFiles";
|
||||
static char szMapiLog[] = "NSMAPI32.LOG";
|
||||
#else
|
||||
//32 bit key strings for trying to read the 32bit registry
|
||||
static char szNavigatorSection32[] = "Software\\Netscape\\Netscape Navigator";
|
||||
static char szNavigatorCurVersionSection32[] = "Software\\Netscape\\Netscape Navigator\\%s\\Main";
|
||||
static char szMapiSection32[] = "Software\\Netscape\\Netscape Navigator\\MAPI";
|
||||
|
||||
// ini section and key strings
|
||||
static char szNetscapeINI[] = "nscp.ini";
|
||||
static char szNavigatorSection[] = "Netscape Navigator";
|
||||
static char szNavigatorCurVersionSection[] = "Netscape Navigator-%s";
|
||||
static char szCurrentVersionKey[] = "CurrentVersion";
|
||||
static char szInstallDirKey[] = "Install Directory";
|
||||
static char szMapiSection[] = "MAPI";
|
||||
static char szTempFiles[] = "TempFiles";
|
||||
static char szExeName[] = "NAVSTART.EXE";
|
||||
static char szMapiLog[] = "NSMAPI16.LOG";
|
||||
#endif
|
||||
|
||||
//Since REGSAM is just an ACCESS_MASK which is just a DWORD and it's not
|
||||
//declared in win16 we'll make one hear for the purpose of keeping parameters
|
||||
//the same even though the access rights don't get used for win16.
|
||||
|
||||
typedef DWORD REGSAM;
|
||||
|
||||
|
||||
// XP declarations
|
||||
|
||||
int LOAD_DS Is_16_OR_32_BIT_CommunitorRunning();
|
||||
WORD LOAD_DS XP_CallProcess(LPCSTR pPath, LPCSTR pCmdLine);
|
||||
HKEY LOAD_DS RegOpenParent(LPCSTR pSection, HKEY hRootKey, REGSAM access);
|
||||
HKEY LOAD_DS RegCreateParent(LPCSTR pSection, HKEY hMasterKey);
|
||||
BOOL LOAD_DS GetConfigInfoStr(LPCSTR pSection, LPCSTR pKey, LPSTR pBuf, int lenBuf, HKEY hMasterKey);
|
||||
BOOL LOAD_DS GetConfigInfoNum(LPCSTR pSection, LPCSTR pKey, DWORD* pVal, HKEY hMasterKey);
|
||||
BOOL LOAD_DS SetConfigInfoStr(LPCSTR pSection, LPCSTR pKey, LPSTR pStr, HKEY hMasterKey);
|
||||
|
||||
BOOL LOAD_DS XP_GetInstallDirectory(LPCSTR pcurVersionSection, LPCSTR pInstallDirKey, LPSTR path, UINT nSize, HKEY hKey);
|
||||
BOOL LOAD_DS XP_GetVersionInfoString(LPCSTR pNavigatorSection, LPCSTR pCurrentVersionKey, LPSTR pcurVersionStr, UINT nSize, HKEY hKey);
|
||||
DWORD LOAD_DS XP_GetInstallLocation(LPSTR pPath, UINT nSize);
|
||||
BOOL LOAD_DS XP_CopyFile(LPCSTR lpExistingFile, LPCSTR lpNewFile, BOOL bFailifExist);
|
||||
|
||||
#endif // __XPAPI_H
|
||||
31
mozilla/mailnews/mapi/old/public/makefile.win
Normal file
31
mozilla/mailnews/mapi/old/public/makefile.win
Normal file
@@ -0,0 +1,31 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..
|
||||
MODULE=mime
|
||||
|
||||
EXPORTS = \
|
||||
nscpmapi.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
351
mozilla/mailnews/mapi/old/public/nscpmapi.h
Normal file
351
mozilla/mailnews/mapi/old/public/nscpmapi.h
Normal file
@@ -0,0 +1,351 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
// This is a header file for the MAPI support within
|
||||
// Communicator.
|
||||
//
|
||||
// Written by: Rich Pizzarro (rhp@netscape.com)
|
||||
//
|
||||
#ifndef _NSCPMAPI
|
||||
#define _NSCPMAPI
|
||||
|
||||
#ifndef MAPI_OLE // Because MSFT doesn't do this for us :-(
|
||||
#include <mapi.h> // for MAPI specific types...
|
||||
#endif
|
||||
|
||||
#ifdef WIN16
|
||||
typedef unsigned char UCHAR;
|
||||
#endif
|
||||
|
||||
|
||||
#define MAX_NAME_LEN 256
|
||||
#define MAX_PW_LEN 256
|
||||
#define MAX_MSGINFO_LEN 512
|
||||
#define MAX_CON 4 // Maximum MAPI session supported
|
||||
#define MAX_POINTERS 32
|
||||
|
||||
//
|
||||
// The MAPI class that will act as the internal mechanism for
|
||||
// Communicator to control multiple MAPI sessions.
|
||||
//
|
||||
class CMAPIConnection
|
||||
{
|
||||
protected:
|
||||
LONG m_ID;
|
||||
BOOL m_defaultConnection;
|
||||
LONG m_sessionCount;
|
||||
LONG m_messageIndex;
|
||||
LPVOID m_cookie;
|
||||
UCHAR m_messageFindInfo[MAX_MSGINFO_LEN];
|
||||
UCHAR m_profileName[MAX_NAME_LEN];
|
||||
UCHAR m_password[MAX_PW_LEN];
|
||||
|
||||
// Methods
|
||||
|
||||
public:
|
||||
CMAPIConnection ( LONG, LPSTR, LPSTR );
|
||||
~CMAPIConnection ( );
|
||||
|
||||
// ID related methods
|
||||
LONG GetID( ) { return m_ID; } ;
|
||||
|
||||
// Dealing with the default session...
|
||||
BOOL IsDefault( ) { return m_defaultConnection; } ;
|
||||
void SetDefault( BOOL flag ) { m_defaultConnection = flag; } ;
|
||||
|
||||
// For handling multiple sessions on a profile name...
|
||||
LONG GetSessionCount( ) { return m_sessionCount; } ;
|
||||
void IncrementSessionCount() { ++m_sessionCount; } ;
|
||||
void DecrementSessionCount() { --m_sessionCount; } ;
|
||||
|
||||
// Information retrieval stuff...
|
||||
LPSTR GetProfileName( ) { return (LPSTR) m_profileName; };
|
||||
LPSTR GetPassword( ) { return (LPSTR) m_password; };
|
||||
|
||||
// Dealing with message information...
|
||||
void SetMessageIndex( LONG mIndex ) { m_messageIndex = mIndex; } ;
|
||||
LONG GetMessageIndex( ) { return m_messageIndex; };
|
||||
|
||||
void SetMessageFindInfo( LPSTR info ) { lstrcpy((LPSTR)m_messageFindInfo, info); } ;
|
||||
LPSTR GetMessageFindInfo( ) { return (LPSTR) m_messageFindInfo; };
|
||||
|
||||
// For enumerating Messages...
|
||||
void SetMapiListContext( LPVOID cookie) { m_cookie = cookie; } ;
|
||||
LPVOID GetMapiListContext( ) { return m_cookie; };
|
||||
};
|
||||
|
||||
//
|
||||
// Defines needed for requests being made with the WM_COPYDATA call...
|
||||
//
|
||||
typedef enum {
|
||||
NSCP_MAPIStartRequestID = 0,
|
||||
NSCP_MAPILogon,
|
||||
NSCP_MAPILogoff,
|
||||
NSCP_MAPIFree,
|
||||
NSCP_MAPISendMail,
|
||||
NSCP_MAPISendDocuments,
|
||||
NSCP_MAPIFindNext,
|
||||
NSCP_MAPIReadMail,
|
||||
NSCP_MAPISaveMail,
|
||||
NSCP_MAPIDeleteMail,
|
||||
NSCP_MAPIAddress,
|
||||
NSCP_MAPIDetails,
|
||||
NSCP_MAPIResolveName,
|
||||
NSCP_MAPIEndRequestID // Note: this is a marker for MAPI IPC requests
|
||||
} NSCP_IPC_REQUEST;
|
||||
|
||||
//
|
||||
// This is to keep track of the pointers allocated in the MAPI DLL
|
||||
// and deal with them correctly.
|
||||
//
|
||||
#define MAPI_MESSAGE_TYPE 0
|
||||
#define MAPI_RECIPIENT_TYPE 1
|
||||
|
||||
typedef struct {
|
||||
LPVOID lpMem;
|
||||
UCHAR memType;
|
||||
} memTrackerType;
|
||||
|
||||
//
|
||||
// This is the generic message that WM_COPYDATA will send to the
|
||||
// Communicator product to allow it to attach to shared memory.
|
||||
// NOTE: On Win16, this will simply reference a pointer.
|
||||
//
|
||||
typedef struct {
|
||||
UCHAR smemName[64]; // Name of shared memory
|
||||
DWORD smemSize; // Size of shared memory
|
||||
LPVOID lpsmem; // Will be really used in Win16 only
|
||||
} MAPIIPCType;
|
||||
|
||||
//
|
||||
// These are message specific structures that will be used for
|
||||
// the various MAPI operations.
|
||||
//
|
||||
typedef struct {
|
||||
ULONG ulUIParam;
|
||||
FLAGS flFlags;
|
||||
LHANDLE lhSession;
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
// LPSTR strSequence, // LPSTR lpszProfileName, LPSTR lpszPassword
|
||||
// This is here to document the fact there will be a string sequence at
|
||||
// this location
|
||||
} MAPILogonType;
|
||||
|
||||
typedef struct {
|
||||
LHANDLE lhSession;
|
||||
ULONG ulUIParam;
|
||||
FLAGS flFlags;
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
} MAPILogoffType;
|
||||
|
||||
typedef struct {
|
||||
LHANDLE lhSession;
|
||||
ULONG ulUIParam;
|
||||
FLAGS flFlags;
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
// The following is the "FLAT" representation of the (lpMapiMessage lpMessage)
|
||||
// argument of this structure
|
||||
FLAGS MSG_flFlags; // unread,return receipt
|
||||
ULONG MSG_nRecipCount; // Number of recipients
|
||||
ULONG MSG_nFileCount; // # of file attachments
|
||||
ULONG MSG_ORIG_ulRecipClass; // Recipient class - MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG
|
||||
BYTE dataBuf[1]; // For easy referencing
|
||||
//
|
||||
// This is where it gets CONFUSING...the following buffer of memory is a
|
||||
// contiguous chunk of memory for various strings that are part of this
|
||||
// multilevel structure. For any of the following structure, any numbers
|
||||
// are represented by strings that will have to be converted back to numeric
|
||||
// values with atoi() calls.
|
||||
|
||||
// String 0: LPSTR lpszSubject; // Message Subject
|
||||
// String 1: LPSTR lpszNoteText FILE NAME; // Message Text will be
|
||||
// stored into a temp file and this will be the pointer to that file.
|
||||
// String 2: LPSTR lpszDateReceived; // in YYYY/MM/DD HH:MM format
|
||||
// String 3: LPSTR lpszConversationID; // conversation thread ID
|
||||
//
|
||||
// The following are for the originator of the message. Only ONE of these.
|
||||
//
|
||||
// String 4: LPSTR lpszName; // Originator name
|
||||
// String 5: LPSTR lpszAddress; // Originator address (optional)
|
||||
//
|
||||
// The following strings are for the recipients for this message. There are
|
||||
// MSG_nRecipCount of these in a row:
|
||||
//
|
||||
// for (i=0; i<MSG_nRecipCount; i++)
|
||||
// String x: LPSTR lpszRecipClass (ULONG) // Recipient class - MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG
|
||||
// String x: LPSTR lpszName; // Recipient N name
|
||||
// String x: LPSTR lpszAddress; // Recipient N address (optional)
|
||||
//
|
||||
// Now, finally, add the attachments for this beast. There are MSG_nFileCount
|
||||
// attachments so it would look like the following:
|
||||
//
|
||||
// for (i=0; i<MSG_nFileCount; i++)
|
||||
//
|
||||
// String x: LPSTR lpszPathName // Fully qualified path of the attached file.
|
||||
// // This path should include the disk drive letter and directory name.
|
||||
// String x: LPSTR lpszFileName // The display name for the attached file
|
||||
//
|
||||
} MAPISendMailType;
|
||||
|
||||
typedef struct {
|
||||
ULONG ulUIParam;
|
||||
ULONG nFileCount;
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
BYTE dataBuf[1]; // For easy referencing
|
||||
//
|
||||
// The sequence of strings to follow are groups of PathName/FileName couples.
|
||||
// The strings will be parsed in MAPI[32].DLL and then put into this format:
|
||||
//
|
||||
// for (i=0; i<nFileCount; i++)
|
||||
//
|
||||
// String x: LPSTR lpszPathName // Fully qualified path of the attached file.
|
||||
// // This path should include the disk drive letter and directory name.
|
||||
// String x: LPSTR lpszFileName // The display name for the attached file
|
||||
} MAPISendDocumentsType;
|
||||
|
||||
typedef struct {
|
||||
LHANDLE lhSession;
|
||||
ULONG ulUIParam;
|
||||
FLAGS flFlags;
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
UCHAR lpszSeedMessageID[MAX_MSGINFO_LEN];
|
||||
UCHAR lpszMessageID[MAX_MSGINFO_LEN];
|
||||
} MAPIFindNextType;
|
||||
|
||||
typedef struct {
|
||||
LHANDLE lhSession;
|
||||
ULONG ulUIParam;
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
UCHAR lpszMessageID[MAX_MSGINFO_LEN];
|
||||
} MAPIDeleteMailType;
|
||||
|
||||
typedef struct {
|
||||
LHANDLE lhSession;
|
||||
ULONG ulUIParam;
|
||||
FLAGS flFlags;
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
UCHAR lpszName[MAX_NAME_LEN];
|
||||
// These are returned by Communicator
|
||||
UCHAR lpszABookID[MAX_NAME_LEN];
|
||||
UCHAR lpszABookName[MAX_NAME_LEN];
|
||||
UCHAR lpszABookAddress[MAX_NAME_LEN];
|
||||
} MAPIResolveNameType;
|
||||
|
||||
typedef struct {
|
||||
LHANDLE lhSession;
|
||||
ULONG ulUIParam;
|
||||
FLAGS flFlags;
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
UCHAR lpszABookID[MAX_NAME_LEN];
|
||||
} MAPIDetailsType;
|
||||
|
||||
typedef struct {
|
||||
LHANDLE lhSession;
|
||||
ULONG ulUIParam;
|
||||
FLAGS flFlags;
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
UCHAR lpszMessageID[MAX_MSGINFO_LEN];
|
||||
//
|
||||
// The following is the "FLAT" representation of the (lpMapiMessage lpMessage)
|
||||
// argument of this structure
|
||||
//
|
||||
FLAGS MSG_flFlags; // unread, return or receipt
|
||||
ULONG MSG_nRecipCount; // Number of recipients
|
||||
ULONG MSG_nFileCount; // # of file attachments
|
||||
ULONG MSG_ORIG_ulRecipClass; // Recipient class - MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG
|
||||
//
|
||||
// Output parameter for blob of information that will live on disk.
|
||||
//
|
||||
UCHAR lpszBlob[MAX_MSGINFO_LEN]; // file name on disk
|
||||
//
|
||||
// The format of this blob of information will be:
|
||||
//
|
||||
// String 0: LPSTR lpszSubject; // Message Subject
|
||||
// String 1: LPSTR lpszNoteText FILE NAME; // Message Text will be
|
||||
// stored into a temp file and this will be the pointer to that file.
|
||||
// String 2: LPSTR lpszDateReceived; // in YYYY/MM/DD HH:MM format
|
||||
// String 3: LPSTR lpszConversationID; // conversation thread ID
|
||||
//
|
||||
// The following are for the originator of the message. Only ONE of these.
|
||||
//
|
||||
// String 4: LPSTR lpszName; // Originator name
|
||||
// String 5: LPSTR lpszAddress; // Originator address (optional)
|
||||
//
|
||||
// The following strings are for the recipients for this message. There are
|
||||
// MSG_nRecipCount of these in a row:
|
||||
//
|
||||
// for (i=0; i<MSG_nRecipCount; i++)
|
||||
// String x: LPSTR lpszName; // Recipient N name
|
||||
// String x: LPSTR lpszAddress; // Recipient N address (optional)
|
||||
// String x: LPSTR lpszRecipClass // recipient class - sprintf of ULONG
|
||||
//
|
||||
// Now, finally, add the attachments for this beast. There are MSG_nFileCount
|
||||
// attachments so it would look like the following:
|
||||
//
|
||||
// for (i=0; i<MSG_nFileCount; i++)
|
||||
//
|
||||
// String x: LPSTR lpszPathName // Fully qualified path of the attached file.
|
||||
// // This path should include the disk drive letter and directory name.
|
||||
// String x: LPSTR lpszFileName // The display name for the attached file
|
||||
//
|
||||
} MAPIReadMailType;
|
||||
|
||||
typedef struct {
|
||||
LHANDLE lhSession;
|
||||
ULONG ulUIParam;
|
||||
FLAGS flFlags;
|
||||
UCHAR lpszCaption[MAX_MSGINFO_LEN];
|
||||
DWORD ipcWorked; // Necessary for IPC check with Communicator
|
||||
// The following is the "FLAT" representation of the (lpMapiRecipDesc lpRecips)
|
||||
// argument of this structure
|
||||
ULONG nRecips; // number of recips to start with...
|
||||
ULONG nNewRecips; // number of recips returned...
|
||||
UCHAR lpszBlob[MAX_MSGINFO_LEN]; // file name for blob of information
|
||||
// that will live on disk.
|
||||
BYTE dataBuf[1]; // For easy referencing
|
||||
//
|
||||
// The following contiguous chunk of memory is the buffer that holds
|
||||
// the recipients to load into the address picker...
|
||||
//
|
||||
// for (i=0; i<MSG_nRecipCount; i++)
|
||||
// String x: LPSTR lpszRecipClass (ULONG) // Recipient class - MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG
|
||||
// String x: LPSTR lpszName; // Recipient N name
|
||||
// String x: LPSTR lpszAddress; // Recipient N address (optional)
|
||||
//
|
||||
} MAPIAddressType;
|
||||
|
||||
#endif // _NSCPMAPI
|
||||
27
mozilla/mailnews/mapi/old/tests/makefile.win
Normal file
27
mozilla/mailnews/mapi/old/tests/makefile.win
Normal file
@@ -0,0 +1,27 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
|
||||
DIRS=mapitest
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
239
mozilla/mailnews/mapi/old/tests/mapitest/main.cpp
Normal file
239
mozilla/mailnews/mapi/old/tests/mapitest/main.cpp
Normal file
@@ -0,0 +1,239 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef MAPI_OLE // Because MSFT doesn't do this for us :-(
|
||||
#include <mapi.h>
|
||||
#endif
|
||||
|
||||
#include "port.h"
|
||||
#include "resource.h"
|
||||
|
||||
#ifndef WM_PAINTICON
|
||||
#define WM_PAINTICON 0x26
|
||||
#endif // WM_PAINTICON
|
||||
|
||||
/*
|
||||
* Forward Declarations...
|
||||
*/
|
||||
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
|
||||
BOOL CALLBACK LOADDS MyDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
|
||||
extern void ProcessCommand(HWND hWnd, int id, HWND hCtl, UINT codeNotify);
|
||||
BOOL OpenMAPI(void);
|
||||
void CloseMAPI(void);
|
||||
|
||||
/*
|
||||
* Global variables
|
||||
*/
|
||||
HINSTANCE hInst;
|
||||
HWND hWnd;
|
||||
|
||||
#ifdef WIN16
|
||||
HICON hIconApp;
|
||||
#endif
|
||||
|
||||
char NEAR szAppName[] = "Netscape QA Helper";
|
||||
char NEAR szShortAppName[] = "QAHelper";
|
||||
char szClassName[] = "Netscape_QAHelper_Class_Name";
|
||||
|
||||
void
|
||||
AppCleanup(void)
|
||||
{
|
||||
extern void DoMAPILogoff(HWND hWnd);
|
||||
static BOOL isDone = FALSE;
|
||||
|
||||
if (isDone)
|
||||
return;
|
||||
|
||||
extern LHANDLE mapiSession;
|
||||
|
||||
if (mapiSession != 0)
|
||||
{
|
||||
DoMAPILogoff(hWnd);
|
||||
}
|
||||
|
||||
CloseMAPI();
|
||||
isDone = TRUE;
|
||||
}
|
||||
|
||||
BOOL
|
||||
InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
{
|
||||
/* Create a main window for this application instance. */
|
||||
hWnd = CreateDialog((HINSTANCE) hInstance,
|
||||
MAKEINTRESOURCE(ID_DIALOG),
|
||||
(HWND) NULL, (DLGPROC) MyDlgProc);
|
||||
|
||||
if (!hWnd)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL InitApp(void)
|
||||
{
|
||||
#ifndef WIN16
|
||||
WNDCLASS wc;
|
||||
wc.style = 0;
|
||||
wc.lpfnWndProc = DefDlgProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = DLGWINDOWEXTRA;
|
||||
wc.hInstance = hInst;
|
||||
wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_APP));
|
||||
wc.hCursor = LoadCursor(0, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = szClassName;
|
||||
|
||||
if(!RegisterClass(&wc))
|
||||
return FALSE;
|
||||
|
||||
#else
|
||||
hIconApp = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON_APP));
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
} // end InitApp
|
||||
|
||||
// Win Main
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
||||
{
|
||||
MSG msg;
|
||||
|
||||
hInst = hInstance;
|
||||
|
||||
if (!InitApp())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!InitInstance(hInstance, nCmdShow))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!OpenMAPI())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ShowWindow(hWnd, SW_SHOW);
|
||||
|
||||
// Start the application
|
||||
while ((GetMessage(&msg, (HWND) NULL, (UINT) NULL, (UINT) NULL)))
|
||||
{
|
||||
if(IsDialogMessage(hWnd, &msg))
|
||||
continue;
|
||||
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
return(msg.wParam);
|
||||
}
|
||||
|
||||
BOOL CALLBACK LOADDS
|
||||
MyDlgProc(HWND hWndMain, UINT wMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (wMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
hWnd = hWndMain;
|
||||
SetDlgItemText(hWnd, ID_EDIT_ROW, "0");
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
{
|
||||
DestroyWindow(hWnd);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_DESTROY:
|
||||
{
|
||||
AppCleanup();
|
||||
|
||||
#ifndef WIN16
|
||||
UnregisterClass(szClassName, hInst);
|
||||
#else
|
||||
// Destroy the 16 bit windows icon
|
||||
if(hIconApp != 0)
|
||||
DestroyIcon(hIconApp);
|
||||
#endif
|
||||
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
case WM_COMMAND:
|
||||
HANDLE_WM_COMMAND(hWnd, wParam, lParam, ProcessCommand);
|
||||
break;
|
||||
|
||||
case WM_QUERYDRAGICON:
|
||||
#ifdef WIN16
|
||||
return (BOOL)hIconApp;
|
||||
#endif
|
||||
|
||||
case WM_PAINTICON:
|
||||
#ifdef WIN16
|
||||
SetClassWord(hWnd, GCW_HICON, 0);
|
||||
|
||||
// fall trough
|
||||
case WM_PAINT:
|
||||
{
|
||||
if(!IsIconic(hWnd))
|
||||
return FALSE;
|
||||
PAINTSTRUCT ps;
|
||||
HDC hDC = BeginPaint(hWnd, &ps);
|
||||
SetMapMode(hDC, MM_TEXT);
|
||||
DrawIcon(hDC, 2, 2, hIconApp);
|
||||
EndPaint(hWnd, &ps);
|
||||
break;
|
||||
}
|
||||
#endif //WIN16
|
||||
break; // RICHIE - if this is not here NT 3.51 Pukes!!!!
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//~~av return (DefWindowProc(hWnd, wMsg, wParam, lParam));
|
||||
return TRUE;
|
||||
}
|
||||
240
mozilla/mailnews/mapi/old/tests/mapitest/makefile.win
Normal file
240
mozilla/mailnews/mapi/old/tests/mapitest/makefile.win
Normal file
@@ -0,0 +1,240 @@
|
||||
# Microsoft Developer Studio Generated NMAKE File, Based on mapitest.dsp
|
||||
!IF "$(CFG)" == ""
|
||||
CFG=mapitest - Win32 Debug
|
||||
!MESSAGE No configuration specified. Defaulting to mapitest - Win32 Debug.
|
||||
!ENDIF
|
||||
|
||||
!IF "$(CFG)" != "mapitest - Win32 Release" && "$(CFG)" != "mapitest - Win32 Debug"
|
||||
!MESSAGE Invalid configuration "$(CFG)" specified.
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "mapitest.mak" CFG="mapitest - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "mapitest - Win32 Release" (based on "Win32 (x86) Application")
|
||||
!MESSAGE "mapitest - Win32 Debug" (based on "Win32 (x86) Application")
|
||||
!MESSAGE
|
||||
!ERROR An invalid configuration is specified.
|
||||
!ENDIF
|
||||
|
||||
!IF "$(OS)" == "Windows_NT"
|
||||
NULL=
|
||||
!ELSE
|
||||
NULL=nul
|
||||
!ENDIF
|
||||
|
||||
!IF "$(CFG)" == "mapitest - Win32 Release"
|
||||
|
||||
OUTDIR=.\Release
|
||||
INTDIR=.\Release
|
||||
# Begin Custom Macros
|
||||
OutDir=.\Release
|
||||
# End Custom Macros
|
||||
|
||||
ALL : "$(OUTDIR)\mapitest.exe"
|
||||
|
||||
export :
|
||||
libs :
|
||||
install :
|
||||
|
||||
clobber_all : clobber
|
||||
|
||||
clobber:
|
||||
-@erase "$(INTDIR)\main.obj"
|
||||
-@erase "$(INTDIR)\mapimail.obj"
|
||||
-@erase "$(INTDIR)\mapiproc.obj"
|
||||
-@erase "$(INTDIR)\mtest32.res"
|
||||
-@erase "$(INTDIR)\readmail.obj"
|
||||
-@erase "$(INTDIR)\vc60.idb"
|
||||
-@erase "$(OUTDIR)\mapitest.exe"
|
||||
-@erase "$(OUTDIR)\mapitest.pch"
|
||||
|
||||
"$(OUTDIR)" :
|
||||
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
|
||||
|
||||
CPP=cl.exe
|
||||
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Fp"$(INTDIR)\mapitest.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
|
||||
|
||||
.c{$(INTDIR)}.obj::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.cpp{$(INTDIR)}.obj::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.cxx{$(INTDIR)}.obj::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.c{$(INTDIR)}.sbr::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.cpp{$(INTDIR)}.sbr::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.cxx{$(INTDIR)}.sbr::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
MTL=midl.exe
|
||||
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
RSC=rc.exe
|
||||
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\mtest32.res" /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
BSC32_FLAGS=/nologo /o"$(OUTDIR)\mapitest.bsc"
|
||||
BSC32_SBRS= \
|
||||
|
||||
LINK32=link.exe
|
||||
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\mapitest.pdb" /machine:I386 /out:"$(OUTDIR)\mapitest.exe"
|
||||
LINK32_OBJS= \
|
||||
"$(INTDIR)\main.obj" \
|
||||
"$(INTDIR)\mapimail.obj" \
|
||||
"$(INTDIR)\mapiproc.obj" \
|
||||
"$(INTDIR)\readmail.obj" \
|
||||
"$(INTDIR)\mtest32.res"
|
||||
|
||||
"$(OUTDIR)\mapitest.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
|
||||
$(LINK32) @<<
|
||||
$(LINK32_FLAGS) $(LINK32_OBJS)
|
||||
<<
|
||||
|
||||
!ELSEIF "$(CFG)" == "mapitest - Win32 Debug"
|
||||
|
||||
OUTDIR=.\Debug
|
||||
INTDIR=.\Debug
|
||||
# Begin Custom Macros
|
||||
OutDir=.\Debug
|
||||
# End Custom Macros
|
||||
|
||||
ALL : "$(OUTDIR)\mapitest.exe"
|
||||
|
||||
export :
|
||||
libs :
|
||||
install :
|
||||
|
||||
clobber_all : clobber
|
||||
|
||||
clobber :
|
||||
-@erase "$(INTDIR)\main.obj"
|
||||
-@erase "$(INTDIR)\mapimail.obj"
|
||||
-@erase "$(INTDIR)\mapiproc.obj"
|
||||
-@erase "$(INTDIR)\mtest32.res"
|
||||
-@erase "$(INTDIR)\readmail.obj"
|
||||
-@erase "$(INTDIR)\vc60.idb"
|
||||
-@erase "$(INTDIR)\vc60.pdb"
|
||||
-@erase "$(OUTDIR)\mapitest.exe"
|
||||
-@erase "$(OUTDIR)\mapitest.ilk"
|
||||
-@erase "$(OUTDIR)\mapitest.pdb"
|
||||
-@erase "$(OUTDIR)\mapitest.pch"
|
||||
|
||||
"$(OUTDIR)" :
|
||||
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
|
||||
|
||||
CPP=cl.exe
|
||||
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Fp"$(INTDIR)\mapitest.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
|
||||
|
||||
.c{$(INTDIR)}.obj::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.cpp{$(INTDIR)}.obj::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.cxx{$(INTDIR)}.obj::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.c{$(INTDIR)}.sbr::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.cpp{$(INTDIR)}.sbr::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
.cxx{$(INTDIR)}.sbr::
|
||||
$(CPP) @<<
|
||||
$(CPP_PROJ) $<
|
||||
<<
|
||||
|
||||
MTL=midl.exe
|
||||
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
RSC=rc.exe
|
||||
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\mtest32.res" /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
BSC32_FLAGS=/nologo /o"$(OUTDIR)\mapitest.bsc"
|
||||
BSC32_SBRS= \
|
||||
|
||||
LINK32=link.exe
|
||||
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\mapitest.pdb" /debug /machine:I386 /out:"$(OUTDIR)\mapitest.exe" /pdbtype:sept
|
||||
LINK32_OBJS= \
|
||||
"$(INTDIR)\main.obj" \
|
||||
"$(INTDIR)\mapimail.obj" \
|
||||
"$(INTDIR)\mapiproc.obj" \
|
||||
"$(INTDIR)\readmail.obj" \
|
||||
"$(INTDIR)\mtest32.res"
|
||||
|
||||
"$(OUTDIR)\mapitest.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
|
||||
$(LINK32) @<<
|
||||
$(LINK32_FLAGS) $(LINK32_OBJS)
|
||||
<<
|
||||
|
||||
!ENDIF
|
||||
|
||||
|
||||
!IF "$(NO_EXTERNAL_DEPS)" != "1"
|
||||
!IF EXISTS("mapitest.dep")
|
||||
!INCLUDE "mapitest.dep"
|
||||
!ELSE
|
||||
!MESSAGE Warning: cannot find "mapitest.dep"
|
||||
!ENDIF
|
||||
!ENDIF
|
||||
|
||||
|
||||
!IF "$(CFG)" == "mapitest - Win32 Release" || "$(CFG)" == "mapitest - Win32 Debug"
|
||||
SOURCE=.\main.cpp
|
||||
|
||||
"$(INTDIR)\main.obj" : $(SOURCE) "$(INTDIR)"
|
||||
|
||||
|
||||
SOURCE=.\mapimail.cpp
|
||||
|
||||
"$(INTDIR)\mapimail.obj" : $(SOURCE) "$(INTDIR)"
|
||||
|
||||
|
||||
SOURCE=.\mapiproc.cpp
|
||||
|
||||
"$(INTDIR)\mapiproc.obj" : $(SOURCE) "$(INTDIR)"
|
||||
|
||||
|
||||
SOURCE=.\mtest32.rc
|
||||
|
||||
"$(INTDIR)\mtest32.res" : $(SOURCE) "$(INTDIR)"
|
||||
$(RSC) $(RSC_PROJ) $(SOURCE)
|
||||
|
||||
|
||||
SOURCE=.\readmail.cpp
|
||||
|
||||
"$(INTDIR)\readmail.obj" : $(SOURCE) "$(INTDIR)"
|
||||
|
||||
|
||||
|
||||
!ENDIF
|
||||
|
||||
772
mozilla/mailnews/mapi/old/tests/mapitest/mapimail.cpp
Normal file
772
mozilla/mailnews/mapi/old/tests/mapitest/mapimail.cpp
Normal file
@@ -0,0 +1,772 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <string.h>
|
||||
#include <mapi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "port.h"
|
||||
#include "resource.h"
|
||||
|
||||
//
|
||||
// Variables...
|
||||
//
|
||||
extern HINSTANCE m_hInstMapi;
|
||||
extern LHANDLE mapiSession;
|
||||
|
||||
//
|
||||
// Forward declarations...
|
||||
//
|
||||
void DoMAPIFreeBuffer(HWND hWnd, LPVOID buf, BOOL alert);
|
||||
extern void ShowMessage(HWND hWnd, LPSTR msg);
|
||||
void DoMAPISendMail(HWND hWnd);
|
||||
void DoMAPISendDocuments(HWND hWnd);
|
||||
void DoMAPISaveMail(HWND hWnd);
|
||||
void DoMAPIAddress(HWND hWnd);
|
||||
extern void SetFooter(LPSTR msg);
|
||||
extern LPSTR GetMAPIError(LONG errorCode);
|
||||
|
||||
void
|
||||
ProcessMailCommand(HWND hWnd, int id, HWND hCtl, UINT codeNotify)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case IDCANCEL:
|
||||
EndDialog(hWnd, 0);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_MAPISENDMAIL:
|
||||
DoMAPISendMail(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_MAPISENDDOCUMENTS:
|
||||
DoMAPISendDocuments(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_MAPISAVEMAIL:
|
||||
DoMAPISaveMail(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_MAPIADDRESS:
|
||||
DoMAPIAddress(hWnd);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CALLBACK LOADDS
|
||||
MailDlgProc(HWND hWndMain, UINT wMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (wMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
HANDLE_WM_COMMAND(hWndMain, wParam, lParam, ProcessMailCommand);
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static LPSTR lpszDelimChar = ";";
|
||||
|
||||
void
|
||||
TackItOn(LPSTR fileBuf, LPSTR nameBuf, LPSTR addOn)
|
||||
{
|
||||
if (addOn[0] != '\0')
|
||||
{
|
||||
lstrcat(fileBuf, addOn);
|
||||
lstrcat(fileBuf, lpszDelimChar);
|
||||
|
||||
lstrcat(nameBuf, "NAMEOF.FILE");
|
||||
lstrcat(nameBuf, lpszDelimChar);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPISendDocuments(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPISendDocuments) (ULONG ulUIParam,
|
||||
LPTSTR lpszDelimChar, LPTSTR lpszFullPaths,
|
||||
LPTSTR lpszFileNames, ULONG ulReserved);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPISendDocuments = GetProcAddress(m_hInstMapi, "MAPISENDDOCUMENTS");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPISendDocuments = GetProcAddress(m_hInstMapi, "MAPISendDocuments");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPISendDocuments)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
char msg[1024];
|
||||
char tempFileName[_MAX_PATH] = "";
|
||||
char lpszFullPaths[(_MAX_PATH + 1) * 4] = "";
|
||||
char lpszFileNames[(_MAX_PATH + 1) * 4] = "";
|
||||
|
||||
// Now get the names of the files to attach...
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH1, tempFileName, sizeof(tempFileName));
|
||||
TackItOn(lpszFullPaths, lpszFileNames, tempFileName);
|
||||
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH2, tempFileName, sizeof(tempFileName));
|
||||
TackItOn(lpszFullPaths, lpszFileNames, tempFileName);
|
||||
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH3, tempFileName, sizeof(tempFileName));
|
||||
TackItOn(lpszFullPaths, lpszFileNames, tempFileName);
|
||||
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH4, tempFileName, sizeof(tempFileName));
|
||||
TackItOn(lpszFullPaths, lpszFileNames, tempFileName);
|
||||
|
||||
LONG rc = (*lpfnMAPISendDocuments)
|
||||
( (ULONG) hWnd,
|
||||
lpszDelimChar,
|
||||
lpszFullPaths,
|
||||
lpszFileNames,
|
||||
0);
|
||||
|
||||
if (rc == SUCCESS_SUCCESS)
|
||||
{
|
||||
ShowMessage(hWnd, "Success with MAPISendDocuments");
|
||||
SetFooter("MAPISendDocuments success");
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from MAPISendDocuments\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("MAPISendDocuments failed");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FreeMAPIFile(lpMapiFileDesc pv)
|
||||
{
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
if (pv->lpszPathName != NULL)
|
||||
free(pv->lpszPathName);
|
||||
|
||||
if (pv->lpszFileName != NULL)
|
||||
free(pv->lpszFileName);
|
||||
}
|
||||
|
||||
void
|
||||
FreeMAPIRecipient(lpMapiRecipDesc pv)
|
||||
{
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
if (pv->lpszName != NULL)
|
||||
free(pv->lpszName);
|
||||
|
||||
if (pv->lpszAddress != NULL)
|
||||
free(pv->lpszAddress);
|
||||
|
||||
if (pv->lpEntryID != NULL)
|
||||
free(pv->lpEntryID);
|
||||
}
|
||||
|
||||
void
|
||||
FreeMAPIMessage(lpMapiMessage pv)
|
||||
{
|
||||
ULONG i;
|
||||
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
if (pv->lpszSubject != NULL)
|
||||
free(pv->lpszSubject);
|
||||
|
||||
if (pv->lpszNoteText)
|
||||
free(pv->lpszNoteText);
|
||||
|
||||
if (pv->lpszMessageType)
|
||||
free(pv->lpszMessageType);
|
||||
|
||||
if (pv->lpszDateReceived)
|
||||
free(pv->lpszDateReceived);
|
||||
|
||||
if (pv->lpszConversationID)
|
||||
free(pv->lpszConversationID);
|
||||
|
||||
if (pv->lpOriginator)
|
||||
FreeMAPIRecipient(pv->lpOriginator);
|
||||
|
||||
for (i=0; i<pv->nRecipCount; i++)
|
||||
{
|
||||
if (&(pv->lpRecips[i]) != NULL)
|
||||
{
|
||||
FreeMAPIRecipient(&(pv->lpRecips[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if (pv->lpRecips != NULL)
|
||||
{
|
||||
free(pv->lpRecips);
|
||||
}
|
||||
|
||||
for (i=0; i<pv->nFileCount; i++)
|
||||
{
|
||||
if (&(pv->lpFiles[i]) != NULL)
|
||||
{
|
||||
FreeMAPIFile(&(pv->lpFiles[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if (pv->lpFiles != NULL)
|
||||
{
|
||||
free(pv->lpFiles);
|
||||
}
|
||||
|
||||
free(pv);
|
||||
pv = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPISendMail(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPISendMail) (LHANDLE lhSession, ULONG ulUIParam,
|
||||
lpMapiMessage lpMessage, FLAGS flFlags, ULONG ulReserved);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPISendMail = GetProcAddress(m_hInstMapi, "MAPISENDMAIL");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPISendMail = GetProcAddress(m_hInstMapi, "MAPISendMail");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPISendMail)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
FLAGS flFlags = 0;
|
||||
char msg[512];
|
||||
char file1[_MAX_PATH] = "";
|
||||
char file2[_MAX_PATH] = "";
|
||||
char file3[_MAX_PATH] = "";
|
||||
char file4[_MAX_PATH] = "";
|
||||
char toAddr[128];
|
||||
char ccAddr[128];
|
||||
char bccAddr[128];
|
||||
char subject[128];
|
||||
char noteText[4096];
|
||||
char dateReceived[128] = "N/A";
|
||||
char threadID[128] = "N/A";;
|
||||
char origName[128] = "N/A";;
|
||||
char origAddress[128] = "N/A";;
|
||||
|
||||
GetDlgItemText(hWnd, ID_EDIT_TOADDRESS, toAddr, sizeof(toAddr));
|
||||
GetDlgItemText(hWnd, ID_EDIT_CCADDRESS, ccAddr, sizeof(ccAddr));
|
||||
GetDlgItemText(hWnd, ID_EDIT_BCCADDRESS, bccAddr, sizeof(bccAddr));
|
||||
GetDlgItemText(hWnd, ID_EDIT_SUBJECT, subject, sizeof(subject));
|
||||
GetDlgItemText(hWnd, ID_EDIT_NOTETEXT, noteText, sizeof(noteText));
|
||||
|
||||
// Do the one flag we support for this call...
|
||||
if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, ID_CHECK_SHOWDIALOG)))
|
||||
{
|
||||
flFlags |= MAPI_DIALOG;
|
||||
}
|
||||
|
||||
// Build the message to send off...
|
||||
lpMapiMessage msgPtr = (MapiMessage *)malloc(sizeof(MapiMessage));
|
||||
if (msgPtr == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memset(msgPtr, 0, sizeof(MapiMessage));
|
||||
|
||||
//
|
||||
// At this point, we need to populate the structure of information
|
||||
// we are passing in via the *lppMessage
|
||||
//
|
||||
|
||||
// Set all of the general information first!
|
||||
msgPtr->lpszSubject = strdup(subject);
|
||||
msgPtr->lpszNoteText = strdup(noteText);
|
||||
msgPtr->lpszDateReceived = strdup(dateReceived);
|
||||
msgPtr->lpszConversationID = strdup(threadID);
|
||||
msgPtr->flFlags = flFlags;
|
||||
|
||||
// Now deal with the recipients of this message
|
||||
DWORD realRecips = 0;
|
||||
if (toAddr[0] != '\0') ++realRecips;
|
||||
if (ccAddr[0] != '\0') ++realRecips;
|
||||
if (bccAddr[0] != '\0') ++realRecips;
|
||||
|
||||
msgPtr->lpRecips = (lpMapiRecipDesc) malloc((size_t) (sizeof(MapiRecipDesc) * realRecips));
|
||||
if (!msgPtr->lpRecips)
|
||||
{
|
||||
FreeMAPIMessage(msgPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
msgPtr->nRecipCount = realRecips;
|
||||
memset(msgPtr->lpRecips, 0, (size_t) (sizeof(MapiRecipDesc) * msgPtr->nRecipCount));
|
||||
|
||||
DWORD rCount = 0;
|
||||
if (toAddr[0] != '\0')
|
||||
{
|
||||
msgPtr->lpRecips[rCount].lpszName = strdup(toAddr);
|
||||
msgPtr->lpRecips[rCount].lpszAddress = strdup(toAddr);
|
||||
msgPtr->lpRecips[rCount].ulRecipClass = MAPI_TO;
|
||||
rCount++;
|
||||
}
|
||||
|
||||
if (ccAddr[0] != '\0')
|
||||
{
|
||||
msgPtr->lpRecips[rCount].lpszName = strdup(ccAddr);
|
||||
msgPtr->lpRecips[rCount].lpszAddress = strdup(ccAddr);
|
||||
msgPtr->lpRecips[rCount].ulRecipClass = MAPI_CC;
|
||||
rCount++;
|
||||
}
|
||||
|
||||
if (bccAddr[0] != '\0')
|
||||
{
|
||||
msgPtr->lpRecips[rCount].lpszName = strdup(bccAddr);
|
||||
msgPtr->lpRecips[rCount].lpszAddress = strdup(bccAddr);
|
||||
msgPtr->lpRecips[rCount].ulRecipClass = MAPI_BCC;
|
||||
rCount++;
|
||||
}
|
||||
|
||||
// Now get the names of the files to attach...
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH1, file1, sizeof(file1));
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH2, file2, sizeof(file2));
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH3, file3, sizeof(file3));
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH4, file4, sizeof(file4));
|
||||
|
||||
DWORD realFiles = 0;
|
||||
if (file1[0] != '\0') ++realFiles;
|
||||
if (file2[0] != '\0') ++realFiles;
|
||||
if (file3[0] != '\0') ++realFiles;
|
||||
if (file4[0] != '\0') ++realFiles;
|
||||
|
||||
// Now deal with the list of attachments! Since the nFileCount should be set
|
||||
// correctly, this loop will automagically be correct
|
||||
//
|
||||
msgPtr->nFileCount = realFiles;
|
||||
if (realFiles > 0)
|
||||
{
|
||||
msgPtr->lpFiles = (lpMapiFileDesc) malloc((size_t) (sizeof(MapiFileDesc) * realFiles));
|
||||
if (!msgPtr->lpFiles)
|
||||
{
|
||||
FreeMAPIMessage(msgPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(msgPtr->lpFiles, 0, (size_t) (sizeof(MapiFileDesc) * msgPtr->nFileCount));
|
||||
}
|
||||
|
||||
rCount = 0;
|
||||
if (file1[0] != '\0')
|
||||
{
|
||||
msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file1);
|
||||
msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file1);
|
||||
++rCount;
|
||||
}
|
||||
|
||||
if (file2[0] != '\0')
|
||||
{
|
||||
msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file2);
|
||||
msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file2);
|
||||
++rCount;
|
||||
}
|
||||
|
||||
if (file3[0] != '\0')
|
||||
{
|
||||
msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file3);
|
||||
msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file3);
|
||||
++rCount;
|
||||
}
|
||||
|
||||
if (file4[0] != '\0')
|
||||
{
|
||||
msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file4);
|
||||
msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file4);
|
||||
++rCount;
|
||||
}
|
||||
|
||||
// Finally, make the call...
|
||||
LONG rc = (*lpfnMAPISendMail)
|
||||
(mapiSession,
|
||||
(ULONG) hWnd,
|
||||
msgPtr,
|
||||
flFlags,
|
||||
0);
|
||||
|
||||
if (rc == SUCCESS_SUCCESS)
|
||||
{
|
||||
ShowMessage(hWnd, "Success with MAPISendMail");
|
||||
SetFooter("MAPISendMail success");
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from MAPISendMail\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("MAPISendMail failed");
|
||||
}
|
||||
|
||||
// Now cleanup and move on...
|
||||
FreeMAPIMessage(msgPtr);
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPISaveMail(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPISaveMail) (LHANDLE lhSession, ULONG ulUIParam,
|
||||
lpMapiMessage lpMessage, FLAGS flFlags, ULONG ulReserved,
|
||||
LPTSTR lpszMessageID);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPISaveMail = GetProcAddress(m_hInstMapi, "MAPISAVEMAIL");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPISaveMail = GetProcAddress(m_hInstMapi, "MAPISaveMail");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPISaveMail)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
FLAGS flFlags = 0;
|
||||
char msg[512];
|
||||
char file1[_MAX_PATH] = "";
|
||||
char file2[_MAX_PATH] = "";
|
||||
char file3[_MAX_PATH] = "";
|
||||
char file4[_MAX_PATH] = "";
|
||||
char toAddr[128];
|
||||
char ccAddr[128];
|
||||
char bccAddr[128];
|
||||
char subject[128];
|
||||
char noteText[4096];
|
||||
char dateReceived[128] = "N/A";
|
||||
char threadID[128] = "N/A";;
|
||||
char origName[128] = "N/A";;
|
||||
char origAddress[128] = "N/A";;
|
||||
|
||||
GetDlgItemText(hWnd, ID_EDIT_TOADDRESS, toAddr, sizeof(toAddr));
|
||||
GetDlgItemText(hWnd, ID_EDIT_CCADDRESS, ccAddr, sizeof(ccAddr));
|
||||
GetDlgItemText(hWnd, ID_EDIT_BCCADDRESS, bccAddr, sizeof(bccAddr));
|
||||
GetDlgItemText(hWnd, ID_EDIT_SUBJECT, subject, sizeof(subject));
|
||||
GetDlgItemText(hWnd, ID_EDIT_NOTETEXT, noteText, sizeof(noteText));
|
||||
|
||||
// Build the message to send off...
|
||||
lpMapiMessage msgPtr = (MapiMessage *)malloc(sizeof(MapiMessage));
|
||||
if (msgPtr == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memset(msgPtr, 0, sizeof(MapiMessage));
|
||||
|
||||
//
|
||||
// At this point, we need to populate the structure of information
|
||||
// we are passing in via the *lppMessage
|
||||
//
|
||||
|
||||
// Set all of the general information first!
|
||||
msgPtr->lpszSubject = strdup(subject);
|
||||
msgPtr->lpszNoteText = strdup(noteText);
|
||||
msgPtr->lpszDateReceived = strdup(dateReceived);
|
||||
msgPtr->lpszConversationID = strdup(threadID);
|
||||
msgPtr->flFlags = flFlags;
|
||||
|
||||
// Now deal with the recipients of this message
|
||||
DWORD realRecips = 0;
|
||||
if (toAddr[0] != '\0') ++realRecips;
|
||||
if (ccAddr[0] != '\0') ++realRecips;
|
||||
if (bccAddr[0] != '\0') ++realRecips;
|
||||
|
||||
msgPtr->lpRecips = (lpMapiRecipDesc) malloc((size_t) (sizeof(MapiRecipDesc) * realRecips));
|
||||
if (!msgPtr->lpRecips)
|
||||
{
|
||||
FreeMAPIMessage(msgPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
msgPtr->nRecipCount = realRecips;
|
||||
memset(msgPtr->lpRecips, 0, (size_t) (sizeof(MapiRecipDesc) * msgPtr->nRecipCount));
|
||||
|
||||
DWORD rCount = 0;
|
||||
if (toAddr[0] != '\0')
|
||||
{
|
||||
msgPtr->lpRecips[rCount].lpszName = strdup(toAddr);
|
||||
msgPtr->lpRecips[rCount].lpszAddress = strdup(toAddr);
|
||||
msgPtr->lpRecips[rCount].ulRecipClass = MAPI_TO;
|
||||
rCount++;
|
||||
}
|
||||
|
||||
if (ccAddr[0] != '\0')
|
||||
{
|
||||
msgPtr->lpRecips[rCount].lpszName = strdup(ccAddr);
|
||||
msgPtr->lpRecips[rCount].lpszAddress = strdup(ccAddr);
|
||||
msgPtr->lpRecips[rCount].ulRecipClass = MAPI_CC;
|
||||
rCount++;
|
||||
}
|
||||
|
||||
if (bccAddr[0] != '\0')
|
||||
{
|
||||
msgPtr->lpRecips[rCount].lpszName = strdup(bccAddr);
|
||||
msgPtr->lpRecips[rCount].lpszAddress = strdup(bccAddr);
|
||||
msgPtr->lpRecips[rCount].ulRecipClass = MAPI_BCC;
|
||||
rCount++;
|
||||
}
|
||||
|
||||
// Now get the names of the files to attach...
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH1, file1, sizeof(file1));
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH2, file2, sizeof(file2));
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH3, file3, sizeof(file3));
|
||||
GetDlgItemText(hWnd, ID_EDIT_ATTACH4, file4, sizeof(file4));
|
||||
|
||||
DWORD realFiles = 0;
|
||||
if (file1[0] != '\0') ++realFiles;
|
||||
if (file2[0] != '\0') ++realFiles;
|
||||
if (file3[0] != '\0') ++realFiles;
|
||||
if (file4[0] != '\0') ++realFiles;
|
||||
|
||||
// Now deal with the list of attachments! Since the nFileCount should be set
|
||||
// correctly, this loop will automagically be correct
|
||||
//
|
||||
msgPtr->nFileCount = realFiles;
|
||||
if (realFiles > 0)
|
||||
{
|
||||
msgPtr->lpFiles = (lpMapiFileDesc) malloc((size_t) (sizeof(MapiFileDesc) * realFiles));
|
||||
if (!msgPtr->lpFiles)
|
||||
{
|
||||
FreeMAPIMessage(msgPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(msgPtr->lpFiles, 0, (size_t) (sizeof(MapiFileDesc) * msgPtr->nFileCount));
|
||||
}
|
||||
|
||||
rCount = 0;
|
||||
if (file1[0] != '\0')
|
||||
{
|
||||
msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file1);
|
||||
msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file1);
|
||||
++rCount;
|
||||
}
|
||||
|
||||
if (file2[0] != '\0')
|
||||
{
|
||||
msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file2);
|
||||
msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file2);
|
||||
++rCount;
|
||||
}
|
||||
|
||||
if (file3[0] != '\0')
|
||||
{
|
||||
msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file3);
|
||||
msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file3);
|
||||
++rCount;
|
||||
}
|
||||
|
||||
if (file4[0] != '\0')
|
||||
{
|
||||
msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file4);
|
||||
msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file4);
|
||||
++rCount;
|
||||
}
|
||||
|
||||
// Finally, make the call...
|
||||
LONG rc = (*lpfnMAPISaveMail)
|
||||
(mapiSession,
|
||||
(ULONG) hWnd,
|
||||
msgPtr,
|
||||
flFlags,
|
||||
0, NULL);
|
||||
|
||||
if (rc == SUCCESS_SUCCESS)
|
||||
{
|
||||
ShowMessage(hWnd, "Success with MAPISaveMail");
|
||||
SetFooter("MAPISaveMail success");
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from MAPISaveMail\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("MAPISaveMail failed");
|
||||
}
|
||||
|
||||
// Now cleanup and move on...
|
||||
FreeMAPIMessage(msgPtr);
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPIAddress(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPIAddress)
|
||||
(LHANDLE lhSession,
|
||||
ULONG ulUIParam,
|
||||
LPSTR lpszCaption,
|
||||
ULONG nEditFields,
|
||||
LPSTR lpszLabels,
|
||||
ULONG nRecips,
|
||||
lpMapiRecipDesc lpRecips,
|
||||
FLAGS flFlags,
|
||||
ULONG ulReserved,
|
||||
LPULONG lpnNewRecips,
|
||||
lpMapiRecipDesc FAR *lppNewRecips);
|
||||
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPIAddress = GetProcAddress(m_hInstMapi, "MAPIADDRESS");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPIAddress = GetProcAddress(m_hInstMapi, "MAPIAddress");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPIAddress)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD i;
|
||||
FLAGS flFlags = 0;
|
||||
DWORD addrCount = 0;
|
||||
char msg[512];
|
||||
char toAddr[128];
|
||||
char ccAddr[128];
|
||||
char bccAddr[128];
|
||||
|
||||
GetDlgItemText(hWnd, ID_EDIT_TOADDRESS, toAddr, sizeof(toAddr));
|
||||
GetDlgItemText(hWnd, ID_EDIT_CCADDRESS, ccAddr, sizeof(ccAddr));
|
||||
GetDlgItemText(hWnd, ID_EDIT_BCCADDRESS, bccAddr, sizeof(bccAddr));
|
||||
|
||||
if (toAddr[0]) ++addrCount;
|
||||
if (ccAddr[0]) ++addrCount;
|
||||
if (bccAddr[0]) ++addrCount;
|
||||
|
||||
lpMapiRecipDesc lpRecips = (lpMapiRecipDesc) malloc((size_t) (sizeof(MapiRecipDesc) * addrCount));
|
||||
if (!lpRecips)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
memset(lpRecips, 0, (size_t) (sizeof(MapiRecipDesc) * addrCount));
|
||||
|
||||
DWORD rCount = 0;
|
||||
if (toAddr[0] != '\0')
|
||||
{
|
||||
lpRecips[rCount].lpszName = strdup("To Address Name");
|
||||
lpRecips[rCount].lpszAddress = strdup(toAddr);
|
||||
lpRecips[rCount].ulRecipClass = MAPI_TO;
|
||||
rCount++;
|
||||
}
|
||||
|
||||
if (ccAddr[0] != '\0')
|
||||
{
|
||||
lpRecips[rCount].lpszName = strdup("CC Address Name");
|
||||
lpRecips[rCount].lpszAddress = strdup(ccAddr);
|
||||
lpRecips[rCount].ulRecipClass = MAPI_CC;
|
||||
rCount++;
|
||||
}
|
||||
|
||||
if (bccAddr[0] != '\0')
|
||||
{
|
||||
lpRecips[rCount].lpszName = strdup("BCC Address Name");
|
||||
lpRecips[rCount].lpszAddress = strdup(bccAddr);
|
||||
lpRecips[rCount].ulRecipClass = MAPI_BCC;
|
||||
rCount++;
|
||||
}
|
||||
|
||||
ULONG newRecips;
|
||||
lpMapiRecipDesc lpNewRecips;
|
||||
|
||||
// Finally, make the call...
|
||||
LONG rc = (*lpfnMAPIAddress)
|
||||
(mapiSession,
|
||||
0,
|
||||
"MAPI Test Address Picker",
|
||||
0,
|
||||
NULL,
|
||||
rCount,
|
||||
lpRecips,
|
||||
0,
|
||||
0,
|
||||
&newRecips,
|
||||
&lpNewRecips);
|
||||
if (rc == SUCCESS_SUCCESS)
|
||||
{
|
||||
for (i=0; i<newRecips; i++)
|
||||
{
|
||||
char tMsg[512];
|
||||
|
||||
wsprintf(tMsg, "User %d\nName=[%s]\nEmail=[%s]\nType=[%d]",
|
||||
i,
|
||||
lpNewRecips[i].lpszName,
|
||||
lpNewRecips[i].lpszAddress,
|
||||
lpNewRecips[i].ulRecipClass);
|
||||
ShowMessage(hWnd, tMsg);
|
||||
}
|
||||
|
||||
SetFooter("MAPIAddress success");
|
||||
|
||||
DoMAPIFreeBuffer(hWnd, lpNewRecips, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from MAPIAddress\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("MAPIAddress failed");
|
||||
}
|
||||
|
||||
// Now cleanup and move on...
|
||||
for (i=0; i<rCount; i++)
|
||||
{
|
||||
FreeMAPIRecipient(&(lpRecips[i]));
|
||||
}
|
||||
}
|
||||
832
mozilla/mailnews/mapi/old/tests/mapitest/mapiproc.cpp
Normal file
832
mozilla/mailnews/mapi/old/tests/mapitest/mapiproc.cpp
Normal file
@@ -0,0 +1,832 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef MAPI_OLE // Because MSFT doesn't do this for us :-(
|
||||
#include <mapi.h>
|
||||
#endif
|
||||
|
||||
#include "port.h"
|
||||
#include "resource.h"
|
||||
|
||||
//
|
||||
// Variables...
|
||||
//
|
||||
extern HINSTANCE hInst;
|
||||
HINSTANCE m_hInstMapi;
|
||||
LHANDLE mapiSession = 0;
|
||||
|
||||
//
|
||||
// Forward declarations...
|
||||
//
|
||||
void LoadNSCPVersionFunc(HWND hWnd);
|
||||
void DoMAPILogon(HWND hWnd);
|
||||
void DoMAPILogoff(HWND hWnd);
|
||||
void DoMAPIFreeBuffer(HWND hWnd, LPVOID buf, BOOL alert);
|
||||
void DoMAPISendMail(HWND hWnd);
|
||||
void DoMAPISendDocuments(HWND hWnd);
|
||||
void DoMAPIFindNext(HWND hWnd);
|
||||
void DoMAPIReadMail(HWND hWnd);
|
||||
void DoMAPIDeleteMail(HWND hWnd);
|
||||
void DoMAPIDetails(HWND hWnd);
|
||||
void DoMAPIResolveName(HWND hWnd);
|
||||
void DoMAPIResolveNameFreeBuffer(HWND hWnd);
|
||||
void SetFooter(LPSTR msg);
|
||||
void DoMAPI_NSCP_Sync(HWND hWnd);
|
||||
LPSTR GetMAPIError(LONG errorCode);
|
||||
extern void DisplayMAPIReadMail(HWND hWnd, lpMapiMessage msgPtr);
|
||||
lpMapiMessage GetMessage(HWND hWnd, LPSTR id);
|
||||
|
||||
void
|
||||
SetFooter(LPSTR msg)
|
||||
{
|
||||
extern HWND hWnd;
|
||||
|
||||
SetDlgItemText(hWnd, ID_STATIC_RESULT, msg);
|
||||
}
|
||||
|
||||
char FAR *
|
||||
GetMAPIError(LONG errorCode)
|
||||
{
|
||||
static char FAR msg[128];
|
||||
|
||||
switch (errorCode) {
|
||||
case MAPI_E_FAILURE:
|
||||
lstrcpy(msg, "General MAPI Failure");
|
||||
break;
|
||||
|
||||
case MAPI_E_INSUFFICIENT_MEMORY:
|
||||
strcpy(msg, "Insufficient Memory");
|
||||
break;
|
||||
|
||||
case MAPI_E_LOGIN_FAILURE:
|
||||
strcpy(msg, "Login Failure");
|
||||
break;
|
||||
|
||||
case MAPI_E_TOO_MANY_SESSIONS:
|
||||
strcpy(msg, "Too many MAPI sessions");
|
||||
break;
|
||||
|
||||
case MAPI_E_INVALID_SESSION:
|
||||
strcpy(msg, "Invalid Session!");
|
||||
break;
|
||||
|
||||
case MAPI_E_INVALID_MESSAGE:
|
||||
strcpy(msg, "Message identifier was bad!");
|
||||
break;
|
||||
|
||||
case MAPI_E_NO_MESSAGES:
|
||||
strcpy(msg, "No messages were found!");
|
||||
break;
|
||||
|
||||
case MAPI_E_ATTACHMENT_WRITE_FAILURE:
|
||||
strcpy(msg, "Attachment write failure!");
|
||||
break;
|
||||
|
||||
case MAPI_E_DISK_FULL:
|
||||
strcpy(msg, "Attachment write failure! DISK FULL");
|
||||
break;
|
||||
|
||||
case MAPI_E_AMBIGUOUS_RECIPIENT:
|
||||
strcpy(msg, "Recipient requested is not a unique address list entry.");
|
||||
break;
|
||||
|
||||
case MAPI_E_UNKNOWN_RECIPIENT:
|
||||
strcpy(msg, "Recipient requested does not exist.");
|
||||
break;
|
||||
|
||||
case MAPI_E_NOT_SUPPORTED:
|
||||
strcpy(msg, "Not supported by messaging system");
|
||||
break;
|
||||
|
||||
case SUCCESS_SUCCESS:
|
||||
strcpy(msg, "Success on MAPI operation");
|
||||
break;
|
||||
|
||||
case MAPI_E_INVALID_RECIPS:
|
||||
strcpy(msg, "Recipient specified in the lpRecip parameter was\nunknown. No dialog box was displayed.");
|
||||
break;
|
||||
|
||||
case MAPI_E_ATTACHMENT_OPEN_FAILURE:
|
||||
strcpy(msg, "One or more files could not be located. No message was sent.");
|
||||
break;
|
||||
|
||||
case MAPI_E_ATTACHMENT_NOT_FOUND:
|
||||
strcpy(msg, "The specified attachment was not found. No message was sent.");
|
||||
break;
|
||||
|
||||
case MAPI_E_BAD_RECIPTYPE:
|
||||
strcpy(msg, "The type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC. No message was sent.");
|
||||
break;
|
||||
|
||||
default:
|
||||
strcpy(msg, "Unknown MAPI Return Code");
|
||||
break;
|
||||
}
|
||||
|
||||
return((LPSTR) &(msg[0]));
|
||||
}
|
||||
|
||||
void
|
||||
ShowMessage(HWND hWnd, LPSTR msg)
|
||||
{
|
||||
MessageBox(hWnd, msg, "Info Message", MB_ICONINFORMATION);
|
||||
}
|
||||
|
||||
BOOL
|
||||
OpenMAPI(void)
|
||||
{
|
||||
#ifdef WIN16
|
||||
m_hInstMapi = LoadLibrary("Y:\\ns\\cmd\\winfe\\mapi\\MAPI.DLL");
|
||||
#else
|
||||
m_hInstMapi = LoadLibrary(".\\COMPONENTS\\MAPI32.DLL");
|
||||
#endif
|
||||
|
||||
if (!m_hInstMapi)
|
||||
{
|
||||
ShowMessage(NULL, "Error Loading the MAPI DLL...Probably not found!");
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
CloseMAPI(void)
|
||||
{
|
||||
if(m_hInstMapi)
|
||||
{
|
||||
FreeLibrary(m_hInstMapi);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ProcessCommand(HWND hWnd, int id, HWND hCtl, UINT codeNotify)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case ID_BUTTON_SYNC:
|
||||
DoMAPI_NSCP_Sync(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_NSCPVERSION:
|
||||
LoadNSCPVersionFunc(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_LOGON:
|
||||
DoMAPILogon(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_LOGOFF:
|
||||
DoMAPILogoff(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_FINDNEXT:
|
||||
case ID_MENU_MAPIFINDNEXT:
|
||||
DoMAPIFindNext(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_READMAIL:
|
||||
case ID_MENU_MAPIREADMAIL:
|
||||
DoMAPIReadMail(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_MAIL:
|
||||
{
|
||||
extern CALLBACK LOADDS
|
||||
MailDlgProc(HWND hWndMain, UINT wMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
DialogBox(hInst, MAKEINTRESOURCE(ID_DIALOG_MAIL), hWnd,
|
||||
(DLGPROC)MailDlgProc);
|
||||
}
|
||||
break;
|
||||
|
||||
case ID_BUTTON_DELETEMAIL:
|
||||
case ID_MENU_MAPIDELETEMAIL:
|
||||
DoMAPIDeleteMail(hWnd);
|
||||
break;
|
||||
|
||||
case ID_MENU_MYEXIT:
|
||||
DestroyWindow(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_CLEAR:
|
||||
case ID_MENU_CLEARRESULTS:
|
||||
ListBox_ResetContent(GetDlgItem(hWnd, ID_LIST_RESULT));
|
||||
break;
|
||||
|
||||
case ID_BUTTON_FREEBUFFER:
|
||||
DoMAPIResolveNameFreeBuffer(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_RESOLVENAME:
|
||||
DoMAPIResolveName(hWnd);
|
||||
break;
|
||||
|
||||
case ID_BUTTON_DETAILS:
|
||||
DoMAPIDetails(hWnd);
|
||||
break;
|
||||
|
||||
case ID_MENU_MYABOUT:
|
||||
MessageBox(hWnd,
|
||||
"Netscape MAPI Test Harness\nWritten by: Rich Pizzarro (rhp@netscape.com)",
|
||||
"About",
|
||||
MB_ICONINFORMATION);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPILogon(HWND hWnd)
|
||||
{
|
||||
char msg[1024];
|
||||
char user[128] = "";
|
||||
char pw[128] = "";
|
||||
|
||||
// Get Address of MAPI function...
|
||||
ULONG (FAR PASCAL *lpfnMAPILogon)(ULONG, LPSTR, LPSTR, FLAGS, ULONG, LPLHANDLE);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPILogon = GetProcAddress(m_hInstMapi, "MAPILOGON");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPILogon = GetProcAddress(m_hInstMapi, "MAPILogon");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPILogon)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
GetDlgItemText(hWnd, ID_EDIT_USERNAME, user, sizeof(user));
|
||||
GetDlgItemText(hWnd, ID_EDIT_PW, pw, sizeof(pw));
|
||||
|
||||
LONG rc = (*lpfnMAPILogon)((ULONG) hWnd, user, pw,
|
||||
MAPI_FORCE_DOWNLOAD | MAPI_NEW_SESSION, 0, &mapiSession);
|
||||
if (rc == SUCCESS_SUCCESS)
|
||||
{
|
||||
wsprintf(msg, "Success with session = %d", mapiSession);
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("Logon success");
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from Logon\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("Logon failed");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPILogoff(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPILogoff) ( LHANDLE lhSession, ULONG ulUIParam,
|
||||
FLAGS flFlags, ULONG ulReserved);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPILogoff = GetProcAddress(m_hInstMapi, "MAPILOGOFF");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPILogoff = GetProcAddress(m_hInstMapi, "MAPILogoff");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPILogoff)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
char msg[1024];
|
||||
LONG rc = (*lpfnMAPILogoff)(mapiSession, (ULONG) hWnd, 0, 0);
|
||||
if (rc == SUCCESS_SUCCESS)
|
||||
{
|
||||
wsprintf(msg, "Successful logoff");
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from Logoff\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("Logoff failed");
|
||||
}
|
||||
|
||||
mapiSession = 0;
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPIFreeBuffer(HWND hWnd, LPVOID buf, BOOL alert)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPIFreeBuffer) (LPVOID lpBuffer);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPIFreeBuffer = GetProcAddress(m_hInstMapi, "MAPIFREEBUFFER");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPIFreeBuffer = GetProcAddress(m_hInstMapi, "MAPIFreeBuffer");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPIFreeBuffer)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
char msg[1024];
|
||||
LONG rc = (*lpfnMAPIFreeBuffer)(buf);
|
||||
#ifdef WIN32
|
||||
if (rc == S_OK)
|
||||
#else
|
||||
if (rc == SUCCESS_SUCCESS)
|
||||
#endif
|
||||
{
|
||||
wsprintf(msg, "Successful Free Buffer Operation");
|
||||
if (alert)
|
||||
ShowMessage(hWnd, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from Logoff", rc);
|
||||
ShowMessage(hWnd, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPIFindNext(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPIFindNext) (LHANDLE lhSession, ULONG ulUIParam,
|
||||
LPTSTR lpszMessageType, LPTSTR lpszSeedMessageID, FLAGS flFlags,
|
||||
ULONG ulReserved, LPTSTR lpszMessageID);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPIFindNext = GetProcAddress(m_hInstMapi, "MAPIFINDNEXT");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPIFindNext = GetProcAddress(m_hInstMapi, "MAPIFindNext");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPIFindNext)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear the list before we start...
|
||||
ListBox_ResetContent(GetDlgItem(hWnd, ID_LIST_RESULT));
|
||||
|
||||
char msg[1024];
|
||||
char messageID[512];
|
||||
LONG rc;
|
||||
#ifdef WIN32
|
||||
FLAGS flags = MAPI_GUARANTEE_FIFO | MAPI_LONG_MSGID | MAPI_UNREAD_ONLY;
|
||||
#else
|
||||
FLAGS flags = MAPI_GUARANTEE_FIFO | MAPI_UNREAD_ONLY;
|
||||
#endif
|
||||
|
||||
while ( (rc = (*lpfnMAPIFindNext) (mapiSession,
|
||||
(ULONG) hWnd,
|
||||
NULL,
|
||||
NULL,
|
||||
flags,
|
||||
0,
|
||||
messageID)) == SUCCESS_SUCCESS)
|
||||
{
|
||||
//
|
||||
|
||||
lpMapiMessage mapiMsg = GetMessage(hWnd, messageID);
|
||||
if (mapiMsg != NULL)
|
||||
{
|
||||
wsprintf(msg, "%s: \"%s\" Sender: %s",
|
||||
messageID,
|
||||
mapiMsg->lpszSubject,
|
||||
mapiMsg->lpOriginator->lpszName);
|
||||
DoMAPIFreeBuffer(hWnd, mapiMsg, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
lstrcpy(msg, messageID);
|
||||
}
|
||||
|
||||
ListBox_InsertString(GetDlgItem(hWnd, ID_LIST_RESULT), 0, msg);
|
||||
}
|
||||
|
||||
wsprintf(msg, "Enumeration ended: Return code %d from MAPIFindNext\nCondition=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("Enumeration ended");
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPIReadMail(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPIReadMail) (LHANDLE lhSession, ULONG ulUIParam,
|
||||
LPTSTR lpszMessageID, FLAGS flFlags, ULONG ulReserved,
|
||||
lpMapiMessage FAR * lppMessage);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPIReadMail = GetProcAddress(m_hInstMapi, "MAPIREADMAIL");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPIReadMail = GetProcAddress(m_hInstMapi, "MAPIReadMail");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPIReadMail)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
char msg[1024];
|
||||
char lpszMessageID[512];
|
||||
lpMapiMessage lpMessage = NULL;
|
||||
FLAGS flFlags = 0;
|
||||
|
||||
DWORD selected = ListBox_GetCurSel(GetDlgItem(hWnd, ID_LIST_RESULT));
|
||||
if (selected == LB_ERR)
|
||||
{
|
||||
ShowMessage(hWnd, "You need to select a valid message. Make sure\nyou have done a MAPIFindNext and selected\none of the resulting messages.");
|
||||
return;
|
||||
}
|
||||
|
||||
ListBox_GetText(GetDlgItem(hWnd, ID_LIST_RESULT), selected, lpszMessageID);
|
||||
|
||||
// Do the various flags for this call...
|
||||
if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, IDC_CHECK_BODYASFILE)))
|
||||
{
|
||||
flFlags |= MAPI_BODY_AS_FILE;
|
||||
}
|
||||
|
||||
if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, IDC_CHECK_ENVELOPEONLY)))
|
||||
{
|
||||
flFlags |= MAPI_ENVELOPE_ONLY;
|
||||
}
|
||||
|
||||
if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, IDC_CHECK_PEEK)))
|
||||
{
|
||||
flFlags |= MAPI_PEEK;
|
||||
}
|
||||
|
||||
if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, IDC_CHECK_SUPPRESSATTACH)))
|
||||
{
|
||||
flFlags |= MAPI_SUPPRESS_ATTACH;
|
||||
}
|
||||
|
||||
char *ptr = strchr( (const char *) lpszMessageID, ':');
|
||||
if (ptr) *ptr = '\0';
|
||||
|
||||
LONG rc = (*lpfnMAPIReadMail)
|
||||
(mapiSession,
|
||||
(ULONG) hWnd,
|
||||
lpszMessageID,
|
||||
flFlags,
|
||||
0,
|
||||
&lpMessage);
|
||||
|
||||
// Deal with error up front and return if need be...
|
||||
if (rc != SUCCESS_SUCCESS)
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from MAPIReadMail\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("ReadMail failed");
|
||||
return;
|
||||
}
|
||||
|
||||
// Now display the message and then return...
|
||||
DisplayMAPIReadMail(hWnd, lpMessage);
|
||||
DoMAPIFreeBuffer(hWnd, lpMessage, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPIDeleteMail(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPIDeleteMail) (LHANDLE lhSession, ULONG ulUIParam,
|
||||
LPTSTR lpszMessageID, FLAGS flFlags, ULONG ulReserved);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPIDeleteMail = GetProcAddress(m_hInstMapi, "MAPIDELETEMAIL");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPIDeleteMail = GetProcAddress(m_hInstMapi, "MAPIDeleteMail");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPIDeleteMail)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
char msg[1024];
|
||||
char lpszMessageID[512];
|
||||
lpMapiMessage lpMessage = NULL;
|
||||
|
||||
DWORD selected = ListBox_GetCurSel(GetDlgItem(hWnd, ID_LIST_RESULT));
|
||||
if (selected == LB_ERR)
|
||||
{
|
||||
ShowMessage(hWnd, "You need to select a valid message. Make sure\nyou have done a MAPIFindNext and selected\none of the resulting messages.");
|
||||
return;
|
||||
}
|
||||
|
||||
ListBox_GetText(GetDlgItem(hWnd, ID_LIST_RESULT), selected, lpszMessageID);
|
||||
|
||||
char *ptr = strchr( (const char *) lpszMessageID, ':');
|
||||
if (ptr) *ptr = '\0';
|
||||
|
||||
LONG rc = (*lpfnMAPIDeleteMail)
|
||||
(mapiSession,
|
||||
(ULONG) hWnd,
|
||||
lpszMessageID,
|
||||
0,
|
||||
0);
|
||||
|
||||
// Deal with the return code...
|
||||
if (rc == SUCCESS_SUCCESS)
|
||||
{
|
||||
wsprintf(msg, "Successful deletion");
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter(msg);
|
||||
|
||||
// If it worked, refresh the list...
|
||||
ShowMessage(hWnd, "The message list will now be refreshed\nsince one message was deleted.");
|
||||
DoMAPIFindNext(hWnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from MAPIDeleteMail\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("Logoff failed");
|
||||
}
|
||||
}
|
||||
|
||||
// This is for the name lookup stuff...
|
||||
lpMapiRecipDesc lpRecip = NULL;
|
||||
|
||||
void
|
||||
DoMAPIResolveName(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPIResolveName) (LHANDLE lhSession, ULONG ulUIParam,
|
||||
LPTSTR lpszName, FLAGS flFlags, ULONG ulReserved,
|
||||
lpMapiRecipDesc FAR * lppRecip);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPIResolveName = GetProcAddress(m_hInstMapi, "MAPIRESOLVENAME");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPIResolveName = GetProcAddress(m_hInstMapi, "MAPIResolveName");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPIResolveName)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (lpRecip != NULL)
|
||||
{
|
||||
ShowMessage(hWnd, "We need to free memory from a previous call...");
|
||||
DoMAPIFreeBuffer(hWnd, lpRecip, TRUE);
|
||||
lpRecip = NULL;
|
||||
}
|
||||
|
||||
char userName[512];
|
||||
char msg[1024];
|
||||
FLAGS flFlags = 0; // We support none...
|
||||
|
||||
GetDlgItemText(hWnd, IDC_EDIT_RESOLVENAME, userName, sizeof(userName));
|
||||
LONG rc = (*lpfnMAPIResolveName)
|
||||
(mapiSession,
|
||||
(ULONG) hWnd,
|
||||
userName,
|
||||
flFlags,
|
||||
0,
|
||||
&lpRecip);
|
||||
|
||||
// Deal with error up front and return if need be...
|
||||
if (rc != SUCCESS_SUCCESS)
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from DoMAPIResolveName\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("DoMAPIResolveName failed");
|
||||
return;
|
||||
}
|
||||
|
||||
// If we get here, we should probably show the information that we
|
||||
// got back
|
||||
wsprintf(msg, "Received information for %s\nName=[%s]\nAddress=[%s]\nID=[%s]",
|
||||
userName, lpRecip->lpszName, lpRecip->lpszAddress, (LPSTR) lpRecip->lpEntryID);
|
||||
ShowMessage(hWnd, msg);
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPIResolveNameFreeBuffer(HWND hWnd)
|
||||
{
|
||||
if (lpRecip == NULL)
|
||||
{
|
||||
ShowMessage(hWnd, "There is no memory allocated from MAPIResolveName()\nto be freed. Request ignored.");
|
||||
}
|
||||
else
|
||||
{
|
||||
DoMAPIFreeBuffer(hWnd, lpRecip, TRUE);
|
||||
lpRecip = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPIDetails(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPIDetails) (LHANDLE lhSession, ULONG ulUIParam,
|
||||
lpMapiRecipDesc lpRecip, FLAGS flFlags, ULONG ulReserved);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPIDetails = GetProcAddress(m_hInstMapi, "MAPIDetails");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPIDetails = GetProcAddress(m_hInstMapi, "MAPIDetails");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPIDetails)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
char msg[1024];
|
||||
FLAGS flFlags = 0; // We really don't support these...
|
||||
|
||||
LONG rc = (*lpfnMAPIDetails)
|
||||
(mapiSession,
|
||||
(ULONG) hWnd,
|
||||
lpRecip,
|
||||
flFlags,
|
||||
0);
|
||||
|
||||
if (rc == SUCCESS_SUCCESS)
|
||||
{
|
||||
|
||||
wsprintf(msg, "MAPIDetails call succeeded");
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
wsprintf(msg, "FAILURE: Return code %d from MAPIDetails\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
|
||||
if (lpRecip == NULL)
|
||||
{
|
||||
lstrcat(msg, "\nNOTE: There is no valid pointer from a MAPIResolveName()\ncall to show details about.");
|
||||
}
|
||||
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("MAPIDetails failed");
|
||||
}
|
||||
}
|
||||
|
||||
lpMapiMessage
|
||||
GetMessage(HWND hWnd, LPSTR id)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnMAPIReadMail) (LHANDLE lhSession, ULONG ulUIParam,
|
||||
LPTSTR lpszMessageID, FLAGS flFlags, ULONG ulReserved,
|
||||
lpMapiMessage FAR * lppMessage);
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnMAPIReadMail = GetProcAddress(m_hInstMapi, "MAPIREADMAIL");
|
||||
#else
|
||||
(FARPROC&) lpfnMAPIReadMail = GetProcAddress(m_hInstMapi, "MAPIReadMail");
|
||||
#endif
|
||||
|
||||
if (!lpfnMAPIReadMail)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char msg[1024];
|
||||
lpMapiMessage lpMessage = NULL;
|
||||
FLAGS flFlags = 0;
|
||||
|
||||
flFlags |= MAPI_ENVELOPE_ONLY;
|
||||
LONG rc = (*lpfnMAPIReadMail)
|
||||
(mapiSession,
|
||||
(ULONG) hWnd,
|
||||
id,
|
||||
flFlags,
|
||||
0,
|
||||
&lpMessage);
|
||||
|
||||
// Deal with error up front and return if need be...
|
||||
if (rc != SUCCESS_SUCCESS)
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from MAPIReadMail\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("ReadMail failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return(lpMessage);
|
||||
}
|
||||
|
||||
void
|
||||
LoadNSCPVersionFunc(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnLoadNSCPVersion) ( void );
|
||||
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnLoadNSCPVersion = GetProcAddress(m_hInstMapi, "MAPIGETNERSCAPEVERSION");
|
||||
#else
|
||||
(FARPROC&) lpfnLoadNSCPVersion = GetProcAddress(m_hInstMapi, "MAPIGetNetscapeVersion");
|
||||
#endif
|
||||
|
||||
if (!lpfnLoadNSCPVersion)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPIGetNetscapeVersion() function.");
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowMessage(hWnd, "MAPIGetNetscapeVersion() function was FOUND!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
DoMAPI_NSCP_Sync(HWND hWnd)
|
||||
{
|
||||
ULONG (FAR PASCAL *lpfnNSCPSync) ( LHANDLE lhSession,
|
||||
ULONG ulReserved );
|
||||
#ifdef WIN16
|
||||
(FARPROC&) lpfnNSCPSync = GetProcAddress(m_hInstMapi, "MAPI_NSCP_SYNCHRONIZECLIENT");
|
||||
#else
|
||||
(FARPROC&) lpfnNSCPSync = GetProcAddress(m_hInstMapi, "MAPI_NSCP_SynchronizeClient");
|
||||
#endif
|
||||
|
||||
if (!lpfnNSCPSync)
|
||||
{
|
||||
ShowMessage(hWnd, "Unable to locate MAPI function.");
|
||||
return;
|
||||
}
|
||||
|
||||
LONG rc = (*lpfnNSCPSync) (mapiSession, 0);
|
||||
|
||||
char msg[256];
|
||||
|
||||
// Deal with error up front and return if need be...
|
||||
if (rc != SUCCESS_SUCCESS)
|
||||
{
|
||||
wsprintf(msg, "FAILURE: Return code %d from MAPI_NSCP_SynchronizeClient\nError=[%s]",
|
||||
rc, GetMAPIError(rc));
|
||||
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("MAPI_NSCP_SynchronizeClient failed");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(msg, "Success for MAPI_NSCP_SynchronizeClient");
|
||||
ShowMessage(hWnd, msg);
|
||||
SetFooter("MAPI_NSCP_SynchronizeClient success");
|
||||
}
|
||||
}
|
||||
25
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.dep
Normal file
25
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.dep
Normal file
@@ -0,0 +1,25 @@
|
||||
# Microsoft Developer Studio Generated Dependency File, included by mapitest.mak
|
||||
|
||||
.\main.cpp : \
|
||||
".\port.h"\
|
||||
"c:\program files\msdev\vc98\include\basetsd.h"\
|
||||
|
||||
|
||||
.\mapimail.cpp : \
|
||||
".\port.h"\
|
||||
"c:\program files\msdev\vc98\include\basetsd.h"\
|
||||
|
||||
|
||||
.\mapiproc.cpp : \
|
||||
".\port.h"\
|
||||
"c:\program files\msdev\vc98\include\basetsd.h"\
|
||||
|
||||
|
||||
.\mtest32.rc : \
|
||||
".\nscicon.ico"\
|
||||
|
||||
|
||||
.\readmail.cpp : \
|
||||
".\port.h"\
|
||||
"c:\program files\msdev\vc98\include\basetsd.h"\
|
||||
|
||||
121
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.dsp
Normal file
121
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.dsp
Normal file
@@ -0,0 +1,121 @@
|
||||
# Microsoft Developer Studio Project File - Name="mapitest" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Application" 0x0101
|
||||
|
||||
CFG=mapitest - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "mapitest.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "mapitest.mak" CFG="mapitest - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "mapitest - Win32 Release" (based on "Win32 (x86) Application")
|
||||
!MESSAGE "mapitest - Win32 Debug" (based on "Win32 (x86) Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "mapitest - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "mapitest - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "mapitest - Win32 Release"
|
||||
# Name "mapitest - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mapimail.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mapiproc.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mtest32.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\readmail.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
29
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.dsw
Normal file
29
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.dsw
Normal file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "mapitest"=.\mapitest.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
BIN
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.ncb
Normal file
BIN
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.ncb
Normal file
Binary file not shown.
BIN
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.opt
Normal file
BIN
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.opt
Normal file
Binary file not shown.
44
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.plg
Normal file
44
mozilla/mailnews/mapi/old/tests/mapitest/mapitest.plg
Normal file
@@ -0,0 +1,44 @@
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>Build Log</h1>
|
||||
<h3>
|
||||
--------------------Configuration: mapitest - Win32 Debug--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating command line "rc.exe /l 0x409 /fo"Debug/mtest32.res" /d "_DEBUG" "Y:\mozilla\mailnews\mapi\tests\mapitest\mtest32.rc""
|
||||
Creating temporary file "C:\TEMP\RSP38A.tmp" with contents
|
||||
[
|
||||
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Fp"Debug/mapitest.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
|
||||
"Y:\mozilla\mailnews\mapi\tests\mapitest\readmail.cpp"
|
||||
"Y:\mozilla\mailnews\mapi\tests\mapitest\mapimail.cpp"
|
||||
"Y:\mozilla\mailnews\mapi\tests\mapitest\mapiproc.cpp"
|
||||
"Y:\mozilla\mailnews\mapi\tests\mapitest\main.cpp"
|
||||
]
|
||||
Creating command line "cl.exe @C:\TEMP\RSP38A.tmp"
|
||||
Creating temporary file "C:\TEMP\RSP38B.tmp" with contents
|
||||
[
|
||||
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/mapitest.pdb" /debug /machine:I386 /out:"Debug/mapitest.exe" /pdbtype:sept
|
||||
.\Debug\readmail.obj
|
||||
.\Debug\mapimail.obj
|
||||
.\Debug\mapiproc.obj
|
||||
.\Debug\mtest32.res
|
||||
.\Debug\main.obj
|
||||
]
|
||||
Creating command line "link.exe @C:\TEMP\RSP38B.tmp"
|
||||
<h3>Output Window</h3>
|
||||
Compiling resources...
|
||||
Compiling...
|
||||
readmail.cpp
|
||||
mapimail.cpp
|
||||
mapiproc.cpp
|
||||
main.cpp
|
||||
Linking...
|
||||
|
||||
|
||||
|
||||
<h3>Results</h3>
|
||||
mapitest.exe - 0 error(s), 0 warning(s)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
245
mozilla/mailnews/mapi/old/tests/mapitest/mtest32.rc
Normal file
245
mozilla/mailnews/mapi/old/tests/mapitest/mtest32.rc
Normal file
@@ -0,0 +1,245 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
ID_DIALOG DIALOG DISCARDABLE 0, 0, 344, 229
|
||||
STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Netscape MAPI Test Harness"
|
||||
MENU ID_MENU
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
GROUPBOX "Open/Close",IDC_STATIC,4,4,336,27
|
||||
LTEXT "User:",IDC_STATIC,9,17,18,11
|
||||
EDITTEXT ID_EDIT_USERNAME,28,15,41,12,ES_AUTOHSCROLL
|
||||
LTEXT "Password:",IDC_STATIC,74,17,38,11
|
||||
EDITTEXT ID_EDIT_PW,112,15,41,12,ES_PASSWORD | ES_AUTOHSCROLL
|
||||
PUSHBUTTON "MAPILogon",ID_BUTTON_LOGON,157,13,46,14
|
||||
PUSHBUTTON "MAPILogoff",ID_BUTTON_LOGOFF,209,13,46,14
|
||||
GROUPBOX "Mail Operations",IDC_STATIC,4,36,336,142
|
||||
PUSHBUTTON "MAPIFindNext",ID_BUTTON_FINDNEXT,17,50,57,14
|
||||
PUSHBUTTON "MAPIDeleteMail",ID_BUTTON_DELETEMAIL,80,50,57,14
|
||||
PUSHBUTTON "Clear Results",ID_BUTTON_CLEAR,143,50,57,14
|
||||
PUSHBUTTON "Send Mail",ID_BUTTON_MAIL,206,50,57,14
|
||||
LISTBOX ID_LIST_RESULT,9,66,325,56,LBS_SORT |
|
||||
LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL |
|
||||
WS_TABSTOP
|
||||
GROUPBOX "User Information",IDC_STATIC,4,181,336,28
|
||||
PUSHBUTTON "MAPIResolveName",ID_BUTTON_RESOLVENAME,9,192,68,14
|
||||
EDITTEXT IDC_EDIT_RESOLVENAME,82,192,130,14,ES_AUTOHSCROLL
|
||||
PUSHBUTTON "MAPIDetails",ID_BUTTON_DETAILS,219,192,48,14
|
||||
LTEXT "",ID_STATIC_RESULT,4,214,336,13,SS_SUNKEN
|
||||
PUSHBUTTON "MAPIReadMail",ID_BUTTON_READMAIL,34,142,57,14
|
||||
CONTROL "MAPI_BODY_AS_FILE - Body as attachment",
|
||||
IDC_CHECK_BODYASFILE,"Button",BS_AUTOCHECKBOX |
|
||||
WS_TABSTOP,121,125,188,9
|
||||
CONTROL "MAPI_ENVELOPE_ONLY - Header information only",
|
||||
IDC_CHECK_ENVELOPEONLY,"Button",BS_AUTOCHECKBOX |
|
||||
WS_TABSTOP,121,138,188,9
|
||||
CONTROL "MAPI_PEEK - Don't mark message as read",IDC_CHECK_PEEK,
|
||||
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,121,151,188,9
|
||||
CONTROL "MAPI_SUPPRESS_ATTACH - Suppress attachments",
|
||||
IDC_CHECK_SUPPRESSATTACH,"Button",BS_AUTOCHECKBOX |
|
||||
WS_TABSTOP,121,164,188,9
|
||||
PUSHBUTTON "<- MAPIFreeBuffer",ID_BUTTON_FREEBUFFER,272,192,63,14
|
||||
PUSHBUTTON "MAPIGetNSCPVersion",ID_BUTTON_NSCPVERSION,261,13,76,14
|
||||
PUSHBUTTON "Synchronize",ID_BUTTON_SYNC,269,50,57,14
|
||||
END
|
||||
|
||||
ID_DIALOG_MAIL DIALOG DISCARDABLE 0, 0, 285, 246
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Composition"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
GROUPBOX "Address Information",IDC_STATIC,4,4,275,55
|
||||
LTEXT "To:",IDC_STATIC,21,19,12,8
|
||||
EDITTEXT ID_EDIT_TOADDRESS,36,16,239,13,ES_AUTOHSCROLL
|
||||
EDITTEXT ID_EDIT_CCADDRESS,36,30,239,13,ES_AUTOHSCROLL
|
||||
EDITTEXT ID_EDIT_BCCADDRESS,36,44,239,13,ES_AUTOHSCROLL
|
||||
LTEXT "Subject:",IDC_STATIC,5,65,29,9
|
||||
EDITTEXT ID_EDIT_SUBJECT,36,63,239,13,ES_AUTOHSCROLL
|
||||
EDITTEXT ID_EDIT_NOTETEXT,4,78,271,72,ES_MULTILINE |
|
||||
ES_AUTOHSCROLL
|
||||
GROUPBOX "Attachments",IDC_STATIC,4,153,275,39
|
||||
EDITTEXT ID_EDIT_ATTACH1,16,162,122,13,ES_AUTOHSCROLL
|
||||
EDITTEXT ID_EDIT_ATTACH2,16,176,122,13,ES_AUTOHSCROLL
|
||||
EDITTEXT ID_EDIT_ATTACH3,147,162,122,13,ES_AUTOHSCROLL
|
||||
EDITTEXT ID_EDIT_ATTACH4,147,175,122,13,ES_AUTOHSCROLL
|
||||
PUSHBUTTON "MAPISendMail",ID_BUTTON_MAPISENDMAIL,70,204,58,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,50,225,84,14
|
||||
PUSHBUTTON "MAPISendDocuments",ID_BUTTON_MAPISENDDOCUMENTS,132,204,
|
||||
79,14
|
||||
CONTROL "Show Dialog",ID_CHECK_SHOWDIALOG,"Button",
|
||||
BS_AUTOCHECKBOX | WS_TABSTOP,8,207,55,9
|
||||
LTEXT "cc:",IDC_STATIC,22,32,12,8
|
||||
LTEXT "bcc:",IDC_STATIC,18,47,15,8
|
||||
GROUPBOX "Send Operations",IDC_STATIC,4,196,275,26
|
||||
PUSHBUTTON "MAPISaveMail",ID_BUTTON_MAPISAVEMAIL,215,204,57,14
|
||||
PUSHBUTTON "MAPIAddress",ID_BUTTON_MAPIADDRESS,150,225,84,14
|
||||
END
|
||||
|
||||
ID_DIALOG_READMAIL DIALOG DISCARDABLE 0, 0, 269, 266
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Mail Message"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
LTEXT "Subject:",IDC_STATIC,5,71,27,9
|
||||
EDITTEXT IDC_EDIT_SUBJECT,36,69,229,12,ES_AUTOHSCROLL |
|
||||
ES_READONLY
|
||||
LISTBOX IDC_LIST_ATTACHMENTS,4,211,261,37,LBS_SORT |
|
||||
LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
|
||||
EDITTEXT IDC_EDIT_BODYTEXT,4,113,261,85,ES_MULTILINE |
|
||||
ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY |
|
||||
ES_WANTRETURN
|
||||
LISTBOX IDC_LIST_RECIPIENTS,4,29,261,36,LBS_SORT |
|
||||
LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Recipients:",IDC_STATIC,4,19,43,9
|
||||
LTEXT "Attachments:",IDC_STATIC,4,202,43,9
|
||||
EDITTEXT IDC_EDIT_DATETIME,36,83,229,12,ES_AUTOHSCROLL |
|
||||
ES_READONLY
|
||||
LTEXT "Date:",IDC_STATIC,13,84,19,9
|
||||
PUSHBUTTON "OK",ID_OK,114,249,42,13
|
||||
EDITTEXT IDC_EDIT_THREAD,36,97,229,12,ES_AUTOHSCROLL |
|
||||
ES_READONLY
|
||||
LTEXT "Thread:",IDC_STATIC,6,99,25,9
|
||||
LTEXT "From:",IDC_STATIC,4,6,19,9
|
||||
EDITTEXT IDC_EDIT_FROM,27,4,238,12,ES_AUTOHSCROLL | ES_READONLY
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO DISCARDABLE
|
||||
BEGIN
|
||||
ID_DIALOG, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 4
|
||||
RIGHTMARGIN, 340
|
||||
VERTGUIDE, 9
|
||||
VERTGUIDE, 309
|
||||
TOPMARGIN, 4
|
||||
BOTTOMMARGIN, 227
|
||||
HORZGUIDE, 206
|
||||
END
|
||||
|
||||
ID_DIALOG_MAIL, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 4
|
||||
RIGHTMARGIN, 281
|
||||
TOPMARGIN, 4
|
||||
BOTTOMMARGIN, 239
|
||||
END
|
||||
|
||||
ID_DIALOG_READMAIL, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 4
|
||||
RIGHTMARGIN, 265
|
||||
TOPMARGIN, 4
|
||||
BOTTOMMARGIN, 262
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
ID_ICON_APP ICON DISCARDABLE "nscicon.ico"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Menu
|
||||
//
|
||||
|
||||
ID_MENU MENU DISCARDABLE
|
||||
BEGIN
|
||||
POPUP "&File"
|
||||
BEGIN
|
||||
MENUITEM "MAPI&FindNext", ID_MENU_MAPIFINDNEXT
|
||||
MENUITEM "MAPI&ReadMail", ID_MENU_MAPIREADMAIL
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "E&xit", ID_MENU_MYEXIT
|
||||
END
|
||||
POPUP "&Edit"
|
||||
BEGIN
|
||||
MENUITEM "MAPI&DeleteMail", ID_MENU_MAPIDELETEMAIL
|
||||
MENUITEM "&Clear Results", ID_MENU_CLEARRESULTS
|
||||
END
|
||||
POPUP "&Help"
|
||||
BEGIN
|
||||
MENUITEM "&About...", ID_MENU_MYABOUT
|
||||
END
|
||||
END
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
BIN
mozilla/mailnews/mapi/old/tests/mapitest/nscicon.ico
Normal file
BIN
mozilla/mailnews/mapi/old/tests/mapitest/nscicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 766 B |
303
mozilla/mailnews/mapi/old/tests/mapitest/port.h
Normal file
303
mozilla/mailnews/mapi/old/tests/mapitest/port.h
Normal file
@@ -0,0 +1,303 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
|
||||
#ifndef PORT_H
|
||||
#define PORT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*****************************************************************\
|
||||
* *
|
||||
* PORT.H *
|
||||
* *
|
||||
* Win16/Win32 portability stuff *
|
||||
* *
|
||||
* A.Sokolsky *
|
||||
* 3.10.94 distilled into this header *
|
||||
* *
|
||||
\*****************************************************************/
|
||||
|
||||
/*
|
||||
* calling conventions
|
||||
*/
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#ifndef CDECL
|
||||
#define CDECL __cdecl
|
||||
#endif // CDECL
|
||||
|
||||
#ifndef PASCAL
|
||||
#define PASCAL __pascal
|
||||
#endif // PASCAL
|
||||
|
||||
#ifdef FASTCALL
|
||||
#error FASTCALL defined
|
||||
#endif // FASTCALL
|
||||
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define FASTCALL __fastcall
|
||||
#else
|
||||
#define FASTCALL PASCAL
|
||||
#endif // NDEBUG
|
||||
|
||||
|
||||
|
||||
#ifndef HWND2DWORD
|
||||
# ifdef WIN32
|
||||
# define HWND2DWORD(X_hWnd) ( (DWORD)(X_hWnd) )
|
||||
# else // WIN16
|
||||
# define HWND2DWORD(X_hWnd) ( (DWORD)MAKELONG(((WORD)(X_hWnd)), 0) )
|
||||
# endif
|
||||
#endif // HWND2DWORD
|
||||
|
||||
|
||||
/*
|
||||
* WIN16 - WIN32 compatibility stuff
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
# define DLLEXPORT __declspec( dllexport )
|
||||
# define EXPORT
|
||||
# define LOADDS
|
||||
# define HUGE
|
||||
# ifndef FAR
|
||||
# define FAR
|
||||
# endif // FAR
|
||||
# ifndef NEAR
|
||||
# define NEAR
|
||||
# endif // NEAR
|
||||
# ifdef UNICODE
|
||||
# define SIZEOF(x) (sizeof(x)/sizeof(WCHAR))
|
||||
# else
|
||||
# define SIZEOF(x) sizeof(x)
|
||||
# endif
|
||||
|
||||
#else // !WIN32 == WIN16
|
||||
|
||||
# define DLLEXPORT
|
||||
# define EXPORT __export
|
||||
# define LOADDS __loadds
|
||||
# define HUGE __huge
|
||||
# ifndef FAR
|
||||
# define FAR __far
|
||||
# define NEAR __near
|
||||
# endif // FAR
|
||||
# define CONST const
|
||||
# define SIZEOF(x) sizeof(x)
|
||||
# define CHAR char
|
||||
# define TCHAR char
|
||||
# define WCHAR char
|
||||
# ifndef LPTSTR
|
||||
# define LPTSTR LPSTR
|
||||
# endif
|
||||
# ifndef LPCTSTR
|
||||
# define LPCTSTR LPCSTR
|
||||
# endif
|
||||
# define UNREFERENCED_PARAMETER(x) x;
|
||||
# ifndef TEXT
|
||||
# define TEXT(x) x
|
||||
# endif
|
||||
# define GetWindowTextW GetWindowText
|
||||
# define lstrcpyW lstrcpy
|
||||
|
||||
# define BN_DBLCLK BN_DOUBLECLICKED // ~~MRJ needed for custom control.
|
||||
// ~~MRJ begin Win95 backward compat section
|
||||
# define LPWSTR LPSTR
|
||||
# define LPCWSTR LPCSTR
|
||||
|
||||
// button check state for WIN16
|
||||
#ifndef BST_UNCHECKED
|
||||
#define BST_UNCHECKED 0x0000
|
||||
#endif
|
||||
|
||||
#ifndef BST_CHECKED
|
||||
#define BST_CHECKED 0x0001
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WIN95_COMPAT
|
||||
# define WIN95_COMPAT
|
||||
#endif
|
||||
|
||||
// ~~MRJ end Win95 compat section.
|
||||
|
||||
// critical section API stubs
|
||||
typedef DWORD CRITICAL_SECTION;
|
||||
typedef CRITICAL_SECTION FAR * LPCRITICAL_SECTION;
|
||||
#ifdef __cplusplus
|
||||
inline void InitializeCriticalSection(LPCRITICAL_SECTION lpSection) {}
|
||||
inline void DeleteCriticalSection(LPCRITICAL_SECTION lpSection) {}
|
||||
inline void EnterCriticalSection(LPCRITICAL_SECTION lpSection) {}
|
||||
inline void LeaveCriticalSection(LPCRITICAL_SECTION lpSection) {}
|
||||
#endif // __cplusplus
|
||||
|
||||
// Added for nssock16 ---Neeti
|
||||
#ifndef ZeroMemory
|
||||
#include <memory.h>
|
||||
#define ZeroMemory(PTR, SIZE) memset(PTR, 0, SIZE)
|
||||
#endif // ZeroMemory
|
||||
|
||||
#endif // WIN16
|
||||
|
||||
/*
|
||||
* unix - windows compatibility stuff
|
||||
*/
|
||||
typedef DWORD u_int32;
|
||||
typedef WORD u_int16;
|
||||
typedef BYTE u_int8;
|
||||
#ifdef WIN32
|
||||
typedef short int Bool16;
|
||||
#else // WIN16
|
||||
typedef BOOL Bool16;
|
||||
#endif // WIN16
|
||||
|
||||
/*
|
||||
* Cross Platform Compatibility
|
||||
*/
|
||||
#ifndef UNALIGNED
|
||||
# ifdef _M_ALPHA
|
||||
# define UNALIGNED __unaligned
|
||||
# else // !_M_ALPHA
|
||||
# define UNALIGNED
|
||||
# endif // !_M_ALPHA
|
||||
#endif // UNALIGNED
|
||||
|
||||
//
|
||||
// RICHIE - for the Alpha port
|
||||
//
|
||||
#ifdef _M_ALPHA
|
||||
# undef pascal
|
||||
# undef PASCAL
|
||||
# if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
|
||||
# define pascal __stdcall
|
||||
# define PASCAL __stdcall
|
||||
# else
|
||||
# define PASCAL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Useful Types
|
||||
*/
|
||||
typedef char HUGE *HPSTR;
|
||||
typedef const char HUGE *HPCSTR;
|
||||
typedef unsigned char HUGE *HPBYTE;
|
||||
typedef WORD HUGE *HPWORD;
|
||||
typedef UINT FAR *LPUINT;
|
||||
typedef BOOL (CALLBACK *USERABORTPROC)();
|
||||
typedef BOOL (CALLBACK *PROGRESSPROC)(UINT uPos, UINT uRange);
|
||||
typedef int INT; // ~~MRJ a function needed this defined.
|
||||
typedef MINMAXINFO FAR *LPMINMAXINFO; // ~~MRJ
|
||||
|
||||
//
|
||||
// stuff missing from windows.h
|
||||
//
|
||||
#ifndef MAKEWORD
|
||||
#define MAKEWORD(low, high) ((WORD)(((BYTE)(low)) | (((WORD)((BYTE)(high))) << 8)))
|
||||
#endif // MAKEWORD
|
||||
|
||||
#ifdef WIN32
|
||||
# ifndef hmemcpy
|
||||
# define hmemcpy memcpy
|
||||
# endif // !defined(hmemcpy)
|
||||
# define _fmemset memset
|
||||
|
||||
# include <malloc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
inline BOOL IsGDIObject(HGDIOBJ hObj) { return (hObj != 0); }
|
||||
inline void *_halloc(long num, unsigned int size) { return malloc(num * size); }
|
||||
inline void _hfree( void *memblock ) { free(memblock); }
|
||||
/*
|
||||
inline BOOL IsInstance(HINSTANCE hInst) {
|
||||
# ifdef WIN32
|
||||
return (hInst != 0);
|
||||
# else // WIN16
|
||||
return (hInst > HINSTANCE_ERROR);
|
||||
# endif
|
||||
}
|
||||
*/
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
WINUSERAPI HANDLE WINAPI LoadImageA(HINSTANCE, LPCSTR, UINT, int, int, UINT);
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
#ifdef __cplusplus
|
||||
inline BOOL IsInstance(HINSTANCE hInst) {
|
||||
# ifdef WIN32
|
||||
return (hInst != 0);
|
||||
# else // WIN16
|
||||
return (hInst > HINSTANCE_ERROR);
|
||||
# endif
|
||||
}
|
||||
inline void SetWindowSmallIcon(HINSTANCE hInst, HWND hWnd, UINT uIconResourceId) {
|
||||
#ifdef WIN32
|
||||
# ifndef WM_SETICON
|
||||
# define WM_SETICON 0x0080
|
||||
# endif // WM_SETICON
|
||||
# ifndef IMAGE_ICON
|
||||
# define IMAGE_ICON 1
|
||||
# endif
|
||||
assert(IsWindow(hWnd));
|
||||
HICON hIcon = (HICON)LoadImageA(hInst, MAKEINTRESOURCE(uIconResourceId), IMAGE_ICON,
|
||||
16, 16, 0);
|
||||
if(NULL != hIcon) {
|
||||
SendMessage(hWnd, WM_SETICON, FALSE, (LPARAM)hIcon);
|
||||
} else {
|
||||
HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(uIconResourceId));
|
||||
assert(hIcon != 0);
|
||||
SendMessage(hWnd, WM_SETICON, FALSE, (LPARAM)hIcon);
|
||||
}
|
||||
#endif // WIN32
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* PORT_H */
|
||||
137
mozilla/mailnews/mapi/old/tests/mapitest/readmail.cpp
Normal file
137
mozilla/mailnews/mapi/old/tests/mapitest/readmail.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
//
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#ifndef MAPI_OLE // Because MSFT doesn't do this for us :-(
|
||||
#include <mapi.h>
|
||||
#endif
|
||||
|
||||
#include "port.h"
|
||||
#include "resource.h"
|
||||
|
||||
//
|
||||
// Variables...
|
||||
//
|
||||
extern HINSTANCE hInst;
|
||||
extern HINSTANCE m_hInstMapi;
|
||||
extern LHANDLE mapiSession;
|
||||
|
||||
//
|
||||
// Forward declarations...
|
||||
//
|
||||
extern void ShowMessage(HWND hWnd, LPSTR msg);
|
||||
extern void SetFooter(LPSTR msg);
|
||||
extern LPSTR GetMAPIError(LONG errorCode);
|
||||
lpMapiMessage mailPtr = NULL;
|
||||
|
||||
void
|
||||
ProcessReadMailCommand(HWND hWnd, int id, HWND hCtl, UINT codeNotify)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case ID_OK:
|
||||
case IDCANCEL:
|
||||
EndDialog(hWnd, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CALLBACK LOADDS
|
||||
ReadMailDlgProc(HWND hWndMail, UINT wMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (wMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
DWORD i;
|
||||
// Do everything we need to display the message pointed to by
|
||||
// mailPtr
|
||||
if (!mailPtr)
|
||||
break;
|
||||
|
||||
// Start with the basics...
|
||||
SetDlgItemText(hWndMail, IDC_EDIT_SUBJECT, mailPtr->lpszSubject);
|
||||
SetDlgItemText(hWndMail, IDC_EDIT_DATETIME, mailPtr->lpszDateReceived);
|
||||
SetDlgItemText(hWndMail, IDC_EDIT_THREAD, mailPtr->lpszConversationID);
|
||||
SetDlgItemText(hWndMail, IDC_EDIT_BODYTEXT, mailPtr->lpszNoteText);
|
||||
|
||||
char buf[1024];
|
||||
wsprintf(buf, "%s (%s)", mailPtr->lpOriginator->lpszName,
|
||||
mailPtr->lpOriginator->lpszAddress);
|
||||
SetDlgItemText(hWndMail, IDC_EDIT_FROM, buf);
|
||||
|
||||
for (i=0; i<mailPtr->nRecipCount; i++)
|
||||
{
|
||||
wsprintf(buf, "%s (%s)", mailPtr->lpRecips[i].lpszName,
|
||||
mailPtr->lpRecips[i].lpszAddress);
|
||||
ListBox_InsertString(GetDlgItem(hWndMail, IDC_LIST_RECIPIENTS),
|
||||
ListBox_GetCount(GetDlgItem(hWndMail, IDC_LIST_RECIPIENTS)),
|
||||
buf);
|
||||
}
|
||||
|
||||
for (i=0; i<mailPtr->nFileCount; i++)
|
||||
{
|
||||
ListBox_InsertString(GetDlgItem(hWndMail, IDC_LIST_ATTACHMENTS),
|
||||
ListBox_GetCount(GetDlgItem(hWndMail, IDC_LIST_ATTACHMENTS)),
|
||||
mailPtr->lpFiles[i].lpszPathName);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
HANDLE_WM_COMMAND(hWndMail, wParam, lParam, ProcessReadMailCommand);
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
DisplayMAPIReadMail(HWND hWnd, lpMapiMessage msgPtr)
|
||||
{
|
||||
mailPtr = msgPtr;
|
||||
DialogBox(hInst, MAKEINTRESOURCE(ID_DIALOG_READMAIL), hWnd,
|
||||
(DLGPROC)ReadMailDlgProc);
|
||||
}
|
||||
108
mozilla/mailnews/mapi/old/tests/mapitest/resource.h
Normal file
108
mozilla/mailnews/mapi/old/tests/mapitest/resource.h
Normal file
@@ -0,0 +1,108 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by mtest32.rc
|
||||
//
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#define ID_GUI_MESSAGE1 1
|
||||
#define ID_BUTTON_MAPIADDRESS 3
|
||||
#define ID_DIALOG 101
|
||||
#define ID_ICON_APP 102
|
||||
#define ID_MENU 104
|
||||
#define ID_DIALOG_MAIL 105
|
||||
#define ID_DIALOG_READMAIL 106
|
||||
#define ID_SETFROMEDIT 1000
|
||||
#define ID_SETTEXT 1001
|
||||
#define ID_GETROWS 1001
|
||||
#define ID_EDIT 1002
|
||||
#define ID_EDIT_HWND 1002
|
||||
#define ID_RESOURCETEXT 1003
|
||||
#define ID_GETTEXT 1003
|
||||
#define ID_STATIC_RESULT 1004
|
||||
#define ID_GETVISROWS 1005
|
||||
#define ID_GETWINID 1006
|
||||
#define ID_SETROWFOCUS 1007
|
||||
#define ID_GETROWFOCUS 1008
|
||||
#define ID_EDIT_ROW 1009
|
||||
#define ID_LIST_RESULT 1010
|
||||
#define ID_GETCOLCOUNT 1011
|
||||
#define ID_BUTTON_LOGON 1011
|
||||
#define ID_SETROWINVIEW 1012
|
||||
#define ID_BUTTON_LOGOFF 1012
|
||||
#define ID_GETNUMCHILDREN 1013
|
||||
#define ID_EDIT_USERNAME 1013
|
||||
#define ID_CLEARRESULTS 1014
|
||||
#define ID_EDIT_PW 1014
|
||||
#define ID_BUTTON_FINDNEXT 1015
|
||||
#define ID_BUTTON_CLEAR 1016
|
||||
#define ID_BUTTON_READMAIL 1017
|
||||
#define ID_BUTTON_DELETEMAIL 1018
|
||||
#define IDC_EDIT_RESOLVENAME 1019
|
||||
#define ID_BUTTON_MAPISENDMAIL 1020
|
||||
#define ID_BUTTON_NSCPVERSION 1020
|
||||
#define ID_BUTTON_RESOLVENAME 1021
|
||||
#define ID_BUTTON_MAPISENDDOCUMENTS 1021
|
||||
#define ID_EDIT_TOADDRESS 1022
|
||||
#define ID_EDIT_CCADDRESS 1023
|
||||
#define ID_BUTTON_DETAILS 1024
|
||||
#define ID_EDIT_BCCADDRESS 1024
|
||||
#define ID_EDIT_SUBJECT 1025
|
||||
#define ID_BUTTON_MAIL 1025
|
||||
#define ID_BUTTON_FREEBUFFER 1026
|
||||
#define ID_EDIT_NOTETEXT 1026
|
||||
#define ID_EDIT_ATTACH1 1027
|
||||
#define ID_BUTTON_SYNC 1027
|
||||
#define ID_EDIT_ATTACH2 1028
|
||||
#define IDC_CHECK_BODYASFILE 1028
|
||||
#define ID_EDIT_ATTACH3 1029
|
||||
#define IDC_CHECK_ENVELOPEONLY 1029
|
||||
#define IDC_LIST_ATTACHMENTS 1029
|
||||
#define ID_EDIT_ATTACH4 1030
|
||||
#define IDC_CHECK_PEEK 1030
|
||||
#define IDC_EDIT_BODYTEXT 1030
|
||||
#define IDC_CHECK_SUPPRESSATTACH 1031
|
||||
#define IDC_LIST_RECIPIENTS 1031
|
||||
#define ID_BUTTON_MAPISAVEMAIL 1031
|
||||
#define IDC_EDIT_SUBJECT 1032
|
||||
#define IDC_EDIT_DATETIME 1033
|
||||
#define ID_OK 1034
|
||||
#define IDC_EDIT_THREAD 1035
|
||||
#define ID_CHECK_SHOWDIALOG 1035
|
||||
#define IDC_EDIT_FROM 1036
|
||||
#define ID_MENU_MYEXIT 30001
|
||||
#define ID_MENU_CLEAR 30002
|
||||
#define ID_MENU_MYABOUT 30003
|
||||
#define ID_MENU_CLEARRESULTS 30004
|
||||
#define ID_MENU_MAPIDELETEMAIL 30005
|
||||
#define ID_MENU_MAPIFINDNEXT 30006
|
||||
#define ID_MENU_MAPIREADMAIL 30007
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 107
|
||||
#define _APS_NEXT_COMMAND_VALUE 30008
|
||||
#define _APS_NEXT_CONTROL_VALUE 1036
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
117
mozilla/mailnews/mapi/resources/content/contents.rdf
Normal file
117
mozilla/mailnews/mapi/resources/content/contents.rdf
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- If you modify this file, please also update the following files -->
|
||||
<!-- mailnews/mapi/resources/content/contents.rdf in the ns tree -->
|
||||
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the packages being supplied by this jar -->
|
||||
<RDF:Seq about="urn:mozilla:package:root">
|
||||
<RDF:li resource="urn:mozilla:package:messenger"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- package information -->
|
||||
<RDF:Description about="urn:mozilla:package:messenger"
|
||||
chrome:displayName="Messenger"
|
||||
chrome:author="mozilla.org"
|
||||
chrome:name="messenger"
|
||||
chrome:localeVersion="0.9.4"
|
||||
chrome:skinVersion="0.9.4">
|
||||
</RDF:Description>
|
||||
|
||||
<!-- overlay information -->
|
||||
<RDF:Seq about="urn:mozilla:overlays">
|
||||
<RDF:li resource="chrome://communicator/content/pref/preftree.xul"/>
|
||||
<RDF:li resource="chrome://communicator/content/pref/pref-appearance.xul"/>
|
||||
<RDF:li resource="chrome://communicator/content/pref/pref-advanced.xul"/>
|
||||
<RDF:li resource="chrome://communicator/content/tasksOverlay.xul"/>
|
||||
<RDF:li resource="chrome://navigator/content/navigatorOverlay.xul"/>
|
||||
<RDF:li resource="chrome://communicator/content/history/history.xul"/>
|
||||
<RDF:li resource="chrome://communicator/content/bookmarks/bookmarks.xul"/>
|
||||
<RDF:li resource="chrome://communicator/content/bookmarks/bm-find.xul"/>
|
||||
<RDF:li resource="chrome://messenger/content/messenger.xul"/>
|
||||
<RDF:li resource="chrome://messenger/content/mail3PaneWindowVertLayout.xul"/>
|
||||
<RDF:li resource="chrome://messenger/content/messengercompose/messengercompose.xul"/>
|
||||
<RDF:li resource="chrome://messenger/content/addressbook/addressbook.xul"/>
|
||||
<RDF:li resource="chrome://messenger/content/addressbook/abSelectAddressesDialog.xul"/>
|
||||
<RDF:li resource="chrome://editor/content/editor.xul"/>
|
||||
<RDF:li resource="chrome://messenger/content/pref-mailnews.xul"/>
|
||||
</RDF:Seq>
|
||||
|
||||
|
||||
<!-- messenger preferences branches -->
|
||||
<RDF:Seq about="chrome://communicator/content/pref/preftree.xul">
|
||||
<RDF:li>chrome://messenger/content/mailPrefsOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger startup pref -->
|
||||
<RDF:Seq about="chrome://communicator/content/pref/pref-appearance.xul">
|
||||
<RDF:li>chrome://messenger/content/mailPrefsOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger js toggle pref -->
|
||||
<RDF:Seq about="chrome://communicator/content/pref/pref-advanced.xul">
|
||||
<RDF:li>chrome://messenger/content/mailPrefsOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger taskbar/tasks menu items -->
|
||||
<RDF:Seq about="chrome://communicator/content/tasksOverlay.xul">
|
||||
<RDF:li>chrome://messenger/content/mailTasksOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger items for History -->
|
||||
<RDF:Seq about="chrome://communicator/content/history/history.xul">
|
||||
<RDF:li>chrome://messenger/content/mailNavigatorOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger items for Bookmarks -->
|
||||
<RDF:Seq about="chrome://communicator/content/bookmarks/bookmarks.xul">
|
||||
<RDF:li>chrome://messenger/content/mailNavigatorOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger items for History -->
|
||||
<RDF:Seq about="chrome://communicator/content/bookmarks/bm-find.xul">
|
||||
<RDF:li>chrome://messenger/content/mailNavigatorOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger items for Navigator -->
|
||||
<RDF:Seq about="chrome://navigator/content/navigatorOverlay.xul">
|
||||
<RDF:li>chrome://messenger/content/mailNavigatorOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger items for Messenger -->
|
||||
<RDF:Seq about="chrome://messenger/content/messenger.xul">
|
||||
<RDF:li>chrome://messenger/content/mailMessengerOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
<RDF:Seq about="chrome://messenger/content/mail3PaneWindowVertLayout.xul">
|
||||
<RDF:li>chrome://messenger/content/mailMessengerOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger items for Mail Compose -->
|
||||
<RDF:Seq about="chrome://messenger/content/messengercompose/messengercompose.xul">
|
||||
<RDF:li>chrome://messenger/content/mailMessengerComposeOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger items for Addressbook -->
|
||||
<RDF:Seq about="chrome://messenger/content/addressbook/addressbook.xul">
|
||||
<RDF:li>chrome://messenger/content/mailABOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- messenger items for Select Addresses dialog -->
|
||||
<RDF:Seq about="chrome://messenger/content/addressbook/abSelectAddressesDialog.xul">
|
||||
<RDF:li>chrome://messenger/content/mailOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
|
||||
<!-- messenger items for Composer -->
|
||||
<RDF:Seq about="chrome://editor/content/editor.xul">
|
||||
<RDF:li>chrome://messenger/content/mailEditorOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- mapi items for Mail And Newsgroups preferences pane -->
|
||||
<RDF:Seq about="chrome://messenger/content/pref-mailnews.xul">
|
||||
<RDF:li>chrome://messenger/content/pref-mailnewsOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
</RDF:RDF>
|
||||
4
mozilla/mailnews/mapi/resources/content/jar.mn
Normal file
4
mozilla/mailnews/mapi/resources/content/jar.mn
Normal file
@@ -0,0 +1,4 @@
|
||||
messenger.jar:
|
||||
content/messenger/pref-mailnewsOverlay.xul
|
||||
+ content/messenger/contents.rdf
|
||||
content/messenger/pref-mailnewsOverlay.js
|
||||
26
mozilla/mailnews/mapi/resources/content/makefile.win
Normal file
26
mozilla/mailnews/mapi/resources/content/makefile.win
Normal file
@@ -0,0 +1,26 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
14
mozilla/mailnews/mapi/resources/content/overlays.rdf
Normal file
14
mozilla/mailnews/mapi/resources/content/overlays.rdf
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:chrome="http://www.mozilla.org/rdf/chrome#"
|
||||
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
|
||||
<!-- mapi items for mailnews preferences -->
|
||||
<RDF:Seq about="urn:mozilla:overlays">
|
||||
<RDF:li resource="chrome://messenger/content/pref-mailnews.xul"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<RDF:Seq about="chrome://messenger/content/pref-mailnews.xul">
|
||||
<RDF:li>chrome://messenger/content/pref-mailnewsOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
</RDF:RDF>
|
||||
104
mozilla/mailnews/mapi/resources/content/pref-mailnewsOverlay.js
Normal file
104
mozilla/mailnews/mapi/resources/content/pref-mailnewsOverlay.js
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Srilatha Moturi <srilatha@netscape.com>
|
||||
*/
|
||||
|
||||
function mailnewsOverlayStartup() {
|
||||
mailnewsOverlayInit();
|
||||
parent.hPrefWindow.registerOKCallbackFunc(onOK);
|
||||
if (!("mapiPref" in parent)) {
|
||||
parent.mapiPref = new Object;
|
||||
parent.mapiPref.isDefaultMailClient =
|
||||
document.getElementById("mailnewsEnableMapi").checked;
|
||||
}
|
||||
else {
|
||||
// when we switch between different panes
|
||||
// set the checkbox based on the saved state
|
||||
var mailnewsEnableMapi = document.getElementById("mailnewsEnableMapi");
|
||||
if (parent.mapiPref.isDefaultMailClient)
|
||||
mailnewsEnableMapi.setAttribute("checked", "true");
|
||||
else
|
||||
mailnewsEnableMapi.setAttribute("checked", "false");
|
||||
}
|
||||
}
|
||||
|
||||
function mailnewsOverlayInit() {
|
||||
try {
|
||||
var mapiRegistry = Components.classes[ "@mozilla.org/mapiregistry;1" ].
|
||||
getService( Components.interfaces.nsIMapiRegistry );
|
||||
}
|
||||
catch(ex){
|
||||
mapiRegistry = null;
|
||||
}
|
||||
|
||||
const prefbase = "system.windows.lock_ui.";
|
||||
var mailnewsEnableMapi = document.getElementById("mailnewsEnableMapi");
|
||||
if (mapiRegistry) {
|
||||
// initialise preference component.
|
||||
// While the data is coming from the system registry, we use a set
|
||||
// of parallel preferences to indicate if the ui should be locked.
|
||||
try {
|
||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService()
|
||||
.QueryInterface(Components.interfaces.nsIPrefService);
|
||||
var prefBranch = prefService.getBranch(prefbase);
|
||||
if (prefBranch && prefBranch.prefIsLocked("default_mail_client")) {
|
||||
if (prefBranch.getBoolPref("default_mail_client"))
|
||||
mapiRegistry.setDefaultMailClient();
|
||||
else
|
||||
mapiRegistry.unsetDefaultMailClient();
|
||||
mailnewsEnableMapi.setAttribute("disabled", "true");
|
||||
}
|
||||
}
|
||||
catch(ex) {}
|
||||
if (mapiRegistry.isDefaultMailClient)
|
||||
mailnewsEnableMapi.setAttribute("checked", "true");
|
||||
else
|
||||
mailnewsEnableMapi.setAttribute("checked", "false");
|
||||
}
|
||||
else
|
||||
mailnewsEnableMapi.setAttribute("disabled", "true");
|
||||
}
|
||||
|
||||
function onEnableMapi() {
|
||||
// save the state of the checkbox
|
||||
if ("mapiPref" in parent)
|
||||
parent.mapiPref.isDefaultMailClient =
|
||||
document.getElementById("mailnewsEnableMapi").checked;
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
try {
|
||||
var mapiRegistry = Components.classes[ "@mozilla.org/mapiregistry;1" ].
|
||||
getService( Components.interfaces.nsIMapiRegistry );
|
||||
}
|
||||
catch(ex){
|
||||
mapiRegistry = null;
|
||||
}
|
||||
if (mapiRegistry &&
|
||||
("mapiPref" in parent) &&
|
||||
(mapiRegistry.isDefaultMailClient != parent.mapiPref.isDefaultMailClient)) {
|
||||
if (parent.mapiPref.isDefaultMailClient)
|
||||
mapiRegistry.setDefaultMailClient();
|
||||
else
|
||||
mapiRegistry.unsetDefaultMailClient();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
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/
|
||||
|
||||
oftware 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 mozilla.org code.
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Srilatha Moturi <srilatha@netscape.com>
|
||||
-->
|
||||
|
||||
<!DOCTYPE window [
|
||||
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
|
||||
%brandDTD;
|
||||
<!ENTITY % prefMailnewsOverlayDTD SYSTEM "chrome://messenger/locale/pref-mailnewsOverlay.dtd" >
|
||||
%prefMailnewsOverlayDTD;
|
||||
]>
|
||||
<overlay id="prefMailnewsOverlay"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script type="application/x-javascript">
|
||||
<![CDATA[
|
||||
_elementIDs.push("mailnewsEnableMapi");
|
||||
]]>
|
||||
</script>
|
||||
<script type="application/x-javascript" src="chrome://messenger/content/pref-mailnewsOverlay.js"/>
|
||||
<hbox autostretch="never" id="mapi">
|
||||
<checkbox id="mailnewsEnableMapi" label="&enableMapi.label;"
|
||||
accesskey="&enableMapi.accesskey;"
|
||||
oncommand="onEnableMapi();"
|
||||
startFunc="mailnewsOverlayStartup();"/>
|
||||
</hbox>
|
||||
</overlay>
|
||||
3
mozilla/mailnews/mapi/resources/locale/en-US/jar.mn
Normal file
3
mozilla/mailnews/mapi/resources/locale/en-US/jar.mn
Normal file
@@ -0,0 +1,3 @@
|
||||
en-US.jar:
|
||||
locale/en-US/messenger/pref-mailnewsOverlay.dtd
|
||||
locale/en-US/messenger/mapi.properties
|
||||
26
mozilla/mailnews/mapi/resources/locale/en-US/makefile.win
Normal file
26
mozilla/mailnews/mapi/resources/locale/en-US/makefile.win
Normal file
@@ -0,0 +1,26 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..\..
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
18
mozilla/mailnews/mapi/resources/locale/en-US/mapi.properties
Normal file
18
mozilla/mailnews/mapi/resources/locale/en-US/mapi.properties
Normal file
@@ -0,0 +1,18 @@
|
||||
# Mail Integration Dialog
|
||||
dialogTitle=%S Mail
|
||||
dialogText=Do you want to use %S as the default mail application?
|
||||
checkboxText=Do not display this dialog again
|
||||
|
||||
# MAPI Messages
|
||||
loginText=Please enter your password for %S:
|
||||
loginTextwithName=Please enter your username and password
|
||||
loginTitle=%S Mail
|
||||
PasswordTitle=%S Mail
|
||||
|
||||
# MAPI Error Messages
|
||||
errorMessage=%S Mail could not be set as the default mail application because a registry key could not be updated. Verify with your system administrator that you have write access to your system registry, and then try again.
|
||||
errorMessageTitle=%S Mail
|
||||
|
||||
# MAPI Security Messages
|
||||
mapiBlindSendWarning=Another application is attempting to send mail using your user profile. Are you sure you want to send mail?
|
||||
mapiBlindSendDontShowAgain=Warn me whenever other applications try to send mail from me
|
||||
@@ -0,0 +1,3 @@
|
||||
<!ENTITY enableMapiTitle.label "When sending mail from other applications">
|
||||
<!ENTITY enableMapi.label "Use &vendorShortName; Mail as the default mail application.">
|
||||
<!ENTITY enableMapi.accesskey "u">
|
||||
28
mozilla/mailnews/mapi/resources/locale/makefile.win
Normal file
28
mozilla/mailnews/mapi/resources/locale/makefile.win
Normal file
@@ -0,0 +1,28 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
DIRS=en-US
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
27
mozilla/mailnews/mapi/resources/makefile.win
Normal file
27
mozilla/mailnews/mapi/resources/makefile.win
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
DIRS=content locale
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
@@ -1,95 +0,0 @@
|
||||
#! gmake
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
include config.mk
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
export:: private_export
|
||||
|
||||
# On AIX 4.3, IBM xlC_r compiler (version 3.6.6) cannot compile
|
||||
# pkcs11c.c in 64-bit mode for unknown reasons. A workaround is
|
||||
# to compile it with optimizations turned on. (Bugzilla bug #63815)
|
||||
ifeq ($(OS_TARGET)$(OS_RELEASE),AIX4.3)
|
||||
ifeq ($(USE_64),1)
|
||||
ifndef BUILD_OPT
|
||||
$(OBJDIR)/pkcs11.o: pkcs11.c
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -o $@ -c -O2 $(CFLAGS) $<
|
||||
$(OBJDIR)/pkcs11c.o: pkcs11c.c
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -o $@ -c -O2 $(CFLAGS) $<
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@@ -1,107 +0,0 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
# $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
|
||||
CRYPTOLIB=$(DIST)/lib/$(LIB_PREFIX)freebl.$(LIB_SUFFIX)
|
||||
CRYPTODIR=../freebl
|
||||
ifdef MOZILLA_SECURITY_BUILD
|
||||
CRYPTOLIB=$(DIST)/lib/$(LIB_PREFIX)crypto.$(LIB_SUFFIX)
|
||||
CRYPTODIR=../crypto
|
||||
endif
|
||||
|
||||
SQLITE_LIB = $(DIST)/lib/$(LIB_PREFIX)sqlite3.$(LIB_SUFFIX)
|
||||
ifdef NSS_USE_SYTEM_SQLITE
|
||||
SQLITE_LIB = -lsqlite3
|
||||
endif
|
||||
|
||||
EXTRA_LIBS += \
|
||||
$(CRYPTOLIB) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)secutil.$(LIB_SUFFIX) \
|
||||
$(SQLITE_LIB) \
|
||||
$(NULL)
|
||||
|
||||
# can't do this in manifest.mn because OS_TARGET isn't defined there.
|
||||
ifeq (,$(filter-out WIN%,$(OS_TARGET)))
|
||||
|
||||
# don't want the 32 in the shared library name
|
||||
SHARED_LIBRARY = $(OBJDIR)/$(DLL_PREFIX)$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
|
||||
IMPORT_LIBRARY = $(OBJDIR)/$(IMPORT_LIB_PREFIX)$(LIBRARY_NAME)$(LIBRARY_VERSION)$(IMPORT_LIB_SUFFIX)
|
||||
|
||||
RES = $(OBJDIR)/$(LIBRARY_NAME).res
|
||||
RESNAME = $(LIBRARY_NAME).rc
|
||||
|
||||
ifdef NS_USE_GCC
|
||||
EXTRA_SHARED_LIBS += \
|
||||
-L$(NSPR_LIB_DIR) \
|
||||
-lplc4 \
|
||||
-lplds4 \
|
||||
-lnspr4 \
|
||||
$(NULL)
|
||||
else # ! NS_USE_GCC
|
||||
|
||||
EXTRA_SHARED_LIBS += \
|
||||
$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plc4.lib \
|
||||
$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plds4.lib \
|
||||
$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)nspr4.lib \
|
||||
$(NULL)
|
||||
endif # NS_USE_GCC
|
||||
|
||||
else
|
||||
|
||||
# $(PROGRAM) has NO explicit dependencies on $(EXTRA_SHARED_LIBS)
|
||||
# $(EXTRA_SHARED_LIBS) come before $(OS_LIBS), except on AIX.
|
||||
EXTRA_SHARED_LIBS += \
|
||||
-L$(NSPR_LIB_DIR) \
|
||||
-lplc4 \
|
||||
-lplds4 \
|
||||
-lnspr4 \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifeq ($(OS_TARGET),SunOS)
|
||||
# The -R '$ORIGIN' linker option instructs this library to search for its
|
||||
# dependencies in the same directory where it resides.
|
||||
MKSHLIB += -R '$$ORIGIN'
|
||||
OS_LIBS += -lbsm
|
||||
endif
|
||||
|
||||
ifeq ($(OS_TARGET),WINCE)
|
||||
DEFINES += -DDBM_USING_NSPR
|
||||
endif
|
||||
|
||||
# indicates dependency on freebl static lib
|
||||
$(SHARED_LIBRARY): $(CRYPTOLIB)
|
||||
@@ -1,641 +0,0 @@
|
||||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Elliptic Curve Cryptography library.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Sun Microsystems, Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com> and
|
||||
* Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
|
||||
#include "blapi.h"
|
||||
#include "secoid.h"
|
||||
#include "secitem.h"
|
||||
#include "secerr.h"
|
||||
#include "ec.h"
|
||||
#include "ecl-curve.h"
|
||||
|
||||
#define CHECK_OK(func) if (func == NULL) goto cleanup
|
||||
#define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup
|
||||
|
||||
/*
|
||||
* Initializes a SECItem from a hexadecimal string
|
||||
*
|
||||
* Warning: This function ignores leading 00's, so any leading 00's
|
||||
* in the hexadecimal string must be optional.
|
||||
*/
|
||||
static SECItem *
|
||||
hexString2SECItem(PRArenaPool *arena, SECItem *item, const char *str)
|
||||
{
|
||||
int i = 0;
|
||||
int byteval = 0;
|
||||
int tmp = PORT_Strlen(str);
|
||||
|
||||
if ((tmp % 2) != 0) return NULL;
|
||||
|
||||
/* skip leading 00's unless the hex string is "00" */
|
||||
while ((tmp > 2) && (str[0] == '0') && (str[1] == '0')) {
|
||||
str += 2;
|
||||
tmp -= 2;
|
||||
}
|
||||
|
||||
item->data = (unsigned char *) PORT_ArenaAlloc(arena, tmp/2);
|
||||
if (item->data == NULL) return NULL;
|
||||
item->len = tmp/2;
|
||||
|
||||
while (str[i]) {
|
||||
if ((str[i] >= '0') && (str[i] <= '9'))
|
||||
tmp = str[i] - '0';
|
||||
else if ((str[i] >= 'a') && (str[i] <= 'f'))
|
||||
tmp = str[i] - 'a' + 10;
|
||||
else if ((str[i] >= 'A') && (str[i] <= 'F'))
|
||||
tmp = str[i] - 'A' + 10;
|
||||
else
|
||||
return NULL;
|
||||
|
||||
byteval = byteval * 16 + tmp;
|
||||
if ((i % 2) != 0) {
|
||||
item->data[i/2] = byteval;
|
||||
byteval = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/* Copy all of the fields from srcParams into dstParams
|
||||
*/
|
||||
SECStatus
|
||||
EC_CopyParams(PRArenaPool *arena, ECParams *dstParams,
|
||||
const ECParams *srcParams)
|
||||
{
|
||||
SECStatus rv = SECFailure;
|
||||
|
||||
dstParams->arena = arena;
|
||||
dstParams->type = srcParams->type;
|
||||
dstParams->fieldID.size = srcParams->fieldID.size;
|
||||
dstParams->fieldID.type = srcParams->fieldID.type;
|
||||
if (srcParams->fieldID.type == ec_field_GFp) {
|
||||
CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->fieldID.u.prime,
|
||||
&srcParams->fieldID.u.prime));
|
||||
} else {
|
||||
CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->fieldID.u.poly,
|
||||
&srcParams->fieldID.u.poly));
|
||||
}
|
||||
dstParams->fieldID.k1 = srcParams->fieldID.k1;
|
||||
dstParams->fieldID.k2 = srcParams->fieldID.k2;
|
||||
dstParams->fieldID.k3 = srcParams->fieldID.k3;
|
||||
CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->curve.a,
|
||||
&srcParams->curve.a));
|
||||
CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->curve.b,
|
||||
&srcParams->curve.b));
|
||||
CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->curve.seed,
|
||||
&srcParams->curve.seed));
|
||||
CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->base,
|
||||
&srcParams->base));
|
||||
CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->order,
|
||||
&srcParams->order));
|
||||
CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->DEREncoding,
|
||||
&srcParams->DEREncoding));
|
||||
dstParams->name = srcParams->name;
|
||||
CHECK_SEC_OK(SECITEM_CopyItem(arena, &dstParams->curveOID,
|
||||
&srcParams->curveOID));
|
||||
dstParams->cofactor = srcParams->cofactor;
|
||||
|
||||
return SECSuccess;
|
||||
|
||||
cleanup:
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
static SECStatus
|
||||
gf_populate_params(ECCurveName name, ECFieldType field_type, ECParams *params)
|
||||
{
|
||||
SECStatus rv = SECFailure;
|
||||
const ECCurveParams *curveParams;
|
||||
/* 2 ['0'+'4'] + MAX_ECKEY_LEN * 2 [x,y] * 2 [hex string] + 1 ['\0'] */
|
||||
char genenc[3 + 2 * 2 * MAX_ECKEY_LEN];
|
||||
|
||||
if ((name < ECCurve_noName) || (name > ECCurve_pastLastCurve)) goto cleanup;
|
||||
params->name = name;
|
||||
curveParams = ecCurve_map[params->name];
|
||||
CHECK_OK(curveParams);
|
||||
params->fieldID.size = curveParams->size;
|
||||
params->fieldID.type = field_type;
|
||||
if (field_type == ec_field_GFp) {
|
||||
CHECK_OK(hexString2SECItem(params->arena, ¶ms->fieldID.u.prime,
|
||||
curveParams->irr));
|
||||
} else {
|
||||
CHECK_OK(hexString2SECItem(params->arena, ¶ms->fieldID.u.poly,
|
||||
curveParams->irr));
|
||||
}
|
||||
CHECK_OK(hexString2SECItem(params->arena, ¶ms->curve.a,
|
||||
curveParams->curvea));
|
||||
CHECK_OK(hexString2SECItem(params->arena, ¶ms->curve.b,
|
||||
curveParams->curveb));
|
||||
genenc[0] = '0';
|
||||
genenc[1] = '4';
|
||||
genenc[2] = '\0';
|
||||
strcat(genenc, curveParams->genx);
|
||||
strcat(genenc, curveParams->geny);
|
||||
CHECK_OK(hexString2SECItem(params->arena, ¶ms->base, genenc));
|
||||
CHECK_OK(hexString2SECItem(params->arena, ¶ms->order,
|
||||
curveParams->order));
|
||||
params->cofactor = curveParams->cofactor;
|
||||
|
||||
rv = SECSuccess;
|
||||
|
||||
cleanup:
|
||||
return rv;
|
||||
}
|
||||
|
||||
SECStatus
|
||||
EC_FillParams(PRArenaPool *arena, const SECItem *encodedParams,
|
||||
ECParams *params)
|
||||
{
|
||||
SECStatus rv = SECFailure;
|
||||
SECOidTag tag;
|
||||
SECItem oid = { siBuffer, NULL, 0};
|
||||
|
||||
#if EC_DEBUG
|
||||
int i;
|
||||
|
||||
printf("Encoded params in EC_DecodeParams: ");
|
||||
for (i = 0; i < encodedParams->len; i++) {
|
||||
printf("%02x:", encodedParams->data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
if ((encodedParams->len != ANSI_X962_CURVE_OID_TOTAL_LEN) &&
|
||||
(encodedParams->len != SECG_CURVE_OID_TOTAL_LEN)) {
|
||||
PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE);
|
||||
return SECFailure;
|
||||
};
|
||||
|
||||
oid.len = encodedParams->len - 2;
|
||||
oid.data = encodedParams->data + 2;
|
||||
if ((encodedParams->data[0] != SEC_ASN1_OBJECT_ID) ||
|
||||
((tag = SECOID_FindOIDTag(&oid)) == SEC_OID_UNKNOWN)) {
|
||||
PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
params->arena = arena;
|
||||
params->cofactor = 0;
|
||||
params->type = ec_params_named;
|
||||
params->name = ECCurve_noName;
|
||||
|
||||
/* For named curves, fill out curveOID */
|
||||
params->curveOID.len = oid.len;
|
||||
params->curveOID.data = (unsigned char *) PORT_ArenaAlloc(arena, oid.len);
|
||||
if (params->curveOID.data == NULL) goto cleanup;
|
||||
memcpy(params->curveOID.data, oid.data, oid.len);
|
||||
|
||||
#if EC_DEBUG
|
||||
printf("Curve: %s\n", SECOID_FindOIDTagDescription(tag));
|
||||
#endif
|
||||
|
||||
switch (tag) {
|
||||
|
||||
/* Binary curves */
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2PNB163V1:
|
||||
/* Populate params for c2pnb163v1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB163V1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2PNB163V2:
|
||||
/* Populate params for c2pnb163v2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB163V2, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2PNB163V3:
|
||||
/* Populate params for c2pnb163v3 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB163V3, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2PNB176V1:
|
||||
/* Populate params for c2pnb176v1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB176V1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2TNB191V1:
|
||||
/* Populate params for c2tnb191v1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB191V1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2TNB191V2:
|
||||
/* Populate params for c2tnb191v2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB191V2, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2TNB191V3:
|
||||
/* Populate params for c2tnb191v3 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB191V3, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2PNB208W1:
|
||||
/* Populate params for c2pnb208w1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB208W1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2TNB239V1:
|
||||
/* Populate params for c2tnb239v1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB239V1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2TNB239V2:
|
||||
/* Populate params for c2tnb239v2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB239V2, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2TNB239V3:
|
||||
/* Populate params for c2tnb239v3 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB239V3, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2PNB272W1:
|
||||
/* Populate params for c2pnb272w1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB272W1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2PNB304W1:
|
||||
/* Populate params for c2pnb304w1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB304W1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2TNB359V1:
|
||||
/* Populate params for c2tnb359v1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB359V1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2PNB368W1:
|
||||
/* Populate params for c2pnb368w1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB368W1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_C2TNB431R1:
|
||||
/* Populate params for c2tnb431r1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB431R1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT113R1:
|
||||
/* Populate params for sect113r1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_113R1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT113R2:
|
||||
/* Populate params for sect113r2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_113R2, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT131R1:
|
||||
/* Populate params for sect131r1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_131R1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT131R2:
|
||||
/* Populate params for sect131r2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_131R2, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT163K1:
|
||||
/* Populate params for sect163k1
|
||||
* (the NIST K-163 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_163K1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT163R1:
|
||||
/* Populate params for sect163r1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_163R1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT163R2:
|
||||
/* Populate params for sect163r2
|
||||
* (the NIST B-163 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_163R2, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT193R1:
|
||||
/* Populate params for sect193r1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_193R1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT193R2:
|
||||
/* Populate params for sect193r2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_193R2, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT233K1:
|
||||
/* Populate params for sect233k1
|
||||
* (the NIST K-233 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_233K1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT233R1:
|
||||
/* Populate params for sect233r1
|
||||
* (the NIST B-233 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_233R1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT239K1:
|
||||
/* Populate params for sect239k1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_239K1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT283K1:
|
||||
/* Populate params for sect283k1
|
||||
* (the NIST K-283 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_283K1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT283R1:
|
||||
/* Populate params for sect283r1
|
||||
* (the NIST B-283 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_283R1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT409K1:
|
||||
/* Populate params for sect409k1
|
||||
* (the NIST K-409 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_409K1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT409R1:
|
||||
/* Populate params for sect409r1
|
||||
* (the NIST B-409 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_409R1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT571K1:
|
||||
/* Populate params for sect571k1
|
||||
* (the NIST K-571 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_571K1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECT571R1:
|
||||
/* Populate params for sect571r1
|
||||
* (the NIST B-571 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_571R1, ec_field_GF2m,
|
||||
params) );
|
||||
break;
|
||||
|
||||
/* Prime curves */
|
||||
|
||||
case SEC_OID_ANSIX962_EC_PRIME192V1:
|
||||
/* Populate params for prime192v1 aka secp192r1
|
||||
* (the NIST P-192 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_192V1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_PRIME192V2:
|
||||
/* Populate params for prime192v2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_192V2, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_PRIME192V3:
|
||||
/* Populate params for prime192v3 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_192V3, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_PRIME239V1:
|
||||
/* Populate params for prime239v1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_239V1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_PRIME239V2:
|
||||
/* Populate params for prime239v2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_239V2, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_PRIME239V3:
|
||||
/* Populate params for prime239v3 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_239V3, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_ANSIX962_EC_PRIME256V1:
|
||||
/* Populate params for prime256v1 aka secp256r1
|
||||
* (the NIST P-256 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_256V1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP112R1:
|
||||
/* Populate params for secp112r1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_112R1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP112R2:
|
||||
/* Populate params for secp112r2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_112R2, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP128R1:
|
||||
/* Populate params for secp128r1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_128R1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP128R2:
|
||||
/* Populate params for secp128r2 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_128R2, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP160K1:
|
||||
/* Populate params for secp160k1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_160K1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP160R1:
|
||||
/* Populate params for secp160r1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_160R1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP160R2:
|
||||
/* Populate params for secp160r1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_160R2, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP192K1:
|
||||
/* Populate params for secp192k1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_192K1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP224K1:
|
||||
/* Populate params for secp224k1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_224K1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP224R1:
|
||||
/* Populate params for secp224r1
|
||||
* (the NIST P-224 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_224R1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP256K1:
|
||||
/* Populate params for secp256k1 */
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_256K1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP384R1:
|
||||
/* Populate params for secp384r1
|
||||
* (the NIST P-384 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_384R1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
case SEC_OID_SECG_EC_SECP521R1:
|
||||
/* Populate params for secp521r1
|
||||
* (the NIST P-521 curve)
|
||||
*/
|
||||
CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_521R1, ec_field_GFp,
|
||||
params) );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
cleanup:
|
||||
if (!params->cofactor) {
|
||||
PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE);
|
||||
#if EC_DEBUG
|
||||
printf("Unrecognized curve, returning NULL params\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
SECStatus
|
||||
EC_DecodeParams(const SECItem *encodedParams, ECParams **ecparams)
|
||||
{
|
||||
PRArenaPool *arena;
|
||||
ECParams *params;
|
||||
SECStatus rv = SECFailure;
|
||||
|
||||
/* Initialize an arena for the ECParams structure */
|
||||
if (!(arena = PORT_NewArena(NSS_FREEBL_DEFAULT_CHUNKSIZE)))
|
||||
return SECFailure;
|
||||
|
||||
params = (ECParams *)PORT_ArenaZAlloc(arena, sizeof(ECParams));
|
||||
if (!params) {
|
||||
PORT_FreeArena(arena, PR_TRUE);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
/* Copy the encoded params */
|
||||
SECITEM_AllocItem(arena, &(params->DEREncoding),
|
||||
encodedParams->len);
|
||||
memcpy(params->DEREncoding.data, encodedParams->data, encodedParams->len);
|
||||
|
||||
/* Fill out the rest of the ECParams structure based on
|
||||
* the encoded params
|
||||
*/
|
||||
rv = EC_FillParams(arena, encodedParams, params);
|
||||
if (rv == SECFailure) {
|
||||
PORT_FreeArena(arena, PR_TRUE);
|
||||
return SECFailure;
|
||||
} else {
|
||||
*ecparams = params;;
|
||||
return SECSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
@@ -1,351 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Network Security Services (NSS).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Red Hat, Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
* This file implements audit logging required by FIPS 140-2 Security
|
||||
* Level 2.
|
||||
*/
|
||||
|
||||
#include "prprf.h"
|
||||
#include "softoken.h"
|
||||
|
||||
/*
|
||||
* Print the value of the returned object handle in the output buffer
|
||||
* on a successful return of the PKCS #11 function. If the PKCS #11
|
||||
* function failed or the pointer to object handle is NULL (which is
|
||||
* the case for C_DeriveKey with CKM_TLS_KEY_AND_MAC_DERIVE), an empty
|
||||
* string is stored in the output buffer.
|
||||
*
|
||||
* out: the output buffer
|
||||
* outlen: the length of the output buffer
|
||||
* argName: the name of the "pointer to object handle" argument
|
||||
* phObject: the pointer to object handle
|
||||
* rv: the return value of the PKCS #11 function
|
||||
*/
|
||||
static void sftk_PrintReturnedObjectHandle(char *out, PRUint32 outlen,
|
||||
const char *argName, CK_OBJECT_HANDLE_PTR phObject, CK_RV rv)
|
||||
{
|
||||
if ((rv == CKR_OK) && phObject) {
|
||||
PR_snprintf(out, outlen,
|
||||
" *%s=0x%08lX", argName, (PRUint32)*phObject);
|
||||
} else {
|
||||
PORT_Assert(outlen != 0);
|
||||
out[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MECHANISM_BUFSIZE needs to be large enough for sftk_PrintMechanism,
|
||||
* which uses <= 49 bytes.
|
||||
*/
|
||||
#define MECHANISM_BUFSIZE 64
|
||||
|
||||
static void sftk_PrintMechanism(char *out, PRUint32 outlen,
|
||||
CK_MECHANISM_PTR pMechanism)
|
||||
{
|
||||
if (pMechanism) {
|
||||
/*
|
||||
* If we change the format string, we need to make sure
|
||||
* MECHANISM_BUFSIZE is still large enough. We allow
|
||||
* 20 bytes for %p on a 64-bit platform.
|
||||
*/
|
||||
PR_snprintf(out, outlen, "%p {mechanism=0x%08lX, ...}",
|
||||
pMechanism, (PRUint32)pMechanism->mechanism);
|
||||
} else {
|
||||
PR_snprintf(out, outlen, "%p", pMechanism);
|
||||
}
|
||||
}
|
||||
|
||||
void sftk_AuditCreateObject(CK_SESSION_HANDLE hSession,
|
||||
CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
|
||||
CK_OBJECT_HANDLE_PTR phObject, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
char shObject[32];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
sftk_PrintReturnedObjectHandle(shObject, sizeof shObject,
|
||||
"phObject", phObject, rv);
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_CreateObject(hSession=0x%08lX, pTemplate=%p, ulCount=%lu, "
|
||||
"phObject=%p)=0x%08lX%s",
|
||||
(PRUint32)hSession, pTemplate, (PRUint32)ulCount,
|
||||
phObject, (PRUint32)rv, shObject);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditCopyObject(CK_SESSION_HANDLE hSession,
|
||||
CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
|
||||
CK_OBJECT_HANDLE_PTR phNewObject, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
char shNewObject[32];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
sftk_PrintReturnedObjectHandle(shNewObject, sizeof shNewObject,
|
||||
"phNewObject", phNewObject, rv);
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_CopyObject(hSession=0x%08lX, hObject=0x%08lX, "
|
||||
"pTemplate=%p, ulCount=%lu, phNewObject=%p)=0x%08lX%s",
|
||||
(PRUint32)hSession, (PRUint32)hObject,
|
||||
pTemplate, (PRUint32)ulCount, phNewObject, (PRUint32)rv, shNewObject);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
/* WARNING: hObject has been destroyed and can only be printed. */
|
||||
void sftk_AuditDestroyObject(CK_SESSION_HANDLE hSession,
|
||||
CK_OBJECT_HANDLE hObject, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_DestroyObject(hSession=0x%08lX, hObject=0x%08lX)=0x%08lX",
|
||||
(PRUint32)hSession, (PRUint32)hObject, (PRUint32)rv);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditGetObjectSize(CK_SESSION_HANDLE hSession,
|
||||
CK_OBJECT_HANDLE hObject, CK_ULONG_PTR pulSize, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_GetObjectSize(hSession=0x%08lX, hObject=0x%08lX, "
|
||||
"pulSize=%p)=0x%08lX",
|
||||
(PRUint32)hSession, (PRUint32)hObject,
|
||||
pulSize, (PRUint32)rv);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditGetAttributeValue(CK_SESSION_HANDLE hSession,
|
||||
CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate,
|
||||
CK_ULONG ulCount, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_GetAttributeValue(hSession=0x%08lX, hObject=0x%08lX, "
|
||||
"pTemplate=%p, ulCount=%lu)=0x%08lX",
|
||||
(PRUint32)hSession, (PRUint32)hObject,
|
||||
pTemplate, (PRUint32)ulCount, (PRUint32)rv);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditSetAttributeValue(CK_SESSION_HANDLE hSession,
|
||||
CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate,
|
||||
CK_ULONG ulCount, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_SetAttributeValue(hSession=0x%08lX, hObject=0x%08lX, "
|
||||
"pTemplate=%p, ulCount=%lu)=0x%08lX",
|
||||
(PRUint32)hSession, (PRUint32)hObject,
|
||||
pTemplate, (PRUint32)ulCount, (PRUint32)rv);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditCryptInit(const char *opName, CK_SESSION_HANDLE hSession,
|
||||
CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
char mech[MECHANISM_BUFSIZE];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
sftk_PrintMechanism(mech, sizeof mech, pMechanism);
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_%sInit(hSession=0x%08lX, pMechanism=%s, "
|
||||
"hKey=0x%08lX)=0x%08lX",
|
||||
opName, (PRUint32)hSession, mech,
|
||||
(PRUint32)hKey, (PRUint32)rv);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditGenerateKey(CK_SESSION_HANDLE hSession,
|
||||
CK_MECHANISM_PTR pMechanism, CK_ATTRIBUTE_PTR pTemplate,
|
||||
CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phKey, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
char mech[MECHANISM_BUFSIZE];
|
||||
char shKey[32];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
sftk_PrintMechanism(mech, sizeof mech, pMechanism);
|
||||
sftk_PrintReturnedObjectHandle(shKey, sizeof shKey, "phKey", phKey, rv);
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_GenerateKey(hSession=0x%08lX, pMechanism=%s, "
|
||||
"pTemplate=%p, ulCount=%lu, phKey=%p)=0x%08lX%s",
|
||||
(PRUint32)hSession, mech,
|
||||
pTemplate, (PRUint32)ulCount, phKey, (PRUint32)rv, shKey);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditGenerateKeyPair(CK_SESSION_HANDLE hSession,
|
||||
CK_MECHANISM_PTR pMechanism, CK_ATTRIBUTE_PTR pPublicKeyTemplate,
|
||||
CK_ULONG ulPublicKeyAttributeCount, CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
|
||||
CK_ULONG ulPrivateKeyAttributeCount, CK_OBJECT_HANDLE_PTR phPublicKey,
|
||||
CK_OBJECT_HANDLE_PTR phPrivateKey, CK_RV rv)
|
||||
{
|
||||
char msg[512];
|
||||
char mech[MECHANISM_BUFSIZE];
|
||||
char shPublicKey[32];
|
||||
char shPrivateKey[32];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
sftk_PrintMechanism(mech, sizeof mech, pMechanism);
|
||||
sftk_PrintReturnedObjectHandle(shPublicKey, sizeof shPublicKey,
|
||||
"phPublicKey", phPublicKey, rv);
|
||||
sftk_PrintReturnedObjectHandle(shPrivateKey, sizeof shPrivateKey,
|
||||
"phPrivateKey", phPrivateKey, rv);
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_GenerateKeyPair(hSession=0x%08lX, pMechanism=%s, "
|
||||
"pPublicKeyTemplate=%p, ulPublicKeyAttributeCount=%lu, "
|
||||
"pPrivateKeyTemplate=%p, ulPrivateKeyAttributeCount=%lu, "
|
||||
"phPublicKey=%p, phPrivateKey=%p)=0x%08lX%s%s",
|
||||
(PRUint32)hSession, mech,
|
||||
pPublicKeyTemplate, (PRUint32)ulPublicKeyAttributeCount,
|
||||
pPrivateKeyTemplate, (PRUint32)ulPrivateKeyAttributeCount,
|
||||
phPublicKey, phPrivateKey, (PRUint32)rv, shPublicKey, shPrivateKey);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditWrapKey(CK_SESSION_HANDLE hSession,
|
||||
CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hWrappingKey,
|
||||
CK_OBJECT_HANDLE hKey, CK_BYTE_PTR pWrappedKey,
|
||||
CK_ULONG_PTR pulWrappedKeyLen, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
char mech[MECHANISM_BUFSIZE];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
sftk_PrintMechanism(mech, sizeof mech, pMechanism);
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_WrapKey(hSession=0x%08lX, pMechanism=%s, hWrappingKey=0x%08lX, "
|
||||
"hKey=0x%08lX, pWrappedKey=%p, pulWrappedKeyLen=%p)=0x%08lX",
|
||||
(PRUint32)hSession, mech, (PRUint32)hWrappingKey,
|
||||
(PRUint32)hKey, pWrappedKey, pulWrappedKeyLen, (PRUint32)rv);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditUnwrapKey(CK_SESSION_HANDLE hSession,
|
||||
CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hUnwrappingKey,
|
||||
CK_BYTE_PTR pWrappedKey, CK_ULONG ulWrappedKeyLen,
|
||||
CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount,
|
||||
CK_OBJECT_HANDLE_PTR phKey, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
char mech[MECHANISM_BUFSIZE];
|
||||
char shKey[32];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
sftk_PrintMechanism(mech, sizeof mech, pMechanism);
|
||||
sftk_PrintReturnedObjectHandle(shKey, sizeof shKey, "phKey", phKey, rv);
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_UnwrapKey(hSession=0x%08lX, pMechanism=%s, "
|
||||
"hUnwrappingKey=0x%08lX, pWrappedKey=%p, ulWrappedKeyLen=%lu, "
|
||||
"pTemplate=%p, ulAttributeCount=%lu, phKey=%p)=0x%08lX%s",
|
||||
(PRUint32)hSession, mech,
|
||||
(PRUint32)hUnwrappingKey, pWrappedKey, (PRUint32)ulWrappedKeyLen,
|
||||
pTemplate, (PRUint32)ulAttributeCount, phKey, (PRUint32)rv, shKey);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditDeriveKey(CK_SESSION_HANDLE hSession,
|
||||
CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hBaseKey,
|
||||
CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount,
|
||||
CK_OBJECT_HANDLE_PTR phKey, CK_RV rv)
|
||||
{
|
||||
char msg[512];
|
||||
char mech[MECHANISM_BUFSIZE];
|
||||
char shKey[32];
|
||||
char sTlsKeys[128];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
sftk_PrintMechanism(mech, sizeof mech, pMechanism);
|
||||
sftk_PrintReturnedObjectHandle(shKey, sizeof shKey, "phKey", phKey, rv);
|
||||
if ((rv == CKR_OK) &&
|
||||
(pMechanism->mechanism == CKM_TLS_KEY_AND_MAC_DERIVE)) {
|
||||
CK_SSL3_KEY_MAT_PARAMS *param =
|
||||
(CK_SSL3_KEY_MAT_PARAMS *)pMechanism->pParameter;
|
||||
CK_SSL3_KEY_MAT_OUT *keymat = param->pReturnedKeyMaterial;
|
||||
PR_snprintf(sTlsKeys, sizeof sTlsKeys,
|
||||
" hClientMacSecret=0x%08lX hServerMacSecret=0x%08lX"
|
||||
" hClientKey=0x%08lX hServerKey=0x%08lX",
|
||||
(PRUint32)keymat->hClientMacSecret,
|
||||
(PRUint32)keymat->hServerMacSecret,
|
||||
(PRUint32)keymat->hClientKey,
|
||||
(PRUint32)keymat->hServerKey);
|
||||
} else {
|
||||
sTlsKeys[0] = '\0';
|
||||
}
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_DeriveKey(hSession=0x%08lX, pMechanism=%s, "
|
||||
"hBaseKey=0x%08lX, pTemplate=%p, ulAttributeCount=%lu, "
|
||||
"phKey=%p)=0x%08lX%s%s",
|
||||
(PRUint32)hSession, mech,
|
||||
(PRUint32)hBaseKey, pTemplate,(PRUint32)ulAttributeCount,
|
||||
phKey, (PRUint32)rv, shKey, sTlsKeys);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
|
||||
void sftk_AuditDigestKey(CK_SESSION_HANDLE hSession,
|
||||
CK_OBJECT_HANDLE hKey, CK_RV rv)
|
||||
{
|
||||
char msg[256];
|
||||
NSSAuditSeverity severity = (rv == CKR_OK) ?
|
||||
NSS_AUDIT_INFO : NSS_AUDIT_ERROR;
|
||||
|
||||
PR_snprintf(msg, sizeof msg,
|
||||
"C_DigestKey(hSession=0x%08lX, hKey=0x%08lX)=0x%08lX",
|
||||
(PRUint32)hSession, (PRUint32)hKey, (PRUint32)rv);
|
||||
sftk_LogAuditMessage(severity, msg);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,80 +0,0 @@
|
||||
#! gmake
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
include config.mk
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
export:: private_export
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* cdbhdl.h - certificate database handle
|
||||
* private to the certdb module
|
||||
*
|
||||
* $Id: cdbhdl.h,v 1.1.2.1 2007-04-03 22:50:02 rrelyea%redhat.com Exp $
|
||||
*/
|
||||
#ifndef _CDBHDL_H_
|
||||
#define _CDBHDL_H_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "mcom_db.h"
|
||||
#include "pcertt.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
/*
|
||||
* Handle structure for open certificate databases
|
||||
*/
|
||||
struct NSSLOWCERTCertDBHandleStr {
|
||||
DB *permCertDB;
|
||||
PZMonitor *dbMon;
|
||||
PRBool dbVerify;
|
||||
PRInt32 ref; /* reference count */
|
||||
};
|
||||
|
||||
#ifdef DBM_USING_NSPR
|
||||
#define NO_RDONLY PR_RDONLY
|
||||
#define NO_RDWR PR_RDWR
|
||||
#define NO_CREATE (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE)
|
||||
#else
|
||||
#define NO_RDONLY O_RDONLY
|
||||
#define NO_RDWR O_RDWR
|
||||
#define NO_CREATE (O_RDWR | O_CREAT | O_TRUNC)
|
||||
#endif
|
||||
|
||||
typedef DB * (*rdbfunc)(const char *appName, const char *prefix,
|
||||
const char *type, int flags);
|
||||
typedef int (*rdbstatusfunc)(void);
|
||||
|
||||
#define RDB_FAIL 1
|
||||
#define RDB_RETRY 2
|
||||
|
||||
DB * rdbopen(const char *appName, const char *prefix,
|
||||
const char *type, int flags, int *status);
|
||||
|
||||
DB *dbsopen (const char *dbname , int flags, int mode, DBTYPE type,
|
||||
const void * appData);
|
||||
SECStatus db_Copy(DB *dest,DB *src);
|
||||
int db_InitComplete(DB *db);
|
||||
|
||||
#endif
|
||||
@@ -1,102 +0,0 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
# $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
|
||||
CRYPTOLIB=$(DIST)/lib/$(LIB_PREFIX)freebl.$(LIB_SUFFIX)
|
||||
CRYPTODIR=../freebl
|
||||
ifdef MOZILLA_SECURITY_BUILD
|
||||
CRYPTOLIB=$(DIST)/lib/$(LIB_PREFIX)crypto.$(LIB_SUFFIX)
|
||||
CRYPTODIR=../crypto
|
||||
endif
|
||||
|
||||
EXTRA_LIBS += \
|
||||
$(CRYPTOLIB) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)secutil.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)dbm.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
|
||||
# can't do this in manifest.mn because OS_TARGET isn't defined there.
|
||||
ifeq (,$(filter-out WIN%,$(OS_TARGET)))
|
||||
|
||||
# don't want the 32 in the shared library name
|
||||
SHARED_LIBRARY = $(OBJDIR)/$(DLL_PREFIX)$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
|
||||
IMPORT_LIBRARY = $(OBJDIR)/$(IMPORT_LIB_PREFIX)$(LIBRARY_NAME)$(LIBRARY_VERSION)$(IMPORT_LIB_SUFFIX)
|
||||
|
||||
RES = $(OBJDIR)/$(LIBRARY_NAME).res
|
||||
RESNAME = $(LIBRARY_NAME).rc
|
||||
|
||||
ifdef NS_USE_GCC
|
||||
EXTRA_SHARED_LIBS += \
|
||||
-L$(NSPR_LIB_DIR) \
|
||||
-lplc4 \
|
||||
-lplds4 \
|
||||
-lnspr4 \
|
||||
$(NULL)
|
||||
else # ! NS_USE_GCC
|
||||
|
||||
EXTRA_SHARED_LIBS += \
|
||||
$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plc4.lib \
|
||||
$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plds4.lib \
|
||||
$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)nspr4.lib \
|
||||
$(NULL)
|
||||
endif # NS_USE_GCC
|
||||
|
||||
else
|
||||
|
||||
# $(PROGRAM) has NO explicit dependencies on $(EXTRA_SHARED_LIBS)
|
||||
# $(EXTRA_SHARED_LIBS) come before $(OS_LIBS), except on AIX.
|
||||
EXTRA_SHARED_LIBS += \
|
||||
-L$(NSPR_LIB_DIR) \
|
||||
-lplc4 \
|
||||
-lplds4 \
|
||||
-lnspr4 \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifeq ($(OS_TARGET),SunOS)
|
||||
# The -R '$ORIGIN' linker option instructs this library to search for its
|
||||
# dependencies in the same directory where it resides.
|
||||
MKSHLIB += -R '$$ORIGIN'
|
||||
OS_LIBS += -lbsm
|
||||
endif
|
||||
|
||||
ifeq ($(OS_TARGET),WINCE)
|
||||
DEFINES += -DDBM_USING_NSPR
|
||||
endif
|
||||
|
||||
# indicates dependency on freebl static lib
|
||||
$(SHARED_LIBRARY): $(CRYPTOLIB)
|
||||
@@ -1,647 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
* Berkeley DB 1.85 Shim code to handle blobs.
|
||||
*
|
||||
* $Id: dbmshim.c,v 1.1.2.1 2007-04-03 22:50:02 rrelyea%redhat.com Exp $
|
||||
*/
|
||||
#include "mcom_db.h"
|
||||
#include "secitem.h"
|
||||
#include "nssb64.h"
|
||||
#include "blapi.h"
|
||||
#include "secerr.h"
|
||||
|
||||
#include "lgdb.h"
|
||||
|
||||
/*
|
||||
* Blob block:
|
||||
* Byte 0 CERTDB Version -+ -+
|
||||
* Byte 1 certDBEntryTypeBlob | BLOB_HEAD_LEN |
|
||||
* Byte 2 flags (always '0'); | |
|
||||
* Byte 3 reserved (always '0'); -+ |
|
||||
* Byte 4 LSB length | <--BLOB_LENGTH_START | BLOB_BUF_LEN
|
||||
* Byte 5 . | |
|
||||
* Byte 6 . | BLOB_LENGTH_LEN |
|
||||
* Byte 7 MSB length | |
|
||||
* Byte 8 blob_filename -+ -+ <-- BLOB_NAME_START |
|
||||
* Byte 9 . | BLOB_NAME_LEN |
|
||||
* . . | |
|
||||
* Byte 37 . -+ -+
|
||||
*/
|
||||
#define DBS_BLOCK_SIZE (16*1024) /* 16 k */
|
||||
#define DBS_MAX_ENTRY_SIZE (DBS_BLOCK_SIZE - (2048)) /* 14 k */
|
||||
#define DBS_CACHE_SIZE DBS_BLOCK_SIZE*8
|
||||
#define ROUNDDIV(x,y) (x+(y-1))/y
|
||||
#define BLOB_HEAD_LEN 4
|
||||
#define BLOB_LENGTH_START BLOB_HEAD_LEN
|
||||
#define BLOB_LENGTH_LEN 4
|
||||
#define BLOB_NAME_START BLOB_LENGTH_START+BLOB_LENGTH_LEN
|
||||
#define BLOB_NAME_LEN 1+ROUNDDIV(SHA1_LENGTH,3)*4+1
|
||||
#define BLOB_BUF_LEN BLOB_HEAD_LEN+BLOB_LENGTH_LEN+BLOB_NAME_LEN
|
||||
|
||||
/* a Shim data structure. This data structure has a db built into it. */
|
||||
typedef struct DBSStr DBS;
|
||||
|
||||
struct DBSStr {
|
||||
DB db;
|
||||
char *blobdir;
|
||||
int mode;
|
||||
PRBool readOnly;
|
||||
PRFileMap *dbs_mapfile;
|
||||
unsigned char *dbs_addr;
|
||||
PRUint32 dbs_len;
|
||||
char staticBlobArea[BLOB_BUF_LEN];
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* return true if the Datablock contains a blobtype
|
||||
*/
|
||||
static PRBool
|
||||
dbs_IsBlob(DBT *blobData)
|
||||
{
|
||||
unsigned char *addr = (unsigned char *)blobData->data;
|
||||
if (blobData->size < BLOB_BUF_LEN) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
return addr && ((certDBEntryType) addr[1] == certDBEntryTypeBlob);
|
||||
}
|
||||
|
||||
/*
|
||||
* extract the filename in the blob of the real data set.
|
||||
* This value is not malloced (does not need to be freed by the caller.
|
||||
*/
|
||||
static const char *
|
||||
dbs_getBlobFileName(DBT *blobData)
|
||||
{
|
||||
char *addr = (char *)blobData->data;
|
||||
|
||||
return &addr[BLOB_NAME_START];
|
||||
}
|
||||
|
||||
/*
|
||||
* extract the size of the actual blob from the blob record
|
||||
*/
|
||||
static PRUint32
|
||||
dbs_getBlobSize(DBT *blobData)
|
||||
{
|
||||
unsigned char *addr = (unsigned char *)blobData->data;
|
||||
|
||||
return (PRUint32)(addr[BLOB_LENGTH_START+3] << 24) |
|
||||
(addr[BLOB_LENGTH_START+2] << 16) |
|
||||
(addr[BLOB_LENGTH_START+1] << 8) |
|
||||
addr[BLOB_LENGTH_START];
|
||||
}
|
||||
|
||||
|
||||
/* We are using base64 data for the filename, but base64 data can include a
|
||||
* '/' which is interpreted as a path separator on many platforms. Replace it
|
||||
* with an inocuous '-'. We don't need to convert back because we never actual
|
||||
* decode the filename.
|
||||
*/
|
||||
|
||||
static void
|
||||
dbs_replaceSlash(char *cp, int len)
|
||||
{
|
||||
while (len--) {
|
||||
if (*cp == '/') *cp = '-';
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* create a blob record from a key, data and return it in blobData.
|
||||
* NOTE: The data element is static data (keeping with the dbm model).
|
||||
*/
|
||||
static void
|
||||
dbs_mkBlob(DBS *dbsp,const DBT *key, const DBT *data, DBT *blobData)
|
||||
{
|
||||
unsigned char sha1_data[SHA1_LENGTH];
|
||||
char *b = dbsp->staticBlobArea;
|
||||
PRUint32 length = data->size;
|
||||
SECItem sha1Item;
|
||||
|
||||
b[0] = CERT_DB_FILE_VERSION; /* certdb version number */
|
||||
b[1] = (char) certDBEntryTypeBlob; /* type */
|
||||
b[2] = 0; /* flags */
|
||||
b[3] = 0; /* reserved */
|
||||
b[BLOB_LENGTH_START] = length & 0xff;
|
||||
b[BLOB_LENGTH_START+1] = (length >> 8) & 0xff;
|
||||
b[BLOB_LENGTH_START+2] = (length >> 16) & 0xff;
|
||||
b[BLOB_LENGTH_START+3] = (length >> 24) & 0xff;
|
||||
sha1Item.data = sha1_data;
|
||||
sha1Item.len = SHA1_LENGTH;
|
||||
SHA1_HashBuf(sha1_data,key->data,key->size);
|
||||
b[BLOB_NAME_START]='b'; /* Make sure we start with a alpha */
|
||||
NSSBase64_EncodeItem(NULL,&b[BLOB_NAME_START+1],BLOB_NAME_LEN-1,&sha1Item);
|
||||
b[BLOB_BUF_LEN-1] = 0;
|
||||
dbs_replaceSlash(&b[BLOB_NAME_START+1],BLOB_NAME_LEN-1);
|
||||
blobData->data = b;
|
||||
blobData->size = BLOB_BUF_LEN;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* construct a path to the actual blob. The string returned must be
|
||||
* freed by the caller with PR_smprintf_free.
|
||||
*
|
||||
* Note: this file does lots of consistancy checks on the DBT. The
|
||||
* routines that call this depend on these checks, so they don't worry
|
||||
* about them (success of this routine implies a good blobdata record).
|
||||
*/
|
||||
static char *
|
||||
dbs_getBlobFilePath(char *blobdir,DBT *blobData)
|
||||
{
|
||||
const char *name;
|
||||
|
||||
if (blobdir == NULL) {
|
||||
PR_SetError(SEC_ERROR_BAD_DATABASE,0);
|
||||
return NULL;
|
||||
}
|
||||
if (!dbs_IsBlob(blobData)) {
|
||||
PR_SetError(SEC_ERROR_BAD_DATABASE,0);
|
||||
return NULL;
|
||||
}
|
||||
name = dbs_getBlobFileName(blobData);
|
||||
if (!name || *name == 0) {
|
||||
PR_SetError(SEC_ERROR_BAD_DATABASE,0);
|
||||
return NULL;
|
||||
}
|
||||
return PR_smprintf("%s" PATH_SEPARATOR "%s", blobdir, name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a blob file pointed to by the blob record.
|
||||
*/
|
||||
static void
|
||||
dbs_removeBlob(DBS *dbsp, DBT *blobData)
|
||||
{
|
||||
char *file;
|
||||
|
||||
file = dbs_getBlobFilePath(dbsp->blobdir, blobData);
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
PR_Delete(file);
|
||||
PR_smprintf_free(file);
|
||||
}
|
||||
|
||||
/*
|
||||
* Directory modes are slightly different, the 'x' bit needs to be on to
|
||||
* access them. Copy all the read bits to 'x' bits
|
||||
*/
|
||||
static int
|
||||
dbs_DirMode(int mode)
|
||||
{
|
||||
int x_bits = (mode >> 2) & 0111;
|
||||
return mode | x_bits;
|
||||
}
|
||||
|
||||
/*
|
||||
* write a data blob to it's file. blobdData is the blob record that will be
|
||||
* stored in the database. data is the actual data to go out on disk.
|
||||
*/
|
||||
static int
|
||||
dbs_writeBlob(DBS *dbsp, int mode, DBT *blobData, const DBT *data)
|
||||
{
|
||||
char *file = NULL;
|
||||
PRFileDesc *filed;
|
||||
PRStatus status;
|
||||
int len;
|
||||
int error = 0;
|
||||
|
||||
file = dbs_getBlobFilePath(dbsp->blobdir, blobData);
|
||||
if (!file) {
|
||||
goto loser;
|
||||
}
|
||||
if (PR_Access(dbsp->blobdir, PR_ACCESS_EXISTS) != PR_SUCCESS) {
|
||||
status = PR_MkDir(dbsp->blobdir,dbs_DirMode(mode));
|
||||
if (status != PR_SUCCESS) {
|
||||
goto loser;
|
||||
}
|
||||
}
|
||||
filed = PR_OpenFile(file,PR_CREATE_FILE|PR_TRUNCATE|PR_WRONLY, mode);
|
||||
if (filed == NULL) {
|
||||
error = PR_GetError();
|
||||
goto loser;
|
||||
}
|
||||
len = PR_Write(filed,data->data,data->size);
|
||||
error = PR_GetError();
|
||||
PR_Close(filed);
|
||||
if (len < (int)data->size) {
|
||||
goto loser;
|
||||
}
|
||||
PR_smprintf_free(file);
|
||||
return 0;
|
||||
|
||||
loser:
|
||||
if (file) {
|
||||
PR_Delete(file);
|
||||
PR_smprintf_free(file);
|
||||
}
|
||||
/* don't let close or delete reset the error */
|
||||
PR_SetError(error,0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* we need to keep a address map in memory between calls to DBM.
|
||||
* remember what we have mapped can close it when we get another dbm
|
||||
* call.
|
||||
*
|
||||
* NOTE: Not all platforms support mapped files. This code is designed to
|
||||
* detect this at runtime. If map files aren't supported the OS will indicate
|
||||
* this by failing the PR_Memmap call. In this case we emulate mapped files
|
||||
* by just reading in the file into regular memory. We signal this state by
|
||||
* making dbs_mapfile NULL and dbs_addr non-NULL.
|
||||
*/
|
||||
|
||||
static void
|
||||
dbs_freemap(DBS *dbsp)
|
||||
{
|
||||
if (dbsp->dbs_mapfile) {
|
||||
PR_MemUnmap(dbsp->dbs_addr,dbsp->dbs_len);
|
||||
PR_CloseFileMap(dbsp->dbs_mapfile);
|
||||
dbsp->dbs_mapfile = NULL;
|
||||
dbsp->dbs_addr = NULL;
|
||||
dbsp->dbs_len = 0;
|
||||
} else if (dbsp->dbs_addr) {
|
||||
PORT_Free(dbsp->dbs_addr);
|
||||
dbsp->dbs_addr = NULL;
|
||||
dbsp->dbs_len = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
dbs_setmap(DBS *dbsp, PRFileMap *mapfile, unsigned char *addr, PRUint32 len)
|
||||
{
|
||||
dbsp->dbs_mapfile = mapfile;
|
||||
dbsp->dbs_addr = addr;
|
||||
dbsp->dbs_len = len;
|
||||
}
|
||||
|
||||
/*
|
||||
* platforms that cannot map the file need to read it into a temp buffer.
|
||||
*/
|
||||
static unsigned char *
|
||||
dbs_EmulateMap(PRFileDesc *filed, int len)
|
||||
{
|
||||
unsigned char *addr;
|
||||
PRInt32 dataRead;
|
||||
|
||||
addr = PORT_Alloc(len);
|
||||
if (addr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dataRead = PR_Read(filed,addr,len);
|
||||
if (dataRead != len) {
|
||||
PORT_Free(addr);
|
||||
if (dataRead > 0) {
|
||||
/* PR_Read didn't set an error, we need to */
|
||||
PR_SetError(SEC_ERROR_BAD_DATABASE,0);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* pull a database record off the disk
|
||||
* data points to the blob record on input and the real record (if we could
|
||||
* read it) on output. if there is an error data is not modified.
|
||||
*/
|
||||
static int
|
||||
dbs_readBlob(DBS *dbsp, DBT *data)
|
||||
{
|
||||
char *file = NULL;
|
||||
PRFileDesc *filed = NULL;
|
||||
PRFileMap *mapfile = NULL;
|
||||
unsigned char *addr = NULL;
|
||||
int error;
|
||||
int len = -1;
|
||||
|
||||
file = dbs_getBlobFilePath(dbsp->blobdir, data);
|
||||
if (!file) {
|
||||
goto loser;
|
||||
}
|
||||
filed = PR_OpenFile(file,PR_RDONLY,0);
|
||||
PR_smprintf_free(file); file = NULL;
|
||||
if (filed == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
len = dbs_getBlobSize(data);
|
||||
mapfile = PR_CreateFileMap(filed, len, PR_PROT_READONLY);
|
||||
if (mapfile == NULL) {
|
||||
/* USE PR_GetError instead of PORT_GetError here
|
||||
* because we are getting the error from PR_xxx
|
||||
* function */
|
||||
if (PR_GetError() != PR_NOT_IMPLEMENTED_ERROR) {
|
||||
goto loser;
|
||||
}
|
||||
addr = dbs_EmulateMap(filed, len);
|
||||
} else {
|
||||
addr = PR_MemMap(mapfile, 0, len);
|
||||
}
|
||||
if (addr == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
PR_Close(filed);
|
||||
dbs_setmap(dbsp,mapfile,addr,len);
|
||||
|
||||
data->data = addr;
|
||||
data->size = len;
|
||||
return 0;
|
||||
|
||||
loser:
|
||||
/* preserve the error code */
|
||||
error = PR_GetError();
|
||||
if (mapfile) {
|
||||
PR_CloseFileMap(mapfile);
|
||||
}
|
||||
if (filed) {
|
||||
PR_Close(filed);
|
||||
}
|
||||
PR_SetError(error,0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* actual DBM shims
|
||||
*/
|
||||
static int
|
||||
dbs_get(const DB *dbs, const DBT *key, DBT *data, unsigned int flags)
|
||||
{
|
||||
int ret;
|
||||
DBS *dbsp = (DBS *)dbs;
|
||||
DB *db = (DB *)dbs->internal;
|
||||
|
||||
|
||||
dbs_freemap(dbsp);
|
||||
|
||||
ret = (* db->get)(db, key, data, flags);
|
||||
if ((ret == 0) && dbs_IsBlob(data)) {
|
||||
ret = dbs_readBlob(dbsp,data);
|
||||
}
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static int
|
||||
dbs_put(const DB *dbs, DBT *key, const DBT *data, unsigned int flags)
|
||||
{
|
||||
DBT blob;
|
||||
int ret = 0;
|
||||
DBS *dbsp = (DBS *)dbs;
|
||||
DB *db = (DB *)dbs->internal;
|
||||
|
||||
dbs_freemap(dbsp);
|
||||
|
||||
/* If the db is readonly, just pass the data down to rdb and let it fail */
|
||||
if (!dbsp->readOnly) {
|
||||
DBT oldData;
|
||||
int ret1;
|
||||
|
||||
/* make sure the current record is deleted if it's a blob */
|
||||
ret1 = (*db->get)(db,key,&oldData,0);
|
||||
if ((ret1 == 0) && flags == R_NOOVERWRITE) {
|
||||
/* let DBM return the error to maintain consistancy */
|
||||
return (* db->put)(db, key, data, flags);
|
||||
}
|
||||
if ((ret1 == 0) && dbs_IsBlob(&oldData)) {
|
||||
dbs_removeBlob(dbsp, &oldData);
|
||||
}
|
||||
|
||||
if (data->size > DBS_MAX_ENTRY_SIZE) {
|
||||
dbs_mkBlob(dbsp,key,data,&blob);
|
||||
ret = dbs_writeBlob(dbsp, dbsp->mode, &blob, data);
|
||||
data = &blob;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = (* db->put)(db, key, data, flags);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static int
|
||||
dbs_sync(const DB *dbs, unsigned int flags)
|
||||
{
|
||||
DB *db = (DB *)dbs->internal;
|
||||
DBS *dbsp = (DBS *)dbs;
|
||||
|
||||
dbs_freemap(dbsp);
|
||||
|
||||
return (* db->sync)(db, flags);
|
||||
}
|
||||
|
||||
static int
|
||||
dbs_del(const DB *dbs, const DBT *key, unsigned int flags)
|
||||
{
|
||||
int ret;
|
||||
DBS *dbsp = (DBS *)dbs;
|
||||
DB *db = (DB *)dbs->internal;
|
||||
|
||||
dbs_freemap(dbsp);
|
||||
|
||||
if (!dbsp->readOnly) {
|
||||
DBT oldData;
|
||||
ret = (*db->get)(db,key,&oldData,0);
|
||||
if ((ret == 0) && dbs_IsBlob(&oldData)) {
|
||||
dbs_removeBlob(dbsp,&oldData);
|
||||
}
|
||||
}
|
||||
|
||||
return (* db->del)(db, key, flags);
|
||||
}
|
||||
|
||||
static int
|
||||
dbs_seq(const DB *dbs, DBT *key, DBT *data, unsigned int flags)
|
||||
{
|
||||
int ret;
|
||||
DBS *dbsp = (DBS *)dbs;
|
||||
DB *db = (DB *)dbs->internal;
|
||||
|
||||
dbs_freemap(dbsp);
|
||||
|
||||
ret = (* db->seq)(db, key, data, flags);
|
||||
if ((ret == 0) && dbs_IsBlob(data)) {
|
||||
/* don't return a blob read as an error so traversals keep going */
|
||||
(void) dbs_readBlob(dbsp,data);
|
||||
}
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static int
|
||||
dbs_close(DB *dbs)
|
||||
{
|
||||
DBS *dbsp = (DBS *)dbs;
|
||||
DB *db = (DB *)dbs->internal;
|
||||
int ret;
|
||||
|
||||
dbs_freemap(dbsp);
|
||||
ret = (* db->close)(db);
|
||||
PORT_Free(dbsp->blobdir);
|
||||
PORT_Free(dbsp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
dbs_fd(const DB *dbs)
|
||||
{
|
||||
DB *db = (DB *)dbs->internal;
|
||||
|
||||
return (* db->fd)(db);
|
||||
}
|
||||
|
||||
/*
|
||||
* the naming convention we use is
|
||||
* change the .xxx into .dir. (for nss it's always .db);
|
||||
* if no .extension exists or is equal to .dir, add a .dir
|
||||
* the returned data must be freed.
|
||||
*/
|
||||
#define DIRSUFFIX ".dir"
|
||||
static char *
|
||||
dbs_mkBlobDirName(const char *dbname)
|
||||
{
|
||||
int dbname_len = PORT_Strlen(dbname);
|
||||
int dbname_end = dbname_len;
|
||||
const char *cp;
|
||||
char *blobDir = NULL;
|
||||
|
||||
/* scan back from the end looking for either a directory separator, a '.',
|
||||
* or the end of the string. NOTE: Windows should check for both separators
|
||||
* here. For now this is safe because we know NSS always uses a '.'
|
||||
*/
|
||||
for (cp = &dbname[dbname_len];
|
||||
(cp > dbname) && (*cp != '.') && (*cp != *PATH_SEPARATOR) ;
|
||||
cp--)
|
||||
/* Empty */ ;
|
||||
if (*cp == '.') {
|
||||
dbname_end = cp - dbname;
|
||||
if (PORT_Strcmp(cp,DIRSUFFIX) == 0) {
|
||||
dbname_end = dbname_len;
|
||||
}
|
||||
}
|
||||
blobDir = PORT_ZAlloc(dbname_end+sizeof(DIRSUFFIX));
|
||||
if (blobDir == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
PORT_Memcpy(blobDir,dbname,dbname_end);
|
||||
PORT_Memcpy(&blobDir[dbname_end],DIRSUFFIX,sizeof(DIRSUFFIX));
|
||||
return blobDir;
|
||||
}
|
||||
|
||||
#define DBM_DEFAULT 0
|
||||
static const HASHINFO dbs_hashInfo = {
|
||||
DBS_BLOCK_SIZE, /* bucket size, must be greater than = to
|
||||
* or maximum entry size (+ header)
|
||||
* we allow before blobing */
|
||||
DBM_DEFAULT, /* Fill Factor */
|
||||
DBM_DEFAULT, /* number of elements */
|
||||
DBS_CACHE_SIZE, /* cache size */
|
||||
DBM_DEFAULT, /* hash function */
|
||||
DBM_DEFAULT, /* byte order */
|
||||
};
|
||||
|
||||
/*
|
||||
* the open function. NOTE: this is the only exposed function in this file.
|
||||
* everything else is called through the function table pointer.
|
||||
*/
|
||||
DB *
|
||||
dbsopen(const char *dbname, int flags, int mode, DBTYPE type,
|
||||
const void *userData)
|
||||
{
|
||||
DB *db = NULL,*dbs = NULL;
|
||||
DBS *dbsp = NULL;
|
||||
|
||||
/* NOTE: we are overriding userData with dbs_hashInfo. since all known
|
||||
* callers pass 0, this is ok, otherwise we should merge the two */
|
||||
|
||||
dbsp = (DBS *)PORT_ZAlloc(sizeof(DBS));
|
||||
if (!dbsp) {
|
||||
return NULL;
|
||||
}
|
||||
dbs = &dbsp->db;
|
||||
|
||||
dbsp->blobdir=dbs_mkBlobDirName(dbname);
|
||||
if (dbsp->blobdir == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
dbsp->mode = mode;
|
||||
dbsp->readOnly = (PRBool)(flags == NO_RDONLY);
|
||||
dbsp->dbs_mapfile = NULL;
|
||||
dbsp->dbs_addr = NULL;
|
||||
dbsp->dbs_len = 0;
|
||||
|
||||
/* the real dbm call */
|
||||
db = dbopen(dbname, flags, mode, type, &dbs_hashInfo);
|
||||
if (db == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
dbs->internal = (void *) db;
|
||||
dbs->type = type;
|
||||
dbs->close = dbs_close;
|
||||
dbs->get = dbs_get;
|
||||
dbs->del = dbs_del;
|
||||
dbs->put = dbs_put;
|
||||
dbs->seq = dbs_seq;
|
||||
dbs->sync = dbs_sync;
|
||||
dbs->fd = dbs_fd;
|
||||
|
||||
return dbs;
|
||||
loser:
|
||||
if (db) {
|
||||
(*db->close)(db);
|
||||
}
|
||||
if (dbsp) {
|
||||
if (dbsp->blobdir) {
|
||||
PORT_Free(dbsp->blobdir);
|
||||
}
|
||||
PORT_Free(dbsp);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* private.h - Private data structures for the software token library
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/* $Id: keydbi.h,v 1.1.2.1 2007-04-03 22:50:02 rrelyea%redhat.com Exp $ */
|
||||
|
||||
#ifndef _KEYDBI_H_
|
||||
#define _KEYDBI_H_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "seccomon.h"
|
||||
#include "mcom_db.h"
|
||||
|
||||
/*
|
||||
* Handle structure for open key databases
|
||||
*/
|
||||
struct NSSLOWKEYDBHandleStr {
|
||||
DB *db;
|
||||
DB *updatedb; /* used when updating an old version */
|
||||
SECItem *global_salt; /* password hashing salt for this db */
|
||||
int version; /* version of the database */
|
||||
char *appname; /* multiaccess app name */
|
||||
char *dbname; /* name of the openned DB */
|
||||
PRBool readOnly; /* is the DB read only */
|
||||
PRLock *lock;
|
||||
PRInt32 ref; /* reference count */
|
||||
};
|
||||
|
||||
/*
|
||||
** Typedef for callback for traversing key database.
|
||||
** "key" is the key used to index the data in the database (nickname)
|
||||
** "data" is the key data
|
||||
** "pdata" is the user's data
|
||||
*/
|
||||
typedef SECStatus (* NSSLOWKEYTraverseKeysFunc)(DBT *key, DBT *data, void *pdata);
|
||||
|
||||
|
||||
SEC_BEGIN_PROTOS
|
||||
|
||||
/*
|
||||
** Traverse the entire key database, and pass the nicknames and keys to a
|
||||
** user supplied function.
|
||||
** "f" is the user function to call for each key
|
||||
** "udata" is the user's data, which is passed through to "f"
|
||||
*/
|
||||
extern SECStatus nsslowkey_TraverseKeys(NSSLOWKEYDBHandle *handle,
|
||||
NSSLOWKEYTraverseKeysFunc f,
|
||||
void *udata);
|
||||
|
||||
SEC_END_PROTOS
|
||||
|
||||
#endif /* _KEYDBI_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,955 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "secitem.h"
|
||||
#include "pkcs11.h"
|
||||
#include "lgdb.h"
|
||||
#include "pcert.h"
|
||||
#include "lowkeyi.h"
|
||||
#include "blapi.h"
|
||||
#include "secder.h"
|
||||
|
||||
#include "keydbi.h"
|
||||
|
||||
/*
|
||||
* ******************** Object Creation Utilities ***************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* check the consistancy and initialize a Certificate Object
|
||||
*/
|
||||
static CK_RV
|
||||
lg_createCertObject(SDB *sdb, CK_OBJECT_HANDLE *handle,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
SECItem derCert;
|
||||
NSSLOWCERTCertificate *cert;
|
||||
NSSLOWCERTCertTrust *trust = NULL;
|
||||
NSSLOWCERTCertTrust userTrust =
|
||||
{ CERTDB_USER, CERTDB_USER, CERTDB_USER };
|
||||
NSSLOWCERTCertTrust defTrust =
|
||||
{ CERTDB_TRUSTED_UNKNOWN,
|
||||
CERTDB_TRUSTED_UNKNOWN, CERTDB_TRUSTED_UNKNOWN };
|
||||
char *label = NULL;
|
||||
char *email = NULL;
|
||||
SECStatus rv;
|
||||
PRBool inDB = PR_TRUE;
|
||||
NSSLOWCERTCertDBHandle *certHandle = lg_getCertDB(sdb);
|
||||
NSSLOWKEYDBHandle *keyHandle = NULL;
|
||||
CK_CERTIFICATE_TYPE type;
|
||||
const CK_ATTRIBUTE *attribute;
|
||||
|
||||
/* we can't store any certs private */
|
||||
if (lg_isTrue(CKA_PRIVATE, templ, count)) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
/* We only support X.509 Certs for now */
|
||||
attribute = lg_FindAttribute(CKA_CERTIFICATE_TYPE, templ, count);
|
||||
if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
|
||||
type = *(CK_CERTIFICATE_TYPE *)attribute->pValue;
|
||||
|
||||
if (type != CKC_X_509) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
/* X.509 Certificate */
|
||||
|
||||
|
||||
if (certHandle == NULL) {
|
||||
return CKR_TOKEN_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
/* get the der cert */
|
||||
attribute = lg_FindAttribute(CKA_VALUE, templ, count);
|
||||
if (!attribute) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
derCert.type = 0;
|
||||
derCert.data = (unsigned char *)attribute->pValue;
|
||||
derCert.len = attribute->ulValueLen ;
|
||||
|
||||
label = lg_getString(CKA_LABEL, templ, count);
|
||||
|
||||
cert = nsslowcert_FindCertByDERCert(certHandle, &derCert);
|
||||
if (cert == NULL) {
|
||||
cert = nsslowcert_DecodeDERCertificate(&derCert, label);
|
||||
inDB = PR_FALSE;
|
||||
}
|
||||
if (cert == NULL) {
|
||||
if (label) PORT_Free(label);
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
keyHandle = lg_getKeyDB(sdb);
|
||||
if (keyHandle) {
|
||||
if (nsslowkey_KeyForCertExists(keyHandle,cert)) {
|
||||
trust = &userTrust;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inDB) {
|
||||
if (!trust) trust = &defTrust;
|
||||
rv = nsslowcert_AddPermCert(certHandle, cert, label, trust);
|
||||
} else {
|
||||
rv = trust ? nsslowcert_ChangeCertTrust(certHandle,cert,trust) :
|
||||
SECSuccess;
|
||||
}
|
||||
|
||||
if (label) PORT_Free(label);
|
||||
|
||||
if (rv != SECSuccess) {
|
||||
nsslowcert_DestroyCertificate(cert);
|
||||
return CKR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a NULL S/MIME profile if necessary.
|
||||
*/
|
||||
email = lg_getString(CKA_NETSCAPE_EMAIL, templ, count);
|
||||
if (email) {
|
||||
certDBEntrySMime *entry;
|
||||
|
||||
entry = nsslowcert_ReadDBSMimeEntry(certHandle,email);
|
||||
if (!entry) {
|
||||
nsslowcert_SaveSMimeProfile(certHandle, email,
|
||||
&cert->derSubject, NULL, NULL);
|
||||
} else {
|
||||
nsslowcert_DestroyDBEntry((certDBEntry *)entry);
|
||||
}
|
||||
PORT_Free(email);
|
||||
}
|
||||
*handle=lg_mkHandle(sdb,&cert->certKey,LG_TOKEN_TYPE_CERT);
|
||||
nsslowcert_DestroyCertificate(cert);
|
||||
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
lg_MapTrust(CK_TRUST trust, PRBool clientAuth)
|
||||
{
|
||||
unsigned int trustCA = clientAuth ? CERTDB_TRUSTED_CLIENT_CA :
|
||||
CERTDB_TRUSTED_CA;
|
||||
switch (trust) {
|
||||
case CKT_NETSCAPE_TRUSTED:
|
||||
return CERTDB_VALID_PEER|CERTDB_TRUSTED;
|
||||
case CKT_NETSCAPE_TRUSTED_DELEGATOR:
|
||||
return CERTDB_VALID_CA|trustCA;
|
||||
case CKT_NETSCAPE_UNTRUSTED:
|
||||
return CERTDB_NOT_TRUSTED;
|
||||
case CKT_NETSCAPE_MUST_VERIFY:
|
||||
return 0;
|
||||
case CKT_NETSCAPE_VALID: /* implies must verify */
|
||||
return CERTDB_VALID_PEER;
|
||||
case CKT_NETSCAPE_VALID_DELEGATOR: /* implies must verify */
|
||||
return CERTDB_VALID_CA;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return CERTDB_TRUSTED_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* check the consistancy and initialize a Trust Object
|
||||
*/
|
||||
static CK_RV
|
||||
lg_createTrustObject(SDB *sdb, CK_OBJECT_HANDLE *handle,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
const CK_ATTRIBUTE *issuer = NULL;
|
||||
const CK_ATTRIBUTE *serial = NULL;
|
||||
NSSLOWCERTCertificate *cert = NULL;
|
||||
const CK_ATTRIBUTE *trust;
|
||||
CK_TRUST sslTrust = CKT_NETSCAPE_TRUST_UNKNOWN;
|
||||
CK_TRUST clientTrust = CKT_NETSCAPE_TRUST_UNKNOWN;
|
||||
CK_TRUST emailTrust = CKT_NETSCAPE_TRUST_UNKNOWN;
|
||||
CK_TRUST signTrust = CKT_NETSCAPE_TRUST_UNKNOWN;
|
||||
CK_BBOOL stepUp;
|
||||
NSSLOWCERTCertTrust dbTrust = { 0 };
|
||||
SECStatus rv;
|
||||
NSSLOWCERTCertDBHandle *certHandle = lg_getCertDB(sdb);
|
||||
NSSLOWCERTIssuerAndSN issuerSN;
|
||||
|
||||
/* we can't store any certs private */
|
||||
if (lg_isTrue(CKA_PRIVATE, templ, count)) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
if (certHandle == NULL) {
|
||||
return CKR_TOKEN_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
issuer = lg_FindAttribute(CKA_ISSUER, templ, count);
|
||||
serial = lg_FindAttribute(CKA_SERIAL_NUMBER, templ, count);
|
||||
|
||||
if (issuer && serial) {
|
||||
issuerSN.derIssuer.data = (unsigned char *)issuer->pValue;
|
||||
issuerSN.derIssuer.len = issuer->ulValueLen ;
|
||||
|
||||
issuerSN.serialNumber.data = (unsigned char *)serial->pValue;
|
||||
issuerSN.serialNumber.len = serial->ulValueLen ;
|
||||
|
||||
cert = nsslowcert_FindCertByIssuerAndSN(certHandle,&issuerSN);
|
||||
}
|
||||
|
||||
if (cert == NULL) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
lg_GetULongAttribute(CKA_TRUST_SERVER_AUTH, templ, count, &sslTrust);
|
||||
lg_GetULongAttribute(CKA_TRUST_CLIENT_AUTH, templ, count, &clientTrust);
|
||||
lg_GetULongAttribute(CKA_TRUST_EMAIL_PROTECTION, templ, count, &emailTrust);
|
||||
lg_GetULongAttribute(CKA_TRUST_CODE_SIGNING, templ, count, &signTrust);
|
||||
stepUp = CK_FALSE;
|
||||
trust = lg_FindAttribute(CKA_TRUST_STEP_UP_APPROVED, templ, count);
|
||||
if (trust) {
|
||||
if (trust->ulValueLen == sizeof(CK_BBOOL)) {
|
||||
stepUp = *(CK_BBOOL*)trust->pValue;
|
||||
}
|
||||
}
|
||||
|
||||
/* preserve certain old fields */
|
||||
if (cert->trust) {
|
||||
dbTrust.sslFlags = cert->trust->sslFlags & CERTDB_PRESERVE_TRUST_BITS;
|
||||
dbTrust.emailFlags=
|
||||
cert->trust->emailFlags & CERTDB_PRESERVE_TRUST_BITS;
|
||||
dbTrust.objectSigningFlags =
|
||||
cert->trust->objectSigningFlags & CERTDB_PRESERVE_TRUST_BITS;
|
||||
}
|
||||
|
||||
dbTrust.sslFlags |= lg_MapTrust(sslTrust,PR_FALSE);
|
||||
dbTrust.sslFlags |= lg_MapTrust(clientTrust,PR_TRUE);
|
||||
dbTrust.emailFlags |= lg_MapTrust(emailTrust,PR_FALSE);
|
||||
dbTrust.objectSigningFlags |= lg_MapTrust(signTrust,PR_FALSE);
|
||||
if (stepUp) {
|
||||
dbTrust.sslFlags |= CERTDB_GOVT_APPROVED_CA;
|
||||
}
|
||||
|
||||
rv = nsslowcert_ChangeCertTrust(certHandle,cert,&dbTrust);
|
||||
*handle=lg_mkHandle(sdb,&cert->certKey,LG_TOKEN_TYPE_TRUST);
|
||||
nsslowcert_DestroyCertificate(cert);
|
||||
if (rv != SECSuccess) {
|
||||
return CKR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* check the consistancy and initialize a Trust Object
|
||||
*/
|
||||
static CK_RV
|
||||
lg_createSMimeObject(SDB *sdb, CK_OBJECT_HANDLE *handle,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
SECItem derSubj,rawProfile,rawTime,emailKey;
|
||||
SECItem *pRawProfile = NULL;
|
||||
SECItem *pRawTime = NULL;
|
||||
char *email = NULL;
|
||||
const CK_ATTRIBUTE *subject = NULL,
|
||||
*profile = NULL,
|
||||
*time = NULL;
|
||||
SECStatus rv;
|
||||
NSSLOWCERTCertDBHandle *certHandle;
|
||||
CK_RV ck_rv = CKR_OK;
|
||||
|
||||
/* we can't store any certs private */
|
||||
if (lg_isTrue(CKA_PRIVATE,templ,count)) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
certHandle = lg_getCertDB(sdb);
|
||||
if (certHandle == NULL) {
|
||||
return CKR_TOKEN_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
/* lookup SUBJECT */
|
||||
subject = lg_FindAttribute(CKA_SUBJECT,templ,count);
|
||||
PORT_Assert(subject);
|
||||
if (!subject) {
|
||||
ck_rv = CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
derSubj.data = (unsigned char *)subject->pValue;
|
||||
derSubj.len = subject->ulValueLen ;
|
||||
derSubj.type = 0;
|
||||
|
||||
/* lookup VALUE */
|
||||
profile = lg_FindAttribute(CKA_VALUE,templ,count);
|
||||
if (profile) {
|
||||
rawProfile.data = (unsigned char *)profile->pValue;
|
||||
rawProfile.len = profile->ulValueLen ;
|
||||
rawProfile.type = siBuffer;
|
||||
pRawProfile = &rawProfile;
|
||||
}
|
||||
|
||||
/* lookup Time */
|
||||
time = lg_FindAttribute(CKA_NETSCAPE_SMIME_TIMESTAMP,templ,count);
|
||||
if (time) {
|
||||
rawTime.data = (unsigned char *)time->pValue;
|
||||
rawTime.len = time->ulValueLen ;
|
||||
rawTime.type = siBuffer;
|
||||
pRawTime = &rawTime;
|
||||
}
|
||||
|
||||
|
||||
email = lg_getString(CKA_NETSCAPE_EMAIL,templ,count);
|
||||
if (!email) {
|
||||
ck_rv = CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Store S/MIME Profile by SUBJECT */
|
||||
rv = nsslowcert_SaveSMimeProfile(certHandle, email, &derSubj,
|
||||
pRawProfile,pRawTime);
|
||||
if (rv != SECSuccess) {
|
||||
ck_rv = CKR_DEVICE_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
emailKey.data = (unsigned char *)email;
|
||||
emailKey.len = PORT_Strlen(email)+1;
|
||||
|
||||
*handle = lg_mkHandle(sdb, &emailKey, LG_TOKEN_TYPE_SMIME);
|
||||
|
||||
loser:
|
||||
if (email) PORT_Free(email);
|
||||
|
||||
return ck_rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* check the consistancy and initialize a Trust Object
|
||||
*/
|
||||
static CK_RV
|
||||
lg_createCrlObject(SDB *sdb, CK_OBJECT_HANDLE *handle,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
PRBool isKRL = PR_FALSE;
|
||||
SECItem derSubj,derCrl;
|
||||
char *url = NULL;
|
||||
const CK_ATTRIBUTE *subject,*crl;
|
||||
SECStatus rv;
|
||||
NSSLOWCERTCertDBHandle *certHandle;
|
||||
|
||||
certHandle = lg_getCertDB(sdb);
|
||||
|
||||
/* we can't store any private crls */
|
||||
if (lg_isTrue(CKA_PRIVATE,templ,count)) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
if (certHandle == NULL) {
|
||||
return CKR_TOKEN_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
/* lookup SUBJECT */
|
||||
subject = lg_FindAttribute(CKA_SUBJECT,templ,count);
|
||||
if (!subject) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
derSubj.data = (unsigned char *)subject->pValue;
|
||||
derSubj.len = subject->ulValueLen ;
|
||||
|
||||
/* lookup VALUE */
|
||||
crl = lg_FindAttribute(CKA_VALUE,templ,count);
|
||||
PORT_Assert(crl);
|
||||
if (!crl) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
derCrl.data = (unsigned char *)crl->pValue;
|
||||
derCrl.len = crl->ulValueLen ;
|
||||
|
||||
url = lg_getString(CKA_NETSCAPE_URL,templ,count);
|
||||
isKRL = lg_isTrue(CKA_NETSCAPE_KRL,templ,count);
|
||||
|
||||
/* Store CRL by SUBJECT */
|
||||
rv = nsslowcert_AddCrl(certHandle, &derCrl, &derSubj, url, isKRL);
|
||||
|
||||
if (url) {
|
||||
PORT_Free(url);
|
||||
}
|
||||
if (rv != SECSuccess) {
|
||||
return CKR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
/* if we overwrote the existing CRL, poison the handle entry so we get
|
||||
* a new object handle */
|
||||
(void) lg_poisonHandle(sdb, &derSubj,
|
||||
isKRL ? LG_TOKEN_KRL_HANDLE : LG_TOKEN_TYPE_CRL);
|
||||
*handle = lg_mkHandle(sdb, &derSubj,
|
||||
isKRL ? LG_TOKEN_KRL_HANDLE : LG_TOKEN_TYPE_CRL);
|
||||
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* check the consistancy and initialize a Public Key Object
|
||||
*/
|
||||
static CK_RV
|
||||
lg_createPublicKeyObject(SDB *sdb, CK_KEY_TYPE key_type,
|
||||
CK_OBJECT_HANDLE *handle, const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
CK_ATTRIBUTE_TYPE pubKeyAttr = CKA_VALUE;
|
||||
CK_RV crv;
|
||||
NSSLOWKEYPrivateKey *priv;
|
||||
SECItem pubKey;
|
||||
NSSLOWKEYDBHandle *keyHandle = NULL;
|
||||
|
||||
switch (key_type) {
|
||||
case CKK_RSA:
|
||||
pubKeyAttr = CKA_MODULUS;
|
||||
break;
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
case CKK_EC:
|
||||
pubKeyAttr = CKA_EC_POINT;
|
||||
break;
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
case CKK_DSA:
|
||||
case CKK_DH:
|
||||
break;
|
||||
default:
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
|
||||
crv = lg_Attribute2SSecItem(NULL,pubKeyAttr,templ,count,&pubKey);
|
||||
if (crv != CKR_OK) return crv;
|
||||
|
||||
PORT_Assert(pubKey.data);
|
||||
keyHandle = lg_getKeyDB(sdb);
|
||||
if (keyHandle == NULL) {
|
||||
PORT_Free(pubKey.data);
|
||||
return CKR_TOKEN_WRITE_PROTECTED;
|
||||
}
|
||||
if (keyHandle->version != 3) {
|
||||
unsigned char buf[SHA1_LENGTH];
|
||||
SHA1_HashBuf(buf,pubKey.data,pubKey.len);
|
||||
PORT_Memcpy(pubKey.data,buf,sizeof(buf));
|
||||
pubKey.len = sizeof(buf);
|
||||
}
|
||||
/* make sure the associated private key already exists */
|
||||
/* only works if we are logged in */
|
||||
priv = nsslowkey_FindKeyByPublicKey(keyHandle, &pubKey, sdb /*password*/);
|
||||
if (priv == NULL) {
|
||||
PORT_Free(pubKey.data);
|
||||
return crv;
|
||||
}
|
||||
nsslowkey_DestroyPrivateKey(priv);
|
||||
|
||||
*handle = lg_mkHandle(sdb, &pubKey, LG_TOKEN_TYPE_PUB);
|
||||
PORT_Free(pubKey.data);
|
||||
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
/* make a private key from a verified object */
|
||||
static NSSLOWKEYPrivateKey *
|
||||
lg_mkPrivKey(SDB *sdb, const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
CK_KEY_TYPE key_type, CK_RV *crvp)
|
||||
{
|
||||
NSSLOWKEYPrivateKey *privKey;
|
||||
PLArenaPool *arena;
|
||||
CK_RV crv = CKR_OK;
|
||||
SECStatus rv;
|
||||
|
||||
arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
|
||||
if (arena == NULL) {
|
||||
*crvp = CKR_HOST_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
privKey = (NSSLOWKEYPrivateKey *)
|
||||
PORT_ArenaZAlloc(arena,sizeof(NSSLOWKEYPrivateKey));
|
||||
if (privKey == NULL) {
|
||||
PORT_FreeArena(arena,PR_FALSE);
|
||||
*crvp = CKR_HOST_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* in future this would be a switch on key_type */
|
||||
privKey->arena = arena;
|
||||
switch (key_type) {
|
||||
case CKK_RSA:
|
||||
privKey->keyType = NSSLOWKEYRSAKey;
|
||||
crv=lg_Attribute2SSecItem(arena,CKA_MODULUS,templ,count,
|
||||
&privKey->u.rsa.modulus);
|
||||
if (crv != CKR_OK) break;
|
||||
crv=lg_Attribute2SSecItem(arena,CKA_PUBLIC_EXPONENT,templ,count,
|
||||
&privKey->u.rsa.publicExponent);
|
||||
if (crv != CKR_OK) break;
|
||||
crv=lg_PrivAttr2SSecItem(arena,CKA_PRIVATE_EXPONENT,templ,count,
|
||||
&privKey->u.rsa.privateExponent, sdb);
|
||||
if (crv != CKR_OK) break;
|
||||
crv=lg_PrivAttr2SSecItem(arena,CKA_PRIME_1,templ,count,
|
||||
&privKey->u.rsa.prime1, sdb);
|
||||
if (crv != CKR_OK) break;
|
||||
crv=lg_PrivAttr2SSecItem(arena,CKA_PRIME_2,templ,count,
|
||||
&privKey->u.rsa.prime2, sdb);
|
||||
if (crv != CKR_OK) break;
|
||||
crv=lg_PrivAttr2SSecItem(arena,CKA_EXPONENT_1,templ,count,
|
||||
&privKey->u.rsa.exponent1, sdb);
|
||||
if (crv != CKR_OK) break;
|
||||
crv=lg_PrivAttr2SSecItem(arena,CKA_EXPONENT_2,templ,count,
|
||||
&privKey->u.rsa.exponent2, sdb);
|
||||
if (crv != CKR_OK) break;
|
||||
crv=lg_PrivAttr2SSecItem(arena,CKA_COEFFICIENT,templ,count,
|
||||
&privKey->u.rsa.coefficient, sdb);
|
||||
if (crv != CKR_OK) break;
|
||||
rv = DER_SetUInteger(privKey->arena, &privKey->u.rsa.version,
|
||||
NSSLOWKEY_VERSION);
|
||||
if (rv != SECSuccess) crv = CKR_HOST_MEMORY;
|
||||
break;
|
||||
|
||||
case CKK_DSA:
|
||||
privKey->keyType = NSSLOWKEYDSAKey;
|
||||
crv = lg_Attribute2SSecItem(arena,CKA_PRIME,templ,count,
|
||||
&privKey->u.dsa.params.prime);
|
||||
if (crv != CKR_OK) break;
|
||||
crv = lg_Attribute2SSecItem(arena,CKA_SUBPRIME,templ,count,
|
||||
&privKey->u.dsa.params.subPrime);
|
||||
if (crv != CKR_OK) break;
|
||||
crv = lg_Attribute2SSecItem(arena,CKA_BASE,templ,count,
|
||||
&privKey->u.dsa.params.base);
|
||||
if (crv != CKR_OK) break;
|
||||
crv = lg_PrivAttr2SSecItem(arena,CKA_VALUE,templ,count,
|
||||
&privKey->u.dsa.privateValue, sdb);
|
||||
if (crv != CKR_OK) break;
|
||||
if (lg_hasAttribute(CKA_NETSCAPE_DB, templ,count)) {
|
||||
crv = lg_Attribute2SSecItem(arena, CKA_NETSCAPE_DB,templ,count,
|
||||
&privKey->u.dsa.publicValue);
|
||||
/* privKey was zero'd so public value is already set to NULL, 0
|
||||
* if we don't set it explicitly */
|
||||
}
|
||||
break;
|
||||
|
||||
case CKK_DH:
|
||||
privKey->keyType = NSSLOWKEYDHKey;
|
||||
crv = lg_Attribute2SSecItem(arena,CKA_PRIME,templ,count,
|
||||
&privKey->u.dh.prime);
|
||||
if (crv != CKR_OK) break;
|
||||
crv = lg_Attribute2SSecItem(arena,CKA_BASE,templ,count,
|
||||
&privKey->u.dh.base);
|
||||
if (crv != CKR_OK) break;
|
||||
crv = lg_PrivAttr2SSecItem(arena,CKA_VALUE,templ,count,
|
||||
&privKey->u.dh.privateValue, sdb);
|
||||
if (crv != CKR_OK) break;
|
||||
if (lg_hasAttribute(CKA_NETSCAPE_DB, templ, count)) {
|
||||
crv = lg_Attribute2SSecItem(arena, CKA_NETSCAPE_DB,templ,count,
|
||||
&privKey->u.dh.publicValue);
|
||||
/* privKey was zero'd so public value is already set to NULL, 0
|
||||
* if we don't set it explicitly */
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
case CKK_EC:
|
||||
privKey->keyType = NSSLOWKEYECKey;
|
||||
crv = lg_Attribute2SSecItem(arena, CKA_EC_PARAMS,templ,count,
|
||||
&privKey->u.ec.ecParams.DEREncoding);
|
||||
if (crv != CKR_OK) break;
|
||||
|
||||
/* Fill out the rest of the ecParams structure
|
||||
* based on the encoded params
|
||||
*/
|
||||
if (LGEC_FillParams(arena, &privKey->u.ec.ecParams.DEREncoding,
|
||||
&privKey->u.ec.ecParams) != SECSuccess) {
|
||||
crv = CKR_DOMAIN_PARAMS_INVALID;
|
||||
break;
|
||||
}
|
||||
crv = lg_PrivAttr2SSecItem(arena,CKA_VALUE,templ,count,
|
||||
&privKey->u.ec.privateValue, sdb);
|
||||
if (crv != CKR_OK) break;
|
||||
if (lg_hasAttribute(CKA_NETSCAPE_DB,templ,count)) {
|
||||
crv = lg_Attribute2SSecItem(arena, CKA_NETSCAPE_DB,templ,count,
|
||||
&privKey->u.ec.publicValue);
|
||||
if (crv != CKR_OK) break;
|
||||
/* privKey was zero'd so public value is already set to NULL, 0
|
||||
* if we don't set it explicitly */
|
||||
}
|
||||
rv = DER_SetUInteger(privKey->arena, &privKey->u.ec.version,
|
||||
NSSLOWKEY_EC_PRIVATE_KEY_VERSION);
|
||||
if (rv != SECSuccess) crv = CKR_HOST_MEMORY;
|
||||
break;
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
|
||||
default:
|
||||
crv = CKR_KEY_TYPE_INCONSISTENT;
|
||||
break;
|
||||
}
|
||||
*crvp = crv;
|
||||
if (crv != CKR_OK) {
|
||||
PORT_FreeArena(arena,PR_FALSE);
|
||||
return NULL;
|
||||
}
|
||||
return privKey;
|
||||
}
|
||||
|
||||
/*
|
||||
* check the consistancy and initialize a Private Key Object
|
||||
*/
|
||||
static CK_RV
|
||||
lg_createPrivateKeyObject(SDB *sdb, CK_KEY_TYPE key_type,
|
||||
CK_OBJECT_HANDLE *handle, const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
NSSLOWKEYPrivateKey *privKey;
|
||||
char *label;
|
||||
SECStatus rv = SECSuccess;
|
||||
CK_RV crv = CKR_DEVICE_ERROR;
|
||||
SECItem pubKey;
|
||||
NSSLOWKEYDBHandle *keyHandle = lg_getKeyDB(sdb);
|
||||
|
||||
if (keyHandle == NULL) {
|
||||
return CKR_TOKEN_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
privKey=lg_mkPrivKey(sdb, templ,count,key_type,&crv);
|
||||
if (privKey == NULL) return crv;
|
||||
label = lg_getString(CKA_LABEL,templ,count);
|
||||
|
||||
crv = lg_Attribute2SSecItem(NULL,CKA_NETSCAPE_DB,templ,count,&pubKey);
|
||||
if (crv != CKR_OK) {
|
||||
crv = CKR_TEMPLATE_INCOMPLETE;
|
||||
rv = SECFailure;
|
||||
goto fail;
|
||||
}
|
||||
#ifdef notdef
|
||||
if (keyHandle->version != 3) {
|
||||
unsigned char buf[SHA1_LENGTH];
|
||||
SHA1_HashBuf(buf,pubKey.data,pubKey.len);
|
||||
PORT_Memcpy(pubKey.data,buf,sizeof(buf));
|
||||
pubKey.len = sizeof(buf);
|
||||
}
|
||||
#endif
|
||||
/* get the key type */
|
||||
if (key_type == CKK_RSA) {
|
||||
rv = RSA_PrivateKeyCheck(&privKey->u.rsa);
|
||||
if (rv == SECFailure) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
rv = nsslowkey_StoreKeyByPublicKey(keyHandle, privKey, &pubKey,
|
||||
label, sdb /*->password*/);
|
||||
|
||||
fail:
|
||||
if (label) PORT_Free(label);
|
||||
*handle = lg_mkHandle(sdb,&pubKey,LG_TOKEN_TYPE_PRIV);
|
||||
if (pubKey.data) PORT_Free(pubKey.data);
|
||||
nsslowkey_DestroyPrivateKey(privKey);
|
||||
if (rv != SECSuccess) return crv;
|
||||
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
|
||||
#define LG_KEY_MAX_RETRIES 10 /* don't hang if we are having problems with the rng */
|
||||
#define LG_KEY_ID_SIZE 18 /* don't use either SHA1 or MD5 sizes */
|
||||
/*
|
||||
* Secret keys must have a CKA_ID value to be stored in the database. This code
|
||||
* will generate one if there wasn't one already.
|
||||
*/
|
||||
static CK_RV
|
||||
lg_GenerateSecretCKA_ID(NSSLOWKEYDBHandle *handle, SECItem *id, char *label)
|
||||
{
|
||||
unsigned int retries;
|
||||
SECStatus rv = SECSuccess;
|
||||
CK_RV crv = CKR_OK;
|
||||
|
||||
id->data = NULL;
|
||||
if (label) {
|
||||
id->data = (unsigned char *)PORT_Strdup(label);
|
||||
if (id->data == NULL) {
|
||||
return CKR_HOST_MEMORY;
|
||||
}
|
||||
id->len = PORT_Strlen(label)+1;
|
||||
if (!nsslowkey_KeyForIDExists(handle,id)) {
|
||||
return CKR_OK;
|
||||
}
|
||||
PORT_Free(id->data);
|
||||
id->data = NULL;
|
||||
id->len = 0;
|
||||
}
|
||||
id->data = (unsigned char *)PORT_Alloc(LG_KEY_ID_SIZE);
|
||||
if (id->data == NULL) {
|
||||
return CKR_HOST_MEMORY;
|
||||
}
|
||||
id->len = LG_KEY_ID_SIZE;
|
||||
|
||||
retries = 0;
|
||||
do {
|
||||
rv = RNG_GenerateGlobalRandomBytes(id->data,id->len);
|
||||
} while (rv == SECSuccess && nsslowkey_KeyForIDExists(handle,id) &&
|
||||
(++retries <= LG_KEY_MAX_RETRIES));
|
||||
|
||||
if ((rv != SECSuccess) || (retries > LG_KEY_MAX_RETRIES)) {
|
||||
crv = CKR_DEVICE_ERROR; /* random number generator is bad */
|
||||
PORT_Free(id->data);
|
||||
id->data = NULL;
|
||||
id->len = 0;
|
||||
}
|
||||
return crv;
|
||||
}
|
||||
|
||||
|
||||
static NSSLOWKEYPrivateKey *lg_mkSecretKeyRep(const CK_ATTRIBUTE *templ,
|
||||
CK_ULONG count, CK_KEY_TYPE key_type,
|
||||
SECItem *pubkey, SDB *sdbpw)
|
||||
{
|
||||
NSSLOWKEYPrivateKey *privKey = 0;
|
||||
PLArenaPool *arena = 0;
|
||||
CK_KEY_TYPE keyType;
|
||||
PRUint32 keyTypeStorage;
|
||||
SECItem keyTypeItem;
|
||||
CK_RV crv;
|
||||
SECStatus rv;
|
||||
static unsigned char derZero[1] = { 0 };
|
||||
|
||||
arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
|
||||
if (arena == NULL) { crv = CKR_HOST_MEMORY; goto loser; }
|
||||
|
||||
privKey = (NSSLOWKEYPrivateKey *)
|
||||
PORT_ArenaZAlloc(arena,sizeof(NSSLOWKEYPrivateKey));
|
||||
if (privKey == NULL) { crv = CKR_HOST_MEMORY; goto loser; }
|
||||
|
||||
privKey->arena = arena;
|
||||
|
||||
/* Secret keys are represented in the database as "fake" RSA keys.
|
||||
* The RSA key is marked as a secret key representation by setting the
|
||||
* public exponent field to 0, which is an invalid RSA exponent.
|
||||
* The other fields are set as follows:
|
||||
* modulus - CKA_ID value for the secret key
|
||||
* private exponent - CKA_VALUE (the key itself)
|
||||
* coefficient - CKA_KEY_TYPE, which indicates what encryption algorithm
|
||||
* is used for the key.
|
||||
* all others - set to integer 0
|
||||
*/
|
||||
privKey->keyType = NSSLOWKEYRSAKey;
|
||||
|
||||
/* The modulus is set to the key id of the symmetric key */
|
||||
crv = lg_Attribute2SecItem(arena, CKA_ID, templ, count,
|
||||
&privKey->u.rsa.modulus);
|
||||
if (crv != CKR_OK) goto loser;
|
||||
|
||||
/* The public exponent is set to 0 length to indicate a special key */
|
||||
privKey->u.rsa.publicExponent.len = sizeof derZero;
|
||||
privKey->u.rsa.publicExponent.data = derZero;
|
||||
|
||||
/* The private exponent is the actual key value */
|
||||
crv = lg_PrivAttr2SecItem(arena, CKA_VALUE, templ, count,
|
||||
&privKey->u.rsa.privateExponent, sdbpw);
|
||||
if (crv != CKR_OK) goto loser;
|
||||
|
||||
/* All other fields empty - needs testing */
|
||||
privKey->u.rsa.prime1.len = sizeof derZero;
|
||||
privKey->u.rsa.prime1.data = derZero;
|
||||
|
||||
privKey->u.rsa.prime2.len = sizeof derZero;
|
||||
privKey->u.rsa.prime2.data = derZero;
|
||||
|
||||
privKey->u.rsa.exponent1.len = sizeof derZero;
|
||||
privKey->u.rsa.exponent1.data = derZero;
|
||||
|
||||
privKey->u.rsa.exponent2.len = sizeof derZero;
|
||||
privKey->u.rsa.exponent2.data = derZero;
|
||||
|
||||
/* Coeficient set to KEY_TYPE */
|
||||
crv = lg_GetULongAttribute(CKA_KEY_TYPE, templ, count, &keyType);
|
||||
if (crv != CKR_OK) goto loser;
|
||||
/* on 64 bit platforms, we still want to store 32 bits of keyType (This is
|
||||
* safe since the PKCS #11 defines for all types are 32 bits or less). */
|
||||
keyTypeStorage = (PRUint32) keyType;
|
||||
keyTypeStorage = PR_htonl(keyTypeStorage);
|
||||
keyTypeItem.data = (unsigned char *)&keyTypeStorage;
|
||||
keyTypeItem.len = sizeof (keyTypeStorage);
|
||||
rv = SECITEM_CopyItem(arena, &privKey->u.rsa.coefficient, &keyTypeItem);
|
||||
if (rv != SECSuccess) {
|
||||
crv = CKR_HOST_MEMORY;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Private key version field set normally for compatibility */
|
||||
rv = DER_SetUInteger(privKey->arena,
|
||||
&privKey->u.rsa.version, NSSLOWKEY_VERSION);
|
||||
if (rv != SECSuccess) { crv = CKR_HOST_MEMORY; goto loser; }
|
||||
|
||||
loser:
|
||||
if (crv != CKR_OK) {
|
||||
PORT_FreeArena(arena,PR_FALSE);
|
||||
privKey = 0;
|
||||
}
|
||||
|
||||
return privKey;
|
||||
}
|
||||
|
||||
/*
|
||||
* check the consistancy and initialize a Secret Key Object
|
||||
*/
|
||||
static CK_RV
|
||||
lg_createSecretKeyObject(SDB *sdb, CK_KEY_TYPE key_type,
|
||||
CK_OBJECT_HANDLE *handle, const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
CK_RV crv;
|
||||
NSSLOWKEYPrivateKey *privKey = NULL;
|
||||
NSSLOWKEYDBHandle *keyHandle = NULL;
|
||||
SECItem pubKey;
|
||||
char *label = NULL;
|
||||
SECStatus rv = SECSuccess;
|
||||
|
||||
pubKey.data = 0;
|
||||
|
||||
/* If the object is a TOKEN object, store in the database */
|
||||
keyHandle = lg_getKeyDB(sdb);
|
||||
|
||||
if (keyHandle == NULL) {
|
||||
return CKR_TOKEN_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
label = lg_getString(CKA_LABEL,templ,count);
|
||||
|
||||
crv = lg_Attribute2SecItem(NULL,CKA_ID,templ,count,&pubKey);
|
||||
/* Should this be ID? */
|
||||
if (crv != CKR_OK) goto loser;
|
||||
|
||||
/* if we don't have an ID, generate one */
|
||||
if (pubKey.len == 0) {
|
||||
if (pubKey.data) {
|
||||
PORT_Free(pubKey.data);
|
||||
pubKey.data = NULL;
|
||||
}
|
||||
crv = lg_GenerateSecretCKA_ID(keyHandle, &pubKey, label);
|
||||
if (crv != CKR_OK) goto loser;
|
||||
}
|
||||
|
||||
privKey = lg_mkSecretKeyRep(templ, count, key_type, &pubKey, sdb);
|
||||
if (privKey == NULL) {
|
||||
crv = CKR_HOST_MEMORY;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
rv = nsslowkey_StoreKeyByPublicKey(keyHandle,
|
||||
privKey, &pubKey, label, sdb /*->password*/);
|
||||
if (rv != SECSuccess) {
|
||||
crv = CKR_DEVICE_ERROR;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*handle = lg_mkHandle(sdb, &pubKey, LG_TOKEN_TYPE_KEY);
|
||||
|
||||
loser:
|
||||
if (label) PORT_Free(label);
|
||||
if (privKey) nsslowkey_DestroyPrivateKey(privKey);
|
||||
if (pubKey.data) PORT_Free(pubKey.data);
|
||||
|
||||
return crv;
|
||||
}
|
||||
|
||||
/*
|
||||
* check the consistancy and initialize a Key Object
|
||||
*/
|
||||
static CK_RV
|
||||
lg_createKeyObject(SDB *sdb, CK_OBJECT_CLASS objclass,
|
||||
CK_OBJECT_HANDLE *handle, const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
CK_RV crv;
|
||||
CK_KEY_TYPE key_type;
|
||||
|
||||
/* get the key type */
|
||||
crv = lg_GetULongAttribute(CKA_KEY_TYPE, templ, count, &key_type);
|
||||
if (crv != CKR_OK) {
|
||||
return crv;
|
||||
}
|
||||
|
||||
switch (objclass) {
|
||||
case CKO_PUBLIC_KEY:
|
||||
return lg_createPublicKeyObject(sdb,key_type,handle,templ,count);
|
||||
case CKO_PRIVATE_KEY:
|
||||
return lg_createPrivateKeyObject(sdb,key_type,handle,templ,count);
|
||||
case CKO_SECRET_KEY:
|
||||
return lg_createSecretKeyObject(sdb,key_type,handle,templ,count);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the template and create an object stored in the DB that reflects.
|
||||
* the object specified in the database.
|
||||
*/
|
||||
CK_RV
|
||||
lg_CreateObject(SDB *sdb, CK_OBJECT_HANDLE *handle,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
CK_RV crv;
|
||||
CK_OBJECT_CLASS objclass;
|
||||
|
||||
/* get the object class */
|
||||
crv = lg_GetULongAttribute(CKA_CLASS, templ, count, &objclass);
|
||||
if (crv != CKR_OK) {
|
||||
return crv;
|
||||
}
|
||||
|
||||
/* Now handle the specific object class.
|
||||
*/
|
||||
switch (objclass) {
|
||||
case CKO_CERTIFICATE:
|
||||
crv = lg_createCertObject(sdb,handle,templ,count);
|
||||
break;
|
||||
case CKO_NETSCAPE_TRUST:
|
||||
crv = lg_createTrustObject(sdb,handle,templ,count);
|
||||
break;
|
||||
case CKO_NETSCAPE_CRL:
|
||||
crv = lg_createCrlObject(sdb,handle,templ,count);
|
||||
break;
|
||||
case CKO_NETSCAPE_SMIME:
|
||||
crv = lg_createSMimeObject(sdb,handle,templ,count);
|
||||
break;
|
||||
case CKO_PRIVATE_KEY:
|
||||
case CKO_PUBLIC_KEY:
|
||||
case CKO_SECRET_KEY:
|
||||
crv = lg_createKeyObject(sdb,objclass,handle,templ,count);
|
||||
break;
|
||||
default:
|
||||
crv = CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
break;
|
||||
}
|
||||
|
||||
return crv;
|
||||
}
|
||||
|
||||
@@ -1,197 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* Internal data structures and functions used by pkcs11.c
|
||||
*/
|
||||
#ifndef _LGDB_H_
|
||||
#define _LGDB_H_ 1
|
||||
|
||||
#include "nssilock.h"
|
||||
#include "seccomon.h"
|
||||
#include "secoidt.h"
|
||||
#include "lowkeyti.h"
|
||||
#include "pkcs11t.h"
|
||||
#include "sdb.h"
|
||||
#include "cdbhdl.h"
|
||||
|
||||
|
||||
#define MULTIACCESS "multiaccess:"
|
||||
|
||||
|
||||
/* machine dependent path stuff used by dbinit.c and pk11db.c */
|
||||
#ifdef macintosh
|
||||
#define PATH_SEPARATOR ":"
|
||||
#define SECMOD_DB "Security Modules"
|
||||
#define CERT_DB_FMT "%sCertificates%s"
|
||||
#define KEY_DB_FMT "%sKey Database%s"
|
||||
#else
|
||||
#define PATH_SEPARATOR "/"
|
||||
#define SECMOD_DB "secmod.db"
|
||||
#define CERT_DB_FMT "%scert%s.db"
|
||||
#define KEY_DB_FMT "%skey%s.db"
|
||||
#endif
|
||||
|
||||
SEC_BEGIN_PROTOS
|
||||
|
||||
|
||||
/* internal utility functions used by pkcs11.c */
|
||||
extern const CK_ATTRIBUTE *lg_FindAttribute(CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count);
|
||||
extern CK_RV lg_Attribute2SecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
SECItem *item);
|
||||
extern CK_RV lg_Attribute2SSecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
SECItem *item);
|
||||
extern CK_RV lg_PrivAttr2SecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
SECItem *item, SDB *sdbpw);
|
||||
extern CK_RV lg_PrivAttr2SSecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
SECItem *item, SDB *sdbpw);
|
||||
extern CK_RV lg_GetULongAttribute(CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
CK_ULONG *out);
|
||||
extern PRBool lg_hasAttribute(CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count);
|
||||
extern PRBool lg_isTrue(CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count);
|
||||
extern PRBool lg_isSensitive(CK_ATTRIBUTE_TYPE type, CK_OBJECT_CLASS inClass);
|
||||
extern char *lg_getString(CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count);
|
||||
extern unsigned int lg_MapTrust(CK_TRUST trust, PRBool clientAuth);
|
||||
|
||||
/* clear out all the existing object ID to database key mappings.
|
||||
* used to reinit a token */
|
||||
extern CK_RV SFTK_ClearTokenKeyHashTable(SDB *sdb);
|
||||
|
||||
|
||||
extern void lg_FreeSearch(SDBFind *search);
|
||||
|
||||
NSSLOWCERTCertDBHandle *lg_getCertDB(SDB *sdb);
|
||||
NSSLOWKEYDBHandle *lg_getKeyDB(SDB *sdb);
|
||||
|
||||
const char *lg_EvaluateConfigDir(const char *configdir, char **domain);
|
||||
|
||||
|
||||
/*
|
||||
* object handle modifiers
|
||||
*/
|
||||
#define LG_TOKEN_MASK 0xc0000000L
|
||||
#define LG_TOKEN_TYPE_MASK 0x38000000L
|
||||
#define LG_TOKEN_TYPE_SHIFT 27
|
||||
/* keydb (high bit == 0) */
|
||||
#define LG_TOKEN_TYPE_PRIV 0x08000000L
|
||||
#define LG_TOKEN_TYPE_PUB 0x10000000L
|
||||
#define LG_TOKEN_TYPE_KEY 0x18000000L
|
||||
/* certdb (high bit == 1) */
|
||||
#define LG_TOKEN_TYPE_TRUST 0x20000000L
|
||||
#define LG_TOKEN_TYPE_CRL 0x28000000L
|
||||
#define LG_TOKEN_TYPE_SMIME 0x30000000L
|
||||
#define LG_TOKEN_TYPE_CERT 0x38000000L
|
||||
|
||||
#define LG_TOKEN_KRL_HANDLE (LG_TOKEN_TYPE_CRL|1)
|
||||
|
||||
#define LG_SEARCH_BLOCK_SIZE 10
|
||||
#define LG_BUF_SPACE 50
|
||||
#define LG_STRICT PR_FALSE
|
||||
|
||||
/*
|
||||
* token object utilities
|
||||
*/
|
||||
void lg_addHandle(SDBFind *search, CK_OBJECT_HANDLE handle);
|
||||
PRBool lg_poisonHandle(SDB *sdb, SECItem *dbkey, CK_OBJECT_HANDLE handle);
|
||||
PRBool lg_tokenMatch(SDB *sdb, const SECItem *dbKey, CK_OBJECT_HANDLE class,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count);
|
||||
const SECItem *lg_lookupTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle);
|
||||
CK_OBJECT_HANDLE lg_mkHandle(SDB *sdb, SECItem *dbKey, CK_OBJECT_HANDLE class);
|
||||
SECStatus lg_deleteTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle);
|
||||
|
||||
SECStatus lg_util_encrypt(PLArenaPool *arena, SDB *sdbpw,
|
||||
SECItem *plainText, SECItem **cipherText);
|
||||
SECStatus lg_util_decrypt(SDB *sdbpw,
|
||||
SECItem *cipherText, SECItem **plainText);
|
||||
PLHashTable *lg_GetHashTable(SDB *sdb);
|
||||
void lg_DBLock(SDB *sdb);
|
||||
void lg_DBUnlock(SDB *sdb);
|
||||
|
||||
typedef void (*LGFreeFunc)(void *);
|
||||
|
||||
|
||||
/*
|
||||
* database functions
|
||||
*/
|
||||
|
||||
/* lg_FindObjectsInit initializes a search for token and session objects
|
||||
* that match a template. */
|
||||
CK_RV lg_FindObjectsInit(SDB *sdb, const CK_ATTRIBUTE *pTemplate,
|
||||
CK_ULONG ulCount, SDBFind **search);
|
||||
/* lg_FindObjects continues a search for token and session objects
|
||||
* that match a template, obtaining additional object handles. */
|
||||
CK_RV lg_FindObjects(SDB *sdb, SDBFind *search,
|
||||
CK_OBJECT_HANDLE *phObject,CK_ULONG ulMaxObjectCount,
|
||||
CK_ULONG *pulObjectCount);
|
||||
|
||||
/* lg_FindObjectsFinal finishes a search for token and session objects. */
|
||||
CK_RV lg_FindObjectsFinal(SDB* lgdb, SDBFind *search);
|
||||
|
||||
/* lg_CreateObject parses the template and create an object stored in the
|
||||
* DB that reflects the object specified in the template. */
|
||||
CK_RV lg_CreateObject(SDB *sdb, CK_OBJECT_HANDLE *handle,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count);
|
||||
|
||||
CK_RV lg_GetAttributeValue(SDB *sdb, CK_OBJECT_HANDLE object_id,
|
||||
CK_ATTRIBUTE *template, CK_ULONG count);
|
||||
CK_RV lg_SetAttributeValue(SDB *sdb, CK_OBJECT_HANDLE object_id,
|
||||
const CK_ATTRIBUTE *template, CK_ULONG count);
|
||||
CK_RV lg_DestroyObject(SDB *sdb, CK_OBJECT_HANDLE object_id);
|
||||
|
||||
CK_RV lg_Close(SDB *sdb);
|
||||
CK_RV lg_Reset(SDB *sdb);
|
||||
|
||||
/*
|
||||
* The old database doesn't share and doesn't support
|
||||
* transactions.
|
||||
*/
|
||||
CK_RV lg_Begin(SDB *sdb);
|
||||
CK_RV lg_Commit(SDB *sdb);
|
||||
CK_RV lg_Abort(SDB *sdb);
|
||||
CK_RV lg_GetPWEntry(SDB *sdb, SDBPasswordEntry *entry);
|
||||
CK_RV lg_PutPWEntry(SDB *sdb, SDBPasswordEntry *entry);
|
||||
|
||||
SEC_END_PROTOS
|
||||
|
||||
#endif /* _LGDB_H_ */
|
||||
@@ -1,64 +0,0 @@
|
||||
;+#
|
||||
;+# ***** BEGIN LICENSE BLOCK *****
|
||||
;+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
;+#
|
||||
;+# 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 the Initial Developer are Copyright (C) 2000
|
||||
;+# the Initial Developer. All Rights Reserved.
|
||||
;+#
|
||||
;+# Contributor(s):
|
||||
;+# Dr Stephen Henson <stephen.henson@gemplus.com>
|
||||
;+#
|
||||
;+# Alternatively, the contents of this file may be used under the terms of
|
||||
;+# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
;+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
;+# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
;+# of those above. If you wish to allow use of your version of this file only
|
||||
;+# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
;+# use your version of this file under the terms of the MPL, indicate your
|
||||
;+# decision by deleting the provisions above and replace them with the notice
|
||||
;+# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
;+# the provisions above, a recipient may use your version of this file under
|
||||
;+# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
;+#
|
||||
;+# ***** END LICENSE BLOCK *****
|
||||
;+#
|
||||
;+# OK, this file is meant to support SUN, LINUX, AIX and WINDOWS
|
||||
;+# 1. For all unix platforms, the string ";-" means "remove this line"
|
||||
;+# 2. For all unix platforms, the string " DATA " will be removed from any
|
||||
;+# line on which it occurs.
|
||||
;+# 3. Lines containing ";+" will have ";+" removed on SUN and LINUX.
|
||||
;+# On AIX, lines containing ";+" will be removed.
|
||||
;+# 4. For all unix platforms, the string ";;" will thave the ";;" removed.
|
||||
;+# 5. For all unix platforms, after the above processing has taken place,
|
||||
;+# all characters after the first ";" on the line will be removed.
|
||||
;+# And for AIX, the first ";" will also be removed.
|
||||
;+# This file is passed directly to windows. Since ';' is a comment, all UNIX
|
||||
;+# directives are hidden behind ";", ";+", and ";-"
|
||||
;+LGDBM_3.12 { # NSS 3.12 release
|
||||
;+ global:
|
||||
LIBRARY lgdbm3 ;-
|
||||
EXPORTS ;-
|
||||
legacy_Open;
|
||||
legacy_Shutdown;
|
||||
legacy_ReadSecmodDB;
|
||||
legacy_ReleaseSecmodDBData;
|
||||
legacy_AddSecmodDB;
|
||||
legacy_DeleteSecmodDB;
|
||||
legacy_SetCryptFunctions;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
@@ -1,144 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* Internal PKCS #11 functions. Should only be called by pkcs11.c
|
||||
*/
|
||||
#include "pkcs11.h"
|
||||
#include "lgdb.h"
|
||||
#include "pcert.h"
|
||||
#include "lowkeyi.h"
|
||||
|
||||
/*
|
||||
* remove an object.
|
||||
*/
|
||||
CK_RV
|
||||
lg_DestroyObject(SDB *sdb, CK_OBJECT_HANDLE object_id)
|
||||
{
|
||||
CK_RV crv = CKR_OK;
|
||||
SECStatus rv;
|
||||
NSSLOWCERTCertificate *cert;
|
||||
NSSLOWCERTCertTrust tmptrust;
|
||||
PRBool isKrl;
|
||||
NSSLOWKEYDBHandle *keyHandle;
|
||||
NSSLOWCERTCertDBHandle *certHandle;
|
||||
const SECItem *dbKey;
|
||||
|
||||
object_id &= ~LG_TOKEN_MASK;
|
||||
dbKey = lg_lookupTokenKeyByHandle(sdb,object_id);
|
||||
if (dbKey == NULL) {
|
||||
return CKR_OBJECT_HANDLE_INVALID;
|
||||
}
|
||||
|
||||
/* remove the objects from the real data base */
|
||||
switch (object_id & LG_TOKEN_TYPE_MASK) {
|
||||
case LG_TOKEN_TYPE_PRIV:
|
||||
case LG_TOKEN_TYPE_KEY:
|
||||
/* KEYID is the public KEY for DSA and DH, and the MODULUS for
|
||||
* RSA */
|
||||
keyHandle = lg_getKeyDB(sdb);
|
||||
if (!keyHandle) {
|
||||
crv = CKR_TOKEN_WRITE_PROTECTED;
|
||||
break;
|
||||
}
|
||||
rv = nsslowkey_DeleteKey(keyHandle, dbKey);
|
||||
if (rv != SECSuccess) {
|
||||
crv = CKR_DEVICE_ERROR;
|
||||
}
|
||||
break;
|
||||
case LG_TOKEN_TYPE_PUB:
|
||||
break; /* public keys only exist at the behest of the priv key */
|
||||
case LG_TOKEN_TYPE_CERT:
|
||||
certHandle = lg_getCertDB(sdb);
|
||||
if (!certHandle) {
|
||||
crv = CKR_TOKEN_WRITE_PROTECTED;
|
||||
break;
|
||||
}
|
||||
cert = nsslowcert_FindCertByKey(certHandle,dbKey);
|
||||
if (cert == NULL) {
|
||||
crv = CKR_DEVICE_ERROR;
|
||||
break;
|
||||
}
|
||||
rv = nsslowcert_DeletePermCertificate(cert);
|
||||
if (rv != SECSuccess) {
|
||||
crv = CKR_DEVICE_ERROR;
|
||||
}
|
||||
nsslowcert_DestroyCertificate(cert);
|
||||
break;
|
||||
case LG_TOKEN_TYPE_CRL:
|
||||
certHandle = lg_getCertDB(sdb);
|
||||
if (!certHandle) {
|
||||
crv = CKR_TOKEN_WRITE_PROTECTED;
|
||||
break;
|
||||
}
|
||||
isKrl = (PRBool) (object_id == LG_TOKEN_KRL_HANDLE);
|
||||
rv = nsslowcert_DeletePermCRL(certHandle, dbKey, isKrl);
|
||||
if (rv == SECFailure) crv = CKR_DEVICE_ERROR;
|
||||
break;
|
||||
case LG_TOKEN_TYPE_TRUST:
|
||||
certHandle = lg_getCertDB(sdb);
|
||||
if (!certHandle) {
|
||||
crv = CKR_TOKEN_WRITE_PROTECTED;
|
||||
break;
|
||||
}
|
||||
cert = nsslowcert_FindCertByKey(certHandle, dbKey);
|
||||
if (cert == NULL) {
|
||||
crv = CKR_DEVICE_ERROR;
|
||||
break;
|
||||
}
|
||||
tmptrust = *cert->trust;
|
||||
tmptrust.sslFlags &= CERTDB_PRESERVE_TRUST_BITS;
|
||||
tmptrust.emailFlags &= CERTDB_PRESERVE_TRUST_BITS;
|
||||
tmptrust.objectSigningFlags &= CERTDB_PRESERVE_TRUST_BITS;
|
||||
tmptrust.sslFlags |= CERTDB_TRUSTED_UNKNOWN;
|
||||
tmptrust.emailFlags |= CERTDB_TRUSTED_UNKNOWN;
|
||||
tmptrust.objectSigningFlags |= CERTDB_TRUSTED_UNKNOWN;
|
||||
rv = nsslowcert_ChangeCertTrust(certHandle, cert, &tmptrust);
|
||||
if (rv != SECSuccess) crv = CKR_DEVICE_ERROR;
|
||||
nsslowcert_DestroyCertificate(cert);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
lg_DBLock(sdb);
|
||||
lg_deleteTokenKeyByHandle(sdb,object_id);
|
||||
lg_DBUnlock(sdb);
|
||||
|
||||
return crv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,941 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "secitem.h"
|
||||
#include "pkcs11.h"
|
||||
#include "lgdb.h"
|
||||
#include "lowkeyi.h"
|
||||
#include "pcert.h"
|
||||
#include "blapi.h"
|
||||
|
||||
#include "keydbi.h"
|
||||
|
||||
/*
|
||||
* This code maps PKCS #11 Finds to legacy database searches. This code
|
||||
* was orginally in pkcs11.c in previous versions of NSS.
|
||||
*/
|
||||
|
||||
struct SDBFindStr {
|
||||
CK_OBJECT_HANDLE *handles;
|
||||
int size;
|
||||
int index;
|
||||
int array_size;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* free a search structure
|
||||
*/
|
||||
void
|
||||
lg_FreeSearch(SDBFind *search)
|
||||
{
|
||||
if (search->handles) {
|
||||
PORT_Free(search->handles);
|
||||
}
|
||||
PORT_Free(search);
|
||||
}
|
||||
|
||||
void
|
||||
lg_addHandle(SDBFind *search, CK_OBJECT_HANDLE handle)
|
||||
{
|
||||
if (search->handles == NULL) {
|
||||
return;
|
||||
}
|
||||
if (search->size >= search->array_size) {
|
||||
search->array_size += LG_SEARCH_BLOCK_SIZE;
|
||||
search->handles = (CK_OBJECT_HANDLE *) PORT_Realloc(search->handles,
|
||||
sizeof(CK_OBJECT_HANDLE)* search->array_size);
|
||||
if (search->handles == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
search->handles[search->size] = handle;
|
||||
search->size++;
|
||||
}
|
||||
|
||||
/*
|
||||
* find any certs that may match the template and load them.
|
||||
*/
|
||||
#define LG_CERT 0x00000001
|
||||
#define LG_TRUST 0x00000002
|
||||
#define LG_CRL 0x00000004
|
||||
#define LG_SMIME 0x00000008
|
||||
#define LG_PRIVATE 0x00000010
|
||||
#define LG_PUBLIC 0x00000020
|
||||
#define LG_KEY 0x00000040
|
||||
|
||||
/*
|
||||
* structure to collect key handles.
|
||||
*/
|
||||
typedef struct lgEntryDataStr {
|
||||
SDB *sdb;
|
||||
SDBFind *searchHandles;
|
||||
const CK_ATTRIBUTE *template;
|
||||
CK_ULONG templ_count;
|
||||
} lgEntryData;
|
||||
|
||||
|
||||
static SECStatus
|
||||
lg_crl_collect(SECItem *data, SECItem *key, certDBEntryType type, void *arg)
|
||||
{
|
||||
lgEntryData *crlData;
|
||||
CK_OBJECT_HANDLE class_handle;
|
||||
SDB *sdb;
|
||||
|
||||
crlData = (lgEntryData *)arg;
|
||||
sdb = crlData->sdb;
|
||||
|
||||
class_handle = (type == certDBEntryTypeRevocation) ? LG_TOKEN_TYPE_CRL :
|
||||
LG_TOKEN_KRL_HANDLE;
|
||||
if (lg_tokenMatch(sdb, key, class_handle,
|
||||
crlData->template, crlData->templ_count)) {
|
||||
lg_addHandle(crlData->searchHandles,
|
||||
lg_mkHandle(sdb,key,class_handle));
|
||||
}
|
||||
return(SECSuccess);
|
||||
}
|
||||
|
||||
static void
|
||||
lg_searchCrls(SDB *sdb, SECItem *derSubject, PRBool isKrl,
|
||||
unsigned long classFlags, SDBFind *search,
|
||||
const CK_ATTRIBUTE *pTemplate, CK_ULONG ulCount)
|
||||
{
|
||||
NSSLOWCERTCertDBHandle *certHandle = NULL;
|
||||
|
||||
certHandle = lg_getCertDB(sdb);
|
||||
if (certHandle == NULL) {
|
||||
return;
|
||||
}
|
||||
if (derSubject->data != NULL) {
|
||||
certDBEntryRevocation *crl =
|
||||
nsslowcert_FindCrlByKey(certHandle, derSubject, isKrl);
|
||||
|
||||
if (crl != NULL) {
|
||||
lg_addHandle(search, lg_mkHandle(sdb, derSubject,
|
||||
isKrl ? LG_TOKEN_KRL_HANDLE : LG_TOKEN_TYPE_CRL));
|
||||
nsslowcert_DestroyDBEntry((certDBEntry *)crl);
|
||||
}
|
||||
} else {
|
||||
lgEntryData crlData;
|
||||
|
||||
/* traverse */
|
||||
crlData.sdb = sdb;
|
||||
crlData.searchHandles = search;
|
||||
crlData.template = pTemplate;
|
||||
crlData.templ_count = ulCount;
|
||||
nsslowcert_TraverseDBEntries(certHandle, certDBEntryTypeRevocation,
|
||||
lg_crl_collect, (void *)&crlData);
|
||||
nsslowcert_TraverseDBEntries(certHandle, certDBEntryTypeKeyRevocation,
|
||||
lg_crl_collect, (void *)&crlData);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* structure to collect key handles.
|
||||
*/
|
||||
typedef struct lgKeyDataStr {
|
||||
SDB *sdb;
|
||||
NSSLOWKEYDBHandle *keyHandle;
|
||||
SDBFind *searchHandles;
|
||||
SECItem *id;
|
||||
const CK_ATTRIBUTE *template;
|
||||
CK_ULONG templ_count;
|
||||
unsigned long classFlags;
|
||||
PRBool strict;
|
||||
} lgKeyData;
|
||||
|
||||
static PRBool
|
||||
isSecretKey(NSSLOWKEYPrivateKey *privKey)
|
||||
{
|
||||
if (privKey->keyType == NSSLOWKEYRSAKey &&
|
||||
privKey->u.rsa.publicExponent.len == 1 &&
|
||||
privKey->u.rsa.publicExponent.data[0] == 0)
|
||||
return PR_TRUE;
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static SECStatus
|
||||
lg_key_collect(DBT *key, DBT *data, void *arg)
|
||||
{
|
||||
lgKeyData *keyData;
|
||||
NSSLOWKEYPrivateKey *privKey = NULL;
|
||||
SECItem tmpDBKey;
|
||||
SDB *sdb;
|
||||
unsigned long classFlags;
|
||||
|
||||
keyData = (lgKeyData *)arg;
|
||||
sdb = keyData->sdb;
|
||||
classFlags = keyData->classFlags;
|
||||
|
||||
tmpDBKey.data = key->data;
|
||||
tmpDBKey.len = key->size;
|
||||
tmpDBKey.type = siBuffer;
|
||||
|
||||
PORT_Assert(keyData->keyHandle);
|
||||
if (!keyData->strict && keyData->id) {
|
||||
SECItem result;
|
||||
PRBool haveMatch= PR_FALSE;
|
||||
unsigned char hashKey[SHA1_LENGTH];
|
||||
result.data = hashKey;
|
||||
result.len = sizeof(hashKey);
|
||||
|
||||
if (keyData->id->len == 0) {
|
||||
/* Make sure this isn't a LG_KEY */
|
||||
privKey = nsslowkey_FindKeyByPublicKey(keyData->keyHandle,
|
||||
&tmpDBKey, keyData->sdb/*->password*/);
|
||||
if (privKey) {
|
||||
/* turn off the unneeded class flags */
|
||||
classFlags &= isSecretKey(privKey) ? ~(LG_PRIVATE|LG_PUBLIC) :
|
||||
~LG_KEY;
|
||||
haveMatch = (PRBool)
|
||||
((classFlags & (LG_KEY|LG_PRIVATE|LG_PUBLIC)) != 0);
|
||||
nsslowkey_DestroyPrivateKey(privKey);
|
||||
}
|
||||
} else {
|
||||
SHA1_HashBuf( hashKey, key->data, key->size ); /* match id */
|
||||
haveMatch = SECITEM_ItemsAreEqual(keyData->id,&result);
|
||||
if (!haveMatch && ((unsigned char *)key->data)[0] == 0) {
|
||||
/* This is a fix for backwards compatibility. The key
|
||||
* database indexes private keys by the public key, and
|
||||
* versions of NSS prior to 3.4 stored the public key as
|
||||
* a signed integer. The public key is now treated as an
|
||||
* unsigned integer, with no leading zero. In order to
|
||||
* correctly compute the hash of an old key, it is necessary
|
||||
* to fallback and detect the leading zero.
|
||||
*/
|
||||
SHA1_HashBuf(hashKey,
|
||||
(unsigned char *)key->data + 1, key->size - 1);
|
||||
haveMatch = SECITEM_ItemsAreEqual(keyData->id,&result);
|
||||
}
|
||||
}
|
||||
if (haveMatch) {
|
||||
if (classFlags & LG_PRIVATE) {
|
||||
lg_addHandle(keyData->searchHandles,
|
||||
lg_mkHandle(sdb,&tmpDBKey,LG_TOKEN_TYPE_PRIV));
|
||||
}
|
||||
if (classFlags & LG_PUBLIC) {
|
||||
lg_addHandle(keyData->searchHandles,
|
||||
lg_mkHandle(sdb,&tmpDBKey,LG_TOKEN_TYPE_PUB));
|
||||
}
|
||||
if (classFlags & LG_KEY) {
|
||||
lg_addHandle(keyData->searchHandles,
|
||||
lg_mkHandle(sdb,&tmpDBKey,LG_TOKEN_TYPE_KEY));
|
||||
}
|
||||
}
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
privKey = nsslowkey_FindKeyByPublicKey(keyData->keyHandle, &tmpDBKey,
|
||||
keyData->sdb/*->password*/);
|
||||
if ( privKey == NULL ) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
if (isSecretKey(privKey)) {
|
||||
if ((classFlags & LG_KEY) &&
|
||||
lg_tokenMatch(keyData->sdb, &tmpDBKey, LG_TOKEN_TYPE_KEY,
|
||||
keyData->template, keyData->templ_count)) {
|
||||
lg_addHandle(keyData->searchHandles,
|
||||
lg_mkHandle(keyData->sdb, &tmpDBKey, LG_TOKEN_TYPE_KEY));
|
||||
}
|
||||
} else {
|
||||
if ((classFlags & LG_PRIVATE) &&
|
||||
lg_tokenMatch(keyData->sdb, &tmpDBKey, LG_TOKEN_TYPE_PRIV,
|
||||
keyData->template, keyData->templ_count)) {
|
||||
lg_addHandle(keyData->searchHandles,
|
||||
lg_mkHandle(keyData->sdb,&tmpDBKey,LG_TOKEN_TYPE_PRIV));
|
||||
}
|
||||
if ((classFlags & LG_PUBLIC) &&
|
||||
lg_tokenMatch(keyData->sdb, &tmpDBKey, LG_TOKEN_TYPE_PUB,
|
||||
keyData->template, keyData->templ_count)) {
|
||||
lg_addHandle(keyData->searchHandles,
|
||||
lg_mkHandle(keyData->sdb, &tmpDBKey,LG_TOKEN_TYPE_PUB));
|
||||
}
|
||||
}
|
||||
|
||||
loser:
|
||||
if ( privKey ) {
|
||||
nsslowkey_DestroyPrivateKey(privKey);
|
||||
}
|
||||
return(SECSuccess);
|
||||
}
|
||||
|
||||
static void
|
||||
lg_searchKeys(SDB *sdb, SECItem *key_id,
|
||||
unsigned long classFlags, SDBFind *search, PRBool mustStrict,
|
||||
const CK_ATTRIBUTE *pTemplate, CK_ULONG ulCount)
|
||||
{
|
||||
NSSLOWKEYDBHandle *keyHandle = NULL;
|
||||
NSSLOWKEYPrivateKey *privKey;
|
||||
lgKeyData keyData;
|
||||
PRBool found = PR_FALSE;
|
||||
|
||||
keyHandle = lg_getKeyDB(sdb);
|
||||
if (keyHandle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key_id->data) {
|
||||
privKey = nsslowkey_FindKeyByPublicKey(keyHandle, key_id, sdb);
|
||||
if (privKey) {
|
||||
if ((classFlags & LG_KEY) && isSecretKey(privKey)) {
|
||||
lg_addHandle(search,
|
||||
lg_mkHandle(sdb,key_id,LG_TOKEN_TYPE_KEY));
|
||||
found = PR_TRUE;
|
||||
}
|
||||
if ((classFlags & LG_PRIVATE) && !isSecretKey(privKey)) {
|
||||
lg_addHandle(search,
|
||||
lg_mkHandle(sdb,key_id,LG_TOKEN_TYPE_PRIV));
|
||||
found = PR_TRUE;
|
||||
}
|
||||
if ((classFlags & LG_PUBLIC) && !isSecretKey(privKey)) {
|
||||
lg_addHandle(search,
|
||||
lg_mkHandle(sdb,key_id,LG_TOKEN_TYPE_PUB));
|
||||
found = PR_TRUE;
|
||||
}
|
||||
nsslowkey_DestroyPrivateKey(privKey);
|
||||
}
|
||||
/* don't do the traversal if we have an up to date db */
|
||||
if (keyHandle->version != 3) {
|
||||
goto loser;
|
||||
}
|
||||
/* don't do the traversal if it can't possibly be the correct id */
|
||||
/* all soft token id's are SHA1_HASH_LEN's */
|
||||
if (key_id->len != SHA1_LENGTH) {
|
||||
goto loser;
|
||||
}
|
||||
if (found) {
|
||||
/* if we already found some keys, don't do the traversal */
|
||||
goto loser;
|
||||
}
|
||||
}
|
||||
keyData.sdb = sdb;
|
||||
keyData.keyHandle = keyHandle;
|
||||
keyData.searchHandles = search;
|
||||
keyData.id = key_id;
|
||||
keyData.template = pTemplate;
|
||||
keyData.templ_count = ulCount;
|
||||
keyData.classFlags = classFlags;
|
||||
keyData.strict = mustStrict ? mustStrict : LG_STRICT;
|
||||
|
||||
nsslowkey_TraverseKeys(keyHandle, lg_key_collect, &keyData);
|
||||
|
||||
loser:
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* structure to collect certs into
|
||||
*/
|
||||
typedef struct lgCertDataStr {
|
||||
SDB *sdb;
|
||||
int cert_count;
|
||||
int max_cert_count;
|
||||
NSSLOWCERTCertificate **certs;
|
||||
const CK_ATTRIBUTE *template;
|
||||
CK_ULONG templ_count;
|
||||
unsigned long classFlags;
|
||||
PRBool strict;
|
||||
} lgCertData;
|
||||
|
||||
/*
|
||||
* collect all the certs from the traverse call.
|
||||
*/
|
||||
static SECStatus
|
||||
lg_cert_collect(NSSLOWCERTCertificate *cert,void *arg)
|
||||
{
|
||||
lgCertData *cd = (lgCertData *)arg;
|
||||
|
||||
if (cert == NULL) {
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
if (cd->certs == NULL) {
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
if (cd->strict) {
|
||||
if ((cd->classFlags & LG_CERT) && !lg_tokenMatch(cd->sdb,
|
||||
&cert->certKey, LG_TOKEN_TYPE_CERT, cd->template,cd->templ_count)) {
|
||||
return SECSuccess;
|
||||
}
|
||||
if ((cd->classFlags & LG_TRUST) && !lg_tokenMatch(cd->sdb,
|
||||
&cert->certKey, LG_TOKEN_TYPE_TRUST,
|
||||
cd->template, cd->templ_count)) {
|
||||
return SECSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
/* allocate more space if we need it. This should only happen in
|
||||
* the general traversal case */
|
||||
if (cd->cert_count >= cd->max_cert_count) {
|
||||
int size;
|
||||
cd->max_cert_count += LG_SEARCH_BLOCK_SIZE;
|
||||
size = cd->max_cert_count * sizeof (NSSLOWCERTCertificate *);
|
||||
cd->certs = (NSSLOWCERTCertificate **)PORT_Realloc(cd->certs,size);
|
||||
if (cd->certs == NULL) {
|
||||
return SECFailure;
|
||||
}
|
||||
}
|
||||
|
||||
cd->certs[cd->cert_count++] = nsslowcert_DupCertificate(cert);
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
/* provide impedence matching ... */
|
||||
static SECStatus
|
||||
lg_cert_collect2(NSSLOWCERTCertificate *cert, SECItem *dymmy, void *arg)
|
||||
{
|
||||
return lg_cert_collect(cert, arg);
|
||||
}
|
||||
|
||||
static void
|
||||
lg_searchSingleCert(lgCertData *certData,NSSLOWCERTCertificate *cert)
|
||||
{
|
||||
if (cert == NULL) {
|
||||
return;
|
||||
}
|
||||
if (certData->strict &&
|
||||
!lg_tokenMatch(certData->sdb, &cert->certKey, LG_TOKEN_TYPE_CERT,
|
||||
certData->template,certData->templ_count)) {
|
||||
nsslowcert_DestroyCertificate(cert);
|
||||
return;
|
||||
}
|
||||
certData->certs = (NSSLOWCERTCertificate **)
|
||||
PORT_Alloc(sizeof (NSSLOWCERTCertificate *));
|
||||
if (certData->certs == NULL) {
|
||||
nsslowcert_DestroyCertificate(cert);
|
||||
return;
|
||||
}
|
||||
certData->certs[0] = cert;
|
||||
certData->cert_count = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
lg_CertSetupData(lgCertData *certData,int count)
|
||||
{
|
||||
certData->max_cert_count = count;
|
||||
|
||||
if (certData->max_cert_count <= 0) {
|
||||
return;
|
||||
}
|
||||
certData->certs = (NSSLOWCERTCertificate **)
|
||||
PORT_Alloc( count * sizeof(NSSLOWCERTCertificate *));
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
lg_searchCertsAndTrust(SDB *sdb, SECItem *derCert, SECItem *name,
|
||||
SECItem *derSubject, NSSLOWCERTIssuerAndSN *issuerSN,
|
||||
SECItem *email,
|
||||
unsigned long classFlags, SDBFind *handles,
|
||||
const CK_ATTRIBUTE *pTemplate, CK_LONG ulCount)
|
||||
{
|
||||
NSSLOWCERTCertDBHandle *certHandle = NULL;
|
||||
lgCertData certData;
|
||||
int i;
|
||||
|
||||
certHandle = lg_getCertDB(sdb);
|
||||
if (certHandle == NULL) return;
|
||||
|
||||
certData.sdb = sdb;
|
||||
certData.max_cert_count = 0;
|
||||
certData.certs = NULL;
|
||||
certData.cert_count = 0;
|
||||
certData.template = pTemplate;
|
||||
certData.templ_count = ulCount;
|
||||
certData.classFlags = classFlags;
|
||||
certData.strict = LG_STRICT;
|
||||
|
||||
|
||||
/*
|
||||
* Find the Cert.
|
||||
*/
|
||||
if (derCert->data != NULL) {
|
||||
NSSLOWCERTCertificate *cert =
|
||||
nsslowcert_FindCertByDERCert(certHandle,derCert);
|
||||
lg_searchSingleCert(&certData,cert);
|
||||
} else if (name->data != NULL) {
|
||||
char *tmp_name = (char*)PORT_Alloc(name->len+1);
|
||||
int count;
|
||||
|
||||
if (tmp_name == NULL) {
|
||||
return;
|
||||
}
|
||||
PORT_Memcpy(tmp_name,name->data,name->len);
|
||||
tmp_name[name->len] = 0;
|
||||
|
||||
count= nsslowcert_NumPermCertsForNickname(certHandle,tmp_name);
|
||||
lg_CertSetupData(&certData,count);
|
||||
nsslowcert_TraversePermCertsForNickname(certHandle,tmp_name,
|
||||
lg_cert_collect, &certData);
|
||||
PORT_Free(tmp_name);
|
||||
} else if (derSubject->data != NULL) {
|
||||
int count;
|
||||
|
||||
count = nsslowcert_NumPermCertsForSubject(certHandle,derSubject);
|
||||
lg_CertSetupData(&certData,count);
|
||||
nsslowcert_TraversePermCertsForSubject(certHandle,derSubject,
|
||||
lg_cert_collect, &certData);
|
||||
} else if ((issuerSN->derIssuer.data != NULL) &&
|
||||
(issuerSN->serialNumber.data != NULL)) {
|
||||
if (classFlags & LG_CERT) {
|
||||
NSSLOWCERTCertificate *cert =
|
||||
nsslowcert_FindCertByIssuerAndSN(certHandle,issuerSN);
|
||||
|
||||
lg_searchSingleCert(&certData,cert);
|
||||
}
|
||||
if (classFlags & LG_TRUST) {
|
||||
NSSLOWCERTTrust *trust =
|
||||
nsslowcert_FindTrustByIssuerAndSN(certHandle, issuerSN);
|
||||
|
||||
if (trust) {
|
||||
lg_addHandle(handles,
|
||||
lg_mkHandle(sdb,&trust->dbKey,LG_TOKEN_TYPE_TRUST));
|
||||
nsslowcert_DestroyTrust(trust);
|
||||
}
|
||||
}
|
||||
} else if (email->data != NULL) {
|
||||
char *tmp_name = (char*)PORT_Alloc(email->len+1);
|
||||
certDBEntrySMime *entry = NULL;
|
||||
|
||||
if (tmp_name == NULL) {
|
||||
return;
|
||||
}
|
||||
PORT_Memcpy(tmp_name,email->data,email->len);
|
||||
tmp_name[email->len] = 0;
|
||||
|
||||
entry = nsslowcert_ReadDBSMimeEntry(certHandle,tmp_name);
|
||||
if (entry) {
|
||||
int count;
|
||||
SECItem *subjectName = &entry->subjectName;
|
||||
|
||||
count = nsslowcert_NumPermCertsForSubject(certHandle, subjectName);
|
||||
lg_CertSetupData(&certData,count);
|
||||
nsslowcert_TraversePermCertsForSubject(certHandle, subjectName,
|
||||
lg_cert_collect, &certData);
|
||||
|
||||
nsslowcert_DestroyDBEntry((certDBEntry *)entry);
|
||||
}
|
||||
PORT_Free(tmp_name);
|
||||
} else {
|
||||
/* we aren't filtering the certs, we are working on all, so turn
|
||||
* on the strict filters. */
|
||||
certData.strict = PR_TRUE;
|
||||
lg_CertSetupData(&certData,LG_SEARCH_BLOCK_SIZE);
|
||||
nsslowcert_TraversePermCerts(certHandle, lg_cert_collect2, &certData);
|
||||
}
|
||||
|
||||
/*
|
||||
* build the handles
|
||||
*/
|
||||
for (i=0 ; i < certData.cert_count ; i++) {
|
||||
NSSLOWCERTCertificate *cert = certData.certs[i];
|
||||
|
||||
/* if we filtered it would have been on the stuff above */
|
||||
if (classFlags & LG_CERT) {
|
||||
lg_addHandle(handles,
|
||||
lg_mkHandle(sdb,&cert->certKey,LG_TOKEN_TYPE_CERT));
|
||||
}
|
||||
if ((classFlags & LG_TRUST) && nsslowcert_hasTrust(cert->trust)) {
|
||||
lg_addHandle(handles,
|
||||
lg_mkHandle(sdb,&cert->certKey,LG_TOKEN_TYPE_TRUST));
|
||||
}
|
||||
nsslowcert_DestroyCertificate(cert);
|
||||
}
|
||||
|
||||
if (certData.certs) PORT_Free(certData.certs);
|
||||
return;
|
||||
}
|
||||
|
||||
static SECStatus
|
||||
lg_smime_collect(SECItem *data, SECItem *key, certDBEntryType type, void *arg)
|
||||
{
|
||||
lgEntryData *smimeData;
|
||||
SDB *sdb;
|
||||
|
||||
smimeData = (lgEntryData *)arg;
|
||||
sdb = smimeData->sdb;
|
||||
|
||||
if (lg_tokenMatch(sdb, key, LG_TOKEN_TYPE_SMIME,
|
||||
smimeData->template, smimeData->templ_count)) {
|
||||
lg_addHandle(smimeData->searchHandles,
|
||||
lg_mkHandle(sdb,key,LG_TOKEN_TYPE_SMIME));
|
||||
}
|
||||
return(SECSuccess);
|
||||
}
|
||||
|
||||
static void
|
||||
lg_searchSMime(SDB *sdb, SECItem *email, SDBFind *handles,
|
||||
const CK_ATTRIBUTE *pTemplate, CK_LONG ulCount)
|
||||
{
|
||||
NSSLOWCERTCertDBHandle *certHandle = NULL;
|
||||
certDBEntrySMime *entry;
|
||||
|
||||
certHandle = lg_getCertDB(sdb);
|
||||
if (certHandle == NULL) return;
|
||||
|
||||
if (email->data != NULL) {
|
||||
char *tmp_name = (char*)PORT_Alloc(email->len+1);
|
||||
|
||||
if (tmp_name == NULL) {
|
||||
return;
|
||||
}
|
||||
PORT_Memcpy(tmp_name,email->data,email->len);
|
||||
tmp_name[email->len] = 0;
|
||||
|
||||
entry = nsslowcert_ReadDBSMimeEntry(certHandle,tmp_name);
|
||||
if (entry) {
|
||||
SECItem emailKey;
|
||||
|
||||
emailKey.data = (unsigned char *)tmp_name;
|
||||
emailKey.len = PORT_Strlen(tmp_name)+1;
|
||||
emailKey.type = 0;
|
||||
lg_addHandle(handles,
|
||||
lg_mkHandle(sdb,&emailKey,LG_TOKEN_TYPE_SMIME));
|
||||
nsslowcert_DestroyDBEntry((certDBEntry *)entry);
|
||||
}
|
||||
PORT_Free(tmp_name);
|
||||
} else {
|
||||
/* traverse */
|
||||
lgEntryData smimeData;
|
||||
|
||||
/* traverse */
|
||||
smimeData.sdb = sdb;
|
||||
smimeData.searchHandles = handles;
|
||||
smimeData.template = pTemplate;
|
||||
smimeData.templ_count = ulCount;
|
||||
nsslowcert_TraverseDBEntries(certHandle, certDBEntryTypeSMimeProfile,
|
||||
lg_smime_collect, (void *)&smimeData);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static CK_RV
|
||||
lg_searchTokenList(SDB *sdb, SDBFind *search,
|
||||
const CK_ATTRIBUTE *pTemplate, CK_LONG ulCount)
|
||||
{
|
||||
int i;
|
||||
PRBool isKrl = PR_FALSE;
|
||||
SECItem derCert = { siBuffer, NULL, 0 };
|
||||
SECItem derSubject = { siBuffer, NULL, 0 };
|
||||
SECItem name = { siBuffer, NULL, 0 };
|
||||
SECItem email = { siBuffer, NULL, 0 };
|
||||
SECItem key_id = { siBuffer, NULL, 0 };
|
||||
SECItem cert_sha1_hash = { siBuffer, NULL, 0 };
|
||||
SECItem cert_md5_hash = { siBuffer, NULL, 0 };
|
||||
NSSLOWCERTIssuerAndSN issuerSN = {
|
||||
{ siBuffer, NULL, 0 },
|
||||
{ siBuffer, NULL, 0 }
|
||||
};
|
||||
SECItem *copy = NULL;
|
||||
CK_CERTIFICATE_TYPE certType;
|
||||
CK_OBJECT_CLASS objectClass;
|
||||
CK_RV crv;
|
||||
unsigned long classFlags =
|
||||
LG_CERT|LG_TRUST|LG_PRIVATE|LG_PUBLIC|LG_KEY|LG_SMIME|LG_CRL;
|
||||
|
||||
if (lg_getCertDB(sdb) == NULL) {
|
||||
classFlags = LG_PRIVATE|LG_KEY;
|
||||
} else {
|
||||
classFlags = LG_CERT|LG_TRUST|LG_PUBLIC|LG_SMIME|LG_CRL;
|
||||
}
|
||||
|
||||
/*
|
||||
* look for things to search on token objects for. If the right options
|
||||
* are specified, we can use them as direct indeces into the database
|
||||
* (rather than using linear searches. We can also use the attributes to
|
||||
* limit the kinds of objects we are searching for. Later we can use this
|
||||
* array to filter the remaining objects more finely.
|
||||
*/
|
||||
for (i=0 ;classFlags && i < (int)ulCount; i++) {
|
||||
|
||||
switch (pTemplate[i].type) {
|
||||
case CKA_SUBJECT:
|
||||
copy = &derSubject;
|
||||
classFlags &= (LG_CERT|LG_PRIVATE|LG_PUBLIC|LG_SMIME|LG_CRL);
|
||||
break;
|
||||
case CKA_ISSUER:
|
||||
copy = &issuerSN.derIssuer;
|
||||
classFlags &= (LG_CERT|LG_TRUST);
|
||||
break;
|
||||
case CKA_SERIAL_NUMBER:
|
||||
copy = &issuerSN.serialNumber;
|
||||
classFlags &= (LG_CERT|LG_TRUST);
|
||||
break;
|
||||
case CKA_VALUE:
|
||||
copy = &derCert;
|
||||
classFlags &= (LG_CERT|LG_CRL|LG_SMIME);
|
||||
break;
|
||||
case CKA_LABEL:
|
||||
copy = &name;
|
||||
break;
|
||||
case CKA_NETSCAPE_EMAIL:
|
||||
copy = &email;
|
||||
classFlags &= LG_SMIME|LG_CERT;
|
||||
break;
|
||||
case CKA_NETSCAPE_SMIME_TIMESTAMP:
|
||||
classFlags &= LG_SMIME;
|
||||
break;
|
||||
case CKA_CLASS:
|
||||
crv = lg_GetULongAttribute(CKA_CLASS,&pTemplate[i],1, &objectClass);
|
||||
if (crv != CKR_OK) {
|
||||
classFlags = 0;
|
||||
break;;
|
||||
}
|
||||
switch (objectClass) {
|
||||
case CKO_CERTIFICATE:
|
||||
classFlags &= LG_CERT;
|
||||
break;
|
||||
case CKO_NETSCAPE_TRUST:
|
||||
classFlags &= LG_TRUST;
|
||||
break;
|
||||
case CKO_NETSCAPE_CRL:
|
||||
classFlags &= LG_CRL;
|
||||
break;
|
||||
case CKO_NETSCAPE_SMIME:
|
||||
classFlags &= LG_SMIME;
|
||||
break;
|
||||
case CKO_PRIVATE_KEY:
|
||||
classFlags &= LG_PRIVATE;
|
||||
break;
|
||||
case CKO_PUBLIC_KEY:
|
||||
classFlags &= LG_PUBLIC;
|
||||
break;
|
||||
case CKO_SECRET_KEY:
|
||||
classFlags &= LG_KEY;
|
||||
break;
|
||||
default:
|
||||
classFlags = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CKA_PRIVATE:
|
||||
if (pTemplate[i].ulValueLen != sizeof(CK_BBOOL)) {
|
||||
classFlags = 0;
|
||||
}
|
||||
if (*((CK_BBOOL *)pTemplate[i].pValue) == CK_TRUE) {
|
||||
classFlags &= (LG_PRIVATE|LG_KEY);
|
||||
} else {
|
||||
classFlags &= ~(LG_PRIVATE|LG_KEY);
|
||||
}
|
||||
break;
|
||||
case CKA_SENSITIVE:
|
||||
if (pTemplate[i].ulValueLen != sizeof(CK_BBOOL)) {
|
||||
classFlags = 0;
|
||||
}
|
||||
if (*((CK_BBOOL *)pTemplate[i].pValue) == CK_TRUE) {
|
||||
classFlags &= (LG_PRIVATE|LG_KEY);
|
||||
} else {
|
||||
classFlags = 0;
|
||||
}
|
||||
break;
|
||||
case CKA_TOKEN:
|
||||
if (pTemplate[i].ulValueLen != sizeof(CK_BBOOL)) {
|
||||
classFlags = 0;
|
||||
}
|
||||
if (*((CK_BBOOL *)pTemplate[i].pValue) != CK_TRUE) {
|
||||
classFlags = 0;
|
||||
}
|
||||
break;
|
||||
case CKA_CERT_SHA1_HASH:
|
||||
classFlags &= LG_TRUST;
|
||||
copy = &cert_sha1_hash; break;
|
||||
case CKA_CERT_MD5_HASH:
|
||||
classFlags &= LG_TRUST;
|
||||
copy = &cert_md5_hash; break;
|
||||
case CKA_CERTIFICATE_TYPE:
|
||||
crv = lg_GetULongAttribute(CKA_CLASS,&pTemplate[i],1,&certType);
|
||||
if (crv != CKR_OK) {
|
||||
classFlags = 0;
|
||||
}
|
||||
classFlags &= LG_CERT;
|
||||
if (certType != CKC_X_509) {
|
||||
classFlags = 0;
|
||||
}
|
||||
break;
|
||||
case CKA_ID:
|
||||
copy = &key_id;
|
||||
classFlags &= (LG_CERT|LG_PRIVATE|LG_KEY|LG_PUBLIC);
|
||||
break;
|
||||
case CKA_NETSCAPE_KRL:
|
||||
if (pTemplate[i].ulValueLen != sizeof(CK_BBOOL)) {
|
||||
classFlags = 0;
|
||||
}
|
||||
classFlags &= LG_CRL;
|
||||
isKrl = (PRBool)(*((CK_BBOOL *)pTemplate[i].pValue) == CK_TRUE);
|
||||
break;
|
||||
case CKA_MODIFIABLE:
|
||||
break;
|
||||
case CKA_KEY_TYPE:
|
||||
case CKA_DERIVE:
|
||||
classFlags &= LG_PUBLIC|LG_PRIVATE|LG_KEY;
|
||||
break;
|
||||
case CKA_VERIFY_RECOVER:
|
||||
classFlags &= LG_PUBLIC;
|
||||
break;
|
||||
case CKA_SIGN_RECOVER:
|
||||
classFlags &= LG_PRIVATE;
|
||||
break;
|
||||
case CKA_ENCRYPT:
|
||||
case CKA_VERIFY:
|
||||
case CKA_WRAP:
|
||||
classFlags &= LG_PUBLIC|LG_KEY;
|
||||
break;
|
||||
case CKA_DECRYPT:
|
||||
case CKA_SIGN:
|
||||
case CKA_UNWRAP:
|
||||
case CKA_ALWAYS_SENSITIVE:
|
||||
case CKA_EXTRACTABLE:
|
||||
case CKA_NEVER_EXTRACTABLE:
|
||||
classFlags &= LG_PRIVATE|LG_KEY;
|
||||
break;
|
||||
/* can't be a certificate if it doesn't match one of the above
|
||||
* attributes */
|
||||
default:
|
||||
classFlags = 0;
|
||||
break;
|
||||
}
|
||||
if (copy) {
|
||||
copy->data = (unsigned char*)pTemplate[i].pValue;
|
||||
copy->len = pTemplate[i].ulValueLen;
|
||||
}
|
||||
copy = NULL;
|
||||
}
|
||||
|
||||
/* certs */
|
||||
if (classFlags & (LG_CERT|LG_TRUST)) {
|
||||
lg_searchCertsAndTrust(sdb,&derCert,&name,&derSubject,
|
||||
&issuerSN, &email,classFlags,search,
|
||||
pTemplate, ulCount);
|
||||
}
|
||||
|
||||
/* keys */
|
||||
if (classFlags & (LG_PRIVATE|LG_PUBLIC|LG_KEY)) {
|
||||
PRBool mustStrict = ((classFlags & LG_KEY) != 0) && (name.len != 0);
|
||||
lg_searchKeys(sdb, &key_id, classFlags, search,
|
||||
mustStrict, pTemplate, ulCount);
|
||||
}
|
||||
|
||||
/* crl's */
|
||||
if (classFlags & LG_CRL) {
|
||||
lg_searchCrls(sdb, &derSubject, isKrl, classFlags, search,
|
||||
pTemplate, ulCount);
|
||||
}
|
||||
/* Add S/MIME entry stuff */
|
||||
if (classFlags & LG_SMIME) {
|
||||
lg_searchSMime(sdb, &email, search, pTemplate, ulCount);
|
||||
}
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
|
||||
/* lg_FindObjectsInit initializes a search for token and session objects
|
||||
* that match a template. */
|
||||
CK_RV lg_FindObjectsInit(SDB *sdb, const CK_ATTRIBUTE *pTemplate,
|
||||
CK_ULONG ulCount, SDBFind **retSearch)
|
||||
{
|
||||
SDBFind *search;
|
||||
CK_RV crv = CKR_OK;
|
||||
|
||||
*retSearch = NULL;
|
||||
|
||||
search = (SDBFind *)PORT_Alloc(sizeof(SDBFind));
|
||||
if (search == NULL) {
|
||||
crv = CKR_HOST_MEMORY;
|
||||
goto loser;
|
||||
}
|
||||
search->handles = (CK_OBJECT_HANDLE *)
|
||||
PORT_Alloc(sizeof(CK_OBJECT_HANDLE) * LG_SEARCH_BLOCK_SIZE);
|
||||
if (search->handles == NULL) {
|
||||
crv = CKR_HOST_MEMORY;
|
||||
goto loser;
|
||||
}
|
||||
search->index = 0;
|
||||
search->size = 0;
|
||||
search->array_size = LG_SEARCH_BLOCK_SIZE;
|
||||
/* FIXME - do we still need to get Login state? */
|
||||
|
||||
crv = lg_searchTokenList(sdb, search, pTemplate, ulCount);
|
||||
if (crv != CKR_OK) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
*retSearch = search;
|
||||
return CKR_OK;
|
||||
|
||||
loser:
|
||||
if (search) {
|
||||
lg_FreeSearch(search);
|
||||
}
|
||||
return crv;
|
||||
}
|
||||
|
||||
|
||||
/* lg_FindObjects continues a search for token and session objects
|
||||
* that match a template, obtaining additional object handles. */
|
||||
CK_RV lg_FindObjects(SDB *sdb, SDBFind *search,
|
||||
CK_OBJECT_HANDLE *phObject,CK_ULONG ulMaxObjectCount,
|
||||
CK_ULONG *pulObjectCount)
|
||||
{
|
||||
int transfer;
|
||||
int left;
|
||||
|
||||
*pulObjectCount = 0;
|
||||
left = search->size - search->index;
|
||||
transfer = ((int)ulMaxObjectCount > left) ? left : ulMaxObjectCount;
|
||||
if (transfer > 0) {
|
||||
PORT_Memcpy(phObject,&search->handles[search->index],
|
||||
transfer*sizeof(CK_OBJECT_HANDLE_PTR));
|
||||
} else {
|
||||
*phObject = CK_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
search->index += transfer;
|
||||
*pulObjectCount = transfer;
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
/* lg_FindObjectsFinal finishes a search for token and session objects. */
|
||||
CK_RV lg_FindObjectsFinal(SDB* lgdb, SDBFind *search)
|
||||
{
|
||||
|
||||
if (search != NULL) {
|
||||
lg_FreeSearch(search);
|
||||
}
|
||||
return CKR_OK;
|
||||
}
|
||||
@@ -1,644 +0,0 @@
|
||||
/*
|
||||
* NSS utility functions
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/* $Id: lginit.c,v 1.1.2.1 2007-04-03 22:50:02 rrelyea%redhat.com Exp $ */
|
||||
|
||||
#include "lowkeyi.h"
|
||||
#include "pcert.h"
|
||||
#include "keydbi.h"
|
||||
#include "lgdb.h"
|
||||
|
||||
typedef struct LGPrivateStr {
|
||||
NSSLOWCERTCertDBHandle *certDB;
|
||||
NSSLOWKEYDBHandle *keyDB;
|
||||
PRLock *dbLock;
|
||||
PLHashTable *hashTable;
|
||||
} LGPrivate;
|
||||
|
||||
static char *
|
||||
lg_certdb_name_cb(void *arg, int dbVersion)
|
||||
{
|
||||
const char *configdir = (const char *)arg;
|
||||
const char *dbver;
|
||||
char *smpname = NULL;
|
||||
char *dbname = NULL;
|
||||
|
||||
switch (dbVersion) {
|
||||
case 8:
|
||||
dbver = "8";
|
||||
break;
|
||||
case 7:
|
||||
dbver = "7";
|
||||
break;
|
||||
case 6:
|
||||
dbver = "6";
|
||||
break;
|
||||
case 5:
|
||||
dbver = "5";
|
||||
break;
|
||||
case 4:
|
||||
default:
|
||||
dbver = "";
|
||||
break;
|
||||
}
|
||||
|
||||
/* make sure we return something allocated with PORT_ so we have properly
|
||||
* matched frees at the end */
|
||||
smpname = PR_smprintf(CERT_DB_FMT, configdir, dbver);
|
||||
if (smpname) {
|
||||
dbname = PORT_Strdup(smpname);
|
||||
PR_smprintf_free(smpname);
|
||||
}
|
||||
return dbname;
|
||||
}
|
||||
|
||||
static char *
|
||||
lg_keydb_name_cb(void *arg, int dbVersion)
|
||||
{
|
||||
const char *configdir = (const char *)arg;
|
||||
const char *dbver;
|
||||
char *smpname = NULL;
|
||||
char *dbname = NULL;
|
||||
|
||||
switch (dbVersion) {
|
||||
case 4:
|
||||
dbver = "4";
|
||||
break;
|
||||
case 3:
|
||||
dbver = "3";
|
||||
break;
|
||||
case 1:
|
||||
dbver = "1";
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
dbver = "";
|
||||
break;
|
||||
}
|
||||
|
||||
smpname = PR_smprintf(KEY_DB_FMT, configdir, dbver);
|
||||
if (smpname) {
|
||||
dbname = PORT_Strdup(smpname);
|
||||
PR_smprintf_free(smpname);
|
||||
}
|
||||
return dbname;
|
||||
}
|
||||
|
||||
const char *
|
||||
lg_EvaluateConfigDir(const char *configdir,char **appName)
|
||||
{
|
||||
if (PORT_Strncmp(configdir, MULTIACCESS, sizeof(MULTIACCESS)-1) == 0) {
|
||||
char *cdir;
|
||||
|
||||
*appName = PORT_Strdup(configdir+sizeof(MULTIACCESS)-1);
|
||||
if (*appName == NULL) {
|
||||
return configdir;
|
||||
}
|
||||
cdir = *appName;
|
||||
while (*cdir && *cdir != ':') {
|
||||
cdir++;
|
||||
}
|
||||
if (*cdir == ':') {
|
||||
*cdir = 0;
|
||||
cdir++;
|
||||
}
|
||||
configdir = cdir;
|
||||
}
|
||||
return configdir;
|
||||
}
|
||||
|
||||
static int rdbmapflags(int flags);
|
||||
static rdbfunc lg_rdbfunc = NULL;
|
||||
static rdbstatusfunc lg_rdbstatusfunc = NULL;
|
||||
|
||||
/* NOTE: SHLIB_SUFFIX is defined on the command line */
|
||||
#define RDBLIB SHLIB_PREFIX"rdb."SHLIB_SUFFIX
|
||||
|
||||
DB * rdbopen(const char *appName, const char *prefix,
|
||||
const char *type, int flags, int *status)
|
||||
{
|
||||
PRLibrary *lib;
|
||||
DB *db;
|
||||
|
||||
if (lg_rdbfunc) {
|
||||
db = (*lg_rdbfunc)(appName,prefix,type,rdbmapflags(flags));
|
||||
if (!db && status && lg_rdbstatusfunc) {
|
||||
*status = (*lg_rdbstatusfunc)();
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
/*
|
||||
* try to open the library.
|
||||
*/
|
||||
lib = PR_LoadLibrary(RDBLIB);
|
||||
|
||||
if (!lib) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* get the entry points */
|
||||
lg_rdbstatusfunc = (rdbstatusfunc) PR_FindSymbol(lib,"rdbstatus");
|
||||
lg_rdbfunc = (rdbfunc) PR_FindSymbol(lib,"rdbopen");
|
||||
if (lg_rdbfunc) {
|
||||
db = (*lg_rdbfunc)(appName,prefix,type,rdbmapflags(flags));
|
||||
if (!db && status && lg_rdbstatusfunc) {
|
||||
*status = (*lg_rdbstatusfunc)();
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
/* couldn't find the entry point, unload the library and fail */
|
||||
PR_UnloadLibrary(lib);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* the following data structures are from rdb.h.
|
||||
*/
|
||||
struct RDBStr {
|
||||
DB db;
|
||||
int (*xactstart)(DB *db);
|
||||
int (*xactdone)(DB *db, PRBool abort);
|
||||
int version;
|
||||
int (*dbinitcomplete)(DB *db);
|
||||
};
|
||||
|
||||
#define DB_RDB ((DBTYPE) 0xff)
|
||||
#define RDB_RDONLY 1
|
||||
#define RDB_RDWR 2
|
||||
#define RDB_CREATE 4
|
||||
|
||||
static int
|
||||
rdbmapflags(int flags) {
|
||||
switch (flags) {
|
||||
case NO_RDONLY:
|
||||
return RDB_RDONLY;
|
||||
case NO_RDWR:
|
||||
return RDB_RDWR;
|
||||
case NO_CREATE:
|
||||
return RDB_CREATE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRBool
|
||||
db_IsRDB(DB *db)
|
||||
{
|
||||
return (PRBool) db->type == DB_RDB;
|
||||
}
|
||||
|
||||
int
|
||||
db_BeginTransaction(DB *db)
|
||||
{
|
||||
struct RDBStr *rdb = (struct RDBStr *)db;
|
||||
if (db->type != DB_RDB) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rdb->xactstart(db);
|
||||
}
|
||||
|
||||
int
|
||||
db_FinishTransaction(DB *db, PRBool abort)
|
||||
{
|
||||
struct RDBStr *rdb = (struct RDBStr *)db;
|
||||
if (db->type != DB_RDB) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rdb->xactdone(db, abort);
|
||||
}
|
||||
|
||||
static DB *
|
||||
lg_getRawDB(SDB *sdb)
|
||||
{
|
||||
NSSLOWCERTCertDBHandle *certDB;
|
||||
NSSLOWKEYDBHandle *keyDB;
|
||||
|
||||
certDB = lg_getCertDB(sdb);
|
||||
if (certDB) {
|
||||
return certDB->permCertDB;
|
||||
}
|
||||
keyDB = lg_getKeyDB(sdb);
|
||||
if (keyDB) {
|
||||
return keyDB->db;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CK_RV
|
||||
lg_Begin(SDB *sdb)
|
||||
{
|
||||
DB *db = lg_getRawDB(sdb);
|
||||
int ret;
|
||||
|
||||
if (db == NULL) {
|
||||
return CKR_GENERAL_ERROR; /* shouldn't happen */
|
||||
}
|
||||
ret = db_BeginTransaction(db);
|
||||
if (ret != 0) {
|
||||
return CKR_GENERAL_ERROR; /* could happen */
|
||||
}
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
CK_RV
|
||||
lg_Commit(SDB *sdb)
|
||||
{
|
||||
DB *db = lg_getRawDB(sdb);
|
||||
int ret;
|
||||
|
||||
if (db == NULL) {
|
||||
return CKR_GENERAL_ERROR; /* shouldn't happen */
|
||||
}
|
||||
ret = db_FinishTransaction(db, PR_FALSE);
|
||||
if (ret != 0) {
|
||||
return CKR_GENERAL_ERROR; /* could happen */
|
||||
}
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
CK_RV
|
||||
lg_Abort(SDB *sdb)
|
||||
{
|
||||
DB *db = lg_getRawDB(sdb);
|
||||
int ret;
|
||||
|
||||
if (db == NULL) {
|
||||
return CKR_GENERAL_ERROR; /* shouldn't happen */
|
||||
}
|
||||
ret = db_FinishTransaction(db, PR_TRUE);
|
||||
if (ret != 0) {
|
||||
return CKR_GENERAL_ERROR; /* could happen */
|
||||
}
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
int
|
||||
db_InitComplete(DB *db)
|
||||
{
|
||||
struct RDBStr *rdb = (struct RDBStr *)db;
|
||||
if (db->type != DB_RDB) {
|
||||
return 0;
|
||||
}
|
||||
/* we should have added a version number to the RDBS structure. Since we
|
||||
* didn't, we detect that we have and 'extended' structure if the rdbstatus
|
||||
* func exists */
|
||||
if (!lg_rdbstatusfunc) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rdb->dbinitcomplete(db);
|
||||
}
|
||||
|
||||
|
||||
|
||||
SECStatus
|
||||
db_Copy(DB *dest,DB *src)
|
||||
{
|
||||
int ret;
|
||||
DBT key,data;
|
||||
ret = (*src->seq)(src, &key, &data, R_FIRST);
|
||||
if (ret) {
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
do {
|
||||
(void)(*dest->put)(dest,&key,&data, R_NOOVERWRITE);
|
||||
} while ( (*src->seq)(src, &key, &data, R_NEXT) == 0);
|
||||
(void)(*dest->sync)(dest,0);
|
||||
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
|
||||
static CK_RV
|
||||
lg_OpenCertDB(const char * configdir, const char *prefix, PRBool readOnly,
|
||||
NSSLOWCERTCertDBHandle **certdbPtr)
|
||||
{
|
||||
NSSLOWCERTCertDBHandle *certdb = NULL;
|
||||
CK_RV crv = CKR_NETSCAPE_CERTDB_FAILED;
|
||||
SECStatus rv;
|
||||
char * name = NULL;
|
||||
char * appName = NULL;
|
||||
|
||||
if (prefix == NULL) {
|
||||
prefix = "";
|
||||
}
|
||||
|
||||
configdir = lg_EvaluateConfigDir(configdir, &appName);
|
||||
|
||||
name = PR_smprintf("%s" PATH_SEPARATOR "%s",configdir,prefix);
|
||||
if (name == NULL) goto loser;
|
||||
|
||||
certdb = (NSSLOWCERTCertDBHandle*)PORT_ZAlloc(sizeof(NSSLOWCERTCertDBHandle));
|
||||
if (certdb == NULL)
|
||||
goto loser;
|
||||
|
||||
certdb->ref = 1;
|
||||
/* fix when we get the DB in */
|
||||
rv = nsslowcert_OpenCertDB(certdb, readOnly, appName, prefix,
|
||||
lg_certdb_name_cb, (void *)name, PR_FALSE);
|
||||
if (rv == SECSuccess) {
|
||||
crv = CKR_OK;
|
||||
*certdbPtr = certdb;
|
||||
certdb = NULL;
|
||||
}
|
||||
loser:
|
||||
if (certdb) PR_Free(certdb);
|
||||
if (name) PR_smprintf_free(name);
|
||||
if (appName) PORT_Free(appName);
|
||||
return crv;
|
||||
}
|
||||
|
||||
static CK_RV
|
||||
lg_OpenKeyDB(const char * configdir, const char *prefix, PRBool readOnly,
|
||||
NSSLOWKEYDBHandle **keydbPtr)
|
||||
{
|
||||
NSSLOWKEYDBHandle *keydb;
|
||||
char * name = NULL;
|
||||
char * appName = NULL;
|
||||
|
||||
if (prefix == NULL) {
|
||||
prefix = "";
|
||||
}
|
||||
configdir = lg_EvaluateConfigDir(configdir, &appName);
|
||||
|
||||
name = PR_smprintf("%s" PATH_SEPARATOR "%s",configdir,prefix);
|
||||
if (name == NULL)
|
||||
return CKR_HOST_MEMORY;
|
||||
keydb = nsslowkey_OpenKeyDB(readOnly, appName, prefix,
|
||||
lg_keydb_name_cb, (void *)name);
|
||||
PR_smprintf_free(name);
|
||||
if (appName) PORT_Free(appName);
|
||||
if (keydb == NULL)
|
||||
return CKR_NETSCAPE_KEYDB_FAILED;
|
||||
*keydbPtr = keydb;
|
||||
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Accessors for the private parts of the sdb structure.
|
||||
*/
|
||||
void
|
||||
lg_DBLock(SDB *sdb)
|
||||
{
|
||||
LGPrivate *lgdb_p = (LGPrivate *)sdb->private;
|
||||
PR_Lock(lgdb_p->dbLock);
|
||||
}
|
||||
|
||||
void
|
||||
lg_DBUnlock(SDB *sdb)
|
||||
{
|
||||
LGPrivate *lgdb_p = (LGPrivate *)sdb->private;
|
||||
PR_Unlock(lgdb_p->dbLock);
|
||||
}
|
||||
|
||||
PLHashTable *
|
||||
lg_GetHashTable(SDB *sdb)
|
||||
{
|
||||
LGPrivate *lgdb_p = (LGPrivate *)sdb->private;
|
||||
return lgdb_p->hashTable;
|
||||
}
|
||||
|
||||
NSSLOWCERTCertDBHandle *
|
||||
lg_getCertDB(SDB *sdb)
|
||||
{
|
||||
LGPrivate *lgdb_p = (LGPrivate *)sdb->private;
|
||||
|
||||
return lgdb_p->certDB;
|
||||
}
|
||||
|
||||
NSSLOWKEYDBHandle *
|
||||
lg_getKeyDB(SDB *sdb)
|
||||
{
|
||||
LGPrivate *lgdb_p = (LGPrivate *)sdb->private;
|
||||
|
||||
return lgdb_p->keyDB;
|
||||
}
|
||||
|
||||
CK_RV
|
||||
lg_Close(SDB *sdb)
|
||||
{
|
||||
LGPrivate *lgdb_p = (LGPrivate *)sdb->private;
|
||||
if (lgdb_p) {
|
||||
if (lgdb_p->certDB) {
|
||||
nsslowcert_ClosePermCertDB(lgdb_p->certDB);
|
||||
} else if (lgdb_p->keyDB) {
|
||||
nsslowkey_CloseKeyDB(lgdb_p->keyDB);
|
||||
}
|
||||
if (lgdb_p->dbLock) {
|
||||
PR_DestroyLock(lgdb_p->dbLock);
|
||||
}
|
||||
if (lgdb_p->hashTable) {
|
||||
PL_HashTableDestroy(lgdb_p->hashTable);
|
||||
}
|
||||
PORT_Free(lgdb_p);
|
||||
}
|
||||
PORT_Free(sdb);
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
static PLHashNumber
|
||||
lg_HashNumber(const void *key)
|
||||
{
|
||||
return (PLHashNumber) key;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* helper function to wrap a NSSLOWCERTCertDBHandle or a NSSLOWKEYDBHandle
|
||||
* with and sdb structure.
|
||||
*/
|
||||
CK_RV
|
||||
lg_init(SDB **pSdb, int flags, NSSLOWCERTCertDBHandle *certdbPtr,
|
||||
NSSLOWKEYDBHandle *keydbPtr)
|
||||
{
|
||||
SDB *sdb = NULL;
|
||||
LGPrivate *lgdb_p = NULL;
|
||||
CK_RV error = CKR_HOST_MEMORY;
|
||||
|
||||
*pSdb = NULL;
|
||||
sdb = (SDB *) PORT_Alloc(sizeof(SDB));
|
||||
if (sdb == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
lgdb_p = (LGPrivate *) PORT_Alloc(sizeof(LGPrivate));
|
||||
if (lgdb_p == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
/* invariant fields */
|
||||
lgdb_p->certDB = certdbPtr;
|
||||
lgdb_p->keyDB = keydbPtr;
|
||||
lgdb_p->dbLock = PR_NewLock();
|
||||
if (lgdb_p->dbLock == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
lgdb_p->hashTable = PL_NewHashTable(64, lg_HashNumber, PL_CompareValues,
|
||||
SECITEM_HashCompare, NULL, 0);
|
||||
if (lgdb_p->hashTable == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
sdb->sdb_type = SDB_LEGACY;
|
||||
sdb->sdb_flags = flags;
|
||||
sdb->private = lgdb_p;
|
||||
sdb->sdb_FindObjectsInit = lg_FindObjectsInit;
|
||||
sdb->sdb_FindObjects = lg_FindObjects;
|
||||
sdb->sdb_FindObjectsFinal = lg_FindObjectsFinal;
|
||||
sdb->sdb_GetAttributeValue = lg_GetAttributeValue;
|
||||
sdb->sdb_SetAttributeValue = lg_SetAttributeValue;
|
||||
sdb->sdb_CreateObject = lg_CreateObject;
|
||||
sdb->sdb_DestroyObject = lg_DestroyObject;
|
||||
sdb->sdb_GetPWEntry = lg_GetPWEntry;
|
||||
sdb->sdb_PutPWEntry = lg_PutPWEntry;
|
||||
sdb->sdb_Begin = lg_Begin;
|
||||
sdb->sdb_Commit = lg_Commit;
|
||||
sdb->sdb_Abort = lg_Abort;
|
||||
sdb->sdb_Close = lg_Reset;
|
||||
sdb->sdb_Close = lg_Close;
|
||||
|
||||
|
||||
*pSdb = sdb;
|
||||
return CKR_OK;
|
||||
|
||||
loser:
|
||||
if (sdb) {
|
||||
PORT_Free(sdb);
|
||||
}
|
||||
if (lgdb_p) {
|
||||
if (lgdb_p->dbLock) {
|
||||
PR_DestroyLock(lgdb_p->dbLock);
|
||||
}
|
||||
if (lgdb_p->hashTable) {
|
||||
PL_HashTableDestroy(lgdb_p->hashTable);
|
||||
}
|
||||
PORT_Free(lgdb_p);
|
||||
}
|
||||
return error;
|
||||
|
||||
}
|
||||
|
||||
extern SECStatus secoid_Init(void); /* util *REALLY* needs
|
||||
* to be a shared library */
|
||||
/*
|
||||
* OK there are now lots of options here, lets go through them all:
|
||||
*
|
||||
* configdir - base directory where all the cert, key, and module datbases live.
|
||||
* certPrefix - prefix added to the beginning of the cert database example: "
|
||||
* "https-server1-"
|
||||
* keyPrefix - prefix added to the beginning of the key database example: "
|
||||
* "https-server1-"
|
||||
* secmodName - name of the security module database (usually "secmod.db").
|
||||
* readOnly - Boolean: true if the databases are to be openned read only.
|
||||
* nocertdb - Don't open the cert DB and key DB's, just initialize the
|
||||
* Volatile certdb.
|
||||
* nomoddb - Don't open the security module DB, just initialize the
|
||||
* PKCS #11 module.
|
||||
* forceOpen - Continue to force initializations even if the databases cannot
|
||||
* be opened.
|
||||
*/
|
||||
CK_RV
|
||||
legacy_Open(const char *configdir, const char *certPrefix,
|
||||
const char *keyPrefix, int certVersion, int keyVersion,
|
||||
int flags, SDB **certDB, SDB **keyDB)
|
||||
{
|
||||
CK_RV crv = CKR_OK;
|
||||
PRBool readOnly = (flags == SDB_RDONLY)? PR_TRUE: PR_FALSE;
|
||||
|
||||
secoid_Init();
|
||||
nsslowcert_InitLocks();
|
||||
|
||||
if (keyDB) *keyDB = NULL;
|
||||
if (certDB) *certDB = NULL;
|
||||
|
||||
if (certDB) {
|
||||
NSSLOWCERTCertDBHandle *certdbPtr;
|
||||
|
||||
crv = lg_OpenCertDB(configdir, certPrefix, readOnly, &certdbPtr);
|
||||
if (crv != CKR_OK) {
|
||||
goto loser;
|
||||
}
|
||||
crv = lg_init(certDB, flags, certdbPtr, NULL);
|
||||
if (crv != CKR_OK) {
|
||||
nsslowcert_ClosePermCertDB(certdbPtr);
|
||||
goto loser;
|
||||
}
|
||||
}
|
||||
if (keyDB) {
|
||||
NSSLOWKEYDBHandle *keydbPtr;
|
||||
|
||||
crv = lg_OpenKeyDB(configdir, keyPrefix, readOnly, &keydbPtr);
|
||||
if (crv != CKR_OK) {
|
||||
goto loser;
|
||||
}
|
||||
crv = lg_init(keyDB, flags, NULL, keydbPtr);
|
||||
if (crv != CKR_OK) {
|
||||
nsslowkey_CloseKeyDB(keydbPtr);
|
||||
goto loser;
|
||||
}
|
||||
if (certDB && *certDB) {
|
||||
LGPrivate *lgdb_p = (LGPrivate *)(*certDB)->private;
|
||||
lgdb_p->keyDB = keydbPtr;
|
||||
}
|
||||
}
|
||||
|
||||
loser:
|
||||
if (crv != CKR_OK) {
|
||||
if (keyDB && *keyDB) {
|
||||
lg_Close(*keyDB);
|
||||
*keyDB = NULL;
|
||||
}
|
||||
if (certDB && *certDB) {
|
||||
lg_Close(*certDB);
|
||||
*certDB = NULL;
|
||||
}
|
||||
}
|
||||
return crv;
|
||||
}
|
||||
|
||||
CK_RV
|
||||
legacy_Shutdown(void)
|
||||
{
|
||||
nsslowcert_DestroyFreeLists();
|
||||
nsslowcert_DestroyGlobalLocks();
|
||||
}
|
||||
@@ -1,424 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "lgdb.h"
|
||||
#include "secerr.h"
|
||||
#include "lgglue.h"
|
||||
|
||||
/*
|
||||
* ******************** Attribute Utilities *******************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* look up and attribute structure from a type and Object structure.
|
||||
* The returned attribute is referenced and needs to be freed when
|
||||
* it is no longer needed.
|
||||
*/
|
||||
const CK_ATTRIBUTE *
|
||||
lg_FindAttribute(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ,
|
||||
CK_ULONG count )
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < count; i++) {
|
||||
if (templ[i].type == type) {
|
||||
return &templ[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* return true if object has attribute
|
||||
*/
|
||||
PRBool
|
||||
lg_hasAttribute(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ,
|
||||
CK_ULONG count )
|
||||
{
|
||||
if (lg_FindAttribute(type, templ, count) == NULL) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* copy an attribute into a SECItem. Secitem is allocated in the specified
|
||||
* arena.
|
||||
*/
|
||||
CK_RV
|
||||
lg_Attribute2SecItem(PLArenaPool *arena, CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
SECItem *item)
|
||||
{
|
||||
int len;
|
||||
const CK_ATTRIBUTE *attribute;
|
||||
|
||||
attribute = lg_FindAttribute(type, templ, count);
|
||||
if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
|
||||
len = attribute->ulValueLen;
|
||||
|
||||
if (arena) {
|
||||
item->data = (unsigned char *) PORT_ArenaAlloc(arena,len);
|
||||
} else {
|
||||
item->data = (unsigned char *) PORT_Alloc(len);
|
||||
}
|
||||
if (item->data == NULL) {
|
||||
return CKR_HOST_MEMORY;
|
||||
}
|
||||
item->len = len;
|
||||
PORT_Memcpy(item->data, attribute->pValue, len);
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* copy an unsigned attribute into a SECItem. Secitem is allocated in
|
||||
* the specified arena.
|
||||
*/
|
||||
CK_RV
|
||||
lg_Attribute2SSecItem(PLArenaPool *arena, CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
SECItem *item)
|
||||
{
|
||||
const CK_ATTRIBUTE *attribute;
|
||||
item->data = NULL;
|
||||
|
||||
attribute = lg_FindAttribute(type, templ, count);
|
||||
if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
|
||||
|
||||
(void)SECITEM_AllocItem(arena, item, attribute->ulValueLen);
|
||||
if (item->data == NULL) {
|
||||
return CKR_HOST_MEMORY;
|
||||
}
|
||||
PORT_Memcpy(item->data, attribute->pValue, item->len);
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* copy an unsigned attribute into a SECItem. Secitem is allocated in
|
||||
* the specified arena.
|
||||
*/
|
||||
CK_RV
|
||||
lg_PrivAttr2SSecItem(PLArenaPool *arena, CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
SECItem *item, SDB *sdbpw)
|
||||
{
|
||||
const CK_ATTRIBUTE *attribute;
|
||||
SECItem epki, *dest = NULL;
|
||||
SECStatus rv;
|
||||
|
||||
item->data = NULL;
|
||||
|
||||
attribute = lg_FindAttribute(type, templ, count);
|
||||
if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
|
||||
|
||||
epki.data = attribute->pValue;
|
||||
epki.len = attribute->ulValueLen;
|
||||
|
||||
rv = lg_util_decrypt(sdbpw, &epki, &dest);
|
||||
if (rv != SECSuccess) {
|
||||
return CKR_USER_NOT_LOGGED_IN;
|
||||
}
|
||||
(void)SECITEM_AllocItem(arena, item, dest->len);
|
||||
if (item->data == NULL) {
|
||||
SECITEM_FreeItem(dest, PR_TRUE);
|
||||
return CKR_HOST_MEMORY;
|
||||
}
|
||||
|
||||
PORT_Memcpy(item->data, dest->data, item->len);
|
||||
SECITEM_FreeItem(dest, PR_TRUE);
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
CK_RV
|
||||
lg_PrivAttr2SecItem(PLArenaPool *arena, CK_ATTRIBUTE_TYPE type,
|
||||
const CK_ATTRIBUTE *templ, CK_ULONG count,
|
||||
SECItem *item, SDB *sdbpw)
|
||||
{
|
||||
return lg_PrivAttr2SSecItem(arena, type, templ, count, item, sdbpw);
|
||||
}
|
||||
|
||||
/*
|
||||
* this is only valid for CK_BBOOL type attributes. Return the state
|
||||
* of that attribute.
|
||||
*/
|
||||
PRBool
|
||||
lg_isTrue(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
const CK_ATTRIBUTE *attribute;
|
||||
PRBool tok = PR_FALSE;
|
||||
|
||||
attribute=lg_FindAttribute(type, templ, count);
|
||||
if (attribute == NULL) { return PR_FALSE; }
|
||||
tok = (PRBool)(*(CK_BBOOL *)attribute->pValue);
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
/*
|
||||
* return a null terminated string from attribute 'type'. This string
|
||||
* is allocated and needs to be freed with PORT_Free() When complete.
|
||||
*/
|
||||
char *
|
||||
lg_getString(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ, CK_ULONG count)
|
||||
{
|
||||
const CK_ATTRIBUTE *attribute;
|
||||
char *label = NULL;
|
||||
|
||||
attribute = lg_FindAttribute(type, templ, count);
|
||||
if (attribute == NULL) return NULL;
|
||||
|
||||
if (attribute->pValue != NULL) {
|
||||
label = (char *) PORT_Alloc(attribute->ulValueLen+1);
|
||||
if (label == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PORT_Memcpy(label,attribute->pValue, attribute->ulValueLen);
|
||||
label[attribute->ulValueLen] = 0;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
CK_RV
|
||||
lg_GetULongAttribute(CK_ATTRIBUTE_TYPE type, const CK_ATTRIBUTE *templ,
|
||||
CK_ULONG count, CK_ULONG *longData)
|
||||
{
|
||||
const CK_ATTRIBUTE *attribute;
|
||||
CK_ULONG value = 0;
|
||||
const unsigned char *data;
|
||||
int i;
|
||||
|
||||
attribute = lg_FindAttribute(type, templ, count);
|
||||
if (attribute == NULL) return CKR_TEMPLATE_INCOMPLETE;
|
||||
|
||||
if (attribute->ulValueLen != sizeof(CK_ULONG)) {
|
||||
return CKR_ATTRIBUTE_VALUE_INVALID;
|
||||
}
|
||||
data = (const unsigned char *)attribute->pValue;
|
||||
for (i=0; i < 4; i++) {
|
||||
value |= (CK_ULONG)(data[i]) << ((3-i)*8);
|
||||
}
|
||||
|
||||
*longData = value;
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* ******************** Object Utilities *******************************
|
||||
*/
|
||||
|
||||
SECStatus
|
||||
lg_deleteTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle)
|
||||
{
|
||||
SECItem *item;
|
||||
PRBool rem;
|
||||
PLHashTable *hashTable= lg_GetHashTable(sdb);
|
||||
|
||||
item = (SECItem *)PL_HashTableLookup(hashTable, (void *)handle);
|
||||
rem = PL_HashTableRemove(hashTable,(void *)handle) ;
|
||||
if (rem && item) {
|
||||
SECITEM_FreeItem(item,PR_TRUE);
|
||||
}
|
||||
return rem ? SECSuccess : SECFailure;
|
||||
}
|
||||
|
||||
/* must be called holding lg_DBLock(sdb) */
|
||||
static SECStatus
|
||||
lg_addTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle, SECItem *key)
|
||||
{
|
||||
PLHashEntry *entry;
|
||||
SECItem *item;
|
||||
PLHashTable *hashTable= lg_GetHashTable(sdb);
|
||||
|
||||
item = SECITEM_DupItem(key);
|
||||
if (item == NULL) {
|
||||
return SECFailure;
|
||||
}
|
||||
entry = PL_HashTableAdd(hashTable,(void *)handle,item);
|
||||
if (entry == NULL) {
|
||||
SECITEM_FreeItem(item,PR_TRUE);
|
||||
return SECFailure;
|
||||
}
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
/* must be called holding lg_DBLock(sdb) */
|
||||
const SECItem *
|
||||
lg_lookupTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle)
|
||||
{
|
||||
PLHashTable *hashTable= lg_GetHashTable(sdb);
|
||||
return (const SECItem *)PL_HashTableLookup(hashTable, (void *)handle);
|
||||
}
|
||||
|
||||
|
||||
static PRIntn
|
||||
lg_freeHashItem(PLHashEntry* entry, PRIntn index, void *arg)
|
||||
{
|
||||
SECItem *item = (SECItem *)entry->value;
|
||||
|
||||
SECITEM_FreeItem(item, PR_TRUE);
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
|
||||
CK_RV
|
||||
LG_ClearTokenKeyHashTable(SDB *sdb)
|
||||
{
|
||||
PLHashTable *hashTable;
|
||||
lg_DBLock(sdb);
|
||||
hashTable= lg_GetHashTable(sdb);
|
||||
PL_HashTableEnumerateEntries(hashTable, lg_freeHashItem, NULL);
|
||||
lg_DBLock(sdb);
|
||||
return CKR_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* handle Token Object stuff
|
||||
*/
|
||||
static void
|
||||
lg_XORHash(unsigned char *key, unsigned char *dbkey, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
PORT_Memset(key, 0, 4);
|
||||
|
||||
for (i=0; i < len-4; i += 4) {
|
||||
key[0] ^= dbkey[i];
|
||||
key[1] ^= dbkey[i+1];
|
||||
key[2] ^= dbkey[i+2];
|
||||
key[3] ^= dbkey[i+3];
|
||||
}
|
||||
}
|
||||
|
||||
/* Make a token handle for an object and record it so we can find it again */
|
||||
CK_OBJECT_HANDLE
|
||||
lg_mkHandle(SDB *sdb, SECItem *dbKey, CK_OBJECT_HANDLE class)
|
||||
{
|
||||
unsigned char hashBuf[4];
|
||||
CK_OBJECT_HANDLE handle;
|
||||
const SECItem *key;
|
||||
|
||||
handle = class;
|
||||
/* there is only one KRL, use a fixed handle for it */
|
||||
if (handle != LG_TOKEN_KRL_HANDLE) {
|
||||
lg_XORHash(hashBuf,dbKey->data,dbKey->len);
|
||||
handle = (hashBuf[0] << 24) | (hashBuf[1] << 16) |
|
||||
(hashBuf[2] << 8) | hashBuf[3];
|
||||
handle = class | (handle & ~(LG_TOKEN_TYPE_MASK|LG_TOKEN_MASK));
|
||||
/* we have a CRL who's handle has randomly matched the reserved KRL
|
||||
* handle, increment it */
|
||||
if (handle == LG_TOKEN_KRL_HANDLE) {
|
||||
handle++;
|
||||
}
|
||||
}
|
||||
|
||||
lg_DBLock(sdb);
|
||||
while ((key = lg_lookupTokenKeyByHandle(sdb,handle)) != NULL) {
|
||||
if (SECITEM_ItemsAreEqual(key,dbKey)) {
|
||||
lg_DBUnlock(sdb);
|
||||
return handle;
|
||||
}
|
||||
handle++;
|
||||
}
|
||||
lg_addTokenKeyByHandle(sdb,handle,dbKey);
|
||||
lg_DBUnlock(sdb);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PRBool
|
||||
lg_poisonHandle(SDB *sdb, SECItem *dbKey, CK_OBJECT_HANDLE class)
|
||||
{
|
||||
unsigned char hashBuf[4];
|
||||
CK_OBJECT_HANDLE handle;
|
||||
const SECItem *key;
|
||||
|
||||
handle = class;
|
||||
/* there is only one KRL, use a fixed handle for it */
|
||||
if (handle != LG_TOKEN_KRL_HANDLE) {
|
||||
lg_XORHash(hashBuf,dbKey->data,dbKey->len);
|
||||
handle = (hashBuf[0] << 24) | (hashBuf[1] << 16) |
|
||||
(hashBuf[2] << 8) | hashBuf[3];
|
||||
handle = class | (handle & ~(LG_TOKEN_TYPE_MASK|LG_TOKEN_MASK));
|
||||
/* we have a CRL who's handle has randomly matched the reserved KRL
|
||||
* handle, increment it */
|
||||
if (handle == LG_TOKEN_KRL_HANDLE) {
|
||||
handle++;
|
||||
}
|
||||
}
|
||||
lg_DBLock(sdb);
|
||||
while ((key = lg_lookupTokenKeyByHandle(sdb,handle)) != NULL) {
|
||||
if (SECITEM_ItemsAreEqual(key,dbKey)) {
|
||||
key->data[0] ^= 0x80;
|
||||
lg_DBUnlock(sdb);
|
||||
return PR_TRUE;
|
||||
}
|
||||
handle++;
|
||||
}
|
||||
lg_DBUnlock(sdb);
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
static LGEncryptFunc lg_encrypt_stub = NULL;
|
||||
static LGDecryptFunc lg_decrypt_stub = NULL;
|
||||
|
||||
void
|
||||
legacy_SetCryptFunctions(LGEncryptFunc enc, LGDecryptFunc dec)
|
||||
{
|
||||
lg_encrypt_stub = enc;
|
||||
lg_decrypt_stub = dec;
|
||||
}
|
||||
|
||||
SECStatus lg_util_encrypt(PLArenaPool *arena, SDB *sdb,
|
||||
SECItem *plainText, SECItem **cipherText)
|
||||
{
|
||||
if (lg_encrypt_stub == NULL) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
return (*lg_encrypt_stub)(arena, sdb, plainText, cipherText);
|
||||
}
|
||||
|
||||
SECStatus lg_util_decrypt(SDB *sdb, SECItem *cipherText, SECItem **plainText)
|
||||
{
|
||||
if (lg_decrypt_stub == NULL) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
return (*lg_decrypt_stub)(sdb, cipherText, plainText);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,824 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
* Certificate handling code
|
||||
*
|
||||
* $Id: lowcert.c,v 1.1.2.2 2007-05-15 21:59:52 rrelyea%redhat.com Exp $
|
||||
*/
|
||||
|
||||
#include "seccomon.h"
|
||||
#include "secder.h"
|
||||
#include "nssilock.h"
|
||||
#include "lowkeyi.h"
|
||||
#include "secasn1.h"
|
||||
#include "secoid.h"
|
||||
#include "secerr.h"
|
||||
#include "pcert.h"
|
||||
|
||||
static const SEC_ASN1Template nsslowcert_SubjectPublicKeyInfoTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWCERTSubjectPublicKeyInfo) },
|
||||
{ SEC_ASN1_INLINE, offsetof(NSSLOWCERTSubjectPublicKeyInfo,algorithm),
|
||||
SECOID_AlgorithmIDTemplate },
|
||||
{ SEC_ASN1_BIT_STRING,
|
||||
offsetof(NSSLOWCERTSubjectPublicKeyInfo,subjectPublicKey), },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
static const SEC_ASN1Template nsslowcert_RSAPublicKeyTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPublicKey) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPublicKey,u.rsa.modulus), },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPublicKey,u.rsa.publicExponent), },
|
||||
{ 0, }
|
||||
};
|
||||
static const SEC_ASN1Template nsslowcert_DSAPublicKeyTemplate[] = {
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPublicKey,u.dsa.publicValue), },
|
||||
{ 0, }
|
||||
};
|
||||
static const SEC_ASN1Template nsslowcert_DHPublicKeyTemplate[] = {
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPublicKey,u.dh.publicValue), },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
/*
|
||||
* See bugzilla bug 125359
|
||||
* Since NSS (via PKCS#11) wants to handle big integers as unsigned ints,
|
||||
* all of the templates above that en/decode into integers must be converted
|
||||
* from ASN.1's signed integer type. This is done by marking either the
|
||||
* source or destination (encoding or decoding, respectively) type as
|
||||
* siUnsignedInteger.
|
||||
*/
|
||||
|
||||
static void
|
||||
prepare_low_rsa_pub_key_for_asn1(NSSLOWKEYPublicKey *pubk)
|
||||
{
|
||||
pubk->u.rsa.modulus.type = siUnsignedInteger;
|
||||
pubk->u.rsa.publicExponent.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
static void
|
||||
prepare_low_dsa_pub_key_for_asn1(NSSLOWKEYPublicKey *pubk)
|
||||
{
|
||||
pubk->u.dsa.publicValue.type = siUnsignedInteger;
|
||||
pubk->u.dsa.params.prime.type = siUnsignedInteger;
|
||||
pubk->u.dsa.params.subPrime.type = siUnsignedInteger;
|
||||
pubk->u.dsa.params.base.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
static void
|
||||
prepare_low_dh_pub_key_for_asn1(NSSLOWKEYPublicKey *pubk)
|
||||
{
|
||||
pubk->u.dh.prime.type = siUnsignedInteger;
|
||||
pubk->u.dh.base.type = siUnsignedInteger;
|
||||
pubk->u.dh.publicValue.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
/*
|
||||
* simple cert decoder to avoid the cost of asn1 engine
|
||||
*/
|
||||
static unsigned char *
|
||||
nsslowcert_dataStart(unsigned char *buf, unsigned int length,
|
||||
unsigned int *data_length, PRBool includeTag,
|
||||
unsigned char* rettag) {
|
||||
unsigned char tag;
|
||||
unsigned int used_length= 0;
|
||||
|
||||
tag = buf[used_length++];
|
||||
|
||||
if (rettag) {
|
||||
*rettag = tag;
|
||||
}
|
||||
|
||||
/* blow out when we come to the end */
|
||||
if (tag == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*data_length = buf[used_length++];
|
||||
|
||||
if (*data_length&0x80) {
|
||||
int len_count = *data_length & 0x7f;
|
||||
|
||||
*data_length = 0;
|
||||
|
||||
while (len_count-- > 0) {
|
||||
*data_length = (*data_length << 8) | buf[used_length++];
|
||||
}
|
||||
}
|
||||
|
||||
if (*data_length > (length-used_length) ) {
|
||||
*data_length = length-used_length;
|
||||
return NULL;
|
||||
}
|
||||
if (includeTag) *data_length += used_length;
|
||||
|
||||
return (buf + (includeTag ? 0 : used_length));
|
||||
}
|
||||
|
||||
static void SetTimeType(SECItem* item, unsigned char tagtype)
|
||||
{
|
||||
switch (tagtype) {
|
||||
case SEC_ASN1_UTC_TIME:
|
||||
item->type = siUTCTime;
|
||||
break;
|
||||
|
||||
case SEC_ASN1_GENERALIZED_TIME:
|
||||
item->type = siGeneralizedTime;
|
||||
break;
|
||||
|
||||
default:
|
||||
PORT_Assert(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
nsslowcert_GetValidityFields(unsigned char *buf,int buf_length,
|
||||
SECItem *notBefore, SECItem *notAfter)
|
||||
{
|
||||
unsigned char tagtype;
|
||||
notBefore->data = nsslowcert_dataStart(buf,buf_length,
|
||||
¬Before->len,PR_FALSE, &tagtype);
|
||||
if (notBefore->data == NULL) return SECFailure;
|
||||
SetTimeType(notBefore, tagtype);
|
||||
buf_length -= (notBefore->data-buf) + notBefore->len;
|
||||
buf = notBefore->data + notBefore->len;
|
||||
notAfter->data = nsslowcert_dataStart(buf,buf_length,
|
||||
¬After->len,PR_FALSE, &tagtype);
|
||||
if (notAfter->data == NULL) return SECFailure;
|
||||
SetTimeType(notAfter, tagtype);
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
static int
|
||||
nsslowcert_GetCertFields(unsigned char *cert,int cert_length,
|
||||
SECItem *issuer, SECItem *serial, SECItem *derSN, SECItem *subject,
|
||||
SECItem *valid, SECItem *subjkey, SECItem *extensions)
|
||||
{
|
||||
unsigned char *buf;
|
||||
unsigned int buf_length;
|
||||
unsigned char *dummy;
|
||||
unsigned int dummylen;
|
||||
|
||||
/* get past the signature wrap */
|
||||
buf = nsslowcert_dataStart(cert,cert_length,&buf_length,PR_FALSE, NULL);
|
||||
if (buf == NULL) return SECFailure;
|
||||
/* get into the raw cert data */
|
||||
buf = nsslowcert_dataStart(buf,buf_length,&buf_length,PR_FALSE, NULL);
|
||||
if (buf == NULL) return SECFailure;
|
||||
/* skip past any optional version number */
|
||||
if ((buf[0] & 0xa0) == 0xa0) {
|
||||
dummy = nsslowcert_dataStart(buf,buf_length,&dummylen,PR_FALSE, NULL);
|
||||
if (dummy == NULL) return SECFailure;
|
||||
buf_length -= (dummy-buf) + dummylen;
|
||||
buf = dummy + dummylen;
|
||||
}
|
||||
/* serial number */
|
||||
if (derSN) {
|
||||
derSN->data=nsslowcert_dataStart(buf,buf_length,&derSN->len,PR_TRUE, NULL);
|
||||
}
|
||||
serial->data = nsslowcert_dataStart(buf,buf_length,&serial->len,PR_FALSE, NULL);
|
||||
if (serial->data == NULL) return SECFailure;
|
||||
buf_length -= (serial->data-buf) + serial->len;
|
||||
buf = serial->data + serial->len;
|
||||
/* skip the OID */
|
||||
dummy = nsslowcert_dataStart(buf,buf_length,&dummylen,PR_FALSE, NULL);
|
||||
if (dummy == NULL) return SECFailure;
|
||||
buf_length -= (dummy-buf) + dummylen;
|
||||
buf = dummy + dummylen;
|
||||
/* issuer */
|
||||
issuer->data = nsslowcert_dataStart(buf,buf_length,&issuer->len,PR_TRUE, NULL);
|
||||
if (issuer->data == NULL) return SECFailure;
|
||||
buf_length -= (issuer->data-buf) + issuer->len;
|
||||
buf = issuer->data + issuer->len;
|
||||
|
||||
/* only wanted issuer/SN */
|
||||
if (valid == NULL) {
|
||||
return SECSuccess;
|
||||
}
|
||||
/* validity */
|
||||
valid->data = nsslowcert_dataStart(buf,buf_length,&valid->len,PR_FALSE, NULL);
|
||||
if (valid->data == NULL) return SECFailure;
|
||||
buf_length -= (valid->data-buf) + valid->len;
|
||||
buf = valid->data + valid->len;
|
||||
/*subject */
|
||||
subject->data=nsslowcert_dataStart(buf,buf_length,&subject->len,PR_TRUE, NULL);
|
||||
if (subject->data == NULL) return SECFailure;
|
||||
buf_length -= (subject->data-buf) + subject->len;
|
||||
buf = subject->data + subject->len;
|
||||
/* subject key info */
|
||||
subjkey->data=nsslowcert_dataStart(buf,buf_length,&subjkey->len,PR_TRUE, NULL);
|
||||
if (subjkey->data == NULL) return SECFailure;
|
||||
buf_length -= (subjkey->data-buf) + subjkey->len;
|
||||
buf = subjkey->data + subjkey->len;
|
||||
|
||||
extensions->data = NULL;
|
||||
extensions->len = 0;
|
||||
while (buf_length > 0) {
|
||||
/* EXTENSIONS */
|
||||
if (buf[0] == 0xa3) {
|
||||
extensions->data = nsslowcert_dataStart(buf,buf_length,
|
||||
&extensions->len, PR_FALSE, NULL);
|
||||
break;
|
||||
}
|
||||
dummy = nsslowcert_dataStart(buf,buf_length,&dummylen,PR_FALSE,NULL);
|
||||
if (dummy == NULL) return SECFailure;
|
||||
buf_length -= (dummy - buf) + dummylen;
|
||||
buf = dummy + dummylen;
|
||||
}
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
static SECStatus
|
||||
nsslowcert_GetCertTimes(NSSLOWCERTCertificate *c, PRTime *notBefore, PRTime *notAfter)
|
||||
{
|
||||
int rv;
|
||||
NSSLOWCERTValidity validity;
|
||||
|
||||
rv = nsslowcert_GetValidityFields(c->validity.data,c->validity.len,
|
||||
&validity.notBefore,&validity.notAfter);
|
||||
if (rv != SECSuccess) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* convert DER not-before time */
|
||||
rv = DER_DecodeTimeChoice(notBefore, &validity.notBefore);
|
||||
if (rv) {
|
||||
return(SECFailure);
|
||||
}
|
||||
|
||||
/* convert DER not-after time */
|
||||
rv = DER_DecodeTimeChoice(notAfter, &validity.notAfter);
|
||||
if (rv) {
|
||||
return(SECFailure);
|
||||
}
|
||||
|
||||
return(SECSuccess);
|
||||
}
|
||||
|
||||
/*
|
||||
* is certa newer than certb? If one is expired, pick the other one.
|
||||
*/
|
||||
PRBool
|
||||
nsslowcert_IsNewer(NSSLOWCERTCertificate *certa, NSSLOWCERTCertificate *certb)
|
||||
{
|
||||
PRTime notBeforeA, notAfterA, notBeforeB, notAfterB, now;
|
||||
SECStatus rv;
|
||||
PRBool newerbefore, newerafter;
|
||||
|
||||
rv = nsslowcert_GetCertTimes(certa, ¬BeforeA, ¬AfterA);
|
||||
if ( rv != SECSuccess ) {
|
||||
return(PR_FALSE);
|
||||
}
|
||||
|
||||
rv = nsslowcert_GetCertTimes(certb, ¬BeforeB, ¬AfterB);
|
||||
if ( rv != SECSuccess ) {
|
||||
return(PR_TRUE);
|
||||
}
|
||||
|
||||
newerbefore = PR_FALSE;
|
||||
if ( LL_CMP(notBeforeA, >, notBeforeB) ) {
|
||||
newerbefore = PR_TRUE;
|
||||
}
|
||||
|
||||
newerafter = PR_FALSE;
|
||||
if ( LL_CMP(notAfterA, >, notAfterB) ) {
|
||||
newerafter = PR_TRUE;
|
||||
}
|
||||
|
||||
if ( newerbefore && newerafter ) {
|
||||
return(PR_TRUE);
|
||||
}
|
||||
|
||||
if ( ( !newerbefore ) && ( !newerafter ) ) {
|
||||
return(PR_FALSE);
|
||||
}
|
||||
|
||||
/* get current time */
|
||||
now = PR_Now();
|
||||
|
||||
if ( newerbefore ) {
|
||||
/* cert A was issued after cert B, but expires sooner */
|
||||
/* if A is expired, then pick B */
|
||||
if ( LL_CMP(notAfterA, <, now ) ) {
|
||||
return(PR_FALSE);
|
||||
}
|
||||
return(PR_TRUE);
|
||||
} else {
|
||||
/* cert B was issued after cert A, but expires sooner */
|
||||
/* if B is expired, then pick A */
|
||||
if ( LL_CMP(notAfterB, <, now ) ) {
|
||||
return(PR_TRUE);
|
||||
}
|
||||
return(PR_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
#define SOFT_DEFAULT_CHUNKSIZE 2048
|
||||
|
||||
static SECStatus
|
||||
nsslowcert_KeyFromIssuerAndSN(PRArenaPool *arena,
|
||||
SECItem *issuer, SECItem *sn, SECItem *key)
|
||||
{
|
||||
unsigned int len = sn->len + issuer->len;
|
||||
|
||||
if (!arena) {
|
||||
PORT_SetError(SEC_ERROR_INVALID_ARGS);
|
||||
goto loser;
|
||||
}
|
||||
key->data = (unsigned char*)PORT_ArenaAlloc(arena, len);
|
||||
if ( !key->data ) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
key->len = len;
|
||||
/* copy the serialNumber */
|
||||
PORT_Memcpy(key->data, sn->data, sn->len);
|
||||
|
||||
/* copy the issuer */
|
||||
PORT_Memcpy(&key->data[sn->len], issuer->data, issuer->len);
|
||||
|
||||
return(SECSuccess);
|
||||
|
||||
loser:
|
||||
return(SECFailure);
|
||||
}
|
||||
|
||||
static SECStatus
|
||||
nsslowcert_KeyFromIssuerAndSNStatic(unsigned char *space,
|
||||
int spaceLen, SECItem *issuer, SECItem *sn, SECItem *key)
|
||||
{
|
||||
unsigned int len = sn->len + issuer->len;
|
||||
|
||||
key->data = pkcs11_allocStaticData(len, space, spaceLen);
|
||||
if ( !key->data ) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
key->len = len;
|
||||
/* copy the serialNumber */
|
||||
PORT_Memcpy(key->data, sn->data, sn->len);
|
||||
|
||||
/* copy the issuer */
|
||||
PORT_Memcpy(&key->data[sn->len], issuer->data, issuer->len);
|
||||
|
||||
return(SECSuccess);
|
||||
|
||||
loser:
|
||||
return(SECFailure);
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
nsslowcert_EmailName(SECItem *derDN, char *space, unsigned int len)
|
||||
{
|
||||
unsigned char *buf;
|
||||
unsigned int buf_length;
|
||||
|
||||
/* unwrap outer sequence */
|
||||
buf=nsslowcert_dataStart(derDN->data,derDN->len,&buf_length,PR_FALSE,NULL);
|
||||
if (buf == NULL) return NULL;
|
||||
|
||||
/* Walk each RDN */
|
||||
while (buf_length > 0) {
|
||||
unsigned char *rdn;
|
||||
unsigned int rdn_length;
|
||||
|
||||
/* grab next rdn */
|
||||
rdn=nsslowcert_dataStart(buf, buf_length, &rdn_length, PR_FALSE, NULL);
|
||||
if (rdn == NULL) { return NULL; }
|
||||
buf_length -= (rdn - buf) + rdn_length;
|
||||
buf = rdn+rdn_length;
|
||||
|
||||
while (rdn_length > 0) {
|
||||
unsigned char *ava;
|
||||
unsigned int ava_length;
|
||||
unsigned char *oid;
|
||||
unsigned int oid_length;
|
||||
unsigned char *name;
|
||||
unsigned int name_length;
|
||||
SECItem oidItem;
|
||||
SECOidTag type;
|
||||
|
||||
/* unwrap the ava */
|
||||
ava=nsslowcert_dataStart(rdn, rdn_length, &ava_length, PR_FALSE,
|
||||
NULL);
|
||||
if (ava == NULL) return NULL;
|
||||
rdn_length -= (ava-rdn)+ava_length;
|
||||
rdn = ava + ava_length;
|
||||
|
||||
oid=nsslowcert_dataStart(ava, ava_length, &oid_length, PR_FALSE,
|
||||
NULL);
|
||||
if (oid == NULL) { return NULL; }
|
||||
ava_length -= (oid-ava)+oid_length;
|
||||
ava = oid+oid_length;
|
||||
|
||||
name=nsslowcert_dataStart(ava, ava_length, &name_length, PR_FALSE,
|
||||
NULL);
|
||||
if (oid == NULL) { return NULL; }
|
||||
ava_length -= (name-ava)+name_length;
|
||||
ava = name+name_length;
|
||||
|
||||
oidItem.data = oid;
|
||||
oidItem.len = oid_length;
|
||||
type = SECOID_FindOIDTag(&oidItem);
|
||||
if ((type == SEC_OID_PKCS9_EMAIL_ADDRESS) ||
|
||||
(type == SEC_OID_RFC1274_MAIL)) {
|
||||
/* Email is supposed to be IA5String, so no
|
||||
* translation necessary */
|
||||
char *emailAddr;
|
||||
emailAddr = (char *)pkcs11_copyStaticData(name,name_length+1,
|
||||
(unsigned char *)space,len);
|
||||
if (emailAddr) {
|
||||
emailAddr[name_length] = 0;
|
||||
}
|
||||
return emailAddr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *
|
||||
nsslowcert_EmailAltName(NSSLOWCERTCertificate *cert, char *space,
|
||||
unsigned int len)
|
||||
{
|
||||
unsigned char *exts;
|
||||
unsigned int exts_length;
|
||||
|
||||
/* unwrap the sequence */
|
||||
exts = nsslowcert_dataStart(cert->extensions.data, cert->extensions.len,
|
||||
&exts_length, PR_FALSE, NULL);
|
||||
/* loop through extension */
|
||||
while (exts && exts_length > 0) {
|
||||
unsigned char * ext;
|
||||
unsigned int ext_length;
|
||||
unsigned char *oid;
|
||||
unsigned int oid_length;
|
||||
unsigned char *nameList;
|
||||
unsigned int nameList_length;
|
||||
SECItem oidItem;
|
||||
SECOidTag type;
|
||||
|
||||
ext = nsslowcert_dataStart(exts, exts_length, &ext_length,
|
||||
PR_FALSE, NULL);
|
||||
if (ext == NULL) { break; }
|
||||
exts_length -= (ext - exts) + ext_length;
|
||||
exts = ext+ext_length;
|
||||
|
||||
oid=nsslowcert_dataStart(ext, ext_length, &oid_length, PR_FALSE, NULL);
|
||||
if (oid == NULL) { break; }
|
||||
ext_length -= (oid - ext) + oid_length;
|
||||
ext = oid+oid_length;
|
||||
oidItem.data = oid;
|
||||
oidItem.len = oid_length;
|
||||
type = SECOID_FindOIDTag(&oidItem);
|
||||
|
||||
/* get Alt Extension */
|
||||
if (type != SEC_OID_X509_SUBJECT_ALT_NAME) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip passed the critical flag */
|
||||
if (ext[0] == 0x01) { /* BOOLEAN */
|
||||
unsigned char *dummy;
|
||||
unsigned int dummy_length;
|
||||
dummy = nsslowcert_dataStart(ext, ext_length, &dummy_length,
|
||||
PR_FALSE, NULL);
|
||||
if (dummy == NULL) { break; }
|
||||
ext_length -= (dummy - ext) + dummy_length;
|
||||
ext = dummy+dummy_length;
|
||||
}
|
||||
|
||||
|
||||
/* unwrap the name list */
|
||||
nameList = nsslowcert_dataStart(ext, ext_length, &nameList_length,
|
||||
PR_FALSE, NULL);
|
||||
if (nameList == NULL) { break; }
|
||||
ext_length -= (nameList - ext) + nameList_length;
|
||||
ext = nameList+nameList_length;
|
||||
nameList = nsslowcert_dataStart(nameList, nameList_length,
|
||||
&nameList_length, PR_FALSE, NULL);
|
||||
/* loop through the name list */
|
||||
while (nameList && nameList_length > 0) {
|
||||
unsigned char *thisName;
|
||||
unsigned int thisName_length;
|
||||
|
||||
thisName = nsslowcert_dataStart(nameList, nameList_length,
|
||||
&thisName_length, PR_FALSE, NULL);
|
||||
if (thisName == NULL) { break; }
|
||||
if (nameList[0] == 0xa2) { /* DNS Name */
|
||||
SECItem dn;
|
||||
char *emailAddr;
|
||||
|
||||
dn.data = thisName;
|
||||
dn.len = thisName_length;
|
||||
emailAddr = nsslowcert_EmailName(&dn, space, len);
|
||||
if (emailAddr) {
|
||||
return emailAddr;
|
||||
}
|
||||
}
|
||||
if (nameList[0] == 0x81) { /* RFC 822name */
|
||||
char *emailAddr;
|
||||
emailAddr = (char *)pkcs11_copyStaticData(thisName,
|
||||
thisName_length+1, (unsigned char *)space,len);
|
||||
if (emailAddr) {
|
||||
emailAddr[thisName_length] = 0;
|
||||
}
|
||||
return emailAddr;
|
||||
}
|
||||
nameList_length -= (thisName-nameList) + thisName_length;
|
||||
nameList = thisName + thisName_length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *
|
||||
nsslowcert_GetCertificateEmailAddress(NSSLOWCERTCertificate *cert)
|
||||
{
|
||||
char *emailAddr = NULL;
|
||||
char *str;
|
||||
|
||||
emailAddr = nsslowcert_EmailName(&cert->derSubject,cert->emailAddrSpace,
|
||||
sizeof(cert->emailAddrSpace));
|
||||
/* couldn't find the email address in the DN, check the subject Alt name */
|
||||
if (!emailAddr && cert->extensions.data) {
|
||||
emailAddr = nsslowcert_EmailAltName(cert, cert->emailAddrSpace,
|
||||
sizeof(cert->emailAddrSpace));
|
||||
}
|
||||
|
||||
|
||||
/* make it lower case */
|
||||
str = emailAddr;
|
||||
while ( str && *str ) {
|
||||
*str = tolower( *str );
|
||||
str++;
|
||||
}
|
||||
return emailAddr;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* take a DER certificate and decode it into a certificate structure
|
||||
*/
|
||||
NSSLOWCERTCertificate *
|
||||
nsslowcert_DecodeDERCertificate(SECItem *derSignedCert, char *nickname)
|
||||
{
|
||||
NSSLOWCERTCertificate *cert;
|
||||
int rv;
|
||||
|
||||
/* allocate the certificate structure */
|
||||
cert = nsslowcert_CreateCert();
|
||||
|
||||
if ( !cert ) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* point to passed in DER data */
|
||||
cert->derCert = *derSignedCert;
|
||||
cert->nickname = NULL;
|
||||
cert->certKey.data = NULL;
|
||||
cert->referenceCount = 1;
|
||||
|
||||
/* decode the certificate info */
|
||||
rv = nsslowcert_GetCertFields(cert->derCert.data, cert->derCert.len,
|
||||
&cert->derIssuer, &cert->serialNumber, &cert->derSN, &cert->derSubject,
|
||||
&cert->validity, &cert->derSubjKeyInfo, &cert->extensions);
|
||||
|
||||
/* cert->subjectKeyID; x509v3 subject key identifier */
|
||||
cert->subjectKeyID.data = NULL;
|
||||
cert->subjectKeyID.len = 0;
|
||||
cert->dbEntry = NULL;
|
||||
cert ->trust = NULL;
|
||||
cert ->dbhandle = NULL;
|
||||
|
||||
/* generate and save the database key for the cert */
|
||||
rv = nsslowcert_KeyFromIssuerAndSNStatic(cert->certKeySpace,
|
||||
sizeof(cert->certKeySpace), &cert->derIssuer,
|
||||
&cert->serialNumber, &cert->certKey);
|
||||
if ( rv ) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* set the nickname */
|
||||
if ( nickname == NULL ) {
|
||||
cert->nickname = NULL;
|
||||
} else {
|
||||
/* copy and install the nickname */
|
||||
cert->nickname = pkcs11_copyNickname(nickname,cert->nicknameSpace,
|
||||
sizeof(cert->nicknameSpace));
|
||||
}
|
||||
|
||||
#ifdef FIXME
|
||||
/* initialize the subjectKeyID */
|
||||
rv = cert_GetKeyID(cert);
|
||||
if ( rv != SECSuccess ) {
|
||||
goto loser;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set the email address */
|
||||
cert->emailAddr = nsslowcert_GetCertificateEmailAddress(cert);
|
||||
|
||||
|
||||
cert->referenceCount = 1;
|
||||
|
||||
return(cert);
|
||||
|
||||
loser:
|
||||
if (cert) {
|
||||
nsslowcert_DestroyCertificate(cert);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
char *
|
||||
nsslowcert_FixupEmailAddr(char *emailAddr)
|
||||
{
|
||||
char *retaddr;
|
||||
char *str;
|
||||
|
||||
if ( emailAddr == NULL ) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* copy the string */
|
||||
str = retaddr = PORT_Strdup(emailAddr);
|
||||
if ( str == NULL ) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* make it lower case */
|
||||
while ( *str ) {
|
||||
*str = tolower( *str );
|
||||
str++;
|
||||
}
|
||||
|
||||
return(retaddr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Generate a database key, based on serial number and issuer, from a
|
||||
* DER certificate.
|
||||
*/
|
||||
SECStatus
|
||||
nsslowcert_KeyFromDERCert(PRArenaPool *arena, SECItem *derCert, SECItem *key)
|
||||
{
|
||||
int rv;
|
||||
NSSLOWCERTCertKey certkey;
|
||||
|
||||
PORT_Memset(&certkey, 0, sizeof(NSSLOWCERTCertKey));
|
||||
|
||||
rv = nsslowcert_GetCertFields(derCert->data, derCert->len,
|
||||
&certkey.derIssuer, &certkey.serialNumber, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
if ( rv ) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return(nsslowcert_KeyFromIssuerAndSN(arena, &certkey.derIssuer,
|
||||
&certkey.serialNumber, key));
|
||||
loser:
|
||||
return(SECFailure);
|
||||
}
|
||||
|
||||
NSSLOWKEYPublicKey *
|
||||
nsslowcert_ExtractPublicKey(NSSLOWCERTCertificate *cert)
|
||||
{
|
||||
NSSLOWCERTSubjectPublicKeyInfo spki;
|
||||
NSSLOWKEYPublicKey *pubk;
|
||||
SECItem os;
|
||||
SECStatus rv;
|
||||
PRArenaPool *arena;
|
||||
SECOidTag tag;
|
||||
SECItem newDerSubjKeyInfo;
|
||||
|
||||
arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE);
|
||||
if (arena == NULL)
|
||||
return NULL;
|
||||
|
||||
pubk = (NSSLOWKEYPublicKey *)
|
||||
PORT_ArenaZAlloc(arena, sizeof(NSSLOWKEYPublicKey));
|
||||
if (pubk == NULL) {
|
||||
PORT_FreeArena (arena, PR_FALSE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pubk->arena = arena;
|
||||
PORT_Memset(&spki,0,sizeof(spki));
|
||||
|
||||
/* copy the DER into the arena, since Quick DER returns data that points
|
||||
into the DER input, which may get freed by the caller */
|
||||
rv = SECITEM_CopyItem(arena, &newDerSubjKeyInfo, &cert->derSubjKeyInfo);
|
||||
if ( rv != SECSuccess ) {
|
||||
PORT_FreeArena (arena, PR_FALSE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* we haven't bothered decoding the spki struct yet, do it now */
|
||||
rv = SEC_QuickDERDecodeItem(arena, &spki,
|
||||
nsslowcert_SubjectPublicKeyInfoTemplate, &newDerSubjKeyInfo);
|
||||
if (rv != SECSuccess) {
|
||||
PORT_FreeArena (arena, PR_FALSE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Convert bit string length from bits to bytes */
|
||||
os = spki.subjectPublicKey;
|
||||
DER_ConvertBitString (&os);
|
||||
|
||||
tag = SECOID_GetAlgorithmTag(&spki.algorithm);
|
||||
switch ( tag ) {
|
||||
case SEC_OID_X500_RSA_ENCRYPTION:
|
||||
case SEC_OID_PKCS1_RSA_ENCRYPTION:
|
||||
pubk->keyType = NSSLOWKEYRSAKey;
|
||||
prepare_low_rsa_pub_key_for_asn1(pubk);
|
||||
rv = SEC_QuickDERDecodeItem(arena, pubk,
|
||||
nsslowcert_RSAPublicKeyTemplate, &os);
|
||||
if (rv == SECSuccess)
|
||||
return pubk;
|
||||
break;
|
||||
case SEC_OID_ANSIX9_DSA_SIGNATURE:
|
||||
pubk->keyType = NSSLOWKEYDSAKey;
|
||||
prepare_low_dsa_pub_key_for_asn1(pubk);
|
||||
rv = SEC_QuickDERDecodeItem(arena, pubk,
|
||||
nsslowcert_DSAPublicKeyTemplate, &os);
|
||||
if (rv == SECSuccess) return pubk;
|
||||
break;
|
||||
case SEC_OID_X942_DIFFIE_HELMAN_KEY:
|
||||
pubk->keyType = NSSLOWKEYDHKey;
|
||||
prepare_low_dh_pub_key_for_asn1(pubk);
|
||||
rv = SEC_QuickDERDecodeItem(arena, pubk,
|
||||
nsslowcert_DHPublicKeyTemplate, &os);
|
||||
if (rv == SECSuccess) return pubk;
|
||||
break;
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
case SEC_OID_ANSIX962_EC_PUBLIC_KEY:
|
||||
pubk->keyType = NSSLOWKEYECKey;
|
||||
/* Since PKCS#11 directly takes the DER encoding of EC params
|
||||
* and public value, we don't need any decoding here.
|
||||
*/
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.ec.ecParams.DEREncoding,
|
||||
&spki.algorithm.parameters);
|
||||
if ( rv != SECSuccess )
|
||||
break;
|
||||
|
||||
/* Fill out the rest of the ecParams structure
|
||||
* based on the encoded params
|
||||
*/
|
||||
if (LGEC_FillParams(arena, &pubk->u.ec.ecParams.DEREncoding,
|
||||
&pubk->u.ec.ecParams) != SECSuccess)
|
||||
break;
|
||||
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.ec.publicValue, &os);
|
||||
if (rv == SECSuccess) return pubk;
|
||||
break;
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
default:
|
||||
rv = SECFailure;
|
||||
break;
|
||||
}
|
||||
|
||||
nsslowkey_DestroyPublicKey (pubk);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,462 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "lowkeyi.h"
|
||||
#include "secoid.h"
|
||||
#include "secitem.h"
|
||||
#include "secder.h"
|
||||
#include "secasn1.h"
|
||||
#include "secerr.h"
|
||||
|
||||
static const SEC_ASN1Template nsslowkey_AttributeTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE,
|
||||
0, NULL, sizeof(NSSLOWKEYAttribute) },
|
||||
{ SEC_ASN1_OBJECT_ID, offsetof(NSSLOWKEYAttribute, attrType) },
|
||||
{ SEC_ASN1_SET_OF, offsetof(NSSLOWKEYAttribute, attrValue),
|
||||
SEC_AnyTemplate },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static const SEC_ASN1Template nsslowkey_SetOfAttributeTemplate[] = {
|
||||
{ SEC_ASN1_SET_OF, 0, nsslowkey_AttributeTemplate },
|
||||
};
|
||||
/* ASN1 Templates for new decoder/encoder */
|
||||
const SEC_ASN1Template nsslowkey_PrivateKeyInfoTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE,
|
||||
0, NULL, sizeof(NSSLOWKEYPrivateKeyInfo) },
|
||||
{ SEC_ASN1_INTEGER,
|
||||
offsetof(NSSLOWKEYPrivateKeyInfo,version) },
|
||||
{ SEC_ASN1_INLINE,
|
||||
offsetof(NSSLOWKEYPrivateKeyInfo,algorithm),
|
||||
SECOID_AlgorithmIDTemplate },
|
||||
{ SEC_ASN1_OCTET_STRING,
|
||||
offsetof(NSSLOWKEYPrivateKeyInfo,privateKey) },
|
||||
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
||||
offsetof(NSSLOWKEYPrivateKeyInfo, attributes),
|
||||
nsslowkey_SetOfAttributeTemplate },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
const SEC_ASN1Template nsslowkey_PQGParamsTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(PQGParams) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(PQGParams,prime) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(PQGParams,subPrime) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(PQGParams,base) },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
const SEC_ASN1Template nsslowkey_RSAPrivateKeyTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.version) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.modulus) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.publicExponent) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.privateExponent) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.prime1) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.prime2) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.exponent1) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.exponent2) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.coefficient) },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
|
||||
const SEC_ASN1Template nsslowkey_DSAPrivateKeyTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dsa.publicValue) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dsa.privateValue) },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
const SEC_ASN1Template nsslowkey_DSAPrivateKeyExportTemplate[] = {
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dsa.privateValue) },
|
||||
};
|
||||
|
||||
const SEC_ASN1Template nsslowkey_DHPrivateKeyTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.publicValue) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.privateValue) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.base) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.prime) },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
|
||||
/* XXX This is just a placeholder for later when we support
|
||||
* generic curves and need full-blown support for parsing EC
|
||||
* parameters. For now, we only support named curves in which
|
||||
* EC params are simply encoded as an object ID and we don't
|
||||
* use nsslowkey_ECParamsTemplate.
|
||||
*/
|
||||
const SEC_ASN1Template nsslowkey_ECParamsTemplate[] = {
|
||||
{ SEC_ASN1_CHOICE, offsetof(ECParams,type), NULL, sizeof(ECParams) },
|
||||
{ SEC_ASN1_OBJECT_ID, offsetof(ECParams,curveOID), NULL, ec_params_named },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
|
||||
/* NOTE: The SECG specification allows the private key structure
|
||||
* to contain curve parameters but recommends that they be stored
|
||||
* in the PrivateKeyAlgorithmIdentifier field of the PrivateKeyInfo
|
||||
* instead.
|
||||
*/
|
||||
const SEC_ASN1Template nsslowkey_ECPrivateKeyTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.ec.version) },
|
||||
{ SEC_ASN1_OCTET_STRING,
|
||||
offsetof(NSSLOWKEYPrivateKey,u.ec.privateValue) },
|
||||
/* XXX The following template works for now since we only
|
||||
* support named curves for which the parameters are
|
||||
* encoded as an object ID. When we support generic curves,
|
||||
* we'll need to define nsslowkey_ECParamsTemplate
|
||||
*/
|
||||
#if 1
|
||||
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED |
|
||||
SEC_ASN1_EXPLICIT | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
||||
offsetof(NSSLOWKEYPrivateKey,u.ec.ecParams.curveOID),
|
||||
SEC_ObjectIDTemplate },
|
||||
#else
|
||||
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED |
|
||||
SEC_ASN1_EXPLICIT | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
||||
offsetof(NSSLOWKEYPrivateKey,u.ec.ecParams),
|
||||
nsslowkey_ECParamsTemplate },
|
||||
#endif
|
||||
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED |
|
||||
SEC_ASN1_EXPLICIT | SEC_ASN1_CONTEXT_SPECIFIC | 1,
|
||||
offsetof(NSSLOWKEYPrivateKey,u.ec.publicValue),
|
||||
SEC_BitStringTemplate },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* smaller version of EC_FillParams. In this code, we only need
|
||||
* oid and DER data.
|
||||
*/
|
||||
SECStatus
|
||||
LGEC_FillParams(PRArenaPool *arena, const SECItem *encodedParams,
|
||||
ECParams *params)
|
||||
{
|
||||
SECOidTag tag;
|
||||
SECItem oid = { siBuffer, NULL, 0};
|
||||
|
||||
#if EC_DEBUG
|
||||
int i;
|
||||
|
||||
printf("Encoded params in EC_DecodeParams: ");
|
||||
for (i = 0; i < encodedParams->len; i++) {
|
||||
printf("%02x:", encodedParams->data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
oid.len = encodedParams->len - 2;
|
||||
oid.data = encodedParams->data + 2;
|
||||
if ((encodedParams->data[0] != SEC_ASN1_OBJECT_ID) ||
|
||||
((tag = SECOID_FindOIDTag(&oid)) == SEC_OID_UNKNOWN)) {
|
||||
PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
params->arena = arena;
|
||||
|
||||
/* For named curves, fill out curveOID */
|
||||
params->curveOID.len = oid.len;
|
||||
params->curveOID.data = (unsigned char *) PORT_ArenaAlloc(arena, oid.len);
|
||||
if (params->curveOID.data == NULL) {
|
||||
return SECFailure;
|
||||
}
|
||||
memcpy(params->curveOID.data, oid.data, oid.len);
|
||||
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
/* Copy all of the fields from srcParams into dstParams
|
||||
*/
|
||||
SECStatus
|
||||
LGEC_CopyParams(PRArenaPool *arena, ECParams *dstParams,
|
||||
const ECParams *srcParams)
|
||||
{
|
||||
SECStatus rv = SECFailure;
|
||||
|
||||
dstParams->arena = arena;
|
||||
rv = SECITEM_CopyItem(arena, &dstParams->DEREncoding,
|
||||
&srcParams->DEREncoding);
|
||||
if (rv != SECSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
rv =SECITEM_CopyItem(arena, &dstParams->curveOID,
|
||||
&srcParams->curveOID);
|
||||
if (rv != SECSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
|
||||
return SECSuccess;
|
||||
|
||||
loser:
|
||||
return SECFailure;
|
||||
}
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
/*
|
||||
* See bugzilla bug 125359
|
||||
* Since NSS (via PKCS#11) wants to handle big integers as unsigned ints,
|
||||
* all of the templates above that en/decode into integers must be converted
|
||||
* from ASN.1's signed integer type. This is done by marking either the
|
||||
* source or destination (encoding or decoding, respectively) type as
|
||||
* siUnsignedInteger.
|
||||
*/
|
||||
|
||||
void
|
||||
prepare_low_rsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.rsa.modulus.type = siUnsignedInteger;
|
||||
key->u.rsa.publicExponent.type = siUnsignedInteger;
|
||||
key->u.rsa.privateExponent.type = siUnsignedInteger;
|
||||
key->u.rsa.prime1.type = siUnsignedInteger;
|
||||
key->u.rsa.prime2.type = siUnsignedInteger;
|
||||
key->u.rsa.exponent1.type = siUnsignedInteger;
|
||||
key->u.rsa.exponent2.type = siUnsignedInteger;
|
||||
key->u.rsa.coefficient.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_pqg_params_for_asn1(PQGParams *params)
|
||||
{
|
||||
params->prime.type = siUnsignedInteger;
|
||||
params->subPrime.type = siUnsignedInteger;
|
||||
params->base.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_dsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.dsa.publicValue.type = siUnsignedInteger;
|
||||
key->u.dsa.privateValue.type = siUnsignedInteger;
|
||||
key->u.dsa.params.prime.type = siUnsignedInteger;
|
||||
key->u.dsa.params.subPrime.type = siUnsignedInteger;
|
||||
key->u.dsa.params.base.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_dsa_priv_key_export_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.dsa.privateValue.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_dh_priv_key_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.dh.prime.type = siUnsignedInteger;
|
||||
key->u.dh.base.type = siUnsignedInteger;
|
||||
key->u.dh.publicValue.type = siUnsignedInteger;
|
||||
key->u.dh.privateValue.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
void
|
||||
prepare_low_ecparams_for_asn1(ECParams *params)
|
||||
{
|
||||
params->DEREncoding.type = siUnsignedInteger;
|
||||
params->curveOID.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_ec_priv_key_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.ec.version.type = siUnsignedInteger;
|
||||
key->u.ec.ecParams.DEREncoding.type = siUnsignedInteger;
|
||||
key->u.ec.ecParams.curveOID.type = siUnsignedInteger;
|
||||
key->u.ec.privateValue.type = siUnsignedInteger;
|
||||
key->u.ec.publicValue.type = siUnsignedInteger;
|
||||
}
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
|
||||
void
|
||||
nsslowkey_DestroyPrivateKey(NSSLOWKEYPrivateKey *privk)
|
||||
{
|
||||
if (privk && privk->arena) {
|
||||
PORT_FreeArena(privk->arena, PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsslowkey_DestroyPublicKey(NSSLOWKEYPublicKey *pubk)
|
||||
{
|
||||
if (pubk && pubk->arena) {
|
||||
PORT_FreeArena(pubk->arena, PR_FALSE);
|
||||
}
|
||||
}
|
||||
unsigned
|
||||
nsslowkey_PublicModulusLen(NSSLOWKEYPublicKey *pubk)
|
||||
{
|
||||
unsigned char b0;
|
||||
|
||||
/* interpret modulus length as key strength... in
|
||||
* fortezza that's the public key length */
|
||||
|
||||
switch (pubk->keyType) {
|
||||
case NSSLOWKEYRSAKey:
|
||||
b0 = pubk->u.rsa.modulus.data[0];
|
||||
return b0 ? pubk->u.rsa.modulus.len : pubk->u.rsa.modulus.len - 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned
|
||||
nsslowkey_PrivateModulusLen(NSSLOWKEYPrivateKey *privk)
|
||||
{
|
||||
|
||||
unsigned char b0;
|
||||
|
||||
switch (privk->keyType) {
|
||||
case NSSLOWKEYRSAKey:
|
||||
b0 = privk->u.rsa.modulus.data[0];
|
||||
return b0 ? privk->u.rsa.modulus.len : privk->u.rsa.modulus.len - 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSSLOWKEYPublicKey *
|
||||
nsslowkey_ConvertToPublicKey(NSSLOWKEYPrivateKey *privk)
|
||||
{
|
||||
NSSLOWKEYPublicKey *pubk;
|
||||
PLArenaPool *arena;
|
||||
|
||||
|
||||
arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE);
|
||||
if (arena == NULL) {
|
||||
PORT_SetError (SEC_ERROR_NO_MEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch(privk->keyType) {
|
||||
case NSSLOWKEYRSAKey:
|
||||
case NSSLOWKEYNullKey:
|
||||
pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
|
||||
sizeof (NSSLOWKEYPublicKey));
|
||||
if (pubk != NULL) {
|
||||
SECStatus rv;
|
||||
|
||||
pubk->arena = arena;
|
||||
pubk->keyType = privk->keyType;
|
||||
if (privk->keyType == NSSLOWKEYNullKey) return pubk;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.rsa.modulus,
|
||||
&privk->u.rsa.modulus);
|
||||
if (rv == SECSuccess) {
|
||||
rv = SECITEM_CopyItem (arena, &pubk->u.rsa.publicExponent,
|
||||
&privk->u.rsa.publicExponent);
|
||||
if (rv == SECSuccess)
|
||||
return pubk;
|
||||
}
|
||||
} else {
|
||||
PORT_SetError (SEC_ERROR_NO_MEMORY);
|
||||
}
|
||||
break;
|
||||
case NSSLOWKEYDSAKey:
|
||||
pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
|
||||
sizeof(NSSLOWKEYPublicKey));
|
||||
if (pubk != NULL) {
|
||||
SECStatus rv;
|
||||
|
||||
pubk->arena = arena;
|
||||
pubk->keyType = privk->keyType;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dsa.publicValue,
|
||||
&privk->u.dsa.publicValue);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dsa.params.prime,
|
||||
&privk->u.dsa.params.prime);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dsa.params.subPrime,
|
||||
&privk->u.dsa.params.subPrime);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dsa.params.base,
|
||||
&privk->u.dsa.params.base);
|
||||
if (rv == SECSuccess) return pubk;
|
||||
}
|
||||
break;
|
||||
case NSSLOWKEYDHKey:
|
||||
pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
|
||||
sizeof(NSSLOWKEYPublicKey));
|
||||
if (pubk != NULL) {
|
||||
SECStatus rv;
|
||||
|
||||
pubk->arena = arena;
|
||||
pubk->keyType = privk->keyType;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dh.publicValue,
|
||||
&privk->u.dh.publicValue);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dh.prime,
|
||||
&privk->u.dh.prime);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dh.base,
|
||||
&privk->u.dh.base);
|
||||
if (rv == SECSuccess) return pubk;
|
||||
}
|
||||
break;
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
case NSSLOWKEYECKey:
|
||||
pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
|
||||
sizeof(NSSLOWKEYPublicKey));
|
||||
if (pubk != NULL) {
|
||||
SECStatus rv;
|
||||
|
||||
pubk->arena = arena;
|
||||
pubk->keyType = privk->keyType;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.ec.publicValue,
|
||||
&privk->u.ec.publicValue);
|
||||
if (rv != SECSuccess) break;
|
||||
pubk->u.ec.ecParams.arena = arena;
|
||||
/* Copy the rest of the params */
|
||||
rv = LGEC_CopyParams(arena, &(pubk->u.ec.ecParams),
|
||||
&(privk->u.ec.ecParams));
|
||||
if (rv == SECSuccess) return pubk;
|
||||
}
|
||||
break;
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
/* No Fortezza in Low Key implementations (Fortezza keys aren't
|
||||
* stored in our data base */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
PORT_FreeArena (arena, PR_FALSE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/* $Id: lowkeyi.h,v 1.1.2.1 2007-04-03 22:50:02 rrelyea%redhat.com Exp $ */
|
||||
|
||||
#ifndef _LOWKEYI_H_
|
||||
#define _LOWKEYI_H_
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "seccomon.h"
|
||||
#include "secoidt.h"
|
||||
#include "pcertt.h"
|
||||
#include "lowkeyti.h"
|
||||
#include "sdb.h"
|
||||
|
||||
SEC_BEGIN_PROTOS
|
||||
|
||||
/*
|
||||
* See bugzilla bug 125359
|
||||
* Since NSS (via PKCS#11) wants to handle big integers as unsigned ints,
|
||||
* all of the templates above that en/decode into integers must be converted
|
||||
* from ASN.1's signed integer type. This is done by marking either the
|
||||
* source or destination (encoding or decoding, respectively) type as
|
||||
* siUnsignedInteger.
|
||||
*/
|
||||
extern void prepare_low_rsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
extern void prepare_low_pqg_params_for_asn1(PQGParams *params);
|
||||
extern void prepare_low_dsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
extern void prepare_low_dsa_priv_key_export_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
extern void prepare_low_dh_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
extern void prepare_low_ec_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
extern void prepare_low_ecparams_for_asn1(ECParams *params);
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
|
||||
typedef char * (* NSSLOWKEYDBNameFunc)(void *arg, int dbVersion);
|
||||
|
||||
/*
|
||||
** Open a key database.
|
||||
*/
|
||||
extern NSSLOWKEYDBHandle *nsslowkey_OpenKeyDB(PRBool readOnly,
|
||||
const char *domain,
|
||||
const char *prefix,
|
||||
NSSLOWKEYDBNameFunc namecb,
|
||||
void *cbarg);
|
||||
|
||||
/*
|
||||
** Close the specified key database.
|
||||
*/
|
||||
extern void nsslowkey_CloseKeyDB(NSSLOWKEYDBHandle *handle);
|
||||
|
||||
/*
|
||||
* Get the version number of the database
|
||||
*/
|
||||
extern int nsslowkey_GetKeyDBVersion(NSSLOWKEYDBHandle *handle);
|
||||
|
||||
/*
|
||||
** Delete a key from the database
|
||||
*/
|
||||
extern SECStatus nsslowkey_DeleteKey(NSSLOWKEYDBHandle *handle,
|
||||
const SECItem *pubkey);
|
||||
|
||||
/*
|
||||
** Store a key in the database, indexed by its public key modulus.
|
||||
** "pk" is the private key to store
|
||||
** "f" is a the callback function for getting the password
|
||||
** "arg" is the argument for the callback
|
||||
*/
|
||||
extern SECStatus nsslowkey_StoreKeyByPublicKey(NSSLOWKEYDBHandle *handle,
|
||||
NSSLOWKEYPrivateKey *pk,
|
||||
SECItem *pubKeyData,
|
||||
char *nickname,
|
||||
SDB *sdb);
|
||||
|
||||
/* does the key for this cert exist in the database filed by modulus */
|
||||
extern PRBool nsslowkey_KeyForCertExists(NSSLOWKEYDBHandle *handle,
|
||||
NSSLOWCERTCertificate *cert);
|
||||
/* does a key with this ID already exist? */
|
||||
extern PRBool nsslowkey_KeyForIDExists(NSSLOWKEYDBHandle *handle, SECItem *id);
|
||||
|
||||
/*
|
||||
** Destroy a private key object.
|
||||
** "key" the object
|
||||
** "freeit" if PR_TRUE then free the object as well as its sub-objects
|
||||
*/
|
||||
extern void nsslowkey_DestroyPrivateKey(NSSLOWKEYPrivateKey *key);
|
||||
|
||||
/*
|
||||
** Destroy a public key object.
|
||||
** "key" the object
|
||||
** "freeit" if PR_TRUE then free the object as well as its sub-objects
|
||||
*/
|
||||
extern void nsslowkey_DestroyPublicKey(NSSLOWKEYPublicKey *key);
|
||||
|
||||
/*
|
||||
** Return the modulus length of "pubKey".
|
||||
*/
|
||||
extern unsigned int nsslowkey_PublicModulusLen(NSSLOWKEYPublicKey *pubKey);
|
||||
|
||||
|
||||
/*
|
||||
** Return the modulus length of "privKey".
|
||||
*/
|
||||
extern unsigned int nsslowkey_PrivateModulusLen(NSSLOWKEYPrivateKey *privKey);
|
||||
|
||||
|
||||
/*
|
||||
** Convert a low private key "privateKey" into a public low key
|
||||
*/
|
||||
extern NSSLOWKEYPublicKey
|
||||
*nsslowkey_ConvertToPublicKey(NSSLOWKEYPrivateKey *privateKey);
|
||||
|
||||
|
||||
SECStatus
|
||||
nsslowkey_UpdateNickname(NSSLOWKEYDBHandle *handle,
|
||||
NSSLOWKEYPrivateKey *privkey,
|
||||
SECItem *pubKeyData,
|
||||
char *nickname,
|
||||
SDB *sdb);
|
||||
|
||||
/* Store key by modulus and specify an encryption algorithm to use.
|
||||
* handle is the pointer to the key database,
|
||||
* privkey is the private key to be stored,
|
||||
* f and arg are the function and arguments to the callback
|
||||
* to get a password,
|
||||
* algorithm is the algorithm which the privKey is to be stored.
|
||||
* A return of anything but SECSuccess indicates failure.
|
||||
*/
|
||||
extern SECStatus
|
||||
nsslowkey_StoreKeyByPublicKeyAlg(NSSLOWKEYDBHandle *handle,
|
||||
NSSLOWKEYPrivateKey *privkey,
|
||||
SECItem *pubKeyData,
|
||||
char *nickname,
|
||||
SDB *sdb,
|
||||
PRBool update);
|
||||
|
||||
/* Find key by modulus. This function is the inverse of store key
|
||||
* by modulus. An attempt to locate the key with "modulus" is
|
||||
* performed. If the key is found, the private key is returned,
|
||||
* else NULL is returned.
|
||||
* modulus is the modulus to locate
|
||||
*/
|
||||
extern NSSLOWKEYPrivateKey *
|
||||
nsslowkey_FindKeyByPublicKey(NSSLOWKEYDBHandle *handle, SECItem *modulus,
|
||||
SDB *sdb);
|
||||
|
||||
extern char *
|
||||
nsslowkey_FindKeyNicknameByPublicKey(NSSLOWKEYDBHandle *handle,
|
||||
SECItem *modulus, SDB *sdb);
|
||||
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
/*
|
||||
* smaller version of EC_FillParams. In this code, we only need
|
||||
* oid and DER data.
|
||||
*/
|
||||
SECStatus LGEC_FillParams(PRArenaPool *arena, const SECItem *encodedParams,
|
||||
ECParams *params);
|
||||
|
||||
/* Copy all of the fields from srcParams into dstParams */
|
||||
SECStatus LGEC_CopyParams(PRArenaPool *arena, ECParams *dstParams,
|
||||
const ECParams *srcParams);
|
||||
#endif
|
||||
SEC_END_PROTOS
|
||||
|
||||
#endif /* _LOWKEYI_H_ */
|
||||
@@ -1,161 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef _LOWKEYTI_H_
|
||||
#define _LOWKEYTI_H_ 1
|
||||
|
||||
#include "blapit.h"
|
||||
#include "prtypes.h"
|
||||
#include "plarena.h"
|
||||
#include "secitem.h"
|
||||
#include "secasn1t.h"
|
||||
#include "secoidt.h"
|
||||
|
||||
|
||||
/*
|
||||
* a key in/for the data base
|
||||
*/
|
||||
struct NSSLOWKEYDBKeyStr {
|
||||
PLArenaPool *arena;
|
||||
int version;
|
||||
char *nickname;
|
||||
SECItem salt;
|
||||
SECItem derPK;
|
||||
};
|
||||
typedef struct NSSLOWKEYDBKeyStr NSSLOWKEYDBKey;
|
||||
|
||||
typedef struct NSSLOWKEYDBHandleStr NSSLOWKEYDBHandle;
|
||||
|
||||
#ifdef NSS_USE_KEY4_DB
|
||||
#define NSSLOWKEY_DB_FILE_VERSION 4
|
||||
#else
|
||||
#define NSSLOWKEY_DB_FILE_VERSION 3
|
||||
#endif
|
||||
|
||||
#define NSSLOWKEY_VERSION 0 /* what we *create* */
|
||||
|
||||
/*
|
||||
** Typedef for callback to get a password "key".
|
||||
*/
|
||||
extern const SEC_ASN1Template nsslowkey_PQGParamsTemplate[];
|
||||
extern const SEC_ASN1Template nsslowkey_RSAPrivateKeyTemplate[];
|
||||
extern const SEC_ASN1Template nsslowkey_DSAPrivateKeyTemplate[];
|
||||
extern const SEC_ASN1Template nsslowkey_DSAPrivateKeyExportTemplate[];
|
||||
extern const SEC_ASN1Template nsslowkey_DHPrivateKeyTemplate[];
|
||||
extern const SEC_ASN1Template nsslowkey_DHPrivateKeyExportTemplate[];
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
#define NSSLOWKEY_EC_PRIVATE_KEY_VERSION 1 /* as per SECG 1 C.4 */
|
||||
extern const SEC_ASN1Template nsslowkey_ECParamsTemplate[];
|
||||
extern const SEC_ASN1Template nsslowkey_ECPrivateKeyTemplate[];
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
|
||||
extern const SEC_ASN1Template nsslowkey_PrivateKeyInfoTemplate[];
|
||||
extern const SEC_ASN1Template nsslowkey_EncryptedPrivateKeyInfoTemplate[];
|
||||
|
||||
/*
|
||||
* PKCS #8 attributes
|
||||
*/
|
||||
struct NSSLOWKEYAttributeStr {
|
||||
SECItem attrType;
|
||||
SECItem *attrValue;
|
||||
};
|
||||
typedef struct NSSLOWKEYAttributeStr NSSLOWKEYAttribute;
|
||||
|
||||
/*
|
||||
** A PKCS#8 private key info object
|
||||
*/
|
||||
struct NSSLOWKEYPrivateKeyInfoStr {
|
||||
PLArenaPool *arena;
|
||||
SECItem version;
|
||||
SECAlgorithmID algorithm;
|
||||
SECItem privateKey;
|
||||
NSSLOWKEYAttribute **attributes;
|
||||
};
|
||||
typedef struct NSSLOWKEYPrivateKeyInfoStr NSSLOWKEYPrivateKeyInfo;
|
||||
#define NSSLOWKEY_PRIVATE_KEY_INFO_VERSION 0 /* what we *create* */
|
||||
|
||||
/*
|
||||
** A PKCS#8 private key info object
|
||||
*/
|
||||
struct NSSLOWKEYEncryptedPrivateKeyInfoStr {
|
||||
PLArenaPool *arena;
|
||||
SECAlgorithmID algorithm;
|
||||
SECItem encryptedData;
|
||||
};
|
||||
typedef struct NSSLOWKEYEncryptedPrivateKeyInfoStr NSSLOWKEYEncryptedPrivateKeyInfo;
|
||||
|
||||
|
||||
typedef enum {
|
||||
NSSLOWKEYNullKey = 0,
|
||||
NSSLOWKEYRSAKey = 1,
|
||||
NSSLOWKEYDSAKey = 2,
|
||||
NSSLOWKEYDHKey = 4,
|
||||
NSSLOWKEYECKey = 5
|
||||
} NSSLOWKEYType;
|
||||
|
||||
/*
|
||||
** An RSA public key object.
|
||||
*/
|
||||
struct NSSLOWKEYPublicKeyStr {
|
||||
PLArenaPool *arena;
|
||||
NSSLOWKEYType keyType ;
|
||||
union {
|
||||
RSAPublicKey rsa;
|
||||
DSAPublicKey dsa;
|
||||
DHPublicKey dh;
|
||||
ECPublicKey ec;
|
||||
} u;
|
||||
};
|
||||
typedef struct NSSLOWKEYPublicKeyStr NSSLOWKEYPublicKey;
|
||||
|
||||
/*
|
||||
** Low Level private key object
|
||||
** This is only used by the raw Crypto engines (crypto), keydb (keydb),
|
||||
** and PKCS #11. Everyone else uses the high level key structure.
|
||||
*/
|
||||
struct NSSLOWKEYPrivateKeyStr {
|
||||
PLArenaPool *arena;
|
||||
NSSLOWKEYType keyType;
|
||||
union {
|
||||
RSAPrivateKey rsa;
|
||||
DSAPrivateKey dsa;
|
||||
DHPrivateKey dh;
|
||||
ECPrivateKey ec;
|
||||
} u;
|
||||
};
|
||||
typedef struct NSSLOWKEYPrivateKeyStr NSSLOWKEYPrivateKey;
|
||||
|
||||
#endif /* _LOWKEYTI_H_ */
|
||||
@@ -1,68 +0,0 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
CORE_DEPTH = ../../../..
|
||||
|
||||
MODULE = nss
|
||||
|
||||
REQUIRES = dbm
|
||||
|
||||
LIBRARY_NAME = lgdbm
|
||||
LIBRARY_VERSION = 3
|
||||
MAPFILE = $(OBJDIR)/lgdbm.def
|
||||
|
||||
DEFINES += -DSHLIB_SUFFIX=\"$(DLL_SUFFIX)\" -DSHLIB_PREFIX=\"$(DLL_PREFIX)\" -DSOFTOKEN_LIB_NAME=\"$(notdir $(SHARED_LIBRARY))\"
|
||||
|
||||
|
||||
CSRCS = \
|
||||
dbmshim.c \
|
||||
keydb.c \
|
||||
lgattr.c \
|
||||
lgcreate.c \
|
||||
lgdestroy.c \
|
||||
lgfind.c \
|
||||
lginit.c \
|
||||
lgutil.c \
|
||||
lowcert.c \
|
||||
lowkey.c \
|
||||
pcertdb.c \
|
||||
pk11db.c \
|
||||
$(NULL)
|
||||
|
||||
ifdef NSS_ENABLE_ECC
|
||||
DEFINES += -DNSS_ENABLE_ECC
|
||||
endif
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _PCERTDB_H_
|
||||
#define _PCERTDB_H_
|
||||
|
||||
#include "plarena.h"
|
||||
#include "prlong.h"
|
||||
#include "pcertt.h"
|
||||
|
||||
#include "lowkeyti.h" /* for struct NSSLOWKEYPublicKeyStr */
|
||||
|
||||
SEC_BEGIN_PROTOS
|
||||
|
||||
/*
|
||||
* initialize any global certificate locks
|
||||
*/
|
||||
SECStatus nsslowcert_InitLocks(void);
|
||||
|
||||
/*
|
||||
** Add a DER encoded certificate to the permanent database.
|
||||
** "derCert" is the DER encoded certificate.
|
||||
** "nickname" is the nickname to use for the cert
|
||||
** "trust" is the trust parameters for the cert
|
||||
*/
|
||||
SECStatus nsslowcert_AddPermCert(NSSLOWCERTCertDBHandle *handle,
|
||||
NSSLOWCERTCertificate *cert,
|
||||
char *nickname, NSSLOWCERTCertTrust *trust);
|
||||
SECStatus nsslowcert_AddPermNickname(NSSLOWCERTCertDBHandle *dbhandle,
|
||||
NSSLOWCERTCertificate *cert, char *nickname);
|
||||
|
||||
SECStatus nsslowcert_DeletePermCertificate(NSSLOWCERTCertificate *cert);
|
||||
|
||||
typedef SECStatus (PR_CALLBACK * PermCertCallback)(NSSLOWCERTCertificate *cert,
|
||||
SECItem *k, void *pdata);
|
||||
/*
|
||||
** Traverse the entire permanent database, and pass the certs off to a
|
||||
** user supplied function.
|
||||
** "certfunc" is the user function to call for each certificate
|
||||
** "udata" is the user's data, which is passed through to "certfunc"
|
||||
*/
|
||||
SECStatus
|
||||
nsslowcert_TraversePermCerts(NSSLOWCERTCertDBHandle *handle,
|
||||
PermCertCallback certfunc,
|
||||
void *udata );
|
||||
|
||||
PRBool
|
||||
nsslowcert_CertDBKeyConflict(SECItem *derCert, NSSLOWCERTCertDBHandle *handle);
|
||||
|
||||
certDBEntryRevocation *
|
||||
nsslowcert_FindCrlByKey(NSSLOWCERTCertDBHandle *handle,
|
||||
SECItem *crlKey, PRBool isKRL);
|
||||
|
||||
SECStatus
|
||||
nsslowcert_DeletePermCRL(NSSLOWCERTCertDBHandle *handle,const SECItem *derName,
|
||||
PRBool isKRL);
|
||||
SECStatus
|
||||
nsslowcert_AddCrl(NSSLOWCERTCertDBHandle *handle, SECItem *derCrl ,
|
||||
SECItem *derKey, char *url, PRBool isKRL);
|
||||
|
||||
NSSLOWCERTCertDBHandle *nsslowcert_GetDefaultCertDB();
|
||||
NSSLOWKEYPublicKey *nsslowcert_ExtractPublicKey(NSSLOWCERTCertificate *);
|
||||
|
||||
NSSLOWCERTCertificate *
|
||||
nsslowcert_NewTempCertificate(NSSLOWCERTCertDBHandle *handle, SECItem *derCert,
|
||||
char *nickname, PRBool isperm, PRBool copyDER);
|
||||
NSSLOWCERTCertificate *
|
||||
nsslowcert_DupCertificate(NSSLOWCERTCertificate *cert);
|
||||
void nsslowcert_DestroyCertificate(NSSLOWCERTCertificate *cert);
|
||||
void nsslowcert_DestroyTrust(NSSLOWCERTTrust *Trust);
|
||||
|
||||
/*
|
||||
* Lookup a certificate in the databases without locking
|
||||
* "certKey" is the database key to look for
|
||||
*
|
||||
* XXX - this should be internal, but pkcs 11 needs to call it during a
|
||||
* traversal.
|
||||
*/
|
||||
NSSLOWCERTCertificate *
|
||||
nsslowcert_FindCertByKey(NSSLOWCERTCertDBHandle *handle, const SECItem *certKey);
|
||||
|
||||
/*
|
||||
* Lookup trust for a certificate in the databases without locking
|
||||
* "certKey" is the database key to look for
|
||||
*
|
||||
* XXX - this should be internal, but pkcs 11 needs to call it during a
|
||||
* traversal.
|
||||
*/
|
||||
NSSLOWCERTTrust *
|
||||
nsslowcert_FindTrustByKey(NSSLOWCERTCertDBHandle *handle, const SECItem *certKey);
|
||||
|
||||
/*
|
||||
** Generate a certificate key from the issuer and serialnumber, then look it
|
||||
** up in the database. Return the cert if found.
|
||||
** "issuerAndSN" is the issuer and serial number to look for
|
||||
*/
|
||||
extern NSSLOWCERTCertificate *
|
||||
nsslowcert_FindCertByIssuerAndSN (NSSLOWCERTCertDBHandle *handle, NSSLOWCERTIssuerAndSN *issuerAndSN);
|
||||
|
||||
/*
|
||||
** Generate a certificate key from the issuer and serialnumber, then look it
|
||||
** up in the database. Return the cert if found.
|
||||
** "issuerAndSN" is the issuer and serial number to look for
|
||||
*/
|
||||
extern NSSLOWCERTTrust *
|
||||
nsslowcert_FindTrustByIssuerAndSN (NSSLOWCERTCertDBHandle *handle, NSSLOWCERTIssuerAndSN *issuerAndSN);
|
||||
|
||||
/*
|
||||
** Find a certificate in the database by a DER encoded certificate
|
||||
** "derCert" is the DER encoded certificate
|
||||
*/
|
||||
extern NSSLOWCERTCertificate *
|
||||
nsslowcert_FindCertByDERCert(NSSLOWCERTCertDBHandle *handle, SECItem *derCert);
|
||||
|
||||
/* convert an email address to lower case */
|
||||
char *nsslowcert_FixupEmailAddr(char *emailAddr);
|
||||
|
||||
/*
|
||||
** Decode a DER encoded certificate into an NSSLOWCERTCertificate structure
|
||||
** "derSignedCert" is the DER encoded signed certificate
|
||||
** "copyDER" is true if the DER should be copied, false if the
|
||||
** existing copy should be referenced
|
||||
** "nickname" is the nickname to use in the database. If it is NULL
|
||||
** then a temporary nickname is generated.
|
||||
*/
|
||||
extern NSSLOWCERTCertificate *
|
||||
nsslowcert_DecodeDERCertificate (SECItem *derSignedCert, char *nickname);
|
||||
|
||||
SECStatus
|
||||
nsslowcert_KeyFromDERCert(PRArenaPool *arena, SECItem *derCert, SECItem *key);
|
||||
|
||||
certDBEntrySMime *
|
||||
nsslowcert_ReadDBSMimeEntry(NSSLOWCERTCertDBHandle *certHandle,
|
||||
char *emailAddr);
|
||||
void
|
||||
nsslowcert_DestroyDBEntry(certDBEntry *entry);
|
||||
|
||||
SECStatus
|
||||
nsslowcert_OpenCertDB(NSSLOWCERTCertDBHandle *handle, PRBool readOnly,
|
||||
const char *domain, const char *prefix,
|
||||
NSSLOWCERTDBNameFunc namecb, void *cbarg, PRBool openVolatile);
|
||||
|
||||
void
|
||||
nsslowcert_ClosePermCertDB(NSSLOWCERTCertDBHandle *handle);
|
||||
|
||||
/*
|
||||
* is certa newer than certb? If one is expired, pick the other one.
|
||||
*/
|
||||
PRBool
|
||||
nsslowcert_IsNewer(NSSLOWCERTCertificate *certa, NSSLOWCERTCertificate *certb);
|
||||
|
||||
|
||||
SECStatus
|
||||
nsslowcert_TraverseDBEntries(NSSLOWCERTCertDBHandle *handle,
|
||||
certDBEntryType type,
|
||||
SECStatus (* callback)(SECItem *data, SECItem *key,
|
||||
certDBEntryType type, void *pdata),
|
||||
void *udata );
|
||||
SECStatus
|
||||
nsslowcert_TraversePermCertsForSubject(NSSLOWCERTCertDBHandle *handle,
|
||||
SECItem *derSubject,
|
||||
NSSLOWCERTCertCallback cb, void *cbarg);
|
||||
int
|
||||
nsslowcert_NumPermCertsForSubject(NSSLOWCERTCertDBHandle *handle,
|
||||
SECItem *derSubject);
|
||||
SECStatus
|
||||
nsslowcert_TraversePermCertsForNickname(NSSLOWCERTCertDBHandle *handle,
|
||||
char *nickname, NSSLOWCERTCertCallback cb, void *cbarg);
|
||||
|
||||
int
|
||||
nsslowcert_NumPermCertsForNickname(NSSLOWCERTCertDBHandle *handle,
|
||||
char *nickname);
|
||||
SECStatus
|
||||
nsslowcert_GetCertTrust(NSSLOWCERTCertificate *cert,
|
||||
NSSLOWCERTCertTrust *trust);
|
||||
|
||||
SECStatus
|
||||
nsslowcert_SaveSMimeProfile(NSSLOWCERTCertDBHandle *dbhandle, char *emailAddr,
|
||||
SECItem *derSubject, SECItem *emailProfile, SECItem *profileTime);
|
||||
|
||||
/*
|
||||
* Change the trust attributes of a certificate and make them permanent
|
||||
* in the database.
|
||||
*/
|
||||
SECStatus
|
||||
nsslowcert_ChangeCertTrust(NSSLOWCERTCertDBHandle *handle,
|
||||
NSSLOWCERTCertificate *cert, NSSLOWCERTCertTrust *trust);
|
||||
|
||||
PRBool
|
||||
nsslowcert_needDBVerify(NSSLOWCERTCertDBHandle *handle);
|
||||
|
||||
void
|
||||
nsslowcert_setDBVerify(NSSLOWCERTCertDBHandle *handle, PRBool value);
|
||||
|
||||
PRBool
|
||||
nsslowcert_hasTrust(NSSLOWCERTCertTrust *trust);
|
||||
|
||||
void
|
||||
nsslowcert_DestroyFreeLists(void);
|
||||
|
||||
void
|
||||
nsslowcert_DestroyGlobalLocks(void);
|
||||
|
||||
void
|
||||
pkcs11_freeNickname(char *nickname, char *space);
|
||||
|
||||
char *
|
||||
pkcs11_copyNickname(char *nickname, char *space, int spaceLen);
|
||||
|
||||
void
|
||||
pkcs11_freeStaticData(unsigned char *data, unsigned char *space);
|
||||
|
||||
unsigned char *
|
||||
pkcs11_allocStaticData(int datalen, unsigned char *space, int spaceLen);
|
||||
|
||||
unsigned char *
|
||||
pkcs11_copyStaticData(unsigned char *data, int datalen, unsigned char *space,
|
||||
int spaceLen);
|
||||
NSSLOWCERTCertificate *
|
||||
nsslowcert_CreateCert(void);
|
||||
|
||||
certDBEntry *
|
||||
nsslowcert_DecodeAnyDBEntry(SECItem *dbData, const SECItem *dbKey,
|
||||
certDBEntryType entryType, void *pdata);
|
||||
|
||||
SEC_END_PROTOS
|
||||
|
||||
#endif /* _PCERTDB_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,450 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* certt.h - public data structures for the certificate library
|
||||
*
|
||||
* $Id: pcertt.h,v 1.1.2.2 2007-05-15 21:59:52 rrelyea%redhat.com Exp $
|
||||
*/
|
||||
#ifndef _PCERTT_H_
|
||||
#define _PCERTT_H_
|
||||
|
||||
#include "prclist.h"
|
||||
#include "pkcs11t.h"
|
||||
#include "seccomon.h"
|
||||
#include "secoidt.h"
|
||||
#include "plarena.h"
|
||||
#include "prcvar.h"
|
||||
#include "nssilock.h"
|
||||
#include "prio.h"
|
||||
#include "prmon.h"
|
||||
|
||||
/* Non-opaque objects */
|
||||
typedef struct NSSLOWCERTCertDBHandleStr NSSLOWCERTCertDBHandle;
|
||||
typedef struct NSSLOWCERTCertKeyStr NSSLOWCERTCertKey;
|
||||
|
||||
typedef struct NSSLOWCERTTrustStr NSSLOWCERTTrust;
|
||||
typedef struct NSSLOWCERTCertTrustStr NSSLOWCERTCertTrust;
|
||||
typedef struct NSSLOWCERTCertificateStr NSSLOWCERTCertificate;
|
||||
typedef struct NSSLOWCERTCertificateListStr NSSLOWCERTCertificateList;
|
||||
typedef struct NSSLOWCERTIssuerAndSNStr NSSLOWCERTIssuerAndSN;
|
||||
typedef struct NSSLOWCERTSignedDataStr NSSLOWCERTSignedData;
|
||||
typedef struct NSSLOWCERTSubjectPublicKeyInfoStr NSSLOWCERTSubjectPublicKeyInfo;
|
||||
typedef struct NSSLOWCERTValidityStr NSSLOWCERTValidity;
|
||||
|
||||
/*
|
||||
** An X.509 validity object
|
||||
*/
|
||||
struct NSSLOWCERTValidityStr {
|
||||
PRArenaPool *arena;
|
||||
SECItem notBefore;
|
||||
SECItem notAfter;
|
||||
};
|
||||
|
||||
/*
|
||||
* A serial number and issuer name, which is used as a database key
|
||||
*/
|
||||
struct NSSLOWCERTCertKeyStr {
|
||||
SECItem serialNumber;
|
||||
SECItem derIssuer;
|
||||
};
|
||||
|
||||
/*
|
||||
** A signed data object. Used to implement the "signed" macro used
|
||||
** in the X.500 specs.
|
||||
*/
|
||||
struct NSSLOWCERTSignedDataStr {
|
||||
SECItem data;
|
||||
SECAlgorithmID signatureAlgorithm;
|
||||
SECItem signature;
|
||||
};
|
||||
|
||||
/*
|
||||
** An X.509 subject-public-key-info object
|
||||
*/
|
||||
struct NSSLOWCERTSubjectPublicKeyInfoStr {
|
||||
PRArenaPool *arena;
|
||||
SECAlgorithmID algorithm;
|
||||
SECItem subjectPublicKey;
|
||||
};
|
||||
|
||||
typedef struct _certDBEntryCert certDBEntryCert;
|
||||
typedef struct _certDBEntryRevocation certDBEntryRevocation;
|
||||
|
||||
struct NSSLOWCERTCertTrustStr {
|
||||
unsigned int sslFlags;
|
||||
unsigned int emailFlags;
|
||||
unsigned int objectSigningFlags;
|
||||
};
|
||||
|
||||
/*
|
||||
** PKCS11 Trust representation
|
||||
*/
|
||||
struct NSSLOWCERTTrustStr {
|
||||
NSSLOWCERTTrust *next;
|
||||
NSSLOWCERTCertDBHandle *dbhandle;
|
||||
SECItem dbKey; /* database key for this cert */
|
||||
certDBEntryCert *dbEntry; /* database entry struct */
|
||||
NSSLOWCERTCertTrust *trust;
|
||||
SECItem *derCert; /* original DER for the cert */
|
||||
unsigned char dbKeySpace[512];
|
||||
};
|
||||
|
||||
/*
|
||||
** An X.509 certificate object (the unsigned form)
|
||||
*/
|
||||
struct NSSLOWCERTCertificateStr {
|
||||
/* the arena is used to allocate any data structures that have the same
|
||||
* lifetime as the cert. This is all stuff that hangs off of the cert
|
||||
* structure, and is all freed at the same time. I is used when the
|
||||
* cert is decoded, destroyed, and at some times when it changes
|
||||
* state
|
||||
*/
|
||||
NSSLOWCERTCertificate *next;
|
||||
NSSLOWCERTCertDBHandle *dbhandle;
|
||||
|
||||
SECItem derCert; /* original DER for the cert */
|
||||
SECItem derIssuer; /* DER for issuer name */
|
||||
SECItem derSN;
|
||||
SECItem serialNumber;
|
||||
SECItem derSubject; /* DER for subject name */
|
||||
SECItem derSubjKeyInfo;
|
||||
NSSLOWCERTSubjectPublicKeyInfo *subjectPublicKeyInfo;
|
||||
SECItem certKey; /* database key for this cert */
|
||||
SECItem validity;
|
||||
certDBEntryCert *dbEntry; /* database entry struct */
|
||||
SECItem subjectKeyID; /* x509v3 subject key identifier */
|
||||
SECItem extensions;
|
||||
char *nickname;
|
||||
char *emailAddr;
|
||||
NSSLOWCERTCertTrust *trust;
|
||||
|
||||
/* the reference count is modified whenever someone looks up, dups
|
||||
* or destroys a certificate
|
||||
*/
|
||||
int referenceCount;
|
||||
|
||||
char nicknameSpace[200];
|
||||
char emailAddrSpace[200];
|
||||
unsigned char certKeySpace[512];
|
||||
};
|
||||
|
||||
#define SEC_CERTIFICATE_VERSION_1 0 /* default created */
|
||||
#define SEC_CERTIFICATE_VERSION_2 1 /* v2 */
|
||||
#define SEC_CERTIFICATE_VERSION_3 2 /* v3 extensions */
|
||||
|
||||
#define SEC_CRL_VERSION_1 0 /* default */
|
||||
#define SEC_CRL_VERSION_2 1 /* v2 extensions */
|
||||
|
||||
struct NSSLOWCERTIssuerAndSNStr {
|
||||
SECItem derIssuer;
|
||||
SECItem serialNumber;
|
||||
};
|
||||
|
||||
typedef SECStatus (* NSSLOWCERTCertCallback)(NSSLOWCERTCertificate *cert, void *arg);
|
||||
|
||||
/* This is the typedef for the callback passed to nsslowcert_OpenCertDB() */
|
||||
/* callback to return database name based on version number */
|
||||
typedef char * (*NSSLOWCERTDBNameFunc)(void *arg, int dbVersion);
|
||||
|
||||
/* XXX Lisa thinks the template declarations belong in cert.h, not here? */
|
||||
|
||||
#include "secasn1t.h" /* way down here because I expect template stuff to
|
||||
* move out of here anyway */
|
||||
|
||||
/*
|
||||
* Certificate Database related definitions and data structures
|
||||
*/
|
||||
|
||||
/* version number of certificate database */
|
||||
#define CERT_DB_FILE_VERSION 8
|
||||
#define CERT_DB_V7_FILE_VERSION 7
|
||||
#define CERT_DB_CONTENT_VERSION 2
|
||||
|
||||
#define SEC_DB_ENTRY_HEADER_LEN 3
|
||||
#define SEC_DB_KEY_HEADER_LEN 1
|
||||
|
||||
/* All database entries have this form:
|
||||
*
|
||||
* byte offset field
|
||||
* ----------- -----
|
||||
* 0 version
|
||||
* 1 type
|
||||
* 2 flags
|
||||
*/
|
||||
|
||||
/* database entry types */
|
||||
typedef enum {
|
||||
certDBEntryTypeVersion = 0,
|
||||
certDBEntryTypeCert = 1,
|
||||
certDBEntryTypeNickname = 2,
|
||||
certDBEntryTypeSubject = 3,
|
||||
certDBEntryTypeRevocation = 4,
|
||||
certDBEntryTypeKeyRevocation = 5,
|
||||
certDBEntryTypeSMimeProfile = 6,
|
||||
certDBEntryTypeContentVersion = 7,
|
||||
certDBEntryTypeBlob = 8
|
||||
} certDBEntryType;
|
||||
|
||||
typedef struct {
|
||||
certDBEntryType type;
|
||||
unsigned int version;
|
||||
unsigned int flags;
|
||||
PRArenaPool *arena;
|
||||
} certDBEntryCommon;
|
||||
|
||||
/*
|
||||
* Certificate entry:
|
||||
*
|
||||
* byte offset field
|
||||
* ----------- -----
|
||||
* 0 sslFlags-msb
|
||||
* 1 sslFlags-lsb
|
||||
* 2 emailFlags-msb
|
||||
* 3 emailFlags-lsb
|
||||
* 4 objectSigningFlags-msb
|
||||
* 5 objectSigningFlags-lsb
|
||||
* 6 derCert-len-msb
|
||||
* 7 derCert-len-lsb
|
||||
* 8 nickname-len-msb
|
||||
* 9 nickname-len-lsb
|
||||
* ... derCert
|
||||
* ... nickname
|
||||
*
|
||||
* NOTE: the nickname string as stored in the database is null terminated,
|
||||
* in other words, the last byte of the db entry is always 0
|
||||
* if a nickname is present.
|
||||
* NOTE: if nickname is not present, then nickname-len-msb and
|
||||
* nickname-len-lsb will both be zero.
|
||||
*/
|
||||
struct _certDBEntryCert {
|
||||
certDBEntryCommon common;
|
||||
certDBEntryCert *next;
|
||||
NSSLOWCERTCertTrust trust;
|
||||
SECItem derCert;
|
||||
char *nickname;
|
||||
char nicknameSpace[200];
|
||||
unsigned char derCertSpace[2048];
|
||||
};
|
||||
|
||||
/*
|
||||
* Certificate Nickname entry:
|
||||
*
|
||||
* byte offset field
|
||||
* ----------- -----
|
||||
* 0 subjectname-len-msb
|
||||
* 1 subjectname-len-lsb
|
||||
* 2... subjectname
|
||||
*
|
||||
* The database key for this type of entry is a nickname string
|
||||
* The "subjectname" value is the DER encoded DN of the identity
|
||||
* that matches this nickname.
|
||||
*/
|
||||
typedef struct {
|
||||
certDBEntryCommon common;
|
||||
char *nickname;
|
||||
SECItem subjectName;
|
||||
} certDBEntryNickname;
|
||||
|
||||
#define DB_NICKNAME_ENTRY_HEADER_LEN 2
|
||||
|
||||
/*
|
||||
* Certificate Subject entry:
|
||||
*
|
||||
* byte offset field
|
||||
* ----------- -----
|
||||
* 0 ncerts-msb
|
||||
* 1 ncerts-lsb
|
||||
* 2 nickname-msb
|
||||
* 3 nickname-lsb
|
||||
* 4 emailAddr-msb
|
||||
* 5 emailAddr-lsb
|
||||
* ... nickname
|
||||
* ... emailAddr
|
||||
* ...+2*i certkey-len-msb
|
||||
* ...+1+2*i certkey-len-lsb
|
||||
* ...+2*ncerts+2*i keyid-len-msb
|
||||
* ...+1+2*ncerts+2*i keyid-len-lsb
|
||||
* ... certkeys
|
||||
* ... keyids
|
||||
*
|
||||
* The database key for this type of entry is the DER encoded subject name
|
||||
* The "certkey" value is an array of certificate database lookup keys that
|
||||
* points to the database entries for the certificates that matche
|
||||
* this subject.
|
||||
*
|
||||
*/
|
||||
typedef struct _certDBEntrySubject {
|
||||
certDBEntryCommon common;
|
||||
SECItem derSubject;
|
||||
unsigned int ncerts;
|
||||
char *nickname;
|
||||
SECItem *certKeys;
|
||||
SECItem *keyIDs;
|
||||
char **emailAddrs;
|
||||
unsigned int nemailAddrs;
|
||||
} certDBEntrySubject;
|
||||
|
||||
#define DB_SUBJECT_ENTRY_HEADER_LEN 6
|
||||
|
||||
/*
|
||||
* Certificate SMIME profile entry:
|
||||
*
|
||||
* byte offset field
|
||||
* ----------- -----
|
||||
* 0 subjectname-len-msb
|
||||
* 1 subjectname-len-lsb
|
||||
* 2 smimeoptions-len-msb
|
||||
* 3 smimeoptions-len-lsb
|
||||
* 4 options-date-len-msb
|
||||
* 5 options-date-len-lsb
|
||||
* 6... subjectname
|
||||
* ... smimeoptions
|
||||
* ... options-date
|
||||
*
|
||||
* The database key for this type of entry is the email address string
|
||||
* The "subjectname" value is the DER encoded DN of the identity
|
||||
* that matches this nickname.
|
||||
* The "smimeoptions" value is a string that represents the algorithm
|
||||
* capabilities on the remote user.
|
||||
* The "options-date" is the date that the smime options value was created.
|
||||
* This is generally the signing time of the signed message that contained
|
||||
* the options. It is a UTCTime value.
|
||||
*/
|
||||
typedef struct {
|
||||
certDBEntryCommon common;
|
||||
char *emailAddr;
|
||||
SECItem subjectName;
|
||||
SECItem smimeOptions;
|
||||
SECItem optionsDate;
|
||||
} certDBEntrySMime;
|
||||
|
||||
#define DB_SMIME_ENTRY_HEADER_LEN 6
|
||||
|
||||
/*
|
||||
* Crl/krl entry:
|
||||
*
|
||||
* byte offset field
|
||||
* ----------- -----
|
||||
* 0 derCert-len-msb
|
||||
* 1 derCert-len-lsb
|
||||
* 2 url-len-msb
|
||||
* 3 url-len-lsb
|
||||
* ... derCert
|
||||
* ... url
|
||||
*
|
||||
* NOTE: the url string as stored in the database is null terminated,
|
||||
* in other words, the last byte of the db entry is always 0
|
||||
* if a nickname is present.
|
||||
* NOTE: if url is not present, then url-len-msb and
|
||||
* url-len-lsb will both be zero.
|
||||
*/
|
||||
#define DB_CRL_ENTRY_HEADER_LEN 4
|
||||
struct _certDBEntryRevocation {
|
||||
certDBEntryCommon common;
|
||||
SECItem derCrl;
|
||||
char *url; /* where to load the crl from */
|
||||
};
|
||||
|
||||
/*
|
||||
* Database Version Entry:
|
||||
*
|
||||
* byte offset field
|
||||
* ----------- -----
|
||||
* only the low level header...
|
||||
*
|
||||
* The database key for this type of entry is the string "Version"
|
||||
*/
|
||||
typedef struct {
|
||||
certDBEntryCommon common;
|
||||
} certDBEntryVersion;
|
||||
|
||||
#define SEC_DB_VERSION_KEY "Version"
|
||||
#define SEC_DB_VERSION_KEY_LEN sizeof(SEC_DB_VERSION_KEY)
|
||||
|
||||
/*
|
||||
* Database Content Version Entry:
|
||||
*
|
||||
* byte offset field
|
||||
* ----------- -----
|
||||
* 0 contentVersion
|
||||
*
|
||||
* The database key for this type of entry is the string "ContentVersion"
|
||||
*/
|
||||
typedef struct {
|
||||
certDBEntryCommon common;
|
||||
char contentVersion;
|
||||
} certDBEntryContentVersion;
|
||||
|
||||
#define SEC_DB_CONTENT_VERSION_KEY "ContentVersion"
|
||||
#define SEC_DB_CONTENT_VERSION_KEY_LEN sizeof(SEC_DB_CONTENT_VERSION_KEY)
|
||||
|
||||
typedef union {
|
||||
certDBEntryCommon common;
|
||||
certDBEntryCert cert;
|
||||
certDBEntryContentVersion content;
|
||||
certDBEntryNickname nickname;
|
||||
certDBEntryRevocation revocation;
|
||||
certDBEntrySMime smime;
|
||||
certDBEntrySubject subject;
|
||||
certDBEntryVersion version;
|
||||
} certDBEntry;
|
||||
|
||||
/* length of the fixed part of a database entry */
|
||||
#define DBCERT_V4_HEADER_LEN 7
|
||||
#define DB_CERT_V5_ENTRY_HEADER_LEN 7
|
||||
#define DB_CERT_V6_ENTRY_HEADER_LEN 7
|
||||
#define DB_CERT_ENTRY_HEADER_LEN 10
|
||||
|
||||
/* common flags for all types of certificates */
|
||||
#define CERTDB_VALID_PEER (1<<0)
|
||||
#define CERTDB_TRUSTED (1<<1)
|
||||
#define CERTDB_SEND_WARN (1<<2)
|
||||
#define CERTDB_VALID_CA (1<<3)
|
||||
#define CERTDB_TRUSTED_CA (1<<4) /* trusted for issuing server certs */
|
||||
#define CERTDB_NS_TRUSTED_CA (1<<5)
|
||||
#define CERTDB_USER (1<<6)
|
||||
#define CERTDB_TRUSTED_CLIENT_CA (1<<7) /* trusted for issuing client certs */
|
||||
#define CERTDB_INVISIBLE_CA (1<<8) /* don't show in UI */
|
||||
#define CERTDB_GOVT_APPROVED_CA (1<<9) /* can do strong crypto in export ver */
|
||||
#define CERTDB_NOT_TRUSTED (1<<10) /* explicitly don't trust this cert */
|
||||
#define CERTDB_TRUSTED_UNKNOWN (1<<11) /* accept trust from another source */
|
||||
|
||||
/* bits not affected by the CKO_NETSCAPE_TRUST object */
|
||||
#define CERTDB_PRESERVE_TRUST_BITS (CERTDB_USER | CERTDB_VALID_PEER | \
|
||||
CERTDB_NS_TRUSTED_CA | CERTDB_VALID_CA | CERTDB_INVISIBLE_CA | \
|
||||
CERTDB_GOVT_APPROVED_CA)
|
||||
|
||||
#endif /* _PCERTT_H_ */
|
||||
@@ -1,773 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* The following code handles the storage of PKCS 11 modules used by the
|
||||
* NSS. This file is written to abstract away how the modules are
|
||||
* stored so we can deside that later.
|
||||
*/
|
||||
|
||||
#include "pk11pars.h"
|
||||
#include "lgdb.h"
|
||||
#include "mcom_db.h"
|
||||
#include "secerr.h"
|
||||
|
||||
#define FREE_CLEAR(p) if (p) { PORT_Free(p); p = NULL; }
|
||||
|
||||
/* Construct a database key for a given module */
|
||||
static SECStatus secmod_MakeKey(DBT *key, char * module) {
|
||||
int len = 0;
|
||||
char *commonName;
|
||||
|
||||
commonName = secmod_argGetParamValue("name",module);
|
||||
if (commonName == NULL) {
|
||||
commonName = secmod_argGetParamValue("library",module);
|
||||
}
|
||||
if (commonName == NULL) return SECFailure;
|
||||
len = PORT_Strlen(commonName);
|
||||
key->data = commonName;
|
||||
key->size = len;
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
/* free out constructed database key */
|
||||
static void
|
||||
secmod_FreeKey(DBT *key)
|
||||
{
|
||||
if (key->data) {
|
||||
PORT_Free(key->data);
|
||||
}
|
||||
key->data = NULL;
|
||||
key->size = 0;
|
||||
}
|
||||
|
||||
typedef struct secmodDataStr secmodData;
|
||||
typedef struct secmodSlotDataStr secmodSlotData;
|
||||
struct secmodDataStr {
|
||||
unsigned char major;
|
||||
unsigned char minor;
|
||||
unsigned char nameStart[2];
|
||||
unsigned char slotOffset[2];
|
||||
unsigned char internal;
|
||||
unsigned char fips;
|
||||
unsigned char ssl[8];
|
||||
unsigned char trustOrder[4];
|
||||
unsigned char cipherOrder[4];
|
||||
unsigned char reserved1;
|
||||
unsigned char isModuleDB;
|
||||
unsigned char isModuleDBOnly;
|
||||
unsigned char isCritical;
|
||||
unsigned char reserved[4];
|
||||
unsigned char names[6]; /* enough space for the length fields */
|
||||
};
|
||||
|
||||
struct secmodSlotDataStr {
|
||||
unsigned char slotID[4];
|
||||
unsigned char defaultFlags[4];
|
||||
unsigned char timeout[4];
|
||||
unsigned char askpw;
|
||||
unsigned char hasRootCerts;
|
||||
unsigned char reserved[18]; /* this makes it a round 32 bytes */
|
||||
};
|
||||
|
||||
#define SECMOD_DB_VERSION_MAJOR 0
|
||||
#define SECMOD_DB_VERSION_MINOR 6
|
||||
#define SECMOD_DB_EXT1_VERSION_MAJOR 0
|
||||
#define SECMOD_DB_EXT1_VERSION_MINOR 6
|
||||
#define SECMOD_DB_NOUI_VERSION_MAJOR 0
|
||||
#define SECMOD_DB_NOUI_VERSION_MINOR 4
|
||||
|
||||
#define SECMOD_PUTSHORT(dest,src) \
|
||||
(dest)[1] = (unsigned char) ((src)&0xff); \
|
||||
(dest)[0] = (unsigned char) (((src) >> 8) & 0xff);
|
||||
#define SECMOD_PUTLONG(dest,src) \
|
||||
(dest)[3] = (unsigned char) ((src)&0xff); \
|
||||
(dest)[2] = (unsigned char) (((src) >> 8) & 0xff); \
|
||||
(dest)[1] = (unsigned char) (((src) >> 16) & 0xff); \
|
||||
(dest)[0] = (unsigned char) (((src) >> 24) & 0xff);
|
||||
#define SECMOD_GETSHORT(src) \
|
||||
((unsigned short) (((src)[0] << 8) | (src)[1]))
|
||||
#define SECMOD_GETLONG(src) \
|
||||
((unsigned long) (( (unsigned long) (src)[0] << 24) | \
|
||||
( (unsigned long) (src)[1] << 16) | \
|
||||
( (unsigned long) (src)[2] << 8) | \
|
||||
(unsigned long) (src)[3]))
|
||||
|
||||
/*
|
||||
* build a data base entry from a module
|
||||
*/
|
||||
static SECStatus
|
||||
secmod_EncodeData(DBT *data, char * module)
|
||||
{
|
||||
secmodData *encoded = NULL;
|
||||
secmodSlotData *slot;
|
||||
unsigned char *dataPtr;
|
||||
unsigned short len, len2 = 0, len3 = 0;
|
||||
int count = 0;
|
||||
unsigned short offset;
|
||||
int dataLen, i;
|
||||
unsigned long order;
|
||||
unsigned long ssl[2];
|
||||
char *commonName = NULL , *dllName = NULL, *param = NULL, *nss = NULL;
|
||||
char *slotParams, *ciphers;
|
||||
PK11PreSlotInfo *slotInfo = NULL;
|
||||
SECStatus rv = SECFailure;
|
||||
|
||||
rv = secmod_argParseModuleSpec(module,&dllName,&commonName,¶m,&nss);
|
||||
if (rv != SECSuccess) return rv;
|
||||
rv = SECFailure;
|
||||
|
||||
if (commonName == NULL) {
|
||||
/* set error */
|
||||
goto loser;
|
||||
}
|
||||
|
||||
len = PORT_Strlen(commonName);
|
||||
if (dllName) {
|
||||
len2 = PORT_Strlen(dllName);
|
||||
}
|
||||
if (param) {
|
||||
len3 = PORT_Strlen(param);
|
||||
}
|
||||
|
||||
slotParams = secmod_argGetParamValue("slotParams",nss);
|
||||
slotInfo = secmod_argParseSlotInfo(NULL,slotParams,&count);
|
||||
if (slotParams) PORT_Free(slotParams);
|
||||
|
||||
if (count && slotInfo == NULL) {
|
||||
/* set error */
|
||||
goto loser;
|
||||
}
|
||||
|
||||
dataLen = sizeof(secmodData) + len + len2 + len3 + sizeof(unsigned short) +
|
||||
count*sizeof(secmodSlotData);
|
||||
|
||||
data->data = (unsigned char *) PORT_ZAlloc(dataLen);
|
||||
encoded = (secmodData *)data->data;
|
||||
dataPtr = (unsigned char *) data->data;
|
||||
data->size = dataLen;
|
||||
|
||||
if (encoded == NULL) {
|
||||
/* set error */
|
||||
goto loser;
|
||||
}
|
||||
|
||||
encoded->major = SECMOD_DB_VERSION_MAJOR;
|
||||
encoded->minor = SECMOD_DB_VERSION_MINOR;
|
||||
encoded->internal = (unsigned char)
|
||||
(secmod_argHasFlag("flags","internal",nss) ? 1 : 0);
|
||||
encoded->fips = (unsigned char)
|
||||
(secmod_argHasFlag("flags","FIPS",nss) ? 1 : 0);
|
||||
encoded->isModuleDB = (unsigned char)
|
||||
(secmod_argHasFlag("flags","isModuleDB",nss) ? 1 : 0);
|
||||
encoded->isModuleDBOnly = (unsigned char)
|
||||
(secmod_argHasFlag("flags","isModuleDBOnly",nss) ? 1 : 0);
|
||||
encoded->isCritical = (unsigned char)
|
||||
(secmod_argHasFlag("flags","critical",nss) ? 1 : 0);
|
||||
|
||||
order = secmod_argReadLong("trustOrder", nss, SECMOD_DEFAULT_TRUST_ORDER,
|
||||
NULL);
|
||||
SECMOD_PUTLONG(encoded->trustOrder,order);
|
||||
order = secmod_argReadLong("cipherOrder", nss, SECMOD_DEFAULT_CIPHER_ORDER,
|
||||
NULL);
|
||||
SECMOD_PUTLONG(encoded->cipherOrder,order);
|
||||
|
||||
|
||||
ciphers = secmod_argGetParamValue("ciphers",nss);
|
||||
secmod_argSetNewCipherFlags(&ssl[0], ciphers);
|
||||
SECMOD_PUTLONG(encoded->ssl,ssl[0]);
|
||||
SECMOD_PUTLONG(&encoded->ssl[4],ssl[1]);
|
||||
if (ciphers) PORT_Free(ciphers);
|
||||
|
||||
offset = (unsigned short) &(((secmodData *)0)->names[0]);
|
||||
SECMOD_PUTSHORT(encoded->nameStart,offset);
|
||||
offset = offset + len + len2 + len3 + 3*sizeof(unsigned short);
|
||||
SECMOD_PUTSHORT(encoded->slotOffset,offset);
|
||||
|
||||
|
||||
SECMOD_PUTSHORT(&dataPtr[offset],((unsigned short)count));
|
||||
slot = (secmodSlotData *)(dataPtr+offset+sizeof(unsigned short));
|
||||
|
||||
offset = 0;
|
||||
SECMOD_PUTSHORT(encoded->names,len);
|
||||
offset += sizeof(unsigned short);
|
||||
PORT_Memcpy(&encoded->names[offset],commonName,len);
|
||||
offset += len;
|
||||
|
||||
|
||||
SECMOD_PUTSHORT(&encoded->names[offset],len2);
|
||||
offset += sizeof(unsigned short);
|
||||
if (len2) PORT_Memcpy(&encoded->names[offset],dllName,len2);
|
||||
offset += len2;
|
||||
|
||||
SECMOD_PUTSHORT(&encoded->names[offset],len3);
|
||||
offset += sizeof(unsigned short);
|
||||
if (len3) PORT_Memcpy(&encoded->names[offset],param,len3);
|
||||
offset += len3;
|
||||
|
||||
if (count) {
|
||||
for (i=0; i < count; i++) {
|
||||
SECMOD_PUTLONG(slot[i].slotID, slotInfo[i].slotID);
|
||||
SECMOD_PUTLONG(slot[i].defaultFlags,
|
||||
slotInfo[i].defaultFlags);
|
||||
SECMOD_PUTLONG(slot[i].timeout,slotInfo[i].timeout);
|
||||
slot[i].askpw = slotInfo[i].askpw;
|
||||
slot[i].hasRootCerts = slotInfo[i].hasRootCerts;
|
||||
PORT_Memset(slot[i].reserved, 0, sizeof(slot[i].reserved));
|
||||
}
|
||||
}
|
||||
rv = SECSuccess;
|
||||
|
||||
loser:
|
||||
if (commonName) PORT_Free(commonName);
|
||||
if (dllName) PORT_Free(dllName);
|
||||
if (param) PORT_Free(param);
|
||||
if (slotInfo) PORT_Free(slotInfo);
|
||||
if (nss) PORT_Free(nss);
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
secmod_FreeData(DBT *data)
|
||||
{
|
||||
if (data->data) {
|
||||
PORT_Free(data->data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
secmod_FreeSlotStrings(char **slotStrings, int count)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < count; i++) {
|
||||
if (slotStrings[i]) {
|
||||
PR_smprintf_free(slotStrings[i]);
|
||||
slotStrings[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* build a module from the data base entry.
|
||||
*/
|
||||
static char *
|
||||
secmod_DecodeData(char *defParams, DBT *data, PRBool *retInternal)
|
||||
{
|
||||
secmodData *encoded;
|
||||
secmodSlotData *slots;
|
||||
PLArenaPool *arena;
|
||||
char *commonName = NULL;
|
||||
char *dllName = NULL;
|
||||
char *parameters = NULL;
|
||||
char *nss;
|
||||
char *moduleSpec;
|
||||
char **slotStrings = NULL;
|
||||
unsigned char *names;
|
||||
unsigned long slotCount;
|
||||
unsigned long ssl0 =0;
|
||||
unsigned long ssl1 =0;
|
||||
unsigned long slotID;
|
||||
unsigned long defaultFlags;
|
||||
unsigned long timeout;
|
||||
unsigned long trustOrder =SECMOD_DEFAULT_TRUST_ORDER;
|
||||
unsigned long cipherOrder =SECMOD_DEFAULT_CIPHER_ORDER;
|
||||
unsigned short len;
|
||||
unsigned short namesOffset = 0; /* start of the names block */
|
||||
unsigned long namesRunningOffset; /* offset to name we are
|
||||
* currently processing */
|
||||
unsigned short slotOffset;
|
||||
PRBool isOldVersion = PR_FALSE;
|
||||
PRBool internal;
|
||||
PRBool isFIPS;
|
||||
PRBool isModuleDB =PR_FALSE;
|
||||
PRBool isModuleDBOnly =PR_FALSE;
|
||||
PRBool extended =PR_FALSE;
|
||||
int i;
|
||||
|
||||
|
||||
arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE);
|
||||
if (arena == NULL)
|
||||
return NULL;
|
||||
|
||||
#define CHECK_SIZE(x) \
|
||||
if ((unsigned int) data->size < (unsigned int)(x)) goto db_loser
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
** Process the buffer header, which is the secmodData struct.
|
||||
** It may be an old or new version. Check the length for each.
|
||||
*/
|
||||
|
||||
CHECK_SIZE( offsetof(secmodData, trustOrder[0]) );
|
||||
|
||||
encoded = (secmodData *)data->data;
|
||||
|
||||
internal = (encoded->internal != 0) ? PR_TRUE: PR_FALSE;
|
||||
isFIPS = (encoded->fips != 0) ? PR_TRUE: PR_FALSE;
|
||||
|
||||
if (retInternal)
|
||||
*retInternal = internal;
|
||||
if (internal) {
|
||||
parameters = PORT_ArenaStrdup(arena,defParams);
|
||||
if (parameters == NULL)
|
||||
goto loser;
|
||||
}
|
||||
if (internal && (encoded->major == SECMOD_DB_NOUI_VERSION_MAJOR) &&
|
||||
(encoded->minor <= SECMOD_DB_NOUI_VERSION_MINOR)) {
|
||||
isOldVersion = PR_TRUE;
|
||||
}
|
||||
if ((encoded->major == SECMOD_DB_EXT1_VERSION_MAJOR) &&
|
||||
(encoded->minor >= SECMOD_DB_EXT1_VERSION_MINOR)) {
|
||||
CHECK_SIZE( sizeof(secmodData));
|
||||
trustOrder = SECMOD_GETLONG(encoded->trustOrder);
|
||||
cipherOrder = SECMOD_GETLONG(encoded->cipherOrder);
|
||||
isModuleDB = (encoded->isModuleDB != 0) ? PR_TRUE: PR_FALSE;
|
||||
isModuleDBOnly = (encoded->isModuleDBOnly != 0) ? PR_TRUE: PR_FALSE;
|
||||
extended = PR_TRUE;
|
||||
}
|
||||
if (internal && !extended) {
|
||||
trustOrder = 0;
|
||||
cipherOrder = 100;
|
||||
}
|
||||
/* decode SSL cipher enable flags */
|
||||
ssl0 = SECMOD_GETLONG(encoded->ssl);
|
||||
ssl1 = SECMOD_GETLONG(encoded->ssl + 4);
|
||||
|
||||
slotOffset = SECMOD_GETSHORT(encoded->slotOffset);
|
||||
namesOffset = SECMOD_GETSHORT(encoded->nameStart);
|
||||
|
||||
|
||||
/*--------------------------------------------------------------
|
||||
** Now process the variable length set of names.
|
||||
** The names have this structure:
|
||||
** struct {
|
||||
** BYTE commonNameLen[ 2 ];
|
||||
** BYTE commonName [ commonNameLen ];
|
||||
** BTTE libNameLen [ 2 ];
|
||||
** BYTE libName [ libNameLen ];
|
||||
** If it is "extended" it also has these members:
|
||||
** BYTE initStringLen[ 2 ];
|
||||
** BYTE initString [ initStringLen ];
|
||||
** }
|
||||
*/
|
||||
|
||||
namesRunningOffset = namesOffset;
|
||||
/* copy the module's common name */
|
||||
CHECK_SIZE( namesRunningOffset + 2);
|
||||
names = (unsigned char *)data->data;
|
||||
len = SECMOD_GETSHORT(names+namesRunningOffset);
|
||||
|
||||
CHECK_SIZE( namesRunningOffset + 2 + len);
|
||||
commonName = (char*)PORT_ArenaAlloc(arena,len+1);
|
||||
if (commonName == NULL)
|
||||
goto loser;
|
||||
PORT_Memcpy(commonName, names + namesRunningOffset + 2, len);
|
||||
commonName[len] = 0;
|
||||
namesRunningOffset += len + 2;
|
||||
|
||||
/* copy the module's shared library file name. */
|
||||
CHECK_SIZE( namesRunningOffset + 2);
|
||||
len = SECMOD_GETSHORT(names + namesRunningOffset);
|
||||
if (len) {
|
||||
CHECK_SIZE( namesRunningOffset + 2 + len);
|
||||
dllName = (char*)PORT_ArenaAlloc(arena,len + 1);
|
||||
if (dllName == NULL)
|
||||
goto loser;
|
||||
PORT_Memcpy(dllName, names + namesRunningOffset + 2, len);
|
||||
dllName[len] = 0;
|
||||
}
|
||||
namesRunningOffset += len + 2;
|
||||
|
||||
/* copy the module's initialization string, if present. */
|
||||
if (!internal && extended) {
|
||||
CHECK_SIZE( namesRunningOffset + 2);
|
||||
len = SECMOD_GETSHORT(names+namesRunningOffset);
|
||||
if (len) {
|
||||
CHECK_SIZE( namesRunningOffset + 2 + len );
|
||||
parameters = (char*)PORT_ArenaAlloc(arena,len + 1);
|
||||
if (parameters == NULL)
|
||||
goto loser;
|
||||
PORT_Memcpy(parameters,names + namesRunningOffset + 2, len);
|
||||
parameters[len] = 0;
|
||||
}
|
||||
namesRunningOffset += len + 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Consistency check: Make sure the slot and names blocks don't
|
||||
* overlap. These blocks can occur in any order, so this check is made
|
||||
* in 2 parts. First we check the case where the slot block starts
|
||||
* after the name block. Later, when we have the slot block length,
|
||||
* we check the case where slot block starts before the name block.
|
||||
* NOTE: in most cases any overlap will likely be detected by invalid
|
||||
* data read from the blocks, but it's better to find out sooner
|
||||
* than later.
|
||||
*/
|
||||
if (slotOffset >= namesOffset) { /* slot block starts after name block */
|
||||
if (slotOffset < namesRunningOffset) {
|
||||
goto db_loser;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
** Part 3, process the slot table.
|
||||
** This part has this structure:
|
||||
** struct {
|
||||
** BYTE slotCount [ 2 ];
|
||||
** secmodSlotData [ slotCount ];
|
||||
** {
|
||||
*/
|
||||
|
||||
CHECK_SIZE( slotOffset + 2 );
|
||||
slotCount = SECMOD_GETSHORT((unsigned char *)data->data + slotOffset);
|
||||
|
||||
/*
|
||||
* Consistency check: Part 2. We now have the slot block length, we can
|
||||
* check the case where the slotblock procedes the name block.
|
||||
*/
|
||||
if (slotOffset < namesOffset) { /* slot block starts before name block */
|
||||
if (namesOffset < slotOffset + 2 + slotCount*sizeof(secmodSlotData)) {
|
||||
goto db_loser;
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_SIZE( (slotOffset + 2 + slotCount * sizeof(secmodSlotData)));
|
||||
slots = (secmodSlotData *) ((unsigned char *)data->data + slotOffset + 2);
|
||||
|
||||
/* slotCount; */
|
||||
slotStrings = (char **)PORT_ArenaZAlloc(arena, slotCount * sizeof(char *));
|
||||
if (slotStrings == NULL)
|
||||
goto loser;
|
||||
for (i=0; i < (int) slotCount; i++, slots++) {
|
||||
PRBool hasRootCerts =PR_FALSE;
|
||||
PRBool hasRootTrust =PR_FALSE;
|
||||
slotID = SECMOD_GETLONG(slots->slotID);
|
||||
defaultFlags = SECMOD_GETLONG(slots->defaultFlags);
|
||||
timeout = SECMOD_GETLONG(slots->timeout);
|
||||
hasRootCerts = slots->hasRootCerts;
|
||||
if (isOldVersion && internal && (slotID != 2)) {
|
||||
unsigned long internalFlags=
|
||||
secmod_argSlotFlags("slotFlags",SECMOD_SLOT_FLAGS);
|
||||
defaultFlags |= internalFlags;
|
||||
}
|
||||
if (hasRootCerts && !extended) {
|
||||
trustOrder = 100;
|
||||
}
|
||||
|
||||
slotStrings[i] = secmod_mkSlotString(slotID, defaultFlags, timeout,
|
||||
(unsigned char)slots->askpw,
|
||||
hasRootCerts, hasRootTrust);
|
||||
if (slotStrings[i] == NULL) {
|
||||
secmod_FreeSlotStrings(slotStrings,i);
|
||||
goto loser;
|
||||
}
|
||||
}
|
||||
|
||||
nss = secmod_mkNSS(slotStrings, slotCount, internal, isFIPS, isModuleDB,
|
||||
isModuleDBOnly, internal, trustOrder, cipherOrder,
|
||||
ssl0, ssl1);
|
||||
secmod_FreeSlotStrings(slotStrings,slotCount);
|
||||
/* it's permissible (and normal) for nss to be NULL. it simply means
|
||||
* there are no NSS specific parameters in the database */
|
||||
moduleSpec = secmod_mkNewModuleSpec(dllName,commonName,parameters,nss);
|
||||
PR_smprintf_free(nss);
|
||||
PORT_FreeArena(arena,PR_TRUE);
|
||||
return moduleSpec;
|
||||
|
||||
db_loser:
|
||||
PORT_SetError(SEC_ERROR_BAD_DATABASE);
|
||||
loser:
|
||||
PORT_FreeArena(arena,PR_TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static DB *
|
||||
secmod_OpenDB(const char *appName, const char *filename, const char *dbName,
|
||||
PRBool readOnly, PRBool update)
|
||||
{
|
||||
DB *pkcs11db = NULL;
|
||||
|
||||
|
||||
if (appName) {
|
||||
char *secname = PORT_Strdup(filename);
|
||||
int len = strlen(secname);
|
||||
int status = RDB_FAIL;
|
||||
|
||||
if (len >= 3 && PORT_Strcmp(&secname[len-3],".db") == 0) {
|
||||
secname[len-3] = 0;
|
||||
}
|
||||
pkcs11db=
|
||||
rdbopen(appName, "", secname, readOnly ? NO_RDONLY:NO_RDWR, NULL);
|
||||
if (update && !pkcs11db) {
|
||||
DB *updatedb;
|
||||
|
||||
pkcs11db = rdbopen(appName, "", secname, NO_CREATE, &status);
|
||||
if (!pkcs11db) {
|
||||
if (status == RDB_RETRY) {
|
||||
pkcs11db= rdbopen(appName, "", secname,
|
||||
readOnly ? NO_RDONLY:NO_RDWR, NULL);
|
||||
}
|
||||
PORT_Free(secname);
|
||||
return pkcs11db;
|
||||
}
|
||||
updatedb = dbopen(dbName, NO_RDONLY, 0600, DB_HASH, 0);
|
||||
if (updatedb) {
|
||||
db_Copy(pkcs11db,updatedb);
|
||||
(*updatedb->close)(updatedb);
|
||||
} else {
|
||||
(*pkcs11db->close)(pkcs11db);
|
||||
PORT_Free(secname);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
PORT_Free(secname);
|
||||
return pkcs11db;
|
||||
}
|
||||
|
||||
/* I'm sure we should do more checks here sometime... */
|
||||
pkcs11db = dbopen(dbName, readOnly ? NO_RDONLY : NO_RDWR, 0600, DB_HASH, 0);
|
||||
|
||||
/* didn't exist? create it */
|
||||
if (pkcs11db == NULL) {
|
||||
if (readOnly)
|
||||
return NULL;
|
||||
|
||||
pkcs11db = dbopen( dbName, NO_CREATE, 0600, DB_HASH, 0 );
|
||||
if (pkcs11db)
|
||||
(* pkcs11db->sync)(pkcs11db, 0);
|
||||
}
|
||||
return pkcs11db;
|
||||
}
|
||||
|
||||
static void
|
||||
secmod_CloseDB(DB *pkcs11db)
|
||||
{
|
||||
(*pkcs11db->close)(pkcs11db);
|
||||
}
|
||||
|
||||
static char *
|
||||
secmod_addEscape(const char *string, char quote)
|
||||
{
|
||||
char *newString = 0;
|
||||
int escapes = 0, size = 0;
|
||||
const char *src;
|
||||
char *dest;
|
||||
|
||||
for (src=string; *src ; src++) {
|
||||
if ((*src == quote) || (*src == '\\')) escapes++;
|
||||
size++;
|
||||
}
|
||||
|
||||
newString = PORT_ZAlloc(escapes+size+1);
|
||||
if (newString == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (src=string, dest=newString; *src; src++,dest++) {
|
||||
if ((*src == '\\') || (*src == quote)) {
|
||||
*dest++ = '\\';
|
||||
}
|
||||
*dest = *src;
|
||||
}
|
||||
|
||||
return newString;
|
||||
}
|
||||
|
||||
SECStatus legacy_AddSecmodDB(const char *appName, const char *filename,
|
||||
const char *dbname, char *module, PRBool rw);
|
||||
|
||||
#define SECMOD_STEP 10
|
||||
#define SFTK_DEFAULT_INTERNAL_INIT "library= name=\"NSS Internal PKCS #11 Module\" parameters=\"%s\" NSS=\"Flags=internal,critical trustOrder=75 cipherOrder=100 slotParams=(1={%s askpw=any timeout=30})\""
|
||||
/*
|
||||
* Read all the existing modules in
|
||||
*/
|
||||
char **
|
||||
legacy_ReadSecmodDB(const char *appName, const char *filename,
|
||||
const char *dbname, char *params, PRBool rw)
|
||||
{
|
||||
DBT key,data;
|
||||
int ret;
|
||||
DB *pkcs11db = NULL;
|
||||
char **moduleList = NULL, **newModuleList = NULL;
|
||||
int moduleCount = 1;
|
||||
int useCount = SECMOD_STEP;
|
||||
|
||||
moduleList = (char **) PORT_ZAlloc(useCount*sizeof(char **));
|
||||
if (moduleList == NULL) return NULL;
|
||||
|
||||
pkcs11db = secmod_OpenDB(appName,filename,dbname,PR_TRUE,rw);
|
||||
if (pkcs11db == NULL) goto done;
|
||||
|
||||
/* read and parse the file or data base */
|
||||
ret = (*pkcs11db->seq)(pkcs11db, &key, &data, R_FIRST);
|
||||
if (ret) goto done;
|
||||
|
||||
|
||||
do {
|
||||
char *moduleString;
|
||||
PRBool internal = PR_FALSE;
|
||||
if ((moduleCount+1) >= useCount) {
|
||||
useCount += SECMOD_STEP;
|
||||
newModuleList =
|
||||
(char **)PORT_Realloc(moduleList,useCount*sizeof(char *));
|
||||
if (newModuleList == NULL) goto done;
|
||||
moduleList = newModuleList;
|
||||
PORT_Memset(&moduleList[moduleCount+1],0,
|
||||
sizeof(char *)*SECMOD_STEP);
|
||||
}
|
||||
moduleString = secmod_DecodeData(params,&data,&internal);
|
||||
if (internal) {
|
||||
moduleList[0] = moduleString;
|
||||
} else {
|
||||
moduleList[moduleCount] = moduleString;
|
||||
moduleCount++;
|
||||
}
|
||||
} while ( (*pkcs11db->seq)(pkcs11db, &key, &data, R_NEXT) == 0);
|
||||
|
||||
done:
|
||||
if (!moduleList[0]) {
|
||||
char * newparams = secmod_addEscape(params,'"');
|
||||
if (newparams) {
|
||||
moduleList[0] = PR_smprintf(SFTK_DEFAULT_INTERNAL_INIT,newparams,
|
||||
SECMOD_SLOT_FLAGS);
|
||||
PORT_Free(newparams);
|
||||
}
|
||||
}
|
||||
/* deal with trust cert db here */
|
||||
|
||||
if (pkcs11db) {
|
||||
secmod_CloseDB(pkcs11db);
|
||||
} else if (moduleList[0] && rw) {
|
||||
legacy_AddSecmodDB(appName,filename,dbname,moduleList[0], rw) ;
|
||||
}
|
||||
if (!moduleList[0]) {
|
||||
PORT_Free(moduleList);
|
||||
moduleList = NULL;
|
||||
}
|
||||
return moduleList;
|
||||
}
|
||||
|
||||
SECStatus
|
||||
legacy_ReleaseSecmodDBData(const char *appName, const char *filename,
|
||||
const char *dbname, char **moduleSpecList, PRBool rw)
|
||||
{
|
||||
if (moduleSpecList) {
|
||||
char **index;
|
||||
for(index = moduleSpecList; *index; index++) {
|
||||
PR_smprintf_free(*index);
|
||||
}
|
||||
PORT_Free(moduleSpecList);
|
||||
}
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a module from the Data Base
|
||||
*/
|
||||
SECStatus
|
||||
legacy_DeleteSecmodDB(const char *appName, const char *filename,
|
||||
const char *dbname, char *args, PRBool rw)
|
||||
{
|
||||
DBT key;
|
||||
SECStatus rv = SECFailure;
|
||||
DB *pkcs11db = NULL;
|
||||
int ret;
|
||||
|
||||
if (!rw) return SECFailure;
|
||||
|
||||
/* make sure we have a db handle */
|
||||
pkcs11db = secmod_OpenDB(appName,filename,dbname,PR_FALSE,PR_FALSE);
|
||||
if (pkcs11db == NULL) {
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
rv = secmod_MakeKey(&key,args);
|
||||
if (rv != SECSuccess) goto done;
|
||||
rv = SECFailure;
|
||||
ret = (*pkcs11db->del)(pkcs11db, &key, 0);
|
||||
secmod_FreeKey(&key);
|
||||
if (ret != 0) goto done;
|
||||
|
||||
|
||||
ret = (*pkcs11db->sync)(pkcs11db, 0);
|
||||
if (ret == 0) rv = SECSuccess;
|
||||
|
||||
done:
|
||||
secmod_CloseDB(pkcs11db);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a module to the Data base
|
||||
*/
|
||||
SECStatus
|
||||
legacy_AddSecmodDB(const char *appName, const char *filename,
|
||||
const char *dbname, char *module, PRBool rw)
|
||||
{
|
||||
DBT key,data;
|
||||
SECStatus rv = SECFailure;
|
||||
DB *pkcs11db = NULL;
|
||||
int ret;
|
||||
|
||||
|
||||
if (!rw) return SECFailure;
|
||||
|
||||
/* make sure we have a db handle */
|
||||
pkcs11db = secmod_OpenDB(appName,filename,dbname,PR_FALSE,PR_FALSE);
|
||||
if (pkcs11db == NULL) {
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
rv = secmod_MakeKey(&key,module);
|
||||
if (rv != SECSuccess) goto done;
|
||||
rv = secmod_EncodeData(&data,module);
|
||||
if (rv != SECSuccess) {
|
||||
secmod_FreeKey(&key);
|
||||
goto done;
|
||||
}
|
||||
rv = SECFailure;
|
||||
ret = (*pkcs11db->put)(pkcs11db, &key, &data, 0);
|
||||
secmod_FreeKey(&key);
|
||||
secmod_FreeData(&data);
|
||||
if (ret != 0) goto done;
|
||||
|
||||
ret = (*pkcs11db->sync)(pkcs11db, 0);
|
||||
if (ret == 0) rv = SECSuccess;
|
||||
|
||||
done:
|
||||
secmod_CloseDB(pkcs11db);
|
||||
return rv;
|
||||
}
|
||||
@@ -1,341 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* The following code handles the storage of PKCS 11 modules used by the
|
||||
* NSS. This file is written to abstract away how the modules are
|
||||
* stored so we can deside that later.
|
||||
*/
|
||||
#include "sftkdb.h"
|
||||
#include "sdb.h"
|
||||
#include "prsystem.h"
|
||||
#include "prprf.h"
|
||||
#include "lgglue.h"
|
||||
#include "secerr.h"
|
||||
|
||||
static LGOpenFunc legacy_glue_open = NULL;
|
||||
static LGReadSecmodFunc legacy_glue_readSecmod = NULL;
|
||||
static LGReleaseSecmodFunc legacy_glue_releaseSecmod = NULL;
|
||||
static LGDeleteSecmodFunc legacy_glue_deleteSecmod = NULL;
|
||||
static LGAddSecmodFunc legacy_glue_addSecmod = NULL;
|
||||
static LGShutdownFunc legacy_glue_shutdown = NULL;
|
||||
|
||||
/*
|
||||
* The following 3 functions duplicate the work done by bl_LoadLibrary.
|
||||
* We should make bl_LoadLibrary a global and replace the call to
|
||||
* sftkdb_LoadLibrary(const char *libname) with it.
|
||||
*/
|
||||
#ifdef XP_UNIX
|
||||
#include <unistd.h>
|
||||
#define LG_MAX_LINKS 20
|
||||
static char *
|
||||
sftkdb_resolvePath(const char *orig)
|
||||
{
|
||||
int count = 0;
|
||||
int len =0;
|
||||
int ret = -1;
|
||||
char *resolved = NULL;
|
||||
char *source = NULL;
|
||||
|
||||
len = 1025; /* MAX PATH +1*/
|
||||
if (strlen(orig)+1 > len) {
|
||||
/* PATH TOO LONG */
|
||||
return NULL;
|
||||
}
|
||||
resolved = PORT_Alloc(len);
|
||||
if (!resolved) {
|
||||
return NULL;
|
||||
}
|
||||
source = PORT_Alloc(len);
|
||||
if (!source) {
|
||||
goto loser;
|
||||
}
|
||||
PORT_Strcpy(source, orig);
|
||||
/* Walk down all the links */
|
||||
while ( count++ < LG_MAX_LINKS) {
|
||||
char *tmp;
|
||||
/* swap our previous sorce out with resolved */
|
||||
/* read it */
|
||||
ret = readlink(source, resolved, len-1);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
resolved[ret] = 0;
|
||||
tmp = source; source = resolved; resolved = tmp;
|
||||
}
|
||||
if (count > 1) {
|
||||
ret = 0;
|
||||
}
|
||||
loser:
|
||||
if (resolved) {
|
||||
PORT_Free(resolved);
|
||||
}
|
||||
if (ret < 0) {
|
||||
if (source) {
|
||||
PORT_Free(source);
|
||||
source = NULL;
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static PRLibrary *
|
||||
sftkdb_LoadFromPath(const char *path, const char *libname)
|
||||
{
|
||||
char *c;
|
||||
int pathLen, nameLen, fullPathLen;
|
||||
char *fullPathName = NULL;
|
||||
PRLibSpec libSpec;
|
||||
PRLibrary *lib = NULL;
|
||||
|
||||
|
||||
/* strip of our parent's library name */
|
||||
c = strrchr(path, PR_GetDirectorySeparator());
|
||||
if (!c) {
|
||||
return NULL; /* invalid path */
|
||||
}
|
||||
pathLen = (c-path)+1;
|
||||
nameLen = strlen(libname);
|
||||
fullPathLen = pathLen + nameLen +1;
|
||||
fullPathName = (char *)PORT_Alloc(fullPathLen);
|
||||
if (fullPathName == NULL) {
|
||||
return NULL; /* memory allocation error */
|
||||
}
|
||||
PORT_Memcpy(fullPathName, path, pathLen);
|
||||
PORT_Memcpy(fullPathName+pathLen, libname, nameLen);
|
||||
fullPathName[fullPathLen-1] = 0;
|
||||
|
||||
libSpec.type = PR_LibSpec_Pathname;
|
||||
libSpec.value.pathname = fullPathName;
|
||||
lib = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL);
|
||||
PORT_Free(fullPathName);
|
||||
return lib;
|
||||
}
|
||||
|
||||
static PRLibrary *
|
||||
sftkdb_LoadLibrary(const char *libname)
|
||||
{
|
||||
PRLibrary *lib = NULL;
|
||||
PRFuncPtr fn_addr;
|
||||
char *parentLibPath = NULL;
|
||||
|
||||
fn_addr = (PRFuncPtr) &sftkdb_LoadLibrary;
|
||||
parentLibPath = PR_GetLibraryFilePathname(SOFTOKEN_LIB_NAME, fn_addr);
|
||||
|
||||
if (!parentLibPath) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
lib = sftkdb_LoadFromPath(parentLibPath, libname);
|
||||
#ifdef XP_UNIX
|
||||
/* handle symbolic link case */
|
||||
if (!lib) {
|
||||
char *trueParentLibPath = sftkdb_resolvePath(parentLibPath);
|
||||
if (!trueParentLibPath) {
|
||||
goto done;
|
||||
}
|
||||
lib = sftkdb_LoadFromPath(trueParentLibPath, libname);
|
||||
PORT_Free(trueParentLibPath);
|
||||
}
|
||||
#endif
|
||||
PORT_Free(parentLibPath);
|
||||
|
||||
done:
|
||||
/* still couldn't load it, try the generic path */
|
||||
if (!lib) {
|
||||
PRLibSpec libSpec;
|
||||
libSpec.type = PR_LibSpec_Pathname;
|
||||
libSpec.value.pathname = libname;
|
||||
lib = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL);
|
||||
}
|
||||
return lib;
|
||||
}
|
||||
|
||||
static PRLibrary *legacy_glue_lib = NULL;
|
||||
static SECStatus
|
||||
sftkdbLoad_Legacy()
|
||||
{
|
||||
PRLibrary *lib = NULL;
|
||||
LGSetCryptFunc setCryptFunction = NULL;
|
||||
|
||||
if (legacy_glue_lib) {
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
lib = sftkdb_LoadLibrary(SHLIB_PREFIX"lgdbm"SHLIB_VERSION"."SHLIB_SUFFIX);
|
||||
if (lib == NULL) {
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
legacy_glue_open = (LGOpenFunc)PR_FindFunctionSymbol(lib, "legacy_Open");
|
||||
legacy_glue_readSecmod = (LGReadSecmodFunc) PR_FindFunctionSymbol(lib,
|
||||
"legacy_ReadSecmodDB");
|
||||
legacy_glue_releaseSecmod = (LGReleaseSecmodFunc) PR_FindFunctionSymbol(lib,
|
||||
"legacy_ReleaseSecmodDBData");
|
||||
legacy_glue_deleteSecmod = (LGDeleteSecmodFunc) PR_FindFunctionSymbol(lib,
|
||||
"legacy_DeleteSecmodDB");
|
||||
legacy_glue_addSecmod = (LGAddSecmodFunc)PR_FindFunctionSymbol(lib,
|
||||
"legacy_AddSecmodDB");
|
||||
legacy_glue_shutdown = (LGShutdownFunc) PR_FindFunctionSymbol(lib,
|
||||
"legacy_Shutdown");
|
||||
setCryptFunction = (LGSetCryptFunc) PR_FindFunctionSymbol(lib,
|
||||
"legacy_SetCryptFunctions");
|
||||
|
||||
if (!legacy_glue_open || !legacy_glue_readSecmod ||
|
||||
!legacy_glue_releaseSecmod || !legacy_glue_deleteSecmod ||
|
||||
!legacy_glue_addSecmod || !setCryptFunction) {
|
||||
PR_UnloadLibrary(lib);
|
||||
return SECFailure;
|
||||
}
|
||||
setCryptFunction(sftkdb_encrypt_stub,sftkdb_decrypt_stub);
|
||||
legacy_glue_lib = lib;
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
CK_RV
|
||||
sftkdbCall_open(const char *dir, const char *certPrefix, const char *keyPrefix,
|
||||
int certVersion, int keyVersion, int flags,
|
||||
SDB **certDB, SDB **keyDB)
|
||||
{
|
||||
SECStatus rv;
|
||||
|
||||
rv = sftkdbLoad_Legacy();
|
||||
if (rv != SECSuccess) {
|
||||
return CKR_GENERAL_ERROR;
|
||||
}
|
||||
if (!legacy_glue_open) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
return (*legacy_glue_open)(dir, certPrefix, keyPrefix,
|
||||
certVersion, keyVersion,
|
||||
flags, certDB, keyDB);
|
||||
}
|
||||
|
||||
char **
|
||||
sftkdbCall_ReadSecmodDB(const char *appName, const char *filename,
|
||||
const char *dbname, char *params, PRBool rw)
|
||||
{
|
||||
SECStatus rv;
|
||||
|
||||
rv = sftkdbLoad_Legacy();
|
||||
if (rv != SECSuccess) {
|
||||
return NULL;
|
||||
}
|
||||
if (!legacy_glue_readSecmod) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
return (*legacy_glue_readSecmod)(appName, filename, dbname, params, rw);
|
||||
}
|
||||
|
||||
SECStatus
|
||||
sftkdbCall_ReleaseSecmodDBData(const char *appName,
|
||||
const char *filename, const char *dbname,
|
||||
char **moduleSpecList, PRBool rw)
|
||||
{
|
||||
SECStatus rv;
|
||||
|
||||
rv = sftkdbLoad_Legacy();
|
||||
if (rv != SECSuccess) {
|
||||
return rv;
|
||||
}
|
||||
if (!legacy_glue_releaseSecmod) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
return (*legacy_glue_releaseSecmod)(appName, filename, dbname,
|
||||
moduleSpecList, rw);
|
||||
}
|
||||
|
||||
SECStatus
|
||||
sftkdbCall_DeleteSecmodDB(const char *appName,
|
||||
const char *filename, const char *dbname,
|
||||
char *args, PRBool rw)
|
||||
{
|
||||
SECStatus rv;
|
||||
|
||||
rv = sftkdbLoad_Legacy();
|
||||
if (rv != SECSuccess) {
|
||||
return rv;
|
||||
}
|
||||
if (!legacy_glue_deleteSecmod) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
return (*legacy_glue_deleteSecmod)(appName, filename, dbname, args, rw);
|
||||
}
|
||||
|
||||
SECStatus
|
||||
sftkdbCall_AddSecmodDB(const char *appName,
|
||||
const char *filename, const char *dbname,
|
||||
char *module, PRBool rw)
|
||||
{
|
||||
SECStatus rv;
|
||||
|
||||
rv = sftkdbLoad_Legacy();
|
||||
if (rv != SECSuccess) {
|
||||
return rv;
|
||||
}
|
||||
if (!legacy_glue_addSecmod) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
return (*legacy_glue_addSecmod)(appName, filename, dbname, module, rw);
|
||||
}
|
||||
|
||||
CK_RV
|
||||
sftkdbCall_Shutdown(void)
|
||||
{
|
||||
CK_RV crv = CKR_OK;
|
||||
if (legacy_glue_lib) {
|
||||
return CKR_OK;
|
||||
}
|
||||
if (legacy_glue_shutdown) {
|
||||
crv = (*legacy_glue_shutdown)();
|
||||
}
|
||||
PR_UnloadLibrary(legacy_glue_lib);
|
||||
legacy_glue_lib = NULL;
|
||||
legacy_glue_open = NULL;
|
||||
legacy_glue_readSecmod = NULL;
|
||||
legacy_glue_releaseSecmod = NULL;
|
||||
legacy_glue_deleteSecmod = NULL;
|
||||
legacy_glue_addSecmod = NULL;
|
||||
return crv;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/*
|
||||
* This code defines the glue layer between softoken and the legacy DB library
|
||||
*/
|
||||
#include "sdb.h"
|
||||
|
||||
/*
|
||||
* function prototypes for the callbacks into softoken from the legacyDB
|
||||
*/
|
||||
|
||||
typedef SECStatus (*LGEncryptFunc)(PRArenaPool *arena, SDB *sdb,
|
||||
SECItem *plainText, SECItem **cipherText);
|
||||
typedef SECStatus (*LGDecryptFunc)(SDB *sdb, SECItem *cipherText,
|
||||
SECItem **plainText);
|
||||
|
||||
/*
|
||||
* function prototypes for the exported functions.
|
||||
*/
|
||||
typedef CK_RV (*LGOpenFunc) (const char *dir, const char *certPrefix,
|
||||
const char *keyPrefix,
|
||||
int certVersion, int keyVersion, int flags,
|
||||
SDB **certDB, SDB **keyDB);
|
||||
typedef char ** (*LGReadSecmodFunc)(const char *appName,
|
||||
const char *filename,
|
||||
const char *dbname, char *params, PRBool rw);
|
||||
typedef SECStatus (*LGReleaseSecmodFunc)(const char *appName,
|
||||
const char *filename,
|
||||
const char *dbname, char **params, PRBool rw);
|
||||
typedef SECStatus (*LGDeleteSecmodFunc)(const char *appName,
|
||||
const char *filename,
|
||||
const char *dbname, char *params, PRBool rw);
|
||||
typedef SECStatus (*LGAddSecmodFunc)(const char *appName,
|
||||
const char *filename,
|
||||
const char *dbname, char *params, PRBool rw);
|
||||
typedef SECStatus (*LGShutdownFunc)(void);
|
||||
typedef void (*LGSetCryptFunc)(LGEncryptFunc, LGDecryptFunc);
|
||||
|
||||
|
||||
/*
|
||||
* Softoken Glue Functions
|
||||
*/
|
||||
CK_RV sftkdbCall_open(const char *dir, const char *certPrefix,
|
||||
const char *keyPrefix,
|
||||
int certVersion, int keyVersion, int flags,
|
||||
SDB **certDB, SDB **keyDB);
|
||||
char ** sftkdbCall_ReadSecmodDB(const char *appName, const char *filename,
|
||||
const char *dbname, char *params, PRBool rw);
|
||||
SECStatus sftkdbCall_ReleaseSecmodDBData(const char *appName,
|
||||
const char *filename, const char *dbname,
|
||||
char **moduleSpecList, PRBool rw);
|
||||
SECStatus sftkdbCall_DeleteSecmodDB(const char *appName,
|
||||
const char *filename, const char *dbname,
|
||||
char *args, PRBool rw);
|
||||
SECStatus sftkdbCall_AddSecmodDB(const char *appName,
|
||||
const char *filename, const char *dbname,
|
||||
char *module, PRBool rw);
|
||||
CK_RV sftkdbCall_Shutdown(void);
|
||||
|
||||
@@ -1,517 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "lowkeyi.h"
|
||||
#include "secoid.h"
|
||||
#include "secitem.h"
|
||||
#include "secder.h"
|
||||
#include "base64.h"
|
||||
#include "secasn1.h"
|
||||
#include "secerr.h"
|
||||
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
#include "softoken.h"
|
||||
#endif
|
||||
|
||||
const SEC_ASN1Template nsslowkey_AttributeTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE,
|
||||
0, NULL, sizeof(NSSLOWKEYAttribute) },
|
||||
{ SEC_ASN1_OBJECT_ID, offsetof(NSSLOWKEYAttribute, attrType) },
|
||||
{ SEC_ASN1_SET_OF, offsetof(NSSLOWKEYAttribute, attrValue),
|
||||
SEC_AnyTemplate },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
const SEC_ASN1Template nsslowkey_SetOfAttributeTemplate[] = {
|
||||
{ SEC_ASN1_SET_OF, 0, nsslowkey_AttributeTemplate },
|
||||
};
|
||||
/* ASN1 Templates for new decoder/encoder */
|
||||
const SEC_ASN1Template nsslowkey_PrivateKeyInfoTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE,
|
||||
0, NULL, sizeof(NSSLOWKEYPrivateKeyInfo) },
|
||||
{ SEC_ASN1_INTEGER,
|
||||
offsetof(NSSLOWKEYPrivateKeyInfo,version) },
|
||||
{ SEC_ASN1_INLINE,
|
||||
offsetof(NSSLOWKEYPrivateKeyInfo,algorithm),
|
||||
SECOID_AlgorithmIDTemplate },
|
||||
{ SEC_ASN1_OCTET_STRING,
|
||||
offsetof(NSSLOWKEYPrivateKeyInfo,privateKey) },
|
||||
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
||||
offsetof(NSSLOWKEYPrivateKeyInfo, attributes),
|
||||
nsslowkey_SetOfAttributeTemplate },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
const SEC_ASN1Template nsslowkey_PQGParamsTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(PQGParams) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(PQGParams,prime) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(PQGParams,subPrime) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(PQGParams,base) },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
const SEC_ASN1Template nsslowkey_RSAPrivateKeyTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.version) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.modulus) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.publicExponent) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.privateExponent) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.prime1) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.prime2) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.exponent1) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.exponent2) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.coefficient) },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
|
||||
const SEC_ASN1Template nsslowkey_DSAPrivateKeyTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dsa.publicValue) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dsa.privateValue) },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
const SEC_ASN1Template nsslowkey_DSAPrivateKeyExportTemplate[] = {
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dsa.privateValue) },
|
||||
};
|
||||
|
||||
const SEC_ASN1Template nsslowkey_DHPrivateKeyTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.publicValue) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.privateValue) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.base) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.prime) },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
|
||||
/* XXX This is just a placeholder for later when we support
|
||||
* generic curves and need full-blown support for parsing EC
|
||||
* parameters. For now, we only support named curves in which
|
||||
* EC params are simply encoded as an object ID and we don't
|
||||
* use nsslowkey_ECParamsTemplate.
|
||||
*/
|
||||
const SEC_ASN1Template nsslowkey_ECParamsTemplate[] = {
|
||||
{ SEC_ASN1_CHOICE, offsetof(ECParams,type), NULL, sizeof(ECParams) },
|
||||
{ SEC_ASN1_OBJECT_ID, offsetof(ECParams,curveOID), NULL, ec_params_named },
|
||||
{ 0, }
|
||||
};
|
||||
|
||||
|
||||
/* NOTE: The SECG specification allows the private key structure
|
||||
* to contain curve parameters but recommends that they be stored
|
||||
* in the PrivateKeyAlgorithmIdentifier field of the PrivateKeyInfo
|
||||
* instead.
|
||||
*/
|
||||
const SEC_ASN1Template nsslowkey_ECPrivateKeyTemplate[] = {
|
||||
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
|
||||
{ SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.ec.version) },
|
||||
{ SEC_ASN1_OCTET_STRING,
|
||||
offsetof(NSSLOWKEYPrivateKey,u.ec.privateValue) },
|
||||
/* XXX The following template works for now since we only
|
||||
* support named curves for which the parameters are
|
||||
* encoded as an object ID. When we support generic curves,
|
||||
* we'll need to define nsslowkey_ECParamsTemplate
|
||||
*/
|
||||
#if 1
|
||||
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED |
|
||||
SEC_ASN1_EXPLICIT | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
||||
offsetof(NSSLOWKEYPrivateKey,u.ec.ecParams.curveOID),
|
||||
SEC_ObjectIDTemplate },
|
||||
#else
|
||||
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED |
|
||||
SEC_ASN1_EXPLICIT | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
||||
offsetof(NSSLOWKEYPrivateKey,u.ec.ecParams),
|
||||
nsslowkey_ECParamsTemplate },
|
||||
#endif
|
||||
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED |
|
||||
SEC_ASN1_EXPLICIT | SEC_ASN1_CONTEXT_SPECIFIC | 1,
|
||||
offsetof(NSSLOWKEYPrivateKey,u.ec.publicValue),
|
||||
SEC_BitStringTemplate },
|
||||
{ 0, }
|
||||
};
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
/*
|
||||
* See bugzilla bug 125359
|
||||
* Since NSS (via PKCS#11) wants to handle big integers as unsigned ints,
|
||||
* all of the templates above that en/decode into integers must be converted
|
||||
* from ASN.1's signed integer type. This is done by marking either the
|
||||
* source or destination (encoding or decoding, respectively) type as
|
||||
* siUnsignedInteger.
|
||||
*/
|
||||
|
||||
void
|
||||
prepare_low_rsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.rsa.modulus.type = siUnsignedInteger;
|
||||
key->u.rsa.publicExponent.type = siUnsignedInteger;
|
||||
key->u.rsa.privateExponent.type = siUnsignedInteger;
|
||||
key->u.rsa.prime1.type = siUnsignedInteger;
|
||||
key->u.rsa.prime2.type = siUnsignedInteger;
|
||||
key->u.rsa.exponent1.type = siUnsignedInteger;
|
||||
key->u.rsa.exponent2.type = siUnsignedInteger;
|
||||
key->u.rsa.coefficient.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_pqg_params_for_asn1(PQGParams *params)
|
||||
{
|
||||
params->prime.type = siUnsignedInteger;
|
||||
params->subPrime.type = siUnsignedInteger;
|
||||
params->base.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_dsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.dsa.publicValue.type = siUnsignedInteger;
|
||||
key->u.dsa.privateValue.type = siUnsignedInteger;
|
||||
key->u.dsa.params.prime.type = siUnsignedInteger;
|
||||
key->u.dsa.params.subPrime.type = siUnsignedInteger;
|
||||
key->u.dsa.params.base.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_dsa_priv_key_export_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.dsa.privateValue.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_dh_priv_key_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.dh.prime.type = siUnsignedInteger;
|
||||
key->u.dh.base.type = siUnsignedInteger;
|
||||
key->u.dh.publicValue.type = siUnsignedInteger;
|
||||
key->u.dh.privateValue.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
void
|
||||
prepare_low_ecparams_for_asn1(ECParams *params)
|
||||
{
|
||||
params->DEREncoding.type = siUnsignedInteger;
|
||||
params->curveOID.type = siUnsignedInteger;
|
||||
}
|
||||
|
||||
void
|
||||
prepare_low_ec_priv_key_for_asn1(NSSLOWKEYPrivateKey *key)
|
||||
{
|
||||
key->u.ec.version.type = siUnsignedInteger;
|
||||
key->u.ec.ecParams.DEREncoding.type = siUnsignedInteger;
|
||||
key->u.ec.ecParams.curveOID.type = siUnsignedInteger;
|
||||
key->u.ec.privateValue.type = siUnsignedInteger;
|
||||
key->u.ec.publicValue.type = siUnsignedInteger;
|
||||
}
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
|
||||
void
|
||||
nsslowkey_DestroyPrivateKey(NSSLOWKEYPrivateKey *privk)
|
||||
{
|
||||
if (privk && privk->arena) {
|
||||
PORT_FreeArena(privk->arena, PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsslowkey_DestroyPublicKey(NSSLOWKEYPublicKey *pubk)
|
||||
{
|
||||
if (pubk && pubk->arena) {
|
||||
PORT_FreeArena(pubk->arena, PR_FALSE);
|
||||
}
|
||||
}
|
||||
unsigned
|
||||
nsslowkey_PublicModulusLen(NSSLOWKEYPublicKey *pubk)
|
||||
{
|
||||
unsigned char b0;
|
||||
|
||||
/* interpret modulus length as key strength... in
|
||||
* fortezza that's the public key length */
|
||||
|
||||
switch (pubk->keyType) {
|
||||
case NSSLOWKEYRSAKey:
|
||||
b0 = pubk->u.rsa.modulus.data[0];
|
||||
return b0 ? pubk->u.rsa.modulus.len : pubk->u.rsa.modulus.len - 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned
|
||||
nsslowkey_PrivateModulusLen(NSSLOWKEYPrivateKey *privk)
|
||||
{
|
||||
|
||||
unsigned char b0;
|
||||
|
||||
switch (privk->keyType) {
|
||||
case NSSLOWKEYRSAKey:
|
||||
b0 = privk->u.rsa.modulus.data[0];
|
||||
return b0 ? privk->u.rsa.modulus.len : privk->u.rsa.modulus.len - 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSSLOWKEYPublicKey *
|
||||
nsslowkey_ConvertToPublicKey(NSSLOWKEYPrivateKey *privk)
|
||||
{
|
||||
NSSLOWKEYPublicKey *pubk;
|
||||
PLArenaPool *arena;
|
||||
|
||||
|
||||
arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE);
|
||||
if (arena == NULL) {
|
||||
PORT_SetError (SEC_ERROR_NO_MEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch(privk->keyType) {
|
||||
case NSSLOWKEYRSAKey:
|
||||
case NSSLOWKEYNullKey:
|
||||
pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
|
||||
sizeof (NSSLOWKEYPublicKey));
|
||||
if (pubk != NULL) {
|
||||
SECStatus rv;
|
||||
|
||||
pubk->arena = arena;
|
||||
pubk->keyType = privk->keyType;
|
||||
if (privk->keyType == NSSLOWKEYNullKey) return pubk;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.rsa.modulus,
|
||||
&privk->u.rsa.modulus);
|
||||
if (rv == SECSuccess) {
|
||||
rv = SECITEM_CopyItem (arena, &pubk->u.rsa.publicExponent,
|
||||
&privk->u.rsa.publicExponent);
|
||||
if (rv == SECSuccess)
|
||||
return pubk;
|
||||
}
|
||||
} else {
|
||||
PORT_SetError (SEC_ERROR_NO_MEMORY);
|
||||
}
|
||||
break;
|
||||
case NSSLOWKEYDSAKey:
|
||||
pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
|
||||
sizeof(NSSLOWKEYPublicKey));
|
||||
if (pubk != NULL) {
|
||||
SECStatus rv;
|
||||
|
||||
pubk->arena = arena;
|
||||
pubk->keyType = privk->keyType;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dsa.publicValue,
|
||||
&privk->u.dsa.publicValue);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dsa.params.prime,
|
||||
&privk->u.dsa.params.prime);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dsa.params.subPrime,
|
||||
&privk->u.dsa.params.subPrime);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dsa.params.base,
|
||||
&privk->u.dsa.params.base);
|
||||
if (rv == SECSuccess) return pubk;
|
||||
}
|
||||
break;
|
||||
case NSSLOWKEYDHKey:
|
||||
pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
|
||||
sizeof(NSSLOWKEYPublicKey));
|
||||
if (pubk != NULL) {
|
||||
SECStatus rv;
|
||||
|
||||
pubk->arena = arena;
|
||||
pubk->keyType = privk->keyType;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dh.publicValue,
|
||||
&privk->u.dh.publicValue);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dh.prime,
|
||||
&privk->u.dh.prime);
|
||||
if (rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.dh.base,
|
||||
&privk->u.dh.base);
|
||||
if (rv == SECSuccess) return pubk;
|
||||
}
|
||||
break;
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
case NSSLOWKEYECKey:
|
||||
pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
|
||||
sizeof(NSSLOWKEYPublicKey));
|
||||
if (pubk != NULL) {
|
||||
SECStatus rv;
|
||||
|
||||
pubk->arena = arena;
|
||||
pubk->keyType = privk->keyType;
|
||||
rv = SECITEM_CopyItem(arena, &pubk->u.ec.publicValue,
|
||||
&privk->u.ec.publicValue);
|
||||
if (rv != SECSuccess) break;
|
||||
pubk->u.ec.ecParams.arena = arena;
|
||||
/* Copy the rest of the params */
|
||||
rv = EC_CopyParams(arena, &(pubk->u.ec.ecParams),
|
||||
&(privk->u.ec.ecParams));
|
||||
if (rv == SECSuccess) return pubk;
|
||||
}
|
||||
break;
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
/* No Fortezza in Low Key implementations (Fortezza keys aren't
|
||||
* stored in our data base */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
PORT_FreeArena (arena, PR_FALSE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NSSLOWKEYPrivateKey *
|
||||
nsslowkey_CopyPrivateKey(NSSLOWKEYPrivateKey *privKey)
|
||||
{
|
||||
NSSLOWKEYPrivateKey *returnKey = NULL;
|
||||
SECStatus rv = SECFailure;
|
||||
PLArenaPool *poolp;
|
||||
|
||||
if(!privKey) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
poolp = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
|
||||
if(!poolp) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
returnKey = (NSSLOWKEYPrivateKey*)PORT_ArenaZAlloc(poolp, sizeof(NSSLOWKEYPrivateKey));
|
||||
if(!returnKey) {
|
||||
rv = SECFailure;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
returnKey->keyType = privKey->keyType;
|
||||
returnKey->arena = poolp;
|
||||
|
||||
switch(privKey->keyType) {
|
||||
case NSSLOWKEYRSAKey:
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.modulus),
|
||||
&(privKey->u.rsa.modulus));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.version),
|
||||
&(privKey->u.rsa.version));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.publicExponent),
|
||||
&(privKey->u.rsa.publicExponent));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.privateExponent),
|
||||
&(privKey->u.rsa.privateExponent));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.prime1),
|
||||
&(privKey->u.rsa.prime1));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.prime2),
|
||||
&(privKey->u.rsa.prime2));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.exponent1),
|
||||
&(privKey->u.rsa.exponent1));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.exponent2),
|
||||
&(privKey->u.rsa.exponent2));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.coefficient),
|
||||
&(privKey->u.rsa.coefficient));
|
||||
if(rv != SECSuccess) break;
|
||||
break;
|
||||
case NSSLOWKEYDSAKey:
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.publicValue),
|
||||
&(privKey->u.dsa.publicValue));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.privateValue),
|
||||
&(privKey->u.dsa.privateValue));
|
||||
if(rv != SECSuccess) break;
|
||||
returnKey->u.dsa.params.arena = poolp;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.params.prime),
|
||||
&(privKey->u.dsa.params.prime));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.params.subPrime),
|
||||
&(privKey->u.dsa.params.subPrime));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.params.base),
|
||||
&(privKey->u.dsa.params.base));
|
||||
if(rv != SECSuccess) break;
|
||||
break;
|
||||
case NSSLOWKEYDHKey:
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.dh.publicValue),
|
||||
&(privKey->u.dh.publicValue));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.dh.privateValue),
|
||||
&(privKey->u.dh.privateValue));
|
||||
if(rv != SECSuccess) break;
|
||||
returnKey->u.dsa.params.arena = poolp;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.dh.prime),
|
||||
&(privKey->u.dh.prime));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.dh.base),
|
||||
&(privKey->u.dh.base));
|
||||
if(rv != SECSuccess) break;
|
||||
break;
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
case NSSLOWKEYECKey:
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.ec.version),
|
||||
&(privKey->u.ec.version));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.ec.publicValue),
|
||||
&(privKey->u.ec.publicValue));
|
||||
if(rv != SECSuccess) break;
|
||||
rv = SECITEM_CopyItem(poolp, &(returnKey->u.ec.privateValue),
|
||||
&(privKey->u.ec.privateValue));
|
||||
if(rv != SECSuccess) break;
|
||||
returnKey->u.ec.ecParams.arena = poolp;
|
||||
/* Copy the rest of the params */
|
||||
rv = EC_CopyParams(poolp, &(returnKey->u.ec.ecParams),
|
||||
&(privKey->u.ec.ecParams));
|
||||
if (rv != SECSuccess) break;
|
||||
break;
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
default:
|
||||
rv = SECFailure;
|
||||
}
|
||||
|
||||
loser:
|
||||
|
||||
if(rv != SECSuccess) {
|
||||
PORT_FreeArena(poolp, PR_TRUE);
|
||||
returnKey = NULL;
|
||||
}
|
||||
|
||||
return returnKey;
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/* $Id: lowkeyi.h,v 1.10.70.3 2007-02-28 20:44:54 rrelyea%redhat.com Exp $ */
|
||||
|
||||
#ifndef _LOWKEYI_H_
|
||||
#define _LOWKEYI_H_
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "seccomon.h"
|
||||
#include "secoidt.h"
|
||||
#include "lowkeyti.h"
|
||||
|
||||
SEC_BEGIN_PROTOS
|
||||
|
||||
/*
|
||||
* See bugzilla bug 125359
|
||||
* Since NSS (via PKCS#11) wants to handle big integers as unsigned ints,
|
||||
* all of the templates above that en/decode into integers must be converted
|
||||
* from ASN.1's signed integer type. This is done by marking either the
|
||||
* source or destination (encoding or decoding, respectively) type as
|
||||
* siUnsignedInteger.
|
||||
*/
|
||||
extern void prepare_low_rsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
extern void prepare_low_pqg_params_for_asn1(PQGParams *params);
|
||||
extern void prepare_low_dsa_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
extern void prepare_low_dsa_priv_key_export_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
extern void prepare_low_dh_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
extern void prepare_low_ec_priv_key_for_asn1(NSSLOWKEYPrivateKey *key);
|
||||
extern void prepare_low_ecparams_for_asn1(ECParams *params);
|
||||
#endif /* NSS_ENABLE_ECC */
|
||||
|
||||
/*
|
||||
** Destroy a private key object.
|
||||
** "key" the object
|
||||
** "freeit" if PR_TRUE then free the object as well as its sub-objects
|
||||
*/
|
||||
extern void nsslowkey_DestroyPrivateKey(NSSLOWKEYPrivateKey *key);
|
||||
|
||||
/*
|
||||
** Destroy a public key object.
|
||||
** "key" the object
|
||||
** "freeit" if PR_TRUE then free the object as well as its sub-objects
|
||||
*/
|
||||
extern void nsslowkey_DestroyPublicKey(NSSLOWKEYPublicKey *key);
|
||||
|
||||
/*
|
||||
** Return the modulus length of "pubKey".
|
||||
*/
|
||||
extern unsigned int nsslowkey_PublicModulusLen(NSSLOWKEYPublicKey *pubKey);
|
||||
|
||||
|
||||
/*
|
||||
** Return the modulus length of "privKey".
|
||||
*/
|
||||
extern unsigned int nsslowkey_PrivateModulusLen(NSSLOWKEYPrivateKey *privKey);
|
||||
|
||||
|
||||
/*
|
||||
** Convert a low private key "privateKey" into a public low key
|
||||
*/
|
||||
extern NSSLOWKEYPublicKey
|
||||
*nsslowkey_ConvertToPublicKey(NSSLOWKEYPrivateKey *privateKey);
|
||||
|
||||
/* Make a copy of a low private key in it's own arena.
|
||||
* a return of NULL indicates an error.
|
||||
*/
|
||||
extern NSSLOWKEYPrivateKey *
|
||||
nsslowkey_CopyPrivateKey(NSSLOWKEYPrivateKey *privKey);
|
||||
|
||||
|
||||
SEC_END_PROTOS
|
||||
|
||||
#endif /* _LOWKEYI_H_ */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user