[pubcookie-dev] WEBISO CVS update: ryanc; pbc_config.h,1.84,1.85 pbc_configure.c,2.6,2.7 pbc_configure.h,2.6,2.7 pbc_myconfig.c,1.37,1.38 pbc_myconfig.h,1.15,1.16 security_legacy.c,1.33,1.34

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


Update of /usr/local/cvsroot/webiso/pubcookie/src
 In directory webiso-cvs.cac.washington.edu:/var/tmp/cvs-serv12267
 
 Modified Files:
 	base64.c libpubcookie.c pbc_config.h pbc_configure.c 
 	pbc_configure.h pbc_myconfig.c pbc_myconfig.h 
 	security_legacy.c 
 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/base64.c
diff -c webiso/pubcookie/src/base64.c:1.17 webiso/pubcookie/src/base64.c:1.18
*** webiso/pubcookie/src/base64.c:1.17	Thu Dec 11 13:48:44 2003
--- webiso/pubcookie/src/base64.c	Thu Jan 22 21:00:26 2004
***************
*** 6,12 ****
  /** @file base64.c
   * Base64 functions
   *
!  * $Id: base64.c,v 1.17 2003/12/11 21:48:44 willey Exp $
   */
                                                                                  
  
--- 6,12 ----
  /** @file base64.c
   * Base64 functions
   *
!  * $Id: base64.c,v 1.18 2004/01/23 05:00:26 ryanc Exp $
   */
                                                                                  
  
***************
*** 15,30 ****
  # include "pbc_path.h"
  #endif
  
! #if defined (APACHE1_3)
! # include "httpd.h"
! # include "http_config.h"
! # include "http_core.h"
! # include "http_log.h"
! # include "http_main.h"
! # include "http_protocol.h"
! # include "util_script.h"
! #else
! typedef void pool;
  #endif
  
  #ifdef HAVE_STRING_H
--- 15,39 ----
  # include "pbc_path.h"
  #endif
  
! #ifndef WIN32
! # if defined (APACHE1_3)
! #  include "httpd.h"
! #  include "http_config.h"
! #  include "http_core.h"
! #  include "http_log.h"
! #  include "http_main.h"
! #  include "http_protocol.h"
! #  include "util_script.h"
! # else
!   typedef void pool;
! # endif
! #else /* WIN32 */
! # include <Windows.h>
! # include <httpfilt.h>
! # include "pbc_config.h"
! # include "pubcookie.h"
! # include "Win32/PubCookieFilter.h"
!   typedef pubcookie_dir_rec pool;
  #endif
  
  #ifdef HAVE_STRING_H


Index: webiso/pubcookie/src/libpubcookie.c
diff -c webiso/pubcookie/src/libpubcookie.c:2.64 webiso/pubcookie/src/libpubcookie.c:2.65
*** webiso/pubcookie/src/libpubcookie.c:2.64	Wed Dec 17 14:10:56 2003
--- webiso/pubcookie/src/libpubcookie.c	Thu Jan 22 21:00:26 2004
***************
*** 6,12 ****
  /** @file libpubcookie.c
   * Core pubcookie library
   *
!  * $Id: libpubcookie.c,v 2.64 2003/12/17 22:10:56 ryanc Exp $
   */
  
  
--- 6,12 ----
  /** @file libpubcookie.c
   * Core pubcookie library
   *
!  * $Id: libpubcookie.c,v 2.65 2004/01/23 05:00:26 ryanc Exp $
   */
  
  
***************
*** 15,30 ****
  # include "pbc_path.h"
  #endif
  
- #if defined (WIN32)
- 
- # include <windows.h>
- typedef  int pid_t;  /* win32 process ID */
- # include <process.h>  /* getpid */
- #include  <io.h>
- #include  <stdio.h>
- 
- #else /* WIN32 */
- 
  # ifdef HAVE_STDIO_H
  #  include <stdio.h>
  # endif /* HAVE_STDIO_H */
--- 15,20 ----
***************
*** 69,86 ****
  #  include <netdb.h>
  # endif /* HAVE_NETDB_H */
  
! #endif /* WIN32 */
! 
! #if defined (APACHE1_3)
! # include "httpd.h"
! # include "http_config.h"
! # include "http_core.h"
! # include "http_log.h"
! # include "http_main.h"
! # include "http_protocol.h"
! # include "util_script.h"
! #else
! typedef void pool;
  #endif
  
  #ifdef OPENSSL_IN_DIR
--- 59,76 ----
  #  include <netdb.h>
  # endif /* HAVE_NETDB_H */
  
! #ifndef WIN32
! # if defined (APACHE1_3)
! #  include "httpd.h"
! #  include "http_config.h"
! #  include "http_core.h"
! #  include "http_log.h"
! #  include "http_main.h"
! #  include "http_protocol.h"
! #  include "util_script.h"
! # else
!   typedef void pool;
! # endif
  #endif
  
  #ifdef OPENSSL_IN_DIR
***************
*** 95,109 ****
  # include <err.h>
  #endif /* OPENSSL_IN_DIR */
  
! /* pubcookie lib stuff */
! #include "pubcookie.h"
! #include "libpubcookie.h"
! #include "pbc_config.h"
  #include "pbc_version.h"
- #include "strlcpy.h"
- #include "security.h"
  #include "pbc_logging.h"
  #include "pbc_configure.h"
  
  #ifdef HAVE_DMALLOC_H
  # if (!defined(APACHE) && !defined(APACHE1_3))
--- 85,113 ----
  # include <err.h>
  #endif /* OPENSSL_IN_DIR */
  
