]> git.decadent.org.uk Git - nfs-utils.git/blob - support/include/nfslib.h
73f3c20cd6c9db64096cd9d53192cd799b9755a8
[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         unsigned int    e_ttl;
99 };
100
101 struct rmtabent {
102         char            r_client[NFSCLNT_IDMAX+1];
103         char            r_path[NFS_MAXPATHLEN+1];
104         int             r_count;
105 };
106
107 /*
108  * configuration file parsing
109  */
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);
119
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);
130
131 /*
132  * wildmat borrowed from INN
133  */
134 int                     wildmat(char *text, char *pattern);
135
136 /*
137  * nfsd library functions.
138  */
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);
144
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);
150
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);
167
168 void closeall(int min);
169
170 int                     svctcp_socket (u_long __number, int __reuse);
171 int                     svcudp_socket (u_long __number);
172
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);
178
179
180 #define UNUSED(x) UNUSED_ ## x __attribute__((unused))
181
182 #endif /* NFSLIB_H */