Skip to content

Commit ed09efe

Browse files
committed
add public zone
1 parent 6e36961 commit ed09efe

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

mod_auth_memcookie.c

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ static apr_table_t *Auth_memCookie_get_session(request_rec *r, strAuth_memCookie
197197
char *szSeparator=", \t";
198198
int nbInfo=0;
199199

200+
/* check if libmemcached configuration are set */
201+
unless(conf->szAuth_memCookie_memCached_Configuration) {
202+
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, LOGTAG_PREFIX "No Auth_memCookie_memCached_Configuration specified");
203+
return NULL;
204+
}
205+
ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO, 0,r,LOGTAG_PREFIX "libmemcached configuration are %s",conf->szAuth_memCookie_memCached_Configuration);
206+
200207
/* init memcache lib */
201208
unless(memc=memcached(szMemcached_Configuration,strlen(szMemcached_Configuration))) {
202209
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, LOGTAG_PREFIX "memcache lib init failed");
@@ -224,7 +231,6 @@ static apr_table_t *Auth_memCookie_get_session(request_rec *r, strAuth_memCookie
224231
szTokenPos=NULL;
225232
for(szField=apr_strtok(szMyValue,"\r\n",&szTokenPos);szField;szField=apr_strtok(NULL,"\r\n",&szTokenPos)) {
226233
szFieldTokenPos=NULL;
227-
ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO, 0,r,LOGTAG_PREFIX "session field:'%s'",szField);
228234
szFieldName=apr_strtok(szField,"=",&szFieldTokenPos);
229235
szFieldValue=apr_strtok(NULL,"\r\n",&szFieldTokenPos);
230236
if (szFieldName!=NULL&&szFieldValue!=NULL) {
@@ -449,13 +455,6 @@ static int Auth_memCookie_check_cookie(request_rec *r)
449455
return Auth_memCookie_Return_Safe_Unauthorized(r);
450456
}
451457

452-
/* check if libmemcached configuration are set */
453-
unless(conf->szAuth_memCookie_memCached_Configuration) {
454-
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, LOGTAG_PREFIX "No Auth_memCookie_memCached_Configuration specified");
455-
return Auth_memCookie_Return_Safe_Unauthorized(r);
456-
}
457-
ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO, 0,r,LOGTAG_PREFIX "libmemcached configuration are %s",conf->szAuth_memCookie_memCached_Configuration);
458-
459458
/* get cookie named "szAuth_memCookie_CookieName" */
460459
unless(szCookieValue = extract_cookie(r, conf->szAuth_memCookie_CookieName))
461460
{
@@ -513,6 +512,49 @@ static int Auth_memCookie_check_cookie(request_rec *r)
513512

514513
#if MODULE_MAGIC_NUMBER_MAJOR > 20051115
515514

515+
static authz_status Auth_memCookie_public_authz_checker(request_rec *r, const char *require_args, const void *parsed_require_args) {
516+
517+
strAuth_memCookie_config_rec *conf=NULL;
518+
char *szMyUser=r->user;
519+
char *szCookieValue=NULL;
520+
521+
apr_table_t *pAuthSession=NULL;
522+
523+
ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO, 0,r,LOGTAG_PREFIX "Auth_memCookie_public_authz_checker in");
524+
if (!szMyUser) {
525+
526+
/* get apache config */
527+
conf = ap_get_module_config(r->per_dir_config, &mod_auth_memcookie_module);
528+
529+
/* check if the cookie name are set */
530+
unless(conf->szAuth_memCookie_CookieName) {
531+
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, LOGTAG_PREFIX "No Auth_memCookie_CookieName specified");
532+
return AUTHZ_GENERAL_ERROR;
533+
}
534+
535+
/* get cookie named "szAuth_memCookie_CookieName" */
536+
unless(szCookieValue = extract_cookie(r, conf->szAuth_memCookie_CookieName))
537+
{
538+
ap_log_rerror(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, 0, r, LOGTAG_PREFIX "cookie not found, continue !");
539+
return AUTHZ_NEUTRAL;
540+
}
541+
ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO, 0,r,LOGTAG_PREFIX "got cookie; value is %s", szCookieValue);
542+
543+
/* get session name "szCookieValue" from memcached */
544+
if((pAuthSession = Auth_memCookie_get_session(r, conf, szCookieValue))==NULL) {
545+
ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r, LOGTAG_PREFIX "AuthSession %s not found: %s", szCookieValue, r->filename);
546+
return AUTHZ_NEUTRAL;
547+
}
548+
549+
/* send http header of the session value to the backend */
550+
if (conf->nAuth_memCookie_SetSessionHTTPHeader) {
551+
ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, r, LOGTAG_PREFIX "nAuth_memCookie_SetSessionHTTPHeader is set then send http header...");
552+
apr_table_do(Auth_memCookie_DoSetHeader,r,pAuthSession,NULL);
553+
}
554+
555+
}
556+
return AUTHZ_NEUTRAL;
557+
}
516558
/**************************************************
517559
*
518560
* Auth_memCookie_check_auth
@@ -719,6 +761,11 @@ static const char *Auth_memCookie_authz_parse_config( cmd_parms *cmd, const char
719761
return NULL;
720762
}
721763

764+
static const authz_provider Auth_memCookie_authz_public_provider = {
765+
&Auth_memCookie_public_authz_checker,
766+
NULL,
767+
};
768+
722769
static const authz_provider Auth_memCookie_authz_group_provider = {
723770
&Auth_memCookie_group_authz_checker,
724771
&Auth_memCookie_authz_parse_config,
@@ -742,6 +789,11 @@ static void register_hooks(apr_pool_t *p)
742789
&Auth_memCookie_authz_group_provider,
743790
AP_AUTH_INTERNAL_PER_CONF);
744791

792+
ap_register_auth_provider(p, AUTHZ_PROVIDER_GROUP, "mcac-public",
793+
AUTHZ_PROVIDER_VERSION,
794+
&Auth_memCookie_authz_public_provider,
795+
AP_AUTH_INTERNAL_PER_CONF);
796+
745797
#else
746798
// apache 2.0 to 2.2 model
747799
ap_hook_check_user_id(Auth_memCookie_check_cookie, NULL, NULL, APR_HOOK_FIRST);

0 commit comments

Comments
 (0)