! #ifdef WIN32
! # include <windows.h>
! # include <process.h>  /* getpid */
! # include <stdio.h>
! # include <io.h>
! # include <assert.h>
! # include <httpfilt.h>
! # include "pbc_config.h"
! # include "pubcookie.h"
! # include "Win32/PubCookieFilter.h"
!   typedef pubcookie_dir_rec pool;
!   typedef  int pid_t;  /* win32 process ID */
! #else
! # include "pubcookie.h"
! # include "pbc_config.h"
! #endif
! 
  #include "pbc_version.h"
  #include "pbc_logging.h"
+ #include "libpubcookie.h"
+ #include "strlcpy.h"
  #include "pbc_configure.h"
+ #include "security.h"
  
  #ifdef HAVE_DMALLOC_H
  # if (!defined(APACHE) && !defined(APACHE1_3))
***************
*** 372,380 ****
   */
  static void make_crypt_keyfile(pool *p, const char *peername, char *buf)
  {
- #ifdef WIN32
- 	char SystemRootBuff[MAX_PATH+1];
- #endif 
      pbc_log_activity(p, PBC_LOG_DEBUG_LOW, "make_crypt_keyfile: hello\n");
  
      strlcpy(buf, PBC_KEY_DIR, 1024);
--- 376,381 ----


Index: webiso/pubcookie/src/pbc_config.h
diff -c webiso/pubcookie/src/pbc_config.h:1.84 webiso/pubcookie/src/pbc_config.h:1.85
*** webiso/pubcookie/src/pbc_config.h:1.84	Thu Dec 11 13:48:44 2003
--- webiso/pubcookie/src/pbc_config.h	Thu Jan 22 21:00:26 2004
***************
*** 4,10 ****
   */
  
  /*
!     $Id: pbc_config.h,v 1.84 2003/12/11 21:48:44 willey Exp $
   */
  
  #ifndef PUBCOOKIE_CONFIG
--- 4,10 ----
   */
  
  /*
!     $Id: pbc_config.h,v 1.85 2004/01/23 05:00:26 ryanc Exp $
   */
  
  #ifndef PUBCOOKIE_CONFIG
***************
*** 18,27 ****
  #define APACHE
  #endif
  
! #ifdef WIN32
! #  define PBC_KEY_DIR (AddSystemRoot(p, SystemRootBuff,"\\inetsrv\\pubcookie\\keys"))
! #  define libpbc_config_getstring(p, k, d) libpbc_config_sb_getstring(p, strbuff, k, d)
! #  define gstring(p, k, d) gstring(p, strbuff, k, d)
  #else
  #  include "pbc_path.h"
  #endif
--- 18,25 ----
  #define APACHE
  #endif
  
! #ifdef WIN32
! #  define PBC_KEY_DIR (AddSystemRoot(p, "\\inetsrv\\pubcookie\\keys"))
  #else
  #  include "pbc_path.h"
  #endif
***************
*** 40,46 ****
  #define PBC_LOGIN_URI (libpbc_config_getstring(p,"login_uri", "https://weblogin.washington.edu/"))
  #define PBC_KEYMGT_URI (libpbc_config_getstring(p,"keymgt_uri", "https://weblogin.washington.edu/cgi-bin/keyserver"))
  #define PBC_ENTRPRS_DOMAIN (libpbc_config_getstring(p,"enterprise_domain", ".washington.edu"))
! 
  #if defined (WIN32)
  	#define PBC_PUBLIC_NAME (libpbc_config_getstring(p, "PUBLIC_dir_name", "PUBLIC")) 
  	#define PBC_NETID_NAME (libpbc_config_getstring(p, "NETID_dir_name", "UWNETID"))
--- 38,44 ----
  #define PBC_LOGIN_URI (libpbc_config_getstring(p,"login_uri", "https://weblogin.washington.edu/"))
  #define PBC_KEYMGT_URI (libpbc_config_getstring(p,"keymgt_uri", "https://weblogin.washington.edu/cgi-bin/keyserver"))
  #define PBC_ENTRPRS_DOMAIN (libpbc_config_getstring(p,"enterprise_domain", ".washington.edu"))
! 
  #if defined (WIN32)
  	#define PBC_PUBLIC_NAME (libpbc_config_getstring(p, "PUBLIC_dir_name", "PUBLIC")) 
  	#define PBC_NETID_NAME (libpbc_config_getstring(p, "NETID_dir_name", "UWNETID"))
***************
*** 53,61 ****
  	#define PBC_AUTHTYPE0 (libpbc_config_getstring(p, "AuthTypeName0", "NONE")) 
  	#define PBC_AUTHTYPE1 (libpbc_config_getstring(p, "AuthTypeName1", "UWNETID"))
  	#define PBC_AUTHTYPE3 (libpbc_config_getstring(p, "AuthTypeName3", "SECURID"))
! 	#define PBC_PUBKEY "System\\CurrentControlSet\\Services\\PubcookieFilter"
  	#define PBC_CLIENT_LOG_FMT (libpbc_config_getstring(p, "ClientLogFormat", "%w(%p)"))
  	#define PBC_WEB_VAR_LOCATION (libpbc_config_getstring(p, "WebVarLocation", "System\\CurrentControlSet\\Services\\PubcookieFilter"))
  #endif
  
  #define PBC_REFRESH_TIME 0
--- 51,66 ----
  	#define PBC_AUTHTYPE0 (libpbc_config_getstring(p, "AuthTypeName0", "NONE")) 
  	#define PBC_AUTHTYPE1 (libpbc_config_getstring(p, "AuthTypeName1", "UWNETID"))
  	#define PBC_AUTHTYPE3 (libpbc_config_getstring(p, "AuthTypeName3", "SECURID"))
! 	#define PBC_FILTER_KEY "System\\CurrentControlSet\\Services\\PubcookieFilter"
! 	#define PBC_PUB_KEY "Software\\"
  	#define PBC_CLIENT_LOG_FMT (libpbc_config_getstring(p, "ClientLogFormat", "%w(%p)"))
  	#define PBC_WEB_VAR_LOCATION (libpbc_config_getstring(p, "WebVarLocation", "System\\CurrentControlSet\\Services\\PubcookieFilter"))
+ 	#define PBC_TEMPLATES_PATH libpbc_config_getstring(p, "RelayTemplatePath", "D:\\Inetpub\\wwwroot\\relay\\")
+ 	#define PBC_RELAY_URI libpbc_config_getstring(p, "relay_uri", "https://relay.example.url/relay/index.cgi")
+ 	#define PBC_RELAY_WEB_KEY "_PBC_Relay_CGI"
+ 	#define PBC_INSTANCE_KEY "_PBC_Web_Instances"
+ 	#define MAX_REG_BUFF 2048 /* Using a fixed size saves a registy lookup 
+                              and malloc to find/set the buffer size */
  #endif
  
  #define PBC_REFRESH_TIME 0


Index: webiso/pubcookie/src/pbc_configure.c
diff -c webiso/pubcookie/src/pbc_configure.c:2.6 webiso/pubcookie/src/pbc_configure.c:2.7
*** webiso/pubcookie/src/pbc_configure.c:2.6	Fri Sep 26 15:27:02 2003
--- webiso/pubcookie/src/pbc_configure.c	Thu Jan 22 21:00:26 2004
***************
*** 6,12 ****
  /** @file pbc_configure.c
   * Configure stuff
   *
!  * $Id: pbc_configure.c,v 2.6 2003/09/26 22:27:02 ryanc Exp $
   */
  
  #ifdef HAVE_CONFIG_H
--- 6,12 ----
  /** @file pbc_configure.c
   * Configure stuff
   *
!  * $Id: pbc_configure.c,v 2.7 2004/01/23 05:00:26 ryanc Exp $
   */
  
  #ifdef HAVE_CONFIG_H
***************
*** 36,41 ****
--- 36,44 ----
  # include <stdarg.h>
  #endif
  
+ #ifdef WIN32
+ # include <windows.h>
+ #endif
  #include "libpubcookie.h"
  #include "pbc_configure.h"
  #include "pbc_logging.h"
***************
*** 96,102 ****
  }
  
  int libpbc_config_getint(pool *p, const char *key, int def)
