1 /*
2 * Copyright © Jan Engelhardt, 2006 - 2009
3 *
4 * This file is part of pam_mount; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 2.1
7 * of the License, or (at your option) any later version.
8 */
9 #include <assert.h>
10 #include <stdarg.h>
11 #include <stdbool.h>
12 #include <stdio.h>
13 #include <stdbool.h>
14 #include <syslog.h>
15 #include "pam_mount.h"
16
17 const char *pmtlog_prefix;
18 bool pmtlog_path[PMTLOG_SRCMAX][PMTLOG_DSTMAX];
19 unsigned int Debug = true;
20
21 /**
22 * misc_log - log an error/warning
23 * @format: printf(3)-style format specifier
24 *
25 * Do not call this function directly; use the l0g() macro instead, so that
26 * file name and line number show up.
27 */
misc_log(const char * format,...)28 int misc_log(const char *format, ...)
29 {
30 va_list args, arg2;
31 int ret = 0;
32
33 assert(format != NULL);
34
35 va_start(args, format);
36 va_copy(arg2, args);
37 if (pmtlog_path[PMTLOG_ERR][PMTLOG_STDERR])
38 ret = vfprintf(stderr, format, args);
39 if (pmtlog_path[PMTLOG_ERR][PMTLOG_SYSLOG])
40 vsyslog(LOG_AUTH | LOG_ERR, format, arg2);
41 va_end(args);
42 va_end(arg2);
43 return ret;
44 }
45
46 /**
47 * misc_warn - debug logger
48 * @format: printf(3)-style format specifier
49 *
50 * If debugging is turned on, the message is logged to syslog and %stderr.
51 * Use this for debugging messages.
52 *
53 * Do not call this function directly; use the w4rn() macro instead, so that
54 * file name and line number show up.
55 */
misc_warn(const char * format,...)56 int misc_warn(const char *format, ...)
57 {
58 va_list args, arg2;
59 int ret = 0;
60
61 assert(format != NULL);
62 if (!pmtlog_path[PMTLOG_DBG][PMTLOG_STDERR] &&
63 !pmtlog_path[PMTLOG_DBG][PMTLOG_SYSLOG])
64 return 0;
65
66 va_start(args, format);
67 va_copy(arg2, args);
68 if (pmtlog_path[PMTLOG_DBG][PMTLOG_STDERR])
69 ret = vfprintf(stderr, format, args);
70 if (pmtlog_path[PMTLOG_DBG][PMTLOG_SYSLOG])
71 vsyslog(LOG_AUTH | LOG_ERR, format, arg2);
72 va_end(args);
73 va_end(arg2);
74 return ret;
75 }
76