xref: /titanic_50/usr/src/uts/common/fs/autofs/auto_sys.c (revision 29e83d4b25fd82feb8e0e0fbe89f7e2a8438533d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/types.h>
29 #include <sys/systm.h>
30 #include <sys/zone.h>
31 #include <sys/errno.h>
32 #include <sys/cred.h>
33 #include <sys/policy.h>
34 
35 #include <sys/fs/autofs.h>
36 
37 extern struct autofs_globals *autofs_zone_init(void);
38 
39 int
40 autofssys(enum autofssys_op opcode, uintptr_t arg)
41 {
42 	int error = 0;
43 
44 	switch (opcode) {
45 	case AUTOFS_UNMOUNTALL: { /* attempt to remove all autofs mounts */
46 		zone_t *zone;
47 		zoneid_t zoneid;
48 		struct autofs_globals *fngp;
49 
50 		zoneid = (zoneid_t)arg;
51 		if (secpolicy_fs_unmount(CRED(), NULL) != 0 ||
52 		    crgetzoneid(CRED()) != GLOBAL_ZONEID)
53 			return (set_errno(EPERM));
54 		if ((zone = zone_find_by_id(zoneid)) == NULL)
55 			return (set_errno(EINVAL));
56 		mutex_enter(&autofs_minor_lock);
57 		fngp = zone_getspecific(autofs_key, zone);
58 		if (fngp == NULL) {
59 			mutex_exit(&autofs_minor_lock);
60 			zone_rele(zone);
61 			/*
62 			 * There were no mounts, so no work to do. Success.
63 			 */
64 			return (0);
65 		}
66 		mutex_exit(&autofs_minor_lock);
67 		unmount_tree(fngp, 1);
68 		zone_rele(zone);
69 		break;
70 	}
71 	case AUTOFS_SETDOOR: { /* set door handle for zone */
72 		uint_t did;
73 		struct autofs_globals *fngp;
74 
75 		/*
76 		 * We need to use the minor_lock to serialize setting this.
77 		 */
78 		mutex_enter(&autofs_minor_lock);
79 		fngp = zone_getspecific(autofs_key, curproc->p_zone);
80 		if (fngp == NULL) {
81 			fngp = autofs_zone_init();
82 			(void) zone_setspecific(autofs_key,
83 						curproc->p_zone, fngp);
84 		}
85 		mutex_exit(&autofs_minor_lock);
86 		ASSERT(fngp != NULL);
87 
88 		if (copyin((uint_t *)arg, &did, sizeof (uint_t)))
89 			return (set_errno(EFAULT));
90 
91 		mutex_enter(&fngp->fng_autofs_daemon_lock);
92 		if (fngp->fng_autofs_daemon_dh)
93 			door_ki_rele(fngp->fng_autofs_daemon_dh);
94 		fngp->fng_autofs_daemon_dh = door_ki_lookup(did);
95 		fngp->fng_autofs_pid = curproc->p_pid;
96 		mutex_exit(&fngp->fng_autofs_daemon_lock);
97 		break;
98 	}
99 	default:
100 		error = EINVAL;
101 		break;
102 	}
103 	return (error ? set_errno(error) : 0);
104 }
105