From 1e94296bc54fc9904caaac74089a44c801852360 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Sun, 8 Apr 2007 21:51:58 +0000 Subject: [PATCH] Added the most basic level of support for authentication. The setting 'pz:authentication' allows you to set an authentication token for a given target. This will allow support for targets which require one authentication token for all users.. it should also be a foundation for adding more fine-grained control. --- src/pazpar2.c | 23 +++++++++++++++++++---- src/settings.c | 3 ++- src/settings.h | 15 ++++++++------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/pazpar2.c b/src/pazpar2.c index 63966b1..9797eee 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.64 2007-04-08 20:52:09 quinn Exp $ */ +/* $Id: pazpar2.c,v 1.65 2007-04-08 21:51:58 quinn Exp $ */ #include #include @@ -48,7 +48,6 @@ static void client_fatal(struct client *cl); static void connection_destroy(struct connection *co); static int client_prep_connection(struct client *cl); static void ingest_records(struct client *cl, Z_Records *r); -//static struct conf_retrievalprofile *database_retrieval_profile(struct database *db); void session_alert_watch(struct session *s, int what); char *session_setting_oneval(struct session *s, struct database *db, int offset); @@ -119,6 +118,23 @@ static int send_apdu(struct client *c, Z_APDU *a) return 0; } +// Set authentication token in init if one is set for the client +// TODO: Extend this to handle other schemes than open (should be simple) +static void init_authentication(struct client *cl, Z_InitRequest *req) +{ + struct database *db = cl->database; + struct session *se = cl->session; + char *auth = session_setting_oneval(se, db, PZ_AUTHENTICATION); + + if (auth) + { + Z_IdAuthentication *idAuth = odr_malloc(global_parameters.odr_out, + sizeof(*idAuth)); + idAuth->which = Z_IdAuthentication_open; + idAuth->u.open = auth; + req->idAuthentication = idAuth; + } +} static void send_init(IOCHAN i) { @@ -139,6 +155,7 @@ static void send_init(IOCHAN i) ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_2); ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_3); + init_authentication(cl, a->u.initRequest); /* add virtual host if tunneling through Z39.50 proxy */ @@ -147,8 +164,6 @@ static void send_init(IOCHAN i) yaz_oi_set_string_oidval(&a->u.initRequest->otherInfo, global_parameters.odr_out, VAL_PROXY, 1, cl->database->url); - - if (send_apdu(cl, a) >= 0) { diff --git a/src/settings.c b/src/settings.c index c5f1b2e..dedda87 100644 --- a/src/settings.c +++ b/src/settings.c @@ -1,4 +1,4 @@ -// $Id: settings.c,v 1.7 2007-04-08 20:52:09 quinn Exp $ +// $Id: settings.c,v 1.8 2007-04-08 21:51:58 quinn Exp $ // This module implements a generic system of settings (attribute-value) that can // be associated with search targets. The system supports both default values, // per-target overrides, and per-user settings. @@ -31,6 +31,7 @@ static char *hard_settings[] = { "pz:encoding", "pz:xslt", "pz:nativesyntax", + "pz:authentication", 0 }; diff --git a/src/settings.h b/src/settings.h index 2a90c40..5c13528 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,13 +1,14 @@ #ifndef SETTINGS_H #define SETTINGS_H -#define PZ_PIGGYBACK 0 -#define PZ_ELEMENTS 1 -#define PZ_SYNTAX 2 -#define PZ_CCLMAP 3 -#define PZ_ENCODING 4 -#define PZ_XSLT 5 -#define PZ_NATIVESYNTAX 6 +#define PZ_PIGGYBACK 0 +#define PZ_ELEMENTS 1 +#define PZ_SYNTAX 2 +#define PZ_CCLMAP 3 +#define PZ_ENCODING 4 +#define PZ_XSLT 5 +#define PZ_NATIVESYNTAX 6 +#define PZ_AUTHENTICATION 7 struct setting { -- 1.7.10.4