]> granicus.if.org Git - apache/blob - modules/aaa/mod_authz_user.c
8607a033d18d526bce152d6c81fd1575ce7432b3
[apache] / modules / aaa / mod_authz_user.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "apr_strings.h"
18
19 #include "ap_config.h"
20 #include "ap_provider.h"
21 #include "httpd.h"
22 #include "http_config.h"
23 #include "http_core.h"
24 #include "http_log.h"
25 #include "http_protocol.h"
26 #include "http_request.h"
27
28 #include "mod_auth.h"
29
30 typedef struct {
31         int dummy;  /* just here to stop compiler warnings for now. */
32 } authz_user_config_rec;
33
34 static void *create_authz_user_dir_config(apr_pool_t *p, char *d)
35 {
36     authz_user_config_rec *conf = apr_palloc(p, sizeof(*conf));
37
38     return conf;
39 }
40
41 static const command_rec authz_user_cmds[] =
42 {
43     {NULL}
44 };
45
46 module AP_MODULE_DECLARE_DATA authz_user_module;
47
48 static authz_status user_check_authorization(request_rec *r,
49                                              const char *require_args)
50 {
51     const char *t, *w;
52
53     t = require_args;
54     while ((w = ap_getword_conf(r->pool, &t)) && w[0]) {
55         if (!strcmp(r->user, w)) {
56             return AUTHZ_GRANTED;
57         }
58     }
59
60     ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
61                   "access to %s failed, reason: user '%s' does not meet "
62                   "'require'ments for user to be allowed access",
63                   r->uri, r->user);
64
65     return AUTHZ_DENIED;
66 }
67
68 static authz_status validuser_check_authorization(request_rec *r, const char *require_line)
69 {
70     return AUTHZ_GRANTED;
71 }
72
73 static const authz_provider authz_user_provider =
74 {
75     &user_check_authorization,
76 };
77 static const authz_provider authz_validuser_provider =
78 {
79     &validuser_check_authorization,
80 };
81
82 static void register_hooks(apr_pool_t *p)
83 {
84     ap_register_provider(p, AUTHZ_PROVIDER_GROUP, "user", "0",
85                          &authz_user_provider);
86     ap_register_provider(p, AUTHZ_PROVIDER_GROUP, "valid-user", "0",
87                          &authz_validuser_provider);
88 }
89
90 module AP_MODULE_DECLARE_DATA authz_user_module =
91 {
92     STANDARD20_MODULE_STUFF,
93     create_authz_user_dir_config, /* dir config creater */
94     NULL,                         /* dir merger --- default is to override */
95     NULL,                         /* server config */
96     NULL,                         /* merge server config */
97     authz_user_cmds,              /* command apr_table_t */
98     register_hooks                /* register hooks */
99 };