[pubcookie-dev] WEBISO CVS update: ryanc; PubCookieFilter.h,1.24,1.25 PubCookieFilter.sln,1.1,1.2 PubCookieFilter.vcproj,1.2,1.3 debug.c,1.11,1.12 debug.h,1.8,1.9 keyclient.vcproj,1.4,1.5 winkeyclient.c,1.6,1.7 winkeyclient.h,1.1,1.2

Ryan Campbell ryanc at cac.washington.edu
Thu Jan 22 21:00:29 PST 2004


Update of /usr/local/cvsroot/webiso/pubcookie/src/Win32
 In directory webiso-cvs.cac.washington.edu:/var/tmp/cvs-serv12267/Win32
 
 Modified Files:
 	PubCookieFilter.cpp PubCookieFilter.h PubCookieFilter.sln 
 	PubCookieFilter.vcproj debug.c debug.h keyclient.vcproj 
 	winkeyclient.c winkeyclient.h 
 Log Message:
 To prepare for multiple server configs, functions now pass the apache memory
 pool parameter p, which has been defined for Windows as type pubcookie_dir_rec.
 
 This allowed removal of some windows-specific code, but added some header
 complexity. May provide a small performance boost as some stack-allocated
 buffers were eliminated in favor of one new buffer in pubcookie_dir_rec.
 
 Windows pbc_myconfig functions now work for unicode or ansi strings.
 
 



Index: webiso/pubcookie/src/Win32/PubCookieFilter.cpp
diff -c webiso/pubcookie/src/Win32/PubCookieFilter.cpp:1.23 webiso/pubcookie/src/Win32/PubCookieFilter.cpp:1.24
*** webiso/pubcookie/src/Win32/PubCookieFilter.cpp:1.23	Wed Dec 17 14:10:56 2003
--- webiso/pubcookie/src/Win32/PubCookieFilter.cpp	Thu Jan 22 21:00:26 2004
***************
*** 4,10 ****
  //
  
  //
! //  $Id: PubCookieFilter.cpp,v 1.23 2003/12/17 22:10:56 ryanc Exp $
  //
  
  //#define COOKIE_PATH
--- 4,10 ----
  //
  
  //
! //  $Id: PubCookieFilter.cpp,v 1.24 2004/01/23 05:00:26 ryanc Exp $
  //
  
  //#define COOKIE_PATH
***************
*** 17,171 ****
  // #include <shfolder.h>  // For System Path, in Platform SDK
  #include <httpfilt.h>
  
- typedef void pool;
- 
  extern "C" 
  {
  #include <pem.h>
  #include "../pubcookie.h"
  #include "../libpubcookie.h"
- #include "../pbc_config.h"
  #include "../pbc_version.h"
  #include "../pbc_myconfig.h"
  #include "../pbc_configure.h"
- #include "PubCookieFilter.h"
  #include "debug.h"
  }
  
! pool *p=NULL;
  
- #define HDRSIZE 56
- 
- VOID filterlog(pubcookie_dir_rec *dcfg, int loglevel, const char *format, ...) {
- 	char source[HDRSIZE];
- 
- 	va_list   args;
- 
-     va_start(args, format);
- 	_snprintf(source,HDRSIZE,"Pubcookie-%s",dcfg->instance_id);
- 
-     filter_log_activity ( source, loglevel, format, args );
- 
-     va_end(args);
- }
- 
- bool logsource_exists(const char *source) {
- 
- 	HKEY hKey;
- 	UCHAR *DataBuff;
- 	DWORD dsize;
- 	DWORD retval;
- 	char SystemRootBuff[MAX_PATH+1];
- 	char strbuff[MAX_REG_BUFF];
- 	
- 	if (!(DataBuff = (UCHAR *)malloc(MAX_REG_BUFF))) {
- 		syslog(LOG_ERR,"Malloc failed in logsource_exists");
- 		return FALSE;
- 	}
- 	
- 	//First, check to see if key exists
- 	dsize = MAX_REG_BUFF;
- 	_snprintf(strbuff,MAX_REG_BUFF,"System\\CurrentControlSet\\Services\\Eventlog\\Application\\%s",source);
- 	
- 	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- 		strbuff,0,KEY_READ,&hKey) != ERROR_SUCCESS) {
- 		return FALSE;
- 	}
- 	
- 	//Then, make sure the Event Message File is the current one
- 	AddSystemRoot(p, SystemRootBuff,"\\inetsrv\\pubcookie\\pbc_messages.dll");
- 		
- 	if (retval = RegQueryValueEx(hKey, "EventMessageFile", NULL, NULL, DataBuff, &dsize)) {
- 		retval = strncmp((char *)DataBuff, SystemRootBuff, MAX_PATH);
- 	}
- 	RegCloseKey(hKey);
- 	free(DataBuff);
- 	
- 	if (retval != 0) {
- 		return FALSE;
- 	}
- 	
- 	return TRUE;
- 
- 
- 
- }
- 
- bool SetRegDWORD (HKEY hKey, LPCTSTR value, const DWORD setDWORD)
- {
- 	DWORD	dtype;
- 	DWORD	dsize;
- 	DWORD	retCode;
- 	
- 	
- 	dsize=sizeof(setDWORD);
- 	dtype=REG_DWORD;
- 	
- 	retCode = RegSetValueEx(hKey, value, NULL, dtype, (const UCHAR*)&setDWORD, dsize);
- 	if (retCode != ERROR_SUCCESS) {
-   //      printerror(retCode);
- 		return (false);
- 	}
- 	
- 	return (true);
- 	
- }
- 
- bool SetRegString (HKEY hKey, LPCTSTR value, LPCTSTR setstr)
- {
- 	DWORD	dtype;
- 	DWORD	dsize;
- 	DWORD	retCode;
- 	
- 	
- 	dsize=strlen(setstr);
- 	dtype=REG_SZ;
- 	
- 	retCode = RegSetValueEx(hKey, value, NULL, dtype, (const UCHAR *)setstr, dsize);
- 	if (retCode != ERROR_SUCCESS) {
- 		return (false);
- 	}
- 	
- 	return (true);
- 	
- }
- 
- VOID create_source(const char *source) {
- 	char keybuff[MAX_REG_BUFF];
- 	HKEY hKey;
- 	UCHAR *dataBuff;
- 	int dsize;
- 	char SystemRootBuff[MAX_PATH+1];
- 	DWORD retval;
- 
- 	if (!(dataBuff = (UCHAR *)malloc(MAX_REG_BUFF))) {
- 		syslog(LOG_ERR,"Malloc failed in create_source");
- 		return;
- 	}
- 
- 	dsize = MAX_REG_BUFF;
- 	_snprintf(keybuff,MAX_REG_BUFF,"System\\CurrentControlSet\\Services\\Eventlog\\Application\\%s",source);
- 
- 	if ((retval = RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
- 					keybuff,
- 					NULL,NULL,NULL,
- 					KEY_ALL_ACCESS,
- 					NULL,
- 					&hKey,
- 					NULL)) != ERROR_SUCCESS) {
- 		char fmtstr[512];
- 		FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,retval,0,fmtstr,512,NULL);
- 		syslog(LOG_ERR,"Cannot create logging source: %s\nError Message: %s",keybuff,fmtstr);
- 	}
- 
- 	SetRegString(hKey,"EventMessageFile", AddSystemRoot(p, SystemRootBuff,"\\inetsrv\\pubcookie\\pbc_messages.dll"));
- 	SetRegDWORD(hKey,"TypesSupported",7);
- 
- 	RegCloseKey(hKey);
- 
- 
- }
- 
  /**
   * get a random int used to bind the granting cookie and pre-session
   * @returns random int or -1 for error
--- 17,168 ----
  // #include <shfolder.h>  // For System Path, in Platform SDK
  #include <httpfilt.h>
  
  extern "C" 
  {
  #include <pem.h>
+ #include "../pbc_config.h"
  #include "../pubcookie.h"
+ #include "PubCookieFilter.h"
+ typedef pubcookie_dir_rec pool;
  #include "../libpubcookie.h"
  #include "../pbc_version.h"
  #include "../pbc_myconfig.h"
  #include "../pbc_configure.h"
  #include "debug.h"
  }
+ #define HDRSIZE 56
+ 
+ VOID filterlog(pubcookie_dir_rec *p, int loglevel, const char *format, ...) {
+ 	char source[HDRSIZE];
+ 
+ 	va_list   args;
+ 
+     va_start(args, format);
+ 	if (p) {  
+ 		_snprintf(source,HDRSIZE,"Pubcookie-%s",p->instance_id);
+ 	}
+ 	else
+ 	{
+ 		_snprintf(source,HDRSIZE,"Pubcookie");
+ 	}
+     filter_log_activity (p, source, loglevel, format, args );
+ 
+     va_end(args);
+ }
+ 
+ bool logsource_exists(pool *p, const char *source) {
+ 
+ 	HKEY hKey;
+ 	UCHAR *DataBuff;
+ 	DWORD dsize;
+ 	DWORD retval;
+ 	
+ 	if (!(DataBuff = (UCHAR *)malloc(MAX_REG_BUFF))) {
+ 		syslog(LOG_ERR,"Malloc failed in logsource_exists");
+ 		return FALSE;
+ 	}
+ 	
+ 	//First, check to see if key exists
+ 	dsize = MAX_REG_BUFF;
+ 	_snprintf(p->strbuff,MAX_REG_BUFF,"System\\CurrentControlSet\\Services\\Eventlog\\Application\\%s",source);
+ 	
+ 	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ 		p->strbuff,0,KEY_READ,&hKey) != ERROR_SUCCESS) {
+ 		return FALSE;
+ 	}
+ 	
+ 	//Then, make sure the Event Message File is the current one
+ 		
+ 	if (retval = RegQueryValueEx(hKey, "EventMessageFile", NULL, NULL, DataBuff, &dsize)) {
+ 		retval = strncmp((char *)DataBuff, AddSystemRoot(p, "\\inetsrv\\pubcookie\\pbc_messages.dll"), MAX_PATH);
+ 	}
+ 	RegCloseKey(hKey);
+ 	free(DataBuff);
+ 	
+ 	if (retval != 0) {
+ 		return FALSE;
+ 	}
+ 	
+ 	return TRUE;
+ 
+ 
+ 
+ }
+ 
+ bool SetRegDWORD (HKEY hKey, LPCTSTR value, const DWORD setDWORD)
+ {
+ 	DWORD	dtype;
+ 	DWORD	dsize;
+ 	DWORD	retCode;
+ 	
+ 	
+ 	dsize=sizeof(setDWORD);
+ 	dtype=REG_DWORD;
+ 	
+ 	retCode = RegSetValueEx(hKey, value, NULL, dtype, (const UCHAR*)&setDWORD, dsize);
+ 	if (retCode != ERROR_SUCCESS) {
+   //      printerror(retCode);
+ 		return (false);
+ 	}
+ 	
+ 	return (true);
+ 	
+ }
  
! bool SetRegString (HKEY hKey, LPCTSTR value, LPCTSTR setstr)
! {
! 	DWORD	dtype;
! 	DWORD	dsize;
! 	DWORD	retCode;
! 	
! 	
! 	dsize=strlen(setstr);
! 	dtype=REG_SZ;
! 	
! 	retCode = RegSetValueEx(hKey, value, NULL, dtype, (const UCHAR *)setstr, dsize);
! 	if (retCode != ERROR_SUCCESS) {
! 		return (false);
! 	}
! 	
! 	return (true);
! 	
! }
! 
! VOID create_source(pool *p, const char *source) {
! 	char keybuff[MAX_REG_BUFF];
! 	HKEY hKey;
! 	UCHAR *dataBuff;
! 	int dsize;
! 	DWORD retval;
! 
! 	if (!(dataBuff = (UCHAR *)malloc(MAX_REG_BUFF))) {
! 		syslog(LOG_ERR,"Malloc failed in create_source");
! 		return;
! 	}
! 
! 	dsize = MAX_REG_BUFF;
! 	_snprintf(keybuff,MAX_REG_BUFF,"System\\CurrentControlSet\\Services\\Eventlog\\Application\\%s",source);
! 
! 	if ((retval = RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
! 					keybuff,
! 					NULL,NULL,NULL,
! 					KEY_ALL_ACCESS,
! 					NULL,
! 					&hKey,
! 					NULL)) != ERROR_SUCCESS) {
! 		char fmtstr[512];
! 		FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,retval,0,fmtstr,512,NULL);
! 		syslog(LOG_ERR,"Cannot create logging source: %s\nError Message: %s",keybuff,fmtstr);
! 	}
! 
! 	SetRegString(hKey,"EventMessageFile", AddSystemRoot(p, "\\inetsrv\\pubcookie\\pbc_messages.dll"));
! 	SetRegDWORD(hKey,"TypesSupported",7);
! 
! 	RegCloseKey(hKey);
! 
! 
! }
  
  /**
   * get a random int used to bind the granting cookie and pre-session
   * @returns random int or -1 for error
***************
*** 173,188 ****
   */
  int get_pre_s_token(HTTP_FILTER_CONTEXT* pFC) {
      int i;
!     pubcookie_dir_rec   *dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 
      if( (i = libpbc_random_int(p)) == -1 ) {
!         filterlog(dcfg, LOG_ERR,	"get_pre_s_token: OpenSSL error");
      }
  
! 		filterlog(dcfg, LOG_INFO, "get_pre_s_token: token is %d\n", i);
      return(i);
  
  }
--- 170,185 ----
   */
  int get_pre_s_token(HTTP_FILTER_CONTEXT* pFC) {
      int i;
!     pubcookie_dir_rec   *p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 
      if( (i = libpbc_random_int(p)) == -1 ) {
!         filterlog(p, LOG_ERR,	"get_pre_s_token: OpenSSL error");
      }
  
! 		filterlog(p, LOG_INFO, "get_pre_s_token: token is %d\n", i);
      return(i);
  
  }
