* SUCH DAMAGE.
*/
+#if defined(_MSC_VER)
+# pragma warning(disable: 4646)
+# pragma warning(disable: 4716)
+#endif
+
#include "krb5_locl.h"
#include <err.h>
static krb5_error_code _warnerr(krb5_context context, int do_errtext,
krb5_error_code code, int level, const char *fmt, va_list ap)
- __attribute__((__format__(__printf__, 5, 0)));
+ __attribute__ ((__format__ (__printf__, 5, 0)));
static krb5_error_code
_warnerr(krb5_context context, int do_errtext,
krb5_error_code code, int level, const char *fmt, va_list ap)
{
- char xfmt[7] = "";
- const char *args[2], **arg;
- char *msg = NULL;
- const char *err_str = NULL;
- krb5_error_code ret;
-
- args[0] = args[1] = NULL;
- arg = args;
- if(fmt){
- strlcat(xfmt, "%s", sizeof(xfmt));
- if(do_errtext)
- strlcat(xfmt, ": ", sizeof(xfmt));
- ret = vasprintf(&msg, fmt, ap);
- if(ret < 0 || msg == NULL)
- return ENOMEM;
- *arg++ = msg;
- }
- if(context && do_errtext){
- strlcat(xfmt, "%s", sizeof(xfmt));
-
- err_str = krb5_get_error_message(context, code);
- if (err_str != NULL) {
- *arg = err_str;
- } else {
- *arg= "<unknown error>";
- }
- }
-
- if(context && context->warn_dest)
- krb5_log(context, context->warn_dest, level, xfmt, args[0], args[1]);
+ if (do_errtext)
+ return heim_vwarn(context ? context->hcontext : NULL, code, fmt, ap);
else
- warnx(xfmt, args[0], args[1]);
- free(msg);
- krb5_free_error_message(context, err_str);
- return 0;
+ return heim_vwarnx(context ? context->hcontext : NULL, fmt, ap);
}
-#define FUNC(ETEXT, CODE, LEVEL) \
- krb5_error_code ret; \
- va_list ap; \
- va_start(ap, fmt); \
- ret = _warnerr(context, ETEXT, CODE, LEVEL, fmt, ap); \
+#define FUNC_NORET(ETEXT, CODE, LEVEL) \
+ va_list ap; \
+ va_start(ap, fmt); \
+ (void) _warnerr(context, ETEXT, CODE, LEVEL, fmt, ap); \
va_end(ap);
#undef __attribute__
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_vwarn(krb5_context context, krb5_error_code code,
const char *fmt, va_list ap)
- __attribute__ ((format (printf, 3, 0)))
+ __attribute__ ((__format__ (__printf__, 3, 0)))
{
- return _warnerr(context, 1, code, 1, fmt, ap);
+ return heim_vwarn(context ? context->hcontext : NULL, code, fmt, ap);
}
/**
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_warn(krb5_context context, krb5_error_code code, const char *fmt, ...)
- __attribute__ ((format (printf, 3, 4)))
+ __attribute__ ((__format__ (__printf__, 3, 4)))
{
- FUNC(1, code, 1);
+ krb5_error_code ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = krb5_vwarn(context, code, fmt, ap);
+ va_end(ap);
return ret;
}
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_vwarnx(krb5_context context, const char *fmt, va_list ap)
- __attribute__ ((format (printf, 2, 0)))
+ __attribute__ ((__format__ (__printf__, 2, 0)))
{
- return _warnerr(context, 0, 0, 1, fmt, ap);
+ return heim_vwarnx(context ? context->hcontext : NULL, fmt, ap);
}
/**
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_warnx(krb5_context context, const char *fmt, ...)
- __attribute__ ((format (printf, 2, 3)))
+ __attribute__ ((__format__ (__printf__, 2, 3)))
{
- FUNC(0, 0, 1);
+ krb5_error_code ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = krb5_vwarnx(context, fmt, ap);
+ va_end(ap);
return ret;
}
* @ingroup krb5_error
*/
-KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
+KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_verr(krb5_context context, int eval, krb5_error_code code,
const char *fmt, va_list ap)
- __attribute__ ((noreturn, format (printf, 4, 0)))
+ __attribute__ ((__noreturn__, __format__ (__printf__, 4, 0)))
{
_warnerr(context, 1, code, 0, fmt, ap);
exit(eval);
* @ingroup krb5_error
*/
-KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
+KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_err(krb5_context context, int eval, krb5_error_code code,
const char *fmt, ...)
- __attribute__ ((noreturn, format (printf, 4, 5)))
+ __attribute__ ((__noreturn__, __format__ (__printf__, 4, 5)))
{
- FUNC(1, code, 0);
+ FUNC_NORET(1, code, 0);
exit(eval);
UNREACHABLE(return 0);
}
* @ingroup krb5_error
*/
-KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
+KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_verrx(krb5_context context, int eval, const char *fmt, va_list ap)
- __attribute__ ((noreturn, format (printf, 3, 0)))
+ __attribute__ ((__noreturn__, __format__ (__printf__, 3, 0)))
{
_warnerr(context, 0, 0, 0, fmt, ap);
exit(eval);
* @ingroup krb5_error
*/
-KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
+KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_errx(krb5_context context, int eval, const char *fmt, ...)
- __attribute__ ((noreturn, format (printf, 3, 4)))
+ __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)))
{
- FUNC(0, 0, 0);
+ FUNC_NORET(0, 0, 0);
exit(eval);
UNREACHABLE(return 0);
}
* @ingroup krb5_error
*/
-KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
+KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_vabort(krb5_context context, krb5_error_code code,
const char *fmt, va_list ap)
- __attribute__ ((noreturn, format (printf, 3, 0)))
+ __attribute__ ((__noreturn__, __format__ (__printf__, 3, 0)))
{
_warnerr(context, 1, code, 0, fmt, ap);
abort();
* @param context A Kerberos 5 context
* @param code error code of the last error
* @param fmt message to print
+ * @param ... arguments for format string
*
* @ingroup krb5_error
*/
-KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
+KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_abort(krb5_context context, krb5_error_code code, const char *fmt, ...)
- __attribute__ ((noreturn, format (printf, 3, 4)))
+ __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)))
{
- FUNC(1, code, 0);
+ FUNC_NORET(1, code, 0);
abort();
UNREACHABLE(return 0);
}
-KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
+KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_vabortx(krb5_context context, const char *fmt, va_list ap)
- __attribute__ ((noreturn, format (printf, 2, 0)))
+ __attribute__ ((__noreturn__, __format__ (__printf__, 2, 0)))
{
_warnerr(context, 0, 0, 0, fmt, ap);
abort();
* Log a warning to the log, default stderr, and then abort.
*
* @param context A Kerberos 5 context
- * @param code error code of the last error
- * @param fmt message to print
+ * @param fmt printf format string of message to print
+ * @param ... arguments for format string
*
* @ingroup krb5_error
*/
-KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
+KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_abortx(krb5_context context, const char *fmt, ...)
- __attribute__ ((noreturn, format (printf, 2, 3)))
+ __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3)))
{
- FUNC(0, 0, 0);
+ FUNC_NORET(0, 0, 0);
abort();
UNREACHABLE(return 0);
}
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_set_warn_dest(krb5_context context, krb5_log_facility *fac)
{
- context->warn_dest = fac;
- return 0;
+ return heim_set_warn_dest(context->hcontext, fac);
}
/**
KRB5_LIB_FUNCTION krb5_log_facility * KRB5_LIB_CALL
krb5_get_warn_dest(krb5_context context)
{
- return context->warn_dest;
+ return heim_get_warn_dest(context->hcontext);
}