1/*++
2/* NAME
3/*	xsasl_cyrus_log 3
4/* SUMMARY
5/*	Cyrus SASL logging call-back routine
6/* SYNOPSIS
7/*	#include <xsasl_cyrus_common.h>
8/*
9/*	int	xsasl_cyrus_log(context, priority, text)
10/*	void	*context;
11/*	int	priority;
12/*	const char *text;
13/* DESCRIPTION
14/*	xsasl_cyrus_log() logs a Cyrus message.
15/* DIAGNOSTICS:
16/*	Fatal: out of memory.
17/* LICENSE
18/* .ad
19/* .fi
20/*	The Secure Mailer license must be distributed with this software.
21/* AUTHOR(S)
22/*	Wietse Venema
23/*	IBM T.J. Watson Research
24/*	P.O. Box 704
25/*	Yorktown Heights, NY 10598, USA
26/*--*/
27
28/* System library. */
29
30#include <sys_defs.h>
31
32/* Utility library. */
33
34#include <msg.h>
35
36/* Application-specific */
37
38#include <xsasl_cyrus_common.h>
39
40#if defined(USE_SASL_AUTH) && defined(USE_CYRUS_SASL)
41
42#include <sasl.h>
43#include <saslutil.h>
44
45/* xsasl_cyrus_log - logging callback */
46
47int     xsasl_cyrus_log(void *unused_context, int priority,
48			        const char *message)
49{
50    switch (priority) {
51	case SASL_LOG_ERR:		/* unusual errors */
52#ifdef SASL_LOG_WARN			/* non-fatal warnings (Cyrus-SASL v2) */
53	case SASL_LOG_WARN:
54#endif
55#ifdef SASL_LOG_WARNING			/* non-fatal warnings (Cyrus-SASL v1) */
56	case SASL_LOG_WARNING:
57#endif
58	msg_warn("SASL authentication problem: %s", message);
59	break;
60#ifdef SASL_LOG_INFO
61    case SASL_LOG_INFO:			/* other info (Cyrus-SASL v1) */
62	if (msg_verbose)
63	    msg_info("SASL authentication info: %s", message);
64	break;
65#endif
66#ifdef SASL_LOG_NOTE
67    case SASL_LOG_NOTE:			/* other info (Cyrus-SASL v2) */
68	if (msg_verbose)
69	    msg_info("SASL authentication info: %s", message);
70	break;
71#endif
72#ifdef SASL_LOG_FAIL
73    case SASL_LOG_FAIL:			/* authentication failures
74						 * (Cyrus-SASL v2) */
75	msg_warn("SASL authentication failure: %s", message);
76	break;
77#endif
78#ifdef SASL_LOG_DEBUG
79    case SASL_LOG_DEBUG:			/* more verbose than LOG_NOTE
80						 * (Cyrus-SASL v2) */
81	if (msg_verbose > 1)
82	    msg_info("SASL authentication debug: %s", message);
83	break;
84#endif
85#ifdef SASL_LOG_TRACE
86    case SASL_LOG_TRACE:			/* traces of internal
87						 * protocols (Cyrus-SASL v2) */
88	if (msg_verbose > 1)
89	    msg_info("SASL authentication trace: %s", message);
90	break;
91#endif
92#ifdef SASL_LOG_PASS
93    case SASL_LOG_PASS:			/* traces of internal
94						 * protocols, including
95						 * passwords (Cyrus-SASL v2) */
96	if (msg_verbose > 1)
97	    msg_info("SASL authentication pass: %s", message);
98	break;
99#endif
100    }
101    return (SASL_OK);
102}
103
104#endif
105