Merge from vendor branch LESS:
[dragonfly.git] / contrib / amd / amd / amd.h
1 /*
2  * Copyright (c) 1997-1999 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: amd.h,v 1.4 1999/09/30 21:01:29 ezk Exp $
42  *
43  */
44
45 #ifndef _AMD_H
46 #define _AMD_H
47
48
49 /*
50  * MACROS:
51  */
52
53 /* options for amd.conf */
54 #define CFM_BROWSABLE_DIRS              0x0001
55 #define CFM_MOUNT_TYPE_AUTOFS           0x0002
56 #define CFM_ENABLE_DEFAULT_SELECTORS    0x0004
57 #define CFM_NORMALIZE_HOSTNAMES         0x0008
58 #define CFM_PROCESS_LOCK                0x0010
59 #define CFM_PRINT_PID                   0x0020
60 #define CFM_RESTART_EXISTING_MOUNTS     0x0040
61 #define CFM_SHOW_STATFS_ENTRIES         0x0080
62 #define CFM_FULLY_QUALIFIED_HOSTS       0x0100
63 #define CFM_BROWSABLE_DIRS_FULL         0x0200 /* allow '/' in readdir() */
64 #define CFM_UNMOUNT_ON_EXIT             0x0400 /* when amd finishing */
65
66 /* some systems (SunOS 4.x) neglect to define the mount null message */
67 #ifndef MOUNTPROC_NULL
68 # define MOUNTPROC_NULL ((u_long)(0))
69 #endif /* not MOUNTPROC_NULL */
70
71 /* Hash table size */
72 #define NKVHASH (1 << 2)        /* Power of two */
73
74 /* interval between forced retries of a mount */
75 #define RETRY_INTERVAL  2
76
77 #define ereturn(x) { *error_return = x; return 0; }
78
79
80 /*
81  * TYPEDEFS:
82  */
83
84 typedef struct cf_map cf_map_t;
85 typedef struct kv kv;
86 /*
87  * Cache map operations
88  */
89 typedef void add_fn(mnt_map *, char *, char *);
90 typedef int init_fn(mnt_map *, char *, time_t *);
91 typedef int mtime_fn(mnt_map *, char *, time_t *);
92 typedef int isup_fn(mnt_map *, char *);
93 typedef int reload_fn(mnt_map *, char *, add_fn *);
94 typedef int search_fn(mnt_map *, char *, char *, char **, time_t *);
95
96
97
98 /*
99  * STRUCTURES:
100  */
101
102 /* global amd options that are manipulated by conf.c */
103 struct amu_global_options {
104   char *arch;                   /* name of current architecture */
105   char *auto_dir;               /* automounter temp dir */
106   char *cluster;                /* cluster name */
107   char *karch;                  /* kernel architecture */
108   char *logfile;                /* amd log file */
109   char *op_sys;                 /* operating system name ${os} */
110   char *op_sys_ver;             /* OS version ${osver} */
111   char *op_sys_full;            /* full OS name ${full_os} */
112   char *op_sys_vendor;          /* name of OS vendor ${vendor} */
113   char *pid_file;               /* PID file */
114   char *sub_domain;             /* local domain */
115   char *map_options;            /* global map options */
116   char *map_type;               /* global map type */
117   char *search_path;            /* search path for maps */
118   char *mount_type;             /* mount type for map */
119   u_int flags;                  /* various CFM_* flags */
120   int amfs_auto_retrans;        /* NFS retransmit counter */
121   int amfs_auto_timeo;          /* NFS retry interval */
122   int am_timeo;                 /* cache duration */
123   int am_timeo_w;               /* dismount interval */
124   int portmap_program;          /* amd RPC program number */
125 #ifdef HAVE_MAP_HESIOD
126   char *hesiod_base;            /* Hesiod rhs */
127 #endif /* HAVE_MAP_HESIOD */
128 #ifdef HAVE_MAP_LDAP
129   char *ldap_base;              /* LDAP base */
130   char *ldap_hostports;         /* LDAP host ports */
131   long ldap_cache_seconds;      /* LDAP internal cache - keep seconds */
132   long ldap_cache_maxmem;       /* LDAP internal cache - max memory (bytes) */
133 #endif /* HAVE_MAP_LDAP */
134 #ifdef HAVE_MAP_NIS
135   char *nis_domain;             /* YP domain name */
136 #endif /* HAVE_MAP_NIS */
137 };
138
139 /* if you add anything here, update conf.c:reset_cf_map() */
140 struct cf_map {
141   char *cfm_dir;                /* /home, /u, /src */
142   char *cfm_name;               /* amd.home, /etc/amd.home ... */
143   char *cfm_type;               /* file, hesiod, ndbm, nis ... */
144   char *cfm_opts;               /* -cache:=all, etc. */
145   char *cfm_search_path;        /* /etc/local:/etc/amdmaps:/misc/yp */
146   char *cfm_tag;                /* optional map tag for amd -T */
147   u_int cfm_flags;              /* browsable_dirs? mount_type? */
148 };
149
150 /*
151  * Key-value pair
152  */
153 struct kv {
154   kv *next;
155   char *key;
156 #ifdef HAVE_REGEXEC
157   regex_t re;                   /* store the regexp from regcomp() */
158 #endif /* HAVE_REGEXEC */
159   char *val;
160 };
161
162 struct mnt_map {
163   qelem hdr;
164   int refc;                     /* Reference count */
165   short flags;                  /* Allocation flags */
166   short alloc;                  /* Allocation mode */
167   time_t modify;                /* Modify time of map */
168   u_int reloads;                /* Number of times map was reloaded */
169   char *map_name;               /* Name of this map */
170   char *wildcard;               /* Wildcard value */
171   reload_fn *reload;            /* Function to be used for reloads */
172   isup_fn *isup;                /* Is service up or not? (1=up, 0=down) */
173   search_fn *search;            /* Function to be used for searching */
174   mtime_fn *mtime;              /* Modify time function */
175   kv *kvhash[NKVHASH];          /* Cached data */
176   /* options available via amd conf file */
177   char *cf_map_type;            /* file, hesiod, ndbm, nis, etc. */
178   char *cf_search_path;         /* /etc/local:/etc/amdmaps:/misc/yp */
179   void *map_data;               /* Map data black box */
180 };
181
182 /*
183  * Mounting a file system may take a significant period of time.  The
184  * problem is that if this is done in the main process thread then the
185  * entire automounter could be blocked, possibly hanging lots of processes
186  * on the system.  Instead we use a continuation scheme to allow mounts to
187  * be attempted in a sub-process.  When the sub-process exits we pick up the
188  * exit status (by convention a UN*X error number) and continue in a
189  * notifier.  The notifier gets handed a data structure and can then
190  * determine whether the mount was successful or not.  If not, it updates
191  * the data structure and tries again until there are no more ways to try
192  * the mount, or some other permanent error occurs.  In the mean time no RPC
193  * reply is sent, even after the mount is successful.  We rely on the RPC
194  * retry mechanism to resend the lookup request which can then be handled.
195  */
196 struct continuation {
197   char **ivec;                  /* Current mount info */
198   am_node *mp;                  /* Node we are trying to mount */
199   char *key;                    /* Map key */
200   char *info;                   /* Info string */
201   char **xivec;                 /* Saved strsplit vector */
202   char *auto_opts;              /* Automount options */
203   am_opts fs_opts;              /* Filesystem options */
204   char *def_opts;               /* Default automount options */
205   int retry;                    /* Try again? */
206   int tried;                    /* Have we tried any yet? */
207   time_t start;                 /* Time we started this mount */
208   int callout;                  /* Callout identifier */
209 };
210
211
212 /*
213  * EXTERNALS:
214  */
215
216 /* Amq server global functions */
217 extern amq_mount_info_list *amqproc_getmntfs_1_svc(voidp argp, struct svc_req *rqstp);
218 extern amq_mount_stats *amqproc_stats_1_svc(voidp argp, struct svc_req *rqstp);
219 extern amq_mount_tree_list *amqproc_export_1_svc(voidp argp, struct svc_req *rqstp);
220 extern amq_mount_tree_p *amqproc_mnttree_1_svc(voidp argp, struct svc_req *rqstp);
221 extern amq_string *amqproc_getvers_1_svc(voidp argp, struct svc_req *rqstp);
222 extern int *amqproc_getpid_1_svc(voidp argp, struct svc_req *rqstp);
223 extern int *amqproc_mount_1_svc(voidp argp, struct svc_req *rqstp);
224 extern int *amqproc_setopt_1_svc(voidp argp, struct svc_req *rqstp);
225 extern voidp amqproc_null_1_svc(voidp argp, struct svc_req *rqstp);
226 extern voidp amqproc_umnt_1_svc(voidp argp, struct svc_req *rqstp);
227
228 /* other external definitions */
229 extern am_nfs_fh *root_fh(char *dir);
230 extern am_node * autofs_lookuppn(am_node *mp, char *fname, int *error_return, int op);
231 extern am_node *find_ap(char *);
232 extern am_node *find_ap2(char *, am_node *);
233 extern bool_t xdr_amq_mount_info_qelem(XDR *xdrs, qelem *qhead);
234 extern fserver *find_nfs_srvr(mntfs *mf);
235 extern int auto_fmount(am_node *mp);
236 extern int auto_fumount(am_node *mp);
237 extern int mount_nfs_fh(am_nfs_handle_t *fhp, char *dir, char *fs_name, char *opts, mntfs *mf);
238 extern int process_last_regular_map(void);
239 extern int set_conf_kv(const char *section, const char *k, const char *v);
240 extern int try_mount(voidp mvp);
241 extern int yyparse (void);
242 extern nfsentry *make_entry_chain(am_node *mp, const nfsentry *current_chain, int fully_browsable);
243 extern void amfs_auto_cont(int rc, int term, voidp closure);
244 extern void amfs_auto_mkcacheref(mntfs *mf);
245 extern void amfs_auto_retry(int rc, int term, voidp closure);
246 extern void assign_error_mntfs(am_node *mp);
247 extern void flush_srvr_nfs_cache(void);
248 extern void free_continuation(struct continuation *cp);
249 extern void mf_mounted(mntfs *mf);
250 extern void quick_reply(am_node *mp, int error);
251 extern void root_newmap(const char *, const char *, const char *, const cf_map_t *);
252
253 /* amd global variables */
254 extern FILE *yyin;
255 extern SVCXPRT *nfs_program_2_transp;   /* For quick_reply() */
256 extern char *conf_tag;
257 extern int NumChild;
258 extern int fwd_sock;
259 extern int select_intr_valid;
260 extern int usage;
261 extern int use_conf_file;       /* use amd configuration file */
262 extern jmp_buf select_intr;
263 extern qelem mfhead;
264 extern struct amu_global_options gopt;  /* where global options are stored */
265
266 #ifdef HAVE_SIGACTION
267 extern sigset_t masked_sigs;
268 #endif /* HAVE_SIGACTION */
269
270 #if defined(HAVE_AM_FS_LINK) || defined(HAVE_AM_FS_LINKX)
271 extern char *amfs_link_match(am_opts *fo);
272 extern int amfs_link_fumount(mntfs *mf);
273 #endif /* defined(HAVE_AM_FS_LINK) || defined(HAVE_AM_FS_LINKX) */
274
275 #ifdef HAVE_AM_FS_NFSL
276 extern char *nfs_match(am_opts *fo);
277 #endif /* HAVE_AM_FS_NFSL */
278
279 #if defined(HAVE_FS_NFS3) && !defined(HAVE_XDR_MOUNTRES3)
280 extern bool_t xdr_mountres3(XDR *xdrs, mountres3 *objp);
281 #endif /* defined(HAVE_FS_NFS3) && !defined(HAVE_XDR_MOUNTRES3) */
282
283 #ifdef HAVE_FS_AUTOFS
284 extern SVCXPRT *autofsxprt;
285 extern u_short autofs_port;
286 extern int amd_use_autofs;
287
288 extern int autofs_mount(am_node *mp);
289 extern int autofs_umount(am_node *mp);
290 extern int create_autofs_service(int *soAUTOFSp, u_short *autofs_portp, SVCXPRT **autofs_xprtp, void (*dispatch_fxn)(struct svc_req *rqstp, SVCXPRT *transp));
291 extern int svc_create_local_service(void (*dispatch) (), u_long prognum, u_long versnum, char *nettype, char *servname);
292 extern void autofs_mounted(mntfs *mf);
293 extern void autofs_program_1(struct svc_req *rqstp, SVCXPRT *transp);
294 #endif /* HAVE_FS_AUTOFS */
295
296 /* Unix file system (irix) */
297 #ifdef HAVE_FS_XFS
298 extern am_ops xfs_ops;          /* Un*x file system */
299 #endif /* HAVE_FS_XFS */
300
301 /* Unix file system (irix) */
302 #ifdef HAVE_FS_EFS
303 extern am_ops efs_ops;          /* Un*x file system */
304 #endif /* HAVE_FS_EFS */
305
306 #endif /* not _AMD_H */