Made SHAR socket name/port configurable.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 14 Feb 2003 07:50:10 +0000 (07:50 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 14 Feb 2003 07:50:10 +0000 (07:50 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@284 cb58f699-b61c-0410-a6fe-9272a202ed29

configs/shibboleth.ini
mod_shibrm/mod_shibrm.cpp
mod_shire/mod_shire.cpp
shar/shar.c
shib-target/shib-config.cpp
shib-target/shib-target.h

index 6671321..a51415f 100644 (file)
@@ -1,6 +1,7 @@
 [general]
 logger=/opt/shibboleth/etc/shibboleth/shibboleth.logger
 schemadir=/opt/shibboleth/etc/shibboleth/
+sharsocket=/tmp/shar-socket
 
 sitesFile=http://wayf.internet2.edu/shibboleth/sites.xml
 #sitesFile=file:///mit/shibboleth/src/shibboleth/java/webApplication/sites.xml
@@ -38,5 +39,4 @@ calist=/opt/shibboleth/etc/shibboleth/ca-bundle.crt
 eduPerson=/opt/shibboleth/lib/libeduPerson.so
 
 [policies]
-InCommon=urn:mace:InCommon:2003
-
+InCommon=urn:mace:InCommon:pilot:
\ No newline at end of file
index 7738656..356c37e 100644 (file)
@@ -32,7 +32,7 @@ using namespace shibtarget;
 
 namespace {
     RPCHandle *rpc_handle = NULL;
-    ShibTargetConfig* g_szConfig = NULL;
+    ShibTargetConfig* g_Config = NULL;
 
     map<string,string> g_mapAttribNameToHeader;
     map<string,string> g_mapAttribRuleToHeader;
@@ -154,7 +154,7 @@ extern "C" void shibrm_child_init(server_rec* s, pool* p)
     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,s,
                 "shibrm_child_init() starting");
 
-    if (g_szConfig) {
+    if (g_Config) {
       ap_log_error(APLOG_MARK,APLOG_ERR|APLOG_NOERRNO,s,
                   "shibrm_child_init(): already initialized!");
       exit (1);
@@ -162,7 +162,7 @@ extern "C" void shibrm_child_init(server_rec* s, pool* p)
 
     try {
       // Assume that we've been initialized from the SHIRE module!
-      g_szConfig = &(ShibTargetConfig::init(SHIBTARGET_RM, "NOOP"));
+      g_Config = &(ShibTargetConfig::init(SHIBTARGET_RM, "NOOP"));
     } catch (...) {
       ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,s,
                   "shibrm_child_init() failed to initialize SHIB Target");
@@ -173,7 +173,7 @@ extern "C" void shibrm_child_init(server_rec* s, pool* p)
 
     // Create the RPC Handle..  Note: this should be per _thread_
     // if there is some way to do that reasonably..
-    rpc_handle = new RPCHandle(SHIB_SHAR_SOCKET, SHIBRPC_PROG, SHIBRPC_VERS_1);
+    rpc_handle = new RPCHandle(g_Config->m_SocketName, SHIBRPC_PROG, SHIBRPC_VERS_1);
 
     // Transcode the attribute names we know about for quick handling map access.
     for (map<string,string>::const_iterator i=g_mapAttribNameToHeader.begin();
@@ -194,8 +194,8 @@ extern "C" void shibrm_child_init(server_rec* s, pool* p)
 extern "C" void shibrm_child_exit(server_rec* s, pool* p)
 {
     delete rpc_handle;
-    g_szConfig->shutdown();
-    g_szConfig = NULL;
+    g_Config->shutdown();
+    g_Config = NULL;
     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,s,"shibrm_child_exit() done");
 }
 
@@ -273,7 +273,7 @@ static const char* get_target(request_rec* r, const char* target)
 {
   const char* serverName = get_service_name(r);
   string tag;
-  if ((g_szConfig->getINI()).get_tag (serverName, "normalizeRequest", true, &tag))
+  if ((g_Config->getINI()).get_tag (serverName, "normalizeRequest", true, &tag))
   {
     if (ShibINI::boolean (tag))
     {
@@ -296,7 +296,7 @@ extern "C" int shibrm_check_auth(request_rec* r)
     threadid << "[" << getpid() << "] shibrm" << '\0';
     saml::NDC ndc(threadid.str().c_str());
 
-    ShibINI& ini = g_szConfig->getINI();
+    ShibINI& ini = g_Config->getINI();
     const char* serverName = get_service_name (r);
 
     shibrm_dir_config* dc=
index 062a1de..42b57b3 100644 (file)
@@ -40,7 +40,7 @@ namespace {
     char* g_szSHIREURL = NULL;
     char* g_szSHIREConfig = NULL;
     RPCHandle *rpc_handle = NULL;
-    ShibTargetConfig * g_szConfig = NULL;
+    ShibTargetConfig * g_Config = NULL;
 }
 
 // per-server configuration structure
@@ -171,14 +171,14 @@ extern "C" void shire_child_init(server_rec* s, pool* p)
     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,s,
                 "shire_child_init() starting");
 
-    if (g_szConfig) {
+    if (g_Config) {
       ap_log_error(APLOG_MARK,APLOG_ERR|APLOG_NOERRNO,s,
                   "shire_child_init(): already initialized!");
       exit (1);
     }
 
     try {
-      g_szConfig = &(ShibTargetConfig::init(SHIBTARGET_SHIRE, g_szSHIREConfig));
+      g_Config = &(ShibTargetConfig::init(SHIBTARGET_SHIRE, g_szSHIREConfig));
     } catch (...) {
       ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,s,
                   "shire_child_init() failed to initialize SHIB Target");
@@ -187,7 +187,7 @@ extern "C" void shire_child_init(server_rec* s, pool* p)
 
     // Create the RPC Handle..  Note: this should be per _thread_
     // if there is some way to do that reasonably..
-    rpc_handle = new RPCHandle(SHIB_SHAR_SOCKET, SHIBRPC_PROG, SHIBRPC_VERS_1);
+    rpc_handle = new RPCHandle(g_Config->m_SocketName, SHIBRPC_PROG, SHIBRPC_VERS_1);
 
     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,s,"shire_child_init() done");
 }
@@ -200,8 +200,8 @@ extern "C" void shire_child_init(server_rec* s, pool* p)
 extern "C" void shire_child_exit(server_rec* s, pool* p)
 {
     delete rpc_handle;
-    g_szConfig->shutdown();
-    g_szConfig = NULL;
+    g_Config->shutdown();
+    g_Config = NULL;
     ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,s,"shire_child_exit() done");
 }
 
@@ -249,7 +249,7 @@ static const char* get_target(request_rec* r, const char* target)
 {
   const char* serverName = get_service_name(r);
   string tag;
-  if ((g_szConfig->getINI()).get_tag (serverName, "normalizeRequest", true, &tag))
+  if ((g_Config->getINI()).get_tag (serverName, "normalizeRequest", true, &tag))
   {
     if (ShibINI::boolean (tag))
     {
@@ -268,7 +268,7 @@ static const char* get_target(request_rec* r, const char* target)
 
 static const char* get_shire_location(request_rec* r, const char* target, bool encode)
 {
-  ShibINI& ini = g_szConfig->getINI();
+  ShibINI& ini = g_Config->getINI();
   const char* serverName = get_service_name(r);
   string shire_location;
 
@@ -334,7 +334,7 @@ extern "C" int shire_check_user(request_rec* r)
     threadid << "[" << getpid() << "] shire" << '\0';
     saml::NDC ndc(threadid.str().c_str());
 
-    ShibINI& ini = g_szConfig->getINI();
+    ShibINI& ini = g_Config->getINI();
     ShibMLP markupProcessor;
 
     ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,r,
@@ -506,7 +506,7 @@ extern "C" int shire_post_handler (request_rec* r)
   threadid << "[" << getpid() << "] shire" << '\0';
   saml::NDC ndc(threadid.str().c_str());
 
-  ShibINI& ini = g_szConfig->getINI();
+  ShibINI& ini = g_Config->getINI();
   ShibMLP markupProcessor;
 
   ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,r,
index 95574ca..19320a9 100644 (file)
@@ -150,7 +150,7 @@ static int parse_args(int argc, char* argv[])
     case 'f':
 #ifndef WIN32
       /* XXX: I know that this is a string on Unix */
-      unlink (SHIB_SHAR_SOCKET);
+      unlink (ShibTargetConfig::getConfig().m_SocketName);
 #endif
       break;
     default:
@@ -169,9 +169,6 @@ main (int argc, char *argv[])
     { SHIBRPC_PROG, SHIBRPC_VERS_1, shibrpc_prog_1 }
   };
 
-  if (parse_args (argc, argv) != 0)
-    usage(argv[0]);
-
   if (setup_signals() != 0)
     return -1;
 
@@ -179,12 +176,15 @@ main (int argc, char *argv[])
   if (shib_target_initialize(SHIBTARGET_SHAR, config))
     return -2;
 
+  if (parse_args (argc, argv) != 0)
+    usage(argv[0]);
+
   /* Create the SHAR listener socket */
   if (shib_sock_create (&sock) != 0)
     return -3;
 
   /* Bind to the proper port */
-  if (shib_sock_bind (sock, SHIB_SHAR_SOCKET) != 0)
+  if (shib_sock_bind (sock, ShibTargetConfig::getConfig().m_SocketName) != 0)
     return -4;
 
   /* Initialize the SHAR Utilitites */
@@ -196,7 +196,7 @@ main (int argc, char *argv[])
   /* Finalize the SHAR, close all clients */
   shar_utils_fini();
 
-  shib_sock_close(sock, SHIB_SHAR_SOCKET);
+  shib_sock_close(sock, ShibTargetConfig::getConfig().m_SocketName);
   fprintf (stderr, "shar_svc_run returned.\n");
   return 0;
 }
index ac092f4..dce9d12 100644 (file)
@@ -83,6 +83,13 @@ ShibTargetConfig& ShibTargetConfig::getConfig()
     return *g_Config;
 }
 
+ShibTargetConfig::~ShibTargetConfig()
+{
+#ifdef WIN32
+#else
+    if (m_SocketName) free(m_SocketName);
+#endif
+}
 
 /****************************************************************************/
 // STConfig
@@ -219,6 +226,19 @@ STConfig::STConfig(const char* app_name, const char* inifile)
     }
     delete iter;
   }
+  
+  string sockname=ini->get(SHIBTARGET_GENERAL, "sharsocket");
+#ifdef WIN32
+  if (sockname.length()>0)
+    m_SocketName=atoi(sockname.c_str());
+  else
+    m_SocketName=SHIB_SHAR_SOCKET;
+#else
+  if (sockname.length()>0)
+    m_SocketName=strdup(sockname.c_str());
+  else
+    m_SocketName=strdup(SHIB_SHAR_SOCKET);
+#endif
 
   ref();
   log.debug("finished");
index 6d291fa..ec44a52 100644 (file)
@@ -20,7 +20,7 @@ extern "C" {
 #include <winsock.h>
 typedef SOCKET ShibSocket;
 typedef u_short ShibSockName;
-#define SHIB_SHAR_SOCKET 12345 /* shar portnumber */
+#define SHIB_SHAR_SOCKET 12345  /* shar portnumber */
 
 #else  /* UNIX */
 
@@ -79,7 +79,7 @@ void shib_sock_close (ShibSocket s, ShibSockName name);
 
 /* application names */
 #define SHIBTARGET_GENERAL     "general"
-#define SHIBTARGET_SHAR                "shar"
+#define SHIBTARGET_SHAR            "shar"
 #define SHIBTARGET_SHIRE       "shire"
 #define SHIBTARGET_RM          "rm"
 #define SHIBTARGET_POLICIES "policies"
@@ -411,8 +411,11 @@ namespace shibtarget {
     static ShibTargetConfig& init(const char* app_name, const char* inifile);
     static ShibTargetConfig& getConfig();
     virtual void shutdown() = 0;
+    virtual ~ShibTargetConfig();
     virtual ShibINI& getINI() = 0;
     virtual saml::Iterator<const XMLCh*> getPolicies() = 0;
+    
+    ShibSockName m_SocketName;
   };
 
 } // namespace