mod_authz_groupfile.c revision 0d05df99444ad6d79d865fa91d94dc8e5f0b51d7
/* Copyright 2002-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* 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
*
*
* 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.
*/
/* This module is triggered by an
*
*
* and the presense of a
*
* require group <list-of-groups>
*
*
* If there are no AuthGroupFile directives valid for
* the request; we DECLINED.
*
* If the AuthGroupFile is defined; but somehow not
* accessible: we SERVER_ERROR (was DECLINED).
*
* If there are no 'require ' directives defined for
* this request then we DECLINED (was OK).
*
* If there are no 'require ' directives valid for
* this request method then we DECLINED. (was OK)
*
* If there are any 'require group' blocks and we
* are not in any group - we HTTP_UNAUTHORIZE
* unless we are non-authoritative; in which
* case we DECLINED.
*
*/
#include "apr_strings.h"
#include "apr_lib.h" /* apr_isspace */
#include "ap_config.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"
typedef struct {
char *groupfile;
int authoritative;
static void *create_authz_groupfile_dir_config(apr_pool_t *p, char *d)
{
return conf;
}
const char *t)
{
if (t && strcmp(t, "standard")) {
}
}
static const command_rec authz_groupfile_cmds[] =
{
"text file containing group names and member user IDs"),
(void *)APR_OFFSETOF(authz_groupfile_config_rec,
"Set to 'Off' to allow access control to be passed along to "
"lower modules if the 'require group' fails. (default is "
"On)."),
{NULL}
};
apr_table_t ** out)
{
ap_configfile_t *f;
apr_pool_t *sp;
char l[MAX_STRING_LEN];
const char *group_name, *ll, *w;
return status ;
}
apr_pool_create(&sp, p);
while (!(ap_cfg_getline(l, MAX_STRING_LEN, f))) {
if ((l[0] == '#') || (!l[0])) {
continue;
}
ll = l;
--group_len;
}
while (ll[0]) {
"in");
break;
}
}
}
ap_cfg_closefile(f);
return APR_SUCCESS;
}
/* Checking ID */
static int check_user_access(request_rec *r)
{
int m = r->method_number;
int required_group = 0;
register int x;
const char *t, *w;
/* If there is no group file - then we are not
* configured. So decline.
*/
return DECLINED;
}
if (!reqs_arr) {
return DECLINED; /* XXX change from legacy */
}
continue;
}
t = reqs[x].requirement;
w = ap_getword_white(r->pool, &t);
/* needs mod_authz_owner to be present */
if (!strcasecmp(w, "file-group")) {
if (!filegroup) {
/* mod_authz_owner is not present or not
* authoritative. We are just a helper module for testing
* group membership, so we don't care and decline.
*/
continue;
}
}
/* create group table only if actually needed. */
if (!grpstatus) {
&grpstatus);
if (status != APR_SUCCESS) {
"Could not open group file: %s",
return HTTP_INTERNAL_SERVER_ERROR;
}
/* no groups available, so exit immediately */
"user doesn't appear in group file "
break;
}
}
if (filegroup) {
return OK;
}
if (conf->authoritative) {
"file group '%s' does not match.",
break;
}
/* now forget the filegroup, thus alternatively require'd
groups get a real chance */
}
else {
while (t[0]) {
w = ap_getword_conf(r->pool, &t);
if (apr_table_get(grpstatus, w)) {
return OK;
}
}
}
}
}
/* No applicable "require group" for this method seen */
return DECLINED;
}
"Authorization of user %s to access %s failed, reason: %s",
"'require'ed group(s).");
return HTTP_UNAUTHORIZED;
}
static void register_hooks(apr_pool_t *p)
{
}
{
create_authz_groupfile_dir_config,/* dir config creater */
NULL, /* dir merger -- default is to override */
NULL, /* server config */
NULL, /* merge server config */
authz_groupfile_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};