]> git.decadent.org.uk Git - nfs-utils.git/blob - support/include/nfslib.h
utils/nfsd: add support for minorvers4
[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_IDMAPDCONF
29 #define _PATH_IDMAPDCONF        "/etc/idmapd.conf"
30 #endif
31 #ifndef _PATH_XTAB
32 #define _PATH_XTAB              NFS_STATEDIR "/xtab"
33 #endif
34 #ifndef _PATH_XTABTMP
35 #define _PATH_XTABTMP           NFS_STATEDIR "/xtab.tmp"
36 #endif
37 #ifndef _PATH_XTABLCK
38 #define _PATH_XTABLCK           NFS_STATEDIR "/.xtab.lock"
39 #endif
40 #ifndef _PATH_ETAB
41 #define _PATH_ETAB              NFS_STATEDIR "/etab"
42 #endif
43 #ifndef _PATH_ETABTMP
44 #define _PATH_ETABTMP           NFS_STATEDIR "/etab.tmp"
45 #endif
46 #ifndef _PATH_ETABLCK
47 #define _PATH_ETABLCK           NFS_STATEDIR "/.etab.lock"
48 #endif
49 #ifndef _PATH_RMTAB
50 #define _PATH_RMTAB             NFS_STATEDIR "/rmtab"
51 #endif
52 #ifndef _PATH_RMTABTMP
53 #define _PATH_RMTABTMP          _PATH_RMTAB ".tmp"
54 #endif
55 #ifndef _PATH_RMTABLCK
56 #define _PATH_RMTABLCK          NFS_STATEDIR "/.rmtab.lock"
57 #endif
58 #ifndef _PATH_PROC_EXPORTS
59 #define _PATH_PROC_EXPORTS      "/proc/fs/nfs/exports"
60 #define _PATH_PROC_EXPORTS_ALT  "/proc/fs/nfsd/exports"
61 #endif
62
63 /* Maximum number of security flavors on an export: */
64 #define SECFLAVOR_COUNT 8
65
66 struct sec_entry {
67         struct flav_info *flav;
68         int flags;
69 };
70
71 /*
72  * Data related to a single exports entry as returned by getexportent.
73  * FIXME: export options should probably be parsed at a later time to
74  * allow overrides when using exportfs.
75  */
76 struct exportent {
77         char *          e_hostname;
78         char            e_path[NFS_MAXPATHLEN+1];
79         int             e_flags;
80         int             e_anonuid;
81         int             e_anongid;
82         int *           e_squids;
83         int             e_nsquids;
84         int *           e_sqgids;
85         int             e_nsqgids;
86         int             e_fsid;
87         char *          e_mountpoint;
88         int             e_fslocmethod;
89         char *          e_fslocdata;
90         char *          e_uuid;
91         struct sec_entry e_secinfo[SECFLAVOR_COUNT+1];
92 };
93
94 struct rmtabent {
95         char            r_client[NFSCLNT_IDMAX+1];
96         char            r_path[NFS_MAXPATHLEN+1];
97         int             r_count;
98 };
99
100 /*
101  * configuration file parsing
102  */
103 void                    setexportent(char *fname, char *type);
104 struct exportent *      getexportent(int,int);
105 void                    secinfo_show(FILE *fp, struct exportent *ep);
106 void                    putexportent(struct exportent *xep);
107 void                    endexportent(void);
108 struct exportent *      mkexportent(char *hname, char *path, char *opts);
109 void                    dupexportent(struct exportent *dst,
110                                         struct exportent *src);
111 int                     updateexportent(struct exportent *eep, char *options);
112
113 int                     setrmtabent(char *type);
114 struct rmtabent *       getrmtabent(int log, long *pos);
115 void                    putrmtabent(struct rmtabent *xep, long *pos);
116 void                    endrmtabent(void);
117 void                    rewindrmtabent(void);
118 FILE *                  fsetrmtabent(char *fname, char *type);
119 struct rmtabent *       fgetrmtabent(FILE *fp, int log, long *pos);
120 void                    fputrmtabent(FILE *fp, struct rmtabent *xep, long *pos);
121 void                    fendrmtabent(FILE *fp);
122 void                    frewindrmtabent(FILE *fp);
123
124 /*
125  * wildmat borrowed from INN
126  */
127 int                     wildmat(char *text, char *pattern);
128
129 /*
130  * nfsd library functions.
131  */
132 int                     nfsctl(int, struct nfsctl_arg *, union nfsctl_res *);
133 int                     nfssvc(int port, int nrservs, unsigned int versbits, int minorvers4, unsigned int portbits, char *haddr);
134 int                     nfsaddclient(struct nfsctl_client *clp);
135 int                     nfsdelclient(struct nfsctl_client *clp);
136 int                     nfsexport(struct nfsctl_export *exp);
137 int                     nfsunexport(struct nfsctl_export *exp);
138 struct nfs_fh_len *     getfh_old(struct sockaddr *addr, dev_t dev, ino_t ino);
139 struct nfs_fh_len *     getfh(struct sockaddr *addr, const char *);
140 struct nfs_fh_len *     getfh_size(struct sockaddr *addr, const char *, int size);
141
142 void qword_print(FILE *f, char *str);
143 void qword_printhex(FILE *f, char *str, int slen);
144 void qword_printint(FILE *f, int num);
145 int qword_eol(FILE *f);
146 int readline(int fd, char **buf, int *lenp);
147 int qword_get(char **bpp, char *dest, int bufsize);
148 int qword_get_int(char **bpp, int *anint);
149 void cache_flush(int force);
150 int check_new_cache(void);
151 void qword_add(char **bpp, int *lp, char *str);
152 void qword_addhex(char **bpp, int *lp, char *buf, int blen);
153 void qword_addint(char **bpp, int *lp, int n);
154 void qword_adduint(char **bpp, int *lp, unsigned int n);
155 void qword_addeol(char **bpp, int *lp);
156
157 void closeall(int min);
158
159 int                     svctcp_socket (u_long __number, int __reuse);
160 int                     svcudp_socket (u_long __number, int __reuse);
161
162 #endif /* NFSLIB_H */