1 /*
2  * eggdrop.h
3  *   Eggdrop compile-time settings
4  *
5  *   IF YOU ALTER THIS FILE, YOU NEED TO RECOMPILE THE BOT.
6  */
7 /*
8  * Copyright (C) 1997 Robey Pointer
9  * Copyright (C) 1999 - 2021 Eggheads Development Team
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25 
26 #ifndef _EGG_EGGDROP_H
27 #define _EGG_EGGDROP_H
28 
29 #include <ctype.h>
30 
31 /*
32  * If you're *only* going to link to new version bots (1.3.0 or higher)
33  * then you can safely define this.
34  */
35 #undef NO_OLD_BOTNET
36 
37 /* DEBUG_CONTEXT is now set in config.h by configure */
38 
39 /*
40  * HANDLEN note:
41  *       HANDLEN defines the maximum length a handle on the bot can be.
42  *       Standard (and minimum) is 9 characters long.
43  *
44  *       Beware that using lengths over 9 chars is 'non-standard' and if
45  *       you wish to link to other bots, they _must_ both have the same
46  *       maximum handle length.
47  *
48  * NICKMAX note:
49  *       You should leave this at 32 characters and modify nick-len in the
50  *       configuration file instead.
51  */
52 #define CHANNELLEN 80 /* FIXME see issue #3 and issue #38 and rfc1459 <= 200 */
53 #define HANDLEN    32 /* valid values 9->NICKMAX                             */
54 #define NICKMAX    32 /* valid values HANDLEN->32                            */
55 #define USERLEN    10
56 
57 
58 /* Handy string lengths */
59 #define HOSTMAX     63            /* DNS RFC 1035, IRC RFC 2812          */
60 #define UHOSTMAX    291 + NICKMAX /* 32 (ident) + 3 (\0, !, @) + NICKMAX */
61 #define DIRMAX      512           /* paranoia                            */
62 #define LOGLINEMAX  9000          /* for misc.c/putlog() <cybah>         */
63 
64 /* Invalid characters */
65 #define BADHANDCHARS "-,+*=:!.@#;$%&"
66 
67 /* And now valid characters! */
68 #define CHARSET_LOWER_ALPHA     "abcdefghijklmnopqrstuvwxyz"
69 #define CHARSET_LOWER_ALPHA_NUM "0123456789abcdefghijklmnopqrstuvwxyz"
70 #define CHARSET_PASSWORD        "0123456789?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
71 
72 
73 /* Language stuff */
74 #define LANGDIR  "./language" /* language file directory                   */
75 #define BASELANG "english"    /* language which always gets loaded before
76                                  all other languages. You do not want to
77                                  change this.                              */
78 
79 
80 /* The 'configure' script should make this next part automatic, so you
81  * shouldn't need to adjust anything below.
82  */
83 #define NICKLEN     NICKMAX + 1
84 #define UHOSTLEN    UHOSTMAX + 1
85 #define DIRLEN      DIRMAX + 1
86 #define LOGLINELEN  LOGLINEMAX + 1
87 #define NOTENAMELEN ((HANDLEN * 2) + 1)
88 #define PASSWORDMAX 30 /* highest value compatible to older eggdrop */
89 #define PASSWORDLEN PASSWORDMAX + 1
90 
91 
92 /* We have to generate compiler errors in a weird way since not all compilers
93  * support the #error preprocessor directive. */
94 #ifndef STDC_HEADERS
95 #  include "Error: Your system must have standard ANSI C headers."
96 #endif
97 
98 #ifdef HAVE_UNISTD_H
99 #  include <unistd.h>
100 #endif
101 
102 /* This allows us to make things a lot less messy in modules.c. */
103 #ifndef STATIC
104 #  if !defined(MODULES_OK) || (!defined(MOD_USE_DL) && !defined(MOD_USE_SHL) && !defined(MOD_USE_DYLD) && !defined(MOD_USE_RLD) && !defined(MOD_USE_LOADER))
105 #    include "Error: You can't compile with module support on this system (try make static)."
106 #  else
107 #    ifdef MOD_USE_DL
108 #      ifndef HAVE_DLOPEN
109 #        include "Error: We have detected that dlopen() should be used to load modules on this OS; but it was not found. Please use 'make static'."
110 #      endif
111 #      undef MOD_USE_SHL
112 #      undef MOD_USE_DYLD
113 #      undef MOD_USE_RLD
114 #      undef MOD_USE_LOADER
115 #    endif
116 #    ifdef MOD_USE_SHL
117 #      ifndef HAVE_SHL_LOAD
118 #        include "Error: We have detected that shl_load() should be used to load modules on this OS; but it was not found. Please use 'make static'."
119 #      endif
120 #      undef MOD_USE_DL
121 #      undef MOD_USE_DYLD
122 #      undef MOD_USE_RLD
123 #      undef MOD_USE_LOADER
124 #    endif
125 #    ifdef MOD_USE_DYLD
126 #      ifndef HAVE_NSLINKMODULE
127 #        include "Error: We have detected that NSLinkModule() should be used to load modules on this OS; but it was not found. Please use 'make static'."
128 #      endif
129 #      undef MOD_USE_DL
130 #      undef MOD_USE_SHL
131 #      undef MOD_USE_RLD
132 #      undef MOD_USE_LOADER
133 #    endif
134 #    ifdef MOD_USE_RLD
135 #      ifndef HAVE_RLD_LOAD
136 #        include "Error: We have detected that rld_load() should be used to load modules on this OS; but it was not found. Please use 'make static'."
137 #      endif
138 #      undef MOD_USE_DL
139 #      undef MOD_USE_SHL
140 #      undef MOD_USE_DYLD
141 #      undef MOD_USE_LOADER
142 #    endif
143 #    ifdef MOD_USE_LOADER
144 #      ifndef HAVE_LOAD
145 #        include "Error: We have detected that load() should be used to load modules on this OS; but it was not found. Please use 'make static'."
146 #      endif
147 #      undef MOD_USE_DL
148 #      undef MOD_USE_SHL
149 #      undef MOD_USE_DYLD
150 #      undef MOD_USE_RLD
151 #    endif
152 #  endif
153 #endif
154 
155 #ifdef EGG_HANDLEN
156 #  undef HANDLEN
157 #  define HANDLEN EGG_HANDLEN
158 #endif
159 
160 #if (NICKMAX < 9) || (NICKMAX > 32)
161 #  include "Error: Invalid NICKMAX value."
162 #endif
163 
164 #if (HANDLEN < 9) || (HANDLEN > 32)
165 #  include "Error: Invalid HANDLEN value."
166 #endif
167 
168 #if HANDLEN > NICKMAX
169 #  include "Error: HANDLEN must be <= NICKMAX."
170 #endif
171 
172 #ifdef HAVE_SYS_PARAM_H
173 #  include <sys/param.h>
174 #endif
175 
176 /* NAME_MAX is what POSIX defines, but BSD calls it MAXNAMLEN.
177  * Use 255 if we can't find anything else.
178  */
179 #ifndef NAME_MAX
180 #  ifdef MAXNAMLEN
181 #    define NAME_MAX    MAXNAMLEN
182 #  else
183 #    define NAME_MAX    255
184 #  endif
185 #endif
186 
187 /* Almost every module needs some sort of time thingy, so... */
188 #ifdef TIME_WITH_SYS_TIME
189 #  include <sys/time.h>
190 #  include <time.h>
191 #else
192 #  ifdef HAVE_SYS_TIME_H
193 #    include <sys/time.h>
194 #  else
195 #    include <time.h>
196 #  endif
197 #endif
198 
199 
200 /* Yikes...who would have thought finding a usable random() would be so much
201  * trouble?
202  * Note: random(), rand(), and lrand48() are *not* thread safe.
203  *
204  * QNX doesn't include random() and srandom() in libc.so, only in libc.a
205  * So we can only use these functions in static builds on QNX.
206  */
207 #if defined QNX_HACKS && defined MAKING_MODS
208 #  undef HAVE_RANDOM
209 #  undef HAVE_SRANDOM
210 #endif
211 
212 #ifdef HAVE_RANDOM
213   /* On systems with random(), RANDOM_MAX may or may not be defined.
214    *
215    * If RANDOM_MAX isn't defined, we use 0x7FFFFFFF (2^31-1), or 2147483647
216    * since this follows the 4.3BSD and POSIX.1-2001 standards. This of course
217    * assumes random() uses a 32 bit long int type per the standards.
218    */
219 #  ifndef RANDOM_MAX
220 #    define RANDOM_MAX 0x7FFFFFFF  /* random() -- 2^31-1 */
221 #  endif
222 #else                              /* !HAVE_RANDOM */
223    /* This shouldn't exist in this case, but just to be safe... */
224 #  ifdef RANDOM_MAX
225 #    undef RANDOM_MAX
226 #  endif
227   /* If we don't have random() it's safe to assume we also don't have
228    * srandom(), and we need both.
229    */
230 #  ifdef HAVE_RAND
231 #    define random() rand()
232 #    define srandom(x) srand(x)
233     /* Depending on the system int size, RAND_MAX can be either 0x7FFFFFFF
234      * (2^31-1), or 2147483647 for a 32 bit int, or 0x7FFF (2^15-1), or
235      * 32767 for a 16 bit int. The standards only state that RAND_MAX must
236      * be _at least_ 32767 but some systems with 16 bit int define it as
237      * 32767. See: SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
238      */
239 #    define RANDOM_MAX RAND_MAX    /* rand() -- 2^31-1 or 2^15-1 */
240 #  else                            /* !HAVE_RAND */
241 #    ifdef  HAVE_LRAND48
242 #      define random() lrand48()
243 #      define srandom(x) srand48(x)
244       /* For lrand48() we define RANDOM_MAX as 0x7FFFFFFF (2^31-1), or
245        * 2147483647 since this is what the SVr4 and POSIX.1-2001 standards
246        * call for. Note: SVID 3 declares these functions as obsolete and
247        * states rand() should be used instead.
248        */
249 #      define RANDOM_MAX 0x7FFFFFFF /* lrand48() -- 2^31-1 */
250 #    else                          /* !HAVE_LRAND48 */
251 #      include "Error: Must define one of HAVE_RANDOM, HAVE_RAND, or HAVE_LRAND48"
252 #    endif                         /* HAVE_LRAND48 */
253 #  endif                           /* HAVE_RAND */
254 #endif                             /* HAVE_RANDOM */
255 
256 
257 /* Use high-order bits for getting the random integer. With a modern
258  * random() implementation, modulo would probably be sufficient, but on
259  * systems lacking random(), it may just be a macro for an older rand()
260  * function.
261  */
262 #define randint(n) (unsigned long) (random() / (RANDOM_MAX + 1.0) * n)
263 
264 
265 #ifdef TLS
266 #  include <openssl/ssl.h>
267 #endif
268 
269 /*
270  *    Handy aliases for memory tracking and core dumps
271  */
272 
273 #define nmalloc(x)    n_malloc((x),__FILE__,__LINE__)
274 #define nrealloc(x,y) n_realloc((x),(y),__FILE__,__LINE__)
275 #define nfree(x)      n_free((x),__FILE__,__LINE__)
276 
277 #ifdef DEBUG_CONTEXT
278 #  define Context           eggContext(__FILE__, __LINE__, NULL)
279 #  define ContextNote(note) eggContextNote(__FILE__, __LINE__, NULL, note)
280 #else
281 #  define Context           do {} while (0)
282 #  define ContextNote(note) do {} while (0)
283 #endif
284 
285 #ifdef DEBUG_ASSERT
286 #  define Assert(expr) do {                                             \
287           if (!(expr))                                                  \
288             eggAssert(__FILE__, __LINE__, NULL);                        \
289 } while (0)
290 #else
291 #  define Assert(expr) do {} while (0)
292 #endif
293 
294 #ifndef COMPILING_MEM
295 #  undef malloc
296 #  define malloc(x) dont_use_old_malloc(x)
297 #  undef free
298 #  define free(x)   dont_use_old_free(x)
299 #endif /* !COMPILING_MEM */
300 
301 /* IP type */
302 typedef uint32_t IP;
303 
304 /* Debug logging macros */
305 #define debug0(x)                putlog(LOG_DEBUG,"*",x)
306 #define debug1(x,a1)             putlog(LOG_DEBUG,"*",x,a1)
307 #define debug2(x,a1,a2)          putlog(LOG_DEBUG,"*",x,a1,a2)
308 #define debug3(x,a1,a2,a3)       putlog(LOG_DEBUG,"*",x,a1,a2,a3)
309 #define debug4(x,a1,a2,a3,a4)    putlog(LOG_DEBUG,"*",x,a1,a2,a3,a4)
310 #define debug5(x,a1,a2,a3,a4,a5) putlog(LOG_DEBUG,"*",x,a1,a2,a3,a4,a5)
311 
312 /* These apparently are unsafe without recasting. */
313 #define egg_isdigit(x)  isdigit((int)  (unsigned char) (x))
314 #define egg_isxdigit(x) isxdigit((int) (unsigned char) (x))
315 #define egg_isascii(x)  isascii((int)  (unsigned char) (x))
316 #define egg_isspace(x)  isspace((int)  (unsigned char) (x))
317 #define egg_islower(x)  islower((int)  (unsigned char) (x))
318 
319 /* The following functions are for backward compatibility only */
320 #define egg_bzero(dest, len) memset(dest, 0, len)
321 #define egg_memcpy memcpy
322 #define egg_memset memset
323 #define egg_strcasecmp strcasecmp
324 #define egg_strftime strftime
325 #define egg_strncasecmp strncasecmp
326 #define my_memcpy memcpy
327 
328 /***********************************************************************/
329 
330 /* It's used in so many places, let's put it here */
331 typedef intptr_t (*Function) ();
332 typedef int (*IntFunc) ();
333 
334 #ifdef IPV6
335 #include "compat/in6.h"
336 #endif
337 
338 #include <sys/socket.h>
339 #include <netinet/in.h>
340 
341 typedef struct {
342   int family;
343   socklen_t addrlen;
344   union {
345     struct sockaddr sa;
346     struct sockaddr_in s4;
347 #ifdef IPV6
348     struct sockaddr_in6 s6;
349 #endif
350   } addr;
351 } sockname_t;
352 
353 /* Public structure for the listening port map */
354 struct portmap {
355   int realport;
356   int mappedto;
357   struct portmap *next;
358 };
359 
360 /* Public structure of all the dcc connections */
361 struct dcc_table {
362   char *name;
363   int flags;
364   void (*eof) (int);
365   void (*activity) (int, char *, int);
366   int *timeout_val;
367   void (*timeout) (int);
368   void (*display) (int, char *);
369   int (*expmem) (void *);
370   void (*kill) (int, void *);
371   void (*output) (int, char *, void *);
372   void (*outdone) (int);
373 };
374 
375 struct userrec;
376 
377 struct dcc_t {
378   long sock;                    /* This should be a long to keep 64-bit machines sane. */
379   IP addr;                      /* IP address in host network byte order. */
380   sockname_t sockname;          /* IPv4/IPv6 sockaddr placeholder */
381   unsigned int port;
382 #ifdef TLS
383   int ssl;
384 #endif
385   struct userrec *user;
386   char nick[NICKLEN];
387   char host[UHOSTLEN];
388   struct dcc_table *type;
389   time_t timeval;               /* This is used for timeout checking. */
390   unsigned long status;         /* A LOT of dcc types have status things; makes it more available. */
391   union {
392     struct chat_info *chat;
393     struct file_info *file;
394     struct edit_info *edit;
395     struct xfer_info *xfer;
396     struct bot_info *bot;
397     struct relay_info *relay;
398     struct script_info *script;
399     struct dns_info *dns;
400     struct dupwait_info *dupwait;
401     int ident_sock;
402     void *other;
403   } u;                          /* Special use depending on type        */
404 };
405 
406 struct chat_info {
407   char *away;                    /* non-NULL if user is away             */
408   int msgs_per_sec;              /* used to stop flooding                */
409   int con_flags;                 /* with console: what to show           */
410   int strip_flags;               /* what codes to strip (b,r,u,c,a,g,*)  */
411   char con_chan[CHANNELLEN + 1]; /* with console: what channel to view   */
412   int channel;                   /* 0=party line, -1=off                 */
413   struct msgq *buffer;           /* a buffer of outgoing lines
414                                   * (for .page cmd)                      */
415   int max_line;                  /* maximum lines at once                */
416   int line_count;                /* number of lines sent since last page */
417   int current_lines;             /* number of lines total stored         */
418   char *su_nick;
419 };
420 
421 struct file_info {
422   struct chat_info *chat;
423   char dir[161];
424 };
425 
426 struct xfer_info {
427   char *filename;
428   char *origname;
429   char dir[DIRLEN];             /* used when uploads go to the current dir */
430   unsigned long length;
431   unsigned long acked;
432   char buf[4];                  /* you only need 5 bytes!                  */
433   unsigned char sofar;          /* how much of the byte count received     */
434   char from[NICKLEN];           /* [GET] user who offered the file         */
435   FILE *f;                      /* pointer to file being sent/received     */
436   unsigned int type;            /* xfer connection type, see enum below    */
437   unsigned short ack_type;      /* type of ack                             */
438   unsigned long offset;         /* offset from beginning of file, during
439                                  * resend.                                 */
440   unsigned long block_pending;  /* bytes of this DCC block which weren't
441                                  * sent yet.                               */
442   time_t start_time;            /* Time when a xfer was started.           */
443 };
444 
445 enum {                          /* transfer connection handling a ...   */
446   XFER_SEND,                    /*  ... normal file-send to s.o.        */
447   XFER_RESEND,                  /*  ... file-resend to s.o.             */
448   XFER_RESEND_PEND,             /*  ... (as above) and waiting for info */
449   XFER_RESUME,                  /*  ... file-send-resume to s.o.        */
450   XFER_RESUME_PEND,             /*  ... (as above) and waiting for conn */
451   XFER_GET                      /*  ... file-get from s.o.              */
452 };
453 
454 enum {
455   XFER_ACK_UNKNOWN,             /* We don't know how blocks are acked.  */
456   XFER_ACK_WITH_OFFSET,         /* Skipped data is also counted as
457                                  * received.                            */
458   XFER_ACK_WITHOUT_OFFSET       /* Skipped data is NOT counted in ack.  */
459 };
460 
461 struct bot_info {
462   char version[121];            /* channel/version info                 */
463   char linker[NOTENAMELEN + 1]; /* who requested this link              */
464   int numver;
465   int port;                     /* base port                            */
466 #ifdef TLS
467   int ssl;                      /* base ssl                             */
468 #endif
469   int uff_flags;                /* user file feature flags              */
470 };
471 
472 struct relay_info {
473   struct chat_info *chat;
474   int sock;
475   int port;
476   int old_status;
477 };
478 
479 struct script_info {
480   struct dcc_table *type;
481   union {
482     struct chat_info *chat;
483     struct file_info *file;
484     void *other;
485   } u;
486   char command[121];
487 };
488 
489 struct dns_info {
490   void (*dns_success) (int);    /* is called if the dns request succeeds   */
491   void (*dns_failure) (int);    /* is called if it fails                   */
492   char *host;                   /* hostname                                */
493   char *cbuf;                   /* temporary buffer. Memory will be free'd
494                                  * as soon as dns_info is free'd           */
495   char *cptr;                   /* temporary pointer                       */
496   sockname_t *ip;               /* pointer to sockname with ipv4/6 address */
497   int ibuf;                     /* temporary buffer for one integer        */
498   char dns_type;                /* lookup type, e.g. RES_HOSTBYIP          */
499   struct dcc_table *type;       /* type of the dcc table we are making the
500                                  * lookup for                              */
501 };
502 
503 /* Flags for dns_type. */
504 #define RES_HOSTBYIP  1         /* hostname to IP address               */
505 #define RES_IPBYHOST  2         /* IP address to hostname               */
506 
507 struct dupwait_info {
508   int atr;                      /* the bots attributes                  */
509   struct chat_info *chat;       /* holds current chat data              */
510 };
511 
512 /* Flags for dcc types. */
513 #define DCT_CHAT      0x00000001        /* this dcc type receives botnet
514                                          * chatter                          */
515 #define DCT_MASTER    0x00000002        /* received master chatter          */
516 #define DCT_SHOWWHO   0x00000004        /* show the user in .who            */
517 #define DCT_REMOTEWHO 0x00000008        /* show in remote who               */
518 #define DCT_VALIDIDX  0x00000010        /* valid idx for outputting to
519                                          * in tcl                           */
520 #define DCT_SIMUL     0x00000020        /* can be tcl_simul'd               */
521 #define DCT_CANBOOT   0x00000040        /* can be booted                    */
522 #define DCT_GETNOTES  DCT_CHAT          /* can receive notes                */
523 #define DCT_FILES     0x00000080        /* gratuitous hack ;)               */
524 #define DCT_FORKTYPE  0x00000100        /* a forking type                   */
525 #define DCT_BOT       0x00000200        /* a bot connection of some sort... */
526 #define DCT_FILETRAN  0x00000400        /* a file transfer of some sort     */
527 #define DCT_FILESEND  0x00000800        /* a sending file transfer,
528                                          * getting = !this                  */
529 #define DCT_LISTEN    0x00001000        /* a listening port of some sort    */
530 
531 /* For dcc chat & files. */
532 #define STAT_ECHO    0x00001    /* echo commands back?                  */
533 #define STAT_FPRINT  0x00002    /* fingerprint auth (ignore password &
534                                  * allow access)                        */
535 #define STAT_CHAT    0x00004    /* in file-system but may return        */
536 #define STAT_TELNET  0x00008    /* connected via telnet                 */
537 #define STAT_PARTY   0x00010    /* only on party line via 'p' flag      */
538 #define STAT_BOTONLY 0x00020    /* telnet on bots-only connect          */
539 #define STAT_USRONLY 0x00040    /* telnet on users-only connect         */
540 #define STAT_PAGE    0x00080    /* page output to the user              */
541 #define STAT_SERV    0x00100    /* this is a server connection          */
542 
543 /* For stripping out mIRC codes. */
544 #define STRIP_COLOR     0x00001    /* remove mIRC color codes            */
545 #define STRIP_BOLD      0x00002    /* remove bold codes                  */
546 #define STRIP_REVERSE   0x00004    /* remove reverse video codes         */
547 #define STRIP_UNDERLINE 0x00008    /* remove underline codes             */
548 #define STRIP_ANSI      0x00010    /* remove ALL ANSI codes              */
549 #define STRIP_BELLS     0x00020    /* remove ctrl-g's                    */
550 #define STRIP_ORDINARY  0x00040    /* remove ordinary codes              */
551 #define STRIP_ITALICS   0x00080    /* remove italics codes               */
552 #define STRIP_ALL       0x000FF    /* remove every damn thing!           */
553 
554 /* For dcc bot links. */
555 #define STAT_PINGED  0x00001    /* waiting for ping to return            */
556 #define STAT_SHARE   0x00002    /* sharing user data with the bot        */
557 #define STAT_CALLED  0x00004    /* this bot called me                    */
558 #define STAT_OFFERED 0x00008    /* offered her the user file             */
559 #define STAT_SENDING 0x00010    /* in the process of sending a user list */
560 #define STAT_GETTING 0x00020    /* in the process of getting a user list */
561 #define STAT_WARNED  0x00040    /* warned him about unleaflike behavior  */
562 #define STAT_LEAF    0x00080    /* this bot is a leaf only               */
563 #define STAT_LINKING 0x00100    /* the bot is currently going through
564                                  * the linking stage                     */
565 #define STAT_AGGRESSIVE 0x00200 /* aggressively sharing with this bot    */
566 
567 /* Flags for listening sockets */
568 #define LSTN_PUBLIC  0x000001   /* No access restrictions               */
569 
570 /* chan & global */
571 #define FLOOD_PRIVMSG    0
572 #define FLOOD_NOTICE     1
573 #define FLOOD_CTCP       2
574 #define FLOOD_NICK       3
575 #define FLOOD_JOIN       4
576 #define FLOOD_KICK       5
577 #define FLOOD_DEOP       6
578 
579 #define FLOOD_CHAN_MAX   7
580 #define FLOOD_GLOBAL_MAX 3
581 
582 /* For local console: */
583 #define STDIN  0
584 #define STDOUT 1
585 #define STDERR 2
586 
587 /* Structure for internal logs */
588 typedef struct {
589   char *filename;
590   unsigned int mask;            /* what to send to this log                 */
591   char *chname;                 /* which channel                            */
592   char szlast[LOGLINELEN];      /* for 'Last message repeated n times'
593                                  * stuff in misc.c/putlog() <cybah>         */
594   int repeats;                  /* number of times szLast has been repeated */
595   unsigned int flags;           /* other flags <rtc>                        */
596   FILE *f;                      /* existing file                            */
597 } log_t;
598 
599 /* Logfile display flags
600  */
601 #define LOG_MSGS     0x000001   /* m   private msgs/notices/ctcps       */
602 #define LOG_PUBLIC   0x000002   /* p   public  msgs/notices/ctcps       */
603 #define LOG_JOIN     0x000004   /* j   channel joins/parts/etc          */
604 #define LOG_MODES    0x000008   /* k   mode changes/kicks/bans          */
605 #define LOG_CMDS     0x000010   /* c   user dcc or msg commands         */
606 #define LOG_MISC     0x000020   /* o   other misc bot things            */
607 #define LOG_BOTS     0x000040   /* b   bot notices                      */
608 #define LOG_RAW      0x000080   /* r   raw server stuff coming in       */
609 #define LOG_FILES    0x000100   /* x   file transfer commands and stats */
610 #define LOG_LEV1     0x000200   /* 1   user log level                   */
611 #define LOG_LEV2     0x000400   /* 2   user log level                   */
612 #define LOG_LEV3     0x000800   /* 3   user log level                   */
613 #define LOG_LEV4     0x001000   /* 4   user log level                   */
614 #define LOG_LEV5     0x002000   /* 5   user log level                   */
615 #define LOG_LEV6     0x004000   /* 6   user log level                   */
616 #define LOG_LEV7     0x008000   /* 7   user log level                   */
617 #define LOG_LEV8     0x010000   /* 8   user log level                   */
618 #define LOG_SERV     0x020000   /* s   server information               */
619 #define LOG_DEBUG    0x040000   /* d   debug                            */
620 #define LOG_WALL     0x080000   /* w   wallops                          */
621 #define LOG_SRVOUT   0x100000   /* v   server output                    */
622 #define LOG_BOTNETIN 0x200000   /* t   incoming botnet traffic          */
623 #define LOG_BOTSHRIN 0x400000   /* h   incoming share traffic           */
624 #define LOG_BOTNETOUT 0x800000  /* u   outgoing botnet traffic          */
625 #define LOG_BOTSHROUT 0x1000000 /* g   outgoing share traffic           */
626 #define LOG_BOTMSG   0x2000000  /* l   linked bot messages              */
627 #define LOG_ALL      0x3ffffff  /* (dump to all logfiles)               */
628 
629 /* Internal logfile flags
630  */
631 #define LF_EXPIRING 0x000001    /* Logfile will be closed soon          */
632 
633 #define FILEDB_HIDE     1
634 #define FILEDB_UNHIDE   2
635 #define FILEDB_SHARE    3
636 #define FILEDB_UNSHARE  4
637 
638 /* Socket flags:
639  */
640 #define SOCK_UNUSED     0x0001  /* empty socket                         */
641 #define SOCK_BINARY     0x0002  /* do not buffer input                  */
642 #define SOCK_LISTEN     0x0004  /* listening port                       */
643 #define SOCK_CONNECT    0x0008  /* connection attempt                   */
644 #define SOCK_NONSOCK    0x0010  /* used for file i/o on debug           */
645 #define SOCK_STRONGCONN 0x0020  /* don't report success until sure      */
646 #define SOCK_EOFD       0x0040  /* it EOF'd recently during a write     */
647 #define SOCK_PROXYWAIT  0x0080  /* waiting for SOCKS traversal          */
648 #define SOCK_PASS       0x0100  /* passed on; only notify in case
649                                  * of traffic                           */
650 #define SOCK_VIRTUAL    0x0200  /* not-connected socket (dont read it!) */
651 #define SOCK_BUFFER     0x0400  /* buffer data; don't notify dcc funcs  */
652 #define SOCK_TCL        0x0800  /* tcl socket, don't do anything on it  */
653 
654 /* Flags to sock_has_data
655  */
656 enum {
657   SOCK_DATA_OUTGOING,           /* Data in out-queue?                   */
658   SOCK_DATA_INCOMING            /* Data in in-queue?                    */
659 };
660 
661 /* Fake idx's for dprintf - these should be ridiculously large +ve nums
662  */
663 #define DP_STDOUT       0x7FF1
664 #define DP_LOG          0x7FF2
665 #define DP_SERVER       0x7FF3
666 #define DP_HELP         0x7FF4
667 #define DP_STDERR       0x7FF5
668 #define DP_MODE         0x7FF6
669 #define DP_MODE_NEXT    0x7FF7
670 #define DP_SERVER_NEXT  0x7FF8
671 #define DP_HELP_NEXT    0x7FF9
672 
673 #define NORMAL          0
674 #define QUICK           1
675 
676 /* Return codes for add_note */
677 #define NOTE_ERROR      0       /* error                        */
678 #define NOTE_OK         1       /* success                      */
679 #define NOTE_STORED     2       /* not online; stored           */
680 #define NOTE_FULL       3       /* too many notes stored        */
681 #define NOTE_TCL        4       /* tcl binding caught it        */
682 #define NOTE_AWAY       5       /* away; stored                 */
683 #define NOTE_FWD        6       /* away; forwarded              */
684 #define NOTE_REJECT     7       /* ignore mask matched          */
685 
686 #define STR_PROTECT     2
687 #define STR_DIR         1
688 
689 #define HELP_DCC        1
690 #define HELP_TEXT       2
691 #define HELP_IRC        16
692 
693 #ifdef TLS
694 /* TLS generic flags */
695 #  define TLS_LISTEN            0x80000000
696 #  define TLS_CONNECT           0x40000000
697 #  define TLS_DEPTH0            0x20000000
698 
699 /* TLS verification flags */
700 #  define TLS_VERIFYPEER        0x00000001
701 #  define TLS_VERIFYISSUER      0x00000002
702 #  define TLS_VERIFYCN          0x00000004
703 #  define TLS_VERIFYTO          0x00000008
704 #  define TLS_VERIFYFROM        0x00000010
705 #  define TLS_VERIFYREV         0x00000020
706 
707 /* Context information to attach to SSL sockets */
708 typedef struct {
709   int flags;                    /* listen/connect, generic ssl flags      */
710   int verify;                   /* certificate validation mode            */
711   int loglevel;                 /* log level to output TLS information to */
712   char host[256];               /* host or IP for certificate validation  */
713   IntFunc cb;
714 } ssl_appdata;
715 #endif /* TLS */
716 
717 /* These are used by the net module to keep track of sockets and what's
718  * queued on them
719  */
720 struct sock_handler {
721   char *inbuf;
722   char *outbuf;
723   unsigned long outbuflen;      /* Outbuf could be binary data  */
724   unsigned long inbuflen;       /* Inbuf could be binary data   */
725 };
726 
727 struct tclsock_handler {
728   int mask;                     /* desired events               */
729   Tcl_FileProc *proc;
730   ClientData cd;
731 };
732 
733 typedef struct sock_list {
734   int sock;
735 #ifdef TLS
736   SSL *ssl;
737 #endif
738   short flags;
739   union {
740     struct sock_handler sock;
741     struct tclsock_handler tclsock;
742   } handler;
743 } sock_list;
744 
745 enum {
746   EGG_OPTION_SET = 1,           /* Set option(s).               */
747   EGG_OPTION_UNSET = 2          /* Unset option(s).             */
748 };
749 
750 #define ESC             27      /* Oct              033
751                                  * Hex              1B
752                                  * Caret notation   ^[
753                                  * Escape sequences \e
754                                  * \e is not supported in all compilers
755                                  */
756 
757 /* Telnet codes.  See "TELNET Protocol Specification" (RFC 854) and
758  * "TELNET Echo Option" (RFC 875) for details. */
759 
760 /* Telnet commands */
761 #define TLN_AYT         246     /* Are You There        */
762 #define TLN_WILL        251     /* Will                 */
763 #define TLN_WILL_C      "\373"
764 #define TLN_WONT        252     /* Won't                */
765 #define TLN_WONT_C      "\374"
766 #define TLN_DO          253     /* Do                   */
767 #define TLN_DO_C        "\375"
768 #define TLN_DONT        254     /* Don't                */
769 #define TLN_DONT_C      "\376"
770 #define TLN_IAC         255     /* Interpret As Command */
771 #define TLN_IAC_C       "\377"
772 
773 /* Telnet options */
774 #define TLN_ECHO        1       /* Echo (RFC 875)        */
775 #define TLN_ECHO_C      "\001"
776 #define TLN_STATUS      5       /* STATUS (RFC 859)      */
777 #define TLN_STATUS_C    "\005"
778 
779 /* From tcl.h */
780 #ifndef STRINGIFY
781 #  define STRINGIFY(x) STRINGIFY1(x)
782 #  define STRINGIFY1(x) #x
783 #endif
784 
785 #ifdef EGG_TDNS
786 #define DTN_TYPE_HOSTBYIP 0
787 #define DTN_TYPE_IPBYHOST 1
788 
789 /* linked list instead of array because of multi threading */
790 struct dns_thread_node {
791   int fildes[2];
792   int type;
793   sockname_t addr;
794   char host[256];
795   int ok;
796   struct dns_thread_node *next;
797 };
798 
799 extern struct dns_thread_node *dns_thread_head;
800 #endif
801 
802 #endif /* _EGG_EGGDROP_H */
803