mod_authz_groupfile.c revision 33bdcae1f7a1a65e351dda2a766a0cf28b1e695d
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor/* ====================================================================
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * The Apache Software License, Version 1.1
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * reserved.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * Redistribution and use in source and binary forms, with or without
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * modification, are permitted provided that the following conditions
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * 1. Redistributions of source code must retain the above copyright
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * notice, this list of conditions and the following disclaimer.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * 2. Redistributions in binary form must reproduce the above copyright
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * notice, this list of conditions and the following disclaimer in
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * the documentation and/or other materials provided with the
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * distribution.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * 3. The end-user documentation included with the redistribution,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if any, must include the following acknowledgment:
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * "This product includes software developed by the
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * Apache Software Foundation (http://www.apache.org/)."
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * Alternately, this acknowledgment may appear in the software itself,
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * if and wherever such third-party acknowledgments normally appear.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * 4. The names "Apache" and "Apache Software Foundation" must
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * not be used to endorse or promote products derived from this
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * software without prior written permission. For written
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * permission, please contact apache@apache.org.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * 5. Products derived from this software may not be called "Apache",
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * nor may "Apache" appear in their name, without prior written
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * permission of the Apache Software Foundation.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * SUCH DAMAGE.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * ====================================================================
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * This software consists of voluntary contributions made by many
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * individuals on behalf of the Apache Software Foundation. For more
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * information on the Apache Software Foundation, please see
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * Portions of this software are based upon public domain software
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * originally written at the National Center for Supercomputing Applications,
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * University of Illinois, Urbana-Champaign.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor/* This module is triggered by an
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * AuthGroupFile standard /path/to/file
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * and the presense of a
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * require group <list-of-groups>
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * In an applicable limit/directory block for that method.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * If there are no AuthGroupFile directives valid for
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * the request; we DECLINED.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * If the AuthGroupFile is defined; but somehow not
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * accessible: we SERVER_ERROR (was DECLINED).
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * If there are no 'require ' directives defined for
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * this request then we DECLINED (was OK).
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * If there are no 'require ' directives valid for
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * this request method then we DECLINED. (was OK)
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * If there are any 'require group' blocks and we
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * are not in any group - we HTTP_UNAUTHORIZE
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * unless we are non-authoritative; in which
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * case we DECLINED.
1462ff536f1b939bb337766b2056109c29664c4erbowentypedef struct {
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzorstatic void *create_authz_groupfile_dir_config(apr_pool_t *p, char *d)
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor authz_groupfile_config_rec *conf = apr_palloc(p, sizeof(*conf));
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor conf->authoritative = 1; /* keep the fortress secure by default */
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzorstatic const char *set_authz_groupfile_slot(cmd_parms *cmd, void *offset, const char *f,
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor const char *t)
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor return apr_pstrcat(cmd->pool, "Invalid auth file type: ", t, NULL);
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor AP_INIT_TAKE12("AuthGroupFile", set_authz_groupfile_slot,
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor (void *)APR_OFFSETOF(authz_groupfile_config_rec, groupfile),
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor "text file containing group names and member user IDs"),
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor AP_INIT_FLAG("AuthzGroupFileAuthoritative", ap_set_flag_slot,
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor "Set to 'Off' to allow access control to be passed along to "
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor "lower modules if the 'require group' fails. (default is "
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzorstatic apr_status_t groups_for_user(apr_pool_t *p, char *user, char *grpfile,
1462ff536f1b939bb337766b2056109c29664c4erbowen if ((status = ap_pcfg_openfile(&f, p, grpfile)) != APR_SUCCESS) {
1462ff536f1b939bb337766b2056109c29664c4erbowen if ((l[0] == '#') || (!l[0])) {
1462ff536f1b939bb337766b2056109c29664c4erbowen while (ll[0]) {
1462ff536f1b939bb337766b2056109c29664c4erbowen apr_table_setn(grps, apr_pstrdup(p, group_name), "in");
1462ff536f1b939bb337766b2056109c29664c4erbowen/* Checking ID */
1462ff536f1b939bb337766b2056109c29664c4erbowen authz_groupfile_config_rec *conf = ap_get_module_config(r->per_dir_config,
1462ff536f1b939bb337766b2056109c29664c4erbowen register int x;
1462ff536f1b939bb337766b2056109c29664c4erbowen const char *t, *w;
1462ff536f1b939bb337766b2056109c29664c4erbowen /* If there is no group file - then we are not
1462ff536f1b939bb337766b2056109c29664c4erbowen * configured. So decline.
if (!filegroup) {
if (!grpstatus) {
&grpstatus);
return HTTP_INTERNAL_SERVER_ERROR;
if (filegroup) {
return OK;
return OK;
return DECLINED;
return HTTP_UNAUTHORIZED;