xref: /titanic_51/usr/src/lib/libbsm/common/audit_mountd.c (revision 8c95159466b445c16660b550063d080ca9868cb5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  */
27 
28 #include <sys/types.h>
29 #include <stdio.h>
30 #include <sys/fcntl.h>
31 #include <bsm/audit.h>
32 #include <bsm/audit_record.h>
33 #include <bsm/audit_uevents.h>
34 #include <bsm/libbsm.h>
35 #include <bsm/audit_private.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <syslog.h>
39 #include <netinet/in.h>
40 #include <unistd.h>
41 #include <synch.h>
42 #include <generic.h>
43 
44 #ifdef C2_DEBUG2
45 #define	dprintf(x) { (void) printf x; }
46 #else
47 #define	dprintf(x)
48 #endif
49 
50 static mutex_t audit_mountd_lock = DEFAULTMUTEX;
51 static int cannotaudit = 0;
52 
53 /*
54  * This setup call is made only once at the start of mountd.
55  * The call sets the auditing state off if appropriate, and is
56  * made in single threaded code, hence no locking is required.
57  */
58 void
59 audit_mountd_setup()
60 {
61 	dprintf(("audit_mountd_setup()\n"));
62 
63 
64 	if (cannot_audit(0))
65 		cannotaudit = 1;
66 }
67 
68 void
69 audit_mountd_mount(clname, path, sorf)
70 char	*clname;	/* client name */
71 char	*path;		/* mount path */
72 int	sorf;		/* flag for success or failure */
73 {
74 	uint32_t buf[4], type;
75 	dprintf(("audit_mountd_mount()\n"));
76 
77 	if (cannotaudit)
78 		return;
79 
80 	(void) mutex_lock(&audit_mountd_lock);
81 
82 	(void) aug_save_namask();
83 
84 	(void) aug_save_me();
85 	aug_save_event(AUE_mountd_mount);
86 	aug_save_sorf(sorf);
87 	aug_save_text(clname);
88 	aug_save_path(path);
89 	(void) aug_get_machine(clname, buf, &type);
90 	aug_save_tid_ex(aug_get_port(), buf, type);
91 	(void) aug_audit();
92 	(void) mutex_unlock(&audit_mountd_lock);
93 }
94 
95 void
96 audit_mountd_umount(clname, path)
97 char	*clname;	/* client name */
98 char	*path;		/* mount path */
99 {
100 	uint32_t buf[4], type;
101 
102 	dprintf(("audit_mountd_mount()\n"));
103 
104 	if (cannotaudit)
105 		return;
106 
107 	(void) mutex_lock(&audit_mountd_lock);
108 
109 	(void) aug_save_namask();
110 
111 	(void) aug_save_me();
112 	aug_save_event(AUE_mountd_umount);
113 	aug_save_sorf(0);
114 	aug_save_text(clname);
115 	aug_save_path(path);
116 	(void) aug_get_machine(clname, buf, &type);
117 	aug_save_tid_ex(aug_get_port(), buf, type);
118 	(void) aug_audit();
119 	(void) mutex_unlock(&audit_mountd_lock);
120 }
121