|
|
@ -18,10 +18,27 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include <syslog.h> |
|
|
|
#include <stdarg.h> |
|
|
|
#include "conf.h" |
|
|
|
#include "log.h" |
|
|
|
|
|
|
|
static t_pusb_options *pusb_opts = NULL; |
|
|
|
|
|
|
|
static void pusb_log_syslog(int level, const char *format, va_list ap) |
|
|
|
{ |
|
|
|
if ((pusb_opts && !pusb_opts->quiet) || |
|
|
|
level == LOG_ERR) |
|
|
|
{ |
|
|
|
if (pusb_opts && pusb_opts->color_log) |
|
|
|
{ |
|
|
|
if (level == LOG_ERR) |
|
|
|
fprintf(stderr, "\033[01;31m*\033[00m "); |
|
|
|
else if (level == LOG_NOTICE) |
|
|
|
fprintf(stderr, "\033[01;32m*\033[00m "); |
|
|
|
} |
|
|
|
else |
|
|
|
fprintf(stderr, "* "); |
|
|
|
vfprintf(stderr, format, ap); |
|
|
|
} |
|
|
|
openlog("pam_usb", LOG_PID, LOG_AUTH); |
|
|
|
vsyslog(level, format, ap); |
|
|
|
closelog(); |
|
|
@ -31,7 +48,9 @@ void __log_debug(const char *file, int line, const char *fmt, ...) |
|
|
|
{ |
|
|
|
va_list ap; |
|
|
|
|
|
|
|
fprintf(stderr, "\033[01;34m*\033[00m [%s:%03d] ", file, line); |
|
|
|
if (!pusb_opts || !pusb_opts->debug) |
|
|
|
return ; |
|
|
|
fprintf(stderr, "[%s:%03d] ", file, line); |
|
|
|
va_start(ap, fmt); |
|
|
|
vfprintf(stderr, fmt, ap); |
|
|
|
va_end(ap); |
|
|
@ -41,10 +60,6 @@ void log_error(const char *fmt, ...) |
|
|
|
{ |
|
|
|
va_list ap; |
|
|
|
|
|
|
|
fprintf(stderr, "\033[01;31m*\033[00m "); |
|
|
|
va_start(ap, fmt); |
|
|
|
vfprintf(stderr, fmt, ap); |
|
|
|
va_end(ap); |
|
|
|
va_start(ap, fmt); |
|
|
|
pusb_log_syslog(LOG_ERR, fmt, ap); |
|
|
|
va_end(ap); |
|
|
@ -54,11 +69,12 @@ void log_info(const char *fmt, ...) |
|
|
|
{ |
|
|
|
va_list ap; |
|
|
|
|
|
|
|
fprintf(stderr, "\033[01;32m*\033[00m "); |
|
|
|
va_start(ap, fmt); |
|
|
|
vfprintf(stderr, fmt, ap); |
|
|
|
va_end(ap); |
|
|
|
va_start(ap, fmt); |
|
|
|
pusb_log_syslog(LOG_NOTICE, fmt, ap); |
|
|
|
va_end(ap); |
|
|
|
} |
|
|
|
|
|
|
|
void pusb_log_init(t_pusb_options *opts) |
|
|
|
{ |
|
|
|
pusb_opts = opts; |
|
|
|
} |