xref: /titanic_41/usr/src/lib/libbsm/common/audit_mountd.c (revision 2a8d6eba033e4713ab12b61178f0513f1f075482)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <stdio.h>
31 #include <sys/fcntl.h>
32 #include <bsm/audit.h>
33 #include <bsm/audit_record.h>
34 #include <bsm/audit_uevents.h>
35 #include <bsm/libbsm.h>
36 #include <bsm/audit_private.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <syslog.h>
40 #include <netinet/in.h>
41 #include <unistd.h>
42 #include <synch.h>
43 #include <generic.h>
44 
45 #ifdef C2_DEBUG2
46 #define	dprintf(x) { printf x; }
47 #else
48 #define	dprintf(x)
49 #endif
50 
51 static mutex_t audit_mountd_lock = DEFAULTMUTEX;
52 static int cannotaudit = 0;
53 
54 /*
55  * This setup call is made only once at the start of mountd.
56  * The call sets the auditing state off if appropriate, and is
57  * made in single threaded code, hence no locking is required.
58  */
59 void
60 audit_mountd_setup()
61 {
62 	dprintf(("audit_mountd_setup()\n"));
63 
64 
65 	if (cannot_audit(0))
66 		cannotaudit = 1;
67 }
68 
69 void
70 audit_mountd_mount(clname, path, sorf)
71 char	*clname;	/* client name */
72 char	*path;		/* mount path */
73 int	sorf;		/* flag for success or failure */
74 {
75 	uint32_t buf[4], type;
76 	dprintf(("audit_mountd_mount()\n"));
77 
78 	if (cannotaudit)
79 		return;
80 
81 	(void) mutex_lock(&audit_mountd_lock);
82 
83 	(void) aug_save_namask();
84 
85 	(void) aug_save_me();
86 	aug_save_event(AUE_mountd_mount);
87 	aug_save_sorf(sorf);
88 	aug_save_text(clname);
89 	aug_save_path(path);
90 	(void) aug_get_machine(clname, buf, &type);
91 	aug_save_tid_ex(aug_get_port(), buf, type);
92 	(void) aug_audit();
93 	(void) mutex_unlock(&audit_mountd_lock);
94 }
95 
96 void
97 audit_mountd_umount(clname, path)
98 char	*clname;	/* client name */
99 char	*path;		/* mount path */
100 {
101 	uint32_t buf[4], type;
102 
103 	dprintf(("audit_mountd_mount()\n"));
104 
105 	if (cannotaudit)
106 		return;
107 
108 	(void) mutex_lock(&audit_mountd_lock);
109 
110 	(void) aug_save_namask();
111 
112 	(void) aug_save_me();
113 	aug_save_event(AUE_mountd_umount);
114 	aug_save_sorf(0);
115 	aug_save_text(clname);
116 	aug_save_path(path);
117 	(void) aug_get_machine(clname, buf, &type);
118 	aug_save_tid_ex(aug_get_port(), buf, type);
119 	(void) aug_audit();
120 	(void) mutex_unlock(&audit_mountd_lock);
121 }
122