/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Plain SASL plugin
* Rob Siemborski
* Tim Martin
* $Id: plain.c,v 1.61 2003/03/26 17:18: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 <string.h>
#include <sasl.h>
#include <saslplug.h>
#include "plugin_common.h"
#ifndef _SUN_SDK_
#ifdef WIN32
/* This must be after sasl.h */
# include "saslPLAIN.h"
#endif /* WIN32 */
#endif /* !_SUN_SDK_ */
#ifdef macintosh
#include <sasl_plain_plugin_decl.h>
#endif
/***************************** Common Section *****************************/
#ifndef _SUN_SDK_
#endif /* !_SUN_SDK_ */
/***************************** Server Section *****************************/
void **conn_context)
{
/* holds state are in */
if (!conn_context) {
return SASL_BADPARAM;
}
*conn_context = NULL;
return SASL_OK;
}
const char *clientin,
unsigned clientinlen,
const char **serverout,
unsigned *serveroutlen,
{
const char *author;
const char *authen;
const char *password;
unsigned lup=0;
int result;
char *passcopy;
*serveroutlen = 0;
/* should have received author-id NUL authen-id NUL password */
/* get author */
if (lup >= clientinlen) {
#ifdef _SUN_SDK_
"Can only find author (no password)");
#else
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
/* get authen */
++lup;
if (lup >= clientinlen) {
#ifdef _SUN_SDK_
#else
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
/* get password */
lup++;
if (lup != clientinlen) {
#ifdef _SUN_SDK_
"Got more data than we were expecting in the PLAIN plugin");
#else
"Got more data than we were expecting in the PLAIN plugin\n");
#endif /* _SUN_SDK_ */
return SASL_BADPROT;
}
/* this kinda sucks. we need password to be null terminated
but we can't assume there is an allocated byte at the end
of password so we have to copy it */
return SASL_NOMEM;
}
/* Canonicalize userid first, so that password verification is only
* against the canonical id */
return result;
}
/* verify password - return sasl_ok on success*/
#ifdef _INTEGRATED_SOLARIS_
gettext("Password verification failed"));
#else
"Password verification failed");
#endif /* _INTEGRATED_SOLARIS_ */
return result;
}
/* Canonicalize and store the authorization ID */
/* We need to do this after calling verify_user just in case verify_user
* needed to get auxprops itself */
/* Transition? */
if (params->transition) {
}
/* set oparams */
oparams->param_version = 0;
return SASL_OK;
}
{
{
"PLAIN", /* mech_name */
0, /* max_ssf */
SASL_SEC_NOANONYMOUS, /* security_flags */
| SASL_FEAT_ALLOWS_PROXY, /* features */
NULL, /* glob_context */
&plain_server_mech_new, /* mech_new */
&plain_server_mech_step, /* mech_step */
NULL, /* 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 {
char *out_buf;
unsigned out_buf_len;
#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,
{
int result;
*clientoutlen = 0;
/* doesn't really matter how the server responds */
/* check if sec layer strong enough */
#ifdef _INTEGRATED_SOLARIS_
#else
#endif /* _INTEGRATED_SOLARIS_ */
return SASL_TOOWEAK;
}
/* try to get the authid */
return auth_result;
}
/* try to get the userid */
return user_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 */
(pass_result == SASL_INTERACT)) {
/* make the prompt list */
result =
#ifdef _INTEGRATED_SOLARIS_
user_result == SASL_INTERACT ?
gettext("Please enter your authorization name"))
: NULL,
NULL,
auth_result == SASL_INTERACT ?
gettext("Please enter your authentication name"))
: NULL,
NULL,
pass_result == SASL_INTERACT ?
NULL,
#else
user_result == SASL_INTERACT ?
"Please enter your authorization name" : NULL,
NULL,
auth_result == SASL_INTERACT ?
"Please enter your authentication name" : NULL,
NULL,
pass_result == SASL_INTERACT ?
#endif /* _INTEGRATED_SOLARIS_ */
return SASL_INTERACT;
}
if (!password) {
return SASL_BADPARAM;
}
}
else {
}
/* send authorized id NUL authentication id NUL password */
/* remember the extra NUL on the end for stupid clients */
/* set oparams */
oparams->param_version = 0;
/* free sensitive info */
return result;
}
const sasl_utils_t *utils)
{
if (!text) return;
#ifdef _INTEGRATED_SOLARIS_
#endif /* _INTEGRATED_SOLARIS_ */
}
{
{
"PLAIN", /* mech_name */
0, /* max_ssf */
SASL_SEC_NOANONYMOUS, /* security_flags */
| SASL_FEAT_ALLOWS_PROXY, /* features */
NULL, /* required_prompts */
NULL, /* glob_context */
&plain_client_mech_new, /* mech_new */
&plain_client_mech_step, /* mech_step */
&plain_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;
}