Bump version to 1.3.3.1
[yazproxy-moved-to-github.git] / src / mod_helsinki.cpp
index 5558c87..150e9ab 100644 (file)
@@ -1,7 +1,5 @@
-/* $Id: mod_helsinki.cpp,v 1.1 2006-03-25 10:56:28 adam Exp $
-   Copyright (c) 1998-2005, Index Data.
-
-This file is part of the yaz-proxy.
+/* This file is part of YAZ proxy
+   Copyright (C) 1998-2008 Index Data
 
 YAZ proxy is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
 
 YAZ proxy is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -14,10 +12,9 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with YAZ proxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
 
 #include <string.h>
 #include <stdio.h>
 
 #include <string.h>
 #include <stdio.h>
@@ -29,7 +26,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include <time.h>
 
 
 #include <time.h>
 
-#if HAVE_XSLT
+#if YAZ_HAVE_XSLT
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <libxml/xinclude.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <libxml/xinclude.h>
@@ -125,7 +122,7 @@ int my_authenticate(void *user_handle,
 {
     // see if we have an "args" attribute
     const char *args = 0;
 {
     // see if we have an "args" attribute
     const char *args = 0;
-#if HAVE_XSLT
+#if YAZ_HAVE_XSLT
     xmlNodePtr ptr = (xmlNodePtr) element_ptr;
     struct _xmlAttr *attr;
 
     xmlNodePtr ptr = (xmlNodePtr) element_ptr;
     struct _xmlAttr *attr;
 
@@ -138,7 +135,7 @@ int my_authenticate(void *user_handle,
 #endif
     // args holds args (or NULL if none are provided)
 
 #endif
     // args holds args (or NULL if none are provided)
 
-    yaz_log(YLOG_LOG, "Authentication: authenticating user %s, address %s", user ? user : "-", peer_IP ? peer_IP : "-");
+    yaz_log(YLOG_LOG, "Authentication: authenticating user %s, address %s", user ? user : "(none)", peer_IP ? peer_IP : "-");
 
     // authentication handler
     char user_file[255], ip_file[255];
 
     // authentication handler
     char user_file[255], ip_file[255];
@@ -146,7 +143,7 @@ int my_authenticate(void *user_handle,
     *ip_file = '\0';
     sscanf(args, "%254[^:]:%254s", user_file, ip_file);
 
     *ip_file = '\0';
     sscanf(args, "%254[^:]:%254s", user_file, ip_file);
 
-    yaz_log(YLOG_LOG, "Authentication: user file: %s, ip file: %s", user_file, ip_file);
+    yaz_log(YLOG_DEBUG, "Authentication: user file: %s, ip file: %s", user_file, ip_file);
 
     // Check if the IP address is listed in the file of allowed address ranges.
     // The format of the file:
 
     // Check if the IP address is listed in the file of allowed address ranges.
     // The format of the file:
@@ -154,13 +151,15 @@ int my_authenticate(void *user_handle,
     // 192.168.0.100
     // 192.168.0.1-192.168.0.200
     int status = YAZPROXY_RET_PERM;
     // 192.168.0.100
     // 192.168.0.1-192.168.0.200
     int status = YAZPROXY_RET_PERM;
-    if (ip_file && peer_IP)
+    if (*ip_file && peer_IP)
     {
     {
-        yaz_log(YLOG_LOG, "Authentication: checking ip address");
+        yaz_log(YLOG_DEBUG, "Authentication: checking ip address");
 
         const char *pIP = peer_IP;
         if (strncmp(pIP, "tcp:", 4) == 0)
             pIP += 4;
 
         const char *pIP = peer_IP;
         if (strncmp(pIP, "tcp:", 4) == 0)
             pIP += 4;
+        if (strncmp(pIP, "::ffff:", 7) == 0)
+            pIP += 7;
         IP_ADDRESS peer_address;
         if (str_to_address(pIP, &peer_address) != 4)
             yaz_log(YLOG_WARN, "Authentication: could not decode peer IP address %s properly", pIP);
         IP_ADDRESS peer_address;
         if (str_to_address(pIP, &peer_address) != 4)
             yaz_log(YLOG_WARN, "Authentication: could not decode peer IP address %s properly", pIP);
@@ -202,7 +201,7 @@ int my_authenticate(void *user_handle,
 
     if (!user || !password || !*user_file)
     {
 
     if (!user || !password || !*user_file)
     {
-        yaz_log(YLOG_WARN, "Authentication: no user name, password or user file specified");
+        yaz_log(YLOG_LOG, "Authentication: anonymous authentication failed");
             return YAZPROXY_RET_PERM;
     }
 
             return YAZPROXY_RET_PERM;
     }