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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * Adapted to allow anonymous logins, just like with Anon-FTP, when
19 * one gives the magic user name 'anonymous' and ones email address
22 * Just add the following tokes to your <directory> setup:
24 * Anonymous magic-userid [magic-userid]...
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
31 * The magic user id is something like 'anonymous', it is NOT case sensitive.
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.
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.
40 * Dirk.vanGulik@jrc.it; http://ewse.ceo.org; http://me-www.jrc.it/~dirkx
44 #include "apr_strings.h"
46 #define APR_WANT_STRFUNC
49 #include "ap_provider.h"
51 #include "http_config.h"
52 #include "http_core.h"
54 #include "http_request.h"
55 #include "http_protocol.h"
59 typedef struct anon_auth_user
{
61 struct anon_auth_user
*next
;
65 anon_auth_user
*users
;
71 } authn_anon_config_rec
;
73 static void *create_authn_anon_dir_config(apr_pool_t
*p
, char *d
)
75 authn_anon_config_rec
*conf
= apr_palloc(p
, sizeof(*conf
));
77 /* just to illustrate the defaults really. */
83 conf
->verifyemail
= 0;
88 static const char *anon_set_string_slots(cmd_parms
*cmd
,
89 void *my_config
, const char *arg
)
91 authn_anon_config_rec
*conf
= my_config
;
92 anon_auth_user
*first
;
95 return "Anonymous string cannot be empty, use Anonymous_NoUserId";
98 /* squeeze in a record */
99 if (!conf
->anyuserid
) {
100 if (!strcmp(arg
, "*")) {
105 conf
->users
= apr_palloc(cmd
->pool
, sizeof(*conf
->users
));
106 conf
->users
->user
= apr_pstrdup(cmd
->pool
, arg
);
107 conf
->users
->next
= first
;
114 static const command_rec authn_anon_cmds
[] =
116 AP_INIT_ITERATE("Anonymous", anon_set_string_slots
, NULL
, OR_AUTHCFG
,
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'"),
133 module AP_MODULE_DECLARE_DATA authn_anon_module
;
135 static authn_status
check_anonymous(request_rec
*r
, const char *user
,
138 authn_anon_config_rec
*conf
= ap_get_module_config(r
->per_dir_config
,
140 authn_status res
= AUTH_USER_NOT_FOUND
;
142 /* Ignore if we are not configured */
143 if (!conf
->users
&& !conf
->anyuserid
) {
144 return AUTH_USER_NOT_FOUND
;
147 /* Do we allow an empty userID and/or is it the magic one
150 if (conf
->nouserid
) {
151 res
= AUTH_USER_FOUND
;
154 else if (conf
->anyuserid
) {
155 res
= AUTH_USER_FOUND
;
158 anon_auth_user
*p
= conf
->users
;
161 if (!strcasecmp(user
, p
->user
)) {
162 res
= AUTH_USER_FOUND
;
169 /* Now if the supplied user-ID was ok, grant access if:
170 * (a) no passwd was sent and no password and no verification
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
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
, '.'))))
181 if (conf
->logemail
&& ap_is_initial_req(r
)) {
182 ap_log_rerror(APLOG_MARK
, APLOG_INFO
, APR_SUCCESS
, r
,
183 "Anonymous: Passwd <%s> Accepted",
184 sent_pw
? sent_pw
: "\'none\'");
190 return (res
== AUTH_USER_NOT_FOUND
? res
: AUTH_DENIED
);
193 static const authn_provider authn_anon_provider
=
199 static void register_hooks(apr_pool_t
*p
)
201 ap_register_auth_provider(p
, AUTHN_PROVIDER_GROUP
, "anon",
202 AUTHN_PROVIDER_VERSION
,
203 &authn_anon_provider
, AP_AUTH_INTERNAL_PER_CONF
);
206 module AP_MODULE_DECLARE_DATA authn_anon_module
=
208 STANDARD20_MODULE_STUFF
,
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 */