am_utils.h revision 119679
1/*
2 * Copyright (c) 1997-2003 Erez Zadok
3 * Copyright (c) 1990 Jan-Simon Pendry
4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 *    must display the following acknowledgment:
21 *      This product includes software developed by the University of
22 *      California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 *    may be used to endorse or promote products derived from this software
25 *    without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 *      %W% (Berkeley) %G%
40 *
41 * $Id: am_utils.h,v 1.11.2.12 2002/12/27 22:45:10 ezk Exp $
42 *
43 */
44
45/*
46 * Definitions that are specific to the am-utils package.
47 */
48
49#ifndef _AM_UTILS_H
50#define _AM_UTILS_H
51
52
53/**************************************************************************/
54/*** MACROS								***/
55/**************************************************************************/
56
57/*
58 * General macros.
59 */
60#ifndef FALSE
61# define FALSE 0
62#endif /* not FALSE */
63#ifndef TRUE
64# define TRUE 1
65#endif /* not TRUE */
66#ifndef MAX
67# define MAX(a, b)	((a) > (b) ? (a) : (b))
68#endif /* not MAX */
69#ifndef MIN
70# define MIN(a, b)	((a) < (b) ? (a) : (b))
71#endif /* not MIN */
72
73#define	ONE_HOUR	(60 * 60)	/* One hour in seconds */
74
75#ifndef MAXHOSTNAMELEN
76# ifdef HOSTNAMESZ
77#  define MAXHOSTNAMELEN HOSTNAMESZ
78# else /* not HOSTNAMESZ */
79#  define MAXHOSTNAMELEN 256
80# endif /* not HOSTNAMESZ */
81#endif /* not MAXHOSTNAMELEN */
82
83/*
84 * for hlfsd, and amd for detecting uid/gid
85 */
86#ifndef INVALIDID
87/* this is also defined in include/am_utils.h */
88# define INVALIDID	(((unsigned short) ~0) - 3)
89#endif /* not INVALIDID */
90
91/*
92 * String comparison macros
93 */
94#define STREQ(s1, s2)		(strcmp((s1), (s2)) == 0)
95#define STRCEQ(s1, s2)		(strcasecmp((s1), (s2)) == 0)
96#define NSTREQ(s1, s2, n)	(strncmp((s1), (s2), (n)) == 0)
97#define NSTRCEQ(s1, s2, n)	(strncasecmp((s1), (s2), (n)) == 0)
98#define FSTREQ(s1, s2)		((*(s1) == *(s2)) && STREQ((s1),(s2)))
99
100/*
101 * Logging options/flags
102 */
103#define	XLOG_FATAL	0x0001
104#define	XLOG_ERROR	0x0002
105#define	XLOG_USER	0x0004
106#define	XLOG_WARNING	0x0008
107#define	XLOG_INFO	0x0010
108#define	XLOG_DEBUG	0x0020
109#define	XLOG_MAP	0x0040
110#define	XLOG_STATS	0x0080
111#define XLOG_DEFSTR	"all,nomap,nostats"	/* Default log options */
112#define XLOG_ALL	(XLOG_FATAL|XLOG_ERROR|XLOG_USER|XLOG_WARNING|XLOG_INFO|XLOG_MAP|XLOG_STATS)
113
114#define clocktime() (clock_valid ? clock_valid : time(&clock_valid))
115
116#ifndef ROOT_MAP
117# define ROOT_MAP "\"root\""
118#endif /* not ROOT_MAP */
119
120#define NO_SUBNET	"notknown"	/* default subnet name for no subnet */
121#define	NEXP_AP		(1022)	/* gdmr: was 254 */
122#define NEXP_AP_MARGIN	(128)
123#define	MAX_READDIR_ENTRIES	16
124
125/*
126 * Linked list macros
127 */
128#define	AM_FIRST(ty, q)	((ty *) ((q)->q_forw))
129#define	AM_LAST(ty, q)	((ty *) ((q)->q_back))
130#define	NEXT(ty, q)	((ty *) (((qelem *) q)->q_forw))
131#define	PREV(ty, q)	((ty *) (((qelem *) q)->q_back))
132#define	HEAD(ty, q)	((ty *) q)
133#define	ITER(v, ty, q) \
134	for ((v) = AM_FIRST(ty,(q)); (v) != HEAD(ty,(q)); (v) = NEXT(ty,(v)))
135
136/* allocate anything of type ty */
137#define	ALLOC(ty)	((ty *) xmalloc(sizeof(ty)))
138#define	CALLOC(ty)	((ty *) xcalloc(1, sizeof(ty)))
139/* simply allocate b bytes */
140#define	SALLOC(b)	xmalloc((b))
141
142/* converting am-filehandles to mount-points */
143#define	fh_to_mp2(fhp, rp) fh_to_mp3(fhp, rp, VLOOK_CREATE)
144
145/*
146 * Systems which have the mount table in a file need to read it before
147 * they can perform an unmount() system call.
148 */
149#define UMOUNT_FS(dir, mtb_name)	umount_fs(dir, mtb_name)
150/* imported via $srcdir/conf/umount/umount_*.c */
151extern int umount_fs(char *fs_name, const char *mnttabname);
152
153/*
154 * macros for automounter vfs/vnode operations.
155 */
156#define	VLOOK_CREATE	0x1
157#define	VLOOK_DELETE	0x2
158#define FS_DIRECTORY	0x0001	/* This looks like a dir, not a link */
159#define	FS_MBACKGROUND	0x0002	/* Should background this mount */
160#define	FS_NOTIMEOUT	0x0004	/* Don't bother with timeouts */
161#define FS_MKMNT	0x0008	/* Need to make the mount point */
162#define FS_UBACKGROUND	0x0010	/* Unmount in background */
163#define	FS_BACKGROUND	(FS_MBACKGROUND|FS_UBACKGROUND)
164#define	FS_DISCARD	0x0020	/* Discard immediately on last reference */
165#define	FS_AMQINFO	0x0040	/* Amq is interested in this fs type */
166
167/*
168 * macros for struct fserver.
169 */
170#define	FSF_VALID	0x0001	/* Valid information available */
171#define	FSF_DOWN	0x0002	/* This fileserver is thought to be down */
172#define	FSF_ERROR	0x0004	/* Permanent error has occurred */
173#define	FSF_WANT	0x0008	/* Want a wakeup call */
174#define	FSF_PINGING	0x0010	/* Already doing pings */
175#define	FSRV_ISDOWN(fs)	(((fs)->fs_flags & (FSF_DOWN|FSF_VALID)) == (FSF_DOWN|FSF_VALID))
176#define	FSRV_ISUP(fs)	(((fs)->fs_flags & (FSF_DOWN|FSF_VALID)) == (FSF_VALID))
177
178/*
179 * macros for struct mntfs (list of mounted filesystems)
180 */
181#define	MFF_MOUNTED	0x0001	/* Node is mounted */
182#define	MFF_MOUNTING	0x0002	/* Mount is in progress */
183#define	MFF_UNMOUNTING	0x0004	/* Unmount is in progress */
184#define	MFF_RESTART	0x0008	/* Restarted node */
185#define MFF_MKMNT	0x0010	/* Delete this node's am_mount */
186#define	MFF_ERROR	0x0020	/* This node failed to mount */
187#define	MFF_LOGDOWN	0x0040	/* Logged that this mount is down */
188#define	MFF_RSTKEEP	0x0080	/* Don't timeout this filesystem - restarted */
189#define	MFF_WANTTIMO	0x0100	/* Need a timeout call when not busy */
190#ifdef HAVE_AMU_FS_NFSL
191# define MFF_NFSLINK	0x0200	/* nfsl type, and deemed a link */
192#endif /* HAVE_AMU_FS_NFSL */
193
194/*
195 * macros for struct am_node (map of auto-mount points).
196 */
197#define	AMF_NOTIMEOUT	0x0001	/* This node never times out */
198#define	AMF_ROOT	0x0002	/* This is a root node */
199#define AMF_AUTOFS	0x0004	/* This node is of type autofs -- not yet supported */
200
201/*
202 * The following values can be tuned...
203 */
204#define	ALLOWED_MOUNT_TIME	40	/* 40s for a mount */
205#define	AM_TTL			(5 * 60)	/* Default cache period */
206#define	AM_TTL_W		(2 * 60)	/* Default unmount interval */
207#define	AM_PINGER		30 /* NFS ping interval for live systems */
208#define	AMFS_AUTO_TIMEO		8 /* Default amfs_auto timeout - .8s */
209
210/*
211 * default amfs_auto retrans - 1/10th seconds
212 */
213#define	AMFS_AUTO_RETRANS	((ALLOWED_MOUNT_TIME*10+5*gopt.amfs_auto_timeo)/gopt.amfs_auto_timeo * 2)
214
215/*
216 * RPC-related macros.
217 */
218#define	RPC_XID_PORTMAP		0
219#define	RPC_XID_MOUNTD		1
220#define	RPC_XID_NFSPING		2
221#define	RPC_XID_MASK		(0x0f)	/* 16 id's for now */
222#define	MK_RPC_XID(type_id, uniq)	((type_id) | ((uniq) << 4))
223
224/*
225 * What level of AMD are we backward compatible with?
226 * This only applies to externally visible characteristics.
227 * Rev.Minor.Branch.Patch (2 digits each)
228 */
229#define	AMD_COMPAT	5000000	/* 5.0 */
230
231/*
232 * Error to return if remote host is not available.
233 * Try, in order, "host down", "host unreachable", "invalid argument".
234 */
235#ifdef EHOSTDOWN
236# define AM_ERRNO_HOST_DOWN	EHOSTDOWN
237# else /* not EHOSTDOWN */
238# ifdef EHOSTUNREACH
239#  define AM_ERRNO_HOST_DOWN	EHOSTUNREACH
240# else /* not EHOSTUNREACH */
241#  define AM_ERRNO_HOST_DOWN	EINVAL
242# endif /* not EHOSTUNREACH */
243#endif /* not EHOSTDOWN */
244
245
246/**************************************************************************/
247/*** STRUCTURES AND TYPEDEFS						***/
248/**************************************************************************/
249
250/* some typedefs must come first */
251typedef char *amq_string;
252typedef struct mntfs mntfs;
253typedef struct am_opts am_opts;
254typedef struct am_ops am_ops;
255typedef struct am_node am_node;
256typedef struct _qelem qelem;
257typedef struct mntlist mntlist;
258typedef struct fserver fserver;
259
260/*
261 * Linked list
262 * (the name 'struct qelem' conflicts with linux's unistd.h)
263 */
264struct _qelem {
265  qelem *q_forw;
266  qelem *q_back;
267};
268
269/*
270 * Option tables
271 */
272struct opt_tab {
273  char *opt;
274  int flag;
275};
276
277/*
278 * Server states
279 */
280typedef enum {
281  Start,
282  Run,
283  Finishing,
284  Quit,
285  Done
286} serv_state;
287
288/*
289 * Options
290 */
291struct am_opts {
292  char *fs_glob;		/* Smashed copy of global options */
293  char *fs_local;		/* Expanded copy of local options */
294  char *fs_mtab;		/* Mount table entry */
295  /* Other options ... */
296  char *opt_dev;
297  char *opt_delay;
298  char *opt_dir;
299  char *opt_fs;
300  char *opt_group;
301  char *opt_mount;
302  char *opt_opts;
303  char *opt_remopts;
304  char *opt_pref;
305  char *opt_cache;
306  char *opt_rfs;
307  char *opt_rhost;
308  char *opt_sublink;
309  char *opt_type;
310  char *opt_unmount;
311  char *opt_user;
312  char *opt_maptype;		/* map type: file, nis, hesiod, etc. */
313  char *opt_cachedir;		/* cache directory */
314  char *opt_addopts;		/* options to add to opt_opts */
315};
316
317/*
318 * List of mounted filesystems
319 */
320struct mntfs {
321  qelem mf_q;			/* List of mounted filesystems */
322  am_ops *mf_ops;		/* Operations on this mountpoint */
323  am_opts *mf_fo;		/* File opts */
324  char *mf_mount;		/* "/a/kiska/home/kiska" */
325  char *mf_info;		/* Mount info */
326  char *mf_auto;		/* Automount opts */
327  char *mf_mopts;		/* FS mount opts */
328  char *mf_remopts;		/* Remote FS mount opts */
329  fserver *mf_server;		/* File server */
330  int mf_flags;			/* Flags MFF_* */
331  int mf_error;			/* Error code from background mount */
332  int mf_refc;			/* Number of references to this node */
333  int mf_cid;			/* Callout id */
334  void (*mf_prfree) (voidp);	/* Free private space */
335  voidp mf_private;		/* Private - per-fs data */
336};
337
338/*
339 * File Handle
340 *
341 * This is interpreted by indexing the exported array
342 * by fhh_id.
343 *
344 * The whole structure is mapped onto a standard fhandle_t
345 * when transmitted.
346 */
347struct am_fh {
348  int fhh_pid;			/* process id */
349  int fhh_id;			/* map id */
350  int fhh_gen;			/* generation number */
351};
352
353/*
354 * Multi-protocol NFS file handle
355 */
356union am_nfs_handle {
357				/* placeholder for V4 file handle */
358#ifdef HAVE_FS_NFS3
359  struct mountres3	v3;	/* NFS version 3 handle */
360#endif /* HAVE_FS_NFS3 */
361  struct fhstatus	v2;	/* NFS version 2 handle */
362};
363typedef union am_nfs_handle am_nfs_handle_t;
364
365/*
366 * automounter vfs/vnode operations.
367 */
368typedef char *(*vfs_match) (am_opts *);
369typedef int (*vfs_init) (mntfs *);
370typedef int (*vmount_fs) (am_node *);
371typedef int (*vfmount_fs) (mntfs *);
372typedef int (*vumount_fs) (am_node *);
373typedef int (*vfumount_fs) (mntfs *);
374typedef am_node *(*vlookuppn) (am_node *, char *, int *, int);
375typedef int (*vreaddir) (am_node *, nfscookie, nfsdirlist *, nfsentry *, int);
376typedef am_node *(*vreadlink) (am_node *, int *);
377typedef void (*vmounted) (mntfs *);
378typedef void (*vumounted) (am_node *);
379typedef fserver *(*vffserver) (mntfs *);
380
381struct am_ops {
382  char		*fs_type;	/* type of filesystems "nfsx" */
383  vfs_match	fs_match;	/* fxn: match */
384  vfs_init	fs_init;	/* fxn: initialization */
385  vmount_fs	mount_fs;	/* fxn: mount vnode */
386  vfmount_fs	fmount_fs;	/* fxn: mount VFS */
387  vumount_fs	umount_fs;	/* fxn: unmount vnode */
388  vfumount_fs	fumount_fs;	/* fxn: unmount VFS */
389  vlookuppn	lookuppn;	/* fxn: lookup path-name */
390  vreaddir	readdir;	/* fxn: read directory */
391  vreadlink	readlink;	/* fxn: read link */
392  vmounted	mounted;	/* fxn: after-mount extra actions */
393  vumounted	umounted;	/* fxn: after-umount extra actions */
394  vffserver	ffserver;	/* fxn: find a file server */
395  int		fs_flags;	/* filesystem flags FS_* */
396};
397
398typedef int (*task_fun) (voidp);
399typedef void (*cb_fun) (int, int, voidp);
400typedef void (*fwd_fun) P((voidp, int, struct sockaddr_in *,
401			   struct sockaddr_in *, voidp, int));
402
403/*
404 * List of mount table entries
405 */
406struct mntlist {
407  struct mntlist *mnext;
408  mntent_t *mnt;
409};
410
411/*
412 * Mount map
413 */
414typedef struct mnt_map mnt_map;
415
416/*
417 * Per-mountpoint statistics
418 */
419struct am_stats {
420  time_t s_mtime;		/* Mount time */
421  u_short s_uid;		/* Uid of mounter */
422  int s_getattr;		/* Count of getattrs */
423  int s_lookup;			/* Count of lookups */
424  int s_readdir;		/* Count of readdirs */
425  int s_readlink;		/* Count of readlinks */
426  int s_statfs;			/* Count of statfs */
427};
428typedef struct am_stats am_stats;
429
430/*
431 * System statistics
432 */
433struct amd_stats {
434  int d_drops;			/* Dropped requests */
435  int d_stale;			/* Stale NFS handles */
436  int d_mok;			/* Successful mounts */
437  int d_merr;			/* Failed mounts */
438  int d_uerr;			/* Failed unmounts */
439};
440extern struct amd_stats amd_stats;
441
442/*
443 * List of fileservers
444 */
445struct fserver {
446  qelem fs_q;			/* List of fileservers */
447  int fs_refc;			/* Number of references to this node */
448  char *fs_host;		/* Normalized hostname of server */
449  struct sockaddr_in *fs_ip;	/* Network address of server */
450  int fs_cid;			/* Callout id */
451  int fs_pinger;		/* Ping (keepalive) interval */
452  int fs_flags;			/* Flags */
453  char *fs_type;		/* File server type */
454  u_long fs_version;		/* NFS version of server (2, 3, etc.)*/
455  char *fs_proto;		/* NFS protocol of server (tcp, udp, etc.) */
456  voidp fs_private;		/* Private data */
457  void (*fs_prfree) (voidp);	/* Free private data */
458};
459
460/*
461 * Map of auto-mount points.
462 */
463struct am_node {
464  int am_mapno;		/* Map number */
465  mntfs *am_mnt;	/* Mounted filesystem */
466  char *am_name;	/* "kiska": name of this node */
467  char *am_path;	/* "/home/kiska": path of this node's mount point */
468  char *am_link;	/* "/a/kiska/home/kiska/this/that": link to sub-dir */
469  am_node *am_parent;	/* Parent of this node */
470  am_node *am_ysib;	/* Younger sibling of this node */
471  am_node *am_osib;	/* Older sibling of this node */
472  am_node *am_child;	/* First child of this node */
473  nfsattrstat am_attr;	/* File attributes */
474#define am_fattr	am_attr.ns_u.ns_attr_u
475  int am_flags;		/* Boolean flags AMF_* */
476  int am_error;		/* Specific mount error */
477  time_t am_ttl;	/* Time to live */
478  int am_timeo_w;	/* Wait interval */
479  int am_timeo;		/* Timeout interval */
480  u_int am_gen;		/* Generation number */
481  char *am_pref;	/* Mount info prefix */
482  am_stats am_stats;	/* Statistics gathering */
483  SVCXPRT *am_transp;	/* Info for quick reply */
484};
485
486
487/**************************************************************************/
488/*** EXTERNALS								***/
489/**************************************************************************/
490
491/*
492 * Useful constants
493 */
494extern char *mnttab_file_name;	/* Mount table */
495extern char *cpu;		/* "CPU type" */
496extern char *endian;		/* "big" */
497extern char *hostdomain;	/* "southseas.nz" */
498extern char copyright[];	/* Copyright info */
499extern char hostd[];		/* "kiska.southseas.nz" */
500extern char pid_fsname[];	/* kiska.southseas.nz:(pid%d) */
501extern char version[];		/* Version info */
502
503/*
504 * Global variables.
505 */
506extern AUTH *nfs_auth;		/* Dummy authorization for remote servers */
507extern FILE *logfp;		/* Log file */
508extern SVCXPRT *nfsxprt;
509extern am_node **exported_ap;	/* List of nodes */
510extern am_node *root_node;	/* Node for "root" */
511extern char *PrimNetName;	/* Name of primary connected network */
512extern char *PrimNetNum;	/* Name of primary connected network */
513extern char *SubsNetName;	/* Name of subsidiary connected network */
514extern char *SubsNetNum;	/* Name of subsidiary connected network */
515
516extern void am_set_progname(char *pn); /* "amd" */
517extern const char *am_get_progname(void); /* "amd" */
518extern void am_set_hostname(char *hn);
519extern const char *am_get_hostname(void);
520extern pid_t am_set_mypid(void);
521extern pid_t am_mypid;
522
523extern int first_free_map;	/* First free node */
524extern int foreground;		/* Foreground process */
525extern int immediate_abort;	/* Should close-down unmounts be retried */
526extern int last_used_map;	/* Last map being used for mounts */
527extern int orig_umask;		/* umask() on startup */
528extern int task_notify_todo;	/* Task notifier needs running */
529extern int xlog_level;		/* Logging level */
530extern int xlog_level_init;
531extern serv_state amd_state;	/* Should we go now */
532extern struct in_addr myipaddr;	/* (An) IP address of this host */
533extern struct opt_tab xlog_opt[];
534extern time_t clock_valid;	/* Clock needs recalculating */
535extern time_t do_mapc_reload;	/* Flush & reload mount map cache */
536extern time_t next_softclock;	/* Time to call softclock() */
537extern u_short nfs_port;	/* Our NFS service port */
538
539/*
540 * Global routines
541 */
542extern CLIENT *get_mount_client(char *unused_host, struct sockaddr_in *sin, struct timeval *tv, int *sock, u_long mnt_version);
543extern RETSIGTYPE sigchld(int);
544extern am_node *efs_lookuppn(am_node *, char *, int *, int);
545extern am_node *exported_ap_alloc(void);
546extern am_node *fh_to_mp(am_nfs_fh *);
547extern am_node *fh_to_mp3(am_nfs_fh *, int *, int);
548extern am_node *find_mf(mntfs *);
549extern am_node *next_map(int *);
550extern am_node *root_ap(char *, int);
551extern am_ops *ops_match(am_opts *, char *, char *, char *, char *, char *);
552extern bool_t xdr_amq_string(XDR *xdrs, amq_string *objp);
553extern bool_t xdr_dirpath(XDR *xdrs, dirpath *objp);
554extern char **strsplit(char *, int, int);
555extern char *expand_key(char *);
556extern char *get_version_string(void);
557extern char *inet_dquad(char *, u_long);
558extern char *print_wires(void);
559extern char *str3cat(char *, char *, char *, char *);
560extern char *strealloc(char *, char *);
561extern char *strip_selectors(char *, char *);
562extern char *strnsave(const char *, int);
563extern fserver *dup_srvr(fserver *);
564extern int amu_close(int fd);
565extern int background(void);
566extern int bind_resv_port(int, u_short *);
567extern int cmdoption(char *, struct opt_tab *, int *);
568extern int compute_automounter_mount_flags(mntent_t *);
569extern int compute_mount_flags(mntent_t *);
570extern int efs_readdir(am_node *, nfscookie, nfsdirlist *, nfsentry *, int);
571extern int eval_fs_opts(am_opts *, char *, char *, char *, char *, char *);
572extern int fwd_init(void);
573extern int fwd_packet(int, voidp, int, struct sockaddr_in *, struct sockaddr_in *, voidp, fwd_fun);
574extern int get_amd_program_number(void);
575extern int getcreds(struct svc_req *, uid_t *, gid_t *, SVCXPRT *);
576extern int hasmntval(mntent_t *, char *);
577extern char *hasmnteq(mntent_t *, char *);
578extern char *haseq(char *);
579extern int is_network_member(const char *net);
580extern int islocalnet(u_long);
581extern int make_nfs_auth(void);
582extern int make_rpc_packet(char *, int, u_long, struct rpc_msg *, voidp, XDRPROC_T_TYPE, AUTH *);
583extern int mapc_keyiter(mnt_map *, void(*)(char *, voidp), voidp);
584extern int mapc_search(mnt_map *, char *, char **);
585extern int mapc_type_exists(const char *type);
586extern int mkdirs(char *, int);
587extern int mount_auto_node(char *, voidp);
588extern int mount_automounter(int);
589extern int mount_exported(void);
590extern int mount_fs(mntent_t *, int, caddr_t, int, MTYPE_TYPE, u_long, const char *, const char *);
591extern int mount_node(am_node *);
592extern int nfs_srvr_port(fserver *, u_short *, voidp);
593extern int pickup_rpc_reply(voidp, int, voidp, XDRPROC_T_TYPE);
594extern int root_keyiter(void(*)(char *, voidp), voidp);
595extern int softclock(void);
596extern int switch_option(char *);
597extern int switch_to_logfile(char *logfile, int orig_umask);
598extern int timeout(u_int, void (*fn)(voidp), voidp);
599extern int valid_key(char *);
600extern mnt_map *mapc_find(char *, char *, const char *);
601extern mntfs *dup_mntfs(mntfs *);
602extern mntfs *find_mntfs(am_ops *, am_opts *, char *, char *, char *, char *, char *);
603extern mntfs *new_mntfs(void);
604extern mntfs *realloc_mntfs(mntfs *, am_ops *, am_opts *, char *, char *, char *, char *, char *);
605extern mntlist *read_mtab(char *, const char *);
606extern struct sockaddr_in *amu_svc_getcaller(SVCXPRT *xprt);
607extern time_t time(time_t *);
608extern void am_mounted(am_node *);
609extern void am_unmounted(am_node *);
610extern void amq_program_1(struct svc_req *rqstp, SVCXPRT *transp);
611extern void amu_get_myaddress(struct in_addr *iap);
612extern void amu_release_controlling_tty(void);
613extern void compute_automounter_nfs_args(nfs_args_t *nap, mntent_t *mntp);
614extern void deslashify(char *);
615extern void discard_mntlist(mntlist *mp);
616extern void do_task_notify(void);
617extern void flush_mntfs(void);
618extern void flush_nfs_fhandle_cache(fserver *);
619extern void forcibly_timeout_mp(am_node *);
620extern void free_map(am_node *);
621extern void free_mntfs(voidp);
622extern void free_mntlist(mntlist *);
623extern void free_opts(am_opts *);
624extern void free_srvr(fserver *);
625extern void fwd_reply(void);
626extern void get_args(int argc, char *argv[]);
627extern void getwire(char **name1, char **number1);
628extern void going_down(int);
629extern void host_normalize(char **);
630extern void init_map(am_node *, char *);
631extern void ins_que(qelem *, qelem *);
632extern void insert_am(am_node *, am_node *);
633extern void make_root_node(void);
634extern void map_flush_srvr(fserver *);
635extern void mapc_add_kv(mnt_map *, char *, char *);
636extern void mapc_free(voidp);
637extern void mapc_reload(void);
638extern void mapc_showtypes(char *buf);
639extern void mk_fattr(am_node *, nfsftype);
640extern void mnt_free(mntent_t *);
641extern void mp_to_fh(am_node *, am_nfs_fh *);
642extern void new_ttl(am_node *);
643extern void nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp);
644extern void normalize_slash(char *);
645extern void ops_showamfstypes(char *buf);
646extern void ops_showfstypes(char *outbuf);
647extern void plog(int, const char *,...)
648     __attribute__ ((__format__ (__printf__, 2, 3)));
649extern void rem_que(qelem *);
650extern void reschedule_timeout_mp(void);
651extern void restart(void);
652extern void rmdirs(char *);
653extern void rpc_msg_init(struct rpc_msg *, u_long, u_long, u_long);
654extern void run_task(task_fun, voidp, cb_fun, voidp);
655extern void sched_task(cb_fun, voidp, voidp);
656extern void set_amd_program_number(int program);
657extern void show_opts(int ch, struct opt_tab *);
658extern void show_rcs_info(const char *, char *);
659extern void srvrlog(fserver *, char *);
660extern void timeout_mp(voidp);
661extern void umount_exported(void);
662extern void unregister_amq(void);
663extern void untimeout(int);
664extern void wakeup(voidp);
665extern void wakeup_srvr(fserver *);
666extern void wakeup_task(int, int, voidp);
667extern voidp xmalloc(int);
668extern voidp xrealloc(voidp, int);
669extern voidp xzalloc(int);
670extern u_long get_nfs_version(char *host, struct sockaddr_in *sin, u_long nfs_version, const char *proto);
671
672
673#ifdef MOUNT_TABLE_ON_FILE
674extern void rewrite_mtab(mntlist *, const char *);
675extern void unlock_mntlist(void);
676extern void write_mntent(mntent_t *, const char *);
677#endif /* MOUNT_TABLE_ON_FILE */
678
679#if defined(HAVE_SYSLOG_H) || defined(HAVE_SYS_SYSLOG_H)
680extern int syslogging;
681#endif /* defined(HAVE_SYSLOG_H) || defined(HAVE_SYS_SYSLOG_H) */
682
683#ifdef HAVE_TRANSPORT_TYPE_TLI
684
685extern void compute_nfs_args(nfs_args_t *nap, mntent_t *mntp, int genflags, struct netconfig *nfsncp, struct sockaddr_in *ip_addr, u_long nfs_version, char *nfs_proto, am_nfs_handle_t *fhp, char *host_name, char *fs_name);
686extern int create_amq_service(int *udp_soAMQp, SVCXPRT **udp_amqpp, struct netconfig **udp_amqncpp, int *tcp_soAMQp, SVCXPRT **tcp_amqpp, struct netconfig **tcp_amqncpp);
687extern int create_nfs_service(int *soNFSp, u_short *nfs_portp, SVCXPRT **nfs_xprtp, void (*dispatch_fxn)(struct svc_req *rqstp, SVCXPRT *transp));
688extern int get_knetconfig(struct knetconfig **kncpp, struct netconfig *in_ncp, char *nc_protoname);
689extern struct netconfig *nfsncp;
690extern void free_knetconfig(struct knetconfig *kncp);
691
692#else /* not HAVE_TRANSPORT_TYPE_TLI */
693
694extern void compute_nfs_args(nfs_args_t *nap, mntent_t *mntp, int genflags, struct sockaddr_in *ip_addr, u_long nfs_version, char *nfs_proto, am_nfs_handle_t *fhp, char *host_name, char *fs_name);
695extern enum clnt_stat pmap_ping(struct sockaddr_in *address);
696extern int create_amq_service(int *udp_soAMQp, SVCXPRT **udp_amqpp, int *tcp_soAMQp, SVCXPRT **tcp_amqpp);
697extern int create_nfs_service(int *soNFSp, u_short *nfs_portp, SVCXPRT **nfs_xprtp, void (*dispatch_fxn)(struct svc_req *rqstp, SVCXPRT *transp));
698
699#endif /* not HAVE_TRANSPORT_TYPE_TLI */
700
701#ifndef HAVE_STRUCT_FHSTATUS_FHS_FH
702# define fhs_fh  fhstatus_u.fhs_fhandle
703#endif /* not HAVE_STRUCT_FHSTATUS_FHS_FH */
704
705
706/**************************************************************************/
707/*** Generic file-system types, implemented as part of the native O/S.	***/
708/**************************************************************************/
709
710/*
711 * Loopback File System
712 * Many systems can't support this, and in any case most of the
713 * functionality is available with Symlink FS.
714 */
715#ifdef HAVE_FS_LOFS
716extern am_ops lofs_ops;
717#endif /* HAVE_FS_LOFS */
718
719/*
720 * CD-ROM File System (CD-ROM)
721 * (HSFS: High Sierra F/S on some machines)
722 * Many systems can't support this, and in any case most of the
723 * functionality is available with program FS.
724 */
725#ifdef HAVE_FS_CDFS
726extern am_ops cdfs_ops;
727#endif /* HAVE_FS_CDFS */
728
729/*
730 * PC File System (MS-DOS)
731 * Many systems can't support this, and in any case most of the
732 * functionality is available with program FS.
733 */
734#ifdef HAVE_FS_PCFS
735extern am_ops pcfs_ops;
736#endif /* HAVE_FS_PCFS */
737
738/*
739 * Caching File System (Solaris)
740 */
741#ifdef HAVE_FS_CACHEFS
742extern am_ops cachefs_ops;
743#endif /* HAVE_FS_CACHEFS */
744
745/*
746 * Network File System
747 * Good, slow, NFS V.2.
748 */
749#ifdef HAVE_FS_NFS
750extern am_ops nfs_ops;		/* NFS */
751extern fserver *find_nfs_srvr (mntfs *);
752extern int nfs_fmount(mntfs *mf);
753extern int nfs_fumount(mntfs *mf);
754extern int nfs_init(mntfs *mf);
755extern qelem nfs_srvr_list;
756extern void nfs_umounted(am_node *mp);
757#endif /* HAVE_FS_NFS */
758
759
760/*
761 * Network File System: the new generation
762 * NFS V.3
763 */
764#ifdef HAVE_FS_NFS3
765# ifndef NFS_VERSION3
766#  define NFS_VERSION3 ((u_int) 3)
767# endif /* not NFS_VERSION3 */
768#endif /* HAVE_FS_NFS3 */
769
770/*
771 * Un*x File System
772 * Normal local disk file system.
773 */
774#ifdef HAVE_FS_UFS
775extern am_ops ufs_ops;		/* Un*x file system */
776#endif /* HAVE_FS_UFS */
777
778
779/**************************************************************************/
780/*** Automounter file-system types, implemented by amd.			***/
781/**************************************************************************/
782
783/*
784 * Automount File System
785 */
786#ifdef HAVE_AMU_FS_AUTO
787extern am_ops amfs_auto_ops;	/* Automount file system (this!) */
788extern am_ops amfs_toplvl_ops;	/* Top-level automount file system */
789extern am_ops amfs_root_ops;	/* Root file system */
790extern qelem amfs_auto_srvr_list;
791extern am_node *amfs_auto_lookuppn(am_node *mp, char *fname, int *error_return, int op);
792extern am_node *next_nonerror_node(am_node *xp);
793extern char *amfs_auto_match(am_opts *fo);
794extern fserver *find_amfs_auto_srvr(mntfs *);
795extern int amfs_auto_readdir(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, int count);
796extern int amfs_auto_umount(am_node *mp);
797extern int amfs_auto_fmount(am_node *mp);
798extern int amfs_auto_fumount(am_node *mp);
799#endif /* HAVE_AMU_FS_AUTO */
800
801/*
802 * Toplvl Automount File System
803 */
804#ifdef HAVE_AMU_FS_TOPLVL
805extern am_ops amfs_toplvl_ops;	/* Toplvl Automount file system */
806extern int amfs_toplvl_mount(am_node *mp);
807extern int amfs_toplvl_umount(am_node *mp);
808extern void amfs_toplvl_mounted(mntfs *mf);
809#endif /* HAVE_AMU_FS_TOPLVL */
810
811/*
812 * Direct Automount File System
813 */
814#ifdef HAVE_AMU_FS_DIRECT
815extern am_ops amfs_direct_ops;	/* Direct Automount file system (this too) */
816#endif /* HAVE_AMU_FS_DIRECT */
817
818/*
819 * Error File System
820 */
821#ifdef HAVE_AMU_FS_ERROR
822extern am_ops amfs_error_ops;	/* Error file system */
823extern am_node *amfs_error_lookuppn(am_node *mp, char *fname, int *error_return, int op);
824extern int amfs_error_readdir(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, int count);
825#endif /* HAVE_AMU_FS_ERROR */
826
827/*
828 * Inheritance File System
829 */
830#ifdef HAVE_AMU_FS_INHERIT
831extern am_ops amfs_inherit_ops;	/* Inheritance file system */
832#endif /* HAVE_AMU_FS_INHERIT */
833
834/*
835 * NFS mounts with local existence check.
836 */
837#ifdef HAVE_AMU_FS_NFSL
838extern am_ops amfs_nfsl_ops;	/* NFSL */
839#endif /* HAVE_AMU_FS_NFSL */
840
841/*
842 * Multi-nfs mounts.
843 */
844#ifdef HAVE_AMU_FS_NFSX
845extern am_ops amfs_nfsx_ops;	/* NFSX */
846#endif /* HAVE_AMU_FS_NFSX */
847
848/*
849 * NFS host - a whole tree.
850 */
851#ifdef HAVE_AMU_FS_HOST
852extern am_ops amfs_host_ops;	/* NFS host */
853#endif /* HAVE_AMU_FS_HOST */
854
855/*
856 * Program File System
857 * This is useful for things like RVD.
858 */
859#ifdef HAVE_AMU_FS_PROGRAM
860extern am_ops amfs_program_ops;	/* Program File System */
861#endif /* HAVE_AMU_FS_PROGRAM */
862
863/*
864 * Symbolic-link file system.
865 * A "filesystem" which is just a symbol link.
866 */
867#ifdef HAVE_AMU_FS_LINK
868extern am_ops amfs_link_ops;	/* Symlink FS */
869extern int amfs_link_fmount(mntfs *mf);
870#endif /* HAVE_AMU_FS_LINK */
871
872/*
873 * Symbolic-link file system, which also checks that the target of
874 * the symlink exists.
875 * A "filesystem" which is just a symbol link.
876 */
877#ifdef HAVE_AMU_FS_LINKX
878extern am_ops amfs_linkx_ops;	/* Symlink FS with existence check */
879#endif /* HAVE_AMU_FS_LINKX */
880
881/*
882 * Union file system
883 */
884#ifdef HAVE_AMU_FS_UNION
885extern am_ops amfs_union_ops;	/* Union FS */
886#endif /* HAVE_AMU_FS_UNION */
887
888
889/**************************************************************************/
890/*** DEBUGGING								***/
891/**************************************************************************/
892
893/*
894 * DEBUGGING:
895 */
896#ifdef DEBUG
897
898# define	D_ALL		(~0)
899# define	D_DAEMON	0x0001	/* Enter daemon mode */
900# define	D_TRACE		0x0002	/* Do protocol trace */
901# define	D_FULL		0x0004	/* Do full trace */
902# define	D_MTAB		0x0008	/* Use local mtab */
903# define	D_AMQ		0x0010	/* Register amq program */
904# define	D_STR		0x0020	/* Debug string munging */
905#  ifdef DEBUG_MEM
906# define	D_MEM		0x0040	/* Trace memory allocations */
907#  endif /* DEBUG_MEM */
908# define	D_FORK		0x0080	/* Fork server */
909		/* info service specific debugging (hesiod, nis, etc) */
910# define	D_INFO		0x0100
911# define	D_HRTIME	0x0200	/* Print high resolution time stamps */
912# define	D_XDRTRACE	0x0400	/* Trace xdr routines */
913# define	D_READDIR	0x0800	/* show browsable_dir progress */
914
915/*
916 * Normally, don't enter daemon mode, don't register amq, and don't trace xdr
917 */
918#  ifdef DEBUG_MEM
919# define	D_TEST	(~(D_DAEMON|D_MEM|D_STR|D_XDRTRACE))
920#  else /* not DEBUG_MEM */
921# define	D_TEST	(~(D_DAEMON|D_STR|D_XDRTRACE))
922#  endif /* not DEBUG_MEM */
923
924# define	amuDebug(x)	if (debug_flags & (x))
925# define	dlog		amuDebug(D_FULL) dplog
926# define	amuDebugNo(x)	if (!(debug_flags & (x)))
927
928/* debugging mount-table file to use */
929# ifndef DEBUG_MNTTAB
930#  define	DEBUG_MNTTAB	"./mnttab"
931# endif /* not DEBUG_MNTTAB */
932
933# ifdef DEBUG_MEM
934/*
935 * If debugging memory, then call a special freeing function that logs
936 * more info, and resets the pointer to NULL so it cannot be used again.
937 */
938#  define	XFREE(x) dxfree(__FILE__,__LINE__,x)
939extern void dxfree(char *file, int line, voidp ptr);
940extern void malloc_verify(void);
941# else /* not DEBUG_MEM */
942/*
943 * If regular debugging, then free the pointer and reset to NULL.
944 * This should remain so for as long as am-utils is in alpha/beta testing.
945 */
946#  define	XFREE(x) do { free((voidp)x); x = NULL;} while (0)
947# endif /* not DEBUG_MEM */
948
949/* functions that depend solely on debugging */
950extern void print_nfs_args(const nfs_args_t *nap, u_long nfs_version);
951extern int debug_option (char *opt);
952
953#else /* not DEBUG */
954
955/*
956 * if not debugging, then simple perform free, and don't bother
957 * resetting the pointer.
958 */
959#  define	XFREE(x) free(x)
960
961#define		amuDebug(x)	if (0)
962#define		dlog		if (0) dplog
963#define		amuDebugNo(x)	if (0)
964
965#define		print_nfs_args(nap, nfs_version)
966#define		debug_option(x)	(1)
967
968#endif /* not DEBUG */
969
970extern int debug_flags;		/* Debug options */
971extern struct opt_tab dbg_opt[];
972extern void dplog(const char *fmt, ...)
973     __attribute__ ((__format__ (__printf__, 1, 2)));
974
975/**************************************************************************/
976/*** MISC (stuff left to autoconfiscate)				***/
977/**************************************************************************/
978
979#endif /* not _AM_UTILS_H */
980