X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fyaz-proxy.cpp;h=4400bbbe85386d242a4a6b9a2199b291c5f22b1a;hb=88c7aa0e04fa66088304eafdf76e8efbb0658467;hp=e97946a12597b633f263d5c45d240a374a8a1158;hpb=d6baec0e7369dd5d01a2998efb3667e3deff6db2;p=yazproxy-moved-to-github.git diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index e97946a..4400bbb 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy.cpp,v 1.20 2005-02-10 08:09:42 oleg Exp $ +/* $Id: yaz-proxy.cpp,v 1.22 2005-02-11 15:19:08 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -249,11 +249,12 @@ void Yaz_Proxy::set_proxy_authentication (const char *auth) if (auth) m_proxy_authentication = (char *) xstrdup (auth); } + void Yaz_Proxy::set_proxy_negotiation (const char *charset, const char *lang) { - yaz_log(YLOG_LOG, "%sSet the proxy negotiation: charset to '%s', - language to '%s'", m_session_str, (charset)?charset:"none", - (lang)?lang:"none"); + yaz_log(YLOG_LOG, "%sSet the proxy negotiation: charset to '%s', " + "language to '%s'", m_session_str, charset?charset:"none", + lang?lang:"none"); xfree (m_proxy_negotiation_charset); xfree (m_proxy_negotiation_lang); m_proxy_negotiation_charset = m_proxy_negotiation_lang = 0; @@ -262,6 +263,7 @@ void Yaz_Proxy::set_proxy_negotiation (const char *charset, const char *lang) if (lang) m_proxy_negotiation_lang = (char *) xstrdup (lang); } + Yaz_ProxyConfig *Yaz_Proxy::check_reconfigure() { if (m_parent) @@ -1667,7 +1669,6 @@ void Yaz_Proxy::handle_charset_lang_negotiation(Z_APDU *apdu) { Z_InitResponse *initResponse = apdu->u.initResponse; Z_OtherInformation **otherInfo; - Z_OtherInformationUnit *oi; if (ODR_MASK_GET(initResponse->options, Z_Options_negotiationModel)) { @@ -1836,6 +1837,41 @@ Z_APDU *Yaz_Proxy::handle_query_validation(Z_APDU *apdu) return apdu; } +int Yaz_Proxy::handle_authentication(Z_APDU *apdu) +{ + if (apdu->which != Z_APDU_initRequest) + return 1; // pass if no init request + Z_InitRequest *req = apdu->u.initRequest; + + Yaz_ProxyConfig *cfg = check_reconfigure(); + if (!cfg) + return 1; // pass if no config + + int ret; + if (req->idAuthentication == 0) + { + ret = cfg->check_authentication(0, 0, 0); + } + else if (req->idAuthentication->which == Z_IdAuthentication_idPass) + { + ret = cfg->check_authentication( + req->idAuthentication->u.idPass->userId, + req->idAuthentication->u.idPass->groupId, + req->idAuthentication->u.idPass->password); + } + else if (req->idAuthentication->which == Z_IdAuthentication_open) + { + char user[64], pass[64]; + *user = '\0'; + *pass = '\0'; + sscanf(req->idAuthentication->u.open, "%63[^/]/%63s", user, pass); + ret = cfg->check_authentication(user, 0, pass); + } + else + ret = cfg->check_authentication(0, 0, 0); + return ret; +} + Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) { m_marcxml_flag = 0; @@ -2563,6 +2599,17 @@ void Yaz_Proxy::handle_incoming_Z_PDU(Z_APDU *apdu) } m_client->m_init_flag = 1; } + + if (!handle_authentication(apdu)) + { + Z_APDU *apdu_reject = zget_APDU(odr_encode(), Z_APDU_initResponse); + *apdu_reject->u.initResponse->result = 0; + send_to_client(apdu_reject); + + shutdown(); + return; + } + handle_max_record_retrieve(apdu); if (apdu)