xref: /titanic_41/usr/src/lib/libbsm/common/audit_mountd.c (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 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 extern int _mutex_lock(mutex_t *);
55 extern int _mutex_unlock(mutex_t *);
56 
57 /*
58  * This setup call is made only once at the start of mountd.
59  * The call sets the auditing state off if appropriate, and is
60  * made in single threaded code, hence no locking is required.
61  */
62 void
63 audit_mountd_setup()
64 {
65 	dprintf(("audit_mountd_setup()\n"));
66 
67 
68 	if (cannot_audit(0))
69 		cannotaudit = 1;
70 }
71 
72 void
73 audit_mountd_mount(clname, path, sorf)
74 char	*clname;	/* client name */
75 char	*path;		/* mount path */
76 int	sorf;		/* flag for success or failure */
77 {
78 	uint32_t buf[4], type;
79 	dprintf(("audit_mountd_mount()\n"));
80 
81 	if (cannotaudit)
82 		return;
83 
84 	(void) _mutex_lock(&audit_mountd_lock);
85 
86 	(void) aug_save_namask();
87 
88 	(void) aug_save_me();
89 	aug_save_event(AUE_mountd_mount);
90 	aug_save_sorf(sorf);
91 	aug_save_text(clname);
92 	aug_save_path(path);
93 	(void) aug_get_machine(clname, buf, &type);
94 	aug_save_tid_ex(aug_get_port(), buf, type);
95 	(void) aug_audit();
96 	(void) _mutex_unlock(&audit_mountd_lock);
97 }
98 
99 void
100 audit_mountd_umount(clname, path)
101 char	*clname;	/* client name */
102 char	*path;		/* mount path */
103 {
104 	uint32_t buf[4], type;
105 
106 	dprintf(("audit_mountd_mount()\n"));
107 
108 	if (cannotaudit)
109 		return;
110 
111 	(void) _mutex_lock(&audit_mountd_lock);
112 
113 	(void) aug_save_namask();
114 
115 	(void) aug_save_me();
116 	aug_save_event(AUE_mountd_umount);
117 	aug_save_sorf(0);
118 	aug_save_text(clname);
119 	aug_save_path(path);
120 	(void) aug_get_machine(clname, buf, &type);
121 	aug_save_tid_ex(aug_get_port(), buf, type);
122 	(void) aug_audit();
123 	(void) _mutex_unlock(&audit_mountd_lock);
124 }
125