xref: /titanic_44/usr/src/uts/common/fs/autofs/auto_sys.c (revision 9dd0f810214fdc8e1af881a9a5c4b6927629ff9e)
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 2006 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 		fngp = zone_getspecific(autofs_key, zone);
57 		if (fngp == NULL) {
58 			zone_rele(zone);
59 			/*
60 			 * There were no mounts, so no work to do. Success.
61 			 */
62 			return (0);
63 		}
64 		unmount_tree(fngp, 1);
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 		fngp = zone_getspecific(autofs_key, curproc->p_zone);
73 		if (fngp == NULL) {
74 			fngp = autofs_zone_init();
75 			(void) zone_setspecific(autofs_key,
76 						curproc->p_zone, fngp);
77 		}
78 		ASSERT(fngp != NULL);
79 
80 		if (copyin((uint_t *)arg, &did, sizeof (uint_t)))
81 			return (set_errno(EFAULT));
82 
83 		mutex_enter(&fngp->fng_autofs_daemon_lock);
84 		if (fngp->fng_autofs_daemon_dh)
85 			door_ki_rele(fngp->fng_autofs_daemon_dh);
86 		fngp->fng_autofs_daemon_dh = door_ki_lookup(did);
87 		fngp->fng_autofs_pid = curproc->p_pid;
88 		mutex_exit(&fngp->fng_autofs_daemon_lock);
89 		break;
90 	}
91 	default:
92 		error = EINVAL;
93 		break;
94 	}
95 	return (error ? set_errno(error) : 0);
96 }
97