]> git.decadent.org.uk Git - nfs-utils.git/blob - support/include/nfslib.h
2fbd0f5a1d6ae2cbb606f492cc66edba6403610b
[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 #include "config.h"
13
14 #include <sys/types.h>
15 #include <sys/socket.h>
16 #include <netinet/in.h>
17 #include <stdio.h>
18 #include <paths.h>
19 #include <rpcsvc/nfs_prot.h>
20 #include <nfs/nfs.h>
21 #include "xlog.h"
22
23 #ifndef _PATH_EXPORTS
24 #define _PATH_EXPORTS           "/etc/exports"
25 #endif
26 #ifndef _PATH_IDMAPDCONF
27 #define _PATH_IDMAPDCONF        "/etc/idmapd.conf"
28 #endif
29 #ifndef _PATH_XTAB
30 #define _PATH_XTAB              NFS_STATEDIR "/xtab"
31 #endif
32 #ifndef _PATH_XTABTMP
33 #define _PATH_XTABTMP           NFS_STATEDIR "/xtab.tmp"
34 #endif
35 #ifndef _PATH_ETAB
36 #define _PATH_ETAB              NFS_STATEDIR "/etab"
37 #endif
38 #ifndef _PATH_ETABTMP
39 #define _PATH_ETABTMP           NFS_STATEDIR "/etab.tmp"
40 #endif
41 #ifndef _PATH_RMTAB
42 #define _PATH_RMTAB             NFS_STATEDIR "/rmtab"
43 #endif
44 #ifndef _PATH_RMTABTMP
45 #define _PATH_RMTABTMP          _PATH_RMTAB ".tmp"
46 #endif
47 #ifndef _PATH_PROC_EXPORTS
48 #define _PATH_PROC_EXPORTS      "/proc/fs/nfs/exports"
49 #define _PATH_PROC_EXPORTS_ALT  "/proc/fs/nfsd/exports"
50 #endif
51
52 enum cle_maptypes {
53         CLE_MAP_IDENT = 0,
54         CLE_MAP_FILE,
55         CLE_MAP_UGIDD,
56 };
57
58 /*
59  * Data related to a single exports entry as returned by getexportent.
60  * FIXME: export options should probably be parsed at a later time to 
61  * allow overrides when using exportfs.
62  */
63 struct exportent {
64         char            e_hostname[NFSCLNT_IDMAX+1];
65         char            e_path[NFS_MAXPATHLEN+1];
66         /* The mount path may be different from the exported path due
67            to submount. It may change for every mount. The idea is we
68            set m_path every time when we process a mount. We should not
69            use it for anything else. */
70         char            m_path[NFS_MAXPATHLEN+1];
71         int             e_flags;
72         int             e_maptype;
73         int             e_anonuid;
74         int             e_anongid;
75         int *           e_squids;
76         int             e_nsquids;
77         int *           e_sqgids;
78         int             e_nsqgids;
79         int             e_fsid;
80         char *          e_mountpoint;
81 };
82
83 struct rmtabent {
84         char            r_client[NFSCLNT_IDMAX+1];
85         char            r_path[NFS_MAXPATHLEN+1];
86         int             r_count;
87 };
88
89 /*
90  * configuration file parsing
91  */
92 void                    setexportent(char *fname, char *type);
93 struct exportent *      getexportent(int,int);
94 void                    putexportent(struct exportent *xep);
95 void                    endexportent(void);
96 struct exportent *      mkexportent(char *hname, char *path, char *opts);
97 void                    dupexportent(struct exportent *dst,
98                                         struct exportent *src);
99 int                     updateexportent(struct exportent *eep, char *options);
100
101 int                     setrmtabent(char *type);
102 struct rmtabent *       getrmtabent(int log, long *pos);
103 void                    putrmtabent(struct rmtabent *xep, long *pos);
104 void                    endrmtabent(void);
105 void                    rewindrmtabent(void);
106 FILE *                  fsetrmtabent(char *fname, char *type);
107 struct rmtabent *       fgetrmtabent(FILE *fp, int log, long *pos);
108 void                    fputrmtabent(FILE *fp, struct rmtabent *xep, long *pos);
109 void                    fendrmtabent(FILE *fp);
110 void                    frewindrmtabent(FILE *fp);
111
112 /*
113  * wildmat borrowed from INN
114  */
115 int                     wildmat(char *text, char *pattern);
116
117 /*
118  * nfsd library functions.
119  */
120 int                     nfsctl(int, struct nfsctl_arg *, union nfsctl_res *);
121 int                     nfssvc(int port, int nrservs);
122 int                     nfsaddclient(struct nfsctl_client *clp);
123 int                     nfsdelclient(struct nfsctl_client *clp);
124 int                     nfsexport(struct nfsctl_export *exp);
125 int                     nfsunexport(struct nfsctl_export *exp);
126 struct nfs_fh_len *     getfh_old(struct sockaddr *addr, dev_t dev, ino_t ino);
127 struct nfs_fh_len *     getfh(struct sockaddr *addr, const char *);
128 struct nfs_fh_len *     getfh_size(struct sockaddr *addr, const char *, int size);
129
130 void qword_print(FILE *f, char *str);
131 void qword_printhex(FILE *f, char *str, int slen);
132 void qword_printint(FILE *f, int num);
133 void qword_eol(FILE *f);
134 int readline(int fd, char **buf, int *lenp);
135 int qword_get(char **bpp, char *dest, int bufsize);
136 int qword_get_int(char **bpp, int *anint);
137 void cache_flush(int force);
138 int check_new_cache(void);
139
140 /* lockd. */
141 int                     lockdsvc();
142
143 int                     svctcp_socket (u_long __number, int __reuse);
144 int                     svcudp_socket (u_long __number, int __reuse);
145
146 #endif /* NFSLIB_H */