Debian Codegraph @

contrib/mod_quotatab.h

raw symbols SCIP
1 /*
2 * ProFTPD: mod_quotatab -- a module for managing FTP byte/file quotas via
3 * centralized tables
4 *
5 * Copyright (c) 2001-2016 TJ Saunders
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
20 *
21 * As a special exemption, TJ Saunders and other respective copyright holders
22 * give permission to link this program with OpenSSL, and distribute the
23 * resulting executable, without including the source code for OpenSSL in the
24 * source distribution.
25 *
26 * This is mod_quotatab, contrib software for proftpd 1.2/1.3.x and above.
27 * For more information contact TJ Saunders <[email protected]>. It is based
28 * the ideas in Eric Estabrook's mod_quota, available from
29 * ftp://pooh.urbanrage.com/pub/c/. This module, however, has been written
30 * from scratch to implement quotas in a different way.
31 */
32
33 #ifndef MOD_QUOTATAB_H
34 #define MOD_QUOTATAB_H
35
36 #include "conf.h"
37 #include "privs.h"
38
39 #define MOD_QUOTATAB_VERSION "mod_quotatab/1.3.1"
40
41 /* Make sure the version of proftpd is as necessary. */
42 #if PROFTPD_VERSION_NUMBER < 0x0001030001
43 # error "ProFTPD 1.3.0rc1 or later required"
44 #endif
45
46 /* Quota types */
47 typedef enum {
48 ALL_QUOTA = 10,
49 USER_QUOTA = 20,
50 GROUP_QUOTA = 30,
51 CLASS_QUOTA = 40
52 } quota_type_t;
53
54 /* Bytes quota limit types */
55 typedef enum {
56 HARD_LIMIT = 1,
57 SOFT_LIMIT = 2
58 } quota_limit_type_t;
59
60 /* Quota objects */
61 typedef struct {
62 char name[81];
63
64 /* name refers to user, group, or class */
65 quota_type_t quota_type;
66
67 /* are quotas enforced per session or not? */
68 unsigned char quota_per_session;
69
70 /* are byte quotas hard or soft? */
71 quota_limit_type_t quota_limit_type;
72
73 /* Configured bytes limits. */
74 double bytes_in_avail;
75 double bytes_out_avail;
76 double bytes_xfer_avail;
77
78 /* Configured files limits. These have no "limit type", as they are
79 * always hard.
80 */
81 unsigned int files_in_avail;
82 unsigned int files_out_avail;
83 unsigned int files_xfer_avail;
84
85 } quota_limit_t;
86
87 typedef struct {
88 char name[81];
89
90 quota_type_t quota_type;
91
92 /* Current bytes tallies. */
93 double bytes_in_used;
94 double bytes_out_used;
95 double bytes_xfer_used;
96
97 /* Current files tallies. */
98 unsigned int files_in_used;
99 unsigned int files_out_used;
100 unsigned int files_xfer_used;
101
102 } quota_tally_t;
103
104 /* Quota table type (ie limit or tally) */
105 typedef enum {
106 TYPE_LIMIT = 100,
107 TYPE_TALLY
108
109 } quota_tabtype_t;
110
111 /* Quota display units */
112 typedef enum {
113 BYTE = 10,
114 KILO,
115 MEGA,
116 GIGA
117
118 } quota_units_t;
119
120 typedef enum {
121 IN = 100,
122 OUT,
123 XFER,
124
125 } quota_xfer_t;
126
127 /* Quota deltas -- used to mark the changes in tallies per-operation.
128 * This structure is useful for submodules (eg mod_quotatab_sql) that are
129 * more interested in the deltas, rather than in the current tallies.
130 */
131 typedef struct {
132
133 /* Deltas of bytes tallies. */
134 double bytes_in_delta;
135 double bytes_out_delta;
136 double bytes_xfer_delta;
137
138 /* Deltas of files tallies. */
139 int files_in_delta;
140 int files_out_delta;
141 int files_xfer_delta;
142
143 } quota_deltas_t;
144
145 typedef struct table_obj {
146
147 /* Memory pool for this object */
148 pool *tab_pool;
149
150 /* Table type, limit or tally */
151 quota_tabtype_t tab_type;
152
153 /* Table handle */
154 int tab_handle;
155
156 /* Table "magic" number */
157 unsigned int tab_magic;
158
159 /* Table record length */
160 unsigned int tab_quotalen;
161
162 /* Arbitrary data pointer */
163 void *tab_data;
164
165 /* Table I/O routines */
166 int (*tab_close)(struct table_obj *);
167 int (*tab_create)(struct table_obj *, void *);
168 unsigned char (*tab_lookup)(struct table_obj *, void *, const char *,
169 quota_type_t);
170 int (*tab_read)(struct table_obj *, void *);
171 unsigned char (*tab_verify)(struct table_obj *);
172 int (*tab_write)(struct table_obj *, void *);
173
174 /* Table locking routines */
175 struct flock tab_lock;
176 int tab_lockfd;
177 int (*tab_rlock)(struct table_obj *);
178 int (*tab_unlock)(struct table_obj *);
179 int (*tab_wlock)(struct table_obj *);
180
181 /* Table locking counters */
182 unsigned int rlock_count;
183 unsigned int wlock_count;
184
185 } quota_table_t;
186
187 #define QUOTATAB_LIMIT_SRC 0x0001
188 #define QUOTATAB_TALLY_SRC 0x0002
189
190 /* Quota objects for the current session. */
191 extern quota_deltas_t quotatab_deltas;
192
193 /* Function prototypes necessary for quotatab sub-modules */
194 int quotatab_log(const char *, ...)
195 #ifdef __GNUC__
196 __attribute__ ((format (printf, 1, 2)));
197 #else
198 ;
199 #endif
200
201 int quotatab_openlog(void);
202 int quotatab_register_backend(const char *,
203 quota_table_t *(*tab_open)(pool *, quota_tabtype_t, const char *),
204 unsigned int);
205 int quotatab_unregister_backend(const char *, unsigned int);
206
207 /* Function prototypes necessary for consumers of quotatab data. */
208
209 /* Note: this function will only find the first occurrence of the given
210 * name and type in the table. This means that if there is a malformed
211 * quota table, with duplicate name/type pairs, the duplicates will be
212 * ignored. Returns TRUE if found, FALSE otherwise.
213 */
214 unsigned char quotatab_lookup(quota_tabtype_t, void *, const char *,
215 quota_type_t);
216
217 unsigned char quotatab_lookup_default(quota_tabtype_t, void *, const char *,
218 quota_type_t);
219
220 /* Reads via this function are only ever done on tally tables. Limit tables
221 * are read via the quotatab_lookup function. Returns 0 on success,
222 * -1 on failure (with errno set appropriately).
223 */
224 int quotatab_read(quota_tally_t *);
225
226 /* Writes via this function are only ever done on tally tables. Returns 0
227 * on success, -1 on failure (with errno set appropriately).
228 */
229 int quotatab_write(quota_tally_t *, double, double, double, int, int, int);
230
231 #endif /* no MOD_QUOTATAB_H */