[Mod-auth-commit] mod_authn_pop3/src mod_authn_pop3.c,1.1,1.2
Brought to you by:
firechipmunk,
honx
From: <fir...@us...> - 2003-11-11 03:26:52
|
Update of /cvsroot/mod-auth/mod_authn_pop3/src In directory sc8-pr-cvs1:/tmp/cvs-serv23734/src Modified Files: mod_authn_pop3.c Log Message: converted pop3 auth to authn_pop3. should "work" for 2.1 authentication now. I also added a couple autoconf things that are the *correct* versions. I hate you autoconf. I hate you so very very much. Index: mod_authn_pop3.c =================================================================== RCS file: /cvsroot/mod-auth/mod_authn_pop3/src/mod_authn_pop3.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mod_authn_pop3.c 11 Nov 2003 02:57:31 -0000 1.1 --- mod_authn_pop3.c 11 Nov 2003 03:26:48 -0000 1.2 *************** *** 83,86 **** --- 83,87 ---- #include "http_protocol.h" #include "http_request.h" /* for ap_hook_(check_user_id | auth_checker)*/ + #include "mod_auth.h" *************** *** 88,95 **** char *serverhostname; int port; - int auth_popauthoritative; } pop_auth_config_rec; ! static void *create_pop_auth_dir_config(apr_pool_t *p, char *d) { pop_auth_config_rec *conf = apr_palloc(p, sizeof(*conf)); --- 89,95 ---- char *serverhostname; int port; } pop_auth_config_rec; ! static void *create_authn_pop3_dir_config(apr_pool_t *p, char *d) { pop_auth_config_rec *conf = apr_palloc(p, sizeof(*conf)); *************** *** 97,114 **** conf->serverhostname = NULL; conf->port = 110; - conf->auth_popauthoritative = 1; /* fortress is secure by default */ return conf; } - static const char *set_pop_slot(cmd_parms *cmd, void *offset, - const char *f, const char *t) - { - if (!t || strcmp(t, "pop")) - return DECLINE_CMD; - - return ap_set_file_slot(cmd, offset, f); - } - static const char *set_pop_hostname(cmd_parms *cmd, void *dir_config, --- 97,104 ---- *************** *** 132,189 **** ! static const command_rec pop_auth_cmds[] = { ! AP_INIT_TAKE1("AuthPOPHostname", set_pop_hostname, NULL, OR_AUTHCFG, "hostname for POP Server"), ! AP_INIT_TAKE1("AuthPOPPort", set_pop_port, NULL, OR_AUTHCFG, "port for POP Server"), - - AP_INIT_FLAG("AuthPOPAuthoritative", ap_set_flag_slot, - (void *)APR_OFFSETOF(pop_auth_config_rec, auth_popauthoritative), - OR_AUTHCFG, "Set to 'no' to allow access control to be passed along to lower modules, if the UserID is not known in this module"), {NULL} }; - typedef struct { - request_rec *r; - const char *cookiename; - char *cookie; - } cookie_res; - - - static int cookie_match( void *result, const char *key, const char *cook) - { - char *value; - cookie_res * cr = (cookie_res *) result; - - if (cook != NULL) { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, cr->r, "mod_auth_pop checking cookie <%s>", cook); - if ((value = strstr(cook, cr->cookiename))) { - char *cookiebuf, *cookieend; - value += strlen(cr->cookiename) + 1; /* Skip over the '=' */ - cookiebuf = apr_pstrdup(cr->r->pool, value); - cookieend = strchr(cookiebuf, ';'); - if (cookieend) - *cookieend = '\0'; /* Ignore anything after a ; */ - cr->cookie = cookiebuf; - return (0); - } - } - return (1); - - } - static char * find_our_cookie(request_rec *r, const char* cookiename) - { - cookie_res *cr = apr_palloc(r->pool, sizeof(cookie_res)); - cr->r = r; - cr->cookie = NULL; - cr->cookiename = cookiename; - apr_table_do(cookie_match, (void *) cr, r->headers_in, "Cookie", NULL); - return (cr->cookie); - } - - #define RECVLEN 200 static apr_status_t send_pop_command( request_rec *r, --- 122,136 ---- ! static const command_rec authn_pop3_cmds[] = { ! AP_INIT_TAKE1("AuthnPOP3Hostname", set_pop_hostname, NULL, OR_AUTHCFG, "hostname for POP Server"), ! AP_INIT_TAKE1("AuthnPOP3Port", set_pop_port, NULL, OR_AUTHCFG, "port for POP Server"), {NULL} }; #define RECVLEN 200 static apr_status_t send_pop_command( request_rec *r, *************** *** 215,218 **** --- 162,166 ---- } + static apr_status_t pop_auth( request_rec *r, *************** *** 242,246 **** return rv; } ! if (apr_socket_create(&sock, sockaddr->family, SOCK_STREAM, pool) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv , r, "apr_socket_create"); return rv; --- 190,194 ---- return rv; } ! if (apr_socket_create(&sock, sockaddr->family, SOCK_STREAM, 0, pool) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv , r, "apr_socket_create"); return rv; *************** *** 307,377 **** return APR_SUCCESS; } - module AP_MODULE_DECLARE_DATA pop_auth_module; ! static int pop_authenticate_basic_user(request_rec *r) { pop_auth_config_rec *conf = ap_get_module_config(r->per_dir_config, ! &pop_auth_module); ! const char *sent_pw; ! apr_status_t invalid_pw; ! apr_interval_time_t timeout = apr_time_from_sec(10); ! int res; ! char *cookie, *cookiename; ! char md5result[120]; ! ! if (!conf->serverhostname ) ! return DECLINED; ! ! if ((res = ap_get_basic_auth_pw(r, &sent_pw))) ! return res; ! ! apr_md5_encode( conf->serverhostname, "severname", md5result, sizeof(md5result)); ! ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, ! "MD5 hash %s %s ", md5result, conf->serverhostname); ! cookiename = apr_psprintf(r->pool, "pam_%s", md5result ); ! cookie = find_our_cookie(r,cookiename); ! invalid_pw = pop_auth( r, ! r->user, ! sent_pw, conf->serverhostname, conf->port, timeout); ! if (invalid_pw != APR_SUCCESS ) { ! if (!(conf->auth_popauthoritative)) ! return DECLINED; ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "POP user %s authentication failure for \"%s\": " "Password Mismatch", r->user, r->uri ); - ap_note_basic_auth_failure(r); - return HTTP_UNAUTHORIZED; } ! return OK; } - /* Checking ID */ ! static int pop_check_auth(request_rec *r) { ! return DECLINED; } static void register_hooks(apr_pool_t *p) { ! ap_hook_check_user_id(pop_authenticate_basic_user, NULL, NULL, ! APR_HOOK_MIDDLE); ! ap_hook_auth_checker(pop_check_auth, NULL, NULL, APR_HOOK_MIDDLE); } ! module AP_MODULE_DECLARE_DATA pop_auth_module = { STANDARD20_MODULE_STUFF, ! create_pop_auth_dir_config, /* dir config creater */ NULL, /* dir merger --- default is to override */ NULL, /* server config */ NULL, /* merge server config */ ! pop_auth_cmds, /* command apr_table_t */ register_hooks /* register hooks */ }; --- 255,319 ---- return APR_SUCCESS; } ! module AP_MODULE_DECLARE_DATA authn_pop3_module; ! ! static authn_status check_pop3_pw(request_rec * r, const char *user, ! const char *password) { + apr_status_t pop3_ret; pop_auth_config_rec *conf = ap_get_module_config(r->per_dir_config, ! &authn_pop3_module); ! int timeout = 20; ! pop3_ret = pop_auth( r, ! user, ! password, conf->serverhostname, conf->port, timeout); ! if (pop3_ret != APR_SUCCESS ) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "POP user %s authentication failure for \"%s\": " "Password Mismatch", r->user, r->uri ); } ! else { ! return AUTH_GRANTED; ! } ! ! return AUTH_DENIED; } ! static authn_status get_pop3_realm_hash(request_rec * r, const char *user, ! const char *realm, char **rethash) { ! ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, ! "[mod_authn_pop3.c] - Digest Authentication with authn_pop3 is not possible"); ! ! return AUTH_DENIED; } + static const authn_provider authn_pop3_provider = { + &check_pop3_pw, + &get_pop3_realm_hash + }; + static void register_hooks(apr_pool_t *p) { ! ap_register_provider(p, AUTHN_PROVIDER_GROUP, "pop3", "0", ! &authn_pop3_provider); ! } ! module AP_MODULE_DECLARE_DATA authn_pop3_module = { STANDARD20_MODULE_STUFF, ! create_authn_pop3_dir_config, /* dir config creater */ NULL, /* dir merger --- default is to override */ NULL, /* server config */ NULL, /* merge server config */ ! authn_pop3_cmds, /* command apr_table_t */ register_hooks /* register hooks */ }; |