amd.h revision 131702
172445Sassar/*
2178825Sdfr * Copyright (c) 1997-2004 Erez Zadok
372445Sassar * Copyright (c) 1990 Jan-Simon Pendry
472445Sassar * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
572445Sassar * Copyright (c) 1990 The Regents of the University of California.
672445Sassar * All rights reserved.
772445Sassar *
872445Sassar * This code is derived from software contributed to Berkeley by
972445Sassar * Jan-Simon Pendry at Imperial College, London.
1072445Sassar *
1172445Sassar * Redistribution and use in source and binary forms, with or without
1272445Sassar * modification, are permitted provided that the following conditions
1372445Sassar * are met:
1472445Sassar * 1. Redistributions of source code must retain the above copyright
1572445Sassar *    notice, this list of conditions and the following disclaimer.
1672445Sassar * 2. Redistributions in binary form must reproduce the above copyright
1772445Sassar *    notice, this list of conditions and the following disclaimer in the
1872445Sassar *    documentation and/or other materials provided with the distribution.
1972445Sassar * 3. All advertising materials mentioning features or use of this software
2072445Sassar *    must display the following acknowledgment:
2172445Sassar *      This product includes software developed by the University of
2272445Sassar *      California, Berkeley and its contributors.
2372445Sassar * 4. Neither the name of the University nor the names of its contributors
2472445Sassar *    may be used to endorse or promote products derived from this software
2572445Sassar *    without specific prior written permission.
2672445Sassar *
2772445Sassar * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2872445Sassar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2972445Sassar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3072445Sassar * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3172445Sassar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3272445Sassar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3372445Sassar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3472445Sassar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3572445Sassar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36178825Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3772445Sassar * SUCH DAMAGE.
3872445Sassar *
3972445Sassar *      %W% (Berkeley) %G%
4072445Sassar *
4172445Sassar * $Id: amd.h,v 1.8.2.8 2004/01/21 04:04:58 ib42 Exp $
4272445Sassar *
4372445Sassar */
4472445Sassar
4572445Sassar#ifndef _AMD_H
4672445Sassar#define _AMD_H
4772445Sassar
4872445Sassar
4972445Sassar/*
5072445Sassar * MACROS:
5172445Sassar */
5272445Sassar
5372445Sassar/* options for amd.conf */
5472445Sassar#define CFM_BROWSABLE_DIRS		0x0001
5572445Sassar#define CFM_MOUNT_TYPE_AUTOFS		0x0002
5672445Sassar#define CFM_SELECTORS_IN_DEFAULTS	0x0004
5772445Sassar#define CFM_NORMALIZE_HOSTNAMES		0x0008
5872445Sassar#define CFM_PROCESS_LOCK		0x0010
5972445Sassar#define CFM_PRINT_PID			0x0020
6072445Sassar#define CFM_RESTART_EXISTING_MOUNTS	0x0040
61178825Sdfr#define CFM_SHOW_STATFS_ENTRIES		0x0080
6272445Sassar#define CFM_FULLY_QUALIFIED_HOSTS	0x0100
6372445Sassar#define CFM_BROWSABLE_DIRS_FULL		0x0200 /* allow '/' in readdir() */
6472445Sassar#define CFM_UNMOUNT_ON_EXIT		0x0400 /* when amd finishing */
6572445Sassar#define CFM_NFS_INSECURE_PORT		0x0800
6672445Sassar
6772445Sassar/* some systems (SunOS 4.x) neglect to define the mount null message */
6872445Sassar#ifndef MOUNTPROC_NULL
69178825Sdfr# define MOUNTPROC_NULL ((u_long)(0))
70178825Sdfr#endif /* not MOUNTPROC_NULL */
7172445Sassar
7272445Sassar/* Hash table size */
7372445Sassar#define NKVHASH (1 << 2)        /* Power of two */
7472445Sassar
7572445Sassar/* interval between forced retries of a mount */
7672445Sassar#define RETRY_INTERVAL	2
7772445Sassar
7872445Sassar#define ereturn(x) { *error_return = x; return 0; }
7972445Sassar
8072445Sassar
8172445Sassar/*
8272445Sassar * TYPEDEFS:
8372445Sassar */
8472445Sassar
8572445Sassartypedef struct cf_map cf_map_t;
8672445Sassartypedef struct kv kv;
8772445Sassar/*
8872445Sassar * Cache map operations
8972445Sassar */
9072445Sassartypedef void add_fn(mnt_map *, char *, char *);
9172445Sassartypedef int init_fn(mnt_map *, char *, time_t *);
9272445Sassartypedef int mtime_fn(mnt_map *, char *, time_t *);
9372445Sassartypedef int isup_fn(mnt_map *, char *);
9472445Sassartypedef int reload_fn(mnt_map *, char *, add_fn *);
9572445Sassartypedef int search_fn(mnt_map *, char *, char *, char **, time_t *);
9672445Sassar
9772445Sassar
9872445Sassar
9972445Sassar/*
10072445Sassar * STRUCTURES:
10172445Sassar */
10272445Sassar
10372445Sassar/* global amd options that are manipulated by conf.c */
10472445Sassarstruct amu_global_options {
10572445Sassar  char *arch;			/* name of current architecture */
10672445Sassar  char *auto_dir;		/* automounter temp dir */
10772445Sassar  char *cluster;		/* cluster name */
10872445Sassar  char *karch;			/* kernel architecture */
109178825Sdfr  char *logfile;		/* amd log file */
11072445Sassar  char *op_sys;			/* operating system name ${os} */
11172445Sassar  char *op_sys_ver;		/* OS version ${osver} */
11272445Sassar  char *op_sys_full;		/* full OS name ${full_os} */
11372445Sassar  char *op_sys_vendor;		/* name of OS vendor ${vendor} */
11472445Sassar  char *pid_file;		/* PID file */
11572445Sassar  char *sub_domain;		/* local domain */
11672445Sassar  char *map_options;		/* global map options */
11772445Sassar  char *map_type;		/* global map type */
11872445Sassar  char *search_path;		/* search path for maps */
11972445Sassar  char *mount_type;		/* mount type for map */
12072445Sassar  u_int flags;			/* various CFM_* flags */
12172445Sassar  int amfs_auto_retrans;	/* NFS retransmit counter */
12272445Sassar  int amfs_auto_timeo;		/* NFS retry interval */
12372445Sassar  int am_timeo;			/* cache duration */
12472445Sassar  int am_timeo_w;		/* dismount interval */
12572445Sassar  int portmap_program;		/* amd RPC program number */
12672445Sassar#ifdef HAVE_MAP_HESIOD
12772445Sassar  char *hesiod_base;		/* Hesiod rhs */
12872445Sassar#endif /* HAVE_MAP_HESIOD */
12972445Sassar#ifdef HAVE_MAP_LDAP
13072445Sassar  char *ldap_base;		/* LDAP base */
13172445Sassar  char *ldap_hostports;		/* LDAP host ports */
13272445Sassar  long ldap_cache_seconds; 	/* LDAP internal cache - keep seconds */
13372445Sassar  long ldap_cache_maxmem;	/* LDAP internal cache - max memory (bytes) */
134178825Sdfr#endif /* HAVE_MAP_LDAP */
13572445Sassar#ifdef HAVE_MAP_NIS
13672445Sassar  char *nis_domain;		/* YP domain name */
13772445Sassar#endif /* HAVE_MAP_NIS */
13878527Sassar  char *nfs_proto;		/* NFS protocol (NULL, udp, tcp) */
139178825Sdfr  int nfs_vers;			/* NFS version (0, 2, 3, 4) */
14072445Sassar};
14190926Snectar
14290926Snectar/* if you add anything here, update conf.c:reset_cf_map() */
14390926Snectarstruct cf_map {
14490926Snectar  char *cfm_dir;		/* /home, /u, /src */
14590926Snectar  char *cfm_name;		/* amd.home, /etc/amd.home ... */
14690926Snectar  char *cfm_type;		/* file, hesiod, ndbm, nis ... */
14790926Snectar  char *cfm_opts;		/* -cache:=all, etc. */
14890926Snectar  char *cfm_search_path;	/* /etc/local:/etc/amdmaps:/misc/yp */
14990926Snectar  char *cfm_tag;		/* optional map tag for amd -T */
150178825Sdfr  u_int cfm_flags;		/* browsable_dirs? mount_type? */
151178825Sdfr};
15272445Sassar
15372445Sassar/*
15472445Sassar * Key-value pair
15572445Sassar */
15672445Sassarstruct kv {
15772445Sassar  kv *next;
15872445Sassar  char *key;
15972445Sassar#ifdef HAVE_REGEXEC
16072445Sassar  regex_t re;                   /* store the regexp from regcomp() */
16172445Sassar#endif /* HAVE_REGEXEC */
162  char *val;
163};
164
165struct mnt_map {
166  qelem hdr;
167  int refc;                     /* Reference count */
168  short flags;                  /* Allocation flags */
169  short alloc;                  /* Allocation mode */
170  time_t modify;                /* Modify time of map */
171  u_int reloads;		/* Number of times map was reloaded */
172  char *map_name;               /* Name of this map */
173  char *wildcard;               /* Wildcard value */
174  reload_fn *reload;            /* Function to be used for reloads */
175  isup_fn *isup;		/* Is service up or not? (1=up, 0=down) */
176  search_fn *search;            /* Function to be used for searching */
177  mtime_fn *mtime;              /* Modify time function */
178  kv *kvhash[NKVHASH];          /* Cached data */
179  /* options available via amd conf file */
180  char *cf_map_type;            /* file, hesiod, ndbm, nis, etc. */
181  char *cf_search_path;         /* /etc/local:/etc/amdmaps:/misc/yp */
182  void *map_data;               /* Map data black box */
183};
184
185/*
186 * Mounting a file system may take a significant period of time.  The
187 * problem is that if this is done in the main process thread then the
188 * entire automounter could be blocked, possibly hanging lots of processes
189 * on the system.  Instead we use a continuation scheme to allow mounts to
190 * be attempted in a sub-process.  When the sub-process exits we pick up the
191 * exit status (by convention a UN*X error number) and continue in a
192 * notifier.  The notifier gets handed a data structure and can then
193 * determine whether the mount was successful or not.  If not, it updates
194 * the data structure and tries again until there are no more ways to try
195 * the mount, or some other permanent error occurs.  In the mean time no RPC
196 * reply is sent, even after the mount is successful.  We rely on the RPC
197 * retry mechanism to resend the lookup request which can then be handled.
198 */
199struct continuation {
200  char **ivec;			/* Current mount info */
201  am_node *mp;			/* Node we are trying to mount */
202  char *key;			/* Map key */
203  char *info;			/* Info string */
204  char **xivec;			/* Saved strsplit vector */
205  char *auto_opts;		/* Automount options */
206  am_opts fs_opts;		/* Filesystem options */
207  char *def_opts;		/* Default automount options */
208  int retry;			/* Try again? */
209  int tried;			/* Have we tried any yet? */
210  time_t start;			/* Time we started this mount */
211  int callout;			/* Callout identifier */
212};
213
214
215/*
216 * EXTERNALS:
217 */
218
219/* Amq server global functions */
220extern amq_mount_info_list *amqproc_getmntfs_1_svc(voidp argp, struct svc_req *rqstp);
221extern amq_mount_stats *amqproc_stats_1_svc(voidp argp, struct svc_req *rqstp);
222extern amq_mount_tree_list *amqproc_export_1_svc(voidp argp, struct svc_req *rqstp);
223extern amq_mount_tree_p *amqproc_mnttree_1_svc(voidp argp, struct svc_req *rqstp);
224extern amq_string *amqproc_getvers_1_svc(voidp argp, struct svc_req *rqstp);
225extern int *amqproc_getpid_1_svc(voidp argp, struct svc_req *rqstp);
226extern int *amqproc_mount_1_svc(voidp argp, struct svc_req *rqstp);
227extern int *amqproc_setopt_1_svc(voidp argp, struct svc_req *rqstp);
228extern voidp amqproc_null_1_svc(voidp argp, struct svc_req *rqstp);
229extern voidp amqproc_umnt_1_svc(voidp argp, struct svc_req *rqstp);
230
231/* other external definitions */
232extern am_nfs_fh *root_fh(char *dir);
233extern am_node *find_ap(char *);
234extern am_node *find_ap2(char *, am_node *);
235extern bool_t xdr_amq_mount_info_qelem(XDR *xdrs, qelem *qhead);
236extern fserver *find_nfs_srvr(mntfs *mf);
237extern int auto_fmount(am_node *mp);
238extern int auto_fumount(am_node *mp);
239extern int mount_nfs_fh(am_nfs_handle_t *fhp, char *dir, char *fs_name, char *opts, mntfs *mf);
240extern int process_last_regular_map(void);
241extern int set_conf_kv(const char *section, const char *k, const char *v);
242extern int try_mount(voidp mvp);
243extern int yyparse (void);
244extern nfsentry *make_entry_chain(am_node *mp, const nfsentry *current_chain, int fully_browsable);
245extern void amfs_auto_cont(int rc, int term, voidp closure);
246extern void amfs_auto_mkcacheref(mntfs *mf);
247extern void amfs_auto_retry(int rc, int term, voidp closure);
248extern void assign_error_mntfs(am_node *mp);
249extern void flush_srvr_nfs_cache(void);
250extern void free_continuation(struct continuation *cp);
251extern void mf_mounted(mntfs *mf);
252extern void quick_reply(am_node *mp, int error);
253extern void root_newmap(const char *, const char *, const char *, const cf_map_t *);
254
255/* amd global variables */
256extern FILE *yyin;
257extern SVCXPRT *nfs_program_2_transp; /* For quick_reply() */
258extern char *conf_tag;
259extern char *opt_gid;
260extern char *opt_uid;
261extern int NumChild;
262extern int fwd_sock;
263extern int select_intr_valid;
264extern int usage;
265extern int use_conf_file;	/* use amd configuration file */
266extern jmp_buf select_intr;
267extern qelem mfhead;
268extern struct am_opts fs_static; /* copy of the options to play with */
269extern struct amu_global_options gopt; /* where global options are stored */
270
271#ifdef HAVE_SIGACTION
272extern sigset_t masked_sigs;
273#endif /* HAVE_SIGACTION */
274
275#if defined(HAVE_AMU_FS_LINK) || defined(HAVE_AMU_FS_LINKX)
276extern char *amfs_link_match(am_opts *fo);
277extern int amfs_link_fumount(mntfs *mf);
278#endif /* defined(HAVE_AMU_FS_LINK) || defined(HAVE_AMU_FS_LINKX) */
279
280#ifdef HAVE_AMU_FS_NFSL
281extern char *nfs_match(am_opts *fo);
282#endif /* HAVE_AMU_FS_NFSL */
283
284#if defined(HAVE_FS_NFS3) && !defined(HAVE_XDR_MOUNTRES3)
285extern bool_t xdr_mountres3(XDR *xdrs, mountres3 *objp);
286#endif /* defined(HAVE_FS_NFS3) && !defined(HAVE_XDR_MOUNTRES3) */
287
288/* Unix file system (irix) */
289#ifdef HAVE_FS_XFS
290extern am_ops xfs_ops;		/* Un*x file system */
291#endif /* HAVE_FS_XFS */
292
293/* Unix file system (irix) */
294#ifdef HAVE_FS_EFS
295extern am_ops efs_ops;		/* Un*x file system */
296#endif /* HAVE_FS_EFS */
297
298#endif /* not _AMD_H */
299