From 676640cef321916c94661bd53749130d86555bb9 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sat, 23 Oct 2004 23:12:23 +0000 Subject: [PATCH] Fixed bug #189: Bad authenticated session transfer. New config element "authentication" which specifies authentication (Open v2/v3 Z39.50) to be used for backend. --- NEWS | 8 +++++-- etc/config.xml | 59 +++++++--------------------------------------- etc/yazproxy.xsd | 4 +++- include/yazproxy/proxy.h | 8 ++++--- src/yaz-proxy-config.cpp | 25 ++++++++++++++------ src/yaz-proxy.cpp | 31 +++++++++++++++++------- 6 files changed, 62 insertions(+), 73 deletions(-) diff --git a/NEWS b/NEWS index 4c7ca70..d1e2c3d 100644 --- a/NEWS +++ b/NEWS @@ -1,10 +1,14 @@ +Fixed bug #189: Bad authenticated session transfer. -New attribute "backendcharset" for syntax section which specifies +New config element "authentication" which specifies authentication +(Open v2/v3 Z39.50) to be used for backend. + +New config attribute "backendcharset" for syntax element which specifies charset (encoding) for record that is returned by backend. If omitted the proxy assumes backend record encoding is MARC-8 (for backwards compatibility). -New attribute "backendtype" for syntax section which specifies +New config attribute "backendtype" for syntax element which specifies record syntax to be transmitted to backend. This allows proxy to offer a record syntax different from that offered by backend. diff --git a/etc/config.xml b/etc/config.xml index d620a3f..6bc751c 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -1,14 +1,14 @@ - + - - indexdata.dk - 240 - 180 + + localhost:9999 + 30 + 60 1000000 1000 @@ -34,54 +34,11 @@ pqf.properties - - - localhost:9999 - 300 - 180 - - - 50000 - 60 - 50 - - - - - - - dc - - - marcxml - - - mods2 - - - mods3 - - - - 2 - - - localhost - 9000 - Default - - - pqf.properties + adam/x + 60 + 30 50 diff --git a/etc/yazproxy.xsd b/etc/yazproxy.xsd index 14ef66a..531a339 100644 --- a/etc/yazproxy.xsd +++ b/etc/yazproxy.xsd @@ -1,6 +1,6 @@ + @@ -48,6 +49,7 @@ + diff --git a/include/yazproxy/proxy.h b/include/yazproxy/proxy.h index 542ec8a..c9c64ee 100644 --- a/include/yazproxy/proxy.h +++ b/include/yazproxy/proxy.h @@ -1,4 +1,4 @@ -/* $Id: proxy.h,v 1.7 2004-10-18 22:10:57 adam Exp $ +/* $Id: proxy.h,v 1.8 2004-10-23 23:12:24 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. @@ -56,7 +56,8 @@ public: int *keepalive_limit_bw, int *keepalive_limit_pdu, int *pre_init, - const char **cql2rpn); + const char **cql2rpn, + const char **authentication); void get_generic_info(int *log_mask, int *max_clients); @@ -66,7 +67,8 @@ public: int *max_clients, int *keepalive_limit_bw, int *keepalive_limit_pdu, int *pre_init, - const char **cql2rpn); + const char **cql2rpn, + const char **authentication); int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo); int check_syntax(ODR odr, const char *name, diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index 21497ec..0486e73 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy-config.cpp,v 1.7 2004-10-18 22:10:57 adam Exp $ +/* $Id: yaz-proxy-config.cpp,v 1.8 2004-10-23 23:12:24 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. @@ -47,7 +47,8 @@ class Yaz_ProxyConfigP { int *limit_bw, int *limit_pdu, int *limit_req, int *target_idletime, int *client_idletime, int *keepalive_limit_bw, int *keepalive_limit_pdu, - int *pre_init, const char **cql2rpn); + int *pre_init, const char **cql2rpn, + const char **authentication); void return_limit(xmlNodePtr ptr, int *limit_bw, int *limit_pdu, int *limit_req); int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query, @@ -176,7 +177,8 @@ void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr, int *keepalive_limit_bw, int *keepalive_limit_pdu, int *pre_init, - const char **cql2rpn) + const char **cql2rpn, + const char **authentication) { *pre_init = 0; int no_url = 0; @@ -240,6 +242,13 @@ void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr, if (t) *cql2rpn = t; } + if (ptr->type == XML_ELEMENT_NODE + && !strcmp((const char *) ptr->name, "authentication")) + { + const char *t = get_text(ptr); + if (t) + *authentication = t; + } } } #endif @@ -680,7 +689,8 @@ int Yaz_ProxyConfig::get_target_no(int no, int *keepalive_limit_bw, int *keepalive_limit_pdu, int *pre_init, - const char **cql2rpn) + const char **cql2rpn, + const char **authentication) { #if HAVE_XSLT xmlNodePtr ptr; @@ -707,7 +717,7 @@ int Yaz_ProxyConfig::get_target_no(int no, limit_bw, limit_pdu, limit_req, target_idletime, client_idletime, keepalive_limit_bw, keepalive_limit_pdu, - pre_init, cql2rpn); + pre_init, cql2rpn, authentication); return 1; } i++; @@ -904,7 +914,8 @@ void Yaz_ProxyConfig::get_target_info(const char *name, int *keepalive_limit_bw, int *keepalive_limit_pdu, int *pre_init, - const char **cql2rpn) + const char **cql2rpn, + const char **authentication) { #if HAVE_XSLT xmlNodePtr ptr; @@ -940,7 +951,7 @@ void Yaz_ProxyConfig::get_target_info(const char *name, m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req, target_idletime, client_idletime, keepalive_limit_bw, keepalive_limit_pdu, - pre_init, cql2rpn); + pre_init, cql2rpn, authentication); } #else *url = name; diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 68defcb..66d7da9 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy.cpp,v 1.9 2004-10-20 20:35:33 adam Exp $ +/* $Id: yaz-proxy.cpp,v 1.10 2004-10-23 23:12:24 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. @@ -395,6 +395,7 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie, proxy_host = m_default_target; int client_idletime = -1; const char *cql2rpn_fname = 0; + const char *authentication = 0; url[0] = m_default_target; url[1] = 0; if (cfg) @@ -407,7 +408,8 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie, &m_keepalive_limit_bw, &m_keepalive_limit_pdu, &pre_init, - &cql2rpn_fname); + &cql2rpn_fname, + &authentication); } if (client_idletime != -1) { @@ -416,6 +418,8 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie, } if (cql2rpn_fname) m_cql2rpn.set_pqf_file(cql2rpn_fname); + if (authentication) + set_proxy_authentication(authentication); if (!url[0]) { yaz_log(LOG_LOG, "%sNo default target", m_session_str); @@ -473,15 +477,17 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie, } } } - else if (!c) + else if (!c && apdu->which == Z_APDU_initRequest + && apdu->u.initRequest->idAuthentication == 0) { - // don't have a client session yet. Search in session w/o cookie + // anonymous sessions without cookie. + // if authentication is set it is NOT anonymous se we can't share them. for (c = parent->m_clientPool; c; c = c->m_next) { - assert (c->m_prev); - assert (*c->m_prev == c); + assert(c->m_prev); + assert(*c->m_prev == c); if (c->m_server == 0 && c->m_cookie == 0 && - c->m_waiting == 0 && + c->m_waiting == 0 && !strcmp(m_proxyTarget, c->get_hostname())) { // found it in cache @@ -528,6 +534,12 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie, odr_strdup (odr_encode(), m_proxy_authentication); } } + else + { + // the client use authentication. We set the keepalive PDU + // to 0 so we don't cache it in releaseClient + m_keepalive_limit_pdu = 0; + } // go through list of clients - and find the lowest/oldest one. Yaz_ProxyClient *c_min = 0; int min_seq = -1; @@ -2291,7 +2303,6 @@ void Yaz_Proxy::releaseClient() assert (m_client->m_waiting != 2); // Tell client (if any) that no server connection is there.. m_client->m_server = 0; - m_invalid_session = 0; m_client = 0; } else if (m_client) @@ -2423,6 +2434,7 @@ void Yaz_Proxy::pre_init() int keepalive_limit_bw, keepalive_limit_pdu; int pre_init; const char *cql2rpn = 0; + const char *authentication = 0; Yaz_ProxyConfig *cfg = check_reconfigure(); @@ -2440,7 +2452,8 @@ void Yaz_Proxy::pre_init() &keepalive_limit_bw, &keepalive_limit_pdu, &pre_init, - &cql2rpn) ; i++) + &cql2rpn, + &authentication) ; i++) { if (pre_init) { -- 1.7.10.4