! {
      return(gint(p, key, def));
  }
  
--- 99,105 ----
  }
  
  int libpbc_config_getint(pool *p, const char *key, int def)
! {
      return(gint(p, key, def));
  }
  
***************
*** 105,121 ****
      return(gswitch(p, key, def));
  }
  
! #ifndef WIN32
! const char *libpbc_config_getstring(pool *p, const char *key, const char *def)
! {
!     return(gstring(p, key, def));
! }
! #else
! char *libpbc_config_sb_getstring(pool *p, char *strbuff, const char *key, const char *def)
! {
!     return(gstring(p, strbuff, key, def));
! }
! #endif
  
  char **libpbc_config_getlist(pool *p, const char *key)
  {
--- 108,117 ----
      return(gswitch(p, key, def));
  }
  
! const char *libpbc_config_getstring(pool *p, const char *key, const char *def)
! {
!     return(gstring(p, key, def));
! }
  
  char **libpbc_config_getlist(pool *p, const char *key)
  {


Index: webiso/pubcookie/src/pbc_configure.h
diff -c webiso/pubcookie/src/pbc_configure.h:2.6 webiso/pubcookie/src/pbc_configure.h:2.7
*** webiso/pubcookie/src/pbc_configure.h:2.6	Fri Sep 26 15:27:02 2003
--- webiso/pubcookie/src/pbc_configure.h	Thu Jan 22 21:00:26 2004
***************
*** 4,10 ****
   */
  
  /*
!   $Id: pbc_configure.h,v 2.6 2003/09/26 22:27:02 ryanc Exp $
   */
  
  #ifndef INCLUDED_PBC_CONFIGURE_H
--- 4,10 ----
   */
  
  /*
!   $Id: pbc_configure.h,v 2.7 2004/01/23 05:00:26 ryanc Exp $
   */
  
  #ifndef INCLUDED_PBC_CONFIGURE_H
***************
*** 25,36 ****
                                        const char *ident);
  typedef int config_getint(pool *p, const char *key, int def);
  typedef char** config_getlist(pool *p, const char *key);
! #ifndef WIN32
! typedef const char* config_getstring(pool *p, const char *key, const char *def);
! #else
! typedef char* config_getstring(pool *p, char *strbuff, const char *key, const char *def);
! #endif
! 
  typedef int config_getswitch(pool *p, const char *key, int def);
  
  /**
--- 25,32 ----
                                        const char *ident);
  typedef int config_getint(pool *p, const char *key, int def);
  typedef char** config_getlist(pool *p, const char *key);
! typedef const char* config_getstring(pool *p, const char *key, const char *def);
! 
  typedef int config_getswitch(pool *p, const char *key, int def);
  
  /**
***************
*** 60,72 ****
  
  int libpbc_config_getint(pool *p, const char *key, int def);
  char** libpbc_config_getlist(pool *p, const char *key);
- #ifndef WIN32
  const char* libpbc_config_getstring(pool *p, const char *key, const char *def);
- #else 
- char* libpbc_config_sb_getstring(pool *p, char *strbuff, const char *key, const char *def);
- #define MAX_REG_BUFF 2048 /* Using a fixed size saves a registy lookup 
-                              and malloc to find/set the buffer size */
- #endif
  int libpbc_config_getswitch(pool *p, const char *key, int def);
  
  #endif /* INCLUDED_PBC_CONFIGURE_H */
