Applied Ere's global client-authentication patch.
[yazproxy-moved-to-github.git] / src / yaz-proxy-config.cpp
index cccfaf7..e6642a5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy-config.cpp,v 1.28 2006-04-06 01:20:02 adam Exp $
+/* $Id: yaz-proxy-config.cpp,v 1.33 2006-06-28 23:38:23 adam Exp $
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
@@ -55,6 +55,7 @@ class Yaz_ProxyConfigP {
     xmlNodePtr find_target_node(const char *name, const char *db);
     xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
     const char *get_text(xmlNodePtr ptr);
+    void get_period(xmlNodePtr ptr, int *period);
     int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
                                 Z_AttributeList *attrs,
                                 char **addinfo);
@@ -165,6 +166,18 @@ const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
         }
     return 0;
 }
+
+void Yaz_ProxyConfigP::get_period(xmlNodePtr ptr, int *period)
+{
+    struct _xmlAttr *attr;
+    *period = 60;
+    for (attr = ptr->properties; attr; attr = attr->next)
+    {
+        if (!strcmp((const char *) attr->name, "period") &&
+            attr->children && attr->children->type == XML_TEXT_NODE)
+            *period = atoi((const char *) attr->children->content);
+    }
+}
 #endif
 
 #if HAVE_XSLT
@@ -663,6 +676,44 @@ int Yaz_ProxyConfig::client_authentication(const char *name,
     return 1;
 }
 
+int Yaz_ProxyConfig::global_client_authentication(const char *user,
+                                                  const char *group,
+                                                  const char *password,
+                                                  const char *peer_IP)
+{
+    int ret = YAZPROXY_RET_NOT_ME;
+#if HAVE_XSLT
+    if (!m_cp->m_proxyPtr)
+        return 1;
+    xmlNodePtr ptr;
+    for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
+    {
+        if (ptr->type == XML_ELEMENT_NODE &&
+            !strcmp((const char *) ptr->name, "client-authentication"))
+        {
+            struct _xmlAttr *attr;
+            const char *module_name = 0;
+            for (attr = ptr->properties; attr; attr = attr->next)
+            {
+                if (!strcmp((const char *) attr->name, "module") &&
+                    attr->children && attr->children->type == XML_TEXT_NODE)
+                    module_name = (const char *) attr->children->content;
+            }
+            ret = m_cp->m_modules.authenticate(module_name,
+                                               NULL, ptr,
+                                               user, group, password,
+                                               peer_IP
+                );
+            if (ret != YAZPROXY_RET_NOT_ME)
+                break;
+        }
+    }
+#endif
+    if (ret == YAZPROXY_RET_PERM)
+        return 0;
+    return 1;
+}
+
 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
                                   Odr_oid *syntax, Z_RecordComposition *comp,
                                   char **addinfo,
@@ -1008,10 +1059,13 @@ int Yaz_ProxyConfig::get_file_access_info(const char *path)
 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
                                        int *max_clients,
                                        int *max_connect,
-                                       int *limit_connect)
+                                       int *limit_connect,
+                                       int *period_connect,
+                                       int *num_msg_threads)
 {
     *max_connect = 0;
     *limit_connect = 0;
+    *num_msg_threads = 0;
 #if HAVE_XSLT
     xmlNodePtr ptr;
     if (!m_cp->m_proxyPtr)
@@ -1037,6 +1091,8 @@ void Yaz_ProxyConfig::get_generic_info(int *log_mask,
                     *log_mask |= PROXY_LOG_REQ_CLIENT;
                 if (m_cp->mycmp(v, "server-requests", len))
                     *log_mask |= PROXY_LOG_REQ_SERVER;
+                if (m_cp->mycmp(v, "client-ip", len))
+                    *log_mask |= PROXY_LOG_IP_CLIENT;
                 if (isdigit(*v))
                     *log_mask |= atoi(v);
                 if (*cp == ',')
@@ -1058,18 +1114,29 @@ void Yaz_ProxyConfig::get_generic_info(int *log_mask,
             }
         }
         else if (ptr->type == XML_ELEMENT_NODE &&
+            !strcmp((const char *) ptr->name, "period-connect"))
+        {
+            const char *t = m_cp->get_text(ptr);
+            if (t)
+                *period_connect = atoi(t);
+        }
+        else if (ptr->type == XML_ELEMENT_NODE &&
             !strcmp((const char *) ptr->name, "max-connect"))
         {
             const char *t = m_cp->get_text(ptr);
             if (t)
+            {
                 *max_connect = atoi(t);
+            }
         }
         else if (ptr->type == XML_ELEMENT_NODE &&
             !strcmp((const char *) ptr->name, "limit-connect"))
         {
             const char *t = m_cp->get_text(ptr);
             if (t)
+            {
                 *limit_connect = atoi(t);
+            }
         }
         else if (ptr->type == XML_ELEMENT_NODE &&
             !strcmp((const char *) ptr->name, "target"))
@@ -1077,6 +1144,21 @@ void Yaz_ProxyConfig::get_generic_info(int *log_mask,
         else if (ptr->type == XML_ELEMENT_NODE &&
             !strcmp((const char *) ptr->name, "docpath"))
             ;
+        else if (ptr->type == XML_ELEMENT_NODE &&
+            !strcmp((const char *) ptr->name, "module"))
+            ;
+        else if (ptr->type == XML_ELEMENT_NODE &&
+            !strcmp((const char *) ptr->name, "client-authentication"))
+            ;
+        else if (ptr->type == XML_ELEMENT_NODE &&
+            !strcmp((const char *) ptr->name, "threads"))
+        {
+            const char *t = m_cp->get_text(ptr);
+            if (t)
+            {
+                *num_msg_threads = atoi(t);
+            }
+        }
         else if (ptr->type == XML_ELEMENT_NODE)
         {
             yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",