xref: /onnv-gate/usr/src/lib/libbsm/common/audit_mountd.c (revision 11706:cd830a066051)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56812Sraf  * Common Development and Distribution License (the "License").
66812Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
216812Sraf 
220Sstevel@tonic-gate /*
23*11706SJan.Friedel@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
25*11706SJan.Friedel@Sun.COM  *
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <stdio.h>
300Sstevel@tonic-gate #include <sys/fcntl.h>
310Sstevel@tonic-gate #include <bsm/audit.h>
320Sstevel@tonic-gate #include <bsm/audit_record.h>
330Sstevel@tonic-gate #include <bsm/audit_uevents.h>
340Sstevel@tonic-gate #include <bsm/libbsm.h>
350Sstevel@tonic-gate #include <bsm/audit_private.h>
360Sstevel@tonic-gate #include <stdlib.h>
370Sstevel@tonic-gate #include <string.h>
380Sstevel@tonic-gate #include <syslog.h>
390Sstevel@tonic-gate #include <netinet/in.h>
400Sstevel@tonic-gate #include <unistd.h>
410Sstevel@tonic-gate #include <synch.h>
420Sstevel@tonic-gate #include <generic.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #ifdef C2_DEBUG2
45*11706SJan.Friedel@Sun.COM #define	dprintf(x) { (void) printf x; }
460Sstevel@tonic-gate #else
470Sstevel@tonic-gate #define	dprintf(x)
480Sstevel@tonic-gate #endif
490Sstevel@tonic-gate 
500Sstevel@tonic-gate static mutex_t audit_mountd_lock = DEFAULTMUTEX;
510Sstevel@tonic-gate static int cannotaudit = 0;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * This setup call is made only once at the start of mountd.
550Sstevel@tonic-gate  * The call sets the auditing state off if appropriate, and is
560Sstevel@tonic-gate  * made in single threaded code, hence no locking is required.
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate void
audit_mountd_setup()590Sstevel@tonic-gate audit_mountd_setup()
600Sstevel@tonic-gate {
610Sstevel@tonic-gate 	dprintf(("audit_mountd_setup()\n"));
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	if (cannot_audit(0))
650Sstevel@tonic-gate 		cannotaudit = 1;
660Sstevel@tonic-gate }
670Sstevel@tonic-gate 
680Sstevel@tonic-gate void
audit_mountd_mount(clname,path,sorf)690Sstevel@tonic-gate audit_mountd_mount(clname, path, sorf)
700Sstevel@tonic-gate char	*clname;	/* client name */
710Sstevel@tonic-gate char	*path;		/* mount path */
720Sstevel@tonic-gate int	sorf;		/* flag for success or failure */
730Sstevel@tonic-gate {
740Sstevel@tonic-gate 	uint32_t buf[4], type;
750Sstevel@tonic-gate 	dprintf(("audit_mountd_mount()\n"));
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	if (cannotaudit)
780Sstevel@tonic-gate 		return;
790Sstevel@tonic-gate 
806812Sraf 	(void) mutex_lock(&audit_mountd_lock);
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	(void) aug_save_namask();
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	(void) aug_save_me();
850Sstevel@tonic-gate 	aug_save_event(AUE_mountd_mount);
860Sstevel@tonic-gate 	aug_save_sorf(sorf);
870Sstevel@tonic-gate 	aug_save_text(clname);
880Sstevel@tonic-gate 	aug_save_path(path);
890Sstevel@tonic-gate 	(void) aug_get_machine(clname, buf, &type);
900Sstevel@tonic-gate 	aug_save_tid_ex(aug_get_port(), buf, type);
910Sstevel@tonic-gate 	(void) aug_audit();
926812Sraf 	(void) mutex_unlock(&audit_mountd_lock);
930Sstevel@tonic-gate }
940Sstevel@tonic-gate 
950Sstevel@tonic-gate void
audit_mountd_umount(clname,path)960Sstevel@tonic-gate audit_mountd_umount(clname, path)
970Sstevel@tonic-gate char	*clname;	/* client name */
980Sstevel@tonic-gate char	*path;		/* mount path */
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate 	uint32_t buf[4], type;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	dprintf(("audit_mountd_mount()\n"));
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	if (cannotaudit)
1050Sstevel@tonic-gate 		return;
1060Sstevel@tonic-gate 
1076812Sraf 	(void) mutex_lock(&audit_mountd_lock);
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	(void) aug_save_namask();
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	(void) aug_save_me();
1120Sstevel@tonic-gate 	aug_save_event(AUE_mountd_umount);
1130Sstevel@tonic-gate 	aug_save_sorf(0);
1140Sstevel@tonic-gate 	aug_save_text(clname);
1150Sstevel@tonic-gate 	aug_save_path(path);
1160Sstevel@tonic-gate 	(void) aug_get_machine(clname, buf, &type);
1170Sstevel@tonic-gate 	aug_save_tid_ex(aug_get_port(), buf, type);
1180Sstevel@tonic-gate 	(void) aug_audit();
1196812Sraf 	(void) mutex_unlock(&audit_mountd_lock);
1200Sstevel@tonic-gate }
121