xref: /onnv-gate/usr/src/uts/common/fs/autofs/auto_sys.c (revision 4092:c859d126a342)
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
52170Sevanl  * Common Development and Distribution License (the "License").
62170Sevanl  * 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  */
210Sstevel@tonic-gate /*
22*4092Sevanl  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/systm.h>
300Sstevel@tonic-gate #include <sys/zone.h>
310Sstevel@tonic-gate #include <sys/errno.h>
320Sstevel@tonic-gate #include <sys/cred.h>
330Sstevel@tonic-gate #include <sys/policy.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <sys/fs/autofs.h>
360Sstevel@tonic-gate 
372170Sevanl extern struct autofs_globals *autofs_zone_init(void);
382170Sevanl 
390Sstevel@tonic-gate int
400Sstevel@tonic-gate autofssys(enum autofssys_op opcode, uintptr_t arg)
410Sstevel@tonic-gate {
420Sstevel@tonic-gate 	int error = 0;
430Sstevel@tonic-gate 
440Sstevel@tonic-gate 	switch (opcode) {
450Sstevel@tonic-gate 	case AUTOFS_UNMOUNTALL: { /* attempt to remove all autofs mounts */
460Sstevel@tonic-gate 		zone_t *zone;
470Sstevel@tonic-gate 		zoneid_t zoneid;
480Sstevel@tonic-gate 		struct autofs_globals *fngp;
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 		zoneid = (zoneid_t)arg;
510Sstevel@tonic-gate 		if (secpolicy_fs_unmount(CRED(), NULL) != 0 ||
520Sstevel@tonic-gate 		    crgetzoneid(CRED()) != GLOBAL_ZONEID)
530Sstevel@tonic-gate 			return (set_errno(EPERM));
540Sstevel@tonic-gate 		if ((zone = zone_find_by_id(zoneid)) == NULL)
550Sstevel@tonic-gate 			return (set_errno(EINVAL));
56*4092Sevanl 		mutex_enter(&autofs_minor_lock);
570Sstevel@tonic-gate 		fngp = zone_getspecific(autofs_key, zone);
580Sstevel@tonic-gate 		if (fngp == NULL) {
59*4092Sevanl 			mutex_exit(&autofs_minor_lock);
600Sstevel@tonic-gate 			zone_rele(zone);
610Sstevel@tonic-gate 			/*
620Sstevel@tonic-gate 			 * There were no mounts, so no work to do. Success.
630Sstevel@tonic-gate 			 */
640Sstevel@tonic-gate 			return (0);
650Sstevel@tonic-gate 		}
66*4092Sevanl 		mutex_exit(&autofs_minor_lock);
670Sstevel@tonic-gate 		unmount_tree(fngp, 1);
680Sstevel@tonic-gate 		zone_rele(zone);
690Sstevel@tonic-gate 		break;
700Sstevel@tonic-gate 	}
712170Sevanl 	case AUTOFS_SETDOOR: { /* set door handle for zone */
722170Sevanl 		uint_t did;
732170Sevanl 		struct autofs_globals *fngp;
742170Sevanl 
75*4092Sevanl 		/*
76*4092Sevanl 		 * We need to use the minor_lock to serialize setting this.
77*4092Sevanl 		 */
78*4092Sevanl 		mutex_enter(&autofs_minor_lock);
792170Sevanl 		fngp = zone_getspecific(autofs_key, curproc->p_zone);
802170Sevanl 		if (fngp == NULL) {
812170Sevanl 			fngp = autofs_zone_init();
822170Sevanl 			(void) zone_setspecific(autofs_key,
832170Sevanl 						curproc->p_zone, fngp);
842170Sevanl 		}
85*4092Sevanl 		mutex_exit(&autofs_minor_lock);
862170Sevanl 		ASSERT(fngp != NULL);
872170Sevanl 
882170Sevanl 		if (copyin((uint_t *)arg, &did, sizeof (uint_t)))
892170Sevanl 			return (set_errno(EFAULT));
902170Sevanl 
912170Sevanl 		mutex_enter(&fngp->fng_autofs_daemon_lock);
922170Sevanl 		if (fngp->fng_autofs_daemon_dh)
932170Sevanl 			door_ki_rele(fngp->fng_autofs_daemon_dh);
942170Sevanl 		fngp->fng_autofs_daemon_dh = door_ki_lookup(did);
952170Sevanl 		fngp->fng_autofs_pid = curproc->p_pid;
962170Sevanl 		mutex_exit(&fngp->fng_autofs_daemon_lock);
972170Sevanl 		break;
982170Sevanl 	}
990Sstevel@tonic-gate 	default:
1000Sstevel@tonic-gate 		error = EINVAL;
1010Sstevel@tonic-gate 		break;
1020Sstevel@tonic-gate 	}
1030Sstevel@tonic-gate 	return (error ? set_errno(error) : 0);
1040Sstevel@tonic-gate }
105