xref: /onnv-gate/usr/src/uts/common/fs/autofs/auto_sys.c (revision 12184:0216e4439444)
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*12184SJan.Kryl@Sun.COM  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #include <sys/types.h>
260Sstevel@tonic-gate #include <sys/systm.h>
270Sstevel@tonic-gate #include <sys/zone.h>
280Sstevel@tonic-gate #include <sys/errno.h>
290Sstevel@tonic-gate #include <sys/cred.h>
300Sstevel@tonic-gate #include <sys/policy.h>
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/fs/autofs.h>
330Sstevel@tonic-gate 
342170Sevanl extern struct autofs_globals *autofs_zone_init(void);
352170Sevanl 
360Sstevel@tonic-gate int
autofssys(enum autofssys_op opcode,uintptr_t arg)370Sstevel@tonic-gate autofssys(enum autofssys_op opcode, uintptr_t arg)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate 	int error = 0;
400Sstevel@tonic-gate 
410Sstevel@tonic-gate 	switch (opcode) {
420Sstevel@tonic-gate 	case AUTOFS_UNMOUNTALL: { /* attempt to remove all autofs mounts */
430Sstevel@tonic-gate 		zone_t *zone;
440Sstevel@tonic-gate 		zoneid_t zoneid;
450Sstevel@tonic-gate 		struct autofs_globals *fngp;
460Sstevel@tonic-gate 
470Sstevel@tonic-gate 		zoneid = (zoneid_t)arg;
480Sstevel@tonic-gate 		if (secpolicy_fs_unmount(CRED(), NULL) != 0 ||
490Sstevel@tonic-gate 		    crgetzoneid(CRED()) != GLOBAL_ZONEID)
500Sstevel@tonic-gate 			return (set_errno(EPERM));
510Sstevel@tonic-gate 		if ((zone = zone_find_by_id(zoneid)) == NULL)
520Sstevel@tonic-gate 			return (set_errno(EINVAL));
534092Sevanl 		mutex_enter(&autofs_minor_lock);
540Sstevel@tonic-gate 		fngp = zone_getspecific(autofs_key, zone);
550Sstevel@tonic-gate 		if (fngp == NULL) {
564092Sevanl 			mutex_exit(&autofs_minor_lock);
570Sstevel@tonic-gate 			zone_rele(zone);
580Sstevel@tonic-gate 			/*
590Sstevel@tonic-gate 			 * There were no mounts, so no work to do. Success.
600Sstevel@tonic-gate 			 */
610Sstevel@tonic-gate 			return (0);
620Sstevel@tonic-gate 		}
634092Sevanl 		mutex_exit(&autofs_minor_lock);
64*12184SJan.Kryl@Sun.COM 		unmount_tree(fngp, B_TRUE);
650Sstevel@tonic-gate 		zone_rele(zone);
660Sstevel@tonic-gate 		break;
670Sstevel@tonic-gate 	}
682170Sevanl 	case AUTOFS_SETDOOR: { /* set door handle for zone */
692170Sevanl 		uint_t did;
702170Sevanl 		struct autofs_globals *fngp;
712170Sevanl 
724092Sevanl 		/*
734092Sevanl 		 * We need to use the minor_lock to serialize setting this.
744092Sevanl 		 */
754092Sevanl 		mutex_enter(&autofs_minor_lock);
762170Sevanl 		fngp = zone_getspecific(autofs_key, curproc->p_zone);
772170Sevanl 		if (fngp == NULL) {
782170Sevanl 			fngp = autofs_zone_init();
792170Sevanl 			(void) zone_setspecific(autofs_key,
80*12184SJan.Kryl@Sun.COM 			    curproc->p_zone, fngp);
812170Sevanl 		}
824092Sevanl 		mutex_exit(&autofs_minor_lock);
832170Sevanl 		ASSERT(fngp != NULL);
842170Sevanl 
852170Sevanl 		if (copyin((uint_t *)arg, &did, sizeof (uint_t)))
862170Sevanl 			return (set_errno(EFAULT));
872170Sevanl 
882170Sevanl 		mutex_enter(&fngp->fng_autofs_daemon_lock);
892170Sevanl 		if (fngp->fng_autofs_daemon_dh)
902170Sevanl 			door_ki_rele(fngp->fng_autofs_daemon_dh);
912170Sevanl 		fngp->fng_autofs_daemon_dh = door_ki_lookup(did);
922170Sevanl 		fngp->fng_autofs_pid = curproc->p_pid;
932170Sevanl 		mutex_exit(&fngp->fng_autofs_daemon_lock);
942170Sevanl 		break;
952170Sevanl 	}
960Sstevel@tonic-gate 	default:
970Sstevel@tonic-gate 		error = EINVAL;
980Sstevel@tonic-gate 		break;
990Sstevel@tonic-gate 	}
1000Sstevel@tonic-gate 	return (error ? set_errno(error) : 0);
1010Sstevel@tonic-gate }
102