--- 56,62 ----


Index: webiso/pubcookie/src/pbc_myconfig.c
diff -c webiso/pubcookie/src/pbc_myconfig.c:1.37 webiso/pubcookie/src/pbc_myconfig.c:1.38
*** webiso/pubcookie/src/pbc_myconfig.c:1.37	Thu Jan 15 15:57:16 2004
--- webiso/pubcookie/src/pbc_myconfig.c	Thu Jan 22 21:00:26 2004
***************
*** 6,12 ****
  /** @file pbc_myconfig.c
   * Runtime configuration 
   *
!  * $Id: pbc_myconfig.c,v 1.37 2004/01/15 23:57:16 fox Exp $
   */
  
  
--- 6,12 ----
  /** @file pbc_myconfig.c
   * Runtime configuration 
   *
!  * $Id: pbc_myconfig.c,v 1.38 2004/01/23 05:00:26 ryanc Exp $
   */
  
  
***************
*** 15,31 ****
  # include "pbc_path.h"
  #endif
  
! #if defined (APACHE1_3)
! # include "httpd.h"
! # include "http_config.h"
! # include "http_core.h"
! # include "http_log.h"
! # include "http_main.h"
! # include "http_protocol.h"
! # include "util_script.h"
! #else
! typedef void pool;
! #endif
  
  #ifdef HAVE_STDIO_H
  # include <stdio.h>
--- 15,33 ----
  # include "pbc_path.h"
  #endif
  
! #ifndef WIN32
! # if defined (APACHE1_3)
! #  include "httpd.h"
! #  include "http_config.h"
! #  include "http_core.h"
! #  include "http_log.h"
! #  include "http_main.h"
! #  include "http_protocol.h"
! #  include "util_script.h"
! # else
!    typedef void pool;
! # endif /* APACHE1_3 */
! #endif /* WIN32 */
  
  #ifdef HAVE_STDIO_H
  # include <stdio.h>
***************
*** 57,62 ****
--- 59,66 ----
  # define EX_OSERR 71
  #endif /* HAVE_SYSEXITS_H */
  
+ #ifndef WIN32  /* See below for WIN32 code */
+ 
  #include "pbc_logging.h"
  #ifdef HAVE_UNISTD_H
  # include <unistd.h>
***************
*** 92,104 ****
  static int nconfiglist;
  
  static void myconfig_read(pool *p, const char *alt_config, int required);
- static void fatal(pool *p, const char *s, int ex);
- 
- #ifdef WIN32
- # include "Win32/debug.h"
- #endif
  
! #ifndef WIN32
  
  int libpbc_myconfig_init(pool *p, const char *alt_config, const char *ident)
  {
--- 96,103 ----
  static int nconfiglist;
  
  static void myconfig_read(pool *p, const char *alt_config, int required);
  
! static void fatal(pool *p, const char *s, int ex);
  
  int libpbc_myconfig_init(pool *p, const char *alt_config, const char *ident)
  {
***************
*** 399,522 ****
  }
  #endif
  
! #else  /*WIN32*/
  
  #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdio.h>
  #include <time.h>
- #include <pem.h>
  #include <httpfilt.h>
  #include "Win32/debug.h"
  
  
- #define CONFIGLISTGROWSIZE 50
- 
- static void fatal(pool *p, const char *s, int ex)
- {
- 	syslog(LOG_ERR, "fatal error: %s\n", s);
-     exit(ex);
- }
- 
- 
- char *libpbc_myconfig_copystring(char **outputstring, const char *inputstring, int size)
- {
- 	if (inputstring != NULL) {
- 		strncpy(*outputstring,inputstring,MAX_REG_BUFF);  
- 	}
- 	else {
- 		free(*outputstring);
- 		*outputstring = NULL;
- 	}
- 	return *outputstring;
- }
- 
- char *libpbc_myconfig_getstring(pool *p, char *strbuff, const char *key, const char *def)
- {
- 	char keyBuff[1024];
- 	HKEY hKey;
- 	int dsize;
- 
- 	dsize = MAX_REG_BUFF;
- 	strcpy (keyBuff,PBC_PUBKEY);  /* config. settings in main pubcookie service key */
- 	
- 	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- 		keyBuff,0,KEY_READ,&hKey) != ERROR_SUCCESS) {
- 		libpbc_myconfig_copystring(&strbuff,def,MAX_REG_BUFF);  
- 	}
- 	else {
- 		if (RegQueryValueEx(hKey, key, NULL, NULL, (UCHAR *)strbuff,
- 			&dsize) != ERROR_SUCCESS) {
- 			libpbc_myconfig_copystring(&strbuff,def,MAX_REG_BUFF);
- 		}
- 		RegCloseKey(hKey);
- 	}
- 
- 	return strbuff;  /* Note that this must have been allocated by the calling process */
- }
- 
- 
- int libpbc_myconfig_getint(pool *p, const char *key, int def)
- {
- 	char keyBuff[1024];
- 	HKEY hKey;
- 	UCHAR *dataBuff;
-     int dsize, value;
- 
- 	if (!(dataBuff = (UCHAR *)malloc(sizeof (DWORD)))) {
- 		fatal(p,"malloc failed in libpbc_myconfig_getint.",2);
- 	}
- 	dsize = sizeof(DWORD);
- 	strcpy (keyBuff,PBC_PUBKEY);  /* config. settings in main pubcookie service key */
- 	
- 	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- 		keyBuff,0,KEY_READ,&hKey) != ERROR_SUCCESS) {
- 		return def;  
- 	}
- 	
- 	if (RegQueryValueEx(hKey, key, NULL, NULL, dataBuff,
- 		&dsize) != ERROR_SUCCESS) {
- 		RegCloseKey(hKey);
- 		return def;
- 	}
- 
- 	value = (int)*dataBuff;
- 	free(dataBuff);
- 	RegCloseKey(hKey);
- 	return value;
- }
- 
- int libpbc_myconfig_getswitch(pool *p, const char *key, int def)
- {
- 	/* Unimplemented */
- 	return def;
- }
- 
- char **libpbc_myconfig_getlist(pool *p, const char *key)
- {
- 	/* Unimplemented */
- 	return NULL;
- }
- 
- int libpbc_myconfig_init(pool *p, const char *alt_config, const char *ident)
- {
- 		return TRUE;
- }
- 
- char *AddSystemRoot(pool *p, char *buff,const char *subdir) 
- {
- 	char strbuff[MAX_REG_BUFF];
- 
- 	strncpy(buff, libpbc_config_sb_getstring(p, strbuff, "System_Root",""),MAX_PATH+1);
- 	if (strcmp(buff,"") == 0) {
- 		GetSystemDirectory(buff,MAX_PATH+1);
- 	}
- 	strncat(buff,subdir,MAX_PATH+1);
- 	return (buff);  //Note, must be allocated by calling process
- }
- 
  
  #endif /*WIN32*/
