Apache HTTPD
mod_authn_anon.c
Go to the documentation of this file.
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/*
18 * Adapted to allow anonymous logins, just like with Anon-FTP, when
19 * one gives the magic user name 'anonymous' and ones email address
20 * as the password.
21 *
22 * Just add the following tokes to your <directory> setup:
23 *
24 * Anonymous magic-userid [magic-userid]...
25 *
26 * Anonymous_MustGiveEmail [ on | off ] default = on
27 * Anonymous_LogEmail [ on | off ] default = on
28 * Anonymous_VerifyEmail [ on | off ] default = off
29 * Anonymous_NoUserId [ on | off ] default = off
30 *
31 * The magic user id is something like 'anonymous', it is NOT case sensitive.
32 *
33 * The MustGiveEmail flag can be used to force users to enter something
34 * in the password field (like an email address). Default is on.
35 *
36 * Furthermore the 'NoUserID' flag can be set to allow completely empty
37 * usernames in as well; this can be is convenient as a single return
38 * in broken GUIs like W95 is often given by the user. The Default is off.
39 *
40 * [email protected]; http://ewse.ceo.org; http://me-www.jrc.it/~dirkx
41 *
42 */
43
44#include "apr_strings.h"
45
46#define APR_WANT_STRFUNC
47#include "apr_want.h"
48
49#include "ap_provider.h"
50#include "httpd.h"
51#include "http_config.h"
52#include "http_core.h"
53#include "http_log.h"
54#include "http_request.h"
55#include "http_protocol.h"
56
57#include "mod_auth.h"
58
59typedef struct anon_auth_user {
60 const char *user;
63
72
74{
75 authn_anon_config_rec *conf = apr_palloc(p, sizeof(*conf));
76
77 /* just to illustrate the defaults really. */
78 conf->users = NULL;
79
80 conf->nouserid = 0;
81 conf->anyuserid = 0;
82 conf->logemail = 1;
83 conf->verifyemail = 0;
84 conf->mustemail = 1;
85 return conf;
86}
87
89 void *my_config, const char *arg)
90{
93
94 if (!*arg) {
95 return "Anonymous string cannot be empty, use Anonymous_NoUserId";
96 }
97
98 /* squeeze in a record */
99 if (!conf->anyuserid) {
100 if (!strcmp(arg, "*")) {
101 conf->anyuserid = 1;
102 }
103 else {
104 first = conf->users;
105 conf->users = apr_palloc(cmd->pool, sizeof(*conf->users));
106 conf->users->user = arg;
107 conf->users->next = first;
108 }
109 }
110
111 return NULL;
112}
113
115{
117 "a space-separated list of user IDs"),
118 AP_INIT_FLAG("Anonymous_MustGiveEmail", ap_set_flag_slot,
119 (void *)APR_OFFSETOF(authn_anon_config_rec, mustemail),
120 OR_AUTHCFG, "Limited to 'on' or 'off'"),
121 AP_INIT_FLAG("Anonymous_NoUserId", ap_set_flag_slot,
122 (void *)APR_OFFSETOF(authn_anon_config_rec, nouserid),
123 OR_AUTHCFG, "Limited to 'on' or 'off'"),
124 AP_INIT_FLAG("Anonymous_VerifyEmail", ap_set_flag_slot,
125 (void *)APR_OFFSETOF(authn_anon_config_rec, verifyemail),
126 OR_AUTHCFG, "Limited to 'on' or 'off'"),
127 AP_INIT_FLAG("Anonymous_LogEmail", ap_set_flag_slot,
128 (void *)APR_OFFSETOF(authn_anon_config_rec, logemail),
129 OR_AUTHCFG, "Limited to 'on' or 'off'"),
130 {NULL}
131};
132
133module AP_MODULE_DECLARE_DATA authn_anon_module;
134
135static authn_status check_anonymous(request_rec *r, const char *user,
136 const char *sent_pw)
137{
139 &authn_anon_module);
141
142 /* Ignore if we are not configured */
143 if (!conf->users && !conf->anyuserid) {
144 return AUTH_USER_NOT_FOUND;
145 }
146
147 /* Do we allow an empty userID and/or is it the magic one
148 */
149 if (!*user) {
150 if (conf->nouserid) {
152 }
153 }
154 else if (conf->anyuserid) {
156 }
157 else {
158 anon_auth_user *p = conf->users;
159
160 while (p) {
161 if (!strcasecmp(user, p->user)) {
163 break;
164 }
165 p = p->next;
166 }
167 }
168
169 /* Now if the supplied user-ID was ok, grant access if:
170 * (a) no passwd was sent and no password and no verification
171 * were configured.
172 * (b) password was sent and no verification was configured
173 * (c) verification was configured and the password (sent or not)
174 * looks like an email address
175 */
176 if ( (res == AUTH_USER_FOUND)
177 && (!conf->mustemail || *sent_pw)
178 && ( !conf->verifyemail
179 || (ap_strchr_c(sent_pw, '@') && ap_strchr_c(sent_pw, '.'))))
180 {
181 if (conf->logemail && ap_is_initial_req(r)) {
183 "Anonymous: Passwd <%s> Accepted",
184 sent_pw ? sent_pw : "\'none\'");
185 }
186
187 return AUTH_GRANTED;
188 }
189
190 return (res == AUTH_USER_NOT_FOUND ? res : AUTH_DENIED);
191}
192
194{
196 NULL
197};
198
205
207{
209 create_authn_anon_dir_config, /* dir config creater */
210 NULL, /* dir merger ensure strictness */
211 NULL, /* server config */
212 NULL, /* merge server config */
213 authn_anon_cmds, /* command apr_table_t */
214 register_hooks /* register hooks */
215};
Apache Provider API.
apr_size_t const unsigned char unsigned int unsigned int d
Definition apr_siphash.h:72
APR Strings library.
APR Standard Headers Support.
#define ap_get_module_config(v, m)
#define AP_DECLARE_MODULE(foo)
#define AP_INIT_FLAG(directive, func, mconfig, where, help)
#define AP_INIT_ITERATE(directive, func, mconfig, where, help)
const char * ap_set_flag_slot(cmd_parms *cmd, void *struct_ptr, int arg)
Definition config.c:1512
request_rec * r
#define APLOGNO(n)
Definition http_log.h:117
#define APLOG_INFO
Definition http_log.h:70
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_MARK
Definition http_log.h:283
apr_status_t ap_register_auth_provider(apr_pool_t *pool, const char *provider_group, const char *provider_name, const char *provider_version, const void *provider, int type)
Definition request.c:2179
#define AP_AUTH_INTERNAL_PER_CONF
int ap_is_initial_req(request_rec *r)
Definition request.c:2567
void const char * arg
Definition http_vhost.h:63
apr_pool_t apr_dbd_t apr_dbd_results_t ** res
Definition apr_dbd.h:287
#define OR_AUTHCFG
#define STANDARD20_MODULE_STUFF
#define ap_strchr_c(s, c)
Definition httpd.h:2353
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int strcasecmp(const char *a, const char *b)
const apr_array_header_t * first
Definition apr_tables.h:207
apr_cmdtype_e cmd
Apache Configuration.
CORE HTTP Daemon.
Apache Logging library.
HTTP protocol handling.
Apache Request library.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
Authentication and Authorization Extension for Apache.
#define AUTHN_PROVIDER_VERSION
Definition mod_auth.h:41
#define AUTHN_PROVIDER_GROUP
Definition mod_auth.h:39
authn_status
Definition mod_auth.h:64
@ AUTH_GRANTED
Definition mod_auth.h:66
@ AUTH_DENIED
Definition mod_auth.h:65
@ AUTH_USER_FOUND
Definition mod_auth.h:67
@ AUTH_USER_NOT_FOUND
Definition mod_auth.h:68
static void * create_authn_anon_dir_config(apr_pool_t *p, char *d)
static const authn_provider authn_anon_provider
static authn_status check_anonymous(request_rec *r, const char *user, const char *sent_pw)
static const char * anon_set_string_slots(cmd_parms *cmd, void *my_config, const char *arg)
static void register_hooks(apr_pool_t *p)
static const command_rec authn_anon_cmds[]
return NULL
Definition mod_so.c:359
const char * user
struct anon_auth_user * next
anon_auth_user * users
A structure that represents the current request.
Definition httpd.h:845
struct ap_conf_vector_t * per_dir_config
Definition httpd.h:1047