2001-06-04 18:44:47 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 Mark R V Murray
|
|
|
|
* All rights reserved.
|
2001-12-05 16:06:35 +00:00
|
|
|
* Copyright (c) 2001 Networks Associates Technologies, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Portions of this software were developed for the FreeBSD Project by
|
|
|
|
* ThinkSec AS and NAI Labs, the Security Research Division of Network
|
|
|
|
* Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
|
|
|
|
* ("CBOSS"), as part of the DARPA CHATS research program.
|
2001-06-04 18:44:47 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2001-12-05 16:06:35 +00:00
|
|
|
* 3. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
2001-06-04 18:44:47 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-09-30 22:11:06 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-08-10 19:05:57 +00:00
|
|
|
#define PROMPT "Password required for %s."
|
|
|
|
#define GUEST_PROMPT "Guest login ok, send your e-mail address as password."
|
2001-06-04 18:44:47 +00:00
|
|
|
|
|
|
|
#include <security/_pam_aconf.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define PAM_SM_AUTH
|
2001-12-05 16:06:35 +00:00
|
|
|
#define PAM_SM_ACCOUNT
|
|
|
|
#define PAM_SM_SESSION
|
|
|
|
#define PAM_SM_PASSWORD
|
|
|
|
|
2001-06-04 18:44:47 +00:00
|
|
|
#include <security/pam_modules.h>
|
|
|
|
#include <pam_mod_misc.h>
|
|
|
|
|
|
|
|
#include <security/_pam_macros.h>
|
|
|
|
|
2001-08-10 19:05:57 +00:00
|
|
|
enum { PAM_OPT_NO_ANON=PAM_OPT_STD_MAX, PAM_OPT_IGNORE, PAM_OPT_USERS };
|
2001-07-09 18:20:51 +00:00
|
|
|
|
|
|
|
static struct opttab other_options[] = {
|
|
|
|
{ "no_anon", PAM_OPT_NO_ANON },
|
|
|
|
{ "ignore", PAM_OPT_IGNORE },
|
2001-08-10 19:05:57 +00:00
|
|
|
{ "users", PAM_OPT_USERS },
|
2001-07-09 18:20:51 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2001-06-04 18:44:47 +00:00
|
|
|
static const char *anonusers[] = {"ftp", "anonymous", NULL};
|
|
|
|
|
2001-08-10 19:05:57 +00:00
|
|
|
/* Check if *user is in supplied *list or *anonusers[] list.
|
|
|
|
* Place username in *userret
|
2001-06-04 18:44:47 +00:00
|
|
|
* Return 1 if listed 0 otherwise
|
|
|
|
*/
|
|
|
|
static int
|
2001-08-10 19:05:57 +00:00
|
|
|
lookup(const char *user, char *list, const char **userret)
|
2001-06-04 18:44:47 +00:00
|
|
|
{
|
|
|
|
int anon, i;
|
|
|
|
char *item, *context, *locallist;
|
|
|
|
|
|
|
|
anon = 0;
|
2001-08-10 19:05:57 +00:00
|
|
|
*userret = user; /* this is the default */
|
2001-06-04 18:44:47 +00:00
|
|
|
if (list) {
|
2001-08-10 19:05:57 +00:00
|
|
|
*userret = NULL;
|
2001-06-04 18:44:47 +00:00
|
|
|
locallist = list;
|
|
|
|
while ((item = strtok_r(locallist, ",", &context))) {
|
2001-08-10 19:05:57 +00:00
|
|
|
if (*userret == NULL)
|
|
|
|
*userret = item;
|
|
|
|
if (strcmp(user, item) == 0) {
|
2001-06-04 18:44:47 +00:00
|
|
|
anon = 1;
|
|
|
|
break;
|
|
|
|
}
|
2001-08-10 19:05:57 +00:00
|
|
|
locallist = NULL;
|
2001-06-04 18:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = 0; anonusers[i] != NULL; i++) {
|
2001-08-10 19:05:57 +00:00
|
|
|
if (strcmp(anonusers[i], user) == 0) {
|
|
|
|
*userret = anonusers[0];
|
2001-06-04 18:44:47 +00:00
|
|
|
anon = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return anon;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the user name is 'ftp' or 'anonymous'.
|
|
|
|
* If this is the case, set the PAM_RUSER to the entered email address
|
|
|
|
* and succeed, otherwise fail.
|
|
|
|
*/
|
|
|
|
PAM_EXTERN int
|
2002-01-24 18:37:17 +00:00
|
|
|
pam_sm_authenticate(pam_handle_t * pamh, int flags __unused, int argc, const char **argv)
|
2001-06-04 18:44:47 +00:00
|
|
|
{
|
2001-07-09 18:20:51 +00:00
|
|
|
struct options options;
|
|
|
|
int retval, anon;
|
2002-01-24 18:37:17 +00:00
|
|
|
char *users, *context, *token, *p;
|
|
|
|
const char *user, *prompt;
|
2001-06-04 18:44:47 +00:00
|
|
|
|
2001-07-09 18:20:51 +00:00
|
|
|
pam_std_option(&options, other_options, argc, argv);
|
|
|
|
|
|
|
|
PAM_LOG("Options processed");
|
2001-06-04 18:44:47 +00:00
|
|
|
|
|
|
|
retval = pam_get_user(pamh, &user, NULL);
|
|
|
|
if (retval != PAM_SUCCESS || user == NULL)
|
2001-07-09 18:20:51 +00:00
|
|
|
PAM_RETURN(PAM_USER_UNKNOWN);
|
2001-06-04 18:44:47 +00:00
|
|
|
|
2001-08-10 19:05:57 +00:00
|
|
|
PAM_LOG("Got user: %s", user);
|
|
|
|
|
|
|
|
users = NULL;
|
|
|
|
if (pam_test_option(&options, PAM_OPT_USERS, &users))
|
|
|
|
PAM_LOG("Got extra anonymous users: %s", users);
|
|
|
|
|
2001-06-04 18:44:47 +00:00
|
|
|
anon = 0;
|
2001-07-09 18:20:51 +00:00
|
|
|
if (!pam_test_option(&options, PAM_OPT_NO_ANON, NULL))
|
2001-06-04 18:44:47 +00:00
|
|
|
anon = lookup(user, users, &user);
|
|
|
|
|
2001-08-10 19:05:57 +00:00
|
|
|
PAM_LOG("Done user: %s", user);
|
|
|
|
|
2001-06-04 18:44:47 +00:00
|
|
|
if (anon) {
|
|
|
|
retval = pam_set_item(pamh, PAM_USER, (const void *)user);
|
2001-08-10 19:05:57 +00:00
|
|
|
if (retval != PAM_SUCCESS)
|
|
|
|
PAM_RETURN(retval);
|
|
|
|
prompt = GUEST_PROMPT;
|
|
|
|
PAM_LOG("Doing anonymous");
|
2001-06-04 18:44:47 +00:00
|
|
|
}
|
2001-08-10 19:05:57 +00:00
|
|
|
else {
|
|
|
|
prompt = PROMPT;
|
|
|
|
PAM_LOG("Doing non-anonymous");
|
2001-06-04 18:44:47 +00:00
|
|
|
}
|
|
|
|
|
2001-08-10 19:05:57 +00:00
|
|
|
retval = pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, prompt, &token);
|
|
|
|
if (retval != PAM_SUCCESS)
|
2001-07-09 18:20:51 +00:00
|
|
|
PAM_RETURN(retval == PAM_CONV_AGAIN
|
|
|
|
? PAM_INCOMPLETE : PAM_AUTHINFO_UNAVAIL);
|
2001-06-04 18:44:47 +00:00
|
|
|
|
2001-08-10 19:05:57 +00:00
|
|
|
PAM_LOG("Got password");
|
2001-07-09 18:20:51 +00:00
|
|
|
|
2001-06-04 18:44:47 +00:00
|
|
|
if (anon) {
|
2001-07-09 18:20:51 +00:00
|
|
|
if (!pam_test_option(&options, PAM_OPT_IGNORE, NULL)) {
|
2001-08-10 19:05:57 +00:00
|
|
|
p = strtok_r(token, "@", &context);
|
|
|
|
if (p != NULL) {
|
|
|
|
pam_set_item(pamh, PAM_RUSER, p);
|
|
|
|
PAM_LOG("Got ruser: %s", p);
|
|
|
|
if (retval == PAM_SUCCESS) {
|
|
|
|
p = strtok_r(NULL, "@", &context);
|
|
|
|
if (p != NULL) {
|
|
|
|
pam_set_item(pamh, PAM_RHOST, p);
|
|
|
|
PAM_LOG("Got rhost: %s", p);
|
|
|
|
}
|
|
|
|
}
|
2001-06-04 18:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-10 19:05:57 +00:00
|
|
|
else
|
|
|
|
PAM_LOG("Ignoring supplied password structure");
|
2001-07-09 18:20:51 +00:00
|
|
|
|
|
|
|
PAM_LOG("Done anonymous");
|
|
|
|
|
2001-08-10 19:05:57 +00:00
|
|
|
retval = PAM_SUCCESS;
|
|
|
|
|
2001-06-04 18:44:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-08-10 19:05:57 +00:00
|
|
|
pam_set_item(pamh, PAM_AUTHTOK, token);
|
|
|
|
|
|
|
|
PAM_VERBOSE_ERROR("Anonymous module reject");
|
2001-07-09 18:20:51 +00:00
|
|
|
|
|
|
|
PAM_LOG("Done non-anonymous");
|
2001-06-04 18:44:47 +00:00
|
|
|
|
2001-08-10 19:05:57 +00:00
|
|
|
retval = PAM_AUTH_ERR;
|
|
|
|
}
|
2001-06-04 18:44:47 +00:00
|
|
|
|
2001-07-09 18:20:51 +00:00
|
|
|
PAM_RETURN(retval);
|
2001-06-04 18:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PAM_EXTERN int
|
2002-01-24 18:37:17 +00:00
|
|
|
pam_sm_setcred(pam_handle_t * pamh __unused, int flags __unused, int argc, const char **argv)
|
2001-06-04 18:44:47 +00:00
|
|
|
{
|
2001-08-10 19:05:57 +00:00
|
|
|
struct options options;
|
|
|
|
|
|
|
|
pam_std_option(&options, other_options, argc, argv);
|
|
|
|
|
|
|
|
PAM_LOG("Options processed");
|
|
|
|
|
|
|
|
PAM_RETURN(PAM_SUCCESS);
|
2001-06-04 18:44:47 +00:00
|
|
|
}
|
|
|
|
|
2001-12-05 16:06:35 +00:00
|
|
|
PAM_EXTERN int
|
2002-01-24 18:37:17 +00:00
|
|
|
pam_sm_acct_mgmt(pam_handle_t *pamh __unused, int flags __unused, int argc ,const char **argv)
|
2001-12-05 16:06:35 +00:00
|
|
|
{
|
|
|
|
struct options options;
|
|
|
|
|
|
|
|
pam_std_option(&options, NULL, argc, argv);
|
|
|
|
|
|
|
|
PAM_LOG("Options processed");
|
|
|
|
|
|
|
|
PAM_RETURN(PAM_IGNORE);
|
|
|
|
}
|
|
|
|
|
|
|
|
PAM_EXTERN int
|
2002-01-24 18:37:17 +00:00
|
|
|
pam_sm_chauthtok(pam_handle_t *pamh __unused, int flags __unused, int argc, const char **argv)
|
2001-12-05 16:06:35 +00:00
|
|
|
{
|
|
|
|
struct options options;
|
|
|
|
|
|
|
|
pam_std_option(&options, NULL, argc, argv);
|
|
|
|
|
|
|
|
PAM_LOG("Options processed");
|
|
|
|
|
|
|
|
PAM_RETURN(PAM_IGNORE);
|
|
|
|
}
|
|
|
|
|
|
|
|
PAM_EXTERN int
|
2002-01-24 18:37:17 +00:00
|
|
|
pam_sm_open_session(pam_handle_t *pamh __unused, int flags __unused, int argc, const char **argv)
|
2001-12-05 16:06:35 +00:00
|
|
|
{
|
|
|
|
struct options options;
|
|
|
|
|
|
|
|
pam_std_option(&options, NULL, argc, argv);
|
|
|
|
|
|
|
|
PAM_LOG("Options processed");
|
|
|
|
|
|
|
|
PAM_RETURN(PAM_IGNORE);
|
|
|
|
}
|
|
|
|
|
|
|
|
PAM_EXTERN int
|
2002-01-24 18:37:17 +00:00
|
|
|
pam_sm_close_session(pam_handle_t *pamh __unused, int flags __unused, int argc, const char **argv)
|
2001-12-05 16:06:35 +00:00
|
|
|
{
|
|
|
|
struct options options;
|
|
|
|
|
|
|
|
pam_std_option(&options, NULL, argc, argv);
|
|
|
|
|
|
|
|
PAM_LOG("Options processed");
|
|
|
|
|
|
|
|
PAM_RETURN(PAM_IGNORE);
|
|
|
|
}
|
|
|
|
|
2001-06-04 18:44:47 +00:00
|
|
|
PAM_MODULE_ENTRY("pam_ftp");
|