2 * support/include/nfslib.h
4 * General support functions for NFS user-space programs.
6 * Copyright (C) 1995 Olaf Kirch <okir@monad.swb.de>
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
21 #include <rpcsvc/nfs_prot.h>
26 #define _PATH_EXPORTS "/etc/exports"
28 #ifndef _PATH_EXPORTS_D
29 #define _PATH_EXPORTS_D "/etc/exports.d"
32 #define _EXT_EXPORT ".exports"
34 #ifndef _PATH_IDMAPDCONF
35 #define _PATH_IDMAPDCONF "/etc/idmapd.conf"
38 #define _PATH_XTAB NFS_STATEDIR "/xtab"
41 #define _PATH_XTABTMP NFS_STATEDIR "/xtab.tmp"
44 #define _PATH_XTABLCK NFS_STATEDIR "/.xtab.lock"
47 #define _PATH_ETAB NFS_STATEDIR "/etab"
50 #define _PATH_ETABTMP NFS_STATEDIR "/etab.tmp"
53 #define _PATH_ETABLCK NFS_STATEDIR "/.etab.lock"
56 #define _PATH_RMTAB NFS_STATEDIR "/rmtab"
58 #ifndef _PATH_RMTABTMP
59 #define _PATH_RMTABTMP _PATH_RMTAB ".tmp"
61 #ifndef _PATH_RMTABLCK
62 #define _PATH_RMTABLCK NFS_STATEDIR "/.rmtab.lock"
64 #ifndef _PATH_PROC_EXPORTS
65 #define _PATH_PROC_EXPORTS "/proc/fs/nfs/exports"
66 #define _PATH_PROC_EXPORTS_ALT "/proc/fs/nfsd/exports"
69 /* Maximum number of security flavors on an export: */
70 #define SECFLAVOR_COUNT 8
73 struct flav_info *flav;
78 * Data related to a single exports entry as returned by getexportent.
79 * FIXME: export options should probably be parsed at a later time to
80 * allow overrides when using exportfs.
84 char e_path[NFS_MAXPATHLEN+1];
97 struct sec_entry e_secinfo[SECFLAVOR_COUNT+1];
102 char r_client[NFSCLNT_IDMAX+1];
103 char r_path[NFS_MAXPATHLEN+1];
108 * configuration file parsing
110 void setexportent(char *fname, char *type);
111 struct exportent * getexportent(int,int);
112 void secinfo_show(FILE *fp, struct exportent *ep);
113 void putexportent(struct exportent *xep);
114 void endexportent(void);
115 struct exportent * mkexportent(char *hname, char *path, char *opts);
116 void dupexportent(struct exportent *dst,
117 struct exportent *src);
118 int updateexportent(struct exportent *eep, char *options);
120 int setrmtabent(char *type);
121 struct rmtabent * getrmtabent(int log, long *pos);
122 void putrmtabent(struct rmtabent *xep, long *pos);
123 void endrmtabent(void);
124 void rewindrmtabent(void);
125 FILE * fsetrmtabent(char *fname, char *type);
126 struct rmtabent * fgetrmtabent(FILE *fp, int log, long *pos);
127 void fputrmtabent(FILE *fp, struct rmtabent *xep, long *pos);
128 void fendrmtabent(FILE *fp);
129 void frewindrmtabent(FILE *fp);
132 * wildmat borrowed from INN
134 int wildmat(char *text, char *pattern);
137 * nfsd library functions.
139 int nfsctl(int, struct nfsctl_arg *, union nfsctl_res *);
140 int nfsaddclient(struct nfsctl_client *clp);
141 int nfsdelclient(struct nfsctl_client *clp);
142 int nfsexport(struct nfsctl_export *exp);
143 int nfsunexport(struct nfsctl_export *exp);
145 struct nfs_fh_len * getfh_old(const struct sockaddr_in *sin,
146 const dev_t dev, const ino_t ino);
147 struct nfs_fh_len * getfh(const struct sockaddr_in *sin, const char *path);
148 struct nfs_fh_len * getfh_size(const struct sockaddr_in *sin,
149 const char *path, int const size);
151 void qword_print(FILE *f, char *str);
152 void qword_printhex(FILE *f, char *str, int slen);
153 void qword_printint(FILE *f, int num);
154 int qword_eol(FILE *f);
155 int readline(int fd, char **buf, int *lenp);
156 int qword_get(char **bpp, char *dest, int bufsize);
157 int qword_get_int(char **bpp, int *anint);
158 void cache_flush(int force);
159 int check_new_cache(void);
160 void qword_add(char **bpp, int *lp, char *str);
161 void qword_addhex(char **bpp, int *lp, char *buf, int blen);
162 void qword_addint(char **bpp, int *lp, int n);
163 void qword_adduint(char **bpp, int *lp, unsigned int n);
164 void qword_addeol(char **bpp, int *lp);
165 int qword_get_uint(char **bpp, unsigned int *anint);
166 void qword_printuint(FILE *f, unsigned int num);
168 void closeall(int min);
170 int svctcp_socket (u_long __number, int __reuse);
171 int svcudp_socket (u_long __number);
173 /* Misc shared code prototypes */
174 size_t strlcat(char *, const char *, size_t);
175 size_t strlcpy(char *, const char *, size_t);
176 ssize_t atomicio(ssize_t (*f) (int, void*, size_t),
177 int, void *, size_t);
180 #define UNUSED(x) UNUSED_ ## x __attribute__((unused))
182 #endif /* NFSLIB_H */