]> git.decadent.org.uk Git - nfs-utils.git/blob - support/include/nfslib.h
cee826bb6f5f9ecb160b02dbe019f839ee7edf36
[nfs-utils.git] / support / include / nfslib.h
1 /*
2  * support/include/nfslib.h
3  *
4  * General support functions for NFS user-space programs.
5  *
6  * Copyright (C) 1995 Olaf Kirch <okir@monad.swb.de>
7  */
8
9 #ifndef NFSLIB_H
10 #define NFSLIB_H
11
12 #ifdef HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <stdio.h>
20 #include <paths.h>
21 #include <rpcsvc/nfs_prot.h>
22 #include <nfs/nfs.h>
23 #include "xlog.h"
24
25 #ifndef _PATH_EXPORTS
26 #define _PATH_EXPORTS           "/etc/exports"
27 #endif
28 #ifndef _PATH_EXPORTS_D
29 #define _PATH_EXPORTS_D         "/etc/exports.d"
30 #endif
31 #ifndef _EXT_EXPORT
32 #define _EXT_EXPORT             ".exports"
33 #endif
34 #ifndef _PATH_IDMAPDCONF
35 #define _PATH_IDMAPDCONF        "/etc/idmapd.conf"
36 #endif
37 #ifndef _PATH_XTAB
38 #define _PATH_XTAB              NFS_STATEDIR "/xtab"
39 #endif
40 #ifndef _PATH_XTABTMP
41 #define _PATH_XTABTMP           NFS_STATEDIR "/xtab.tmp"
42 #endif
43 #ifndef _PATH_XTABLCK
44 #define _PATH_XTABLCK           NFS_STATEDIR "/.xtab.lock"
45 #endif
46 #ifndef _PATH_ETAB
47 #define _PATH_ETAB              NFS_STATEDIR "/etab"
48 #endif
49 #ifndef _PATH_ETABTMP
50 #define _PATH_ETABTMP           NFS_STATEDIR "/etab.tmp"
51 #endif
52 #ifndef _PATH_ETABLCK
53 #define _PATH_ETABLCK           NFS_STATEDIR "/.etab.lock"
54 #endif
55 #ifndef _PATH_RMTAB
56 #define _PATH_RMTAB             NFS_STATEDIR "/rmtab"
57 #endif
58 #ifndef _PATH_RMTABTMP
59 #define _PATH_RMTABTMP          _PATH_RMTAB ".tmp"
60 #endif
61 #ifndef _PATH_RMTABLCK
62 #define _PATH_RMTABLCK          NFS_STATEDIR "/.rmtab.lock"
63 #endif
64 #ifndef _PATH_PROC_EXPORTS
65 #define _PATH_PROC_EXPORTS      "/proc/fs/nfs/exports"
66 #define _PATH_PROC_EXPORTS_ALT  "/proc/fs/nfsd/exports"
67 #endif
68
69 /* Maximum number of security flavors on an export: */
70 #define SECFLAVOR_COUNT 8
71
72 struct sec_entry {
73         struct flav_info *flav;
74         int flags;
75 };
76
77 /*
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.
81  */
82 struct exportent {
83         char *          e_hostname;
84         char            e_path[NFS_MAXPATHLEN+1];
85         int             e_flags;
86         int             e_anonuid;
87         int             e_anongid;
88         int *           e_squids;
89         int             e_nsquids;
90         int *           e_sqgids;
91         int             e_nsqgids;
92         unsigned int    e_fsid;
93         char *          e_mountpoint;
94         int             e_fslocmethod;
95         char *          e_fslocdata;
96         char *          e_uuid;
97         struct sec_entry e_secinfo[SECFLAVOR_COUNT+1];
98 };
99
100 struct rmtabent {
101         char            r_client[NFSCLNT_IDMAX+1];
102         char            r_path[NFS_MAXPATHLEN+1];
103         int             r_count;
104 };
105
106 /*
107  * configuration file parsing
108  */
109 void                    setexportent(char *fname, char *type);
110 struct exportent *      getexportent(int,int);
111 void                    secinfo_show(FILE *fp, struct exportent *ep);
112 void                    putexportent(struct exportent *xep);
113 void                    endexportent(void);
114 struct exportent *      mkexportent(char *hname, char *path, char *opts);
115 void                    dupexportent(struct exportent *dst,
116                                         struct exportent *src);
117 int                     updateexportent(struct exportent *eep, char *options);
118
119 int                     setrmtabent(char *type);
120 struct rmtabent *       getrmtabent(int log, long *pos);
121 void                    putrmtabent(struct rmtabent *xep, long *pos);
122 void                    endrmtabent(void);
123 void                    rewindrmtabent(void);
124 FILE *                  fsetrmtabent(char *fname, char *type);
125 struct rmtabent *       fgetrmtabent(FILE *fp, int log, long *pos);
126 void                    fputrmtabent(FILE *fp, struct rmtabent *xep, long *pos);
127 void                    fendrmtabent(FILE *fp);
128 void                    frewindrmtabent(FILE *fp);
129
130 /*
131  * wildmat borrowed from INN
132  */
133 int                     wildmat(char *text, char *pattern);
134
135 /*
136  * nfsd library functions.
137  */
138 int                     nfsctl(int, struct nfsctl_arg *, union nfsctl_res *);
139 int                     nfsaddclient(struct nfsctl_client *clp);
140 int                     nfsdelclient(struct nfsctl_client *clp);
141 int                     nfsexport(struct nfsctl_export *exp);
142 int                     nfsunexport(struct nfsctl_export *exp);
143
144 struct nfs_fh_len *     getfh_old(const struct sockaddr_in *sin,
145                                         const dev_t dev, const ino_t ino);
146 struct nfs_fh_len *     getfh(const struct sockaddr_in *sin, const char *path);
147 struct nfs_fh_len *     getfh_size(const struct sockaddr_in *sin,
148                                         const char *path, int const size);
149
150 void qword_print(FILE *f, char *str);
151 void qword_printhex(FILE *f, char *str, int slen);
152 void qword_printint(FILE *f, int num);
153 int qword_eol(FILE *f);
154 int readline(int fd, char **buf, int *lenp);
155 int qword_get(char **bpp, char *dest, int bufsize);
156 int qword_get_int(char **bpp, int *anint);
157 void cache_flush(int force);
158 int check_new_cache(void);
159 void qword_add(char **bpp, int *lp, char *str);
160 void qword_addhex(char **bpp, int *lp, char *buf, int blen);
161 void qword_addint(char **bpp, int *lp, int n);
162 void qword_adduint(char **bpp, int *lp, unsigned int n);
163 void qword_addeol(char **bpp, int *lp);
164 int qword_get_uint(char **bpp, unsigned int *anint);
165 void qword_printuint(FILE *f, unsigned int num);
166
167 void closeall(int min);
168
169 int                     svctcp_socket (u_long __number, int __reuse);
170 int                     svcudp_socket (u_long __number);
171
172 /* Misc shared code prototypes */
173 size_t  strlcat(char *, const char *, size_t);
174 size_t  strlcpy(char *, const char *, size_t);
175 ssize_t atomicio(ssize_t (*f) (int, void*, size_t),
176                  int, void *, size_t);
177
178
179 #define UNUSED(x) UNUSED_ ## x __attribute__((unused))
180
181 #endif /* NFSLIB_H */