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*3bfb48feSsemery % * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate % * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate % */ 257c478bd9Sstevel@tonic-gate % 267c478bd9Sstevel@tonic-gate %#include <sys/vfs.h> 277c478bd9Sstevel@tonic-gate %#include <sys/dirent.h> 287c478bd9Sstevel@tonic-gate %#include <sys/types.h> 297c478bd9Sstevel@tonic-gate %#include <sys/types32.h> 307c478bd9Sstevel@tonic-gate % 317c478bd9Sstevel@tonic-gate %#define xdr_dev_t xdr_u_int 327c478bd9Sstevel@tonic-gate %#define xdr_bool_t xdr_bool 337c478bd9Sstevel@tonic-gate % 347c478bd9Sstevel@tonic-gate /* 357c478bd9Sstevel@tonic-gate * Autofs/automountd communication protocol. 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate const AUTOFS_MAXPATHLEN = 1024; 397c478bd9Sstevel@tonic-gate const AUTOFS_MAXCOMPONENTLEN = 255; 407c478bd9Sstevel@tonic-gate const AUTOFS_MAXOPTSLEN = 1024; 417c478bd9Sstevel@tonic-gate const AUTOFS_DAEMONCOOKIE = 100000; 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * Action Status 457c478bd9Sstevel@tonic-gate * Automountd replies to autofs indicating whether the operation is done, 467c478bd9Sstevel@tonic-gate * or further action needs to be taken by autofs. 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate enum autofs_stat { 497c478bd9Sstevel@tonic-gate AUTOFS_ACTION=0, /* list of actions included */ 507c478bd9Sstevel@tonic-gate AUTOFS_DONE=1 /* no further action required by kernel */ 517c478bd9Sstevel@tonic-gate }; 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * Used by autofs to either create a link, or mount a new filesystem. 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate enum autofs_action { 577c478bd9Sstevel@tonic-gate AUTOFS_MOUNT_RQ=0, /* mount request */ 587c478bd9Sstevel@tonic-gate AUTOFS_LINK_RQ=1, /* link create */ 597c478bd9Sstevel@tonic-gate AUTOFS_NONE=2 /* no action */ 607c478bd9Sstevel@tonic-gate }; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate enum autofs_res { 637c478bd9Sstevel@tonic-gate AUTOFS_OK=0, 647c478bd9Sstevel@tonic-gate AUTOFS_NOENT=2, 657c478bd9Sstevel@tonic-gate AUTOFS_ECOMM=5, 667c478bd9Sstevel@tonic-gate AUTOFS_NOMEM=12, 677c478bd9Sstevel@tonic-gate AUTOFS_NOTDIR=20, 687c478bd9Sstevel@tonic-gate AUTOFS_SHUTDOWN=1000 697c478bd9Sstevel@tonic-gate }; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * Lookup/Mount request. 737c478bd9Sstevel@tonic-gate * Argument structure passed to both autofs_lookup() and autofs_mount(). 747c478bd9Sstevel@tonic-gate * autofs_lookup(): 757c478bd9Sstevel@tonic-gate * Query automountd if 'path/subdir/name' exists in 'map' 767c478bd9Sstevel@tonic-gate * autofs_mount(): 777c478bd9Sstevel@tonic-gate * Request automountd to mount the map entry associated with 787c478bd9Sstevel@tonic-gate * 'path/subdir/name' in 'map' given 'opts' options. 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate struct autofs_lookupargs { 817c478bd9Sstevel@tonic-gate string map<AUTOFS_MAXPATHLEN>; /* context or map name */ 827c478bd9Sstevel@tonic-gate string path<AUTOFS_MAXPATHLEN>; /* mountpoint */ 837c478bd9Sstevel@tonic-gate string name<AUTOFS_MAXCOMPONENTLEN>; /* entry we're looking for */ 847c478bd9Sstevel@tonic-gate string subdir<AUTOFS_MAXPATHLEN>; /* subdir within map */ 857c478bd9Sstevel@tonic-gate string opts<AUTOFS_MAXOPTSLEN>; 867c478bd9Sstevel@tonic-gate bool_t isdirect; /* direct mountpoint? */ 87*3bfb48feSsemery uid_t uid; /* uid of caller */ 887c478bd9Sstevel@tonic-gate }; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * Symbolic link information. 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate struct linka { 947c478bd9Sstevel@tonic-gate string dir<AUTOFS_MAXPATHLEN>; /* original name */ 957c478bd9Sstevel@tonic-gate string link<AUTOFS_MAXPATHLEN>; /* link (new) name */ 967c478bd9Sstevel@tonic-gate }; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /* 997c478bd9Sstevel@tonic-gate * We don't define netbuf in RPCL, we include the header file that 1007c478bd9Sstevel@tonic-gate * includes it, and implement the xdr function ourselves. 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * Autofs Mount specific information - used to mount a new 1057c478bd9Sstevel@tonic-gate * autofs filesystem. 1067c478bd9Sstevel@tonic-gate */ 1077c478bd9Sstevel@tonic-gate struct autofs_args { 1087c478bd9Sstevel@tonic-gate struct netbuf addr; /* daemon address */ 1097c478bd9Sstevel@tonic-gate string path<AUTOFS_MAXPATHLEN>; /* autofs mountpoint */ 1107c478bd9Sstevel@tonic-gate string opts<AUTOFS_MAXOPTSLEN>; /* default mount options */ 1117c478bd9Sstevel@tonic-gate string map<AUTOFS_MAXPATHLEN>; /* name of map */ 1127c478bd9Sstevel@tonic-gate string subdir<AUTOFS_MAXPATHLEN>; /* subdir within map */ 1137c478bd9Sstevel@tonic-gate string key<AUTOFS_MAXCOMPONENTLEN>; /* used in direct mounts only */ 1147c478bd9Sstevel@tonic-gate int mount_to; /* time in sec the fs is to remain */ 1157c478bd9Sstevel@tonic-gate /* mounted after last reference */ 1167c478bd9Sstevel@tonic-gate int rpc_to; /* timeout for rpc calls */ 1177c478bd9Sstevel@tonic-gate int direct; /* 1 = direct mount */ 1187c478bd9Sstevel@tonic-gate }; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate %#ifdef _SYSCALL32 1217c478bd9Sstevel@tonic-gate %/* 1227c478bd9Sstevel@tonic-gate % * This is an LP64 representation of the ILP32 autofs_args data structure 1237c478bd9Sstevel@tonic-gate % * for use by autofs_mount which may receive the data structure "raw" 1247c478bd9Sstevel@tonic-gate % * from a 32-bit program without being processed by XDR. rpcgen doesn't 1257c478bd9Sstevel@tonic-gate % * need to see this structure since RPC/XDR only deals with the "native" 1267c478bd9Sstevel@tonic-gate % * version of autofs_args. If this isn't hidden from rpcgen then it will 1277c478bd9Sstevel@tonic-gate % * insist on generating unnecessary code to deal with it. 1287c478bd9Sstevel@tonic-gate % */ 1297c478bd9Sstevel@tonic-gate %struct autofs_args32 { 1307c478bd9Sstevel@tonic-gate % struct netbuf32 addr; /* daemon address */ 1317c478bd9Sstevel@tonic-gate % caddr32_t path; /* autofs mountpoint */ 1327c478bd9Sstevel@tonic-gate % caddr32_t opts; /* default mount options */ 1337c478bd9Sstevel@tonic-gate % caddr32_t map; /* name of map */ 1347c478bd9Sstevel@tonic-gate % caddr32_t subdir; /* subdir within map */ 1357c478bd9Sstevel@tonic-gate % caddr32_t key; /* used in direct mounts */ 1367c478bd9Sstevel@tonic-gate % int32_t mount_to; /* time in sec the fs is to remain */ 1377c478bd9Sstevel@tonic-gate % /* mounted after last reference */ 1387c478bd9Sstevel@tonic-gate % int32_t rpc_to; /* timeout for rpc calls */ 1397c478bd9Sstevel@tonic-gate % int32_t direct; /* 1 = direct mount */ 1407c478bd9Sstevel@tonic-gate %}; 1417c478bd9Sstevel@tonic-gate %#endif /* _SYSCALL32 */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate /* 1447c478bd9Sstevel@tonic-gate * Contains the necessary information to notify autofs to 1457c478bd9Sstevel@tonic-gate * perfom either a new mount or create a symbolic link. 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gate union action_list_entry switch (autofs_action action) { 1487c478bd9Sstevel@tonic-gate case AUTOFS_MOUNT_RQ: 1497c478bd9Sstevel@tonic-gate struct mounta mounta; 1507c478bd9Sstevel@tonic-gate case AUTOFS_LINK_RQ: 1517c478bd9Sstevel@tonic-gate struct linka linka; 1527c478bd9Sstevel@tonic-gate default: 1537c478bd9Sstevel@tonic-gate void; 1547c478bd9Sstevel@tonic-gate }; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * List of actions that need to be performed by autofs to 1587c478bd9Sstevel@tonic-gate * finish the requested operation. 1597c478bd9Sstevel@tonic-gate */ 1607c478bd9Sstevel@tonic-gate struct action_list { 1617c478bd9Sstevel@tonic-gate action_list_entry action; 1627c478bd9Sstevel@tonic-gate action_list *next; 1637c478bd9Sstevel@tonic-gate }; 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate union mount_result_type switch (autofs_stat status) { 1667c478bd9Sstevel@tonic-gate case AUTOFS_ACTION: 1677c478bd9Sstevel@tonic-gate action_list *list; 1687c478bd9Sstevel@tonic-gate case AUTOFS_DONE: 1697c478bd9Sstevel@tonic-gate int error; 1707c478bd9Sstevel@tonic-gate default: 1717c478bd9Sstevel@tonic-gate void; 1727c478bd9Sstevel@tonic-gate }; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate /* 1757c478bd9Sstevel@tonic-gate * Result from mount operation. 1767c478bd9Sstevel@tonic-gate */ 1777c478bd9Sstevel@tonic-gate struct autofs_mountres { 1787c478bd9Sstevel@tonic-gate mount_result_type mr_type; 1797c478bd9Sstevel@tonic-gate int mr_verbose; 1807c478bd9Sstevel@tonic-gate }; 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate union lookup_result_type switch (autofs_action action) { 1837c478bd9Sstevel@tonic-gate case AUTOFS_LINK_RQ: 1847c478bd9Sstevel@tonic-gate struct linka lt_linka; 1857c478bd9Sstevel@tonic-gate case AUTOFS_MOUNT_RQ: 1867c478bd9Sstevel@tonic-gate void; 1877c478bd9Sstevel@tonic-gate default: 1887c478bd9Sstevel@tonic-gate void; 1897c478bd9Sstevel@tonic-gate }; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * Result from lookup operation. 1937c478bd9Sstevel@tonic-gate */ 1947c478bd9Sstevel@tonic-gate struct autofs_lookupres { 1957c478bd9Sstevel@tonic-gate enum autofs_res lu_res; 1967c478bd9Sstevel@tonic-gate lookup_result_type lu_type; 1977c478bd9Sstevel@tonic-gate int lu_verbose; 1987c478bd9Sstevel@tonic-gate }; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* 2017c478bd9Sstevel@tonic-gate * Unmount operation request 2027c478bd9Sstevel@tonic-gate * Automountd will issue unmount system call for the 2037c478bd9Sstevel@tonic-gate * given fstype on the given mntpnt. 2047c478bd9Sstevel@tonic-gate */ 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate struct umntrequest { 2077c478bd9Sstevel@tonic-gate bool_t isdirect; /* direct mount? */ 2087c478bd9Sstevel@tonic-gate string mntresource<AUTOFS_MAXPATHLEN>; /* mntpnt source */ 2097c478bd9Sstevel@tonic-gate string mntpnt<AUTOFS_MAXPATHLEN>; /* mntpnt to unmount */ 2107c478bd9Sstevel@tonic-gate string fstype<AUTOFS_MAXCOMPONENTLEN>; /* filesystem type to umount */ 2117c478bd9Sstevel@tonic-gate string mntopts<AUTOFS_MAXOPTSLEN>; /* mntpnt options */ 2127c478bd9Sstevel@tonic-gate struct umntrequest *next; /* next unmount */ 2137c478bd9Sstevel@tonic-gate }; 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate /* 2167c478bd9Sstevel@tonic-gate * Unmount operation result 2177c478bd9Sstevel@tonic-gate * status = 0 if unmount was successful, 2187c478bd9Sstevel@tonic-gate * otherwise status = errno. 2197c478bd9Sstevel@tonic-gate */ 2207c478bd9Sstevel@tonic-gate struct umntres { 2217c478bd9Sstevel@tonic-gate int status; 2227c478bd9Sstevel@tonic-gate }; 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * AUTOFS readdir request 2267c478bd9Sstevel@tonic-gate * Request list of entries in 'rda_map' map starting at the given 2277c478bd9Sstevel@tonic-gate * offset 'rda_offset', for 'rda_count' bytes. 2287c478bd9Sstevel@tonic-gate */ 2297c478bd9Sstevel@tonic-gate struct autofs_rddirargs { 2307c478bd9Sstevel@tonic-gate string rda_map<AUTOFS_MAXPATHLEN>; 2317c478bd9Sstevel@tonic-gate u_int rda_offset; /* starting offset */ 2327c478bd9Sstevel@tonic-gate u_int rda_count; /* total size requested */ 233*3bfb48feSsemery uid_t uid; /* uid of caller */ 2347c478bd9Sstevel@tonic-gate }; 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate struct autofsrddir { 2377c478bd9Sstevel@tonic-gate u_int rddir_offset; /* last offset in list */ 2387c478bd9Sstevel@tonic-gate u_int rddir_size; /* size in bytes of entries */ 2397c478bd9Sstevel@tonic-gate bool_t rddir_eof; /* TRUE if last entry in result */ 2407c478bd9Sstevel@tonic-gate struct dirent64 *rddir_entries; /* variable number of entries */ 2417c478bd9Sstevel@tonic-gate }; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate /* 2447c478bd9Sstevel@tonic-gate * AUTOFS readdir result. 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate struct autofs_rddirres { 2477c478bd9Sstevel@tonic-gate enum autofs_res rd_status; 2487c478bd9Sstevel@tonic-gate u_int rd_bufsize; /* autofs request size (not xdr'ed) */ 2497c478bd9Sstevel@tonic-gate struct autofsrddir rd_rddir; 2507c478bd9Sstevel@tonic-gate }; 251