Convert session user name to dynamic size storage

Using the previously introduced storage facility convert storage of the
user name from being constrained to fixed sized strings to being
constrained only by the overall entry cache size.

Signed-off-by: Simo Sorce <simo@redhat.com>

git-svn-id: https://modmellon.googlecode.com/svn/trunk@236 a716ebb1-153a-0410-b759-cfb97c6a1b53
This commit is contained in:
olavmrk 2014-06-20 11:25:28 +00:00
parent 5ad49a4c84
commit 519f22493e
3 changed files with 30 additions and 10 deletions

View File

@ -22,6 +22,8 @@
#ifndef MOD_AUTH_MELLON_H
#define MOD_AUTH_MELLON_H
#include <stdbool.h>
#include <lasso/lasso.h>
#include <lasso/xml/saml-2.0/samlp2_authn_request.h>
#include <lasso/xml/saml-2.0/samlp2_logout_request.h>
@ -255,7 +257,7 @@ typedef struct am_cache_entry_t {
apr_time_t expires;
int logged_in;
unsigned short size;
char user[AM_CACHE_USERSIZE];
am_cache_storage_t user;
/* Variables used to store lasso state between login requests
*and logout requests.

View File

@ -111,6 +111,11 @@ am_cache_entry_t *am_cache_lock(server_rec *s,
return NULL;
}
static inline bool am_cache_entry_slot_is_empty(am_cache_storage_t *slot)
{
return (slot->ptr == 0);
}
static inline void am_cache_storage_null(am_cache_storage_t *slot)
{
slot->ptr = 0;
@ -318,8 +323,8 @@ am_cache_entry_t *am_cache_new(server_rec *s, const char *key)
t->logged_in = 0;
t->size = 0;
t->user[0] = '\0';
am_cache_storage_null(&t->user);
am_cache_storage_null(&t->lasso_identity);
am_cache_storage_null(&t->lasso_session);
am_cache_storage_null(&t->lasso_saml_response);
@ -471,17 +476,24 @@ void am_cache_env_populate(request_rec *r, am_cache_entry_t *t)
const char *varname_prefix;
const char *value;
int *count;
int status;
d = am_get_dir_cfg(r);
/* Check if the user attribute has been set, and set it if it
* hasn't been set. */
if(t->user[0] == '\0') {
if (am_cache_entry_slot_is_empty(&t->user)) {
for(i = 0; i < t->size; ++i) {
varname = am_cache_entry_get_string(t, &t->env[i].varname);
if (strcmp(varname, d->userattr) == 0) {
value = am_cache_entry_get_string(t, &t->env[i].value);
strcpy(t->user, value);
status = am_cache_entry_store_string(t, &t->user, value);
if (status != 0) {
ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r,
"Unable to store the user name because there"
" is no more space in the session. "
"Username = \"%s\".", value);
}
}
}
}
@ -512,8 +524,16 @@ void am_cache_env_populate(request_rec *r, am_cache_entry_t *t)
/*
* If we find a variable remapping to MellonUser, use it.
*/
if ((t->user[0] == '\0') && (strcmp(varname, d->userattr) == 0))
strcpy(t->user, value);
if (am_cache_entry_slot_is_empty(&t->user) &&
(strcmp(varname, d->userattr) == 0)) {
status = am_cache_entry_store_string(t, &t->user, value);
if (status != 0) {
ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r,
"Unable to store the user name because there"
" is no more space in the session. "
"Username = \"%s\".", value);
}
}
/* Find the number of times this variable has been set. */
count = apr_hash_get(counters, varname, APR_HASH_KEY_STRING);
@ -541,9 +561,9 @@ void am_cache_env_populate(request_rec *r, am_cache_entry_t *t)
++(*count);
}
if(t->user[0] != '\0') {
if (!am_cache_entry_slot_is_empty(&t->user)) {
/* We have a user-"name". Set r->user and r->ap_auth_type. */
r->user = apr_pstrdup(r->pool, t->user);
r->user = apr_pstrdup(r->pool, am_cache_entry_get_string(t, &t->user));
r->ap_auth_type = apr_pstrdup(r->pool, "Mellon");
} else {
/* We don't have a user-"name". Log error. */

View File

@ -19,8 +19,6 @@
*
*/
#include <stdbool.h>
#include "auth_mellon.h"
/* This is the default endpoint path. Remember to update the description of