xref: /titanic_41/usr/src/uts/common/fs/autofs/auto_sys.c (revision f3312ec0e8acbd249df97358fb8c3ca92f4e089c)
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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include <sys/types.h>
26 #include <sys/systm.h>
27 #include <sys/zone.h>
28 #include <sys/errno.h>
29 #include <sys/cred.h>
30 #include <sys/policy.h>
31 
32 #include <sys/fs/autofs.h>
33 
34 extern struct autofs_globals *autofs_zone_init(void);
35 
36 int
37 autofssys(enum autofssys_op opcode, uintptr_t arg)
38 {
39 	int error = 0;
40 
41 	switch (opcode) {
42 	case AUTOFS_UNMOUNTALL: { /* attempt to remove all autofs mounts */
43 		zone_t *zone;
44 		zoneid_t zoneid;
45 		struct autofs_globals *fngp;
46 
47 		zoneid = (zoneid_t)arg;
48 		if (secpolicy_fs_unmount(CRED(), NULL) != 0 ||
49 		    crgetzoneid(CRED()) != GLOBAL_ZONEID)
50 			return (set_errno(EPERM));
51 		if ((zone = zone_find_by_id(zoneid)) == NULL)
52 			return (set_errno(EINVAL));
53 		mutex_enter(&autofs_minor_lock);
54 		fngp = zone_getspecific(autofs_key, zone);
55 		if (fngp == NULL) {
56 			mutex_exit(&autofs_minor_lock);
57 			zone_rele(zone);
58 			/*
59 			 * There were no mounts, so no work to do. Success.
60 			 */
61 			return (0);
62 		}
63 		mutex_exit(&autofs_minor_lock);
64 		unmount_tree(fngp, B_TRUE);
65 		zone_rele(zone);
66 		break;
67 	}
68 	case AUTOFS_SETDOOR: { /* set door handle for zone */
69 		uint_t did;
70 		struct autofs_globals *fngp;
71 
72 		/*
73 		 * We need to use the minor_lock to serialize setting this.
74 		 */
75 		mutex_enter(&autofs_minor_lock);
76 		fngp = zone_getspecific(autofs_key, curproc->p_zone);
77 		if (fngp == NULL) {
78 			fngp = autofs_zone_init();
79 			(void) zone_setspecific(autofs_key,
80 			    curproc->p_zone, fngp);
81 		}
82 		mutex_exit(&autofs_minor_lock);
83 		ASSERT(fngp != NULL);
84 
85 		if (copyin((uint_t *)arg, &did, sizeof (uint_t)))
86 			return (set_errno(EFAULT));
87 
88 		mutex_enter(&fngp->fng_autofs_daemon_lock);
89 		if (fngp->fng_autofs_daemon_dh)
90 			door_ki_rele(fngp->fng_autofs_daemon_dh);
91 		fngp->fng_autofs_daemon_dh = door_ki_lookup(did);
92 		fngp->fng_autofs_pid = curproc->p_pid;
93 		mutex_exit(&fngp->fng_autofs_daemon_lock);
94 		break;
95 	}
96 	default:
97 		error = EINVAL;
98 		break;
99 	}
100 	return (error ? set_errno(error) : 0);
101 }
102