17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57257d1b4Sraf  * Common Development and Distribution License (the "License").
67257d1b4Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217257d1b4Sraf 
227c478bd9Sstevel@tonic-gate /*
23*dfc7be02SJan Friedel  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*dfc7be02SJan Friedel  *
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
317c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
327c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
337c478bd9Sstevel@tonic-gate #include <bsm/audit_uevents.h>
347c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
357c478bd9Sstevel@tonic-gate #include <bsm/audit_private.h>
367c478bd9Sstevel@tonic-gate #include <stdlib.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate #include <syslog.h>
397c478bd9Sstevel@tonic-gate #include <netinet/in.h>
407c478bd9Sstevel@tonic-gate #include <unistd.h>
417c478bd9Sstevel@tonic-gate #include <synch.h>
427c478bd9Sstevel@tonic-gate #include <generic.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #ifdef C2_DEBUG2
45*dfc7be02SJan Friedel #define	dprintf(x) { (void) printf x; }
467c478bd9Sstevel@tonic-gate #else
477c478bd9Sstevel@tonic-gate #define	dprintf(x)
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate static mutex_t audit_mountd_lock = DEFAULTMUTEX;
517c478bd9Sstevel@tonic-gate static int cannotaudit = 0;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * This setup call is made only once at the start of mountd.
557c478bd9Sstevel@tonic-gate  * The call sets the auditing state off if appropriate, and is
567c478bd9Sstevel@tonic-gate  * made in single threaded code, hence no locking is required.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate void
audit_mountd_setup()597c478bd9Sstevel@tonic-gate audit_mountd_setup()
607c478bd9Sstevel@tonic-gate {
617c478bd9Sstevel@tonic-gate 	dprintf(("audit_mountd_setup()\n"));
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	if (cannot_audit(0))
657c478bd9Sstevel@tonic-gate 		cannotaudit = 1;
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate void
audit_mountd_mount(clname,path,sorf)697c478bd9Sstevel@tonic-gate audit_mountd_mount(clname, path, sorf)
707c478bd9Sstevel@tonic-gate char	*clname;	/* client name */
717c478bd9Sstevel@tonic-gate char	*path;		/* mount path */
727c478bd9Sstevel@tonic-gate int	sorf;		/* flag for success or failure */
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate 	uint32_t buf[4], type;
757c478bd9Sstevel@tonic-gate 	dprintf(("audit_mountd_mount()\n"));
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	if (cannotaudit)
787c478bd9Sstevel@tonic-gate 		return;
797c478bd9Sstevel@tonic-gate 
807257d1b4Sraf 	(void) mutex_lock(&audit_mountd_lock);
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	(void) aug_save_namask();
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	(void) aug_save_me();
857c478bd9Sstevel@tonic-gate 	aug_save_event(AUE_mountd_mount);
867c478bd9Sstevel@tonic-gate 	aug_save_sorf(sorf);
877c478bd9Sstevel@tonic-gate 	aug_save_text(clname);
887c478bd9Sstevel@tonic-gate 	aug_save_path(path);
897c478bd9Sstevel@tonic-gate 	(void) aug_get_machine(clname, buf, &type);
907c478bd9Sstevel@tonic-gate 	aug_save_tid_ex(aug_get_port(), buf, type);
917c478bd9Sstevel@tonic-gate 	(void) aug_audit();
927257d1b4Sraf 	(void) mutex_unlock(&audit_mountd_lock);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate void
audit_mountd_umount(clname,path)967c478bd9Sstevel@tonic-gate audit_mountd_umount(clname, path)
977c478bd9Sstevel@tonic-gate char	*clname;	/* client name */
987c478bd9Sstevel@tonic-gate char	*path;		/* mount path */
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 	uint32_t buf[4], type;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	dprintf(("audit_mountd_mount()\n"));
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	if (cannotaudit)
1057c478bd9Sstevel@tonic-gate 		return;
1067c478bd9Sstevel@tonic-gate 
1077257d1b4Sraf 	(void) mutex_lock(&audit_mountd_lock);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	(void) aug_save_namask();
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	(void) aug_save_me();
1127c478bd9Sstevel@tonic-gate 	aug_save_event(AUE_mountd_umount);
1137c478bd9Sstevel@tonic-gate 	aug_save_sorf(0);
1147c478bd9Sstevel@tonic-gate 	aug_save_text(clname);
1157c478bd9Sstevel@tonic-gate 	aug_save_path(path);
1167c478bd9Sstevel@tonic-gate 	(void) aug_get_machine(clname, buf, &type);
1177c478bd9Sstevel@tonic-gate 	aug_save_tid_ex(aug_get_port(), buf, type);
1187c478bd9Sstevel@tonic-gate 	(void) aug_audit();
1197257d1b4Sraf 	(void) mutex_unlock(&audit_mountd_lock);
1207c478bd9Sstevel@tonic-gate }
121