1*bbef9da5Schristos /* $NetBSD: am_utils.h,v 1.2 2015/10/14 16:00:17 christos Exp $ */ 2a53f50b9Schristos 3a53f50b9Schristos /* 48bae5d40Schristos * Copyright (c) 1997-2014 Erez Zadok 5a53f50b9Schristos * Copyright (c) 1990 Jan-Simon Pendry 6a53f50b9Schristos * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 7a53f50b9Schristos * Copyright (c) 1990 The Regents of the University of California. 8a53f50b9Schristos * All rights reserved. 9a53f50b9Schristos * 10a53f50b9Schristos * This code is derived from software contributed to Berkeley by 11a53f50b9Schristos * Jan-Simon Pendry at Imperial College, London. 12a53f50b9Schristos * 13a53f50b9Schristos * Redistribution and use in source and binary forms, with or without 14a53f50b9Schristos * modification, are permitted provided that the following conditions 15a53f50b9Schristos * are met: 16a53f50b9Schristos * 1. Redistributions of source code must retain the above copyright 17a53f50b9Schristos * notice, this list of conditions and the following disclaimer. 18a53f50b9Schristos * 2. Redistributions in binary form must reproduce the above copyright 19a53f50b9Schristos * notice, this list of conditions and the following disclaimer in the 20a53f50b9Schristos * documentation and/or other materials provided with the distribution. 218bae5d40Schristos * 3. Neither the name of the University nor the names of its contributors 22a53f50b9Schristos * may be used to endorse or promote products derived from this software 23a53f50b9Schristos * without specific prior written permission. 24a53f50b9Schristos * 25a53f50b9Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26a53f50b9Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27a53f50b9Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28a53f50b9Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29a53f50b9Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30a53f50b9Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31a53f50b9Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32a53f50b9Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33a53f50b9Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34a53f50b9Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35a53f50b9Schristos * SUCH DAMAGE. 36a53f50b9Schristos * 37a53f50b9Schristos * 38a53f50b9Schristos * File: am-utils/include/am_utils.h 39a53f50b9Schristos * 40a53f50b9Schristos */ 41a53f50b9Schristos 42a53f50b9Schristos /* 43a53f50b9Schristos * Definitions that are specific to the am-utils package. 44a53f50b9Schristos */ 45a53f50b9Schristos 46a53f50b9Schristos #ifndef _AM_UTILS_H 47a53f50b9Schristos #define _AM_UTILS_H 48a53f50b9Schristos 49a53f50b9Schristos 50a53f50b9Schristos #include "aux_conf.h" 51a53f50b9Schristos 52a53f50b9Schristos /**************************************************************************/ 53a53f50b9Schristos /*** MACROS ***/ 54a53f50b9Schristos /**************************************************************************/ 55a53f50b9Schristos 56*bbef9da5Schristos #if !defined(__syslog_attribute__) && !defined(__syslog__) 57*bbef9da5Schristos #define __syslog__ __printf__ 58*bbef9da5Schristos #endif 59*bbef9da5Schristos 60a53f50b9Schristos /* 61a53f50b9Schristos * General macros. 62a53f50b9Schristos */ 63a53f50b9Schristos #ifndef FALSE 64a53f50b9Schristos # define FALSE 0 65a53f50b9Schristos #endif /* not FALSE */ 66a53f50b9Schristos #ifndef TRUE 67a53f50b9Schristos # define TRUE 1 68a53f50b9Schristos #endif /* not TRUE */ 69a53f50b9Schristos #ifndef MAX 70a53f50b9Schristos # define MAX(a, b) ((a) > (b) ? (a) : (b)) 71a53f50b9Schristos #endif /* not MAX */ 72a53f50b9Schristos #ifndef MIN 73a53f50b9Schristos # define MIN(a, b) ((a) < (b) ? (a) : (b)) 74a53f50b9Schristos #endif /* not MIN */ 75a53f50b9Schristos 76a53f50b9Schristos #define ONE_HOUR (60 * 60) /* One hour in seconds */ 77a53f50b9Schristos 78a53f50b9Schristos #ifndef MAXHOSTNAMELEN 79a53f50b9Schristos # ifdef HOSTNAMESZ 80a53f50b9Schristos # define MAXHOSTNAMELEN HOSTNAMESZ 81a53f50b9Schristos # else /* not HOSTNAMESZ */ 82a53f50b9Schristos # define MAXHOSTNAMELEN 256 83a53f50b9Schristos # endif /* not HOSTNAMESZ */ 84a53f50b9Schristos #endif /* not MAXHOSTNAMELEN */ 85a53f50b9Schristos 86a53f50b9Schristos /* 87a53f50b9Schristos * for hlfsd, and amd for detecting uid/gid 88a53f50b9Schristos */ 89a53f50b9Schristos #ifndef INVALIDID 90a53f50b9Schristos /* this is also defined in include/am_utils.h */ 91a53f50b9Schristos # define INVALIDID (((unsigned short) ~0) - 3) 92a53f50b9Schristos #endif /* not INVALIDID */ 93a53f50b9Schristos 94a53f50b9Schristos /* 95a53f50b9Schristos * String comparison macros 96a53f50b9Schristos */ 97a53f50b9Schristos #define STREQ(s1, s2) (strcmp((s1), (s2)) == 0) 98a53f50b9Schristos #define STRCEQ(s1, s2) (strcasecmp((s1), (s2)) == 0) 99a53f50b9Schristos #define NSTREQ(s1, s2, n) (strncmp((s1), (s2), (n)) == 0) 100a53f50b9Schristos #define NSTRCEQ(s1, s2, n) (strncasecmp((s1), (s2), (n)) == 0) 101a53f50b9Schristos #define FSTREQ(s1, s2) ((*(s1) == *(s2)) && STREQ((s1),(s2))) 102a53f50b9Schristos 103a53f50b9Schristos /* 104a53f50b9Schristos * Logging options/flags 105a53f50b9Schristos */ 106a53f50b9Schristos #define XLOG_FATAL 0x0001 107a53f50b9Schristos #define XLOG_ERROR 0x0002 108a53f50b9Schristos #define XLOG_USER 0x0004 109a53f50b9Schristos #define XLOG_WARNING 0x0008 110a53f50b9Schristos #define XLOG_INFO 0x0010 111a53f50b9Schristos #define XLOG_DEBUG 0x0020 112a53f50b9Schristos #define XLOG_MAP 0x0040 113a53f50b9Schristos #define XLOG_STATS 0x0080 114a53f50b9Schristos /* log option compositions */ 115a53f50b9Schristos #define XLOG_MASK 0x00ff /* mask for all flags */ 116a53f50b9Schristos #define XLOG_MANDATORY (XLOG_FATAL|XLOG_ERROR) /* cannot turn these off */ 117a53f50b9Schristos #define XLOG_ALL (XLOG_FATAL|XLOG_ERROR|XLOG_USER|XLOG_WARNING|XLOG_INFO|XLOG_MAP|XLOG_STATS) 118a53f50b9Schristos /* default: fatal + error + user + warning + info */ 119a53f50b9Schristos #define XLOG_DEFAULT (XLOG_MASK & (XLOG_ALL & ~XLOG_MAP & ~XLOG_STATS)) 120a53f50b9Schristos 121a53f50b9Schristos /* default: no logging options */ 122a53f50b9Schristos 123a53f50b9Schristos #define NO_SUBNET "notknown" /* default subnet name for no subnet */ 124a53f50b9Schristos #define NEXP_AP (1022) /* gdmr: was 254 */ 125a53f50b9Schristos #define NEXP_AP_MARGIN (128) /* ???? not used */ 126a53f50b9Schristos 127a53f50b9Schristos /* 128a53f50b9Schristos * Linked list macros 129a53f50b9Schristos */ 130a53f50b9Schristos #define AM_FIRST(ty, q) ((ty *) ((q)->q_forw)) 131a53f50b9Schristos #define AM_LAST(ty, q) ((ty *) ((q)->q_back)) 132a53f50b9Schristos #define NEXT(ty, q) ((ty *) (((qelem *) q)->q_forw)) 133a53f50b9Schristos #define PREV(ty, q) ((ty *) (((qelem *) q)->q_back)) 134a53f50b9Schristos #define HEAD(ty, q) ((ty *) q) 135a53f50b9Schristos #define ITER(v, ty, q) \ 136a53f50b9Schristos for ((v) = AM_FIRST(ty,(q)); (v) != HEAD(ty,(q)); (v) = NEXT(ty,(v))) 137a53f50b9Schristos 138a53f50b9Schristos /* allocate anything of type ty */ 139a53f50b9Schristos #define ALLOC(ty) ((ty *) xmalloc(sizeof(ty))) 140a53f50b9Schristos #define CALLOC(ty) ((ty *) xzalloc(sizeof(ty))) 141a53f50b9Schristos /* simply allocate b bytes */ 142a53f50b9Schristos #define SALLOC(b) xmalloc((b)) 143a53f50b9Schristos 144a53f50b9Schristos /* 145a53f50b9Schristos * Systems which have the mount table in a file need to read it before 146a53f50b9Schristos * they can perform an unmount() system call. 147a53f50b9Schristos */ 148a53f50b9Schristos #define UMOUNT_FS(dir, mtb_name, unmount_flags) umount_fs(dir, mtb_name, unmount_flags) 149a53f50b9Schristos /* next two are imported via $srcdir/conf/umount/umount_*.c */ 150a53f50b9Schristos extern int umount_fs(char *mntdir, const char *mnttabname, u_int unmount_flags); 151a53f50b9Schristos #ifdef MNT2_GEN_OPT_FORCE 152a53f50b9Schristos extern int umount2_fs(const char *mntdir, u_int unmount_flags); 153a53f50b9Schristos #endif /* MNT2_GEN_OPT_FORCE */ 154a53f50b9Schristos 155a53f50b9Schristos /* unmount-related flags (special handling of autofs, forced/lazy, etc.) */ 156a53f50b9Schristos #define AMU_UMOUNT_FORCE 0x1 157a53f50b9Schristos #define AMU_UMOUNT_DETACH 0x2 158a53f50b9Schristos #define AMU_UMOUNT_AUTOFS 0x4 159a53f50b9Schristos 160a53f50b9Schristos /* 161a53f50b9Schristos * The following values can be tuned... 162a53f50b9Schristos */ 163a53f50b9Schristos #define ALLOWED_MOUNT_TIME 40 /* 40s for a mount */ 164a53f50b9Schristos 165a53f50b9Schristos /* 166a53f50b9Schristos * RPC-related macros. 167a53f50b9Schristos */ 168a53f50b9Schristos #define RPC_XID_PORTMAP 0 169a53f50b9Schristos #define RPC_XID_MOUNTD 1 170a53f50b9Schristos #define RPC_XID_NFSPING 2 171a53f50b9Schristos #define RPC_XID_WEBNFS 3 172a53f50b9Schristos #define RPC_XID_MASK (0x0f) /* 16 id's for now */ 173a53f50b9Schristos #define MK_RPC_XID(type_id, uniq) ((type_id) | ((uniq) << 4)) 174a53f50b9Schristos 175a53f50b9Schristos /* 176a53f50b9Schristos * What level of AMD are we backward compatible with? 177a53f50b9Schristos * This only applies to externally visible characteristics. 178a53f50b9Schristos * Rev.Minor.Branch.Patch (2 digits each) 179a53f50b9Schristos */ 180a53f50b9Schristos #define AMD_COMPAT 5000000 /* 5.0 */ 181a53f50b9Schristos 182a53f50b9Schristos 183a53f50b9Schristos /**************************************************************************/ 184a53f50b9Schristos /*** STRUCTURES AND TYPEDEFS ***/ 185a53f50b9Schristos /**************************************************************************/ 186a53f50b9Schristos 187a53f50b9Schristos /* some typedefs must come first */ 188a53f50b9Schristos typedef char *amq_string; 189a53f50b9Schristos typedef struct _qelem qelem; 190a53f50b9Schristos typedef struct mntlist mntlist; 191a53f50b9Schristos 192a53f50b9Schristos /* 193a53f50b9Schristos * Linked list 194a53f50b9Schristos * (the name 'struct qelem' conflicts with linux's unistd.h) 195a53f50b9Schristos */ 196a53f50b9Schristos struct _qelem { 197a53f50b9Schristos qelem *q_forw; 198a53f50b9Schristos qelem *q_back; 199a53f50b9Schristos }; 200a53f50b9Schristos 201a53f50b9Schristos /* 202a53f50b9Schristos * Option tables 203a53f50b9Schristos */ 204a53f50b9Schristos struct opt_tab { 205a53f50b9Schristos char *opt; 206a53f50b9Schristos int flag; 207a53f50b9Schristos }; 208a53f50b9Schristos 209a53f50b9Schristos /* 210a53f50b9Schristos * Server states 211a53f50b9Schristos */ 212a53f50b9Schristos typedef enum { 213a53f50b9Schristos Start, 214a53f50b9Schristos Run, 215a53f50b9Schristos Finishing, 216a53f50b9Schristos Quit, 217a53f50b9Schristos Done 218a53f50b9Schristos } serv_state; 219a53f50b9Schristos 220a53f50b9Schristos 221a53f50b9Schristos /* 222a53f50b9Schristos * List of mount table entries 223a53f50b9Schristos */ 224a53f50b9Schristos struct mntlist { 225a53f50b9Schristos struct mntlist *mnext; 226a53f50b9Schristos mntent_t *mnt; 227a53f50b9Schristos }; 228a53f50b9Schristos 229a53f50b9Schristos /* 230a53f50b9Schristos * Mount map 231a53f50b9Schristos */ 232a53f50b9Schristos typedef struct mnt_map mnt_map; 233a53f50b9Schristos 234a53f50b9Schristos 235a53f50b9Schristos /**************************************************************************/ 236a53f50b9Schristos /*** EXTERNALS ***/ 237a53f50b9Schristos /**************************************************************************/ 238a53f50b9Schristos 239a53f50b9Schristos /* 240a53f50b9Schristos * Useful constants 241a53f50b9Schristos */ 242a53f50b9Schristos extern char *mnttab_file_name; /* Mount table */ 243a53f50b9Schristos extern char *cpu; /* "CPU type" */ 244a53f50b9Schristos extern char *endian; /* "big" */ 245a53f50b9Schristos extern char *hostdomain; /* "southseas.nz" */ 246a53f50b9Schristos extern char copyright[]; /* Copyright info */ 247a53f50b9Schristos extern char version[]; /* Version info */ 248a53f50b9Schristos 249a53f50b9Schristos /* 250a53f50b9Schristos * Global variables. 251a53f50b9Schristos */ 252a53f50b9Schristos extern AUTH *nfs_auth; /* Dummy authorization for remote servers */ 253a53f50b9Schristos extern FILE *logfp; /* Log file */ 254a53f50b9Schristos extern SVCXPRT *nfsxprt; 255a53f50b9Schristos extern char *PrimNetName; /* Name of primary connected network */ 256a53f50b9Schristos extern char *PrimNetNum; /* Name of primary connected network */ 257a53f50b9Schristos extern char *SubsNetName; /* Name of subsidiary connected network */ 258a53f50b9Schristos extern char *SubsNetNum; /* Name of subsidiary connected network */ 259a53f50b9Schristos 260a53f50b9Schristos extern void am_set_progname(char *pn); /* "amd" */ 261a53f50b9Schristos extern const char *am_get_progname(void); /* "amd" */ 262a53f50b9Schristos extern void am_set_hostname(char *hn); 263a53f50b9Schristos extern const char *am_get_hostname(void); 264a53f50b9Schristos extern pid_t am_set_mypid(void); 265a53f50b9Schristos extern pid_t am_mypid; 266a53f50b9Schristos 267a53f50b9Schristos extern int foreground; /* Foreground process */ 268a53f50b9Schristos extern int orig_umask; /* umask() on startup */ 269a53f50b9Schristos extern serv_state amd_state; /* Should we go now */ 270a53f50b9Schristos extern struct in_addr myipaddr; /* (An) IP address of this host */ 271a53f50b9Schristos extern struct opt_tab xlog_opt[]; 272a53f50b9Schristos extern u_short nfs_port; /* Our NFS service port */ 273a53f50b9Schristos 274a53f50b9Schristos /* 275a53f50b9Schristos * Global routines 276a53f50b9Schristos */ 277a53f50b9Schristos extern CLIENT *get_mount_client(char *unused_host, struct sockaddr_in *sin, struct timeval *tv, int *sock, u_long mnt_version); 278a53f50b9Schristos extern RETSIGTYPE sigchld(int); 279a53f50b9Schristos extern bool_t xdr_amq_string(XDR *xdrs, amq_string *objp); 280a53f50b9Schristos extern bool_t xdr_dirpath(XDR *xdrs, dirpath *objp); 281a53f50b9Schristos extern char **strsplit(char *, int, int); 282a53f50b9Schristos extern char *expand_selectors(char *); 283a53f50b9Schristos extern char *get_version_string(void); 284a53f50b9Schristos extern char *inet_dquad(char *, size_t, u_long); 285a53f50b9Schristos extern char *print_wires(void); 286a53f50b9Schristos extern char *str3cat(char *, char *, char *, char *); 2878bae5d40Schristos extern char *strvcat(const char *, ...); 288a53f50b9Schristos extern char *strealloc(char *, char *); 289a53f50b9Schristos extern char *strip_selectors(char *, char *); 290a53f50b9Schristos extern char *strnsave(const char *, int); 291a53f50b9Schristos extern int amu_close(int fd); 292a53f50b9Schristos extern int bind_resv_port(int, u_short *); 293a53f50b9Schristos extern int cmdoption(char *, struct opt_tab *, u_int *); 294a53f50b9Schristos extern int compute_automounter_mount_flags(mntent_t *); 295a53f50b9Schristos extern int compute_mount_flags(mntent_t *); 2968bae5d40Schristos extern void discard_nfs_args(void *, u_long); 297a53f50b9Schristos extern u_long get_amd_program_number(void); 298a53f50b9Schristos extern int getcreds(struct svc_req *, uid_t *, gid_t *, SVCXPRT *); 299a53f50b9Schristos extern int hasmntval(mntent_t *, char *); 300a53f50b9Schristos extern unsigned int hasmntvalerr(mntent_t *, char *, int *); 301a53f50b9Schristos extern char *hasmntstr(mntent_t *, char *); 302a53f50b9Schristos extern char *hasmnteq(mntent_t *, char *); 303a53f50b9Schristos extern char *haseq(char *); 304a53f50b9Schristos extern int is_network_member(const char *net); 305a53f50b9Schristos extern int is_interface_local(u_long); 306a53f50b9Schristos extern int islocalnet(u_long); 307a53f50b9Schristos extern int make_rpc_packet(char *, int, u_long, struct rpc_msg *, voidp, XDRPROC_T_TYPE, AUTH *); 308a53f50b9Schristos extern int mkdirs(char *, int); 309a53f50b9Schristos extern int mount_fs(mntent_t *, int, caddr_t, int, MTYPE_TYPE, u_long, const char *, const char *, int); 310a53f50b9Schristos extern void nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp); 3118bae5d40Schristos extern void nfs_program_3(struct svc_req *rqstp, SVCXPRT *transp); 3128bae5d40Schristos #define get_nfs_dispatcher_version(a) \ 3138bae5d40Schristos ((a) == nfs_program_2 ? NFS_VERSION : NFS_VERSION3) 314a53f50b9Schristos extern int pickup_rpc_reply(voidp, int, voidp, XDRPROC_T_TYPE); 315a53f50b9Schristos extern int switch_option(char *); 316a53f50b9Schristos extern int switch_to_logfile(char *logfile, int orig_umask, int truncate_log); 317a53f50b9Schristos extern mntlist *read_mtab(char *, const char *); 318a53f50b9Schristos #ifndef HAVE_TRANSPORT_TYPE_TLI 319a53f50b9Schristos extern struct sockaddr_in *amu_svc_getcaller(SVCXPRT *xprt); 320a53f50b9Schristos #endif /* not HAVE_TRANSPORT_TYPE_TLI */ 321a53f50b9Schristos extern time_t time(time_t *); 322a53f50b9Schristos extern void amu_get_myaddress(struct in_addr *iap, const char *preferred_localhost); 323a53f50b9Schristos extern void amu_release_controlling_tty(void); 324a53f50b9Schristos extern void compute_automounter_nfs_args(nfs_args_t *nap, mntent_t *mntp); 325a53f50b9Schristos extern void discard_mntlist(mntlist *mp); 326a53f50b9Schristos extern void free_mntlist(mntlist *); 327a53f50b9Schristos extern void getwire(char **name1, char **number1); 328a53f50b9Schristos extern void going_down(int); 329a53f50b9Schristos extern void mnt_free(mntent_t *); 330a53f50b9Schristos extern void plog(int, const char *,...) 331*bbef9da5Schristos __attribute__ ((__format__ (__syslog__, 2, 3))); 332a53f50b9Schristos extern void rmdirs(char *); 333a53f50b9Schristos extern void rpc_msg_init(struct rpc_msg *, u_long, u_long, u_long); 334a53f50b9Schristos extern void set_amd_program_number(u_long program); 335a53f50b9Schristos extern void show_opts(int ch, struct opt_tab *); 336a53f50b9Schristos extern void unregister_amq(void); 337a53f50b9Schristos extern voidp xmalloc(int); 338a53f50b9Schristos extern voidp xrealloc(voidp, int); 339a53f50b9Schristos extern voidp xzalloc(int); 3408bae5d40Schristos extern char *xstrdup(const char *); 341a53f50b9Schristos extern int check_pmap_up(char *host, struct sockaddr_in* sin); 3428bae5d40Schristos extern u_long get_nfs_version(char *host, struct sockaddr_in *sin, u_long nfs_version, const char *proto, u_long def); 3438bae5d40Schristos extern int nfs_valid_version(u_long vers); 344a53f50b9Schristos extern long get_server_pid(void); 345a53f50b9Schristos extern void setup_sighandler(int signum, void (*handler)(int)); 346a53f50b9Schristos extern time_t clocktime(nfstime *nt); 347a53f50b9Schristos 348a53f50b9Schristos #if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS)) 349a53f50b9Schristos # ifdef HAVE_C99_VARARGS_MACROS 350a53f50b9Schristos #define xsnprintf(str,size,fmt,...) _xsnprintf(__FILE__,__LINE__,(str),(size),(fmt),__VA_ARGS__) 351a53f50b9Schristos # endif /* HAVE_C99_VARARGS_MACROS */ 352a53f50b9Schristos # ifdef HAVE_GCC_VARARGS_MACROS 353a53f50b9Schristos #define xsnprintf(str,size,fmt,args...) _xsnprintf(__FILE__,__LINE__,(str),(size),(fmt),args) 354a53f50b9Schristos # endif /* HAVE_GCC_VARARGS_MACROS */ 355a53f50b9Schristos extern int _xsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, ...); 356a53f50b9Schristos #define xvsnprintf(str,size,fmt,ap) _xvsnprintf(__FILE__,__LINE__,(str),(size),(fmt),(ap)) 357a53f50b9Schristos extern int _xvsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, va_list ap); 358a53f50b9Schristos #else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ 359a53f50b9Schristos extern int xsnprintf(char *str, size_t size, const char *format, ...); 360a53f50b9Schristos extern int xvsnprintf(char *str, size_t size, const char *format, va_list ap); 361a53f50b9Schristos #endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ 362a53f50b9Schristos 363a53f50b9Schristos #ifdef DEBUG 364a53f50b9Schristos extern void _xstrlcat(const char *filename, int lineno, char *dst, const char *src, size_t len); 365a53f50b9Schristos # define xstrlcat(d,s,l) _xstrlcat(__FILE__,__LINE__,(d),(s),(l)) 366a53f50b9Schristos extern void _xstrlcpy(const char *filename, int lineno, char *dst, const char *src, size_t len); 367a53f50b9Schristos # define xstrlcpy(d,s,l) _xstrlcpy(__FILE__,__LINE__,(d),(s),(l)) 368a53f50b9Schristos #else /* not DEBUG */ 369a53f50b9Schristos extern void xstrlcat(char *dst, const char *src, size_t len); 370a53f50b9Schristos extern void xstrlcpy(char *dst, const char *src, size_t len); 371a53f50b9Schristos #endif /* not DEBUG */ 372a53f50b9Schristos 373a53f50b9Schristos #ifdef MOUNT_TABLE_ON_FILE 374a53f50b9Schristos extern void rewrite_mtab(mntlist *, const char *); 375a53f50b9Schristos extern void unlock_mntlist(void); 376a53f50b9Schristos extern void write_mntent(mntent_t *, const char *); 377a53f50b9Schristos #endif /* MOUNT_TABLE_ON_FILE */ 378a53f50b9Schristos 379a53f50b9Schristos #if defined(HAVE_SYSLOG_H) || defined(HAVE_SYS_SYSLOG_H) 380a53f50b9Schristos extern int syslogging; 381a53f50b9Schristos #endif /* defined(HAVE_SYSLOG_H) || defined(HAVE_SYS_SYSLOG_H) */ 382a53f50b9Schristos 3838bae5d40Schristos extern void compute_nfs_args(void *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); 3848bae5d40Schristos extern void destroy_nfs_args(void *nap, u_long nfs_version); 385a53f50b9Schristos extern int create_amq_service(int *udp_soAMQp, SVCXPRT **udp_amqpp, struct netconfig **udp_amqncpp, int *tcp_soAMQp, SVCXPRT **tcp_amqpp, struct netconfig **tcp_amqncpp, u_short preferred_amq_port); 3868bae5d40Schristos extern int create_nfs_service(int *soNFSp, u_short *nfs_portp, SVCXPRT **nfs_xprtp, void (*dispatch_fxn)(struct svc_req *rqstp, SVCXPRT *transp), u_long nfs_version); 387a53f50b9Schristos extern int amu_svc_register(SVCXPRT *, u_long, u_long, void (*)(struct svc_req *, SVCXPRT *), u_long, struct netconfig *); 388a53f50b9Schristos 389a53f50b9Schristos #ifdef HAVE_TRANSPORT_TYPE_TLI 390a53f50b9Schristos 391a53f50b9Schristos extern int get_knetconfig(struct knetconfig **kncpp, struct netconfig *in_ncp, char *nc_protoname); 392a53f50b9Schristos extern struct netconfig *nfsncp; 393a53f50b9Schristos extern void free_knetconfig(struct knetconfig *kncp); 394a53f50b9Schristos 395a53f50b9Schristos #endif /* HAVE_TRANSPORT_TYPE_TLI */ 396a53f50b9Schristos 397a53f50b9Schristos #ifdef HAVE_FS_AUTOFS 398a53f50b9Schristos extern int register_autofs_service(char *autofs_conftype, void (*autofs_dispatch)(struct svc_req *rqstp, SVCXPRT *xprt)); 399a53f50b9Schristos extern int unregister_autofs_service(char *autofs_conftype); 400a53f50b9Schristos #endif /* HAVE_FS_AUTOFS */ 401a53f50b9Schristos 402a53f50b9Schristos 403a53f50b9Schristos #ifndef HAVE_STRUCT_FHSTATUS_FHS_FH 404a53f50b9Schristos # define fhs_fh fhstatus_u.fhs_fhandle 405a53f50b9Schristos #endif /* not HAVE_STRUCT_FHSTATUS_FHS_FH */ 406a53f50b9Schristos 407a53f50b9Schristos 408a53f50b9Schristos /* 4098bae5d40Schristos * Network File System: the old faithful generation NFS V.2 4108bae5d40Schristos */ 4118bae5d40Schristos #ifndef NFS_VERSION2 4128bae5d40Schristos # define NFS_VERSION2 ((u_int) 2) 4138bae5d40Schristos #endif /* not NFS_VERSION2 */ 4148bae5d40Schristos 4158bae5d40Schristos /* 4168bae5d40Schristos * Network File System: the not so new anymore generation NFS V.3 417a53f50b9Schristos */ 418a53f50b9Schristos #ifdef HAVE_FS_NFS3 419a53f50b9Schristos # ifndef NFS_VERSION3 420a53f50b9Schristos # define NFS_VERSION3 ((u_int) 3) 421a53f50b9Schristos # endif /* not NFS_VERSION3 */ 422a53f50b9Schristos #endif /* HAVE_FS_NFS3 */ 423a53f50b9Schristos 4248bae5d40Schristos /* 4258bae5d40Schristos * Network File System: the new generation NFS V.4 4268bae5d40Schristos */ 4278bae5d40Schristos #ifdef HAVE_FS_NFS4 4288bae5d40Schristos # ifndef NFS_VERSION4 4298bae5d40Schristos # define NFS_VERSION4 ((u_int) 4) 4308bae5d40Schristos # endif /* not NFS_VERSION4 */ 4318bae5d40Schristos #endif /* HAVE_FS_NFS4 */ 432a53f50b9Schristos 433a53f50b9Schristos /**************************************************************************/ 434a53f50b9Schristos /*** DEBUGGING ***/ 435a53f50b9Schristos /**************************************************************************/ 436a53f50b9Schristos 437a53f50b9Schristos /* 438a53f50b9Schristos * DEBUGGING: 439a53f50b9Schristos */ 440a53f50b9Schristos 441a53f50b9Schristos #ifdef DEBUG 442a53f50b9Schristos 443a53f50b9Schristos # define D_DAEMON 0x0001 /* Enter daemon mode */ 444a53f50b9Schristos # define D_TRACE 0x0002 /* Do protocol trace */ 445a53f50b9Schristos # define D_FULL 0x0004 /* Do full trace */ 446a53f50b9Schristos # define D_MTAB 0x0008 /* Use local mtab */ 447a53f50b9Schristos # define D_AMQ 0x0010 /* Register amq program */ 448a53f50b9Schristos # define D_STR 0x0020 /* Debug string munging */ 449a53f50b9Schristos # ifdef DEBUG_MEM 450a53f50b9Schristos # define D_MEM 0x0040 /* Trace memory allocations */ 451a53f50b9Schristos # else /* not DEBUG_MEM */ 452a53f50b9Schristos # define D_MEM 0x0000 /* Dummy */ 453a53f50b9Schristos # endif /* not DEBUG_MEM */ 454a53f50b9Schristos # define D_FORK 0x0080 /* Fork server (hlfsd only) */ 455a53f50b9Schristos # define D_INFO 0x0100 /* info service specific debugging (hesiod, nis, etc) */ 456a53f50b9Schristos # define D_HRTIME 0x0200 /* Print high resolution time stamps */ 457a53f50b9Schristos # define D_XDRTRACE 0x0400 /* Trace xdr routines */ 458a53f50b9Schristos # define D_READDIR 0x0800 /* Show browsable_dir progress */ 459a53f50b9Schristos /* debug option compositions */ 460a53f50b9Schristos # define D_MASK 0x0fff /* mask of known flags */ 461a53f50b9Schristos # define D_BASIC (D_TRACE|D_FULL|D_STR|D_MEM|D_INFO|D_XDRTRACE|D_READDIR) 462a53f50b9Schristos # define D_CONTROL (D_DAEMON|D_AMQ|D_FORK) 463a53f50b9Schristos /* immutable flags: cannot be changed via "amq -D" */ 464a53f50b9Schristos # define D_IMMUTABLE (D_MTAB | D_CONTROL) 465a53f50b9Schristos # define D_ALL (D_BASIC | D_CONTROL) 466a53f50b9Schristos # define D_DEFAULT (D_MASK & D_ALL & ~D_XDRTRACE) 467a53f50b9Schristos /* test mode: nodaemon, noamq, nofork, (local) mtab */ 468a53f50b9Schristos # define D_TEST (D_BASIC | D_MTAB) 469a53f50b9Schristos 470a53f50b9Schristos # define amuDebug(x) (debug_flags & (x)) 471a53f50b9Schristos # define dlog if (amuDebug(D_FULL)) dplog 472a53f50b9Schristos 473a53f50b9Schristos /* my favorite debugging tool -Erez */ 474a53f50b9Schristos #define EZKDBG plog(XLOG_INFO,"EZK:%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__) 475a53f50b9Schristos 476a53f50b9Schristos # ifdef DEBUG_MEM 477a53f50b9Schristos /* 478a53f50b9Schristos * If debugging memory, then call a special freeing function that logs 479a53f50b9Schristos * more info, and resets the pointer to NULL so it cannot be used again. 480a53f50b9Schristos */ 481a53f50b9Schristos # define XFREE(x) dxfree(__FILE__,__LINE__,x) 482a53f50b9Schristos extern void dxfree(char *file, int line, voidp ptr); 483a53f50b9Schristos extern void malloc_verify(void); 484a53f50b9Schristos # else /* not DEBUG_MEM */ 485a53f50b9Schristos /* 486a53f50b9Schristos * If regular debugging, then free the pointer and reset to NULL. 487a53f50b9Schristos * This should remain so for as long as am-utils is in alpha/beta testing. 488a53f50b9Schristos */ 489a53f50b9Schristos # define XFREE(x) do { free((voidp)x); x = NULL;} while (0) 490a53f50b9Schristos # endif /* not DEBUG_MEM */ 491a53f50b9Schristos 492a53f50b9Schristos /* functions that depend solely on debugging */ 4938bae5d40Schristos extern void print_nfs_args(const void *, u_long nfs_version); 494a53f50b9Schristos extern int debug_option (char *opt); 495a53f50b9Schristos extern void dplog(const char *fmt, ...) 496*bbef9da5Schristos __attribute__ ((__format__ (__syslog__, 1, 2))); 497a53f50b9Schristos 498a53f50b9Schristos #else /* not DEBUG */ 499a53f50b9Schristos 500a53f50b9Schristos /* set dummy flags to zero */ 501a53f50b9Schristos # define D_DAEMON 0x0001 /* Enter daemon mode */ 502a53f50b9Schristos # define D_TRACE 0x0000 /* dummy: Do protocol trace */ 503a53f50b9Schristos # define D_FULL 0x0000 /* dummy: Do full trace */ 504a53f50b9Schristos # define D_MTAB 0x0000 /* dummy: Use local mtab */ 505a53f50b9Schristos # define D_AMQ 0x0010 /* Register amq program */ 506a53f50b9Schristos # define D_STR 0x0000 /* dummy: Debug string munging */ 507a53f50b9Schristos # define D_MEM 0x0000 /* dummy: Trace memory allocations */ 508a53f50b9Schristos # define D_FORK 0x0080 /* Fork server (hlfsd only) */ 509a53f50b9Schristos # define D_INFO 0x0000 /* dummy: info service debugging */ 510a53f50b9Schristos # define D_HRTIME 0x0000 /* dummy: hi-res time stamps */ 511a53f50b9Schristos # define D_XDRTRACE 0x0000 /* dummy: Trace xdr routines */ 512a53f50b9Schristos # define D_READDIR 0x0000 /* dummy: browsable_dir progress */ 513a53f50b9Schristos # define D_CONTROL (D_DAEMON|D_AMQ|D_FORK) 514a53f50b9Schristos # define amuDebug(x) (debug_flags & (x)) 515a53f50b9Schristos /* 516a53f50b9Schristos * If not debugging, then also reset the pointer. 517a53f50b9Schristos * It's safer -- and besides, free() should do that anyway. 518a53f50b9Schristos */ 519a53f50b9Schristos # define XFREE(x) do { free((voidp)x); x = NULL;} while (0) 520a53f50b9Schristos 521a53f50b9Schristos # if defined(HAVE_GCC_VARARGS_MACROS) 522a53f50b9Schristos # define dlog(fmt...) 523a53f50b9Schristos # elif defined(HAVE_C99_VARARGS_MACROS) 524a53f50b9Schristos # define dlog(...) 525a53f50b9Schristos # else /* no c99 varargs */ 526a53f50b9Schristos /* this define means that we CCP leaves code behind the (list,of,args) */ 527a53f50b9Schristos # define dlog 528a53f50b9Schristos # endif /* no c99 varargs */ 529a53f50b9Schristos 530a53f50b9Schristos # define print_nfs_args(nap, nfs_version) 531a53f50b9Schristos # define debug_option(x) (1) 532a53f50b9Schristos 533a53f50b9Schristos #endif /* not DEBUG */ 534a53f50b9Schristos 535a53f50b9Schristos extern u_int debug_flags; /* Debug options */ 536a53f50b9Schristos extern struct opt_tab dbg_opt[]; 537a53f50b9Schristos 538a53f50b9Schristos /**************************************************************************/ 539a53f50b9Schristos /*** MISC (stuff left to autoconfiscate) ***/ 540a53f50b9Schristos /**************************************************************************/ 541a53f50b9Schristos 542a53f50b9Schristos #endif /* not _AM_UTILS_H */ 543