--- 398,543 ----
  }
  #endif
  
! #else  /*WIN32*/
  
  #include <windows.h>
  #include <time.h>
  #include <httpfilt.h>
+ #include <strsafe.h>
+ 
+ #include "pubcookie.h"
+ #include "pbc_config.h"
+ #include "Win32/PubCookieFilter.h" 
+ 
+ typedef pubcookie_dir_rec pool;
+ 
  #include "Win32/debug.h"
+ #include "pbc_configure.h"
+ #include "snprintf.h"
+ #include "libpubcookie.h"
+ #include "pbc_logging.h"
+ 
+ 
+ static void fatal(pool *p, const LPTSTR s, int ex)
+ {
+ 	syslog(LOG_ERR, "fatal error: %s\n", s);
+     exit(ex);
+ }
+ 
+ 
+ LPTSTR libpbc_myconfig_copystring(LPTSTR outputstring, LPCTSTR inputstring, int size)
+ {
+ 	if (inputstring != NULL) {
+ 		StringCchCopy(outputstring, size, inputstring);  
+ 	}
+ 	else {
+ 		free(outputstring);
+ 		outputstring = NULL;
+ 	}
+ 	return outputstring;
+ }
+ 
+ /* Note that strbuff must have been allocated by the calling process */
+ LPTSTR libpbc_myconfig_getstring(pool *p, LPCTSTR key, LPCTSTR def)
+ {
+ 	char keyBuff[PBC_1K];
+ 	HKEY hKey;
+ 	int dsize;
+ 
+ 	if (!p) fatal(p, "libpbc_myconfig_getstring called without an allocated pool",3);
+ 	
+ 	dsize = MAX_REG_BUFF;
+ 	/* first look in web key */
+ 	StringCchCopy(keyBuff, PBC_1K, PBC_FILTER_KEY);
+ 	StringCchCat (keyBuff, PBC_1K, "\\");
+ 	StringCchCat (keyBuff, PBC_1K, PBC_INSTANCE_KEY);
+ //	StringCchCat (keyBuff, PBC_1K, "\\");
+ //	StringCchCat (keyBuff, PBC_1K, web_instance);
+ 
+ 	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyBuff,0,KEY_READ,&hKey) == ERROR_SUCCESS) {
+ 		if (RegQueryValueEx(hKey, key, NULL, NULL, (UCHAR *)p->strbuff, &dsize) == ERROR_SUCCESS) {
+ 			/* if we find the value here, we're done */
+ 			RegCloseKey(hKey);
+ 			return p->strbuff;  
+ 		}
+ 		RegCloseKey(hKey);
+ 	}
+ 
+ 	/* then look for config. settings in main pubcookie service key */
+ 	StringCchCopy(keyBuff, PBC_1K, PBC_FILTER_KEY);  
+ 
+ 	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyBuff,0,KEY_READ,&hKey) == ERROR_SUCCESS) {
+ 		if (RegQueryValueEx(hKey, key, NULL, NULL, (UCHAR *)p->strbuff, &dsize) != ERROR_SUCCESS) {
+ 			libpbc_myconfig_copystring(p->strbuff,def,MAX_REG_BUFF);
+ 		} /* else if ERROR_SUCCESS we keep the value returned in strbuff */
+ 		RegCloseKey(hKey);
+ 	} else {
+ 		libpbc_myconfig_copystring(p->strbuff,def,MAX_REG_BUFF);
+ 	}
+ 
+ 	return p->strbuff;  
+ }
+ 
+ 
+ int libpbc_myconfig_getint(pool *p, LPCTSTR key, int def)
+ {
+ 	char keyBuff[PBC_1K];
+ 	HKEY hKey;
+ 	UCHAR *dataBuff;
+     int dsize, value;
+ 
+ 	if (!p) fatal(p, "libpbc_myconfig_getint called without an allocated pool",3);
+ 
+ 	if (!(dataBuff = (UCHAR *)malloc(sizeof (DWORD)))) {
+ 		fatal(p,"malloc failed in libpbc_myconfig_getint.",2);
+ 	}
+ 	dsize = sizeof(DWORD);
+ 	StringCchCopy(keyBuff, PBC_1K, PBC_FILTER_KEY);  /* config. settings in main pubcookie service key */
+ 	
+ 	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ 		keyBuff,0,KEY_READ,&hKey) != ERROR_SUCCESS) {
+ 		return def;  
+ 	}
+ 	
+ 	if (RegQueryValueEx(hKey, key, NULL, NULL, dataBuff,
+ 		&dsize) != ERROR_SUCCESS) {
+ 		RegCloseKey(hKey);
+ 		return def;
+ 	}
+ 
+ 	value = (int)*dataBuff;
+ 	free(dataBuff);
+ 	RegCloseKey(hKey);
+ 	return value;
+ }
  
