/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/
/* LOGIN is a PLAIN-like authenticator, but for older deployments. */
/* Login SASL plugin
* Rob Siemborski (SASLv2 Conversion)
* contributed by Rainer Schoepf <schoepf@uni-mainz.de>
* based on PLAIN, by Tim Martin <tmartin@andrew.cmu.edu>
* $Id: login.c,v 1.25 2003/02/13 19:56:04 rjs3 Exp $
*/
/*
* Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
*
* 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
* distribution.
*
* 3. The name "Carnegie Mellon University" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For permission or any other legal
* details, please contact
* Office of Technology Transfer
* Carnegie Mellon University
* 5000 Forbes Avenue
* Pittsburgh, PA 15213-3890
* (412) 268-4387, fax: (412) 268-7395
* tech-transfer@andrew.cmu.edu
*
* 4. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by Computing Services
* at Carnegie Mellon University (http://www.cmu.edu/computing/)."
*
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <stdio.h>
#include <ctype.h>
#include <sasl.h>
#include <saslplug.h>
#include "plugin_common.h"
#ifndef _SUN_SDK_
#ifdef WIN32
/* This must be after sasl.h */
# include "saslLOGIN.h"
#endif /* WIN32 */
#endif /* !_SUN_SDK_ */
/***************************** Common Section *****************************/
#ifndef _SUN_SDK_
#endif /* !_SUN_SDK_ */
/***************************** Server Section *****************************/
typedef struct context {
int state;
char *username;
void **conn_context)
{
/* holds state are in */
return SASL_NOMEM;
}
*conn_context = text;
return SASL_OK;
}
const char *clientin,
unsigned clientinlen,
const char **serverout,
unsigned *serveroutlen,
{
*serveroutlen = 0;
case 1:
/* Check inlen, (possibly we have already the user name) */
/* In this case fall through to state 2 */
if (clientinlen == 0) {
/* demand username */
return SASL_CONTINUE;
}
case 2:
/* Catch really long usernames */
if (clientinlen > 1024) {
#ifdef _SUN_SDK_
"username too long (>1024 characters)");
#else
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
/* get username */
return SASL_NOMEM;
}
/* demand password */
return SASL_CONTINUE;
case 3: {
int result;
/* Catch really long passwords */
if (clientinlen > 1024) {
#ifdef _SUN_SDK_
"clientinlen is > 1024 characters in LOGIN plugin");
#else
"clientinlen is > 1024 characters in LOGIN plugin");
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
/* get password */
password =
if (!password) {
return SASL_NOMEM;
}
/* canonicalize username first, so that password verification is
* done against the canonical id */
return result;
}
/* verify_password - return sasl_ok on success */
return result;
}
if (params->transition) {
}
*serveroutlen = 0;
oparams->param_version = 0;
return SASL_OK;
}
default:
return SASL_FAIL;
}
return SASL_FAIL; /* should never get here */
}
const sasl_utils_t *utils)
{
if (!text) return;
}
{
{
"LOGIN", /* mech_name */
0, /* max_ssf */
SASL_SEC_NOANONYMOUS, /* security_flags */
0, /* features */
NULL, /* glob_context */
&login_server_mech_new, /* mech_new */
&login_server_mech_step, /* mech_step */
&login_server_mech_dispose, /* mech_dispose */
NULL, /* mech_free */
NULL, /* setpass */
NULL, /* user_query */
NULL, /* idle */
NULL, /* mech_avail */
NULL /* spare */
}
};
int maxversion,
int *out_version,
int *plugcount)
{
if (maxversion < SASL_SERVER_PLUG_VERSION) {
return SASL_BADVERS;
}
*plugcount = 1;
return SASL_OK;
}
/***************************** Client Section *****************************/
typedef struct client_context {
int state;
#ifdef _INTEGRATED_SOLARIS_
void *h;
#endif /* _INTEGRATED_SOLARIS_ */
void **conn_context)
{
/* holds state are in */
return SASL_NOMEM;
}
*conn_context = text;
return SASL_OK;
}
const char **clientout,
unsigned *clientoutlen,
{
*clientoutlen = 0;
case 1: {
const char *user;
int result;
/* check if sec layer strong enough */
#ifdef _INTEGRATED_SOLARIS_
gettext("SSF requested of LOGIN plugin"));
#else
#endif /* _INTEGRATED_SOLARIS_ */
return SASL_TOOWEAK;
}
/* try to get the userid */
/* Note: we want to grab the authname and not the userid, which is
* who we AUTHORIZE as, and will be the same as the authname
* for the LOGIN mech.
*/
return auth_result;
}
/* try to get the password */
return pass_result;
}
/* free prompts we got */
if (prompt_need && *prompt_need) {
*prompt_need = NULL;
}
/* if there are prompts not filled in */
/* make the prompt list */
result =
#ifdef _INTEGRATED_SOLARIS_
auth_result == SASL_INTERACT ?
NULL,
pass_result == SASL_INTERACT ?
#else
auth_result == SASL_INTERACT ?
"Please enter your authentication name" : NULL,
NULL,
pass_result == SASL_INTERACT ?
#endif /* _INTEGRATED_SOLARIS_ */
return SASL_INTERACT;
}
return SASL_BADPARAM;
}
/* server should have sent request for username - we ignore it */
if (!serverin) {
#ifdef _SUN_SDK_
"Server didn't issue challenge for USERNAME");
#else
"Server didn't issue challenge for USERNAME");
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
if (!clientout) {
return SASL_BADPARAM;
}
return SASL_CONTINUE;
}
case 2:
/* server should have sent request for password - we ignore it */
if (!serverin) {
#ifdef _SUN_SDK_
"Server didn't issue challenge for PASSWORD");
#else
"Server didn't issue challenge for PASSWORD");
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
if (!clientout) {
return SASL_BADPARAM;
}
/* set oparams */
oparams->param_version = 0;
return SASL_OK;
default:
return SASL_FAIL;
}
return SASL_FAIL; /* should never get here */
}
const sasl_utils_t *utils)
{
if (!text) return;
/* free sensitive info */
#ifdef _INTEGRATED_SOLARIS_
#endif /* _INTEGRATED_SOLARIS_ */
}
{
{
"LOGIN", /* mech_name */
0, /* max_ssf */
SASL_SEC_NOANONYMOUS, /* security_flags */
SASL_FEAT_SERVER_FIRST, /* features */
NULL, /* required_prompts */
NULL, /* glob_context */
&login_client_mech_new, /* mech_new */
&login_client_mech_step, /* mech_step */
&login_client_mech_dispose, /* mech_dispose */
NULL, /* mech_free */
NULL, /* idle */
NULL, /* spare */
NULL /* spare */
}
};
int maxversion,
int *out_version,
int *plugcount)
{
if (maxversion < SASL_CLIENT_PLUG_VERSION) {
return SASL_BADVERS;
}
*plugcount = 1;
return SASL_OK;
}