/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* seterror.c - sasl_seterror split out because glue libraries
* can't pass varargs lists
* Rob Siemborski
* Tim Martin
* split from common.c by Rolf Braun
* $Id: seterror.c,v 1.7 2003/02/13 19:55:55 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 <stdlib.h>
#include <limits.h>
#ifdef HAVE_SYSLOG
#include <syslog.h>
#endif
#include <stdarg.h>
#include <ctype.h>
#include <sasl.h>
#include <saslutil.h>
#include <saslplug.h>
#include "saslint.h"
#ifdef WIN32
/* need to handle the fact that errno has been defined as a function
in a dll, not an extern int */
# ifdef errno
# endif /* errno */
#endif /* WIN32 */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef _SUN_SDK_
#include "plugin_common.h"
#include <wchar.h>
#endif /* _SUN_SDK_ */
/* this is apparently no longer a user function */
{
/* Hide the difference in a username failure and a password failure */
if (saslerr == SASL_NOUSER)
return SASL_BADAUTH;
/* otherwise return the error given; no transform necessary */
return saslerr;
}
/* set the error string which will be returned by sasl_errdetail() using
* syslog()-style formatting (e.g. printf-style with %m as the string form
* of an errno error)
*
* primarily for use by server callbacks such as the sasl_authorize_t
* callback and internally to plug-ins
*
* This will also trigger a call to the SASL logging callback (if any)
* with a level of SASL_LOG_FAIL unless the SASL_NOLOG flag is set.
*
* Messages should be sensitive to the current language setting. If there
* is no SASL_CB_LANGUAGE callback messages MUST be US-ASCII otherwise UTF-8
* is used and use of RFC 2482 for mixed-language text is encouraged.
*
* if conn is NULL, function does nothing
*/
unsigned flags,
const char *fmt, ...)
{
int formatlen;
int result;
void *log_ctx;
int ival;
char *cval;
char **error_buf;
#ifdef _SUN_SDK_
#endif /* _SUN_SDK_ */
#ifdef _INTEGRATED_SOLARIS_
void *simple_context;
int ret;
int char_len;
char *utf8_buf;
int is_client;
#endif /* _INTEGRATED_SOLARIS_ */
if(!conn) {
#ifndef SASL_OSX_CFMGLUE
if(!(flags & SASL_NOLOG)) {
/* See if we have a logging callback... */
return;
"No sasl_conn_t passed to sasl_seterror");
}
#endif /* SASL_OSX_CFMGLUE */
return;
} else if(!fmt) return;
#ifdef _SUN_SDK_
#endif /* _SUN_SDK_ */
#ifdef _INTEGRATED_SOLARIS_
is_client = 0;
is_client = 1;
} else
}
#endif /* _INTEGRATED_SOLARIS_ */
/* we need to use a back end function to get the buffer because the
cfm glue can't be rooting around in the internal structs */
{
{
#ifdef _INTEGRATED_SOLARIS_
return;
while (char_len-- > 0) {
outlen++;
pos++;
}
#else
return;
outlen++;
pos++;
#endif /* _INTEGRATED_SOLARIS_ */
} else { /* formating thing */
int done=0;
frmt[0]='%';
pos++;
while (done==0)
{
{
case 's': /* need to handle this */
return;
done=1;
break;
case '%': /* double % output the '%' character */
return;
outlen++;
done=1;
break;
case 'm': /* insert the errno string */
&outlen,
return;
done=1;
break;
case 'z': /* insert the sasl error string */
#ifdef _INTEGRATED_SOLARIS_
(char *)sasl_errstring(_sasl_seterror_usererr(
#else
(char *)sasl_errstring(_sasl_seterror_usererr(
#endif /* _INTEGRATED_SOLARIS_ */
return;
done=1;
break;
case 'c':
#ifndef _SUN_SDK_
#endif /* _SUN_SDK_ */
/* now add the character */
return;
done=1;
break;
case 'd':
case 'i':
/* now add the string */
return;
done=1;
break;
default:
#ifdef _SUN_SDK_
#else
if (frmtpos>9)
#endif /* _SUN_SDK_ */
done=1;
}
pos++;
done=1;
}
}
}
#ifdef _INTEGRATED_SOLARIS_
if (outlen >= *error_buf_len)
return;
}
}
}
#endif /* _INTEGRATED_SOLARIS_ */
#ifndef SASL_OSX_CFMGLUE
if(!(flags & SASL_NOLOG)) {
/* See if we have a logging callback... */
return;
}
#endif /* SASL_OSX_CFMGLUE */
}