Imported Upstream version 2.4.3
[platform/upstream/audit.git] / auparse / message.c
1 /* message.c --
2  * Copyright 2004, 2005 Red Hat Inc., Durham, North Carolina.
3  * All Rights Reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * Authors:
20  *      Steve Grubb <sgrubb@redhat.com>
21  */
22
23 #include "config.h"
24 #include <stdio.h>
25 #include <stdarg.h>
26 #include "libaudit.h"
27 #include "private.h"
28
29 /* The message mode refers to where informational messages go
30    0 - stderr, 1 - syslog, 2 - quiet. The default is quiet. */
31 static message_t message_mode = MSG_QUIET;
32 static debug_message_t debug_message = DBG_NO;
33
34 void set_aumessage_mode(message_t mode, debug_message_t debug)
35 {
36         message_mode = mode;
37         debug_message = debug;
38 }
39
40 void audit_msg(int priority, const char *fmt, ...)
41 {
42         va_list   ap;
43
44         if (message_mode == MSG_QUIET)
45                 return;
46
47         if (priority == LOG_DEBUG && debug_message == DBG_NO)
48                 return;
49
50         va_start(ap, fmt);
51         if (message_mode == MSG_SYSLOG)
52                 vsyslog(priority, fmt, ap);
53         else {
54                 vfprintf(stderr, fmt, ap);
55                 fputc('\n', stderr);
56         }
57         va_end( ap );
58 }