mod_intercept_form_submit-1.1.0/ 0000775 0001750 0001750 00000000000 13015247412 016612 5 ustar adelton adelton mod_intercept_form_submit-1.1.0/docs/ 0000775 0001750 0001750 00000000000 12243012162 017534 5 ustar adelton adelton mod_intercept_form_submit-1.1.0/docs/typical_form_based_authentication.txt 0000664 0001750 0001750 00000002621 12237035660 027236 0 ustar adelton adelton
1. User accesses application's URL: http://app.example.com/hosts
2. Browser issues HTTP GET request
to app.exmple.com for /hosts
--- GET /hosts --->
3. Apache runs or hands the request over
to application
4. Application does not find
valid session cookie
5. Application redirects the
browser to logon page
<--- 302 Location /login?back=/hosts ---
6. Browser accesses the logon page /login
--- GET /login?back=/hosts --->
7. Apache runs or hands the request over
to application
8. Application does not see POST
with login & password
9. Application returns logon form
<--- 200 + page with logon form, action set back to /login ---
10. User fills in the login and password and hits "Log in"
11. Browser submits the form
--- POST /login --->
12. Apache runs or hands the request over
to application
13. Application validates the
login & password; if they
are not valid, go to 9 with
message "Bad login or password"
14. Application creates session,
returns session cookies
<--- 302 Location /hosts with Set-Cookie ---
15. Like 2, now with Cookie set
--- GET /hosts --->
16. Apache runs or hands the request over
to application
17. Application sees valid session
cookie, returns the page
<--- 200 + the /hosts page that user wanted to see ---
mod_intercept_form_submit-1.1.0/docs/form_based_authentication_with_mod_intercept_form_submit.txt 0000664 0001750 0001750 00000004360 12243012200 034046 0 ustar adelton adelton
1. User accesses application's URL: http://app.example.com/hosts
2. Browser issues HTTP GET request
to app.exmple.com for /hosts
--- GET /hosts --->
3. Apache runs or hands the request over
to application
4. Application does not find
valid session cookie
5. Application redirects the
browser to logon page
<--- 302 Location /login?back=/hosts ---
6. Browser accesses the logon page /login
--- GET /login?back=/hosts --->
7. Apache runs or hands the request over
to application
8. Application does not see POST
with login & password
9. Application returns logon form
<--- 200 + page with logon form, action set back to /login ---
10. User fills in the login and password and hits "Log in"
11. Browser submits the form
--- POST /login --->
12.1. Module mod_intercept_form_submit gets
invoked
12.2. Module parses the post data, finds
the login & password
12.3. If login not in InterceptFormLoginSkip,
runs pam_authenticate
12.4. If login in InterceptFormLoginSkip and
InterceptFormClearRemoteUserForSkipped
on, clears possible existing
REMOTE_USER / r->user
12.5. If InterceptFormPasswordRedact on,
replaces the password in the POST
data with [REDACTED]
12.6. If pam_authenticate passes, module sets
the REMOTE_USER environment variable and
r->user
12.7. If pam_authenticate passes and
mod_lookup_identity loaded, it gets
called
12.8. (orig 12) Apache runs or hands the
request over to application
13.1. Application gets run
13.2. When it sees REMOTE_USER, it
trusts it
13.3. (orig 13) Otherwise it validates
the login & password; if they
are not valid, go to 9 with
message "Bad login or password"
14. Application creates session,
returns session cookies
<--- 302 Location /hosts with Set-Cookie ---
15. Like 2, now with Cookie set
--- GET /hosts --->
16. Apache runs or hands the request over
to application
17. Application sees valid session
cookie, returns the page
<--- 200 + the /hosts page that user wanted to see ---
mod_intercept_form_submit-1.1.0/intercept_form_submit.module 0000664 0001750 0001750 00000000121 12354206675 024431 0 ustar adelton adelton
# LoadModule intercept_form_submit_module modules/mod_intercept_form_submit.so
mod_intercept_form_submit-1.1.0/intercept_form_submit.conf 0000664 0001750 0001750 00000000245 12354206675 024100 0 ustar adelton adelton
#
# InterceptFormPAMService http_application_sss
# InterceptFormLogin user_login
# InterceptFormPassword user_password
#
mod_intercept_form_submit-1.1.0/mod_intercept_form_submit.c 0000644 0001750 0001750 00000044553 13015245551 024233 0 ustar adelton adelton
/*
* Copyright 2013--2016 Jan Pazdziora
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include "apr_strings.h"
#include "apr_optional.h"
#include "http_core.h"
#include "http_log.h"
#include "http_config.h"
#include "http_request.h"
#include "mod_auth.h"
typedef struct ifs_config {
char * login_name;
char * password_name;
int password_redact;
char * pam_service;
apr_hash_t * login_blacklist;
int clear_blacklisted;
int success_to_get;
apr_array_header_t * realms;
} ifs_config;
typedef struct {
apr_status_t cached_ret;
apr_bucket_brigade * cached_brigade;
apr_bucket * password_fragment_start_bucket;
int password_fragment_start_bucket_offset;
} ifs_filter_ctx_t;
module AP_MODULE_DECLARE_DATA intercept_form_submit_module;
#ifdef APLOG_USE_MODULE
#define SHOW_MODULE ""
#else
#define SHOW_MODULE "mod_intercept_form_submit: "
#endif
APR_DECLARE_OPTIONAL_FN(authn_status, pam_authenticate_with_login_password,
(request_rec * r, const char * pam_service,
const char * login, const char * password, int steps));
static APR_OPTIONAL_FN_TYPE(pam_authenticate_with_login_password) * pam_authenticate_with_login_password_fn = NULL;
static const char * add_login_to_blacklist(cmd_parms * cmd, void * conf_void, const char * arg) {
ifs_config * cfg = (ifs_config *) conf_void;
if (cfg) {
if (! cfg->login_blacklist) {
cfg->login_blacklist = apr_hash_make(cmd->pool);
}
apr_hash_set(cfg->login_blacklist, apr_pstrdup(cmd->pool, arg), APR_HASH_KEY_STRING, "1");
}
return NULL;
}
static const char * add_realm(cmd_parms * cmd, void * conf_void, const char * arg) {
ifs_config * cfg = (ifs_config *) conf_void;
if (cfg) {
if (! cfg->realms) {
cfg->realms = apr_array_make(cmd->pool, 1, sizeof(char *));
}
*(const char **) apr_array_push(cfg->realms) = arg;
}
return NULL;
}
static const command_rec directives[] = {
AP_INIT_TAKE1("InterceptFormLogin", ap_set_string_slot, (void *)APR_OFFSETOF(ifs_config, login_name), ACCESS_CONF, "Name of the login parameter in the POST request"),
AP_INIT_TAKE1("InterceptFormPassword", ap_set_string_slot, (void *)APR_OFFSETOF(ifs_config, password_name), ACCESS_CONF, "Name of the password parameter in the POST request"),
AP_INIT_FLAG("InterceptFormPasswordRedact", ap_set_flag_slot, (void *)APR_OFFSETOF(ifs_config, password_redact), ACCESS_CONF, "When password is seen in the POST for non-blacklisted user, the value will be redacted"),
AP_INIT_TAKE1("InterceptFormPAMService", ap_set_string_slot, (void *)APR_OFFSETOF(ifs_config, pam_service), ACCESS_CONF, "PAM service to authenticate against"),
AP_INIT_ITERATE("InterceptFormLoginSkip", add_login_to_blacklist, NULL, ACCESS_CONF, "Login name(s) for which no PAM authentication will be done"),
AP_INIT_FLAG("InterceptFormClearRemoteUserForSkipped", ap_set_flag_slot, (void *)APR_OFFSETOF(ifs_config, clear_blacklisted), ACCESS_CONF, "When authentication is skipped for users listed with InterceptFormLoginSkip, clear r->user and REMOTE_USER"),
AP_INIT_FLAG("InterceptGETOnSuccess", ap_set_flag_slot, (void *)APR_OFFSETOF(ifs_config, success_to_get), ACCESS_CONF, "When authentication passes, turn the POST request to GET internally"),
AP_INIT_ITERATE("InterceptFormLoginRealms", add_realm, NULL, ACCESS_CONF, "Realm(s) that will be appended to login name which does not have one"),
{ NULL }
};
#define _REMOTE_USER_ENV_NAME "REMOTE_USER"
static void register_pam_authenticate_with_login_password_fn(void) {
pam_authenticate_with_login_password_fn = APR_RETRIEVE_OPTIONAL_FN(pam_authenticate_with_login_password);
}
static int hex2char(int c) {
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'z')
return c - 'a' + 10;
if (c >= 'A' && c <= 'Z')
return c - 'A' + 10;
return -1;
}
static char * intercept_form_submit_process_keyval(apr_pool_t * pool, const char * name,
const char * key, int key_len, const char * val, int val_len) {
if (val_len == 0)
return NULL;
int i;
for (i = 0; i < key_len; i++, name++) {
if (*name == '\0')
return NULL;
int c = key[i];
if (c == '+')
c = ' ';
else if (c == '%') {
if (i > key_len - 3)
return NULL;
int m = hex2char(key[++i]);
int n = hex2char(key[++i]);
if (m < 0 || n < 0)
return NULL;
c = (m << 4) + n;
}
if (c != *name)
return NULL;
}
if (*name != '\0')
return NULL;
char * ret = apr_palloc(pool, val_len + 1);
char * p = ret;
for (i = 0; i < val_len; i++, p++) {
if (val[i] == '+')
*p = ' ';
else if (val[i] == '%') {
if (i > val_len - 3)
return NULL;
int m = hex2char(val[++i]);
int n = hex2char(val[++i]);
if (m < 0 || n < 0)
return NULL;
*p = (m << 4) + n;
} else {
*p = val[i];
}
}
*p = '\0';
return ret;
}
static authn_status pam_authenticate_in_realms(request_rec * r, const char * pam_service,
const char * login, const char * password, apr_array_header_t * realms, int steps) {
if (strchr(login, '@') || (! realms) || (! realms->nelts)) {
return pam_authenticate_with_login_password_fn(r, pam_service, login, password, steps);
}
authn_status first_status = AUTH_GENERAL_ERROR;
int i;
for (i = 0; i < realms->nelts; i++) {
const char * realm = ((const char**)realms->elts)[i];
const char * full_login = login;
if (realm && strlen(realm))
full_login = apr_pstrcat(r->pool, login, "@", realm, NULL);
authn_status status = pam_authenticate_with_login_password_fn(r, pam_service, full_login, password, steps);
if (status == AUTH_GRANTED)
return status;
if (i == 0)
first_status = status;
}
return first_status;
}
#define _REDACTED_STRING "[REDACTED]"
static void intercept_form_redact_password(ap_filter_t * f, ifs_config * config) {
request_rec * r = f->r;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, SHOW_MODULE "will redact password (value of %s) in the POST data", config->password_name);
ifs_filter_ctx_t * ctx = f->ctx;
apr_bucket * b = ctx->password_fragment_start_bucket;
int fragment_start_bucket_offset = ctx->password_fragment_start_bucket_offset;
if (fragment_start_bucket_offset) {
apr_bucket_split(b, fragment_start_bucket_offset);
b = APR_BUCKET_NEXT(b);
}
char * new_password_data = apr_pstrcat(r->pool, config->password_name, "=", _REDACTED_STRING, NULL);
int new_password_data_length = strlen(new_password_data);
apr_bucket * new_b = apr_bucket_immortal_create(new_password_data, new_password_data_length, f->c->bucket_alloc);
APR_BUCKET_INSERT_BEFORE(b, new_b);
int password_remove_length = 0;
apr_bucket * remove_b = NULL;
do {
if (remove_b) {
apr_bucket_delete(remove_b);
remove_b = NULL;
}
if (b == APR_BRIGADE_SENTINEL(ctx->cached_brigade)) {
break;
}
if (APR_BUCKET_IS_METADATA(b))
continue;
const char * buffer;
apr_size_t nbytes;
if (apr_bucket_read(b, &buffer, &nbytes, APR_BLOCK_READ) != APR_SUCCESS)
continue;
if (! nbytes)
continue;
const char * e = memchr(buffer, '&', nbytes);
if (e) {
password_remove_length += (e - buffer);
remove_b = b;
apr_bucket_split(b, (e - buffer));
break;
} else {
password_remove_length += nbytes;
remove_b = b;
}
} while ((b = APR_BUCKET_NEXT(b)));
if (remove_b) {
apr_bucket_delete(remove_b);
}
if (password_remove_length != new_password_data_length) {
const char * orig_content_length = apr_table_get(r->headers_in, "Content-Length");
if (orig_content_length) {
char * end;
apr_off_t content_length;
apr_status_t status = apr_strtoff(&content_length, orig_content_length, &end, 10);
if (status != APR_SUCCESS || *end || end == orig_content_length || content_length < 0) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, SHOW_MODULE "Failed to parse the original Content-Length value %s, cannot update it after redacting password, clearing", orig_content_length);
apr_table_unset(r->headers_in, "Content-Length");
} else {
apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(r->pool, "%ld", content_length - password_remove_length + new_password_data_length));
}
}
}
}
static int intercept_form_submit_process_buffer(ap_filter_t * f, ifs_config * config, char ** login_value, char ** password_value,
const char * buffer, int buffer_length, apr_bucket * fragment_start_bucket, int fragment_start_bucket_offset, authn_status * out_status) {
char * sep = memchr(buffer, '=', buffer_length);
if (! sep) {
return 0;
}
request_rec * r = f->r;
int run_auth = 0;
if (! *login_value) {
*login_value = intercept_form_submit_process_keyval(r->pool, config->login_name,
buffer, sep - buffer, sep + 1, buffer_length - (sep - buffer) - 1);
if (*login_value) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
SHOW_MODULE "login found in POST: %s=%s", config->login_name, *login_value);
if (config->login_blacklist && apr_hash_get(config->login_blacklist, *login_value, APR_HASH_KEY_STRING)) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
SHOW_MODULE "login %s in blacklist, stopping", *login_value);
if (config->clear_blacklisted > 0) {
apr_table_unset(r->subprocess_env, _REMOTE_USER_ENV_NAME);
r->user = NULL;
}
return 1;
}
if (*password_value) {
run_auth = 1;
}
}
}
if (! *password_value) {
*password_value = intercept_form_submit_process_keyval(r->pool, config->password_name,
buffer, sep - buffer, sep + 1, buffer_length - (sep - buffer) - 1);
if (*password_value) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
SHOW_MODULE "password found in POST: %s=" _REDACTED_STRING, config->password_name);
if (*login_value) {
run_auth = 1;
}
ifs_filter_ctx_t * ctx = f->ctx;
ctx->password_fragment_start_bucket = fragment_start_bucket;
ctx->password_fragment_start_bucket_offset = fragment_start_bucket_offset;
}
}
if (run_auth) {
if (! pam_authenticate_with_login_password_fn) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, SHOW_MODULE "pam_authenticate_with_login_password not found; perhaps mod_authnz_pam is not loaded");
return 0;
}
(*out_status) = pam_authenticate_in_realms(r, config->pam_service, *login_value, *password_value, config->realms, 3);
if (config->password_redact > 0) {
intercept_form_redact_password(f, config);
}
return 1;
}
return 0;
}
static apr_status_t intercept_form_submit_filter(ap_filter_t * f, apr_bucket_brigade * bb,
ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes) {
ifs_filter_ctx_t * ctx = f->ctx;
if (ctx && ctx->cached_brigade) {
APR_BRIGADE_CONCAT(bb, ctx->cached_brigade);
apr_brigade_cleanup(ctx->cached_brigade);
ctx->cached_brigade = NULL;
return ctx->cached_ret;
}
return ap_get_brigade(f->next, bb, mode, block, readbytes);
}
static apr_status_t intercept_form_submit_filter_prefetch(request_rec * r, ifs_config * config, ap_filter_t * f) {
if (r->status != 200)
return DECLINED;
ifs_filter_ctx_t * ctx = f->ctx;
if (! ctx) {
f->ctx = ctx = apr_pcalloc(r->pool, sizeof(ifs_filter_ctx_t));
ctx->cached_brigade = apr_brigade_create(f->c->pool, f->c->bucket_alloc);
}
char * login_value = NULL;
char * password_value = NULL;
char * fragment = NULL;
int fragment_length = 0;
apr_bucket * fragment_start_bucket = NULL;
int fragment_start_bucket_offset = 0;
authn_status out_status = AUTH_GENERAL_ERROR;
apr_bucket_brigade * bb = apr_brigade_create(f->c->pool, f->c->bucket_alloc);
int fetch_more = 1;
while (fetch_more) {
ctx->cached_ret = ap_get_brigade(f->next, bb, AP_MODE_READBYTES, APR_BLOCK_READ, HUGE_STRING_LEN);
if (ctx->cached_ret != APR_SUCCESS)
break;
apr_bucket * b = APR_BRIGADE_FIRST(bb);
APR_BRIGADE_CONCAT(ctx->cached_brigade, bb);
for (; b != APR_BRIGADE_SENTINEL(ctx->cached_brigade); b = APR_BUCKET_NEXT(b)) {
if (! fetch_more)
break;
if (APR_BUCKET_IS_EOS(b)) {
if (fragment)
intercept_form_submit_process_buffer(f, config, &login_value, &password_value,
fragment, fragment_length, fragment_start_bucket, fragment_start_bucket_offset, &out_status);
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, SHOW_MODULE "hit EOS");
fetch_more = 0;
break;
}
if (APR_BUCKET_IS_METADATA(b))
continue;
const char * buffer;
apr_size_t nbytes;
if (apr_bucket_read(b, &buffer, &nbytes, APR_BLOCK_READ) != APR_SUCCESS)
continue;
if (! nbytes)
continue;
const char * p = buffer;
const char * e;
while ((nbytes > 0) && (e = memchr(p, '&', nbytes))) {
if (fragment) {
int new_length = fragment_length + (e - p);
fragment = realloc(fragment, new_length);
memcpy(fragment + fragment_length, p, e - p);
if (intercept_form_submit_process_buffer(f, config, &login_value, &password_value,
fragment, new_length, fragment_start_bucket, fragment_start_bucket_offset, &out_status)) {
fetch_more = 0;
break;
}
free(fragment);
fragment = NULL;
} else {
if (intercept_form_submit_process_buffer(f, config, &login_value, &password_value,
p, e - p, b, (p - buffer), &out_status)) {
fetch_more = 0;
break;
}
}
nbytes -= (e - p) + 1;
p = e + 1;
}
if (! fetch_more)
break;
if (nbytes > 0) {
if (fragment) {
int new_length = fragment_length + nbytes;
fragment = realloc(fragment, new_length);
memcpy(fragment + fragment_length, p, nbytes);
fragment_length = new_length;
} else if (APR_BUCKET_NEXT(b) && APR_BUCKET_IS_EOS(APR_BUCKET_NEXT(b))) {
/* shortcut if this is the last bucket, slurp the rest */
intercept_form_submit_process_buffer(f, config, &login_value, &password_value,
p, nbytes, b, (p - buffer), &out_status);
fetch_more = 0;
} else {
fragment = malloc(nbytes);
memcpy(fragment, p, nbytes);
fragment_length = nbytes;
fragment_start_bucket = b;
fragment_start_bucket_offset = p - buffer;
}
}
}
}
if (fragment)
free(fragment);
return out_status == AUTH_GRANTED ? OK : DECLINED;
}
#define _INTERCEPT_CONTENT_TYPE "application/x-www-form-urlencoded"
static apr_status_t intercept_form_submit_init(request_rec * r) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, SHOW_MODULE "intercept_form_submit_init invoked");
if (r->method_number != M_POST) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, SHOW_MODULE "skipping, no POST request");
return DECLINED;
}
ifs_config * config = ap_get_module_config(r->per_dir_config, &intercept_form_submit_module);
if (!(config && config->login_name && config->password_name && config->pam_service)) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, SHOW_MODULE "skipping, not configured");
return DECLINED;
}
if (apr_table_get(r->subprocess_env, _REMOTE_USER_ENV_NAME)) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, SHOW_MODULE "skipping, " _REMOTE_USER_ENV_NAME " already set");
return DECLINED;
}
const char * content_type = apr_table_get(r->headers_in, "Content-Type");
if (content_type) {
char * content_type_pure = apr_pstrdup(r->pool, content_type);
char * sep;
if ((sep = strchr(content_type_pure, ';'))) {
*sep = '\0';
}
apr_collapse_spaces(content_type_pure, content_type_pure);
if (!apr_strnatcasecmp(content_type_pure, _INTERCEPT_CONTENT_TYPE)) {
ap_filter_t * the_filter = ap_add_input_filter("intercept_form_submit_filter", NULL, r, r->connection);
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, SHOW_MODULE "inserted filter intercept_form_submit_filter, starting intercept_form_submit_filter_prefetch");
apr_status_t status = intercept_form_submit_filter_prefetch(r, config, the_filter);
if (status == OK && config->success_to_get >= 0) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, SHOW_MODULE "intercept_form_submit_filter_prefetch returned OK, turning the method to GET");
r->status_line = NULL;
r->method = "GET";
r->method_number = M_GET;
apr_table_unset(r->headers_in, "Content-Length");
}
return DECLINED;
}
}
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, SHOW_MODULE "skipping, no " _INTERCEPT_CONTENT_TYPE);
return DECLINED;
}
static void * create_dir_conf(apr_pool_t * pool, char * dir) {
ifs_config * cfg = apr_pcalloc(pool, sizeof(ifs_config));
cfg->password_redact = -1;
cfg->clear_blacklisted = -1;
cfg->success_to_get = -1;
return cfg;
}
static void * merge_dir_conf(apr_pool_t * pool, void * base_void, void * add_void) {
ifs_config * base = (ifs_config *) base_void;
ifs_config * add = (ifs_config *) add_void;
ifs_config * cfg = (ifs_config *) create_dir_conf(pool, NULL);
cfg->login_name = add->login_name ? add->login_name : base->login_name;
cfg->password_name = add->password_name ? add->password_name : base->password_name;
cfg->password_redact = add->password_redact >= 0 ? add->password_redact : base->password_redact;
cfg->success_to_get = add->success_to_get >= 0 ? add->success_to_get : base->success_to_get;
cfg->clear_blacklisted = add->clear_blacklisted >= 0 ? add->clear_blacklisted : base->clear_blacklisted;
cfg->pam_service = add->pam_service ? add->pam_service : base->pam_service;
if (add->login_blacklist) {
if (base->login_blacklist) {
cfg->login_blacklist = apr_hash_overlay(apr_hash_pool_get(add->login_blacklist), add->login_blacklist, base->login_blacklist);
} else {
cfg->login_blacklist = add->login_blacklist;
}
} else if (base->login_blacklist) {
cfg->login_blacklist = base->login_blacklist;
}
cfg->realms = add->realms ? add->realms : base->realms;
return cfg;
}
static void register_hooks(apr_pool_t * pool) {
ap_hook_fixups(intercept_form_submit_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_register_input_filter("intercept_form_submit_filter", intercept_form_submit_filter, NULL, AP_FTYPE_RESOURCE);
ap_hook_optional_fn_retrieve(register_pam_authenticate_with_login_password_fn, NULL, NULL, APR_HOOK_MIDDLE);
}
#ifdef AP_DECLARE_MODULE
AP_DECLARE_MODULE(intercept_form_submit)
#else
module AP_MODULE_DECLARE_DATA intercept_form_submit_module
#endif
= {
STANDARD20_MODULE_STUFF,
create_dir_conf, /* Per-directory configuration handler */
merge_dir_conf, /* Merge handler for per-directory configurations */
NULL, /* Per-server configuration handler */
NULL, /* Merge handler for per-server configurations */
directives, /* Any directives we may have for httpd */
register_hooks /* Our hook registering function */
};
mod_intercept_form_submit-1.1.0/mod_intercept_form_submit.spec 0000664 0001750 0001750 00000007236 13015245716 024745 0 ustar adelton adelton %{!?_httpd_mmn: %{expand: %%global _httpd_mmn %%(cat %{_includedir}/httpd/.mmn || echo 0-0)}}
%{!?_httpd_apxs: %{expand: %%global _httpd_apxs %%{_sbindir}/apxs}}
%{!?_httpd_confdir: %{expand: %%global _httpd_confdir %%{_sysconfdir}/httpd/conf.d}}
# /etc/httpd/conf.d with httpd < 2.4 and defined as /etc/httpd/conf.modules.d with httpd >= 2.4
%{!?_httpd_modconfdir: %{expand: %%global _httpd_modconfdir %%{_sysconfdir}/httpd/conf.d}}
%{!?_httpd_moddir: %{expand: %%global _httpd_moddir %%{_libdir}/httpd/modules}}
Summary: Apache module to intercept login form submission and run PAM authentication
Name: mod_intercept_form_submit
Version: 1.1.0
Release: 1%{?dist}
License: ASL 2.0
Group: System Environment/Daemons
URL: http://www.adelton.com/apache/mod_intercept_form_submit/
Source0: http://www.adelton.com/apache/mod_intercept_form_submit/%{name}-%{version}.tar.gz
BuildRequires: httpd-devel
BuildRequires: pkgconfig
Requires: httpd-mmn = %{_httpd_mmn}
Requires: mod_authnz_pam >= 0.7
# Suppres auto-provides for module DSO per
# https://fedoraproject.org/wiki/Packaging:AutoProvidesAndRequiresFiltering#Summary
%{?filter_provides_in: %filter_provides_in %{_libdir}/httpd/modules/.*\.so$}
%{?filter_setup}
%description
mod_intercept_form_submit can intercept submission of application login
forms. It retrieves the login and password information from the POST
HTTP request, runs PAM authentication with those credentials, and sets
the REMOTE_USER environment variable if the authentication passes.
%prep
%setup -q -n %{name}-%{version}
%build
%{_httpd_apxs} -c -Wc,"%{optflags} -Wall -pedantic -std=c99" mod_intercept_form_submit.c
%if "%{_httpd_modconfdir}" != "%{_httpd_confdir}"
echo > intercept_form_submit.confx
echo "# Load the module in %{_httpd_modconfdir}/55-intercept_form_submit.conf" >> intercept_form_submit.confx
cat intercept_form_submit.conf >> intercept_form_submit.confx
%else
cat intercept_form_submit.module > intercept_form_submit.confx
cat intercept_form_submit.conf >> intercept_form_submit.confx
%endif
%install
rm -rf $RPM_BUILD_ROOT
install -Dm 755 .libs/mod_intercept_form_submit.so $RPM_BUILD_ROOT%{_httpd_moddir}/mod_intercept_form_submit.so
%if "%{_httpd_modconfdir}" != "%{_httpd_confdir}"
# httpd >= 2.4.x
install -Dp -m 0644 intercept_form_submit.module $RPM_BUILD_ROOT%{_httpd_modconfdir}/55-intercept_form_submit.conf
%endif
install -Dp -m 0644 intercept_form_submit.confx $RPM_BUILD_ROOT%{_httpd_confdir}/intercept_form_submit.conf
%files
%doc README LICENSE docs/*
%if "%{_httpd_modconfdir}" != "%{_httpd_confdir}"
%config(noreplace) %{_httpd_modconfdir}/55-intercept_form_submit.conf
%endif
%config(noreplace) %{_httpd_confdir}/intercept_form_submit.conf
%{_httpd_moddir}/*.so
%changelog
* Wed Nov 23 2016 Jan Pazdziora - 1.1.0-1
- Logging improvements.
* Fri May 06 2016 Jan Pazdziora - 1.0.1-1
- Add support for InterceptGETOnSuccess.
* Mon Mar 21 2016 Jan Pazdziora - 1.0.0-1
- 1319094 - the Requires(pre) httpd does not seem to be needed.
* Mon Jun 30 2014 Jan Pazdziora - 0.9.8-1
- 1109923 - Fix module loading/configuration for Apache 2.4.
- Document the runtime dependency on pam_authenticate_with_login_password.
- Comment/code cleanup.
* Tue May 13 2014 Jan Pazdziora - 0.9.7-1
- No longer call lookup_identity_hook explicitly, hook order does
the same.
- Silence compile warnings by specifying C99.
* Tue Apr 15 2014 Jan Pazdziora - 0.9.6-1
- Add support for InterceptFormLoginRealms.
* Thu Jan 30 2014 Jan Pazdziora - 0.9.5-1
- 1058809 - .spec changes for Fedora package review.
mod_intercept_form_submit-1.1.0/README 0000664 0001750 0001750 00000013312 12713104107 017467 0 ustar adelton adelton
Apache module mod_intercept_form_submit
=======================================
Apache module to intercept submission of application login forms. It
retrieves the login and password information from the POST HTTP
request, runs PAM authentication with those credentials, and sets the
REMOTE_USER environment variable if the authentication passes. The
internal r->user field is also set so other modules can use it (even
if the module is invoked very late in the request processing).
If the REMOTE_USER is already set (presumably by some previous module),
no authentication takes place.
If the PAM authentication fails, environment variable
EXTERNAL_AUTH_ERROR is set to the string describing the error.
The assumption is that the application will be amended to trust the
REMOTE_USER value if it is set and skip its own login/password
validation (see the docs/ directory for outline of the interaction).
Module configuration
--------------------
Module mod_authnz_pam needs to be installed and loaded with
LoadModule authnz_pam_module modules/mod_authnz_pam.so
because mod_intercept_form_submit uses it to do the actual PAM operations.
The mod_intercept_form_submit module needs to be configured for Location
that the application uses to process the login form POST requests. The
configuration has to specify three values:
InterceptFormPAMService name_of_the_PAM_service
The PAM service to authenticate against.
InterceptFormLogin the_login_field_name
Name of the login field in the login form, and thus the login
parameter in the POST request.
InterceptFormPassword the_password_field_name
Name of the password field in the login form, and thus the
password parameter in the POST request.
All three parameters above need to be specified or the interception
will not be enabled.
Optional parameters:
InterceptFormLoginSkip one_login [or_more_logins]
List of logins to ignore (never attempt to authenticate).
By default authentication will be attempted for all logins.
InterceptFormClearRemoteUserForSkipped on|off
When set to on and authentication is skipped for users
listed with InterceptFormLoginSkip, clears r->user and
REMOTE_USER.
Default is off.
InterceptFormPasswordRedact on|off
When set to on and authentication is attempted (no matter
if it passes or fails), the value of the password will
be modified in the POST data to string [REDACTED].
Default is off.
InterceptFormLoginRealms REALM1 [other REALM2]
List of realm/domain names to append to the login and try
in cycle when the login does not contain the '@' sign. This
can be used for force particular realms without users being
forced to enter them. Empty string can be used in the list
to explicitly try authentication without any realm.
This can be used with mod_auth_kerb's (default)
KrbMethodK5Passwd Off to present login names including realms
to web applications.
By default, no modifications to login happens.
InterceptGETOnSuccess on|off
When the authentication using the POST data passes, the
method of the request is internally changed to GET. This
stops applications and frameworks that insist on running
their own authentication on POST irrespective of REMOTE_USER
value to think that they process GET.
Example:
LoadModule intercept_form_submit_module modules/mod_intercept_form_submit.so
LoadModule authnz_pam_module modules/mod_authnz_pam.so
InterceptFormPAMService http_application_sss
InterceptFormLogin login[login]
InterceptFormPassword login[password]
InterceptFormLoginSkip admin
InterceptFormClearRemoteUserForSkipped on
InterceptFormPasswordRedact on
InterceptFormLoginRealms EXAMPLE.COM LAB.EXAMPLE.COM ''
InterceptGETOnSuccess on
The PAM service needs to be configured. For the above shown
http_application_sss example, file /etc/pam.d/http_application_sss
could be created with content
auth required pam_sss.so
account required pam_sss.so
to authenticate against sssd.
On SELinux enabled systems, boolean allow_httpd_mod_auth_pam needs to
be enabled:
setsebool -P allow_httpd_mod_auth_pam 1
Building from sources
---------------------
When building from sources, command
apxs -i -a -c mod_intercept_form_submit.c -Wall -pedantic
should build and install the module.
Dependency on mod_authnz_pam
----------------------------
Module mod_intercept_form_submit has soft (runtime) dependency on
function pam_authenticate_with_login_password with prototype
authn_status pam_authenticate_with_login_password(
request_rec * r, const char * pam_service,
const char * login, const char * password,
int steps
);
This function is typically provided by module mod_authnz_pam, and is
called to achieve the actual authentication via the PAM stack. When
mod_authnz_pam is not loaded and thus this function not available,
error
mod_intercept_form_submit: pam_authenticate_with_login_password
not found; perhaps mod_authnz_pam is not loaded
is logged and authentication does not take place.
License
-------
Copyright 2013--2016 Jan Pazdziora
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
http://www.apache.org/licenses/LICENSE-2.0
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.
mod_intercept_form_submit-1.1.0/LICENSE 0000664 0001750 0001750 00000026136 12234160720 017625 0 ustar adelton adelton
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://www.apache.org/licenses/LICENSE-2.0
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.
mod_intercept_form_submit-1.1.0/Makefile 0000664 0001750 0001750 00000001255 12713104107 020252 0 ustar adelton adelton
NAME=mod_intercept_form_submit
SOURCE0 := $(shell spectool $(NAME).spec)
SOURCE := $(shell echo $(SOURCE0) | sed 's%^.*/%%')
NAME_VER := $(shell echo $(SOURCE) | sed 's%\.tar\.gz$$%%')
all:
@echo 'Usage: make dist to build the .tar.gz'
@echo ' make timestamps set file timestamps to match commit times'
timestamps:
git ls-files | while read -r f ; do touch -ch -d "$$(git log -1 --format=%ci "$$f")" "$$f" ; done
dist:
@if test -f ../$(SOURCE) ; then ( echo "The source [../$(SOURCE)] already exists." >&2 ; exit 1 ) ; fi
@mkdir .dist
@mkdir .dist/$(NAME_VER) && cp -rp * .dist/$(NAME_VER)
tar cvzf ../$(SOURCE) -C .dist $(NAME_VER)
@rm -rf .dist