17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 539d3e169Sevanl * Common Development and Distribution License (the "License"). 639d3e169Sevanl * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*f798ee53SJan Kryl * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #include <sys/types.h> 267c478bd9Sstevel@tonic-gate #include <sys/systm.h> 277c478bd9Sstevel@tonic-gate #include <sys/zone.h> 287c478bd9Sstevel@tonic-gate #include <sys/errno.h> 297c478bd9Sstevel@tonic-gate #include <sys/cred.h> 307c478bd9Sstevel@tonic-gate #include <sys/policy.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/fs/autofs.h> 337c478bd9Sstevel@tonic-gate 3439d3e169Sevanl extern struct autofs_globals *autofs_zone_init(void); 3539d3e169Sevanl 367c478bd9Sstevel@tonic-gate int 377c478bd9Sstevel@tonic-gate autofssys(enum autofssys_op opcode, uintptr_t arg) 387c478bd9Sstevel@tonic-gate { 397c478bd9Sstevel@tonic-gate int error = 0; 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate switch (opcode) { 427c478bd9Sstevel@tonic-gate case AUTOFS_UNMOUNTALL: { /* attempt to remove all autofs mounts */ 437c478bd9Sstevel@tonic-gate zone_t *zone; 447c478bd9Sstevel@tonic-gate zoneid_t zoneid; 457c478bd9Sstevel@tonic-gate struct autofs_globals *fngp; 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate zoneid = (zoneid_t)arg; 487c478bd9Sstevel@tonic-gate if (secpolicy_fs_unmount(CRED(), NULL) != 0 || 497c478bd9Sstevel@tonic-gate crgetzoneid(CRED()) != GLOBAL_ZONEID) 507c478bd9Sstevel@tonic-gate return (set_errno(EPERM)); 517c478bd9Sstevel@tonic-gate if ((zone = zone_find_by_id(zoneid)) == NULL) 527c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 53780213fbSevanl mutex_enter(&autofs_minor_lock); 547c478bd9Sstevel@tonic-gate fngp = zone_getspecific(autofs_key, zone); 557c478bd9Sstevel@tonic-gate if (fngp == NULL) { 56780213fbSevanl mutex_exit(&autofs_minor_lock); 577c478bd9Sstevel@tonic-gate zone_rele(zone); 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * There were no mounts, so no work to do. Success. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate return (0); 627c478bd9Sstevel@tonic-gate } 63780213fbSevanl mutex_exit(&autofs_minor_lock); 64*f798ee53SJan Kryl unmount_tree(fngp, B_TRUE); 657c478bd9Sstevel@tonic-gate zone_rele(zone); 667c478bd9Sstevel@tonic-gate break; 677c478bd9Sstevel@tonic-gate } 6839d3e169Sevanl case AUTOFS_SETDOOR: { /* set door handle for zone */ 6939d3e169Sevanl uint_t did; 7039d3e169Sevanl struct autofs_globals *fngp; 7139d3e169Sevanl 72780213fbSevanl /* 73780213fbSevanl * We need to use the minor_lock to serialize setting this. 74780213fbSevanl */ 75780213fbSevanl mutex_enter(&autofs_minor_lock); 7639d3e169Sevanl fngp = zone_getspecific(autofs_key, curproc->p_zone); 7739d3e169Sevanl if (fngp == NULL) { 7839d3e169Sevanl fngp = autofs_zone_init(); 7939d3e169Sevanl (void) zone_setspecific(autofs_key, 8039d3e169Sevanl curproc->p_zone, fngp); 8139d3e169Sevanl } 82780213fbSevanl mutex_exit(&autofs_minor_lock); 8339d3e169Sevanl ASSERT(fngp != NULL); 8439d3e169Sevanl 8539d3e169Sevanl if (copyin((uint_t *)arg, &did, sizeof (uint_t))) 8639d3e169Sevanl return (set_errno(EFAULT)); 8739d3e169Sevanl 8839d3e169Sevanl mutex_enter(&fngp->fng_autofs_daemon_lock); 8939d3e169Sevanl if (fngp->fng_autofs_daemon_dh) 9039d3e169Sevanl door_ki_rele(fngp->fng_autofs_daemon_dh); 9139d3e169Sevanl fngp->fng_autofs_daemon_dh = door_ki_lookup(did); 9239d3e169Sevanl fngp->fng_autofs_pid = curproc->p_pid; 9339d3e169Sevanl mutex_exit(&fngp->fng_autofs_daemon_lock); 9439d3e169Sevanl break; 9539d3e169Sevanl } 967c478bd9Sstevel@tonic-gate default: 977c478bd9Sstevel@tonic-gate error = EINVAL; 987c478bd9Sstevel@tonic-gate break; 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate return (error ? set_errno(error) : 0); 1017c478bd9Sstevel@tonic-gate } 102