+ int libpbc_myconfig_getswitch(pool *p, LPCTSTR key, int def)
+ {
+ 	/* Unimplemented */
+ 	return def;
+ }
+ 
+ LPTSTR *libpbc_myconfig_getlist(pool *p, LPCTSTR key)
+ {
+ 	/* Unimplemented */
+ 	return NULL;
+ }
+ 
+ int libpbc_myconfig_init(pool *p, LPCTSTR alt_config, LPCTSTR ident)
+ {
+ 		return TRUE;
+ }
+ 
+ LPTSTR AddSystemRoot(pool *p, LPCTSTR subdir) 
+ {
+ 	if (!p) fatal(p, "AddSystemRoot called without an allocated pool",3);
+ 
+ 	if (strncmp(libpbc_config_getstring(p, "System_Root",""),"",MAX_PATH) == 0) {
+ 		GetSystemDirectory(p->strbuff,MAX_PATH+1);
+ 	}
+ 	strncat(p->strbuff,subdir,MAX_PATH+1);
+ 	return (p->strbuff); 
+ }
  
  
  #endif /*WIN32*/


Index: webiso/pubcookie/src/pbc_myconfig.h
diff -c webiso/pubcookie/src/pbc_myconfig.h:1.15 webiso/pubcookie/src/pbc_myconfig.h:1.16
*** webiso/pubcookie/src/pbc_myconfig.h:1.15	Thu Dec 11 13:48:44 2003
--- webiso/pubcookie/src/pbc_myconfig.h	Thu Jan 22 21:00:26 2004
***************
*** 6,12 ****
  /** @file pbc_myconfig.h
   * header file for Runtime configuration
   *
!  * $Id: pbc_myconfig.h,v 1.15 2003/12/11 21:48:44 willey Exp $
   */
  
  
--- 6,12 ----
  /** @file pbc_myconfig.h
   * header file for Runtime configuration
   *
!  * $Id: pbc_myconfig.h,v 1.16 2004/01/23 05:00:26 ryanc Exp $
   */
  
  
***************
*** 17,22 ****
--- 17,23 ----
  # include "config.h"
  #endif
  
+ #ifndef WIN32
  /**
   * initialize the config subsystem
   * @param pool Apache memory pool
***************
*** 34,46 ****
   * @param def the default value to return if the key isn't found
   * @return the value of the option or def if it isn't found.  the
   * string belongs to the config library---it should not be changed or
!  * free().  */
  
- #ifndef WIN32
- extern const char *libpbc_myconfig_getstring(pool *p, const char *key, const char *def);
- #else
- extern char *libpbc_myconfig_getstring(pool *p, char *strbuff, const char *key, const char *def);
- #endif
  /**
   * return an int variable identified by key
   * @param pool Apache memory pool
--- 35,43 ----
   * @param def the default value to return if the key isn't found
   * @return the value of the option or def if it isn't found.  the
   * string belongs to the config library---it should not be changed or
!  * free().  */
! extern LPCTSTR libpbc_myconfig_getstring(pool *p, LPTSTR strbuff, LPCTSTR key, LPCTSTR def);
  
  /**
   * return an int variable identified by key
   * @param pool Apache memory pool
***************
*** 67,75 ****
   * @return a NULL terminated array of NUL terminated strings.
   * the array must be free() when the caller is done */
  extern char **libpbc_myconfig_getlist(pool *p, const char *key);
! 
! # ifdef WIN32
!   extern char * AddSystemRoot(pool *p, char *buff, const char *subdir);
  # endif
  #endif /* INCLUDED_PBC_MYCONF_H */
  
--- 64,86 ----
   * @return a NULL terminated array of NUL terminated strings.
   * the array must be free() when the caller is done */
  extern char **libpbc_myconfig_getlist(pool *p, const char *key);
! 
! #else  //Win32 declarations.  Descriptions same as above.
! 
! extern int libpbc_myconfig_init(pool *p, LPCTSTR alt_config, LPCTSTR ident);
! extern int libpbc_myconfig_getint(pool *p, LPCTSTR key, int def);
! extern LPTSTR libpbc_myconfig_getstring(pool *p, LPCTSTR key, LPCTSTR def);
! extern int libpbc_myconfig_getswitch(pool *p, LPCTSTR key, int def);
! extern LPTSTR *libpbc_myconfig_getlist(pool *p, LPCTSTR key);
! 
! /**
!  * Add a given subdirectory to the Windows System path. 
!  * In: pool     Apache memory pool (not used)
!  * In: subdir   Subdirectory to add
!  * In: buff     pointer to preallocated memory to hold result
!  * Returns:     pointer to preallocated memory (buff) */
! extern LPTSTR  AddSystemRoot(pool *p, LPCTSTR subdir);
! 
  # endif
  #endif /* INCLUDED_PBC_MYCONF_H */
  


