From eed96190637564acc890b7b13055e34845445f6b Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sat, 22 Apr 2006 18:22:41 +0000 Subject: [PATCH] Make auth handers receive connection info --- src/configfile.c | 4 ++-- src/configfile.h | 2 +- src/dispatch.c | 2 +- src/dispatch.h | 2 +- src/main.c | 1 + src/plugin.h | 2 ++ src/webserver.c | 16 ++++++++-------- src/webserver.h | 4 ++-- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/configfile.c b/src/configfile.c index a28b63b9..342a8433 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -352,12 +352,12 @@ void config_handler(WS_CONNINFO *pwsc) { * \param user username passed in the auth request * \param password password passed in the auth request */ -int config_auth(char *hostname, char *user, char *password) { +int config_auth(WS_CONNINFO *pwsc, char *user, char *password) { char *adminpassword; int res; #ifdef WIN32 - if((hostname) && (os_islocaladdr(hostname))) + if((pwsc->hostname) && (os_islocaladdr(pwsc->hostname))) return TRUE; #endif diff --git a/src/configfile.h b/src/configfile.h index f1281ed5..55e576d5 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -25,7 +25,7 @@ #include "daapd.h" #include "webserver.h" -extern int config_auth(char *hostname, char *user, char *password); +extern int config_auth(WS_CONNINFO *pwsc, char *user, char *password); extern void config_handler(WS_CONNINFO *pwsc); extern void config_set_status(WS_CONNINFO *pwsc, int session, char *fmt, ...); extern int config_get_session_count(void); diff --git a/src/dispatch.c b/src/dispatch.c index f8550f16..4fb4304e 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -127,7 +127,7 @@ void dispatch_cleanup(DBQUERYINFO *pqi) { * @param password The password passed by iTunes * @returns 1 if auth successful, 0 otherwise */ -int daap_auth(char *hostname, char *username, char *password) { +int daap_auth(WS_CONNINFO *pwsc, char *username, char *password) { char *readpassword; readpassword = conf_alloc_string("general","password",NULL); diff --git a/src/dispatch.h b/src/dispatch.h index 07b10b48..17f74c49 100644 --- a/src/dispatch.h +++ b/src/dispatch.h @@ -8,7 +8,7 @@ #include "db-generic.h" extern void daap_handler(WS_CONNINFO *pwsc); -extern int daap_auth(char *hostname, char *username, char *password); +extern int daap_auth(WS_CONNINFO *pwsc, char *username, char *password); extern void dispatch_stream_id(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, char *id); #endif diff --git a/src/main.c b/src/main.c index ad5a8599..c1b0081b 100644 --- a/src/main.c +++ b/src/main.c @@ -316,6 +316,7 @@ int main(int argc, char *argv[]) { /* load plugins before we drop privs? Maybe... let the * plugins do stuff they might need to */ + plugin_init(); if((plugindir=conf_alloc_string("plugins","plugin_dir",NULL)) != NULL) { if(conf_get_array("plugins","plugins",&pluginarray)==TRUE) { index = 0; diff --git a/src/plugin.h b/src/plugin.h index a2fce0b9..4ef84801 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -24,7 +24,9 @@ #include "webserver.h" +extern int plugin_init(void); extern int plugin_load(char **pe, char *path); +extern int plugin_deinit(void); /* Interfaces for web */ extern int plugin_url_candispatch(WS_CONNINFO *pwsc); diff --git a/src/webserver.c b/src/webserver.c index 3ea1bcb6..18a3caf6 100644 --- a/src/webserver.c +++ b/src/webserver.c @@ -64,7 +64,7 @@ typedef struct tag_ws_handler { regex_t regex; void (*req_handler)(WS_CONNINFO*); - int(*auth_handler)(char *, char *, char *); + int(*auth_handler)(WS_CONNINFO*, char *, char *); int addheaders; struct tag_ws_handler *next; } WS_HANDLER; @@ -107,11 +107,11 @@ char *ws_getarg(ARGLIST *root, char *key); int ws_testarg(ARGLIST *root, char *key, char *value); int ws_findhandler(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc, void(**preq)(WS_CONNINFO*), - int(**pauth)(char *, char *, char *), + int(**pauth)(WS_CONNINFO*, char *, char *), int *addheaders); int ws_registerhandler(WSHANDLE ws, char *regex, void(*handler)(WS_CONNINFO*), - int(*auth)(char *, char *, char *), + int(*auth)(WS_CONNINFO*, char *, char *), int addheaders); int ws_decodepassword(char *header, char **username, char **password); int ws_testrequestheader(WS_CONNINFO *pwsc, char *header, char *value); @@ -766,7 +766,7 @@ void *ws_dispatcher(void *arg) { time_t now; struct tm now_tm; void (*req_handler)(WS_CONNINFO*); - int(*auth_handler)(char *, char *, char *); + int(*auth_handler)(WS_CONNINFO*, char *, char *); DPRINTF(E_DBG,L_WS,"Thread %d: Entering ws_dispatcher (Connection from %s)\n", pwsc->threadno, pwsc->hostname); @@ -933,12 +933,12 @@ void *ws_dispatcher(void *arg) { * username and password of NULL, then don't bother * authing. */ - if((auth_handler) && (auth_handler(pwsc->hostname,NULL,NULL)==0)) { + if((auth_handler) && (auth_handler(pwsc,NULL,NULL)==0)) { /* do the auth thing */ auth=ws_getarg(&pwsc->request_headers,"Authorization"); if(auth) { ws_decodepassword(auth,&username,&password); - if(auth_handler(pwsc->hostname,username,password)) + if(auth_handler(pwsc,username,password)) can_dispatch=1; ws_addarg(&pwsc->request_vars,"HTTP_USER",username); ws_addarg(&pwsc->request_vars,"HTTP_PASSWD",password); @@ -1320,7 +1320,7 @@ char *ws_urldecode(char *string, int space_as_plus) { */ int ws_registerhandler(WSHANDLE ws, char *regex, void(*handler)(WS_CONNINFO*), - int(*auth)(char *, char *, char *), + int(*auth)(WS_CONNINFO *, char *, char *), int addheaders) { WS_HANDLER *phandler; WS_PRIVATE *pwsp = (WS_PRIVATE *)ws; @@ -1357,7 +1357,7 @@ int ws_registerhandler(WSHANDLE ws, char *regex, */ int ws_findhandler(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc, void(**preq)(WS_CONNINFO*), - int(**pauth)(char *, char *, char *), + int(**pauth)(WS_CONNINFO *, char *, char *), int *addheaders) { WS_HANDLER *phandler=pwsp->handlers.next; diff --git a/src/webserver.h b/src/webserver.h index ac9d8e53..e39510eb 100644 --- a/src/webserver.h +++ b/src/webserver.h @@ -70,13 +70,13 @@ typedef struct tag_ws_conninfo { */ #define WS_REQ_HANDLER void (*)(WS_CONNINFO *) -#define WS_AUTH_HANDLER int (*)(char *, char *, char *) +#define WS_AUTH_HANDLER int (*)(WS_CONNINFO*, char *, char *) extern WSHANDLE ws_start(WSCONFIG *config); extern int ws_stop(WSHANDLE ws); extern int ws_registerhandler(WSHANDLE ws, char *regex, void(*handler)(WS_CONNINFO*), - int(*auth)(char *, char *, char *), + int(*auth)(WS_CONNINFO*, char *, char *), int addheaders); extern void ws_lock_local_storage(WS_CONNINFO *pwsc);