xref: /onnv-gate/usr/src/uts/common/fs/autofs/auto_sys.c (revision 2170:eb691d2a219e)
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
5*2170Sevanl  * Common Development and Distribution License (the "License").
6*2170Sevanl  * 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*2170Sevanl  * Copyright 2006 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 
37*2170Sevanl extern struct autofs_globals *autofs_zone_init(void);
38*2170Sevanl 
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));
560Sstevel@tonic-gate 		fngp = zone_getspecific(autofs_key, zone);
570Sstevel@tonic-gate 		if (fngp == NULL) {
580Sstevel@tonic-gate 			zone_rele(zone);
590Sstevel@tonic-gate 			/*
600Sstevel@tonic-gate 			 * There were no mounts, so no work to do. Success.
610Sstevel@tonic-gate 			 */
620Sstevel@tonic-gate 			return (0);
630Sstevel@tonic-gate 		}
640Sstevel@tonic-gate 		unmount_tree(fngp, 1);
650Sstevel@tonic-gate 		zone_rele(zone);
660Sstevel@tonic-gate 		break;
670Sstevel@tonic-gate 	}
68*2170Sevanl 	case AUTOFS_SETDOOR: { /* set door handle for zone */
69*2170Sevanl 		uint_t did;
70*2170Sevanl 		struct autofs_globals *fngp;
71*2170Sevanl 
72*2170Sevanl 		fngp = zone_getspecific(autofs_key, curproc->p_zone);
73*2170Sevanl 		if (fngp == NULL) {
74*2170Sevanl 			fngp = autofs_zone_init();
75*2170Sevanl 			(void) zone_setspecific(autofs_key,
76*2170Sevanl 						curproc->p_zone, fngp);
77*2170Sevanl 		}
78*2170Sevanl 		ASSERT(fngp != NULL);
79*2170Sevanl 
80*2170Sevanl 		if (copyin((uint_t *)arg, &did, sizeof (uint_t)))
81*2170Sevanl 			return (set_errno(EFAULT));
82*2170Sevanl 
83*2170Sevanl 		mutex_enter(&fngp->fng_autofs_daemon_lock);
84*2170Sevanl 		if (fngp->fng_autofs_daemon_dh)
85*2170Sevanl 			door_ki_rele(fngp->fng_autofs_daemon_dh);
86*2170Sevanl 		fngp->fng_autofs_daemon_dh = door_ki_lookup(did);
87*2170Sevanl 		fngp->fng_autofs_pid = curproc->p_pid;
88*2170Sevanl 		mutex_exit(&fngp->fng_autofs_daemon_lock);
89*2170Sevanl 		break;
90*2170Sevanl 	}
910Sstevel@tonic-gate 	default:
920Sstevel@tonic-gate 		error = EINVAL;
930Sstevel@tonic-gate 		break;
940Sstevel@tonic-gate 	}
950Sstevel@tonic-gate 	return (error ? set_errno(error) : 0);
960Sstevel@tonic-gate }
97