Imported Upstream version 2.4.3
[platform/upstream/audit.git] / lib / deprecated.c
1 /* deprecated.c -- This file is the trash heap of things about to leave 
2  * Copyright 2006-07,2009 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 <errno.h>
25 #include <string.h>
26 #include <pwd.h>
27 #include <grp.h>
28 #include <ctype.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31
32 #include "libaudit.h"
33 #include "private.h"
34
35 /*
36  * This function will send a user space message to the kernel.
37  * It returns the sequence number which is > 0 on success  
38  * or <= 0 on error. (pam uses this) This is the main audit sending
39  * function now.
40  */
41 int audit_send_user_message(int fd, int type, hide_t hide_error,
42         const char *message)
43 {
44         int retry_cnt = 0;
45         int rc;
46 retry:
47         rc = audit_send(fd, type, message, strlen(message)+1);
48         if (rc == -ECONNREFUSED) {
49                 /* This is here to let people that build their own kernel
50                    and disable the audit system get in. ECONNREFUSED is
51                    issued by the kernel when there is "no on listening". */
52                 return 0;
53         } else if (rc == -EPERM && getuid() != 0 && hide_error == HIDE_IT) {
54                 /* If we get this, then the kernel supports auditing
55                  * but we don't have enough privilege to write to the
56                  * socket. Therefore, we have already been authenticated
57                  * and we are a common user. Just act as though auditing
58                  * is not enabled. Any other error we take seriously.
59                  * This is here basically to satisfy Xscreensaver. */
60                 return 0;
61         } else if (rc == -EINVAL) {
62                 /* If we get this, the kernel doesn't understand the
63                  * netlink message type. This is most likely due to
64                  * being an old kernel. Use the old message type. */
65                 if (type >= AUDIT_FIRST_USER_MSG && 
66                                 type <= AUDIT_LAST_USER_MSG && !retry_cnt) {
67
68                         /* do retry */
69                         type = AUDIT_USER;
70                         retry_cnt++;
71                         goto retry;
72                 } 
73         }
74         return rc;
75 }
76 hidden_def(audit_send_user_message)
77