Index: webiso/pubcookie/src/security_legacy.c
diff -c webiso/pubcookie/src/security_legacy.c:1.33 webiso/pubcookie/src/security_legacy.c:1.34
*** webiso/pubcookie/src/security_legacy.c:1.33	Wed Dec 17 14:10:56 2003
--- webiso/pubcookie/src/security_legacy.c	Thu Jan 22 21:00:26 2004
***************
*** 6,12 ****
  /** @file security_legacy.c
   * Heritage message protection
   *
!  * $Id: security_legacy.c,v 1.33 2003/12/17 22:10:56 ryanc Exp $
   */
  
  
--- 6,12 ----
  /** @file security_legacy.c
   * Heritage message protection
   *
!  * $Id: security_legacy.c,v 1.34 2004/01/23 05:00:26 ryanc Exp $
   */
  
  
***************
*** 15,30 ****
  # include "pbc_path.h"
  #endif
  
! #if defined (APACHE1_3)
! # include "httpd.h"
! # include "http_config.h"
! # include "http_core.h"
! # include "http_log.h"
! # include "http_main.h"
! # include "http_protocol.h"
! # include "util_script.h"
! #else
! typedef void pool;
  #endif
  
  #ifdef HAVE_STDIO_H
--- 15,32 ----
  # include "pbc_path.h"
  #endif
  
! #ifndef WIN32
! # if defined (APACHE1_3)
! #  include "httpd.h"
! #  include "http_config.h"
! #  include "http_core.h"
! #  include "http_log.h"
! #  include "http_main.h"
! #  include "http_protocol.h"
! #  include "util_script.h"
! # else
!   typedef void pool;
! # endif
  #endif
  
  #ifdef HAVE_STDIO_H
***************
*** 65,86 ****
  #endif /* HAVE_ASSERT_H */
  
  #ifdef WIN32
- # include <io.h>
- # include <assert.h>
  # define DIR_SEP "\\"
  #else
  # define DIR_SEP "/"
  #endif
  
! #include "pbc_config.h"
! #include "pbc_logging.h"
! #include "libpubcookie.h"
! #include "strlcpy.h"
! #include "snprintf.h"
! #include "pbc_configure.h"
! 
! #include "security.h"
! #include "pubcookie.h"
  
  #ifdef HAVE_DMALLOC_H
  # if (!defined(APACHE) && !defined(APACHE1_3))
--- 67,101 ----
  #endif /* HAVE_ASSERT_H */
  
  #ifdef WIN32
  # define DIR_SEP "\\"
  #else
  # define DIR_SEP "/"
  #endif
  
! #ifdef WIN32
! # include <io.h>
! # include <assert.h>
! # include <httpfilt.h>
! # include "pbc_config.h"
! # include "pubcookie.h"
! # include "Win32/PubCookieFilter.h"
!   typedef pubcookie_dir_rec pool;
! # include "pbc_logging.h"
! # include "libpubcookie.h"
! # include "strlcpy.h"
! # include "snprintf.h"
! # include "pbc_configure.h"
! # include "security.h"
! #else
! # include "pbc_config.h"
! # include "pbc_logging.h"
! # include "libpubcookie.h"
! # include "strlcpy.h"
! # include "snprintf.h"
! # include "pbc_configure.h"
! # include "security.h"
! # include "pubcookie.h"
! #endif
  
  #ifdef HAVE_DMALLOC_H
  # if (!defined(APACHE) && !defined(APACHE1_3))
***************
*** 168,206 ****
      /* the granting key & certificate */
      char *g_keyfile;
      char *g_certfile;
- #ifdef WIN32
- 	char SystemRootBuff[MAX_PATH+1];
- 	char strbuff[MAX_REG_BUFF];
- #endif 
      FILE *fp;
  
      pbc_log_activity(p, PBC_LOG_DEBUG_LOW, "security_init: hello\n");
! 
! 	/* initialize the random number generator */
! #if defined (WIN32)
!     /* Windows only has milliseconds */
!     {
! 	SYSTEMTIME   ts;
! 	unsigned char buf[sizeof(ts.wMilliseconds)];
! 	
! 	GetLocalTime(&ts);
! 	memcpy(buf, &ts.wMilliseconds, sizeof(ts.wMilliseconds));
! 	RAND_seed(buf, sizeof(ts.wMilliseconds));
!     }
! #else
!     {
! 	struct timeval tv; 
! 	struct timezone tz;
! 	unsigned char buf[sizeof(tv.tv_usec)];
! 	
! 	gettimeofday(&tv, &tz);
! 	memcpy(buf, &tv.tv_usec, sizeof(tv.tv_usec));
! 	RAND_seed(buf, sizeof(tv.tv_usec));
!     }
! #endif
  
      /* first we try to use the ssl files */
