/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* SASL server API implementation
* Rob Siemborski
* Tim Martin
* $Id: checkpw.c,v 1.62 2003/03/19 18:25:27 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>
/* checkpw stuff */
#include <stdio.h>
#include "sasl.h"
#include "saslutil.h"
#include "saslplug.h"
#include "saslint.h"
#include <assert.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <fcntl.h>
#ifdef USE_DOORS
#include <door.h>
#endif
#include <stdlib.h>
#ifndef WIN32
#include <strings.h>
#include <netdb.h>
#else
#include <string.h>
#endif
#include <ctype.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif /* HAVE_PWD_H */
#ifdef HAVE_SHADOW_H
#include <shadow.h>
#endif /* HAVE_SHADOW_H */
#if defined(HAVE_PWCHECK) || defined(HAVE_SASLAUTHD)
# include <errno.h>
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
extern int errno;
#endif
/* we store the following secret to check plaintext passwords:
*
* <salt> \0 <secret>
*
* where <secret> = MD5(<salt>, "sasldb", <pass>)
*/
#ifdef _SUN_SDK_
#else
static int _sasl_make_plain_secret(const char *salt,
#endif /* _SUN_SDK_ */
{
#ifdef _SUN_SDK_
sec_len * sizeof(char));
#else
sec_len * sizeof(char));
#endif /* _SUN_SDK_ */
return SASL_NOMEM;
}
_sasl_MD5Init(&ctx);
return SASL_OK;
}
/* erase & dispose of a sasl_secret_t
*/
const char *userstr,
const char *passwd,
{
#ifndef _SUN_SDK_
#endif /* !_SUN_SDK_ */
"*cmusaslsecretPLAIN",
NULL };
return SASL_BADPARAM;
/* We need to clear any previous results and re-canonify to
* ensure correctness */
/* ensure its requested */
if(result < 0)
return result;
if((!auxprop_values[0].name
return SASL_NOUSER;
/* It is possible for us to get useful information out of just
* the lookup, so we won't check that we have a password until now */
if(!passwd) {
ret = SASL_BADPARAM;
goto done;
}
/* At the point this has been called, the username has been canonified
* and we've done the auxprop lookup. This should be easy. */
if(auxprop_values[0].name
&& auxprop_values[0].values
&& auxprop_values[0].values[0]
/* We have a plaintext version and it matched! */
return SASL_OK;
#ifdef _SUN_SDK_
&construct);
#else
&construct);
#endif /* _SUN_SDK_ */
goto done;
}
/* password verified! */
} else {
/* passwords do not match */
ret = SASL_BADAUTH;
}
#ifdef _SUN_SDK_
#else
#endif /* _SUN_SDK_ */
} else {
/* passwords do not match */
ret = SASL_BADAUTH;
}
done:
#ifdef _SUN_SDK_
#else
#endif /* _SUN_SDK_ */
/* We're not going to erase the property here because other people
* may want it */
return ret;
}
#ifdef DO_SASL_CHECKAPOP
const char *userstr,
const char *challenge,
const char *response,
{
#ifndef _SUN_SDK_
#endif /* !_SUN_SDK_ */
int i;
/* We've done the auxprop lookup already (in our caller) */
/* sadly, APOP has no provision for storing secrets */
if(ret < 0) {
#ifdef _SUN_SDK_
#else
#endif /* _SUN_SDK_ */
goto done;
}
if(!auxprop_values[0].name ||
!auxprop_values[0].values ||
!auxprop_values[0].values[0]) {
#ifdef _INTEGRATED_SOLARIS_
#else
#endif /* _INTEGRATED_SOLARIS_ */
ret = SASL_NOUSER;
goto done;
}
_sasl_MD5Init(&ctx);
/* convert digest from binary to ASCII hex */
for (i = 0; i < 16; i++)
/* password verified! */
} else {
/* passwords do not match */
ret = SASL_BADAUTH;
}
done:
#ifdef _INTEGRATED_SOLARIS_
gettext("login incorrect"));
#else
"login incorrect");
#endif /* _INTEGRATED_SOLARIS_ */
#ifdef _SUN_SDK_
#else
#endif /* _SUN_SDK_ */
return ret;
}
#endif /* DO_SASL_CHECKAPOP */
#if defined(HAVE_PWCHECK) || defined(HAVE_SASLAUTHD)
/*
* Keep calling the writev() system call with 'fd', 'iov', and 'iovcnt'
* until all the data is written out or an error occurs.
*/
{
int n;
int i;
int written = 0;
static int iov_max =
#ifdef MAXIOV
#else
#ifdef IOV_MAX
#else
8192
#endif
#endif
;
for (;;) {
iov++;
iovcnt--;
}
if (n == -1) {
iov_max /= 2;
continue;
}
return -1;
}
written += n;
for (i = 0; i < iovcnt; i++) {
break;
}
}
}
}
#endif
#ifdef HAVE_PWCHECK
/* pwcheck daemon-authenticated login */
const char *userid,
const char *passwd,
const char *user_realm
__attribute__((unused)))
{
int s;
int r;
unsigned start, n;
if (s == -1) return errno;
if (r == -1) {
return SASL_FAIL;
}
start = 0;
if (n < 1) break;
start += n;
}
close(s);
return SASL_OK;
}
return SASL_BADAUTH;
}
#endif
#ifdef HAVE_SASLAUTHD
/*
* Keep calling the read() system call with 'fd', 'buf', and 'nbyte'
* until all the data is read in or an error occurs.
*/
{
int n;
int nread = 0;
if (nbyte == 0) return 0;
for (;;) {
if (n == -1 || n == 0) {
return -1;
}
nread += n;
buf += n;
nbyte -= n;
}
}
/* saslauthd-authenticated login */
const char *userid,
const char *passwd,
const char *service,
const char *user_realm)
{
int s;
void *context;
const char *p = NULL;
#ifdef USE_DOORS
#endif
/* check to see if the user configured a rundir */
}
if (p) {
} else {
return SASL_FAIL;
}
/*
* build request of the form:
*
* count authid count password count service count realm
*/
{
/* request just too damn big */
return SASL_FAIL;
}
query_end += sizeof(unsigned short);
query_end += sizeof(unsigned short);
query_end += sizeof(unsigned short);
query_end += sizeof(unsigned short);
}
#ifdef USE_DOORS
if (s < 0) {
return SASL_FAIL;
}
/* oh damn, we got back a really long response */
return SASL_FAIL;
}
close(s);
#else
/* unix sockets */
if (s == -1) {
return SASL_FAIL;
}
{
if (r == -1) {
return SASL_FAIL;
}
}
{
return SASL_FAIL;
}
}
{
unsigned short count = 0;
/*
* read response of the form:
*
* count result
*/
return SASL_FAIL;
}
close(s);
return SASL_FAIL;
}
close(s);
return SASL_FAIL;
}
}
close(s);
#endif /* USE_DOORS */
return SASL_OK;
}
return SASL_BADAUTH;
}
#endif
#ifdef HAVE_ALWAYSTRUE
const char *userstr,
{
userstr);
return SASL_OK;
}
#endif
{ "auxprop", &auxprop_verify_password },
#ifdef HAVE_PWCHECK
{ "pwcheck", &pwcheck_verify_password },
#endif
#ifdef HAVE_SASLAUTHD
{ "saslauthd", &saslauthd_verify_password },
#endif
#ifdef HAVE_ALWAYSTRUE
{ "alwaystrue", &always_true },
#endif
};