***************
*** 190,210 ****
  
  int get_pre_s_from_cookie(HTTP_FILTER_CONTEXT* pFC)
  {
!     pubcookie_dir_rec   *dcfg;
      pbc_cookie_data     *cookie_data = NULL;
      char 		*cookie = NULL;
  
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
      if( (cookie = Get_Cookie(pFC, PBC_PRE_S_COOKIENAME)) == NULL )
  
!         filterlog(dcfg, LOG_ERR,	"get_pre_s_from_cookie: no pre_s cookie, uri: %s\n", dcfg->uri);
      else
! 		cookie_data = libpbc_unbundle_cookie(p, cookie, dcfg->server_hostname, false);
  
      if( cookie_data == NULL ) {
!         filterlog(dcfg, LOG_ERR, "get_pre_s_from_cookie: can't unbundle pre_s cookie uri: %s\n", dcfg->uri);
! 	dcfg->failed = PBC_BAD_AUTH;
  	return -1;
      }
   
--- 187,207 ----
  
  int get_pre_s_from_cookie(HTTP_FILTER_CONTEXT* pFC)
  {
!     pubcookie_dir_rec   *p;
      pbc_cookie_data     *cookie_data = NULL;
      char 		*cookie = NULL;
  
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
      if( (cookie = Get_Cookie(pFC, PBC_PRE_S_COOKIENAME)) == NULL )
  
!         filterlog(p, LOG_ERR,	"get_pre_s_from_cookie: no pre_s cookie, uri: %s\n", p->uri);
      else
! 		cookie_data = libpbc_unbundle_cookie(p, cookie, p->server_hostname, false);
  
      if( cookie_data == NULL ) {
!         filterlog(p, LOG_ERR, "get_pre_s_from_cookie: can't unbundle pre_s cookie uri: %s\n", p->uri);
! 	p->failed = PBC_BAD_AUTH;
  	return -1;
      }
   
***************
*** 217,226 ****
  
  	char new_cookie[START_COOKIE_SIZE];
  	char secure_string[16];
!     pubcookie_dir_rec   *dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
  	if (secure) {
  		strncpy (secure_string,"; secure",15);
  	}
--- 214,223 ----
  
  	char new_cookie[START_COOKIE_SIZE];
  	char secure_string[16];
!     pubcookie_dir_rec   *p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
  	if (secure) {
  		strncpy (secure_string,"; secure",15);
  	}
***************
*** 239,257 ****
  	
  		pFC->AddResponseHeaders(pFC,new_cookie,0);
  
! 		filterlog(dcfg, LOG_INFO,"  Cleared Cookie %s\n",cookie_name);
  }
  
  int Redirect(HTTP_FILTER_CONTEXT* pFC, char* RUrl) {
      char    szBuff[2048];
  	DWORD	dwBuffSize;
!     pubcookie_dir_rec   *dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
      sprintf(szBuff,"Content-Type: text/html\r\n");
  		
! 	filterlog(dcfg, LOG_INFO," Redirect to %s",RUrl);
  
  	pFC->AddResponseHeaders(pFC,szBuff,0);
  
--- 236,254 ----
  	
  		pFC->AddResponseHeaders(pFC,new_cookie,0);
  
! 		filterlog(p, LOG_INFO,"  Cleared Cookie %s\n",cookie_name);
  }
  
  int Redirect(HTTP_FILTER_CONTEXT* pFC, char* RUrl) {
      char    szBuff[2048];
  	DWORD	dwBuffSize;
!     pubcookie_dir_rec   *p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
      sprintf(szBuff,"Content-Type: text/html\r\n");
  		
! 	filterlog(p, LOG_INFO," Redirect to %s",RUrl);
  
  	pFC->AddResponseHeaders(pFC,szBuff,0);
  
***************
*** 278,290 ****
  BOOL Pubcookie_Init () 
  {
  	int rslt;
  
  	// Need TCPIP for gethostname stuff
  	   
  	WSADATA wsaData;
  
! 	libpbc_config_init(p,"","");
! 
  	syslog(LOG_INFO,"Pubcookie_Init\n  %s\n",Pubcookie_Version);
  	
  	if ( rslt = WSAStartup((WORD)0x0101, &wsaData ) ) 
--- 275,288 ----
  BOOL Pubcookie_Init () 
  {
  	int rslt;
+ 	pool *p=NULL;
  
  	// Need TCPIP for gethostname stuff
  	   
  	WSADATA wsaData;
  
! 	libpbc_config_init(p,"","");
! 
  	syslog(LOG_INFO,"Pubcookie_Init\n  %s\n",Pubcookie_Version);
  	
  	if ( rslt = WSAStartup((WORD)0x0101, &wsaData ) ) 
***************
*** 295,310 ****
  
  	// Initialize Pubcookie Stuff
  
! 	if (!libpbc_pubcookie_init(p)) {
  		return FALSE;
  	}
! 
      return TRUE;
  
  }  /* Pubcookie_Init */
  
  // 'X' out the pubcookie cookies so the web page can't see them.
! void Blank_Cookie (HTTP_FILTER_CONTEXT* pFC,
  				   HTTP_FILTER_PREPROC_HEADERS* pHeaderInfo,
  				   char *name) 
  {
--- 293,308 ----
  
  	// Initialize Pubcookie Stuff
  
! 	if (!libpbc_pubcookie_init(p)) {
  		return FALSE;
  	}
! 
      return TRUE;
  
  }  /* Pubcookie_Init */
  
  // 'X' out the pubcookie cookies so the web page can't see them.
! void Blank_Cookie (HTTP_FILTER_CONTEXT* pFC,
  				   HTTP_FILTER_PREPROC_HEADERS* pHeaderInfo,
  				   char *name) 
  {
***************
*** 314,330 ****
  	char name_w_eq[256];
  	int pos;
  	DWORD cbSize, dwError;
!     pubcookie_dir_rec   *dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 	filterlog(dcfg, LOG_INFO," Blank_Cookie\n"); 
! 
  	cookie_data[0] = NULL;
  	cbSize = MAX_COOKIE_SIZE;
  	if (!pHeaderInfo->GetHeader(pFC,"Cookie:",cookie_data,&cbSize)) {
  		dwError = GetLastError();
! 		filterlog(dcfg, LOG_INFO," GetHeader[Cookie:] failed = %d (%x), buffer size= %d\n",
  			dwError,dwError,cbSize);
  		return;
  	}
--- 312,328 ----
  	char name_w_eq[256];
  	int pos;
  	DWORD cbSize, dwError;
!     pubcookie_dir_rec   *p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 	filterlog(p, LOG_INFO," Blank_Cookie\n"); 
! 
  	cookie_data[0] = NULL;
  	cbSize = MAX_COOKIE_SIZE;
  	if (!pHeaderInfo->GetHeader(pFC,"Cookie:",cookie_data,&cbSize)) {
  		dwError = GetLastError();
! 		filterlog(p, LOG_INFO," GetHeader[Cookie:] failed = %d (%x), buffer size= %d\n",
  			dwError,dwError,cbSize);
  		return;
  	}
***************
*** 369,379 ****
  int Hide_Cookies (HTTP_FILTER_CONTEXT* pFC,
  					  HTTP_FILTER_PREPROC_HEADERS* pHeaderInfo)
  {
!     pubcookie_dir_rec   *dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 	filterlog(dcfg, LOG_INFO," Hide_Cookies\n");
  
  	Blank_Cookie(pFC, pHeaderInfo, PBC_S_COOKIENAME);
      Blank_Cookie(pFC, pHeaderInfo, PBC_G_COOKIENAME);
--- 367,377 ----
  int Hide_Cookies (HTTP_FILTER_CONTEXT* pFC,
  					  HTTP_FILTER_PREPROC_HEADERS* pHeaderInfo)
  {
!     pubcookie_dir_rec   *p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 	filterlog(p, LOG_INFO," Hide_Cookies\n");
  
  	Blank_Cookie(pFC, pHeaderInfo, PBC_S_COOKIENAME);
      Blank_Cookie(pFC, pHeaderInfo, PBC_G_COOKIENAME);
***************
*** 400,410 ****
  void Add_Cookie (HTTP_FILTER_CONTEXT* pFC, char* cookie_name, unsigned char* cookie_contents, char* cookie_domain)
  {
  	char			szHeaders[PBC_1K];
!     pubcookie_dir_rec   *dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(dcfg, LOG_INFO,"  Adding cookie %s\n   domain=%s;\n   path=/;\n   secure;\n",cookie_name,cookie_domain);
  
  	snprintf(szHeaders, PBC_1K, "Set-Cookie: %s=%s; domain=%s; path=/; secure\r\n",
  		cookie_name, 
--- 398,408 ----
  void Add_Cookie (HTTP_FILTER_CONTEXT* pFC, char* cookie_name, unsigned char* cookie_contents, char* cookie_domain)
  {
  	char			szHeaders[PBC_1K];
!     pubcookie_dir_rec   *p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(p, LOG_INFO,"  Adding cookie %s\n   domain=%s;\n   path=/;\n   secure;\n",cookie_name,cookie_domain);
  
  	snprintf(szHeaders, PBC_1K, "Set-Cookie: %s=%s; domain=%s; path=/; secure\r\n",
  		cookie_name, 
***************
*** 424,458 ****
      unsigned char   *pre_s;
  	int				pre_sess_tok;
  
! 	pubcookie_dir_rec* dcfg;
  
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(dcfg, LOG_INFO," Auth_Failed\n");
  
  	/* reset these dippy flags */
! 	dcfg->failed = 0;
  
  	/* deal with GET args */
! 	if ( strlen(dcfg->args) > 0 ) {
! 		if ( strlen(dcfg->args) > sizeof(args) ) {  // ?? does base64 double size ??
! 			filterlog(dcfg, LOG_ERR,"[Pubcookie_Init] Invalid Args Length = %d; remote_host: %s",
! 				strlen(dcfg->args), dcfg->remote_host);
  			strcpy(args, "");
  		} else
! 			libpbc_base64_encode(p, (unsigned char *)dcfg->args, (unsigned char *)args,
! 						strlen(dcfg->args));
  		}
  	else
  		strcpy(args, "");
  
! 	strcpy(szTemp,dcfg->appsrvid);
! 	if ( strlen(dcfg->appsrv_port) > 0 ) {
  		strcat(szTemp,":");
! 		strcat(szTemp,dcfg->appsrv_port);
  	}
      if( (pre_sess_tok=get_pre_s_token(pFC)) == -1 ) {
! 		filterlog(dcfg, LOG_ERR,"Security Warning:  Unable to randomize pre-session cookie!");
          return(OK);
      }
  
--- 422,456 ----
      unsigned char   *pre_s;
  	int				pre_sess_tok;
  
! 	pubcookie_dir_rec* p;
  
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(p, LOG_INFO," Auth_Failed\n");
  
  	/* reset these dippy flags */
! 	p->failed = 0;
  
  	/* deal with GET args */
! 	if ( strlen(p->args) > 0 ) {
! 		if ( strlen(p->args) > sizeof(args) ) {  // ?? does base64 double size ??
! 			filterlog(p, LOG_ERR,"[Pubcookie_Init] Invalid Args Length = %d; remote_host: %s",
! 				strlen(p->args), p->remote_host);
  			strcpy(args, "");
  		} else
! 			libpbc_base64_encode(p, (unsigned char *)p->args, (unsigned char *)args,
! 						strlen(p->args));
  		}
  	else
  		strcpy(args, "");
  
! 	strcpy(szTemp,p->appsrvid);
! 	if ( strlen(p->appsrv_port) > 0 ) {
  		strcat(szTemp,":");
! 		strcat(szTemp,p->appsrv_port);
  	}
      if( (pre_sess_tok=get_pre_s_token(pFC)) == -1 ) {
! 		filterlog(p, LOG_ERR,"Security Warning:  Unable to randomize pre-session cookie!");
          return(OK);
      }
  
***************
*** 462,484 ****
  	sprintf(g_req_contents, 
  		"%s=%s&%s=%s&%s=%c&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%d&%s=%d", 
  		PBC_GETVAR_APPSRVID,
! 		  dcfg->server_hostname,   // Need full domain name 
  		PBC_GETVAR_APPID,
! 		  dcfg->appid,
  		PBC_GETVAR_CREDS, 
! 		  dcfg->AuthType, 
  		PBC_GETVAR_VERSION, 
  		  PBC_VERSION, 
  		PBC_GETVAR_METHOD, 
! 		  dcfg->method, 
  		PBC_GETVAR_HOST, 
  		  szTemp,
  		PBC_GETVAR_URI, 
! 		  dcfg->uri,
  		PBC_GETVAR_ARGS, 
  		  args,
  		PBC_GETVAR_SESSION_REAUTH,
! 		  dcfg->session_reauth,
  		PBC_GETVAR_PRE_SESS_TOK,
  		  pre_sess_tok);
  
--- 460,482 ----
  	sprintf(g_req_contents, 
  		"%s=%s&%s=%s&%s=%c&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%d&%s=%d", 
  		PBC_GETVAR_APPSRVID,
! 		  p->server_hostname,   // Need full domain name 
  		PBC_GETVAR_APPID,
! 		  p->appid,
  		PBC_GETVAR_CREDS, 
! 		  p->AuthType, 
  		PBC_GETVAR_VERSION, 
  		  PBC_VERSION, 
  		PBC_GETVAR_METHOD, 
! 		  p->method, 
  		PBC_GETVAR_HOST, 
  		  szTemp,
  		PBC_GETVAR_URI, 
! 		  p->uri,
  		PBC_GETVAR_ARGS, 
  		  args,
  		PBC_GETVAR_SESSION_REAUTH,
! 		  p->session_reauth,
  		PBC_GETVAR_PRE_SESS_TOK,
  		  pre_sess_tok);
  
***************
*** 486,492 ****
  	libpbc_base64_encode(p, (unsigned char *)g_req_contents, (unsigned char *)e_g_req_contents,
  				strlen(g_req_contents));
  
! 	Add_Cookie(pFC, PBC_G_REQ_COOKIENAME, e_g_req_contents, dcfg->Enterprise_Domain);
  
  	/* make the pre-session cookie */
      pre_s = libpbc_get_cookie(  
--- 484,490 ----
  	libpbc_base64_encode(p, (unsigned char *)g_req_contents, (unsigned char *)e_g_req_contents,
  				strlen(g_req_contents));
  
! 	Add_Cookie(pFC, PBC_G_REQ_COOKIENAME, e_g_req_contents, p->Enterprise_Domain);
  
  	/* make the pre-session cookie */
      pre_s = libpbc_get_cookie(  
***************
*** 495,554 ****
  		PBC_COOKIE_TYPE_PRE_S, 
  		PBC_CREDS_NONE, 
  		pre_sess_tok,
! 		(unsigned char *)dcfg->server_hostname, 
! 		(unsigned char *)dcfg->appid,
! 		dcfg->server_hostname,
  		0);
  	
!     Add_Cookie (pFC,PBC_PRE_S_COOKIENAME,pre_s,dcfg->appsrvid);
  	
  	Add_No_Cache(pFC);
  
! 	return (Redirect(pFC,dcfg->Login_URI));
  
  }  /* Auth_Failed */
  
  
  int Bad_User (HTTP_FILTER_CONTEXT* pFC)
  {
! 	char szTemp[1024];
! 	DWORD dwSize;
! 	pubcookie_dir_rec* dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 
! 	filterlog(dcfg, LOG_INFO," Bad_User\n"); 
! 
! 	if ( strlen(dcfg->Error_Page) == 0 ) {
! 
! 		pFC->ServerSupportFunction(pFC,SF_REQ_SEND_RESPONSE_HEADER,
! 								"200 OK",NULL,NULL);
! 
! 		sprintf(szTemp,"<B> User Authentication Failed!<br><br>"
! 			           " Please contact <a href=\"mailto:ntadmin@%s\">ntadmin@%s</a> </B> <br>",
! 			dcfg->server_hostname,dcfg->server_hostname);
! 		dwSize=strlen(szTemp);
! 
! 		pFC->WriteClient (pFC, szTemp, &dwSize, 0);
! 
! 	} else {
! 		Redirect(pFC, dcfg->Error_Page);
! 	}
! 
! 	return OK;
  
  }  /* Bad_User */
  
  
! int Is_Pubcookie_Auth (pubcookie_dir_rec *dcfg)
  {
! 	if ( dcfg->AuthType != AUTH_NONE ) {
! 		filterlog(dcfg, LOG_INFO," Is_Pubcookie_Auth: True");
  		return TRUE;
  	}
  	else {
! 		filterlog(dcfg, LOG_INFO," Is_Pubcookie_Auth: False");
  		return FALSE;
  	}
  
--- 493,552 ----
  		PBC_COOKIE_TYPE_PRE_S, 
  		PBC_CREDS_NONE, 
  		pre_sess_tok,
! 		(unsigned char *)p->server_hostname, 
! 		(unsigned char *)p->appid,
! 		p->server_hostname,
  		0);
  	
!     Add_Cookie (pFC,PBC_PRE_S_COOKIENAME,pre_s,p->appsrvid);
  	
  	Add_No_Cache(pFC);
  
! 	return (Redirect(pFC,p->Login_URI));
  
  }  /* Auth_Failed */
  
  
  int Bad_User (HTTP_FILTER_CONTEXT* pFC)
  {
! 	char szTemp[1024];
! 	DWORD dwSize;
! 	pubcookie_dir_rec* p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 
! 	filterlog(p, LOG_INFO," Bad_User\n"); 
! 
! 	if ( strlen(p->Error_Page) == 0 ) {
! 
! 		pFC->ServerSupportFunction(pFC,SF_REQ_SEND_RESPONSE_HEADER,
! 								"200 OK",NULL,NULL);
! 
! 		sprintf(szTemp,"<B> User Authentication Failed!<br><br>"
! 			           " Please contact <a href=\"mailto:ntadmin@%s\">ntadmin@%s</a> </B> <br>",
! 			p->server_hostname,p->server_hostname);
! 		dwSize=strlen(szTemp);
! 
! 		pFC->WriteClient (pFC, szTemp, &dwSize, 0);
! 
! 	} else {
! 		Redirect(pFC, p->Error_Page);
! 	}
! 
! 	return OK;
  
  }  /* Bad_User */
  
  
! int Is_Pubcookie_Auth (pubcookie_dir_rec *p)
  {
! 	if ( p->AuthType != AUTH_NONE ) {
! 		filterlog(p, LOG_INFO," Is_Pubcookie_Auth: True");
  		return TRUE;
  	}
  	else {
! 		filterlog(p, LOG_INFO," Is_Pubcookie_Auth: False");
  		return FALSE;
  	}
  
***************
*** 559,574 ****
  /* b is from the module                                                       */
  int Pubcookie_Check_Version (HTTP_FILTER_CONTEXT* pFC, unsigned char *a, unsigned char *b) 
  {
!     pubcookie_dir_rec   *dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 	filterlog(dcfg, LOG_DEBUG," Pubcookie_Check_Version\n");
  
  	if ( a[0] == b[0] && a[1] == b[1] )
  		return 1;
  	if ( a[0] == b[0] && a[1] != b[1] ) {
! 		filterlog(dcfg, LOG_ERR,"[Pubcookie_Check_Version] Minor version mismatch cookie: %s your version: %s", a, b);
  		return 1;
  	}
  
--- 557,572 ----
  /* b is from the module                                                       */
  int Pubcookie_Check_Version (HTTP_FILTER_CONTEXT* pFC, unsigned char *a, unsigned char *b) 
  {
!     pubcookie_dir_rec   *p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 	filterlog(p, LOG_DEBUG," Pubcookie_Check_Version\n");
  
  	if ( a[0] == b[0] && a[1] == b[1] )
  		return 1;
  	if ( a[0] == b[0] && a[1] != b[1] ) {
! 		filterlog(p, LOG_ERR,"[Pubcookie_Check_Version] Minor version mismatch cookie: %s your version: %s", a, b);
  		return 1;
  	}
  
***************
*** 580,595 ****
  /* check and see if whatever has timed out                                    */
  int Pubcookie_Check_Exp(HTTP_FILTER_CONTEXT* pFC, time_t fromc, int exp)
  {
!     pubcookie_dir_rec   *dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
  	if ( (fromc + exp) > time(NULL) ) {
! 		filterlog(dcfg, LOG_INFO," Pubcookie_Check_Exp: True");
  		return 1;
  	}
  	else {
! 		filterlog(dcfg, LOG_INFO," Pubcookie_Check_Exp: False");
  		return 0;
  	}
  
--- 578,593 ----
  /* check and see if whatever has timed out                                    */
  int Pubcookie_Check_Exp(HTTP_FILTER_CONTEXT* pFC, time_t fromc, int exp)
  {
!     pubcookie_dir_rec   *p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
  	if ( (fromc + exp) > time(NULL) ) {
! 		filterlog(p, LOG_INFO," Pubcookie_Check_Exp: True");
  		return 1;
  	}
  	else {
! 		filterlog(p, LOG_INFO," Pubcookie_Check_Exp: False");
  		return 0;
  	}
  
***************
*** 604,621 ****
  	char name_w_eq [256];
  	char *cookie, *ptr;
  	DWORD cbSize, dwError;
!     pubcookie_dir_rec   *dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
  	cookie_data[0] = NULL;
  	cbSize = MAX_COOKIE_SIZE;
  	if (!pFC->GetServerVariable(pFC,"HTTP_COOKIE",cookie_data,&cbSize)) {
  		dwError = GetLastError();
! 		filterlog(dcfg, LOG_DEBUG," GetServerVariable[HTTP_COOKIE] failed = %d (%x), buffer size= %d\n",
  			dwError,dwError,cbSize);
  		if ( dwError == ERROR_INSUFFICIENT_BUFFER) {  // Should quit if too much cookie
! 			filterlog(dcfg, LOG_ERR,"[Get_Cookie] Cookie Data too large : %d", cbSize);
  	//		return ERROR_INSUFFICIENT_BUFFER
  		}
  	//	else	
--- 602,619 ----
  	char name_w_eq [256];
  	char *cookie, *ptr;
  	DWORD cbSize, dwError;
!     pubcookie_dir_rec   *p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
  	cookie_data[0] = NULL;
  	cbSize = MAX_COOKIE_SIZE;
  	if (!pFC->GetServerVariable(pFC,"HTTP_COOKIE",cookie_data,&cbSize)) {
  		dwError = GetLastError();
! 		filterlog(p, LOG_DEBUG," GetServerVariable[HTTP_COOKIE] failed = %d (%x), buffer size= %d\n",
  			dwError,dwError,cbSize);
  		if ( dwError == ERROR_INSUFFICIENT_BUFFER) {  // Should quit if too much cookie
! 			filterlog(p, LOG_ERR,"[Get_Cookie] Cookie Data too large : %d", cbSize);
  	//		return ERROR_INSUFFICIENT_BUFFER
  		}
  	//	else	
***************
*** 626,639 ****
  	strcpy(name_w_eq,name);
  	strcat(name_w_eq,"=");
  
! 	filterlog(dcfg, LOG_DEBUG,"  Looking for cookie name '%s' in (%d) (first 3000 bytes)\n%.3000s\n",
  		name_w_eq,strlen(cookie_data),cookie_data);
  
  	/* find the one that's pubcookie */
  
      if (!(cookie_header = strstr(cookie_data, name_w_eq))) {
  
! 		filterlog(dcfg, LOG_INFO, " Get_Cookie: %s : Not Found",name);
  		return NULL;
  	}
  	cookie_header += strlen(name_w_eq);
--- 624,637 ----
  	strcpy(name_w_eq,name);
  	strcat(name_w_eq,"=");
  
! 	filterlog(p, LOG_DEBUG,"  Looking for cookie name '%s' in (%d) (first 3000 bytes)\n%.3000s\n",
  		name_w_eq,strlen(cookie_data),cookie_data);
  
  	/* find the one that's pubcookie */
  
      if (!(cookie_header = strstr(cookie_data, name_w_eq))) {
  
! 		filterlog(p, LOG_INFO, " Get_Cookie: %s : Not Found",name);
  		return NULL;
  	}
  	cookie_header += strlen(name_w_eq);
***************
*** 647,653 ****
  	
      cookie = (char *)pbc_malloc(p, strlen(cookie_header)+1);
  	if (!cookie) {
! 		filterlog(dcfg, LOG_ERR,"[Get_Cookie] Error allocating memory");
  		return NULL;
  	}
  
--- 645,651 ----
  	
      cookie = (char *)pbc_malloc(p, strlen(cookie_header)+1);
  	if (!cookie) {
! 		filterlog(p, LOG_ERR,"[Get_Cookie] Error allocating memory");
  		return NULL;
  	}
  
***************
*** 655,751 ****
  
  //	Blank_Cookie (name);   // Why Blank it ??
  
! 		filterlog(dcfg, LOG_INFO, " Get_Cookie: %s : Found",name);
  
  	return cookie;
  
  }  /* Get_Cookie */
  
! void Read_Reg_Values (char *key, pubcookie_dir_rec* dcfg)
  {
  	HKEY hKey;
  	DWORD dwRead;
  	long rslt;
! 	char authname[512];
! 	char strbuff[MAX_REG_BUFF];
  
  	if (rslt = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  		key,0,KEY_READ,&hKey) == ERROR_SUCCESS)
  	{
! 		dwRead = sizeof (dcfg->pszUser);
  		RegQueryValueEx (hKey, "NTUserId",
! 			NULL, NULL, (LPBYTE) dcfg->pszUser, &dwRead);
  		
! 		dwRead = sizeof (dcfg->pszPassword);
  		RegQueryValueEx (hKey, "Password", 
! 			NULL, NULL, (LPBYTE) dcfg->pszPassword, &dwRead);
  		
! 		dwRead = sizeof (dcfg->inact_exp);
  		RegQueryValueEx (hKey, "Inactive_Timeout",
! 			NULL, NULL, (LPBYTE) &dcfg->inact_exp, &dwRead);
  		
! 		dwRead = sizeof (dcfg->hard_exp);
  		RegQueryValueEx (hKey, "Hard_Timeout",
! 			NULL, NULL, (LPBYTE) &dcfg->hard_exp, &dwRead);
  		
! 		dwRead = sizeof (dcfg->force_reauth);
  		RegQueryValueEx (hKey, "Force_Reauth",
! 			NULL, NULL, (LPBYTE) dcfg->force_reauth, &dwRead);
  		
! 		dwRead = sizeof (dcfg->session_reauth);
  		RegQueryValueEx (hKey, "Session_Reauth",
! 			NULL, NULL, (LPBYTE) &dcfg->session_reauth, &dwRead);
  		
! 		dwRead = sizeof (dcfg->logout_action);
  			RegQueryValueEx (hKey, "Logout_Action",
! 							 NULL, NULL, (LPBYTE) &dcfg->logout_action, &dwRead);
  		
  		dwRead = sizeof (authname); authname[0] = NULL;
  		RegQueryValueEx (hKey, "AuthType",
  			NULL, NULL, (LPBYTE) authname, &dwRead);
  		if ( strlen(authname) > 0 ) {
  			if ( stricmp(authname,(PBC_AUTHTYPE1)) == 0 ) 
! 				dcfg->AuthType = AUTH_NETID;
  			else
  				if ( stricmp(authname,(PBC_AUTHTYPE3))== 0 ) 
! 					dcfg->AuthType = AUTH_SECURID;
  				else
  					if ( stricmp(authname,(PBC_AUTHTYPE0)) == 0 )
! 						dcfg->AuthType = AUTH_NONE;
  		}
  
! 		dwRead = sizeof (dcfg->default_url);
  		RegQueryValueEx (hKey, "Default_Url",
! 			NULL, NULL, (LPBYTE) dcfg->default_url, &dwRead);
  		
! 		dwRead = sizeof (dcfg->timeout_url);
  		RegQueryValueEx (hKey, "Timeout_Url",
! 			NULL, NULL, (LPBYTE) dcfg->timeout_url, &dwRead);
  		
! 		dwRead = sizeof (dcfg->Login_URI);
  		RegQueryValueEx (hKey, "Web_Login",
! 			NULL, NULL, (LPBYTE) dcfg->Login_URI, &dwRead);
  		RegQueryValueEx (hKey, "Login_URI",
! 			NULL, NULL, (LPBYTE) dcfg->Login_URI, &dwRead);
  
! 		dwRead = sizeof (dcfg->Enterprise_Domain);
  		RegQueryValueEx (hKey, "Enterprise_Domain",
! 			NULL, NULL, (LPBYTE) dcfg->Enterprise_Domain, &dwRead);
! 		dwRead = sizeof (dcfg->Error_Page);
  		RegQueryValueEx (hKey, "Error_Page",
! 			NULL, NULL, (LPBYTE) dcfg->Error_Page, &dwRead);
! 		dwRead = sizeof (dcfg->Set_Server_Values);
  		RegQueryValueEx (hKey, "SetHeaderValues",
! 			NULL, NULL, (LPBYTE) &dcfg->Set_Server_Values, &dwRead);
  
  #	ifndef COOKIE_PATH
! 		dwRead = sizeof (dcfg->appid);
  		RegQueryValueEx (hKey, "AppId",
! 			NULL, NULL, (LPBYTE) dcfg->appid, &dwRead);
  #	endif		
  		
! 		if (dcfg->logout_action != LOGOUT_NONE) {   //Local logout cannot be authenticated. Redirect could, but isn't
! 			dcfg->AuthType = AUTH_NONE;
  		}
  		
  	}
--- 653,748 ----
  
  //	Blank_Cookie (name);   // Why Blank it ??
  
! 		filterlog(p, LOG_INFO, " Get_Cookie: %s : Found",name);
  
  	return cookie;
  
  }  /* Get_Cookie */
  
! void Read_Reg_Values (char *key, pubcookie_dir_rec* p)
  {
  	HKEY hKey;
  	DWORD dwRead;
  	long rslt;
! 	char authname[512];
  
  	if (rslt = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  		key,0,KEY_READ,&hKey) == ERROR_SUCCESS)
  	{
! 		dwRead = sizeof (p->pszUser);
  		RegQueryValueEx (hKey, "NTUserId",
! 			NULL, NULL, (LPBYTE) p->pszUser, &dwRead);
  		
! 		dwRead = sizeof (p->pszPassword);
  		RegQueryValueEx (hKey, "Password", 
! 			NULL, NULL, (LPBYTE) p->pszPassword, &dwRead);
  		
! 		dwRead = sizeof (p->inact_exp);
  		RegQueryValueEx (hKey, "Inactive_Timeout",
! 			NULL, NULL, (LPBYTE) &p->inact_exp, &dwRead);
  		
! 		dwRead = sizeof (p->hard_exp);
  		RegQueryValueEx (hKey, "Hard_Timeout",
! 			NULL, NULL, (LPBYTE) &p->hard_exp, &dwRead);
  		
! 		dwRead = sizeof (p->force_reauth);
  		RegQueryValueEx (hKey, "Force_Reauth",
! 			NULL, NULL, (LPBYTE) p->force_reauth, &dwRead);
  		
! 		dwRead = sizeof (p->session_reauth);
  		RegQueryValueEx (hKey, "Session_Reauth",
! 			NULL, NULL, (LPBYTE) &p->session_reauth, &dwRead);
  		
! 		dwRead = sizeof (p->logout_action);
  			RegQueryValueEx (hKey, "Logout_Action",
! 							 NULL, NULL, (LPBYTE) &p->logout_action, &dwRead);
  		
  		dwRead = sizeof (authname); authname[0] = NULL;
  		RegQueryValueEx (hKey, "AuthType",
  			NULL, NULL, (LPBYTE) authname, &dwRead);
  		if ( strlen(authname) > 0 ) {
  			if ( stricmp(authname,(PBC_AUTHTYPE1)) == 0 ) 
! 				p->AuthType = AUTH_NETID;
  			else
  				if ( stricmp(authname,(PBC_AUTHTYPE3))== 0 ) 
! 					p->AuthType = AUTH_SECURID;
  				else
  					if ( stricmp(authname,(PBC_AUTHTYPE0)) == 0 )
! 						p->AuthType = AUTH_NONE;
  		}
  
! 		dwRead = sizeof (p->default_url);
  		RegQueryValueEx (hKey, "Default_Url",
! 			NULL, NULL, (LPBYTE) p->default_url, &dwRead);
  		
! 		dwRead = sizeof (p->timeout_url);
  		RegQueryValueEx (hKey, "Timeout_Url",
! 			NULL, NULL, (LPBYTE) p->timeout_url, &dwRead);
  		
! 		dwRead = sizeof (p->Login_URI);
  		RegQueryValueEx (hKey, "Web_Login",
! 			NULL, NULL, (LPBYTE) p->Login_URI, &dwRead);
  		RegQueryValueEx (hKey, "Login_URI",
! 			NULL, NULL, (LPBYTE) p->Login_URI, &dwRead);
  
! 		dwRead = sizeof (p->Enterprise_Domain);
  		RegQueryValueEx (hKey, "Enterprise_Domain",
! 			NULL, NULL, (LPBYTE) p->Enterprise_Domain, &dwRead);
! 		dwRead = sizeof (p->Error_Page);
  		RegQueryValueEx (hKey, "Error_Page",
! 			NULL, NULL, (LPBYTE) p->Error_Page, &dwRead);
! 		dwRead = sizeof (p->Set_Server_Values);
  		RegQueryValueEx (hKey, "SetHeaderValues",
! 			NULL, NULL, (LPBYTE) &p->Set_Server_Values, &dwRead);
  
  #	ifndef COOKIE_PATH
! 		dwRead = sizeof (p->appid);
  		RegQueryValueEx (hKey, "AppId",
! 			NULL, NULL, (LPBYTE) p->appid, &dwRead);
  #	endif		
  		
! 		if (p->logout_action != LOGOUT_NONE) {   //Local logout cannot be authenticated. Redirect could, but isn't
! 			p->AuthType = AUTH_NONE;
  		}
  		
  	}
***************
*** 760,788 ****
  {
  	char key[1024+MAX_PATH], szBuff[1025];
  	char *pachUrl;
! 	pubcookie_dir_rec* dcfg;
! 	DWORD dwBufferSize = 1024;
! 	char strbuff[MAX_REG_BUFF];
  
- 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
- 
  	// Initialize default values  
  	// These can be overriden in /default
  
! 	dcfg->inact_exp = PBC_DEFAULT_INACT_EXPIRE;
! 	dcfg->hard_exp  = PBC_DEFAULT_HARD_EXPIRE;
  
! 	strcpy(dcfg->pszUser,"");
! 	strcpy(dcfg->pszPassword,"");
! 	strcpy(dcfg->force_reauth,PBC_NO_FORCE_REAUTH);
! 	dcfg->session_reauth = 0;
! 	dcfg->AuthType = AUTH_NONE;
! 	dcfg->logout_action = LOGOUT_NONE;
! 	strcpy(dcfg->Enterprise_Domain,(PBC_ENTRPRS_DOMAIN));
! 	strcpy(dcfg->Login_URI, (PBC_LOGIN_URI));
! 	strcpy(dcfg->Error_Page,"");
! 	dcfg->Set_Server_Values = false;
! 	dcfg->legacy = false;
  	
      // Then Look in default key
  	
--- 757,784 ----
  {
  	char key[1024+MAX_PATH], szBuff[1025];
  	char *pachUrl;
! 	pubcookie_dir_rec* p;
! 	DWORD dwBufferSize = 1024;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
  	// Initialize default values  
  	// These can be overriden in /default
  
! 	p->inact_exp = PBC_DEFAULT_INACT_EXPIRE;
! 	p->hard_exp  = PBC_DEFAULT_HARD_EXPIRE;
  
! 	strcpy(p->pszUser,"");
! 	strcpy(p->pszPassword,"");
! 	strcpy(p->force_reauth,PBC_NO_FORCE_REAUTH);
! 	p->session_reauth = 0;
! 	p->AuthType = AUTH_NONE;
! 	p->logout_action = LOGOUT_NONE;
! 	strcpy(p->Enterprise_Domain,(PBC_ENTRPRS_DOMAIN));
! 	strcpy(p->Login_URI, (PBC_LOGIN_URI));
! 	strcpy(p->Error_Page,"");
! 	p->Set_Server_Values = false;
! 	p->legacy = false;
  	
      // Then Look in default key
  	
***************
*** 790,805 ****
  	strcat (key,"\\");
  	strcat (key, PBC_DEFAULT_KEY);
  
! 	Read_Reg_Values (key, dcfg);
  
  
  	// Then first node (current appid)
  
  	strcpy (key, PBC_WEB_VAR_LOCATION);
  	strcat (key,"\\");
! 	strcat (key, dcfg->appid);
! 
! 	Read_Reg_Values (key, dcfg);
  
  	// Then any app/subdirectory/file settings
  
--- 786,801 ----
  	strcat (key,"\\");
  	strcat (key, PBC_DEFAULT_KEY);
  
! 	Read_Reg_Values (key, p);
  
  
  	// Then first node (current appid)
  
  	strcpy (key, PBC_WEB_VAR_LOCATION);
  	strcat (key,"\\");
! 	strcat (key, p->appid);
! 
! 	Read_Reg_Values (key, p);
  
  	// Then any app/subdirectory/file settings
  
***************
*** 824,862 ****
  
  		if ((PBC_LEGACY_DIR_NAMES)) {
  			if ( stricmp((const char *)szBuff, (PBC_NETID_NAME)) == 0 ) {
! 				dcfg->AuthType = AUTH_NETID;
! 				dcfg->legacy = true;
! 				filterlog(dcfg, LOG_INFO,"  dir type       : %s\n",szBuff);
  			}
  			else if ( stricmp((const char *)szBuff, (PBC_SECURID_NAME)) == 0 ) {
! 				dcfg->AuthType = AUTH_SECURID;
! 				dcfg->legacy = true;
! 				filterlog(dcfg, LOG_INFO,"  dir type       : %s\n",szBuff);
  			}
  			else if ( stricmp((const char *)szBuff, (PBC_PUBLIC_NAME)) == 0 ) {
! 				dcfg->AuthType = AUTH_NONE;
! 				dcfg->Set_Server_Values = true;
! 				dcfg->legacy = true;
! 				filterlog(dcfg, LOG_INFO,"  dir type       : %s\n",szBuff);
  			}
  		}
  
  		strcat (key, "\\");
  		strcat (key, szBuff);
  
! 		Read_Reg_Values (key, dcfg);
  
  	}
  
  #ifndef COOKIE_PATH
  	// Convert appid to lower case
! 	strlwr(dcfg->appid);
  #endif
  
! 	{ 
! 		char buff[4096];
  
! 		_snprintf(buff,4096,
  			"Get_Effective_Values\n" 
  			"  Values for: %s\n" 
  			"    AppId            : %s\n" 
--- 820,858 ----
  
  		if ((PBC_LEGACY_DIR_NAMES)) {
  			if ( stricmp((const char *)szBuff, (PBC_NETID_NAME)) == 0 ) {
! 				p->AuthType = AUTH_NETID;
! 				p->legacy = true;
! 				filterlog(p, LOG_INFO,"  dir type       : %s\n",szBuff);
  			}
  			else if ( stricmp((const char *)szBuff, (PBC_SECURID_NAME)) == 0 ) {
! 				p->AuthType = AUTH_SECURID;
! 				p->legacy = true;
! 				filterlog(p, LOG_INFO,"  dir type       : %s\n",szBuff);
  			}
  			else if ( stricmp((const char *)szBuff, (PBC_PUBLIC_NAME)) == 0 ) {
! 				p->AuthType = AUTH_NONE;
! 				p->Set_Server_Values = true;
! 				p->legacy = true;
! 				filterlog(p, LOG_INFO,"  dir type       : %s\n",szBuff);
  			}
  		}
  
  		strcat (key, "\\");
  		strcat (key, szBuff);
  
! 		Read_Reg_Values (key, p);
  
  	}
  
  #ifndef COOKIE_PATH
  	// Convert appid to lower case
! 	strlwr(p->appid);
  #endif
  
! 	{ 
! 		char buff[4096];
  
! 		_snprintf(buff,4096,
  			"Get_Effective_Values\n" 
  			"  Values for: %s\n" 
  			"    AppId            : %s\n" 
***************
*** 874,899 ****
  			"    Enterprise_Domain: %s\n" 
  			"    Error_Page       : %s\n" 
  			"    Set_Server_Values: %d\n",
! 			key,
! 			dcfg->appid,
! 			dcfg->pszUser,
! 			(strlen(dcfg->pszPassword) > 0),
! 			dcfg->inact_exp,
! 			dcfg->hard_exp,
! 			dcfg->force_reauth,
! 			dcfg->session_reauth,
! 			dcfg->logout_action,
! 			dcfg->AuthType,
! 			dcfg->default_url,
! 			dcfg->timeout_url,
! 			dcfg->Login_URI,
! 			dcfg->Enterprise_Domain,
! 			dcfg->Error_Page,
! 			dcfg->Set_Server_Values);
! 		
! 	filterlog(dcfg, LOG_INFO,buff);
  	}
! 	sprintf(dcfg->s_cookiename,"%s_%s",PBC_S_COOKIENAME,dcfg->appid);
  
  } 
  
--- 870,895 ----
  			"    Enterprise_Domain: %s\n" 
  			"    Error_Page       : %s\n" 
  			"    Set_Server_Values: %d\n",
! 			key,
! 			p->appid,
! 			p->pszUser,
! 			(strlen(p->pszPassword) > 0),
! 			p->inact_exp,
! 			p->hard_exp,
! 			p->force_reauth,
! 			p->session_reauth,
! 			p->logout_action,
! 			p->AuthType,
! 			p->default_url,
! 			p->timeout_url,
! 			p->Login_URI,
! 			p->Enterprise_Domain,
! 			p->Error_Page,
! 			p->Set_Server_Values);
! 		
! 	filterlog(p, LOG_INFO,buff);
  	}
! 	sprintf(p->s_cookiename,"%s_%s",PBC_S_COOKIENAME,p->appid);
  
  } 
  
***************
*** 902,923 ****
  					   HTTP_FILTER_PREPROC_HEADERS* pHeaderInfo)
  {
  	char temp[16];
! 	pubcookie_dir_rec* dcfg;
  
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
  	// Set Pubcookie Appid, User and Creds level
  
! 	pHeaderInfo->AddHeader(pFC,PBC_Header_Server,dcfg->server_hostname);
  
! 	pHeaderInfo->AddHeader(pFC,PBC_Header_Appid,dcfg->appid);
  
! //	pHeaderInfo->SetHeader(pFC,"REMOTE_USER",dcfg->user);
  // Don't know how to override server variables so use our own
  
! 	pHeaderInfo->AddHeader(pFC,PBC_Header_User,dcfg->user);
  
! 	sprintf(temp,"%c",dcfg->AuthType);
  
  	pHeaderInfo->AddHeader(pFC,PBC_Header_Creds,temp);
  
--- 898,919 ----
  					   HTTP_FILTER_PREPROC_HEADERS* pHeaderInfo)
  {
  	char temp[16];
! 	pubcookie_dir_rec* p;
  
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
  	// Set Pubcookie Appid, User and Creds level
  
! 	pHeaderInfo->AddHeader(pFC,PBC_Header_Server,p->server_hostname);
  
! 	pHeaderInfo->AddHeader(pFC,PBC_Header_Appid,p->appid);
  
! //	pHeaderInfo->SetHeader(pFC,"REMOTE_USER",p->user);
  // Don't know how to override server variables so use our own
  
! 	pHeaderInfo->AddHeader(pFC,PBC_Header_User,p->user);
  
! 	sprintf(temp,"%c",p->AuthType);
  
  	pHeaderInfo->AddHeader(pFC,PBC_Header_Creds,temp);
  
***************
*** 939,951 ****
  	DWORD dwBuffSize;
  	char *pachUrl;
  	char *ptr;
! 	pubcookie_dir_rec* dcfg;
! 	int pre_sess_from_cookie;
! 	char strbuff[MAX_REG_BUFF];
  
!     dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(dcfg, LOG_INFO," Pubcookie_User\n");
  
      // First check to see if this directory needs protection
  
--- 935,946 ----
  	DWORD dwBuffSize;
  	char *pachUrl;
  	char *ptr;
! 	pubcookie_dir_rec* p;
! 	int pre_sess_from_cookie;
  
!     p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(p, LOG_INFO," Pubcookie_User\n");
  
      // First check to see if this directory needs protection
  
***************
*** 953,959 ****
  
      pHeaderInfo->GetHeader(pFC,"url",achUrl,&cbURL);
  
! 	filterlog(dcfg, LOG_INFO,"  Requested URL : %s\n",achUrl);
  
  	// Have to parse Query_String ourselves, server hasn't scanned it yet
  
--- 948,954 ----
  
      pHeaderInfo->GetHeader(pFC,"url",achUrl,&cbURL);
  
! 	filterlog(p, LOG_INFO,"  Requested URL : %s\n",achUrl);
  
  	// Have to parse Query_String ourselves, server hasn't scanned it yet
  
***************
*** 962,969 ****
  		*ptr++;
  		strncpy(szBuff, ptr, strlen(ptr));
  		szBuff[strlen(ptr)] = NULL;
! 		strcpy(dcfg->args,szBuff);
! 		filterlog(dcfg, LOG_INFO,"  Query String  : %s\n",szBuff);
  	}
  	// Else dfcg->args[0]=NULL because of original memset
  
--- 957,964 ----
  		*ptr++;
  		strncpy(szBuff, ptr, strlen(ptr));
  		szBuff[strlen(ptr)] = NULL;
! 		strcpy(p->args,szBuff);
! 		filterlog(p, LOG_INFO,"  Query String  : %s\n",szBuff);
  	}
  	// Else dfcg->args[0]=NULL because of original memset
  
***************
*** 972,993 ****
  	pFC->ServerSupportFunction(pFC,SF_REQ_NORMALIZE_URL,
  								achUrl,NULL,NULL);
  
! 	filterlog(dcfg, LOG_DEBUG,"  Normalized URL: %s\n",achUrl);
  
  	// set Uri
! 	strcpy(dcfg->uri,achUrl);
  
  	// set Request Method
! 	dwBuffSize = sizeof(dcfg->method);
! 	pHeaderInfo->GetHeader(pFC,"method",dcfg->method,&dwBuffSize);
  
! 	filterlog(dcfg, LOG_INFO,"  Request Method: %s\n",dcfg->method);
  
  	// Get Application ID from first node
  
! 	strcpy((char *)dcfg->appid,(PBC_DEFAULT_APP_NAME));
! 	dcfg->user[0]  = NULL;
! 	dcfg->AuthType    = AUTH_NONE;
  
  	pachUrl = achUrl;
  
--- 967,988 ----
  	pFC->ServerSupportFunction(pFC,SF_REQ_NORMALIZE_URL,
  								achUrl,NULL,NULL);
  
! 	filterlog(p, LOG_DEBUG,"  Normalized URL: %s\n",achUrl);
  
  	// set Uri
! 	strcpy(p->uri,achUrl);
  
  	// set Request Method
! 	dwBuffSize = sizeof(p->method);
! 	pHeaderInfo->GetHeader(pFC,"method",p->method,&dwBuffSize);
  
! 	filterlog(p, LOG_INFO,"  Request Method: %s\n",p->method);
  
  	// Get Application ID from first node
  
! 	strcpy((char *)p->appid,(PBC_DEFAULT_APP_NAME));
! 	p->user[0]  = NULL;
! 	p->AuthType    = AUTH_NONE;
  
  	pachUrl = achUrl;
  
***************
*** 999,1048 ****
      *pachUrl++;		// skip over first '/'
      ptr = strchr(pachUrl,'/');
  	if ( ptr ) {
! 		strncpy((char *)dcfg->appid, pachUrl, ptr-pachUrl);
! 		dcfg->appid[(ptr-pachUrl)] = NULL;
  	}
  	else if (strlen(pachUrl) > 0) {   // This could set appid to a filename in the root dir
! 		strcpy((char *)dcfg->appid, pachUrl);
  	}
  
  	// Save Path unchanged so cookies will be returned properly
! 	// strcpy(dcfg->path_id,dcfg->appid);
  
  	// Get userid, timeouts, AuthType, etc for this app.  Could change appid.
  	Get_Effective_Values(pFC,pHeaderInfo,ptr);
! 
      /* Log out if indicated */
  
! 	if (dcfg->logout_action > LOGOUT_NONE) {
  #ifdef COOKIE_PATH
! 		if ( stricmp(dcfg->appid,(PBC_DEFAULT_APP_NAME)) == 0 )
  			strcpy(szBuff,"/");
  		else 
! 			sprintf(szBuff,"/%s",dcfg->appid);
  #else
  		strcpy(szBuff,"/");
  #endif
  		//  If we're logging out, clear the cookie.
  		
! 		Clear_Cookie(pFC,dcfg->s_cookiename,dcfg->appsrvid,szBuff,FALSE); 
  		
! 		if (dcfg->logout_action == LOGOUT_REDIRECT || dcfg->logout_action == LOGOUT_REDIRECT_CLEAR_LOGIN) {
  			
! 			filterlog(dcfg, LOG_INFO,"  Logout Redirect....\n");
  			
  			sprintf(szBuff, "%s?%s=%d&%s=%s&%s=%s",
! 				dcfg->Login_URI,
  				PBC_GETVAR_LOGOUT_ACTION,
! 				(dcfg->logout_action == LOGOUT_REDIRECT_CLEAR_LOGIN ? LOGOUT_ACTION_CLEAR_L : LOGOUT_ACTION_NOTHING),
  				PBC_GETVAR_APPID,
! 				dcfg->appid,
  				PBC_GETVAR_APPSRVID,
! 				dcfg->appsrvid);
  			
  			
! 			dcfg->failed = PBC_LOGOUT_REDIR;
! 			dcfg->handler = PBC_LOGOUT_REDIR;
  			
  			return (Redirect(pFC, szBuff));
  			
--- 994,1050 ----
      *pachUrl++;		// skip over first '/'
      ptr = strchr(pachUrl,'/');
  	if ( ptr ) {
! 		strncpy((char *)p->appid, pachUrl, ptr-pachUrl);
! 		p->appid[(ptr-pachUrl)] = NULL;
  	}
  	else if (strlen(pachUrl) > 0) {   // This could set appid to a filename in the root dir
! 		strcpy((char *)p->appid, pachUrl);
  	}
  
  	// Save Path unchanged so cookies will be returned properly
! 	// strcpy(p->path_id,p->appid);
  
  	// Get userid, timeouts, AuthType, etc for this app.  Could change appid.
  	Get_Effective_Values(pFC,pHeaderInfo,ptr);
! //debug
! 	{
! 		char data[16384];
! 		DWORD cbdata=16384;
! 		pFC->GetServerVariable(pFC,"ALL_HTTP",data,&cbdata);
! 		filterlog(p, LOG_ERR,"HTTP Headers: %s",data);
! 	}
! //debug
      /* Log out if indicated */
  
! 	if (p->logout_action > LOGOUT_NONE) {
  #ifdef COOKIE_PATH
! 		if ( stricmp(p->appid,(PBC_DEFAULT_APP_NAME)) == 0 )
  			strcpy(szBuff,"/");
  		else 
! 			sprintf(szBuff,"/%s",p->appid);
  #else
  		strcpy(szBuff,"/");
  #endif
  		//  If we're logging out, clear the cookie.
  		
! 		Clear_Cookie(pFC,p->s_cookiename,p->appsrvid,szBuff,FALSE); 
  		
! 		if (p->logout_action == LOGOUT_REDIRECT || p->logout_action == LOGOUT_REDIRECT_CLEAR_LOGIN) {
  			
! 			filterlog(p, LOG_INFO,"  Logout Redirect....\n");
  			
  			sprintf(szBuff, "%s?%s=%d&%s=%s&%s=%s",
! 				p->Login_URI,
  				PBC_GETVAR_LOGOUT_ACTION,
! 				(p->logout_action == LOGOUT_REDIRECT_CLEAR_LOGIN ? LOGOUT_ACTION_CLEAR_L : LOGOUT_ACTION_NOTHING),
  				PBC_GETVAR_APPID,
! 				p->appid,
  				PBC_GETVAR_APPSRVID,
! 				p->appsrvid);
  			
  			
! 			p->failed = PBC_LOGOUT_REDIR;
! 			p->handler = PBC_LOGOUT_REDIR;
  			
  			return (Redirect(pFC, szBuff));
  			
***************
*** 1053,1060 ****
  	}
  
  	/* We're done if this is an unprotected page */
! 	if (dcfg->AuthType == AUTH_NONE) {
! 		if (dcfg->Set_Server_Values) {
  			Add_Header_Values   (pFC,pHeaderInfo);
  		}
  		return DECLINED;
--- 1055,1062 ----
  	}
  
  	/* We're done if this is an unprotected page */
! 	if (p->AuthType == AUTH_NONE) {
! 		if (p->Set_Server_Values) {
  			Add_Header_Values   (pFC,pHeaderInfo);
  		}
  		return DECLINED;
***************
*** 1067,1158 ****
  							szBuff, &dwBuffSize);
  	if ( strcmp(szBuff,"0") == 0 ) 
  	{
! 		dcfg->failed = PBC_BAD_PORT;
! 		sprintf(szBuff,"https://%s%s%s%s",dcfg->appsrvid, achUrl,(strlen(dcfg->args) ? "?" : ""), dcfg->args);
  		return(Redirect(pFC,szBuff));
  	}
  
  
  
! 	filterlog(dcfg, LOG_INFO,"  creds= %c\n",dcfg->AuthType);
  
  
  	// Set force reauth URL to requested URL if not "NFR"
! 	if ( strcmp(dcfg->force_reauth,PBC_NO_FORCE_REAUTH) != 0 )
! 		if ( strlen(dcfg->default_url) > 0 )
! 			strcpy((char *)dcfg->force_reauth,dcfg->default_url);
  		else
! 			strcpy((char *)dcfg->force_reauth,achUrl);
  
      // Get Granting cookie or Session cookie
  	// If '<cookie name>=' then client has bogus time and cleared cookie hasn't expired
  
  	if( !(cookie = Get_Cookie(pFC,PBC_G_COOKIENAME)) || (strcmp(cookie,"")==0) ) {
  		if (cookie) pbc_free(p, cookie);
! 		if( !(cookie = Get_Cookie(pFC,dcfg->s_cookiename)) || (strcmp(cookie,"")==0) ) {
! 			filterlog(dcfg, LOG_INFO,"  Pubcookie_User: no cookies yet, must authenticate\n");
  			if (cookie) pbc_free(p, cookie);
! 			dcfg->failed = PBC_BAD_AUTH;
  			return OK;
  		}
  		else {
  
! 			if( ! (cookie_data = libpbc_unbundle_cookie(p, cookie, dcfg->server_hostname, false)) ) {
! 				filterlog(dcfg, LOG_ERR,"[Pubcookie_User] Can't unbundle Session cookie for URL %s; remote_host: %s",
! 					dcfg->uri, dcfg->remote_host);
! 				dcfg->failed = PBC_BAD_SESSION_CERT;
  				pbc_free(p, cookie);
  				return OK;
  			}
  		else {
! 			dcfg->cookie_data = cookie_data;
  		}
  
  		pbc_free(p, cookie);
  
! 		filterlog(dcfg, LOG_INFO,"  Session Cookie Contents:\n    user= %s\n    version= %s\n    appsrvid= %s\n    appid= %s\n    type= %c\n    creds= %c\n    create_ts= %d\n    last_ts= %d\n",
  			(*cookie_data).broken.user,(*cookie_data).broken.version,(*cookie_data).broken.appsrvid,
  			(*cookie_data).broken.appid,(*cookie_data).broken.type,(*cookie_data).broken.creds,
  			(*cookie_data).broken.create_ts,(*cookie_data).broken.last_ts);
  
! 		strcpy(dcfg->user, (char *)(*cookie_data).broken.user);
  
  		// maintain highest level of creds
! 		if ( dcfg->AuthType == AUTH_NETID && (*cookie_data).broken.creds == AUTH_SECURID )
! 			 dcfg->AuthType = AUTH_SECURID;
  
! 		if( ! Pubcookie_Check_Exp(pFC,(*cookie_data).broken.create_ts,dcfg->hard_exp)) {
! 			filterlog(dcfg, LOG_INFO,"  Session cookie hard expired for user: %s create_ts: %ld timeout: %d elapsed: %ld\n",
                  (*cookie_data).broken.user,
                  (*cookie_data).broken.create_ts,
!                 dcfg->hard_exp,
                  (time(NULL)-(*cookie_data).broken.create_ts) );
! 			if ( strcmp(dcfg->force_reauth,PBC_NO_FORCE_REAUTH) != 0 &&
! 				 strlen(dcfg->timeout_url) > 0 )
! 				strcpy((char *)dcfg->force_reauth,dcfg->timeout_url);
! 			dcfg->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		}
  		else {
! 			filterlog(dcfg, LOG_INFO,"  Session cookie not hard expired for user: %s create_ts: %ld timeout: %d elapsed: %ld\n",
                  (*cookie_data).broken.user,
                  (*cookie_data).broken.create_ts,
!                 dcfg->hard_exp,
                  (time(NULL)-(*cookie_data).broken.create_ts) );
  		}
  
! 		if(dcfg->inact_exp != -1 &&
! 			! Pubcookie_Check_Exp(pFC,(*cookie_data).broken.last_ts,dcfg->inact_exp) ) {
! 			filterlog(dcfg, LOG_INFO,"  Session cookie inact expired for user: %s last_ts: %ld timeout: %d elapsed: %ld\n",
                  (*cookie_data).broken.user,
                  (*cookie_data).broken.last_ts,
!                 dcfg->inact_exp,
                  (time(NULL)-(*cookie_data).broken.last_ts) );
! 			if ( strcmp(dcfg->force_reauth,PBC_NO_FORCE_REAUTH) != 0 &&
! 				 strlen(dcfg->timeout_url) > 0 )
! 				strcpy((char *)dcfg->force_reauth,dcfg->timeout_url);
! 			dcfg->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		}
--- 1069,1160 ----
  							szBuff, &dwBuffSize);
  	if ( strcmp(szBuff,"0") == 0 ) 
  	{
! 		p->failed = PBC_BAD_PORT;
! 		sprintf(szBuff,"https://%s%s%s%s",p->appsrvid, achUrl,(strlen(p->args) ? "?" : ""), p->args);
  		return(Redirect(pFC,szBuff));
  	}
  
  
  
! 	filterlog(p, LOG_INFO,"  creds= %c\n",p->AuthType);
  
  
  	// Set force reauth URL to requested URL if not "NFR"
! 	if ( strcmp(p->force_reauth,PBC_NO_FORCE_REAUTH) != 0 )
! 		if ( strlen(p->default_url) > 0 )
! 			strcpy((char *)p->force_reauth,p->default_url);
  		else
! 			strcpy((char *)p->force_reauth,achUrl);
  
      // Get Granting cookie or Session cookie
  	// If '<cookie name>=' then client has bogus time and cleared cookie hasn't expired
  
  	if( !(cookie = Get_Cookie(pFC,PBC_G_COOKIENAME)) || (strcmp(cookie,"")==0) ) {
  		if (cookie) pbc_free(p, cookie);
! 		if( !(cookie = Get_Cookie(pFC,p->s_cookiename)) || (strcmp(cookie,"")==0) ) {
! 			filterlog(p, LOG_INFO,"  Pubcookie_User: no cookies yet, must authenticate\n");
  			if (cookie) pbc_free(p, cookie);
! 			p->failed = PBC_BAD_AUTH;
  			return OK;
  		}
  		else {
  
! 			if( ! (cookie_data = libpbc_unbundle_cookie(p, cookie, p->server_hostname, false)) ) {
! 				filterlog(p, LOG_ERR,"[Pubcookie_User] Can't unbundle Session cookie for URL %s; remote_host: %s",
! 					p->uri, p->remote_host);
! 				p->failed = PBC_BAD_SESSION_CERT;
  				pbc_free(p, cookie);
  				return OK;
  			}
  		else {
! 			p->cookie_data = cookie_data;
  		}
  
  		pbc_free(p, cookie);
  
! 		filterlog(p, LOG_INFO,"  Session Cookie Contents:\n    user= %s\n    version= %s\n    appsrvid= %s\n    appid= %s\n    type= %c\n    creds= %c\n    create_ts= %d\n    last_ts= %d\n",
  			(*cookie_data).broken.user,(*cookie_data).broken.version,(*cookie_data).broken.appsrvid,
  			(*cookie_data).broken.appid,(*cookie_data).broken.type,(*cookie_data).broken.creds,
  			(*cookie_data).broken.create_ts,(*cookie_data).broken.last_ts);
  
! 		strcpy(p->user, (char *)(*cookie_data).broken.user);
  
  		// maintain highest level of creds
! 		if ( p->AuthType == AUTH_NETID && (*cookie_data).broken.creds == AUTH_SECURID )
! 			 p->AuthType = AUTH_SECURID;
  
! 		if( ! Pubcookie_Check_Exp(pFC,(*cookie_data).broken.create_ts,p->hard_exp)) {
! 			filterlog(p, LOG_INFO,"  Session cookie hard expired for user: %s create_ts: %ld timeout: %d elapsed: %ld\n",
                  (*cookie_data).broken.user,
                  (*cookie_data).broken.create_ts,
!                 p->hard_exp,
                  (time(NULL)-(*cookie_data).broken.create_ts) );
! 			if ( strcmp(p->force_reauth,PBC_NO_FORCE_REAUTH) != 0 &&
! 				 strlen(p->timeout_url) > 0 )
! 				strcpy((char *)p->force_reauth,p->timeout_url);
! 			p->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		}
  		else {
! 			filterlog(p, LOG_INFO,"  Session cookie not hard expired for user: %s create_ts: %ld timeout: %d elapsed: %ld\n",
                  (*cookie_data).broken.user,
                  (*cookie_data).broken.create_ts,
!                 p->hard_exp,
                  (time(NULL)-(*cookie_data).broken.create_ts) );
  		}
  
! 		if(p->inact_exp != -1 &&
! 			! Pubcookie_Check_Exp(pFC,(*cookie_data).broken.last_ts,p->inact_exp) ) {
! 			filterlog(p, LOG_INFO,"  Session cookie inact expired for user: %s last_ts: %ld timeout: %d elapsed: %ld\n",
                  (*cookie_data).broken.user,
                  (*cookie_data).broken.last_ts,
!                 p->inact_exp,
                  (time(NULL)-(*cookie_data).broken.last_ts) );
! 			if ( strcmp(p->force_reauth,PBC_NO_FORCE_REAUTH) != 0 &&
! 				 strlen(p->timeout_url) > 0 )
! 				strcpy((char *)p->force_reauth,p->timeout_url);
! 			p->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		}
***************
*** 1162,1182 ****
  	}
  	else {
  
! 		dcfg->has_granting = 1;
  
  		/* the granting cookie gets blanked too early and another login */
  		/* server loop is required, this just speeds up that loop */
  		/*if( strncmp(cookie, PBC_X_STRING, PBC_XS_IN_X_STRING) == 0 ) {
! 			dcfg->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie);
  			return OK;
  		}*/ 		/* PBC_X_STRING doesn't seem to be used any longer */
  
  
! 		if( !(cookie_data = libpbc_unbundle_cookie(p, cookie, dcfg->server_hostname, true)) ) {
! 			filterlog(dcfg, LOG_ERR,"[Pubcookie_User] Can't unbundle Granting cookie for URL %s; remote_host: %s", 
! 				dcfg->uri, dcfg->remote_host);
! 			dcfg->failed = PBC_BAD_GRANTING_CERT;
  			pbc_free(p, cookie);
  			return OK;
  		}
--- 1164,1184 ----
  	}
  	else {
  
! 		p->has_granting = 1;
  
  		/* the granting cookie gets blanked too early and another login */
  		/* server loop is required, this just speeds up that loop */
  		/*if( strncmp(cookie, PBC_X_STRING, PBC_XS_IN_X_STRING) == 0 ) {
! 			p->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie);
  			return OK;
  		}*/ 		/* PBC_X_STRING doesn't seem to be used any longer */
  
  
! 		if( !(cookie_data = libpbc_unbundle_cookie(p, cookie, p->server_hostname, true)) ) {
! 			filterlog(p, LOG_ERR,"[Pubcookie_User] Can't unbundle Granting cookie for URL %s; remote_host: %s", 
! 				p->uri, p->remote_host);
! 			p->failed = PBC_BAD_GRANTING_CERT;
  			pbc_free(p, cookie);
  			return OK;
  		}
***************
*** 1184,1193 ****
  		/* check pre_session cookie */
  		pre_sess_from_cookie = get_pre_s_from_cookie(pFC);
  		if( (*cookie_data).broken.pre_sess_token != pre_sess_from_cookie ) {
! 			filterlog(dcfg, LOG_INFO,"pubcookie_user, pre session tokens mismatched, uri: %s", dcfg->uri);
! 			filterlog(dcfg, LOG_INFO,"pubcookie_user, pre session from G: %d PRE_S: %d, uri: %s", 
! 				(*cookie_data).broken.pre_sess_token, pre_sess_from_cookie, dcfg->uri);
! 			dcfg->failed = PBC_BAD_AUTH;
  			return OK;
  		}
  
--- 1186,1195 ----
  		/* check pre_session cookie */
  		pre_sess_from_cookie = get_pre_s_from_cookie(pFC);
  		if( (*cookie_data).broken.pre_sess_token != pre_sess_from_cookie ) {
! 			filterlog(p, LOG_INFO,"pubcookie_user, pre session tokens mismatched, uri: %s", p->uri);
! 			filterlog(p, LOG_INFO,"pubcookie_user, pre session from G: %d PRE_S: %d, uri: %s", 
! 				(*cookie_data).broken.pre_sess_token, pre_sess_from_cookie, p->uri);
! 			p->failed = PBC_BAD_AUTH;
  			return OK;
  		}
  
***************
*** 1195,1215 ****
  
  		pbc_free(p, cookie);
  
! 		filterlog(dcfg, LOG_INFO,"  Granting Cookie Contents:\n    user= %s\n    version= %s\n    appsrvid= %s\n    appid= %s\n    type= %c\n    creds= %c\n    create_ts= %d\n    last_ts= %d\n",
  			(*cookie_data).broken.user  ,(*cookie_data).broken.version  ,(*cookie_data).broken.appsrvid,
  			(*cookie_data).broken.appid,(*cookie_data).broken.type     ,(*cookie_data).broken.creds,
  			(*cookie_data).broken.create_ts,(*cookie_data).broken.last_ts);
  
! 		strcpy(dcfg->user,(const char *)(*cookie_data).broken.user);
  
  		// maintain highest level of creds
! 		if ( dcfg->AuthType == AUTH_NETID && (*cookie_data).broken.creds == AUTH_SECURID )
! 			 dcfg->AuthType = AUTH_SECURID;
  
  		if( ! Pubcookie_Check_Exp(pFC,(*cookie_data).broken.create_ts, PBC_GRANTING_EXPIRE) ) {
! 			filterlog(dcfg, LOG_INFO,"[Pubcookie_User] Granting cookie expired for user: %s  elapsed: %d limit: %d; remote_host: %s", 
! 				(*cookie_data).broken.user,(time(NULL)-(*cookie_data).broken.create_ts), PBC_GRANTING_EXPIRE, dcfg->remote_host);
! 			dcfg->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		}
--- 1197,1217 ----
  
  		pbc_free(p, cookie);
  
! 		filterlog(p, LOG_INFO,"  Granting Cookie Contents:\n    user= %s\n    version= %s\n    appsrvid= %s\n    appid= %s\n    type= %c\n    creds= %c\n    create_ts= %d\n    last_ts= %d\n",
  			(*cookie_data).broken.user  ,(*cookie_data).broken.version  ,(*cookie_data).broken.appsrvid,
  			(*cookie_data).broken.appid,(*cookie_data).broken.type     ,(*cookie_data).broken.creds,
  			(*cookie_data).broken.create_ts,(*cookie_data).broken.last_ts);
  
! 		strcpy(p->user,(const char *)(*cookie_data).broken.user);
  
  		// maintain highest level of creds
! 		if ( p->AuthType == AUTH_NETID && (*cookie_data).broken.creds == AUTH_SECURID )
! 			 p->AuthType = AUTH_SECURID;
  
  		if( ! Pubcookie_Check_Exp(pFC,(*cookie_data).broken.create_ts, PBC_GRANTING_EXPIRE) ) {
! 			filterlog(p, LOG_INFO,"[Pubcookie_User] Granting cookie expired for user: %s  elapsed: %d limit: %d; remote_host: %s", 
! 				(*cookie_data).broken.user,(time(NULL)-(*cookie_data).broken.create_ts), PBC_GRANTING_EXPIRE, p->remote_host);
! 			p->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		}
***************
*** 1217,1270 ****
  	} /* end if granting cookie */
  
  	/* check appid */
! 	current_appid = dcfg->appid;
  	if( _strnicmp((const char *)current_appid, (const char *)(*cookie_data).broken.appid, 
  					sizeof((*cookie_data).broken.appid)-1) != 0 ) {
! 	//	filterlog(dcfg, LOG_ERR,"[Pubcookie_User] Wrong appid; current: %s cookie: %s; remote_host: %s", 
! 	//		current_appid, (*cookie_data).broken.appid, dcfg->remote_host);
! 		dcfg->failed = PBC_BAD_AUTH;   // PBC_BAD_APPID;  // Left over from failed application
  		pbc_free(p, cookie_data);
  		return OK;
  	}
  
  	/* make sure this cookie is for this server */
  	/* Use server_hostname instead of appsrvid so we only need one c_key per server */
! 	if( _strnicmp((const char *)dcfg->server_hostname, (const char *)(*cookie_data).broken.appsrvid, 
  					sizeof((*cookie_data).broken.appsrvid)-1) != 0 ) {
! 		filterlog(dcfg, LOG_WARN,"[Pubcookie_User] Wrong app server id; current: %s cookie: %s; remote_host: %s", 
! 				dcfg->server_hostname, (*cookie_data).broken.appsrvid, dcfg->remote_host);
! 		dcfg->failed = PBC_BAD_AUTH;  // PBC_BAD_SERVERID;
  		pbc_free(p, cookie_data);
  		return OK;  
  	}
  
  	if( !Pubcookie_Check_Version(pFC,(*cookie_data).broken.version, 
  			(unsigned char *)PBC_VERSION)){
! 		filterlog(dcfg, LOG_ERR,"[Pubcookie_User] Wrong version id; module: %d cookie: %d", 
  				PBC_VERSION, (*cookie_data).broken.version);
! 		dcfg->failed = PBC_BAD_VERSION;
  		pbc_free(p, cookie_data);
  		return OK;
  	}
  
! 	if(dcfg->AuthType == AUTH_NETID ) {
  		if( (*cookie_data).broken.creds != AUTH_NETID &&
  			(*cookie_data).broken.creds != AUTH_SECURID    ) {
! 			filterlog(dcfg, LOG_ERR,"[Pubcookie_User] Wrong creds directory; %c cookie: %c", 
  				AUTH_NETID, (*cookie_data).broken.creds);
! 			dcfg->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		} else {
! 			dcfg->AuthType = (*cookie_data).broken.creds;   // Use Creds from Cookie
  			}
  	}
  	else
! 	if(dcfg->AuthType == AUTH_SECURID ) {
  		if( (*cookie_data).broken.creds != AUTH_SECURID ) {
! 			filterlog(dcfg, LOG_ERR,"  Pubcookie_User: Wrong creds directory; %c cookie: %c", 
  				AUTH_SECURID, (*cookie_data).broken.creds);
! 			dcfg->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		}
--- 1219,1272 ----
  	} /* end if granting cookie */
  
  	/* check appid */
! 	current_appid = p->appid;
  	if( _strnicmp((const char *)current_appid, (const char *)(*cookie_data).broken.appid, 
  					sizeof((*cookie_data).broken.appid)-1) != 0 ) {
! 	//	filterlog(p, LOG_ERR,"[Pubcookie_User] Wrong appid; current: %s cookie: %s; remote_host: %s", 
! 	//		current_appid, (*cookie_data).broken.appid, p->remote_host);
! 		p->failed = PBC_BAD_AUTH;   // PBC_BAD_APPID;  // Left over from failed application
  		pbc_free(p, cookie_data);
  		return OK;
  	}
  
  	/* make sure this cookie is for this server */
  	/* Use server_hostname instead of appsrvid so we only need one c_key per server */
! 	if( _strnicmp((const char *)p->server_hostname, (const char *)(*cookie_data).broken.appsrvid, 
  					sizeof((*cookie_data).broken.appsrvid)-1) != 0 ) {
! 		filterlog(p, LOG_WARN,"[Pubcookie_User] Wrong app server id; current: %s cookie: %s; remote_host: %s", 
! 				p->server_hostname, (*cookie_data).broken.appsrvid, p->remote_host);
! 		p->failed = PBC_BAD_AUTH;  // PBC_BAD_SERVERID;
  		pbc_free(p, cookie_data);
  		return OK;  
  	}
  
  	if( !Pubcookie_Check_Version(pFC,(*cookie_data).broken.version, 
  			(unsigned char *)PBC_VERSION)){
! 		filterlog(p, LOG_ERR,"[Pubcookie_User] Wrong version id; module: %d cookie: %d", 
  				PBC_VERSION, (*cookie_data).broken.version);
! 		p->failed = PBC_BAD_VERSION;
  		pbc_free(p, cookie_data);
  		return OK;
  	}
  
! 	if(p->AuthType == AUTH_NETID ) {
  		if( (*cookie_data).broken.creds != AUTH_NETID &&
  			(*cookie_data).broken.creds != AUTH_SECURID    ) {
! 			filterlog(p, LOG_ERR,"[Pubcookie_User] Wrong creds directory; %c cookie: %c", 
  				AUTH_NETID, (*cookie_data).broken.creds);
! 			p->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		} else {
! 			p->AuthType = (*cookie_data).broken.creds;   // Use Creds from Cookie
  			}
  	}
  	else
! 	if(p->AuthType == AUTH_SECURID ) {
  		if( (*cookie_data).broken.creds != AUTH_SECURID ) {
! 			filterlog(p, LOG_ERR,"  Pubcookie_User: Wrong creds directory; %c cookie: %c", 
  				AUTH_SECURID, (*cookie_data).broken.creds);
! 			p->failed = PBC_BAD_AUTH;
  			pbc_free(p, cookie_data);
  			return OK;
  		}
***************
*** 1279,1294 ****
  
  int Pubcookie_Auth (HTTP_FILTER_CONTEXT* pFC)
  {
! 	pubcookie_dir_rec* dcfg;
  
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(dcfg, LOG_INFO," Pubcookie_Auth\n");
  
! 	if( !Is_Pubcookie_Auth(dcfg) ) 
  		return DECLINED;
  
! 	if(dcfg->failed)  /* Pubcookie_User has failed so pass to typer */
  		return OK;
  
  	return DECLINED;
--- 1281,1296 ----
  
  int Pubcookie_Auth (HTTP_FILTER_CONTEXT* pFC)
  {
! 	pubcookie_dir_rec* p;
  
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(p, LOG_INFO," Pubcookie_Auth\n");
  
! 	if( !Is_Pubcookie_Auth(p) ) 
  		return DECLINED;
  
! 	if(p->failed)  /* Pubcookie_User has failed so pass to typer */
  		return OK;
  
  	return DECLINED;
***************
*** 1301,1379 ****
  {
  	unsigned char	*cookie;
  	int first_time_in_session = 0;
! 	pubcookie_dir_rec* dcfg;
! 	char session_cookie_name[MAX_PATH];
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(dcfg, LOG_DEBUG," Pubcookie_Typer\n");
  
! 	if( dcfg->logout_action ) 
  		return OK;  //if we got here while logging out, we're redirecting
! 	if( !Is_Pubcookie_Auth(dcfg) ) 
  		return DECLINED;  //if we got here without auth, something must have changed midstream
  
! 	filterlog(dcfg, LOG_INFO," Pubcookie_Typer\n Has_Granting= %d, Failed= %d\n",dcfg->has_granting,dcfg->failed);
  
! 	if (dcfg->has_granting ) {
  
  		/* clear granting and presession cookies */
! 		Clear_Cookie(pFC,PBC_G_COOKIENAME,dcfg->Enterprise_Domain,"/",TRUE);
! 		Clear_Cookie(pFC,PBC_PRE_S_COOKIENAME,dcfg->appsrvid,"/",TRUE);
  
  		first_time_in_session = 1;
! 		dcfg->has_granting = 0;
  	}
  
! 	if (!dcfg->failed) {
  	/* if the inactivity timeout is turned off don't send a session cookie 
  	everytime, but be sure to send a session cookie if it's the first time
  	in the app */
! 		if (dcfg->inact_exp > 0 || first_time_in_session) {
  			
  			if( !first_time_in_session ) {
! 				cookie = libpbc_update_lastts(p, dcfg->cookie_data, dcfg->server_hostname, 0);
! 				filterlog(dcfg, LOG_INFO,"  Setting session cookie last timestamp to: %ld\n",dcfg->cookie_data->broken.last_ts);
  			}
  			else {
  				cookie = libpbc_get_cookie(p,
! 					(unsigned char *)dcfg->user, 
  					PBC_COOKIE_TYPE_S,
! 					dcfg->AuthType,
  					23,
! 					(unsigned char *)dcfg->server_hostname, 
! 					(unsigned char *)dcfg->appid,
! 					dcfg->server_hostname,
  					0);
  
! 				filterlog(dcfg, LOG_INFO,"  Created new session cookie.\n");
  			}
  
  
  
  #ifdef COOKIE_PATH
! 			if ( stricmp(dcfg->appid,(PBC_DEFAULT_APP_NAME)) == 0 )
  				sprintf(new_cookie, "Set-Cookie: %s_%s=%s; domain=%s; path=/; secure\r\n", 
! 				PBC_S_COOKIENAME, dcfg->appid,
  				cookie, 
! 				dcfg->appsrvid);
  			else 
  				sprintf(new_cookie, "Set-Cookie: %s_%s=%s; domain=%s; path=/%s; secure\r\n", 
! 				PBC_S_COOKIENAME, dcfg->appid,
  				cookie, 
! 				dcfg->appsrvid,
! 				dcfg->appid);
! 
  			pFC->AddResponseHeaders(pFC,new_cookie,0);
  
  #else
! 			snprintf(session_cookie_name,MAX_PATH,"%s_%s",PBC_S_COOKIENAME,dcfg->appid);
! 			Add_Cookie(pFC,session_cookie_name,cookie,dcfg->appsrvid);
  			
  	
  #endif
  			pbc_free(p, cookie);
! 			pbc_free(p, dcfg->cookie_data);
  			
  		
  		}
--- 1303,1381 ----
  {
  	unsigned char	*cookie;
  	int first_time_in_session = 0;
! 	pubcookie_dir_rec* p;
! 	char session_cookie_name[MAX_PATH];
  
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	filterlog(p, LOG_DEBUG," Pubcookie_Typer\n");
! 
! 	if( p->logout_action ) 
  		return OK;  //if we got here while logging out, we're redirecting
! 	if( !Is_Pubcookie_Auth(p) ) 
  		return DECLINED;  //if we got here without auth, something must have changed midstream
  
! 	filterlog(p, LOG_INFO," Pubcookie_Typer\n Has_Granting= %d, Failed= %d\n",p->has_granting,p->failed);
  
! 	if (p->has_granting ) {
  
  		/* clear granting and presession cookies */
! 		Clear_Cookie(pFC,PBC_G_COOKIENAME,p->Enterprise_Domain,"/",TRUE);
! 		Clear_Cookie(pFC,PBC_PRE_S_COOKIENAME,p->appsrvid,"/",TRUE);
  
  		first_time_in_session = 1;
! 		p->has_granting = 0;
  	}
  
! 	if (!p->failed) {
  	/* if the inactivity timeout is turned off don't send a session cookie 
  	everytime, but be sure to send a session cookie if it's the first time
  	in the app */
! 		if (p->inact_exp > 0 || first_time_in_session) {
  			
  			if( !first_time_in_session ) {
! 				cookie = libpbc_update_lastts(p, p->cookie_data, p->server_hostname, 0);
! 				filterlog(p, LOG_INFO,"  Setting session cookie last timestamp to: %ld\n",p->cookie_data->broken.last_ts);
  			}
  			else {
  				cookie = libpbc_get_cookie(p,
! 					(unsigned char *)p->user, 
  					PBC_COOKIE_TYPE_S,
! 					p->AuthType,
  					23,
! 					(unsigned char *)p->server_hostname, 
! 					(unsigned char *)p->appid,
! 					p->server_hostname,
  					0);
  
! 				filterlog(p, LOG_INFO,"  Created new session cookie.\n");
  			}
  
  
  
  #ifdef COOKIE_PATH
! 			if ( stricmp(p->appid,(PBC_DEFAULT_APP_NAME)) == 0 )
  				sprintf(new_cookie, "Set-Cookie: %s_%s=%s; domain=%s; path=/; secure\r\n", 
! 				PBC_S_COOKIENAME, p->appid,
  				cookie, 
! 				p->appsrvid);
  			else 
  				sprintf(new_cookie, "Set-Cookie: %s_%s=%s; domain=%s; path=/%s; secure\r\n", 
! 				PBC_S_COOKIENAME, p->appid,
  				cookie, 
! 				p->appsrvid,
! 				p->appid);
! 
  			pFC->AddResponseHeaders(pFC,new_cookie,0);
  
  #else
! 			snprintf(session_cookie_name,MAX_PATH,"%s_%s",PBC_S_COOKIENAME,p->appid);
! 			Add_Cookie(pFC,session_cookie_name,cookie,p->appsrvid);
  			
  	
  #endif
  			pbc_free(p, cookie);
! 			pbc_free(p, p->cookie_data);
  			
  		
  		}
***************
*** 1384,1415 ****
  
  		return DECLINED;
  
! 	} else if (dcfg->failed == PBC_BAD_AUTH) {
! 		dcfg->handler = PBC_BAD_AUTH;
  		return OK;
! 	} else if (dcfg->failed == PBC_BAD_USER) {
! 		dcfg->handler = PBC_BAD_USER;
  		return OK;
! 	} else if (dcfg->failed == PBC_FORCE_REAUTH) {
! 		dcfg->handler = PBC_FORCE_REAUTH;
  		return OK;
! 	} else if (dcfg->failed == PBC_BAD_GRANTING_CERT) {
! 		dcfg->handler = PBC_BAD_GRANTING_CERT;
  		return OK;
! 	} else if (dcfg->failed == PBC_BAD_SESSION_CERT) {
! 		dcfg->handler = PBC_BAD_SESSION_CERT;
  		return OK;
! 	} else if (dcfg->failed == PBC_BAD_VERSION) {
! 		dcfg->handler = PBC_BAD_VERSION;
  		return OK;
! 	} else if (dcfg->failed == PBC_BAD_APPID) {
! 		dcfg->handler = PBC_BAD_APPID;
  		return OK;
! 	} else if (dcfg->failed == PBC_BAD_SERVERID) {
! 		dcfg->handler = PBC_BAD_SERVERID;
  		return OK;
! 	} else if (dcfg->failed == PBC_BAD_PORT) {
! 		dcfg->handler = PBC_BAD_PORT;
  		return OK;
  	} else {
  		return DECLINED;
--- 1386,1417 ----
  
  		return DECLINED;
  
! 	} else if (p->failed == PBC_BAD_AUTH) {
! 		p->handler = PBC_BAD_AUTH;
  		return OK;
! 	} else if (p->failed == PBC_BAD_USER) {
! 		p->handler = PBC_BAD_USER;
  		return OK;
! 	} else if (p->failed == PBC_FORCE_REAUTH) {
! 		p->handler = PBC_FORCE_REAUTH;
  		return OK;
! 	} else if (p->failed == PBC_BAD_GRANTING_CERT) {
! 		p->handler = PBC_BAD_GRANTING_CERT;
  		return OK;
! 	} else if (p->failed == PBC_BAD_SESSION_CERT) {
! 		p->handler = PBC_BAD_SESSION_CERT;
  		return OK;
! 	} else if (p->failed == PBC_BAD_VERSION) {
! 		p->handler = PBC_BAD_VERSION;
  		return OK;
! 	} else if (p->failed == PBC_BAD_APPID) {
! 		p->handler = PBC_BAD_APPID;
  		return OK;
! 	} else if (p->failed == PBC_BAD_SERVERID) {
! 		p->handler = PBC_BAD_SERVERID;
  		return OK;
! 	} else if (p->failed == PBC_BAD_PORT) {
! 		p->handler = PBC_BAD_PORT;
  		return OK;
  	} else {
  		return DECLINED;
***************
*** 1436,1443 ****
  	
  	syslog(LOG_INFO,"[GetFilterVersion] %s",Pubcookie_Version);
  
! 	pVer->dwFlags = Notify_Flags;
! 
  	return TRUE;
  
  }  /* GetFilterVersion */
--- 1438,1445 ----
  	
  	syslog(LOG_INFO,"[GetFilterVersion] %s",Pubcookie_Version);
  
! 	pVer->dwFlags = Notify_Flags;
! 
  	return TRUE;
  
  }  /* GetFilterVersion */
***************
*** 1446,1537 ****
  DWORD OnReadRawData (HTTP_FILTER_CONTEXT *pFC,
                       HTTP_FILTER_RAW_DATA *pRawDataInfo)
  {
! 	pubcookie_dir_rec* dcfg;
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 	filterlog(dcfg, LOG_INFO,
! 		"\nPBC_OnReadRawData\n"
  		"  Revision: x%x\n"
! 		"  Secure  : x%x\n"
  		,pFC->Revision,pFC->fIsSecurePort);
  	
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnReadRawData */
! 
  DWORD OnPreprocHeaders (HTTP_FILTER_CONTEXT* pFC,
                          HTTP_FILTER_PREPROC_HEADERS* pHeaderInfo)
  {
  	char szBuff[1024];
! 	char achUrl[1024];
! 	char LogBuff[LOGBUFFSIZE]="";
! //	char *ptr;
  	DWORD dwBuffSize=1024;
  	DWORD return_rslt;
! //	unsigned long net_addr;
! //	hostent *hp;
! 	pubcookie_dir_rec* dcfg;
! 	time_t ltime;
! 	char SystemRootBuff[MAX_PATH+1];
! 
! 	// IBM Network Dispatcher probes web sites with a URL of "/" and command of HEAD
! 	// bail quickly if this is the case
! 
! 	achUrl[0]= NULL; dwBuffSize=1024;
! 	pHeaderInfo->GetHeader(pFC, "url",
! 							achUrl, &dwBuffSize);
! 
! 	if ( PBC_IGNORE_POLL && strcmp(achUrl,"/") == 0 ) {
! 		pFC->ServerSupportFunction(pFC,SF_REQ_DISABLE_NOTIFICATIONS,
! 								NULL,Notify_Flags,NULL);
! 		return SF_STATUS_REQ_NEXT_NOTIFICATION;
! 	}
! 
! 	// pFC->pFilterContext = pbc_malloc(p, sizeof(pubcookie_dir_rec));
! 	pFC->pFilterContext = pFC->AllocMem(pFC,sizeof(pubcookie_dir_rec),0);
! 
! 	if (!pFC->pFilterContext) {
! 		syslog(LOG_ERR,"[PBC_OnPreprocHeaders] Error allocating memory");
! 		return SF_STATUS_REQ_ERROR;
! 	}
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
! 	
! 	memset(dcfg,0,sizeof(pubcookie_dir_rec));
! 
  	time(&ltime);
! 
! 	szBuff[0]= NULL; dwBuffSize=1024;
! 	pFC->GetServerVariable(pFC, "INSTANCE_ID",
! 							szBuff, &dwBuffSize);
! 	AddToLog(LogBuff,"  Instance ID    : %s\n",szBuff);
! 	strncpy(dcfg->instance_id, szBuff, 8);
! 
! 	//Check for logging sources and create if needed
! 
! 	_snprintf (szBuff,1024,"Pubcookie-%s",dcfg->instance_id);
! 	if (!logsource_exists(szBuff)) {
! 		create_source(szBuff);
! 	}
! 	if (!logsource_exists("PubCookie")) {
! 		create_source("PubCookie");
! 	}
! 
! 	szBuff[0]= NULL; dwBuffSize=1024;
! 	pFC->GetServerVariable (pFC,
!       "SERVER_NAME",szBuff,&dwBuffSize);
! 	AddToLog(LogBuff,"  Server Name    : %s\n",szBuff);
! 	strncpy((char *)dcfg->server_hostname, szBuff, PBC_APPSRV_ID_LEN);
! 	strncpy(dcfg->appsrvid, szBuff, PBC_APPSRV_ID_LEN);   // Use SERVER_NAME for appsrvid
! 
! 	filterlog(dcfg, LOG_INFO,"\n %s \n PBC_OnPreprocHeaders\n",ctime(&ltime));
! 	filterlog(dcfg, LOG_INFO,"\n Using crypt key: %s\\%s",PBC_KEY_DIR,dcfg->server_hostname);
! 
  	szBuff[0]= NULL; dwBuffSize=1024;
  	pFC->GetServerVariable(pFC, "REMOTE_HOST",
  							szBuff, &dwBuffSize);
  	AddToLog(LogBuff,"  Remote_Host    : %s\n",szBuff);
! 	strcpy(dcfg->remote_host,szBuff);
  
  	szBuff[0]= NULL; dwBuffSize=1024;
  	pFC->GetServerVariable(pFC, "HTTP_REFERER",
--- 1448,1543 ----
  DWORD OnReadRawData (HTTP_FILTER_CONTEXT *pFC,
                       HTTP_FILTER_RAW_DATA *pRawDataInfo)
  {
! 	pubcookie_dir_rec* p;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 
! 	syslog(LOG_INFO,    
! 		"\nPBC_OnReadRawData\n"
  		"  Revision: x%x\n"
! 		"  Secure  : x%x\n"
  		,pFC->Revision,pFC->fIsSecurePort);
+ 	{
+ 		LPSTR lpRawData;
+ 		DWORD dwRawSize;
+ 		lpRawData = (LPSTR)pRawDataInfo->pvInData;
+ 		dwRawSize = pRawDataInfo->cbInData;
  	
+ 		syslog(LOG_ERR, "  Read:(%d) \n%s",  
+ 			dwRawSize,lpRawData);
+ 	}//debug
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnReadRawData */
! 
  DWORD OnPreprocHeaders (HTTP_FILTER_CONTEXT* pFC,
                          HTTP_FILTER_PREPROC_HEADERS* pHeaderInfo)
  {
  	char szBuff[1024];
! 	char achUrl[1024];
! 	char LogBuff[LOGBUFFSIZE]="";
  	DWORD dwBuffSize=1024;
  	DWORD return_rslt;
! 	pubcookie_dir_rec* p;
! 	time_t ltime;
! 
! 	// pFC->pFilterContext = pbc_malloc(p, sizeof(pubcookie_dir_rec)); 
! 	/* Slower but safer to let IIS handle this malloc */
! 	pFC->pFilterContext = pFC->AllocMem(pFC,sizeof(pubcookie_dir_rec),0);
! 
! 	if (!pFC->pFilterContext) {
! 		syslog(LOG_ERR,"[PBC_OnPreprocHeaders] Error allocating memory");
! 		return SF_STATUS_REQ_ERROR;
! 	}
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
! 	
! 	memset(p,0,sizeof(pubcookie_dir_rec));
! 
! 	// IBM Network Dispatcher probes web sites with a URL of "/" and command of HEAD
! 	// bail quickly if this is the case
! 
! 	achUrl[0]= NULL; dwBuffSize=1024;
! 	pHeaderInfo->GetHeader(pFC, "url",
! 							achUrl, &dwBuffSize);
! 	if ( PBC_IGNORE_POLL && strcmp(achUrl,"/") == 0 ) {
! 		pFC->ServerSupportFunction(pFC,SF_REQ_DISABLE_NOTIFICATIONS,
! 								NULL,Notify_Flags,NULL);
! 		return SF_STATUS_REQ_NEXT_NOTIFICATION;
! 	}
! 
  	time(&ltime);
! 
! 	szBuff[0]= NULL; dwBuffSize=1024;
! 	pFC->GetServerVariable(pFC, "INSTANCE_ID",
! 							szBuff, &dwBuffSize);
! 	AddToLog(LogBuff,"  Instance ID    : %s\n",szBuff);
! 	strncpy(p->instance_id, szBuff, 8);
! 
! 	//Check for logging sources and create if needed
! 
! 	_snprintf (szBuff,1024,"Pubcookie-%s",p->instance_id);
! 	if (!logsource_exists(p, szBuff)) {
! 		create_source(p, szBuff);
! 	}
! 	if (!logsource_exists(p, "PubCookie")) {
! 		create_source(p, "PubCookie");
! 	}
! 
! 	szBuff[0]= NULL; dwBuffSize=1024;
! 	pFC->GetServerVariable (pFC,
!       "SERVER_NAME",szBuff,&dwBuffSize);
! 	AddToLog(LogBuff,"  Server Name    : %s\n",szBuff);
! 	strncpy((char *)p->server_hostname, szBuff, PBC_APPSRV_ID_LEN);
! 	strncpy(p->appsrvid, szBuff, PBC_APPSRV_ID_LEN);   // Use SERVER_NAME for appsrvid
! 
! 	filterlog(p, LOG_INFO,"\n %s \n PBC_OnPreprocHeaders\n",ctime(&ltime));
! 	filterlog(p, LOG_INFO,"\n Using crypt key: %s\\%s",PBC_KEY_DIR,p->server_hostname);
! 
  	szBuff[0]= NULL; dwBuffSize=1024;
  	pFC->GetServerVariable(pFC, "REMOTE_HOST",
  							szBuff, &dwBuffSize);
  	AddToLog(LogBuff,"  Remote_Host    : %s\n",szBuff);
! 	strcpy(p->remote_host,szBuff);
  
  	szBuff[0]= NULL; dwBuffSize=1024;
  	pFC->GetServerVariable(pFC, "HTTP_REFERER",
***************
*** 1571,1581 ****
  	pFC->GetServerVariable(pFC,"SERVER_PORT",
  							szBuff, &dwBuffSize);
  	AddToLog(LogBuff,"  Server SERVER_PORT: %s\n",szBuff);
! 	strcpy(dcfg->appsrv_port,szBuff);
  	// Force port 80 or 443(ssl) to null
! 	if ( strcmp(dcfg->appsrv_port, "80") == 0 ||
! 	 	 strcmp(dcfg->appsrv_port,"443") == 0    )
! 		strcpy(dcfg->appsrv_port,"");
  
  //	szBuff[0]= NULL; dwBuffSize=1024;
  //	pFC->GetServerVariable(pFC,"QUERY_STRING",
--- 1577,1587 ----
  	pFC->GetServerVariable(pFC,"SERVER_PORT",
  							szBuff, &dwBuffSize);
  	AddToLog(LogBuff,"  Server SERVER_PORT: %s\n",szBuff);
! 	strcpy(p->appsrv_port,szBuff);
  	// Force port 80 or 443(ssl) to null
! 	if ( strcmp(p->appsrv_port, "80") == 0 ||
! 	 	 strcmp(p->appsrv_port,"443") == 0    )
! 		strcpy(p->appsrv_port,"");
  
  //	szBuff[0]= NULL; dwBuffSize=1024;
  //	pFC->GetServerVariable(pFC,"QUERY_STRING",
***************
*** 1586,1592 ****
  //	pHeaderInfo->GetHeader(pFC,"QUERY_STRING:",
  //							szBuff, &dwBuffSize);
  //	AddToLog(LogBuff,"  Header QUERY_STRING: %s\n",szBuff);
! //	strcpy(dcfg->args,szBuff);
  
  	szBuff[0]= NULL; dwBuffSize=1024;
  	pFC->GetServerVariable(pFC,"HTTP_HOST",
--- 1592,1598 ----
  //	pHeaderInfo->GetHeader(pFC,"QUERY_STRING:",
  //							szBuff, &dwBuffSize);
  //	AddToLog(LogBuff,"  Header QUERY_STRING: %s\n",szBuff);
! //	strcpy(p->args,szBuff);
  
  	szBuff[0]= NULL; dwBuffSize=1024;
  	pFC->GetServerVariable(pFC,"HTTP_HOST",
***************
*** 1594,1609 ****
  	AddToLog(LogBuff,"  Server HTTP_HOST  : %s\n",szBuff);
  
  	return_rslt = SF_STATUS_REQ_NEXT_NOTIFICATION;
! 	dcfg->pszUser[0] = NULL;    // For OnAuth
! 
! 	filterlog(dcfg, LOG_INFO, LogBuff);
  
     // Begin Pubcookie logic
  
  	if ( Pubcookie_User(pFC,pHeaderInfo) == OK ) 
  //		if ( Pubcookie_Auth(pFC) == OK )
  			if ( Pubcookie_Typer(pFC,pHeaderInfo) == OK )
! 				switch (dcfg->handler)
  				{
  				case PBC_BAD_AUTH:
  					Auth_Failed(pFC);
--- 1600,1615 ----
  	AddToLog(LogBuff,"  Server HTTP_HOST  : %s\n",szBuff);
  
  	return_rslt = SF_STATUS_REQ_NEXT_NOTIFICATION;
! 	p->pszUser[0] = NULL;    // For OnAuth
! 
! 	filterlog(p, LOG_INFO, LogBuff);
  
     // Begin Pubcookie logic
  
  	if ( Pubcookie_User(pFC,pHeaderInfo) == OK ) 
  //		if ( Pubcookie_Auth(pFC) == OK )
  			if ( Pubcookie_Typer(pFC,pHeaderInfo) == OK )
! 				switch (p->handler)
  				{
  				case PBC_BAD_AUTH:
  					Auth_Failed(pFC);
***************
*** 1645,1652 ****
  					return_rslt = SF_STATUS_REQ_FINISHED;
  					break;
  				default:
! 					filterlog(dcfg, LOG_ERR,"[PBC_OnPreprocHeaders] Unexpected dcfg->handler value = %d",
! 						dcfg->handler);
  					return_rslt = SF_STATUS_REQ_ERROR;
  					break;
  				}
--- 1651,1658 ----
  					return_rslt = SF_STATUS_REQ_FINISHED;
  					break;
  				default:
! 					filterlog(p, LOG_ERR,"[PBC_OnPreprocHeaders] Unexpected p->handler value = %d",
! 						p->handler);
  					return_rslt = SF_STATUS_REQ_ERROR;
  					break;
  				}
***************
*** 1655,1663 ****
  //		else
  //			Hide_Cookies(pFC,pHeaderInfo);
  	else
! 		Hide_Cookies(pFC,pHeaderInfo);
! 
! 	filterlog(dcfg, LOG_DEBUG," OnPreprocHeaders returned x%X\n",return_rslt);
  	
  	return return_rslt;
  
--- 1661,1669 ----
  //		else
  //			Hide_Cookies(pFC,pHeaderInfo);
  	else
! 		Hide_Cookies(pFC,pHeaderInfo);
! 
! 	filterlog(p, LOG_DEBUG," OnPreprocHeaders returned x%X\n",return_rslt);
  	
  	return return_rslt;
  
***************
*** 1666,1685 ****
  
  DWORD OnUrlMap (HTTP_FILTER_CONTEXT* pFC, 
  			    HTTP_FILTER_URL_MAP* pUrlMapInfo)
! {
! 	char LogBuff[LOGBUFFSIZE]="";
! 	pubcookie_dir_rec* dcfg;
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( dcfg ) {
! 		AddToLog(LogBuff,"PBC_OnUrlMap (%s)\n",dcfg->remote_host);
  	}else {
  		AddToLog(LogBuff,"PBC_OnUrlMap\n");
  	}
  
! 	AddToLog(LogBuff,"  PhysicalPath: %s\n",pUrlMapInfo->pszPhysicalPath);
! 
! 	filterlog(dcfg, LOG_INFO, LogBuff);
  
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
--- 1672,1691 ----
  
  DWORD OnUrlMap (HTTP_FILTER_CONTEXT* pFC, 
  			    HTTP_FILTER_URL_MAP* pUrlMapInfo)
! {
! 	char LogBuff[LOGBUFFSIZE]="";
! 	pubcookie_dir_rec* p;
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( p ) {
! 		AddToLog(LogBuff,"PBC_OnUrlMap (%s)\n",p->remote_host);
  	}else {
  		AddToLog(LogBuff,"PBC_OnUrlMap\n");
  	}
  
! 	AddToLog(LogBuff,"  PhysicalPath: %s\n",pUrlMapInfo->pszPhysicalPath);
! 
! 	filterlog(p, LOG_INFO, LogBuff);
  
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
***************
*** 1689,1700 ****
  DWORD OnAuthentication (HTTP_FILTER_CONTEXT* pFC,
                          HTTP_FILTER_AUTHENT* pAuthInfo)
  {
! 	pubcookie_dir_rec* dcfg;
! 	char LogBuff[LOGBUFFSIZE]="";
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( dcfg ) {
! 		AddToLog(LogBuff,"PBC_OnAuthentication (%s)\n",dcfg->remote_host);
  	} else {
  		AddToLog(LogBuff,"PBC_OnAuthentication\n");
  	}
--- 1695,1706 ----
  DWORD OnAuthentication (HTTP_FILTER_CONTEXT* pFC,
                          HTTP_FILTER_AUTHENT* pAuthInfo)
  {
! 	pubcookie_dir_rec* p;
! 	char LogBuff[LOGBUFFSIZE]="";
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( p ) {
! 		AddToLog(LogBuff,"PBC_OnAuthentication (%s)\n",p->remote_host);
  	} else {
  		AddToLog(LogBuff,"PBC_OnAuthentication\n");
  	}
***************
*** 1702,1718 ****
  	AddToLog(LogBuff,"  Old UserName: %s\n",pAuthInfo->pszUser);
  //	AddToLog(LogBuff,"  Old Password: %s\n",pAuthInfo->pszPassword);
  
! 	if ( dcfg )
! 	if ( strlen(dcfg->pszUser) > 0 && dcfg->legacy) {
  		// Give the mapped user/password back to the server
! 		strcpy(pAuthInfo->pszUser    , dcfg->pszUser);
! 		strcpy(pAuthInfo->pszPassword, dcfg->pszPassword);
  
  		AddToLog(LogBuff,"  New UserName : %s\n",pAuthInfo->pszUser);
  		AddToLog(LogBuff,"  New PW length: %d\n",strlen(pAuthInfo->pszPassword));
  	}
! 	filterlog(dcfg, LOG_INFO, LogBuff);
! 
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnAuthentication */
--- 1708,1724 ----
  	AddToLog(LogBuff,"  Old UserName: %s\n",pAuthInfo->pszUser);
  //	AddToLog(LogBuff,"  Old Password: %s\n",pAuthInfo->pszPassword);
  
! 	if ( p )
! 	if ( strlen(p->pszUser) > 0 && p->legacy) {
  		// Give the mapped user/password back to the server
! 		strcpy(pAuthInfo->pszUser    , p->pszUser);
! 		strcpy(pAuthInfo->pszPassword, p->pszPassword);
  
  		AddToLog(LogBuff,"  New UserName : %s\n",pAuthInfo->pszUser);
  		AddToLog(LogBuff,"  New PW length: %d\n",strlen(pAuthInfo->pszPassword));
  	}
! 	filterlog(p, LOG_INFO, LogBuff);
! 
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnAuthentication */
***************
*** 1721,1733 ****
  DWORD OnAccessDenied (HTTP_FILTER_CONTEXT* pFC, 
  					  HTTP_FILTER_ACCESS_DENIED* pDenyInfo)
  {
! 	pubcookie_dir_rec* dcfg;
! 	char LogBuff[LOGBUFFSIZE]="";
! 
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( dcfg ) {
! 		AddToLog(LogBuff,"PBC_OnAccessDenied (%s)\n",dcfg->remote_host);
  	} else {
  		AddToLog(LogBuff,"PBC_OnAccessDenied\n");
  	}
--- 1727,1739 ----
  DWORD OnAccessDenied (HTTP_FILTER_CONTEXT* pFC, 
  					  HTTP_FILTER_ACCESS_DENIED* pDenyInfo)
  {
! 	pubcookie_dir_rec* p;
! 	char LogBuff[LOGBUFFSIZE]="";
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( p ) {
! 		AddToLog(LogBuff,"PBC_OnAccessDenied (%s)\n",p->remote_host);
  	} else {
  		AddToLog(LogBuff,"PBC_OnAccessDenied\n");
  	}
***************
*** 1736,1743 ****
  	AddToLog(LogBuff,"  PATH  : %s\n",pDenyInfo->pszPhysicalPath);
  	AddToLog(LogBuff,"  Reason: x%x\n",pDenyInfo->dwReason);
  
! 	filterlog(dcfg, LOG_INFO, LogBuff);
! 
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnAccessDenied */
--- 1742,1749 ----
  	AddToLog(LogBuff,"  PATH  : %s\n",pDenyInfo->pszPhysicalPath);
  	AddToLog(LogBuff,"  Reason: x%x\n",pDenyInfo->dwReason);
  
! 	filterlog(p, LOG_INFO, LogBuff);
! 
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnAccessDenied */
***************
*** 1746,1765 ****
  DWORD OnSendResponse (HTTP_FILTER_CONTEXT* pFC,
                        HTTP_FILTER_SEND_RESPONSE* pResponseInfo)
  {
! 	pubcookie_dir_rec* dcfg;
! 	char LogBuff[LOGBUFFSIZE]="";
  
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( dcfg ) {
! 		AddToLog(LogBuff,"PBC_OnSendResponse (%s)\n",dcfg->remote_host);
  	} else {
  		AddToLog(LogBuff,"PBC_OnSendResponse\n");
  	}
  
  	AddToLog(LogBuff,"  HttpStatus: %d\n",pResponseInfo->HttpStatus);
! 
! 	filterlog(dcfg, LOG_INFO, LogBuff);
  
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
--- 1752,1771 ----
  DWORD OnSendResponse (HTTP_FILTER_CONTEXT* pFC,
                        HTTP_FILTER_SEND_RESPONSE* pResponseInfo)
  {
! 	pubcookie_dir_rec* p;
! 	char LogBuff[LOGBUFFSIZE]="";
  
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( p ) {
! 		AddToLog(LogBuff,"PBC_OnSendResponse (%s)\n",p->remote_host);
  	} else {
  		AddToLog(LogBuff,"PBC_OnSendResponse\n");
  	}
  
  	AddToLog(LogBuff,"  HttpStatus: %d\n",pResponseInfo->HttpStatus);
! 
! 	filterlog(p, LOG_INFO, LogBuff);
  
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
***************
*** 1769,1790 ****
  DWORD OnSendRawData (HTTP_FILTER_CONTEXT* pFC,
                       HTTP_FILTER_RAW_DATA* pRawDataInfo)
  {
! 	pubcookie_dir_rec* dcfg;
! 	char LogBuff[LOGBUFFSIZE]="";
  
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( dcfg ) {
! 		AddToLog(LogBuff,"PBC_OnSendRawData (%s)\n",dcfg->remote_host);
  	} else {
  		AddToLog(LogBuff,"PBC_OnSendRawData\n");
  	}
  
  	AddToLog(LogBuff,"  Sending(%d): \n%.*s\n",
  		pRawDataInfo->cbInData,pRawDataInfo->cbInData,pRawDataInfo->pvInData);
! 
! 	filterlog(dcfg, LOG_INFO, LogBuff);
! 
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnSendRawData */
--- 1775,1796 ----
  DWORD OnSendRawData (HTTP_FILTER_CONTEXT* pFC,
                       HTTP_FILTER_RAW_DATA* pRawDataInfo)
  {
! 	pubcookie_dir_rec* p;
! 	char LogBuff[LOGBUFFSIZE]="";
  
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( p ) {
! 		AddToLog(LogBuff,"PBC_OnSendRawData (%s)\n",p->remote_host);
  	} else {
  		AddToLog(LogBuff,"PBC_OnSendRawData\n");
  	}
  
  	AddToLog(LogBuff,"  Sending(%d): \n%.*s\n",
  		pRawDataInfo->cbInData,pRawDataInfo->cbInData,pRawDataInfo->pvInData);
! 
! 	syslog(LOG_ERR, LogBuff); //debug LOG_INFO
! 
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnSendRawData */
***************
*** 1792,1809 ****
  
  DWORD OnEndOfRequest (HTTP_FILTER_CONTEXT* pFC)
  {
! 	pubcookie_dir_rec* dcfg;
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( dcfg ) {
! 		filterlog(dcfg, LOG_INFO,"PBC_OnEndOfRequest (%s)\n",dcfg->remote_host);
  	} else {
! 		filterlog(dcfg, LOG_INFO,"PBC_OnEndOfRequest\n");
  	}
  			
  	// OnEndOfNetSession is not called consistantly for each request,
  	// free here instead.
! 	// Assumes we don't need this structure in OnLog below
  	// **Need to use AllocMem instead** we can't be sure we don't need it in OnLog.
  	
  	//pbc_free(p, pFC->pFilterContext);
--- 1798,1815 ----
  
  DWORD OnEndOfRequest (HTTP_FILTER_CONTEXT* pFC)
  {
! 	pubcookie_dir_rec* p;
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( p ) {
! 		filterlog(p, LOG_INFO,"PBC_OnEndOfRequest (%s)\n",p->remote_host);
  	} else {
! 		filterlog(p, LOG_INFO,"PBC_OnEndOfRequest\n");
  	}
  			
  	// OnEndOfNetSession is not called consistantly for each request,
  	// free here instead.
! 	// Assumes we don't need this structure in OnLog below
  	// **Need to use AllocMem instead** we can't be sure we don't need it in OnLog.
  	
  	//pbc_free(p, pFC->pFilterContext);
***************
*** 1835,1849 ****
  DWORD OnLog (HTTP_FILTER_CONTEXT* pFC, 
  		  	 HTTP_FILTER_LOG* pLogInfo)
  {
! 	char szBuff[1024];
! 	char LogBuff[LOGBUFFSIZE]="";
  	DWORD dwBuffSize,dwReserved=NULL;
! 	pubcookie_dir_rec* dcfg;
! 	char *pszNewClient;
! 	char strbuff[MAX_REG_BUFF];
  
- 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
- 
  	AddToLog(LogBuff,"PBC_OnLog\n");
  
  	szBuff[0]= NULL; dwBuffSize=1024;
--- 1841,1854 ----
  DWORD OnLog (HTTP_FILTER_CONTEXT* pFC, 
  		  	 HTTP_FILTER_LOG* pLogInfo)
  {
! 	char szBuff[1024];
! 	char LogBuff[LOGBUFFSIZE]="";
  	DWORD dwBuffSize,dwReserved=NULL;
! 	pubcookie_dir_rec* p;
! 	char *pszNewClient;
! 
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
  	AddToLog(LogBuff,"PBC_OnLog\n");
  
  	szBuff[0]= NULL; dwBuffSize=1024;
***************
*** 1852,1868 ****
  							szBuff, &dwBuffSize);
  	AddToLog(LogBuff,"  Instance ID   : %s\n",szBuff);
  
! 	if ( dcfg ) {
! 		if (strlen(dcfg->user) > 0) {
! 			dwBuffSize=1024;
! 			pszNewClient = (char *)pFC->AllocMem(pFC,dwBuffSize,0);
! 			strncpy(pszNewClient,(PBC_CLIENT_LOG_FMT), dwBuffSize);
! 			ReplaceToken("%w",pLogInfo->pszClientUserName,pszNewClient, dwBuffSize);
! 			ReplaceToken("%p",dcfg->user, pszNewClient, dwBuffSize);
! 			AddToLog(LogBuff,"  Modified user : %s\n",pszNewClient);
! 			pLogInfo->pszClientUserName = pszNewClient;
! 		}
! 	}
  	AddToLog(LogBuff,"  ClientHostName: %s\n",pLogInfo->pszClientHostName);
  	AddToLog(LogBuff,"  ClientUserName: %s\n",pLogInfo->pszClientUserName);
  	AddToLog(LogBuff,"  ServerName    : %s\n",pLogInfo->pszServerName);
--- 1857,1873 ----
  							szBuff, &dwBuffSize);
  	AddToLog(LogBuff,"  Instance ID   : %s\n",szBuff);
  
! 	if ( p ) {
! 		if (strlen(p->user) > 0) {
! 			dwBuffSize=1024;
! 			pszNewClient = (char *)pFC->AllocMem(pFC,dwBuffSize,0);
! 			strncpy(pszNewClient,(PBC_CLIENT_LOG_FMT), dwBuffSize);
! 			ReplaceToken("%w",pLogInfo->pszClientUserName,pszNewClient, dwBuffSize);
! 			ReplaceToken("%p",p->user, pszNewClient, dwBuffSize);
! 			AddToLog(LogBuff,"  Modified user : %s\n",pszNewClient);
! 			pLogInfo->pszClientUserName = pszNewClient;
! 		}
! 	}
  	AddToLog(LogBuff,"  ClientHostName: %s\n",pLogInfo->pszClientHostName);
  	AddToLog(LogBuff,"  ClientUserName: %s\n",pLogInfo->pszClientUserName);
  	AddToLog(LogBuff,"  ServerName    : %s\n",pLogInfo->pszServerName);
***************
*** 1875,1882 ****
  	AddToLog(LogBuff,"  BytesReceived : %d\n",pLogInfo->dwBytesRecvd);
  	AddToLog(LogBuff,"  ProcTime      : %d\n",pLogInfo->msTimeForProcessing);
  
! 	filterlog(dcfg, LOG_INFO, LogBuff);
! 
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnLog */
--- 1880,1887 ----
  	AddToLog(LogBuff,"  BytesReceived : %d\n",pLogInfo->dwBytesRecvd);
  	AddToLog(LogBuff,"  ProcTime      : %d\n",pLogInfo->msTimeForProcessing);
  
! 	filterlog(p, LOG_INFO, LogBuff);
! 
  	return SF_STATUS_REQ_NEXT_NOTIFICATION;
  
  }  /* OnLog */
***************
*** 1884,1896 ****
  
  DWORD OnEndOfNetSession (HTTP_FILTER_CONTEXT* pFC)
  {
! 	pubcookie_dir_rec* dcfg;
! 	dcfg = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( dcfg ) {
! 		filterlog(dcfg, LOG_INFO,"PBC_OnEndOfNetSession (%s)\n",dcfg->remote_host);
  	} else {
! 		filterlog(dcfg, LOG_INFO,"PBC_OnEndOfNetSession\n");
  	}
  			
  	// Free pFilterContext here if allocated via malloc
--- 1889,1901 ----
  
  DWORD OnEndOfNetSession (HTTP_FILTER_CONTEXT* pFC)
  {
! 	pubcookie_dir_rec* p;
! 	p = (pubcookie_dir_rec *)pFC->pFilterContext;
  
! 	if ( p ) {
! 		filterlog(p, LOG_INFO,"PBC_OnEndOfNetSession (%s)\n",p->remote_host);
  	} else {
! 		filterlog(p, LOG_INFO,"PBC_OnEndOfNetSession\n");
  	}
  			
  	// Free pFilterContext here if allocated via malloc
***************
*** 1948,1954 ****
  		dwRet = SF_STATUS_REQ_NEXT_NOTIFICATION;
  		break;
  	}
! 
  	return dwRet;
  
  }  /* HttpFilterProc */
--- 1953,1959 ----
  		dwRet = SF_STATUS_REQ_NEXT_NOTIFICATION;
  		break;
  	}
! 
  	return dwRet;
  
  }  /* HttpFilterProc */
***************
*** 2040,2046 ****
  			break;
  		}
      }   /* switch */
! 	
  	syslog(LOG_INFO, "PBC_DllMain: Returning %d\n",fReturn); 
  	
      return ( fReturn);
--- 2045,2051 ----
  			break;
  		}
      }   /* switch */
! 	
  	syslog(LOG_INFO, "PBC_DllMain: Returning %d\n",fReturn); 
  	
      return ( fReturn);


Index: webiso/pubcookie/src/Win32/PubCookieFilter.h
diff -c webiso/pubcookie/src/Win32/PubCookieFilter.h:1.24 webiso/pubcookie/src/Win32/PubCookieFilter.h:1.25
*** webiso/pubcookie/src/Win32/PubCookieFilter.h:1.24	Thu Nov 20 22:50:49 2003
--- webiso/pubcookie/src/Win32/PubCookieFilter.h	Thu Jan 22 21:00:26 2004
***************
*** 4,10 ****
  //
  
  //
! //  $Id: PubCookieFilter.h,v 1.24 2003/11/21 06:50:49 ryanc Exp $
  //
  
  #define Pubcookie_Version "Pubcookie ISAPI Filter, 3.0.1 pre-beta1"
--- 4,10 ----
  //
  
  //
! //  $Id: PubCookieFilter.h,v 1.25 2004/01/23 05:00:26 ryanc Exp $
  //
  
  #define Pubcookie_Version "Pubcookie ISAPI Filter, 3.0.1 pre-beta1"
***************
*** 43,50 ****
  	char			*s_certfile;
  	char			*crypt_keyfile;
  	int				serial_s_sent;
! 	char			server_hostname[MAX_PATH];
  	char			instance_id[8];
  
  } pubcookie_dir_rec;
  
--- 43,51 ----
  	char			*s_certfile;
  	char			*crypt_keyfile;
  	int				serial_s_sent;
! 	char			server_hostname[MAX_PATH];
  	char			instance_id[8];
+ 	char			strbuff[MAX_REG_BUFF];  //temporary buffer for libpbc_config_getstring calls
  
  } pubcookie_dir_rec;
  
***************
*** 108,126 ****
  #define LOGOUT_LOCAL 1  //NOTE: overrides AuthType to PUBLIC
  #define LOGOUT_REDIRECT 2
  #define LOGOUT_REDIRECT_CLEAR_LOGIN 3
! 
! // Only need two marked below for functionality, rest for debug
! const DWORD 	
! Notify_Flags =  ( SF_NOTIFY_SECURE_PORT         |
! 					  SF_NOTIFY_NONSECURE_PORT      |
! //					  SF_NOTIFY_READ_RAW_DATA       | // Only for Global Filters
! 					  SF_NOTIFY_PREPROC_HEADERS     | // ** Needed
! 					  SF_NOTIFY_URL_MAP             |
! 					  SF_NOTIFY_AUTHENTICATION      | // ** Needed
! 					  SF_NOTIFY_ACCESS_DENIED       |
! 					  SF_NOTIFY_SEND_RESPONSE       |
! //					  SF_NOTIFY_SEND_RAW_DATA       |  // Too many debug calls
! 					  SF_NOTIFY_END_OF_REQUEST      |
! 					  SF_NOTIFY_LOG                 |
! 					  SF_NOTIFY_END_OF_NET_SESSION  |
! 					  SF_NOTIFY_ORDER_DEFAULT ); 
--- 109,127 ----
  #define LOGOUT_LOCAL 1  //NOTE: overrides AuthType to PUBLIC
  #define LOGOUT_REDIRECT 2
  #define LOGOUT_REDIRECT_CLEAR_LOGIN 3
! 
! // Only need two marked below for functionality, rest for debug
! static const DWORD 	
! Notify_Flags =  ( SF_NOTIFY_SECURE_PORT         |
! 					  SF_NOTIFY_NONSECURE_PORT      |
! 					  SF_NOTIFY_READ_RAW_DATA       | // Only for Global Filters  //debug
! 					  SF_NOTIFY_PREPROC_HEADERS     | // ** Needed
! 					  SF_NOTIFY_URL_MAP             |
! 					  SF_NOTIFY_AUTHENTICATION      | // ** Needed
! 					  SF_NOTIFY_ACCESS_DENIED       |
! 					  SF_NOTIFY_SEND_RESPONSE       |
! 					  SF_NOTIFY_SEND_RAW_DATA       |  // Too many debug calls  //debug
! 					  SF_NOTIFY_END_OF_REQUEST      |
! 					  SF_NOTIFY_LOG                 |
! 					  SF_NOTIFY_END_OF_NET_SESSION  |
! 					  SF_NOTIFY_ORDER_DEFAULT ); 


Index: webiso/pubcookie/src/Win32/PubCookieFilter.sln
diff -c webiso/pubcookie/src/Win32/PubCookieFilter.sln:1.1 webiso/pubcookie/src/Win32/PubCookieFilter.sln:1.2
*** webiso/pubcookie/src/Win32/PubCookieFilter.sln:1.1	Thu Nov 20 22:50:49 2003
--- webiso/pubcookie/src/Win32/PubCookieFilter.sln	Thu Jan 22 21:00:26 2004
***************
*** 1,27 ****
! Microsoft Visual Studio Solution File, Format Version 7.00
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PubCookieFilter", "PubCookieFilter.vcproj", "{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}"
! EndProject
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pbc_messages", "pbc_messages.vcproj", "{70162427-59FC-45E7-AD96-E87043A23374}"
! EndProject
! Global
! 	GlobalSection(SolutionConfiguration) = preSolution
! 		ConfigName.0 = Debug
! 		ConfigName.1 = Release
! 	EndGlobalSection
! 	GlobalSection(ProjectDependencies) = postSolution
! 	EndGlobalSection
! 	GlobalSection(ProjectConfiguration) = postSolution
! 		{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}.Debug.ActiveCfg = Release|Win32
! 		{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}.Debug.Build.0 = Release|Win32
! 		{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}.Release.ActiveCfg = Release|Win32
! 		{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}.Release.Build.0 = Release|Win32
! 		{70162427-59FC-45E7-AD96-E87043A23374}.Debug.ActiveCfg = Release|Win32
! 		{70162427-59FC-45E7-AD96-E87043A23374}.Debug.Build.0 = Release|Win32
! 		{70162427-59FC-45E7-AD96-E87043A23374}.Release.ActiveCfg = Release|Win32
! 		{70162427-59FC-45E7-AD96-E87043A23374}.Release.Build.0 = Release|Win32
! 	EndGlobalSection
! 	GlobalSection(ExtensibilityGlobals) = postSolution
! 	EndGlobalSection
! 	GlobalSection(ExtensibilityAddIns) = postSolution
! 	EndGlobalSection
! EndGlobal
--- 1,27 ----
! Microsoft Visual Studio Solution File, Format Version 7.00
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PubCookieFilter", "PubCookieFilter.vcproj", "{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}"
! EndProject
! Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pbc_messages", "pbc_messages.vcproj", "{70162427-59FC-45E7-AD96-E87043A23374}"
! EndProject
! Global
! 	GlobalSection(SolutionConfiguration) = preSolution
! 		ConfigName.0 = Debug
! 		ConfigName.1 = Release
! 	EndGlobalSection
! 	GlobalSection(ProjectDependencies) = postSolution
! 	EndGlobalSection
! 	GlobalSection(ProjectConfiguration) = postSolution
! 		{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}.Debug.ActiveCfg = Debug|Win32
! 		{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}.Debug.Build.0 = Debug|Win32
! 		{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}.Release.ActiveCfg = Release|Win32
! 		{1A25D5CB-EAD0-4631-9013-F11F3109C2D5}.Release.Build.0 = Release|Win32
! 		{70162427-59FC-45E7-AD96-E87043A23374}.Debug.ActiveCfg = Release|Win32
! 		{70162427-59FC-45E7-AD96-E87043A23374}.Debug.Build.0 = Release|Win32
! 		{70162427-59FC-45E7-AD96-E87043A23374}.Release.ActiveCfg = Release|Win32
! 		{70162427-59FC-45E7-AD96-E87043A23374}.Release.Build.0 = Release|Win32
! 	EndGlobalSection
! 	GlobalSection(ExtensibilityGlobals) = postSolution
! 	EndGlobalSection
! 	GlobalSection(ExtensibilityAddIns) = postSolution
! 	EndGlobalSection
! EndGlobal


Index: webiso/pubcookie/src/Win32/PubCookieFilter.vcproj
diff -c webiso/pubcookie/src/Win32/PubCookieFilter.vcproj:1.2 webiso/pubcookie/src/Win32/PubCookieFilter.vcproj:1.3
*** webiso/pubcookie/src/Win32/PubCookieFilter.vcproj:1.2	Wed Dec 17 14:10:56 2003
--- webiso/pubcookie/src/Win32/PubCookieFilter.vcproj	Thu Jan 22 21:00:26 2004
***************
*** 1,208 ****
! <?xml version="1.0" encoding = "Windows-1252"?>
! <VisualStudioProject
! 	ProjectType="Visual C++"
! 	Version="7.00"
! 	Name="PubCookieFilter"
! 	SccProjectName="&quot;$/PubCookieFilter&quot;, XXBAAAAA"
! 	SccLocalPath=".">
! 	<Platforms>
! 		<Platform
! 			Name="Win32"/>
! 	</Platforms>
! 	<Configurations>
! 		<Configuration
! 			Name="Release|Win32"
! 			OutputDirectory=".\Release"
! 			IntermediateDirectory=".\Release"
! 			ConfigurationType="2"
! 			UseOfMFC="0"
! 			ATLMinimizesCRunTimeLibraryUsage="FALSE"
! 			CharacterSet="2">
! 			<Tool
! 				Name="VCCLCompilerTool"
! 				InlineFunctionExpansion="1"
! 				AdditionalIncludeDirectories=".\include,.\include\openssl"
! 				PreprocessorDefinitions="NDEBUG;_USRDLL;WIN32;_WINDOWS;STATICLIB;HAVE_STRING_H;HAVE_STDIO_H;HAVE_STDARG_H;HAVE_SNPRINTF"
! 				StringPooling="TRUE"
! 				RuntimeLibrary="2"
! 				EnableFunctionLevelLinking="TRUE"
! 				UsePrecompiledHeader="0"
! 				PrecompiledHeaderFile=".\Release/PubCookieFilter.pch"
! 				AssemblerListingLocation=".\Release/"
! 				ObjectFile=".\Release/"
! 				ProgramDataBaseFileName=".\Release/"
! 				BrowseInformation="1"
! 				WarningLevel="3"
! 				SuppressStartupBanner="TRUE"
! 				CompileAs="0"/>
! 			<Tool
! 				Name="VCCustomBuildTool"/>
! 			<Tool
! 				Name="VCLinkerTool"
! 				AdditionalOptions="/MACHINE:I386"
! 				AdditionalDependencies="libeay32.lib odbc32.lib odbccp32.lib wsock32.lib"
! 				OutputFile=".\Release/PubCookieFilter.dll"
! 				LinkIncremental="1"
! 				AdditionalLibraryDirectories=".\lib"
! 				ModuleDefinitionFile=".\PubCookieFilter.def"
! 				ProgramDatabaseFile=".\Release/PubCookieFilter.pdb"
! 				ImportLibrary=".\Release/PubCookieFilter.lib"/>
! 			<Tool
! 				Name="VCMIDLTool"
! 				PreprocessorDefinitions="NDEBUG"
! 				MkTypLibCompatible="TRUE"
! 				SuppressStartupBanner="TRUE"
! 				TargetEnvironment="1"
! 				TypeLibraryName=".\Release/PubCookieFilter.tlb"/>
! 			<Tool
! 				Name="VCPostBuildEventTool"/>
! 			<Tool
! 				Name="VCPreBuildEventTool"/>
! 			<Tool
! 				Name="VCPreLinkEventTool"/>
! 			<Tool
! 				Name="VCResourceCompilerTool"
! 				PreprocessorDefinitions="NDEBUG"
! 				Culture="1033"/>
! 			<Tool
! 				Name="VCWebServiceProxyGeneratorTool"/>
! 			<Tool
! 				Name="VCWebDeploymentTool"/>
! 		</Configuration>
! 		<Configuration
! 			Name="Debug|Win32"
! 			OutputDirectory=".\Debug"
! 			IntermediateDirectory=".\Debug"
! 			ConfigurationType="2"
! 			UseOfMFC="0"
! 			ATLMinimizesCRunTimeLibraryUsage="FALSE">
! 			<Tool
! 				Name="VCCLCompilerTool"
! 				Optimization="0"
! 				AdditionalIncludeDirectories=".\include,.\include\openssl"
! 				PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;STATICLIB;HAVE_STRING_H;HAVE_STDIO_H;HAVE_STDARG_H;HAVE_SNPRINTF"
! 				BasicRuntimeChecks="3"
! 				RuntimeLibrary="1"
! 				UsePrecompiledHeader="2"
! 				PrecompiledHeaderFile=".\Debug/PubCookieFilter.pch"
! 				AssemblerListingLocation=".\Debug/"
! 				ObjectFile=".\Debug/"
! 				ProgramDataBaseFileName=".\Debug/"
! 				BrowseInformation="1"
! 				WarningLevel="3"
! 				SuppressStartupBanner="TRUE"
! 				DebugInformationFormat="4"
! 				CompileAs="0"/>
! 			<Tool
! 				Name="VCCustomBuildTool"/>
! 			<Tool
! 				Name="VCLinkerTool"
! 				AdditionalOptions="/MACHINE:I386"
! 				AdditionalDependencies="libeay32.lib odbc32.lib odbccp32.lib wsock32.lib"
! 				OutputFile=".\Debug/PubCookieFilter.dll"
! 				LinkIncremental="1"
! 				AdditionalLibraryDirectories=".\lib"
! 				IgnoreDefaultLibraryNames="MSVCRT.lib"
! 				ModuleDefinitionFile=".\PubCookieFilter.def"
! 				GenerateDebugInformation="TRUE"
! 				ProgramDatabaseFile=".\Debug/PubCookieFilter.pdb"
! 				GenerateMapFile="TRUE"
! 				MapFileName=".\Debug/PubCookieFilter.map"
! 				ImportLibrary=".\Debug/PubCookieFilter.lib"/>
! 			<Tool
! 				Name="VCMIDLTool"
! 				PreprocessorDefinitions="_DEBUG"
! 				MkTypLibCompatible="TRUE"
! 				SuppressStartupBanner="TRUE"
! 				TargetEnvironment="1"
! 				TypeLibraryName=".\Debug/PubCookieFilter.tlb"/>
! 			<Tool
! 				Name="VCPostBuildEventTool"/>
! 			<Tool
! 				Name="VCPreBuildEventTool"/>
! 			<Tool
! 				Name="VCPreLinkEventTool"/>
! 			<Tool
! 				Name="VCResourceCompilerTool"
! 				PreprocessorDefinitions="_DEBUG"
! 				Culture="1033"/>
! 			<Tool
! 				Name="VCWebServiceProxyGeneratorTool"/>
! 			<Tool
! 				Name="VCWebDeploymentTool"/>
! 		</Configuration>
! 	</Configurations>
! 	<Files>
! 		<Filter
! 			Name="Source Files"
! 			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
! 			<File
! 				RelativePath=".\PubCookieFilter.cpp">
! 			</File>
! 			<File
! 				RelativePath=".\PubCookieFilter.def">
! 			</File>
! 			<File
! 				RelativePath="..\base64.c">
! 			</File>
! 			<File
! 				RelativePath=".\debug.c">
! 			</File>
! 			<File
! 				RelativePath="..\libpubcookie.c">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_configure.c">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_myconfig.c">
! 			</File>
! 			<File
! 				RelativePath="..\security_legacy.c">
! 			</File>
! 			<File
! 				RelativePath="..\strlcpy.c">
! 			</File>
! 		</Filter>
! 		<Filter
! 			Name="Header Files"
! 			Filter="h;hpp;hxx;hm;inl">
! 			<File
! 				RelativePath=".\PubCookieFilter.h">
! 			</File>
! 			<File
! 				RelativePath=".\debug.h">
! 			</File>
! 			<File
! 				RelativePath="..\libpubcookie.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_config.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_configure.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_myconfig.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_version.h">
! 			</File>
! 			<File
! 				RelativePath="..\pubcookie.h">
! 			</File>
! 			<File
! 				RelativePath="..\security.h">
! 			</File>
! 		</Filter>
! 		<Filter
! 			Name="Resource Files"
! 			Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
! 			<File
! 				RelativePath=".\PubcookieFilter.rc">
! 			</File>
! 		</Filter>
! 	</Files>
! 	<Globals>
! 	</Globals>
! </VisualStudioProject>
--- 1,210 ----
! <?xml version="1.0" encoding = "Windows-1252"?>
! <VisualStudioProject
! 	ProjectType="Visual C++"
! 	Version="7.00"
! 	Name="PubCookieFilter"
! 	SccProjectName="&quot;$/PubCookieFilter&quot;, XXBAAAAA"
! 	SccLocalPath=".">
! 	<Platforms>
! 		<Platform
! 			Name="Win32"/>
! 	</Platforms>
! 	<Configurations>
! 		<Configuration
! 			Name="Release|Win32"
! 			OutputDirectory=".\Release"
! 			IntermediateDirectory=".\Release"
! 			ConfigurationType="2"
! 			UseOfMFC="0"
! 			ATLMinimizesCRunTimeLibraryUsage="FALSE"
! 			CharacterSet="2">
! 			<Tool
! 				Name="VCCLCompilerTool"
! 				InlineFunctionExpansion="1"
! 				AdditionalIncludeDirectories=".\include,.\include\openssl"
! 				PreprocessorDefinitions="_USRDLL;WIN32;_WINDOWS;STATICLIB;HAVE_STDLIB_H;HAVE_STRING_H;HAVE_STDIO_H;HAVE_STDARG_H;HAVE_SNPRINTF;HAVE_CTYPE_H"
! 				StringPooling="TRUE"
! 				RuntimeLibrary="2"
! 				EnableFunctionLevelLinking="TRUE"
! 				UsePrecompiledHeader="0"
! 				PrecompiledHeaderFile=".\Release/PubCookieFilter.pch"
! 				AssemblerListingLocation=".\Release/"
! 				ObjectFile=".\Release/"
! 				ProgramDataBaseFileName=".\Release/"
! 				BrowseInformation="1"
! 				WarningLevel="3"
! 				SuppressStartupBanner="TRUE"
! 				DebugInformationFormat="0"
! 				CompileAs="0"/>
! 			<Tool
! 				Name="VCCustomBuildTool"/>
! 			<Tool
! 				Name="VCLinkerTool"
! 				AdditionalOptions="/MACHINE:I386"
! 				AdditionalDependencies="libeay32.lib odbc32.lib odbccp32.lib wsock32.lib"
! 				OutputFile=".\Release/PubCookieFilter.dll"
! 				LinkIncremental="1"
! 				AdditionalLibraryDirectories=".\lib"
! 				ModuleDefinitionFile=".\PubCookieFilter.def"
! 				ProgramDatabaseFile=".\Release/PubCookieFilter.pdb"
! 				ImportLibrary=".\Release/PubCookieFilter.lib"/>
! 			<Tool
! 				Name="VCMIDLTool"
! 				PreprocessorDefinitions="NDEBUG"
! 				MkTypLibCompatible="TRUE"
! 				SuppressStartupBanner="TRUE"
! 				TargetEnvironment="1"
! 				TypeLibraryName=".\Release/PubCookieFilter.tlb"/>
! 			<Tool
! 				Name="VCPostBuildEventTool"/>
! 			<Tool
! 				Name="VCPreBuildEventTool"/>
! 			<Tool
! 				Name="VCPreLinkEventTool"/>
! 			<Tool
! 				Name="VCResourceCompilerTool"
! 				PreprocessorDefinitions="NDEBUG"
! 				Culture="1033"/>
! 			<Tool
! 				Name="VCWebServiceProxyGeneratorTool"/>
! 			<Tool
! 				Name="VCWebDeploymentTool"/>
! 		</Configuration>
! 		<Configuration
! 			Name="Debug|Win32"
! 			OutputDirectory=".\Debug"
! 			IntermediateDirectory=".\Debug"
! 			ConfigurationType="2"
! 			UseOfMFC="0"
! 			ATLMinimizesCRunTimeLibraryUsage="FALSE"
! 			CharacterSet="2">
! 			<Tool
! 				Name="VCCLCompilerTool"
! 				Optimization="0"
! 				AdditionalIncludeDirectories=".\include,.\include\openssl"
! 				PreprocessorDefinitions="_DEBUG;_USRDLL;WIN32;_WINDOWS;STATICLIB;HAVE_STRING_H;HAVE_STDIO_H;HAVE_STDARG_H;HAVE_SNPRINTF"
! 				BasicRuntimeChecks="3"
! 				RuntimeLibrary="3"
! 				UsePrecompiledHeader="2"
! 				PrecompiledHeaderFile=".\Debug/PubCookieFilter.pch"
! 				AssemblerListingLocation=".\Debug/"
! 				ObjectFile=".\Debug/"
! 				ProgramDataBaseFileName=".\Debug/"
! 				BrowseInformation="1"
! 				WarningLevel="3"
! 				SuppressStartupBanner="TRUE"
! 				DebugInformationFormat="3"
! 				CompileAs="0"/>
! 			<Tool
! 				Name="VCCustomBuildTool"/>
! 			<Tool
! 				Name="VCLinkerTool"
! 				AdditionalOptions="/MACHINE:I386"
! 				AdditionalDependencies="libeay32.lib odbc32.lib odbccp32.lib wsock32.lib"
! 				OutputFile=".\Debug/PubCookieFilter.dll"
! 				LinkIncremental="1"
! 				AdditionalLibraryDirectories=".\lib"
! 				IgnoreDefaultLibraryNames=""
! 				ModuleDefinitionFile=".\PubCookieFilter.def"
! 				GenerateDebugInformation="TRUE"
! 				ProgramDatabaseFile=".\Debug/PubCookieFilter.pdb"
! 				GenerateMapFile="TRUE"
! 				MapFileName=".\Debug/PubCookieFilter.map"
! 				ImportLibrary=".\Debug/PubCookieFilter.lib"/>
! 			<Tool
! 				Name="VCMIDLTool"
! 				PreprocessorDefinitions="_DEBUG"
! 				MkTypLibCompatible="TRUE"
! 				SuppressStartupBanner="TRUE"
! 				TargetEnvironment="1"
! 				TypeLibraryName=".\Debug/PubCookieFilter.tlb"/>
! 			<Tool
! 				Name="VCPostBuildEventTool"/>
! 			<Tool
! 				Name="VCPreBuildEventTool"/>
! 			<Tool
! 				Name="VCPreLinkEventTool"/>
! 			<Tool
! 				Name="VCResourceCompilerTool"
! 				PreprocessorDefinitions="_DEBUG"
! 				Culture="1033"/>
! 			<Tool
! 				Name="VCWebServiceProxyGeneratorTool"/>
! 			<Tool
! 				Name="VCWebDeploymentTool"/>
! 		</Configuration>
! 	</Configurations>
! 	<Files>
! 		<Filter
! 			Name="Source Files"
! 			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
! 			<File
! 				RelativePath=".\PubCookieFilter.cpp">
! 			</File>
! 			<File
! 				RelativePath=".\PubCookieFilter.def">
! 			</File>
! 			<File
! 				RelativePath="..\base64.c">
! 			</File>
! 			<File
! 				RelativePath=".\debug.c">
! 			</File>
! 			<File
! 				RelativePath="..\libpubcookie.c">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_configure.c">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_myconfig.c">
! 			</File>
! 			<File
! 				RelativePath="..\security_legacy.c">
! 			</File>
! 			<File
! 				RelativePath="..\strlcpy.c">
! 			</File>
! 		</Filter>
! 		<Filter
! 			Name="Header Files"
! 			Filter="h;hpp;hxx;hm;inl">
! 			<File
! 				RelativePath=".\PubCookieFilter.h">
! 			</File>
! 			<File
! 				RelativePath=".\debug.h">
! 			</File>
! 			<File
! 				RelativePath="..\libpubcookie.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_config.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_configure.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_myconfig.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_version.h">
! 			</File>
! 			<File
! 				RelativePath="..\pubcookie.h">
! 			</File>
! 			<File
! 				RelativePath="..\security.h">
! 			</File>
! 		</Filter>
! 		<Filter
! 			Name="Resource Files"
! 			Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
! 			<File
! 				RelativePath=".\PubcookieFilter.rc">
! 			</File>
! 		</Filter>
! 	</Files>
! 	<Globals>
! 	</Globals>
! </VisualStudioProject>


Index: webiso/pubcookie/src/Win32/debug.c
diff -c webiso/pubcookie/src/Win32/debug.c:1.11 webiso/pubcookie/src/Win32/debug.c:1.12
*** webiso/pubcookie/src/Win32/debug.c:1.11	Tue Nov 11 20:46:29 2003
--- webiso/pubcookie/src/Win32/debug.c	Thu Jan 22 21:00:26 2004
***************
*** 1,119 ****
! //
! //  Copyright (c) 1999-2003 University of Washington.  All rights reserved.
! //  For terms of use see doc/LICENSE.txt in this distribution.
! //
! 
! //
! //  $Id: debug.c,v 1.11 2003/11/12 04:46:29 ryanc Exp $
! //
! 
! #include <windows.h>
! #include <stdio.h>
! #include <stdlib.h>
! #include <string.h>
! #include <ctype.h>
! #include <stdio.h>
! #include <time.h>
! #include <direct.h>
! 
! typedef void pool;
! 
! 
! #include <pem.h>
! #include "../pubcookie.h"
! #include "../libpubcookie.h"
! #include "../pbc_config.h"
! #include "../pbc_version.h"
! #include "../pbc_myconfig.h"
! #include "../pbc_configure.h"
! #include "debug.h"
! 
! extern pool *p=NULL;
! 
! #define BUFFSIZE 4096
! 
! extern void filter_log_activity ( const char * source, int logging_level, const char * format, va_list args )
! {
! 
!     char      log[BUFFSIZE];
! 	HANDLE hEvent;
! 	PTSTR pszaStrings[1];
! 	unsigned short errortype;
! 	DWORD eventid=PBC_ERR_ID_SIMPLE;
! 
!     if (logging_level <= (libpbc_config_getint(p,"Debug_Trace", LOG_WARN)))    {
! 		
! 		switch (logging_level) {
! 		case LOG_INFO:
!             errortype = EVENTLOG_INFORMATION_TYPE;
!             break;
! 		case LOG_DEBUG:
!             errortype = EVENTLOG_INFORMATION_TYPE;
! 			eventid = PBC_ERR_ID_DEBUG;
!             break;
! 		case LOG_ERR:
!             errortype = EVENTLOG_ERROR_TYPE;
! 			break;
! 		case LOG_WARN:
! 		default:
! 			errortype = EVENTLOG_WARNING_TYPE;
! 			
! 		}
!         _vsnprintf(log, BUFFSIZE, format, args);
! 		pszaStrings[0] = log;
!         hEvent = RegisterEventSource(NULL,source);
! 		if (hEvent) 
! 		{
! 			ReportEvent(hEvent, errortype, 0, eventid, NULL, (WORD)1, 0,                  
!                 (const char **)pszaStrings, NULL);                   
! 			DeregisterEventSource(hEvent);
! 		}
! 	}
! 
! 
! }
! 
! void pbc_vlog_activity( int logging_level, const char * format, va_list args )
! {
! 	filter_log_activity ("Pubcookie", logging_level, format, args);
! }
! 
! extern void syslog(int whichlog, const char *message, ...) {
! 
!     va_list   args;
! 
!     va_start(args, message);
! 
!     pbc_vlog_activity( whichlog, message, args );
! 
!     va_end(args);
! 
! }
! extern void pbc_log_activity(pool *p, int logging_level, const char *message,...)
! {
!     va_list   args;
! 
!     va_start(args, message);
! 
!     pbc_vlog_activity( logging_level, message, args );
! 
!     va_end(args);
! }
! 
! char * AddToLog(char*LogBuff, const char *format, ...) {
! 	char *LogPos;
! 
! 	va_list   args;
! 
!     va_start(args, format);
! 
! 	LogPos = LogBuff + strlen(LogBuff);
! 
!     _vsnprintf(LogPos, LOGBUFFSIZE - (LogPos - LogBuff), format, args);
! 
!     va_end(args);
! 
!     return (LogBuff);
! }
! 
! 
--- 1,123 ----
! //
! //  Copyright (c) 1999-2003 University of Washington.  All rights reserved.
! //  For terms of use see doc/LICENSE.txt in this distribution.
! //
! 
! //
! //  $Id: debug.c,v 1.12 2004/01/23 05:00:26 ryanc Exp $
! //
! 
! #include <windows.h>
! #include <stdio.h>
! #include <stdlib.h>
! #include <string.h>
! #include <ctype.h>
! #include <stdio.h>
! #include <time.h>
! #include <direct.h>
! 
! #include <pem.h>
! #include <httpfilt.h>
! #include "../pubcookie.h"
! #include "../pbc_config.h"
! #include "PubCookieFilter.h"
! typedef pubcookie_dir_rec pool;
! #include "../libpubcookie.h"
! #include "../pbc_version.h"
! #include "../pbc_myconfig.h"
! #include "../pbc_configure.h"
! #include "debug.h"
! 
! #define BUFFSIZE 4096
! 
! extern void filter_log_activity (pool *p, const char * source, int logging_level, const char * format, va_list args )
! {
! 
!     char      log[BUFFSIZE];
! 	HANDLE hEvent;
! 	PTSTR pszaStrings[1];
! 	unsigned short errortype;
! 	DWORD eventid=PBC_ERR_ID_SIMPLE;
! 
!     if (logging_level <= (libpbc_config_getint(p,"Debug_Trace", LOG_WARN)))    {
! 		
! 		switch (logging_level) {
! 		case LOG_INFO:
!             errortype = EVENTLOG_INFORMATION_TYPE;
!             break;
! 		case LOG_DEBUG:
!             errortype = EVENTLOG_INFORMATION_TYPE;
! 			eventid = PBC_ERR_ID_DEBUG;
!             break;
! 		case LOG_ERR:
!             errortype = EVENTLOG_ERROR_TYPE;
! 			break;
! 		case LOG_WARN:
! 		default:
! 			errortype = EVENTLOG_WARNING_TYPE;
! 			
! 		}
!         _vsnprintf(log, BUFFSIZE, format, args);
! 		pszaStrings[0] = log;
!         hEvent = RegisterEventSource(NULL,source);
! 		if (hEvent) 
! 		{
! 			ReportEvent(hEvent, errortype, 0, eventid, NULL, (WORD)1, 0,                  
!                 (const char **)pszaStrings, NULL);                   
! 			DeregisterEventSource(hEvent);
! 		}
! 	}
! 
! 
! }
! 
! void pbc_vlog_activity(pool *p, int logging_level, const char * format, va_list args )
! {
! 	filter_log_activity (p, "Pubcookie", logging_level, format, args);
! }
! 
! extern void syslog(int whichlog, const char *message, ...) {
! 
! 	pool *p;
! 	va_list   args;
! 
! 	p = malloc(sizeof(pool)); 
! 	bzero(p,sizeof(pool));
! 
!     va_start(args, message);
! 
!     pbc_vlog_activity(p, whichlog, message, args );
! 
!     va_end(args);
! 
! 	free(p);
! 
! }
! extern void pbc_log_activity(pool *p, int logging_level, const char *message,...)
! {
!     va_list   args;
! 
!     va_start(args, message);
! 
!     pbc_vlog_activity(p, logging_level, message, args );
! 
!     va_end(args);
! }
! 
! char * AddToLog(char*LogBuff, const char *format, ...) {
! 	char *LogPos;
! 
! 	va_list   args;
! 
!     va_start(args, format);
! 
! 	LogPos = LogBuff + strlen(LogBuff);
! 
!     _vsnprintf(LogPos, LOGBUFFSIZE - (LogPos - LogBuff), format, args);
! 
!     va_end(args);
! 
!     return (LogBuff);
! }
! 
! 


Index: webiso/pubcookie/src/Win32/debug.h
diff -c webiso/pubcookie/src/Win32/debug.h:1.8 webiso/pubcookie/src/Win32/debug.h:1.9
*** webiso/pubcookie/src/Win32/debug.h:1.8	Fri Sep 26 15:27:02 2003
--- webiso/pubcookie/src/Win32/debug.h	Thu Jan 22 21:00:26 2004
***************
*** 1,47 ****
! //
! //  Copyright (c) 1999-2003 University of Washington.  All rights reserved.
! //  For terms of use see doc/LICENSE.txt in this distribution.
! //
! 
! //
! //  $Id: debug.h,v 1.8 2003/09/26 22:27:02 ryanc Exp $
! //
! 
! #include <windows.h>
! 
! void syslog(int whichlog, const char *message, ...);
! char * AddToLog(char*LogBuff, const char *format, ...);
! void filter_log_activity ( const char * source, int logging_level, const char * format, va_list args );
! 
! extern char Instance[64];
! extern char *SystemRoot;
! 
! //Message Event IDs
! 
! // MessageId: ERR_ONE
! //
! // MessageText:
! //
! //  Generic Error
! //
! #define PBC_ERR_ID_GENERIC                      0x00000001L
! 
! //
! // MessageId: ERR_TWO
! //
! // MessageText:
! //
! //  Debug: %1
! //
! #define PBC_ERR_ID_DEBUG                        0x00000002L
! 
! //
! // MessageId: ERR_THREE
! //
! // MessageText:
! //
! //  %1
! //
! #define PBC_ERR_ID_SIMPLE                       0x00000003L
! 
! #define LOGBUFFSIZE 4096
--- 1,47 ----
! //
! //  Copyright (c) 1999-2003 University of Washington.  All rights reserved.
! //  For terms of use see doc/LICENSE.txt in this distribution.
! //
! 
! //
! //  $Id: debug.h,v 1.9 2004/01/23 05:00:26 ryanc Exp $
! //
! 
! #include <windows.h>
! 
! void syslog(int whichlog, const char *message, ...);
! char * AddToLog(char*LogBuff, const char *format, ...);
! void filter_log_activity ( pool *p, const char * source, int logging_level, const char * format, va_list args );
! 
! extern char Instance[64];
! extern char *SystemRoot;
! 
! //Message Event IDs
! 
! // MessageId: ERR_ONE
! //
! // MessageText:
! //
! //  Generic Error
! //
! #define PBC_ERR_ID_GENERIC                      0x00000001L
! 
! //
! // MessageId: ERR_TWO
! //
! // MessageText:
! //
! //  Debug: %1
! //
! #define PBC_ERR_ID_DEBUG                        0x00000002L
! 
! //
! // MessageId: ERR_THREE
! //
! // MessageText:
! //
! //  %1
! //
! #define PBC_ERR_ID_SIMPLE                       0x00000003L
! 
! #define LOGBUFFSIZE 4096


Index: webiso/pubcookie/src/Win32/keyclient.vcproj
diff -c webiso/pubcookie/src/Win32/keyclient.vcproj:1.4 webiso/pubcookie/src/Win32/keyclient.vcproj:1.5
*** webiso/pubcookie/src/Win32/keyclient.vcproj:1.4	Wed Dec 17 14:10:56 2003
--- webiso/pubcookie/src/Win32/keyclient.vcproj	Thu Jan 22 21:00:26 2004
***************
*** 1,178 ****
! <?xml version="1.0" encoding = "Windows-1252"?>
! <VisualStudioProject
! 	ProjectType="Visual C++"
! 	Version="7.00"
! 	Name="keyclient"
! 	ProjectGUID="{EB0E3F9C-882E-4DFF-9F48-F647DE26A259}"
! 	SccProjectName=""
! 	SccLocalPath="">
! 	<Platforms>
! 		<Platform
! 			Name="Win32"/>
! 	</Platforms>
! 	<Configurations>
! 		<Configuration
! 			Name="Release|Win32"
! 			OutputDirectory=".\Release"
! 			IntermediateDirectory=".\Release"
! 			ConfigurationType="1"
! 			UseOfMFC="0"
! 			ATLMinimizesCRunTimeLibraryUsage="FALSE"
! 			CharacterSet="2">
! 			<Tool
! 				Name="VCCLCompilerTool"
! 				InlineFunctionExpansion="1"
! 				AdditionalIncludeDirectories="include/openssl,include"
! 				PreprocessorDefinitions="NDEBUG,WIN32,_WINDOWS,HAVE_STRING_H,HAVE_STDIO_H,HAVE_STDARG_H,HAVE_SNPRINTF"
! 				StringPooling="TRUE"
! 				RuntimeLibrary="0"
! 				EnableFunctionLevelLinking="TRUE"
! 				UsePrecompiledHeader="2"
! 				PrecompiledHeaderFile=".\Release/keyclient.pch"
! 				AssemblerListingLocation=".\Release/"
! 				ObjectFile=".\Release/"
! 				ProgramDataBaseFileName=".\Release/"
! 				BrowseInformation="1"
! 				WarningLevel="3"
! 				SuppressStartupBanner="TRUE"
! 				CompileAs="0"/>
! 			<Tool
! 				Name="VCCustomBuildTool"/>
! 			<Tool
! 				Name="VCLinkerTool"
! 				AdditionalOptions="/MACHINE:I386"
! 				AdditionalDependencies="crypt32.lib wsock32.lib odbc32.lib odbccp32.lib"
! 				OutputFile=".\Release/keyclient.exe"
! 				LinkIncremental="1"
! 				SuppressStartupBanner="TRUE"
! 				AdditionalLibraryDirectories="lib"
! 				ProgramDatabaseFile=".\Release/keyclient.pdb"
! 				SubSystem="2"/>
! 			<Tool
! 				Name="VCMIDLTool"
! 				TypeLibraryName=".\Release/keyclient.tlb"/>
! 			<Tool
! 				Name="VCPostBuildEventTool"/>
! 			<Tool
! 				Name="VCPreBuildEventTool"/>
! 			<Tool
! 				Name="VCPreLinkEventTool"/>
! 			<Tool
! 				Name="VCResourceCompilerTool"
! 				PreprocessorDefinitions="NDEBUG"
! 				Culture="1033"/>
! 			<Tool
! 				Name="VCWebServiceProxyGeneratorTool"/>
! 			<Tool
! 				Name="VCWebDeploymentTool"/>
! 		</Configuration>
! 		<Configuration
! 			Name="Debug|Win32"
! 			OutputDirectory=".\Debug"
! 			IntermediateDirectory=".\Debug"
! 			ConfigurationType="1"
! 			UseOfMFC="0"
! 			ATLMinimizesCRunTimeLibraryUsage="FALSE"
! 			CharacterSet="2">
! 			<Tool
! 				Name="VCCLCompilerTool"
! 				Optimization="0"
! 				AdditionalIncludeDirectories="include/openssl,include"
! 				PreprocessorDefinitions="_DEBUG,WIN32,_WINDOWS,HAVE_STRING_H,HAVE_STDIO_H,HAVE_STDARG_H,HAVE_SNPRINTF"
! 				BasicRuntimeChecks="3"
! 				RuntimeLibrary="1"
! 				UsePrecompiledHeader="2"
! 				PrecompiledHeaderFile=".\Debug/keyclient.pch"
! 				AssemblerListingLocation=".\Debug/"
! 				ObjectFile=".\Debug/"
! 				ProgramDataBaseFileName=".\Debug/"
! 				BrowseInformation="1"
! 				WarningLevel="3"
! 				SuppressStartupBanner="TRUE"
! 				DebugInformationFormat="4"
! 				CompileAs="0"/>
! 			<Tool
! 				Name="VCCustomBuildTool"/>
! 			<Tool
! 				Name="VCLinkerTool"
! 				AdditionalOptions="/MACHINE:I386"
! 				AdditionalDependencies="crypt32.lib wsock32.lib odbc32.lib odbccp32.lib"
! 				OutputFile=".\Debug/keyclient.exe"
! 				LinkIncremental="2"
! 				SuppressStartupBanner="TRUE"
! 				AdditionalLibraryDirectories="lib"
! 				GenerateDebugInformation="TRUE"
! 				ProgramDatabaseFile=".\Debug/keyclient.pdb"
! 				SubSystem="2"/>
! 			<Tool
! 				Name="VCMIDLTool"
! 				TypeLibraryName=".\Debug/keyclient.tlb"/>
! 			<Tool
! 				Name="VCPostBuildEventTool"/>
! 			<Tool
! 				Name="VCPreBuildEventTool"/>
! 			<Tool
! 				Name="VCPreLinkEventTool"/>
! 			<Tool
! 				Name="VCResourceCompilerTool"
! 				PreprocessorDefinitions="_DEBUG"
! 				Culture="1033"/>
! 			<Tool
! 				Name="VCWebServiceProxyGeneratorTool"/>
! 			<Tool
! 				Name="VCWebDeploymentTool"/>
! 		</Configuration>
! 	</Configurations>
! 	<Files>
! 		<Filter
! 			Name="Source Files"
! 			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
! 			<File
! 				RelativePath="WebClient.c">
! 			</File>
! 			<File
! 				RelativePath="..\base64.c">
! 			</File>
! 			<File
! 				RelativePath=".\debug.c">
! 			</File>
! 			<File
! 				RelativePath="getopt.c">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_configure.c">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_myconfig.c">
! 			</File>
! 			<File
! 				RelativePath="..\strlcpy.c">
! 			</File>
! 			<File
! 				RelativePath="winkeyclient.c">
! 			</File>
! 		</Filter>
! 		<Filter
! 			Name="Header Files"
! 			Filter="h;hpp;hxx;hm;inl">
! 			<File
! 				RelativePath="WebClient.h">
! 			</File>
! 			<File
! 				RelativePath="getopt.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_config.h">
! 			</File>
! 			<File
! 				RelativePath=".\winkeyclient.h">
! 			</File>
! 		</Filter>
! 		<Filter
! 			Name="Resource Files"
! 			Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
! 		</Filter>
! 	</Files>
! 	<Globals>
! 	</Globals>
! </VisualStudioProject>
--- 1,187 ----
! <?xml version="1.0" encoding = "Windows-1252"?>
! <VisualStudioProject
! 	ProjectType="Visual C++"
! 	Version="7.00"
! 	Name="keyclient"
! 	ProjectGUID="{EB0E3F9C-882E-4DFF-9F48-F647DE26A259}"
! 	SccProjectName=""
! 	SccLocalPath="">
! 	<Platforms>
! 		<Platform
! 			Name="Win32"/>
! 	</Platforms>
! 	<Configurations>
! 		<Configuration
! 			Name="Release|Win32"
! 			OutputDirectory=".\Release"
! 			IntermediateDirectory=".\Release"
! 			ConfigurationType="1"
! 			UseOfMFC="0"
! 			ATLMinimizesCRunTimeLibraryUsage="FALSE"
! 			CharacterSet="2">
! 			<Tool
! 				Name="VCCLCompilerTool"
! 				InlineFunctionExpansion="1"
! 				AdditionalIncludeDirectories="include/openssl,include"
! 				PreprocessorDefinitions="NDEBUG,WIN32,_WINDOWS,HAVE_STRING_H,HAVE_STDIO_H,HAVE_STDARG_H,HAVE_SNPRINTF"
! 				StringPooling="TRUE"
! 				RuntimeLibrary="0"
! 				EnableFunctionLevelLinking="TRUE"
! 				UsePrecompiledHeader="2"
! 				PrecompiledHeaderFile=".\Release/keyclient.pch"
! 				AssemblerListingLocation=".\Release/"
! 				ObjectFile=".\Release/"
! 				ProgramDataBaseFileName=".\Release/"
! 				BrowseInformation="1"
! 				WarningLevel="3"
! 				SuppressStartupBanner="TRUE"
! 				CompileAs="0"/>
! 			<Tool
! 				Name="VCCustomBuildTool"/>
! 			<Tool
! 				Name="VCLinkerTool"
! 				AdditionalOptions="/MACHINE:I386"
! 				AdditionalDependencies="crypt32.lib wsock32.lib odbc32.lib odbccp32.lib"
! 				OutputFile=".\Release/keyclient.exe"
! 				LinkIncremental="1"
! 				SuppressStartupBanner="TRUE"
! 				AdditionalLibraryDirectories="lib"
! 				ProgramDatabaseFile=".\Release/keyclient.pdb"
! 				SubSystem="2"/>
! 			<Tool
! 				Name="VCMIDLTool"
! 				TypeLibraryName=".\Release/keyclient.tlb"/>
! 			<Tool
! 				Name="VCPostBuildEventTool"/>
! 			<Tool
! 				Name="VCPreBuildEventTool"/>
! 			<Tool
! 				Name="VCPreLinkEventTool"/>
! 			<Tool
! 				Name="VCResourceCompilerTool"
! 				PreprocessorDefinitions="NDEBUG"
! 				Culture="1033"/>
! 			<Tool
! 				Name="VCWebServiceProxyGeneratorTool"/>
! 			<Tool
! 				Name="VCWebDeploymentTool"/>
! 		</Configuration>
! 		<Configuration
! 			Name="Debug|Win32"
! 			OutputDirectory=".\Debug"
! 			IntermediateDirectory=".\Debug"
! 			ConfigurationType="1"
! 			UseOfMFC="0"
! 			ATLMinimizesCRunTimeLibraryUsage="FALSE"
! 			CharacterSet="2">
! 			<Tool
! 				Name="VCCLCompilerTool"
! 				Optimization="0"
! 				AdditionalIncludeDirectories="include/openssl,include"
! 				PreprocessorDefinitions="_DEBUG,WIN32,_WINDOWS,HAVE_STRING_H,HAVE_STDIO_H,HAVE_STDARG_H,HAVE_SNPRINTF"
! 				BasicRuntimeChecks="3"
! 				RuntimeLibrary="1"
! 				UsePrecompiledHeader="2"
! 				PrecompiledHeaderFile=".\Debug/keyclient.pch"
! 				AssemblerListingLocation=".\Debug/"
! 				ObjectFile=".\Debug/"
! 				ProgramDataBaseFileName=".\Debug/"
! 				BrowseInformation="1"
! 				WarningLevel="3"
! 				SuppressStartupBanner="TRUE"
! 				DebugInformationFormat="4"
! 				CompileAs="0"/>
! 			<Tool
! 				Name="VCCustomBuildTool"/>
! 			<Tool
! 				Name="VCLinkerTool"
! 				AdditionalOptions="/MACHINE:I386"
! 				AdditionalDependencies="crypt32.lib wsock32.lib odbc32.lib odbccp32.lib"
! 				OutputFile=".\Debug/keyclient.exe"
! 				LinkIncremental="2"
! 				SuppressStartupBanner="TRUE"
! 				AdditionalLibraryDirectories="lib"
! 				GenerateDebugInformation="TRUE"
! 				ProgramDatabaseFile=".\Debug/keyclient.pdb"
! 				SubSystem="2"/>
! 			<Tool
! 				Name="VCMIDLTool"
! 				TypeLibraryName=".\Debug/keyclient.tlb"/>
! 			<Tool
! 				Name="VCPostBuildEventTool"/>
! 			<Tool
! 				Name="VCPreBuildEventTool"/>
! 			<Tool
! 				Name="VCPreLinkEventTool"/>
! 			<Tool
! 				Name="VCResourceCompilerTool"
! 				PreprocessorDefinitions="_DEBUG"
! 				Culture="1033"/>
! 			<Tool
! 				Name="VCWebServiceProxyGeneratorTool"/>
! 			<Tool
! 				Name="VCWebDeploymentTool"/>
! 		</Configuration>
! 	</Configurations>
! 	<Files>
! 		<Filter
! 			Name="Source Files"
! 			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
! 			<File
! 				RelativePath="WebClient.c">
! 			</File>
! 			<File
! 				RelativePath="..\base64.c">
! 			</File>
! 			<File
! 				RelativePath=".\debug.c">
! 			</File>
! 			<File
! 				RelativePath="getopt.c">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_configure.c">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_myconfig.c">
! 			</File>
! 			<File
! 				RelativePath="..\strlcpy.c">
! 			</File>
! 			<File
! 				RelativePath="winkeyclient.c">
! 			</File>
! 		</Filter>
! 		<Filter
! 			Name="Header Files"
! 			Filter="h;hpp;hxx;hm;inl">
! 			<File
! 				RelativePath="PubCookieFilter.h">
! 			</File>
! 			<File
! 				RelativePath="WebClient.h">
! 			</File>
! 			<File
! 				RelativePath="debug.h">
! 			</File>
! 			<File
! 				RelativePath="getopt.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_config.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_configure.h">
! 			</File>
! 			<File
! 				RelativePath="..\pbc_myconfig.h">
! 			</File>
! 		</Filter>
! 		<Filter
! 			Name="Resource Files"
! 			Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
! 		</Filter>
! 	</Files>
! 	<Globals>
! 	</Globals>
! </VisualStudioProject>


Index: webiso/pubcookie/src/Win32/winkeyclient.c
diff -c webiso/pubcookie/src/Win32/winkeyclient.c:1.6 webiso/pubcookie/src/Win32/winkeyclient.c:1.7
*** webiso/pubcookie/src/Win32/winkeyclient.c:1.6	Wed Dec 17 14:10:56 2003
--- webiso/pubcookie/src/Win32/winkeyclient.c	Thu Jan 22 21:00:26 2004
***************
*** 1,199 ****
! /*
!   Copyright (c) 1999-2003 University of Washington.  All rights reserved.
!   For terms of use see doc/LICENSE.txt in this distribution.
!  */
! 
! /*
!   $Id: winkeyclient.c,v 1.6 2003/12/17 22:10:56 ryanc Exp $
!  */
! #include <stdio.h>
! #include <stdlib.h>
! #include <windows.h> 
! #include <winsock.h>
! #include <wincrypt.h>
! #include <wintrust.h>
! #include <schannel.h>
! 
! #define SECURITY_WIN32
! #include <security.h>
! #include <sspi.h>
! 
! #ifdef HAVE_CONFIG_H
! # include "config.h"
! # include "pbc_path.h"
! #endif
! 
! typedef void pool;
! 
! 
! #ifdef HAVE_SYS_TYPES_H
! # include <sys/types.h>
! #endif /* HAVE_SYS_TYPES_H */
! 
! #ifdef HAVE_SYS_SOCKET_H
! # include <sys/socket.h>
! #endif /* HAVE_SYS_SOCKET_H */
! 
! #ifdef HAVE_NETINET_IN_H
! # include <netinet/in.h>
! #endif /* HAVE_NETINET_IN_H */
! 
! #ifdef HAVE_ARPA_INET_H
! # include <arpa/inet.h>
! #endif /* HAVE_ARPA_INET_H */
! 
! #ifdef HAVE_NETDB_H
! # include <netdb.h>
! #endif /* HAVE_NETDB_H */
! 
! #ifdef HAVE_STRING_H
! # include <string.h>
! #endif /* HAVE_STRING_H */
! 
! #ifdef HAVE_UNISTD_H
! # include <unistd.h>
! #endif /* HAVE_UNISTD_H */
! 
! #include "getopt.h"
! #include "../pbc_config.h"
! #include "../pbc_configure.h"
! #include "../libpubcookie.h"
! #include "../strlcpy.h"
! #include "../snprintf.h"
! 
! #ifdef HAVE_DMALLOC_H
! # if (!defined(APACHE) && !defined(APACHE1_3))
! #  include <dmalloc.h>
! 
! #  ifdef __STDC__
! extern char * optarg;
! #  endif /* __STDC__ */
! # endif /* ! APACHE */
! #endif /* HAVE_DMALLOC_H */
! 
! #  include "debug.h"
! #  include "WebClient.h"
! #  include <process.h>
! #  include <io.h>
! #  define pid_t int
! #  define snprintf _snprintf
! 
! /* globals */
! int noop = 0;
! extern pool *p; //initialized in debug
! int newkeyp = 1;
! char *hostname = NULL;
! 
! 
! int Messagef(const char * format, ...){
!     char msg[2048];
! 
! 	va_list   args;
! 
!     va_start(args, format);
! 
!     _vsnprintf(msg, sizeof(msg)-1, format, args);
! 
! 	MessageBox(NULL,msg,"Keyclient",MB_OK);
! 
!     va_end(args);
! 
!     return 1;
! }
! 
! /* destructively returns the value of the CN */
! static char *extract_cn(char *s)
! {
!     char *pp = strstr(s, "CN=");
!     char *q;
! 
!     if (pp) {
!         pp += 3;
!         q = strstr(pp, "/Email=");
!         if (q) {
!             *q = '\0';
!         }
!         /* fix for subjects that go leaf -> root */
!         q = strchr(pp, '/');
!         if (q) {
!             *q = '\0';
!         }
!     }
! 
!     return pp;
! }
! 
! /**
!  * generates the filename that stores the DES key
!  * @param peername the certificate name of the peer
!  * @param buf a buffer of at least 1024 characters which gets the filename
!  * @return always succeeds
!  */
! static void make_crypt_keyfile(const char *peername, char *buf)
! {
! 	char SystemRootBuff[MAX_PATH+1];
! 
!     strlcpy(buf, PBC_KEY_DIR, 1024);
! 
!     if (buf[strlen(buf)-1] != '/') {
!         strlcat(buf, "/", 1024);
!     }
!     strlcat(buf, peername, 1024);
! }
! 
! /**
!  * writes the key 'key' to disk for peer 'peer'
!  * @param a pointer to the PB_C_DES_KEY_BUF-sized key
!  * @param peer the certificate name of the peer
!  * @return PBC_OK for success, PBC_FAIL for failure
!  */
! int set_crypt_key(const char *key, const char *peer)
! {
!     char keyfile[1024];
!     FILE *f;
! 
!     make_crypt_keyfile(peer, keyfile);
!     if (!(f = fopen(keyfile, "wb"))) {
! 	return PBC_FAIL;
!     }
!     fwrite(key, sizeof(char), PBC_DES_KEY_BUF, f);
!     fclose(f);
! 
!     return PBC_OK;
! }
! 
! /*                                                                           */
! int get_crypt_key(crypt_stuff *c_stuff, const char *peer)
! {
!     FILE             *fp;
!     char             *key_in;
!     char keyfile[1024];
! 
! 
!     make_crypt_keyfile(peer, keyfile);
! 
!     key_in = (char *)malloc(PBC_DES_KEY_BUF);
! 
!     if( ! (fp = fopen(keyfile, "rb")) ) { /* win32 - must be binary read */
!         Messagef("get_crypt_key: Failed open: %s\n", keyfile);
!         return PBC_FAIL;
!     }
!     
!     if( fread(key_in, sizeof(char), PBC_DES_KEY_BUF, fp) != PBC_DES_KEY_BUF) {
!         Messagef("get_crypt_key: Failed read: %s\n", keyfile);
! 	fclose(fp);
! 	return PBC_FAIL;
!     }
!     fclose(fp);
! 
!     memcpy(c_stuff->key_a, key_in, sizeof(c_stuff->key_a));
!     free(key_in);
! 
!     return PBC_OK;
! }
! void ParseCmdLine(LPSTR lpCmdLine) {
! 	int c;
! 
      while ((c = getopt(__argc, __argv, "udH:")) != -1) {
          switch (c) {
              case 'd':
--- 1,203 ----
! /*
!   Copyright (c) 1999-2003 University of Washington.  All rights reserved.
!   For terms of use see doc/LICENSE.txt in this distribution.
!  */
! 
! /*
!   $Id: winkeyclient.c,v 1.7 2004/01/23 05:00:26 ryanc Exp $
!  */
! #include <stdio.h>
! #include <stdlib.h>
! #include <windows.h> 
! #include <winsock.h>
! #include <wincrypt.h>
! #include <wintrust.h>
! #include <schannel.h>
! 
! #define SECURITY_WIN32
! #include <security.h>
! #include <sspi.h>
! 
! #ifdef HAVE_CONFIG_H
! # include "config.h"
! # include "pbc_path.h"
! #endif
! 
! #ifdef HAVE_SYS_TYPES_H
! # include <sys/types.h>
! #endif /* HAVE_SYS_TYPES_H */
! 
! #ifdef HAVE_SYS_SOCKET_H
! # include <sys/socket.h>
! #endif /* HAVE_SYS_SOCKET_H */
! 
! #ifdef HAVE_NETINET_IN_H
! # include <netinet/in.h>
! #endif /* HAVE_NETINET_IN_H */
! 
! #ifdef HAVE_ARPA_INET_H
! # include <arpa/inet.h>
! #endif /* HAVE_ARPA_INET_H */
! 
! #ifdef HAVE_NETDB_H
! # include <netdb.h>
! #endif /* HAVE_NETDB_H */
! 
! #ifdef HAVE_STRING_H
! # include <string.h>
! #endif /* HAVE_STRING_H */
! 
! #ifdef HAVE_UNISTD_H
! # include <unistd.h>
! #endif /* HAVE_UNISTD_H */
! 
! #include <httpfilt.h>
! //todo #include <strsafe.h>
! 
! #include "../pubcookie.h"
! #include "../pbc_config.h"
! #include "PubCookieFilter.h"
! typedef pubcookie_dir_rec pool;
! 
! #include "getopt.h"
! #include "../libpubcookie.h"
! #include "../strlcpy.h"
! #include "../snprintf.h"
! #include "../pbc_myconfig.h"
! #include "../pbc_configure.h"
! 
! #ifdef HAVE_DMALLOC_H
! # if (!defined(APACHE) && !defined(APACHE1_3))
! #  include <dmalloc.h>
! 
! #  ifdef __STDC__
! extern char * optarg;
! #  endif /* __STDC__ */
! # endif /* ! APACHE */
! #endif /* HAVE_DMALLOC_H */
! 
! #  include "debug.h"
! #  include "WebClient.h"
! #  include <process.h>
! #  include <io.h>
! #  define pid_t int
! #  define snprintf _snprintf
! 
! #define MAX_REG_BUFF 2048
! 
! /* globals */
! int noop = 0;
! int newkeyp = 1;
! pool *p = NULL;
! char *hostname = NULL;
! 
! int Messagef(const char * format, ...){
!     char msg[2048];
! 
! 	va_list   args;
! 
!     va_start(args, format);
! 
!     _vsnprintf(msg, sizeof(msg)-1, format, args);
! 
! 	MessageBox(NULL,msg,"Keyclient",MB_OK);
! 
!     va_end(args);
! 
!     return 1;
! }
! 
! /* destructively returns the value of the CN */
! static char *extract_cn(char *s)
! {
!     char *pp = strstr(s, "CN=");
!     char *q;
! 
!     if (pp) {
!         pp += 3;
!         q = strstr(pp, "/Email=");
!         if (q) {
!             *q = '\0';
!         }
!         /* fix for subjects that go leaf -> root */
!         q = strchr(pp, '/');
!         if (q) {
!             *q = '\0';
!         }
!     }
! 
!     return pp;
! }
! 
! /**
!  * generates the filename that stores the DES key
!  * @param peername the certificate name of the peer
!  * @param buf a buffer of at least 1024 characters which gets the filename
!  * @return always succeeds
!  */
! static void make_crypt_keyfile(const char *peername, char *buf)
! {
!     strlcpy(buf, PBC_KEY_DIR, 1024);
! 
! 	if (buf[strlen(buf)-1] != '/') {
!         strlcat(buf, "/", 1024);
!     }
!     strlcat(buf, peername, 1024);
! }
! 
! /**
!  * writes the key 'key' to disk for peer 'peer'
!  * @param a pointer to the PB_C_DES_KEY_BUF-sized key
!  * @param peer the certificate name of the peer
!  * @return PBC_OK for success, PBC_FAIL for failure
!  */
! int set_crypt_key(const char *key, const char *peer)
! {
!     char keyfile[1024];
!     FILE *f;
! 
!     make_crypt_keyfile(peer, keyfile);
!     if (!(f = fopen(keyfile, "wb"))) {
! 	return PBC_FAIL;
!     }
!     fwrite(key, sizeof(char), PBC_DES_KEY_BUF, f);
!     fclose(f);
! 
!     return PBC_OK;
! }
! 
! /*                                                                           */
! int get_crypt_key(crypt_stuff *c_stuff, const char *peer)
! {
!     FILE             *fp;
!     char             *key_in;
!     char keyfile[1024];
! 
! 
!     make_crypt_keyfile(peer, keyfile);
! 
!     key_in = (char *)malloc(PBC_DES_KEY_BUF);
! 
!     if( ! (fp = fopen(keyfile, "rb")) ) { /* win32 - must be binary read */
!         Messagef("get_crypt_key: Failed open: %s\n", keyfile);
!         return PBC_FAIL;
!     }
!     
!     if( fread(key_in, sizeof(char), PBC_DES_KEY_BUF, fp) != PBC_DES_KEY_BUF) {
!         Messagef("get_crypt_key: Failed read: %s\n", keyfile);
! 	fclose(fp);
! 	return PBC_FAIL;
!     }
!     fclose(fp);
! 
!     memcpy(c_stuff->key_a, key_in, sizeof(c_stuff->key_a));
!     free(key_in);
! 
!     return PBC_OK;
! }
! void ParseCmdLine(LPSTR lpCmdLine) {
! 	int c;
! 
      while ((c = getopt(__argc, __argv, "udH:")) != -1) {
          switch (c) {
              case 'd':
***************
*** 216,483 ****
              default:
                  break;
          }
!     }
! }
! 
! int APIENTRY WinMain(HINSTANCE hInstance,
!                      HINSTANCE hPrevInstance,
!                      LPSTR     lpCmdLine,
!                      int       nCmdShow)
! {
!     char *cp;
!     char buf[2 * PBC_DES_KEY_BUF]; /* plenty of room for base64 encoding */
!     unsigned char thekey[PBC_DES_KEY_BUF];
!     crypt_stuff c_stuff;
! 	struct hostent *h;
!     int ret;
!     int done = 0;
!     const char *keymgturi = NULL;
!     char *keyhost = NULL;
! 	char *keymgtpath = NULL;
!     int keyport = 443;
!     pool *p = NULL;
! 	WSADATA wsaData;
!     SOCKET  Socket;
!     CtxtHandle hContext;
!     SecBuffer  ExtraData;
!     SECURITY_STATUS Status;
!     SecurityFunctionTable *lpSecurityFunc = NULL;
!     PCCERT_CONTEXT pRemoteCertContext = NULL;
! 	CredHandle hClientCreds;
! 	char *Reply = NULL;
! 	char sztmp[1024];
! 	char SystemRootBuff[MAX_PATH+1];
! 	char strbuff[MAX_REG_BUFF];
! 
! 	if( WSAStartup((WORD)0x0101, &wsaData ) ) 
! 	{  
! 		Messagef("Unable to initialize WINSOCK: %d\n", WSAGetLastError() );
! 		return ERROR_INSTALL_FAILURE;
! 	}
!     if(!LoadSecurityLibrary(&lpSecurityFunc))
!     {
!         Messagef("Error initializing the security library\n");
!         return ERROR_INSTALL_FAILURE;
!     }
! 
!     libpbc_config_init(p, NULL, "keyclient");
! 
! 	ParseCmdLine(lpCmdLine);
! 
! 	if (!hostname) { 
! 		gethostname(sztmp, sizeof(sztmp)-1);
! 		h = gethostbyname(sztmp);
! 		hostname = strdup(h->h_name);
! 	}
! 
!     //
!     // Create credentials.
!     //
! 
! 	if(Status = CreateCredentials(hostname, &hClientCreds))
! 	{
! 		if (Status == SEC_E_NO_CREDENTIALS) {
! 			Messagef("Error creating credentials.  Could not find server certificate for %s",hostname);
! 			return ERROR_INSTALL_FAILURE;
! 		}
! 		else {
! 			Messagef("Error creating credentials. Error code: 0x%x\n", Status);
! 			return ERROR_INSTALL_FAILURE;
! 		}
! 	}
! 
! 
!     /* figure out the key management server */
! 	keymgturi = strdup(PBC_KEYMGT_URI);
!     keyhost = strdup(keymgturi);
! 
!     if (!strncmp(keyhost, "https://", 8)) keyhost += 8;
!     cp = strchr(keyhost, '/');
!     if (cp) {
! 		keymgtpath = strdup(cp);
!         *cp = '\0';
!     }
! 
!     cp = strchr(keyhost, ':');
!     if (cp) {
!         *cp++ = '\0';
!         keyport = atoi(cp);
!     }
! 
!     /* connect to the keyserver */
! 
!     if(ret = ConnectToServer(keyhost, keyport, &Socket))
!     {
! 		Messagef("Cannot connect to %s:%u\n",keyhost,keyport);
!         return ERROR_INSTALL_FAILURE;
!     }
! 
! 
!     //
!     // Perform handshake
!     //
! 
!     if(PerformClientHandshake(Socket,
!                               &hClientCreds,
!                               keyhost,
!                               &hContext,
!                               &ExtraData))
!     {
!         Messagef("Error performing handshake\n");
!         return ERROR_INSTALL_FAILURE;
!     }
! 
! 
!     //
!     // Authenticate server's credentials.
!     //
! 
!     // Get server's certificate.
!     Status = lpSecurityFunc->QueryContextAttributes(&hContext,
!                                     SECPKG_ATTR_REMOTE_CERT_CONTEXT,
!                                     (PVOID)&pRemoteCertContext);
!     if(Status != SEC_E_OK)
!     {
!         Messagef("Error 0x%x querying remote certificate\n", Status);
!         return ERROR_INSTALL_FAILURE;
!     }
! 
!     // Display server certificate chain.
!     // DisplayCertChain(pRemoteCertContext, FALSE);
! 
!     // Attempt to validate server certificate.
!     Status = VerifyServerCertificate(pRemoteCertContext,
!                                      keyhost,
!                                      0);
!     if(Status)
!     {
!         Messagef("Error authenticating server credentials.  Check to make sure that your server has a certificate that is trusted by your machine.\n");
! 
!         exit(ERROR_INSTALL_FAILURE);
!     }
! 
! 
! 
!     /* make the HTTP query */
!     if (newkeyp == -1) {
!         char enckey[PBC_DES_KEY_BUF * 2];
! 
!         if (get_crypt_key(&c_stuff, hostname) != PBC_OK) {
!             Messagef("couldn't retrieve key\r\n");
!             exit(ERROR_INSTALL_FAILURE);
!         }
! 
!         libpbc_base64_encode(cp, c_stuff.key_a, (unsigned char *) enckey, PBC_DES_KEY_BUF);
! 
!         /* we're uploading! */
!         snprintf(buf, sizeof(buf),
!                  "%s?genkey=put?setkey=%s;%s",
!                  keymgtpath, hostname, enckey);
!     } else {
!         snprintf(buf, sizeof(buf), 
!                  "%s?genkey=%s", keymgtpath,
!                  newkeyp ? "yes" : "no");
!     }
! 
! 
!     if (noop && newkeyp) {
!         Messagef("-n specified; not performing any writes:\n");
!         Messagef("%s", buf);
!         exit(ERROR_INSTALL_FAILURE);
!     }
!     if(HttpsGetFile(Socket, 
!                     &hClientCreds,
!                     &hContext, 
!                     buf,
! 					&Reply))
!     {
!         Messagef("Error fetching file from server.\n");
!         return ERROR_INSTALL_FAILURE;
!     }
! 
! 	cp = Reply;
!     /* look for the 'OK' */
!     while (*cp) {
!         if (cp[0] == '\r' && cp[1] == '\n' &&
!             cp[2] == 'O' && cp[3] == 'K' &&
!             cp[4] == ' ') {
!             cp += 5;
!             /* cp points to a base64 key we should decode */
!             if (strlen(cp) >= (4 * PBC_DES_KEY_BUF + 100) / 3) {
!                 Messagef("key too long\n");
!                 exit(ERROR_INSTALL_FAILURE);
!             }
! 
!             if (newkeyp != -1) {
!                 if (strchr(cp, '\r')) {
!                     /* chomp new line */
!                     *(strchr(cp, '\r')) = '\0';
!                 }
!                 if (strchr(cp, '\n')) {
!                     /* chomp new line */
!                     *(strchr(cp, '\n')) = '\0';
!                 }
! 
!                 if (noop) {
!                     Messagef("would have set key to '%s'\n", cp);
!                 } else {
! 		    int osize = 0;
!                     int ret;
!                     if (strchr(cp, '\r')) {
!                         /* chomp new line */
!                         *strchr(cp, '\r') = '\0';
!                     }
!                     ret = libpbc_base64_decode(cp, (unsigned char *) cp, thekey, &osize);
! 		    if (osize != PBC_DES_KEY_BUF) {
!                         Messagef("keyserver returned wrong key size: expected %d got %d\n", PBC_DES_KEY_BUF, osize);
!                         exit(ERROR_INSTALL_FAILURE);
!                     }
! 
!                     if (! ret) {
!                         Messagef( "Bad base64 decode.\n" );
!                         exit(ERROR_INSTALL_FAILURE);
!                     }
! 
!                     if (set_crypt_key((const char *) thekey, hostname) != PBC_OK) {
!                         Messagef("Cannot store key.  Make sure that key path (%s) exists and can be written to.\n",PBC_KEY_DIR);
!                         exit(ERROR_INSTALL_FAILURE);
!                     }
!                 }
!             }
! 
!             done = 1;
!             break;
!         }
!         cp++;
!     }
! 
!     //
!     // Cleanup.
!     //
! 
!     if(DisconnectFromServer(Socket, &hClientCreds, &hContext))
!     {
!         Messagef("Error disconnecting from server\n");
!     }
! 
! 
!     // Free SSPI credentials handle.
!     lpSecurityFunc->FreeCredentialsHandle(&hClientCreds);
! 
!     // Close socket.
!     closesocket(Socket);
! 
!     // Shutdown WinSock subsystem.
!     WSACleanup();
! 
!     // Close certificate store.
!     CertCloseMyStore();
! 
! 	if (!done) {
! 		Messagef("Operation failed.\nYou will need to sucessfully run keyclient and obtain a key before using the Pubcookie filter.\n\nServer Reply:\n%s", Reply);
! 		exit(ERROR_INSTALL_FAILURE);
!     }
! 
! 
!     return ERROR_SUCCESS;
! }
--- 220,489 ----
              default:
                  break;
          }
!     }
! }
! 
! int APIENTRY WinMain(HINSTANCE hInstance,
!                      HINSTANCE hPrevInstance,
!                      LPSTR     lpCmdLine,
!                      int       nCmdShow)
! {
!     char *cp;
!     char buf[2 * PBC_DES_KEY_BUF]; /* plenty of room for base64 encoding */
!     unsigned char thekey[PBC_DES_KEY_BUF];
!     crypt_stuff c_stuff;
! 	struct hostent *h;
!     int ret;
!     int done = 0;
!     const char *keymgturi = NULL;
!     char *keyhost = NULL;
! 	char *keymgtpath = NULL;
!     int keyport = 443;
! 	WSADATA wsaData;
!     SOCKET  Socket;
!     CtxtHandle hContext;
!     SecBuffer  ExtraData;
!     SECURITY_STATUS Status;
!     SecurityFunctionTable *lpSecurityFunc = NULL;
!     PCCERT_CONTEXT pRemoteCertContext = NULL;
! 	CredHandle hClientCreds;
! 	char *Reply = NULL;
! 	char sztmp[1024];
! 
! 	p = malloc(sizeof(pool));
! 	bzero(p,sizeof(pool));
! 
! 	if( WSAStartup((WORD)0x0101, &wsaData ) ) 
! 	{  
! 		Messagef("Unable to initialize WINSOCK: %d\n", WSAGetLastError() );
! 		return ERROR_INSTALL_FAILURE;
! 	}
!     if(!LoadSecurityLibrary(&lpSecurityFunc))
!     {
!         Messagef("Error initializing the security library\n");
!         return ERROR_INSTALL_FAILURE;
!     }
! 
! 	libpbc_config_init(p,"","keyclient");
! 
! 	ParseCmdLine(lpCmdLine);
! 
! 	if (!hostname) { 
! 		gethostname(sztmp, sizeof(sztmp)-1);
! 		h = gethostbyname(sztmp);
! 		hostname = strdup(h->h_name);
! 	}
! 
!     //
!     // Create credentials.
!     //
! 
! 	if(Status = CreateCredentials(hostname, &hClientCreds))
! 	{
! 		if (Status == SEC_E_NO_CREDENTIALS) {
! 			Messagef("Error creating credentials.  Could not find server certificate for %s",hostname);
! 			return ERROR_INSTALL_FAILURE;
! 		}
! 		else {
! 			Messagef("Error creating credentials. Error code: 0x%x\n", Status);
! 			return ERROR_INSTALL_FAILURE;
! 		}
! 	}
! 
! 
!     /* figure out the key management server */
! 	keymgturi = strdup(PBC_KEYMGT_URI);
!     keyhost = strdup(keymgturi);
! 
!     if (!strncmp(keyhost, "https://", 8)) keyhost += 8;
!     cp = strchr(keyhost, '/');
!     if (cp) {
! 		keymgtpath = strdup(cp);
!         *cp = '\0';
!     }
! 
!     cp = strchr(keyhost, ':');
!     if (cp) {
!         *cp++ = '\0';
!         keyport = atoi(cp);
!     }
! 
!     /* connect to the keyserver */
! 
!     if(ret = ConnectToServer(keyhost, keyport, &Socket))
!     {
! 		Messagef("Cannot connect to %s:%u\n",keyhost,keyport);
!         return ERROR_INSTALL_FAILURE;
!     }
! 
! 
!     //
!     // Perform handshake
!     //
! 
!     if(PerformClientHandshake(Socket,
!                               &hClientCreds,
!                               keyhost,
!                               &hContext,
!                               &ExtraData))
!     {
!         Messagef("Error performing handshake\n");
!         return ERROR_INSTALL_FAILURE;
!     }
! 
! 
!     //
!     // Authenticate server's credentials.
!     //
! 
!     // Get server's certificate.
!     Status = lpSecurityFunc->QueryContextAttributes(&hContext,
!                                     SECPKG_ATTR_REMOTE_CERT_CONTEXT,
!                                     (PVOID)&pRemoteCertContext);
!     if(Status != SEC_E_OK)
!     {
!         Messagef("Error 0x%x querying remote certificate\n", Status);
!         return ERROR_INSTALL_FAILURE;
!     }
! 
!     // Display server certificate chain.
!     // DisplayCertChain(pRemoteCertContext, FALSE);
! 
!     // Attempt to validate server certificate.
!     Status = VerifyServerCertificate(pRemoteCertContext,
!                                      keyhost,
!                                      0);
!     if(Status)
!     {
!         Messagef("Error authenticating server credentials.  Check to make sure that your server has a certificate that is trusted by your machine.\n");
! 
!         exit(ERROR_INSTALL_FAILURE);
!     }
! 
! 
! 
!     /* make the HTTP query */
!     if (newkeyp == -1) {
!         char enckey[PBC_DES_KEY_BUF * 2];
! 
!         if (get_crypt_key(&c_stuff, hostname) != PBC_OK) {
!             Messagef("couldn't retrieve key\r\n");
!             exit(ERROR_INSTALL_FAILURE);
!         }
! 
!         libpbc_base64_encode(p, c_stuff.key_a, (unsigned char *) enckey, PBC_DES_KEY_BUF);
! 
!         /* we're uploading! */
!         snprintf(buf, sizeof(buf),
!                  "%s?genkey=put?setkey=%s;%s",
!                  keymgtpath, hostname, enckey);
!     } else {
!         snprintf(buf, sizeof(buf), 
!                  "%s?genkey=%s", keymgtpath,
!                  newkeyp ? "yes" : "no");
!     }
! 
! 
!     if (noop && newkeyp) {
!         Messagef("-n specified; not performing any writes:\n");
!         Messagef("%s", buf);
!         exit(ERROR_INSTALL_FAILURE);
!     }
!     if(HttpsGetFile(Socket, 
!                     &hClientCreds,
!                     &hContext, 
!                     buf,
! 					&Reply))
!     {
!         Messagef("Error fetching file from server.\n");
!         return ERROR_INSTALL_FAILURE;
!     }
! 
! 	cp = Reply;
!     /* look for the 'OK' */
!     while (*cp) {
!         if (cp[0] == '\r' && cp[1] == '\n' &&
!             cp[2] == 'O' && cp[3] == 'K' &&
!             cp[4] == ' ') {
!             cp += 5;
!             /* cp points to a base64 key we should decode */
!             if (strlen(cp) >= (4 * PBC_DES_KEY_BUF + 100) / 3) {
!                 Messagef("key too long\n");
!                 exit(ERROR_INSTALL_FAILURE);
!             }
! 
!             if (newkeyp != -1) {
!                 if (strchr(cp, '\r')) {
!                     /* chomp new line */
!                     *(strchr(cp, '\r')) = '\0';
!                 }
!                 if (strchr(cp, '\n')) {
!                     /* chomp new line */
!                     *(strchr(cp, '\n')) = '\0';
!                 }
! 
!                 if (noop) {
!                     Messagef("would have set key to '%s'\n", cp);
!                 } else {
! 		    int osize = 0;
!                     int ret;
!                     if (strchr(cp, '\r')) {
!                         /* chomp new line */
!                         *strchr(cp, '\r') = '\0';
!                     }
!                     ret = libpbc_base64_decode(p, (unsigned char *) cp, thekey, &osize);
! 		    if (osize != PBC_DES_KEY_BUF) {
!                         Messagef("keyserver returned wrong key size: expected %d got %d\n", PBC_DES_KEY_BUF, osize);
!                         exit(ERROR_INSTALL_FAILURE);
!                     }
! 
!                     if (! ret) {
!                         Messagef( "Bad base64 decode.\n" );
!                         exit(ERROR_INSTALL_FAILURE);
!                     }
! 
!                     if (set_crypt_key((const char *) thekey, hostname) != PBC_OK) {
!                         Messagef("Cannot store key.  Make sure that key path (%s) exists and can be written to.\n",PBC_KEY_DIR);
!                         exit(ERROR_INSTALL_FAILURE);
!                     }
!                 }
!             }
! 
!             done = 1;
!             break;
!         }
!         cp++;
!     }
! 
!     //
!     // Cleanup.
!     //
! 
!     if(DisconnectFromServer(Socket, &hClientCreds, &hContext))
!     {
!         Messagef("Error disconnecting from server\n");
!     }
! 
! 
!     // Free SSPI credentials handle.
!     lpSecurityFunc->FreeCredentialsHandle(&hClientCreds);
! 
!     // Close socket.
!     closesocket(Socket);
! 
!     // Shutdown WinSock subsystem.
!     WSACleanup();
! 
!     // Close certificate store.
!     CertCloseMyStore();
! 
! 	if (!done) {
! 		Messagef("Operation failed.\nYou will need to sucessfully run keyclient and obtain a key before using the Pubcookie filter.\n\nServer Reply:\n%s", Reply);
! 		exit(ERROR_INSTALL_FAILURE);
!     }
! 
! 	// free memory pool
! 	free(p);
! 
!     return ERROR_SUCCESS;
! }


Index: webiso/pubcookie/src/Win32/winkeyclient.h
diff -c webiso/pubcookie/src/Win32/winkeyclient.h:1.1 webiso/pubcookie/src/Win32/winkeyclient.h:1.2
*** webiso/pubcookie/src/Win32/winkeyclient.h:1.1	Fri Jul  4 02:02:24 2003
--- webiso/pubcookie/src/Win32/winkeyclient.h	Thu Jan 22 21:00:26 2004
***************
*** 1,11 ****
! #define SECURITY_WIN32
! #include <windows.h>
! #include <security.h>
! #include <schannel.h>
! #include <sspi.h>
! 
! #define pid_t int
! #define snprintf _snprintf
! typedef void pool;
! 
! 
--- 1,44 ----
! typedef struct {
! 	char			remote_host[MAX_PATH];
! 	DWORD			inact_exp;
! 	DWORD			hard_exp;
! 	DWORD			failed;
! 	DWORD			has_granting;
! 	char			pszUser[SF_MAX_USERNAME];
! 	char			pszPassword[SF_MAX_PASSWORD];
! 	char			appid[PBC_APP_ID_LEN];
! 	char			s_cookiename[64];
! 	char			force_reauth[4];
! 	char			AuthType;
! 	char			default_url[1024];
! 	char			timeout_url[1024];
! 	char			user[PBC_USER_LEN];
! 	char			appsrvid[PBC_APPSRV_ID_LEN];
! 	char			appsrv_port[6];
! 	char			uri[1024];		              // *** size ??
! 	char			args[4096];                   // ***
! 	char			method[8];		              // ***
! 	char			handler;
! 	DWORD			session_reauth;
! 	DWORD			logout_action;
! 	char			Error_Page[MAX_PATH];
! 	char			Enterprise_Domain[1024];
! 	char			Login_URI[1024];
!     pbc_cookie_data *cookie_data;
! 	DWORD			Set_Server_Values;
! 	DWORD			legacy;
! 	char			*g_certfile;
! 	char			*s_keyfile;
! 	char			*s_certfile;
! 	char			*crypt_keyfile;
! 	int				serial_s_sent;
! 	char			server_hostname[MAX_PATH];
! 	char			instance_id[8];
! 	char			strbuff[MAX_REG_BUFF];  //temporary buffer for libpbc_config_getstring calls
! 
! } pubcookie_dir_rec;
! 
! #define pid_t int
! #define snprintf _snprintf
! 
! 



end of message


More information about the pubcookie-dev mailing list