!     keyfile = mystrdup(p, libpbc_config_getstring(p, "ssl_key_file", NULL));
      if (keyfile && access(keyfile, R_OK | F_OK)) {
          pbc_free(p, keyfile);
          /* not there ? */
--- 183,217 ----
      /* the granting key & certificate */
      char *g_keyfile;
      char *g_certfile;
      FILE *fp;
  
      pbc_log_activity(p, PBC_LOG_DEBUG_LOW, "security_init: hello\n");
! 
! 	/* initialize the random number generator */
! #if defined (WIN32)
!     /* Windows only has milliseconds */
!     {
! 	SYSTEMTIME   ts;
! 	unsigned char buf[sizeof(ts.wMilliseconds)];
! 	
! 	GetLocalTime(&ts);
! 	memcpy(buf, &ts.wMilliseconds, sizeof(ts.wMilliseconds));
! 	RAND_seed(buf, sizeof(ts.wMilliseconds));
!     }
! #else
!     {
! 	struct timeval tv; 
! 	struct timezone tz;
! 	unsigned char buf[sizeof(tv.tv_usec)];
! 	
! 	gettimeofday(&tv, &tz);
! 	memcpy(buf, &tv.tv_usec, sizeof(tv.tv_usec));
! 	RAND_seed(buf, sizeof(tv.tv_usec));
!     }
! #endif
  
      /* first we try to use the ssl files */
!     keyfile = mystrdup(p, libpbc_config_getstring(p, "ssl_key_file", NULL));
      if (keyfile && access(keyfile, R_OK | F_OK)) {
          pbc_free(p, keyfile);
          /* not there ? */
***************
*** 255,261 ****
          pbc_log_activity(p, PBC_LOG_ERROR, 
  		"security_init: couldn't find session keyfile (try setting ssl_key_file?)");
          return -1;
!     }
      if (!certfile) {
          pbc_log_activity(p, PBC_LOG_ERROR, 
  		"security_init: couldn't find session certfile (try setting ssl_cert_file?)");
--- 266,272 ----
          pbc_log_activity(p, PBC_LOG_ERROR, 
  		"security_init: couldn't find session keyfile (try setting ssl_key_file?)");
          return -1;
!     }
      if (!certfile) {
          pbc_log_activity(p, PBC_LOG_ERROR, 
  		"security_init: couldn't find session certfile (try setting ssl_cert_file?)");
***************
*** 295,303 ****
  
      /* now read them into memory */
  	
!     /* session key */
! #ifdef WIN32
!     if (keyfile && certfile) {
  #endif
      fp = pbc_fopen(p, keyfile, "r");
  
--- 306,314 ----
  
      /* now read them into memory */
  	
!     /* session key */
! #ifdef WIN32
!     if (keyfile && certfile) {
  #endif
      fp = pbc_fopen(p, keyfile, "r");
  
***************
*** 352,390 ****
          myname = mystrdup(p, tmp);
      }
      pbc_fclose(p, fp);
! #ifdef WIN32
! 	}
! 	else {
! 
! 		sess_key=EVP_PKEY_new();
! 		
! 		if (!EVP_PKEY_assign_RSA(sess_key,RSA_generate_key(1024,RSA_F4,NULL,NULL)))
! 		{
! 			pbc_log_activity(p, PBC_LOG_ERROR, 
! 				"[Pubcookie_Init] Unable to find or generate session keypair.");
! 			return -1;
! 		}
! 
! 		/* sess_key was assigned both public and private keys */
! 		sess_pub = sess_key;
          pbc_log_activity(p, PBC_LOG_AUDIT, 
                           "security_init: generated new session keypair.");
! 	}
! 
! 	{
! 		char tmp[1024];
! 		struct hostent *hp;
! 
! 		gethostname(tmp, sizeof(tmp)-1);
! 		if ( !(hp = gethostbyname(tmp)) ) {
! 			pbc_log_activity(p, PBC_LOG_ERROR, 
! 				"[Pubcookie_Init] gethostbyname failed.");
! 			return -1;
! 		}
! 		myname = mystrdup(p, hp->h_name);
! 	}
! 
! #endif
      /* granting key */
      if (g_keyfile) {
  	fp = pbc_fopen(p, g_keyfile, "r");
--- 363,401 ----
          myname = mystrdup(p, tmp);
      }
      pbc_fclose(p, fp);
! #ifdef WIN32
! 	}
! 	else {
! 
! 		sess_key=EVP_PKEY_new();
! 		
! 		if (!EVP_PKEY_assign_RSA(sess_key,RSA_generate_key(1024,RSA_F4,NULL,NULL)))
! 		{
! 			pbc_log_activity(p, PBC_LOG_ERROR, 
! 				"[Pubcookie_Init] Unable to find or generate session keypair.");
! 			return -1;
! 		}
! 
! 		/* sess_key was assigned both public and private keys */
! 		sess_pub = sess_key;
          pbc_log_activity(p, PBC_LOG_AUDIT, 
                           "security_init: generated new session keypair.");
! 	}
! 
! 	{
! 		char tmp[1024];
! 		struct hostent *hp;
! 
! 		gethostname(tmp, sizeof(tmp)-1);
! 		if ( !(hp = gethostbyname(tmp)) ) {
! 			pbc_log_activity(p, PBC_LOG_ERROR, 
! 				"[Pubcookie_Init] gethostbyname failed.");
! 			return -1;
! 		}
! 		myname = mystrdup(p, hp->h_name);
! 	}
! 
! #endif
      /* granting key */
      if (g_keyfile) {
  	fp = pbc_fopen(p, g_keyfile, "r");
***************
*** 464,472 ****
   */
  static void make_crypt_keyfile(pool *p, const char *peername, char *buf)
  {
- #ifdef WIN32
- 	char SystemRootBuff[MAX_PATH+1];
- #endif 
      pbc_log_activity(p, PBC_LOG_DEBUG_LOW, "make_crypt_keyfile: hello\n");
  
      strlcpy(buf, PBC_KEY_DIR, 1024);
--- 475,480 ----



end of message


More information about the pubcookie-dev mailing list