-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnntpd.h
More file actions
569 lines (479 loc) · 14.9 KB
/
nntpd.h
File metadata and controls
569 lines (479 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
#ifndef NNTPD_H
# define NNTPD_H
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/syslog.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <syslog.h>
#include <pwd.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <inttypes.h>
#include <curl/curl.h>
#include <openssl/ssl.h>
#ifndef false
#define false 0
#endif
#ifndef true
#define true 1
#endif
#ifndef ulong
#define ulong unsigned long
#endif
#ifndef bool
#define bool unsigned char
#endif
#ifndef ulong64
typedef unsigned long long ulong64;
#endif
#ifndef long64
typedef long long long64;
#endif
#define MAX_HOSTNAME 256 /* max hostname length */
#define MAX_USERPASS 64 /* max length of username or password */
#define MAX_ACLS 2048
#define MAX_ARGS 64
#define MAX_ALIASES 256
#define MAX_AUTHS 2048
#define MAX_PROFILES 512
#define MAX_SERVERS 128 /* let me know if you have more! */
#define MAX_VHOSTS 128
#define MAX_GROUP 160 /* max groupname length */
#define MAX_SERVER 32 /* max servername length (hostname and short id name in servers.conf) */
#define MAX_SERVERRSP 512 /* max length of server reply */
#define MAX_GROUPS 128000
#define MAX_PROC 8192 /* max of the max, config via nntpswitch.conf */
#define MAX_USERS MAX_PROC
#define MAX_HEADER 1024 /* max size of single header */
#define MAX_FOOTER 1024 /* max length of appended footer */
#define MAX_WILDMATS 32 /* max N wildmat pattern (access.conf) */
#define MAX_OVERVIEWFMT 16 /* max lines */
#define MAX_LEVEL 1000 /* max Level in server config */
#define MAX_CFGLINE 16384 /* max line length in config files */
#define MAX_DAYLIMITS 16 /* max size of profile Limits array */
#define MAX_POST_AGE 86400 /* oldest (or newest) post we accept, max 1d old or 1d new */
#define MAX_PATH 128 /* max path+filename length */
#define MAX_NFS 64 /* max nr of nntpswitch servers running */
#define MAX_CLIENTHOSTS 50 /* Allow maximum 50 host for unique users counting. */
/* The following might be hardcoded in sscanf's */
#define MAX_STRING 256 /* generally max string length */
#define MAX_NAME 32 /* general max length of a name for something */
#define MSG_OVERVIEWFMT "215 Overview.fmt follows\r\n"
#define MSG_POST_RECEIVED "240 Thanks!\r\n"
#define MSG_POST_MAILED "240 Thanks, post mailed to moderator\r\n"
#define MSG_POST_OK "340 Try Me!\r\n"
#define MSG_POST_WRONGHEADER "441 Newsgroups, From or Subject missing\r\n"
#define MSG_POST_NOMAIL "441 Couldn't mail your post to the moderator, please try again\r\n"
#define MSG_POST_CANCEL "441 Post Cancelled\r\n"
#define MSG_POST_HDRTOOLONG "441 Header too long\r\n"
#define MSG_POST_TOOOLD "441 Post is too old, check your system clock\r\n"
#define MSG_POST_TOONEW "441 Post is too new, check your system clock\r\n"
#define MSG_POST_WRONGEMAIL "441 From address not in internet syntax\r\n"
#define MSG_POST_WRONGMSGID "441 Incorrect Message-ID syntax\r\n"
#define MSG_POST_TOOMANYGROUPS "441 Too many newsgroups\r\n"
#define MSG_AUTH_OK "281 Authentication Accepted\r\n"
#define MSG_MOREAUTHREQ "381 More Authentication Required\r\n"
#define MSG_SESSIONLIMIT "400 Session Time Limit Reached (please reconnect)\r\n"
#define MSG_BYTELIMIT "400 Session Byte Limit Reached (please reconnect)\r\n"
#define MSG_AUTHREQUIRED "480 Authentication Required\r\n"
#define MSG_AUTH_REJ "482 Authentication Rejected\r\n"
#define MSG_AUTH_ERR "482 Authentication Temporarily Unavailable\r\n"
#define MSG_AUTH_TOOMANYCON "482 Too many connections in your class\r\n"
#define MSG_AUTH_TOOMANYUSR "482 Too many users in your class\r\n"
#define MSG_AUTH_USERFULL "482 Too many connections for your user (nntpswitch)\r\n"
#define MSG_AUTH_USERFULLREMOTE "482 Too many connections for your user (remote)\r\n"
#define MSG_AUTH_HOSTFULL "482 You are already connected from a different host\r\n"
#define MSG_AUTH_HOSTMAX "482 Already connected from maximum number of different hosts (%d)\r\n"
#define MSG_AUTH_OVERQUOTA "482 You have reached your download limit.\r\n"
#define MSG_AUTH_OVERTIME "482 This account can only be used between %s and %s.\r\n"
#define MSG_AUTH_TWICE "281 You are already authenticated (please disconnect first)\r\n"
#define MSG_NOSUCHGROUP "411 No such group\r\n"
#define MSG_NOGROUP "412 No group selected\r\n"
#define MSG_ARTICLECANT "430 Cant retrieve article, try joining a newsgroup first\r\n"
#define MSG_ARTICLENOPERM "430 Cant retrieve article, permission denied\r\n"
#define MSG_NOPOSTING "440 Posting Denied\r\n"
#define MSG_SERVER_DOWN "403 Remote Server Unavailable\r\n"
#define MSG_COMMAND_HTTP "500 Disconnected due to HTTP command\r\n"
#define MSG_NONEWNEWS "501 NEWNEWS only supports single newsgroup names\r\n"
#define MSG_NOPATINDEX "501 Sorry, your search for this header type has been disabled\r\n"
#define MSG_SERVERFULL "400 Sorry, server is full at the moment, try later\r\n"
#define MSG_TOOMANYUSERS "400 Too many users\r\n"
#define MSG_TOOMANYUSERSPRF "400 Too many users in your class\r\n"
#define MSG_TOOMANYCONNSPRF "400 Too many connections in your class\r\n"
#define MSG_TOOMANY_CONCURRENT "400 Too many concurrent connections, you are allowed %d\r\n"
#define MSG_GENERIC_ERROR "502 %s\r\n"
#define MSG_UNSUPPORTED "500 Unsupported\r\n"
#define MSG_NOTIMPLEMENTED "500 Not Implemented\r\n"
#define MSG_NOACL "500 Can't get ACL\r\n"
#define MSG_NOPERM "500 Permission Denied\r\n"
#define MSG_AUTH_UNKNOWN "501 Unsupported AUTHINFO command\r\n"
#define MSG_AUTH_NOMEM "501 Out of memory for authentication\r\n"
#define MSG_CANNOTSSL "500 Cannot setup SSL connection\r\n"
#define MSG_SSLDISABLED "502 SSL connection is disabled for this user\r\n"
#define UMSG_SERVERTIMEOUT "Remote Server Timeout"
#define DEFAULT_AUTH "auth_default"
#define DEFAULT_ACCT "acct_default"
#define DEFAULT_PROFILE "default"
#define DEFAULT_WILDMAT "*"
#define RL_INITVAL 100000 /* this much usec as start for rate-limits */
/* If this is defined, send accounting record after this many bytes
* instead of waiting for end of connection
*/
#define INTERMEDIATE_ACCT 500000000
#define MAX_PFXMAPS 4
#define PFX_MAPSIZE 0x3FFFFF
enum article_result
{
CHECK_ARTICLE_OK,
CHECK_ARTICLE_FAIL,
CHECK_ARTICLE_NOPERM
};
enum connect_result
{
CONNECT_OK,
CONNECT_ERR,
CONNECT_DOWN
};
typedef struct
{
char name[32];
char map[PFX_MAPSIZE];
} PFXMAP;
struct _hlist
{
char *hdr;
char *val;
struct _hlist *next;
};
#define HLIST struct _hlist
typedef struct
{
char name[MAX_STRING];
char lib[MAX_STRING];
char args[MAX_STRING];
} ALIAS;
typedef struct
{
char name[MAX_STRING];
char args[MAX_STRING];
} ARGS;
typedef struct
{
int gb;
int kbit;
} LIMITS;
struct _profile
{
char Name[MAX_NAME];
char ReadPat[MAX_STRING];
char PostPat[MAX_STRING];
int MaxConnections;
int MaxUserConcurrent;
int MaxHostConcurrent;
int Slave;
int ASMaxConns;
int ASMaxHosts;
int MaxUsers;
int MaxSessionTime;
ulong64 MaxSessionBytes;
uint MaxUserBPS;
uint MaxProfileBPS;
char XComplaintsTo[MAX_STRING];
char Organization[MAX_STRING];
int ForceOrganization;
int AddNNTPPostingHost;
int MaxCross;
char Hostname[MAX_STRING];
char FooterFile[MAX_STRING];
char Footer[MAX_FOOTER];
int FooterSize;
int NoControl;
int ArticleSearch;
int ClientReadTimeout;
ALIAS* Accounting;
char AccountingPrefix[MAX_STRING];
LIMITS Limits[MAX_DAYLIMITS];
int NumLimits;
char Disabled[MAX_STRING];
int AllowSSL;
uint connections; /* current connection counter */
uint numusers; /* current user counter */
uint realusers; /* active users counter (i.e. after auth) */
ulong64 bytes; /* for rrd */
ulong64 rbytes; /* reset after output (json stats) */
ulong articles;
ulong64 postbytes;
ulong postarticles;
/* rate limiter */
uint rl_curbytes;
uint rl_lastbytes;
double rl_sleep;
struct timeval rl_start;
double rl_curbps;
double UserRLFactorU;
double UserRLFactorD;
double ProfileRLFactorU;
double ProfileRLFactorD;
uint Retention;
char XHeaderSSLUpload[MAX_HEADER];
PFXMAP * PrefixMap;
struct _profile * FailProfile;
};
#define PROFILE struct _profile
typedef struct
{
char pattern[1024];
char name[MAX_NAME];
} WILDMAT;
typedef struct
{
char mask[128];
ALIAS* auth;
PROFILE* profile;
} AUTH;
typedef struct
{
/* username and password are set by the main nntpswitch authenticator */
char * username;
char * password; /* cleartext */
char * username_s; /* username with matched pattern stripped */
int port; /* port (slot) id */
char * hostname; /* client hostname */
struct in_addr in_addr; /* client ip adres */
/* Those are copied from the MASTER struct */
ARGS * args;
int numargs;
/*
* the following fields should be set by the authentication module
* if left blank (untouched by the module), the default from the
* currently selected ACL is used. The struct including strings are
* free()'d after authentication.
*/
bool authenticated; /* succeeded or not */
char * message; /* txt message like '482 no access' or '281 welcome' */
char * profile; /* profile name */
bool posting; /* posting allowed */
ulong64 bytes; /* bytes remaining */
int userkbit; /* max user kbit */
char * logname; /* username for accounting, eg stripped username */
char * readpat;
char * postpat;
int timeleft;
bool overquota; /* Not used. */
bool disabled; /* Not used. */
char * posthost;
char * postabuse;
char * postorg;
} AUTHRESULT;
typedef struct
{
ulong start;
ulong end;
ulong size;
PROFILE * profile;
uint read:1;
uint post:1;
uint apost:1;
uint deny:1;
uint auth:1;
uint stats:1;
uint unlimit:1;
} ACL;
typedef struct
{
ulong hi;
ulong lo;
ulong times;
ulong id;
char mode;
char newsgroup[MAX_GROUP];
char server[32];
} ACTIVE;
enum _cmdnum
{
cmd_mode, cmd_slave, cmd_authinfo,
cmd_help, cmd_date, cmd_quit,
cmd_list, cmd_group, cmd_listgroup, cmd_newgroups, cmd_xgtitle,
cmd_over, cmd_xover, cmd_xzver, cmd_xhdr, cmd_xzhdr, cmd_xpat, cmd_newnews, cmd_post,
cmd_stat, cmd_head, cmd_body, cmd_article, cmd_next, cmd_last,
cmd_ihave, cmd_http, cmd_statistics, cmd_unsupported
};
typedef struct
{
char* command;
enum _cmdnum num;
uint auth:1; /* auth needed for command */
uint acct:1; /* account this command */
uint limit:1; /* rate-limit this command */
uint usecount;
} CMDINFO;
enum servertype
{
type_spool, type_xover, type_post
};
enum serverpol
{
policy_single, policy_backup, policy_balance
};
typedef struct
{
char Name[MAX_NAME];
char Hostname[MAX_HOSTNAME];
char Groups[MAX_CFGLINE];
char Username[MAX_USERPASS];
char Password[MAX_USERPASS];
uint Port;
uint Timeout;
uint Level;
enum servertype ServerType;
enum serverpol Policy;
bool ActiveTimes;
bool Descriptions;
bool SplitList;
uint MaxConnections;
uint connections;
} SERVER;
typedef struct
{
char ipaddress[MAX_HOSTNAME];
char Banner[MAX_STRING];
char AddSuffix[MAX_USERPASS];
int ReplaceBanner;
char SSLKeyFile[MAX_PATH];
char SSLCAList[MAX_PATH];
char SSLPassword[MAX_USERPASS];
SSL_CTX * ssl_ctx;
} VHOST;
typedef struct
{
char key[128];
uint id; /* this is the position in memory */
uint MaxUserBPS; /* copied from profile or authresult */
long64 bytesleft; /* initialized on connect or authenticate */
uint connections; /* number of client structs refering to us */
uint realuser; /* set if client is connected, ready for commands etc */
char readpat[MAX_STRING];
char postpat[MAX_STRING];
int timeleft;
/* rate limiter */
uint rl_curbytes;
uint rl_lastbytes;
double rl_sleep;
struct timeval rl_start;
double rl_curbps;
} USER;
typedef struct
{
int socket;
int useSSL;
SSL* ssl;
time_t connectsince;
pid_t pid;
int numcore; /* proceccor core we're bound to */
int serversock; /* primary server socket */
int postsock; /* post server socket */
SERVER * groupserver;
ACTIVE * group;
SERVER * currserver; /* replacement for lastserver */
char hostname[MAX_HOSTNAME];
ulong ip4addr;
struct sockaddr_in addr;
ACL * acl;
AUTH * auth;
CMDINFO * command;
PROFILE * profile;
USER * user;
VHOST * vhost;
char username[MAX_USERPASS];
char logname[MAX_USERPASS]; /* for postfix stripped usernames */
char password[MAX_USERPASS];
uint id;
uint concur; /* this is the clients N'th session */
char * bbuf; /* client buffer */
int error; /* set if we got error and have to exit */
int timeout; /* set if timeout was caught */
char * errstr;
/* rate limiter */
int RateIntervalUs; /* 1/cfg.Period * 100000 */
/* statistics */
ulong64 bytes;
ulong64 rbytes; /* reset after output (json stats) */
uint groups;
uint articles;
uint posts;
ulong64 postbytes;
uint grouparts;
ulong64 groupbytes;
uint serverarts;
ulong64 serverbytes;
uint starttime;
long64 initbytes; /* copied to user after auth */
uint connected:1;
uint authenticated:1;
uint inuse:1;
uint posting:1; /* copied form acl and/or authres */
} CLIENT;
typedef struct
{
int numgroups; /* total groups in active file */
int numaliases;
int numargs;
int numauths;
int numprofiles;
int numacls; /* number of access.conf entries */
int numwildmats; /* number of wildmat entries */
int numservers;
int numvhosts;
time_t laststatactive; /* remember filedate using stat() */
time_t laststatserver;
uint serverstart; /* uptime */
ulong64 nrforks;
ulong64 nrlocks;
ulong64 nrunlocks;
int numcores; /* Number of cores in system */
int currcore; /* Current core counter */
int connections; /* total connections, also key for *clients */
CLIENT clients[MAX_PROC];
int numusers; /* total users, also key for *users */
// ulong userid_id; /* just incremental counter */
USER users[MAX_USERS];
SERVER * lservers[MAX_SERVERS]; /* servers sorted by level */
SERVER servers[MAX_SERVERS];
AUTH auths[MAX_AUTHS];
PROFILE profiles[MAX_PROFILES];
ALIAS aliases[MAX_ALIASES];
WILDMAT wildmats[MAX_WILDMATS];
ACL acls[MAX_ACLS];
ARGS args[MAX_ARGS];
VHOST vhosts[MAX_VHOSTS];
/* The BalanceID is a counter from 0 to N where N is the number of servers
* with the same level. This is used for the load balancing policy. */
int balance_pos[MAX_LEVEL];
/* ipc semaphore */
int semid;
uint dllock; /* used for daylimits accounting lock */
uint num_pfxmaps;
PFXMAP prefixmap[MAX_PFXMAPS] __attribute__ ((aligned(4)));
int nflist[MAX_NFS];
} MASTER;
extern CLIENT *client;
extern MASTER *master;
extern char* config_file;
time_t parsedate(char *);
#endif
/* vim: set ts=8 noexpandtab */