]> granicus.if.org Git - shadow/blob - libmisc/audit_help.c
* NEWS, libmisc/chowntty.c: Fix a race condition that could lead to
[shadow] / libmisc / audit_help.c
1 /*
2  * Copyright (c) 2005       , Red Hat, Inc.
3  * Copyright (c) 2005       , Tomasz Kłoczko
4  * Copyright (c) 2008       , Nicolas François
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the copyright holders or contributors may not be used to
16  *    endorse or promote products derived from this software without
17  *    specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
23  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 /*
33  *  Audit helper functions used throughout shadow
34  *
35  */
36
37 #include <config.h>
38
39 #ifdef WITH_AUDIT
40
41 #include <stdlib.h>
42 #include <syslog.h>
43 #include <stdarg.h>
44 #include <libaudit.h>
45 #include <errno.h>
46 #include <stdio.h>
47 #include "prototypes.h"
48 int audit_fd;
49
50 void audit_help_open (void)
51 {
52         audit_fd = audit_open ();
53         if (audit_fd < 0) {
54                 /* You get these only when the kernel doesn't have
55                  * audit compiled in. */
56                 if (errno == EINVAL || errno == EPROTONOSUPPORT ||
57                     errno == EAFNOSUPPORT)
58                         return;
59                 fprintf (stderr,
60                          _("Cannot open audit interface - aborting.\n"));
61                 exit (1);
62         }
63 }
64
65 /*
66  * This function will log a message to the audit system using a predefined
67  * message format. Parameter usage is as follows:
68  *
69  * type - type of message: AUDIT_USER_CHAUTHTOK for changing any account 
70  *        attributes.
71  * pgname - program's name
72  * op  -  operation. "adding user", "changing finger info", "deleting group"
73  * name - user's account or group name. If not available use NULL.
74  * id  -  uid or gid that the operation is being performed on. This is used
75  *        only when user is NULL.
76  * result - 1 is "success" and 0 is "failed"
77  */
78 void audit_logger (int type, const char *pgname, const char *op,
79                    const char *name, unsigned int id,
80                    shadow_audit_result result)
81 {
82         if (audit_fd < 0) {
83                 return;
84         } else {
85                 audit_log_acct_message (audit_fd, type, NULL, op, name, id,
86                                         NULL, NULL, NULL, (int) result);
87         }
88 }
89
90 #else                           /* WITH_AUDIT */
91 extern int errno;       /* warning: ANSI C forbids an empty source file */
92 #endif                          /* WITH_AUDIT */
93