00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef SERVICES_H
00015 #define SERVICES_H
00016
00017
00018
00019 #include "sysconf.h"
00020 #include "config.h"
00021
00022 #ifndef MAX_CMD_HASH
00023 #define MAX_CMD_HASH 1024
00024 #endif
00025
00026
00027
00028 #ifndef _GNU_SOURCE
00029 #define _GNU_SOURCE
00030 #endif
00031
00032
00033 #ifdef __sun
00034
00035
00036
00037 #undef u_int8_t
00038 #undef u_int16_t
00039 #undef u_int32_t
00040 #undef u_int_64_t
00041 #define u_int8_t uint8_t
00042 #define u_int16_t uint16_t
00043 #define u_int32_t uint32_t
00044 #define u_int64_t uint64_t
00045
00046 #ifndef INADDR_NONE
00047 #define INADDR_NONE (-1)
00048 #endif
00049
00050 #endif
00051
00052
00053 #include <stdarg.h>
00054 #include <stdio.h>
00055 #include <stdlib.h>
00056 #include <string.h>
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #ifndef _WIN32
00068 #include <unistd.h>
00069 #endif
00070
00071 #include <signal.h>
00072 #include <time.h>
00073 #include <errno.h>
00074
00075 #ifndef _WIN32
00076 #include <grp.h>
00077 #endif
00078
00079 #include <limits.h>
00080
00081 #ifndef _WIN32
00082 #include <netdb.h>
00083 #include <netinet/in.h>
00084 #include <arpa/inet.h>
00085 #include <sys/socket.h>
00086 #else
00087 #include <winsock.h>
00088 #include <windows.h>
00089 #endif
00090
00091 #include <sys/stat.h>
00092 #include <sys/types.h>
00093
00094 #ifndef _WIN32
00095 #include <sys/time.h>
00096 #endif
00097
00098 #ifdef _WIN32
00099 #include <sys/timeb.h>
00100 #include <direct.h>
00101 #include <io.h>
00102 #endif
00103
00104 #include <fcntl.h>
00105
00106 #ifndef _WIN32
00107 #ifdef HAVE_BACKTRACE
00108 #include <execinfo.h>
00109 #endif
00110 #endif
00111
00112 #ifndef _WIN32
00113 #include <dirent.h>
00114 #endif
00115
00116 #ifdef _WIN32
00117
00118 #define vsnprintf _vsnprintf
00119 #endif
00120
00121 #ifdef USE_RDB
00122 # define MAX_SQL_BUF 4096
00123 #endif
00124
00125 #ifdef USE_MYSQL
00126 # define MYSQL_WARNING 2
00127 # define MYSQL_ERROR 4
00128 # define MYSQL_DEFAULT_PORT 3306
00129 #ifdef MYSQL_HEADER_PREFIX
00130 # include <mysql/mysql.h>
00131 # include <mysql/errmsg.h>
00132 #else
00133 # include <mysql.h>
00134 # include <errmsg.h>
00135 #endif
00136 #endif
00137
00138 #if HAVE_STRINGS_H
00139 # include <strings.h>
00140 #endif
00141
00142 #if HAVE_SYS_SELECT_H
00143 # include <sys/select.h>
00144 #endif
00145
00146 #include "sockets.h"
00147
00148 #ifndef va_copy
00149 # ifdef __va_copy
00150 # define VA_COPY(DEST,SRC) __va_copy((DEST),(SRC))
00151 # else
00152 # define VA_COPY(DEST, SRC) memcpy ((&DEST), (&SRC), sizeof(va_list))
00153 # endif
00154 #else
00155 # ifdef HAVE_VA_LIST_AS_ARRAY
00156 # define VA_COPY(DEST,SRC) (*(DEST) = *(SRC))
00157 # else
00158 # define VA_COPY(DEST, SRC) va_copy(DEST, SRC)
00159 # endif
00160 #endif
00161
00162 #ifdef _AIX
00163
00164
00165 extern int strcasecmp(const char *, const char *);
00166 extern int strncasecmp(const char *, const char *, size_t);
00167 # if 0
00168 extern int gettimeofday(struct timeval *, struct timezone *);
00169 extern int socket(int, int, int);
00170 extern int bind(int, struct sockaddr *, int);
00171 extern int connect(int, struct sockaddr *, int);
00172 extern int shutdown(int, int);
00173 # endif
00174 # undef FD_ZERO
00175 # define FD_ZERO(p) memset((p), 0, sizeof(*(p)))
00176 #endif
00177
00178
00179
00180 #if !HAVE_STRICMP && HAVE_STRCASECMP
00181 # define stricmp strcasecmp
00182 # define strnicmp strncasecmp
00183 #endif
00184
00185
00186 #include <ctype.h>
00187 #undef tolower
00188 #undef toupper
00189 #define tolower tolower_
00190 #define toupper toupper_
00191
00192
00193 #define encrypt encrypt_
00194
00195
00196 #ifdef __WINS__
00197 #ifndef BKCHECK
00198 #define BKCHECK
00199 extern "C" void __pfnBkCheck() {}
00200 #endif
00201 #endif
00202
00203
00204 #if INTTYPE_WORKAROUND
00205 # undef int16
00206 # undef int32
00207 #endif
00208
00209
00210
00211 #include "defs.h"
00212 #include "slist.h"
00213 #include "events.h"
00214
00215
00216
00217 typedef struct server_ Server;
00218 typedef struct user_ User;
00219 typedef struct channel_ Channel;
00220 typedef struct ModuleData_ ModuleData;
00221 typedef struct memo_ Memo;
00222 typedef struct nickrequest_ NickRequest;
00223 typedef struct nickalias_ NickAlias;
00224 typedef struct nickcore_ NickCore;
00225 typedef struct botinfo_ BotInfo;
00226 typedef struct chaninfo_ ChannelInfo;
00227 typedef struct badword_ BadWord;
00228 typedef struct bandata_ BanData;
00229 typedef struct userdata_ UserData;
00230 typedef struct mailinfo_ MailInfo;
00231 typedef struct akill_ Akill;
00232 typedef struct sxline_ SXLine;
00233 typedef struct hostcore_ HostCore;
00234 typedef struct newsitem_ NewsItem;
00235 typedef struct exception_ Exception;
00236 typedef struct cbmode_ CBMode;
00237 typedef struct cbmodeinfo_ CBModeInfo;
00238 typedef struct cmmode_ CMMode;
00239 typedef struct csmode_ CSMode;
00240 typedef struct cumode_ CUMode;
00241 typedef struct csmodeutil_ CSModeUtil;
00242 typedef struct session_ Session;
00243 typedef struct uid_ Uid;
00244
00245
00246
00247
00248
00249
00250
00251 #ifndef _WIN32
00252 typedef enum { false, true } boolean;
00253 #else
00254 #ifndef true
00255 #define true 1
00256 #endif
00257 #ifndef false
00258 #define false 0
00259 #endif
00260 #endif
00261
00262
00263
00264
00265
00266 typedef struct ircdvars_ IRCDVar;
00267 typedef struct ircdcapab_ IRCDCAPAB;
00268
00269 struct ircdvars_ {
00270 char *name;
00271 char *nickservmode;
00272 char *chanservmode;
00273 char *memoservmode;
00274 char *hostservmode;
00275 char *operservmode;
00276 char *botservmode;
00277 char *helpservmode;
00278 char *devnullmode;
00279 char *globalmode;
00280 char *nickservaliasmode;
00281 char *chanservaliasmode;
00282 char *memoservaliasmode;
00283 char *hostservaliasmode;
00284 char *operservaliasmode;
00285 char *botservaliasmode;
00286 char *helpservaliasmode;
00287 char *devnullvaliasmode;
00288 char *globalaliasmode;
00289 char *botserv_bot_mode;
00290 int max_symbols;
00291 char *modestoremove;
00292 char *botchanumode;
00293 int svsnick;
00294 int vhost;
00295 int owner;
00296 char *ownerset;
00297 char *ownerunset;
00298 char *adminset;
00299 char *adminunset;
00300 char *modeonreg;
00301 char *rootmodeonid;
00302 char *adminmodeonid;
00303 char *opermodeonid;
00304 char *modeonunreg;
00305 char *modeonnick;
00306 int sgline;
00307 int sqline;
00308 int szline;
00309 int halfop;
00310 int numservargs;
00311 int join2set;
00312 int join2msg;
00313 int except;
00314 int topictsforward;
00315 int topictsbackward;
00316 uint32 protectedumode;
00317 int admin;
00318 int chansqline;
00319 int quitonkill;
00320 int svsmode_unban;
00321 int protect;
00322 int reversekickcheck;
00323 int chanreg;
00324 uint32 regmode;
00325 int vident;
00326 int svshold;
00327 int tsonmode;
00328 int nickip;
00329 int omode;
00330 int umode;
00331 int nickvhost;
00332 int chgreal;
00333 uint32 noknock;
00334 uint32 adminmode;
00335 uint32 defmlock;
00336 uint32 vhostmode;
00337 int fmode;
00338 int Lmode;
00339 uint32 chan_fmode;
00340 uint32 chan_lmode;
00341 int check_nick_id;
00342 int knock_needs_i;
00343 char *chanmodes;
00344 int token;
00345 int tokencaseless;
00346 int sjb64;
00347 int invitemode;
00348 int sjoinbanchar;
00349 int sjoinexchar;
00350 int sjoininvchar;
00351 int svsmode_ucmode;
00352 int sglineenforce;
00353 char *vhostchar;
00354 int ts6;
00355 int supporthelper;
00356 int p10;
00357 char *nickchars;
00358 int sync;
00359 };
00360
00361 struct ircdcapab_ {
00362 uint32 noquit;
00363 uint32 tsmode;
00364 uint32 unconnect;
00365 uint32 nickip;
00366 uint32 nsjoin;
00367 uint32 zip;
00368 uint32 burst;
00369 uint32 ts5;
00370 uint32 ts3;
00371 uint32 dkey;
00372 uint32 pt4;
00373 uint32 scs;
00374 uint32 qs;
00375 uint32 uid;
00376 uint32 knock;
00377 uint32 client;
00378 uint32 ipv6;
00379 uint32 ssj5;
00380 uint32 sn2;
00381 uint32 token;
00382 uint32 vhost;
00383 uint32 ssj3;
00384 uint32 nick2;
00385 uint32 umode2;
00386 uint32 vl;
00387 uint32 tlkext;
00388 uint32 dodkey;
00389 uint32 dozip;
00390 uint32 chanmodes;
00391 uint32 sjb64;
00392 uint32 nickchars;
00393 };
00394
00395
00396
00397
00398 struct uid_ {
00399 Uid *next, *prev;
00400 char nick[NICKMAX];
00401 char *uid;
00402 };
00403
00404
00405
00406
00407
00408 #define MAXPARAMS 8
00409
00410
00411
00412 typedef struct {
00413 char *name;
00414 struct {
00415 int type;
00416 int flags;
00417 void *ptr;
00418 } params[MAXPARAMS];
00419 } Directive;
00420
00421 #define PARAM_NONE 0
00422 #define PARAM_INT 1
00423 #define PARAM_POSINT 2
00424 #define PARAM_PORT 3
00425 #define PARAM_STRING 4
00426 #define PARAM_TIME 5
00427 #define PARAM_STRING_ARRAY 6
00428 #define PARAM_SET -1
00429
00430 #define PARAM_DEPRECATED -2
00431
00432
00433
00434 #define PARAM_OPTIONAL 0x01
00435 #define PARAM_FULLONLY 0x02
00436 #define PARAM_RELOAD 0x04
00437
00438
00439
00440
00441
00442
00443 #define BOT_VERSION 10
00444 #define CHAN_VERSION 16
00445 #define EXCEPTION_VERSION 9
00446 #define NEWS_VERSION 9
00447 #define NICK_VERSION 13
00448 #define PRE_NICK_VERSION 1
00449 #define OPER_VERSION 13
00450 #define HELP_VERSION 1
00451 #define HOST_VERSION 3
00452
00453
00454
00455
00460 struct ModuleData_ {
00461 char *moduleName;
00462 char *key;
00463 char *value;
00464 ModuleData *next;
00465 };
00466
00467
00468
00469
00470
00471
00472 struct memo_ {
00473 uint32 number;
00474 uint16 flags;
00475 time_t time;
00476 char sender[NICKMAX];
00477 char *text;
00478 ModuleData *moduleData;
00479 #ifdef USE_MYSQL
00480 uint32 id;
00481 #endif
00482 };
00483
00484 typedef struct {
00485 int16 memocount, memomax;
00486 Memo *memos;
00487 } MemoInfo;
00488
00489
00490
00491
00492
00493
00494 struct nickrequest_ {
00495 NickRequest *next, *prev;
00496 char *nick;
00497 char *passcode;
00498 char *password;
00499 char *email;
00500 time_t requested;
00501 time_t lastmail;
00502 };
00503
00504 struct nickalias_ {
00505 NickAlias *next, *prev;
00506 char *nick;
00507 char *last_quit;
00508 char *last_realname;
00509 char *last_usermask;
00510 time_t time_registered;
00511 time_t last_seen;
00512 uint16 status;
00513 NickCore *nc;
00514
00515 ModuleData *moduleData;
00516 User *u;
00517 };
00518
00519 struct nickcore_ {
00520 NickCore *next, *prev;
00521
00522 char *display;
00523 char *pass;
00524 char *email;
00525 char *greet;
00526 uint32 icq;
00527 char *url;
00528 uint32 flags;
00529 uint16 language;
00530 uint16 accesscount;
00531 char **access;
00532 MemoInfo memos;
00533 uint16 channelcount;
00534 uint16 channelmax;
00535
00536
00537 ModuleData *moduleData;
00538 time_t lastmail;
00539 SList aliases;
00540 };
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550 struct botinfo_ {
00551 BotInfo *next, *prev;
00552
00553 char *nick;
00554 char *user;
00555 char *host;
00556 char *real;
00557 int16 flags;
00558 time_t created;
00559 int16 chancount;
00560
00561 time_t lastmsg;
00562 };
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572 typedef struct {
00573 uint16 in_use;
00574 int16 level;
00575 NickCore *nc;
00576 time_t last_seen;
00577 } ChanAccess;
00578
00579
00580
00581
00582
00583
00584 #define ACCESS_FOUNDER 10000
00585 #define ACCESS_INVALID -10000
00586
00587
00588
00589
00590 #define ACCESS_SUPERADMIN 10001
00591
00592
00593
00594 #define ACCESS_VOP 3
00595 #define ACCESS_HOP 4
00596 #define ACCESS_AOP 5
00597 #define ACCESS_SOP 10
00598
00599
00600 typedef struct {
00601 int16 in_use;
00602 int16 is_nick;
00603 uint16 flags;
00604 union {
00605 char *mask;
00606 NickCore *nc;
00607 } u;
00608 char *reason;
00609
00610 char *creator;
00611 time_t addtime;
00612 } AutoKick;
00613
00614 #define AK_USED 0x0001
00615 #define AK_ISNICK 0x0002
00616 #define AK_STUCK 0x0004
00617
00618
00619
00620 struct badword_ {
00621 uint16 in_use;
00622 char *word;
00623 uint16 type;
00624 };
00625
00626 #define BW_ANY 0
00627 #define BW_SINGLE 1
00628 #define BW_START 2
00629 #define BW_END 3
00630
00631
00632 struct chaninfo_ {
00633 ChannelInfo *next, *prev;
00634 char name[CHANMAX];
00635 NickCore *founder;
00636 NickCore *successor;
00637
00638 char founderpass[PASSMAX];
00639 char *desc;
00640 char *url;
00641 char *email;
00642
00643 time_t time_registered;
00644 time_t last_used;
00645 char *last_topic;
00646 char last_topic_setter[NICKMAX];
00647 time_t last_topic_time;
00648
00649 uint32 flags;
00650 char *forbidby;
00651 char *forbidreason;
00652
00653 int16 bantype;
00654 int16 *levels;
00655
00656 uint16 accesscount;
00657 ChanAccess *access;
00658 uint16 akickcount;
00659 AutoKick *akick;
00660
00661 uint32 mlock_on, mlock_off;
00662 uint32 mlock_limit;
00663 char *mlock_key;
00664 char *mlock_flood;
00665 char *mlock_redirect;
00666
00667 char *entry_message;
00668
00669 MemoInfo memos;
00670
00671 struct channel_ *c;
00672
00673
00674 ModuleData *moduleData;
00675
00676
00677
00678 BotInfo *bi;
00679 uint32 botflags;
00680 int16 *ttb;
00681
00682 uint16 bwcount;
00683 BadWord *badwords;
00684 int16 capsmin, capspercent;
00685 int16 floodlines, floodsecs;
00686 int16 repeattimes;
00687 };
00688
00689
00690 #define CI_KEEPTOPIC 0x00000001
00691
00692 #define CI_SECUREOPS 0x00000002
00693
00694 #define CI_PRIVATE 0x00000004
00695
00696 #define CI_TOPICLOCK 0x00000008
00697
00698 #define CI_RESTRICTED 0x00000010
00699
00700 #define CI_PEACE 0x00000020
00701
00702 #define CI_SECURE 0x00000040
00703
00704 #define CI_VERBOTEN 0x00000080
00705
00706 #define CI_ENCRYPTEDPW 0x00000100
00707
00708 #define CI_NO_EXPIRE 0x00000200
00709
00710 #define CI_MEMO_HARDMAX 0x00000400
00711
00712 #define CI_OPNOTICE 0x00000800
00713
00714 #define CI_SECUREFOUNDER 0x00001000
00715
00716 #define CI_SIGNKICK 0x00002000
00717
00718 #define CI_SIGNKICK_LEVEL 0x00004000
00719
00720 #define CI_XOP 0x00008000
00721
00722 #define CI_SUSPENDED 0x00010000
00723
00724
00725 #define CI_INHABIT 0x80000000
00726
00727
00728 #define CA_INVITE 0