Update of /cvsroot/mod-auth/mod_authn_cache/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1505
Modified Files:
mod_authn_cache.c
Removed Files:
mod_authn_cache.h
Log Message:
move it back to a framework
Index: mod_authn_cache.c
===================================================================
RCS file: /cvsroot/mod-auth/mod_authn_cache/src/mod_authn_cache.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mod_authn_cache.c 6 Jan 2004 01:31:01 -0000 1.7
+++ mod_authn_cache.c 8 Feb 2004 22:48:48 -0000 1.8
@@ -1,353 +1,42 @@
/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact ap...@ap....
+ * Copyright 2003-2004 Paul Querna
*
- * 5. Products derived from this software may not be called "Apache",
- * nor may "Apache" appear in their name, without prior written
- * permission of the Apache Software Foundation.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*
- * Portions of this software are based upon public domain software
- * originally written at the National Center for Supercomputing Applications,
- * University of Illinois, Urbana-Champaign.
*/
/*
* mod_authn_cache
- *
- * Paul Querna
+ *
*/
#include "apr_lib.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "apr_strings.h"
-#include "apr_md5.h"
-#include "apr_sha1.h"
-#include "apr_reslist.h"
-#include "apr_thread_mutex.h"
-#include "apr_hash.h"
-#include "apr_shm.h"
-
#include "ap_provider.h"
+
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_request.h"
-#include "mod_auth.h"
-
-#include "util_md5.h"
-#define DFLT_HOSTNAME "localhost"
-#define DFLT_PORT (8008)
-#define DFLT_CONN_MIN (10)
-#define DFLT_CONN_SOFT (15)
-#define DFLT_CONN_MAX (25)
-#define DFLT_CONN_TTL (600)
-#define DFLT_TIMEOUT (6)
-#define DFLT_OPTIONS (0)
-
-static int mcd_conn_count = 0;
-static apr_reslist_t *reslist_pool;
+#include "mod_auth.h"
module AP_MODULE_DECLARE_DATA authn_cache_module;
-typedef struct mcd_rest_struct
-{
- apr_sockaddr_t *sockaddr;
- apr_socket_t *sock;
- apr_bucket_alloc_t *bb_l;
- apr_bucket_brigade *bb;
- apr_pool_t* pool;
-
-} mcd_res_t;
-
-
-static apr_status_t mcd_new_conn(void **resource, void *params, apr_pool_t * pool)
-{
- apr_status_t rv = APR_SUCCESS;
- mcd_res_t *mcdres;
- apr_bucket *e;
-
- mcdres = apr_palloc(pool, sizeof(*mcdres));
-
- rv = apr_sockaddr_info_get(&mcdres->sockaddr, DFLT_HOSTNAME, APR_UNSPEC, DFLT_PORT, 0, pool);
- if (rv != APR_SUCCESS) {
- ap_log_perror(APLOG_MARK, APLOG_ERR, rv, pool, "apr_sockaddr_info_get");
- return rv;
- }
- if (apr_socket_create_ex(&mcdres->sock, mcdres->sockaddr->family, SOCK_STREAM, 0,
- pool) != APR_SUCCESS) {
- ap_log_perror(APLOG_MARK, APLOG_ERR, rv, pool, "apr_socket_create");
- return rv;
- }
-
- rv = apr_socket_timeout_set(mcdres->sock, DFLT_TIMEOUT);
- if (rv != APR_SUCCESS) {
- ap_log_perror(APLOG_MARK, APLOG_ERR, rv, pool, "apr_socket_timeout_set");
- return rv;
- }
-
- rv = apr_socket_connect(mcdres->sock, mcdres->sockaddr);
- if (rv != APR_SUCCESS) {
- ap_log_perror(APLOG_MARK, APLOG_ERR, rv, pool, "apr_socket_connect");
- return rv;
- }
-
- mcdres->bb_l = apr_bucket_alloc_create(pool);
- mcdres->bb = apr_brigade_create(pool, mcdres->bb_l);
- e = apr_bucket_socket_create(mcdres->sock, mcdres->bb_l);
- APR_BRIGADE_INSERT_TAIL(mcdres->bb, e);
- mcdres->pool = pool;
- *resource = mcdres;
- return rv;
-}
-
-static apr_status_t mcd_kill_conn(void *resource, void *params, apr_pool_t * pool)
-{
- apr_status_t rv = APR_SUCCESS;
- mcd_res_t *mcd = resource;
-
- apr_brigade_destroy(mcd->bb);
- apr_bucket_alloc_destroy(mcd->bb_l);
- rv = apr_socket_close(mcd->sock);
-
- return rv;
-}
-
-#define MIN_LINE_ALLOC 80
-
-static apr_status_t ap_mcd_getline(char **s, apr_size_t n,
- apr_size_t *read, apr_pool_t* pool,
- mcd_res_t *mcd)
-{
- apr_status_t rv;
- apr_bucket *e;
- apr_size_t bytes_handled = 0, current_alloc = 0;
- char *pos, *last_char = *s;
- int do_alloc = (*s == NULL), saw_eos = 0;
- apr_bucket_alloc_t *bb_l;
- apr_bucket_brigade *b;
-
- bb_l = apr_bucket_alloc_create(mcd->pool);
- b = apr_brigade_create(mcd->pool, bb_l);
- rv = apr_brigade_split_line(b, mcd->bb, APR_NONBLOCK_READ, n);
-
- /* Something horribly wrong happened. Someone didn't block! */
- if (APR_BRIGADE_EMPTY(b)) {
- return APR_EGENERAL;
- }
-
- for (;;) {
-
- APR_BRIGADE_FOREACH(e, b) {
- const char *str;
- apr_size_t len;
- /* If we see an EOS, don't bother doing anything more. */
- if (APR_BUCKET_IS_EOS(e)) {
- saw_eos = 1;
- break;
- }
-
- rv = apr_bucket_read(e, &str, &len, APR_NONBLOCK_READ);
-
- if (rv != APR_SUCCESS) {
- return rv;
- }
- if (len == 0) {
- /* no use attempting a zero-byte alloc (hurts when
- * using --with-efence --enable-pool-debug) or
- * doing any of the other logic either
- */
- continue;
- }
-
- /* Would this overrun our buffer? If so, we'll die. */
- if (n < bytes_handled + len) {
- *read = bytes_handled;
- return APR_ENOSPC;
- }
- /* Just copy the rest of the data to the end of the old buffer. */
- pos = *s + bytes_handled;
- memcpy(pos, str, len);
- last_char = pos + len - 1;
-
- /* We've now processed that new data - update accordingly. */
- bytes_handled += len;
- }
-
- /* If we got a full line of input, stop reading */
- if (last_char && (*last_char == APR_ASCII_LF)) {
- break;
- }
- }
-
- /* We now go backwards over any CR (if present) or white spaces.
- *
- * Trim any extra trailing spaces or tabs except for the first
- * space or tab at the beginning of a blank string. This makes
- * it much easier to check field values for exact matches, and
- * saves memory as well. Terminate string at end of line.
- */
- pos = last_char;
- if (pos > *s && *(pos - 1) == APR_ASCII_CR) {
- --pos;
- }
-
- /* Trim any extra trailing spaces or tabs except for the first
- * space or tab at the beginning of a blank string. This makes
- * it much easier to check field values for exact matches, and
- * saves memory as well.
- */
- while (pos > ((*s) + 1)
- && (*(pos - 1) == APR_ASCII_BLANK || *(pos - 1) == APR_ASCII_TAB)) {
- --pos;
- }
-
- /* Since we want to remove the LF from the line, we'll go ahead
- * and set this last character to be the term NULL and reset
- * bytes_handled accordingly.
- */
- *pos = '\0';
- last_char = pos;
- bytes_handled = pos - *s;
- *read = bytes_handled;
-
- apr_brigade_destroy(b);
- apr_bucket_alloc_destroy(bb_l);
- return APR_SUCCESS;
-}
-
-#define LINELEN 512
-static apr_status_t mcd_get(request_rec * r, mcd_res_t* mcd, const char* key, char** value) {
- apr_status_t rv = APR_SUCCESS;
- apr_size_t sendlen;
- apr_size_t recvlen;
- apr_bucket *e;
- char *command = NULL;
- char *cmd;
- char *vlen;
- int i;
-
- command = apr_psprintf(mcd->pool, "get %s\r\n", key);
- sendlen = strlen(command);
-
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: send line: '%s'", command);
- rv = apr_socket_send(mcd->sock, command, &sendlen);
-
- if (rv != APR_SUCCESS) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: apr_socket_send");
- return rv;
- }
-
- command = apr_palloc(r->pool, LINELEN);
- for(i=0;i<10;) { // prevent runways
- memset(command, 0, LINELEN);
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: watiing for line'");
- ap_mcd_getline(&command, LINELEN, &recvlen, r->pool, mcd);
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: got line: '%s'", command);
-
- if(strcmp("END", command) == 0) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: got END.");
- break;
- }
-
- if(strlen(command) == 0) {
- i++;
- }
-
- cmd = ap_getword_white_nc(r->pool, &command);
- if(strcmp("VALUE", cmd) == 0) {
- //foo 600 5
- cmd = ap_getword_white_nc(r->pool, &command);
- cmd = ap_getword_white_nc(r->pool, &command);
- vlen = ap_getword_white_nc(r->pool, &command);
- recvlen = apr_strtoi64(vlen, NULL, 10);
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: Looking for Value of Len: '%d'", recvlen);
-/* for (;;) {
- const char *str;
- apr_size_t len;
- APR_BRIGADE_FOREACH(e, mcd->bb) {
- rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);
- if (rv != APR_SUCCESS) {
- return rv;
- }
- }
- }
- */
- //break;
- }
- }
-
-
- return rv;
-}
-
-static apr_status_t mcd_set(request_rec * r, mcd_res_t* mcd, const char* key) {
- apr_status_t rv = APR_SUCCESS;
- apr_size_t sendlen;
- char *command;
-
- command = apr_psprintf(r->pool, "set %s\r\n", key);
- sendlen = strlen(command);
-
- rv = apr_socket_send(mcd->sock, command, &sendlen);
- if (rv != APR_SUCCESS) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "mcd_get: apr_socket_send");
- return rv;
- }
- //getLine(r, mcd, &command, 5000);
-
- return rv;
-}
-
-
typedef struct authn_cache_conf_t {
authn_provider_list *providers;
} authn_cache_conf_t;
@@ -442,10 +131,6 @@
current_provider = conf->providers;
-// apr_reslist_acquire(reslist_pool, (void **) &mcd);
- mcd_new_conn((void**)&mcd, NULL, r->pool);
- mcd_get(r, mcd, "foo", &foo);
- mcd_kill_conn((void*) mcd, NULL, r->pool);
do {
const authn_provider *provider;
if (!current_provider) {
@@ -486,11 +171,8 @@
}
else {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "NOT adding user(but auth good?): %s to cache for realm: %s!",user,ap_auth_name(r));
- }
- // apr_reslist_release(reslist_pool, (void **) mcd);
+ }
return auth_result;
}
@@ -501,12 +183,6 @@
return AUTH_USER_NOT_FOUND;
}
-static apr_status_t kill_mcd(void *p)
-{
- apr_status_t rv = APR_SUCCESS;
- apr_reslist_destroy(reslist_pool);
- return rv;
-}
static int init_authn_cache(apr_pool_t *p, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s)
@@ -514,7 +190,7 @@
apr_status_t rv;
void *data;
- const char *userdata_key = "mod_authn_dbi_init";
+ const char *userdata_key = "mod_authn_cache_init";
apr_pool_userdata_get(&data, userdata_key, s->process->pool);
@@ -524,17 +200,7 @@
return OK;
}
- // apr_reslist_create(&reslist_pool, DFLT_CONN_MIN, /* hard minimum */
- // DFLT_CONN_SOFT, /* soft maximum */
- // DFLT_CONN_MAX, /* hard maximum */
- // DFLT_CONN_TTL, /* Time to live -- mcd server might override/disconnect! */
- // mcd_new_conn, /* Make a New Connection */
- // mcd_kill_conn, /* Kill Old Connection */
- // (void *) NULL, p);
-
-// apr_pool_cleanup_register(p, p, kill_mcd, apr_pool_cleanup_null);
-
- ap_add_version_component(p, "mod_authn_cache_mcd/0.1");
+ ap_add_version_component(p, "mod_authn_cache/0.1");
return 0;
}
--- mod_authn_cache.h DELETED ---
|