amd.h revision 82794
1266423Sjfv/* 2266423Sjfv * Copyright (c) 1997-2001 Erez Zadok 3333343Serj * Copyright (c) 1990 Jan-Simon Pendry 4266423Sjfv * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 5266423Sjfv * Copyright (c) 1990 The Regents of the University of California. 6266423Sjfv * All rights reserved. 7266423Sjfv * 8266423Sjfv * This code is derived from software contributed to Berkeley by 9266423Sjfv * Jan-Simon Pendry at Imperial College, London. 10266423Sjfv * 11266423Sjfv * Redistribution and use in source and binary forms, with or without 12266423Sjfv * modification, are permitted provided that the following conditions 13266423Sjfv * are met: 14266423Sjfv * 1. Redistributions of source code must retain the above copyright 15266423Sjfv * notice, this list of conditions and the following disclaimer. 16266423Sjfv * 2. Redistributions in binary form must reproduce the above copyright 17266423Sjfv * notice, this list of conditions and the following disclaimer in the 18266423Sjfv * documentation and/or other materials provided with the distribution. 19266423Sjfv * 3. All advertising materials mentioning features or use of this software 20266423Sjfv * must display the following acknowledgment: 21266423Sjfv * This product includes software developed by the University of 22266423Sjfv * California, Berkeley and its contributors. 23266423Sjfv * 4. Neither the name of the University nor the names of its contributors 24266423Sjfv * may be used to endorse or promote products derived from this software 25266423Sjfv * without specific prior written permission. 26266423Sjfv * 27266423Sjfv * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28266423Sjfv * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29266423Sjfv * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30266423Sjfv * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31266423Sjfv * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32266423Sjfv * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33266423Sjfv * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34266423Sjfv * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35266423Sjfv * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36266423Sjfv * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37266423Sjfv * SUCH DAMAGE. 38266423Sjfv * 39266423Sjfv * %W% (Berkeley) %G% 40266423Sjfv * 41266423Sjfv * $Id: amd.h,v 1.8.2.3 2001/04/07 00:47:41 ib42 Exp $ 42266423Sjfv * 43266423Sjfv */ 44333343Serj 45270346Sjfv#ifndef _AMD_H 46333343Serj#define _AMD_H 47333343Serj 48266423Sjfv 49333343Serj/* 50333343Serj * MACROS: 51333343Serj */ 52333343Serj 53333343Serj/* options for amd.conf */ 54333343Serj#define CFM_BROWSABLE_DIRS 0x0001 55333343Serj#define CFM_MOUNT_TYPE_AUTOFS 0x0002 56266423Sjfv#define CFM_SELECTORS_IN_DEFAULTS 0x0004 57266423Sjfv#define CFM_NORMALIZE_HOSTNAMES 0x0008 58266423Sjfv#define CFM_PROCESS_LOCK 0x0010 59266423Sjfv#define CFM_PRINT_PID 0x0020 60266423Sjfv#define CFM_RESTART_EXISTING_MOUNTS 0x0040 61266423Sjfv#define CFM_SHOW_STATFS_ENTRIES 0x0080 62266423Sjfv#define CFM_FULLY_QUALIFIED_HOSTS 0x0100 63266423Sjfv#define CFM_BROWSABLE_DIRS_FULL 0x0200 /* allow '/' in readdir() */ 64266423Sjfv#define CFM_UNMOUNT_ON_EXIT 0x0400 /* when amd finishing */ 65266423Sjfv 66266423Sjfv/* some systems (SunOS 4.x) neglect to define the mount null message */ 67266423Sjfv#ifndef MOUNTPROC_NULL 68266423Sjfv# define MOUNTPROC_NULL ((u_long)(0)) 69266423Sjfv#endif /* not MOUNTPROC_NULL */ 70266423Sjfv 71266423Sjfv/* Hash table size */ 72266423Sjfv#define NKVHASH (1 << 2) /* Power of two */ 73266423Sjfv 74266423Sjfv/* interval between forced retries of a mount */ 75266423Sjfv#define RETRY_INTERVAL 2 76266423Sjfv 77266423Sjfv#define ereturn(x) { *error_return = x; return 0; } 78266423Sjfv 79266423Sjfv 80266423Sjfv/* 81266423Sjfv * TYPEDEFS: 82266423Sjfv */ 83266423Sjfv 84266423Sjfvtypedef struct cf_map cf_map_t; 85266423Sjfvtypedef struct kv kv; 86270346Sjfv/* 87270346Sjfv * Cache map operations 88270346Sjfv */ 89270346Sjfvtypedef void add_fn(mnt_map *, char *, char *); 90270346Sjfvtypedef int init_fn(mnt_map *, char *, time_t *); 91270346Sjfvtypedef int mtime_fn(mnt_map *, char *, time_t *); 92270346Sjfvtypedef int isup_fn(mnt_map *, char *); 93270346Sjfvtypedef int reload_fn(mnt_map *, char *, add_fn *); 94270346Sjfvtypedef int search_fn(mnt_map *, char *, char *, char **, time_t *); 95270346Sjfv 96270346Sjfv 97266423Sjfv 98270346Sjfv/* 99270346Sjfv * STRUCTURES: 100270346Sjfv */ 101270346Sjfv 102270346Sjfv/* global amd options that are manipulated by conf.c */ 103270346Sjfvstruct amu_global_options { 104270346Sjfv char *arch; /* name of current architecture */ 105270346Sjfv char *auto_dir; /* automounter temp dir */ 106270346Sjfv char *cluster; /* cluster name */ 107270346Sjfv char *karch; /* kernel architecture */ 108270346Sjfv char *logfile; /* amd log file */ 109266423Sjfv char *op_sys; /* operating system name ${os} */ 110266423Sjfv char *op_sys_ver; /* OS version ${osver} */ 111266423Sjfv char *op_sys_full; /* full OS name ${full_os} */ 112270346Sjfv char *op_sys_vendor; /* name of OS vendor ${vendor} */ 113270346Sjfv char *pid_file; /* PID file */ 114270346Sjfv char *sub_domain; /* local domain */ 115270346Sjfv char *map_options; /* global map options */ 116270346Sjfv char *map_type; /* global map type */ 117270346Sjfv char *search_path; /* search path for maps */ 118270346Sjfv char *mount_type; /* mount type for map */ 119270346Sjfv u_int flags; /* various CFM_* flags */ 120270346Sjfv int amfs_auto_retrans; /* NFS retransmit counter */ 121270346Sjfv int amfs_auto_timeo; /* NFS retry interval */ 122270346Sjfv int am_timeo; /* cache duration */ 123270346Sjfv int am_timeo_w; /* dismount interval */ 124270346Sjfv int portmap_program; /* amd RPC program number */ 125270346Sjfv#ifdef HAVE_MAP_HESIOD 126270346Sjfv char *hesiod_base; /* Hesiod rhs */ 127270346Sjfv#endif /* HAVE_MAP_HESIOD */ 128270346Sjfv#ifdef HAVE_MAP_LDAP 129270346Sjfv char *ldap_base; /* LDAP base */ 130270346Sjfv char *ldap_hostports; /* LDAP host ports */ 131270346Sjfv long ldap_cache_seconds; /* LDAP internal cache - keep seconds */ 132270346Sjfv long ldap_cache_maxmem; /* LDAP internal cache - max memory (bytes) */ 133270346Sjfv#endif /* HAVE_MAP_LDAP */ 134270346Sjfv#ifdef HAVE_MAP_NIS 135266423Sjfv char *nis_domain; /* YP domain name */ 136266423Sjfv#endif /* HAVE_MAP_NIS */ 137266423Sjfv char *nfs_proto; /* NFS protocol (NULL, udp, tcp) */ 138266423Sjfv int nfs_vers; /* NFS version (0, 2, 3, 4) */ 139266423Sjfv}; 140270346Sjfv 141270346Sjfv/* if you add anything here, update conf.c:reset_cf_map() */ 142270346Sjfvstruct cf_map { 143270346Sjfv char *cfm_dir; /* /home, /u, /src */ 144266423Sjfv char *cfm_name; /* amd.home, /etc/amd.home ... */ 145266423Sjfv char *cfm_type; /* file, hesiod, ndbm, nis ... */ 146270346Sjfv char *cfm_opts; /* -cache:=all, etc. */ 147270346Sjfv char *cfm_search_path; /* /etc/local:/etc/amdmaps:/misc/yp */ 148266423Sjfv char *cfm_tag; /* optional map tag for amd -T */ 149270346Sjfv u_int cfm_flags; /* browsable_dirs? mount_type? */ 150270346Sjfv}; 151266423Sjfv 152303967Ssbruno/* 153303967Ssbruno * Key-value pair 154303967Ssbruno */ 155303967Ssbrunostruct kv { 156266423Sjfv kv *next; 157270346Sjfv char *key; 158270346Sjfv#ifdef HAVE_REGEXEC 159266423Sjfv regex_t re; /* store the regexp from regcomp() */ 160266423Sjfv#endif /* HAVE_REGEXEC */ 161270346Sjfv char *val; 162266423Sjfv}; 163303967Ssbruno 164303967Ssbrunostruct mnt_map { 165303967Ssbruno qelem hdr; 166318357Serj int refc; /* Reference count */ 167303967Ssbruno short flags; /* Allocation flags */ 168266423Sjfv short alloc; /* Allocation mode */ 169270346Sjfv time_t modify; /* Modify time of map */ 170270346Sjfv u_int reloads; /* Number of times map was reloaded */ 171270346Sjfv char *map_name; /* Name of this map */ 172270346Sjfv char *wildcard; /* Wildcard value */ 173270346Sjfv reload_fn *reload; /* Function to be used for reloads */ 174299549Serj isup_fn *isup; /* Is service up or not? (1=up, 0=down) */ 175299555Serj search_fn *search; /* Function to be used for searching */ 176299555Serj mtime_fn *mtime; /* Modify time function */ 177266423Sjfv kv *kvhash[NKVHASH]; /* Cached data */ 178270346Sjfv /* options available via amd conf file */ 179270346Sjfv char *cf_map_type; /* file, hesiod, ndbm, nis, etc. */ 180270346Sjfv char *cf_search_path; /* /etc/local:/etc/amdmaps:/misc/yp */ 181266423Sjfv void *map_data; /* Map data black box */ 182270346Sjfv}; 183270346Sjfv 184270346Sjfv/* 185266423Sjfv * Mounting a file system may take a significant period of time. The 186270346Sjfv * problem is that if this is done in the main process thread then the 187270346Sjfv * entire automounter could be blocked, possibly hanging lots of processes 188270346Sjfv * on the system. Instead we use a continuation scheme to allow mounts to 189266423Sjfv * be attempted in a sub-process. When the sub-process exits we pick up the 190270346Sjfv * exit status (by convention a UN*X error number) and continue in a 191266423Sjfv * notifier. The notifier gets handed a data structure and can then 192270346Sjfv * determine whether the mount was successful or not. If not, it updates 193270346Sjfv * the data structure and tries again until there are no more ways to try 194270346Sjfv * the mount, or some other permanent error occurs. In the mean time no RPC 195270346Sjfv * reply is sent, even after the mount is successful. We rely on the RPC 196270346Sjfv * retry mechanism to resend the lookup request which can then be handled. 197270346Sjfv */ 198270346Sjfvstruct continuation { 199270346Sjfv char **ivec; /* Current mount info */ 200270346Sjfv am_node *mp; /* Node we are trying to mount */ 201270346Sjfv char *key; /* Map key */ 202270346Sjfv char *info; /* Info string */ 203270346Sjfv char **xivec; /* Saved strsplit vector */ 204270346Sjfv char *auto_opts; /* Automount options */ 205270346Sjfv am_opts fs_opts; /* Filesystem options */ 206303967Ssbruno char *def_opts; /* Default automount options */ 207266423Sjfv int retry; /* Try again? */ 208270346Sjfv int tried; /* Have we tried any yet? */ 209270346Sjfv time_t start; /* Time we started this mount */ 210266423Sjfv int callout; /* Callout identifier */ 211266423Sjfv}; 212270346Sjfv 213270346Sjfv 214333343Serj/* 215266423Sjfv * EXTERNALS: 216266423Sjfv */ 217270346Sjfv 218270346Sjfv/* Amq server global functions */ 219270346Sjfvextern amq_mount_info_list *amqproc_getmntfs_1_svc(voidp argp, struct svc_req *rqstp); 220270346Sjfvextern amq_mount_stats *amqproc_stats_1_svc(voidp argp, struct svc_req *rqstp); 221270346Sjfvextern amq_mount_tree_list *amqproc_export_1_svc(voidp argp, struct svc_req *rqstp); 222270346Sjfvextern amq_mount_tree_p *amqproc_mnttree_1_svc(voidp argp, struct svc_req *rqstp); 223266423Sjfvextern amq_string *amqproc_getvers_1_svc(voidp argp, struct svc_req *rqstp); 224270346Sjfvextern int *amqproc_getpid_1_svc(voidp argp, struct svc_req *rqstp); 225270346Sjfvextern int *amqproc_mount_1_svc(voidp argp, struct svc_req *rqstp); 226270346Sjfvextern int *amqproc_setopt_1_svc(voidp argp, struct svc_req *rqstp); 227270346Sjfvextern voidp amqproc_null_1_svc(voidp argp, struct svc_req *rqstp); 228270346Sjfvextern voidp amqproc_umnt_1_svc(voidp argp, struct svc_req *rqstp); 229270346Sjfv 230270346Sjfv/* other external definitions */ 231270346Sjfvextern am_nfs_fh *root_fh(char *dir); 232270346Sjfvextern am_node *autofs_lookuppn(am_node *mp, char *fname, int *error_return, int op); 233270346Sjfvextern am_node *find_ap(char *); 234270346Sjfvextern am_node *find_ap2(char *, am_node *); 235266423Sjfvextern bool_t xdr_amq_mount_info_qelem(XDR *xdrs, qelem *qhead); 236270346Sjfvextern fserver *find_nfs_srvr(mntfs *mf); 237270346Sjfvextern int auto_fmount(am_node *mp); 238266423Sjfvextern int auto_fumount(am_node *mp); 239266423Sjfvextern int mount_nfs_fh(am_nfs_handle_t *fhp, char *dir, char *fs_name, char *opts, mntfs *mf); 240270346Sjfvextern int process_last_regular_map(void); 241270346Sjfvextern int set_conf_kv(const char *section, const char *k, const char *v); 242270346Sjfvextern int try_mount(voidp mvp); 243270346Sjfvextern int yyparse (void); 244270346Sjfvextern nfsentry *make_entry_chain(am_node *mp, const nfsentry *current_chain, int fully_browsable); 245270346Sjfvextern void amfs_auto_cont(int rc, int term, voidp closure); 246270346Sjfvextern void amfs_auto_mkcacheref(mntfs *mf); 247270346Sjfvextern void amfs_auto_retry(int rc, int term, voidp closure); 248270346Sjfvextern void assign_error_mntfs(am_node *mp); 249270346Sjfvextern void flush_srvr_nfs_cache(void); 250270346Sjfvextern void free_continuation(struct continuation *cp); 251270346Sjfvextern void mf_mounted(mntfs *mf); 252270346Sjfvextern void quick_reply(am_node *mp, int error); 253299549Serjextern void root_newmap(const char *, const char *, const char *, const cf_map_t *); 254333343Serj 255333343Serj/* amd global variables */ 256266423Sjfvextern FILE *yyin; 257266423Sjfvextern SVCXPRT *nfs_program_2_transp; /* For quick_reply() */ 258270346Sjfvextern char *conf_tag; 259270346Sjfvextern char *opt_gid; 260270346Sjfvextern char *opt_uid; 261270346Sjfvextern int NumChild; 262270346Sjfvextern int fwd_sock; 263333343Serjextern int select_intr_valid; 264284049Sjfvextern int usage; 265299549Serjextern int use_conf_file; /* use amd configuration file */ 266266423Sjfvextern jmp_buf select_intr; 267266423Sjfvextern qelem mfhead; 268270346Sjfvextern struct am_opts fs_static; /* copy of the options to play with */ 269270346Sjfvextern struct amu_global_options gopt; /* where global options are stored */ 270270346Sjfv 271266423Sjfv#ifdef HAVE_SIGACTION 272266423Sjfvextern sigset_t masked_sigs; 273270346Sjfv#endif /* HAVE_SIGACTION */ 274270346Sjfv 275270346Sjfv#if defined(HAVE_AMU_FS_LINK) || defined(HAVE_AMU_FS_LINKX) 276270346Sjfvextern char *amfs_link_match(am_opts *fo); 277270346Sjfvextern int amfs_link_fumount(mntfs *mf); 278270346Sjfv#endif /* defined(HAVE_AMU_FS_LINK) || defined(HAVE_AMU_FS_LINKX) */ 279270346Sjfv 280266423Sjfv#ifdef HAVE_AMU_FS_NFSL 281266423Sjfvextern char *nfs_match(am_opts *fo); 282270346Sjfv#endif /* HAVE_AMU_FS_NFSL */ 283270346Sjfv 284270346Sjfv#if defined(HAVE_FS_NFS3) && !defined(HAVE_XDR_MOUNTRES3) 285270346Sjfvextern bool_t xdr_mountres3(XDR *xdrs, mountres3 *objp); 286270346Sjfv#endif /* defined(HAVE_FS_NFS3) && !defined(HAVE_XDR_MOUNTRES3) */ 287270346Sjfv 288270346Sjfv#ifdef HAVE_FS_AUTOFS 289277082Sjfvextern SVCXPRT *autofsxprt; 290277082Sjfvextern u_short autofs_port; 291277082Sjfvextern int amd_use_autofs; 292266423Sjfv 293266423Sjfvextern int autofs_mount(am_node *mp); 294270346Sjfvextern int autofs_umount(am_node *mp); 295270346Sjfvextern int create_autofs_service(int *soAUTOFSp, u_short *autofs_portp, SVCXPRT **autofs_xprtp, void (*dispatch_fxn)(struct svc_req *rqstp, SVCXPRT *transp)); 296303967Ssbrunoextern int svc_create_local_service(void (*dispatch) (), u_long prognum, u_long versnum, char *nettype, char *servname); 297303967Ssbrunoextern void autofs_mounted(mntfs *mf); 298303967Ssbrunoextern void autofs_program_1(struct svc_req *rqstp, SVCXPRT *transp); 299303967Ssbruno#endif /* HAVE_FS_AUTOFS */ 300266423Sjfv 301266423Sjfv/* Unix file system (irix) */ 302270346Sjfv#ifdef HAVE_FS_XFS 303266423Sjfvextern am_ops xfs_ops; /* Un*x file system */ 304266423Sjfv#endif /* HAVE_FS_XFS */ 305270346Sjfv 306270346Sjfv/* Unix file system (irix) */ 307277082Sjfv#ifdef HAVE_FS_EFS 308277082Sjfvextern am_ops efs_ops; /* Un*x file system */ 309266423Sjfv#endif /* HAVE_FS_EFS */ 310266423Sjfv 311270346Sjfv#endif /* not _AMD_H */ 312270346Sjfv