From 548d66d26c3e8e52ada71de84f07569fcee33f69 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 5 Jul 2026 12:09:16 +0200 Subject: [PATCH] Reformat all source code, using 'make format' (clang-format 21.1.8) This reformats entire UnrealIRCd source code, according to .clang-format which was previously commited. This is reproducable using clang-format version 21.1.8. These are only visual changes, they have no effect on code. This commit will be added to .git-blame-ignore-revs so 'git blame' and the similar blame view on GitHub will ignore this commit. --- include/channel.h | 12 +- include/common.h | 162 +- include/config.h | 151 +- include/dbuf.h | 18 +- include/dns.h | 29 +- include/dynconf.h | 384 +- include/fdlist.h | 27 +- include/h.h | 410 +- include/ircsprintf.h | 8 +- include/license.h | 40 +- include/list.h | 121 +- include/mempool.h | 46 +- include/mmdb.h | 36 +- include/modules.h | 1152 ++--- include/modversion.h | 4 +- include/msg.h | 274 +- include/numeric.h | 458 +- include/resource.h | 102 +- include/struct.h | 2430 +++++------ include/sys.h | 216 +- include/types.h | 6 +- include/version.h | 42 +- include/whowas.h | 14 +- include/windows/setup.h | 26 +- src/aliases.c | 133 +- src/api-apicallback.c | 18 +- src/api-channelmode.c | 131 +- src/api-clicap.c | 21 +- src/api-command.c | 18 +- src/api-efunctions.c | 21 +- src/api-event.c | 3 +- src/api-extban.c | 39 +- src/api-history-backend.c | 29 +- src/api-isupport.c | 10 +- src/api-messagetag.c | 23 +- src/api-moddata.c | 72 +- src/api-rpc.c | 15 +- src/api-usermode.c | 24 +- src/auth.c | 106 +- src/channel.c | 134 +- src/conf.c | 3930 ++++++++---------- src/conf_preprocessor.c | 192 +- src/crashreport.c | 239 +- src/dbuf.c | 32 +- src/debug.c | 76 +- src/dispatch.c | 147 +- src/dns.c | 90 +- src/fdlist.c | 9 +- src/hash.c | 304 +- src/ircd.c | 376 +- src/ircd_vars.c | 20 +- src/ircsprintf.c | 111 +- src/json.c | 102 +- src/list.c | 123 +- src/log.c | 329 +- src/match.c | 142 +- src/mempool.c | 690 +-- src/misc.c | 386 +- src/modulemanager.c | 254 +- src/modules.c | 397 +- src/modules/account-notify.c | 23 +- src/modules/account-tag.c | 15 +- src/modules/addmotd.c | 19 +- src/modules/addomotd.c | 19 +- src/modules/admin.c | 19 +- src/modules/antimixedutf8.c | 51 +- src/modules/antirandom.c | 156 +- src/modules/authprompt.c | 75 +- src/modules/away.c | 25 +- src/modules/batch.c | 20 +- src/modules/blacklist.c | 251 +- src/modules/bot-tag.c | 15 +- src/modules/botmotd.c | 19 +- src/modules/cap.c | 51 +- src/modules/central-api.c | 56 +- src/modules/central-blocklist.c | 222 +- src/modules/certfp.c | 24 +- src/modules/chanmodes/censor.c | 88 +- src/modules/chanmodes/chanadmin.c | 15 +- src/modules/chanmodes/chanop.c | 15 +- src/modules/chanmodes/chanowner.c | 15 +- src/modules/chanmodes/delayjoin.c | 44 +- src/modules/chanmodes/floodprot.c | 267 +- src/modules/chanmodes/halfop.c | 15 +- src/modules/chanmodes/history.c | 112 +- src/modules/chanmodes/inviteonly.c | 19 +- src/modules/chanmodes/isregistered.c | 17 +- src/modules/chanmodes/issecure.c | 47 +- src/modules/chanmodes/key.c | 28 +- src/modules/chanmodes/limit.c | 28 +- src/modules/chanmodes/link.c | 46 +- src/modules/chanmodes/moderated.c | 21 +- src/modules/chanmodes/nocolor.c | 35 +- src/modules/chanmodes/noctcp.c | 23 +- src/modules/chanmodes/noexternalmsgs.c | 19 +- src/modules/chanmodes/noinvite.c | 26 +- src/modules/chanmodes/nokick.c | 26 +- src/modules/chanmodes/noknock.c | 29 +- src/modules/chanmodes/nonickchange.c | 32 +- src/modules/chanmodes/nonotice.c | 19 +- src/modules/chanmodes/operonly.c | 34 +- src/modules/chanmodes/permanent.c | 22 +- src/modules/chanmodes/private.c | 17 +- src/modules/chanmodes/regonly.c | 26 +- src/modules/chanmodes/regonlyspeak.c | 29 +- src/modules/chanmodes/secret.c | 17 +- src/modules/chanmodes/secureonly.c | 31 +- src/modules/chanmodes/stripcolor.c | 26 +- src/modules/chanmodes/topiclimit.c | 19 +- src/modules/chanmodes/voice.c | 15 +- src/modules/channel-context.c | 15 +- src/modules/channeldb.c | 84 +- src/modules/charsys.c | 126 +- src/modules/chathistory.c | 66 +- src/modules/chghost.c | 69 +- src/modules/chgident.c | 44 +- src/modules/chgname.c | 52 +- src/modules/clienttagdeny.c | 36 +- src/modules/cloak_md5.c | 142 +- src/modules/cloak_none.c | 10 +- src/modules/cloak_sha256.c | 80 +- src/modules/close.c | 23 +- src/modules/connect-flood.c | 37 +- src/modules/connect.c | 46 +- src/modules/connthrottle.c | 259 +- src/modules/creationtime.c | 21 +- src/modules/crule.c | 265 +- src/modules/cycle.c | 22 +- src/modules/dccallow.c | 84 +- src/modules/dccdeny.c | 117 +- src/modules/echo-message.c | 49 +- src/modules/eos.c | 17 +- src/modules/extbans/account.c | 17 +- src/modules/extbans/asn.c | 21 +- src/modules/extbans/certfp.c | 19 +- src/modules/extbans/country.c | 19 +- src/modules/extbans/flood.c | 21 +- src/modules/extbans/inchannel.c | 26 +- src/modules/extbans/inherit.c | 43 +- src/modules/extbans/join.c | 17 +- src/modules/extbans/msgbypass.c | 36 +- src/modules/extbans/nickchange.c | 17 +- src/modules/extbans/operclass.c | 21 +- src/modules/extbans/partmsg.c | 15 +- src/modules/extbans/quiet.c | 17 +- src/modules/extbans/realname.c | 17 +- src/modules/extbans/securitygroup.c | 26 +- src/modules/extbans/textban.c | 86 +- src/modules/extbans/timedban.c | 102 +- src/modules/extended-isupport.c | 15 +- src/modules/extended-monitor.c | 20 +- src/modules/extjwt.c | 140 +- src/modules/geoip-tag.c | 20 +- src/modules/geoip_base.c | 60 +- src/modules/geoip_classic.c | 52 +- src/modules/geoip_csv.c | 108 +- src/modules/geoip_mmdb.c | 47 +- src/modules/globops.c | 23 +- src/modules/help.c | 37 +- src/modules/hideserver.c | 106 +- src/modules/history.c | 19 +- src/modules/history_backend_mem.c | 244 +- src/modules/history_backend_null.c | 13 +- src/modules/ident_lookup.c | 28 +- src/modules/invite.c | 118 +- src/modules/ircops.c | 43 +- src/modules/ison.c | 20 +- src/modules/issued-by-tag.c | 24 +- src/modules/isupport.c | 33 +- src/modules/join.c | 129 +- src/modules/jointhrottle.c | 48 +- src/modules/json-log-tag.c | 15 +- src/modules/jumpserver.c | 43 +- src/modules/kick.c | 97 +- src/modules/kill.c | 28 +- src/modules/knock.c | 21 +- src/modules/labeled-response.c | 112 +- src/modules/lag.c | 21 +- src/modules/link-security.c | 47 +- src/modules/links.c | 23 +- src/modules/list.c | 117 +- src/modules/locops.c | 19 +- src/modules/lusers.c | 29 +- src/modules/map.c | 62 +- src/modules/max-unknown-connections-per-ip.c | 17 +- src/modules/maxperip.c | 98 +- src/modules/md.c | 73 +- src/modules/message-ids.c | 23 +- src/modules/message-tags.c | 30 +- src/modules/message.c | 108 +- src/modules/mkpasswd.c | 19 +- src/modules/mmdb.c | 145 +- src/modules/mode.c | 243 +- src/modules/monitor.c | 44 +- src/modules/motd.c | 37 +- src/modules/multiline.c | 126 +- src/modules/names.c | 40 +- src/modules/netinfo.c | 23 +- src/modules/nick.c | 191 +- src/modules/no-implicit-names.c | 16 +- src/modules/nocodes.c | 16 +- src/modules/oper.c | 55 +- src/modules/operinfo.c | 18 +- src/modules/opermotd.c | 23 +- src/modules/part.c | 60 +- src/modules/pass.c | 25 +- src/modules/pingpong.c | 35 +- src/modules/plaintext-policy.c | 23 +- src/modules/portinfo.c | 15 +- src/modules/protoctl.c | 147 +- src/modules/quit.c | 85 +- src/modules/real-quit-reason.c | 15 +- src/modules/reply-tag.c | 15 +- src/modules/reputation.c | 252 +- src/modules/require-module.c | 23 +- src/modules/restrict-commands.c | 56 +- src/modules/rmtkl.c | 71 +- src/modules/rpc/channel.c | 17 +- src/modules/rpc/log.c | 27 +- src/modules/rpc/message.c | 15 +- src/modules/rpc/name_ban.c | 21 +- src/modules/rpc/rpc.c | 195 +- src/modules/rpc/security_group.c | 13 +- src/modules/rpc/server.c | 40 +- src/modules/rpc/server_ban.c | 22 +- src/modules/rpc/server_ban_exception.c | 54 +- src/modules/rpc/spamfilter.c | 22 +- src/modules/rpc/stats.c | 16 +- src/modules/rpc/user.c | 24 +- src/modules/rpc/whowas.c | 20 +- src/modules/rules.c | 20 +- src/modules/sajoin.c | 42 +- src/modules/samode.c | 17 +- src/modules/sapart.c | 77 +- src/modules/sasl.c | 72 +- src/modules/sdesc.c | 23 +- src/modules/sendsno.c | 17 +- src/modules/sendumode.c | 19 +- src/modules/server-time.c | 15 +- src/modules/server.c | 524 ++- src/modules/sethost.c | 31 +- src/modules/setident.c | 19 +- src/modules/setname.c | 40 +- src/modules/silence.c | 30 +- src/modules/sinfo.c | 32 +- src/modules/sjoin.c | 176 +- src/modules/slog.c | 17 +- src/modules/spamreport.c | 118 +- src/modules/sqline.c | 36 +- src/modules/squit.c | 28 +- src/modules/sreply.c | 23 +- src/modules/staff.c | 29 +- src/modules/standard-replies.c | 15 +- src/modules/starttls.c | 19 +- src/modules/stats.c | 278 +- src/modules/sts.c | 15 +- src/modules/svsjoin.c | 31 +- src/modules/svskill.c | 19 +- src/modules/svslogin.c | 20 +- src/modules/svslusers.c | 29 +- src/modules/svsmode.c | 128 +- src/modules/svsmotd.c | 17 +- src/modules/svsnick.c | 25 +- src/modules/svsnline.c | 139 +- src/modules/svsnolag.c | 19 +- src/modules/svsnoop.c | 20 +- src/modules/svso.c | 16 +- src/modules/svspart.c | 30 +- src/modules/svssilence.c | 24 +- src/modules/svssno.c | 25 +- src/modules/svswatch.c | 23 +- src/modules/swhois.c | 27 +- src/modules/targetfloodprot.c | 47 +- src/modules/time.c | 17 +- src/modules/tkl.c | 1301 +++--- src/modules/tkldb.c | 144 +- src/modules/tline.c | 25 +- src/modules/tls_antidos.c | 28 +- src/modules/tls_cipher.c | 19 +- src/modules/topic.c | 73 +- src/modules/trace.c | 90 +- src/modules/tsctl.c | 21 +- src/modules/typing-indicator.c | 15 +- src/modules/umode2.c | 27 +- src/modules/unreal_server_compat.c | 51 +- src/modules/unsqline.c | 29 +- src/modules/user.c | 23 +- src/modules/userhost-tag.c | 20 +- src/modules/userhost.c | 40 +- src/modules/userip-tag.c | 20 +- src/modules/userip.c | 40 +- src/modules/usermodes/bot.c | 23 +- src/modules/usermodes/censor.c | 89 +- src/modules/usermodes/noctcp.c | 23 +- src/modules/usermodes/nokick.c | 35 +- src/modules/usermodes/privacy.c | 25 +- src/modules/usermodes/privdeaf.c | 17 +- src/modules/usermodes/regonlymsg.c | 25 +- src/modules/usermodes/secureonlymsg.c | 32 +- src/modules/usermodes/servicebot.c | 55 +- src/modules/usermodes/showwhois.c | 27 +- src/modules/usermodes/wallops.c | 27 +- src/modules/utf8functions.c | 91 +- src/modules/utf8only.c | 30 +- src/modules/vhost.c | 108 +- src/modules/watch-backend.c | 142 +- src/modules/watch.c | 120 +- src/modules/webirc.c | 51 +- src/modules/webredir.c | 39 +- src/modules/webserver.c | 97 +- src/modules/websocket.c | 60 +- src/modules/websocket_common.c | 51 +- src/modules/who_old.c | 297 +- src/modules/whois.c | 101 +- src/modules/whowas.c | 53 +- src/modules/whowasdb.c | 123 +- src/modules/whox.c | 268 +- src/operclass.c | 71 +- src/parse.c | 83 +- src/proc_io_client.c | 21 +- src/proc_io_server.c | 7 +- src/random.c | 439 +- src/scache.c | 12 +- src/securitygroup.c | 145 +- src/send.c | 170 +- src/serv.c | 228 +- src/socket.c | 278 +- src/support.c | 380 +- src/tls.c | 240 +- src/unrealdb.c | 85 +- src/unrealircdctl.c | 21 +- src/url_curl.c | 23 +- src/url_unreal.c | 180 +- src/user.c | 100 +- src/utf8.c | 37 +- src/whowas.c | 19 +- src/windows/compilerhelp.c | 32 +- src/windows/config.c | 43 +- src/windows/def-clean.c | 15 +- src/windows/editor.c | 440 +- src/windows/gui.c | 418 +- src/windows/resource.h | 200 +- src/windows/rtf.c | 309 +- src/windows/service.c | 30 +- src/windows/unrealsvc.c | 132 +- src/windows/win.c | 428 +- src/windows/win.h | 1 - src/windows/windebug.c | 158 +- 348 files changed, 17458 insertions(+), 17664 deletions(-) diff --git a/include/channel.h b/include/channel.h index 51c5fc2cb..a718adced 100644 --- a/include/channel.h +++ b/include/channel.h @@ -19,20 +19,20 @@ * $Id$ */ -#ifndef __channel_include__ +#ifndef __channel_include__ #define __channel_include__ -#define CREATE 1 /* whether a channel should be created or just tested for existance */ +#define CREATE 1 /* whether a channel should be created or just tested for existance */ -#define MODEBUFLEN 200 -#define MAXBANLEN 200 /* Maximum length of a complete ban */ +#define MODEBUFLEN 200 +#define MAXBANLEN 200 /* Maximum length of a complete ban */ -#define ChannelExists(n) (find_channel(n)) +#define ChannelExists(n) (find_channel(n)) /* NOTE: Timestamps will be added to MODE-commands, so never make * RESYNCMODES and MODEPARAMS higher than MAXPARA-3. DALnet servers * before Dreamforge aren't safe with more than six. -Donwulff */ #include "msg.h" -#define MAXMODEPARAMS (MAXPARA_USER-3) /* Maximum modes processed */ +#define MAXMODEPARAMS (MAXPARA_USER - 3) /* Maximum modes processed */ #endif diff --git a/include/common.h b/include/common.h index 5a03d55f4..638d63cbc 100644 --- a/include/common.h +++ b/include/common.h @@ -19,27 +19,27 @@ * $Id$ */ -#ifndef __common_include__ +#ifndef __common_include__ #define __common_include__ #include #ifdef _WIN32 -#include -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include + #include #endif #include "types.h" #include "config.h" #ifndef _WIN32 -#include -#include + #include + #include #else typedef int bool; -#define false 0 -#define true 1 + #define false 0 + #define true 1 #endif #include "sys.h" @@ -48,48 +48,48 @@ typedef int bool; #include "list.h" #ifdef DEVELOP_CVS -#define ID_Copyright(x) static char id_copyright[] = x -#define ID_Notes(x) static char id_notes[] = x + #define ID_Copyright(x) static char id_copyright[] = x + #define ID_Notes(x) static char id_notes[] = x #else -#define ID_Copyright(x) -#define ID_Notes(x) + #define ID_Copyright(x) + #define ID_Notes(x) #endif #define BMAGIC 0x4675636B596F754661736369737473 #ifdef _WIN32 -#define DEADBEEF_ADDR 0xDEADBEEFDEADBEEF + #define DEADBEEF_ADDR 0xDEADBEEFDEADBEEF #else -#define DEADBEEF_ADDR 0xDEADBEEF + #define DEADBEEF_ADDR 0xDEADBEEF #endif #define BASE_VERSION "UnrealIRCd" #ifndef _WIN32 -#define FDwrite(x,y,z) write(x, y, z) + #define FDwrite(x, y, z) write(x, y, z) #else -#define FDwrite(x,y,z) send(x, y, z, 0) + #define FDwrite(x, y, z) send(x, y, z, 0) #endif #ifndef NULL -#define NULL 0 + #define NULL 0 #endif #ifdef TRUE -#undef TRUE + #undef TRUE #endif #ifdef FALSE -#undef FALSE + #undef FALSE #endif #define FALSE (0) #define TRUE (!FALSE) #ifndef UNSURE -#define UNSURE (2) + #define UNSURE (2) #endif -#define mycmp(a,b) \ - ( (toupper(a[0])!=toupper(b[0])) || smycmp((a)+1,(b)+1) ) +#define mycmp(a, b) \ + ((toupper(a[0]) != toupper(b[0])) || smycmp((a) + 1, (b) + 1)) extern int smycmp(const char *, const char *); #ifndef GLIBC2_x extern int myncmp(const char *, const char *, int); @@ -98,7 +98,7 @@ extern int myncmp(const char *, const char *, int); extern char *strtoken(char **, char *, char *); extern char *strtoken_noskip(char **, char *, char *); -extern MODVAR int global_count, max_global_count; +extern MODVAR int global_count, max_global_count; #ifdef _WIN32 extern int gettimeofday(struct timeval *tp, void *tzp); #endif @@ -106,10 +106,10 @@ extern int gettimeofday(struct timeval *tp, void *tzp); #define PRECISE_CHECK #ifndef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) + #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) + #define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif extern MODVAR u_char tolowertab[], touppertab[]; @@ -131,36 +131,36 @@ extern MODVAR u_char tolowertab[], touppertab[]; #undef iscntrl extern MODVAR unsigned char char_atribs[]; -#define PRINT 1 -#define CNTRL 2 -#define ALPHA 4 -#define PUNCT 8 -#define DIGIT 16 -#define SPACE 32 -#define ALLOW 64 +#define PRINT 1 +#define CNTRL 2 +#define ALPHA 4 +#define PUNCT 8 +#define DIGIT 16 +#define SPACE 32 +#define ALLOW 64 #define ALLOWN 128 #ifndef KLINE_TEMP -#define KLINE_PERM 0 -#define KLINE_TEMP 1 -#define KLINE_AKILL 2 -#define KLINE_EXCEPT 3 + #define KLINE_PERM 0 + #define KLINE_TEMP 1 + #define KLINE_AKILL 2 + #define KLINE_EXCEPT 3 #endif -#define isallowed(c) (char_atribs[(u_char)(c)]&ALLOW) -#define iscntrl(c) (char_atribs[(u_char)(c)]&CNTRL) -#define isalpha(c) (char_atribs[(u_char)(c)]&ALPHA) -#define isspace(c) (char_atribs[(u_char)(c)]&SPACE) -#define islower(c) ((char_atribs[(u_char)(c)]&ALPHA) && ((u_char)(c) > 0x5f)) -#define isupper(c) ((char_atribs[(u_char)(c)]&ALPHA) && ((u_char)(c) < 0x60)) -#define isdigit(c) (char_atribs[(u_char)(c)]&DIGIT) -#define isxdigit(c) (isdigit(c) || ('a' <= (c) && (c) <= 'f') || \ - ('A' <= (c) && (c) <= 'F')) -#define isalnum(c) (char_atribs[(u_char)(c)]&(DIGIT|ALPHA)) -#define isprint(c) (char_atribs[(u_char)(c)]&PRINT) -#define isascii(c) ((u_char)(c) >= 0 && (u_char)(c) <= 0x7f) -#define isgraph(c) ((char_atribs[(u_char)(c)]&PRINT) && ((u_char)(c) != 0x32)) -#define ispunct(c) (!(char_atribs[(u_char)(c)]&(CNTRL|ALPHA|DIGIT))) +#define isallowed(c) (char_atribs[(u_char)(c)] & ALLOW) +#define iscntrl(c) (char_atribs[(u_char)(c)] & CNTRL) +#define isalpha(c) (char_atribs[(u_char)(c)] & ALPHA) +#define isspace(c) (char_atribs[(u_char)(c)] & SPACE) +#define islower(c) ((char_atribs[(u_char)(c)] & ALPHA) && ((u_char)(c) > 0x5f)) +#define isupper(c) ((char_atribs[(u_char)(c)] & ALPHA) && ((u_char)(c) < 0x60)) +#define isdigit(c) (char_atribs[(u_char)(c)] & DIGIT) +#define isxdigit(c) (isdigit(c) || ('a' <= (c) && (c) <= 'f') || \ + ('A' <= (c) && (c) <= 'F')) +#define isalnum(c) (char_atribs[(u_char)(c)] & (DIGIT | ALPHA)) +#define isprint(c) (char_atribs[(u_char)(c)] & PRINT) +#define isascii(c) ((u_char)(c) >= 0 && (u_char)(c) <= 0x7f) +#define isgraph(c) ((char_atribs[(u_char)(c)] & PRINT) && ((u_char)(c) != 0x32)) +#define ispunct(c) (!(char_atribs[(u_char)(c)] & (CNTRL | ALPHA | DIGIT))) #define iswseperator(c) (!isalnum(c) && !((u_char)c >= 128)) /* @@ -170,11 +170,11 @@ extern MODVAR unsigned char char_atribs[]; /* IRCu/Hybrid/unrealircd way now :) -Stskeeps */ -#define EXPAR1 extchmstr[0] -#define EXPAR2 extchmstr[1] -#define EXPAR3 extchmstr[2] -#define EXPAR4 extchmstr[3] -#define CHPAR1 "beI" +#define EXPAR1 extchmstr[0] +#define EXPAR2 extchmstr[1] +#define EXPAR3 extchmstr[2] +#define EXPAR4 extchmstr[3] +#define CHPAR1 "beI" #ifdef _WIN32 /* @@ -184,7 +184,7 @@ extern MODVAR unsigned char char_atribs[]; extern int DisplayString(HWND hWnd, char *InBuf, ...); #else typedef int SOCKET; -#define INVALID_SOCKET -1 + #define INVALID_SOCKET -1 #endif #if defined(__FreeBSD__) || defined(__APPLE__) @@ -198,29 +198,29 @@ extern int lu_noninv, lu_inv, lu_serv, lu_oper, extern MODVAR time_t now; #ifndef _WIN32 -#if defined(__STDC__) -#define __const const -#define __signed signed -#define __volatile volatile -#ifndef __GNUC__ -#define __inline -#endif + #if defined(__STDC__) + #define __const const + #define __signed signed + #define __volatile volatile + #ifndef __GNUC__ + #define __inline + #endif + #else + #ifndef __GNUC__ + #define __const + #define __inline + #define __signed + #define __volatile + #ifndef NO_ANSI_KEYWORDS + #define const /* delete ANSI C keywords */ + #define inline + #define signed + #define volatile + #endif + #endif + #endif #else -#ifndef __GNUC__ -#define __const -#define __inline -#define __signed -#define __volatile -#ifndef NO_ANSI_KEYWORDS -#define const /* delete ANSI C keywords */ -#define inline -#define signed -#define volatile -#endif -#endif -#endif -#else -#define inline __inline + #define inline __inline #endif #endif /* __common_include__ */ diff --git a/include/config.h b/include/config.h index ae259e791..6dd3328f0 100644 --- a/include/config.h +++ b/include/config.h @@ -19,8 +19,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef __config_include__ -#define __config_include__ +#ifndef __config_include__ +#define __config_include__ #include "setup.h" @@ -44,28 +44,28 @@ * this to determine what backend is used. */ #ifndef _WIN32 -# ifdef HAVE_EPOLL -# define BACKEND_EPOLL -# else -# ifdef HAVE_KQUEUE -# define BACKEND_KQUEUE -# else -# ifdef HAVE_POLL -# define BACKEND_POLL -# else -# define BACKEND_SELECT -# endif -# endif -# endif + #ifdef HAVE_EPOLL + #define BACKEND_EPOLL + #else + #ifdef HAVE_KQUEUE + #define BACKEND_KQUEUE + #else + #ifdef HAVE_POLL + #define BACKEND_POLL + #else + #define BACKEND_SELECT + #endif + #endif + #endif #else -# define BACKEND_SELECT + #define BACKEND_SELECT #endif /* Define the ircd module suffix, should be .so on UNIX, and .dll on Windows. */ #ifndef _WIN32 -# define MODULE_SUFFIX ".so" + #define MODULE_SUFFIX ".so" #else -# define MODULE_SUFFIX ".dll" + #define MODULE_SUFFIX ".dll" #endif /* Permit remote /rehash */ @@ -78,10 +78,10 @@ ** HOW_MANY_FREELINKS_ALLOWED - how many freelinks allowed */ #ifndef GARBAGE_COLLECT_EVERY -#define GARBAGE_COLLECT_EVERY 600 /* default: 600 (10 mins) */ + #define GARBAGE_COLLECT_EVERY 600 /* default: 600 (10 mins) */ #endif -#define HOW_MANY_FREELINKS_ALLOWED 200 /* default: 200 */ +#define HOW_MANY_FREELINKS_ALLOWED 200 /* default: 200 */ /* * read/write are restarted after signals defining this 1, gets @@ -89,7 +89,7 @@ * behaviour (apollo sr10.1/bsd4.3 needs this) */ #ifdef APOLLO -#define RESTARTING_SYSTEMCALLS + #define RESTARTING_SYSTEMCALLS #endif /* DEBUGMODE: This should only be used when tracing a problem. It creates @@ -101,15 +101,15 @@ /* * Full pathnames and defaults of irc system's support files. */ -#define CPATH CONFDIR"/unrealircd.conf" /* server configuration file */ -#define MPATH CONFDIR"/ircd.motd" /* server MOTD file */ -#define SMPATH CONFDIR"/ircd.smotd" /* short MOTD file */ -#define RPATH CONFDIR"/ircd.rules" /* server rules file */ -#define OPATH CONFDIR"/oper.motd" /* Operators MOTD file */ -#define LPATH LOGDIR"/debug.log" /* Where the debug file lives, if DEBUGMODE */ -#define VPATH CONFDIR"/ircd.svsmotd" /* Services MOTD append. */ -#define BPATH CONFDIR"/bot.motd" /* Bot MOTD */ -#define IRCDTUNE PERMDATADIR"/ircd.tune" /* tuning .. */ +#define CPATH CONFDIR "/unrealircd.conf" /* server configuration file */ +#define MPATH CONFDIR "/ircd.motd" /* server MOTD file */ +#define SMPATH CONFDIR "/ircd.smotd" /* short MOTD file */ +#define RPATH CONFDIR "/ircd.rules" /* server rules file */ +#define OPATH CONFDIR "/oper.motd" /* Operators MOTD file */ +#define LPATH LOGDIR "/debug.log" /* Where the debug file lives, if DEBUGMODE */ +#define VPATH CONFDIR "/ircd.svsmotd" /* Services MOTD append. */ +#define BPATH CONFDIR "/bot.motd" /* Bot MOTD */ +#define IRCDTUNE PERMDATADIR "/ircd.tune" /* tuning .. */ /** FAKELAG_CONFIGURABLE makes it possible to make certain classes exempted * from 'fake lag' (that is, the artificial delay that is added by the ircd @@ -126,9 +126,9 @@ //#undef FAKELAG_CONFIGURABLE /* The default value for class::sendq */ -#define DEFAULT_SENDQ 3000000 +#define DEFAULT_SENDQ 3000000 /* The default value for class::recvq */ -#define DEFAULT_RECVQ 8000 +#define DEFAULT_RECVQ 8000 /* STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP */ @@ -144,11 +144,11 @@ * 2004-10-13: 1024 -> 4096 */ #ifdef _WIN32 - #define MAXCONNECTIONS 10240 + #define MAXCONNECTIONS 10240 #else /* Non-Windows: */ #if (!defined(MAXCONNECTIONS_REQUEST) || (MAXCONNECTIONS_REQUEST < 1)) && \ - (defined(HAVE_POLL) || defined(HAVE_EPOLL) || defined(HAVE_KQUEUE)) + (defined(HAVE_POLL) || defined(HAVE_EPOLL) || defined(HAVE_KQUEUE)) /* Have poll/epoll/kqueue and either no --with-maxconnections or * --with-maxconnections=0, either of which indicates 'automatic' mode. * At the time of writing we will try a limit of 16384. @@ -182,7 +182,7 @@ * chasing possible for mode and kick. */ #ifndef NICKNAMEHISTORYLENGTH -#define NICKNAMEHISTORYLENGTH 2000 + #define NICKNAMEHISTORYLENGTH 2000 #endif /* @@ -201,7 +201,7 @@ * This can't be in the configuration file, as we need it while * fetching the configuration file.. ;) */ -#define DOWNLOAD_CONNECT_TIMEOUT 15 +#define DOWNLOAD_CONNECT_TIMEOUT 15 #define DOWNLOAD_TRANSFER_TIMEOUT 45 /* Maximum number of HTTP redirects to follow. @@ -235,7 +235,7 @@ * This is kinda experimental, and requires getrusage. */ #ifndef _WIN32 -#define SPAMFILTER_DETECTSLOW + #define SPAMFILTER_DETECTSLOW #endif /* Limits for PCRE2 regex matching (eg. spamfilter, badwords). A regex that @@ -245,8 +245,8 @@ * We use the same defaults that PHP has been using for a long time (which is * actually 10 times lower than PCRE2 defaults, as of 2026). */ -#define UNREAL_PCRE2_MATCH_LIMIT 1000000 -#define UNREAL_PCRE2_DEPTH_LIMIT 100000 +#define UNREAL_PCRE2_MATCH_LIMIT 1000000 +#define UNREAL_PCRE2_DEPTH_LIMIT 100000 /* Maximum number of ModData objects that may be attached to an object */ /* UnrealIRCd 4.0.0: 8, 8, 4, 4 @@ -255,13 +255,13 @@ * UnrealIRCd 6.0.0: 24, 12, 8, 4, 4, 500, 500 * UnrealIRCd 6.1.2: 24, 24, 8, 4, 4, 500, 500 */ -#define MODDATA_MAX_CLIENT 24 -#define MODDATA_MAX_LOCAL_CLIENT 24 -#define MODDATA_MAX_CHANNEL 8 -#define MODDATA_MAX_MEMBER 4 -#define MODDATA_MAX_MEMBERSHIP 4 -#define MODDATA_MAX_LOCAL_VARIABLE 500 -#define MODDATA_MAX_GLOBAL_VARIABLE 500 +#define MODDATA_MAX_CLIENT 24 +#define MODDATA_MAX_LOCAL_CLIENT 24 +#define MODDATA_MAX_CHANNEL 8 +#define MODDATA_MAX_MEMBER 4 +#define MODDATA_MAX_MEMBERSHIP 4 +#define MODDATA_MAX_LOCAL_VARIABLE 500 +#define MODDATA_MAX_GLOBAL_VARIABLE 500 /** Size of the member modes buffer, so can be max this-1 modes * assigned to an individual user (and thus max prefixes as well). @@ -269,7 +269,7 @@ * It allows for vhoaq (5) and then 2 additional ones from 3rd * party modules. */ -#define MEMBERMODESLEN 8 +#define MEMBERMODESLEN 8 /* If EXPERIMENTAL is #define'd then all users will receive a notice about * this when they connect, along with a pointer to bugs.unrealircd.org where @@ -294,27 +294,27 @@ * UNREALIRCD_DEFAULT_TLS_GROUPS_SECONDARY requires OpenSSL 1.1.0 * UNREALIRCD_DEFAULT_TLS_GROUPS_TERTIARY is the last fallback option */ -#define UNREALIRCD_DEFAULT_TLS_GROUPS_PRIMARY "X25519MLKEM768/X25519:secp521r1:secp384r1:prime256v1" +#define UNREALIRCD_DEFAULT_TLS_GROUPS_PRIMARY "X25519MLKEM768/X25519:secp521r1:secp384r1:prime256v1" #define UNREALIRCD_DEFAULT_TLS_GROUPS_SECONDARY "X25519:secp521r1:secp384r1:prime256v1" -#define UNREALIRCD_DEFAULT_TLS_GROUPS_TERTIARY "secp521r1:secp384r1:prime256v1" +#define UNREALIRCD_DEFAULT_TLS_GROUPS_TERTIARY "secp521r1:secp384r1:prime256v1" /* These can be changed via set::central-spamfilter::url and ::feed */ -#define DEFAULT_CENTRAL_SPAMFILTER_URL_OPEN_ACCESS "https://spamfilter.unrealircd.org/spamfilter/v6/$feed/central_spamfilter.conf" +#define DEFAULT_CENTRAL_SPAMFILTER_URL_OPEN_ACCESS "https://spamfilter.unrealircd.org/spamfilter/v6/$feed/central_spamfilter.conf" #define DEFAULT_CENTRAL_SPAMFILTER_URL_RESTRICTED_ACCESS "https://spamfilter.unrealircd-api.org/spamfilter/v6/$feed/central_spamfilter.conf" -#define DEFAULT_CENTRAL_SPAMFILTER_FEED "standard" +#define DEFAULT_CENTRAL_SPAMFILTER_FEED "standard" /* These are just defaults, which you can override via set::dns */ #define DNS_DEFAULT_CLIENT_TIMEOUT 1500 #define DNS_DEFAULT_CLIENT_RETRIES 2 -#define DNS_DEFAULT_DNSBL_TIMEOUT 3000 -#define DNS_DEFAULT_DNSBL_RETRIES 2 +#define DNS_DEFAULT_DNSBL_TIMEOUT 3000 +#define DNS_DEFAULT_DNSBL_RETRIES 2 /* ------------------------- END CONFIGURATION SECTION -------------------- */ -#define MOTD MPATH -#define RULES RPATH -#define MYNAME BINDIR "/unrealircd" -#define CONFIGFILE CPATH -#define IRCD_PIDFILE PIDFILE +#define MOTD MPATH +#define RULES RPATH +#define MYNAME BINDIR "/unrealircd" +#define CONFIGFILE CPATH +#define IRCD_PIDFILE PIDFILE #ifdef DEBUGMODE #define LOGFILE LPATH @@ -323,14 +323,14 @@ #endif #if defined(DEFAULT_RECVQ) -# if (DEFAULT_RECVQ < 512) - error DEFAULT_RECVQ needs redefining. -# endif + #if (DEFAULT_RECVQ < 512) +error DEFAULT_RECVQ needs redefining. + #endif #else - error DEFAULT_RECVQ undefined +error DEFAULT_RECVQ undefined #endif #if (NICKNAMEHISTORYLENGTH < 100) -# define NICKNAMEHISTORYLENGTH 100 + #define NICKNAMEHISTORYLENGTH 100 #endif #if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ @@ -338,25 +338,30 @@ !defined(__cplusplus) #define GCC_TYPECHECKING - /* copied from cURL: */ + /* copied from cURL: */ #define _UNREAL_WARNING(id, message) \ - static void __attribute__((__warning__(message))) \ - __attribute__((__unused__)) __attribute__((__noinline__)) \ - id(void) { __asm__(""); } + static void __attribute__((__warning__(message))) \ + __attribute__((__unused__)) __attribute__((__noinline__)) \ + id(void) \ + { \ + __asm__(""); \ + } #define _UNREAL_ERROR(id, message) \ - static void __attribute__((__error__(message))) \ - __attribute__((__unused__)) __attribute__((__noinline__)) \ - id(void) { __asm__(""); } + static void __attribute__((__error__(message))) \ + __attribute__((__unused__)) __attribute__((__noinline__)) \ + id(void) \ + { \ + __asm__(""); \ + } #endif #ifndef __has_feature - #define __has_feature(x) 0 // Compatibility with non-clang compilers. + #define __has_feature(x) 0 // Compatibility with non-clang compilers. #endif #ifndef __has_extension #define __has_extension __has_feature // Compatibility with pre-3.0 compilers. #endif -#endif /* __config_include__ */ - +#endif /* __config_include__ */ diff --git a/include/dbuf.h b/include/dbuf.h index b097987ab..ab1aaa13d 100644 --- a/include/dbuf.h +++ b/include/dbuf.h @@ -40,7 +40,7 @@ * 2nd page. Note that there is no need to provide room for malloc * overhead as we use mempools. */ -#define DBUF_BLOCK_SIZE (4072+4096) +#define DBUF_BLOCK_SIZE (4072 + 4096) /* ** dbuf is a collection of functions which can be used to @@ -58,8 +58,8 @@ ** interface. */ typedef struct dbuf { - u_int length; /* Current number of bytes stored */ -// u_int offset; /* Offset to the first byte */ + u_int length; /* Current number of bytes stored */ + // u_int offset; /* Offset to the first byte */ struct list_head dbuf_list; } dbuf; @@ -83,13 +83,13 @@ typedef struct dbufbuf { ** from users buffer. */ void dbuf_put(dbuf *, const char *, size_t); - /* Dynamic buffer header */ - /* Pointer to data to be stored */ - /* Number of bytes to store */ +/* Dynamic buffer header */ +/* Pointer to data to be stored */ +/* Number of bytes to store */ void dbuf_delete(dbuf *, size_t); - /* Dynamic buffer header */ - /* Number of bytes to delete */ +/* Dynamic buffer header */ +/* Number of bytes to delete */ /* ** DBufLength @@ -104,7 +104,7 @@ void dbuf_delete(dbuf *, size_t); ** Scratch the current content of the buffer. Release all ** allocated buffers and make it empty. */ -#define DBufClear(dyn) dbuf_delete((dyn),DBufLength(dyn)) +#define DBufClear(dyn) dbuf_delete((dyn), DBufLength(dyn)) extern int dbuf_getmsg(dbuf *, char *); extern int dbuf_get(dbuf *dyn, char **buf); diff --git a/include/dns.h b/include/dns.h index 7fbf8ec52..1bc8a2ab5 100644 --- a/include/dns.h +++ b/include/dns.h @@ -14,22 +14,22 @@ typedef struct DNSReq DNSReq; */ struct DNSReq { DNSReq *prev, *next; - char *name; /**< Name being resolved (only for DNSREQ_LINKCONF and DNSREQ_CONNECT) */ - char ipv6; /**< Resolving for ipv6 or ipv4? */ - DNSReqType type; /**< DNS Request type (DNSREQ_*) */ - Client *client; /**< Client the request is for, NULL if client died OR unavailable */ - ConfigItem_link *linkblock; /**< Linkblock */ + char *name; /**< Name being resolved (only for DNSREQ_LINKCONF and DNSREQ_CONNECT) */ + char ipv6; /**< Resolving for ipv6 or ipv4? */ + DNSReqType type; /**< DNS Request type (DNSREQ_*) */ + Client *client; /**< Client the request is for, NULL if client died OR unavailable */ + ConfigItem_link *linkblock; /**< Linkblock */ }; typedef struct DNSCache DNSCache; /** DNS Cache entry - used in src/dns.c */ struct DNSCache { - DNSCache *prev, *next; /**< Previous and next in linked list */ - DNSCache *hprev, *hnext; /**< Previous and next in hash list */ - char *name; /**< The hostname */ - char *ip; /**< The IP address */ - time_t expires; /**< When record expires */ + DNSCache *prev, *next; /**< Previous and next in linked list */ + DNSCache *hprev, *hnext; /**< Previous and next in hash list */ + char *name; /**< The hostname */ + char *ip; /**< The IP address */ + time_t expires; /**< When record expires */ }; typedef struct DNSStats DNSStats; @@ -41,11 +41,11 @@ struct DNSStats { }; /** Time to keep cache records. */ -#define DNS_CACHE_TTL 600 -#define DNS_NEGCACHE_TTL 60 +#define DNS_CACHE_TTL 600 +#define DNS_NEGCACHE_TTL 60 /** Size of the DNS cache hash table. */ -#define DNS_HASH_SIZE 4096 +#define DNS_HASH_SIZE 4096 /** Max # of entries we want in our cache. * This: @@ -58,7 +58,7 @@ struct DNSStats { * Note that in most situations there will be far * fewer items, as the TTL is rather short. */ -#define DNS_MAX_ENTRIES DNS_HASH_SIZE +#define DNS_MAX_ENTRIES DNS_HASH_SIZE extern ares_channel resolver_channel_client; extern ares_channel resolver_channel_https; @@ -69,4 +69,3 @@ extern void init_resolver(int); struct hostent *unrealdns_doclient(Client *cptr); extern void unreal_gethostbyname_api(const char *name, int family, const char *callbackname, void *arg); - diff --git a/include/dynconf.h b/include/dynconf.h index 2ec4bd483..efe44c14f 100644 --- a/include/dynconf.h +++ b/include/dynconf.h @@ -35,13 +35,18 @@ struct FloodSettings { typedef struct LogThrottleConfig LogThrottleConfig; struct LogThrottleConfig { LogThrottleConfig *prev, *next; - char *event_id; /**< the event_id this policy applies to */ - int threshold; /**< per-window cap */ - int period; /**< window length in seconds */ - int unlimited; /**< if set, never throttle */ + char *event_id; /**< the event_id this policy applies to */ + int threshold; /**< per-window cap */ + int period; /**< window length in seconds */ + int unlimited; /**< if set, never throttle */ }; -enum UHAllowed { UHALLOW_ALWAYS, UHALLOW_NOCHANS, UHALLOW_REJOIN, UHALLOW_NEVER }; +enum UHAllowed { + UHALLOW_ALWAYS, + UHALLOW_NOCHANS, + UHALLOW_REJOIN, + UHALLOW_NEVER +}; struct ChMode { long mode; @@ -54,35 +59,62 @@ typedef struct OperStat { char *flag; } OperStat; -typedef enum BroadcastChannelMessagesOption { BROADCAST_CHANNEL_MESSAGES_AUTO=1, BROADCAST_CHANNEL_MESSAGES_ALWAYS=2, BROADCAST_CHANNEL_MESSAGES_NEVER=3 } BroadcastChannelMessagesOption; +typedef enum BroadcastChannelMessagesOption { + BROADCAST_CHANNEL_MESSAGES_AUTO = 1, + BROADCAST_CHANNEL_MESSAGES_ALWAYS = 2, + BROADCAST_CHANNEL_MESSAGES_NEVER = 3 +} BroadcastChannelMessagesOption; -typedef enum AllowedChannelChars { ALLOWED_CHANNELCHARS_ANY=1, ALLOWED_CHANNELCHARS_ASCII=2, ALLOWED_CHANNELCHARS_UTF8=3 } AllowedChannelChars; +typedef enum AllowedChannelChars { + ALLOWED_CHANNELCHARS_ANY = 1, + ALLOWED_CHANNELCHARS_ASCII = 2, + ALLOWED_CHANNELCHARS_UTF8 = 3 +} AllowedChannelChars; -typedef enum BanTarget { BAN_TARGET_IP=1, BAN_TARGET_USERIP=2, BAN_TARGET_HOST=3, BAN_TARGET_USERHOST=4, BAN_TARGET_ACCOUNT=5, BAN_TARGET_CERTFP=6 } BanTarget; +typedef enum BanTarget { + BAN_TARGET_IP = 1, + BAN_TARGET_USERIP = 2, + BAN_TARGET_HOST = 3, + BAN_TARGET_USERHOST = 4, + BAN_TARGET_ACCOUNT = 5, + BAN_TARGET_CERTFP = 6 +} BanTarget; -typedef enum HideIdleTimePolicy { HIDE_IDLE_TIME_NEVER=1, HIDE_IDLE_TIME_ALWAYS=2, HIDE_IDLE_TIME_USERMODE=3, HIDE_IDLE_TIME_OPER_USERMODE=4 } HideIdleTimePolicy; +typedef enum HideIdleTimePolicy { + HIDE_IDLE_TIME_NEVER = 1, + HIDE_IDLE_TIME_ALWAYS = 2, + HIDE_IDLE_TIME_USERMODE = 3, + HIDE_IDLE_TIME_OPER_USERMODE = 4 +} HideIdleTimePolicy; -typedef enum LimitSVSCMDS { LIMIT_SVSCMDS_SERVERS=0, LIMIT_SVSCMDS_ULINES=1 } LimitSVSCMDS; +typedef enum LimitSVSCMDS { + LIMIT_SVSCMDS_SERVERS = 0, + LIMIT_SVSCMDS_ULINES = 1 +} LimitSVSCMDS; -typedef enum HideBanReasonOption { HIDE_BAN_REASON_NO=0, HIDE_BAN_REASON_YES=1, HIDE_BAN_REASON_AUTO=2 } HideBanReasonOption; +typedef enum HideBanReasonOption { + HIDE_BAN_REASON_NO = 0, + HIDE_BAN_REASON_YES = 1, + HIDE_BAN_REASON_AUTO = 2 +} HideBanReasonOption; /** The set { } block configuration */ typedef struct Configuration Configuration; struct Configuration { - unsigned show_opermotd:1; - unsigned hide_ulines:1; - unsigned flat_map:1; - unsigned ident_check:1; - unsigned fail_oper_warn:1; - unsigned show_connect_info:1; - unsigned no_connect_tls_info:1; - unsigned dont_resolve:1; - unsigned use_ban_version:1; - unsigned mkpasswd_for_everyone:1; + unsigned show_opermotd : 1; + unsigned hide_ulines : 1; + unsigned flat_map : 1; + unsigned ident_check : 1; + unsigned fail_oper_warn : 1; + unsigned show_connect_info : 1; + unsigned no_connect_tls_info : 1; + unsigned dont_resolve : 1; + unsigned use_ban_version : 1; + unsigned mkpasswd_for_everyone : 1; unsigned allow_insane_bans; - unsigned allow_part_if_shunned:1; - unsigned disable_cap:1; - unsigned check_target_nick_bans:1; + unsigned allow_part_if_shunned : 1; + unsigned disable_cap : 1; + unsigned check_target_nick_bans : 1; HideBanReasonOption hide_ban_reason; int hide_killed_by; char *link_bindip; @@ -100,9 +132,9 @@ struct Configuration { int maxdccallow; int anti_spam_quit_message_time; TLSOptions *tls_options; - TLSOptions *server_linking_tls_options; /**< set::server-linking::tls-options, NULL if not configured */ - int server_linking_mixed_certificates; /**< set::server-linking::mixed-certificates: suppress the s2s cert mismatch warning */ - int server_linking_allow_ca_certificate; /**< set::server-linking::allow-ca-certificate: suppress the "CA cert used for linking" advice */ + TLSOptions *server_linking_tls_options; /**< set::server-linking::tls-options, NULL if not configured */ + int server_linking_mixed_certificates; /**< set::server-linking::mixed-certificates: suppress the s2s cert mismatch warning */ + int server_linking_allow_ca_certificate; /**< set::server-linking::allow-ca-certificate: suppress the "CA cert used for linking" advice */ Policy plaintext_policy_user; MultiLine *plaintext_policy_user_message; Policy plaintext_policy_oper; @@ -185,7 +217,7 @@ struct Configuration { BroadcastChannelMessagesOption broadcast_channel_messages; AllowedChannelChars allowed_channelchars; HideIdleTimePolicy hide_idle_time; - unsigned inah:1; + unsigned inah : 1; char *network_name; char *network_name_005; char *default_server; @@ -218,160 +250,160 @@ extern MODVAR int ipv6_disabled; */ typedef struct BestPractices BestPractices; struct BestPractices { - int hashed_passwords; /**< Use hashed passwords */ - int hashed_passwords_hits; /**< - How many times advice has been given (like 'warnings' but it is advice) */ - int trusted_cert; /**< Uses a SSL cert issued by a CA */ - int trusted_cert_hits; /**< - How many times advice has been given (like 'warnings' but it is advice) */ - int trusted_cert_valid_hostname; /**< Uses a SSL cert issued by a CA that is valid for me::name */ - int trusted_cert_valid_hostname_hits; /**< - How many times advice has been given (like 'warnings' but it is advice) */ - int listen_tls_only; /**< listen { } blocks only with tls */ - int listen_nontls_port; /**< first non-tls port found */ - int listen_nontls_port_hits; /**< - How many times advice has been given (like 'warnings' but it is advice) */ + int hashed_passwords; /**< Use hashed passwords */ + int hashed_passwords_hits; /**< - How many times advice has been given (like 'warnings' but it is advice) */ + int trusted_cert; /**< Uses a SSL cert issued by a CA */ + int trusted_cert_hits; /**< - How many times advice has been given (like 'warnings' but it is advice) */ + int trusted_cert_valid_hostname; /**< Uses a SSL cert issued by a CA that is valid for me::name */ + int trusted_cert_valid_hostname_hits; /**< - How many times advice has been given (like 'warnings' but it is advice) */ + int listen_tls_only; /**< listen { } blocks only with tls */ + int listen_nontls_port; /**< first non-tls port found */ + int listen_nontls_port_hits; /**< - How many times advice has been given (like 'warnings' but it is advice) */ }; extern MODVAR BestPractices bestpractices; -#define KLINE_ADDRESS iConf.kline_address -#define GLINE_ADDRESS iConf.gline_address -#define OPER_MODES iConf.oper_modes -#define OPER_SNOMASK iConf.oper_snomask -#define SHOWOPERMOTD iConf.show_opermotd -#define HIDE_ULINES iConf.hide_ulines -#define FLAT_MAP iConf.flat_map -#define ALLOW_CHATOPS iConf.allow_chatops -#define PINGWARNING iConf.ping_warning -#define MAXDCCALLOW iConf.maxdccallow -#define DONT_RESOLVE iConf.dont_resolve -#define OPER_AUTO_JOIN_CHANS iConf.oper_auto_join_chans -#define LINK_BINDIP iConf.link_bindip -#define IDENT_CHECK iConf.ident_check -#define FAILOPER_WARN iConf.fail_oper_warn -#define SHOWCONNECTINFO iConf.show_connect_info -#define NOCONNECTTLSLINFO iConf.no_connect_tls_info -#define ALLOW_USER_STATS iConf.allow_user_stats -#define ANTI_SPAM_QUIT_MSG_TIME iConf.anti_spam_quit_message_time -#define NETWORK_NAME iConf.network_name -#define NETWORK_NAME_005 iConf.network_name_005 -#define DEFAULT_SERVER iConf.default_server -#define SERVICES_NAME iConf.services_name -#define CLOAK_PREFIX iConf.cloak_prefix -#define HELP_CHANNEL iConf.helpchan -#define STATS_SERVER iConf.stats_server -#define SASL_SERVER iConf.sasl_server -#define iNAH iConf.inah -#define PREFIX_QUIT iConf.prefix_quit -#define UHOST_ALLOWED iConf.userhost_allowed -#define RESTRICT_CHANNELMODES iConf.restrict_channelmodes -#define THROTTLING_PERIOD iConf.throttle_period -#define THROTTLING_COUNT iConf.throttle_count -#define USE_BAN_VERSION iConf.use_ban_version -#define MODES_ON_JOIN iConf.modes_on_join.extmodes -#define LEVEL_ON_JOIN iConf.level_on_join -#define IDENT_CONNECT_TIMEOUT iConf.ident_connect_timeout -#define IDENT_READ_TIMEOUT iConf.ident_read_timeout -#define MKPASSWD_FOR_EVERYONE iConf.mkpasswd_for_everyone -#define HIDE_BAN_REASON iConf.hide_ban_reason -#define ALLOW_INSANE_BANS iConf.allow_insane_bans -#define CHANCMDPFX iConf.channel_command_prefix -#define DEFAULT_BANTIME iConf.default_bantime -#define WHOLIMIT iConf.who_limit -#define ALLOW_PART_IF_SHUNNED iConf.allow_part_if_shunned -#define DISABLE_CAP iConf.disable_cap -#define DISABLE_IPV6 ipv6_disabled -#define BAN_VERSION_TKL_TIME iConf.ban_version_tkl_time -#define SILENCE_LIMIT (iConf.silence_limit ? iConf.silence_limit : 15) -#define SPAMFILTER_BAN_TIME iConf.spamfilter_ban_time -#define SPAMFILTER_BAN_REASON iConf.spamfilter_ban_reason -#define SPAMFILTER_VIRUSCHAN iConf.spamfilter_virus_help_channel -#define SPAMFILTER_VIRUSCHANDENY iConf.spamfilter_vchan_deny -#define SPAMFILTER_EXCEPT iConf.spamexcept_line -#define SPAMFILTER_DETECTSLOW_WARN iConf.spamfilter_detectslow_warn -#define SPAMFILTER_DETECTSLOW_FATAL iConf.spamfilter_detectslow_fatal -#define SPAMFILTER_STOP_ON_FIRST_MATCH iConf.spamfilter_stop_on_first_match -#define CHECK_TARGET_NICK_BANS iConf.check_target_nick_bans -#define MAXBANS iConf.maxbans -#define WATCH_AWAY_NOTIFICATION iConf.watch_away_notification -#define UHNAMES_ENABLED iConf.uhnames -#define UTF8ONLY iConf.utf8_only -#define NETWORK_ICON iConf.network_icon +#define KLINE_ADDRESS iConf.kline_address +#define GLINE_ADDRESS iConf.gline_address +#define OPER_MODES iConf.oper_modes +#define OPER_SNOMASK iConf.oper_snomask +#define SHOWOPERMOTD iConf.show_opermotd +#define HIDE_ULINES iConf.hide_ulines +#define FLAT_MAP iConf.flat_map +#define ALLOW_CHATOPS iConf.allow_chatops +#define PINGWARNING iConf.ping_warning +#define MAXDCCALLOW iConf.maxdccallow +#define DONT_RESOLVE iConf.dont_resolve +#define OPER_AUTO_JOIN_CHANS iConf.oper_auto_join_chans +#define LINK_BINDIP iConf.link_bindip +#define IDENT_CHECK iConf.ident_check +#define FAILOPER_WARN iConf.fail_oper_warn +#define SHOWCONNECTINFO iConf.show_connect_info +#define NOCONNECTTLSLINFO iConf.no_connect_tls_info +#define ALLOW_USER_STATS iConf.allow_user_stats +#define ANTI_SPAM_QUIT_MSG_TIME iConf.anti_spam_quit_message_time +#define NETWORK_NAME iConf.network_name +#define NETWORK_NAME_005 iConf.network_name_005 +#define DEFAULT_SERVER iConf.default_server +#define SERVICES_NAME iConf.services_name +#define CLOAK_PREFIX iConf.cloak_prefix +#define HELP_CHANNEL iConf.helpchan +#define STATS_SERVER iConf.stats_server +#define SASL_SERVER iConf.sasl_server +#define iNAH iConf.inah +#define PREFIX_QUIT iConf.prefix_quit +#define UHOST_ALLOWED iConf.userhost_allowed +#define RESTRICT_CHANNELMODES iConf.restrict_channelmodes +#define THROTTLING_PERIOD iConf.throttle_period +#define THROTTLING_COUNT iConf.throttle_count +#define USE_BAN_VERSION iConf.use_ban_version +#define MODES_ON_JOIN iConf.modes_on_join.extmodes +#define LEVEL_ON_JOIN iConf.level_on_join +#define IDENT_CONNECT_TIMEOUT iConf.ident_connect_timeout +#define IDENT_READ_TIMEOUT iConf.ident_read_timeout +#define MKPASSWD_FOR_EVERYONE iConf.mkpasswd_for_everyone +#define HIDE_BAN_REASON iConf.hide_ban_reason +#define ALLOW_INSANE_BANS iConf.allow_insane_bans +#define CHANCMDPFX iConf.channel_command_prefix +#define DEFAULT_BANTIME iConf.default_bantime +#define WHOLIMIT iConf.who_limit +#define ALLOW_PART_IF_SHUNNED iConf.allow_part_if_shunned +#define DISABLE_CAP iConf.disable_cap +#define DISABLE_IPV6 ipv6_disabled +#define BAN_VERSION_TKL_TIME iConf.ban_version_tkl_time +#define SILENCE_LIMIT (iConf.silence_limit ? iConf.silence_limit : 15) +#define SPAMFILTER_BAN_TIME iConf.spamfilter_ban_time +#define SPAMFILTER_BAN_REASON iConf.spamfilter_ban_reason +#define SPAMFILTER_VIRUSCHAN iConf.spamfilter_virus_help_channel +#define SPAMFILTER_VIRUSCHANDENY iConf.spamfilter_vchan_deny +#define SPAMFILTER_EXCEPT iConf.spamexcept_line +#define SPAMFILTER_DETECTSLOW_WARN iConf.spamfilter_detectslow_warn +#define SPAMFILTER_DETECTSLOW_FATAL iConf.spamfilter_detectslow_fatal +#define SPAMFILTER_STOP_ON_FIRST_MATCH iConf.spamfilter_stop_on_first_match +#define CHECK_TARGET_NICK_BANS iConf.check_target_nick_bans +#define MAXBANS iConf.maxbans +#define WATCH_AWAY_NOTIFICATION iConf.watch_away_notification +#define UHNAMES_ENABLED iConf.uhnames +#define UTF8ONLY iConf.utf8_only +#define NETWORK_ICON iConf.network_icon /** Used for testing the set { } block configuration. * It tests if a setting is present and is also used for duplicate checking. */ struct SetCheck { - unsigned has_show_opermotd:1; - unsigned has_hide_ulines:1; - unsigned has_flat_map:1; - unsigned has_allow_chatops:1; - unsigned has_ident_check:1; - unsigned has_fail_oper_warn:1; - unsigned has_show_connect_info:1; - unsigned has_dont_resolve:1; - unsigned has_mkpasswd_for_everyone:1; - unsigned has_allow_part_if_shunned:1; - unsigned has_tls_server_cipher_list :1; - unsigned has_tls_protocols :1; - unsigned has_dns_bind_ip:1; - unsigned has_link_bind_ip:1; - unsigned has_throttle_period:1; - unsigned has_throttle_connections:1; - unsigned has_kline_address:1; - unsigned has_gline_address:1; - unsigned has_modes_on_oper:1; - unsigned has_snomask_on_connect:1; - unsigned has_snomask_on_oper:1; - unsigned has_oper_auto_join:1; - unsigned has_check_target_nick_bans:1; - unsigned has_watch_away_notification:1; - unsigned has_uhnames:1; - unsigned has_allow_user_stats:1; - unsigned has_ping_warning:1; - unsigned has_maxdccallow:1; - unsigned has_anti_spam_quit_message_time:1; - unsigned has_allow_userhost_change:1; - unsigned has_allow_setident:1; - unsigned has_allow_setname:1; - unsigned has_restrict_channelmodes:1; - unsigned has_channel_command_prefix:1; - unsigned has_modes_on_join:1; - unsigned has_level_on_join:1; - unsigned has_ident_connect_timeout:1; - unsigned has_ident_read_timeout:1; - unsigned has_default_bantime:1; - unsigned has_who_limit:1; - unsigned has_maxbans:1; - unsigned has_silence_limit:1; - unsigned has_ban_version_tkl_time:1; - unsigned has_spamfilter_ban_time:1; - unsigned has_spamfilter_ban_reason:1; - unsigned has_spamfilter_virus_help_channel:1; - unsigned has_spamfilter_virus_help_channel_deny:1; - unsigned has_spamfilter_except:1; - unsigned has_network_name:1; - unsigned has_network_icon:1; - unsigned has_default_server:1; - unsigned has_services_server:1; - unsigned has_sasl_server:1; - unsigned has_hiddenhost_prefix:1; - unsigned has_prefix_quit:1; - unsigned has_help_channel:1; - unsigned has_stats_server:1; - unsigned has_cloak_keys:1; - unsigned has_options_hide_ulines:1; - unsigned has_options_flat_map:1; - unsigned has_options_show_opermotd:1; - unsigned has_options_identd_check:1; - unsigned has_options_fail_oper_warn:1; - unsigned has_options_dont_resolve:1; - unsigned has_options_show_connect_info:1; - unsigned has_options_no_connect_tls_info:1; - unsigned has_options_mkpasswd_for_everyone:1; - unsigned has_options_allow_insane_bans:1; - unsigned has_options_allow_part_if_shunned:1; - unsigned has_options_disable_cap:1; - unsigned has_options_disable_ipv6:1; - unsigned has_ping_cookie:1; - unsigned has_min_nick_length:1; - unsigned has_nick_length:1; - unsigned has_hide_ban_reason:1; - unsigned has_hide_killed_by:1; + unsigned has_show_opermotd : 1; + unsigned has_hide_ulines : 1; + unsigned has_flat_map : 1; + unsigned has_allow_chatops : 1; + unsigned has_ident_check : 1; + unsigned has_fail_oper_warn : 1; + unsigned has_show_connect_info : 1; + unsigned has_dont_resolve : 1; + unsigned has_mkpasswd_for_everyone : 1; + unsigned has_allow_part_if_shunned : 1; + unsigned has_tls_server_cipher_list : 1; + unsigned has_tls_protocols : 1; + unsigned has_dns_bind_ip : 1; + unsigned has_link_bind_ip : 1; + unsigned has_throttle_period : 1; + unsigned has_throttle_connections : 1; + unsigned has_kline_address : 1; + unsigned has_gline_address : 1; + unsigned has_modes_on_oper : 1; + unsigned has_snomask_on_connect : 1; + unsigned has_snomask_on_oper : 1; + unsigned has_oper_auto_join : 1; + unsigned has_check_target_nick_bans : 1; + unsigned has_watch_away_notification : 1; + unsigned has_uhnames : 1; + unsigned has_allow_user_stats : 1; + unsigned has_ping_warning : 1; + unsigned has_maxdccallow : 1; + unsigned has_anti_spam_quit_message_time : 1; + unsigned has_allow_userhost_change : 1; + unsigned has_allow_setident : 1; + unsigned has_allow_setname : 1; + unsigned has_restrict_channelmodes : 1; + unsigned has_channel_command_prefix : 1; + unsigned has_modes_on_join : 1; + unsigned has_level_on_join : 1; + unsigned has_ident_connect_timeout : 1; + unsigned has_ident_read_timeout : 1; + unsigned has_default_bantime : 1; + unsigned has_who_limit : 1; + unsigned has_maxbans : 1; + unsigned has_silence_limit : 1; + unsigned has_ban_version_tkl_time : 1; + unsigned has_spamfilter_ban_time : 1; + unsigned has_spamfilter_ban_reason : 1; + unsigned has_spamfilter_virus_help_channel : 1; + unsigned has_spamfilter_virus_help_channel_deny : 1; + unsigned has_spamfilter_except : 1; + unsigned has_network_name : 1; + unsigned has_network_icon : 1; + unsigned has_default_server : 1; + unsigned has_services_server : 1; + unsigned has_sasl_server : 1; + unsigned has_hiddenhost_prefix : 1; + unsigned has_prefix_quit : 1; + unsigned has_help_channel : 1; + unsigned has_stats_server : 1; + unsigned has_cloak_keys : 1; + unsigned has_options_hide_ulines : 1; + unsigned has_options_flat_map : 1; + unsigned has_options_show_opermotd : 1; + unsigned has_options_identd_check : 1; + unsigned has_options_fail_oper_warn : 1; + unsigned has_options_dont_resolve : 1; + unsigned has_options_show_connect_info : 1; + unsigned has_options_no_connect_tls_info : 1; + unsigned has_options_mkpasswd_for_everyone : 1; + unsigned has_options_allow_insane_bans : 1; + unsigned has_options_allow_part_if_shunned : 1; + unsigned has_options_disable_cap : 1; + unsigned has_options_disable_ipv6 : 1; + unsigned has_ping_cookie : 1; + unsigned has_min_nick_length : 1; + unsigned has_nick_length : 1; + unsigned has_hide_ban_reason : 1; + unsigned has_hide_killed_by : 1; }; diff --git a/include/fdlist.h b/include/fdlist.h index d1084a3f4..6b68ef2eb 100644 --- a/include/fdlist.h +++ b/include/fdlist.h @@ -3,11 +3,15 @@ /* $Id$ */ -#define FD_DESC_SZ (100) +#define FD_DESC_SZ (100) typedef void (*IOCallbackFunc)(int fd, int revents, void *data); -typedef enum FDCloseMethod { FDCLOSE_SOCKET=0, FDCLOSE_FILE=1, FDCLOSE_NONE=3 } FDCloseMethod; +typedef enum FDCloseMethod { + FDCLOSE_SOCKET = 0, + FDCLOSE_FILE = 1, + FDCLOSE_NONE = 3 +} FDCloseMethod; typedef struct fd_entry { int fd; @@ -31,10 +35,12 @@ extern int fd_accept(int sockfd); extern void fd_desc(int fd, const char *desc); extern int fd_fileopen(const char *path, unsigned int flags); -#define FD_SELECT_READ 0x1 -#define FD_SELECT_WRITE 0x2 +#define FD_SELECT_READ 0x1 +#define FD_SELECT_WRITE 0x2 -#define fd_setselect(fd, flags, iocb, data) do { \ +#define fd_setselect(fd, flags, iocb, data) \ + do \ + { \ if (fd < 0) \ { \ unreal_log(ULOG_ERROR, "io", "BUG_FD_SETSELECT_NEGATIVE_FD", NULL, \ @@ -42,13 +48,14 @@ extern int fd_fileopen(const char *path, unsigned int flags); log_data_string("file", __FILE__), \ log_data_integer("line", __LINE__), \ log_data_integer("fd", fd)); \ - } else { \ + } else \ + { \ fd_setselect_real(fd, flags, iocb, data); \ } \ - } while(0) + } while (0) extern void fd_setselect_real(int fd, int flags, IOCallbackFunc iocb, void *data); -extern void fd_select(int delay); /* backend-specific */ -extern void fd_refresh(int fd); /* backend-specific */ -extern void fd_fork(); /* backend-specific */ +extern void fd_select(int delay); /* backend-specific */ +extern void fd_refresh(int fd); /* backend-specific */ +extern void fd_fork(); /* backend-specific */ #endif diff --git a/include/h.h b/include/h.h index 26934f4e8..fbc1f48bd 100644 --- a/include/h.h +++ b/include/h.h @@ -69,7 +69,7 @@ extern MODVAR int bootopt; extern MODVAR time_t timeofday; extern MODVAR struct timeval timeofday_tv; extern MODVAR char cmodestring[512]; -extern MODVAR char umodestring[UMODETABLESZ+1]; +extern MODVAR char umodestring[UMODETABLESZ + 1]; /* newconf */ #define get_sendq(x) ((x)->local->class ? (x)->local->class->sendq : DEFAULT_SENDQ) /* get_recvq is only called in send.c for local connections */ @@ -89,33 +89,33 @@ extern void preprocessor_replace_defines(char **item, ConfigEntry *ce); /* * Configuration linked lists */ -extern MODVAR ConfigItem_me *conf_me; -extern MODVAR ConfigItem_files *conf_files; -extern MODVAR ConfigItem_class *conf_class; -extern MODVAR ConfigItem_class *default_class; -extern MODVAR ConfigItem_admin *conf_admin; -extern MODVAR ConfigItem_admin *conf_admin_tail; -extern MODVAR ConfigItem_drpass *conf_drpass; -extern MODVAR ConfigItem_ulines *conf_ulines; -extern MODVAR ConfigItem_tld *conf_tld; -extern MODVAR ConfigItem_oper *conf_oper; -extern MODVAR ConfigItem_listen *conf_listen; -extern MODVAR ConfigItem_allow *conf_allow; -extern MODVAR ConfigItem_link *conf_link; -extern MODVAR ConfigItem_sni *conf_sni; -extern MODVAR ConfigItem_ban *conf_ban; -extern MODVAR ConfigItem_deny_channel *conf_deny_channel; +extern MODVAR ConfigItem_me *conf_me; +extern MODVAR ConfigItem_files *conf_files; +extern MODVAR ConfigItem_class *conf_class; +extern MODVAR ConfigItem_class *default_class; +extern MODVAR ConfigItem_admin *conf_admin; +extern MODVAR ConfigItem_admin *conf_admin_tail; +extern MODVAR ConfigItem_drpass *conf_drpass; +extern MODVAR ConfigItem_ulines *conf_ulines; +extern MODVAR ConfigItem_tld *conf_tld; +extern MODVAR ConfigItem_oper *conf_oper; +extern MODVAR ConfigItem_listen *conf_listen; +extern MODVAR ConfigItem_allow *conf_allow; +extern MODVAR ConfigItem_link *conf_link; +extern MODVAR ConfigItem_sni *conf_sni; +extern MODVAR ConfigItem_ban *conf_ban; +extern MODVAR ConfigItem_deny_channel *conf_deny_channel; extern MODVAR ConfigItem_allow_channel *conf_allow_channel; -extern MODVAR ConfigItem_deny_version *conf_deny_version; -extern MODVAR ConfigItem_alias *conf_alias; -extern MODVAR ConfigItem_help *conf_help; -extern MODVAR ConfigItem_offchans *conf_offchans; -extern MODVAR ConfigItem_proxy *conf_proxy; -extern void completed_connection(int, int, void *); +extern MODVAR ConfigItem_deny_version *conf_deny_version; +extern MODVAR ConfigItem_alias *conf_alias; +extern MODVAR ConfigItem_help *conf_help; +extern MODVAR ConfigItem_offchans *conf_offchans; +extern MODVAR ConfigItem_proxy *conf_proxy; +extern void completed_connection(int, int, void *); extern void clear_unknown(); extern EVENT(e_unload_module_delayed); -extern void module_loadall(void); +extern void module_loadall(void); extern long set_usermode(const char *umode); extern const char *get_usermode_string(Client *acptr); extern const char *get_usermode_string_r(Client *client, char *buf, size_t buflen); @@ -123,8 +123,8 @@ extern const char *get_usermode_string_raw(long umodes); extern const char *get_usermode_string_raw_r(long umodes, char *buf, size_t buflen); extern ConfigFile *config_parse(const char *filename, char *confdata); extern ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsigned int line_offset); -extern void config_error(FORMAT_STRING(const char *format), ...) __attribute__((format(printf,1,2))); -extern void config_warn(FORMAT_STRING(const char *format), ...) __attribute__((format(printf,1,2))); +extern void config_error(FORMAT_STRING(const char *format), ...) __attribute__((format(printf, 1, 2))); +extern void config_warn(FORMAT_STRING(const char *format), ...) __attribute__((format(printf, 1, 2))); extern void config_error_missing(const char *filename, int line, const char *entry); extern void config_error_unknown(const char *filename, int line, const char *block, const char *entry); extern void config_error_unknownflag(const char *filename, int line, const char *block, const char *entry); @@ -141,19 +141,19 @@ extern void config_entry_free_all(ConfigEntry *ce); extern ConfigFile *config_load(const char *filename, const char *displayname); extern void config_free(ConfigFile *cfptr); extern void ipport_seperate(const char *string, char **ip, char **port); -extern ConfigItem_class *find_class(const char *name); -extern ConfigItem_oper *find_oper(const char *name); -extern ConfigItem_operclass *find_operclass(const char *name); +extern ConfigItem_class *find_class(const char *name); +extern ConfigItem_oper *find_oper(const char *name); +extern ConfigItem_operclass *find_operclass(const char *name); extern ConfigItem_listen *find_listen(const char *ipmask, int port, SocketType socket_type); extern ConfigItem_sni *find_sni(const char *name); -extern ConfigItem_ulines *find_uline(const char *host); -extern ConfigItem_tld *find_tld(Client *cptr); -extern ConfigItem_link *find_link(const char *servername); -extern ConfigItem_ban *find_ban(Client *, const char *host, short type); -extern ConfigItem_ban *find_banEx(Client *,const char *host, short type, short type2); +extern ConfigItem_ulines *find_uline(const char *host); +extern ConfigItem_tld *find_tld(Client *cptr); +extern ConfigItem_link *find_link(const char *servername); +extern ConfigItem_ban *find_ban(Client *, const char *host, short type); +extern ConfigItem_ban *find_banEx(Client *, const char *host, short type, short type2); extern ConfigItem_deny_channel *find_channel_allowed(Client *cptr, const char *name); -extern ConfigItem_alias *find_alias(const char *name); -extern ConfigItem_help *find_Help(const char *command); +extern ConfigItem_alias *find_alias(const char *name); +extern ConfigItem_help *find_Help(const char *command); extern OperPermission ValidatePermissionsForPath(const char *path, Client *client, Client *victim, Channel *channel, const void *extra); extern void OperClassValidatorDel(OperClassValidator *validator); @@ -164,7 +164,7 @@ extern void OperClass_freePath(OperClassACLPath *path); extern OperClassACL *_conf_parseACL(const char *name, ConfigEntry *ce); extern void free_operclass_struct(OperClass *o); -extern ConfigItem_ban *find_ban_ip(Client *client); +extern ConfigItem_ban *find_ban_ip(Client *client); extern void add_ListItem(ListStruct *, ListStruct **); extern void append_ListItem(ListStruct *item, ListStruct **list); extern void add_ListItemPrio(ListStructPrio *, ListStructPrio **, int); @@ -172,13 +172,13 @@ extern void del_ListItem(ListStruct *, ListStruct **); extern MODVAR LoopStruct loop; extern int del_banid(Channel *channel, const char *banid); extern int del_exbanid(Channel *channel, const char *banid); -#define REPORT_DO_DNS "NOTICE * :*** Looking up your hostname...\r\n" -#define REPORT_FIN_DNS "NOTICE * :*** Found your hostname\r\n" +#define REPORT_DO_DNS "NOTICE * :*** Looking up your hostname...\r\n" +#define REPORT_FIN_DNS "NOTICE * :*** Found your hostname\r\n" #define REPORT_FIN_DNSC "NOTICE * :*** Found your hostname (cached)\r\n" #define REPORT_FAIL_DNS "NOTICE * :*** Couldn't resolve your hostname; using your IP address instead\r\n" -#define REPORT_DO_ID "NOTICE * :*** Checking ident...\r\n" -#define REPORT_FIN_ID "NOTICE * :*** Received identd response\r\n" -#define REPORT_FAIL_ID "NOTICE * :*** No ident response; username prefixed with ~\r\n" +#define REPORT_DO_ID "NOTICE * :*** Checking ident...\r\n" +#define REPORT_FIN_ID "NOTICE * :*** Received identd response\r\n" +#define REPORT_FAIL_ID "NOTICE * :*** No ident response; username prefixed with ~\r\n" extern MODVAR int R_do_dns, R_fin_dns, R_fin_dnsc, R_fail_dns, R_do_id, R_fin_id, R_fail_id; extern MODVAR struct list_head client_list; extern MODVAR struct list_head lclient_list; @@ -259,7 +259,7 @@ extern MODVAR int debuglevel; #else extern int debuglevel, errno, h_errno; #endif -extern MODVAR int OpenFiles; /* number of files currently open */ +extern MODVAR int OpenFiles; /* number of files currently open */ extern MODVAR int debuglevel, portnum, debugtty, maxusersperchannel; extern MODVAR int readcalls, udpfd, resfd; extern Client *add_connection(ConfigItem_listen *, int); @@ -284,31 +284,31 @@ extern void set_socket_buffers(int fd, int rcvbuf, int sndbuf); extern int send_queued(Client *); extern void send_queued_cb(int fd, int revents, void *data); extern void sendto_serv_butone_nickcmd(Client *one, MessageTag *mtags, Client *client, const char *umodes); -extern void sendto_message_one(Client *to, Client *from, const char *sender, const char *cmd, const char *nick, const char *msg); +extern void sendto_message_one(Client *to, Client *from, const char *sender, const char *cmd, const char *nick, const char *msg); extern LineCache *linecache_init(void); extern void linecache_free(LineCache *cache); extern void sendto_prefix_one_cached(LineCache *cache, int line_opts, Client *to, Client *from, MessageTag *mtags, - FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,6,7))); + FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 6, 7))); extern void sendto_channel(Channel *channel, Client *from, Client *skip, char *member_modes, long clicap, int sendflags, MessageTag *mtags, - FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,8,9))); + FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 8, 9))); extern void sendto_local_common_channels(Client *user, Client *skip, long clicap, MessageTag *mtags, - FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,5,6))); + FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 5, 6))); extern void quit_sendto_local_common_channels(Client *user, MessageTag *mtags, const char *reason); -extern void sendto_match_servs(Channel *, Client *, FORMAT_STRING(const char *), ...) __attribute__((format(printf,3,4))); +extern void sendto_match_servs(Channel *, Client *, FORMAT_STRING(const char *), ...) __attribute__((format(printf, 3, 4))); extern void sendto_match_butone(Client *, Client *, const char *, int, MessageTag *, - FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,6,7))); -extern void sendto_all_butone(Client *, Client *, FORMAT_STRING(const char *), ...) __attribute__((format(printf,3,4))); -extern void sendto_ops(FORMAT_STRING(const char *), ...) __attribute__((format(printf,1,2))); -extern void sendto_prefix_one(Client *, Client *, MessageTag *, FORMAT_STRING(const char *), ...) __attribute__((format(printf,4,5))); + FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 6, 7))); +extern void sendto_all_butone(Client *, Client *, FORMAT_STRING(const char *), ...) __attribute__((format(printf, 3, 4))); +extern void sendto_ops(FORMAT_STRING(const char *), ...) __attribute__((format(printf, 1, 2))); +extern void sendto_prefix_one(Client *, Client *, MessageTag *, FORMAT_STRING(const char *), ...) __attribute__((format(printf, 4, 5))); extern void vsendto_prefix_one(Client *to, Client *from, MessageTag *mtags, const char *pattern, va_list vl); -extern void sendto_opers(FORMAT_STRING(const char *), ...) __attribute__((format(printf,1,2))); -extern void sendto_umode(int, FORMAT_STRING(const char *), ...) __attribute__((format(printf,2,3))); -extern void sendto_umode_global(int, FORMAT_STRING(const char *), ...) __attribute__((format(printf,2,3))); -extern void sendnotice(Client *to, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,2,3))); +extern void sendto_opers(FORMAT_STRING(const char *), ...) __attribute__((format(printf, 1, 2))); +extern void sendto_umode(int, FORMAT_STRING(const char *), ...) __attribute__((format(printf, 2, 3))); +extern void sendto_umode_global(int, FORMAT_STRING(const char *), ...) __attribute__((format(printf, 2, 3))); +extern void sendnotice(Client *to, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 2, 3))); /** Send numeric message to a client. * @param to The recipient * @param numeric The numeric, one of RPL_* or ERR_*, see include/numeric.h @@ -327,7 +327,7 @@ extern void sendnotice(Client *to, FORMAT_STRING(const char *pattern), ...) __at * @endcode * @ingroup SendFunctions */ -#define sendnumeric(to, numeric, ...) sendtaggednumericfmt(to, NULL, numeric, STR_ ## numeric, ##__VA_ARGS__) +#define sendnumeric(to, numeric, ...) sendtaggednumericfmt(to, NULL, numeric, STR_##numeric, ##__VA_ARGS__) /** Send numeric message to a client - format to user specific needs. * This will ignore the numeric definition of src/numeric.c and always send ":me.name numeric clientname " @@ -350,11 +350,11 @@ extern void sendnotice(Client *to, FORMAT_STRING(const char *pattern), ...) __at * @param ... Format string parameters. * @note Don't forget to add a colon if you need it (eg `:%%s`), this is a common mistake. */ -#define sendtaggednumeric(to, mtags, numeric, ...) sendtaggednumericfmt(to, mtags, numeric, STR_ ## numeric, ##__VA_ARGS__) +#define sendtaggednumeric(to, mtags, numeric, ...) sendtaggednumericfmt(to, mtags, numeric, STR_##numeric, ##__VA_ARGS__) -extern void sendtaggednumericfmt(Client *to, MessageTag *mtags, int numeric, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,4,5))); +extern void sendtaggednumericfmt(Client *to, MessageTag *mtags, int numeric, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 4, 5))); -extern void sendtxtnumeric(Client *to, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,2,3))); +extern void sendtxtnumeric(Client *to, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 2, 3))); /** Build numeric message so it is ready to be sent to a client - rarely used, normally you use sendnumeric() instead. * This function is normally only used in eg CAN_KICK and CAN_SET_TOPIC, where * you need to set an 'errbuf' with a full IRC protocol line to reject the request @@ -367,8 +367,8 @@ extern void sendtxtnumeric(Client *to, FORMAT_STRING(const char *pattern), ...) * @note Be sure to provide the correct number and type of parameters that belong to the numeric. Check include/numeric.h when in doubt! * @ingroup SendFunctions */ -#define buildnumeric(buf, buflen, to, numeric, ...) buildnumericfmt(buf, buflen, to, numeric, STR_ ## numeric, ##__VA_ARGS__) -extern void buildnumericfmt(char *buf, size_t buflen, Client *to, int numeric, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,5,6))); +#define buildnumeric(buf, buflen, to, numeric, ...) buildnumericfmt(buf, buflen, to, numeric, STR_##numeric, ##__VA_ARGS__) +extern void buildnumericfmt(char *buf, size_t buflen, Client *to, int numeric, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 5, 6))); extern void sendto_server(Client *one, unsigned long caps, unsigned long nocaps, MessageTag *mtags, FORMAT_STRING(const char *format), ...) __attribute__((format(printf, 5, 6))); extern void send_raw_direct(Client *user, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 2, 3))); extern MODVAR int writecalls, writeb[]; @@ -402,7 +402,7 @@ extern int hunt_server(Client *, MessageTag *, const char *, int, int, const cha extern int cmd_server_estab(Client *); extern void umode_init(void); #define UMODE_GLOBAL 1 -#define UMODE_LOCAL 0 +#define UMODE_LOCAL 0 extern int umode_allow_all(Client *client, int what); extern int umode_allow_unset(Client *client, int what); extern int umode_allow_opers(Client *client, int what); @@ -440,8 +440,8 @@ extern time_t expire_cache(time_t); extern void del_queries(const char *); /* Hash stuff */ -#define NICK_HASH_TABLE_SIZE 32768 -#define CHAN_HASH_TABLE_SIZE 32768 +#define NICK_HASH_TABLE_SIZE 32768 +#define CHAN_HASH_TABLE_SIZE 32768 #define WHOWAS_HASH_TABLE_SIZE 32768 extern uint64_t siphash(const char *in, const char *k); extern uint64_t siphash_raw(const char *in, size_t len, const char *k); @@ -471,16 +471,16 @@ extern Client *hash_find_server(const char *, Client *); /* Mode externs */ -extern MODVAR long UMODE_INVISIBLE; /* makes user invisible */ -extern MODVAR long UMODE_OPER; /* Operator */ -extern MODVAR long UMODE_REGNICK; /* Nick set by services as registered */ -extern MODVAR long UMODE_SERVNOTICE;/* server notices such as kill */ -extern MODVAR long UMODE_HIDE; /* Hide from Nukes */ -extern MODVAR long UMODE_SECURE; /* User is a secure connect */ -extern MODVAR long UMODE_DEAF; /* Deaf */ -extern MODVAR long UMODE_HIDEOPER; /* Hide oper mode */ -extern MODVAR long UMODE_SETHOST; /* used sethost */ -extern MODVAR long UMODE_HIDLE; /* hides oper idle times */ +extern MODVAR long UMODE_INVISIBLE; /* makes user invisible */ +extern MODVAR long UMODE_OPER; /* Operator */ +extern MODVAR long UMODE_REGNICK; /* Nick set by services as registered */ +extern MODVAR long UMODE_SERVNOTICE; /* server notices such as kill */ +extern MODVAR long UMODE_HIDE; /* Hide from Nukes */ +extern MODVAR long UMODE_SECURE; /* User is a secure connect */ +extern MODVAR long UMODE_DEAF; /* Deaf */ +extern MODVAR long UMODE_HIDEOPER; /* Hide oper mode */ +extern MODVAR long UMODE_SETHOST; /* used sethost */ +extern MODVAR long UMODE_HIDLE; /* hides oper idle times */ extern MODVAR long AllUmodes, SendUmodes; extern MODVAR long SNO_KILLS; @@ -518,7 +518,7 @@ extern char *strldup(const char *src, size_t n); extern void dopacket(Client *, char *, int); -extern void debug(int, FORMAT_STRING(const char *), ...) __attribute__((format(printf,2,3))); +extern void debug(int, FORMAT_STRING(const char *), ...) __attribute__((format(printf, 2, 3))); #if defined(DEBUGMODE) extern void send_usage(Client *, const char *); extern void count_memory(Client *, const char *); @@ -551,14 +551,14 @@ extern int b64_decode(char const *src, unsigned char *target, size_t targsize); extern AuthenticationType Auth_FindType(const char *hash, const char *type); extern void AuthBlockToAuthConfig(ConfigEntry *ce, AuthConfig **list); -extern void Auth_FreeAuthConfig(AuthConfig *as); -extern int Auth_Check(Client *cptr, AuthConfig *as, const char *para); -extern const char *Auth_Hash(AuthenticationType type, const char *text); -extern int Auth_CheckError(ConfigEntry *ce, int warn_on_plaintext); -extern int Auth_AutoDetectHashType(const char *hash); +extern void Auth_FreeAuthConfig(AuthConfig *as); +extern int Auth_Check(Client *cptr, AuthConfig *as, const char *para); +extern const char *Auth_Hash(AuthenticationType type, const char *text); +extern int Auth_CheckError(ConfigEntry *ce, int warn_on_plaintext); +extern int Auth_AutoDetectHashType(const char *hash); extern void make_cloakedhost(Client *client, const char *curr, char *buf, size_t buflen); -extern int channel_canjoin(Client *client, const char *name); +extern int channel_canjoin(Client *client, const char *name); extern char *collapse(char *pattern); extern void dcc_sync(Client *client); extern void request_rehash(Client *client); @@ -568,10 +568,10 @@ extern int match_simple(const char *mask, const char *name); extern int match_esc(const char *mask, const char *name); extern int add_listener(ConfigItem_listen *conf); extern void link_cleanup(ConfigItem_link *link_ptr); -extern void listen_cleanup(); -extern int numeric_collides(long numeric); -extern void flag_add(char ch); -extern void flag_del(char ch); +extern void listen_cleanup(); +extern int numeric_collides(long numeric); +extern void flag_add(char ch); +extern void flag_del(char ch); extern void init_dynconf(void); extern int config_read_start(void); extern int is_config_read_finished(void); @@ -596,7 +596,13 @@ extern void *safe_alloc(size_t size); /** Free previously allocate memory pointer. * This also sets the pointer to NULL, since that would otherwise be common to forget. */ -#define safe_free(x) do { if (x) free(x); x = NULL; } while(0) +#define safe_free(x) \ + do \ + { \ + if (x) \ + free(x); \ + x = NULL; \ + } while (0) /** Free previously allocated memory pointer. * Raw version which does not touch the pointer itself. You most likely don't * need this, as it's only used in 1 place in UnrealIRCd. @@ -607,7 +613,16 @@ extern void *safe_alloc(size_t size); * @param dst The current pointer and the pointer where a new copy of the string will be stored. * @param str The string you want to copy */ -#define safe_strdup(dst,str) do { if (dst) free(dst); if ((str) == NULL) dst = NULL; else dst = our_strdup(str); } while(0) +#define safe_strdup(dst, str) \ + do \ + { \ + if (dst) \ + free(dst); \ + if ((str) == NULL) \ + dst = NULL; \ + else \ + dst = our_strdup(str); \ + } while (0) /** Return a copy of the string. Do not free any existing memory. * @param str The string to duplicate @@ -628,7 +643,16 @@ extern void *safe_alloc(size_t size); * @param str The string you want to copy * @param sz Length limit including the NUL byte, usually sizeof(dst) */ -#define safe_strldup(dst,str,sz) do { if (dst) free(dst); if (!str) dst = NULL; else dst = our_strldup(str,sz); } while(0) +#define safe_strldup(dst, str, sz) \ + do \ + { \ + if (dst) \ + free(dst); \ + if (!str) \ + dst = NULL; \ + else \ + dst = our_strldup(str, sz); \ + } while (0) /** Return a duplicate of the specified string with a length limit. Do not free any existing memory. * @param str The string you want to copy @@ -653,7 +677,13 @@ extern void *safe_alloc_sensitive(size_t size); * It also sets the pointer to NULL, since that would otherwise be common to forget. * @note If you call this function on normally allocated memory (non-sensitive) then we will crash. */ -#define safe_free_sensitive(x) do { if (x) sodium_free(x); x = NULL; } while(0) +#define safe_free_sensitive(x) \ + do \ + { \ + if (x) \ + sodium_free(x); \ + x = NULL; \ + } while (0) /** Free previous memory (if any) and then save a duplicate of the specified string - * This is the 'sensitive' version which should only be used for HIGHLY sensitive data, @@ -661,12 +691,26 @@ extern void *safe_alloc_sensitive(size_t size); * @param dst The current pointer and the pointer where a new copy of the string will be stored. * @param str The string you want to copy */ -#define safe_strdup_sensitive(dst,str) do { if (dst) sodium_free(dst); if (!(str)) dst = NULL; else dst = our_strdup_sensitive(str); } while(0) +#define safe_strdup_sensitive(dst, str) \ + do \ + { \ + if (dst) \ + sodium_free(dst); \ + if (!(str)) \ + dst = NULL; \ + else \ + dst = our_strdup_sensitive(str); \ + } while (0) /** Safely destroy a string in memory (but do not free!) */ #define destroy_string(str) sodium_memzero(str, strlen(str)) -#define safe_json_decref(result) do { json_decref(result); result = NULL; } while(0) +#define safe_json_decref(result) \ + do \ + { \ + json_decref(result); \ + result = NULL; \ + } while (0) /** @} */ extern char *our_strdup(const char *str); @@ -674,7 +718,7 @@ extern char *our_strldup(const char *str, size_t max); extern char *our_strdup_sensitive(const char *str); extern long config_checkval(const char *value, unsigned short flags); -extern void config_status(FORMAT_STRING(const char *format), ...) __attribute__((format(printf,1,2))); +extern void config_status(FORMAT_STRING(const char *format), ...) __attribute__((format(printf, 1, 2))); extern void init_random(); extern u_char getrandom8(); extern uint16_t getrandom16(); @@ -682,9 +726,21 @@ extern uint32_t getrandom32(); extern void gen_random_alnum(char *buf, int numbytes); /* Check config entry for empty/missing parameter */ -#define CheckNull(x) if ((!(x)->value) || (!(*((x)->value)))) { config_error("%s:%i: missing parameter", (x)->file->filename, (x)->line_number); errors++; continue; } +#define CheckNull(x) \ + if ((!(x)->value) || (!(*((x)->value)))) \ + { \ + config_error("%s:%i: missing parameter", (x)->file->filename, (x)->line_number); \ + errors++; \ + continue; \ + } /* as above, but accepting empty string */ -#define CheckNullAllowEmpty(x) if ((!(x)->value)) { config_error("%s:%i: missing parameter", (x)->file->filename, (x)->line_number); errors++; continue; } +#define CheckNullAllowEmpty(x) \ + if ((!(x)->value)) \ + { \ + config_error("%s:%i: missing parameter", (x)->file->filename, (x)->line_number); \ + errors++; \ + continue; \ + } extern MODVAR char extchmstr[4][64]; @@ -740,8 +796,18 @@ extern void parse_ban_action_config(ConfigEntry *ce, BanAction **store_action); extern int test_ban_action_config(ConfigEntry *ce); extern void free_single_ban_action(BanAction *action); extern void free_all_ban_actions(BanAction *actions); -#define safe_free_all_ban_actions(x) do { free_all_ban_actions(x); x = NULL; } while(0) -#define safe_free_single_ban_action(x) do { free_single_ban_action(x); x = NULL; } while(0) +#define safe_free_all_ban_actions(x) \ + do \ + { \ + free_all_ban_actions(x); \ + x = NULL; \ + } while (0) +#define safe_free_single_ban_action(x) \ + do \ + { \ + free_single_ban_action(x); \ + x = NULL; \ + } while (0) BanAction *duplicate_ban_actions(BanAction *actions); extern int highest_ban_action(BanAction *action); extern BanActionValue banact_stringtoval(const char *s); @@ -765,7 +831,7 @@ extern void remove_oper_modes(Client *client); extern char *spamfilter_inttostring_long(int v); extern int is_invited(Client *client, Channel *channel); extern void channel_modes(Client *client, char *mbuf, char *pbuf, size_t mbuf_size, size_t pbuf_size, Channel *channel, int hide_local_modes); -extern int op_can_override(const char *acl, Client *client,Channel *channel,void* extra); +extern int op_can_override(const char *acl, Client *client, Channel *channel, void *extra); extern Client *find_chasing(Client *client, const char *user, int *chasing); extern MODVAR long opermode; extern MODVAR long sajoinmode; @@ -810,7 +876,7 @@ extern MODVAR void (*join_channel)(Channel *channel, Client *client, MessageTag extern MODVAR int (*can_join)(Client *client, Channel *channel, const char *key, char **errmsg); extern MODVAR void (*do_mode)(Channel *channel, Client *client, MessageTag *mtags, int parc, const char *parv[], time_t sendts, int samode); extern MODVAR MultiLineMode *(*set_mode)(Channel *channel, Client *cptr, int parc, const char *parv[], u_int *pcount, - char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]); + char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]); extern MODVAR void (*set_channel_mode)(Channel *channel, MessageTag *mtags, const char *modes, const char *parameters); extern MODVAR void (*set_channel_topic)(Client *client, Channel *channel, MessageTag *recv_mtags, const char *topic, const char *set_by, time_t set_at); extern MODVAR void (*cmd_umode)(ClientContext *, Client *, MessageTag *, int, const char **); @@ -828,7 +894,7 @@ extern MODVAR TKL *(*tkl_add_banexception)(int type, const char *usermask, const const char *reason, const char *set_by, time_t expire_at, time_t set_at, int soft, const char *bantypes, int flags); extern MODVAR TKL *(*tkl_add_nameban)(int type, const char *name, int hold, const char *reason, const char *setby, - time_t expire_at, time_t set_at, int flags); + time_t expire_at, time_t set_at, int flags); extern MODVAR TKL *(*tkl_add_spamfilter)(int type, const char *id, unsigned short target, BanAction *action, Match *match, const char *rule, SecurityGroup *except, const char *setby, @@ -928,7 +994,7 @@ extern MODVAR void (*webserver_close_client)(Client *client); extern MODVAR int (*webserver_handle_body)(Client *client, WebRequest *web, const char *readbuf, int length); extern MODVAR void (*rpc_response)(Client *client, json_t *request, json_t *result); extern MODVAR void (*rpc_error)(Client *client, json_t *request, JsonRpcError error_code, const char *error_message); -extern MODVAR void (*rpc_error_fmt)(Client *client, json_t *request, JsonRpcError error_code, FORMAT_STRING(const char *fmt), ...) __attribute__((format(printf,4,5))); +extern MODVAR void (*rpc_error_fmt)(Client *client, json_t *request, JsonRpcError error_code, FORMAT_STRING(const char *fmt), ...) __attribute__((format(printf, 4, 5))); extern MODVAR void (*rpc_send_request_to_remote)(Client *source, Client *target, json_t *request); extern MODVAR void (*rpc_send_response_to_remote)(Client *source, Client *target, json_t *request); extern MODVAR int (*rrpc_supported_simple)(Client *target, char **problem_server); @@ -944,7 +1010,12 @@ extern MODVAR int (*spamreport)(Client *client, const char *ip, NameValuePrioLis extern MODVAR int (*crule_test)(const char *rule); extern MODVAR CRuleNode *(*crule_parse)(const char *rule); extern MODVAR int (*crule_eval)(crule_context *context, CRuleNode *rule); -#define safe_crule_free(x) do { if (x) crule_free(&x); } while(0) +#define safe_crule_free(x) \ + do \ + { \ + if (x) \ + crule_free(&x); \ + } while (0) extern MODVAR void (*crule_free)(CRuleNode **); extern MODVAR const char *(*crule_errstring)(int errcode); extern MODVAR void (*ban_act_set_reputation)(Client *client, BanAction *action); @@ -974,7 +1045,7 @@ extern MODVAR void (*channel_flood_expand_json)(json_t *root, Client *client); /* TLS functions */ extern int early_init_tls(); extern int init_tls(); -extern int ssl_handshake(Client *); /* Handshake the accpeted con.*/ +extern int ssl_handshake(Client *); /* Handshake the accpeted con.*/ extern int ssl_client_handshake(Client *, ConfigItem_link *); /* and the initiated con.*/ extern int unreal_tls_accept(Client *acptr, int fd); extern int unreal_tls_connect(Client *acptr, int fd); @@ -1226,13 +1297,19 @@ extern int is_handshake_finished(Client *client); extern void SetCapability(Client *acptr, const char *token); extern void ClearCapability(Client *acptr, const char *token); extern void new_message(Client *sender, MessageTag *recv_mtags, MessageTag **mtag_list); -extern void new_message_special(Client *sender, MessageTag *recv_mtags, MessageTag **mtag_list, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,4,5))); +extern void new_message_special(Client *sender, MessageTag *recv_mtags, MessageTag **mtag_list, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 4, 5))); extern void generate_batch_id(char *str); extern MessageTag *find_mtag(MessageTag *mtags, const char *token); extern MessageTag *duplicate_mtag(MessageTag *mtag); extern MessageTag *duplicate_mtags(MessageTag *mtags); extern MessageTag *duplicate_mtags_for_subsequent_lines(MessageTag *mtags); -#define safe_free_message_tags(x) do { if (x) free_message_tags(x); x = NULL; } while(0) +#define safe_free_message_tags(x) \ + do \ + { \ + if (x) \ + free_message_tags(x); \ + x = NULL; \ + } while (0) extern void free_message_tags(MessageTag *m); extern int history_set_limit(const char *object, int max_lines, long max_t); extern int history_add(const char *object, MessageTag *mtags, const char *line); @@ -1274,7 +1351,13 @@ extern int is_extended_ban(const char *str); extern int is_extended_server_ban(const char *str); extern int empty_mode(const char *m); extern void free_multilinemode(MultiLineMode *m); -#define safe_free_multilinemode(m) do { if (m) free_multilinemode(m); m = NULL; } while(0) +#define safe_free_multilinemode(m) \ + do \ + { \ + if (m) \ + free_multilinemode(m); \ + m = NULL; \ + } while (0) extern ExtbanType mode_letter_to_extbantype(char c); extern ExtbanType listmode_sjoin_prefix_to_extbantype(char c); extern int valid_sid(const char *name); @@ -1286,7 +1369,13 @@ extern char *filename_add_suffix(const char *fname, const char *suffix); extern int filename_has_suffix(const char *fname, const char *suffix); extern void addmultiline(MultiLine **l, const char *line); extern void freemultiline(MultiLine *l); -#define safe_free_multiline(x) do { if (x) freemultiline(x); x = NULL; } while(0) +#define safe_free_multiline(x) \ + do \ + { \ + if (x) \ + freemultiline(x); \ + x = NULL; \ + } while (0) extern MultiLine *line2multiline(const char *str); extern void sendnotice_multiline(Client *client, MultiLine *m); extern void unreal_del_quotes(char *i); @@ -1299,12 +1388,12 @@ extern void lost_server_link(Client *serv, const char *tls_error_string); extern const char *sendtype_to_cmd(SendType sendtype); extern MODVAR MessageTagHandler *mtaghandlers; extern MODVAR RPCHandler *rpchandlers; -#define nv_find_by_name(stru, name) do_nv_find_by_name(stru, name, ARRAY_SIZEOF((stru))) +#define nv_find_by_name(stru, name) do_nv_find_by_name(stru, name, ARRAY_SIZEOF((stru))) extern long do_nv_find_by_name(NameValue *table, const char *cmd, int numelements); -#define nv_find_by_value(stru, value) do_nv_find_by_value(stru, value, ARRAY_SIZEOF((stru))) +#define nv_find_by_value(stru, value) do_nv_find_by_value(stru, value, ARRAY_SIZEOF((stru))) extern const char *do_nv_find_by_value(NameValue *table, long value, int numelements); extern NameValuePrioList *add_nvplist(NameValuePrioList **lst, int priority, const char *name, const char *value); -extern void add_fmt_nvplist(NameValuePrioList **lst, int priority, const char *name, FORMAT_STRING(const char *format), ...) __attribute__((format(printf,4,5))); +extern void add_fmt_nvplist(NameValuePrioList **lst, int priority, const char *name, FORMAT_STRING(const char *format), ...) __attribute__((format(printf, 4, 5))); /** Combination of add_nvplist() and buildnumeric() for convenience - only used in WHOIS response functions. * @param lst The NameValuePrioList &head * @param priority The priority of the item being added @@ -1314,12 +1403,17 @@ extern void add_fmt_nvplist(NameValuePrioList **lst, int priority, const char *n * @param ... The parameters for the numeric * @note Be sure to provide the correct number and type of parameters that belong to the numeric. Check include/numeric.h when in doubt! */ -#define add_nvplist_numeric(lst, priority, name, to, numeric, ...) add_nvplist_numeric_fmt(lst, priority, name, to, numeric, STR_ ## numeric, ##__VA_ARGS__) -extern void add_nvplist_numeric_fmt(NameValuePrioList **lst, int priority, const char *name, Client *to, int numeric, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,6,7))); +#define add_nvplist_numeric(lst, priority, name, to, numeric, ...) add_nvplist_numeric_fmt(lst, priority, name, to, numeric, STR_##numeric, ##__VA_ARGS__) +extern void add_nvplist_numeric_fmt(NameValuePrioList **lst, int priority, const char *name, Client *to, int numeric, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 6, 7))); extern NameValuePrioList *find_nvplist(NameValuePrioList *list, const char *name); extern const char *get_nvplist(NameValuePrioList *list, const char *name); extern void free_nvplist(NameValuePrioList *lst); -#define safe_free_nvplist(x) do { free_nvplist(x); x = NULL; } while(0) +#define safe_free_nvplist(x) \ + do \ + { \ + free_nvplist(x); \ + x = NULL; \ + } while (0) extern void del_nvplist_entry(NameValuePrioList *nvp, NameValuePrioList **lst); extern NameValuePrioList *duplicate_nvplist(NameValuePrioList *e); extern NameValuePrioList *duplicate_nvplist_append(NameValuePrioList *e, NameValuePrioList **list); @@ -1375,7 +1469,15 @@ extern int security_group_exists(const char *name); extern SecurityGroup *add_security_group(const char *name, int order); extern SecurityGroup *find_security_group(const char *name); extern void free_security_group(SecurityGroup *s); -#define safe_free_security_group(x) do { if (x) { free_security_group(x); x = NULL; } } while(0) +#define safe_free_security_group(x) \ + do \ + { \ + if (x) \ + { \ + free_security_group(x); \ + x = NULL; \ + } \ + } while (0) extern SecurityGroup *duplicate_security_group(SecurityGroup *s); extern void set_security_group_defaults(void); extern int user_allowed_by_security_group(Client *client, SecurityGroup *s); @@ -1436,7 +1538,7 @@ extern const char *log_level_terminal_color(LogLevel loglevel); extern LogType log_type_stringtoval(const char *str); extern const char *log_type_valtostring(LogType v); #ifdef DEBUGMODE -/* In debug mode we include file/linenumber. We put this arg at the end, however + /* In debug mode we include file/linenumber. We put this arg at the end, however * there is an issue if unreal_log() is used with a parameter like xyz ? log_data_string("zzz") : NULL, * since then our log_data_source() would be beyond NULL and thus would never be freed, * so we allocate and handle that differently. File/line would still be lost but at @@ -1444,31 +1546,41 @@ extern const char *log_type_valtostring(LogType v); * parameters explicitly, put log_data_source() at the beginning of the argument list * and then use non-portable ## __VA_ARGS__ for the remainder. */ -#define unreal_log(level, sys, id, ...) do { \ - if (!log_throttled((sys), (id))) { \ - LogData *lds = log_data_source(__FILE__, __LINE__, __FUNCTION__); \ - do_unreal_log((level), (sys), (id), __VA_ARGS__, lds, NULL); \ - log_data_free(lds); \ - } \ - } while(0) -#define unreal_log_raw(level, sys, id, ...) do { \ - if (!log_throttled((sys), (id))) { \ - LogData *lds = log_data_source(__FILE__, __LINE__, __FUNCTION__); \ - do_unreal_log_raw((level), (sys), (id), __VA_ARGS__, lds, NULL); \ - log_data_free(lds); \ - } \ - } while(0) + #define unreal_log(level, sys, id, ...) \ + do \ + { \ + if (!log_throttled((sys), (id))) \ + { \ + LogData *lds = log_data_source(__FILE__, __LINE__, __FUNCTION__); \ + do_unreal_log((level), (sys), (id), __VA_ARGS__, lds, NULL); \ + log_data_free(lds); \ + } \ + } while (0) + #define unreal_log_raw(level, sys, id, ...) \ + do \ + { \ + if (!log_throttled((sys), (id))) \ + { \ + LogData *lds = log_data_source(__FILE__, __LINE__, __FUNCTION__); \ + do_unreal_log_raw((level), (sys), (id), __VA_ARGS__, lds, NULL); \ + log_data_free(lds); \ + } \ + } while (0) #else -#define unreal_log(level, sys, id, ...) do { \ - if (!log_throttled((sys), (id))) \ - do_unreal_log((level), (sys), (id), __VA_ARGS__, NULL); \ - } while(0) -#define unreal_log_raw(level, sys, id, ...) do { \ - if (!log_throttled((sys), (id))) \ - do_unreal_log_raw((level), (sys), (id), __VA_ARGS__, NULL); \ - } while(0) + #define unreal_log(level, sys, id, ...) \ + do \ + { \ + if (!log_throttled((sys), (id))) \ + do_unreal_log((level), (sys), (id), __VA_ARGS__, NULL); \ + } while (0) + #define unreal_log_raw(level, sys, id, ...) \ + do \ + { \ + if (!log_throttled((sys), (id))) \ + do_unreal_log_raw((level), (sys), (id), __VA_ARGS__, NULL); \ + } while (0) #endif -extern void do_unreal_log(LogLevel loglevel, const char *subsystem, const char *event_id, Client *client, const char *msg, ...) __attribute__((format(printf,5,0))); +extern void do_unreal_log(LogLevel loglevel, const char *subsystem, const char *event_id, Client *client, const char *msg, ...) __attribute__((format(printf, 5, 0))); extern void do_unreal_log_raw(LogLevel loglevel, const char *subsystem, const char *event_id, Client *client, const char *msg, ...); extern void do_unreal_log_internal_from_remote(LogLevel loglevel, const char *subsystem, const char *event_id, MultiLine *msg, json_t *json, const char *json_serialized, Client *from_server); extern LogData *log_data_string(const char *key, const char *str); @@ -1542,7 +1654,7 @@ extern int downloads_in_progress(void); /* end of url stuff */ extern char *collapse(char *pattern); extern void clear_scache_hash_table(void); -extern void sendto_one(Client *, MessageTag *mtags, FORMAT_STRING(const char *), ...) __attribute__((format(printf,3,4))); +extern void sendto_one(Client *, MessageTag *mtags, FORMAT_STRING(const char *), ...) __attribute__((format(printf, 3, 4))); extern void vsendto_one(Client *to, MessageTag *mtags, const char *pattern, va_list vl); extern void mark_data_to_send(Client *to); extern EVENT(garbage_collect); @@ -1596,7 +1708,15 @@ extern MODVAR DynamicSetBlock unknown_users_set; extern MODVAR DynamicSetBlock dynamic_set; extern void start_dns_and_ident_lookup(Client *client); extern void free_webserver(WebServer *webserver); -#define safe_free_webserver(x) do { if (x) { free_webserver(x); x = NULL; } } while(0) +#define safe_free_webserver(x) \ + do \ + { \ + if (x) \ + { \ + free_webserver(x); \ + x = NULL; \ + } \ + } while (0) extern Tag *find_tag(Client *client, const char *name); extern Tag *add_tag(Client *client, const char *name, int value); extern void free_all_tags(Client *client); @@ -1612,7 +1732,15 @@ extern int highest_channel_member_count(Client *client); extern MODVAR long long central_spamfilter_last_download; extern int valid_operclass_character(char c); extern int valid_operclass_name(const char *str); -#define safe_free_outgoingwebrequest(x) do { if (x) { free_outgoingwebrequest(x); x = NULL; } } while(0) +#define safe_free_outgoingwebrequest(x) \ + do \ + { \ + if (x) \ + { \ + free_outgoingwebrequest(x); \ + x = NULL; \ + } \ + } while (0) extern void free_outgoingwebrequest(OutgoingWebRequest *r); extern OutgoingWebRequest *duplicate_outgoingwebrequest(OutgoingWebRequest *orig); extern void url_callback(OutgoingWebRequest *r, const char *file, const char *memory, long long memory_len, const char *errorbuf, int cached, void *ptr); diff --git a/include/ircsprintf.h b/include/ircsprintf.h index af308083d..80ea10283 100644 --- a/include/ircsprintf.h +++ b/include/ircsprintf.h @@ -11,13 +11,13 @@ /* ugly hack GRR, for both attribute and FORMAT_STRING */ #if !defined(__GNUC__) && !defined(__common_include__) -#define __attribute__(x) /* nothing */ + #define __attribute__(x) /* nothing */ #endif #ifndef FORMAT_STRING -# define FORMAT_STRING(p) p + #define FORMAT_STRING(p) p #endif -extern char *ircvsnprintf(char *str, size_t size, const char *format, va_list) __attribute__((format(printf,3,0))); -extern char *ircsnprintf(char *str, size_t size, FORMAT_STRING(const char *format), ...) __attribute__((format(printf,3,4))); +extern char *ircvsnprintf(char *str, size_t size, const char *format, va_list) __attribute__((format(printf, 3, 0))); +extern char *ircsnprintf(char *str, size_t size, FORMAT_STRING(const char *format), ...) __attribute__((format(printf, 3, 4))); #endif diff --git a/include/license.h b/include/license.h index abf766e55..b899fb8eb 100644 --- a/include/license.h +++ b/include/license.h @@ -26,24 +26,24 @@ char *gnulicense[] = { - " \2UnrealIRCd License\2", - "This program is free software; you can redistribute it and/or", - "modify it under the terms of the GNU General Public License", - "as published by the Free Software Foundation; either version 2", - "of the License, or (at your option) any later version.", - "", - "This program is distributed in the hope that it will be useful,", - "but WITHOUT ANY WARRANTY; without even the implied warranty of", - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", - "GNU General Public License for more details.", - "", - "You should have received a copy of the GNU General Public License", - "along with this program; if not, write to the Free Software", - "Foundation, Inc., 51 Franklin Street, Fifth Floor,", - "Boston, MA 02110-1301, USA.", - "", - "To see the UnrealIRCd License, please point your browser", - "to https://www.gnu.org/licenses/old-licenses/gpl-2.0.html", - "or look at the LICENSE file in the UnrealIRCd distribution.", - NULL, + " \2UnrealIRCd License\2", + "This program is free software; you can redistribute it and/or", + "modify it under the terms of the GNU General Public License", + "as published by the Free Software Foundation; either version 2", + "of the License, or (at your option) any later version.", + "", + "This program is distributed in the hope that it will be useful,", + "but WITHOUT ANY WARRANTY; without even the implied warranty of", + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", + "GNU General Public License for more details.", + "", + "You should have received a copy of the GNU General Public License", + "along with this program; if not, write to the Free Software", + "Foundation, Inc., 51 Franklin Street, Fifth Floor,", + "Boston, MA 02110-1301, USA.", + "", + "To see the UnrealIRCd License, please point your browser", + "to https://www.gnu.org/licenses/old-licenses/gpl-2.0.html", + "or look at the LICENSE file in the UnrealIRCd distribution.", + NULL, }; diff --git a/include/list.h b/include/list.h index 5965f841c..d1b0df03d 100644 --- a/include/list.h +++ b/include/list.h @@ -10,13 +10,13 @@ #include "common.h" #ifndef _WIN32 -#define SINLINE static inline + #define SINLINE static inline #else -#define SINLINE static + #define SINLINE static #endif #ifdef _WIN32 -#define typeof(x) Client + #define typeof(x) Client /* ^ FIXME if/when Microsoft supports this. * All functions use Client at the moment, with the exception of CAP, which has * to use list_for_each_entry2 because of it @@ -33,7 +33,7 @@ * */ #define container_of(ptr, type, member) \ - ((type *)( (char *)ptr - offsetof(type, member) )) + ((type *)((char *)ptr - offsetof(type, member))) struct list_head { struct list_head *next, *prev; @@ -49,7 +49,7 @@ struct list_head { * using the generic single-entry routines. */ -#define LIST_HEAD_INIT(name) { &(name), &(name) } +#define LIST_HEAD_INIT(name) {&(name), &(name)} #define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name) @@ -67,8 +67,8 @@ SINLINE void INIT_LIST_HEAD(struct list_head *list) * the prev/next entries already! */ SINLINE void __list_add(struct list_head *new, - struct list_head *prev, - struct list_head *next) + struct list_head *prev, + struct list_head *next) { next->prev = new; new->next = next; @@ -110,7 +110,7 @@ SINLINE void list_add_tail(struct list_head *new, struct list_head *head) * This is only for internal list manipulation where we know * the prev/next entries already! */ -SINLINE void __list_del(struct list_head * prev, struct list_head * next) +SINLINE void __list_del(struct list_head *prev, struct list_head *next) { next->prev = prev; prev->next = next; @@ -141,7 +141,7 @@ SINLINE void list_del(struct list_head *entry) * If @old was empty, it will be overwritten. */ SINLINE void list_replace(struct list_head *old, - struct list_head *new) + struct list_head *new) { new->next = old->next; new->next->prev = new; @@ -150,7 +150,7 @@ SINLINE void list_replace(struct list_head *old, } SINLINE void list_replace_init(struct list_head *old, - struct list_head *new) + struct list_head *new) { list_replace(old, new); INIT_LIST_HEAD(old); @@ -183,7 +183,7 @@ SINLINE void list_move(struct list_head *list, struct list_head *head) * @head: the head that will follow our entry */ SINLINE void list_move_tail(struct list_head *list, - struct list_head *head) + struct list_head *head) { __list_del_entry(list); list_add_tail(list, head); @@ -195,7 +195,7 @@ SINLINE void list_move_tail(struct list_head *list, * @head: the head of the list */ SINLINE int list_is_last(const struct list_head *list, - const struct list_head *head) + const struct list_head *head) { return list->next == head; } @@ -236,7 +236,8 @@ SINLINE void list_rotate_left(struct list_head *head) { struct list_head *first; - if (!list_empty(head)) { + if (!list_empty(head)) + { first = head->next; list_move_tail(first, head); } @@ -252,7 +253,7 @@ SINLINE int list_is_singular(const struct list_head *head) } SINLINE void __list_cut_position(struct list_head *list, - struct list_head *head, struct list_head *entry) + struct list_head *head, struct list_head *entry) { struct list_head *new_first = entry->next; list->next = head->next; @@ -278,12 +279,12 @@ SINLINE void __list_cut_position(struct list_head *list, * */ SINLINE void list_cut_position(struct list_head *list, - struct list_head *head, struct list_head *entry) + struct list_head *head, struct list_head *entry) { if (list_empty(head)) return; if (list_is_singular(head) && - (head->next != entry && head != entry)) + (head->next != entry && head != entry)) return; if (entry == head) INIT_LIST_HEAD(list); @@ -292,8 +293,8 @@ SINLINE void list_cut_position(struct list_head *list, } SINLINE void __list_splice(const struct list_head *list, - struct list_head *prev, - struct list_head *next) + struct list_head *prev, + struct list_head *next) { struct list_head *first = list->next; struct list_head *last = list->prev; @@ -311,7 +312,7 @@ SINLINE void __list_splice(const struct list_head *list, * @head: the place to add it in the first list. */ SINLINE void list_splice(const struct list_head *list, - struct list_head *head) + struct list_head *head) { if (!list_empty(list)) __list_splice(list, head, head->next); @@ -323,7 +324,7 @@ SINLINE void list_splice(const struct list_head *list, * @head: the place to add it in the first list. */ SINLINE void list_splice_tail(struct list_head *list, - struct list_head *head) + struct list_head *head) { if (!list_empty(list)) __list_splice(list, head->prev, head); @@ -337,9 +338,10 @@ SINLINE void list_splice_tail(struct list_head *list, * The list at @list is reinitialised */ SINLINE void list_splice_init(struct list_head *list, - struct list_head *head) + struct list_head *head) { - if (!list_empty(list)) { + if (!list_empty(list)) + { __list_splice(list, head, head->next); INIT_LIST_HEAD(list); } @@ -354,9 +356,10 @@ SINLINE void list_splice_init(struct list_head *list, * The list at @list is reinitialised */ SINLINE void list_splice_tail_init(struct list_head *list, - struct list_head *head) + struct list_head *head) { - if (!list_empty(list)) { + if (!list_empty(list)) + { __list_splice(list, head->prev, head); INIT_LIST_HEAD(list); } @@ -417,7 +420,7 @@ SINLINE void list_splice_tail_init(struct list_head *list, */ #define list_for_each_safe(pos, n, head) \ for (pos = (head)->next, n = pos->next; pos != (head); \ - pos = n, n = pos->next) + pos = n, n = pos->next) /** * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry @@ -487,9 +490,9 @@ SINLINE void list_splice_tail_init(struct list_head *list, * } * @endcode */ -#define list_for_each_entry(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ +#define list_for_each_entry(pos, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member); \ + &pos->member != (head); \ pos = list_entry(pos->member.next, typeof(*pos), member)) /** @@ -498,9 +501,9 @@ SINLINE void list_splice_tail_init(struct list_head *list, * @head: the head for your list. * @member: the name of the list_struct within the struct. */ -#define list_for_each_entry2(pos, tpe, head, member) \ - for (pos = list_entry((head)->next, tpe, member); \ - &pos->member != (head); \ +#define list_for_each_entry2(pos, tpe, head, member) \ + for (pos = list_entry((head)->next, tpe, member); \ + &pos->member != (head); \ pos = list_entry(pos->member.next, tpe, member)) /** @@ -509,9 +512,9 @@ SINLINE void list_splice_tail_init(struct list_head *list, * @head: the head for your list. * @member: the name of the list_struct within the struct. */ -#define list_for_each_entry_reverse(pos, head, member) \ - for (pos = list_entry((head)->prev, typeof(*pos), member); \ - &pos->member != (head); \ +#define list_for_each_entry_reverse(pos, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member); \ + &pos->member != (head); \ pos = list_entry(pos->member.prev, typeof(*pos), member)) /** @@ -523,7 +526,7 @@ SINLINE void list_splice_tail_init(struct list_head *list, * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). */ #define list_prepare_entry(pos, head, member) \ - ((pos) ? : list_entry(head, typeof(*pos), member)) + ((pos) ?: list_entry(head, typeof(*pos), member)) /** * list_for_each_entry_continue - continue iteration over list of given type @@ -534,9 +537,9 @@ SINLINE void list_splice_tail_init(struct list_head *list, * Continue to iterate over list of given type, continuing after * the current position. */ -#define list_for_each_entry_continue(pos, head, member) \ - for (pos = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ +#define list_for_each_entry_continue(pos, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ pos = list_entry(pos->member.next, typeof(*pos), member)) /** @@ -548,9 +551,9 @@ SINLINE void list_splice_tail_init(struct list_head *list, * Start to iterate over list of given type backwards, continuing after * the current position. */ -#define list_for_each_entry_continue_reverse(pos, head, member) \ - for (pos = list_entry(pos->member.prev, typeof(*pos), member); \ - &pos->member != (head); \ +#define list_for_each_entry_continue_reverse(pos, head, member) \ + for (pos = list_entry(pos->member.prev, typeof(*pos), member); \ + &pos->member != (head); \ pos = list_entry(pos->member.prev, typeof(*pos), member)) /** @@ -561,8 +564,8 @@ SINLINE void list_splice_tail_init(struct list_head *list, * * Iterate over list of given type, continuing from current position. */ -#define list_for_each_entry_from(pos, head, member) \ - for (; &pos->member != (head); \ +#define list_for_each_entry_from(pos, head, member) \ + for (; &pos->member != (head); \ pos = list_entry(pos->member.next, typeof(*pos), member)) /** Walk through client lists - special 'safe' version. @@ -576,10 +579,10 @@ SINLINE void list_splice_tail_init(struct list_head *list, * @param member The name of the list_struct within the struct. * @ingroup ListFunctions */ -#define list_for_each_entry_safe(pos, n, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ +#define list_for_each_entry_safe(pos, n, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) /** @@ -592,10 +595,10 @@ SINLINE void list_splice_tail_init(struct list_head *list, * Iterate over list of given type, continuing after current point, * safe against removal of list entry. */ -#define list_for_each_entry_safe_continue(pos, n, head, member) \ - for (pos = list_entry(pos->member.next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ +#define list_for_each_entry_safe_continue(pos, n, head, member) \ + for (pos = list_entry(pos->member.next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) /** @@ -608,9 +611,9 @@ SINLINE void list_splice_tail_init(struct list_head *list, * Iterate over list of given type from current point, safe against * removal of list entry. */ -#define list_for_each_entry_safe_from(pos, n, head, member) \ - for (n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ +#define list_for_each_entry_safe_from(pos, n, head, member) \ + for (n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) /** @@ -623,10 +626,10 @@ SINLINE void list_splice_tail_init(struct list_head *list, * Iterate backwards over list of given type, safe against removal * of list entry. */ -#define list_for_each_entry_safe_reverse(pos, n, head, member) \ - for (pos = list_entry((head)->prev, typeof(*pos), member), \ - n = list_entry(pos->member.prev, typeof(*pos), member); \ - &pos->member != (head); \ +#define list_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member), \ + n = list_entry(pos->member.prev, typeof(*pos), member); \ + &pos->member != (head); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) /** @@ -641,7 +644,7 @@ SINLINE void list_splice_tail_init(struct list_head *list, * and list_safe_reset_next is called after re-taking the lock and before * completing the current iteration of the loop body. */ -#define list_safe_reset_next(pos, n, member) \ +#define list_safe_reset_next(pos, n, member) \ n = list_entry(pos->member.next, typeof(*pos), member) #endif diff --git a/include/mempool.h b/include/mempool.h index 6648ceeca..79366fc26 100644 --- a/include/mempool.h +++ b/include/mempool.h @@ -40,7 +40,7 @@ #define TOR_MEMPOOL_H #ifdef _WIN32 - #define uint64_t unsigned __int64 + #define uint64_t unsigned __int64 #endif /** A memory pool is a context in which a large number of fixed-sized @@ -61,44 +61,44 @@ extern void mp_pool_garbage_collect(void *); #define MEMPOOL_STATS struct mp_pool_t { - /** Next pool. A pool is usually linked into the mp_allocated_pools list. */ - mp_pool_t *next; + /** Next pool. A pool is usually linked into the mp_allocated_pools list. */ + mp_pool_t *next; - /** Doubly-linked list of chunks in which no items have been allocated. + /** Doubly-linked list of chunks in which no items have been allocated. * The front of the list is the most recently emptied chunk. */ - struct mp_chunk_t *empty_chunks; + struct mp_chunk_t *empty_chunks; - /** Doubly-linked list of chunks in which some items have been allocated, + /** Doubly-linked list of chunks in which some items have been allocated, * but which are not yet full. The front of the list is the chunk that has * most recently been modified. */ - struct mp_chunk_t *used_chunks; + struct mp_chunk_t *used_chunks; - /** Doubly-linked list of chunks in which no more items can be allocated. + /** Doubly-linked list of chunks in which no more items can be allocated. * The front of the list is the chunk that has most recently become full. */ - struct mp_chunk_t *full_chunks; + struct mp_chunk_t *full_chunks; - /** Length of empty_chunks. */ - int n_empty_chunks; + /** Length of empty_chunks. */ + int n_empty_chunks; - /** Lowest value of empty_chunks since last call to + /** Lowest value of empty_chunks since last call to * mp_pool_clean(-1). */ - int min_empty_chunks; + int min_empty_chunks; - /** Size of each chunk (in items). */ - int new_chunk_capacity; + /** Size of each chunk (in items). */ + int new_chunk_capacity; - /** Size to allocate for each item, including overhead and alignment + /** Size to allocate for each item, including overhead and alignment * padding. */ - size_t item_alloc_size; + size_t item_alloc_size; #ifdef MEMPOOL_STATS - /** Total number of items allocated ever. */ - uint64_t total_items_allocated; + /** Total number of items allocated ever. */ + uint64_t total_items_allocated; - /** Total number of chunks allocated ever. */ - uint64_t total_chunks_allocated; + /** Total number of chunks allocated ever. */ + uint64_t total_chunks_allocated; - /** Total number of chunks freed ever. */ - uint64_t total_chunks_freed; + /** Total number of chunks freed ever. */ + uint64_t total_chunks_freed; #endif }; diff --git a/include/mmdb.h b/include/mmdb.h index 535a273ce..f33fbdd9a 100644 --- a/include/mmdb.h +++ b/include/mmdb.h @@ -39,29 +39,29 @@ #include #include #else -#include -#include + #include + #include #endif /** Status/error codes returned by mmdb functions */ typedef enum { - MMDB_OK = 0, /**< Success */ - MMDB_ERR_OPEN, /**< Could not open or mmap the file */ - MMDB_ERR_INVALID_DB, /**< Not a valid MMDB file */ - MMDB_ERR_CORRUPT, /**< Search tree or data section corruption */ - MMDB_ERR_NODATA, /**< IP found but requested path doesn't exist */ - MMDB_ERR_TYPE, /**< Type mismatch (asked for string, got uint, etc) */ - MMDB_ERR_IPV6_IN_V4, /**< Tried to look up an IPv6 address in an IPv4-only db */ - MMDB_ERR_BADARG, /**< Invalid argument (e.g. unparseable IP address) */ + MMDB_OK = 0, /**< Success */ + MMDB_ERR_OPEN, /**< Could not open or mmap the file */ + MMDB_ERR_INVALID_DB, /**< Not a valid MMDB file */ + MMDB_ERR_CORRUPT, /**< Search tree or data section corruption */ + MMDB_ERR_NODATA, /**< IP found but requested path doesn't exist */ + MMDB_ERR_TYPE, /**< Type mismatch (asked for string, got uint, etc) */ + MMDB_ERR_IPV6_IN_V4, /**< Tried to look up an IPv6 address in an IPv4-only db */ + MMDB_ERR_BADARG, /**< Invalid argument (e.g. unparseable IP address) */ } MMDB_Status; /** Database metadata */ typedef struct { - uint32_t node_count; /**< Number of nodes in the search tree */ - uint16_t record_size; /**< Size of each record in bits */ - uint16_t ip_version; /**< IP version the database covers (4 or 6) */ - uint64_t build_epoch; /**< Unix timestamp when the database was built */ - char database_type[128]; /**< Database type string (e.g. "GeoLite2-Country") */ + uint32_t node_count; /**< Number of nodes in the search tree */ + uint16_t record_size; /**< Size of each record in bits */ + uint16_t ip_version; /**< IP version the database covers (4 or 6) */ + uint64_t build_epoch; /**< Unix timestamp when the database was built */ + char database_type[128]; /**< Database type string (e.g. "GeoLite2-Country") */ } MMDB_Metadata; /** Database handle */ @@ -78,9 +78,9 @@ typedef struct { /** Lookup result */ typedef struct { - MMDB_DB *db; /**< Database this result belongs to */ - size_t offset; /**< Offset into data section, or 0 if not found */ - int has_data; /**< 1 if IP was found and has data */ + MMDB_DB *db; /**< Database this result belongs to */ + size_t offset; /**< Offset into data section, or 0 if not found */ + int has_data; /**< 1 if IP was found and has data */ } MMDB_Result; /** Open an MMDB database file. diff --git a/include/modules.h b/include/modules.h index 44028f3d5..e4c9b6fd9 100644 --- a/include/modules.h +++ b/include/modules.h @@ -21,35 +21,35 @@ #ifndef MODULES_H #define MODULES_H #include "types.h" -#define MAXCUSTOMHOOKS 30 -#define MAXHOOKTYPES 200 -#define MAXCALLBACKS 30 -#define MAXEFUNCTIONS 192 +#define MAXCUSTOMHOOKS 30 +#define MAXHOOKTYPES 200 +#define MAXCALLBACKS 30 +#define MAXEFUNCTIONS 192 #if defined(_WIN32) - #define MOD_EXTENSION "dll" - #define DLLFUNC _declspec(dllexport) - #define irc_dlopen(x,y) LoadLibrary(x) - #define irc_dlclose FreeLibrary - #define irc_dlsym(x,y,z) z = (void *)GetProcAddress(x,y) - #define irc_dlerror our_dlerror + #define MOD_EXTENSION "dll" + #define DLLFUNC _declspec(dllexport) + #define irc_dlopen(x, y) LoadLibrary(x) + #define irc_dlclose FreeLibrary + #define irc_dlsym(x, y, z) z = (void *)GetProcAddress(x, y) + #define irc_dlerror our_dlerror #else #define MOD_EXTENSION "so" - #define irc_dlopen dlopen - #define irc_dlclose dlclose + #define irc_dlopen dlopen + #define irc_dlclose dlclose #if defined(UNDERSCORE) - #define irc_dlsym(x,y,z) z = obsd_dlsym(x,y) + #define irc_dlsym(x, y, z) z = obsd_dlsym(x, y) #else - #define irc_dlsym(x,y,z) z = dlsym(x,y) + #define irc_dlsym(x, y, z) z = dlsym(x, y) #endif #define irc_dlerror dlerror - #define DLLFUNC + #define DLLFUNC #endif -#define EVENT(x) void (x) (void *data) +#define EVENT(x) void(x)(void *data) /* Casts to int, void, void *, and char * function pointers */ -#define TO_INTFUNC(x) (int (*)())(x) -#define TO_VOIDFUNC(x) (void (*)())(x) +#define TO_INTFUNC(x) (int (*)())(x) +#define TO_VOIDFUNC(x) (void (*)())(x) #define TO_PVOIDFUNC(x) (void *(*)())(x) #define TO_PCHARFUNC(x) (char *(*)())(x) @@ -77,9 +77,8 @@ typedef struct ModuleHeader { typedef struct Module Module; -typedef struct ModuleChild -{ - struct ModuleChild *prev, *next; +typedef struct ModuleChild { + struct ModuleChild *prev, *next; Module *child; /* Aww. aint it cute? */ } ModuleChild; @@ -115,23 +114,23 @@ typedef enum ModuleObjectType { typedef struct Umode Umode; struct Umode { Umode *prev, *next; - long mode; /**< Mode mask */ - char letter; /**< Mode character */ - int unset_on_deoper; /**< When set to 1 then this user mode will be unset on de-oper */ + long mode; /**< Mode mask */ + char letter; /**< Mode character */ + int unset_on_deoper; /**< When set to 1 then this user mode will be unset on de-oper */ int (*allowed)(Client *client, int what); /**< The 'is this user allowed to set this mode?' routine */ - char unloaded; /**< Internal flag to indicate module is being unloaded */ - Module *owner; /**< Module that owns this user mode */ + char unloaded; /**< Internal flag to indicate module is being unloaded */ + Module *owner; /**< Module that owns this user mode */ }; #define HIGHESTMODDATATYPE 7 typedef enum ModDataType { - MODDATATYPE_LOCAL_VARIABLE = 1, - MODDATATYPE_GLOBAL_VARIABLE = 2, - MODDATATYPE_CLIENT = 3, - MODDATATYPE_LOCAL_CLIENT = 4, - MODDATATYPE_CHANNEL = 5, - MODDATATYPE_MEMBER = 6, - MODDATATYPE_MEMBERSHIP = 7, + MODDATATYPE_LOCAL_VARIABLE = 1, + MODDATATYPE_GLOBAL_VARIABLE = 2, + MODDATATYPE_CLIENT = 3, + MODDATATYPE_LOCAL_CLIENT = 4, + MODDATATYPE_CHANNEL = 5, + MODDATATYPE_MEMBER = 6, + MODDATATYPE_MEMBERSHIP = 7, /* If you add more here, then 1) increase MODDATATYPES, * 2) in src/api-moddata.c update moddatatypelimits[], * 3) add a lot of code at other places in src/api-moddata.c. @@ -139,35 +138,35 @@ typedef enum ModDataType { } ModDataType; typedef enum ModDataSync { - MODDATA_SYNC_NORMAL = 1, /**< Sync normally via MD command */ - MODDATA_SYNC_EARLY = 2, /**< Attempt to (also) sync early in the UID command */ + MODDATA_SYNC_NORMAL = 1, /**< Sync normally via MD command */ + MODDATA_SYNC_EARLY = 2, /**< Attempt to (also) sync early in the UID command */ } ModDataSync; typedef struct ModDataInfo ModDataInfo; struct ModDataInfo { ModDataInfo *prev, *next; - int priority; /**< For sorting purposes (ones with most key lookups should go first) */ - char *name; /**< Name for this moddata */ - Module *owner; /**< Owner of this moddata */ - ModDataType type; /**< Type of module data (eg: for client, channel, etc..) */ - int slot; /**< Assigned slot */ - char unloaded; /**< Module being unloaded? */ - void (*free)(ModData *m); /**< Function will be called when the data needs to be freed (may be NULL if not using dynamic storage) */ - const char *(*serialize)(ModData *m); /**< Function which converts the data to a string. May return NULL if 'm' contains no data (since for example m->ptr may be NULL). */ + int priority; /**< For sorting purposes (ones with most key lookups should go first) */ + char *name; /**< Name for this moddata */ + Module *owner; /**< Owner of this moddata */ + ModDataType type; /**< Type of module data (eg: for client, channel, etc..) */ + int slot; /**< Assigned slot */ + char unloaded; /**< Module being unloaded? */ + void (*free)(ModData *m); /**< Function will be called when the data needs to be freed (may be NULL if not using dynamic storage) */ + const char *(*serialize)(ModData *m); /**< Function which converts the data to a string. May return NULL if 'm' contains no data (since for example m->ptr may be NULL). */ void (*unserialize)(const char *str, ModData *m); /**< Function which converts the string back to data */ - ModDataSync sync; /**< Send in netsynch (when servers connect) */ - int remote_write; /**< Allow remote servers to set/unset this moddata, even if it they target one of our own clients */ - int self_write; /**< Allow remote servers to set/unset moddata of their own server object (irc1.example.net writing the MD object of irc1.example.net) */ + ModDataSync sync; /**< Send in netsynch (when servers connect) */ + int remote_write; /**< Allow remote servers to set/unset this moddata, even if it they target one of our own clients */ + int self_write; /**< Allow remote servers to set/unset moddata of their own server object (irc1.example.net writing the MD object of irc1.example.net) */ }; -#define moddata_client(acptr, md) acptr->moddata[md->slot] -#define moddata_local_client(acptr, md) acptr->local->moddata[md->slot] -#define moddata_channel(channel, md) channel->moddata[md->slot] -#define moddata_member(m, md) m->moddata[md->slot] -#define moddata_membership(m, md) m->moddata[md->slot] -#define moddata_local_variable(md) local_variable_moddata[md->slot] -#define moddata_global_variable(md) global_variable_moddata[md->slot] +#define moddata_client(acptr, md) acptr->moddata[md->slot] +#define moddata_local_client(acptr, md) acptr->local->moddata[md->slot] +#define moddata_channel(channel, md) channel->moddata[md->slot] +#define moddata_member(m, md) m->moddata[md->slot] +#define moddata_membership(m, md) m->moddata[md->slot] +#define moddata_local_variable(md) local_variable_moddata[md->slot] +#define moddata_global_variable(md) global_variable_moddata[md->slot] /* Can bypass message restriction - Types */ typedef enum BypassChannelMessageRestrictionType { @@ -182,33 +181,33 @@ typedef enum BypassChannelMessageRestrictionType { * @{ */ -#define EXCHK_ACCESS 0 /**< Check user access */ -#define EXCHK_ACCESS_ERR 1 /**< Check user access and send error to user */ -#define EXCHK_PARAM 2 /**< Check parameter */ +#define EXCHK_ACCESS 0 /**< Check user access */ +#define EXCHK_ACCESS_ERR 1 /**< Check user access and send error to user */ +#define EXCHK_PARAM 2 /**< Check parameter */ /* return values for EXCHK_ACCESS*: */ -#define EX_DENY 0 /**< MODE change disallowed, except in case of operoverride */ -#define EX_ALLOW 1 /**< MODE change allowed */ -#define EX_ALWAYS_DENY -1 /**< MODE change disallowed, even in case of operoverride */ +#define EX_DENY 0 /**< MODE change disallowed, except in case of operoverride */ +#define EX_ALLOW 1 /**< MODE change allowed */ +#define EX_ALWAYS_DENY -1 /**< MODE change disallowed, even in case of operoverride */ -#define EXSJ_SAME 0 /**< SJOIN: Parameters are the same */ -#define EXSJ_WEWON 1 /**< SJOIN: We won! w00t */ -#define EXSJ_THEYWON 2 /**< SJOIN: They won :( */ -#define EXSJ_MERGE 3 /**< SJOIN: Merging of modes, neither won nor lost */ +#define EXSJ_SAME 0 /**< SJOIN: Parameters are the same */ +#define EXSJ_WEWON 1 /**< SJOIN: We won! w00t */ +#define EXSJ_THEYWON 2 /**< SJOIN: They won :( */ +#define EXSJ_MERGE 3 /**< SJOIN: Merging of modes, neither won nor lost */ /** Channel mode bit/value */ typedef unsigned long long Cmode_t; typedef enum CmodeType { - CMODE_NORMAL=0, - CMODE_MEMBER=1, + CMODE_NORMAL = 0, + CMODE_MEMBER = 1, } CmodeType; -#define RANK_CHANOWNER 4000 -#define RANK_CHANADMIN 3000 -#define RANK_CHANOP 2000 -#define RANK_HALFOP 1000 -#define RANK_VOICE -1 +#define RANK_CHANOWNER 4000 +#define RANK_CHANADMIN 3000 +#define RANK_CHANOP 2000 +#define RANK_HALFOP 1000 +#define RANK_VOICE -1 /** Channel mode handler. * This struct contains all extended channel mode information, @@ -223,20 +222,20 @@ struct Cmode { Cmode *prev, *next; /** mode character (like 'Z') */ - char letter; + char letter; - CmodeType type; + CmodeType type; /** If type is CMODE_NORMAL, then bitmask (eg: 0x10) that * is used in channel->mode.mode */ - Cmode_t mode; + Cmode_t mode; /** If type is CMODE_MEMBER, then the prefix used in NAMES etc (eg @) */ - char prefix; + char prefix; /** If type is CMODE_MEMBER, then the prefix used in SJOIN (eg @) */ - char sjoin_prefix; + char sjoin_prefix; /** If type is CMODE_MEMBER, then the rank of this prefix. * Higher ranking = more rights. @@ -244,10 +243,10 @@ struct Cmode { * show one symbol but not all. * For the shipped modules vhoaq we use the RANK_* values. */ - int rank; + int rank; /** Number of parameters (1 or 0) */ - int paracount; + int paracount; /** Check access or parameter of the channel mode. * @param client The client @@ -325,7 +324,7 @@ struct Cmode { /** Local channel mode? Prevents remote servers from setting/unsetting this */ char local; - + /** Unsetting also eats/requires a parameter. Unusual, but possible. */ char unset_with_param; @@ -344,93 +343,93 @@ struct Cmode { /** Slot number - Can be used instead of GETPARAMSLOT() */ int param_slot; - + /** Module owner */ - Module *owner; + Module *owner; }; /** The struct used to register a channel mode handler. * For documentation, see Cmode struct. */ typedef struct { - char letter; - CmodeType type; - char prefix; - char sjoin_prefix; - int rank; - int paracount; - int (*is_ok)(Client *,Channel *, char mode, const char *para, int, int); - void * (*put_param)(void *, const char *); - const char * (*get_param)(void *); - const char * (*conv_param)(const char *, Client *, Channel *); - int (*free_param)(void *, int); - void * (*dup_struct)(void *); - int (*sjoin_check)(Channel *, void *, void *); - char local; - char unset_with_param; - char flood_type_action; + char letter; + CmodeType type; + char prefix; + char sjoin_prefix; + int rank; + int paracount; + int (*is_ok)(Client *, Channel *, char mode, const char *para, int, int); + void *(*put_param)(void *, const char *); + const char *(*get_param)(void *); + const char *(*conv_param)(const char *, Client *, Channel *); + int (*free_param)(void *, int); + void *(*dup_struct)(void *); + int (*sjoin_check)(Channel *, void *, void *); + char local; + char unset_with_param; + char flood_type_action; } CmodeInfo; /** Get a slot number for a param - eg GETPARAMSLOT('k') */ -#define GETPARAMSLOT(x) param_to_slot_mapping[x] +#define GETPARAMSLOT(x) param_to_slot_mapping[x] /** Get a cmode handler by slot - for example for [dont use this]: GETPARAMHANDLERBYSLOT(5)->get_param(channel) */ -#define GETPARAMHANDLERBYSLOT(slotid) ParamTable[slotid] +#define GETPARAMHANDLERBYSLOT(slotid) ParamTable[slotid] /** Same as GETPARAMHANDLERBYSLOT but then by letter - like [dont use this]: GETPARAMHANDLERBYSLOT('k')->get_param(channel) */ -#define GETPARAMHANDLERBYLETTER(x) ParamTable[GETPARAMSLOT(x)] +#define GETPARAMHANDLERBYLETTER(x) ParamTable[GETPARAMSLOT(x)] /** Get paramter data struct - for like: ((aModejEntry *)GETPARASTRUCT(channel, 'j'))->t */ -#define GETPARASTRUCT(mychannel, mychar) channel->mode.mode_params[GETPARAMSLOT(mychar)] +#define GETPARASTRUCT(mychannel, mychar) channel->mode.mode_params[GETPARAMSLOT(mychar)] -#define GETPARASTRUCTEX(v, mychar) v[GETPARAMSLOT(mychar)] +#define GETPARASTRUCTEX(v, mychar) v[GETPARAMSLOT(mychar)] /** @} */ -#define CMP_GETSLOT(x) GETPARAMSLOT(x) -#define CMP_GETHANDLERBYSLOT(x) GETPARAMHANDLERBYSLOT(x) +#define CMP_GETSLOT(x) GETPARAMSLOT(x) +#define CMP_GETHANDLERBYSLOT(x) GETPARAMHANDLERBYSLOT(x) #define CMP_GETHANDLERBYLETTER(x) GETPARAMHANDLERBYLETTER(x) -#define CMP_GETSTRUCT(x,y) GETPARASTRUCT(x,y) +#define CMP_GETSTRUCT(x, y) GETPARASTRUCT(x, y) /*** Extended bans ***/ typedef enum ExtbanCheck { - EXBCHK_ACCESS=0, /**< Check access */ - EXBCHK_ACCESS_ERR=1, /**< Check access and send error */ - EXBCHK_PARAM=2 /**< Check if the parameter is valid */ + EXBCHK_ACCESS = 0, /**< Check access */ + EXBCHK_ACCESS_ERR = 1, /**< Check access and send error */ + EXBCHK_PARAM = 2 /**< Check if the parameter is valid */ } ExtbanCheck; typedef enum ExtbanType { - EXBTYPE_BAN=0, /**< Ban (channel mode +b) */ - EXBTYPE_EXCEPT=1, /**< Ban exception (channel mode +e) */ - EXBTYPE_INVEX=2, /**< Invite exception (channel mode +I) */ - EXBTYPE_TKL=3 /**< TKL or other generic matcher outside banning routines */ + EXBTYPE_BAN = 0, /**< Ban (channel mode +b) */ + EXBTYPE_EXCEPT = 1, /**< Ban exception (channel mode +e) */ + EXBTYPE_INVEX = 2, /**< Invite exception (channel mode +I) */ + EXBTYPE_TKL = 3 /**< TKL or other generic matcher outside banning routines */ } ExtbanType; -#define BCTX_CONV_OPTION_WRITE_LETTER_BANS 1 /* Always write letter extbans in output of conv_param */ +#define BCTX_CONV_OPTION_WRITE_LETTER_BANS 1 /* Always write letter extbans in output of conv_param */ -#define EXTBANTABLESZ 32 +#define EXTBANTABLESZ 32 typedef enum ExtbanOptions { - EXTBOPT_CHSVSMODE=0x1, /**< SVSMODE -b/-e/-I will clear this ban (UNUSED as of 6.0.1+) */ - EXTBOPT_ACTMODIFIER=0x2, /**< Action modifier (not a matcher). These are extended bans like ~q/~n/~j. */ - EXTBOPT_NOSTACKCHILD=0x4, /**< Disallow prefixing with another extban. Eg disallow ~n:~T:censor:xyz */ - EXTBOPT_INVEX=0x8, /**< Available for use with +I too */ - EXTBOPT_TKL=0x10 /**< Available for use in TKL's too (eg: /GLINE ~a:account) */ + EXTBOPT_CHSVSMODE = 0x1, /**< SVSMODE -b/-e/-I will clear this ban (UNUSED as of 6.0.1+) */ + EXTBOPT_ACTMODIFIER = 0x2, /**< Action modifier (not a matcher). These are extended bans like ~q/~n/~j. */ + EXTBOPT_NOSTACKCHILD = 0x4, /**< Disallow prefixing with another extban. Eg disallow ~n:~T:censor:xyz */ + EXTBOPT_INVEX = 0x8, /**< Available for use with +I too */ + EXTBOPT_TKL = 0x10 /**< Available for use in TKL's too (eg: /GLINE ~a:account) */ } ExtbanOptions; typedef struct { - Client *client; /**< Client to check, can be a remote client */ - Channel *channel; /**< Channel to check */ - const char *banstr; /**< Mask string (ban) */ - int ban_check_types; /**< Ban types to check for, one or more of BANCHK_* OR'd together */ - const char *msg; /**< Message, only for some BANCHK_* types (for censoring text) */ - const char *error_msg; /**< Error message, can be NULL */ - int no_extbans; /**< Set to 1 to disable extended bans checking - only nick!user@host allowed */ - int what; /**< MODE_ADD or MODE_DEL (for is_ok) */ - ExtbanType ban_type; /**< EXBTYPE_BAN or EXBTYPE_EXCEPT (for is_ok) */ - ExtbanCheck is_ok_check;/**< One of EXBCHK_* (for is_ok) */ - int conv_options; /**< One of BCTX_CONV_OPTION_* (for conv_param) */ + Client *client; /**< Client to check, can be a remote client */ + Channel *channel; /**< Channel to check */ + const char *banstr; /**< Mask string (ban) */ + int ban_check_types; /**< Ban types to check for, one or more of BANCHK_* OR'd together */ + const char *msg; /**< Message, only for some BANCHK_* types (for censoring text) */ + const char *error_msg; /**< Error message, can be NULL */ + int no_extbans; /**< Set to 1 to disable extended bans checking - only nick!user@host allowed */ + int what; /**< MODE_ADD or MODE_DEL (for is_ok) */ + ExtbanType ban_type; /**< EXBTYPE_BAN or EXBTYPE_EXCEPT (for is_ok) */ + ExtbanCheck is_ok_check; /**< One of EXBCHK_* (for is_ok) */ + int conv_options; /**< One of BCTX_CONV_OPTION_* (for conv_param) */ } BanContext; typedef struct Extban Extban; @@ -447,7 +446,7 @@ struct Extban { /** extban options */ ExtbanOptions options; - unsigned int is_banned_events; /**< Which BANCHK_* events to listen on */ + unsigned int is_banned_events; /**< Which BANCHK_* events to listen on */ int (*is_ok)(BanContext *b); @@ -502,22 +501,22 @@ struct Versionflag { /* This type needs a forward declaration: */ typedef struct MessageTagHandler MessageTagHandler; -#define CLICAP_FLAGS_NONE 0x0 -#define CLICAP_FLAGS_AFFECTS_MTAGS 0x1 /**< Setting this clientcapability can have an effect on which message tags are displayed or their content */ -#define CLICAP_FLAGS_ADVERTISE_ONLY 0x4 +#define CLICAP_FLAGS_NONE 0x0 +#define CLICAP_FLAGS_AFFECTS_MTAGS 0x1 /**< Setting this clientcapability can have an effect on which message tags are displayed or their content */ +#define CLICAP_FLAGS_ADVERTISE_ONLY 0x4 typedef struct ClientCapability ClientCapability; struct ClientCapability { ClientCapability *prev, *next; - char *name; /**< The name of the CAP */ - long cap; /**< The acptr->user->proto we should set (if any, can be 0, like for sts) */ - int flags; /**< A flag from CLICAP_FLAGS_* */ - int (*visible)(Client *); /**< Should the capability be visible? Note: parameter may be NULL. [optional] */ - const char *(*parameter)(Client *); /**< CAP parameters. Note: parameter may be NULL. [optional] */ - MessageTagHandler *mtag_handler; /**< For reverse dependency */ - Module *owner; /**< Module introducing this CAP. */ - char unloaded; /**< Internal flag to indicate module is being unloaded */ - int minimum_cap_version; /**< Minimum CAP version to show this CAP */ + char *name; /**< The name of the CAP */ + long cap; /**< The acptr->user->proto we should set (if any, can be 0, like for sts) */ + int flags; /**< A flag from CLICAP_FLAGS_* */ + int (*visible)(Client *); /**< Should the capability be visible? Note: parameter may be NULL. [optional] */ + const char *(*parameter)(Client *); /**< CAP parameters. Note: parameter may be NULL. [optional] */ + MessageTagHandler *mtag_handler; /**< For reverse dependency */ + Module *owner; /**< Module introducing this CAP. */ + char unloaded; /**< Internal flag to indicate module is being unloaded */ + int minimum_cap_version; /**< Minimum CAP version to show this CAP */ }; typedef struct { @@ -533,25 +532,25 @@ typedef struct { */ /** No special message-tag handler flags */ -#define MTAG_HANDLER_FLAGS_NONE 0x0 +#define MTAG_HANDLER_FLAGS_NONE 0x0 /** This message-tag does not have a CAP REQ xx (eg: for "msgid") */ -#define MTAG_HANDLER_FLAGS_NO_CAP_NEEDED 0x1 +#define MTAG_HANDLER_FLAGS_NO_CAP_NEEDED 0x1 /** This tag should only appear on the first message of the * multiline fallback (for clients that don't support multiline). * Used by "msgid" and "+draft/reply". */ -#define MTAG_HANDLER_FLAGS_FIRST_ONLY 0x2 +#define MTAG_HANDLER_FLAGS_FIRST_ONLY 0x2 /** Message Tag Handler */ struct MessageTagHandler { MessageTagHandler *prev, *next; - char *name; /**< The name of the message-tag */ - int flags; /**< A flag of MTAG_HANDLER_FLAGS_* */ - int (*is_ok)(Client *, const char *, const char *); /**< Verify syntax and access rights */ - int (*should_send_to_client)(Client *); /**< Tag may be sent to this client (normally NULL!) */ - Module *owner; /**< Module introducing this CAP. */ - ClientCapability *clicap_handler; /**< Client capability handler associated with this */ - char unloaded; /**< Internal flag to indicate module is being unloaded */ + char *name; /**< The name of the message-tag */ + int flags; /**< A flag of MTAG_HANDLER_FLAGS_* */ + int (*is_ok)(Client *, const char *, const char *); /**< Verify syntax and access rights */ + int (*should_send_to_client)(Client *); /**< Tag may be sent to this client (normally NULL!) */ + Module *owner; /**< Module introducing this CAP. */ + ClientCapability *clicap_handler; /**< Client capability handler associated with this */ + char unloaded; /**< Internal flag to indicate module is being unloaded */ }; /** The struct used to register a message tag handler. @@ -569,26 +568,26 @@ typedef struct { /** Filter for history: the command / type of the request */ typedef enum HistoryFilterCommand { - HFC_SIMPLE=1, /**< Simple history request for lines / unixtime */ - HFC_BEFORE=2, /**< CHATHISTORY BEFORE */ - HFC_AFTER=3, /**< CHATHISTORY AFTER */ - HFC_LATEST=4, /**< CHATHISTORY LATEST */ - HFC_AROUND=5, /**< CHATHISTORY AROUND */ - HFC_BETWEEN=6 /**< CHATHISTORY BETWEEN */ + HFC_SIMPLE = 1, /**< Simple history request for lines / unixtime */ + HFC_BEFORE = 2, /**< CHATHISTORY BEFORE */ + HFC_AFTER = 3, /**< CHATHISTORY AFTER */ + HFC_LATEST = 4, /**< CHATHISTORY LATEST */ + HFC_AROUND = 5, /**< CHATHISTORY AROUND */ + HFC_BETWEEN = 6 /**< CHATHISTORY BETWEEN */ } HistoryFilterCommand; /** Filter for history get requests */ typedef struct HistoryFilter HistoryFilter; struct HistoryFilter { - HistoryFilterCommand cmd; /**< Filter command, one of HistoryFilterCommand */ - int last_lines; /**< Used by HFC_SIMPLE */ - int last_seconds; /**< Used by HFC_SIMPLE */ - char *timestamp_a; /**< First parameter of HFC_* (either this or msgid_a) */ - char *msgid_a; /**< First parameter of HFC_* (either this or timestamp_a) */ - char *timestamp_b; /**< Second parameter of HFC_BETWEEN (either this or msgid_b) */ - char *msgid_b; /**< Second parameter of HFC_BETWEEN (either this or timestamp_b) */ - char *account; /**< (For deletion only) if not NULL, reject deletion of messages not from this account */ - int limit; /**< Maximum number of lines to return */ + HistoryFilterCommand cmd; /**< Filter command, one of HistoryFilterCommand */ + int last_lines; /**< Used by HFC_SIMPLE */ + int last_seconds; /**< Used by HFC_SIMPLE */ + char *timestamp_a; /**< First parameter of HFC_* (either this or msgid_a) */ + char *msgid_a; /**< First parameter of HFC_* (either this or timestamp_a) */ + char *timestamp_b; /**< Second parameter of HFC_BETWEEN (either this or msgid_b) */ + char *msgid_b; /**< Second parameter of HFC_BETWEEN (either this or timestamp_b) */ + char *account; /**< (For deletion only) if not NULL, reject deletion of messages not from this account */ + int limit; /**< Maximum number of lines to return */ }; /** A single line within a multiline batch. @@ -597,33 +596,33 @@ struct HistoryFilter { typedef struct MLine MLine; struct MLine { MLine *next; - char *text; /**< Message text for this line (may be empty string for blank lines) */ - int concat; /**< 1 if draft/multiline-concat tag was present */ + char *text; /**< Message text for this line (may be empty string for blank lines) */ + int concat; /**< 1 if draft/multiline-concat tag was present */ }; /** History log lines, used by HistoryResult among others */ typedef struct HistoryLogLine HistoryLogLine; struct HistoryLogLine { HistoryLogLine *prev, *next; - HistoryLogLine *next_in_batch; /**< Next line in multiline batch, or NULL for standalone/last-in-batch */ - int num_lines; /**< Number of physical lines: 1 for regular msgs, N for multiline */ - int num_bytes; /**< Total strlen of line(s): for a batch this includes all lines in the batch */ - int concat; /**< 1 if draft/multiline-concat tag was present */ - time_t t; /**< Rounded time on seconds, for quick access. */ - char *msgid; /**< Pointer to 'msgid' mtag. Do NOT free this, it is freed by freeing 'mtags'. */ - char *time; /**< Pointer to 'time' mtag. Do NOT free this, it is freed by freeing 'mtags'. */ - MessageTag *mtags; /**< Message tags associated with this message */ - char line[]; /**< The full (old-skool) IRC protocol line */ + HistoryLogLine *next_in_batch; /**< Next line in multiline batch, or NULL for standalone/last-in-batch */ + int num_lines; /**< Number of physical lines: 1 for regular msgs, N for multiline */ + int num_bytes; /**< Total strlen of line(s): for a batch this includes all lines in the batch */ + int concat; /**< 1 if draft/multiline-concat tag was present */ + time_t t; /**< Rounded time on seconds, for quick access. */ + char *msgid; /**< Pointer to 'msgid' mtag. Do NOT free this, it is freed by freeing 'mtags'. */ + char *time; /**< Pointer to 'time' mtag. Do NOT free this, it is freed by freeing 'mtags'. */ + MessageTag *mtags; /**< Message tags associated with this message */ + char line[]; /**< The full (old-skool) IRC protocol line */ }; typedef struct HistoryResult HistoryResult; struct HistoryResult { - char *object; /**< Name of the history object, eg '#test' */ - HistoryLogLine *log; /**< The resulting log lines */ - HistoryLogLine *log_tail; /**< Last entry in the log lines */ - int num_lines; /**< Total number of lines in the result */ - int num_bytes; /**< Total bytes of all lines in the result */ - int reached_end; /**< Set by backend: 1 = no more history beyond this page, 0 = more may exist (or unknown). Used by the draft/chathistory-end tag. Default 0. */ + char *object; /**< Name of the history object, eg '#test' */ + HistoryLogLine *log; /**< The resulting log lines */ + HistoryLogLine *log_tail; /**< Last entry in the log lines */ + int num_lines; /**< Total number of lines in the result */ + int num_bytes; /**< Total bytes of all lines in the result */ + int reached_end; /**< Set by backend: 1 = no more history beyond this page, 0 = more may exist (or unknown). Used by the draft/chathistory-end tag. Default 0. */ }; /** History Backend */ @@ -668,19 +667,19 @@ typedef struct { */ /** No special flags set */ -#define RPC_HANDLER_FLAGS_NONE 0x0 -#define RPC_HANDLER_FLAGS_UNFILTERED 0x1 /**< Don't filter input (don't reject strings bigger than 510 in length or containing \r or \n) */ +#define RPC_HANDLER_FLAGS_NONE 0x0 +#define RPC_HANDLER_FLAGS_UNFILTERED 0x1 /**< Don't filter input (don't reject strings bigger than 510 in length or containing \r or \n) */ /** RPC Tag Handler */ typedef struct RPCHandler RPCHandler; struct RPCHandler { RPCHandler *prev, *next; - char *method; /**< Name of the method handler, eg "client.get" */ - int flags; /**< A flag of RPC_HANDLER_FLAG_* */ - LogLevel loglevel; /**< Log level to use for this call: for example ULOG_DEBUG for .list calls, leave 0 for default */ - void (*call)(Client *, json_t *request, json_t *params); /**< RPC call: use RPC_CALL_FUNC() ! */ - Module *owner; /**< Module introducing this. */ - char unloaded; /**< Internal flag to indicate module is being unloaded */ + char *method; /**< Name of the method handler, eg "client.get" */ + int flags; /**< A flag of RPC_HANDLER_FLAG_* */ + LogLevel loglevel; /**< Log level to use for this call: for example ULOG_DEBUG for .list calls, leave 0 for default */ + void (*call)(Client *, json_t *request, json_t *params); /**< RPC call: use RPC_CALL_FUNC() ! */ + Module *owner; /**< Module introducing this. */ + char unloaded; /**< Internal flag to indicate module is being unloaded */ }; /** The struct used to register a RPC handler. @@ -702,7 +701,7 @@ typedef struct { * @param params Parameters of the JSON-RPC call * @note You are expected to call rpc_response() or rpc_error() on the request. */ -#define RPC_CALL_FUNC(x) void (x) (Client *client, json_t *request, json_t *params) +#define RPC_CALL_FUNC(x) void(x)(Client * client, json_t * request, json_t * params) /** @} */ @@ -799,10 +798,10 @@ typedef struct ModuleObject { * What we use to keep track internally of the modules */ -#define MODERR_NOERROR 0 -#define MODERR_EXISTS 1 -#define MODERR_NOSPACE 2 -#define MODERR_INVALID 3 +#define MODERR_NOERROR 0 +#define MODERR_EXISTS 1 +#define MODERR_NOSPACE 2 +#define MODERR_INVALID 3 #define MODERR_NOTFOUND 4 extern unsigned int ModuleGetError(Module *module); @@ -810,17 +809,16 @@ extern const char *ModuleGetErrorStr(Module *module); extern unsigned int ModuleGetOptions(Module *module); extern void ModuleSetOptions(Module *module, unsigned int options, int action); -struct Module -{ +struct Module { struct Module *prev, *next; int priority; - ModuleHeader *header; /* The module's header */ + ModuleHeader *header; /* The module's header */ #ifdef _WIN32 - HMODULE dll; /* Return value of LoadLibrary */ + HMODULE dll; /* Return value of LoadLibrary */ #else - void *dll; /* Return value of dlopen */ -#endif - unsigned char flags; /* 8-bits for flags .. [<- this is misleading, there's mod->flags = .. everywhere] */ + void *dll; /* Return value of dlopen */ +#endif + unsigned char flags; /* 8-bits for flags .. [<- this is misleading, there's mod->flags = .. everywhere] */ ModuleChild *children; ModuleObject *objects; ModuleInfo modinfo; /* Used to store handle info for module */ @@ -835,39 +833,39 @@ struct Module * Symbol table */ -#define MOD_OPT_PERM 0x0001 /* Permanent module (not unloadable) */ -#define MOD_OPT_OFFICIAL 0x0002 /* Official module, do not set "tainted" */ -#define MOD_OPT_PERM_RELOADABLE 0x0004 /* Module is semi-permanent: it can be re-loaded but not un-loaded */ -#define MOD_OPT_GLOBAL 0x0008 /* Module is required to be loaded globally (i.e. across the entire network) */ -#define MOD_OPT_PRIORITY 0x1000 /* Module wants a higher or lower priority for unloading, init, load, etc */ -#define MOD_OPT_UNLOAD_PRIORITY 0x1000 /* Alias for MOD_OPT_PRIORITY */ +#define MOD_OPT_PERM 0x0001 /* Permanent module (not unloadable) */ +#define MOD_OPT_OFFICIAL 0x0002 /* Official module, do not set "tainted" */ +#define MOD_OPT_PERM_RELOADABLE 0x0004 /* Module is semi-permanent: it can be re-loaded but not un-loaded */ +#define MOD_OPT_GLOBAL 0x0008 /* Module is required to be loaded globally (i.e. across the entire network) */ +#define MOD_OPT_PRIORITY 0x1000 /* Module wants a higher or lower priority for unloading, init, load, etc */ +#define MOD_OPT_UNLOAD_PRIORITY 0x1000 /* Alias for MOD_OPT_PRIORITY */ -#define MOD_Dep(name, container,module) {#name, (vFP *) &container, module} +#define MOD_Dep(name, container, module) {#name, (vFP *)&container, module} /** Websocket module should init 'first' because it handles sockets */ -#define WEBSOCKET_MODULE_PRIORITY_INIT -1000000000 +#define WEBSOCKET_MODULE_PRIORITY_INIT -1000000000 /** Websocket module should unload 'last' because it handles sockets */ -#define WEBSOCKET_MODULE_PRIORITY_UNLOAD 1000000000 +#define WEBSOCKET_MODULE_PRIORITY_UNLOAD 1000000000 /** Event structs */ struct Event { - Event *prev; /**< Previous event (linked list) */ - Event *next; /**< Next event (linked list) */ - char *name; /**< Name of the event */ - long every_msec; /**< How often we should run this event */ - long count; /**< How many times this event should run (0 = infinite) */ - vFP event; /**< Actual function to call */ - void *data; /**< The data to pass in the function call */ - struct timeval last_run; /**< Last time this event ran */ - char deleted; /**< Set to 1 if this event is marked for deletion */ - Module *owner; /**< To which module this event belongs */ + Event *prev; /**< Previous event (linked list) */ + Event *next; /**< Next event (linked list) */ + char *name; /**< Name of the event */ + long every_msec; /**< How often we should run this event */ + long count; /**< How many times this event should run (0 = infinite) */ + vFP event; /**< Actual function to call */ + void *data; /**< The data to pass in the function call */ + struct timeval last_run; /**< Last time this event ran */ + char deleted; /**< Set to 1 if this event is marked for deletion */ + Module *owner; /**< To which module this event belongs */ }; -#define EMOD_EVERY 0x0001 +#define EMOD_EVERY 0x0001 #define EMOD_HOWMANY 0x0002 -#define EMOD_NAME 0x0004 -#define EMOD_EVENT 0x0008 -#define EMOD_DATA 0x0010 +#define EMOD_NAME 0x0004 +#define EMOD_EVENT 0x0008 +#define EMOD_DATA 0x0010 /** event struct information, for EventMod() only - see Event for documentation */ struct EventInfo { @@ -886,7 +884,7 @@ typedef enum APICallbackType { struct APICallback { APICallback *prev, *next; - char *name; /**< Name of the api callback */ + char *name; /**< Name of the api callback */ Module *owner; /**< To which module this object belongs */ char unloaded; /**< Set to 1 if this object is marked for deletion */ APICallbackType callback_type; @@ -896,14 +894,14 @@ struct APICallback { } callback; /**< The callback itself, obviously chosen by .callback_type */ }; -extern MODVAR Hook *Hooks[MAXHOOKTYPES]; -extern MODVAR Hooktype Hooktypes[MAXCUSTOMHOOKS]; +extern MODVAR Hook *Hooks[MAXHOOKTYPES]; +extern MODVAR Hooktype Hooktypes[MAXCUSTOMHOOKS]; extern MODVAR Callback *Callbacks[MAXCALLBACKS], *RCallbacks[MAXCALLBACKS]; extern MODVAR ClientCapability *clicaps; extern MODVAR long clicaps_affecting_mtag; extern Event *EventAdd(Module *module, const char *name, vFP event, void *data, long every_msec, int count); -extern void EventDel(Event *event); +extern void EventDel(Event *event); extern Event *EventMarkDel(Event *event); extern Event *EventFind(const char *name); extern int EventMod(Event *event, EventInfo *mods); @@ -937,7 +935,7 @@ extern void ISupportSetValue(ISupport *isupport, const char *value); extern void ISupportDel(ISupport *isupport); extern ISupport *ISupportFind(const char *token); extern void ISupportSet(Module *module, const char *name, const char *value); -extern void ISupportSetFmt(Module *module, const char *name, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,3,4))); +extern void ISupportSetFmt(Module *module, const char *name, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 3, 4))); extern void ISupportDelByName(const char *name); extern ClientCapability *ClientCapabilityFind(const char *token, Client *client); @@ -958,7 +956,7 @@ extern RPCHandler *RPCHandlerAdd(Module *module, RPCHandlerInfo *mreq); extern void RPCHandlerDel(RPCHandler *m); #ifndef GCC_TYPECHECKING -/** Add a hook that returns an int. + /** Add a hook that returns an int. * @param module The module adding the hook * @param hooktype The hook type (HOOKTYPE_*) * @param priority Priority for hook execution order. Lower value = called first. Use 0 for normal. @@ -967,8 +965,8 @@ extern void RPCHandlerDel(RPCHandler *m); * @note Call this from MOD_INIT(), except for HOOKTYPE_CONFIGTEST and * HOOKTYPE_CONFIGPOSTTEST hooks which should be added in MOD_TEST(). */ -#define HookAdd(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, func, NULL, NULL, NULL) -/** Add a hook that returns void. + #define HookAdd(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, func, NULL, NULL, NULL) + /** Add a hook that returns void. * @param module The module adding the hook * @param hooktype The hook type (HOOKTYPE_*) * @param priority Priority for hook execution order. Lower value = called first. Use 0 for normal. @@ -977,8 +975,8 @@ extern void RPCHandlerDel(RPCHandler *m); * @note Call this from MOD_INIT(), except for HOOKTYPE_CONFIGTEST and * HOOKTYPE_CONFIGPOSTTEST hooks which should be added in MOD_TEST(). */ -#define HookAddVoid(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, func, NULL, NULL) -/** Add a hook that returns a string (char *). + #define HookAddVoid(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, func, NULL, NULL) + /** Add a hook that returns a string (char *). * @param module The module adding the hook * @param hooktype The hook type (HOOKTYPE_*) * @param priority Priority for hook execution order. Lower value = called first. Use 0 for normal. @@ -987,8 +985,8 @@ extern void RPCHandlerDel(RPCHandler *m); * @note Call this from MOD_INIT(), except for HOOKTYPE_CONFIGTEST and * HOOKTYPE_CONFIGPOSTTEST hooks which should be added in MOD_TEST(). */ -#define HookAddString(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, NULL, func, NULL) -/** Add a hook that returns a const string (const char *). + #define HookAddString(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, NULL, func, NULL) + /** Add a hook that returns a const string (const char *). * @param module The module adding the hook * @param hooktype The hook type (HOOKTYPE_*) * @param priority Priority for hook execution order. Lower value = called first. Use 0 for normal. @@ -997,30 +995,30 @@ extern void RPCHandlerDel(RPCHandler *m); * @note Call this from MOD_INIT(), except for HOOKTYPE_CONFIGTEST and * HOOKTYPE_CONFIGPOSTTEST hooks which should be added in MOD_TEST(). */ -#define HookAddConstString(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, NULL, NULL, func) + #define HookAddConstString(module, hooktype, priority, func) HookAddMain(module, hooktype, priority, NULL, NULL, NULL, func) #else -#define HookAdd(module, hooktype, priority, func) \ -__extension__ ({ \ - ValidateHooks(hooktype, func); \ - HookAddMain(module, hooktype, priority, func, NULL, NULL, NULL); \ -}) + #define HookAdd(module, hooktype, priority, func) \ + __extension__({ \ + ValidateHooks(hooktype, func); \ + HookAddMain(module, hooktype, priority, func, NULL, NULL, NULL); \ + }) -#define HookAddVoid(module, hooktype, priority, func) \ -__extension__ ({ \ - ValidateHooks(hooktype, func); \ - HookAddMain(module, hooktype, priority, NULL, func, NULL, NULL); \ -}) + #define HookAddVoid(module, hooktype, priority, func) \ + __extension__({ \ + ValidateHooks(hooktype, func); \ + HookAddMain(module, hooktype, priority, NULL, func, NULL, NULL); \ + }) -#define HookAddString(module, hooktype, priority, func) \ -__extension__ ({ \ - ValidateHooks(hooktype, func); \ - HookAddMain(module, hooktype, priority, NULL, NULL, func, NULL); \ -}) -#define HookAddConstString(module, hooktype, priority, func) \ -__extension__ ({ \ - ValidateHooks(hooktype, func); \ - HookAddMain(module, hooktype, priority, NULL, NULL, NULL, func); \ -}) + #define HookAddString(module, hooktype, priority, func) \ + __extension__({ \ + ValidateHooks(hooktype, func); \ + HookAddMain(module, hooktype, priority, NULL, NULL, func, NULL); \ + }) + #define HookAddConstString(module, hooktype, priority, func) \ + __extension__({ \ + ValidateHooks(hooktype, func); \ + HookAddMain(module, hooktype, priority, NULL, NULL, NULL, func); \ + }) #endif /* GCC_TYPCHECKING */ /** Add a hook - internal function. @@ -1037,8 +1035,8 @@ __extension__ ({ \ * @note Call this from MOD_INIT(), except for HOOKTYPE_CONFIGTEST and * HOOKTYPE_CONFIGPOSTTEST hooks which should be added in MOD_TEST(). */ -extern Hook *HookAddMain(Module *module, int hooktype, int priority, int (*intfunc)(), void (*voidfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)()); -extern Hook *HookDel(Hook *hook); +extern Hook *HookAddMain(Module *module, int hooktype, int priority, int (*intfunc)(), void (*voidfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)()); +extern Hook *HookDel(Hook *hook); extern Hooktype *HooktypeAdd(Module *module, const char *string, int *type); extern void HooktypeDel(Hooktype *hooktype, Module *module); @@ -1049,23 +1047,30 @@ extern void HooktypeDel(Hooktype *hooktype, Module *module); * @param hooktype The hook type (HOOKTYPE_*) * @param ... Arguments to pass to the hook functions */ -#define RunHook(hooktype,...) do { Hook *h; for (h = Hooks[hooktype]; h; h = h->next) (*(h->func.intfunc))(__VA_ARGS__); } while(0) +#define RunHook(hooktype, ...) \ + do \ + { \ + Hook *h; \ + for (h = Hooks[hooktype]; h; h = h->next) \ + (*(h->func.intfunc))(__VA_ARGS__); \ + } while (0) /** Run all hooks for a given hook type, returning early from the calling function * if a hook signals to stop processing (used by the IRCd core to call modules). * @param hooktype The hook type (HOOKTYPE_*) * @param retchk Condition on return value to stop processing, eg != 0 * @param ... Arguments to pass to the hook functions */ -#define RunHookReturn(hooktype,retchk,...) \ -{ \ - int retval; \ - Hook *h; \ - for (h = Hooks[hooktype]; h; h = h->next) \ - { \ - retval = (*(h->func.intfunc))(__VA_ARGS__); \ - if (retval retchk) return; \ - } \ -} +#define RunHookReturn(hooktype, retchk, ...) \ + { \ + int retval; \ + Hook *h; \ + for (h = Hooks[hooktype]; h; h = h->next) \ + { \ + retval = (*(h->func.intfunc))(__VA_ARGS__); \ + if (retval retchk) \ + return; \ + } \ + } /** Run all hooks for a given hook type, returning the hook's return value from * the calling function if a hook signals to stop processing * (used by the IRCd core to call modules). @@ -1074,16 +1079,17 @@ extern void HooktypeDel(Hooktype *hooktype, Module *module); * @param ... Arguments to pass to the hook functions * @returns The return value of the hook function that triggered the early return */ -#define RunHookReturnInt(hooktype,retchk,...) \ -{ \ - int retval; \ - Hook *h; \ - for (h = Hooks[hooktype]; h; h = h->next) \ - { \ - retval = (*(h->func.intfunc))(__VA_ARGS__); \ - if (retval retchk) return retval; \ - } \ -} +#define RunHookReturnInt(hooktype, retchk, ...) \ + { \ + int retval; \ + Hook *h; \ + for (h = Hooks[hooktype]; h; h = h->next) \ + { \ + retval = (*(h->func.intfunc))(__VA_ARGS__); \ + if (retval retchk) \ + return retval; \ + } \ + } /** Add a callback that returns an int. * @param module The module adding the callback @@ -1132,7 +1138,7 @@ extern void HooktypeDel(Hooktype *hooktype, Module *module); #define CallbackAddConstString(module, cbtype, func) CallbackAddMain(module, cbtype, NULL, NULL, NULL, NULL, func) extern Callback *CallbackAddMain(Module *module, int cbtype, int (*func)(), void (*vfunc)(), void *(*pvfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)()); -extern Callback *CallbackDel(Callback *cb); +extern Callback *CallbackDel(Callback *cb); /** Add an efunction that returns an int. * @param module The module adding the efunction @@ -1212,7 +1218,7 @@ extern void CallCommandOverride(CommandOverride *ovr, ClientContext *clictx, Cli * in future UnrealIRCd versions. * @note Can only be used inside a CMD_OVERRIDE_FUNC() function. */ -#define CALL_NEXT_COMMAND_OVERRIDE() CallCommandOverride(ovr, clictx, client, recv_mtags, parc, parv) +#define CALL_NEXT_COMMAND_OVERRIDE() CallCommandOverride(ovr, clictx, client, recv_mtags, parc, parv) extern void moddata_free_client(Client *acptr); extern void moddata_free_local_client(Client *acptr); @@ -1297,14 +1303,15 @@ extern void APICallbackDel(APICallback *m); extern APICallback *APICallbackAdd(Module *module, APICallback *mreq); #define RegisterApiCallback(modhandle, api_callback_type, api_callback_function, api_name, api_func) \ - do { \ + do \ + { \ APICallback req; \ memset(&req, 0, sizeof(req)); \ req.name = api_name; \ req.callback_type = api_callback_type; \ req.callback.api_callback_function = api_func; \ APICallbackAdd(modhandle, &req); \ - } while(0) + } while (0) #define RegisterApiCallbackWebResponse(modhandle, api_name, api_func) \ RegisterApiCallback(modhandle, API_CALLBACK_WEB_RESPONSE, web_response, api_name, api_func) @@ -1324,261 +1331,261 @@ extern APICallback *APICallbackAdd(Module *module, APICallback *mreq); /* Hook types */ /** See hooktype_pre_local_connect() */ -#define HOOKTYPE_PRE_LOCAL_CONNECT 1 +#define HOOKTYPE_PRE_LOCAL_CONNECT 1 /** See hooktype_local_connect() */ -#define HOOKTYPE_LOCAL_CONNECT 2 +#define HOOKTYPE_LOCAL_CONNECT 2 /** See hooktype_remote_connect() */ -#define HOOKTYPE_REMOTE_CONNECT 3 +#define HOOKTYPE_REMOTE_CONNECT 3 /** See hooktype_pre_local_quit() */ -#define HOOKTYPE_PRE_LOCAL_QUIT 4 +#define HOOKTYPE_PRE_LOCAL_QUIT 4 /** See hooktype_local_quit() */ -#define HOOKTYPE_LOCAL_QUIT 5 +#define HOOKTYPE_LOCAL_QUIT 5 /** See hooktype_remote_quit() */ -#define HOOKTYPE_REMOTE_QUIT 6 +#define HOOKTYPE_REMOTE_QUIT 6 /** See hooktype_unkuser_quit() */ -#define HOOKTYPE_UNKUSER_QUIT 7 +#define HOOKTYPE_UNKUSER_QUIT 7 /** See hooktype_server_connect() */ -#define HOOKTYPE_SERVER_CONNECT 8 +#define HOOKTYPE_SERVER_CONNECT 8 /** See hooktype_server_handshake_out() */ -#define HOOKTYPE_SERVER_HANDSHAKE_OUT 9 +#define HOOKTYPE_SERVER_HANDSHAKE_OUT 9 /** See hooktype_server_sync() */ -#define HOOKTYPE_SERVER_SYNC 10 +#define HOOKTYPE_SERVER_SYNC 10 /** See hooktype_post_server_connect() */ -#define HOOKTYPE_POST_SERVER_CONNECT 11 +#define HOOKTYPE_POST_SERVER_CONNECT 11 /** See hooktype_server_synced() */ -#define HOOKTYPE_SERVER_SYNCED 12 +#define HOOKTYPE_SERVER_SYNCED 12 /** See hooktype_server_quit() */ -#define HOOKTYPE_SERVER_QUIT 13 +#define HOOKTYPE_SERVER_QUIT 13 /** See hooktype_local_nickchange() */ -#define HOOKTYPE_LOCAL_NICKCHANGE 14 +#define HOOKTYPE_LOCAL_NICKCHANGE 14 /** See hooktype_remote_nickchange() */ -#define HOOKTYPE_REMOTE_NICKCHANGE 15 +#define HOOKTYPE_REMOTE_NICKCHANGE 15 /** See hooktype_can_join() */ -#define HOOKTYPE_CAN_JOIN 16 +#define HOOKTYPE_CAN_JOIN 16 /** See hooktype_pre_local_join() */ -#define HOOKTYPE_PRE_LOCAL_JOIN 17 +#define HOOKTYPE_PRE_LOCAL_JOIN 17 /** See hooktype_local_join() */ -#define HOOKTYPE_LOCAL_JOIN 18 +#define HOOKTYPE_LOCAL_JOIN 18 /** See hooktype_remote_join() */ -#define HOOKTYPE_REMOTE_JOIN 19 +#define HOOKTYPE_REMOTE_JOIN 19 /** See hooktype_pre_local_part() */ -#define HOOKTYPE_PRE_LOCAL_PART 20 +#define HOOKTYPE_PRE_LOCAL_PART 20 /** See hooktype_local_part() */ -#define HOOKTYPE_LOCAL_PART 21 +#define HOOKTYPE_LOCAL_PART 21 /** See hooktype_remote_part() */ -#define HOOKTYPE_REMOTE_PART 22 +#define HOOKTYPE_REMOTE_PART 22 /** See hooktype_pre_local_kick() */ -#define HOOKTYPE_PRE_LOCAL_KICK 23 +#define HOOKTYPE_PRE_LOCAL_KICK 23 /** See hooktype_can_kick() */ -#define HOOKTYPE_CAN_KICK 24 +#define HOOKTYPE_CAN_KICK 24 /** See hooktype_local_kick() */ -#define HOOKTYPE_LOCAL_KICK 25 +#define HOOKTYPE_LOCAL_KICK 25 /** See hooktype_remote_kick() */ -#define HOOKTYPE_REMOTE_KICK 26 +#define HOOKTYPE_REMOTE_KICK 26 /** See hooktype_pre_chanmsg() */ -#define HOOKTYPE_PRE_CHANMSG 28 +#define HOOKTYPE_PRE_CHANMSG 28 /** See hooktype_can_send_to_user() */ -#define HOOKTYPE_CAN_SEND_TO_USER 29 +#define HOOKTYPE_CAN_SEND_TO_USER 29 /** See hooktype_can_send_to_channel() */ -#define HOOKTYPE_CAN_SEND_TO_CHANNEL 30 +#define HOOKTYPE_CAN_SEND_TO_CHANNEL 30 /** See hooktype_usermsg() */ -#define HOOKTYPE_USERMSG 31 +#define HOOKTYPE_USERMSG 31 /** See hooktype_chanmsg() */ -#define HOOKTYPE_CHANMSG 32 +#define HOOKTYPE_CHANMSG 32 /** See hooktype_pre_local_topic() */ -#define HOOKTYPE_PRE_LOCAL_TOPIC 33 +#define HOOKTYPE_PRE_LOCAL_TOPIC 33 /** See hooktype_topic() */ -#define HOOKTYPE_TOPIC 35 +#define HOOKTYPE_TOPIC 35 /** See hooktype_pre_local_chanmode() */ -#define HOOKTYPE_PRE_LOCAL_CHANMODE 36 +#define HOOKTYPE_PRE_LOCAL_CHANMODE 36 /** See hooktype_pre_remote_chanmode() */ -#define HOOKTYPE_PRE_REMOTE_CHANMODE 37 +#define HOOKTYPE_PRE_REMOTE_CHANMODE 37 /** See hooktype_local_chanmode() */ -#define HOOKTYPE_LOCAL_CHANMODE 38 +#define HOOKTYPE_LOCAL_CHANMODE 38 /** See hooktype_remote_chanmode() */ -#define HOOKTYPE_REMOTE_CHANMODE 39 +#define HOOKTYPE_REMOTE_CHANMODE 39 /** See hooktype_modechar_del() */ -#define HOOKTYPE_MODECHAR_DEL 40 +#define HOOKTYPE_MODECHAR_DEL 40 /** See hooktype_modechar_add() */ -#define HOOKTYPE_MODECHAR_ADD 41 +#define HOOKTYPE_MODECHAR_ADD 41 /** See hooktype_away() */ -#define HOOKTYPE_AWAY 42 +#define HOOKTYPE_AWAY 42 /** See hooktype_pre_invite() */ -#define HOOKTYPE_PRE_INVITE 43 +#define HOOKTYPE_PRE_INVITE 43 /** See hooktype_invite() */ -#define HOOKTYPE_INVITE 44 +#define HOOKTYPE_INVITE 44 /** See hooktype_pre_knock() */ -#define HOOKTYPE_PRE_KNOCK 45 +#define HOOKTYPE_PRE_KNOCK 45 /** See hooktype_knock() */ -#define HOOKTYPE_KNOCK 46 +#define HOOKTYPE_KNOCK 46 /** See hooktype_whois() */ -#define HOOKTYPE_WHOIS 47 +#define HOOKTYPE_WHOIS 47 /** See hooktype_who_status() */ -#define HOOKTYPE_WHO_STATUS 48 +#define HOOKTYPE_WHO_STATUS 48 /** See hooktype_pre_kill() */ -#define HOOKTYPE_PRE_KILL 49 +#define HOOKTYPE_PRE_KILL 49 /** See hooktype_local_kill() */ -#define HOOKTYPE_LOCAL_KILL 50 +#define HOOKTYPE_LOCAL_KILL 50 /** See hooktype_rehashflag() */ -#define HOOKTYPE_REHASHFLAG 51 +#define HOOKTYPE_REHASHFLAG 51 /** See hooktype_configposttest() */ -#define HOOKTYPE_CONFIGPOSTTEST 52 +#define HOOKTYPE_CONFIGPOSTTEST 52 /** See hooktype_rehash() */ -#define HOOKTYPE_REHASH 53 +#define HOOKTYPE_REHASH 53 /** See hooktype_rehash_complete() */ -#define HOOKTYPE_REHASH_COMPLETE 54 +#define HOOKTYPE_REHASH_COMPLETE 54 /** See hooktype_configtest() */ -#define HOOKTYPE_CONFIGTEST 55 +#define HOOKTYPE_CONFIGTEST 55 /** See hooktype_configrun() */ -#define HOOKTYPE_CONFIGRUN 56 +#define HOOKTYPE_CONFIGRUN 56 /** See hooktype_configrun_ex() */ -#define HOOKTYPE_CONFIGRUN_EX 57 +#define HOOKTYPE_CONFIGRUN_EX 57 /** See hooktype_stats() */ -#define HOOKTYPE_STATS 58 +#define HOOKTYPE_STATS 58 /** See hooktype_local_oper() */ -#define HOOKTYPE_LOCAL_OPER 59 +#define HOOKTYPE_LOCAL_OPER 59 /** See hooktype_local_pass() */ -#define HOOKTYPE_LOCAL_PASS 60 +#define HOOKTYPE_LOCAL_PASS 60 /** See hooktype_channel_create() */ -#define HOOKTYPE_CHANNEL_CREATE 61 +#define HOOKTYPE_CHANNEL_CREATE 61 /** See hooktype_channel_destroy() */ -#define HOOKTYPE_CHANNEL_DESTROY 62 +#define HOOKTYPE_CHANNEL_DESTROY 62 /** See hooktype_tkl_except() */ -#define HOOKTYPE_TKL_EXCEPT 63 +#define HOOKTYPE_TKL_EXCEPT 63 /** See hooktype_umode_change() */ -#define HOOKTYPE_UMODE_CHANGE 64 +#define HOOKTYPE_UMODE_CHANGE 64 /** See hooktype_tkl_add() */ -#define HOOKTYPE_TKL_ADD 65 +#define HOOKTYPE_TKL_ADD 65 /** See hooktype_tkl_del() */ -#define HOOKTYPE_TKL_DEL 66 +#define HOOKTYPE_TKL_DEL 66 /** See hooktype_log() */ -#define HOOKTYPE_LOG 67 +#define HOOKTYPE_LOG 67 /** See hooktype_local_spamfilter() */ -#define HOOKTYPE_LOCAL_SPAMFILTER 68 +#define HOOKTYPE_LOCAL_SPAMFILTER 68 /** See hooktype_silenced() */ -#define HOOKTYPE_SILENCED 69 +#define HOOKTYPE_SILENCED 69 /** See hooktype_rawpacket_in() */ -#define HOOKTYPE_RAWPACKET_IN 70 +#define HOOKTYPE_RAWPACKET_IN 70 /** See hooktype_packet() */ -#define HOOKTYPE_PACKET 71 +#define HOOKTYPE_PACKET 71 /** See hooktype_handshake() */ -#define HOOKTYPE_HANDSHAKE 72 +#define HOOKTYPE_HANDSHAKE 72 /** See hooktype_free_client() */ -#define HOOKTYPE_FREE_CLIENT 73 +#define HOOKTYPE_FREE_CLIENT 73 /** See hooktype_free_user() */ -#define HOOKTYPE_FREE_USER 74 +#define HOOKTYPE_FREE_USER 74 /** See hooktype_can_join_limitexceeded() */ -#define HOOKTYPE_CAN_JOIN_LIMITEXCEEDED 75 +#define HOOKTYPE_CAN_JOIN_LIMITEXCEEDED 75 /** See hooktype_see_channel_in_whois() */ -#define HOOKTYPE_SEE_CHANNEL_IN_WHOIS 77 +#define HOOKTYPE_SEE_CHANNEL_IN_WHOIS 77 /** See hooktype_join_data() */ -#define HOOKTYPE_JOIN_DATA 78 +#define HOOKTYPE_JOIN_DATA 78 /** See hooktype_invite_bypass() */ -#define HOOKTYPE_INVITE_BYPASS 79 +#define HOOKTYPE_INVITE_BYPASS 79 /** See hooktype_view_topic_outside_channel() */ -#define HOOKTYPE_VIEW_TOPIC_OUTSIDE_CHANNEL 80 +#define HOOKTYPE_VIEW_TOPIC_OUTSIDE_CHANNEL 80 /** See hooktype_chan_permit_nick_change() */ -#define HOOKTYPE_CHAN_PERMIT_NICK_CHANGE 81 +#define HOOKTYPE_CHAN_PERMIT_NICK_CHANGE 81 /** See hooktype_is_channel_secure() */ -#define HOOKTYPE_IS_CHANNEL_SECURE 82 +#define HOOKTYPE_IS_CHANNEL_SECURE 82 /** See hooktype_channel_synced() */ -#define HOOKTYPE_CHANNEL_SYNCED 83 +#define HOOKTYPE_CHANNEL_SYNCED 83 /** See hooktype_can_sajoin() */ -#define HOOKTYPE_CAN_SAJOIN 84 +#define HOOKTYPE_CAN_SAJOIN 84 /** See hooktype_mode_deop() */ -#define HOOKTYPE_MODE_DEOP 86 +#define HOOKTYPE_MODE_DEOP 86 /** See hooktype_dcc_denied() */ -#define HOOKTYPE_DCC_DENIED 87 +#define HOOKTYPE_DCC_DENIED 87 /** See hooktype_secure_connect() */ -#define HOOKTYPE_SECURE_CONNECT 88 +#define HOOKTYPE_SECURE_CONNECT 88 /** See hooktype_can_bypass_channel_message_restriction() */ -#define HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION 89 +#define HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION 89 /** See hooktype_sasl_continuation() */ -#define HOOKTYPE_SASL_CONTINUATION 91 +#define HOOKTYPE_SASL_CONTINUATION 91 /** See hooktype_sasl_result() */ -#define HOOKTYPE_SASL_RESULT 92 +#define HOOKTYPE_SASL_RESULT 92 /** See hooktype_take_action() */ -#define HOOKTYPE_TAKE_ACTION 93 +#define HOOKTYPE_TAKE_ACTION 93 /** See hooktype_find_tkline_match() */ -#define HOOKTYPE_FIND_TKLINE_MATCH 94 +#define HOOKTYPE_FIND_TKLINE_MATCH 94 /** See hooktype_welcome() */ -#define HOOKTYPE_WELCOME 95 +#define HOOKTYPE_WELCOME 95 /** See hooktype_pre_command() */ -#define HOOKTYPE_PRE_COMMAND 96 +#define HOOKTYPE_PRE_COMMAND 96 /** See hooktype_post_command() */ -#define HOOKTYPE_POST_COMMAND 97 +#define HOOKTYPE_POST_COMMAND 97 /** See hooktype_new_message() */ -#define HOOKTYPE_NEW_MESSAGE 98 +#define HOOKTYPE_NEW_MESSAGE 98 /** See hooktype_is_handshake_finished() */ -#define HOOKTYPE_IS_HANDSHAKE_FINISHED 99 +#define HOOKTYPE_IS_HANDSHAKE_FINISHED 99 /** See hooktype_pre_local_quit_chan() */ -#define HOOKTYPE_PRE_LOCAL_QUIT_CHAN 100 +#define HOOKTYPE_PRE_LOCAL_QUIT_CHAN 100 /** See hooktype_ident_lookup() */ -#define HOOKTYPE_IDENT_LOOKUP 101 +#define HOOKTYPE_IDENT_LOOKUP 101 /** See hooktype_account_login() */ -#define HOOKTYPE_ACCOUNT_LOGIN 102 +#define HOOKTYPE_ACCOUNT_LOGIN 102 /** See hooktype_close_connection() */ -#define HOOKTYPE_CLOSE_CONNECTION 103 +#define HOOKTYPE_CLOSE_CONNECTION 103 /** See hooktype_connect_extinfo() */ -#define HOOKTYPE_CONNECT_EXTINFO 104 +#define HOOKTYPE_CONNECT_EXTINFO 104 /** See hooktype_is_invited() */ -#define HOOKTYPE_IS_INVITED 105 +#define HOOKTYPE_IS_INVITED 105 /** See hooktype_post_local_nickchange() */ -#define HOOKTYPE_POST_LOCAL_NICKCHANGE 106 +#define HOOKTYPE_POST_LOCAL_NICKCHANGE 106 /** See hooktype_post_remote_nickchange() */ -#define HOOKTYPE_POST_REMOTE_NICKCHANGE 107 +#define HOOKTYPE_POST_REMOTE_NICKCHANGE 107 /** See hooktype_userhost_change() */ #define HOOKTYPE_USERHOST_CHANGE 108 /** See hooktype_realname_change() */ #define HOOKTYPE_REALNAME_CHANGE 109 /** See hooktype_can_set_topic() */ -#define HOOKTYPE_CAN_SET_TOPIC 110 +#define HOOKTYPE_CAN_SET_TOPIC 110 /** See hooktype_ip_change() */ -#define HOOKTYPE_IP_CHANGE 111 +#define HOOKTYPE_IP_CHANGE 111 /** See hooktype_json_expand_client() */ -#define HOOKTYPE_JSON_EXPAND_CLIENT 112 +#define HOOKTYPE_JSON_EXPAND_CLIENT 112 /** See hooktype_json_expand_client() */ -#define HOOKTYPE_JSON_EXPAND_CLIENT_USER 113 +#define HOOKTYPE_JSON_EXPAND_CLIENT_USER 113 /** See hooktype_json_expand_client() */ -#define HOOKTYPE_JSON_EXPAND_CLIENT_SERVER 114 +#define HOOKTYPE_JSON_EXPAND_CLIENT_SERVER 114 /** See hooktype_json_expand_channel() */ -#define HOOKTYPE_JSON_EXPAND_CHANNEL 115 +#define HOOKTYPE_JSON_EXPAND_CHANNEL 115 /** See hooktype_accept() */ -#define HOOKTYPE_ACCEPT 116 +#define HOOKTYPE_ACCEPT 116 /** See hooktype_pre_local_handshake_timeout */ -#define HOOKTYPE_PRE_LOCAL_HANDSHAKE_TIMEOUT 117 +#define HOOKTYPE_PRE_LOCAL_HANDSHAKE_TIMEOUT 117 /** See hooktype_rehash_log */ -#define HOOKTYPE_REHASH_LOG 118 +#define HOOKTYPE_REHASH_LOG 118 /** See hooktype_dns_finished */ -#define HOOKTYPE_DNS_FINISHED 119 +#define HOOKTYPE_DNS_FINISHED 119 /** See hooktype_reconfigure_web_listener */ -#define HOOKTYPE_CONFIG_LISTENER 120 +#define HOOKTYPE_CONFIG_LISTENER 120 /** See hooktype_watch_add */ -#define HOOKTYPE_WATCH_ADD 121 +#define HOOKTYPE_WATCH_ADD 121 /** See hooktype_watch_del */ -#define HOOKTYPE_WATCH_DEL 122 +#define HOOKTYPE_WATCH_DEL 122 /** See hooktype_monitor_notification */ -#define HOOKTYPE_MONITOR_NOTIFICATION 123 +#define HOOKTYPE_MONITOR_NOTIFICATION 123 /** See hooktype_sasl_authenticate */ -#define HOOKTYPE_SASL_AUTHENTICATE 124 +#define HOOKTYPE_SASL_AUTHENTICATE 124 /** See hooktype_sasl_mechs */ -#define HOOKTYPE_SASL_MECHS 125 +#define HOOKTYPE_SASL_MECHS 125 /* See hooktype_allow_client */ -#define HOOKTYPE_ALLOW_CLIENT 126 +#define HOOKTYPE_ALLOW_CLIENT 126 /** See hooktype_analyze_text */ -#define HOOKTYPE_ANALYZE_TEXT 127 +#define HOOKTYPE_ANALYZE_TEXT 127 /** See hooktype_can_use_nick */ -#define HOOKTYPE_CAN_USE_NICK 128 +#define HOOKTYPE_CAN_USE_NICK 128 /** See hooktype_banned_client */ #define HOOKTYPE_BANNED_CLIENT 129 /** See hooktype_motd */ #define HOOKTYPE_MOTD 130 /** See hooktype_known_user_cache_change() */ -#define HOOKTYPE_KNOWN_USER_CACHE_CHANGE 131 +#define HOOKTYPE_KNOWN_USER_CACHE_CHANGE 131 /** See hooktype_chanmsg_multiline() */ -#define HOOKTYPE_CHANMSG_MULTILINE 132 +#define HOOKTYPE_CHANMSG_MULTILINE 132 /** See hooktype_postconf() */ -#define HOOKTYPE_POSTCONF 133 +#define HOOKTYPE_POSTCONF 133 /* Adding a new hook here? @@ -2772,153 +2779,153 @@ int hooktype_known_user_cache_change(Client *client); /** @} */ #ifdef GCC_TYPECHECKING -#define ValidateHook(validatefunc, func) __builtin_types_compatible_p(__typeof__(func), __typeof__(validatefunc)) + #define ValidateHook(validatefunc, func) __builtin_types_compatible_p(__typeof__(func), __typeof__(validatefunc)) _UNREAL_ERROR(_hook_error_incompatible, "Incompatible hook function. Check arguments and return type of function.") -#define ValidateHooks(hooktype, func) \ - if (((hooktype == HOOKTYPE_LOCAL_QUIT) && !ValidateHook(hooktype_local_quit, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_NICKCHANGE) && !ValidateHook(hooktype_local_nickchange, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_CONNECT) && !ValidateHook(hooktype_local_connect, func)) || \ - ((hooktype == HOOKTYPE_REHASHFLAG) && !ValidateHook(hooktype_rehashflag, func)) || \ - ((hooktype == HOOKTYPE_PRE_LOCAL_PART) && !ValidateHook(hooktype_pre_local_part, func)) || \ - ((hooktype == HOOKTYPE_CONFIGPOSTTEST) && !ValidateHook(hooktype_configposttest, func)) || \ - ((hooktype == HOOKTYPE_REHASH) && !ValidateHook(hooktype_rehash, func)) || \ - ((hooktype == HOOKTYPE_PRE_LOCAL_CONNECT) && !ValidateHook(hooktype_pre_local_connect, func)) || \ - ((hooktype == HOOKTYPE_PRE_LOCAL_QUIT) && !ValidateHook(hooktype_pre_local_quit, func)) || \ - ((hooktype == HOOKTYPE_SERVER_CONNECT) && !ValidateHook(hooktype_server_connect, func)) || \ - ((hooktype == HOOKTYPE_SERVER_SYNC) && !ValidateHook(hooktype_server_sync, func)) || \ - ((hooktype == HOOKTYPE_SERVER_QUIT) && !ValidateHook(hooktype_server_quit, func)) || \ - ((hooktype == HOOKTYPE_STATS) && !ValidateHook(hooktype_stats, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_JOIN) && !ValidateHook(hooktype_local_join, func)) || \ - ((hooktype == HOOKTYPE_CONFIGTEST) && !ValidateHook(hooktype_configtest, func)) || \ - ((hooktype == HOOKTYPE_CONFIGRUN) && !ValidateHook(hooktype_configrun, func)) || \ - ((hooktype == HOOKTYPE_USERMSG) && !ValidateHook(hooktype_usermsg, func)) || \ - ((hooktype == HOOKTYPE_CHANMSG) && !ValidateHook(hooktype_chanmsg, func)) || \ - ((hooktype == HOOKTYPE_CHANMSG_MULTILINE) && !ValidateHook(hooktype_chanmsg_multiline, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_PART) && !ValidateHook(hooktype_local_part, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_KICK) && !ValidateHook(hooktype_local_kick, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_CHANMODE) && !ValidateHook(hooktype_local_chanmode, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_OPER) && !ValidateHook(hooktype_local_oper, func)) || \ - ((hooktype == HOOKTYPE_UNKUSER_QUIT) && !ValidateHook(hooktype_unkuser_quit, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_PASS) && !ValidateHook(hooktype_local_pass, func)) || \ - ((hooktype == HOOKTYPE_REMOTE_CONNECT) && !ValidateHook(hooktype_remote_connect, func)) || \ - ((hooktype == HOOKTYPE_REMOTE_QUIT) && !ValidateHook(hooktype_remote_quit, func)) || \ - ((hooktype == HOOKTYPE_PRE_LOCAL_JOIN) && !ValidateHook(hooktype_pre_local_join, func)) || \ - ((hooktype == HOOKTYPE_PRE_LOCAL_KICK) && !ValidateHook(hooktype_pre_local_kick, func)) || \ - ((hooktype == HOOKTYPE_CAN_SET_TOPIC) && !ValidateHook(hooktype_can_set_topic, func)) || \ - ((hooktype == HOOKTYPE_PRE_LOCAL_TOPIC) && !ValidateHook(hooktype_pre_local_topic, func)) || \ - ((hooktype == HOOKTYPE_REMOTE_NICKCHANGE) && !ValidateHook(hooktype_remote_nickchange, func)) || \ - ((hooktype == HOOKTYPE_CHANNEL_CREATE) && !ValidateHook(hooktype_channel_create, func)) || \ - ((hooktype == HOOKTYPE_CHANNEL_DESTROY) && !ValidateHook(hooktype_channel_destroy, func)) || \ - ((hooktype == HOOKTYPE_REMOTE_CHANMODE) && !ValidateHook(hooktype_remote_chanmode, func)) || \ - ((hooktype == HOOKTYPE_TKL_EXCEPT) && !ValidateHook(hooktype_tkl_except, func)) || \ - ((hooktype == HOOKTYPE_UMODE_CHANGE) && !ValidateHook(hooktype_umode_change, func)) || \ - ((hooktype == HOOKTYPE_TOPIC) && !ValidateHook(hooktype_topic, func)) || \ - ((hooktype == HOOKTYPE_REHASH_COMPLETE) && !ValidateHook(hooktype_rehash_complete, func)) || \ - ((hooktype == HOOKTYPE_POSTCONF) && !ValidateHook(hooktype_postconf, func)) || \ - ((hooktype == HOOKTYPE_TKL_ADD) && !ValidateHook(hooktype_tkl_add, func)) || \ - ((hooktype == HOOKTYPE_TKL_DEL) && !ValidateHook(hooktype_tkl_del, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_KILL) && !ValidateHook(hooktype_local_kill, func)) || \ - ((hooktype == HOOKTYPE_LOG) && !ValidateHook(hooktype_log, func)) || \ - ((hooktype == HOOKTYPE_REMOTE_JOIN) && !ValidateHook(hooktype_remote_join, func)) || \ - ((hooktype == HOOKTYPE_REMOTE_PART) && !ValidateHook(hooktype_remote_part, func)) || \ - ((hooktype == HOOKTYPE_REMOTE_KICK) && !ValidateHook(hooktype_remote_kick, func)) || \ - ((hooktype == HOOKTYPE_LOCAL_SPAMFILTER) && !ValidateHook(hooktype_local_spamfilter, func)) || \ - ((hooktype == HOOKTYPE_SILENCED) && !ValidateHook(hooktype_silenced, func)) || \ - ((hooktype == HOOKTYPE_POST_SERVER_CONNECT) && !ValidateHook(hooktype_post_server_connect, func)) || \ - ((hooktype == HOOKTYPE_RAWPACKET_IN) && !ValidateHook(hooktype_rawpacket_in, func)) || \ - ((hooktype == HOOKTYPE_PACKET) && !ValidateHook(hooktype_packet, func)) || \ - ((hooktype == HOOKTYPE_HANDSHAKE) && !ValidateHook(hooktype_handshake, func)) || \ - ((hooktype == HOOKTYPE_AWAY) && !ValidateHook(hooktype_away, func)) || \ - ((hooktype == HOOKTYPE_INVITE) && !ValidateHook(hooktype_invite, func)) || \ - ((hooktype == HOOKTYPE_CAN_JOIN) && !ValidateHook(hooktype_can_join, func)) || \ - ((hooktype == HOOKTYPE_CAN_SEND_TO_CHANNEL) && !ValidateHook(hooktype_can_send_to_channel, func)) || \ - ((hooktype == HOOKTYPE_CAN_SEND_TO_USER) && !ValidateHook(hooktype_can_send_to_user, func)) || \ - ((hooktype == HOOKTYPE_CAN_KICK) && !ValidateHook(hooktype_can_kick, func)) || \ - ((hooktype == HOOKTYPE_FREE_CLIENT) && !ValidateHook(hooktype_free_client, func)) || \ - ((hooktype == HOOKTYPE_FREE_USER) && !ValidateHook(hooktype_free_user, func)) || \ - ((hooktype == HOOKTYPE_PRE_CHANMSG) && !ValidateHook(hooktype_pre_chanmsg, func)) || \ - ((hooktype == HOOKTYPE_KNOCK) && !ValidateHook(hooktype_knock, func)) || \ - ((hooktype == HOOKTYPE_MODECHAR_ADD) && !ValidateHook(hooktype_modechar_add, func)) || \ - ((hooktype == HOOKTYPE_MODECHAR_DEL) && !ValidateHook(hooktype_modechar_del, func)) || \ - ((hooktype == HOOKTYPE_CAN_JOIN_LIMITEXCEEDED) && !ValidateHook(hooktype_can_join_limitexceeded, func)) || \ - ((hooktype == HOOKTYPE_PRE_LOCAL_CHANMODE) && !ValidateHook(hooktype_pre_local_chanmode, func)) || \ - ((hooktype == HOOKTYPE_PRE_REMOTE_CHANMODE) && !ValidateHook(hooktype_pre_remote_chanmode, func)) || \ - ((hooktype == HOOKTYPE_JOIN_DATA) && !ValidateHook(hooktype_join_data, func)) || \ - ((hooktype == HOOKTYPE_PRE_KNOCK) && !ValidateHook(hooktype_pre_knock, func)) || \ - ((hooktype == HOOKTYPE_PRE_INVITE) && !ValidateHook(hooktype_pre_invite, func)) || \ - ((hooktype == HOOKTYPE_INVITE_BYPASS) && !ValidateHook(hooktype_invite_bypass, func)) || \ - ((hooktype == HOOKTYPE_VIEW_TOPIC_OUTSIDE_CHANNEL) && !ValidateHook(hooktype_view_topic_outside_channel, func)) || \ - ((hooktype == HOOKTYPE_CHAN_PERMIT_NICK_CHANGE) && !ValidateHook(hooktype_chan_permit_nick_change, func)) || \ - ((hooktype == HOOKTYPE_IS_CHANNEL_SECURE) && !ValidateHook(hooktype_is_channel_secure, func)) || \ - ((hooktype == HOOKTYPE_CHANNEL_SYNCED) && !ValidateHook(hooktype_channel_synced, func)) || \ - ((hooktype == HOOKTYPE_CAN_SAJOIN) && !ValidateHook(hooktype_can_sajoin, func)) || \ - ((hooktype == HOOKTYPE_WHOIS) && !ValidateHook(hooktype_whois, func)) || \ - ((hooktype == HOOKTYPE_WHO_STATUS) && !ValidateHook(hooktype_who_status, func)) || \ - ((hooktype == HOOKTYPE_MODE_DEOP) && !ValidateHook(hooktype_mode_deop, func)) || \ - ((hooktype == HOOKTYPE_PRE_KILL) && !ValidateHook(hooktype_pre_kill, func)) || \ - ((hooktype == HOOKTYPE_SEE_CHANNEL_IN_WHOIS) && !ValidateHook(hooktype_see_channel_in_whois, func)) || \ - ((hooktype == HOOKTYPE_DCC_DENIED) && !ValidateHook(hooktype_dcc_denied, func)) || \ - ((hooktype == HOOKTYPE_SERVER_HANDSHAKE_OUT) && !ValidateHook(hooktype_server_handshake_out, func)) || \ - ((hooktype == HOOKTYPE_SERVER_SYNCED) && !ValidateHook(hooktype_server_synced, func)) || \ - ((hooktype == HOOKTYPE_SECURE_CONNECT) && !ValidateHook(hooktype_secure_connect, func)) || \ - ((hooktype == HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION) && !ValidateHook(hooktype_can_bypass_channel_message_restriction, func)) || \ - ((hooktype == HOOKTYPE_SASL_CONTINUATION) && !ValidateHook(hooktype_sasl_continuation, func)) || \ - ((hooktype == HOOKTYPE_SASL_RESULT) && !ValidateHook(hooktype_sasl_result, func)) || \ - ((hooktype == HOOKTYPE_TAKE_ACTION) && !ValidateHook(hooktype_take_action, func)) || \ - ((hooktype == HOOKTYPE_FIND_TKLINE_MATCH) && !ValidateHook(hooktype_find_tkline_match, func)) || \ - ((hooktype == HOOKTYPE_WELCOME) && !ValidateHook(hooktype_welcome, func)) || \ - ((hooktype == HOOKTYPE_PRE_COMMAND) && !ValidateHook(hooktype_pre_command, func)) || \ - ((hooktype == HOOKTYPE_POST_COMMAND) && !ValidateHook(hooktype_post_command, func)) || \ - ((hooktype == HOOKTYPE_NEW_MESSAGE) && !ValidateHook(hooktype_new_message, func)) || \ - ((hooktype == HOOKTYPE_IS_HANDSHAKE_FINISHED) && !ValidateHook(hooktype_is_handshake_finished, func)) || \ - ((hooktype == HOOKTYPE_PRE_LOCAL_QUIT_CHAN) && !ValidateHook(hooktype_pre_local_quit_chan, func)) || \ - ((hooktype == HOOKTYPE_IDENT_LOOKUP) && !ValidateHook(hooktype_ident_lookup, func)) || \ - ((hooktype == HOOKTYPE_CONFIGRUN_EX) && !ValidateHook(hooktype_configrun_ex, func)) || \ - ((hooktype == HOOKTYPE_ACCOUNT_LOGIN) && !ValidateHook(hooktype_account_login, func)) || \ - ((hooktype == HOOKTYPE_CLOSE_CONNECTION) && !ValidateHook(hooktype_close_connection, func)) || \ - ((hooktype == HOOKTYPE_CONNECT_EXTINFO) && !ValidateHook(hooktype_connect_extinfo, func)) || \ - ((hooktype == HOOKTYPE_IS_INVITED) && !ValidateHook(hooktype_is_invited, func)) || \ - ((hooktype == HOOKTYPE_POST_LOCAL_NICKCHANGE) && !ValidateHook(hooktype_post_local_nickchange, func)) || \ - ((hooktype == HOOKTYPE_POST_REMOTE_NICKCHANGE) && !ValidateHook(hooktype_post_remote_nickchange, func)) || \ - ((hooktype == HOOKTYPE_USERHOST_CHANGE) && !ValidateHook(hooktype_userhost_change, func)) || \ - ((hooktype == HOOKTYPE_REALNAME_CHANGE) && !ValidateHook(hooktype_realname_change, func)) || \ - ((hooktype == HOOKTYPE_IP_CHANGE) && !ValidateHook(hooktype_ip_change, func)) || \ - ((hooktype == HOOKTYPE_JSON_EXPAND_CLIENT) && !ValidateHook(hooktype_json_expand_client, func)) || \ - ((hooktype == HOOKTYPE_JSON_EXPAND_CLIENT_USER) && !ValidateHook(hooktype_json_expand_client_user, func)) || \ - ((hooktype == HOOKTYPE_JSON_EXPAND_CLIENT_SERVER) && !ValidateHook(hooktype_json_expand_client_server, func)) || \ - ((hooktype == HOOKTYPE_JSON_EXPAND_CHANNEL) && !ValidateHook(hooktype_json_expand_channel, func)) || \ - ((hooktype == HOOKTYPE_PRE_LOCAL_HANDSHAKE_TIMEOUT) && !ValidateHook(hooktype_pre_local_handshake_timeout, func)) || \ - ((hooktype == HOOKTYPE_REHASH_LOG) && !ValidateHook(hooktype_rehash_log, func)) || \ - ((hooktype == HOOKTYPE_DNS_FINISHED) && !ValidateHook(hooktype_dns_finished, func)) || \ - ((hooktype == HOOKTYPE_CONFIG_LISTENER) && !ValidateHook(hooktype_config_listener, func)) || \ - ((hooktype == HOOKTYPE_WATCH_ADD) && !ValidateHook(hooktype_watch_add, func)) || \ - ((hooktype == HOOKTYPE_WATCH_DEL) && !ValidateHook(hooktype_watch_del, func)) || \ - ((hooktype == HOOKTYPE_MONITOR_NOTIFICATION) && !ValidateHook(hooktype_monitor_notification, func)) || \ - ((hooktype == HOOKTYPE_SASL_AUTHENTICATE) && !ValidateHook(hooktype_sasl_authenticate, func)) || \ - ((hooktype == HOOKTYPE_SASL_MECHS) && !ValidateHook(hooktype_sasl_mechs, func)) || \ - ((hooktype == HOOKTYPE_ALLOW_CLIENT) && !ValidateHook(hooktype_allow_client, func)) || \ - ((hooktype == HOOKTYPE_ANALYZE_TEXT) && !ValidateHook(hooktype_analyze_text, func)) || \ - ((hooktype == HOOKTYPE_CAN_USE_NICK) && !ValidateHook(hooktype_can_use_nick, func)) || \ - ((hooktype == HOOKTYPE_BANNED_CLIENT) && !ValidateHook(hooktype_banned_client, func)) || \ - ((hooktype == HOOKTYPE_MOTD) && !ValidateHook(hooktype_motd, func)) || \ - ((hooktype == HOOKTYPE_KNOWN_USER_CACHE_CHANGE) && !ValidateHook(hooktype_known_user_cache_change, func))) \ - _hook_error_incompatible(); + #define ValidateHooks(hooktype, func) \ + if (((hooktype == HOOKTYPE_LOCAL_QUIT) && !ValidateHook(hooktype_local_quit, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_NICKCHANGE) && !ValidateHook(hooktype_local_nickchange, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_CONNECT) && !ValidateHook(hooktype_local_connect, func)) || \ + ((hooktype == HOOKTYPE_REHASHFLAG) && !ValidateHook(hooktype_rehashflag, func)) || \ + ((hooktype == HOOKTYPE_PRE_LOCAL_PART) && !ValidateHook(hooktype_pre_local_part, func)) || \ + ((hooktype == HOOKTYPE_CONFIGPOSTTEST) && !ValidateHook(hooktype_configposttest, func)) || \ + ((hooktype == HOOKTYPE_REHASH) && !ValidateHook(hooktype_rehash, func)) || \ + ((hooktype == HOOKTYPE_PRE_LOCAL_CONNECT) && !ValidateHook(hooktype_pre_local_connect, func)) || \ + ((hooktype == HOOKTYPE_PRE_LOCAL_QUIT) && !ValidateHook(hooktype_pre_local_quit, func)) || \ + ((hooktype == HOOKTYPE_SERVER_CONNECT) && !ValidateHook(hooktype_server_connect, func)) || \ + ((hooktype == HOOKTYPE_SERVER_SYNC) && !ValidateHook(hooktype_server_sync, func)) || \ + ((hooktype == HOOKTYPE_SERVER_QUIT) && !ValidateHook(hooktype_server_quit, func)) || \ + ((hooktype == HOOKTYPE_STATS) && !ValidateHook(hooktype_stats, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_JOIN) && !ValidateHook(hooktype_local_join, func)) || \ + ((hooktype == HOOKTYPE_CONFIGTEST) && !ValidateHook(hooktype_configtest, func)) || \ + ((hooktype == HOOKTYPE_CONFIGRUN) && !ValidateHook(hooktype_configrun, func)) || \ + ((hooktype == HOOKTYPE_USERMSG) && !ValidateHook(hooktype_usermsg, func)) || \ + ((hooktype == HOOKTYPE_CHANMSG) && !ValidateHook(hooktype_chanmsg, func)) || \ + ((hooktype == HOOKTYPE_CHANMSG_MULTILINE) && !ValidateHook(hooktype_chanmsg_multiline, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_PART) && !ValidateHook(hooktype_local_part, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_KICK) && !ValidateHook(hooktype_local_kick, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_CHANMODE) && !ValidateHook(hooktype_local_chanmode, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_OPER) && !ValidateHook(hooktype_local_oper, func)) || \ + ((hooktype == HOOKTYPE_UNKUSER_QUIT) && !ValidateHook(hooktype_unkuser_quit, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_PASS) && !ValidateHook(hooktype_local_pass, func)) || \ + ((hooktype == HOOKTYPE_REMOTE_CONNECT) && !ValidateHook(hooktype_remote_connect, func)) || \ + ((hooktype == HOOKTYPE_REMOTE_QUIT) && !ValidateHook(hooktype_remote_quit, func)) || \ + ((hooktype == HOOKTYPE_PRE_LOCAL_JOIN) && !ValidateHook(hooktype_pre_local_join, func)) || \ + ((hooktype == HOOKTYPE_PRE_LOCAL_KICK) && !ValidateHook(hooktype_pre_local_kick, func)) || \ + ((hooktype == HOOKTYPE_CAN_SET_TOPIC) && !ValidateHook(hooktype_can_set_topic, func)) || \ + ((hooktype == HOOKTYPE_PRE_LOCAL_TOPIC) && !ValidateHook(hooktype_pre_local_topic, func)) || \ + ((hooktype == HOOKTYPE_REMOTE_NICKCHANGE) && !ValidateHook(hooktype_remote_nickchange, func)) || \ + ((hooktype == HOOKTYPE_CHANNEL_CREATE) && !ValidateHook(hooktype_channel_create, func)) || \ + ((hooktype == HOOKTYPE_CHANNEL_DESTROY) && !ValidateHook(hooktype_channel_destroy, func)) || \ + ((hooktype == HOOKTYPE_REMOTE_CHANMODE) && !ValidateHook(hooktype_remote_chanmode, func)) || \ + ((hooktype == HOOKTYPE_TKL_EXCEPT) && !ValidateHook(hooktype_tkl_except, func)) || \ + ((hooktype == HOOKTYPE_UMODE_CHANGE) && !ValidateHook(hooktype_umode_change, func)) || \ + ((hooktype == HOOKTYPE_TOPIC) && !ValidateHook(hooktype_topic, func)) || \ + ((hooktype == HOOKTYPE_REHASH_COMPLETE) && !ValidateHook(hooktype_rehash_complete, func)) || \ + ((hooktype == HOOKTYPE_POSTCONF) && !ValidateHook(hooktype_postconf, func)) || \ + ((hooktype == HOOKTYPE_TKL_ADD) && !ValidateHook(hooktype_tkl_add, func)) || \ + ((hooktype == HOOKTYPE_TKL_DEL) && !ValidateHook(hooktype_tkl_del, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_KILL) && !ValidateHook(hooktype_local_kill, func)) || \ + ((hooktype == HOOKTYPE_LOG) && !ValidateHook(hooktype_log, func)) || \ + ((hooktype == HOOKTYPE_REMOTE_JOIN) && !ValidateHook(hooktype_remote_join, func)) || \ + ((hooktype == HOOKTYPE_REMOTE_PART) && !ValidateHook(hooktype_remote_part, func)) || \ + ((hooktype == HOOKTYPE_REMOTE_KICK) && !ValidateHook(hooktype_remote_kick, func)) || \ + ((hooktype == HOOKTYPE_LOCAL_SPAMFILTER) && !ValidateHook(hooktype_local_spamfilter, func)) || \ + ((hooktype == HOOKTYPE_SILENCED) && !ValidateHook(hooktype_silenced, func)) || \ + ((hooktype == HOOKTYPE_POST_SERVER_CONNECT) && !ValidateHook(hooktype_post_server_connect, func)) || \ + ((hooktype == HOOKTYPE_RAWPACKET_IN) && !ValidateHook(hooktype_rawpacket_in, func)) || \ + ((hooktype == HOOKTYPE_PACKET) && !ValidateHook(hooktype_packet, func)) || \ + ((hooktype == HOOKTYPE_HANDSHAKE) && !ValidateHook(hooktype_handshake, func)) || \ + ((hooktype == HOOKTYPE_AWAY) && !ValidateHook(hooktype_away, func)) || \ + ((hooktype == HOOKTYPE_INVITE) && !ValidateHook(hooktype_invite, func)) || \ + ((hooktype == HOOKTYPE_CAN_JOIN) && !ValidateHook(hooktype_can_join, func)) || \ + ((hooktype == HOOKTYPE_CAN_SEND_TO_CHANNEL) && !ValidateHook(hooktype_can_send_to_channel, func)) || \ + ((hooktype == HOOKTYPE_CAN_SEND_TO_USER) && !ValidateHook(hooktype_can_send_to_user, func)) || \ + ((hooktype == HOOKTYPE_CAN_KICK) && !ValidateHook(hooktype_can_kick, func)) || \ + ((hooktype == HOOKTYPE_FREE_CLIENT) && !ValidateHook(hooktype_free_client, func)) || \ + ((hooktype == HOOKTYPE_FREE_USER) && !ValidateHook(hooktype_free_user, func)) || \ + ((hooktype == HOOKTYPE_PRE_CHANMSG) && !ValidateHook(hooktype_pre_chanmsg, func)) || \ + ((hooktype == HOOKTYPE_KNOCK) && !ValidateHook(hooktype_knock, func)) || \ + ((hooktype == HOOKTYPE_MODECHAR_ADD) && !ValidateHook(hooktype_modechar_add, func)) || \ + ((hooktype == HOOKTYPE_MODECHAR_DEL) && !ValidateHook(hooktype_modechar_del, func)) || \ + ((hooktype == HOOKTYPE_CAN_JOIN_LIMITEXCEEDED) && !ValidateHook(hooktype_can_join_limitexceeded, func)) || \ + ((hooktype == HOOKTYPE_PRE_LOCAL_CHANMODE) && !ValidateHook(hooktype_pre_local_chanmode, func)) || \ + ((hooktype == HOOKTYPE_PRE_REMOTE_CHANMODE) && !ValidateHook(hooktype_pre_remote_chanmode, func)) || \ + ((hooktype == HOOKTYPE_JOIN_DATA) && !ValidateHook(hooktype_join_data, func)) || \ + ((hooktype == HOOKTYPE_PRE_KNOCK) && !ValidateHook(hooktype_pre_knock, func)) || \ + ((hooktype == HOOKTYPE_PRE_INVITE) && !ValidateHook(hooktype_pre_invite, func)) || \ + ((hooktype == HOOKTYPE_INVITE_BYPASS) && !ValidateHook(hooktype_invite_bypass, func)) || \ + ((hooktype == HOOKTYPE_VIEW_TOPIC_OUTSIDE_CHANNEL) && !ValidateHook(hooktype_view_topic_outside_channel, func)) || \ + ((hooktype == HOOKTYPE_CHAN_PERMIT_NICK_CHANGE) && !ValidateHook(hooktype_chan_permit_nick_change, func)) || \ + ((hooktype == HOOKTYPE_IS_CHANNEL_SECURE) && !ValidateHook(hooktype_is_channel_secure, func)) || \ + ((hooktype == HOOKTYPE_CHANNEL_SYNCED) && !ValidateHook(hooktype_channel_synced, func)) || \ + ((hooktype == HOOKTYPE_CAN_SAJOIN) && !ValidateHook(hooktype_can_sajoin, func)) || \ + ((hooktype == HOOKTYPE_WHOIS) && !ValidateHook(hooktype_whois, func)) || \ + ((hooktype == HOOKTYPE_WHO_STATUS) && !ValidateHook(hooktype_who_status, func)) || \ + ((hooktype == HOOKTYPE_MODE_DEOP) && !ValidateHook(hooktype_mode_deop, func)) || \ + ((hooktype == HOOKTYPE_PRE_KILL) && !ValidateHook(hooktype_pre_kill, func)) || \ + ((hooktype == HOOKTYPE_SEE_CHANNEL_IN_WHOIS) && !ValidateHook(hooktype_see_channel_in_whois, func)) || \ + ((hooktype == HOOKTYPE_DCC_DENIED) && !ValidateHook(hooktype_dcc_denied, func)) || \ + ((hooktype == HOOKTYPE_SERVER_HANDSHAKE_OUT) && !ValidateHook(hooktype_server_handshake_out, func)) || \ + ((hooktype == HOOKTYPE_SERVER_SYNCED) && !ValidateHook(hooktype_server_synced, func)) || \ + ((hooktype == HOOKTYPE_SECURE_CONNECT) && !ValidateHook(hooktype_secure_connect, func)) || \ + ((hooktype == HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION) && !ValidateHook(hooktype_can_bypass_channel_message_restriction, func)) || \ + ((hooktype == HOOKTYPE_SASL_CONTINUATION) && !ValidateHook(hooktype_sasl_continuation, func)) || \ + ((hooktype == HOOKTYPE_SASL_RESULT) && !ValidateHook(hooktype_sasl_result, func)) || \ + ((hooktype == HOOKTYPE_TAKE_ACTION) && !ValidateHook(hooktype_take_action, func)) || \ + ((hooktype == HOOKTYPE_FIND_TKLINE_MATCH) && !ValidateHook(hooktype_find_tkline_match, func)) || \ + ((hooktype == HOOKTYPE_WELCOME) && !ValidateHook(hooktype_welcome, func)) || \ + ((hooktype == HOOKTYPE_PRE_COMMAND) && !ValidateHook(hooktype_pre_command, func)) || \ + ((hooktype == HOOKTYPE_POST_COMMAND) && !ValidateHook(hooktype_post_command, func)) || \ + ((hooktype == HOOKTYPE_NEW_MESSAGE) && !ValidateHook(hooktype_new_message, func)) || \ + ((hooktype == HOOKTYPE_IS_HANDSHAKE_FINISHED) && !ValidateHook(hooktype_is_handshake_finished, func)) || \ + ((hooktype == HOOKTYPE_PRE_LOCAL_QUIT_CHAN) && !ValidateHook(hooktype_pre_local_quit_chan, func)) || \ + ((hooktype == HOOKTYPE_IDENT_LOOKUP) && !ValidateHook(hooktype_ident_lookup, func)) || \ + ((hooktype == HOOKTYPE_CONFIGRUN_EX) && !ValidateHook(hooktype_configrun_ex, func)) || \ + ((hooktype == HOOKTYPE_ACCOUNT_LOGIN) && !ValidateHook(hooktype_account_login, func)) || \ + ((hooktype == HOOKTYPE_CLOSE_CONNECTION) && !ValidateHook(hooktype_close_connection, func)) || \ + ((hooktype == HOOKTYPE_CONNECT_EXTINFO) && !ValidateHook(hooktype_connect_extinfo, func)) || \ + ((hooktype == HOOKTYPE_IS_INVITED) && !ValidateHook(hooktype_is_invited, func)) || \ + ((hooktype == HOOKTYPE_POST_LOCAL_NICKCHANGE) && !ValidateHook(hooktype_post_local_nickchange, func)) || \ + ((hooktype == HOOKTYPE_POST_REMOTE_NICKCHANGE) && !ValidateHook(hooktype_post_remote_nickchange, func)) || \ + ((hooktype == HOOKTYPE_USERHOST_CHANGE) && !ValidateHook(hooktype_userhost_change, func)) || \ + ((hooktype == HOOKTYPE_REALNAME_CHANGE) && !ValidateHook(hooktype_realname_change, func)) || \ + ((hooktype == HOOKTYPE_IP_CHANGE) && !ValidateHook(hooktype_ip_change, func)) || \ + ((hooktype == HOOKTYPE_JSON_EXPAND_CLIENT) && !ValidateHook(hooktype_json_expand_client, func)) || \ + ((hooktype == HOOKTYPE_JSON_EXPAND_CLIENT_USER) && !ValidateHook(hooktype_json_expand_client_user, func)) || \ + ((hooktype == HOOKTYPE_JSON_EXPAND_CLIENT_SERVER) && !ValidateHook(hooktype_json_expand_client_server, func)) || \ + ((hooktype == HOOKTYPE_JSON_EXPAND_CHANNEL) && !ValidateHook(hooktype_json_expand_channel, func)) || \ + ((hooktype == HOOKTYPE_PRE_LOCAL_HANDSHAKE_TIMEOUT) && !ValidateHook(hooktype_pre_local_handshake_timeout, func)) || \ + ((hooktype == HOOKTYPE_REHASH_LOG) && !ValidateHook(hooktype_rehash_log, func)) || \ + ((hooktype == HOOKTYPE_DNS_FINISHED) && !ValidateHook(hooktype_dns_finished, func)) || \ + ((hooktype == HOOKTYPE_CONFIG_LISTENER) && !ValidateHook(hooktype_config_listener, func)) || \ + ((hooktype == HOOKTYPE_WATCH_ADD) && !ValidateHook(hooktype_watch_add, func)) || \ + ((hooktype == HOOKTYPE_WATCH_DEL) && !ValidateHook(hooktype_watch_del, func)) || \ + ((hooktype == HOOKTYPE_MONITOR_NOTIFICATION) && !ValidateHook(hooktype_monitor_notification, func)) || \ + ((hooktype == HOOKTYPE_SASL_AUTHENTICATE) && !ValidateHook(hooktype_sasl_authenticate, func)) || \ + ((hooktype == HOOKTYPE_SASL_MECHS) && !ValidateHook(hooktype_sasl_mechs, func)) || \ + ((hooktype == HOOKTYPE_ALLOW_CLIENT) && !ValidateHook(hooktype_allow_client, func)) || \ + ((hooktype == HOOKTYPE_ANALYZE_TEXT) && !ValidateHook(hooktype_analyze_text, func)) || \ + ((hooktype == HOOKTYPE_CAN_USE_NICK) && !ValidateHook(hooktype_can_use_nick, func)) || \ + ((hooktype == HOOKTYPE_BANNED_CLIENT) && !ValidateHook(hooktype_banned_client, func)) || \ + ((hooktype == HOOKTYPE_MOTD) && !ValidateHook(hooktype_motd, func)) || \ + ((hooktype == HOOKTYPE_KNOWN_USER_CACHE_CHANGE) && !ValidateHook(hooktype_known_user_cache_change, func))) \ + _hook_error_incompatible(); #endif /* GCC_TYPECHECKING */ /* Hook return values */ #define HOOK_CONTINUE 0 -#define HOOK_ALLOW -1 -#define HOOK_DENY 1 +#define HOOK_ALLOW -1 +#define HOOK_DENY 1 /* Callback types */ -#define CALLBACKTYPE_CLOAK 1 -#define CALLBACKTYPE_CLOAK_KEY_CHECKSUM 2 -#define CALLBACKTYPE_CLOAK_EX 3 -#define CALLBACKTYPE_BLACKLIST_CHECK 4 +#define CALLBACKTYPE_CLOAK 1 +#define CALLBACKTYPE_CLOAK_KEY_CHECKSUM 2 +#define CALLBACKTYPE_CLOAK_EX 3 +#define CALLBACKTYPE_BLACKLIST_CHECK 4 #define CALLBACKTYPE_REPUTATION_STARTTIME 5 -#define CALLBACKTYPE_GEOIP_LOOKUP 6 +#define CALLBACKTYPE_GEOIP_LOOKUP 6 /* To add a new efunction, only if you are an UnrealIRCd coder: * 1) Add a new entry here @@ -2929,7 +2936,7 @@ _UNREAL_ERROR(_hook_error_incompatible, "Incompatible hook function. Check argum */ /** Efunction types. */ enum EfunctionType { - EFUNC_DO_JOIN=1, + EFUNC_DO_JOIN = 1, EFUNC_JOIN_CHANNEL, EFUNC_CAN_JOIN, EFUNC_DO_MODE, @@ -3087,43 +3094,42 @@ enum EfunctionType { }; /* Module flags */ -#define MODFLAG_NONE 0x0000 -#define MODFLAG_LOADED 0x0001 /* Fully loaded */ +#define MODFLAG_NONE 0x0000 +#define MODFLAG_LOADED 0x0001 /* Fully loaded */ #define MODFLAG_TESTING 0x0002 /* Not yet initialized */ -#define MODFLAG_INIT 0x0004 /* Initialized */ +#define MODFLAG_INIT 0x0004 /* Initialized */ #define MODFLAG_DELAYED 0x0008 /* Delayed unload */ /* Module function return values */ #define MOD_SUCCESS 0 -#define MOD_FAILED -1 -#define MOD_DELAY 2 +#define MOD_FAILED -1 +#define MOD_DELAY 2 -#define CONFIG_MAIN 1 -#define CONFIG_SET 2 -#define CONFIG_BAN 3 -#define CONFIG_EXCEPT 4 -#define CONFIG_DENY 5 -#define CONFIG_ALLOW 6 -#define CONFIG_CLOAKKEYS 7 -#define CONFIG_SET_ANTI_FLOOD 8 -#define CONFIG_REQUIRE 9 -#define CONFIG_LISTEN 10 -#define CONFIG_LISTEN_OPTIONS 11 +#define CONFIG_MAIN 1 +#define CONFIG_SET 2 +#define CONFIG_BAN 3 +#define CONFIG_EXCEPT 4 +#define CONFIG_DENY 5 +#define CONFIG_ALLOW 6 +#define CONFIG_CLOAKKEYS 7 +#define CONFIG_SET_ANTI_FLOOD 8 +#define CONFIG_REQUIRE 9 +#define CONFIG_LISTEN 10 +#define CONFIG_LISTEN_OPTIONS 11 #define CONFIG_SET_HISTORY_CHANNEL 12 -#define CONFIG_ALLOW_BLOCK 13 -#define CONFIG_CLASS 14 +#define CONFIG_ALLOW_BLOCK 13 +#define CONFIG_CLASS 14 -#define MOD_HEADER Mod_Header -#define MOD_TEST() DLLFUNC int Mod_Test(ModuleInfo *modinfo) -#define MOD_INIT() DLLFUNC int Mod_Init(ModuleInfo *modinfo) -#define MOD_LOAD() DLLFUNC int Mod_Load(ModuleInfo *modinfo) +#define MOD_HEADER Mod_Header +#define MOD_TEST() DLLFUNC int Mod_Test(ModuleInfo *modinfo) +#define MOD_INIT() DLLFUNC int Mod_Init(ModuleInfo *modinfo) +#define MOD_LOAD() DLLFUNC int Mod_Load(ModuleInfo *modinfo) #define MOD_UNLOAD() DLLFUNC int Mod_Unload(ModuleInfo *modinfo) -#define CLOAK_KEY_CHECKSUM RCallbacks[CALLBACKTYPE_CLOAK_KEY_CHECKSUM] != NULL ? RCallbacks[CALLBACKTYPE_CLOAK_KEY_CHECKSUM]->func.stringfunc() : "nil" +#define CLOAK_KEY_CHECKSUM RCallbacks[CALLBACKTYPE_CLOAK_KEY_CHECKSUM] != NULL ? RCallbacks[CALLBACKTYPE_CLOAK_KEY_CHECKSUM]->func.stringfunc() : "nil" #ifdef DYNAMIC_LINKING #include "modversion.h" #endif #endif - diff --git a/include/modversion.h b/include/modversion.h index 396be2e18..56788e1f0 100644 --- a/include/modversion.h +++ b/include/modversion.h @@ -30,7 +30,7 @@ */ #ifdef UNREALCORE - char our_mod_version[] = BASE_VERSION "-" PATCH1 PATCH2 PATCH3 PATCH4 PATCH6 PATCH7 PATCH8 PATCH9; +char our_mod_version[] = BASE_VERSION "-" PATCH1 PATCH2 PATCH3 PATCH4 PATCH6 PATCH7 PATCH8 PATCH9; #else - DLLFUNC char Mod_Version[] = BASE_VERSION "-" PATCH1 PATCH2 PATCH3 PATCH4 PATCH6 PATCH7 PATCH8 PATCH9; +DLLFUNC char Mod_Version[] = BASE_VERSION "-" PATCH1 PATCH2 PATCH3 PATCH4 PATCH6 PATCH7 PATCH8 PATCH9; #endif diff --git a/include/msg.h b/include/msg.h index 02f32cd31..1678fb90b 100644 --- a/include/msg.h +++ b/include/msg.h @@ -21,145 +21,145 @@ * $Id$ */ -#ifndef __msg_include__ +#ifndef __msg_include__ #define __msg_include__ -#define MSG_PRIVATE "PRIVMSG" /* PRIV */ -#define MSG_WHOIS "WHOIS" /* WHOI */ -#define MSG_WHOWAS "WHOWAS" /* WHOW */ -#define MSG_USER "USER" /* USER */ -#define MSG_NICK "NICK" /* NICK */ -#define MSG_SERVER "SERVER" /* SERV */ -#define MSG_LIST "LIST" /* LIST */ -#define MSG_TOPIC "TOPIC" /* TOPI */ -#define MSG_INVITE "INVITE" /* INVI */ -#define MSG_VERSION "VERSION" /* VERS */ -#define MSG_QUIT "QUIT" /* QUIT */ -#define MSG_SQUIT "SQUIT" /* SQUI */ -#define MSG_KILL "KILL" /* KILL */ -#define MSG_INFO "INFO" /* INFO */ -#define MSG_LINKS "LINKS" /* LINK */ -#define MSG_SUMMON "SUMMON" /* SUMM */ -#define MSG_STATS "STATS" /* STAT */ -#define MSG_USERS "USERS" /* USER -> USRS */ -#define MSG_HELP "HELP" /* HELP */ -#define MSG_HELPOP "HELPOP" /* HELP */ -#define MSG_ERROR "ERROR" /* ERRO */ -#define MSG_AWAY "AWAY" /* AWAY */ -#define MSG_CONNECT "CONNECT" /* CONN */ -#define MSG_PING "PING" /* PING */ -#define MSG_PONG "PONG" /* PONG */ -#define MSG_OPER "OPER" /* OPER */ -#define MSG_PASS "PASS" /* PASS */ -#define MSG_TIME "TIME" /* TIME */ -#define MSG_NAMES "NAMES" /* NAME */ -#define MSG_ADMIN "ADMIN" /* ADMI */ -#define MSG_NOTICE "NOTICE" /* NOTI */ -#define MSG_JOIN "JOIN" /* JOIN */ -#define MSG_PART "PART" /* PART */ -#define MSG_LUSERS "LUSERS" /* LUSE */ -#define MSG_MOTD "MOTD" /* MOTD */ -#define MSG_MODE "MODE" /* MODE */ -#define MSG_KICK "KICK" /* KICK */ -#define MSG_SERVICE "SERVICE" /* SERV -> SRVI */ -#define MSG_USERHOST "USERHOST" /* USER -> USRH */ -#define MSG_ISON "ISON" /* ISON */ -#define MSG_REHASH "REHASH" /* REHA */ -#define MSG_RESTART "RESTART" /* REST */ -#define MSG_CLOSE "CLOSE" /* CLOS */ -#define MSG_DIE "DIE" /* DIE */ -#define MSG_HASH "HASH" /* HASH */ -#define MSG_DNS "DNS" /* DNS -> DNSS */ -#define MSG_SILENCE "SILENCE" /* SILE */ -#define MSG_AKILL "AKILL" /* AKILL */ -#define MSG_KLINE "KLINE" /* KLINE */ -#define MSG_UNKLINE "UNKLINE" /* UNKLINE */ -#define MSG_RAKILL "RAKILL" /* RAKILL */ -#define MSG_GNOTICE "GNOTICE" /* GNOTICE */ -#define MSG_GOPER "GOPER" /* GOPER */ -#define MSG_GLOBOPS "GLOBOPS" /* GLOBOPS */ -#define MSG_LOCOPS "LOCOPS" /* LOCOPS */ -#define MSG_PROTOCTL "PROTOCTL" /* PROTOCTL */ -#define MSG_WATCH "WATCH" /* WATCH */ -#define MSG_TRACE "TRACE" /* TRAC */ -#define MSG_SQLINE "SQLINE" /* SQLINE */ -#define MSG_UNSQLINE "UNSQLINE" /* UNSQLINE */ -#define MSG_SVSNICK "SVSNICK" /* SVSNICK */ -#define MSG_SVSNOOP "SVSNOOP" /* SVSNOOP */ -#define MSG_IDENTIFY "IDENTIFY" /* IDENTIFY */ -#define MSG_SVSKILL "SVSKILL" /* SVSKILL */ -#define MSG_NICKSERV "NICKSERV" /* NICKSERV */ -#define MSG_NS "NS" -#define MSG_CHANSERV "CHANSERV" /* CHANSERV */ -#define MSG_CS "CS" -#define MSG_OPERSERV "OPERSERV" /* OPERSERV */ -#define MSG_OS "OS" -#define MSG_MEMOSERV "MEMOSERV" /* MEMOSERV */ -#define MSG_MS "MS" -#define MSG_SERVICES "SERVICES" /* SERVICES */ -#define MSG_SVSMODE "SVSMODE" /* SVSMODE */ -#define MSG_SAMODE "SAMODE" /* SAMODE */ -#define MSG_CHATOPS "CHATOPS" /* CHATOPS */ -#define MSG_ZLINE "ZLINE" /* ZLINE */ -#define MSG_UNZLINE "UNZLINE" /* UNZLINE */ -#define MSG_HELPSERV "HELPSERV" /* HELPSERV */ -#define MSG_HS "HS" -#define MSG_RULES "RULES" /* RULES */ -#define MSG_MAP "MAP" /* MAP */ -#define MSG_SVS2MODE "SVS2MODE" /* SVS2MODE */ -#define MSG_DALINFO "DALINFO" /* dalinfo */ -#define MSG_ADMINCHAT "ADCHAT" /* Admin chat */ -#define MSG_MKPASSWD "MKPASSWD" /* MKPASSWD */ -#define MSG_ADDLINE "ADDLINE" /* ADDLINE */ -#define MSG_GLINE "GLINE" /* The awesome g-line */ -#define MSG_SJOIN "SJOIN" -#define MSG_SETHOST "SETHOST" /* sethost */ -#define MSG_NACHAT "NACHAT" /* netadmin chat */ -#define MSG_SETIDENT "SETIDENT" -#define MSG_SETNAME "SETNAME" /* set GECOS */ -#define MSG_LAG "LAG" /* Lag detect */ -#define MSG_STATSERV "STATSERV" /* alias */ -#define MSG_KNOCK "KNOCK" -#define MSG_CREDITS "CREDITS" -#define MSG_LICENSE "LICENSE" -#define MSG_CHGHOST "CHGHOST" -#define MSG_NETINFO "NETINFO" -#define MSG_SENDUMODE "SENDUMODE" -#define MSG_ADDMOTD "ADDMOTD" -#define MSG_ADDOMOTD "ADDOMOTD" -#define MSG_SVSMOTD "SVSMOTD" -#define MSG_SMO "SMO" -#define MSG_OPERMOTD "OPERMOTD" -#define MSG_TSCTL "TSCTL" -#define MSG_SVSJOIN "SVSJOIN" -#define MSG_SAJOIN "SAJOIN" -#define MSG_SVSPART "SVSPART" -#define MSG_SAPART "SAPART" -#define MSG_CHGIDENT "CHGIDENT" -#define MSG_SWHOIS "SWHOIS" -#define MSG_SVSO "SVSO" -#define MSG_SVSFLINE "SVSFLINE" -#define MSG_TKL "TKL" -#define MSG_VHOST "VHOST" -#define MSG_BOTMOTD "BOTMOTD" -#define MSG_REMGLINE "REMGLINE" /* remove g-line */ -#define MSG_UMODE2 "UMODE2" -#define MSG_DCCDENY "DCCDENY" -#define MSG_UNDCCDENY "UNDCCDENY" -#define MSG_CHGNAME "CHGNAME" -#define MSG_SHUN "SHUN" -#define MSG_NEWJOIN "NEWJOIN" /* For CR Java Chat */ -#define MSG_POST "POST" -#define MSG_INFOSERV "INFOSERV" -#define MSG_IS "IS" -#define MSG_BOTSERV "BOTSERV" -#define MSG_CYCLE "CYCLE" -#define MSG_MODULE "MODULE" -#define MSG_SENDSNO "SENDSNO" -#define MSG_EOS "EOS" -#define MSG_MLOCK "MLOCK" +#define MSG_PRIVATE "PRIVMSG" /* PRIV */ +#define MSG_WHOIS "WHOIS" /* WHOI */ +#define MSG_WHOWAS "WHOWAS" /* WHOW */ +#define MSG_USER "USER" /* USER */ +#define MSG_NICK "NICK" /* NICK */ +#define MSG_SERVER "SERVER" /* SERV */ +#define MSG_LIST "LIST" /* LIST */ +#define MSG_TOPIC "TOPIC" /* TOPI */ +#define MSG_INVITE "INVITE" /* INVI */ +#define MSG_VERSION "VERSION" /* VERS */ +#define MSG_QUIT "QUIT" /* QUIT */ +#define MSG_SQUIT "SQUIT" /* SQUI */ +#define MSG_KILL "KILL" /* KILL */ +#define MSG_INFO "INFO" /* INFO */ +#define MSG_LINKS "LINKS" /* LINK */ +#define MSG_SUMMON "SUMMON" /* SUMM */ +#define MSG_STATS "STATS" /* STAT */ +#define MSG_USERS "USERS" /* USER -> USRS */ +#define MSG_HELP "HELP" /* HELP */ +#define MSG_HELPOP "HELPOP" /* HELP */ +#define MSG_ERROR "ERROR" /* ERRO */ +#define MSG_AWAY "AWAY" /* AWAY */ +#define MSG_CONNECT "CONNECT" /* CONN */ +#define MSG_PING "PING" /* PING */ +#define MSG_PONG "PONG" /* PONG */ +#define MSG_OPER "OPER" /* OPER */ +#define MSG_PASS "PASS" /* PASS */ +#define MSG_TIME "TIME" /* TIME */ +#define MSG_NAMES "NAMES" /* NAME */ +#define MSG_ADMIN "ADMIN" /* ADMI */ +#define MSG_NOTICE "NOTICE" /* NOTI */ +#define MSG_JOIN "JOIN" /* JOIN */ +#define MSG_PART "PART" /* PART */ +#define MSG_LUSERS "LUSERS" /* LUSE */ +#define MSG_MOTD "MOTD" /* MOTD */ +#define MSG_MODE "MODE" /* MODE */ +#define MSG_KICK "KICK" /* KICK */ +#define MSG_SERVICE "SERVICE" /* SERV -> SRVI */ +#define MSG_USERHOST "USERHOST" /* USER -> USRH */ +#define MSG_ISON "ISON" /* ISON */ +#define MSG_REHASH "REHASH" /* REHA */ +#define MSG_RESTART "RESTART" /* REST */ +#define MSG_CLOSE "CLOSE" /* CLOS */ +#define MSG_DIE "DIE" /* DIE */ +#define MSG_HASH "HASH" /* HASH */ +#define MSG_DNS "DNS" /* DNS -> DNSS */ +#define MSG_SILENCE "SILENCE" /* SILE */ +#define MSG_AKILL "AKILL" /* AKILL */ +#define MSG_KLINE "KLINE" /* KLINE */ +#define MSG_UNKLINE "UNKLINE" /* UNKLINE */ +#define MSG_RAKILL "RAKILL" /* RAKILL */ +#define MSG_GNOTICE "GNOTICE" /* GNOTICE */ +#define MSG_GOPER "GOPER" /* GOPER */ +#define MSG_GLOBOPS "GLOBOPS" /* GLOBOPS */ +#define MSG_LOCOPS "LOCOPS" /* LOCOPS */ +#define MSG_PROTOCTL "PROTOCTL" /* PROTOCTL */ +#define MSG_WATCH "WATCH" /* WATCH */ +#define MSG_TRACE "TRACE" /* TRAC */ +#define MSG_SQLINE "SQLINE" /* SQLINE */ +#define MSG_UNSQLINE "UNSQLINE" /* UNSQLINE */ +#define MSG_SVSNICK "SVSNICK" /* SVSNICK */ +#define MSG_SVSNOOP "SVSNOOP" /* SVSNOOP */ +#define MSG_IDENTIFY "IDENTIFY" /* IDENTIFY */ +#define MSG_SVSKILL "SVSKILL" /* SVSKILL */ +#define MSG_NICKSERV "NICKSERV" /* NICKSERV */ +#define MSG_NS "NS" +#define MSG_CHANSERV "CHANSERV" /* CHANSERV */ +#define MSG_CS "CS" +#define MSG_OPERSERV "OPERSERV" /* OPERSERV */ +#define MSG_OS "OS" +#define MSG_MEMOSERV "MEMOSERV" /* MEMOSERV */ +#define MSG_MS "MS" +#define MSG_SERVICES "SERVICES" /* SERVICES */ +#define MSG_SVSMODE "SVSMODE" /* SVSMODE */ +#define MSG_SAMODE "SAMODE" /* SAMODE */ +#define MSG_CHATOPS "CHATOPS" /* CHATOPS */ +#define MSG_ZLINE "ZLINE" /* ZLINE */ +#define MSG_UNZLINE "UNZLINE" /* UNZLINE */ +#define MSG_HELPSERV "HELPSERV" /* HELPSERV */ +#define MSG_HS "HS" +#define MSG_RULES "RULES" /* RULES */ +#define MSG_MAP "MAP" /* MAP */ +#define MSG_SVS2MODE "SVS2MODE" /* SVS2MODE */ +#define MSG_DALINFO "DALINFO" /* dalinfo */ +#define MSG_ADMINCHAT "ADCHAT" /* Admin chat */ +#define MSG_MKPASSWD "MKPASSWD" /* MKPASSWD */ +#define MSG_ADDLINE "ADDLINE" /* ADDLINE */ +#define MSG_GLINE "GLINE" /* The awesome g-line */ +#define MSG_SJOIN "SJOIN" +#define MSG_SETHOST "SETHOST" /* sethost */ +#define MSG_NACHAT "NACHAT" /* netadmin chat */ +#define MSG_SETIDENT "SETIDENT" +#define MSG_SETNAME "SETNAME" /* set GECOS */ +#define MSG_LAG "LAG" /* Lag detect */ +#define MSG_STATSERV "STATSERV" /* alias */ +#define MSG_KNOCK "KNOCK" +#define MSG_CREDITS "CREDITS" +#define MSG_LICENSE "LICENSE" +#define MSG_CHGHOST "CHGHOST" +#define MSG_NETINFO "NETINFO" +#define MSG_SENDUMODE "SENDUMODE" +#define MSG_ADDMOTD "ADDMOTD" +#define MSG_ADDOMOTD "ADDOMOTD" +#define MSG_SVSMOTD "SVSMOTD" +#define MSG_SMO "SMO" +#define MSG_OPERMOTD "OPERMOTD" +#define MSG_TSCTL "TSCTL" +#define MSG_SVSJOIN "SVSJOIN" +#define MSG_SAJOIN "SAJOIN" +#define MSG_SVSPART "SVSPART" +#define MSG_SAPART "SAPART" +#define MSG_CHGIDENT "CHGIDENT" +#define MSG_SWHOIS "SWHOIS" +#define MSG_SVSO "SVSO" +#define MSG_SVSFLINE "SVSFLINE" +#define MSG_TKL "TKL" +#define MSG_VHOST "VHOST" +#define MSG_BOTMOTD "BOTMOTD" +#define MSG_REMGLINE "REMGLINE" /* remove g-line */ +#define MSG_UMODE2 "UMODE2" +#define MSG_DCCDENY "DCCDENY" +#define MSG_UNDCCDENY "UNDCCDENY" +#define MSG_CHGNAME "CHGNAME" +#define MSG_SHUN "SHUN" +#define MSG_NEWJOIN "NEWJOIN" /* For CR Java Chat */ +#define MSG_POST "POST" +#define MSG_INFOSERV "INFOSERV" +#define MSG_IS "IS" +#define MSG_BOTSERV "BOTSERV" +#define MSG_CYCLE "CYCLE" +#define MSG_MODULE "MODULE" +#define MSG_SENDSNO "SENDSNO" +#define MSG_EOS "EOS" +#define MSG_MLOCK "MLOCK" -#define MAXPARA 30 -#define MAXPARA_USER 15 +#define MAXPARA 30 +#define MAXPARA_USER 15 #endif diff --git a/include/numeric.h b/include/numeric.h index 012c95f2f..a28cb0db2 100644 --- a/include/numeric.h +++ b/include/numeric.h @@ -350,232 +350,232 @@ /* Numeric texts */ -#define STR_RPL_WELCOME /* 001 */ ":Welcome to the %s IRC Network %s!%s@%s" -#define STR_RPL_YOURHOST /* 002 */ ":Your host is %s, running version %s" -#define STR_RPL_CREATED /* 003 */ ":This server was created %s" -#define STR_RPL_MYINFO /* 004 */ "%s %s %s %s" -#define STR_RPL_ISUPPORT /* 005 */ "%s :are supported by this server" -#define STR_RPL_MAP /* 006 */ ":%s%s %s | Users: %*ld (%*.2f%%)%s" -#define STR_RPL_MAPEND /* 007 */ ":End of /MAP" -#define STR_RPL_SNOMASK /* 008 */ "+%s :Server notice mask" -#define STR_RPL_REDIR /* 010 */ "%s %d :Please use this Server/Port instead" -#define STR_RPL_MAPUSERS /* 018 */ ":%d server%s and %d user%s, average %.2f users per server" -#define STR_RPL_REMOTEISUPPORT /* 105 */ "%s :are supported by this server" -#define STR_RPL_TRACELINK /* 200 */ "Link %s%s %s %s" -#define STR_RPL_TRACECONNECTING /* 201 */ "Attempt %s %s" -#define STR_RPL_TRACEHANDSHAKE /* 202 */ "Handshaking %s %s" -#define STR_RPL_TRACEUNKNOWN /* 203 */ "???? %s %s" -#define STR_RPL_TRACEOPERATOR /* 204 */ "Operator %s %s [%s] %lld" -#define STR_RPL_TRACEUSER /* 205 */ "User %s %s [%s] %lld" -#define STR_RPL_TRACESERVER /* 206 */ "Server %s %dS %dC %s %s!%s@%s %lld" -#define STR_RPL_TRACENEWTYPE /* 208 */ "%s 0 %s" -#define STR_RPL_TRACECLASS /* 209 */ "Class %s %d" -#define STR_RPL_STATSHELP /* 210 */ ":%s" -#define STR_RPL_STATSCOMMANDS /* 212 */ "%s %u %lu" -#define STR_RPL_STATSCLINE /* 213 */ "%c %s * %s %d %d %s" -#define STR_RPL_STATSILINE /* 215 */ "I %s %s %d %d %s %s %d" -#define STR_RPL_STATSQLINE /* 217 */ "%c %s %lld %lld %s %lld %lld %s :%s" -#define STR_RPL_STATSYLINE /* 218 */ "Y %s %d %d %d %d %d" -#define STR_RPL_ENDOFSTATS /* 219 */ "%c :End of /STATS report" -#define STR_RPL_UMODEIS /* 221 */ "%s" -#define STR_RPL_STATSGLINE /* 223 */ "%c %s %lld %lld %s %lld %lld %s %s :%s" -#define STR_RPL_STATSTLINE /* 224 */ "T %s %s %s" -#define STR_RPL_STATSNLINE /* 226 */ "n %s %s" -#define STR_RPL_STATSVLINE /* 227 */ "v %s %s %s" -#define STR_RPL_STATSBANVER /* 228 */ "%s %s" -#define STR_RPL_STATSSPAMF /* 229 */ "%c %s %s %s %lld %lld %lld %s %s %lld %lld %lld %lld %s :%s" -#define STR_RPL_STATSEXCEPTTKL /* 230 */ "%s %s %lld %lld %s %s :%s" -#define STR_RPL_RULES /* 232 */ ":- %s" -#define STR_RPL_STATSLLINE /* 241 */ "%c %s * %s %d %d" -#define STR_RPL_STATSUPTIME /* 242 */ ":Server Up %lld days, %lld:%02lld:%02lld" -#define STR_RPL_STATSOLINE /* 243 */ "%c %s * %s %s %s" -#define STR_RPL_STATSHLINE /* 244 */ "%c %s * %s %d %d" -#define STR_RPL_STATSXLINE /* 247 */ "X %s %d" -#define STR_RPL_STATSULINE /* 248 */ "U %s" -#define STR_RPL_STATSDEBUG /* 249 */ ":%s" -#define STR_RPL_STATSCONN /* 250 */ ":Highest connection count: %d (%d clients)" -#define STR_RPL_LUSERCLIENT /* 251 */ ":There are %d users and %d invisible on %d servers" -#define STR_RPL_LUSEROP /* 252 */ "%d :operator(s) online" -#define STR_RPL_LUSERUNKNOWN /* 253 */ "%d :unknown connection(s)" -#define STR_RPL_LUSERCHANNELS /* 254 */ "%d :channels formed" -#define STR_RPL_LUSERME /* 255 */ ":I have %d clients and %d servers" -#define STR_RPL_ADMINME /* 256 */ ":Administrative info about %s" -#define STR_RPL_ADMINLOC1 /* 257 */ ":%s" -#define STR_RPL_ADMINLOC2 /* 258 */ ":%s" -#define STR_RPL_ADMINEMAIL /* 259 */ ":%s" -#define STR_RPL_TRACELOG /* 261 */ "File %s %d" -#define STR_RPL_TRYAGAIN /* 263 */ "%s :Flooding detected. Please wait a while and try again." -#define STR_RPL_LOCALUSERS /* 265 */ "%d %d :Current local users %d, max %d" -#define STR_RPL_GLOBALUSERS /* 266 */ "%d %d :Current global users %d, max %d" -#define STR_RPL_SILELIST /* 271 */ "%s" -#define STR_RPL_ENDOFSILELIST /* 272 */ ":End of Silence List" -#define STR_RPL_STATSDLINE /* 275 */ "%c %s %s" -#define STR_RPL_WHOISCERTFP /* 276 */ "%s :has client certificate fingerprint %s" -#define STR_RPL_AWAY /* 301 */ "%s :%s" -#define STR_RPL_USERHOST /* 302 */ ":%s %s %s %s %s" -#define STR_RPL_ISON /* 303 */ ":" -#define STR_RPL_UNAWAY /* 305 */ ":You are no longer marked as being away" -#define STR_RPL_NOWAWAY /* 306 */ ":You have been marked as being away" -#define STR_RPL_WHOISREGNICK /* 307 */ "%s :is identified for this nick" -#define STR_RPL_RULESSTART /* 308 */ ":- %s Server Rules - " -#define STR_RPL_ENDOFRULES /* 309 */ ":End of RULES command." -#define STR_RPL_WHOISUSER /* 311 */ "%s %s %s * :%s" -#define STR_RPL_WHOISSERVER /* 312 */ "%s %s :%s" -#define STR_RPL_WHOISOPERATOR /* 313 */ "%s :is %s" -#define STR_RPL_WHOWASUSER /* 314 */ "%s %s %s * :%s" -#define STR_RPL_ENDOFWHO /* 315 */ "%s :End of /WHO list." -#define STR_RPL_WHOISIDLE /* 317 */ "%s %lld %lld :seconds idle, signon time" -#define STR_RPL_ENDOFWHOIS /* 318 */ "%s :End of /WHOIS list." -#define STR_RPL_WHOISCHANNELS /* 319 */ "%s :%s" -#define STR_RPL_WHOISSPECIAL /* 320 */ "%s :%s" -#define STR_RPL_LISTSTART /* 321 */ "Channel :Users Name" -#define STR_RPL_LIST /* 322 */ "%s %d :%s %s" -#define STR_RPL_LISTEND /* 323 */ ":End of /LIST" -#define STR_RPL_CHANNELMODEIS /* 324 */ "%s %s %s" -#define STR_RPL_CREATIONTIME /* 329 */ "%s %lld" -#define STR_RPL_WHOISLOGGEDIN /* 330 */ "%s %s :is logged in as" -#define STR_RPL_NOTOPIC /* 331 */ "%s :No topic is set." -#define STR_RPL_TOPIC /* 332 */ "%s :%s" -#define STR_RPL_TOPICWHOTIME /* 333 */ "%s %s %lld" -#define STR_RPL_LISTSYNTAX /* 334 */ ":%s" -#define STR_RPL_WHOISBOT /* 335 */ "%s :is a \2Bot\2 on %s" -#define STR_RPL_INVITELIST /* 336 */ ":%s" -#define STR_RPL_ENDOFINVITELIST /* 337 */ ":End of /INVITE list." -#define STR_RPL_USERIP /* 340 */ ":%s %s %s %s %s" -#define STR_RPL_INVITING /* 341 */ "%s %s" -#define STR_RPL_WHOISCOUNTRY /* 344 */ "%s %s :is connecting from %s" -#define STR_RPL_INVEXLIST /* 346 */ "%s %s %s %lld" -#define STR_RPL_ENDOFINVEXLIST /* 347 */ "%s :End of Channel Invite List" -#define STR_RPL_EXLIST /* 348 */ "%s %s %s %lld" -#define STR_RPL_ENDOFEXLIST /* 349 */ "%s :End of Channel Exception List" -#define STR_RPL_VERSION /* 351 */ "%s.%s %s :%s%s%s [%s=%d]" -#define STR_RPL_WHOREPLY /* 352 */ "%s %s %s %s %s %s :%d %s" -#define STR_RPL_NAMREPLY /* 353 */ "%s" -#define STR_RPL_CLOSING /* 362 */ "%s :Closed. Status = %d" -#define STR_RPL_CLOSEEND /* 363 */ "%d: Connections Closed" -#define STR_RPL_LINKS /* 364 */ "%s %s :%d %s" -#define STR_RPL_ENDOFLINKS /* 365 */ "%s :End of /LINKS list." -#define STR_RPL_ENDOFNAMES /* 366 */ "%s :End of /NAMES list." -#define STR_RPL_BANLIST /* 367 */ "%s %s %s %lld" -#define STR_RPL_ENDOFBANLIST /* 368 */ "%s :End of Channel Ban List" -#define STR_RPL_ENDOFWHOWAS /* 369 */ "%s :End of WHOWAS" -#define STR_RPL_INFO /* 371 */ ":%s" -#define STR_RPL_MOTD /* 372 */ ":- %s" -#define STR_RPL_ENDOFINFO /* 374 */ ":End of /INFO list." -#define STR_RPL_MOTDSTART /* 375 */ ":- %s Message of the Day - " -#define STR_RPL_ENDOFMOTD /* 376 */ ":End of /MOTD command." -#define STR_RPL_WHOISHOST /* 378 */ "%s :is connecting from %s@%s %s" -#define STR_RPL_WHOISMODES /* 379 */ "%s :is using modes %s %s" -#define STR_RPL_YOUREOPER /* 381 */ ":You are now an IRC Operator" -#define STR_RPL_REHASHING /* 382 */ "%s :Rehashing" -#define STR_RPL_QLIST /* 386 */ "%s %s" -#define STR_RPL_ENDOFQLIST /* 387 */ "%s :End of Channel Owner List" -#define STR_RPL_ALIST /* 388 */ "%s %s" -#define STR_RPL_ENDOFALIST /* 389 */ "%s :End of Protected User List" -#define STR_RPL_TIME /* 391 */ "%s :%s" -#define STR_RPL_HOSTHIDDEN /* 396 */ "%s :is now your displayed host" -#define STR_ERR_NOSUCHNICK /* 401 */ "%s :No such nick/channel" -#define STR_ERR_NOSUCHSERVER /* 402 */ "%s :No such server" -#define STR_ERR_NOSUCHCHANNEL /* 403 */ "%s :No such channel" -#define STR_ERR_CANNOTSENDTOCHAN /* 404 */ "%s :%s (%s)" -#define STR_ERR_TOOMANYCHANNELS /* 405 */ "%s :You have joined too many channels" -#define STR_ERR_WASNOSUCHNICK /* 406 */ "%s :There was no such nickname" -#define STR_ERR_TOOMANYTARGETS /* 407 */ "%s :Too many targets. The maximum is %d for %s." -#define STR_ERR_NOORIGIN /* 409 */ ":No origin specified" -#define STR_ERR_INVALIDCAPCMD /* 410 */ "%s :Invalid CAP subcommand" -#define STR_ERR_NORECIPIENT /* 411 */ ":No recipient given (%s)" -#define STR_ERR_NOTEXTTOSEND /* 412 */ ":No text to send" -#define STR_ERR_TOOMANYMATCHES /* 416 */ "%s :%s" -#define STR_ERR_INPUTTOOLONG /* 417 */ ":Input line was too long" -#define STR_ERR_UNKNOWNCOMMAND /* 421 */ "%s :Unknown command" -#define STR_ERR_NOMOTD /* 422 */ ":MOTD File is missing" -#define STR_ERR_NOADMININFO /* 423 */ "%s :No administrative info available" -#define STR_ERR_NOOPERMOTD /* 425 */ ":OPERMOTD File is missing" -#define STR_ERR_TOOMANYAWAY /* 429 */ ":Too Many aways - Flood Protection activated" -#define STR_ERR_NONICKNAMEGIVEN /* 431 */ ":No nickname given" -#define STR_ERR_ERRONEUSNICKNAME /* 432 */ "%s :Nickname is unavailable: %s" -#define STR_ERR_NICKNAMEINUSE /* 433 */ "%s :Nickname is already in use." -#define STR_ERR_NORULES /* 434 */ ":RULES File is missing" -#define STR_ERR_BANNICKCHANGE /* 437 */ "%s :Cannot change nickname while banned on channel" -#define STR_ERR_NCHANGETOOFAST /* 438 */ "%s :Nick change too fast. Please try again later." -#define STR_ERR_TARGETTOOFAST /* 439 */ "%s :Message target change too fast. Please wait %lld seconds" -#define STR_ERR_SERVICESDOWN /* 440 */ "%s :Services are currently down. Please try again later." -#define STR_ERR_USERNOTINCHANNEL /* 441 */ "%s %s :They aren't on that channel" -#define STR_ERR_NOTONCHANNEL /* 442 */ "%s :You're not on that channel" -#define STR_ERR_USERONCHANNEL /* 443 */ "%s %s :is already on channel" -#define STR_ERR_NONICKCHANGE /* 447 */ ":Can not change nickname while on %s (+N)" -#define STR_ERR_FORBIDDENCHANNEL /* 448 */ "%s :Cannot join channel: %s" -#define STR_ERR_NOTREGISTERED /* 451 */ ":You have not registered" -#define STR_ERR_NOTFORHALFOPS /* 460 */ ":Halfops cannot set mode %c" -#define STR_ERR_NEEDMOREPARAMS /* 461 */ "%s :Not enough parameters" -#define STR_ERR_ALREADYREGISTRED /* 462 */ ":You may not reregister" -#define STR_ERR_PASSWDMISMATCH /* 464 */ ":Password Incorrect" -#define STR_ERR_YOUREBANNEDCREEP /* 465 */ ":%s" -#define STR_ERR_ONLYSERVERSCANCHANGE /* 468 */ "%s :Only servers can change that mode" -#define STR_ERR_LINKCHANNEL /* 470 */ "%s %s :[Link] %s has become full, so you are automatically being transferred to the linked channel %s" -#define STR_ERR_CHANNELISFULL /* 471 */ "%s :Cannot join channel (+l)" -#define STR_ERR_UNKNOWNMODE /* 472 */ "%c :is unknown mode char to me" -#define STR_ERR_INVITEONLYCHAN /* 473 */ "%s :Cannot join channel (+i)" -#define STR_ERR_BANNEDFROMCHAN /* 474 */ "%s :Cannot join channel (+b)" -#define STR_ERR_BADCHANNELKEY /* 475 */ "%s :Cannot join channel (+k)" -#define STR_ERR_NEEDREGGEDNICK /* 477 */ "%s :You need a registered nick to join that channel." -#define STR_ERR_BANLISTFULL /* 478 */ "%s %s :Channel ban/ignore list is full" -#define STR_ERR_CANNOTKNOCK /* 480 */ ":Cannot knock on %s (%s)" -#define STR_ERR_NOPRIVILEGES /* 481 */ ":Permission Denied- You do not have the correct IRC operator privileges" -#define STR_ERR_CHANOPRIVSNEEDED /* 482 */ "%s :You're not channel operator" -#define STR_ERR_KILLDENY /* 485 */ ":Cannot kill protected user %s." -#define STR_ERR_NOTFORUSERS /* 487 */ ":%s is a server only command" -#define STR_ERR_SECUREONLYCHAN /* 489 */ "%s :Cannot join channel (Secure connection is required)" -#define STR_ERR_NOOPERHOST /* 491 */ ":No O-lines for your host" -#define STR_ERR_CHANOWNPRIVNEEDED /* 499 */ "%s :You're not a channel owner" -#define STR_ERR_TOOMANYJOINS /* 500 */ "%s :Too many join requests. Please wait a while and try again." -#define STR_ERR_UMODEUNKNOWNFLAG /* 501 */ ":Unknown MODE flag" -#define STR_ERR_USERSDONTMATCH /* 502 */ ":Cant change mode for other users" -#define STR_ERR_SILELISTFULL /* 511 */ "%s :Your silence list is full" -#define STR_ERR_TOOMANYWATCH /* 512 */ "%s :Maximum size for WATCH-list is 128 entries" -#define STR_ERR_TOOMANYDCC /* 514 */ "%s :Your dcc allow list is full. Maximum size is %d entries" -#define STR_ERR_DISABLED /* 517 */ "%s :%s" /* ircu */ -#define STR_ERR_NOINVITE /* 518 */ ":Cannot invite (+V) at channel %s" -#define STR_ERR_OPERONLY /* 520 */ ":Cannot join channel %s (IRCops only)" -#define STR_ERR_LISTSYNTAX /* 521 */ ":Bad list syntax, type /quote list ? or /raw list ?" -#define STR_ERR_WHOLIMEXCEED /* 523 */ ":Error, /who limit of %d exceeded. Please narrow your search down and try again" -#define STR_ERR_OPERSPVERIFY /* 524 */ "%s :Trying to join +s or +p channel as an oper. Please invite yourself first." -#define STR_ERR_CANTSENDTOUSER /* 531 */ "%s :%s" -#define STR_RPL_WHOISASN /* 569 */ "%u :%s [%s]" -#define STR_RPL_REAWAY /* 597 */ "%s %s %s %lld :%s" -#define STR_RPL_GONEAWAY /* 598 */ "%s %s %s %lld :%s" -#define STR_RPL_NOTAWAY /* 599 */ "%s %s %s %lld :is no longer away" -#define STR_RPL_LOGON /* 600 */ "%s %s %s %lld :logged online" -#define STR_RPL_LOGOFF /* 601 */ "%s %s %s %lld :logged offline" -#define STR_RPL_WATCHOFF /* 602 */ "%s %s %s %lld :stopped watching" -#define STR_RPL_WATCHSTAT /* 603 */ ":You have %d and are on %d WATCH entries" -#define STR_RPL_NOWON /* 604 */ "%s %s %s %lld :is online" -#define STR_RPL_NOWOFF /* 605 */ "%s %s %s %lld :is offline" -#define STR_RPL_WATCHLIST /* 606 */ ":%s" -#define STR_RPL_ENDOFWATCHLIST /* 607 */ ":End of WATCH %c" -#define STR_RPL_NOWISAWAY /* 609 */ "%s %s %s %lld :is away" -#define STR_RPL_MAPMORE /* 610 */ ":%s%-*s --> *more*" -#define STR_RPL_DCCSTATUS /* 617 */ ":%s has been %s your DCC allow list" -#define STR_RPL_DCCLIST /* 618 */ ":%s" -#define STR_RPL_ENDOFDCCLIST /* 619 */ ":End of DCCALLOW %s" -#define STR_RPL_DCCINFO /* 620 */ ":%s" -#define STR_RPL_SPAMCMDFWD /* 659 */ "%s :Command processed, but a copy has been sent to ircops for evaluation (anti-spam) purposes. [%s]" -#define STR_RPL_STARTTLS /* 670 */ ":STARTTLS successful, go ahead with TLS handshake" /* kineircd */ -#define STR_RPL_WHOISSECURE /* 671 */ "%s :%s" /* our variation on the kineircd numeric */ -#define STR_ERR_STARTTLS /* 691 */ ":%s" -#define STR_ERR_INVALIDMODEPARAM /* 696 */ "%s %c %s :%s" -#define STR_RPL_MONONLINE /* 730 */ ":%s!%s@%s" -#define STR_RPL_MONOFFLINE /* 731 */ ":%s" -#define STR_RPL_MONLIST /* 732 */ ":%s" -#define STR_RPL_ENDOFMONLIST /* 733 */ ":End of MONITOR list" -#define STR_ERR_MONLISTFULL /* 734 */ "%d %s :Monitor list is full." -#define STR_ERR_MLOCKRESTRICTED /* 742 */ "%s %c %s :MODE cannot be set due to channel having an active MLOCK restriction policy" -#define STR_RPL_LOGGEDIN /* 900 */ "%s!%s@%s %s :You are now logged in as %s." -#define STR_RPL_LOGGEDOUT /* 901 */ "%s!%s@%s :You are now logged out." -#define STR_RPL_SASLSUCCESS /* 903 */ ":SASL authentication successful" -#define STR_ERR_SASLFAIL /* 904 */ ":SASL authentication failed" -#define STR_ERR_SASLTOOLONG /* 905 */ ":SASL message too long" -#define STR_ERR_SASLABORTED /* 906 */ ":SASL authentication aborted" -#define STR_RPL_SASLMECHS /* 908 */ "%s :are available SASL mechanisms" -#define STR_ERR_CANNOTDOCOMMAND /* 972 */ "%s :%s" -#define STR_ERR_CANNOTCHANGECHANMODE /* 974 */ "%c :%s" +#define STR_RPL_WELCOME /* 001 */ ":Welcome to the %s IRC Network %s!%s@%s" +#define STR_RPL_YOURHOST /* 002 */ ":Your host is %s, running version %s" +#define STR_RPL_CREATED /* 003 */ ":This server was created %s" +#define STR_RPL_MYINFO /* 004 */ "%s %s %s %s" +#define STR_RPL_ISUPPORT /* 005 */ "%s :are supported by this server" +#define STR_RPL_MAP /* 006 */ ":%s%s %s | Users: %*ld (%*.2f%%)%s" +#define STR_RPL_MAPEND /* 007 */ ":End of /MAP" +#define STR_RPL_SNOMASK /* 008 */ "+%s :Server notice mask" +#define STR_RPL_REDIR /* 010 */ "%s %d :Please use this Server/Port instead" +#define STR_RPL_MAPUSERS /* 018 */ ":%d server%s and %d user%s, average %.2f users per server" +#define STR_RPL_REMOTEISUPPORT /* 105 */ "%s :are supported by this server" +#define STR_RPL_TRACELINK /* 200 */ "Link %s%s %s %s" +#define STR_RPL_TRACECONNECTING /* 201 */ "Attempt %s %s" +#define STR_RPL_TRACEHANDSHAKE /* 202 */ "Handshaking %s %s" +#define STR_RPL_TRACEUNKNOWN /* 203 */ "???? %s %s" +#define STR_RPL_TRACEOPERATOR /* 204 */ "Operator %s %s [%s] %lld" +#define STR_RPL_TRACEUSER /* 205 */ "User %s %s [%s] %lld" +#define STR_RPL_TRACESERVER /* 206 */ "Server %s %dS %dC %s %s!%s@%s %lld" +#define STR_RPL_TRACENEWTYPE /* 208 */ "%s 0 %s" +#define STR_RPL_TRACECLASS /* 209 */ "Class %s %d" +#define STR_RPL_STATSHELP /* 210 */ ":%s" +#define STR_RPL_STATSCOMMANDS /* 212 */ "%s %u %lu" +#define STR_RPL_STATSCLINE /* 213 */ "%c %s * %s %d %d %s" +#define STR_RPL_STATSILINE /* 215 */ "I %s %s %d %d %s %s %d" +#define STR_RPL_STATSQLINE /* 217 */ "%c %s %lld %lld %s %lld %lld %s :%s" +#define STR_RPL_STATSYLINE /* 218 */ "Y %s %d %d %d %d %d" +#define STR_RPL_ENDOFSTATS /* 219 */ "%c :End of /STATS report" +#define STR_RPL_UMODEIS /* 221 */ "%s" +#define STR_RPL_STATSGLINE /* 223 */ "%c %s %lld %lld %s %lld %lld %s %s :%s" +#define STR_RPL_STATSTLINE /* 224 */ "T %s %s %s" +#define STR_RPL_STATSNLINE /* 226 */ "n %s %s" +#define STR_RPL_STATSVLINE /* 227 */ "v %s %s %s" +#define STR_RPL_STATSBANVER /* 228 */ "%s %s" +#define STR_RPL_STATSSPAMF /* 229 */ "%c %s %s %s %lld %lld %lld %s %s %lld %lld %lld %lld %s :%s" +#define STR_RPL_STATSEXCEPTTKL /* 230 */ "%s %s %lld %lld %s %s :%s" +#define STR_RPL_RULES /* 232 */ ":- %s" +#define STR_RPL_STATSLLINE /* 241 */ "%c %s * %s %d %d" +#define STR_RPL_STATSUPTIME /* 242 */ ":Server Up %lld days, %lld:%02lld:%02lld" +#define STR_RPL_STATSOLINE /* 243 */ "%c %s * %s %s %s" +#define STR_RPL_STATSHLINE /* 244 */ "%c %s * %s %d %d" +#define STR_RPL_STATSXLINE /* 247 */ "X %s %d" +#define STR_RPL_STATSULINE /* 248 */ "U %s" +#define STR_RPL_STATSDEBUG /* 249 */ ":%s" +#define STR_RPL_STATSCONN /* 250 */ ":Highest connection count: %d (%d clients)" +#define STR_RPL_LUSERCLIENT /* 251 */ ":There are %d users and %d invisible on %d servers" +#define STR_RPL_LUSEROP /* 252 */ "%d :operator(s) online" +#define STR_RPL_LUSERUNKNOWN /* 253 */ "%d :unknown connection(s)" +#define STR_RPL_LUSERCHANNELS /* 254 */ "%d :channels formed" +#define STR_RPL_LUSERME /* 255 */ ":I have %d clients and %d servers" +#define STR_RPL_ADMINME /* 256 */ ":Administrative info about %s" +#define STR_RPL_ADMINLOC1 /* 257 */ ":%s" +#define STR_RPL_ADMINLOC2 /* 258 */ ":%s" +#define STR_RPL_ADMINEMAIL /* 259 */ ":%s" +#define STR_RPL_TRACELOG /* 261 */ "File %s %d" +#define STR_RPL_TRYAGAIN /* 263 */ "%s :Flooding detected. Please wait a while and try again." +#define STR_RPL_LOCALUSERS /* 265 */ "%d %d :Current local users %d, max %d" +#define STR_RPL_GLOBALUSERS /* 266 */ "%d %d :Current global users %d, max %d" +#define STR_RPL_SILELIST /* 271 */ "%s" +#define STR_RPL_ENDOFSILELIST /* 272 */ ":End of Silence List" +#define STR_RPL_STATSDLINE /* 275 */ "%c %s %s" +#define STR_RPL_WHOISCERTFP /* 276 */ "%s :has client certificate fingerprint %s" +#define STR_RPL_AWAY /* 301 */ "%s :%s" +#define STR_RPL_USERHOST /* 302 */ ":%s %s %s %s %s" +#define STR_RPL_ISON /* 303 */ ":" +#define STR_RPL_UNAWAY /* 305 */ ":You are no longer marked as being away" +#define STR_RPL_NOWAWAY /* 306 */ ":You have been marked as being away" +#define STR_RPL_WHOISREGNICK /* 307 */ "%s :is identified for this nick" +#define STR_RPL_RULESSTART /* 308 */ ":- %s Server Rules - " +#define STR_RPL_ENDOFRULES /* 309 */ ":End of RULES command." +#define STR_RPL_WHOISUSER /* 311 */ "%s %s %s * :%s" +#define STR_RPL_WHOISSERVER /* 312 */ "%s %s :%s" +#define STR_RPL_WHOISOPERATOR /* 313 */ "%s :is %s" +#define STR_RPL_WHOWASUSER /* 314 */ "%s %s %s * :%s" +#define STR_RPL_ENDOFWHO /* 315 */ "%s :End of /WHO list." +#define STR_RPL_WHOISIDLE /* 317 */ "%s %lld %lld :seconds idle, signon time" +#define STR_RPL_ENDOFWHOIS /* 318 */ "%s :End of /WHOIS list." +#define STR_RPL_WHOISCHANNELS /* 319 */ "%s :%s" +#define STR_RPL_WHOISSPECIAL /* 320 */ "%s :%s" +#define STR_RPL_LISTSTART /* 321 */ "Channel :Users Name" +#define STR_RPL_LIST /* 322 */ "%s %d :%s %s" +#define STR_RPL_LISTEND /* 323 */ ":End of /LIST" +#define STR_RPL_CHANNELMODEIS /* 324 */ "%s %s %s" +#define STR_RPL_CREATIONTIME /* 329 */ "%s %lld" +#define STR_RPL_WHOISLOGGEDIN /* 330 */ "%s %s :is logged in as" +#define STR_RPL_NOTOPIC /* 331 */ "%s :No topic is set." +#define STR_RPL_TOPIC /* 332 */ "%s :%s" +#define STR_RPL_TOPICWHOTIME /* 333 */ "%s %s %lld" +#define STR_RPL_LISTSYNTAX /* 334 */ ":%s" +#define STR_RPL_WHOISBOT /* 335 */ "%s :is a \2Bot\2 on %s" +#define STR_RPL_INVITELIST /* 336 */ ":%s" +#define STR_RPL_ENDOFINVITELIST /* 337 */ ":End of /INVITE list." +#define STR_RPL_USERIP /* 340 */ ":%s %s %s %s %s" +#define STR_RPL_INVITING /* 341 */ "%s %s" +#define STR_RPL_WHOISCOUNTRY /* 344 */ "%s %s :is connecting from %s" +#define STR_RPL_INVEXLIST /* 346 */ "%s %s %s %lld" +#define STR_RPL_ENDOFINVEXLIST /* 347 */ "%s :End of Channel Invite List" +#define STR_RPL_EXLIST /* 348 */ "%s %s %s %lld" +#define STR_RPL_ENDOFEXLIST /* 349 */ "%s :End of Channel Exception List" +#define STR_RPL_VERSION /* 351 */ "%s.%s %s :%s%s%s [%s=%d]" +#define STR_RPL_WHOREPLY /* 352 */ "%s %s %s %s %s %s :%d %s" +#define STR_RPL_NAMREPLY /* 353 */ "%s" +#define STR_RPL_CLOSING /* 362 */ "%s :Closed. Status = %d" +#define STR_RPL_CLOSEEND /* 363 */ "%d: Connections Closed" +#define STR_RPL_LINKS /* 364 */ "%s %s :%d %s" +#define STR_RPL_ENDOFLINKS /* 365 */ "%s :End of /LINKS list." +#define STR_RPL_ENDOFNAMES /* 366 */ "%s :End of /NAMES list." +#define STR_RPL_BANLIST /* 367 */ "%s %s %s %lld" +#define STR_RPL_ENDOFBANLIST /* 368 */ "%s :End of Channel Ban List" +#define STR_RPL_ENDOFWHOWAS /* 369 */ "%s :End of WHOWAS" +#define STR_RPL_INFO /* 371 */ ":%s" +#define STR_RPL_MOTD /* 372 */ ":- %s" +#define STR_RPL_ENDOFINFO /* 374 */ ":End of /INFO list." +#define STR_RPL_MOTDSTART /* 375 */ ":- %s Message of the Day - " +#define STR_RPL_ENDOFMOTD /* 376 */ ":End of /MOTD command." +#define STR_RPL_WHOISHOST /* 378 */ "%s :is connecting from %s@%s %s" +#define STR_RPL_WHOISMODES /* 379 */ "%s :is using modes %s %s" +#define STR_RPL_YOUREOPER /* 381 */ ":You are now an IRC Operator" +#define STR_RPL_REHASHING /* 382 */ "%s :Rehashing" +#define STR_RPL_QLIST /* 386 */ "%s %s" +#define STR_RPL_ENDOFQLIST /* 387 */ "%s :End of Channel Owner List" +#define STR_RPL_ALIST /* 388 */ "%s %s" +#define STR_RPL_ENDOFALIST /* 389 */ "%s :End of Protected User List" +#define STR_RPL_TIME /* 391 */ "%s :%s" +#define STR_RPL_HOSTHIDDEN /* 396 */ "%s :is now your displayed host" +#define STR_ERR_NOSUCHNICK /* 401 */ "%s :No such nick/channel" +#define STR_ERR_NOSUCHSERVER /* 402 */ "%s :No such server" +#define STR_ERR_NOSUCHCHANNEL /* 403 */ "%s :No such channel" +#define STR_ERR_CANNOTSENDTOCHAN /* 404 */ "%s :%s (%s)" +#define STR_ERR_TOOMANYCHANNELS /* 405 */ "%s :You have joined too many channels" +#define STR_ERR_WASNOSUCHNICK /* 406 */ "%s :There was no such nickname" +#define STR_ERR_TOOMANYTARGETS /* 407 */ "%s :Too many targets. The maximum is %d for %s." +#define STR_ERR_NOORIGIN /* 409 */ ":No origin specified" +#define STR_ERR_INVALIDCAPCMD /* 410 */ "%s :Invalid CAP subcommand" +#define STR_ERR_NORECIPIENT /* 411 */ ":No recipient given (%s)" +#define STR_ERR_NOTEXTTOSEND /* 412 */ ":No text to send" +#define STR_ERR_TOOMANYMATCHES /* 416 */ "%s :%s" +#define STR_ERR_INPUTTOOLONG /* 417 */ ":Input line was too long" +#define STR_ERR_UNKNOWNCOMMAND /* 421 */ "%s :Unknown command" +#define STR_ERR_NOMOTD /* 422 */ ":MOTD File is missing" +#define STR_ERR_NOADMININFO /* 423 */ "%s :No administrative info available" +#define STR_ERR_NOOPERMOTD /* 425 */ ":OPERMOTD File is missing" +#define STR_ERR_TOOMANYAWAY /* 429 */ ":Too Many aways - Flood Protection activated" +#define STR_ERR_NONICKNAMEGIVEN /* 431 */ ":No nickname given" +#define STR_ERR_ERRONEUSNICKNAME /* 432 */ "%s :Nickname is unavailable: %s" +#define STR_ERR_NICKNAMEINUSE /* 433 */ "%s :Nickname is already in use." +#define STR_ERR_NORULES /* 434 */ ":RULES File is missing" +#define STR_ERR_BANNICKCHANGE /* 437 */ "%s :Cannot change nickname while banned on channel" +#define STR_ERR_NCHANGETOOFAST /* 438 */ "%s :Nick change too fast. Please try again later." +#define STR_ERR_TARGETTOOFAST /* 439 */ "%s :Message target change too fast. Please wait %lld seconds" +#define STR_ERR_SERVICESDOWN /* 440 */ "%s :Services are currently down. Please try again later." +#define STR_ERR_USERNOTINCHANNEL /* 441 */ "%s %s :They aren't on that channel" +#define STR_ERR_NOTONCHANNEL /* 442 */ "%s :You're not on that channel" +#define STR_ERR_USERONCHANNEL /* 443 */ "%s %s :is already on channel" +#define STR_ERR_NONICKCHANGE /* 447 */ ":Can not change nickname while on %s (+N)" +#define STR_ERR_FORBIDDENCHANNEL /* 448 */ "%s :Cannot join channel: %s" +#define STR_ERR_NOTREGISTERED /* 451 */ ":You have not registered" +#define STR_ERR_NOTFORHALFOPS /* 460 */ ":Halfops cannot set mode %c" +#define STR_ERR_NEEDMOREPARAMS /* 461 */ "%s :Not enough parameters" +#define STR_ERR_ALREADYREGISTRED /* 462 */ ":You may not reregister" +#define STR_ERR_PASSWDMISMATCH /* 464 */ ":Password Incorrect" +#define STR_ERR_YOUREBANNEDCREEP /* 465 */ ":%s" +#define STR_ERR_ONLYSERVERSCANCHANGE /* 468 */ "%s :Only servers can change that mode" +#define STR_ERR_LINKCHANNEL /* 470 */ "%s %s :[Link] %s has become full, so you are automatically being transferred to the linked channel %s" +#define STR_ERR_CHANNELISFULL /* 471 */ "%s :Cannot join channel (+l)" +#define STR_ERR_UNKNOWNMODE /* 472 */ "%c :is unknown mode char to me" +#define STR_ERR_INVITEONLYCHAN /* 473 */ "%s :Cannot join channel (+i)" +#define STR_ERR_BANNEDFROMCHAN /* 474 */ "%s :Cannot join channel (+b)" +#define STR_ERR_BADCHANNELKEY /* 475 */ "%s :Cannot join channel (+k)" +#define STR_ERR_NEEDREGGEDNICK /* 477 */ "%s :You need a registered nick to join that channel." +#define STR_ERR_BANLISTFULL /* 478 */ "%s %s :Channel ban/ignore list is full" +#define STR_ERR_CANNOTKNOCK /* 480 */ ":Cannot knock on %s (%s)" +#define STR_ERR_NOPRIVILEGES /* 481 */ ":Permission Denied- You do not have the correct IRC operator privileges" +#define STR_ERR_CHANOPRIVSNEEDED /* 482 */ "%s :You're not channel operator" +#define STR_ERR_KILLDENY /* 485 */ ":Cannot kill protected user %s." +#define STR_ERR_NOTFORUSERS /* 487 */ ":%s is a server only command" +#define STR_ERR_SECUREONLYCHAN /* 489 */ "%s :Cannot join channel (Secure connection is required)" +#define STR_ERR_NOOPERHOST /* 491 */ ":No O-lines for your host" +#define STR_ERR_CHANOWNPRIVNEEDED /* 499 */ "%s :You're not a channel owner" +#define STR_ERR_TOOMANYJOINS /* 500 */ "%s :Too many join requests. Please wait a while and try again." +#define STR_ERR_UMODEUNKNOWNFLAG /* 501 */ ":Unknown MODE flag" +#define STR_ERR_USERSDONTMATCH /* 502 */ ":Cant change mode for other users" +#define STR_ERR_SILELISTFULL /* 511 */ "%s :Your silence list is full" +#define STR_ERR_TOOMANYWATCH /* 512 */ "%s :Maximum size for WATCH-list is 128 entries" +#define STR_ERR_TOOMANYDCC /* 514 */ "%s :Your dcc allow list is full. Maximum size is %d entries" +#define STR_ERR_DISABLED /* 517 */ "%s :%s" /* ircu */ +#define STR_ERR_NOINVITE /* 518 */ ":Cannot invite (+V) at channel %s" +#define STR_ERR_OPERONLY /* 520 */ ":Cannot join channel %s (IRCops only)" +#define STR_ERR_LISTSYNTAX /* 521 */ ":Bad list syntax, type /quote list ? or /raw list ?" +#define STR_ERR_WHOLIMEXCEED /* 523 */ ":Error, /who limit of %d exceeded. Please narrow your search down and try again" +#define STR_ERR_OPERSPVERIFY /* 524 */ "%s :Trying to join +s or +p channel as an oper. Please invite yourself first." +#define STR_ERR_CANTSENDTOUSER /* 531 */ "%s :%s" +#define STR_RPL_WHOISASN /* 569 */ "%u :%s [%s]" +#define STR_RPL_REAWAY /* 597 */ "%s %s %s %lld :%s" +#define STR_RPL_GONEAWAY /* 598 */ "%s %s %s %lld :%s" +#define STR_RPL_NOTAWAY /* 599 */ "%s %s %s %lld :is no longer away" +#define STR_RPL_LOGON /* 600 */ "%s %s %s %lld :logged online" +#define STR_RPL_LOGOFF /* 601 */ "%s %s %s %lld :logged offline" +#define STR_RPL_WATCHOFF /* 602 */ "%s %s %s %lld :stopped watching" +#define STR_RPL_WATCHSTAT /* 603 */ ":You have %d and are on %d WATCH entries" +#define STR_RPL_NOWON /* 604 */ "%s %s %s %lld :is online" +#define STR_RPL_NOWOFF /* 605 */ "%s %s %s %lld :is offline" +#define STR_RPL_WATCHLIST /* 606 */ ":%s" +#define STR_RPL_ENDOFWATCHLIST /* 607 */ ":End of WATCH %c" +#define STR_RPL_NOWISAWAY /* 609 */ "%s %s %s %lld :is away" +#define STR_RPL_MAPMORE /* 610 */ ":%s%-*s --> *more*" +#define STR_RPL_DCCSTATUS /* 617 */ ":%s has been %s your DCC allow list" +#define STR_RPL_DCCLIST /* 618 */ ":%s" +#define STR_RPL_ENDOFDCCLIST /* 619 */ ":End of DCCALLOW %s" +#define STR_RPL_DCCINFO /* 620 */ ":%s" +#define STR_RPL_SPAMCMDFWD /* 659 */ "%s :Command processed, but a copy has been sent to ircops for evaluation (anti-spam) purposes. [%s]" +#define STR_RPL_STARTTLS /* 670 */ ":STARTTLS successful, go ahead with TLS handshake" /* kineircd */ +#define STR_RPL_WHOISSECURE /* 671 */ "%s :%s" /* our variation on the kineircd numeric */ +#define STR_ERR_STARTTLS /* 691 */ ":%s" +#define STR_ERR_INVALIDMODEPARAM /* 696 */ "%s %c %s :%s" +#define STR_RPL_MONONLINE /* 730 */ ":%s!%s@%s" +#define STR_RPL_MONOFFLINE /* 731 */ ":%s" +#define STR_RPL_MONLIST /* 732 */ ":%s" +#define STR_RPL_ENDOFMONLIST /* 733 */ ":End of MONITOR list" +#define STR_ERR_MONLISTFULL /* 734 */ "%d %s :Monitor list is full." +#define STR_ERR_MLOCKRESTRICTED /* 742 */ "%s %c %s :MODE cannot be set due to channel having an active MLOCK restriction policy" +#define STR_RPL_LOGGEDIN /* 900 */ "%s!%s@%s %s :You are now logged in as %s." +#define STR_RPL_LOGGEDOUT /* 901 */ "%s!%s@%s :You are now logged out." +#define STR_RPL_SASLSUCCESS /* 903 */ ":SASL authentication successful" +#define STR_ERR_SASLFAIL /* 904 */ ":SASL authentication failed" +#define STR_ERR_SASLTOOLONG /* 905 */ ":SASL message too long" +#define STR_ERR_SASLABORTED /* 906 */ ":SASL authentication aborted" +#define STR_RPL_SASLMECHS /* 908 */ "%s :are available SASL mechanisms" +#define STR_ERR_CANNOTDOCOMMAND /* 972 */ "%s :%s" +#define STR_ERR_CANNOTCHANGECHANMODE /* 974 */ "%c :%s" diff --git a/include/resource.h b/include/resource.h index fc7ab1ee6..97d1a8e4f 100644 --- a/include/resource.h +++ b/include/resource.h @@ -2,58 +2,58 @@ // Microsoft Developer Studio generated include file. // Used by GENERIC.RC // $Id$ -#define IDC_USERID 1051 -#define IDC_REALNAME 1052 -#define IDC_PNICK 1053 -#define IDC_ANICK 1054 -#define IDC_SERVERLIST 1057 -#define IDC_NEWSERVER 1058 -#define IDC_EDITSERVER 1059 -#define IDC_IRCDCONF 1059 -#define IDC_DELSERVER 1060 -#define IDC_SHOW_GLOBOPS 1060 -#define IDC_SHOW_WALLOPS 1061 -#define IDC_SHOW_HELPOPS 1062 -#define IDC_SHOW_SERVNOTICE 1063 -#define IDC_INFOTEXT 1063 -#define IDM_OPEN 40001 -#define IDM_SAVE 40002 -#define IDM_SAVEAS 40003 -#define IDM_EXIT 40004 -#define IDM_ABOUT 40005 -#define IDM_WINDOWCHILD 40006 -#define IDM_REHASH 40007 -#define IDM_OPTIONS 40008 -#define IDM_CREDITS 40009 -#define IDM_DF 40010 -#define IDM_LICENSE 40011 -#define IDM_DBGOFF 41099 -#define IDM_DBGFATAL 41100 -#define IDM_DBGERROR 41101 -#define IDM_DBGNOTICE 41103 -#define IDM_DBGDNS 41104 -#define IDM_DBGINFO 41105 -#define IDM_DBGNUM 41106 -#define IDM_DBGSEND 41107 -#define IDM_DBGDEBUG 41108 -#define IDM_DBGMALLOC 41109 -#define IDM_DBGLIST 41110 -#define IDM_POPUP 50000 -#define IDC_STATIC -1 -#define IDM_IRCDRULES 65530 -#define IDM_IRCDMOTD 65531 -#define IDC_VERSION 65532 -#define IDM_SETUP 65536 -#define IDM_IRCDCONF 65535 +#define IDC_USERID 1051 +#define IDC_REALNAME 1052 +#define IDC_PNICK 1053 +#define IDC_ANICK 1054 +#define IDC_SERVERLIST 1057 +#define IDC_NEWSERVER 1058 +#define IDC_EDITSERVER 1059 +#define IDC_IRCDCONF 1059 +#define IDC_DELSERVER 1060 +#define IDC_SHOW_GLOBOPS 1060 +#define IDC_SHOW_WALLOPS 1061 +#define IDC_SHOW_HELPOPS 1062 +#define IDC_SHOW_SERVNOTICE 1063 +#define IDC_INFOTEXT 1063 +#define IDM_OPEN 40001 +#define IDM_SAVE 40002 +#define IDM_SAVEAS 40003 +#define IDM_EXIT 40004 +#define IDM_ABOUT 40005 +#define IDM_WINDOWCHILD 40006 +#define IDM_REHASH 40007 +#define IDM_OPTIONS 40008 +#define IDM_CREDITS 40009 +#define IDM_DF 40010 +#define IDM_LICENSE 40011 +#define IDM_DBGOFF 41099 +#define IDM_DBGFATAL 41100 +#define IDM_DBGERROR 41101 +#define IDM_DBGNOTICE 41103 +#define IDM_DBGDNS 41104 +#define IDM_DBGINFO 41105 +#define IDM_DBGNUM 41106 +#define IDM_DBGSEND 41107 +#define IDM_DBGDEBUG 41108 +#define IDM_DBGMALLOC 41109 +#define IDM_DBGLIST 41110 +#define IDM_POPUP 50000 +#define IDC_STATIC -1 +#define IDM_IRCDRULES 65530 +#define IDM_IRCDMOTD 65531 +#define IDC_VERSION 65532 +#define IDM_SETUP 65536 +#define IDM_IRCDCONF 65535 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 113 -#define _APS_NEXT_COMMAND_VALUE 40011 -#define _APS_NEXT_CONTROL_VALUE 1064 -#define _APS_NEXT_SYMED_VALUE 104 -#endif + #ifndef APSTUDIO_READONLY_SYMBOLS + #define _APS_NO_MFC 1 + #define _APS_NEXT_RESOURCE_VALUE 113 + #define _APS_NEXT_COMMAND_VALUE 40011 + #define _APS_NEXT_CONTROL_VALUE 1064 + #define _APS_NEXT_SYMED_VALUE 104 + #endif #endif diff --git a/include/struct.h b/include/struct.h index 77649fb03..5f5517016 100644 --- a/include/struct.h +++ b/include/struct.h @@ -20,7 +20,7 @@ * $Id$ */ -#ifndef __struct_include__ +#ifndef __struct_include__ #define __struct_include__ #include "config.h" @@ -29,18 +29,18 @@ * conflicting types with isalnum/isalpha/etc @ redhat. -- Syzop */ #define OPENSSL_NO_KRB5 -#include /* SSL stuff */ +#include /* SSL stuff */ #include #include #include #include -#include +#include #include #include #include #include #ifdef HAS_X509_check_host -#include + #include #endif #include #include @@ -50,24 +50,24 @@ #include #include #ifndef _WIN32 -#include -#include -#include + #include + #include + #include #endif #ifdef HAVE_SYSLOG -# include -# ifdef SYSSYSLOGH -# include -# endif -#ifndef UNREAL_LOGGER_CODE -/* undef these as they cause confusion with our ULOG_xxx codes */ -#undef LOG_DEBUG -#undef LOG_INFO -#undef LOG_WARNING -#undef LOG_ERROR -#undef LOG_FATAL -#endif + #include + #ifdef SYSSYSLOGH + #include + #endif + #ifndef UNREAL_LOGGER_CODE + /* undef these as they cause confusion with our ULOG_xxx codes */ + #undef LOG_DEBUG + #undef LOG_INFO + #undef LOG_WARNING + #undef LOG_ERROR + #undef LOG_FATAL + #endif #endif #define PCRE2_CODE_UNIT_WIDTH 8 #include "pcre2.h" @@ -104,7 +104,7 @@ typedef struct ConfigItem_allow ConfigItem_allow; typedef struct ConfigFlag_allow ConfigFlag_allow; typedef struct ConfigItem_allow_channel ConfigItem_allow_channel; typedef struct ConfigItem_allow_dcc ConfigItem_allow_dcc; -typedef struct ConfigItem_link ConfigItem_link; +typedef struct ConfigItem_link ConfigItem_link; typedef struct ConfigItem_ban ConfigItem_ban; typedef struct ConfigItem_deny_dcc ConfigItem_deny_dcc; typedef struct ConfigItem_deny_channel ConfigItem_deny_channel; @@ -120,8 +120,8 @@ typedef struct Secret Secret; typedef struct ListStruct ListStruct; typedef struct ListStructPrio ListStructPrio; -#define CFG_TIME 0x0001 -#define CFG_SIZE 0x0002 +#define CFG_TIME 0x0001 +#define CFG_SIZE 0x0002 #define CFG_YESNO 0x0004 typedef struct Watch Watch; @@ -147,18 +147,28 @@ typedef struct LocalMember LocalMember; typedef struct OutgoingWebRequest OutgoingWebRequest; typedef struct OutgoingWebResponse OutgoingWebResponse; -typedef enum LineCacheUserType { LCUT_NORMAL=0, LCUT_OPER=1, LCUT_REMOTE=2 } LineCacheUserType; +typedef enum LineCacheUserType { + LCUT_NORMAL = 0, + LCUT_OPER = 1, + LCUT_REMOTE = 2 +} LineCacheUserType; typedef struct LineCacheLine LineCacheLine; typedef struct LineCache LineCache; -typedef enum OperClassEntryType { OPERCLASSENTRY_ALLOW=1, OPERCLASSENTRY_DENY=2} OperClassEntryType; +typedef enum OperClassEntryType { + OPERCLASSENTRY_ALLOW = 1, + OPERCLASSENTRY_DENY = 2 +} OperClassEntryType; -typedef enum OperPermission { OPER_ALLOW=1, OPER_DENY=0} OperPermission; +typedef enum OperPermission { + OPER_ALLOW = 1, + OPER_DENY = 0 +} OperPermission; typedef enum SendType { - SEND_TYPE_PRIVMSG = 0, - SEND_TYPE_NOTICE = 1, - SEND_TYPE_TAGMSG = 2 + SEND_TYPE_PRIVMSG = 0, + SEND_TYPE_NOTICE = 1, + SEND_TYPE_TAGMSG = 2 } SendType; struct OperClassValidator; @@ -170,59 +180,59 @@ typedef struct OperClassACLEntry OperClassACLEntry; typedef struct OperClassACLEntryVar OperClassACLEntryVar; typedef struct OperClassCheckParams OperClassCheckParams; -typedef OperPermission (*OperClassEntryEvalCallback)(OperClassACLEntryVar* variables,OperClassCheckParams* params); +typedef OperPermission (*OperClassEntryEvalCallback)(OperClassACLEntryVar *variables, OperClassCheckParams *params); #ifndef VMSP -#include "dbuf.h" /* THIS REALLY SHOULDN'T BE HERE!!! --msa */ + #include "dbuf.h" /* THIS REALLY SHOULDN'T BE HERE!!! --msa */ #endif -#define HOSTLEN 63 /* Length of hostname */ -#define NICKLEN 30 -#define USERLEN 10 -#define REALLEN 50 -#define ACCOUNTLEN 30 -#define MAXTOPICLEN 360 /* absolute maximum permitted topic length (above this = potential desync) */ -#define MAXAWAYLEN 360 /* absolute maximum permitted away length (above this = potential desync) */ -#define MAXKICKLEN 360 /* absolute maximum kick length (above this = only cutoff danger) */ -#define MAXQUITLEN 395 /* absolute maximum quit length (above this = only cutoff danger) */ -#define CHANNELLEN 32 -#define PASSWDLEN 256 /* some insane large limit (previously: 20, 32, 48) */ -#define KEYLEN 23 -#define LINKLEN 32 -#define BUFSIZE 512 /* WARNING: *DONT* CHANGE THIS!!!! */ -#define MAXTAGSIZE 8192 /**< Maximum length of message tags (4K user + 4K server) */ -#define MAXLINELENGTH_USER (MAXTAGSIZE+BUFSIZE) /**< Maximum length of a line on IRC (for non-servers): 4k client tags + 4k server tags + 512 bytes (IRCv3) */ -#define MAXLINELENGTH 16384 /**< Maximum length of a line on IRC: from servers is 16k */ -#define READBUFSIZE MAXLINELENGTH /**< for the read buffer */ -#define MAXRECIPIENTS 20 -#define MAXSILELENGTH NICKLEN+USERLEN+HOSTLEN+10 -#define IDLEN 12 -#define SIDLEN 3 -#define SWHOISLEN 256 -#define OPERCLASSLEN 64 -#define UMODETABLESZ (sizeof(long) * 8) -#define MAXCCUSERS 20 /* Maximum for set::anti-flood::max-concurrent-conversations */ -#define BATCHLEN 22 -#define MAXBATCHREFLEN 48 /* Max length of client-sent batch reference tags */ +#define HOSTLEN 63 /* Length of hostname */ +#define NICKLEN 30 +#define USERLEN 10 +#define REALLEN 50 +#define ACCOUNTLEN 30 +#define MAXTOPICLEN 360 /* absolute maximum permitted topic length (above this = potential desync) */ +#define MAXAWAYLEN 360 /* absolute maximum permitted away length (above this = potential desync) */ +#define MAXKICKLEN 360 /* absolute maximum kick length (above this = only cutoff danger) */ +#define MAXQUITLEN 395 /* absolute maximum quit length (above this = only cutoff danger) */ +#define CHANNELLEN 32 +#define PASSWDLEN 256 /* some insane large limit (previously: 20, 32, 48) */ +#define KEYLEN 23 +#define LINKLEN 32 +#define BUFSIZE 512 /* WARNING: *DONT* CHANGE THIS!!!! */ +#define MAXTAGSIZE 8192 /**< Maximum length of message tags (4K user + 4K server) */ +#define MAXLINELENGTH_USER (MAXTAGSIZE + BUFSIZE) /**< Maximum length of a line on IRC (for non-servers): 4k client tags + 4k server tags + 512 bytes (IRCv3) */ +#define MAXLINELENGTH 16384 /**< Maximum length of a line on IRC: from servers is 16k */ +#define READBUFSIZE MAXLINELENGTH /**< for the read buffer */ +#define MAXRECIPIENTS 20 +#define MAXSILELENGTH NICKLEN + USERLEN + HOSTLEN + 10 +#define IDLEN 12 +#define SIDLEN 3 +#define SWHOISLEN 256 +#define OPERCLASSLEN 64 +#define UMODETABLESZ (sizeof(long) * 8) +#define MAXCCUSERS 20 /* Maximum for set::anti-flood::max-concurrent-conversations */ +#define BATCHLEN 22 +#define MAXBATCHREFLEN 48 /* Max length of client-sent batch reference tags */ /* * Watch it - Don't change this unless you also change the ERR_TOOMANYWATCH * and PROTOCOL_SUPPORTED settings. */ -#define MAXWATCH 128 +#define MAXWATCH 128 -#define USERHOST_REPLYLEN (NICKLEN+HOSTLEN+USERLEN+5) +#define USERHOST_REPLYLEN (NICKLEN + HOSTLEN + USERLEN + 5) -#define ISUPPORTLEN BUFSIZE-HOSTLEN-NICKLEN-39 +#define ISUPPORTLEN BUFSIZE - HOSTLEN - NICKLEN - 39 /* NOTE: this must be down here so the stuff from struct.h IT uses works */ #include "whowas.h" /* Logging types */ -#define LOG_ERROR 0x0001 -#define LOG_KILL 0x0002 -#define LOG_SACMDS 0x0080 -#define LOG_CHGCMDS 0x0100 +#define LOG_ERROR 0x0001 +#define LOG_KILL 0x0002 +#define LOG_SACMDS 0x0080 +#define LOG_CHGCMDS 0x0100 #define LOG_OVERRIDE 0x0200 typedef enum LogFieldType { @@ -239,7 +249,7 @@ typedef enum LogFieldType { typedef struct LogData { LogFieldType type; char *key; - char *label; /**< Display label for LOG_FIELD_OPTIONAL_NAME_VALUE, NULL otherwise */ + char *label; /**< Display label for LOG_FIELD_OPTIONAL_NAME_VALUE, NULL otherwise */ union { int64_t integer; char *string; @@ -271,15 +281,15 @@ typedef enum LogType { LOG_TYPE_JSON = 2, } LogType; -#define LOG_CATEGORY_LEN 32 -#define LOG_EVENT_ID_LEN 64 +#define LOG_CATEGORY_LEN 32 +#define LOG_EVENT_ID_LEN 64 typedef struct LogSource LogSource; struct LogSource { LogSource *prev, *next; LogLevel loglevel; char negative; /**< 1 if negative match (eg !operoverride), 0 if normal */ - char subsystem[LOG_CATEGORY_LEN+1]; - char event_id[LOG_EVENT_ID_LEN+1]; + char subsystem[LOG_CATEGORY_LEN + 1]; + char event_id[LOG_EVENT_ID_LEN + 1]; }; typedef struct Log Log; @@ -287,7 +297,7 @@ struct Log { Log *prev, *next; LogSource *sources; int type; - char destination[CHANNELLEN+1]; + char destination[CHANNELLEN + 1]; int show_event; /* for destination::file */ char *file; @@ -305,7 +315,15 @@ struct Log { }; /** This is used for deciding the in logs[] and temp_logs[] */ -typedef enum LogDestination { LOG_DEST_SNOMASK=0, LOG_DEST_OPER=1, LOG_DEST_REMOTE=2, LOG_DEST_CHANNEL=3, LOG_DEST_DISK=4, LOG_DEST_MEMORY=5, LOG_DEST_WEBHOOK=6 } LogDestination; +typedef enum LogDestination { + LOG_DEST_SNOMASK = 0, + LOG_DEST_OPER = 1, + LOG_DEST_REMOTE = 2, + LOG_DEST_CHANNEL = 3, + LOG_DEST_DISK = 4, + LOG_DEST_MEMORY = 5, + LOG_DEST_WEBHOOK = 6 +} LogDestination; #define NUM_LOG_DESTINATIONS 7 typedef struct LogEntry LogEntry; @@ -325,20 +343,20 @@ struct LogEntry { ** should be size_t but... --msa */ #ifndef offsetof -#define offsetof(t,m) (int)((&((t *)0L)->m)) + #define offsetof(t, m) (int)((&((t *)0L)->m)) #endif -#define elementsof(x) (sizeof(x)/sizeof(x[0])) +#define elementsof(x) (sizeof(x) / sizeof(x[0])) /* Calculate the size of an array */ -#define ARRAY_SIZEOF(x) (sizeof((x))/sizeof((x)[0])) +#define ARRAY_SIZEOF(x) (sizeof((x)) / sizeof((x)[0])) /* ** flags for bootup options (command line flags) */ -#define BOOT_DEBUG 1 -#define BOOT_TTY 2 -#define BOOT_NOFORK 4 +#define BOOT_DEBUG 1 +#define BOOT_TTY 2 +#define BOOT_NOFORK 4 /* Length of the key that you feed into siphash_generate_key() * DO NOT CHANGE THIS as the siphash code depends on it. @@ -351,7 +369,7 @@ struct LogEntry { * than 128 bits of randomness (62^22 > 2^128). * See mtag_add_or_inherit_msgid() for more information. */ -#define MSGIDLEN 22 +#define MSGIDLEN 22 /** This specifies the current client status or the client type - see @link ClientStatus @endlink in particular. * You may think "server" or "client" are the only choices here, but there are many more @@ -360,52 +378,52 @@ struct LogEntry { * @{ */ typedef enum ClientStatus { - CLIENT_STATUS_RPC = -10, /**< RPC Client (either local or remote) */ - CLIENT_STATUS_CONTROL = -9, /**< Client is on the control channel */ - CLIENT_STATUS_LOG = -8, /**< Client is a log file */ - CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE = -7, /**< Client is doing a STARTTLS handshake */ - CLIENT_STATUS_CONNECTING = -6, /**< Client is an outgoing connect */ - CLIENT_STATUS_TLS_CONNECT_HANDSHAKE = -5, /**< Client is doing an TLS handshake - outgoing connection */ - CLIENT_STATUS_TLS_ACCEPT_HANDSHAKE = -4, /**< Client is doing an TLS handshake - incoming connection */ - CLIENT_STATUS_HANDSHAKE = -3, /**< Client is doing a server handshake - outgoing connection */ - CLIENT_STATUS_ME = -2, /**< Client is &me (this server) */ - CLIENT_STATUS_UNKNOWN = -1, /**< Client is doing a hanshake. May become a server or user later, we don't know yet */ - CLIENT_STATUS_SERVER = 0, /**< Client is a server (fully authenticated) */ - CLIENT_STATUS_USER = 1, /**< Client is a user (fully authenticated) */ + CLIENT_STATUS_RPC = -10, /**< RPC Client (either local or remote) */ + CLIENT_STATUS_CONTROL = -9, /**< Client is on the control channel */ + CLIENT_STATUS_LOG = -8, /**< Client is a log file */ + CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE = -7, /**< Client is doing a STARTTLS handshake */ + CLIENT_STATUS_CONNECTING = -6, /**< Client is an outgoing connect */ + CLIENT_STATUS_TLS_CONNECT_HANDSHAKE = -5, /**< Client is doing an TLS handshake - outgoing connection */ + CLIENT_STATUS_TLS_ACCEPT_HANDSHAKE = -4, /**< Client is doing an TLS handshake - incoming connection */ + CLIENT_STATUS_HANDSHAKE = -3, /**< Client is doing a server handshake - outgoing connection */ + CLIENT_STATUS_ME = -2, /**< Client is &me (this server) */ + CLIENT_STATUS_UNKNOWN = -1, /**< Client is doing a hanshake. May become a server or user later, we don't know yet */ + CLIENT_STATUS_SERVER = 0, /**< Client is a server (fully authenticated) */ + CLIENT_STATUS_USER = 1, /**< Client is a user (fully authenticated) */ } ClientStatus; -#define MyConnect(x) ((x)->local) /**< Is a locally connected client (server or user) */ -#define MyUser(x) (MyConnect(x) && IsUser(x)) /**< Is a locally connected user */ -#define IsUser(x) ((x)->status == CLIENT_STATUS_USER) /**< Is a user that has completed the connection handshake */ -#define IsRegistered(x) ((x)->status >= CLIENT_STATUS_SERVER) /**< Client has completed the connection handshake (user or server) */ -#define IsConnecting(x) ((x)->status == CLIENT_STATUS_CONNECTING) /**< Is an outgoing connect to another server */ -#define IsHandshake(x) ((x)->status == CLIENT_STATUS_HANDSHAKE) /**< Is doing a handshake (while connecting to another server) */ -#define IsMe(x) ((x)->status == CLIENT_STATUS_ME) /**< This is true for &me */ +#define MyConnect(x) ((x)->local) /**< Is a locally connected client (server or user) */ +#define MyUser(x) (MyConnect(x) && IsUser(x)) /**< Is a locally connected user */ +#define IsUser(x) ((x)->status == CLIENT_STATUS_USER) /**< Is a user that has completed the connection handshake */ +#define IsRegistered(x) ((x)->status >= CLIENT_STATUS_SERVER) /**< Client has completed the connection handshake (user or server) */ +#define IsConnecting(x) ((x)->status == CLIENT_STATUS_CONNECTING) /**< Is an outgoing connect to another server */ +#define IsHandshake(x) ((x)->status == CLIENT_STATUS_HANDSHAKE) /**< Is doing a handshake (while connecting to another server) */ +#define IsMe(x) ((x)->status == CLIENT_STATUS_ME) /**< This is true for &me */ /** Client is not fully registered yet. May become a user or a server, we don't know yet. */ -#define IsUnknown(x) (((x)->status == CLIENT_STATUS_UNKNOWN) || ((x)->status == CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE)) -#define IsServer(x) ((x)->status == CLIENT_STATUS_SERVER) /**< Is a server that has completed the connection handshake */ -#define IsControl(x) ((x)->status == CLIENT_STATUS_CONTROL) /**< Is on the control channel (not an IRC client) */ -#define IsRPC(x) ((x)->status == CLIENT_STATUS_RPC) /**< Is doing RPC (not an IRC client) */ -#define IsLog(x) ((x)->status == CLIENT_STATUS_LOG) /**< Is a log file, not a user or server */ -#define IsStartTLSHandshake(x) ((x)->status == CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE) /**< Currently doing a STARTTLS handshake */ -#define IsTLSAcceptHandshake(x) ((x)->status == CLIENT_STATUS_TLS_ACCEPT_HANDSHAKE) /**< Currently doing a TLS handshake - incoming */ -#define IsTLSConnectHandshake(x) ((x)->status == CLIENT_STATUS_TLS_CONNECT_HANDSHAKE) /**< Currently doing a TLS handshake - outgoing */ +#define IsUnknown(x) (((x)->status == CLIENT_STATUS_UNKNOWN) || ((x)->status == CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE)) +#define IsServer(x) ((x)->status == CLIENT_STATUS_SERVER) /**< Is a server that has completed the connection handshake */ +#define IsControl(x) ((x)->status == CLIENT_STATUS_CONTROL) /**< Is on the control channel (not an IRC client) */ +#define IsRPC(x) ((x)->status == CLIENT_STATUS_RPC) /**< Is doing RPC (not an IRC client) */ +#define IsLog(x) ((x)->status == CLIENT_STATUS_LOG) /**< Is a log file, not a user or server */ +#define IsStartTLSHandshake(x) ((x)->status == CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE) /**< Currently doing a STARTTLS handshake */ +#define IsTLSAcceptHandshake(x) ((x)->status == CLIENT_STATUS_TLS_ACCEPT_HANDSHAKE) /**< Currently doing a TLS handshake - incoming */ +#define IsTLSConnectHandshake(x) ((x)->status == CLIENT_STATUS_TLS_CONNECT_HANDSHAKE) /**< Currently doing a TLS handshake - outgoing */ /** Currently doing a TLS handshake (incoming/outgoing/STARTTLS) */ #define IsTLSHandshake(x) (IsTLSAcceptHandshake(x) || IsTLSConnectHandshake(x) | IsStartTLSHandshake(x)) -#define SetStartTLSHandshake(x) ((x)->status = CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE) -#define SetTLSAcceptHandshake(x) ((x)->status = CLIENT_STATUS_TLS_ACCEPT_HANDSHAKE) -#define SetTLSConnectHandshake(x) ((x)->status = CLIENT_STATUS_TLS_CONNECT_HANDSHAKE) -#define SetConnecting(x) ((x)->status = CLIENT_STATUS_CONNECTING) -#define SetHandshake(x) ((x)->status = CLIENT_STATUS_HANDSHAKE) -#define SetMe(x) ((x)->status = CLIENT_STATUS_ME) -#define SetUnknown(x) ((x)->status = CLIENT_STATUS_UNKNOWN) -#define SetServer(x) ((x)->status = CLIENT_STATUS_SERVER) -#define SetUser(x) ((x)->status = CLIENT_STATUS_USER) -#define SetLog(x) ((x)->status = CLIENT_STATUS_LOG) -#define SetControl(x) ((x)->status = CLIENT_STATUS_CONTROL) -#define SetRPC(x) ((x)->status = CLIENT_STATUS_RPC) -#define SetUser(x) ((x)->status = CLIENT_STATUS_USER) +#define SetStartTLSHandshake(x) ((x)->status = CLIENT_STATUS_TLS_STARTTLS_HANDSHAKE) +#define SetTLSAcceptHandshake(x) ((x)->status = CLIENT_STATUS_TLS_ACCEPT_HANDSHAKE) +#define SetTLSConnectHandshake(x) ((x)->status = CLIENT_STATUS_TLS_CONNECT_HANDSHAKE) +#define SetConnecting(x) ((x)->status = CLIENT_STATUS_CONNECTING) +#define SetHandshake(x) ((x)->status = CLIENT_STATUS_HANDSHAKE) +#define SetMe(x) ((x)->status = CLIENT_STATUS_ME) +#define SetUnknown(x) ((x)->status = CLIENT_STATUS_UNKNOWN) +#define SetServer(x) ((x)->status = CLIENT_STATUS_SERVER) +#define SetUser(x) ((x)->status = CLIENT_STATUS_USER) +#define SetLog(x) ((x)->status = CLIENT_STATUS_LOG) +#define SetControl(x) ((x)->status = CLIENT_STATUS_CONTROL) +#define SetRPC(x) ((x)->status = CLIENT_STATUS_RPC) +#define SetUser(x) ((x)->status = CLIENT_STATUS_USER) /** @} */ @@ -413,94 +431,102 @@ typedef enum ClientStatus { * @defgroup ClientFlags Client flags * @{ */ -#define CLIENT_FLAG_PINGSENT 0x00000001 /**< PING sent, no reply yet */ -#define CLIENT_FLAG_DEAD 0x00000002 /**< Client is dead: already quit/exited and removed from all lists -- Remaining part will soon be freed in main loop */ -#define CLIENT_FLAG_DEADSOCKET 0x00000004 /**< Local socket is dead but otherwise the client still exists fully -- Will soon exit in main loop */ -#define CLIENT_FLAG_KILLED 0x00000008 /**< Prevents "QUIT" from being sent for this */ -#define CLIENT_FLAG_MONITOR_REHASH 0x00000010 /**< Client is monitoring rehash output */ -#define CLIENT_FLAG_OUTGOING 0x00000020 /**< Outgoing connection (do not touch cptr->listener->clients) */ -#define CLIENT_FLAG_CLOSING 0x00000040 /**< Set when closing to suppress errors */ -#define CLIENT_FLAG_LISTEN 0x00000080 /**< Used to mark clients which we listen() on */ -#define CLIENT_FLAG_DNSLOOKUP 0x00000100 /**< Client is doing a DNS lookup */ -#define CLIENT_FLAG_IDENTLOOKUP 0x00000200 /**< Client is doing an Ident lookup (RFC931) */ -#define CLIENT_FLAG_IDENTLOOKUPSENT 0x00000400 /**< Set if we havent writen to ident server */ -#define CLIENT_FLAG_LOCALHOST 0x00000800 /**< Set for localhost clients */ -#define CLIENT_FLAG_IDENTSUCCESS 0x00001000 /**< Successful ident lookup achieved */ -#define CLIENT_FLAG_USEIDENT 0x00002000 /**< The allow { } block says we should use the ident (if available) */ -#define CLIENT_FLAG_NEXTCALL 0x00004000 /**< Next call (don't ask...) */ -#define CLIENT_FLAG_ULINE 0x00008000 /**< User/server is considered U-lined (eg: services) */ -#define CLIENT_FLAG_SQUIT 0x00010000 /**< Server has been /SQUIT by an oper */ -#define CLIENT_FLAG_PROTOCTL 0x00020000 /**< Received at least 1 PROTOCTL message */ -#define CLIENT_FLAG_EAUTH 0x00040000 /**< Server authenticated via PROTOCTL EAUTH */ -#define CLIENT_FLAG_NETINFO 0x00080000 /**< Received a NETINFO message */ -#define CLIENT_FLAG_QUARANTINE 0x00100000 /**< Quarantined server (don't allow ircops on this server) */ -#define CLIENT_FLAG_DCCNOTICE 0x00200000 /**< Has the user seen a notice on how to use DCCALLOW already? */ -#define CLIENT_FLAG_SHUNNED 0x00400000 /**< Connection is shunned (user cannot execute any commands) */ -#define CLIENT_FLAG_VIRUS 0x00800000 /**< Tagged by spamfilter as a virus */ -#define CLIENT_FLAG_TLS 0x01000000 /**< Connection is using TLS */ -#define CLIENT_FLAG_NOFAKELAG 0x02000000 /**< Exemption from fake lag */ -#define CLIENT_FLAG_DCCBLOCK 0x04000000 /**< Block all DCC send requests */ -#define CLIENT_FLAG_MAP 0x08000000 /**< Show this entry in /MAP (only used in map module) */ -#define CLIENT_FLAG_PINGWARN 0x10000000 /**< Server ping warning (remote server slow with responding to PINGs) */ -#define CLIENT_FLAG_NOHANDSHAKEDELAY 0x20000000 /**< No handshake delay */ -#define CLIENT_FLAG_SERVER_DISCONNECT_LOGGED 0x40000000 /**< Server disconnect message is (already) logged */ -#define CLIENT_FLAG_ASYNC_RPC 0x80000000 /**< Asynchronous remote RPC request - special case for rehash etc. */ -#define CLIENT_FLAG_IPUSERS_BUMPED 0x100000000 /**< The IpUsersBucket for this IP has been bumped (and needs to be decreased on disconnect) */ -#define CLIENT_FLAG_DEADSOCKET_IS_BANNED 0x200000000 /**< The deadsocket message should also send ERR_YOUREBANNEDCREEP and such */ -#define CLIENT_FLAG_CONNECT_FLOOD_CHECKED 0x400000000 /**< connect-flood has been checked (there are two hooks, so need this) */ -#define CLIENT_FLAG_IPV6 0x800000000 /**< client is using IPv6 */ +#define CLIENT_FLAG_PINGSENT 0x00000001 /**< PING sent, no reply yet */ +#define CLIENT_FLAG_DEAD 0x00000002 /**< Client is dead: already quit/exited and removed from all lists -- Remaining part will soon be freed in main loop */ +#define CLIENT_FLAG_DEADSOCKET 0x00000004 /**< Local socket is dead but otherwise the client still exists fully -- Will soon exit in main loop */ +#define CLIENT_FLAG_KILLED 0x00000008 /**< Prevents "QUIT" from being sent for this */ +#define CLIENT_FLAG_MONITOR_REHASH 0x00000010 /**< Client is monitoring rehash output */ +#define CLIENT_FLAG_OUTGOING 0x00000020 /**< Outgoing connection (do not touch cptr->listener->clients) */ +#define CLIENT_FLAG_CLOSING 0x00000040 /**< Set when closing to suppress errors */ +#define CLIENT_FLAG_LISTEN 0x00000080 /**< Used to mark clients which we listen() on */ +#define CLIENT_FLAG_DNSLOOKUP 0x00000100 /**< Client is doing a DNS lookup */ +#define CLIENT_FLAG_IDENTLOOKUP 0x00000200 /**< Client is doing an Ident lookup (RFC931) */ +#define CLIENT_FLAG_IDENTLOOKUPSENT 0x00000400 /**< Set if we havent writen to ident server */ +#define CLIENT_FLAG_LOCALHOST 0x00000800 /**< Set for localhost clients */ +#define CLIENT_FLAG_IDENTSUCCESS 0x00001000 /**< Successful ident lookup achieved */ +#define CLIENT_FLAG_USEIDENT 0x00002000 /**< The allow { } block says we should use the ident (if available) */ +#define CLIENT_FLAG_NEXTCALL 0x00004000 /**< Next call (don't ask...) */ +#define CLIENT_FLAG_ULINE 0x00008000 /**< User/server is considered U-lined (eg: services) */ +#define CLIENT_FLAG_SQUIT 0x00010000 /**< Server has been /SQUIT by an oper */ +#define CLIENT_FLAG_PROTOCTL 0x00020000 /**< Received at least 1 PROTOCTL message */ +#define CLIENT_FLAG_EAUTH 0x00040000 /**< Server authenticated via PROTOCTL EAUTH */ +#define CLIENT_FLAG_NETINFO 0x00080000 /**< Received a NETINFO message */ +#define CLIENT_FLAG_QUARANTINE 0x00100000 /**< Quarantined server (don't allow ircops on this server) */ +#define CLIENT_FLAG_DCCNOTICE 0x00200000 /**< Has the user seen a notice on how to use DCCALLOW already? */ +#define CLIENT_FLAG_SHUNNED 0x00400000 /**< Connection is shunned (user cannot execute any commands) */ +#define CLIENT_FLAG_VIRUS 0x00800000 /**< Tagged by spamfilter as a virus */ +#define CLIENT_FLAG_TLS 0x01000000 /**< Connection is using TLS */ +#define CLIENT_FLAG_NOFAKELAG 0x02000000 /**< Exemption from fake lag */ +#define CLIENT_FLAG_DCCBLOCK 0x04000000 /**< Block all DCC send requests */ +#define CLIENT_FLAG_MAP 0x08000000 /**< Show this entry in /MAP (only used in map module) */ +#define CLIENT_FLAG_PINGWARN 0x10000000 /**< Server ping warning (remote server slow with responding to PINGs) */ +#define CLIENT_FLAG_NOHANDSHAKEDELAY 0x20000000 /**< No handshake delay */ +#define CLIENT_FLAG_SERVER_DISCONNECT_LOGGED 0x40000000 /**< Server disconnect message is (already) logged */ +#define CLIENT_FLAG_ASYNC_RPC 0x80000000 /**< Asynchronous remote RPC request - special case for rehash etc. */ +#define CLIENT_FLAG_IPUSERS_BUMPED 0x100000000 /**< The IpUsersBucket for this IP has been bumped (and needs to be decreased on disconnect) */ +#define CLIENT_FLAG_DEADSOCKET_IS_BANNED 0x200000000 /**< The deadsocket message should also send ERR_YOUREBANNEDCREEP and such */ +#define CLIENT_FLAG_CONNECT_FLOOD_CHECKED 0x400000000 /**< connect-flood has been checked (there are two hooks, so need this) */ +#define CLIENT_FLAG_IPV6 0x800000000 /**< client is using IPv6 */ /** @} */ #define OPER_SNOMASKS "+bBcdfxkqsSoO" #define SEND_UMODES (SendUmodes) -#define ALL_UMODES (AllUmodes) +#define ALL_UMODES (AllUmodes) /* SEND_UMODES and ALL_UMODES are now handled by umode_get/umode_lget/umode_gget -- Syzop. */ -#define CLIENT_FLAG_ID (CLIENT_FLAG_USEIDENT|CLIENT_FLAG_IDENTSUCCESS) +#define CLIENT_FLAG_ID (CLIENT_FLAG_USEIDENT | CLIENT_FLAG_IDENTSUCCESS) /* PROTO_*: Server protocol extensions (acptr->local->proto). * Note that client protocol extensions have been moved * to the ClientCapability API which uses acptr->local->caps. */ -#define PROTO_VL 0x000001 /* Negotiated VL protocol */ -#define PROTO_VHP 0x000002 /* Send hostnames in NICKv2 even if not sethosted */ -#define PROTO_CLK 0x000004 /* Send cloaked host in the NICK command (regardless of +x/-x) */ -#define PROTO_MLOCK 0x000008 /* server supports MLOCK */ -#define PROTO_EXTSWHOIS 0x000010 /* extended SWHOIS support */ -#define PROTO_SJSBY 0x000020 /* SJOIN setby information (TS and nick) */ -#define PROTO_MTAGS 0x000040 /* Support message tags and big buffers */ -#define PROTO_NEXTBANS 0x000080 /* Server supports named extended bans */ -#define PROTO_BIGLINES 0x000100 /* BIGLINES support */ +#define PROTO_VL 0x000001 /* Negotiated VL protocol */ +#define PROTO_VHP 0x000002 /* Send hostnames in NICKv2 even if not sethosted */ +#define PROTO_CLK 0x000004 /* Send cloaked host in the NICK command (regardless of +x/-x) */ +#define PROTO_MLOCK 0x000008 /* server supports MLOCK */ +#define PROTO_EXTSWHOIS 0x000010 /* extended SWHOIS support */ +#define PROTO_SJSBY 0x000020 /* SJOIN setby information (TS and nick) */ +#define PROTO_MTAGS 0x000040 /* Support message tags and big buffers */ +#define PROTO_NEXTBANS 0x000080 /* Server supports named extended bans */ +#define PROTO_BIGLINES 0x000100 /* BIGLINES support */ /* For client capabilities: */ -#define CAP_INVERT 1L +#define CAP_INVERT 1L /** HasCapabilityFast() checks for a token if you know exactly which bit to check */ #define HasCapabilityFast(cptr, val) ((cptr)->local->caps & (val)) /** HasCapability() checks for a token by name and is slightly slower */ #define HasCapability(cptr, token) ((cptr)->local->caps & ClientCapabilityBit(token)) -#define SetCapabilityFast(cptr, val) do { (cptr)->local->caps |= (val); } while(0) -#define ClearCapabilityFast(cptr, val) do { (cptr)->local->caps &= ~(val); } while(0) +#define SetCapabilityFast(cptr, val) \ + do \ + { \ + (cptr)->local->caps |= (val); \ + } while (0) +#define ClearCapabilityFast(cptr, val) \ + do \ + { \ + (cptr)->local->caps &= ~(val); \ + } while (0) /* Usermode and snomask macros: */ -#define IsDeaf(x) ((x)->umodes & UMODE_DEAF) -#define IsOper(x) ((x)->umodes & UMODE_OPER) -#define IsInvisible(x) ((x)->umodes & UMODE_INVISIBLE) -#define IsRegNick(x) ((x)->umodes & UMODE_REGNICK) -#define IsHidden(x) ((x)->umodes & UMODE_HIDE) -#define IsSetHost(x) ((x)->umodes & UMODE_SETHOST) -#define IsHideOper(x) ((x)->umodes & UMODE_HIDEOPER) -#define SetOper(x) ((x)->umodes |= UMODE_OPER) -#define SetInvisible(x) ((x)->umodes |= UMODE_INVISIBLE) -#define SetRegNick(x) ((x)->umodes & UMODE_REGNICK) -#define SetHidden(x) ((x)->umodes |= UMODE_HIDE) -#define SetHideOper(x) ((x)->umodes |= UMODE_HIDEOPER) -#define IsSecureConnect(x) ((x)->umodes & UMODE_SECURE) -#define ClearOper(x) ((x)->umodes &= ~UMODE_OPER) -#define ClearInvisible(x) ((x)->umodes &= ~UMODE_INVISIBLE) -#define ClearHidden(x) ((x)->umodes &= ~UMODE_HIDE) -#define ClearHideOper(x) ((x)->umodes &= ~UMODE_HIDEOPER) +#define IsDeaf(x) ((x)->umodes & UMODE_DEAF) +#define IsOper(x) ((x)->umodes & UMODE_OPER) +#define IsInvisible(x) ((x)->umodes & UMODE_INVISIBLE) +#define IsRegNick(x) ((x)->umodes & UMODE_REGNICK) +#define IsHidden(x) ((x)->umodes & UMODE_HIDE) +#define IsSetHost(x) ((x)->umodes & UMODE_SETHOST) +#define IsHideOper(x) ((x)->umodes & UMODE_HIDEOPER) +#define SetOper(x) ((x)->umodes |= UMODE_OPER) +#define SetInvisible(x) ((x)->umodes |= UMODE_INVISIBLE) +#define SetRegNick(x) ((x)->umodes & UMODE_REGNICK) +#define SetHidden(x) ((x)->umodes |= UMODE_HIDE) +#define SetHideOper(x) ((x)->umodes |= UMODE_HIDEOPER) +#define IsSecureConnect(x) ((x)->umodes & UMODE_SECURE) +#define ClearOper(x) ((x)->umodes &= ~UMODE_OPER) +#define ClearInvisible(x) ((x)->umodes &= ~UMODE_INVISIBLE) +#define ClearHidden(x) ((x)->umodes &= ~UMODE_HIDE) +#define ClearHideOper(x) ((x)->umodes &= ~UMODE_HIDEOPER) /* Client flags macros: to check for via IsXX(), * to set via SetXX() and to clear the flag via ClearXX() @@ -509,41 +535,41 @@ typedef enum ClientStatus { * @addtogroup ClientFlags * @{ */ -#define IsIdentLookup(x) ((x)->flags & CLIENT_FLAG_IDENTLOOKUP) /**< Is doing Ident lookups */ -#define IsClosing(x) ((x)->flags & CLIENT_FLAG_CLOSING) /**< Is closing the connection */ -#define IsDCCBlock(x) ((x)->flags & CLIENT_FLAG_DCCBLOCK) -#define IsDCCNotice(x) ((x)->flags & CLIENT_FLAG_DCCNOTICE) -#define IsDead(x) ((x)->flags & CLIENT_FLAG_DEAD) -#define IsDeadSocket(x) ((x)->flags & CLIENT_FLAG_DEADSOCKET) -#define IsServerDisconnectLogged(x) ((x)->flags & CLIENT_FLAG_SERVER_DISCONNECT_LOGGED) -#define IsUseIdent(x) ((x)->flags & CLIENT_FLAG_USEIDENT) -#define IsDNSLookup(x) ((x)->flags & CLIENT_FLAG_DNSLOOKUP) -#define IsEAuth(x) ((x)->flags & CLIENT_FLAG_EAUTH) -#define IsIdentSuccess(x) ((x)->flags & CLIENT_FLAG_IDENTSUCCESS) -#define IsKilled(x) ((x)->flags & CLIENT_FLAG_KILLED) -#define IsMonitorRehash(x) ((x)->flags & CLIENT_FLAG_MONITOR_REHASH) -#define IsListening(x) ((x)->flags & CLIENT_FLAG_LISTEN) -#define IsLocalhost(x) ((x)->flags & CLIENT_FLAG_LOCALHOST) -#define IsMap(x) ((x)->flags & CLIENT_FLAG_MAP) -#define IsNextCall(x) ((x)->flags & CLIENT_FLAG_NEXTCALL) -#define IsNetInfo(x) ((x)->flags & CLIENT_FLAG_NETINFO) -#define IsNoFakeLag(x) ((x)->flags & CLIENT_FLAG_NOFAKELAG) -#define IsOutgoing(x) ((x)->flags & CLIENT_FLAG_OUTGOING) -#define IsPingSent(x) ((x)->flags & CLIENT_FLAG_PINGSENT) -#define IsPingWarning(x) ((x)->flags & CLIENT_FLAG_PINGWARN) -#define IsNoHandshakeDelay(x) ((x)->flags & CLIENT_FLAG_NOHANDSHAKEDELAY) -#define IsProtoctlReceived(x) ((x)->flags & CLIENT_FLAG_PROTOCTL) -#define IsQuarantined(x) ((x)->flags & CLIENT_FLAG_QUARANTINE) -#define IsShunned(x) ((x)->flags & CLIENT_FLAG_SHUNNED) -#define IsSQuit(x) ((x)->flags & CLIENT_FLAG_SQUIT) -#define IsTLS(x) ((x)->flags & CLIENT_FLAG_TLS) -#define IsSecure(x) ((x)->flags & CLIENT_FLAG_TLS) -#define IsULine(x) ((x)->flags & CLIENT_FLAG_ULINE) -#define IsSvsCmdOk(x) (((x)->flags & CLIENT_FLAG_ULINE) || ((iConf.limit_svscmds == LIMIT_SVSCMDS_SERVERS) && (IsServer((x)) || IsMe((x))))) -#define IsVirus(x) ((x)->flags & CLIENT_FLAG_VIRUS) -#define IsIdentLookupSent(x) ((x)->flags & CLIENT_FLAG_IDENTLOOKUPSENT) -#define IsAsyncRPC(x) ((x)->flags & CLIENT_FLAG_ASYNC_RPC) -#define IsIPV6(x) ((x)->flags & CLIENT_FLAG_IPV6) +#define IsIdentLookup(x) ((x)->flags & CLIENT_FLAG_IDENTLOOKUP) /**< Is doing Ident lookups */ +#define IsClosing(x) ((x)->flags & CLIENT_FLAG_CLOSING) /**< Is closing the connection */ +#define IsDCCBlock(x) ((x)->flags & CLIENT_FLAG_DCCBLOCK) +#define IsDCCNotice(x) ((x)->flags & CLIENT_FLAG_DCCNOTICE) +#define IsDead(x) ((x)->flags & CLIENT_FLAG_DEAD) +#define IsDeadSocket(x) ((x)->flags & CLIENT_FLAG_DEADSOCKET) +#define IsServerDisconnectLogged(x) ((x)->flags & CLIENT_FLAG_SERVER_DISCONNECT_LOGGED) +#define IsUseIdent(x) ((x)->flags & CLIENT_FLAG_USEIDENT) +#define IsDNSLookup(x) ((x)->flags & CLIENT_FLAG_DNSLOOKUP) +#define IsEAuth(x) ((x)->flags & CLIENT_FLAG_EAUTH) +#define IsIdentSuccess(x) ((x)->flags & CLIENT_FLAG_IDENTSUCCESS) +#define IsKilled(x) ((x)->flags & CLIENT_FLAG_KILLED) +#define IsMonitorRehash(x) ((x)->flags & CLIENT_FLAG_MONITOR_REHASH) +#define IsListening(x) ((x)->flags & CLIENT_FLAG_LISTEN) +#define IsLocalhost(x) ((x)->flags & CLIENT_FLAG_LOCALHOST) +#define IsMap(x) ((x)->flags & CLIENT_FLAG_MAP) +#define IsNextCall(x) ((x)->flags & CLIENT_FLAG_NEXTCALL) +#define IsNetInfo(x) ((x)->flags & CLIENT_FLAG_NETINFO) +#define IsNoFakeLag(x) ((x)->flags & CLIENT_FLAG_NOFAKELAG) +#define IsOutgoing(x) ((x)->flags & CLIENT_FLAG_OUTGOING) +#define IsPingSent(x) ((x)->flags & CLIENT_FLAG_PINGSENT) +#define IsPingWarning(x) ((x)->flags & CLIENT_FLAG_PINGWARN) +#define IsNoHandshakeDelay(x) ((x)->flags & CLIENT_FLAG_NOHANDSHAKEDELAY) +#define IsProtoctlReceived(x) ((x)->flags & CLIENT_FLAG_PROTOCTL) +#define IsQuarantined(x) ((x)->flags & CLIENT_FLAG_QUARANTINE) +#define IsShunned(x) ((x)->flags & CLIENT_FLAG_SHUNNED) +#define IsSQuit(x) ((x)->flags & CLIENT_FLAG_SQUIT) +#define IsTLS(x) ((x)->flags & CLIENT_FLAG_TLS) +#define IsSecure(x) ((x)->flags & CLIENT_FLAG_TLS) +#define IsULine(x) ((x)->flags & CLIENT_FLAG_ULINE) +#define IsSvsCmdOk(x) (((x)->flags & CLIENT_FLAG_ULINE) || ((iConf.limit_svscmds == LIMIT_SVSCMDS_SERVERS) && (IsServer((x)) || IsMe((x))))) +#define IsVirus(x) ((x)->flags & CLIENT_FLAG_VIRUS) +#define IsIdentLookupSent(x) ((x)->flags & CLIENT_FLAG_IDENTLOOKUPSENT) +#define IsAsyncRPC(x) ((x)->flags & CLIENT_FLAG_ASYNC_RPC) +#define IsIPV6(x) ((x)->flags & CLIENT_FLAG_IPV6) /* clang-format off */ #define SetIdentLookup(x) do { (x)->flags |= CLIENT_FLAG_IDENTLOOKUP; } while(0) #define SetClosing(x) do { (x)->flags |= CLIENT_FLAG_CLOSING; } while(0) @@ -613,15 +639,19 @@ typedef enum ClientStatus { /* clang-format on */ /** @} */ -#define IsUnixSocket(x) ((x)->local->socket_type == SOCKET_TYPE_UNIX) -#define SetUnixSocket(x) do { (x)->local->socket_type = SOCKET_TYPE_UNIX; } while(0) +#define IsUnixSocket(x) ((x)->local->socket_type == SOCKET_TYPE_UNIX) +#define SetUnixSocket(x) \ + do \ + { \ + (x)->local->socket_type = SOCKET_TYPE_UNIX; \ + } while (0) /* Others that access client structs: */ -#define IsNotSpoof(x) ((x)->local->nospoof == 0) -#define GetHost(x) (IsHidden(x) ? (x)->user->virthost : (x)->user->realhost) -#define GetIP(x) (x->ip ? x->ip : "255.255.255.255") -#define IsLoggedIn(x) (x->user && (*x->user->account != '*') && !isdigit(*x->user->account)) /**< Logged into services */ -#define IsSynched(x) ((x->server->flags.synced) && (x->direction->server->flags.synced)) +#define IsNotSpoof(x) ((x)->local->nospoof == 0) +#define GetHost(x) (IsHidden(x) ? (x)->user->virthost : (x)->user->realhost) +#define GetIP(x) (x->ip ? x->ip : "255.255.255.255") +#define IsLoggedIn(x) (x->user && (*x->user->account != '*') && !isdigit(*x->user->account)) /**< Logged into services */ +#define IsSynched(x) ((x->server->flags.synced) && (x->direction->server->flags.synced)) #define IsServerSent(x) (x->server && x->server->flags.server_sent) /* And more that access client stuff - but actually modularized */ @@ -629,109 +659,111 @@ typedef enum ClientStatus { /* PROTOCTL (Server protocol) stuff */ #ifndef DEBUGMODE -#define CHECKSERVERPROTO(x,y) (((x)->local->proto & y) == y) + #define CHECKSERVERPROTO(x, y) (((x)->local->proto & y) == y) #else -#define CHECKSERVERPROTO(x,y) (checkprotoflags(x, y, __FILE__, __LINE__)) + #define CHECKSERVERPROTO(x, y) (checkprotoflags(x, y, __FILE__, __LINE__)) #endif -#define SupportVL(x) (CHECKSERVERPROTO(x, PROTO_VL)) -#define SupportSJSBY(x) (CHECKSERVERPROTO(x, PROTO_SJSBY)) -#define SupportVHP(x) (CHECKSERVERPROTO(x, PROTO_VHP)) -#define SupportCLK(x) (CHECKSERVERPROTO(x, PROTO_CLK)) -#define SupportMTAGS(x) (CHECKSERVERPROTO(x, PROTO_MTAGS)) -#define SupportNEXTBANS(x) (CHECKSERVERPROTO(x, PROTO_NEXTBANS)) -#define SupportBIGLINES(x) (CHECKSERVERPROTO(x, PROTO_BIGLINES)) +#define SupportVL(x) (CHECKSERVERPROTO(x, PROTO_VL)) +#define SupportSJSBY(x) (CHECKSERVERPROTO(x, PROTO_SJSBY)) +#define SupportVHP(x) (CHECKSERVERPROTO(x, PROTO_VHP)) +#define SupportCLK(x) (CHECKSERVERPROTO(x, PROTO_CLK)) +#define SupportMTAGS(x) (CHECKSERVERPROTO(x, PROTO_MTAGS)) +#define SupportNEXTBANS(x) (CHECKSERVERPROTO(x, PROTO_NEXTBANS)) +#define SupportBIGLINES(x) (CHECKSERVERPROTO(x, PROTO_BIGLINES)) -#define SetVL(x) ((x)->local->proto |= PROTO_VL) -#define SetSJSBY(x) ((x)->local->proto |= PROTO_SJSBY) -#define SetVHP(x) ((x)->local->proto |= PROTO_VHP) -#define SetCLK(x) ((x)->local->proto |= PROTO_CLK) -#define SetMTAGS(x) ((x)->local->proto |= PROTO_MTAGS) -#define SetNEXTBANS(x) ((x)->local->proto |= PROTO_NEXTBANS) -#define SetBIGLINES(x) ((x)->local->proto |= PROTO_BIGLINES) +#define SetVL(x) ((x)->local->proto |= PROTO_VL) +#define SetSJSBY(x) ((x)->local->proto |= PROTO_SJSBY) +#define SetVHP(x) ((x)->local->proto |= PROTO_VHP) +#define SetCLK(x) ((x)->local->proto |= PROTO_CLK) +#define SetMTAGS(x) ((x)->local->proto |= PROTO_MTAGS) +#define SetNEXTBANS(x) ((x)->local->proto |= PROTO_NEXTBANS) +#define SetBIGLINES(x) ((x)->local->proto |= PROTO_BIGLINES) /* Dcc deny types (see src/s_extra.c) */ -#define DCCDENY_HARD 0 -#define DCCDENY_SOFT 1 +#define DCCDENY_HARD 0 +#define DCCDENY_SOFT 1 /* Linked list dcc flags */ -#define DCC_LINK_ME 1 /* My dcc allow */ -#define DCC_LINK_REMOTE 2 /* I need to remove dccallows from these clients when I die */ +#define DCC_LINK_ME 1 /* My dcc allow */ +#define DCC_LINK_REMOTE 2 /* I need to remove dccallows from these clients when I die */ /** Union for moddata objects */ typedef union ModData ModData; -union ModData -{ - int i; - long l; - long long ll; - char *str; - void *ptr; +union ModData { + int i; + long l; + long long ll; + char *str; + void *ptr; }; #ifndef _WIN32 - #define CHECK_LIST_ENTRY(list) if (offsetof(typeof(*list),prev) != offsetof(ListStruct,prev)) \ - { \ - unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ - "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ - log_data_string("error_details", "->prev must be 1st struct member"), \ - log_data_string("file", __FILE__), \ - log_data_integer("line", __LINE__)); \ - abort(); \ - } \ - if (offsetof(typeof(*list),next) != offsetof(ListStruct,next)) \ - { \ - unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ - "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ - log_data_string("error_details", "->next must be 2nd struct member"), \ - log_data_string("file", __FILE__), \ - log_data_integer("line", __LINE__)); \ - abort(); \ - } + #define CHECK_LIST_ENTRY(list) \ + if (offsetof(typeof(*list), prev) != offsetof(ListStruct, prev)) \ + { \ + unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ + "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ + log_data_string("error_details", "->prev must be 1st struct member"), \ + log_data_string("file", __FILE__), \ + log_data_integer("line", __LINE__)); \ + abort(); \ + } \ + if (offsetof(typeof(*list), next) != offsetof(ListStruct, next)) \ + { \ + unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ + "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ + log_data_string("error_details", "->next must be 2nd struct member"), \ + log_data_string("file", __FILE__), \ + log_data_integer("line", __LINE__)); \ + abort(); \ + } #else - #define CHECK_LIST_ENTRY(list) /* not available on Windows, typeof() not reliable */ + #define CHECK_LIST_ENTRY(list) /* not available on Windows, typeof() not reliable */ #endif #ifndef _WIN32 - #define CHECK_PRIO_LIST_ENTRY(list) if (offsetof(typeof(*list),prev) != offsetof(ListStructPrio,prev)) \ - { \ - unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ - "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ - log_data_string("error_details", "->prev must be 1st struct member"), \ - log_data_string("file", __FILE__), \ - log_data_integer("line", __LINE__)); \ - abort(); \ - } \ - if (offsetof(typeof(*list),next) != offsetof(ListStructPrio,next)) \ - { \ - unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ - "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ - log_data_string("error_details", "->next must be 2nd struct member"), \ - log_data_string("file", __FILE__), \ - log_data_integer("line", __LINE__)); \ - abort(); \ - } \ - if (offsetof(typeof(*list),priority) != offsetof(ListStructPrio,priority)) \ - { \ - unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ - "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ - log_data_string("error_details", "->priority must be 3rd struct member"), \ - log_data_string("file", __FILE__), \ - log_data_integer("line", __LINE__)); \ - abort(); \ - } + #define CHECK_PRIO_LIST_ENTRY(list) \ + if (offsetof(typeof(*list), prev) != offsetof(ListStructPrio, prev)) \ + { \ + unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ + "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ + log_data_string("error_details", "->prev must be 1st struct member"), \ + log_data_string("file", __FILE__), \ + log_data_integer("line", __LINE__)); \ + abort(); \ + } \ + if (offsetof(typeof(*list), next) != offsetof(ListStructPrio, next)) \ + { \ + unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ + "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ + log_data_string("error_details", "->next must be 2nd struct member"), \ + log_data_string("file", __FILE__), \ + log_data_integer("line", __LINE__)); \ + abort(); \ + } \ + if (offsetof(typeof(*list), priority) != offsetof(ListStructPrio, priority)) \ + { \ + unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION", NULL, \ + "[BUG] $file:$line: List operation on struct with incorrect order ($error_details)", \ + log_data_string("error_details", "->priority must be 3rd struct member"), \ + log_data_string("file", __FILE__), \ + log_data_integer("line", __LINE__)); \ + abort(); \ + } #else - #define CHECK_PRIO_LIST_ENTRY(list) /* not available on Windows, typeof() not reliable */ + #define CHECK_PRIO_LIST_ENTRY(list) /* not available on Windows, typeof() not reliable */ #endif -#define CHECK_NULL_LIST_ITEM(item) if ((item)->prev || (item)->next) \ - { \ - unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION_DOUBLE_ADD", NULL, \ - "[BUG] $file:$line: List operation on item with non-NULL 'prev' or 'next' -- are you adding to a list twice?", \ - log_data_string("file", __FILE__), \ - log_data_integer("line", __LINE__)); \ - abort(); \ - } +#define CHECK_NULL_LIST_ITEM(item) \ + if ((item)->prev || (item)->next) \ + { \ + unreal_log(ULOG_FATAL, "main", "BUG_LIST_OPERATION_DOUBLE_ADD", NULL, \ + "[BUG] $file:$line: List operation on item with non-NULL 'prev' or 'next' -- are you adding to a list twice?", \ + log_data_string("file", __FILE__), \ + log_data_integer("line", __LINE__)); \ + abort(); \ + } /** These are the generic list functions that are used all around in UnrealIRCd. * @defgroup ListFunctions List functions @@ -751,53 +783,63 @@ struct ListStructPrio { /** Add an item to a standard linked list (in the front) */ -#define AddListItem(item,list) do { \ - CHECK_LIST_ENTRY(list) \ - CHECK_LIST_ENTRY(item) \ - CHECK_NULL_LIST_ITEM(item) \ - add_ListItem((ListStruct *)item, (ListStruct **)&list); \ - } while(0) +#define AddListItem(item, list) \ + do \ + { \ + CHECK_LIST_ENTRY(list) \ + CHECK_LIST_ENTRY(item) \ + CHECK_NULL_LIST_ITEM(item) \ + add_ListItem((ListStruct *)item, (ListStruct **)&list); \ + } while (0) /** Append an item to a standard linked list (at the back) */ -#define AppendListItem(item,list) do { \ - CHECK_LIST_ENTRY(list) \ - CHECK_LIST_ENTRY(item) \ - CHECK_NULL_LIST_ITEM(item) \ - append_ListItem((ListStruct *)item, (ListStruct **)&list); \ - } while(0) +#define AppendListItem(item, list) \ + do \ + { \ + CHECK_LIST_ENTRY(list) \ + CHECK_LIST_ENTRY(item) \ + CHECK_NULL_LIST_ITEM(item) \ + append_ListItem((ListStruct *)item, (ListStruct **)&list); \ + } while (0) /** Delete an item from a standard linked list */ -#define DelListItem(item,list) do { \ - CHECK_LIST_ENTRY(list) \ - CHECK_LIST_ENTRY(item) \ - del_ListItem((ListStruct *)item, (ListStruct **)&list); \ - } while(0) +#define DelListItem(item, list) \ + do \ + { \ + CHECK_LIST_ENTRY(list) \ + CHECK_LIST_ENTRY(item) \ + del_ListItem((ListStruct *)item, (ListStruct **)&list); \ + } while (0) /** Add an item to a standard linked list - UNCHECKED function, only use if absolutely necessary! */ -#define AddListItemUnchecked(item,list) add_ListItem((ListStruct *)item, (ListStruct **)&list) +#define AddListItemUnchecked(item, list) add_ListItem((ListStruct *)item, (ListStruct **)&list) /** Append an item to a standard linked list - UNCHECKED function, only use if absolutely necessary! */ -#define AppendListItemUnchecked(item,list) append_ListItem((ListStruct *)item, (ListStruct **)&list) +#define AppendListItemUnchecked(item, list) append_ListItem((ListStruct *)item, (ListStruct **)&list) /** Delete an item from a standard linked list - UNCHECKED function, only use if absolutely necessary! */ -#define DelListItemUnchecked(item,list) del_ListItem((ListStruct *)item, (ListStruct **)&list) +#define DelListItemUnchecked(item, list) del_ListItem((ListStruct *)item, (ListStruct **)&list) -#define AddListItemPrio(item,list,prio) do { \ - CHECK_PRIO_LIST_ENTRY(list) \ - CHECK_PRIO_LIST_ENTRY(item) \ - CHECK_NULL_LIST_ITEM(item) \ - item->priority = prio; \ - add_ListItemPrio((ListStructPrio *)item, (ListStructPrio **)&list, prio); \ - } while(0) +#define AddListItemPrio(item, list, prio) \ + do \ + { \ + CHECK_PRIO_LIST_ENTRY(list) \ + CHECK_PRIO_LIST_ENTRY(item) \ + CHECK_NULL_LIST_ITEM(item) \ + item->priority = prio; \ + add_ListItemPrio((ListStructPrio *)item, (ListStructPrio **)&list, prio); \ + } while (0) -#define DelListItemPrio(item,list,prio) do { \ - CHECK_PRIO_LIST_ENTRY(list) \ - CHECK_PRIO_LIST_ENTRY(item) \ - del_ListItem((ListStruct *)item, (ListStruct **)&list); \ - } while(0) +#define DelListItemPrio(item, list, prio) \ + do \ + { \ + CHECK_PRIO_LIST_ENTRY(list) \ + CHECK_PRIO_LIST_ENTRY(item) \ + del_ListItem((ListStruct *)item, (ListStruct **)&list); \ + } while (0) typedef struct NameList NameList; /** Generic linked list where each entry has a name which you can use. @@ -813,15 +855,20 @@ struct NameList { }; /** Free an entire NameList */ -#define free_entire_name_list(list) do { _free_entire_name_list(list); list = NULL; } while(0) +#define free_entire_name_list(list) \ + do \ + { \ + _free_entire_name_list(list); \ + list = NULL; \ + } while (0) #define safe_free_name_list free_entire_name_list /** Add an entry to a NameList */ -#define add_name_list(list, str) _add_name_list(&list, str) +#define add_name_list(list, str) _add_name_list(&list, str) /** Append an entry to the end of a NameList */ -#define append_name_list(list, str) _append_name_list(&list, str) +#define append_name_list(list, str) _append_name_list(&list, str) /** Delete an entry from a NameList - AND free it */ -#define del_name_list(list, str) _del_name_list(&list, str) +#define del_name_list(list, str) _del_name_list(&list, str) extern void unreal_add_names(NameList **n, ConfigEntry *ce); @@ -843,8 +890,7 @@ struct MultiLine { char *line; }; -struct MOTDFile -{ +struct MOTDFile { struct MOTDLine *lines; struct tm last_modified; /* store the last modification time */ }; @@ -856,16 +902,16 @@ struct MOTDLine { /** Current status of configuration in memory (what stage are we in..) */ typedef enum ConfigStatus { - CONFIG_STATUS_NONE = 0, /**< Config files have not been parsed yet */ - CONFIG_STATUS_TEST = 1, /**< Currently running MOD_TEST() */ - CONFIG_STATUS_POSTTEST = 2, /**< Currently running post_config_test hooks */ - CONFIG_STATUS_PRE_INIT = 3, /**< In-between */ - CONFIG_STATUS_INIT = 4, /**< Currently running MOD_INIT() */ - CONFIG_STATUS_RUN_CONFIG = 5, /**< Currently running CONFIG_RUN hooks */ - CONFIG_STATUS_LOAD = 6, /**< Currently running MOD_LOAD() */ - CONFIG_STATUS_POSTLOAD = 7, /**< Doing post-load stuff like activating listeners */ - CONFIG_STATUS_COMPLETE = 8, /**< Load or rehash complete */ - CONFIG_STATUS_ROLLBACK = 99, /**< Configuration failed, rolling back changes */ + CONFIG_STATUS_NONE = 0, /**< Config files have not been parsed yet */ + CONFIG_STATUS_TEST = 1, /**< Currently running MOD_TEST() */ + CONFIG_STATUS_POSTTEST = 2, /**< Currently running post_config_test hooks */ + CONFIG_STATUS_PRE_INIT = 3, /**< In-between */ + CONFIG_STATUS_INIT = 4, /**< Currently running MOD_INIT() */ + CONFIG_STATUS_RUN_CONFIG = 5, /**< Currently running CONFIG_RUN hooks */ + CONFIG_STATUS_LOAD = 6, /**< Currently running MOD_LOAD() */ + CONFIG_STATUS_POSTLOAD = 7, /**< Doing post-load stuff like activating listeners */ + CONFIG_STATUS_COMPLETE = 8, /**< Load or rehash complete */ + CONFIG_STATUS_ROLLBACK = 99, /**< Configuration failed, rolling back changes */ } ConfigStatus; struct LoopStruct { @@ -873,7 +919,7 @@ struct LoopStruct { unsigned config_test : 1; unsigned booted : 1; unsigned forked : 1; - unsigned do_bancheck : 1; /* perform *line bancheck? */ + unsigned do_bancheck : 1; /* perform *line bancheck? */ unsigned do_bancheck_spamf_user : 1; /* perform 'user' spamfilter bancheck */ unsigned do_bancheck_spamf_away : 1; /* perform 'away' spamfilter bancheck */ unsigned terminating : 1; @@ -888,9 +934,9 @@ struct LoopStruct { /** Matching types for Match.type */ typedef enum { - MATCH_SIMPLE=1, /**< Simple pattern with * and ? */ - MATCH_PCRE_REGEX=2, /**< PCRE2 Perl-like regex (new) */ - MATCH_NONE=3, /**< No matching at all (rule-based) */ + MATCH_SIMPLE = 1, /**< Simple pattern with * and ? */ + MATCH_PCRE_REGEX = 2, /**< PCRE2 Perl-like regex (new) */ + MATCH_NONE = 3, /**< No matching at all (rule-based) */ } MatchType; /** Match struct, which allows various matching styles, see MATCH_* */ @@ -903,7 +949,7 @@ typedef struct Match { } Match; typedef struct Whowas { - int hashv; + int hashv; char *name; char *username; char *hostname; @@ -917,11 +963,11 @@ typedef struct Whowas { time_t logoff; time_t connected_since; WhoWasEvent event; - struct Client *online; /* Pointer to new nickname for chasing or NULL */ - struct Whowas *next; /* for hash table... */ - struct Whowas *prev; /* for hash table... */ - struct Whowas *cnext; /* for client struct linked list */ - struct Whowas *cprev; /* for client struct linked list */ + struct Client *online; /* Pointer to new nickname for chasing or NULL */ + struct Whowas *next; /* for hash table... */ + struct Whowas *prev; /* for hash table... */ + struct Whowas *cnext; /* for client struct linked list */ + struct Whowas *cprev; /* for client struct linked list */ } WhoWas; typedef struct SWhois SWhois; @@ -935,19 +981,19 @@ struct SWhois { #define UNICODE_BLOCK_COUNT 339 /** Text analysis by utf8_text_analysis() and other modules */ typedef struct TextAnalysis { - int antimixedutf8_points; /**< Points given by AntiMixedUTF8 */ - int unicode_blocks; /**< Number of different unicode blocks used in the text (low = normal, high = suspicious) */ - int num_bytes; /**< Number of bytes of the text */ - int num_unicode_characters; /**< Number of unicode characters (which is not the same as strlen) */ + int antimixedutf8_points; /**< Points given by AntiMixedUTF8 */ + int unicode_blocks; /**< Number of different unicode blocks used in the text (low = normal, high = suspicious) */ + int num_bytes; /**< Number of bytes of the text */ + int num_unicode_characters; /**< Number of unicode characters (which is not the same as strlen) */ char unicode_blockmap[UNICODE_BLOCK_COUNT]; /**< Unicode block counts, eg unicode_blockmap[0] is the number of latin characters */ - char deconfused[512]; /**< The string with accents removed, confusables handled. Not guaranteed to be 100% correct. */ + char deconfused[512]; /**< The string with accents removed, confusables handled. Not guaranteed to be 100% correct. */ } TextAnalysis; /** Client context (passed in commands) */ typedef struct ClientContext { - RealCommand *cmd; /**< Command handler (eg. cmd->command is the command name) */ + RealCommand *cmd; /**< Command handler (eg. cmd->command is the command name) */ TextAnalysis *textanalysis; /**< Analysis of text (can be NULL, eg for non-PRIVMSG/NOTICE or remote clients) */ - long fake_lag_added_msec; /**< Fake lag (in msec) added by parse_addlag() for this command */ + long fake_lag_added_msec; /**< Fake lag (in msec) added by parse_addlag() for this command */ } ClientContext; /** The command API - used by modules and the core to add commands, overrides, etc. @@ -956,29 +1002,29 @@ typedef struct ClientContext { * @{ */ /** Command can be called by unregistered users (still in handshake) */ -#define CMD_UNREGISTERED 0x0001 +#define CMD_UNREGISTERED 0x0001 /** Command can be called by users (either directly connected, or remote) */ -#define CMD_USER 0x0002 +#define CMD_USER 0x0002 /** Command can be called by servers */ -#define CMD_SERVER 0x0004 +#define CMD_SERVER 0x0004 /** Command can be used by shunned users (only very few commands need this) */ -#define CMD_SHUN 0x0008 +#define CMD_SHUN 0x0008 /** Command will NOT add fake lag (extremely rare, use with care) */ -#define CMD_NOLAG 0x0010 +#define CMD_NOLAG 0x0010 /** Command is actually an alias */ -#define CMD_ALIAS 0x0020 +#define CMD_ALIAS 0x0020 /** Command will reset the idle time (only for PRIVMSG) */ -#define CMD_RESETIDLE 0x0040 +#define CMD_RESETIDLE 0x0040 /** Command can be used by virus tagged users (only very few commands) */ -#define CMD_VIRUS 0x0080 +#define CMD_VIRUS 0x0080 /** Command requires IRCOp privileges */ -#define CMD_OPER 0x0200 +#define CMD_OPER 0x0200 /** Command is for control channel only (unrealircd.ctl socket) */ -#define CMD_CONTROL 0x0400 +#define CMD_CONTROL 0x0400 /** Command is able to receive BIG lines */ -#define CMD_BIGLINES 0x0800 +#define CMD_BIGLINES 0x0800 /** The last parameter of the command should go through text analysis */ -#define CMD_TEXTANALYSIS 0x1000 +#define CMD_TEXTANALYSIS 0x1000 /** Command function - used by all command handlers. * This is used in the code like
CMD_FUNC(cmd_yourcmd)
as a function definition. @@ -995,7 +1041,7 @@ typedef struct ClientContext { * Note that reading parv[parc] and beyond is OUT OF BOUNDS and will cause a crash. * E.g. parv[3] in the above example is out of bounds. */ -#define CMD_FUNC(x) void (x) (ClientContext *clictx, Client *client, MessageTag *recv_mtags, int parc, const char *parv[]) +#define CMD_FUNC(x) void(x)(ClientContext * clictx, Client * client, MessageTag * recv_mtags, int parc, const char *parv[]) /** Call a command function - can be useful if you are calling another command function in your own module. * For example in cmd_nick() we call cmd_nick_local() for local functions, @@ -1003,7 +1049,7 @@ typedef struct ClientContext { * to bother with passing the right command arguments. Which is nice because * command arguments may change in future UnrealIRCd versions. */ -#define CALL_CMD_FUNC(x) (x)(clictx, client, recv_mtags, parc, parv) +#define CALL_CMD_FUNC(x) (x)(clictx, client, recv_mtags, parc, parv) /** @} */ @@ -1021,8 +1067,7 @@ typedef struct ClientContext { * Note that reading parv[parc] and beyond is OUT OF BOUNDS and will cause a crash. * E.g. parv[3] in the above example. */ -#define CMD_OVERRIDE_FUNC(x) void (x)(CommandOverride *ovr, ClientContext *clictx, Client *client, MessageTag *recv_mtags, int parc, const char *parv[]) - +#define CMD_OVERRIDE_FUNC(x) void(x)(CommandOverride * ovr, ClientContext * clictx, Client * client, MessageTag * recv_mtags, int parc, const char *parv[]) typedef void (*CmdFunc)(ClientContext *clictx, Client *client, MessageTag *mtags, int parc, const char *parv[]); @@ -1060,31 +1105,31 @@ typedef enum UnrealDBKDF { /** Database configuration for a particular file */ typedef struct UnrealDBConfig { - uint16_t kdf; /**< Key derivation function (always 0x01) */ - uint16_t t_cost; /**< Time cost (number of rounds) */ - uint16_t m_cost; /**< Memory cost (in number of bitshifts, eg 15 means 1<<15=32M) */ - uint16_t p_cost; /**< Parallel cost (number of concurrent threads) */ - uint16_t saltlen; /**< Length of the salt (normally UNREALDB_SALT_LEN) */ - char *salt; /**< Salt */ - uint16_t cipher; /**< Encryption cipher (always 0x01) */ - uint16_t keylen; /**< Key length */ - char *key; /**< The key used for encryption/decryption */ + uint16_t kdf; /**< Key derivation function (always 0x01) */ + uint16_t t_cost; /**< Time cost (number of rounds) */ + uint16_t m_cost; /**< Memory cost (in number of bitshifts, eg 15 means 1<<15=32M) */ + uint16_t p_cost; /**< Parallel cost (number of concurrent threads) */ + uint16_t saltlen; /**< Length of the salt (normally UNREALDB_SALT_LEN) */ + char *salt; /**< Salt */ + uint16_t cipher; /**< Encryption cipher (always 0x01) */ + uint16_t keylen; /**< Key length */ + char *key; /**< The key used for encryption/decryption */ } UnrealDBConfig; /** Error codes returned by @ref UnrealDBFunctions * @ingroup UnrealDBFunctions */ typedef enum UnrealDBError { - UNREALDB_ERROR_SUCCESS = 0, /**< Success, not an error */ - UNREALDB_ERROR_FILENOTFOUND = 1, /**< File does not exist */ - UNREALDB_ERROR_CRYPTED = 2, /**< File is crypted but no password provided */ - UNREALDB_ERROR_NOTCRYPTED = 3, /**< File is not crypted and a password was provided */ - UNREALDB_ERROR_HEADER = 4, /**< Header is corrupt, invalid or unknown format */ - UNREALDB_ERROR_SECRET = 5, /**< Invalid secret { } block provided - either does not exist or does not meet requirements */ - UNREALDB_ERROR_PASSWORD = 6, /**< Invalid password provided */ - UNREALDB_ERROR_IO = 7, /**< I/O error */ - UNREALDB_ERROR_API = 8, /**< API call violation, eg requesting to write on a file opened for reading */ - UNREALDB_ERROR_INTERNAL = 9, /**< Internal error, eg crypto routine returned something unexpected */ + UNREALDB_ERROR_SUCCESS = 0, /**< Success, not an error */ + UNREALDB_ERROR_FILENOTFOUND = 1, /**< File does not exist */ + UNREALDB_ERROR_CRYPTED = 2, /**< File is crypted but no password provided */ + UNREALDB_ERROR_NOTCRYPTED = 3, /**< File is not crypted and a password was provided */ + UNREALDB_ERROR_HEADER = 4, /**< Header is corrupt, invalid or unknown format */ + UNREALDB_ERROR_SECRET = 5, /**< Invalid secret { } block provided - either does not exist or does not meet requirements */ + UNREALDB_ERROR_PASSWORD = 6, /**< Invalid password provided */ + UNREALDB_ERROR_IO = 7, /**< I/O error */ + UNREALDB_ERROR_API = 8, /**< API call violation, eg requesting to write on a file opened for reading */ + UNREALDB_ERROR_INTERNAL = 9, /**< Internal error, eg crypto routine returned something unexpected */ } UnrealDBError; /** Database handle @@ -1092,16 +1137,16 @@ typedef enum UnrealDBError { * @ingroup UnrealDBFunctions */ typedef struct UnrealDB { - FILE *fd; /**< File descriptor */ - UnrealDBMode mode; /**< UNREALDB_MODE_READ / UNREALDB_MODE_WRITE */ - int crypted; /**< Are we doing any encryption or just plaintext? */ - uint64_t creationtime; /**< When this file was created/updates */ + FILE *fd; /**< File descriptor */ + UnrealDBMode mode; /**< UNREALDB_MODE_READ / UNREALDB_MODE_WRITE */ + int crypted; /**< Are we doing any encryption or just plaintext? */ + uint64_t creationtime; /**< When this file was created/updates */ crypto_secretstream_xchacha20poly1305_state st; /**< Internal state for crypto engine */ - char buf[UNREALDB_CRYPT_FILE_CHUNK_SIZE]; /**< Buffer used for reading/writing */ - int buflen; /**< Length of current data in buffer */ - UnrealDBError error_code; /**< Last error code. Whenever this happens we will set this, never overwrite, and block further I/O */ - char *error_string; /**< Error string upon failure */ - UnrealDBConfig *config; /**< Config */ + char buf[UNREALDB_CRYPT_FILE_CHUNK_SIZE]; /**< Buffer used for reading/writing */ + int buflen; /**< Length of current data in buffer */ + UnrealDBError error_code; /**< Last error code. Whenever this happens we will set this, never overwrite, and block further I/O */ + char *error_string; /**< Error string upon failure */ + UnrealDBConfig *config; /**< Config */ } UnrealDB; /** Used for speeding up reading/writing of DBs (so we don't have to run argon2 repeatedly) */ @@ -1122,41 +1167,40 @@ struct Secret { /* CRULE stuff */ -#define CRULE_ALL 0 -#define CRULE_AUTO 1 +#define CRULE_ALL 0 +#define CRULE_AUTO 1 /* some constants and shared data types */ -#define CR_MAXARGLEN 160 /**< Maximum arg length (must be > HOSTLEN) */ -#define CR_MAXARGS 5 /**< Maximum number of args for a rule */ +#define CR_MAXARGLEN 160 /**< Maximum arg length (must be > HOSTLEN) */ +#define CR_MAXARGS 5 /**< Maximum number of args for a rule */ /* context when running a crule */ typedef struct crule_context crule_context; -struct crule_context -{ - Client *client; /**< Client that is being processed (can be NULL) */ - const char *text; /**< The input string, if any (can be NULL) */ - const char *destination; /**< Destination of the message, like '#xyz' for spamfilter (can be NULL, eg for 'u') */ - ClientContext *clictx; /**< Client context (can be NULL) */ +struct crule_context { + Client *client; /**< Client that is being processed (can be NULL) */ + const char *text; /**< The input string, if any (can be NULL) */ + const char *destination; /**< Destination of the message, like '#xyz' for spamfilter (can be NULL, eg for 'u') */ + ClientContext *clictx; /**< Client context (can be NULL) */ }; /** Evaluation function for a connection rule. */ -typedef int (*crule_funcptr) (crule_context *context, int, void **); +typedef int (*crule_funcptr)(crule_context *context, int, void **); -#define CRULE_FLAG_NOT 0x1 -#define CRULE_FLAG_AND_OR 0x2 +#define CRULE_FLAG_NOT 0x1 +#define CRULE_FLAG_AND_OR 0x2 /** CRULE - Node in a connection rule tree. */ struct CRuleNode { - int flags; - crule_funcptr funcptr; /**< Evaluation function for this node. */ - int numargs; /**< Number of arguments. */ - /** Array of arguments. For operators, each arg + int flags; + crule_funcptr funcptr; /**< Evaluation function for this node. */ + int numargs; /**< Number of arguments. */ + /** Array of arguments. For operators, each arg * is a tree element; for functions, each arg is * a string. */ - void *arg[CR_MAXARGS]; - int func_test_type; /* for >, < and == */ - int func_test_value; /* integer value to compare against */ + void *arg[CR_MAXARGS]; + int func_test_type; /* for >, < and == */ + int func_test_value; /* integer value to compare against */ }; typedef struct CRuleNode CRuleNode; @@ -1166,83 +1210,83 @@ typedef struct CRuleNode CRuleNode; * TKL_KILL = Local K-Line * TKL_ZAP = Local Z-Line */ -#define TKL_KILL 0x00000001 -#define TKL_ZAP 0x00000002 -#define TKL_GLOBAL 0x00000004 -#define TKL_SHUN 0x00000008 -#define TKL_SPAMF 0x00000020 -#define TKL_NAME 0x00000040 -#define TKL_EXCEPTION 0x00000080 +#define TKL_KILL 0x00000001 +#define TKL_ZAP 0x00000002 +#define TKL_GLOBAL 0x00000004 +#define TKL_SHUN 0x00000008 +#define TKL_SPAMF 0x00000020 +#define TKL_NAME 0x00000040 +#define TKL_EXCEPTION 0x00000080 /* these are not real tkl types, but only used for exceptions: */ -#define TKL_BLACKLIST 0x0001000 -#define TKL_CONNECT_FLOOD 0x0002000 -#define TKL_MAXPERIP 0x0004000 -#define TKL_HANDSHAKE_DATA_FLOOD 0x0008000 -#define TKL_ANTIRANDOM 0x0010000 -#define TKL_ANTIMIXEDUTF8 0x0020000 -#define TKL_BAN_VERSION 0x0040000 +#define TKL_BLACKLIST 0x0001000 +#define TKL_CONNECT_FLOOD 0x0002000 +#define TKL_MAXPERIP 0x0004000 +#define TKL_HANDSHAKE_DATA_FLOOD 0x0008000 +#define TKL_ANTIRANDOM 0x0010000 +#define TKL_ANTIMIXEDUTF8 0x0020000 +#define TKL_BAN_VERSION 0x0040000 -#define TKLIsServerBan(tkl) ((tkl)->type & (TKL_KILL|TKL_ZAP|TKL_SHUN)) -#define TKLIsServerBanType(tpe) ((tpe) & (TKL_KILL|TKL_ZAP|TKL_SHUN)) -#define TKLIsSpamfilter(tkl) ((tkl)->type & TKL_SPAMF) -#define TKLIsSpamfilterType(tpe) ((tpe) & TKL_SPAMF) -#define TKLIsNameBan(tkl) ((tkl)->type & TKL_NAME) -#define TKLIsNameBanType(tpe) ((tpe) & TKL_NAME) -#define TKLIsBanException(tkl) ((tkl)->type & TKL_EXCEPTION) -#define TKLIsBanExceptionType(tpe) ((tpe) & TKL_EXCEPTION) +#define TKLIsServerBan(tkl) ((tkl)->type & (TKL_KILL | TKL_ZAP | TKL_SHUN)) +#define TKLIsServerBanType(tpe) ((tpe) & (TKL_KILL | TKL_ZAP | TKL_SHUN)) +#define TKLIsSpamfilter(tkl) ((tkl)->type & TKL_SPAMF) +#define TKLIsSpamfilterType(tpe) ((tpe) & TKL_SPAMF) +#define TKLIsNameBan(tkl) ((tkl)->type & TKL_NAME) +#define TKLIsNameBanType(tpe) ((tpe) & TKL_NAME) +#define TKLIsBanException(tkl) ((tkl)->type & TKL_EXCEPTION) +#define TKLIsBanExceptionType(tpe) ((tpe) & TKL_EXCEPTION) -#define IsCentralSpamfilter(tkl) ((tkl)->flags & TKL_FLAG_CENTRAL_SPAMFILTER) -#define IsCentralSpamfilterType(tpe) ((tpe) & TKL_FLAG_CENTRAL_SPAMFILTER) +#define IsCentralSpamfilter(tkl) ((tkl)->flags & TKL_FLAG_CENTRAL_SPAMFILTER) +#define IsCentralSpamfilterType(tpe) ((tpe) & TKL_FLAG_CENTRAL_SPAMFILTER) -#define SPAMF_CHANMSG 0x0001 /* c */ -#define SPAMF_USERMSG 0x0002 /* p */ -#define SPAMF_USERNOTICE 0x0004 /* n */ -#define SPAMF_CHANNOTICE 0x0008 /* N */ -#define SPAMF_PART 0x0010 /* P */ -#define SPAMF_QUIT 0x0020 /* q */ -#define SPAMF_DCC 0x0040 /* d */ -#define SPAMF_USER 0x0080 /* u */ -#define SPAMF_AWAY 0x0100 /* a */ -#define SPAMF_TOPIC 0x0200 /* t */ -#define SPAMF_MTAG 0x0400 /* m */ -#define SPAMF_RAW 0x0800 /* R */ +#define SPAMF_CHANMSG 0x0001 /* c */ +#define SPAMF_USERMSG 0x0002 /* p */ +#define SPAMF_USERNOTICE 0x0004 /* n */ +#define SPAMF_CHANNOTICE 0x0008 /* N */ +#define SPAMF_PART 0x0010 /* P */ +#define SPAMF_QUIT 0x0020 /* q */ +#define SPAMF_DCC 0x0040 /* d */ +#define SPAMF_USER 0x0080 /* u */ +#define SPAMF_AWAY 0x0100 /* a */ +#define SPAMF_TOPIC 0x0200 /* t */ +#define SPAMF_MTAG 0x0400 /* m */ +#define SPAMF_RAW 0x0800 /* R */ /* Other flags only for function calls: */ -#define SPAMFLAG_NOWARN 0x0001 +#define SPAMFLAG_NOWARN 0x0001 /* Ban actions. These must be ordered by severity (!) */ typedef enum BanActionValue { - BAN_ACT_GZLINE =1100, - BAN_ACT_GLINE =1000, - BAN_ACT_SOFT_GLINE = 950, - BAN_ACT_ZLINE = 900, - BAN_ACT_KLINE = 800, - BAN_ACT_SOFT_KLINE = 850, - BAN_ACT_SHUN = 700, - BAN_ACT_SOFT_SHUN = 650, - BAN_ACT_KILL = 600, - BAN_ACT_SOFT_KILL = 550, - BAN_ACT_TEMPSHUN = 500, - BAN_ACT_SOFT_TEMPSHUN = 450, - BAN_ACT_VIRUSCHAN = 400, - BAN_ACT_SOFT_VIRUSCHAN = 350, - BAN_ACT_DCCBLOCK = 300, - BAN_ACT_SOFT_DCCBLOCK = 250, - BAN_ACT_BLOCK = 200, - BAN_ACT_SOFT_BLOCK = 150, - BAN_ACT_WARN = 100, + BAN_ACT_GZLINE = 1100, + BAN_ACT_GLINE = 1000, + BAN_ACT_SOFT_GLINE = 950, + BAN_ACT_ZLINE = 900, + BAN_ACT_KLINE = 800, + BAN_ACT_SOFT_KLINE = 850, + BAN_ACT_SHUN = 700, + BAN_ACT_SOFT_SHUN = 650, + BAN_ACT_KILL = 600, + BAN_ACT_SOFT_KILL = 550, + BAN_ACT_TEMPSHUN = 500, + BAN_ACT_SOFT_TEMPSHUN = 450, + BAN_ACT_VIRUSCHAN = 400, + BAN_ACT_SOFT_VIRUSCHAN = 350, + BAN_ACT_DCCBLOCK = 300, + BAN_ACT_SOFT_DCCBLOCK = 250, + BAN_ACT_BLOCK = 200, + BAN_ACT_SOFT_BLOCK = 150, + BAN_ACT_WARN = 100, // do not use 99, it is special in tkl take_action - BAN_ACT_SOFT_WARN = 50, - BAN_ACT_REPORT = 40, + BAN_ACT_SOFT_WARN = 50, + BAN_ACT_REPORT = 40, // anything above BAN_ACT_SET will will cause a log message to be emitted - BAN_ACT_SET = 30, - BAN_ACT_STOP = 5, + BAN_ACT_SET = 30, + BAN_ACT_STOP = 5, } BanActionValue; typedef enum VarActionValue { - VAR_ACT_SET = 1, - VAR_ACT_INCREASE = 2, - VAR_ACT_DECREASE = 3, + VAR_ACT_SET = 1, + VAR_ACT_INCREASE = 2, + VAR_ACT_DECREASE = 3, } VarActionValue; typedef struct BanAction BanAction; @@ -1254,16 +1298,16 @@ struct BanAction { VarActionValue var_action; }; -#define IsSoftBanAction(x) ((x == BAN_ACT_SOFT_GLINE) || (x == BAN_ACT_SOFT_KLINE) || \ - (x == BAN_ACT_SOFT_SHUN) || (x == BAN_ACT_SOFT_KILL) || \ - (x == BAN_ACT_SOFT_TEMPSHUN) || (x == BAN_ACT_SOFT_VIRUSCHAN) || \ - (x == BAN_ACT_SOFT_DCCBLOCK) || (x == BAN_ACT_SOFT_BLOCK) || \ - (x == BAN_ACT_SOFT_WARN)) +#define IsSoftBanAction(x) ((x == BAN_ACT_SOFT_GLINE) || (x == BAN_ACT_SOFT_KLINE) || \ + (x == BAN_ACT_SOFT_SHUN) || (x == BAN_ACT_SOFT_KILL) || \ + (x == BAN_ACT_SOFT_TEMPSHUN) || (x == BAN_ACT_SOFT_VIRUSCHAN) || \ + (x == BAN_ACT_SOFT_DCCBLOCK) || (x == BAN_ACT_SOFT_BLOCK) || \ + (x == BAN_ACT_SOFT_WARN)) /** Skip BAN_ACT_SET (eg because you already processed them earlier, like in match_spamfilter) */ -#define TAKE_ACTION_SKIP_SET 0x1 +#define TAKE_ACTION_SKIP_SET 0x1 /** Don't ban/kill/block/etc, but do return value as if we did */ -#define TAKE_ACTION_SIMULATE_USER_ACTION 0x2 +#define TAKE_ACTION_SIMULATE_USER_ACTION 0x2 typedef enum SpamfilterShowMessageContentOnHit { SPAMFILTER_SHOW_MESSAGE_CONTENT_ON_HIT_ALWAYS = 1, @@ -1273,38 +1317,38 @@ typedef enum SpamfilterShowMessageContentOnHit { /** Server ban sub-struct of TKL entry (KLINE/GLINE/ZLINE/GZLINE/SHUN) */ struct ServerBan { - char *usermask; /**< User mask (can be NULL if 'match' is non-NULL) */ - char *hostmask; /**< Host mask (can be NULL if 'match' is non-NULL) */ - SecurityGroup *match; /**< Match item (if set, usermask/hostmask is ignored) */ + char *usermask; /**< User mask (can be NULL if 'match' is non-NULL) */ + char *hostmask; /**< Host mask (can be NULL if 'match' is non-NULL) */ + SecurityGroup *match; /**< Match item (if set, usermask/hostmask is ignored) */ unsigned short subtype; /**< See TKL_SUBTYPE_* */ - char *reason; /**< Reason */ + char *reason; /**< Reason */ }; /* Name ban sub-struct of TKL entry (QLINE) */ struct NameBan { - char hold; /**< nickname hold is used by services */ - char *name; /**< the nick or channel that is banned */ + char hold; /**< nickname hold is used by services */ + char *name; /**< the nick or channel that is banned */ char *reason; /**< Reason */ }; -#define INPUT_CONVERSION_STRIP_CONTROL_CODES 0x1 -#define INPUT_CONVERSION_DEFAULT (INPUT_CONVERSION_STRIP_CONTROL_CODES) -#define INPUT_CONVERSION_CONFUSABLES 0x2 +#define INPUT_CONVERSION_STRIP_CONTROL_CODES 0x1 +#define INPUT_CONVERSION_DEFAULT (INPUT_CONVERSION_STRIP_CONTROL_CODES) +#define INPUT_CONVERSION_CONFUSABLES 0x2 /** Spamfilter sub-struct of TKL entry (Spamfilter) */ struct Spamfilter { unsigned short target; - BanAction *action; /**< Ban action */ - Match *match; /**< Spamfilter matcher */ - CRuleNode *rule; /**< parsed crule */ - char *prettyrule; /**< human printable version */ - char *tkl_reason; /**< Reason to use for bans placed by this spamfilter, escaped by unreal_encodespace(). */ - time_t tkl_duration; /**< Duration of bans placed by this spamfilter */ - char *id; /**< ID */ + BanAction *action; /**< Ban action */ + Match *match; /**< Spamfilter matcher */ + CRuleNode *rule; /**< parsed crule */ + char *prettyrule; /**< human printable version */ + char *tkl_reason; /**< Reason to use for bans placed by this spamfilter, escaped by unreal_encodespace(). */ + time_t tkl_duration; /**< Duration of bans placed by this spamfilter */ + char *id; /**< ID */ long long hits_except; /**< Spamfilter hits by exempt clients */ time_t lasthit_except; /**< When an exempt client last hit this spamfilter, or 0 if never */ SecurityGroup *except; /**< Don't run this spamfilter at all for these users (not counting towards hits_except btw) */ - int input_conversion; /**< How we should handle the input */ + int input_conversion; /**< How we should handle the input */ /** For overriding set::spamfilter::show-message-content-on-hit * (0 means use default, so iConf.spamfilter_show_message_content_on_hit) */ @@ -1313,35 +1357,35 @@ struct Spamfilter { /** Ban exception sub-struct of TKL entry (ELINE) */ struct BanException { - char *usermask; /**< User mask */ - char *hostmask; /**< Host mask */ - SecurityGroup *match; /**< Security group (for config file items only) */ + char *usermask; /**< User mask */ + char *hostmask; /**< Host mask */ + SecurityGroup *match; /**< Security group (for config file items only) */ unsigned short subtype; /**< See TKL_SUBTYPE_* */ - char *bantypes; /**< Exception types */ - char *reason; /**< Reason */ + char *bantypes; /**< Exception types */ + char *reason; /**< Reason */ }; -#define TKL_SUBTYPE_NONE 0x0000 -#define TKL_SUBTYPE_SOFT 0x0001 /* (require SASL) */ +#define TKL_SUBTYPE_NONE 0x0000 +#define TKL_SUBTYPE_SOFT 0x0001 /* (require SASL) */ -#define TKL_FLAG_CONFIG 0x0001 /* Entry from configuration file. Cannot be removed by using commands. */ -#define TKL_FLAG_CENTRAL_SPAMFILTER 0x0002 /* Entry from central spamfilter. */ +#define TKL_FLAG_CONFIG 0x0001 /* Entry from configuration file. Cannot be removed by using commands. */ +#define TKL_FLAG_CENTRAL_SPAMFILTER 0x0002 /* Entry from central spamfilter. */ -#define TKLIDLEN 16 /**< TKL id buffer size: native 'prefix+body' or an external id. Max 15 chars + NUL. */ +#define TKLIDLEN 16 /**< TKL id buffer size: native 'prefix+body' or an external id. Max 15 chars + NUL. */ /** A TKL entry, such as a KLINE, GLINE, Spamfilter, QLINE, Exception, .. */ struct TKL { TKL *prev, *next; - unsigned int type; /**< TKL type. One of TKL_*, such as TKL_KILL|TKL_GLOBAL for gline */ - unsigned short flags; /**< One of TKL_FLAG_*, such as TKL_FLAG_CONFIG */ - char *set_by; /**< By who was this entry added */ - time_t set_at; /**< When this entry was added */ - time_t expire_at; /**< When this entry will expire */ - char id[TKLIDLEN]; /**< Unique ID: assigned (random, generated by originating server) or external (eg from services), or empty string if none */ + unsigned int type; /**< TKL type. One of TKL_*, such as TKL_KILL|TKL_GLOBAL for gline */ + unsigned short flags; /**< One of TKL_FLAG_*, such as TKL_FLAG_CONFIG */ + char *set_by; /**< By who was this entry added */ + time_t set_at; /**< When this entry was added */ + time_t expire_at; /**< When this entry will expire */ + char id[TKLIDLEN]; /**< Unique ID: assigned (random, generated by originating server) or external (eg from services), or empty string if none */ char spamfilter_id[TKLIDLEN]; /**< For server bans created by a spamfilter: that spamfilter's id. Empty otherwise. */ - long long hits; /**< Number of times this TKL was enforced (counted locally on this server) */ - time_t lasthit; /**< When this TKL was last enforced, or 0 if never */ + long long hits; /**< Number of times this TKL was enforced (counted locally on this server) */ + time_t lasthit; /**< When this TKL was last enforced, or 0 if never */ union { Spamfilter *spamfilter; ServerBan *serverban; @@ -1353,16 +1397,16 @@ struct TKL { /** IRC Counts, used for /LUSERS */ typedef struct IRCCounts IRCCounts; struct IRCCounts { - int clients; /* total */ - int invisible; /* invisible */ - int servers; /* servers */ - int operators; /* operators */ - int unknown; /* unknown local connections */ - int channels; /* channels */ - int me_clients; /* my clients */ - int me_servers; /* my servers */ - int me_max; /* local max */ - int global_max; /* global max */ + int clients; /* total */ + int invisible; /* invisible */ + int servers; /* servers */ + int operators; /* operators */ + int unknown; /* unknown local connections */ + int channels; /* channels */ + int me_clients; /* my clients */ + int me_servers; /* my servers */ + int me_max; /* local max */ + int global_max; /* global max */ }; /** The /LUSERS stats information */ @@ -1370,8 +1414,7 @@ extern MODVAR IRCCounts irccounts; typedef struct NameValue NameValue; /** Name and value list used in a static array, such as in conf.c */ -struct NameValue -{ +struct NameValue { long value; char *name; }; @@ -1396,30 +1439,30 @@ struct NameValuePrioList { /** A "real" command (internal interface, not for modules) */ struct RealCommand { - RealCommand *prev, *next; - char *cmd; - CmdFunc func; - AliasCmdFunc aliasfunc; - int flags; - unsigned int count; - unsigned parameters : 5; - unsigned long bytes; - Module *owner; - RealCommand *friend; /* cmd if token, token if cmd */ - CommandOverride *overriders; + RealCommand *prev, *next; + char *cmd; + CmdFunc func; + AliasCmdFunc aliasfunc; + int flags; + unsigned int count; + unsigned parameters : 5; + unsigned long bytes; + Module *owner; + RealCommand *friend; /* cmd if token, token if cmd */ + CommandOverride *overriders; #ifdef DEBUGMODE - unsigned long lticks; - unsigned long rticks; + unsigned long lticks; + unsigned long rticks; #endif }; /** A command override */ struct CommandOverride { - CommandOverride *prev, *next; - int priority; - Module *owner; - RealCommand *command; - OverrideCmdFunc func; + CommandOverride *prev, *next; + int priority; + Module *owner; + RealCommand *command; + OverrideCmdFunc func; }; extern MODVAR Umode *usermodes; @@ -1437,64 +1480,66 @@ extern void ModDataDel(ModDataInfo *md); extern void unload_all_unused_moddata(void); extern void moddatatype_dump(Client *client); -#define LISTENER_NORMAL 0x000001 -#define LISTENER_CLIENTSONLY 0x000002 -#define LISTENER_SERVERSONLY 0x000004 -#define LISTENER_TLS 0x000010 -#define LISTENER_BOUND 0x000020 -#define LISTENER_DEFER_ACCEPT 0x000040 -#define LISTENER_CONTROL 0x000080 /**< Control channel */ -#define LISTENER_NO_CHECK_CONNECT_FLOOD 0x000100 /**< Don't check for connect-flood and max-unknown-connections-per-ip (eg for RPC) */ -#define LISTENER_NO_CHECK_ZLINED 0x000200 /**< Don't check for zlines */ +#define LISTENER_NORMAL 0x000001 +#define LISTENER_CLIENTSONLY 0x000002 +#define LISTENER_SERVERSONLY 0x000004 +#define LISTENER_TLS 0x000010 +#define LISTENER_BOUND 0x000020 +#define LISTENER_DEFER_ACCEPT 0x000040 +#define LISTENER_CONTROL 0x000080 /**< Control channel */ +#define LISTENER_NO_CHECK_CONNECT_FLOOD 0x000100 /**< Don't check for connect-flood and max-unknown-connections-per-ip (eg for RPC) */ +#define LISTENER_NO_CHECK_ZLINED 0x000200 /**< Don't check for zlines */ -#define IsServersOnlyListener(x) ((x) && ((x)->options & LISTENER_SERVERSONLY)) +#define IsServersOnlyListener(x) ((x) && ((x)->options & LISTENER_SERVERSONLY)) -#define CONNECT_OUTGOING_TLS 0x000001 -#define CONNECT_OUTGOING_AUTO 0x000002 -#define CONNECT_OUTGOING_INSECURE 0x000008 +#define CONNECT_OUTGOING_TLS 0x000001 +#define CONNECT_OUTGOING_AUTO 0x000002 +#define CONNECT_OUTGOING_INSECURE 0x000008 -#define CONNECT_QUARANTINE 0x000001 -#define CONNECT_NO_CERTIFICATE_VERIFICATION 0x000002 +#define CONNECT_QUARANTINE 0x000001 +#define CONNECT_NO_CERTIFICATE_VERIFICATION 0x000002 -#define TLSFLAG_FAILIFNOCERT 0x0001 -#define TLSFLAG_NOSTARTTLS 0x0002 -#define TLSFLAG_DISABLECLIENTCERT 0x0004 +#define TLSFLAG_FAILIFNOCERT 0x0001 +#define TLSFLAG_NOSTARTTLS 0x0002 +#define TLSFLAG_DISABLECLIENTCERT 0x0004 /** Flood counters for local clients */ typedef struct FloodCounter { - int count; /**< Maximum allowed number per... */ - long t; /**< ..time period */ - int blocked; /**< How many times this flood limit was hit */ + int count; /**< Maximum allowed number per... */ + long t; /**< ..time period */ + int blocked; /**< How many times this flood limit was hit */ } FloodCounter; /** This is the list of different flood counters that we keep for local clients. */ /* IMPORTANT: If you change this, update floodoption_names[] in src/user.c too !!!!!!!!!!!! */ typedef enum FloodOption { - FLD_NICK = 0, /**< nick-flood */ - FLD_JOIN = 1, /**< join-flood */ - FLD_AWAY = 2, /**< away-flood */ - FLD_INVITE = 3, /**< invite-flood */ - FLD_KNOCK = 4, /**< knock-flood */ - FLD_CONVERSATIONS = 5, /**< max-concurrent-conversations */ - FLD_LAG_PENALTY = 6, /**< lag-penalty / lag-penalty-bytes */ - FLD_VHOST = 7, /**< vhost-flood */ - FLD_MULTILINE = 8, /**< multiline max-lines / max-bytes */ + FLD_NICK = 0, /**< nick-flood */ + FLD_JOIN = 1, /**< join-flood */ + FLD_AWAY = 2, /**< away-flood */ + FLD_INVITE = 3, /**< invite-flood */ + FLD_KNOCK = 4, /**< knock-flood */ + FLD_CONVERSATIONS = 5, /**< max-concurrent-conversations */ + FLD_LAG_PENALTY = 6, /**< lag-penalty / lag-penalty-bytes */ + FLD_VHOST = 7, /**< vhost-flood */ + FLD_MULTILINE = 8, /**< multiline max-lines / max-bytes */ } FloodOption; -#define MULTILINE_MAX_CONFIGURABLE_LINES 200 /**< Maximum configurable max-lines for multiline */ -#define MULTILINE_MAX_CONFIGURABLE_BYTES 131072 /**< Maximum configurable max-bytes for multiline (128KB) */ -#define MAXFLOODOPTIONS 10 +#define MULTILINE_MAX_CONFIGURABLE_LINES 200 /**< Maximum configurable max-lines for multiline */ +#define MULTILINE_MAX_CONFIGURABLE_BYTES 131072 /**< Maximum configurable max-bytes for multiline (128KB) */ +#define MAXFLOODOPTIONS 10 typedef struct TrafficStats TrafficStats; struct TrafficStats { - long long messages_sent; /* IRC lines sent */ - long long messages_received; /* IRC lines received */ - long long bytes_sent; /* Bytes sent */ - long long bytes_received; /* Received bytes */ + long long messages_sent; /* IRC lines sent */ + long long messages_received; /* IRC lines received */ + long long bytes_sent; /* Bytes sent */ + long long bytes_received; /* Received bytes */ }; /** Socket type (IPv4, IPv6, UNIX) */ typedef enum { - SOCKET_TYPE_IPV4=0, SOCKET_TYPE_IPV6=1, SOCKET_TYPE_UNIX=2 + SOCKET_TYPE_IPV4 = 0, + SOCKET_TYPE_IPV6 = 1, + SOCKET_TYPE_UNIX = 2 } SocketType; /** This shows the Client struct (any client), the User struct (a user), Server (a server) that are commonly accessed both in the core and by 3rd party coders. @@ -1505,115 +1550,115 @@ typedef enum { /** A client on this or a remote server - can be a user, server, unknown, etc.. */ struct Client { - struct list_head client_node; /**< For global client list (client_list) */ - struct list_head lclient_node; /**< For local client list (lclient_list) */ - struct list_head special_node; /**< For special lists (server || unknown || oper) */ - LocalClient *local; /**< Additional information regarding locally connected clients */ - User *user; /**< Additional information, if this client is a user */ - Server *server; /**< Additional information, if this is a server */ - RPCClient *rpc; /**< RPC Client, or NULL */ - ClientStatus status; /**< Client status, one of CLIENT_STATUS_* */ - struct list_head client_hash; /**< For name hash table (clientTable) */ - char name[HOSTLEN + 1]; /**< Unique name of the client: nickname for users, hostname for servers */ - time_t lastnick; /**< Timestamp on nick */ - uint64_t flags; /**< Client flags (one or more of CLIENT_FLAG_*) */ - long umodes; /**< Client usermodes (if user) */ + struct list_head client_node; /**< For global client list (client_list) */ + struct list_head lclient_node; /**< For local client list (lclient_list) */ + struct list_head special_node; /**< For special lists (server || unknown || oper) */ + LocalClient *local; /**< Additional information regarding locally connected clients */ + User *user; /**< Additional information, if this client is a user */ + Server *server; /**< Additional information, if this is a server */ + RPCClient *rpc; /**< RPC Client, or NULL */ + ClientStatus status; /**< Client status, one of CLIENT_STATUS_* */ + struct list_head client_hash; /**< For name hash table (clientTable) */ + char name[HOSTLEN + 1]; /**< Unique name of the client: nickname for users, hostname for servers */ + time_t lastnick; /**< Timestamp on nick */ + uint64_t flags; /**< Client flags (one or more of CLIENT_FLAG_*) */ + long umodes; /**< Client usermodes (if user) */ /** Direction from which this client originated. * This always points to a directly connected server or &me. * It is never NULL */ Client *direction; - unsigned char hopcount; /**< Number of servers to this, 0 means local client */ - unsigned char known_user_cached; /**< Cached as a "known user" */ - char ident[USERLEN + 1]; /**< Ident of the user, if available. Otherwise set to "unknown". */ - char info[REALLEN + 1]; /**< Additional client information text. For users this is gecos/realname */ - char id[IDLEN + 1]; /**< Unique ID: SID or UID */ - struct list_head id_hash; /**< For UID/SID hash table (idTable) */ - Client *uplink; /**< Server on where this client is connected to (can be &me) */ - char *ip; /**< IP address of user or server (can be NULL, eg for Services) */ - char rawip[16]; /**< The raw IP in network byte order */ - ModData moddata[MODDATA_MAX_CLIENT]; /**< Client attached module data, used by the ModData system */ + unsigned char hopcount; /**< Number of servers to this, 0 means local client */ + unsigned char known_user_cached; /**< Cached as a "known user" */ + char ident[USERLEN + 1]; /**< Ident of the user, if available. Otherwise set to "unknown". */ + char info[REALLEN + 1]; /**< Additional client information text. For users this is gecos/realname */ + char id[IDLEN + 1]; /**< Unique ID: SID or UID */ + struct list_head id_hash; /**< For UID/SID hash table (idTable) */ + Client *uplink; /**< Server on where this client is connected to (can be &me) */ + char *ip; /**< IP address of user or server (can be NULL, eg for Services) */ + char rawip[16]; /**< The raw IP in network byte order */ + ModData moddata[MODDATA_MAX_CLIENT]; /**< Client attached module data, used by the ModData system */ }; /** Local client information, use client->local to access these (see also @link Client @endlink). */ struct LocalClient { - int fd; /**< File descriptor, can be <0 if socket has been closed already. */ - SocketType socket_type; /**< Type of socket: IPv4, IPV6, UNIX */ - SSL *ssl; /**< OpenSSL/LibreSSL struct for TLS connection */ - time_t fake_lag; /**< Time when user will next be allowed to send something (actually fake_lag0 if SASL authentication was successful */ - time_t sasl_sent_time; /**< SASL: 0 or the time that the (last) AUTHENTICATE command has been sent */ - char *sni_servername; /**< Servername as sent by client via SNI (Server Name Indication) in TLS, otherwise NULL */ - int cap_protocol; /**< CAP protocol in use. At least 300 for any CAP capable client. 302 for 3.2, etc.. */ - uint32_t nospoof; /**< Anti-spoofing random number (used in user handshake PING/PONG) */ - char *passwd; /**< Password used during connect, if any (freed once connected and set to NULL) */ - int authfd; /**< File descriptor for ident checking (RFC931) */ - int identbufcnt; /**< Counter for 'ident' reading code */ - struct hostent *hostp; /**< Host record for this client (used by DNS code) */ - char sockhost[HOSTLEN + 1]; /**< Hostname from the socket */ + int fd; /**< File descriptor, can be <0 if socket has been closed already. */ + SocketType socket_type; /**< Type of socket: IPv4, IPV6, UNIX */ + SSL *ssl; /**< OpenSSL/LibreSSL struct for TLS connection */ + time_t fake_lag; /**< Time when user will next be allowed to send something (actually fake_lag0 if SASL authentication was successful */ + time_t sasl_sent_time; /**< SASL: 0 or the time that the (last) AUTHENTICATE command has been sent */ + char *sni_servername; /**< Servername as sent by client via SNI (Server Name Indication) in TLS, otherwise NULL */ + int cap_protocol; /**< CAP protocol in use. At least 300 for any CAP capable client. 302 for 3.2, etc.. */ + uint32_t nospoof; /**< Anti-spoofing random number (used in user handshake PING/PONG) */ + char *passwd; /**< Password used during connect, if any (freed once connected and set to NULL) */ + int authfd; /**< File descriptor for ident checking (RFC931) */ + int identbufcnt; /**< Counter for 'ident' reading code */ + struct hostent *hostp; /**< Host record for this client (used by DNS code) */ + char sockhost[HOSTLEN + 1]; /**< Hostname from the socket */ FloodCounter flood[MAXFLOODOPTIONS]; - RPCClient *rpc; /**< RPC Client, or NULL */ - Tag *tags; /**< Tags from spamfilter */ - int tags_serial; /**< To keep track of 'tags' changes */ - int spamfilter_run_tags_serial; /**< The last time (well, tags_serial) that rule-only-spamfilters ran. */ + RPCClient *rpc; /**< RPC Client, or NULL */ + Tag *tags; /**< Tags from spamfilter */ + int tags_serial; /**< To keep track of 'tags' changes */ + int spamfilter_run_tags_serial; /**< The last time (well, tags_serial) that rule-only-spamfilters ran. */ }; /** User information (persons, not servers), you use client->user to access these (see also @link Client @endlink). */ struct User { - Membership *channel; /**< Channels that the user is in (linked list) */ - Link *dccallow; /**< DCCALLOW list (linked list) */ - char account[ACCOUNTLEN + 1]; /**< Services account name or ID (SVID) - use IsLoggedIn(client) to check if logged in */ - int joined; /**< Number of channels joined */ - char username[USERLEN + 1]; /**< Username, the user portion in nick!user@host. */ - char realhost[HOSTLEN + 1]; /**< Realhost, the real host of the user (IP or hostname) - usually this is not shown to other users */ - char cloakedhost[HOSTLEN + 1]; /**< Cloaked host - generated by cloaking algorithm */ - char *virthost; /**< Virtual host - when user has user mode +x this is the active host */ - char *server; /**< Server name the user is on (?) */ - SWhois *swhois; /**< Special "additional" WHOIS entries such as "a Network Administrator" */ - WhoWas *whowas; /**< Something for whowas :D :D */ - char *snomask; /**< Server Notice Mask (snomask) - only for IRCOps */ - char *operlogin; /**< Which oper { } block was used to oper up, otherwise NULL - used for auditting and by oper::maxlogins */ - char *away; /**< AWAY message, or NULL if not away */ - time_t away_since; /**< Last time the user went AWAY */ + Membership *channel; /**< Channels that the user is in (linked list) */ + Link *dccallow; /**< DCCALLOW list (linked list) */ + char account[ACCOUNTLEN + 1]; /**< Services account name or ID (SVID) - use IsLoggedIn(client) to check if logged in */ + int joined; /**< Number of channels joined */ + char username[USERLEN + 1]; /**< Username, the user portion in nick!user@host. */ + char realhost[HOSTLEN + 1]; /**< Realhost, the real host of the user (IP or hostname) - usually this is not shown to other users */ + char cloakedhost[HOSTLEN + 1]; /**< Cloaked host - generated by cloaking algorithm */ + char *virthost; /**< Virtual host - when user has user mode +x this is the active host */ + char *server; /**< Server name the user is on (?) */ + SWhois *swhois; /**< Special "additional" WHOIS entries such as "a Network Administrator" */ + WhoWas *whowas; /**< Something for whowas :D :D */ + char *snomask; /**< Server Notice Mask (snomask) - only for IRCOps */ + char *operlogin; /**< Which oper { } block was used to oper up, otherwise NULL - used for auditting and by oper::maxlogins */ + char *away; /**< AWAY message, or NULL if not away */ + time_t away_since; /**< Last time the user went AWAY */ }; /** Server information (local servers and remote servers), you use client->server to access these (see also @link Client @endlink). */ struct Server { - char by[NICKLEN + 1]; /**< Uhhhh - who activated this connection - AGAIN? */ - ConfigItem_link *conf; /**< link { } block associated with this server, or NULL */ - long users; /**< Number of users on this server */ - time_t boottime; /**< Startup time of server (boot time) */ + char by[NICKLEN + 1]; /**< Uhhhh - who activated this connection - AGAIN? */ + ConfigItem_link *conf; /**< link { } block associated with this server, or NULL */ + long users; /**< Number of users on this server */ + time_t boottime; /**< Startup time of server (boot time) */ struct { - unsigned synced:1; /**< Server synchronization finished? (3.2beta18+) */ - unsigned server_sent:1; /**< SERVER message sent to this link? (for outgoing links) */ + unsigned synced : 1; /**< Server synchronization finished? (3.2beta18+) */ + unsigned server_sent : 1; /**< SERVER message sent to this link? (for outgoing links) */ } flags; struct { - char *usermodes; /**< Usermodes that this server knows about */ - char *chanmodes[4]; /**< Channel modes that this server knows (in 4 groups, like CHANMODES= in ISUPPORT/005) */ - int protocol; /**< Link-protocol version */ - char *software; /**< Name of the software (eg: unrealircd-X.Y.Z) */ - char *nickchars; /**< Nick character sets active on this server) */ + char *usermodes; /**< Usermodes that this server knows about */ + char *chanmodes[4]; /**< Channel modes that this server knows (in 4 groups, like CHANMODES= in ISUPPORT/005) */ + int protocol; /**< Link-protocol version */ + char *software; /**< Name of the software (eg: unrealircd-X.Y.Z) */ + char *nickchars; /**< Nick character sets active on this server) */ } features; }; @@ -1621,8 +1666,8 @@ struct Server { /** RPC Client information */ struct RPCClient { - char *rpc_user; /**< Name of the rpc-user block after authentication, NULL during pre-auth */ - char *issuer; /**< Optional name of the issuer, set by rpc.set_issuer(), eg logged in user on admin panel, can be NULL */ + char *rpc_user; /**< Name of the rpc-user block after authentication, NULL during pre-auth */ + char *issuer; /**< Optional name of the issuer, set by rpc.set_issuer(), eg logged in user on admin panel, can be NULL */ json_t *rehash_request; /**< If a REHASH (request) is currently running, otherwise NULL */ LogSource *log_sources; /**< Subscribed to which log sources */ }; @@ -1633,8 +1678,7 @@ struct MessageTag { char *value; }; -struct LineCacheLine -{ +struct LineCacheLine { LineCacheLine *prev, *next; LineCacheUserType user_type; unsigned long caps; @@ -1643,37 +1687,36 @@ struct LineCacheLine int linelen; }; -struct LineCache -{ +struct LineCache { LineCacheLine *items; }; /* conf preprocessor */ typedef enum PreprocessorItem { - PREPROCESSOR_ERROR = 0, - PREPROCESSOR_DEFINE = 1, - PREPROCESSOR_IF = 2, - PREPROCESSOR_ENDIF = 3, - PREPROCESSOR_ELSE = 4, - PREPROCESSOR_USER_ERROR = 5, - PREPROCESSOR_USER_WARNING = 6 + PREPROCESSOR_ERROR = 0, + PREPROCESSOR_DEFINE = 1, + PREPROCESSOR_IF = 2, + PREPROCESSOR_ENDIF = 3, + PREPROCESSOR_ELSE = 4, + PREPROCESSOR_USER_ERROR = 5, + PREPROCESSOR_USER_WARNING = 6 } PreprocessorItem; typedef enum PreprocessorPhase { - PREPROCESSOR_PHASE_INITIAL = 1, - PREPROCESSOR_PHASE_SECONDARY = 2, - PREPROCESSOR_PHASE_MODULE = 3 + PREPROCESSOR_PHASE_INITIAL = 1, + PREPROCESSOR_PHASE_SECONDARY = 2, + PREPROCESSOR_PHASE_MODULE = 3 } PreprocessorPhase; typedef enum AuthenticationType { - AUTHTYPE_INVALID = -1, - AUTHTYPE_PLAINTEXT = 0, - AUTHTYPE_TLS_CLIENTCERT = 1, - AUTHTYPE_TLS_CLIENTCERTFP = 2, - AUTHTYPE_SPKIFP = 3, - AUTHTYPE_UNIXCRYPT = 4, - AUTHTYPE_BCRYPT = 5, - AUTHTYPE_ARGON2 = 6, + AUTHTYPE_INVALID = -1, + AUTHTYPE_PLAINTEXT = 0, + AUTHTYPE_TLS_CLIENTCERT = 1, + AUTHTYPE_TLS_CLIENTCERTFP = 2, + AUTHTYPE_SPKIFP = 3, + AUTHTYPE_UNIXCRYPT = 4, + AUTHTYPE_BCRYPT = 5, + AUTHTYPE_ARGON2 = 6, } AuthenticationType; typedef struct AuthConfig AuthConfig; @@ -1682,94 +1725,103 @@ typedef struct AuthConfig AuthConfig; * configuration file. */ struct AuthConfig { - AuthConfig *prev, *next; - AuthenticationType type; /**< Type of data, one of AUTHTYPE_* */ - char *data; /**< Data associated with this record */ + AuthConfig *prev, *next; + AuthenticationType type; /**< Type of data, one of AUTHTYPE_* */ + char *data; /**< Data associated with this record */ }; #ifndef HAVE_CRYPT -#define crypt DES_crypt + #define crypt DES_crypt #endif /* * conf2 stuff -stskeeps */ -typedef enum ConfigIfCondition { IF_DEFINED=1, IF_VALUE=2, IF_MODULE_LOADED=3, IF_MODULE_EXISTS=4, IF_MINIMUM_VERSION=5, IF_FILE_EXISTS=6, IF_ENVIRONMENT=7, IF_MODULE_VERSION=8} ConfigIfCondition; -typedef enum CompareOp { COMPARE_EQ=0, COMPARE_NE=1, COMPARE_GT=2, COMPARE_GE=3, COMPARE_LT=4, COMPARE_LE=5 } CompareOp; +typedef enum ConfigIfCondition { + IF_DEFINED = 1, + IF_VALUE = 2, + IF_MODULE_LOADED = 3, + IF_MODULE_EXISTS = 4, + IF_MINIMUM_VERSION = 5, + IF_FILE_EXISTS = 6, + IF_ENVIRONMENT = 7, + IF_MODULE_VERSION = 8 +} ConfigIfCondition; +typedef enum CompareOp { + COMPARE_EQ = 0, + COMPARE_NE = 1, + COMPARE_GT = 2, + COMPARE_GE = 3, + COMPARE_LT = 4, + COMPARE_LE = 5 +} CompareOp; -struct ConditionalConfig -{ +struct ConditionalConfig { ConditionalConfig *prev, *next; - int priority; /**< Preprocessor level. Starts with 1, then 2, 3, .. */ + int priority; /**< Preprocessor level. Starts with 1, then 2, 3, .. */ ConfigIfCondition condition; /**< See ConfigIfCondition, one of: IF_* */ - int negative; /**< For ! conditions */ - CompareOp compare_op; /**< Only for IF_VALUE */ - int had_else; /**< Set to 1 after @else, to prevent duplicate @else */ - char *name; /**< Name of the variable or module */ - char *opt; /**< Only for IF_VALUE */ + int negative; /**< For ! conditions */ + CompareOp compare_op; /**< Only for IF_VALUE */ + int had_else; /**< Set to 1 after @else, to prevent duplicate @else */ + char *name; /**< Name of the variable or module */ + char *opt; /**< Only for IF_VALUE */ }; /** Configuration file (config parser) */ -struct ConfigFile -{ - char *filename; /**< Filename of configuration file */ - ConfigEntry *items; /**< All items in the configuration file */ - ConfigFile *next; /**< Next configuration file */ +struct ConfigFile { + char *filename; /**< Filename of configuration file */ + ConfigEntry *items; /**< All items in the configuration file */ + ConfigFile *next; /**< Next configuration file */ }; /** Configuration entry (config parser) */ -struct ConfigEntry -{ - char *name; /**< Variable name */ - char *value; /**< Variable value, can be NULL */ - ConfigEntry *next; /**< Next ConfigEntry */ - ConfigEntry *items; /**< Items (children), can be NULL */ - ConfigFile *file; /**< To which configfile does this belong? */ - int line_number; /**< Line number of the variable name (this one is usually used for errors) */ - int file_position_start; /**< Position (byte) within configuration file of the start of the block, rarely used */ - int file_position_end; /**< Position (byte) within configuration file of the end of the block, rarely used */ - int section_linenumber; /**< Line number of the section (only used internally for parse errors) */ - ConfigEntry *parent; /**< Parent item, can be NULL */ - ConditionalConfig *conditional_config; /**< Used for conditional config by the main parser */ - unsigned escaped:1; - unsigned bad:1; +struct ConfigEntry { + char *name; /**< Variable name */ + char *value; /**< Variable value, can be NULL */ + ConfigEntry *next; /**< Next ConfigEntry */ + ConfigEntry *items; /**< Items (children), can be NULL */ + ConfigFile *file; /**< To which configfile does this belong? */ + int line_number; /**< Line number of the variable name (this one is usually used for errors) */ + int file_position_start; /**< Position (byte) within configuration file of the start of the block, rarely used */ + int file_position_end; /**< Position (byte) within configuration file of the end of the block, rarely used */ + int section_linenumber; /**< Line number of the section (only used internally for parse errors) */ + ConfigEntry *parent; /**< Parent item, can be NULL */ + ConditionalConfig *conditional_config; /**< Used for conditional config by the main parser */ + unsigned escaped : 1; + unsigned bad : 1; }; -struct ConfigFlag -{ - unsigned temporary : 1; - unsigned permanent : 1; +struct ConfigFlag { + unsigned temporary : 1; + unsigned permanent : 1; }; /* configflag specialized for except socks/ban -Stskeeps */ -struct ConfigFlag_except -{ - unsigned temporary : 1; - unsigned type : 4; +struct ConfigFlag_except { + unsigned temporary : 1; + unsigned type : 4; }; -struct ConfigFlag_ban -{ - unsigned temporary : 1; - unsigned type : 4; - unsigned type2 : 2; +struct ConfigFlag_ban { + unsigned temporary : 1; + unsigned type : 4; + unsigned type2 : 2; }; -struct ConfigFlag_tld -{ - unsigned temporary : 1; - unsigned motdptr : 1; - unsigned ruleclient : 1; +struct ConfigFlag_tld { + unsigned temporary : 1; + unsigned motdptr : 1; + unsigned ruleclient : 1; }; -#define CONF_BAN_SERVER 1 -#define CONF_BAN_VERSION 2 -#define CONF_BAN_REALNAME 3 +#define CONF_BAN_SERVER 1 +#define CONF_BAN_VERSION 2 +#define CONF_BAN_REALNAME 3 -#define CONF_BAN_TYPE_CONF 0 -#define CONF_BAN_TYPE_AKILL 1 +#define CONF_BAN_TYPE_CONF 0 +#define CONF_BAN_TYPE_AKILL 1 #define CONF_BAN_TYPE_TEMPORARY 2 struct ConfigItem { @@ -1778,28 +1830,28 @@ struct ConfigItem { }; struct ConfigItem_me { - char *name, *info, *sid; + char *name, *info, *sid; }; struct ConfigItem_files { - char *motd_file, *rules_file, *smotd_file; - char *botmotd_file, *opermotd_file, *svsmotd_file; - char *pid_file, *tune_file; + char *motd_file, *rules_file, *smotd_file; + char *botmotd_file, *opermotd_file, *svsmotd_file; + char *pid_file, *tune_file; }; struct ConfigItem_admin { ConfigItem_admin *prev, *next; ConfigFlag flag; - char *line; + char *line; }; -#define CLASS_OPT_NOFAKELAG 0x1 +#define CLASS_OPT_NOFAKELAG 0x1 struct ConfigItem_class { ConfigItem_class *prev, *next; ConfigFlag flag; - char *name; - int pingfreq, connfreq, maxclients, sendq, recvq, clients; + char *name; + int pingfreq, connfreq, maxclients, sendq, recvq, clients; int xrefcount; /* EXTRA reference count, 'clients' also acts as a reference count but * link blocks also refer to classes so a 2nd ref. count was needed. */ @@ -1807,10 +1859,10 @@ struct ConfigItem_class { }; struct ConfigFlag_allow { - unsigned noident :1; - unsigned useip :1; - unsigned tls :1; - unsigned reject_on_auth_failure :1; + unsigned noident : 1; + unsigned useip : 1; + unsigned tls : 1; + unsigned reject_on_auth_failure : 1; }; /** allow { } block settings */ @@ -1820,54 +1872,48 @@ struct ConfigItem_allow { SecurityGroup *match; char *server; AuthConfig *auth; - int maxperip; /**< Maximum connections permitted per IP address (locally) */ + int maxperip; /**< Maximum connections permitted per IP address (locally) */ int global_maxperip; /**< Maximum connections permitted per IP address (globally) */ int port; ConfigItem_class *class; ConfigFlag_allow flags; }; -struct OperClassACLPath -{ - OperClassACLPath *prev,*next; +struct OperClassACLPath { + OperClassACLPath *prev, *next; char *identifier; }; -struct OperClassACLEntryVar -{ - OperClassACLEntryVar *prev,*next; - char *name; - char *value; +struct OperClassACLEntryVar { + OperClassACLEntryVar *prev, *next; + char *name; + char *value; }; -struct OperClassACLEntry -{ - OperClassACLEntry *prev,*next; - OperClassACLEntryVar *variables; - OperClassEntryType type; +struct OperClassACLEntry { + OperClassACLEntry *prev, *next; + OperClassACLEntryVar *variables; + OperClassEntryType type; }; -struct OperClassACL -{ - OperClassACL *prev,*next; - char *name; - OperClassACLEntry *entries; - OperClassACL *acls; +struct OperClassACL { + OperClassACL *prev, *next; + char *name; + OperClassACLEntry *entries; + OperClassACL *acls; }; -struct OperClass -{ - char *ISA; - char *name; - OperClassACL *acls; +struct OperClass { + char *ISA; + char *name; + OperClassACL *acls; }; -struct OperClassCheckParams -{ - Client *client; - Client *victim; - Channel *channel; - const void *extra; +struct OperClassCheckParams { + Client *client; + Client *victim; + Channel *channel; + const void *extra; }; struct ConfigItem_operclass { @@ -1902,7 +1948,7 @@ typedef struct TLSOptions TLSOptions; struct TLSOptions { NameList *certificate_files; NameList *key_files; - NameList *spkifp; /**< spkifp of each loaded certificate, computed by init_ctx() */ + NameList *spkifp; /**< spkifp of each loaded certificate, computed by init_ctx() */ char *trusted_ca_file; unsigned int protocols; char *ciphers; @@ -1927,54 +1973,53 @@ struct ConfigItem_mask { }; struct ConfigItem_drpass { - AuthConfig *restartauth; - AuthConfig *dieauth; + AuthConfig *restartauth; + AuthConfig *dieauth; }; struct ConfigItem_ulines { - ConfigItem_ulines *prev, *next; - ConfigFlag flag; - char *servername; + ConfigItem_ulines *prev, *next; + ConfigFlag flag; + char *servername; }; -#define TLD_TLS 0x1 -#define TLD_REMOTE 0x2 +#define TLD_TLS 0x1 +#define TLD_REMOTE 0x2 struct ConfigItem_tld { - ConfigItem_tld *prev, *next; - ConfigFlag_tld flag; - SecurityGroup *match; - char *channel; - char *motd_file, *rules_file, *smotd_file; - char *botmotd_file, *opermotd_file; - MOTDFile rules, motd, smotd, botmotd, opermotd; - u_short options; + ConfigItem_tld *prev, *next; + ConfigFlag_tld flag; + SecurityGroup *match; + char *channel; + char *motd_file, *rules_file, *smotd_file; + char *botmotd_file, *opermotd_file; + MOTDFile rules, motd, smotd, botmotd, opermotd; + u_short options; }; -#define WEB_OPT_ENABLE 0x1 +#define WEB_OPT_ENABLE 0x1 /** The HTTP method to use */ typedef enum HttpMethod { - HTTP_METHOD_NONE = 0, /**< No valid HTTP request (yet) */ - HTTP_METHOD_HEAD = 1, /**< HEAD request */ - HTTP_METHOD_GET = 2, /**< GET request */ - HTTP_METHOD_PUT = 3, /**< PUT request */ - HTTP_METHOD_POST = 4, /**< POST request */ + HTTP_METHOD_NONE = 0, /**< No valid HTTP request (yet) */ + HTTP_METHOD_HEAD = 1, /**< HEAD request */ + HTTP_METHOD_GET = 2, /**< GET request */ + HTTP_METHOD_PUT = 3, /**< PUT request */ + HTTP_METHOD_POST = 4, /**< POST request */ } HttpMethod; typedef enum TransferEncoding { - TRANSFER_ENCODING_NONE=0, - TRANSFER_ENCODING_CHUNKED=1 + TRANSFER_ENCODING_NONE = 0, + TRANSFER_ENCODING_CHUNKED = 1 } TransferEncoding; /* Used to parse http Forwarded header (RFC 7239)... */ #define IPLEN 48 typedef struct HTTPForwardedHeader HTTPForwardedHeader; -struct HTTPForwardedHeader -{ +struct HTTPForwardedHeader { int secure; - char hostname[HOSTLEN+1]; - char ip[IPLEN+1]; + char hostname[HOSTLEN + 1]; + char ip[IPLEN + 1]; }; @@ -1988,22 +2033,21 @@ struct HTTPForwardedHeader * 1) update duplicate_outgoingwebrequest() in src/misc.c * 2) and update free_outgoingwebrequest() there as well (if something needs to be freed) */ -struct OutgoingWebRequest -{ +struct OutgoingWebRequest { void (*callback)(OutgoingWebRequest *request, OutgoingWebResponse *response); /**< Either use this for non-modules (NOT recommended) */ - char *apicallback; /**< Set this to the name of an api callback that you registered via RegisterApiCallbackWebResponse() in MOD_INIT */ - void *callback_data; /**< Optionally, set this to keep track of requests. The response function will carry this in OutgoingWebResponse in 'ptr' */ - char *url; /**< The URL to visit */ - char *actual_url; /**< if you actually want to use a different url, mostly for redirects (end-users: don't set this!) */ - HttpMethod http_method; /**< Must be set explicitly. When in doubt, use HTTP_METHOD_GET */ - char *body; /**< If you want to send a body in the request. This only makes sense for PUT/POST */ - NameValuePrioList *headers; /**< Any headers you want to see in the HTTP request */ - int store_in_file; /**< Set to 1 to store the result in a file (basically a download), used by remote includes and the like. */ - time_t cachetime; /**< The cached time of an existing file on disk. If the version online is the same then this may avoid downloading a large file. */ - int max_redirects; /**< Maximum number of times we are allowed to redirect from one page to another */ - int keep_file; /**< Normally, if store_in_file is set to 1, the downloaded file is deleted after the callback function was called. If you set this to 1 then the file is not removed. */ - int connect_timeout; /**< How many seconds to wait for the (TLS) connect to succeed */ - int transfer_timeout; /**< How many seconds the total transfer may take (connect+reading everything) */ + char *apicallback; /**< Set this to the name of an api callback that you registered via RegisterApiCallbackWebResponse() in MOD_INIT */ + void *callback_data; /**< Optionally, set this to keep track of requests. The response function will carry this in OutgoingWebResponse in 'ptr' */ + char *url; /**< The URL to visit */ + char *actual_url; /**< if you actually want to use a different url, mostly for redirects (end-users: don't set this!) */ + HttpMethod http_method; /**< Must be set explicitly. When in doubt, use HTTP_METHOD_GET */ + char *body; /**< If you want to send a body in the request. This only makes sense for PUT/POST */ + NameValuePrioList *headers; /**< Any headers you want to see in the HTTP request */ + int store_in_file; /**< Set to 1 to store the result in a file (basically a download), used by remote includes and the like. */ + time_t cachetime; /**< The cached time of an existing file on disk. If the version online is the same then this may avoid downloading a large file. */ + int max_redirects; /**< Maximum number of times we are allowed to redirect from one page to another */ + int keep_file; /**< Normally, if store_in_file is set to 1, the downloaded file is deleted after the callback function was called. If you set this to 1 then the file is not removed. */ + int connect_timeout; /**< How many seconds to wait for the (TLS) connect to succeed */ + int transfer_timeout; /**< How many seconds the total transfer may take (connect+reading everything) */ int minimum_tls_version; long long max_size; /**< Max response size, in bytes. 0 selects a default * based on the download mode: @@ -2015,35 +2059,34 @@ struct OutgoingWebRequest /** The result of an HTTP(S) call, such as the downloaded file, error, etc. * If you add or modify fields, update url_callback() in src/misc.c! */ -struct OutgoingWebResponse -{ - const char *file; /**< The temporary file of the download, or NULL. This is only set if OutgoingWebRequest had 'store_in_file' set to 1 and the download was succesful. */ - const char *memory; /**< The memory buffer of the response, or NULL if an error occured (see errorbuf) */ +struct OutgoingWebResponse { + const char *file; /**< The temporary file of the download, or NULL. This is only set if OutgoingWebRequest had 'store_in_file' set to 1 and the download was succesful. */ + const char *memory; /**< The memory buffer of the response, or NULL if an error occured (see errorbuf) */ long long memory_len; /**< The length of 'memory', since the response may contain binary data. */ const char *errorbuf; /**< If this is non-NULL then an error occured and this is the error string. Check this member before checking any others! */ - int cached; /**< Set to 1 if OutgoingWebRequest had 'cachetime' set and we have a cache hit on the webserver. The file and errobuf will be NULL since there was no data transfer. */ - void *ptr; /**< The OutgoingWebRequest 'callback_data' */ + int cached; /**< Set to 1 if OutgoingWebRequest had 'cachetime' set and we have a cache hit on the webserver. The file and errobuf will be NULL since there was no data transfer. */ + void *ptr; /**< The OutgoingWebRequest 'callback_data' */ }; typedef struct WebRequest WebRequest; /** An incoming web request */ struct WebRequest { - HttpMethod method; /**< GET/PUT/POST */ - char *uri; /**< Requested resource, eg "/api" */ + HttpMethod method; /**< GET/PUT/POST */ + char *uri; /**< Requested resource, eg "/api" */ NameValuePrioList *headers; /**< HTTP request headers */ - int num_headers; /**< Number of HTTP request headers (also used for sorting the list) */ + int num_headers; /**< Number of HTTP request headers (also used for sorting the list) */ char request_header_parsed; /**< Done parsing? */ - char *lefttoparse; /**< Leftover buffer to parse */ - int lefttoparselen; /**< Length of lefttoparse buffer */ - int pending_close; /**< Set to 1 when connection should be closed as soon as all data is sent (sendq==0) */ - char *request_buffer; /**< Buffer for POST data */ - int request_buffer_size; /**< Size of buffer for POST data */ - int request_body_complete; /**< POST data has all been read */ - long long content_length; /**< "Content-Length" as sent by the client */ + char *lefttoparse; /**< Leftover buffer to parse */ + int lefttoparselen; /**< Length of lefttoparse buffer */ + int pending_close; /**< Set to 1 when connection should be closed as soon as all data is sent (sendq==0) */ + char *request_buffer; /**< Buffer for POST data */ + int request_buffer_size; /**< Size of buffer for POST data */ + int request_body_complete; /**< POST data has all been read */ + long long content_length; /**< "Content-Length" as sent by the client */ long long chunk_remaining; TransferEncoding transfer_encoding; long long config_max_request_buffer_size; /**< CONFIG: Maximum request length allowed */ - HTTPForwardedHeader *forwarded; /**< If using a proxy */ + HTTPForwardedHeader *forwarded; /**< If using a proxy */ }; typedef struct WebServer WebServer; @@ -2054,17 +2097,17 @@ struct WebServer { typedef enum WebSocketType { WEBSOCKET_TYPE_BINARY = 1, - WEBSOCKET_TYPE_TEXT = 2 + WEBSOCKET_TYPE_TEXT = 2 } WebSocketType; typedef struct WebSocketUser WebSocketUser; struct WebSocketUser { - char get; /**< GET initiated */ - char handshake_completed; /**< Handshake completed, use websocket frames */ - char *handshake_key; /**< Handshake key (used during handshake) */ - char *lefttoparse; /**< Leftover buffer to parse */ - int lefttoparselen; /**< Length of lefttoparse buffer */ - WebSocketType type; /**< WEBSOCKET_TYPE_BINARY or WEBSOCKET_TYPE_TEXT */ + char get; /**< GET initiated */ + char handshake_completed; /**< Handshake completed, use websocket frames */ + char *handshake_key; /**< Handshake key (used during handshake) */ + char *lefttoparse; /**< Leftover buffer to parse */ + int lefttoparselen; /**< Length of lefttoparse buffer */ + WebSocketType type; /**< WEBSOCKET_TYPE_BINARY or WEBSOCKET_TYPE_TEXT */ char *sec_websocket_protocol; /**< Only valid during parsing of the request, after that it is NULL again */ }; @@ -2081,22 +2124,22 @@ struct WebSocketUser { struct ConfigItem_listen { ConfigItem_listen *prev, *next; ConfigFlag flag; - SocketType socket_type; /**< Socket type, eg. SOCKET_TYPE_IPV4 or SOCKET_TYPE_UNIX */ - char *file; /**< If the listener is a file, the full pathname */ - char *ip; /**< IP bind address (if IP listener) */ - int port; /**< Port to listen on (if IP listener) */ - int mode; /**< Mode permissions (if file aka unix socket listener) */ - int options; /**< e.g. LISTENER_BOUND if active */ - int clients; /**< Clients connected to this socket / listener */ - int fd; /**< File descriptor (if open), or -1 (if not open yet) */ - char *spoof_ip; /**< listen::spoof-ip (only for listen::file, if you want to override 127.0.0.1) */ - SSL_CTX *ssl_ctx; /**< SSL/TLS context */ - TLSOptions *tls_options; /**< SSL/TLS options */ - WebServer *webserver; /**< For the webserver module */ + SocketType socket_type; /**< Socket type, eg. SOCKET_TYPE_IPV4 or SOCKET_TYPE_UNIX */ + char *file; /**< If the listener is a file, the full pathname */ + char *ip; /**< IP bind address (if IP listener) */ + int port; /**< Port to listen on (if IP listener) */ + int mode; /**< Mode permissions (if file aka unix socket listener) */ + int options; /**< e.g. LISTENER_BOUND if active */ + int clients; /**< Clients connected to this socket / listener */ + int fd; /**< File descriptor (if open), or -1 (if not open yet) */ + char *spoof_ip; /**< listen::spoof-ip (only for listen::file, if you want to override 127.0.0.1) */ + SSL_CTX *ssl_ctx; /**< SSL/TLS context */ + TLSOptions *tls_options; /**< SSL/TLS options */ + WebServer *webserver; /**< For the webserver module */ void (*start_handshake)(Client *client); /**< Function to call on accept() */ - int websocket_options; /**< Websocket options (for the websocket module) */ - NameList *websocket_origin; /**< List of permitted Origin */ - int rpc_options; /**< For the RPC module */ + int websocket_options; /**< Websocket options (for the websocket module) */ + NameList *websocket_origin; /**< List of permitted Origin */ + int rpc_options; /**< For the RPC module */ }; struct ConfigItem_sni { @@ -2108,77 +2151,82 @@ struct ConfigItem_sni { }; struct ConfigItem_link { - ConfigItem_link *prev, *next; - ConfigFlag flag; + ConfigItem_link *prev, *next; + ConfigFlag flag; /* config options: */ char *servername; /**< Name of the server ('link { }') */ struct { SecurityGroup *match; /**< incoming mask(s) to accept */ } incoming; struct { - char *file; /**< UNIX domain socket to connect to */ - char *bind_ip; /**< Our IP to bind to when doing the connect */ + char *file; /**< UNIX domain socket to connect to */ + char *bind_ip; /**< Our IP to bind to when doing the connect */ char *hostname; /**< Hostname or IP to connect to */ - int port; /**< Port to connect to */ - int options; /**< Connect options like tls or autoconnect */ + int port; /**< Port to connect to */ + int options; /**< Connect options like tls or autoconnect */ } outgoing; - AuthConfig *auth; /**< authentication method (eg: password) */ - char *hub; /**< Hub mask */ - char *leaf; /**< Leaf mask */ - int leaf_depth; /**< Leaf depth */ + AuthConfig *auth; /**< authentication method (eg: password) */ + char *hub; /**< Hub mask */ + char *leaf; /**< Leaf mask */ + int leaf_depth; /**< Leaf depth */ ConfigItem_class *class; /**< Class the server should use */ - int options; /**< Generic options such as quarantine */ + int options; /**< Generic options such as quarantine */ int verify_certificate; /* internal: */ - int refcount; /**< Reference counter (used so we know if the struct may be freed) */ - time_t hold; /**< For how long the server is "on hold" for outgoing connects (why?) */ - char *connect_ip; /**< actual IP to use for outgoing connect (filled in after host is resolved) */ - SSL_CTX *ssl_ctx; /**< SSL Context for outgoing connection (optional) */ + int refcount; /**< Reference counter (used so we know if the struct may be freed) */ + time_t hold; /**< For how long the server is "on hold" for outgoing connects (why?) */ + char *connect_ip; /**< actual IP to use for outgoing connect (filled in after host is resolved) */ + SSL_CTX *ssl_ctx; /**< SSL Context for outgoing connection (optional) */ TLSOptions *tls_options; /**< SSL Options for outgoing connection (optional) */ }; struct ConfigItem_ban { - ConfigItem_ban *prev, *next; - ConfigFlag_ban flag; - char *mask, *reason; - BanAction *action; + ConfigItem_ban *prev, *next; + ConfigFlag_ban flag; + char *mask, *reason; + BanAction *action; }; struct ConfigItem_deny_dcc { - ConfigItem_deny_dcc *prev, *next; - ConfigFlag_ban flag; - char *filename, *reason; + ConfigItem_deny_dcc *prev, *next; + ConfigFlag_ban flag; + char *filename, *reason; }; struct ConfigItem_deny_version { - ConfigItem_deny_version *prev, *next; - ConfigFlag flag; - char *mask, *version, *flags; + ConfigItem_deny_version *prev, *next; + ConfigFlag flag; + char *mask, *version, *flags; }; struct ConfigItem_deny_channel { - ConfigItem_deny_channel *prev, *next; - ConfigFlag flag; - char *channel, *reason, *redirect, *class; - unsigned char warn; - SecurityGroup *match; + ConfigItem_deny_channel *prev, *next; + ConfigFlag flag; + char *channel, *reason, *redirect, *class; + unsigned char warn; + SecurityGroup *match; }; struct ConfigItem_allow_channel { - ConfigItem_allow_channel *prev, *next; - ConfigFlag flag; - char *channel, *class; - SecurityGroup *match; + ConfigItem_allow_channel *prev, *next; + ConfigFlag flag; + char *channel, *class; + SecurityGroup *match; }; struct ConfigItem_allow_dcc { - ConfigItem_allow_dcc *prev, *next; - ConfigFlag_ban flag; - char *filename; + ConfigItem_allow_dcc *prev, *next; + ConfigFlag_ban flag; + char *filename; }; -typedef enum { - ALIAS_SERVICES=1, ALIAS_STATS, ALIAS_NORMAL, ALIAS_COMMAND, ALIAS_CHANNEL, ALIAS_REAL +typedef enum { + ALIAS_SERVICES = 1, + ALIAS_STATS, + ALIAS_NORMAL, + ALIAS_COMMAND, + ALIAS_CHANNEL, + ALIAS_REAL } AliasType; struct ConfigItem_alias { @@ -2187,7 +2235,7 @@ struct ConfigItem_alias { ConfigItem_alias_format *format; char *alias, *nick; AliasType type; - unsigned int spamfilter:1; + unsigned int spamfilter : 1; }; struct ConfigItem_alias_format { @@ -2199,32 +2247,32 @@ struct ConfigItem_alias_format { Match *expr; }; -#define RESOURCE_REMOTE 0x1 -#define RESOURCE_DLQUEUED 0x2 -#define RESOURCE_INCLUDE 0x4 +#define RESOURCE_REMOTE 0x1 +#define RESOURCE_DLQUEUED 0x2 +#define RESOURCE_INCLUDE 0x4 typedef struct ConfigEntryWrapper ConfigEntryWrapper; struct ConfigEntryWrapper { ConfigEntryWrapper *prev, *next; ConfigEntry *ce; }; - + struct ConfigResource { ConfigResource *prev, *next; int type; - ConfigEntryWrapper *wce; /**< The place(s) where this resource is begin used */ - char *file; /**< File to read: can be a conf/something file or a downloaded file */ - char *url; /**< URL, if it is an URL */ - char *cache_file; /**< Set to filename of local cached copy, if it is available */ + ConfigEntryWrapper *wce; /**< The place(s) where this resource is begin used */ + char *file; /**< File to read: can be a conf/something file or a downloaded file */ + char *url; /**< URL, if it is an URL */ + char *cache_file; /**< Set to filename of local cached copy, if it is available */ NameList *restrict_config; /**< If non-NULL: list of permitted config items */ - int warn_only_on_fail; /**< Set to 1 if we should ignore failed download attempts (and only warn) */ + int warn_only_on_fail; /**< Set to 1 if we should ignore failed download attempts (and only warn) */ }; /* When doing a HTTP request and it is requested to store the * response to memory (rather than file), we enlarge the buffer * in this chunk size. */ -#define URL_MEMORY_BACKED_CHUNK_SIZE 8192 +#define URL_MEMORY_BACKED_CHUNK_SIZE 8192 struct ConfigItem_blacklist_module { ConfigItem_blacklist_module *prev, *next; @@ -2240,23 +2288,23 @@ struct ConfigItem_help { struct ConfigItem_offchans { ConfigItem_offchans *prev, *next; - char name[CHANNELLEN+1]; + char name[CHANNELLEN + 1]; char *topic; }; typedef struct ConfigItem_proxy ConfigItem_proxy; typedef enum { - PROXY_WEBIRC_PASS=1, - PROXY_WEBIRC=2, - PROXY_FORWARDED=3, - PROXY_X_FORWARDED=4, - PROXY_CLOUDFLARE=5, + PROXY_WEBIRC_PASS = 1, + PROXY_WEBIRC = 2, + PROXY_FORWARDED = 3, + PROXY_X_FORWARDED = 4, + PROXY_CLOUDFLARE = 5, } ProxyType; -#define IsWebProxy(x) (((x) == PROXY_FORWARDED) || \ - ((x) == PROXY_X_FORWARDED) || \ - ((x) == PROXY_CLOUDFLARE)) +#define IsWebProxy(x) (((x) == PROXY_FORWARDED) || \ + ((x) == PROXY_X_FORWARDED) || \ + ((x) == PROXY_CLOUDFLARE)) struct ConfigItem_proxy { ConfigItem_proxy *prev, *next; @@ -2272,12 +2320,12 @@ typedef union DynamicSetOption { } DynamicSetOption; typedef enum SetOption { - SET_AUTO_JOIN = 0, /**< set::auto-join */ - SET_MODES_ON_CONNECT = 1, /**< set::modes-on-connect */ - SET_RESTRICT_USERMODES = 2, /**< set::restrict-usermodes */ - SET_MAX_CHANNELS_PER_USER = 3, /**< set::max-channels-per-user */ - SET_STATIC_QUIT = 4, /**< set::static-quit */ - SET_STATIC_PART = 5 /**< set::static-part */ + SET_AUTO_JOIN = 0, /**< set::auto-join */ + SET_MODES_ON_CONNECT = 1, /**< set::modes-on-connect */ + SET_RESTRICT_USERMODES = 2, /**< set::restrict-usermodes */ + SET_MAX_CHANNELS_PER_USER = 3, /**< set::max-channels-per-user */ + SET_STATIC_QUIT = 4, /**< set::static-quit */ + SET_STATIC_PART = 5 /**< set::static-part */ } SetOption; #define MAXDYNAMICSETTINGS 16 @@ -2295,7 +2343,7 @@ typedef struct DynamicSetBlock { struct SecurityGroup { SecurityGroup *prev, *next; int priority; - char name[SECURITYGROUPLEN+1]; + char name[SECURITYGROUPLEN + 1]; int public; NameValuePrioList *printable_list; int printable_list_counter; @@ -2311,7 +2359,7 @@ struct SecurityGroup { NameList *server_port; NameList *security_group; char *prettyrule; /* ::rule as a string */ - CRuleNode *rule; /**< parsed crule */ + CRuleNode *rule; /**< parsed crule */ NameList *destination; NameValuePrioList *extended; // IMPORTANT: If you are adding anything: @@ -2334,7 +2382,7 @@ struct SecurityGroup { NameList *exclude_server_port; NameList *exclude_security_group; char *exclude_prettyrule; /* ::exclude-rule as a string */ - CRuleNode *exclude_rule; /**< parsed crule */ + CRuleNode *exclude_rule; /**< parsed crule */ NameList *exclude_destination; NameValuePrioList *exclude_extended; /* Settings */ @@ -2345,7 +2393,7 @@ struct SecurityGroup { #define HM_IPV4 2 #define HM_IPV6 3 -#define SETTER_NICK 0 +#define SETTER_NICK 0 #define SETTER_NICK_USER_HOST 1 /* @@ -2353,24 +2401,24 @@ struct SecurityGroup { */ typedef struct IRCStatistics IRCStatistics; struct IRCStatistics { - unsigned int is_cl; /* number of client connections */ - unsigned int is_sv; /* number of server connections */ - unsigned int is_ni; /* connection but no idea who it was */ - time_t is_cti; /* time spent connected by clients */ - time_t is_sti; /* time spent connected by servers */ - unsigned int is_ac; /* connections accepted */ - unsigned int is_ref; /* accepts refused */ - unsigned int is_unco; /* unknown commands */ - unsigned int is_wrdi; /* command going in wrong direction */ - unsigned int is_unpf; /* unknown prefix */ - unsigned int is_empt; /* empty message */ - unsigned int is_num; /* numeric message */ - unsigned int is_kill; /* number of kills generated on collisions */ - unsigned int is_fake; /* MODE 'fakes' */ - unsigned int is_asuc; /* successful auth requests */ - unsigned int is_abad; /* bad auth requests */ - unsigned int is_udp; /* packets recv'd on udp port */ - unsigned int is_loc; /* local connections made */ + unsigned int is_cl; /* number of client connections */ + unsigned int is_sv; /* number of server connections */ + unsigned int is_ni; /* connection but no idea who it was */ + time_t is_cti; /* time spent connected by clients */ + time_t is_sti; /* time spent connected by servers */ + unsigned int is_ac; /* connections accepted */ + unsigned int is_ref; /* accepts refused */ + unsigned int is_unco; /* unknown commands */ + unsigned int is_wrdi; /* command going in wrong direction */ + unsigned int is_unpf; /* unknown prefix */ + unsigned int is_empt; /* empty message */ + unsigned int is_num; /* numeric message */ + unsigned int is_kill; /* number of kills generated on collisions */ + unsigned int is_fake; /* MODE 'fakes' */ + unsigned int is_asuc; /* successful auth requests */ + unsigned int is_abad; /* bad auth requests */ + unsigned int is_udp; /* packets recv'd on udp port */ + unsigned int is_loc; /* local connections made */ }; #define EXTCMODETABLESZ 32 @@ -2386,29 +2434,29 @@ struct IRCStatistics { * Otherwise, see the extended channel modes API, CmodeAdd(), etc. */ struct Mode { - Cmode_t mode; /**< Other ("extended") channel modes set on this channel */ - void *mode_params[MAXPARAMMODES+1]; /**< Parameters for extended channel modes */ + Cmode_t mode; /**< Other ("extended") channel modes set on this channel */ + void *mode_params[MAXPARAMMODES + 1]; /**< Parameters for extended channel modes */ }; /* flags for Link if used to contain Watch --k4be */ /* WATCH type */ -#define WATCH_FLAG_TYPE_WATCH (1<<0) /* added via /WATCH command */ -#define WATCH_FLAG_TYPE_MONITOR (1<<1) /* added via /MONITOR command */ +#define WATCH_FLAG_TYPE_WATCH (1 << 0) /* added via /WATCH command */ +#define WATCH_FLAG_TYPE_MONITOR (1 << 1) /* added via /MONITOR command */ /* behaviour switches */ -#define WATCH_FLAG_AWAYNOTIFY (1<<8) /* should send AWAY notifications */ +#define WATCH_FLAG_AWAYNOTIFY (1 << 8) /* should send AWAY notifications */ /* watch triggering events */ -#define WATCH_EVENT_ONLINE 0 -#define WATCH_EVENT_OFFLINE 1 -#define WATCH_EVENT_AWAY 2 -#define WATCH_EVENT_NOTAWAY 3 -#define WATCH_EVENT_REAWAY 4 -#define WATCH_EVENT_USERHOST 5 -#define WATCH_EVENT_REALNAME 6 -#define WATCH_EVENT_LOGGEDIN 7 -#define WATCH_EVENT_LOGGEDOUT 8 +#define WATCH_EVENT_ONLINE 0 +#define WATCH_EVENT_OFFLINE 1 +#define WATCH_EVENT_AWAY 2 +#define WATCH_EVENT_NOTAWAY 3 +#define WATCH_EVENT_REAWAY 4 +#define WATCH_EVENT_USERHOST 5 +#define WATCH_EVENT_REALNAME 6 +#define WATCH_EVENT_LOGGEDIN 7 +#define WATCH_EVENT_LOGGEDOUT 8 /* Used for notify-hash buckets... -Donwulff */ @@ -2437,7 +2485,7 @@ struct Link { } value; }; -#define IsInvalidChannelTS(x) ((x) <= 1000000) /**< Invalid channel creation time */ +#define IsInvalidChannelTS(x) ((x) <= 1000000) /**< Invalid channel creation time */ /** * @addtogroup CommonStructs @@ -2446,41 +2494,40 @@ struct Link { /** A channel on IRC */ struct Channel { - struct Channel *nextch; /**< Next channel in linked list (channel) */ - struct Channel *prevch; /**< Previous channel in linked list (channel) */ - struct Channel *hnextch; /**< Next channel in hash table */ - Mode mode; /**< Channel Mode set on this channel */ - time_t creationtime; /**< When the channel was first created */ - char *topic; /**< Channel TOPIC */ - char *topic_nick; /**< Person (or server) who set the TOPIC */ - time_t topic_time; /**< Time at which the topic was last set */ - int users; /**< Number of users in the channel */ - Member *members; /**< List of channel members (users in the channel) */ - LocalMember *local_members; /**< List of channel members (users in the channel) */ - Ban *banlist; /**< List of bans (+b) */ - Ban *exlist; /**< List of ban exceptions (+e) */ - Ban *invexlist; /**< List of invite exceptions (+I) */ - char *mode_lock; /**< Mode lock (MLOCK) applied to channel - usually by Services */ - ModData moddata[MODDATA_MAX_CHANNEL]; /**< Channel attached module data, used by the ModData system */ - char name[CHANNELLEN+1]; /**< Channel name */ + struct Channel *nextch; /**< Next channel in linked list (channel) */ + struct Channel *prevch; /**< Previous channel in linked list (channel) */ + struct Channel *hnextch; /**< Next channel in hash table */ + Mode mode; /**< Channel Mode set on this channel */ + time_t creationtime; /**< When the channel was first created */ + char *topic; /**< Channel TOPIC */ + char *topic_nick; /**< Person (or server) who set the TOPIC */ + time_t topic_time; /**< Time at which the topic was last set */ + int users; /**< Number of users in the channel */ + Member *members; /**< List of channel members (users in the channel) */ + LocalMember *local_members; /**< List of channel members (users in the channel) */ + Ban *banlist; /**< List of bans (+b) */ + Ban *exlist; /**< List of ban exceptions (+e) */ + Ban *invexlist; /**< List of invite exceptions (+I) */ + char *mode_lock; /**< Mode lock (MLOCK) applied to channel - usually by Services */ + ModData moddata[MODDATA_MAX_CHANNEL]; /**< Channel attached module data, used by the ModData system */ + char name[CHANNELLEN + 1]; /**< Channel name */ }; -#define MEMB_FLAG_INVISIBLE 0x1 +#define MEMB_FLAG_INVISIBLE 0x1 /** user/channel member struct (channel->members). * This is Member which is used in the linked list channel->members for each channel. * There is also Membership which is used in client->user->channels (see Membership for that). * Both must be kept synchronized 100% at all times. */ -struct Member -{ - struct Member *prev, *next; /**< Previous and next entry in list */ - Client *client; /**< The client */ - char member_modes[MEMBERMODESLEN]; /**< The access of the user on this channel (eg "vhoqa") */ - Membership *related; /**< The related Membership item */ +struct Member { + struct Member *prev, *next; /**< Previous and next entry in list */ + Client *client; /**< The client */ + char member_modes[MEMBERMODESLEN]; /**< The access of the user on this channel (eg "vhoqa") */ + Membership *related; /**< The related Membership item */ LocalMember *local_member; - ModData moddata[MODDATA_MAX_MEMBER]; /**< Member attached module data, used by the ModData system */ - int memb_flags; /**< Special member flags (currently only MEMB_FLAG_INVISIBLE) */ + ModData moddata[MODDATA_MAX_MEMBER]; /**< Member attached module data, used by the ModData system */ + int memb_flags; /**< Special member flags (currently only MEMB_FLAG_INVISIBLE) */ }; /** user/channel membership struct (client->user->channels). @@ -2488,22 +2535,20 @@ struct Member * There is also Member which is used in channel->members (see Member for that). * Both must be kept synchronized 100% at all times. */ -struct Membership -{ - struct Membership *prev, *next; /**< Previous and next entry in list */ - struct Channel *channel; /**< The channel */ - char member_modes[MEMBERMODESLEN]; /**< The (new) access of the user on this channel (eg "vhoqa") */ - Member *related; /**< The related Member item */ - ModData moddata[MODDATA_MAX_MEMBERSHIP]; /**< Membership attached module data, used by the ModData system */ - int memb_flags; /**< Special member flags (currently only MEMB_FLAG_INVISIBLE) */ +struct Membership { + struct Membership *prev, *next; /**< Previous and next entry in list */ + struct Channel *channel; /**< The channel */ + char member_modes[MEMBERMODESLEN]; /**< The (new) access of the user on this channel (eg "vhoqa") */ + Member *related; /**< The related Member item */ + ModData moddata[MODDATA_MAX_MEMBERSHIP]; /**< Membership attached module data, used by the ModData system */ + int memb_flags; /**< Special member flags (currently only MEMB_FLAG_INVISIBLE) */ }; /** This is used for channel->local_members. * We use these local members for fast local sending, * and channel->members everywhere else. */ -struct LocalMember -{ +struct LocalMember { struct LocalMember *prev, *next; Member *ptr; }; @@ -2512,57 +2557,59 @@ struct LocalMember /** A ban, exempt or invite exception entry */ struct Ban { - struct Ban *next; /**< Next entry in list */ - char *banstr; /**< The string (eg: *!*@*.example.org) */ - char *who; /**< Person or server who set the entry (eg: Nick) */ - time_t when; /**< When the entry was added */ + struct Ban *next; /**< Next entry in list */ + char *banstr; /**< The string (eg: *!*@*.example.org) */ + char *who; /**< Person or server who set the entry (eg: Nick) */ + time_t when; /**< When the entry was added */ }; /* Channel macros */ -#define MODE_EXCEPT 0x0200 -#define MODE_BAN 0x0400 -#define MODE_INVEX 0x8000000 +#define MODE_EXCEPT 0x0200 +#define MODE_BAN 0x0400 +#define MODE_INVEX 0x8000000 /* name invisible */ -#define SecretChannel(x) ((x) && has_channel_mode((x), 's')) +#define SecretChannel(x) ((x) && has_channel_mode((x), 's')) /* channel not shown but names are */ -#define HiddenChannel(x) ((x) && has_channel_mode((x), 'p')) +#define HiddenChannel(x) ((x) && has_channel_mode((x), 'p')) /* channel visible */ -#define ShowChannel(v,c) (PubChannel(c) || IsMember((v),(c))) -#define PubChannel(x) (!SecretChannel((x)) && !HiddenChannel((x))) +#define ShowChannel(v, c) (PubChannel(c) || IsMember((v), (c))) +#define PubChannel(x) (!SecretChannel((x)) && !HiddenChannel((x))) -#define IsChannelName(name) ((name) && (*(name) == '#')) +#define IsChannelName(name) ((name) && (*(name) == '#')) -#define IsMember(blah,chan) ((blah && blah->user && \ - find_membership_link((blah->user)->channel, chan)) ? 1 : 0) +#define IsMember(blah, chan) ((blah && blah->user && \ + find_membership_link((blah->user)->channel, chan)) \ + ? 1 \ + : 0) /* Misc macros */ -#define BadPtr(x) (!(x) || (*(x) == '\0')) +#define BadPtr(x) (!(x) || (*(x) == '\0')) /** Is valid character in nick? [not for external usage, use do_check_nickname instead!] */ -#define isvalid(c) (char_atribs[(u_char)(c)]&ALLOWN) +#define isvalid(c) (char_atribs[(u_char)(c)] & ALLOWN) #define TStime() (timeofday) /* used in SetMode() in channel.c and cmd_umode() in s_msg.c */ -#define MODE_NULL 0 -#define MODE_ADD 0x40000000 -#define MODE_DEL 0x20000000 +#define MODE_NULL 0 +#define MODE_ADD 0x40000000 +#define MODE_DEL 0x20000000 /* return values for hunt_server() */ -#define HUNTED_NOSUCH (-1) /* if the hunted server is not found */ -#define HUNTED_ISME 0 /* if this server should execute the command */ -#define HUNTED_PASS 1 /* if message passed onwards successfully */ +#define HUNTED_NOSUCH (-1) /* if the hunted server is not found */ +#define HUNTED_ISME 0 /* if this server should execute the command */ +#define HUNTED_PASS 1 /* if message passed onwards successfully */ /* used when sending to #mask or $mask */ -#define MATCH_SERVER 1 -#define MATCH_HOST 2 +#define MATCH_SERVER 1 +#define MATCH_HOST 2 /* misc variable externs */ @@ -2571,7 +2618,7 @@ extern MODVAR char *generation, *creation; extern MODVAR char *gnulicense[]; /* misc defines */ -#define COMMA "," +#define COMMA "," #define isexcept void @@ -2579,19 +2626,19 @@ extern MODVAR SSL_CTX *ctx; extern MODVAR SSL_CTX *ctx_server; extern MODVAR SSL_CTX *ctx_client; -#define TLS_PROTOCOL_TLSV1 0x0001 -#define TLS_PROTOCOL_TLSV1_1 0x0002 -#define TLS_PROTOCOL_TLSV1_2 0x0004 -#define TLS_PROTOCOL_TLSV1_3 0x0008 +#define TLS_PROTOCOL_TLSV1 0x0001 +#define TLS_PROTOCOL_TLSV1_1 0x0002 +#define TLS_PROTOCOL_TLSV1_2 0x0004 +#define TLS_PROTOCOL_TLSV1_3 0x0008 -#define TLS_PROTOCOL_ALL 0xffff +#define TLS_PROTOCOL_ALL 0xffff typedef struct CoreChannelModeTable CoreChannelModeTable; struct CoreChannelModeTable { - long mode; /**< Mode value (which bit will be set) */ - char flag; /**< Mode letter (eg: 't') */ - unsigned halfop : 1; /**< May halfop set this mode? 1/0 */ - unsigned parameters : 1; /**< Mode requires a parameter? 1/0 */ + long mode; /**< Mode value (which bit will be set) */ + char flag; /**< Mode letter (eg: 't') */ + unsigned halfop : 1; /**< May halfop set this mode? 1/0 */ + unsigned parameters : 1; /**< Mode requires a parameter? 1/0 */ }; /** Parse channel mode */ @@ -2603,28 +2650,28 @@ struct ParseMode { Cmode *extm; const char *modebuf; /* curr pos */ const char *parabuf; /* curr pos */ - char buf[512]; /* internal parse buffer */ + char buf[512]; /* internal parse buffer */ }; -#define MAXMULTILINEMODES 3 +#define MAXMULTILINEMODES 3 typedef struct MultiLineMode MultiLineMode; struct MultiLineMode { - char *modeline[MAXMULTILINEMODES+1]; - char *paramline[MAXMULTILINEMODES+1]; + char *modeline[MAXMULTILINEMODES + 1]; + char *paramline[MAXMULTILINEMODES + 1]; int numlines; }; typedef struct PendingServer PendingServer; struct PendingServer { PendingServer *prev, *next; - char sid[IDLEN+1]; + char sid[IDLEN + 1]; }; typedef struct PendingNet PendingNet; struct PendingNet { PendingNet *prev, *next; /* Previous and next in list */ - Client *client; /**< Client to which these servers belong */ - PendingServer *servers; /**< The list of servers connected to the client */ + Client *client; /**< Client to which these servers belong */ + PendingServer *servers; /**< The list of servers connected to the client */ }; typedef struct MaxTarget MaxTarget; @@ -2633,52 +2680,67 @@ struct MaxTarget { char *cmd; int limit; }; -#define MAXTARGETS_MAX 1000000 /* used for 'max' */ +#define MAXTARGETS_MAX 1000000 /* used for 'max' */ -#define VERIFY_OPERCOUNT(clnt,tag) { if (irccounts.operators < 0) verify_opercount(clnt,tag); } while(0) +#define VERIFY_OPERCOUNT(clnt, tag) \ + { \ + if (irccounts.operators < 0) \ + verify_opercount(clnt, tag); \ + } \ + while (0) -#define MARK_AS_OFFICIAL_MODULE(modinf) do { if (modinf && modinf->handle) ModuleSetOptions(modinfo->handle, MOD_OPT_OFFICIAL, 1); } while(0) -#define MARK_AS_GLOBAL_MODULE(modinf) do { if (modinf && modinf->handle) ModuleSetOptions(modinfo->handle, MOD_OPT_GLOBAL, 1); } while(0) +#define MARK_AS_OFFICIAL_MODULE(modinf) \ + do \ + { \ + if (modinf && modinf->handle) \ + ModuleSetOptions(modinfo->handle, MOD_OPT_OFFICIAL, 1); \ + } while (0) +#define MARK_AS_GLOBAL_MODULE(modinf) \ + do \ + { \ + if (modinf && modinf->handle) \ + ModuleSetOptions(modinfo->handle, MOD_OPT_GLOBAL, 1); \ + } while (0) /* used for is_banned type field: */ -#define BANCHK_JOIN 0x0001 /* checking if a ban forbids the person from joining */ -#define BANCHK_MSG 0x0002 /* checking if a ban forbids the person from sending messages */ -#define BANCHK_NICK 0x0004 /* checking if a ban forbids the person from changing his/her nick */ -#define BANCHK_LEAVE_MSG 0x0008 /* checking if a ban forbids the person from leaving a message in PART or QUIT */ -#define BANCHK_TKL 0x0010 /* called from a server ban routine, or other match_user() usage */ -#define BANCHK_ALL (BANCHK_JOIN|BANCHK_MSG|BANCHK_NICK|BANCHK_LEAVE_MSG) /* all events except BANCHK_TKL which is special */ +#define BANCHK_JOIN 0x0001 /* checking if a ban forbids the person from joining */ +#define BANCHK_MSG 0x0002 /* checking if a ban forbids the person from sending messages */ +#define BANCHK_NICK 0x0004 /* checking if a ban forbids the person from changing his/her nick */ +#define BANCHK_LEAVE_MSG 0x0008 /* checking if a ban forbids the person from leaving a message in PART or QUIT */ +#define BANCHK_TKL 0x0010 /* called from a server ban routine, or other match_user() usage */ +#define BANCHK_ALL (BANCHK_JOIN | BANCHK_MSG | BANCHK_NICK | BANCHK_LEAVE_MSG) /* all events except BANCHK_TKL which is special */ -#define TKLISTLEN 26 -#define TKLIPHASHLEN1 4 -#define TKLIPHASHLEN2 1021 +#define TKLISTLEN 26 +#define TKLIPHASHLEN1 4 +#define TKLIPHASHLEN2 1021 -#define MATCH_CHECK_IP 0x0001 -#define MATCH_CHECK_REAL_HOST 0x0002 -#define MATCH_CHECK_CLOAKED_HOST 0x0004 -#define MATCH_CHECK_VISIBLE_HOST 0x0008 -#define MATCH_CHECK_EXTENDED 0x0010 +#define MATCH_CHECK_IP 0x0001 +#define MATCH_CHECK_REAL_HOST 0x0002 +#define MATCH_CHECK_CLOAKED_HOST 0x0004 +#define MATCH_CHECK_VISIBLE_HOST 0x0008 +#define MATCH_CHECK_EXTENDED 0x0010 -#define MATCH_CHECK_ALL (MATCH_CHECK_IP|MATCH_CHECK_REAL_HOST|MATCH_CHECK_CLOAKED_HOST|MATCH_CHECK_VISIBLE_HOST|MATCH_CHECK_EXTENDED) -#define MATCH_CHECK_REAL (MATCH_CHECK_IP|MATCH_CHECK_REAL_HOST|MATCH_CHECK_EXTENDED) +#define MATCH_CHECK_ALL (MATCH_CHECK_IP | MATCH_CHECK_REAL_HOST | MATCH_CHECK_CLOAKED_HOST | MATCH_CHECK_VISIBLE_HOST | MATCH_CHECK_EXTENDED) +#define MATCH_CHECK_REAL (MATCH_CHECK_IP | MATCH_CHECK_REAL_HOST | MATCH_CHECK_EXTENDED) -#define MATCH_MASK_IS_UHOST 0x1000 -#define MATCH_MASK_IS_HOST 0x2000 +#define MATCH_MASK_IS_UHOST 0x1000 +#define MATCH_MASK_IS_HOST 0x2000 typedef enum { - POLICY_ALLOW=1, - POLICY_WARN=2, - POLICY_DENY=3 + POLICY_ALLOW = 1, + POLICY_WARN = 2, + POLICY_DENY = 3 } Policy; -#define NO_EXIT_CLIENT 99 +#define NO_EXIT_CLIENT 99 /*-- badwords --*/ -#define MAX_MATCH 1 -#define MAX_WORDLEN 64 +#define MAX_MATCH 1 +#define MAX_WORDLEN 64 -#define PATTERN "\\w*%s\\w*" -#define REPLACEWORD "" +#define PATTERN "\\w*%s\\w*" +#define REPLACEWORD "" #define BADW_TYPE_INVALID 0x0 #define BADW_TYPE_FAST 0x1 @@ -2687,31 +2749,31 @@ typedef enum { #define BADW_TYPE_REGEX 0x8 #define BADWORD_REPLACE 1 -#define BADWORD_BLOCK 2 +#define BADWORD_BLOCK 2 typedef struct ConfigItem_badword ConfigItem_badword; struct ConfigItem_badword { - ConfigItem_badword *prev, *next; - ConfigFlag flag; - char *word, *replace; - unsigned short type; - char action; - pcre2_code *pcre2_expr; + ConfigItem_badword *prev, *next; + ConfigFlag flag; + char *word, *replace; + unsigned short type; + char action; + pcre2_code *pcre2_expr; }; /*-- end of badwords --*/ /* Flags for 'sendflags' in 'sendto_channel' */ -#define SEND_LOCAL 0x1 -#define SEND_REMOTE 0x2 -#define SEND_ALL (SEND_LOCAL|SEND_REMOTE) -#define SKIP_DEAF 0x4 -#define SKIP_CTCP 0x8 -#define CHECK_INVISIBLE 0x10 +#define SEND_LOCAL 0x1 +#define SEND_REMOTE 0x2 +#define SEND_ALL (SEND_LOCAL | SEND_REMOTE) +#define SKIP_DEAF 0x4 +#define SKIP_CTCP 0x8 +#define CHECK_INVISIBLE 0x10 /* Flags for 'flags' in 'can_send_to_user' (and future: can_send_to_channel) */ -#define CAN_SEND_SKIP_SPAMFILTER 0x1 +#define CAN_SEND_SKIP_SPAMFILTER 0x1 typedef struct GeoIPResult GeoIPResult; struct GeoIPResult { @@ -2722,15 +2784,15 @@ struct GeoIPResult { }; typedef enum WhoisConfigDetails { - WHOIS_CONFIG_DETAILS_DEFAULT = 0, - WHOIS_CONFIG_DETAILS_NONE = 1, - WHOIS_CONFIG_DETAILS_LIMITED = 2, - WHOIS_CONFIG_DETAILS_FULL = 3, + WHOIS_CONFIG_DETAILS_DEFAULT = 0, + WHOIS_CONFIG_DETAILS_NONE = 1, + WHOIS_CONFIG_DETAILS_LIMITED = 2, + WHOIS_CONFIG_DETAILS_FULL = 3, } WhoisConfigDetails; /* Options for StripControlCodesEx() */ -#define UNRL_STRIP_LOW_ASCII 0x1 /**< Strip all ASCII < 32 (control codes) */ -#define UNRL_STRIP_KEEP_LF 0x2 /**< Do not strip LF (line feed, \n) */ +#define UNRL_STRIP_LOW_ASCII 0x1 /**< Strip all ASCII < 32 (control codes) */ +#define UNRL_STRIP_KEEP_LF 0x2 /**< Do not strip LF (line feed, \n) */ /** JSON-RPC API Errors, according to jsonrpc.org spec. * The -327xx range are the official JSON-RPC error codes, @@ -2738,64 +2800,70 @@ typedef enum WhoisConfigDetails { * and -1000 and below are UnrealIRCd specific application error codes. */ typedef enum JsonRpcError { - JSON_RPC_ERROR_PARSE_ERROR = -32700, /**< JSON parse error (fatal) */ - JSON_RPC_ERROR_INVALID_REQUEST = -32600, /**< Invalid JSON-RPC Request */ - JSON_RPC_ERROR_METHOD_NOT_FOUND = -32601, /**< Method not found */ - JSON_RPC_ERROR_INVALID_PARAMS = -32602, /**< Method parameters invalid */ - JSON_RPC_ERROR_INTERNAL_ERROR = -32603, /**< Internal server error */ - JSON_RPC_ERROR_API_CALL_DENIED = -32000, /**< The api user does not have enough permissions to do this call */ - JSON_RPC_ERROR_SERVER_GONE = -32001, /**< The request was forwarded to a remote server, but this server went gone while processing the request */ - JSON_RPC_ERROR_TIMEOUT = -32002, /**< The request was forwarded to a remote server, but the request/response timed out (15 seconds) */ - JSON_RPC_ERROR_REMOTE_SERVER_NO_RPC = -32003, /**< The request was going to be forwarded to a remote server, but the remote server does not support JSON-RPC */ - JSON_RPC_ERROR_NOT_FOUND = -1000, /**< Target not found (no such nick / channel / ..) */ - JSON_RPC_ERROR_ALREADY_EXISTS = -1001, /**< Resource already exists by that name (eg on nickchange request, a gline, etc) */ - JSON_RPC_ERROR_INVALID_NAME = -1002, /**< Name is not permitted (eg: nick, channel, ..) */ - JSON_RPC_ERROR_USERNOTINCHANNEL = -1003, /**< The user is not in the channel */ - JSON_RPC_ERROR_TOO_MANY_ENTRIES = -1004, /**< Too many entries (eg: banlist, ..) */ - JSON_RPC_ERROR_DENIED = -1005, /**< Permission denied for user (unrelated to api user permissions) */ + JSON_RPC_ERROR_PARSE_ERROR = -32700, /**< JSON parse error (fatal) */ + JSON_RPC_ERROR_INVALID_REQUEST = -32600, /**< Invalid JSON-RPC Request */ + JSON_RPC_ERROR_METHOD_NOT_FOUND = -32601, /**< Method not found */ + JSON_RPC_ERROR_INVALID_PARAMS = -32602, /**< Method parameters invalid */ + JSON_RPC_ERROR_INTERNAL_ERROR = -32603, /**< Internal server error */ + JSON_RPC_ERROR_API_CALL_DENIED = -32000, /**< The api user does not have enough permissions to do this call */ + JSON_RPC_ERROR_SERVER_GONE = -32001, /**< The request was forwarded to a remote server, but this server went gone while processing the request */ + JSON_RPC_ERROR_TIMEOUT = -32002, /**< The request was forwarded to a remote server, but the request/response timed out (15 seconds) */ + JSON_RPC_ERROR_REMOTE_SERVER_NO_RPC = -32003, /**< The request was going to be forwarded to a remote server, but the remote server does not support JSON-RPC */ + JSON_RPC_ERROR_NOT_FOUND = -1000, /**< Target not found (no such nick / channel / ..) */ + JSON_RPC_ERROR_ALREADY_EXISTS = -1001, /**< Resource already exists by that name (eg on nickchange request, a gline, etc) */ + JSON_RPC_ERROR_INVALID_NAME = -1002, /**< Name is not permitted (eg: nick, channel, ..) */ + JSON_RPC_ERROR_USERNOTINCHANNEL = -1003, /**< The user is not in the channel */ + JSON_RPC_ERROR_TOO_MANY_ENTRIES = -1004, /**< Too many entries (eg: banlist, ..) */ + JSON_RPC_ERROR_DENIED = -1005, /**< Permission denied for user (unrelated to api user permissions) */ } JsonRpcError; /** Require a parameter in an RPC command */ -#define REQUIRE_PARAM_STRING(name, varname) do { \ - varname = json_object_get_string(params, name); \ - if (!varname) \ - { \ - rpc_error_fmt(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: '%s'", name); \ - return; \ - } \ - } while(0) +#define REQUIRE_PARAM_STRING(name, varname) \ + do \ + { \ + varname = json_object_get_string(params, name); \ + if (!varname) \ + { \ + rpc_error_fmt(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: '%s'", name); \ + return; \ + } \ + } while (0) -#define REQUIRE_PARAM_INTEGER(name, varname) do { \ - json_t *t = json_object_get(params, name); \ - if (!t || !json_is_integer(t)) \ - { \ - rpc_error_fmt(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: '%s'", name); \ - return; \ - } \ - varname = json_integer_value(t); \ - } while(0) +#define REQUIRE_PARAM_INTEGER(name, varname) \ + do \ + { \ + json_t *t = json_object_get(params, name); \ + if (!t || !json_is_integer(t)) \ + { \ + rpc_error_fmt(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: '%s'", name); \ + return; \ + } \ + varname = json_integer_value(t); \ + } while (0) -#define REQUIRE_PARAM_BOOLEAN(name, varname) do { \ - json_t *v = json_object_get(params, name); \ - if (!v || !json_is_boolean(v)) \ - { \ - rpc_error_fmt(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: '%s'", name); \ - return; \ - } \ - varname = json_is_true(v) ? 1 : 0; \ - } while(0) +#define REQUIRE_PARAM_BOOLEAN(name, varname) \ + do \ + { \ + json_t *v = json_object_get(params, name); \ + if (!v || !json_is_boolean(v)) \ + { \ + rpc_error_fmt(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: '%s'", name); \ + return; \ + } \ + varname = json_is_true(v) ? 1 : 0; \ + } while (0) -#define OPTIONAL_PARAM_STRING(name, varname) varname = json_object_get_string(params, name) -#define OPTIONAL_PARAM_INTEGER(name, varname, def) varname = json_object_get_integer(params, name, def) -#define OPTIONAL_PARAM_BOOLEAN(name, varname, def) varname = json_object_get_boolean(params, name, def) +#define OPTIONAL_PARAM_STRING(name, varname) varname = json_object_get_string(params, name) +#define OPTIONAL_PARAM_INTEGER(name, varname, def) varname = json_object_get_integer(params, name, def) +#define OPTIONAL_PARAM_BOOLEAN(name, varname, def) varname = json_object_get_boolean(params, name, def) /** Valid character for variable names in logging engine buildlogstring and also in buildvarstring* */ -#define validvarcharacter(x) (isalnum((x)) || ((x) == '_')) +#define validvarcharacter(x) (isalnum((x)) || ((x) == '_')) -#define BUILDVARSTRING_URLENCODE 0x1 -#define BUILDVARSTRING_XML 0x2 -#define BUILDVARSTRING_UNKNOWN_VAR_IS_EMPTY 0x4 -#define BUILDVARSTRING_KEEP_SPACE_FOR_EMPTY_VAR 0x8 +#define BUILDVARSTRING_URLENCODE 0x1 +#define BUILDVARSTRING_XML 0x2 +#define BUILDVARSTRING_UNKNOWN_VAR_IS_EMPTY 0x4 +#define BUILDVARSTRING_KEEP_SPACE_FOR_EMPTY_VAR 0x8 #include "dynconf.h" diff --git a/include/sys.h b/include/sys.h index e7c8e71dd..1775652a6 100644 --- a/include/sys.h +++ b/include/sys.h @@ -19,51 +19,51 @@ * $Id$ */ -#ifndef __sys_include__ +#ifndef __sys_include__ #define __sys_include__ /* PATH_MAX */ #include #ifdef ISC202 -#include + #include #else -#include + #include #endif #include "setup.h" #include #include #ifndef _WIN32 -#include + #include #else -#include -#include + #include + #include #endif #include #ifndef _WIN32 -#include -#include -#include + #include + #include + #include #endif /* get intptr_t if the system provides it -- otherwise, ./configure will define it for us */ #ifdef HAVE_STDINT_H -#include + #include #else -#ifdef HAVE_INTTYPES_H -#include -#endif /* HAVE_INTTYPES_H */ -#endif /* HAVE_STDINT_H */ + #ifdef HAVE_INTTYPES_H + #include + #endif /* HAVE_INTTYPES_H */ +#endif /* HAVE_STDINT_H */ #ifndef _WIN32 -#include -#include -#include -#include + #include + #include + #include + #include #else -#include -#include -#include + #include + #include + #include #endif #ifdef HAVE_TCP_INFO @@ -71,39 +71,39 @@ #endif #ifndef _WIN32 -#include + #include #endif #include #ifndef _WIN32 -#include -#ifndef WEXITSTATUS -#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) -#endif -#ifndef WIFEXITED -#define WIFEXITED(stat_val) (((stat_val) & 255) == 0) -#endif + #include + #ifndef WEXITSTATUS + #define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) + #endif + #ifndef WIFEXITED + #define WIFEXITED(stat_val) (((stat_val) & 255) == 0) + #endif #endif /* * Different name on NetBSD, FreeBSD, and BSDI */ #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__bsdi__) || defined(__linux__) || defined(__APPLE__) -#define dn_skipname __dn_skipname + #define dn_skipname __dn_skipname #endif /* * Mac OS X Tiger Support (Intel Only) */ #if defined(macosx) || defined(__APPLE__) -#define OSXTIGER + #define OSXTIGER #endif #ifndef _WIN32 extern void dummy(); #endif -#ifdef NO_U_TYPES +#ifdef NO_U_TYPES typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned long u_long; @@ -111,12 +111,12 @@ typedef unsigned int u_int; #endif #ifdef _WIN32 -#define MYOSNAME OSName + #define MYOSNAME OSName extern char OSName[256]; -#define PATH_MAX MAX_PATH -#define getpid _getpid + #define PATH_MAX MAX_PATH + #define getpid _getpid #else -#define MYOSNAME getosname() + #define MYOSNAME getosname() #endif #define MYDUMMY_SIZE 128 @@ -125,74 +125,74 @@ extern char OSName[256]; * Socket, File, and Error portability macros */ #ifndef _WIN32 -#define SET_ERRNO(x) errno = x -#define READ_SOCK(fd, buf, len) read((fd), (buf), (len)) -#define WRITE_SOCK(fd, buf, len) write((fd), (buf), (len)) -#define CLOSE_SOCK(fd) close(fd) -#define IOCTL(x, y, z) ioctl((x), (y), (z)) -#define ERRNO errno -#define STRERROR(x) strerror(x) + #define SET_ERRNO(x) errno = x + #define READ_SOCK(fd, buf, len) read((fd), (buf), (len)) + #define WRITE_SOCK(fd, buf, len) write((fd), (buf), (len)) + #define CLOSE_SOCK(fd) close(fd) + #define IOCTL(x, y, z) ioctl((x), (y), (z)) + #define ERRNO errno + #define STRERROR(x) strerror(x) -/* error constant portability */ -#define P_EMFILE EMFILE -#define P_ENOBUFS ENOBUFS -#define P_EWOULDBLOCK EWOULDBLOCK -#define P_EAGAIN EAGAIN -#define P_EINPROGRESS EINPROGRESS -#define P_EWORKING EINPROGRESS -#define P_EINTR EINTR -#define P_ETIMEDOUT ETIMEDOUT -#define P_ENOTSOCK ENOTSOCK -#define P_EIO EIO -#define P_ECONNABORTED ECONNABORTED -#define P_ECONNRESET ECONNRESET -#define P_ENOTCONN ENOTCONN -#define P_EMSGSIZE EMSGSIZE + /* error constant portability */ + #define P_EMFILE EMFILE + #define P_ENOBUFS ENOBUFS + #define P_EWOULDBLOCK EWOULDBLOCK + #define P_EAGAIN EAGAIN + #define P_EINPROGRESS EINPROGRESS + #define P_EWORKING EINPROGRESS + #define P_EINTR EINTR + #define P_ETIMEDOUT ETIMEDOUT + #define P_ENOTSOCK ENOTSOCK + #define P_EIO EIO + #define P_ECONNABORTED ECONNABORTED + #define P_ECONNRESET ECONNRESET + #define P_ENOTCONN ENOTCONN + #define P_EMSGSIZE EMSGSIZE #else -/* WIN32 */ + /* WIN32 */ -#define NETDB_INTERNAL -1 /* see errno */ -#define NETDB_SUCCESS 0 /* no problem */ + #define NETDB_INTERNAL -1 /* see errno */ + #define NETDB_SUCCESS 0 /* no problem */ -/* IO and Error portability macros */ -#define READ_SOCK(fd, buf, len) recv((fd), (buf), (len), 0) -#define WRITE_SOCK(fd, buf, len) send((fd), (buf), (len), 0) -#define CLOSE_SOCK(fd) closesocket(fd) -#define IOCTL(x, y, z) ioctlsocket((x), (y), (z)) -#define ERRNO WSAGetLastError() -#define STRERROR(x) sock_strerror(x) -#define SET_ERRNO(x) WSASetLastError(x) -/* Error constant portability */ -#define P_EMFILE WSAEMFILE -#define P_ENOBUFS WSAENOBUFS -#define P_EWOULDBLOCK WSAEWOULDBLOCK -#define P_EAGAIN WSAEWOULDBLOCK -#define P_EINPROGRESS WSAEINPROGRESS -#define P_EWORKING WSAEWOULDBLOCK -#define P_EINTR WSAEINTR -#define P_ETIMEDOUT WSAETIMEDOUT -#define P_ENOTSOCK WSAENOTSOCK -#define P_EIO EIO -#define P_ECONNABORTED WSAECONNABORTED -#define P_ECONNRESET WSAECONNRESET -#define P_ENOTCONN WSAENOTCONN -#define P_EMSGSIZE WSAEMSGSIZE + /* IO and Error portability macros */ + #define READ_SOCK(fd, buf, len) recv((fd), (buf), (len), 0) + #define WRITE_SOCK(fd, buf, len) send((fd), (buf), (len), 0) + #define CLOSE_SOCK(fd) closesocket(fd) + #define IOCTL(x, y, z) ioctlsocket((x), (y), (z)) + #define ERRNO WSAGetLastError() + #define STRERROR(x) sock_strerror(x) + #define SET_ERRNO(x) WSASetLastError(x) + /* Error constant portability */ + #define P_EMFILE WSAEMFILE + #define P_ENOBUFS WSAENOBUFS + #define P_EWOULDBLOCK WSAEWOULDBLOCK + #define P_EAGAIN WSAEWOULDBLOCK + #define P_EINPROGRESS WSAEINPROGRESS + #define P_EWORKING WSAEWOULDBLOCK + #define P_EINTR WSAEINTR + #define P_ETIMEDOUT WSAETIMEDOUT + #define P_ENOTSOCK WSAENOTSOCK + #define P_EIO EIO + #define P_ECONNABORTED WSAECONNABORTED + #define P_ECONNRESET WSAECONNRESET + #define P_ENOTCONN WSAENOTCONN + #define P_EMSGSIZE WSAEMSGSIZE #endif #ifndef __GNUC__ -#define __attribute__(x) /* nothing */ + #define __attribute__(x) /* nothing */ #endif #undef FORMAT_STRING #if _MSC_VER >= 1400 -# include -# if _MSC_VER > 1400 -# define FORMAT_STRING(p) _Printf_format_string_ p -# else -# define FORMAT_STRING(p) __format_string p -# endif /* FORMAT_STRING */ + #include + #if _MSC_VER > 1400 + #define FORMAT_STRING(p) _Printf_format_string_ p + #else + #define FORMAT_STRING(p) __format_string p + #endif /* FORMAT_STRING */ #else -# define FORMAT_STRING(p) p + #define FORMAT_STRING(p) p #endif /* _MSC_VER */ /* A normal abort() on windows causes the crucial stack frame to be missing @@ -200,13 +200,19 @@ extern char OSName[256]; * It's silly but this works: */ #ifdef _WIN32 - #define abort() do { char *crash = NULL; *crash = 'x'; exit(1); } while(0) + #define abort() \ + do \ + { \ + char *crash = NULL; \ + *crash = 'x'; \ + exit(1); \ + } while (0) #endif #ifndef SOMAXCONN -# define LISTEN_SIZE (5) + #define LISTEN_SIZE (5) #else -# define LISTEN_SIZE (SOMAXCONN) + #define LISTEN_SIZE (SOMAXCONN) #endif /* @@ -214,17 +220,17 @@ extern char OSName[256]; * number of files allowed to be open by this process. */ #ifdef RLIMIT_FDMAX -# define RLIMIT_FD_MAX RLIMIT_FDMAX + #define RLIMIT_FD_MAX RLIMIT_FDMAX #else -# ifdef RLIMIT_NOFILE -# define RLIMIT_FD_MAX RLIMIT_NOFILE -# else -# ifdef RLIMIT_OPEN_MAX -# define RLIMIT_FD_MAX RLIMIT_OPEN_MAX -# else -# undef RLIMIT_FD_MAX -# endif -# endif + #ifdef RLIMIT_NOFILE + #define RLIMIT_FD_MAX RLIMIT_NOFILE + #else + #ifdef RLIMIT_OPEN_MAX + #define RLIMIT_FD_MAX RLIMIT_OPEN_MAX + #else + #undef RLIMIT_FD_MAX + #endif + #endif #endif #ifdef NATIVE_BIG_ENDIAN diff --git a/include/types.h b/include/types.h index 1db1e346d..67f9ed0fd 100644 --- a/include/types.h +++ b/include/types.h @@ -20,9 +20,9 @@ #ifndef TYPES_H #define TYPES_H -typedef void (*vFP)(); /* Void function pointer */ -typedef int (*iFP)(); /* Integer function pointer */ -typedef char (*cFP)(); /* char * function pointer */ +typedef void (*vFP)(); /* Void function pointer */ +typedef int (*iFP)(); /* Integer function pointer */ +typedef char (*cFP)(); /* char * function pointer */ #ifndef MODVAR #if defined(MODULE_COMPILE) && defined(_WIN32) diff --git a/include/version.h b/include/version.h index 80f9b31d4..55ff964e2 100644 --- a/include/version.h +++ b/include/version.h @@ -14,24 +14,24 @@ * $ info '(cpp) Stringification' */ #define _macro_to_str(n) #n -#define macro_to_str(n) _macro_to_str(n) +#define macro_to_str(n) _macro_to_str(n) /* * Mark of settings */ #ifdef DEBUGMODE -#define DEBUGMODESET "+(debug)" + #define DEBUGMODESET "+(debug)" #else -#define DEBUGMODESET "" + #define DEBUGMODESET "" #endif - /**/ +/**/ #ifdef DEBUG -#define DEBUGSET "(Debug)" + #define DEBUGSET "(Debug)" #else -#define DEBUGSET "" + #define DEBUGSET "" #endif - /**/ +/**/ #define COMPILEINFO DEBUGMODESET DEBUGSET /* Version info follows @@ -54,20 +54,20 @@ * Can be useful if the above 3 versionids are insufficient for you (eg: you want to support CVS). * This is updated automatically on the CVS server every Monday. so don't touch it. */ -#define UNREAL_VERSION_TIME 202610 +#define UNREAL_VERSION_TIME 202610 -#define UNREAL_VERSION ((UNREAL_VERSION_GENERATION << 24) + (UNREAL_VERSION_MAJOR << 16) + (UNREAL_VERSION_MINOR << 8)) -#define UnrealProtocol 6100 -#define PATCH1 macro_to_str(UNREAL_VERSION_GENERATION) -#define PATCH2 "." macro_to_str(UNREAL_VERSION_MAJOR) -#define PATCH3 "." macro_to_str(UNREAL_VERSION_MINOR) -#define PATCH4 UNREAL_VERSION_SUFFIX -#define PATCH5 "" -#define PATCH6 "" -#define PATCH7 "" -#define PATCH8 COMPILEINFO -#define PATCH9 "" +#define UNREAL_VERSION ((UNREAL_VERSION_GENERATION << 24) + (UNREAL_VERSION_MAJOR << 16) + (UNREAL_VERSION_MINOR << 8)) +#define UnrealProtocol 6100 +#define PATCH1 macro_to_str(UNREAL_VERSION_GENERATION) +#define PATCH2 "." macro_to_str(UNREAL_VERSION_MAJOR) +#define PATCH3 "." macro_to_str(UNREAL_VERSION_MINOR) +#define PATCH4 UNREAL_VERSION_SUFFIX +#define PATCH5 "" +#define PATCH6 "" +#define PATCH7 "" +#define PATCH8 COMPILEINFO +#define PATCH9 "" /* release header */ -#define Rh BASE_VERSION -#define VERSIONONLY PATCH1 PATCH2 PATCH3 PATCH4 PATCH5 PATCH6 PATCH7 +#define Rh BASE_VERSION +#define VERSIONONLY PATCH1 PATCH2 PATCH3 PATCH4 PATCH5 PATCH6 PATCH7 #endif /* __versioninclude */ diff --git a/include/whowas.h b/include/whowas.h index 4f4d330d4..bd3c8e651 100644 --- a/include/whowas.h +++ b/include/whowas.h @@ -32,16 +32,16 @@ * $Id$ */ -#ifndef __whowas_include__ +#ifndef __whowas_include__ #define __whowas_include__ /* NOTE: Don't reorder values of these, as they are used in whowasdb */ typedef enum WhoWasEvent { - WHOWAS_EVENT_QUIT=0, - WHOWAS_EVENT_NICK_CHANGE=1, - WHOWAS_EVENT_SERVER_TERMINATING=2 + WHOWAS_EVENT_QUIT = 0, + WHOWAS_EVENT_NICK_CHANGE = 1, + WHOWAS_EVENT_SERVER_TERMINATING = 2 } WhoWasEvent; -#define WHOWAS_LOWEST_EVENT 0 +#define WHOWAS_LOWEST_EVENT 0 #define WHOWAS_HIGHEST_EVENT 2 /* @@ -69,8 +69,8 @@ void off_history(Client *); ** one found... */ Client *get_history(const char *, time_t); - /* Nick name */ - /* Time limit in seconds */ +/* Nick name */ +/* Time limit in seconds */ /* ** for debugging...counts related structures stored in whowas array. diff --git a/include/windows/setup.h b/include/windows/setup.h index 4dc10aa35..99a22595a 100644 --- a/include/windows/setup.h +++ b/include/windows/setup.h @@ -22,25 +22,25 @@ #ifndef __setup_include__ #define __setup_include__ -#undef SYSSYSLOGH +#undef SYSSYSLOGH #define NOINDEX -#undef TIMES_2 -#undef GETRUSAGE_2 -#define CONFDIR "conf" -#define MODULESDIR "modules" -#define LOGDIR "logs" +#undef TIMES_2 +#undef GETRUSAGE_2 +#define CONFDIR "conf" +#define MODULESDIR "modules" +#define LOGDIR "logs" #define PERMDATADIR "data" -#define CACHEDIR "cache" -#define TMPDIR "tmp" -#define PIDFILE PERMDATADIR"/unrealircd.pid" -#define CONTROLFILE PERMDATADIR"/unrealircd.ctl" +#define CACHEDIR "cache" +#define TMPDIR "tmp" +#define PIDFILE PERMDATADIR "/unrealircd.pid" +#define CONTROLFILE PERMDATADIR "/unrealircd.ctl" #define NO_U_TYPES #define NEED_U_INT32_T -#define strcasecmp _stricmp +#define strcasecmp _stricmp #define strncasecmp _strnicmp #define HAVE_EXPLICIT_BZERO #define HAVE_STRNLEN -#define explicit_bzero(a,b) SecureZeroMemory(a,b) +#define explicit_bzero(a, b) SecureZeroMemory(a, b) #define HAS_ASN1_TIME_diff #define HAS_SSL_CTX_SET1_CURVES_LIST #define HAS_SSL_CTX_SET_MIN_PROTO_VERSION @@ -60,7 +60,7 @@ /* We require Windows 7 or later */ #define NTDDI_VERSION 0x06010000 -#define _WIN32_WINNT 0x0601 +#define _WIN32_WINNT 0x0601 /* What geoip engine to use */ #define GEOIP_ENGINE "geoip_mmdb" diff --git a/src/aliases.c b/src/aliases.c index b66154f6f..2a8c7c85a 100644 --- a/src/aliases.c +++ b/src/aliases.c @@ -20,24 +20,28 @@ #include "unrealircd.h" /* Function to return a group of tokens -- codemastr */ -void strrangetok(char *in, char *out, char tok, short first, short last) { +void strrangetok(char *in, char *out, char tok, short first, short last) +{ int i = 0, tokcount = 0, j = 0; first--; last--; - while(in[i]) { - if (in[i] == tok) { + while (in[i]) + { + if (in[i] == tok) + { tokcount++; if (tokcount == first) i++; } - if (tokcount >= first && (tokcount <= last || last == -1)) { + if (tokcount >= first && (tokcount <= last || last == -1)) + { out[j] = in[i]; j++; } i++; } out[j] = 0; -} +} /* cmd_alias is a special type of command, it has an extra argument 'cmd'. */ static int recursive_alias = 0; @@ -49,13 +53,13 @@ void cmd_alias(ClientContext *clictx, Client *client, MessageTag *mtags, int par int ret; char request[BUFSIZE]; - if (!(alias = find_alias(cmd))) + if (!(alias = find_alias(cmd))) { sendto_one(client, NULL, ":%s %d %s %s :Unknown command", - me.name, ERR_UNKNOWNCOMMAND, client->name, cmd); + me.name, ERR_UNKNOWNCOMMAND, client->name, cmd); return; } - + /* If it isn't an ALIAS_COMMAND, we require a paramter ... We check ALIAS_COMMAND LATER */ if (alias->type != ALIAS_COMMAND && (parc < 2 || *parv[1] == '\0')) { @@ -63,48 +67,42 @@ void cmd_alias(ClientContext *clictx, Client *client, MessageTag *mtags, int par return; } - if (alias->type == ALIAS_SERVICES) + if (alias->type == ALIAS_SERVICES) { if (SERVICES_NAME && (acptr = find_user(alias->nick, NULL))) { if (alias->spamfilter && match_spamfilter(client, parv[1], SPAMF_USERMSG, cmd, alias->nick, 0, clictx, NULL)) return; sendto_one(acptr, NULL, ":%s PRIVMSG %s@%s :%s", client->name, - alias->nick, SERVICES_NAME, parv[1]); - } - else + alias->nick, SERVICES_NAME, parv[1]); + } else sendnumeric(client, ERR_SERVICESDOWN, alias->nick); - } - else if (alias->type == ALIAS_STATS) + } else if (alias->type == ALIAS_STATS) { if (STATS_SERVER && (acptr = find_user(alias->nick, NULL))) { if (alias->spamfilter && match_spamfilter(client, parv[1], SPAMF_USERMSG, cmd, alias->nick, 0, clictx, NULL)) return; sendto_one(acptr, NULL, ":%s PRIVMSG %s@%s :%s", client->name, - alias->nick, STATS_SERVER, parv[1]); - } - else + alias->nick, STATS_SERVER, parv[1]); + } else sendnumeric(client, ERR_SERVICESDOWN, alias->nick); - } - else if (alias->type == ALIAS_NORMAL) + } else if (alias->type == ALIAS_NORMAL) { - if ((acptr = find_user(alias->nick, NULL))) + if ((acptr = find_user(alias->nick, NULL))) { if (alias->spamfilter && match_spamfilter(client, parv[1], SPAMF_USERMSG, cmd, alias->nick, 0, clictx, NULL)) return; if (MyUser(acptr)) - sendto_one(acptr, NULL, ":%s!%s@%s PRIVMSG %s :%s", client->name, - client->user->username, GetHost(client), - alias->nick, parv[1]); + sendto_one(acptr, NULL, ":%s!%s@%s PRIVMSG %s :%s", client->name, + client->user->username, GetHost(client), + alias->nick, parv[1]); else sendto_one(acptr, NULL, ":%s PRIVMSG %s :%s", client->name, - alias->nick, parv[1]); - } - else + alias->nick, parv[1]); + } else sendnumeric(client, ERR_NOSUCHNICK, alias->nick); - } - else if (alias->type == ALIAS_CHANNEL) + } else if (alias->type == ALIAS_CHANNEL) { Channel *channel; if ((channel = find_channel(alias->nick))) @@ -118,7 +116,7 @@ void cmd_alias(ClientContext *clictx, Client *client, MessageTag *mtags, int par { new_message(client, NULL, &mtags); sendto_channel(channel, client, client->direction, - NULL, 0, SEND_ALL|SKIP_DEAF, mtags, + NULL, 0, SEND_ALL | SKIP_DEAF, mtags, ":%s PRIVMSG %s :%s", client->name, channel->name, parv[1]); free_message_tags(mtags); @@ -128,9 +126,8 @@ void cmd_alias(ClientContext *clictx, Client *client, MessageTag *mtags, int par if (IsDead(client)) return; sendnumeric(client, ERR_CANNOTDOCOMMAND, - cmd, "You may not use this command at this time"); - } - else if (alias->type == ALIAS_COMMAND) + cmd, "You may not use this command at this time"); + } else if (alias->type == ALIAS_COMMAND) { ConfigItem_alias_format *format; char *ptr = ""; @@ -153,42 +150,41 @@ void cmd_alias(ClientContext *clictx, Client *client, MessageTag *mtags, int par memset(current, 0, sizeof(current)); memset(output, 0, sizeof(output)); - while(format->parameters[i] && j < 500) + while (format->parameters[i] && j < 500) { k = 0; - if (format->parameters[i] == '%') + if (format->parameters[i] == '%') { i++; - if (format->parameters[i] == '%') + if (format->parameters[i] == '%') output[j++] = '%'; - else if (isdigit(format->parameters[i])) + else if (isdigit(format->parameters[i])) { - for(; isdigit(format->parameters[i]) && k < 2; i++, k++) { + for (; isdigit(format->parameters[i]) && k < 2; i++, k++) + { nums[k] = format->parameters[i]; } nums[k] = 0; i--; - if (format->parameters[i+1] == '-') { - strrangetok(ptr, current, ' ', atoi(nums),0); + if (format->parameters[i + 1] == '-') + { + strrangetok(ptr, current, ' ', atoi(nums), 0); i++; - } - else + } else strrangetok(ptr, current, ' ', atoi(nums), atoi(nums)); if (!*current) continue; - if (j + strlen(current)+1 >= 500) + if (j + strlen(current) + 1 >= 500) break; strlcat(output, current, sizeof output); j += strlen(current); - - } - else if (format->parameters[i] == 'n' || - format->parameters[i] == 'N') + + } else if (format->parameters[i] == 'n' || + format->parameters[i] == 'N') { strlcat(output, client->name, sizeof output); j += strlen(client->name); - } - else + } else { output[j++] = '%'; output[j++] = format->parameters[i]; @@ -205,47 +201,43 @@ void cmd_alias(ClientContext *clictx, Client *client, MessageTag *mtags, int par sendnumeric(client, ERR_NEEDMOREPARAMS, cmd); return; } - - if (format->type == ALIAS_SERVICES) + + if (format->type == ALIAS_SERVICES) { if (SERVICES_NAME && (acptr = find_user(format->nick, NULL))) { if (alias->spamfilter && match_spamfilter(client, output, SPAMF_USERMSG, cmd, format->nick, 0, clictx, NULL)) return; sendto_one(acptr, NULL, ":%s PRIVMSG %s@%s :%s", client->name, - format->nick, SERVICES_NAME, output); + format->nick, SERVICES_NAME, output); } else sendnumeric(client, ERR_SERVICESDOWN, format->nick); - } - else if (format->type == ALIAS_STATS) + } else if (format->type == ALIAS_STATS) { if (STATS_SERVER && (acptr = find_user(format->nick, NULL))) { if (alias->spamfilter && match_spamfilter(client, output, SPAMF_USERMSG, cmd, format->nick, 0, clictx, NULL)) return; sendto_one(acptr, NULL, ":%s PRIVMSG %s@%s :%s", client->name, - format->nick, STATS_SERVER, output); + format->nick, STATS_SERVER, output); } else sendnumeric(client, ERR_SERVICESDOWN, format->nick); - } - else if (format->type == ALIAS_NORMAL) + } else if (format->type == ALIAS_NORMAL) { - if ((acptr = find_user(format->nick, NULL))) + if ((acptr = find_user(format->nick, NULL))) { if (alias->spamfilter && match_spamfilter(client, output, SPAMF_USERMSG, cmd, format->nick, 0, clictx, NULL)) return; if (MyUser(acptr)) - sendto_one(acptr, NULL, ":%s!%s@%s PRIVMSG %s :%s", client->name, - client->user->username, IsHidden(client) ? client->user->virthost : client->user->realhost, - format->nick, output); + sendto_one(acptr, NULL, ":%s!%s@%s PRIVMSG %s :%s", client->name, + client->user->username, IsHidden(client) ? client->user->virthost : client->user->realhost, + format->nick, output); else sendto_one(acptr, NULL, ":%s PRIVMSG %s :%s", client->name, - format->nick, output); - } - else + format->nick, output); + } else sendnumeric(client, ERR_NOSUCHNICK, format->nick); - } - else if (format->type == ALIAS_CHANNEL) + } else if (format->type == ALIAS_CHANNEL) { Channel *channel; if ((channel = find_channel(format->nick))) @@ -255,11 +247,11 @@ void cmd_alias(ClientContext *clictx, Client *client, MessageTag *mtags, int par /* FIXME: when can_send_to_channel() gets 'int flags', pass * alias->spamfilter ? 0 : CAN_SEND_SKIP_SPAMFILTER */ - if (can_send_to_channel(client, channel, &msg, &errmsg, 0, clictx)) + if (can_send_to_channel(client, channel, &msg, &errmsg, 0, clictx)) { new_message(client, NULL, &mtags); sendto_channel(channel, client, client->direction, - NULL, 0, SEND_ALL|SKIP_DEAF, mtags, + NULL, 0, SEND_ALL | SKIP_DEAF, mtags, ":%s PRIVMSG %s :%s", client->name, channel->name, parv[1]); free_message_tags(mtags); @@ -269,13 +261,12 @@ void cmd_alias(ClientContext *clictx, Client *client, MessageTag *mtags, int par if (IsDead(client)) return; sendnumeric(client, ERR_CANNOTDOCOMMAND, cmd, - "You may not use this command at this time"); - } - else if (format->type == ALIAS_REAL) + "You may not use this command at this time"); + } else if (format->type == ALIAS_REAL) { int ret; char mybuf[500]; - + snprintf(mybuf, sizeof(mybuf), "%s %s", format->nick, output); if (recursive_alias) diff --git a/src/api-apicallback.c b/src/api-apicallback.c index 9acdf0827..5eb1c3615 100644 --- a/src/api-apicallback.c +++ b/src/api-apicallback.c @@ -37,9 +37,9 @@ APICallback *APICallbackAdd(Module *module, APICallback *mreq) if (!mreq->callback_type) { unreal_log(ULOG_ERROR, "module", "API_CALLBACK_ADD_API_ERROR", NULL, - "APICallbackAdd() from module $module_name: " - "Missing required fields.", - log_data_string("module_name", module->header->name)); + "APICallbackAdd() from module $module_name: " + "Missing required fields.", + log_data_string("module_name", module->header->name)); abort(); } @@ -49,12 +49,14 @@ APICallback *APICallbackAdd(Module *module, APICallback *mreq) if (m->unloaded) { m->unloaded = 0; - } else { + } else + { if (module) module->errorcode = MODERR_EXISTS; return NULL; } - } else { + } else + { /* New API callback */ m = safe_alloc(sizeof(APICallback)); safe_strdup(m->name, mreq->name); @@ -177,9 +179,9 @@ void print_apicallbacks(void) { m_next = m->next; unreal_log(ULOG_DEBUG, "module", "API_CALLBACK_LIST", NULL, - "$name ($deleted)", - log_data_string("name", m->name), - log_data_string("deleted", m->unloaded ? "deleted" : "")); + "$name ($deleted)", + log_data_string("name", m->name), + log_data_string("deleted", m->unloaded ? "deleted" : "")); } unreal_log(ULOG_DEBUG, "module", "API_CALLBACK_LIST", NULL, "----"); } diff --git a/src/api-channelmode.c b/src/api-channelmode.c index c46de1b74..773b502f3 100644 --- a/src/api-channelmode.c +++ b/src/api-channelmode.c @@ -47,7 +47,7 @@ char extchmstr[4][64]; static void make_cmodestr(void); static char previous_chanmodes[256]; static char previous_prefix[256]; -static Cmode *ParamTable[MAXPARAMMODES+1]; +static Cmode *ParamTable[MAXPARAMMODES + 1]; static void unload_extcmode_commit(Cmode *cmode); /** Create the strings that are used for CHANMODES=a,b,c,d in numeric 005 */ @@ -56,29 +56,29 @@ void make_extcmodestr() char *p; Cmode *cm; int i; - + extchmstr[0][0] = extchmstr[1][0] = extchmstr[2][0] = extchmstr[3][0] = '\0'; - + /* type 1: lists (like b/e) */ /* [NOT IMPLEMENTED IN EXTCMODES] */ /* type 2: 1 par to set/unset (has .unset_with_param) */ p = extchmstr[1]; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if (cm->paracount && cm->letter && cm->unset_with_param && (cm->type != CMODE_MEMBER)) *p++ = cm->letter; *p = '\0'; /* type 3: 1 param to set, 0 params to unset (does not have .unset_with_param) */ p = extchmstr[2]; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if (cm->paracount && cm->letter && !cm->unset_with_param) *p++ = cm->letter; *p = '\0'; - + /* type 4: paramless modes */ p = extchmstr[3]; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if (!cm->paracount && cm->letter) *p++ = cm->letter; *p = '\0'; @@ -97,7 +97,7 @@ static void make_cmodestr(void) p++; tab++; } - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if (cm->letter) *p++ = cm->letter; *p = '\0'; @@ -134,9 +134,9 @@ void extcmodes_check_for_changed_channel_modes(void) strlcpy(previous_chanmodes, chanmodes, sizeof(previous_chanmodes)); return; /* not booted yet. then we are done here. */ } - + ISupportSetValue(isup, chanmodes); - + if (*previous_chanmodes && strcmp(chanmodes, previous_chanmodes)) { unreal_log(ULOG_INFO, "mode", "CHANNEL_MODES_CHANGED", NULL, @@ -161,7 +161,7 @@ void make_prefix(char **isupport_prefix, char **isupport_statusmsg) *prefix = *prefix_prefix = *prefix_modes = '\0'; - for (n=0, cm=channelmodes; cm && n < ARRAY_SIZEOF(rank)-1; cm = cm->next) + for (n = 0, cm = channelmodes; cm && n < ARRAY_SIZEOF(rank) - 1; cm = cm->next) { if ((cm->type == CMODE_MEMBER) && cm->letter) { @@ -176,9 +176,9 @@ void make_prefix(char **isupport_prefix, char **isupport_statusmsg) { int i, j; /* Now sort the damn thing */ - for (i=0; i < n; i++) + for (i = 0; i < n; i++) { - for (j=i+1; j < n; j++) + for (j = i + 1; j < n; j++) { if (rank[i] < rank[j]) { @@ -314,7 +314,7 @@ Cmode *CmodeAdd(Module *module, CmodeInfo req, Cmode_t *mode) int existing = 0; Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (cm->letter == req.letter) { @@ -323,7 +323,8 @@ Cmode *CmodeAdd(Module *module, CmodeInfo req, Cmode_t *mode) cm->unloaded = 0; existing = 1; break; - } else { + } else + { if (module) module->errorcode = MODERR_EXISTS; return NULL; @@ -338,10 +339,10 @@ Cmode *CmodeAdd(Module *module, CmodeInfo req, Cmode_t *mode) if (req.type == CMODE_NORMAL) { - for (l = 1; l < ULLONG_MAX/2; l *= 2) + for (l = 1; l < ULLONG_MAX / 2; l *= 2) { found = 0; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (cm->mode == l) { @@ -356,7 +357,7 @@ Cmode *CmodeAdd(Module *module, CmodeInfo req, Cmode_t *mode) if (found) { unreal_log(ULOG_ERROR, "module", "CHANNEL_MODE_OUT_OF_SPACE", NULL, - "CmodeAdd: out of space!!!"); + "CmodeAdd: out of space!!!"); if (module) module->errorcode = MODERR_NOSPACE; return NULL; @@ -371,15 +372,16 @@ Cmode *CmodeAdd(Module *module, CmodeInfo req, Cmode_t *mode) !req.unset_with_param || !req.rank) { unreal_log(ULOG_ERROR, "module", "CMODEADD_API_ERROR", NULL, - "CmodeAdd(): module is missing required information. " - "Module: $module_name", - log_data_string("module_name", module->header->name)); + "CmodeAdd(): module is missing required information. " + "Module: $module_name", + log_data_string("module_name", module->header->name)); module->errorcode = MODERR_INVALID; return NULL; } cm = safe_alloc(sizeof(Cmode)); cm->letter = req.letter; - } else { + } else + { abort(); } channelmode_add_sorted(cm); @@ -391,8 +393,7 @@ Cmode *CmodeAdd(Module *module, CmodeInfo req, Cmode_t *mode) { /* Re-use parameter slot of the module with the same modechar that is unloading */ paraslot = cm->param_slot; - } - else + } else { /* Allocate a new one */ for (paraslot = 0; ParamTable[paraslot]; paraslot++) @@ -400,7 +401,7 @@ Cmode *CmodeAdd(Module *module, CmodeInfo req, Cmode_t *mode) if (paraslot == MAXPARAMMODES - 1) { unreal_log(ULOG_ERROR, "module", "CHANNEL_MODE_OUT_OF_SPACE", NULL, - "CmodeAdd: out of space!!! Place 2."); + "CmodeAdd: out of space!!! Place 2."); if (module) module->errorcode = MODERR_NOSPACE; return NULL; @@ -455,8 +456,10 @@ void CmodeDel(Cmode *cmode) if (cmode->owner) { ModuleObject *cmodeobj; - for (cmodeobj = cmode->owner->objects; cmodeobj; cmodeobj = cmodeobj->next) { - if (cmodeobj->type == MOBJ_CMODE && cmodeobj->object.cmode == cmode) { + for (cmodeobj = cmode->owner->objects; cmodeobj; cmodeobj = cmodeobj->next) + { + if (cmodeobj->type == MOBJ_CMODE && cmodeobj->object.cmode == cmode) + { DelListItem(cmodeobj, cmode->owner->objects); safe_free(cmodeobj); break; @@ -468,7 +471,6 @@ void CmodeDel(Cmode *cmode) cmode->unloaded = 1; else unload_extcmode_commit(cmode); - } /** @} */ @@ -498,11 +500,11 @@ static void unload_extcmode_commit(Cmode *cmode) new_message(&me, NULL, &mtags); sendto_channel(channel, &me, NULL, 0, 0, SEND_LOCAL, mtags, - ":%s MODE %s -%c", - me.name, channel->name, cmode->letter); + ":%s MODE %s -%c", + me.name, channel->name, cmode->letter); sendto_server(NULL, 0, 0, mtags, - ":%s MODE %s -%c 0", - me.id, channel->name, cmode->letter); + ":%s MODE %s -%c 0", + me.id, channel->name, cmode->letter); free_message_tags(mtags); channel->mode.mode &= ~cmode->mode; @@ -522,18 +524,19 @@ static void unload_extcmode_commit(Cmode *cmode) { const char *param = cmode->get_param(GETPARASTRUCT(channel, cmode->letter)); sendto_channel(channel, &me, NULL, 0, 0, SEND_LOCAL, mtags, - ":%s MODE %s -%c %s", - me.name, channel->name, cmode->letter, param); + ":%s MODE %s -%c %s", + me.name, channel->name, cmode->letter, param); sendto_server(NULL, 0, 0, mtags, - ":%s MODE %s -%c %s 0", - me.id, channel->name, cmode->letter, param); - } else { + ":%s MODE %s -%c %s 0", + me.id, channel->name, cmode->letter, param); + } else + { sendto_channel(channel, &me, NULL, 0, 0, SEND_LOCAL, mtags, - ":%s MODE %s -%c", - me.name, channel->name, cmode->letter); + ":%s MODE %s -%c", + me.name, channel->name, cmode->letter); sendto_server(NULL, 0, 0, mtags, - ":%s MODE %s -%c 0", - me.id, channel->name, cmode->letter); + ":%s MODE %s -%c 0", + me.id, channel->name, cmode->letter); } free_message_tags(mtags); @@ -543,8 +546,7 @@ static void unload_extcmode_commit(Cmode *cmode) } extcmode_para_delslot(cmode, cmode->param_slot); } - } else - if (cmode->type == CMODE_MEMBER) + } else if (cmode->type == CMODE_MEMBER) { for (channel = channels; channel; channel = channel->nextch) { @@ -557,11 +559,11 @@ static void unload_extcmode_commit(Cmode *cmode) new_message(&me, NULL, &mtags); sendto_channel(channel, &me, NULL, 0, 0, SEND_LOCAL, mtags, - ":%s MODE %s -%c %s", - me.name, channel->name, cmode->letter, m->client->name); + ":%s MODE %s -%c %s", + me.name, channel->name, cmode->letter, m->client->name); sendto_server(NULL, 0, 0, mtags, - ":%s MODE %s -%c %s 0", - me.id, channel->name, cmode->letter, m->client->id); + ":%s MODE %s -%c %s 0", + me.id, channel->name, cmode->letter, m->client->id); free_message_tags(mtags); del_member_mode(m->client, channel, cmode->letter); } @@ -578,7 +580,7 @@ void unload_all_unused_extcmodes(void) { Cmode *cm, *cm_next; - for (cm=channelmodes; cm; cm = cm_next) + for (cm = channelmodes; cm; cm = cm_next) { cm_next = cm->next; if (cm->letter && cm->unloaded) @@ -586,7 +588,6 @@ void unload_all_unused_extcmodes(void) unload_extcmode_commit(cm); } } - } /** @defgroup ChannelModeAPI Channel mode API @@ -729,7 +730,7 @@ int module_has_extcmode_param_mode(Module *mod) { Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->letter) && (cm->owner == mod) && (cm->paracount)) return 1; @@ -862,7 +863,7 @@ Cmode *find_channel_mode_handler(char letter) { Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if (cm->letter == letter) return cm; return NULL; @@ -895,7 +896,7 @@ void addlettertomstring(char *str, char letter) my_rank = cm->rank; n = strlen(str); - if (n >= MEMBERMODESLEN-1) + if (n >= MEMBERMODESLEN - 1) return; // panic! for (p = str; *p; p++) @@ -907,14 +908,14 @@ void addlettertomstring(char *str, char letter) { /* We need to insert us here */ n = strlen(p); - memmove(p+1, p, n+1); // +1 for NUL byte + memmove(p + 1, p, n + 1); // +1 for NUL byte *p = letter; return; } } /* We should be at the end */ str[n] = letter; - str[n+1] = '\0'; + str[n + 1] = '\0'; } void add_member_mode_fast(Member *mb, Membership *mbs, char letter) @@ -981,7 +982,7 @@ char sjoin_prefix_to_mode(char s) return 'I'; /* Now the dynamic ones (+vhoaq): */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->sjoin_prefix == s) && (cm->type == CMODE_MEMBER)) return cm->letter; @@ -1006,7 +1007,7 @@ char mode_to_sjoin_prefix(char s) return '\''; /* Now the dynamic ones (+vhoaq): */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->letter == s) && (cm->type == CMODE_MEMBER)) return cm->sjoin_prefix; @@ -1040,7 +1041,7 @@ char mode_to_prefix(char s) return '\0'; /* Now the dynamic ones (+vhoaq): */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->letter == s) && (cm->type == CMODE_MEMBER)) return cm->prefix; @@ -1074,7 +1075,7 @@ char prefix_to_mode(char s) return '\0'; /* Now the dynamic ones (+vhoaq): */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->prefix == s) && (cm->type == CMODE_MEMBER)) return cm->letter; @@ -1085,7 +1086,7 @@ char prefix_to_mode(char s) char rank_to_mode(int rank) { Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->type == CMODE_MEMBER) && (cm->rank == rank)) return cm->letter; return '\0'; @@ -1094,7 +1095,7 @@ char rank_to_mode(int rank) int mode_to_rank(char mode) { Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->type == CMODE_MEMBER) && (cm->letter == mode)) return cm->rank; return '\0'; @@ -1103,7 +1104,7 @@ int mode_to_rank(char mode) int prefix_to_rank(char prefix) { Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->type == CMODE_MEMBER) && (cm->prefix == prefix)) return cm->rank; return '\0'; @@ -1112,7 +1113,7 @@ int prefix_to_rank(char prefix) char rank_to_prefix(int rank) { Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->type == CMODE_MEMBER) && (cm->rank == rank)) return cm->prefix; return '\0'; @@ -1168,9 +1169,9 @@ void channel_member_modes_generate_equal_or_greater(const char *modes, char *buf if (!rank) return; /* zero matches */ - for (cm=channelmodes; cm; cm = cm->next) - if ((cm->type == CMODE_MEMBER) && (cm->rank >= rank)) - strlcat_letter(buf, cm->letter, buflen); + for (cm = channelmodes; cm; cm = cm->next) + if ((cm->type == CMODE_MEMBER) && (cm->rank >= rank)) + strlcat_letter(buf, cm->letter, buflen); } /** @} */ diff --git a/src/api-clicap.c b/src/api-clicap.c index 5c6060cf2..b1663d8ec 100644 --- a/src/api-clicap.c +++ b/src/api-clicap.c @@ -27,7 +27,7 @@ * If exceeded, the caps just won't be stored and will be re-added safely. --k4be */ -#define MAXCLICAPS ((int)(sizeof(long)*8 - 1 + ADVERTISEONLYCAPS)) /* how many cap bits will fit in `long`? */ +#define MAXCLICAPS ((int)(sizeof(long) * 8 - 1 + ADVERTISEONLYCAPS)) /* how many cap bits will fit in `long`? */ static char *old_caps[MAXCLICAPS]; /**< List of old CAP names - used for /rehash */ int old_caps_proto[MAXCLICAPS]; /**< List of old CAP protocol values - used for /rehash */ @@ -116,7 +116,7 @@ long clicap_allocate_cap(void) ClientCapability *clicap; /* The first bit (v=1) is used by the "invert" marker */ - for (v=2; v; v <<= 1) + for (v = 2; v; v <<= 1) { unsigned char found = 0; for (clicap = clicaps; clicap; clicap = clicap->next) @@ -172,12 +172,14 @@ ClientCapability *ClientCapabilityAdd(Module *module, ClientCapabilityInfo *clic if (clicap->unloaded) { clicap->unloaded = 0; - } else { + } else + { if (module) module->errorcode = MODERR_EXISTS; return NULL; } - } else { + } else + { long v = 0; /* Allocate a bit, but only if the module needs it. @@ -256,7 +258,6 @@ void unload_clicap_commit(ClientCapability *clicap) safe_free(clicap->name); safe_free(clicap); clicap_update_affecting(); - } /** Remove a client capability. * @param clicap The client capability to remove. @@ -268,8 +269,10 @@ void ClientCapabilityDel(ClientCapability *clicap) if (clicap->owner) { ModuleObject *mobj; - for (mobj = clicap->owner->objects; mobj; mobj = mobj->next) { - if (mobj->type == MOBJ_CLICAP && mobj->object.clicap == clicap) { + for (mobj = clicap->owner->objects; mobj; mobj = mobj->next) + { + if (mobj->type == MOBJ_CLICAP && mobj->object.clicap == clicap) + { DelListItem(mobj, clicap->owner->objects); safe_free(mobj); break; @@ -302,13 +305,13 @@ void clicap_pre_rehash(void) ClientCapability *clicap; int i = 0; - for (i=0; i < MAXCLICAPS; i++) + for (i = 0; i < MAXCLICAPS; i++) { safe_free(old_caps[i]); old_caps_proto[i] = 0; } - for (i=0, clicap = clicaps; clicap; clicap = clicap->next) + for (i = 0, clicap = clicaps; clicap; clicap = clicap->next) { if (i == MAXCLICAPS) { diff --git a/src/api-command.c b/src/api-command.c index b870a12ca..1de4b2236 100644 --- a/src/api-command.c +++ b/src/api-command.c @@ -35,7 +35,7 @@ static RealCommand *add_Command_backend(const char *cmd); int CommandExists(const char *name) { RealCommand *p; - + for (p = CommandHash[toupper(*name)]; p; p = p->next) { if (!strcasecmp(p->cmd, name)) @@ -95,7 +95,7 @@ static Command *CommandAddInternal(Module *module, const char *cmd, CmdFunc func module->errorcode = MODERR_EXISTS; return NULL; } - + if (!flags) { config_error("CommandAdd(): Could not add command '%s': flags are 0", cmd); @@ -103,7 +103,7 @@ static Command *CommandAddInternal(Module *module, const char *cmd, CmdFunc func module->errorcode = MODERR_INVALID; return NULL; } - + c = add_Command_backend(cmd); c->parameters = (params > MAXPARA) ? MAXPARA : params; c->flags = flags; @@ -144,7 +144,7 @@ void CommandDelX(Command *command, RealCommand *cmd) { if (cmdobj->type == MOBJ_COMMAND && cmdobj->object.command == command) { - DelListItem(cmdobj,cmd->owner->objects); + DelListItem(cmdobj, cmd->owner->objects); safe_free(cmdobj); break; } @@ -208,7 +208,7 @@ void do_cmd(Client *client, MessageTag *mtags, const char *cmd, int parc, const new_message(client, NULL, &mtags); memset(&clictx, 0, sizeof(clictx)); clictx.cmd = cmptr; - (*cmptr->func) (&clictx, client, mtags, parc, parv); + (*cmptr->func)(&clictx, client, mtags, parc, parv); if (gen_mtags) free_message_tags(mtags); } @@ -228,11 +228,11 @@ RealCommand *CommandHash[256]; /* one per letter */ void init_CommandHash(void) { memset(CommandHash, 0, sizeof(CommandHash)); - CommandAdd(NULL, MSG_ERROR, cmd_error, MAXPARA, CMD_UNREGISTERED|CMD_SERVER); - CommandAdd(NULL, MSG_VERSION, cmd_version, MAXPARA, CMD_UNREGISTERED|CMD_USER|CMD_SERVER); + CommandAdd(NULL, MSG_ERROR, cmd_error, MAXPARA, CMD_UNREGISTERED | CMD_SERVER); + CommandAdd(NULL, MSG_VERSION, cmd_version, MAXPARA, CMD_UNREGISTERED | CMD_USER | CMD_SERVER); CommandAdd(NULL, MSG_INFO, cmd_info, MAXPARA, CMD_USER); CommandAdd(NULL, MSG_DNS, cmd_dns, MAXPARA, CMD_USER); - CommandAdd(NULL, MSG_REHASH, cmd_rehash, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(NULL, MSG_REHASH, cmd_rehash, MAXPARA, CMD_USER | CMD_SERVER); CommandAdd(NULL, MSG_RESTART, cmd_restart, 2, CMD_USER); CommandAdd(NULL, MSG_DIE, cmd_die, MAXPARA, CMD_USER); CommandAdd(NULL, MSG_CREDITS, cmd_credits, MAXPARA, CMD_USER); @@ -294,7 +294,7 @@ RealCommand *find_command_simple(const char *cmd) for (c = CommandHash[toupper(*cmd)]; c; c = c->next) { if (!strcasecmp(c->cmd, cmd)) - return c; + return c; } return NULL; diff --git a/src/api-efunctions.c b/src/api-efunctions.c index 386bd0548..bb5b28988 100644 --- a/src/api-efunctions.c +++ b/src/api-efunctions.c @@ -55,10 +55,10 @@ const char *(*tkl_type_string)(TKL *tk); const char *(*tkl_type_config_string)(TKL *tk); char *(*tkl_uhost)(TKL *tkl, char *buf, size_t buflen, int options); TKL *(*tkl_add_serverban)(int type, const char *usermask, const char *hostmask, SecurityGroup *match, - const char *reason, const char *setby, - time_t expire_at, time_t set_at, int soft, int flags); + const char *reason, const char *setby, + time_t expire_at, time_t set_at, int soft, int flags); TKL *(*tkl_add_nameban)(int type, const char *name, int hold, const char *reason, const char *setby, - time_t expire_at, time_t set_at, int flags); + time_t expire_at, time_t set_at, int flags); TKL *(*tkl_add_spamfilter)(int type, const char *id, unsigned short target, BanAction *action, Match *match, const char *rule, SecurityGroup *except, const char *setby, @@ -77,7 +77,7 @@ void (*tkl_hit)(Client *client, TKL *tkl); void (*remove_config_tkls)(int flag); void (*config_tkl_hits_restore)(void); int (*find_shun)(Client *client); -int(*find_spamfilter_user)(Client *client, int flags); +int (*find_spamfilter_user)(Client *client, int flags); TKL *(*find_qline)(Client *client, const char *nick, int *ishold); TKL *(*find_tkline_match_zap)(Client *client); void (*tkl_stats)(Client *client, int type, const char *para, int *cnt); @@ -225,7 +225,7 @@ Efunction *EfunctionAddMain(Module *module, EfunctionType eftype, int (*func)(), module->errorcode = MODERR_INVALID; return NULL; } - + p = safe_alloc(sizeof(Efunction)); if (func) p->func.intfunc = func; @@ -302,7 +302,7 @@ static int num_efunctions(EfunctionType eftype) for (e = Efunctions[eftype]; e; e = e->next) if (!e->willberemoved) cnt++; - + return cnt; } @@ -310,9 +310,9 @@ static int num_efunctions(EfunctionType eftype) /** Ensure that all efunctions are present. */ int efunctions_check(void) { - int i, n, errors=0; + int i, n, errors = 0; - for (i=0; i < MAXEFUNCTIONS; i++) + for (i = 0; i < MAXEFUNCTIONS; i++) { if (efunction_table[i].name) { @@ -328,8 +328,7 @@ int efunctions_check(void) "load all required modules! (hint: see modules.default.conf)", efunction_table[i].name); errors++; - } else - if (n > 1) + } else if (n > 1) { config_error("ERROR: efunction '%s' was found %d times, perhaps you " "loaded a module multiple times??", @@ -362,7 +361,7 @@ void efunctions_switchover(void) * as 'willberemoved' if needed. */ - for (i=0; i < MAXEFUNCTIONS; i++) + for (i = 0; i < MAXEFUNCTIONS; i++) { int found = 0; for (e = Efunctions[i]; e; e = e->next) diff --git a/src/api-event.c b/src/api-event.c index 31fa23dfc..8d5cdc129 100644 --- a/src/api-event.c +++ b/src/api-event.c @@ -62,7 +62,7 @@ Event *EventAdd(Module *module, const char *name, vFP event, void *data, long ev newevent->last_run.tv_sec = timeofday_tv.tv_sec; newevent->last_run.tv_usec = timeofday_tv.tv_usec; newevent->owner = module; - AddListItem(newevent,events); + AddListItem(newevent, events); if (module) { ModuleObject *eventobj = safe_alloc(sizeof(ModuleObject)); @@ -72,7 +72,6 @@ Event *EventAdd(Module *module, const char *name, vFP event, void *data, long ev module->errorcode = MODERR_NOERROR; } return newevent; - } /** Mark the Event for deletion. diff --git a/src/api-extban.c b/src/api-extban.c index 6641739b4..d52d70451 100644 --- a/src/api-extban.c +++ b/src/api-extban.c @@ -42,7 +42,7 @@ Extban *findmod_by_bantype_raw(const char *str, int ban_name_length) { Extban *e; - for (e=extbans; e; e = e->next) + for (e = extbans; e; e = e->next) { if ((ban_name_length == 1) && (e->letter == str[0])) return e; @@ -54,7 +54,7 @@ Extban *findmod_by_bantype_raw(const char *str, int ban_name_length) } } - return NULL; + return NULL; } Extban *findmod_by_bantype(const char *str, const char **remainder) @@ -69,10 +69,10 @@ Extban *findmod_by_bantype(const char *str, const char **remainder) return NULL; } if (remainder) - *remainder = p+1; + *remainder = p + 1; ban_name_length = p - str - 1; - return findmod_by_bantype_raw(str+1, ban_name_length); + return findmod_by_bantype_raw(str + 1, ban_name_length); } /* Check if this is a valid extended ban name */ @@ -141,8 +141,8 @@ Extban *ExtbanAdd(Module *module, ExtbanInfo req) { module->errorcode = MODERR_INVALID; unreal_log(ULOG_ERROR, "module", "EXTBANADD_API_ERROR", NULL, - "ExtbanAdd(): name must be specified for ban (new in U6). Module: $module_name", - log_data_string("module_name", module->header->name)); + "ExtbanAdd(): name must be specified for ban (new in U6). Module: $module_name", + log_data_string("module_name", module->header->name)); return NULL; } @@ -150,9 +150,9 @@ Extban *ExtbanAdd(Module *module, ExtbanInfo req) { module->errorcode = MODERR_INVALID; unreal_log(ULOG_ERROR, "module", "EXTBANADD_API_ERROR", NULL, - "ExtbanAdd(): module must indicate via .is_banned_events on which BANCHK_* " - "events to listen on (new in U6). Module: $module_name", - log_data_string("module_name", module->header->name)); + "ExtbanAdd(): module must indicate via .is_banned_events on which BANCHK_* " + "events to listen on (new in U6). Module: $module_name", + log_data_string("module_name", module->header->name)); return NULL; } @@ -181,12 +181,12 @@ Extban *ExtbanAdd(Module *module, ExtbanInfo req) { module->errorcode = MODERR_INVALID; unreal_log(ULOG_ERROR, "module", "EXTBANADD_API_ERROR", NULL, - "ExtbanAdd(): conv_param event missing. Module: $module_name", - log_data_string("module_name", module->header->name)); + "ExtbanAdd(): conv_param event missing. Module: $module_name", + log_data_string("module_name", module->header->name)); return NULL; } - for (e=extbans; e; e = e->next) + for (e = extbans; e; e = e->next) { if (e->letter == req.letter) { @@ -196,8 +196,7 @@ Extban *ExtbanAdd(Module *module, ExtbanInfo req) e->unloaded = 0; existing = 1; break; - } else - if ((module->flags == MODFLAG_TESTING) && e->preregistered) + } else if ((module->flags == MODFLAG_TESTING) && e->preregistered) { /* We are in MOD_INIT (yeah confusing, isn't it?) * and the extban already exists and it was preregistered. @@ -206,8 +205,7 @@ Extban *ExtbanAdd(Module *module, ExtbanInfo req) e->preregistered = 0; existing = 1; break; - } else - if (module->flags == MODFLAG_NONE) + } else if (module->flags == MODFLAG_NONE) { /* Better don't touch it, as we may still fail at this stage * and if we would set .conv_param etc to this and the new module @@ -274,7 +272,7 @@ void unload_all_unused_extbans(void) { Extban *e, *e_next; - for (e=extbans; e; e = e_next) + for (e = extbans; e; e = e_next) { e_next = e->next; if (e->letter && e->unloaded) @@ -282,7 +280,6 @@ void unload_all_unused_extbans(void) unload_extban_commit(e); } } - } /** Delete an extended ban. @@ -411,9 +408,9 @@ const char *extban_conv_param_nuh_or_extban(BanContext *b, Extban *self_extban) #if (NICKLEN + USERLEN + HOSTLEN + 32) > MAXBANLEN #error "MAXBANLEN is not sufficient to hold n!u@h plus some extra for extban prefixes. wtf?" #endif - static char retbuf[MAXBANLEN+1]; + static char retbuf[MAXBANLEN + 1]; char *mask; - char tmpbuf[MAXBANLEN+1]; + char tmpbuf[MAXBANLEN + 1]; const char *ret = NULL; const char *nextbanstr; Extban *extban = NULL; @@ -428,7 +425,7 @@ const char *extban_conv_param_nuh_or_extban(BanContext *b, Extban *self_extban) * 2) The second item may never be an action modifier, nor have the * EXTBOPT_NOSTACKCHILD letter set (for things like a textban). */ - + /* Rule #1. Yes the recursion check is also in extban_is_ok_nuh_extban, * but it's possible to get here without the is_ok() function ever * being called (think: non-local client). And no, don't delete it diff --git a/src/api-history-backend.c b/src/api-history-backend.c index 4e86e2730..8ebb17ed0 100644 --- a/src/api-history-backend.c +++ b/src/api-history-backend.c @@ -67,8 +67,8 @@ HistoryBackend *HistoryBackendAdd(Module *module, HistoryBackendInfo *mreq) { module->errorcode = MODERR_INVALID; unreal_log(ULOG_ERROR, "module", "HISTORYBACKENDADD_API_ERROR", NULL, - "HistoryBackendAdd(): missing a handler for add/del/request/destroy/set_limit. Module: $module_name", - log_data_string("module_name", module->header->name)); + "HistoryBackendAdd(): missing a handler for add/del/request/destroy/set_limit. Module: $module_name", + log_data_string("module_name", module->header->name)); return NULL; } m = HistoryBackendFind(mreq->name); @@ -78,11 +78,13 @@ HistoryBackend *HistoryBackendAdd(Module *module, HistoryBackendInfo *mreq) if (m->unloaded) { m->unloaded = 0; - } else { + } else + { module->errorcode = MODERR_EXISTS; return NULL; } - } else { + } else + { /* New history backend */ m = safe_alloc(sizeof(HistoryBackend)); safe_strdup(m->name, mreq->name); @@ -127,7 +129,8 @@ void HistoryBackendDel(HistoryBackend *m) if (m->owner) { ModuleObject *mobj; - for (mobj = m->owner->objects; mobj; mobj = mobj->next) { + for (mobj = m->owner->objects; mobj; mobj = mobj->next) + { if (mobj->type == MOBJ_HISTORY_BACKEND && mobj->object.history_backend == m) { DelListItem(mobj, m->owner->objects); @@ -160,7 +163,7 @@ int history_add(const char *object, MessageTag *mtags, const char *line) { HistoryBackend *hb; - for (hb = historybackends; hb; hb=hb->next) + for (hb = historybackends; hb; hb = hb->next) hb->history_add(object, mtags, line); return 1; @@ -226,7 +229,7 @@ int history_destroy(const char *object) { HistoryBackend *hb; - for (hb = historybackends; hb; hb=hb->next) + for (hb = historybackends; hb; hb = hb->next) hb->history_destroy(object); return 1; @@ -236,7 +239,7 @@ int history_set_limit(const char *object, int max_lines, long max_t) { HistoryBackend *hb; - for (hb = historybackends; hb; hb=hb->next) + for (hb = historybackends; hb; hb = hb->next) hb->history_set_limit(object, max_lines, max_t); return 1; @@ -282,7 +285,8 @@ static void history_send_result_line(Client *client, HistoryLogLine *l, const ch if (BadPtr(batchid)) { sendto_one(client, l->mtags, "%s", l->line); - } else { + } else + { MessageTag *m = safe_alloc(sizeof(MessageTag)); safe_strdup(m->name, "batch"); safe_strdup(m->value, batchid); @@ -299,7 +303,7 @@ static void history_send_result_line(Client *client, HistoryLogLine *l, const ch static void history_send_result_multiline(Client *client, HistoryLogLine *head, const char *outer_batch, const char *object) { - char inner_batch[BATCHLEN+1]; + char inner_batch[BATCHLEN + 1]; HistoryLogLine *l; MessageTag *m; @@ -376,7 +380,7 @@ static void history_send_result_multiline_fallback(Client *client, HistoryLogLin */ void history_send_result(Client *client, HistoryResult *r, int end_of_pagination) { - char batch[BATCHLEN+1]; + char batch[BATCHLEN + 1]; HistoryLogLine *l; int has_multiline; MessageTag *batch_open_mtags = NULL; @@ -409,7 +413,8 @@ void history_send_result(Client *client, HistoryResult *r, int end_of_pagination history_send_result_multiline(client, l, batch, r->object); else history_send_result_multiline_fallback(client, l, batch); - } else { + } else + { history_send_result_line(client, l, batch); } } diff --git a/src/api-isupport.c b/src/api-isupport.c index e898cfe7e..a20ddaeed 100644 --- a/src/api-isupport.c +++ b/src/api-isupport.c @@ -28,7 +28,7 @@ ISupport *ISupports = NULL; /* List of ISUPPORT (005) tokens */ ISupport *ISupports_old = NULL; /* see isupport_snapshot() and isupport_check_for_changes() */ #define MAXISUPPORTLINES 10 -MODVAR char *ISupportStrings[MAXISUPPORTLINES+1]; +MODVAR char *ISupportStrings[MAXISUPPORTLINES + 1]; void isupport_add_sorted(ISupport *is); void make_isupportstrings(void); @@ -125,7 +125,7 @@ void isupport_init(void) ISupportSet(NULL, "draft/ICON", iConf.network_icon); else ISupportDelByName("draft/ICON"); - + set_isupport_extban(); /* EXTBAN=xyz */ set_isupport_targmax(); /* TARGMAX=... */ } @@ -201,7 +201,7 @@ ISupport *ISupportAdd(Module *module, const char *token, const char *value) return NULL; } } - if (!token || !*token || c-token > 20) + if (!token || !*token || c - token > 20) { if (module) module->errorcode = MODERR_INVALID; @@ -279,7 +279,7 @@ void make_isupportstrings(void) safe_free(ISupportStrings[i]); i = 0; - ISupportStrings[i] = safe_alloc(bufsize+1); + ISupportStrings[i] = safe_alloc(bufsize + 1); for (isupport = ISupports; isupport; isupport = isupport->next) { @@ -292,7 +292,7 @@ void make_isupportstrings(void) if ((strlen(ISupportStrings[i]) + strlen(tmp) + 1 >= ISUPPORTLEN) || (tokcnt == 13)) { /* No room or max tokens reached: start a new buffer */ - ISupportStrings[++i] = safe_alloc(bufsize+1); + ISupportStrings[++i] = safe_alloc(bufsize + 1); tokcnt = 1; if (i == MAXISUPPORTLINES) abort(); /* should never happen anyway */ diff --git a/src/api-messagetag.c b/src/api-messagetag.c index 5f4dcc292..68c7193f6 100644 --- a/src/api-messagetag.c +++ b/src/api-messagetag.c @@ -53,17 +53,17 @@ MessageTagHandler *MessageTagHandlerAdd(Module *module, MessageTagHandlerInfo *m if ((mreq->flags & MTAG_HANDLER_FLAGS_NO_CAP_NEEDED) && mreq->clicap_handler) { unreal_log(ULOG_ERROR, "module", "MESSAGETAGHANDLERADD_API_ERROR", NULL, - "MessageTagHandlerAdd() from module $module_name: " - ".flags is set to MTAG_HANDLER_FLAGS_NO_CAP_NEEDED " - "but a .clicap_handler is passed as well. These options are mutually " - "exclusive, choose one or the other.", - log_data_string("module_name", module->header->name)); + "MessageTagHandlerAdd() from module $module_name: " + ".flags is set to MTAG_HANDLER_FLAGS_NO_CAP_NEEDED " + "but a .clicap_handler is passed as well. These options are mutually " + "exclusive, choose one or the other.", + log_data_string("module_name", module->header->name)); abort(); } else if (!(mreq->flags & MTAG_HANDLER_FLAGS_NO_CAP_NEEDED) && !mreq->clicap_handler) { unreal_log(ULOG_ERROR, "module", "MESSAGETAGHANDLERADD_API_ERROR", NULL, - "MessageTagHandlerAdd() from module $module_name: " - "no .clicap_handler is passed. If the " + "MessageTagHandlerAdd() from module $module_name: " + "no .clicap_handler is passed. If the " "message tag really does not require a cap then you must " "set .flags to MTAG_HANDLER_FLAGS_NO_CAP_NEEDED", log_data_string("module_name", module->header->name)); @@ -76,12 +76,14 @@ MessageTagHandler *MessageTagHandlerAdd(Module *module, MessageTagHandlerInfo *m if (m->unloaded) { m->unloaded = 0; - } else { + } else + { if (module) module->errorcode = MODERR_EXISTS; return NULL; } - } else { + } else + { /* New message tag handler */ m = safe_alloc(sizeof(MessageTagHandler)); safe_strdup(m->name, mreq->name); @@ -137,7 +139,8 @@ void MessageTagHandlerDel(MessageTagHandler *m) if (m->owner) { ModuleObject *mobj; - for (mobj = m->owner->objects; mobj; mobj = mobj->next) { + for (mobj = m->owner->objects; mobj; mobj = mobj->next) + { if (mobj->type == MOBJ_MTAG && mobj->object.mtag == m) { DelListItem(mobj, m->owner->objects); diff --git a/src/api-moddata.c b/src/api-moddata.c index 95a7fb0d2..b911d629f 100644 --- a/src/api-moddata.c +++ b/src/api-moddata.c @@ -22,7 +22,7 @@ #include "unrealircd.h" -MODVAR ModDataInfo *MDInfo[HIGHESTMODDATATYPE+1] = { NULL }; +MODVAR ModDataInfo *MDInfo[HIGHESTMODDATATYPE + 1] = {NULL}; MODVAR ModData local_variable_moddata[MODDATA_MAX_LOCAL_VARIABLE]; MODVAR ModData global_variable_moddata[MODDATA_MAX_GLOBAL_VARIABLE]; @@ -35,14 +35,14 @@ struct moddatatypelimit { }; struct moddatatypelimit moddatatypelimits[] = { - { MODDATATYPE_LOCAL_VARIABLE, "MODDATATYPE_LOCAL_VARIABLE", MODDATA_MAX_LOCAL_VARIABLE, "MODDATA_MAX_LOCAL_VARIABLE" }, - { MODDATATYPE_GLOBAL_VARIABLE, "MODDATATYPE_GLOBAL_VARIABLE", MODDATA_MAX_GLOBAL_VARIABLE, "MODDATA_MAX_GLOBAL_VARIABLE" }, - { MODDATATYPE_CLIENT, "MODDATATYPE_CLIENT", MODDATA_MAX_CLIENT, "MODDATA_MAX_CLIENT" }, - { MODDATATYPE_LOCAL_CLIENT, "MODDATATYPE_LOCAL_CLIENT", MODDATA_MAX_LOCAL_CLIENT, "MODDATA_MAX_LOCAL_CLIENT" }, - { MODDATATYPE_CHANNEL, "MODDATATYPE_CHANNEL", MODDATA_MAX_CHANNEL, "MODDATA_MAX_CHANNEL" }, - { MODDATATYPE_MEMBER, "MODDATATYPE_MEMBER", MODDATA_MAX_MEMBER, "MODDATA_MAX_MEMBER" }, - { MODDATATYPE_MEMBERSHIP, "MODDATATYPE_MEMBERSHIP", MODDATATYPE_MEMBERSHIP, "MODDATATYPE_MAX_MEMBERSHIP" }, - { 0, NULL, 0, NULL }, + {MODDATATYPE_LOCAL_VARIABLE, "MODDATATYPE_LOCAL_VARIABLE", MODDATA_MAX_LOCAL_VARIABLE, "MODDATA_MAX_LOCAL_VARIABLE"}, + {MODDATATYPE_GLOBAL_VARIABLE, "MODDATATYPE_GLOBAL_VARIABLE", MODDATA_MAX_GLOBAL_VARIABLE, "MODDATA_MAX_GLOBAL_VARIABLE"}, + {MODDATATYPE_CLIENT, "MODDATATYPE_CLIENT", MODDATA_MAX_CLIENT, "MODDATA_MAX_CLIENT"}, + {MODDATATYPE_LOCAL_CLIENT, "MODDATATYPE_LOCAL_CLIENT", MODDATA_MAX_LOCAL_CLIENT, "MODDATA_MAX_LOCAL_CLIENT"}, + {MODDATATYPE_CHANNEL, "MODDATATYPE_CHANNEL", MODDATA_MAX_CHANNEL, "MODDATA_MAX_CHANNEL"}, + {MODDATATYPE_MEMBER, "MODDATATYPE_MEMBER", MODDATA_MAX_MEMBER, "MODDATA_MAX_MEMBER"}, + {MODDATATYPE_MEMBERSHIP, "MODDATATYPE_MEMBERSHIP", MODDATATYPE_MEMBERSHIP, "MODDATATYPE_MAX_MEMBERSHIP"}, + {0, NULL, 0, NULL}, }; int exceeds_moddatatype_limit(int type, int slot) @@ -56,15 +56,15 @@ int exceeds_moddatatype_limit(int type, int slot) if (slot >= moddatatypelimits[i].limit) { unreal_log(ULOG_ERROR, "module", "MOD_DATA_OUT_OF_SPACE", NULL, - "ModDataAdd: out of space! Your $mod_data_type limit of $limit is reached. " - "Perhaps you have many third party modules loaded?\n" - "If you need more space then you could open include/config.h and " - "raise $mod_data_type_limit_name. You may also want to raise the other limits " - "there, just to be sure. After changing that file, you will have to " - "recompile (make clean; make install) and restart the IRCd.", - log_data_string("mod_data_type", moddatatypelimits[i].type_name), - log_data_string("mod_data_type_limit_name", moddatatypelimits[i].limit_name), - log_data_integer("limit", moddatatypelimits[i].limit)); + "ModDataAdd: out of space! Your $mod_data_type limit of $limit is reached. " + "Perhaps you have many third party modules loaded?\n" + "If you need more space then you could open include/config.h and " + "raise $mod_data_type_limit_name. You may also want to raise the other limits " + "there, just to be sure. After changing that file, you will have to " + "recompile (make clean; make install) and restart the IRCd.", + log_data_string("mod_data_type", moddatatypelimits[i].type_name), + log_data_string("mod_data_type_limit_name", moddatatypelimits[i].limit_name), + log_data_integer("limit", moddatatypelimits[i].limit)); return 1; } return 0; @@ -90,7 +90,7 @@ void moddatatype_dump(Client *client) #ifdef DEBUGMODE sendtxtnumeric(client, "=== %s ===", moddatatypelimits[i].type_name); #endif - for (position = 0, m = MDInfo[moddatatypelimits[i].type]; m ; m = m->next, position++) + for (position = 0, m = MDInfo[moddatatypelimits[i].type]; m; m = m->next, position++) { #ifdef DEBUGMODE sendtxtnumeric(client, "Position %d: %s", @@ -121,7 +121,7 @@ ModDataInfo *ModDataAdd(Module *module, ModDataInfo req) abort(); /* Hunt for highest available slot */ - for (m = MDInfo[req.type]; m ; m = m->next) + for (m = MDInfo[req.type]; m; m = m->next) { /* Does an entry already exist with this name? */ if (!strcmp(m->name, req.name)) @@ -139,7 +139,7 @@ ModDataInfo *ModDataAdd(Module *module, ModDataInfo req) return NULL; } /* Update next available slot */ - slotav = MAX(slotav, m->slot+1); + slotav = MAX(slotav, m->slot + 1); } if (exceeds_moddatatype_limit(req.type, slotav)) @@ -163,7 +163,7 @@ moddataadd_isok: m->self_write = req.self_write; m->owner = module; m->priority = req.priority; - + if (new_struct) AddListItemPrio(m, MDInfo[req.type], m->priority); @@ -175,7 +175,7 @@ moddataadd_isok: AddListItem(mobj, module->objects); module->errorcode = MODERR_NOERROR; } - + return m; } @@ -237,7 +237,7 @@ void moddata_free_membership(Membership *m) /** Actually free all the ModData from all objects */ void unload_moddata_commit(ModDataInfo *md) { - switch(md->type) + switch (md->type) { case MODDATATYPE_LOCAL_VARIABLE: if (md->free && moddata_local_variable(md).ptr) @@ -286,7 +286,7 @@ void unload_moddata_commit(ModDataInfo *md) case MODDATATYPE_CHANNEL: { Channel *channel; - for (channel = channels; channel; channel=channel->nextch) + for (channel = channels; channel; channel = channel->nextch) { if (md->free && moddata_channel(channel, md).ptr) md->free(&moddata_channel(channel, md)); @@ -298,7 +298,7 @@ void unload_moddata_commit(ModDataInfo *md) { Channel *channel; Member *m; - for (channel = channels; channel; channel=channel->nextch) + for (channel = channels; channel; channel = channel->nextch) { for (m = channel->members; m; m = m->next) { @@ -327,7 +327,7 @@ void unload_moddata_commit(ModDataInfo *md) break; } } - + DelListItem(md, MDInfo[md->type]); safe_free(md->name); safe_free(md); @@ -364,7 +364,8 @@ void ModDataDel(ModDataInfo *md) md->serialize = NULL; md->unserialize = NULL; md->unloaded = 1; - } else { + } else + { /* We need the free function and the like, * and then completely destroy 'md'. */ @@ -387,7 +388,8 @@ void unload_all_unused_moddata(void) //config_status("UNLOADING: md %s (owner %p, type %d, slot %d)", // md->name, md->owner, md->type, md->slot); unload_moddata_commit(md); - } else { + } else + { //config_status("loaded: md %s (owner %p, type %d, slot %d)", // md->name, md->owner, md->type, md->slot); } @@ -433,8 +435,7 @@ int moddata_client_set(Client *client, const char *varname, const char *value) { /* SET */ md->unserialize(value, &moddata_client(client, md)); - } - else + } else { /* UNSET */ md->free(&moddata_client(client, md)); @@ -493,8 +494,7 @@ int moddata_local_client_set(Client *client, const char *varname, const char *va { /* SET */ md->unserialize(value, &moddata_local_client(client, md)); - } - else + } else { /* UNSET */ md->free(&moddata_local_client(client, md)); @@ -540,8 +540,7 @@ int moddata_local_variable_set(const char *varname, const char *value) { /* SET */ md->unserialize(value, &moddata_local_variable(md)); - } - else + } else { /* UNSET */ md->free(&moddata_local_variable(md)); @@ -565,8 +564,7 @@ int moddata_global_variable_set(const char *varname, const char *value) { /* SET */ md->unserialize(value, &moddata_global_variable(md)); - } - else + } else { /* UNSET */ md->free(&moddata_global_variable(md)); diff --git a/src/api-rpc.c b/src/api-rpc.c index 10ea9fb7d..47bee31f8 100644 --- a/src/api-rpc.c +++ b/src/api-rpc.c @@ -38,9 +38,9 @@ RPCHandler *RPCHandlerAdd(Module *module, RPCHandlerInfo *mreq) if (!mreq->method || !mreq->call) { unreal_log(ULOG_ERROR, "module", "RPCHANDLERADD_API_ERROR", NULL, - "RPCHandlerAdd() from module $module_name: " - "Missing required fields.", - log_data_string("module_name", module->header->name)); + "RPCHandlerAdd() from module $module_name: " + "Missing required fields.", + log_data_string("module_name", module->header->name)); abort(); } @@ -50,12 +50,14 @@ RPCHandler *RPCHandlerAdd(Module *module, RPCHandlerInfo *mreq) if (m->unloaded) { m->unloaded = 0; - } else { + } else + { if (module) module->errorcode = MODERR_EXISTS; return NULL; } - } else { + } else + { /* New RPC handler */ m = safe_alloc(sizeof(RPCHandler)); safe_strdup(m->method, mreq->method); @@ -106,7 +108,8 @@ void RPCHandlerDel(RPCHandler *m) if (m->owner) { ModuleObject *mobj; - for (mobj = m->owner->objects; mobj; mobj = mobj->next) { + for (mobj = m->owner->objects; mobj; mobj = mobj->next) + { if (mobj->type == MOBJ_RPC && mobj->object.rpc == m) { DelListItem(mobj, m->owner->objects); diff --git a/src/api-usermode.c b/src/api-usermode.c index 5bb8b4229..da24b071b 100644 --- a/src/api-usermode.c +++ b/src/api-usermode.c @@ -22,7 +22,7 @@ #include "unrealircd.h" -char umodestring[UMODETABLESZ+1]; +char umodestring[UMODETABLESZ + 1]; /** User modes and their handlers */ Umode *usermodes = NULL; @@ -53,8 +53,8 @@ long SNO_SPAMF = 0L; long SNO_SNOTICE = 0L; long SNO_OPER = 0L; -long AllUmodes; /* All umodes */ -long SendUmodes; /* All umodes which are sent to other servers (global umodes) */ +long AllUmodes; /* All umodes */ +long SendUmodes; /* All umodes which are sent to other servers (global umodes) */ Umode *umode_letter_to_handler[256]; @@ -83,7 +83,7 @@ void make_umodestr(void) Umode *um; char *p = umodestring; - for (um=usermodes; um; um = um->next) + for (um = usermodes; um; um = um->next) { if (um->letter) { @@ -177,7 +177,7 @@ Umode *UmodeAdd(Module *module, char ch, int global, int unset_on_deoper, int (* Umode *um; int existing = 0; - for (um=usermodes; um; um = um->next) + for (um = usermodes; um; um = um->next) { if (um->letter == ch) { @@ -186,7 +186,8 @@ Umode *UmodeAdd(Module *module, char ch, int global, int unset_on_deoper, int (* um->unloaded = 0; existing = 1; break; - } else { + } else + { if (module) module->errorcode = MODERR_EXISTS; return NULL; @@ -198,10 +199,10 @@ Umode *UmodeAdd(Module *module, char ch, int global, int unset_on_deoper, int (* { /* Not found, create */ long l, found = 0; - for (l = 1; l < LONG_MAX/2; l *= 2) + for (l = 1; l < LONG_MAX / 2; l *= 2) { found = 0; - for (um=usermodes; um; um = um->next) + for (um = usermodes; um; um = um->next) { if (um->mode == l) { @@ -216,7 +217,7 @@ Umode *UmodeAdd(Module *module, char ch, int global, int unset_on_deoper, int (* if (found) { unreal_log(ULOG_ERROR, "module", "USER_MODE_OUT_OF_SPACE", NULL, - "UmodeAdd: out of space!!!"); + "UmodeAdd: out of space!!!"); if (module) module->errorcode = MODERR_NOSPACE; return NULL; @@ -225,7 +226,8 @@ Umode *UmodeAdd(Module *module, char ch, int global, int unset_on_deoper, int (* um->letter = ch; um->mode = l; usermode_add_sorted(um); - } else { + } else + { umode_letter_to_handler[um->letter] = um; } @@ -353,7 +355,7 @@ void unload_all_unused_umodes(void) { Umode *um, *um_next; - for (um=usermodes; um; um = um_next) + for (um = usermodes; um; um = um_next) { um_next = um->next; if (um->letter && um->unloaded) diff --git a/src/auth.c b/src/auth.c index c9bb6a160..c83a69fba 100644 --- a/src/auth.c +++ b/src/auth.c @@ -23,26 +23,26 @@ typedef struct AuthTypeList AuthTypeList; struct AuthTypeList { - char *name; - AuthenticationType type; + char *name; + AuthenticationType type; }; /** The list of authentication types that we support. */ AuthTypeList MODVAR AuthTypeLists[] = { - {"plain", AUTHTYPE_PLAINTEXT}, - {"plaintext", AUTHTYPE_PLAINTEXT}, - {"crypt", AUTHTYPE_UNIXCRYPT}, - {"unixcrypt", AUTHTYPE_UNIXCRYPT}, - {"bcrypt", AUTHTYPE_BCRYPT}, - {"cert", AUTHTYPE_TLS_CLIENTCERT}, - {"sslclientcert", AUTHTYPE_TLS_CLIENTCERT}, - {"tlsclientcert", AUTHTYPE_TLS_CLIENTCERT}, - {"certfp", AUTHTYPE_TLS_CLIENTCERTFP}, - {"sslclientcertfp", AUTHTYPE_TLS_CLIENTCERTFP}, - {"tlsclientcertfp", AUTHTYPE_TLS_CLIENTCERTFP}, - {"spkifp", AUTHTYPE_SPKIFP}, - {"argon2", AUTHTYPE_ARGON2}, - {NULL, 0}, + {"plain", AUTHTYPE_PLAINTEXT}, + {"plaintext", AUTHTYPE_PLAINTEXT}, + {"crypt", AUTHTYPE_UNIXCRYPT}, + {"unixcrypt", AUTHTYPE_UNIXCRYPT}, + {"bcrypt", AUTHTYPE_BCRYPT}, + {"cert", AUTHTYPE_TLS_CLIENTCERT}, + {"sslclientcert", AUTHTYPE_TLS_CLIENTCERT}, + {"tlsclientcert", AUTHTYPE_TLS_CLIENTCERT}, + {"certfp", AUTHTYPE_TLS_CLIENTCERTFP}, + {"sslclientcertfp", AUTHTYPE_TLS_CLIENTCERTFP}, + {"tlsclientcertfp", AUTHTYPE_TLS_CLIENTCERTFP}, + {"spkifp", AUTHTYPE_SPKIFP}, + {"argon2", AUTHTYPE_ARGON2}, + {NULL, 0}, }; /* Forward declarations */ @@ -58,15 +58,15 @@ static int parsepass(const char *str, char **salt, char **hash) /* Syntax: $$ */ if (*str != '$') return 0; - p = strchr(str+1, '$'); - if (!p || (p == str+1) || !p[1]) + p = strchr(str + 1, '$'); + if (!p || (p == str + 1) || !p[1]) return 0; max = p - str; if (max > sizeof(saltbuf)) max = sizeof(saltbuf); - strlcpy(saltbuf, str+1, max); - strlcpy(hashbuf, p+1, sizeof(hashbuf)); + strlcpy(saltbuf, str + 1, max); + strlcpy(hashbuf, p + 1, sizeof(hashbuf)); *salt = saltbuf; *hash = hashbuf; return 1; @@ -116,13 +116,13 @@ int Auth_AutoDetectHashType(const char *hash) 112 | if ((*hash != '$') || !strchr(hash+1, '$')) */ #if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstringop-overread" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-overread" #endif - if ((*hash != '$') || !strchr(hash+1, '$')) + if ((*hash != '$') || !strchr(hash + 1, '$')) return AUTHTYPE_PLAINTEXT; #if defined(__GNUC__) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif if (!strncmp(hash, "$2a$", 4) || !strncmp(hash, "$2b$", 4) || !strncmp(hash, "$2y$", 4)) @@ -182,13 +182,13 @@ int Auth_CheckError(ConfigEntry *ce, int warn_on_plaintext) if (!ce->value) { config_error("%s:%i: authentication module failure: missing parameter", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return -1; } if (ce->items && ce->items->next) { config_error("%s:%i: you may not have multiple authentication methods", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return -1; } @@ -196,8 +196,8 @@ int Auth_CheckError(ConfigEntry *ce, int warn_on_plaintext) if (type == -1) { config_error("%s:%i: authentication module failure: %s is not an implemented/enabled authentication method", - ce->file->filename, ce->line_number, - ce->items->name); + ce->file->filename, ce->line_number, + ce->items->name); return -1; } @@ -208,13 +208,13 @@ int Auth_CheckError(ConfigEntry *ce, int warn_on_plaintext) { const char *hashedpass = mkpass_argon2(ce->value); unreal_log(ULOG_ADVICE, "config", "BEST_PRACTICES_HASHED_PASSWORDS", NULL, - "$file:$line_number: $config_item: Advice: it is not recommended to use plaintext passwords in the config file. " - "You can replace this password with the following password hash:\n" - "password \"$hashed_password\";", - log_data_string("config_item", config_item_name(ce)), - log_data_string("file", ce->file->filename), - log_data_integer("line_number", ce->line_number), - log_data_string("hashed_password", hashedpass)); + "$file:$line_number: $config_item: Advice: it is not recommended to use plaintext passwords in the config file. " + "You can replace this password with the following password hash:\n" + "password \"$hashed_password\";", + log_data_string("config_item", config_item_name(ce)), + log_data_string("file", ce->file->filename), + log_data_integer("line_number", ce->line_number), + log_data_string("hashed_password", hashedpass)); bestpractices.hashed_passwords_hits++; } break; @@ -223,7 +223,7 @@ int Auth_CheckError(ConfigEntry *ce, int warn_on_plaintext) if (strlen(ce->value) < 2) { config_error("%s:%i: authentication module failure: AUTHTYPE_UNIXCRYPT: no salt (crypt strings will always be >2 in length)", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return -1; } break; @@ -232,7 +232,7 @@ int Auth_CheckError(ConfigEntry *ce, int warn_on_plaintext) if (!(x509_f = fopen(ce->value, "r"))) { config_error("%s:%i: authentication module failure: AUTHTYPE_TLS_CLIENTCERT: error opening file %s: %s", - ce->file->filename, ce->line_number, ce->value, strerror(errno)); + ce->file->filename, ce->line_number, ce->value, strerror(errno)); return -1; } x509_filecert = PEM_read_X509(x509_f, NULL, NULL, NULL); @@ -240,12 +240,12 @@ int Auth_CheckError(ConfigEntry *ce, int warn_on_plaintext) if (!x509_filecert) { config_error("%s:%i: authentication module failure: AUTHTYPE_TLS_CLIENTCERT: PEM_read_X509 errored in file %s (format error?)", - ce->file->filename, ce->line_number, ce->value); + ce->file->filename, ce->line_number, ce->value); return -1; } X509_free(x509_filecert); break; - default: ; + default:; } /* Unix crypt is a bit more complicated: most types are outright 'bad', @@ -263,13 +263,13 @@ int Auth_CheckError(ConfigEntry *ce, int warn_on_plaintext) config_warn("%s:%i: Using simple crypt for authentication is not recommended. " "Consider using the more secure auth-type 'argon2' instead. " "See https://www.unrealircd.org/docs/Authentication_types for the complete list.", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); /* do not return, not an error. */ } if ((type == AUTHTYPE_PLAINTEXT) && (strlen(ce->value) > PASSWDLEN)) { config_error("%s:%i: passwords length may not exceed %d", - ce->file->filename, ce->line_number, PASSWDLEN); + ce->file->filename, ce->line_number, PASSWDLEN); return -1; } return 1; @@ -310,8 +310,8 @@ void Auth_FreeAuthConfig(AuthConfig *as) * and REAL salt length (after b64_encode, including terminating nul), * used for reserving memory. */ -#define RAWSALTLEN 6 -#define REALSALTLEN 12 +#define RAWSALTLEN 6 +#define REALSALTLEN 12 static int authcheck_argon2(Client *client, AuthConfig *as, const char *para) { @@ -411,7 +411,7 @@ static int authcheck_tls_clientcert_fingerprint(Client *client, AuthConfig *as, /* Check colon version, so that we keep in line with * previous versions, based on Nath's patch -dboyz */ - for (i=0, k=0; idata, "changemeplease") && !strcmp(para, as->data)) { unreal_log(ULOG_INFO, "auth", "AUTH_REJECT_DEFAULT_PASSWORD", client, - "Rejecting default password 'changemeplease'. " - "Please change the password in the configuration file."); + "Rejecting default password 'changemeplease'. " + "Please change the password in the configuration file."); return 0; } /* plain text compare */ @@ -526,11 +526,11 @@ int Auth_Check(Client *client, AuthConfig *as, const char *para) return 0; } -#define UNREALIRCD_ARGON2_DEFAULT_TIME_COST 2 -#define UNREALIRCD_ARGON2_DEFAULT_MEMORY_COST 6144 -#define UNREALIRCD_ARGON2_DEFAULT_PARALLELISM_COST 2 -#define UNREALIRCD_ARGON2_DEFAULT_HASH_LENGTH 32 -#define UNREALIRCD_ARGON2_DEFAULT_SALT_LENGTH (128/8) +#define UNREALIRCD_ARGON2_DEFAULT_TIME_COST 2 +#define UNREALIRCD_ARGON2_DEFAULT_MEMORY_COST 6144 +#define UNREALIRCD_ARGON2_DEFAULT_PARALLELISM_COST 2 +#define UNREALIRCD_ARGON2_DEFAULT_HASH_LENGTH 32 +#define UNREALIRCD_ARGON2_DEFAULT_SALT_LENGTH (128 / 8) static char *mkpass_argon2(const char *para) { @@ -542,7 +542,7 @@ static char *mkpass_argon2(const char *para) return NULL; /* Initialize salt */ - for (i=0; i < sizeof(salt); i++) + for (i = 0; i < sizeof(salt); i++) salt[i] = getrandom8(); *buf = '\0'; @@ -579,7 +579,7 @@ static char *mkpass_bcrypt(const char *para) memset(data, 0, sizeof(data)); - for (i=0; ibanstr, banid, MAXBANLEN+1); /* cAsE may differ, use oldest version of it */ - safe_strldup(ban->who, setby, NICKLEN+USERLEN+HOSTLEN+4); + safe_strldup(ban->banstr, banid, MAXBANLEN + 1); /* cAsE may differ, use oldest version of it */ + safe_strldup(ban->who, setby, NICKLEN + USERLEN + HOSTLEN + 4); ban->when = seton; return isnew ? 1 : 0; } @@ -310,7 +311,7 @@ int add_listmode_ex(Ban **list, Client *client, Channel *channel, const char *ba int add_listmode(Ban **list, Client *client, Channel *channel, const char *banid) { char *setby = client->name; - char nuhbuf[NICKLEN+USERLEN+HOSTLEN+4]; + char nuhbuf[NICKLEN + USERLEN + HOSTLEN + 4]; if (IsUser(client) && (iConf.ban_setter == SETTER_NICK_USER_HOST)) setby = make_nick_user_host_r(nuhbuf, sizeof(nuhbuf), client->name, client->user->username, GetHost(client)); @@ -373,12 +374,12 @@ inline int ban_check_mask(BanContext *b) if (!extban || !(extban->is_banned_events & b->ban_check_types)) { return 0; - } else { + } else + { b->banstr = nextbanstr; return extban->is_banned(b); } - } - else + } else { /* Is a n!u@h mask. */ return match_user(b->banstr, b->client, MATCH_CHECK_ALL); @@ -396,7 +397,7 @@ inline int ban_check_mask(BanContext *b) Ban *is_banned_with_nick(Client *client, Channel *channel, int type, const char *nick, const char **msg, const char **errmsg) { Ban *ban, *ex; - char savednick[NICKLEN+1]; + char savednick[NICKLEN + 1]; BanContext *b = safe_alloc(sizeof(BanContext)); /* It's not really doable to pass 'nick' to all the ban layers, @@ -490,7 +491,7 @@ int ban_exists_ignore_time(Ban *lst, const char *str) if (!strncmp(lst->banstr, "~time:", 6)) { /* Special treatment for ~time:xx: */ - p = strchr(lst->banstr+6, ':'); + p = strchr(lst->banstr + 6, ':'); if (p) { p++; @@ -588,12 +589,13 @@ int remove_user_from_channel_withmb(Client *client, Channel *channel, Membership if (MyUser(client)) { unreal_log(ULOG_INFO, "part", "LOCAL_CLIENT_PART", client, - "User $client left $channel", - log_data_channel("channel", channel)); - } else { + "User $client left $channel", + log_data_channel("channel", channel)); + } else + { unreal_log(ULOG_INFO, "part", "REMOTE_CLIENT_PART", client, - "User $client left $channel", - log_data_channel("channel", channel)); + "User $client left $channel", + log_data_channel("channel", channel)); } } @@ -633,7 +635,7 @@ int has_channel_mode(Channel *channel, char mode) { Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->letter == mode) && (channel->mode.mode & cm->mode)) return 1; @@ -645,7 +647,7 @@ int has_channel_mode_raw(Cmode_t m, char mode) { Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) if ((cm->letter == mode) && (m & cm->mode)) return 1; @@ -657,11 +659,11 @@ Cmode_t get_extmode_bitbychar(char m) { Cmode *cm; - for (cm=channelmodes; cm; cm = cm->next) - if (cm->letter == m) - return cm->mode; + for (cm = channelmodes; cm; cm = cm->next) + if (cm->letter == m) + return cm->mode; - return 0; + return 0; } /** Write the "simple" list of channel modes for channel channel onto buffer mbuf with the parameters in pbuf. @@ -683,7 +685,7 @@ void channel_modes(Client *client, char *mbuf, char *pbuf, size_t mbuf_size, siz return; if (!client || IsMember(client, channel) || IsServer(client) || IsMe(client) || IsULine(client) || - ValidatePermissionsForPath("channel:see:mode:remote",client,NULL,channel,NULL)) + ValidatePermissionsForPath("channel:see:mode:remote", client, NULL, channel, NULL)) { show_mode_parameters = 1; } @@ -691,7 +693,7 @@ void channel_modes(Client *client, char *mbuf, char *pbuf, size_t mbuf_size, siz *pbuf = '\0'; strlcpy(mbuf, "+", mbuf_size); - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (cm->letter && !(hide_local_modes && cm->local) && @@ -712,7 +714,7 @@ void channel_modes(Client *client, char *mbuf, char *pbuf, size_t mbuf_size, siz /* Remove the trailing space from the parameters -- codemastr */ if (*pbuf) - pbuf[strlen(pbuf)-1]='\0'; + pbuf[strlen(pbuf) - 1] = '\0'; } /** Make a pretty mask from the input string - only used by SILENCE @@ -732,8 +734,7 @@ char *pretty_mask(const char *mask_in) *host++ = '\0'; if (!user) return make_nick_user_host(NULL, cp, host); - } - else if (!user && strchr(cp, '.')) + } else if (!user && strchr(cp, '.')) { return make_nick_user_host(NULL, NULL, cp); } @@ -797,16 +798,15 @@ const char *convert_regular_ban(char *mask, char *buf, size_t buflen) { *host++ = '\0'; if (!user) - return make_nick_user_host_r(buf, buflen, NULL, trim_str(mask,USERLEN), trim_str(host,HOSTLEN)); - } - else if (!user && (strchr(mask, '.') || strchr(mask, ':'))) + return make_nick_user_host_r(buf, buflen, NULL, trim_str(mask, USERLEN), trim_str(host, HOSTLEN)); + } else if (!user && (strchr(mask, '.') || strchr(mask, ':'))) { /* 1.2.3.4 -> *!*@1.2.3.4 (and the same for IPv6) */ - return make_nick_user_host_r(buf, buflen, NULL, NULL, trim_str(mask,HOSTLEN)); + return make_nick_user_host_r(buf, buflen, NULL, NULL, trim_str(mask, HOSTLEN)); } /* regular nick!user@host with the auto-trimming feature */ - return make_nick_user_host_r(buf, buflen, trim_str(mask,NICKLEN), trim_str(user,USERLEN), trim_str(host,HOSTLEN)); + return make_nick_user_host_r(buf, buflen, trim_str(mask, NICKLEN), trim_str(user, USERLEN), trim_str(host, HOSTLEN)); } /** Make a proper ban mask. @@ -829,7 +829,8 @@ const char *clean_ban_mask(const char *mask_in, int what, ExtbanType ban_type, C static char mask[512]; /* Strip any ':' at beginning since that would cause a desync */ - for (; (*mask_in && (*mask_in == ':')); mask_in++); + for (; (*mask_in && (*mask_in == ':')); mask_in++) + ; if (!*mask_in) return NULL; @@ -890,7 +891,7 @@ const char *clean_ban_mask(const char *mask_in, int what, ExtbanType ban_type, C } /* else, do some basic sanity checks and cut it off at 80 bytes */ if ((mask[1] != ':') || (mask[2] == '\0')) - return NULL; /* require a ":" after extban type */ + return NULL; /* require a ":" after extban type */ if (strlen(mask) > 80) mask[80] = '\0'; return mask; @@ -947,8 +948,7 @@ int valid_channelname(const char *cname) if (*p < 33 || *p == ',' || *p == ':') return 0; } - } else - if (iConf.allowed_channelchars == ALLOWED_CHANNELCHARS_ASCII) + } else if (iConf.allowed_channelchars == ALLOWED_CHANNELCHARS_ASCII) { /* The strict setting: only allow ASCII 32-128, except some chars */ for (p = cname; *p; p++) @@ -956,8 +956,7 @@ int valid_channelname(const char *cname) if (*p < 33 || *p == ',' || *p == ':' || *p > 127) return 0; } - } else - if (iConf.allowed_channelchars == ALLOWED_CHANNELCHARS_UTF8) + } else if (iConf.allowed_channelchars == ALLOWED_CHANNELCHARS_UTF8) { /* Only allow UTF8, and also disallow some chars */ for (p = cname; *p; p++) @@ -994,7 +993,7 @@ Channel *make_channel(const char *name) Channel *channel; int len; char *p; - char namebuf[CHANNELLEN+1]; + char namebuf[CHANNELLEN + 1]; if (BadPtr(name)) return NULL; @@ -1135,8 +1134,8 @@ void set_channel_mlock(Client *client, Channel *channel, const char *newmlock, i if (propagate) { sendto_server(client, 0, 0, NULL, ":%s MLOCK %lld %s :%s", - client->id, (long long)channel->creationtime, channel->name, - BadPtr(channel->mode_lock) ? "" : channel->mode_lock); + client->id, (long long)channel->creationtime, channel->name, + BadPtr(channel->mode_lock) ? "" : channel->mode_lock); } } @@ -1169,7 +1168,7 @@ int parse_chanmode(ParseMode *pm, const char *modebuf_in, const char *parabuf_in pm->what = MODE_ADD; } - while(1) + while (1) { if (*pm->modebuf == '\0') return 0; @@ -1178,14 +1177,12 @@ int parse_chanmode(ParseMode *pm, const char *modebuf_in, const char *parabuf_in pm->what = MODE_ADD; pm->modebuf++; continue; - } - else if (*pm->modebuf == '-') + } else if (*pm->modebuf == '-') { pm->what = MODE_DEL; pm->modebuf++; continue; - } - else + } else { CoreChannelModeTable *tab = &corechannelmodetable[0]; Cmode *cm; @@ -1210,10 +1207,11 @@ int parse_chanmode(ParseMode *pm, const char *modebuf_in, const char *parabuf_in { eatparam = 1; } - } else { + } else + { /* EXTENDED CHANNEL MODE */ int found = 0; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (cm->letter == *pm->modebuf) { @@ -1244,7 +1242,8 @@ int parse_chanmode(ParseMode *pm, const char *modebuf_in, const char *parabuf_in if (pm->parabuf && *pm->parabuf) { const char *start, *end; - for (; *pm->parabuf == ' '; pm->parabuf++); /* skip whitespace */ + for (; *pm->parabuf == ' '; pm->parabuf++) + ; /* skip whitespace */ start = pm->parabuf; if (*pm->parabuf == '\0') { @@ -1259,15 +1258,15 @@ int parse_chanmode(ParseMode *pm, const char *modebuf_in, const char *parabuf_in if (end - start + 1 > sizeof(pm->buf)) end = start + sizeof(pm->buf); /* 'never' reached */ strlcpy(pm->buf, start, end - start + 1); - } - else + } else { strlcpy(pm->buf, start, sizeof(pm->buf)); pm->parabuf = pm->parabuf + strlen(pm->parabuf); /* point to \0 at end */ } stripcrlf(pm->buf); /* needed for unreal_server_compat.c */ pm->param = pm->buf; - } else { + } else + { pm->modebuf++; continue; /* invalid, got mode but no parameter available */ } @@ -1413,7 +1412,8 @@ void set_user_invisible(Client *client, Channel *channel, int invisible) { m->memb_flags |= MEMB_FLAG_INVISIBLE; m->related->memb_flags |= MEMB_FLAG_INVISIBLE; - } else { + } else + { m->memb_flags &= ~MEMB_FLAG_INVISIBLE; m->related->memb_flags &= ~MEMB_FLAG_INVISIBLE; } @@ -1431,12 +1431,12 @@ void send_invalid_channelname(Client *client, const char *channelname) if (*channelname != '#') { reason = "Channel name must start with a hash mark (#)"; - } else - if (strlen(channelname) > CHANNELLEN) + } else if (strlen(channelname) > CHANNELLEN) { reason = "Channel name is too long"; - } else { - switch(iConf.allowed_channelchars) + } else + { + switch (iConf.allowed_channelchars) { case ALLOWED_CHANNELCHARS_ASCII: reason = "Channel name contains illegal characters (must be ASCII)"; @@ -1463,7 +1463,7 @@ int is_extended_ban(const char *str) if (*str != '~') return 0; - for (p = str+1; *p; p++) + for (p = str + 1; *p; p++) { if (!isalnum(*p)) { @@ -1505,7 +1505,7 @@ void free_multilinemode(MultiLineMode *m) int i; if (m == NULL) return; - for (i=0; i < m->numlines; i++) + for (i = 0; i < m->numlines; i++) { safe_free(m->modeline[i]); safe_free(m->paramline[i]); diff --git a/src/conf.c b/src/conf.c index 53051a5e1..0f1125c20 100644 --- a/src/conf.c +++ b/src/conf.c @@ -24,78 +24,77 @@ * Some typedefs.. */ typedef struct ConfigCommand ConfigCommand; -struct ConfigCommand -{ - char *name; - int (*conffunc)(ConfigFile *conf, ConfigEntry *ce); - int (*testfunc)(ConfigFile *conf, ConfigEntry *ce); +struct ConfigCommand { + char *name; + int (*conffunc)(ConfigFile *conf, ConfigEntry *ce); + int (*testfunc)(ConfigFile *conf, ConfigEntry *ce); }; /* Config commands */ -static int _conf_admin (ConfigFile *conf, ConfigEntry *ce); -static int _conf_me (ConfigFile *conf, ConfigEntry *ce); -static int _conf_files (ConfigFile *conf, ConfigEntry *ce); -static int _conf_oper (ConfigFile *conf, ConfigEntry *ce); -static int _conf_operclass (ConfigFile *conf, ConfigEntry *ce); -static int _conf_class (ConfigFile *conf, ConfigEntry *ce); -static int _conf_drpass (ConfigFile *conf, ConfigEntry *ce); -static int _conf_ulines (ConfigFile *conf, ConfigEntry *ce); -static int _conf_include (ConfigFile *conf, ConfigEntry *ce); -static int _conf_tld (ConfigFile *conf, ConfigEntry *ce); -static int _conf_listen (ConfigFile *conf, ConfigEntry *ce); -static int _conf_allow (ConfigFile *conf, ConfigEntry *ce); -static int _conf_except (ConfigFile *conf, ConfigEntry *ce); -static int _conf_link (ConfigFile *conf, ConfigEntry *ce); -static int _conf_ban (ConfigFile *conf, ConfigEntry *ce); -static int _conf_set (ConfigFile *conf, ConfigEntry *ce); -static int _conf_deny (ConfigFile *conf, ConfigEntry *ce); -static int _conf_deny_channel (ConfigFile *conf, ConfigEntry *ce); -static int _conf_deny_version (ConfigFile *conf, ConfigEntry *ce); -static int _conf_require (ConfigFile *conf, ConfigEntry *ce); -static int _conf_allow_channel (ConfigFile *conf, ConfigEntry *ce); -static int _conf_loadmodule (ConfigFile *conf, ConfigEntry *ce); -static int _conf_alias (ConfigFile *conf, ConfigEntry *ce); -static int _conf_help (ConfigFile *conf, ConfigEntry *ce); -static int _conf_offchans (ConfigFile *conf, ConfigEntry *ce); -static int _conf_sni (ConfigFile *conf, ConfigEntry *ce); -extern int _conf_security_group (ConfigFile *conf, ConfigEntry *ce); -static int _conf_secret (ConfigFile *conf, ConfigEntry *ce); -static int _conf_proxy (ConfigFile *conf, ConfigEntry *ce); +static int _conf_admin(ConfigFile *conf, ConfigEntry *ce); +static int _conf_me(ConfigFile *conf, ConfigEntry *ce); +static int _conf_files(ConfigFile *conf, ConfigEntry *ce); +static int _conf_oper(ConfigFile *conf, ConfigEntry *ce); +static int _conf_operclass(ConfigFile *conf, ConfigEntry *ce); +static int _conf_class(ConfigFile *conf, ConfigEntry *ce); +static int _conf_drpass(ConfigFile *conf, ConfigEntry *ce); +static int _conf_ulines(ConfigFile *conf, ConfigEntry *ce); +static int _conf_include(ConfigFile *conf, ConfigEntry *ce); +static int _conf_tld(ConfigFile *conf, ConfigEntry *ce); +static int _conf_listen(ConfigFile *conf, ConfigEntry *ce); +static int _conf_allow(ConfigFile *conf, ConfigEntry *ce); +static int _conf_except(ConfigFile *conf, ConfigEntry *ce); +static int _conf_link(ConfigFile *conf, ConfigEntry *ce); +static int _conf_ban(ConfigFile *conf, ConfigEntry *ce); +static int _conf_set(ConfigFile *conf, ConfigEntry *ce); +static int _conf_deny(ConfigFile *conf, ConfigEntry *ce); +static int _conf_deny_channel(ConfigFile *conf, ConfigEntry *ce); +static int _conf_deny_version(ConfigFile *conf, ConfigEntry *ce); +static int _conf_require(ConfigFile *conf, ConfigEntry *ce); +static int _conf_allow_channel(ConfigFile *conf, ConfigEntry *ce); +static int _conf_loadmodule(ConfigFile *conf, ConfigEntry *ce); +static int _conf_alias(ConfigFile *conf, ConfigEntry *ce); +static int _conf_help(ConfigFile *conf, ConfigEntry *ce); +static int _conf_offchans(ConfigFile *conf, ConfigEntry *ce); +static int _conf_sni(ConfigFile *conf, ConfigEntry *ce); +extern int _conf_security_group(ConfigFile *conf, ConfigEntry *ce); +static int _conf_secret(ConfigFile *conf, ConfigEntry *ce); +static int _conf_proxy(ConfigFile *conf, ConfigEntry *ce); /* * Validation commands */ -static int _test_admin (ConfigFile *conf, ConfigEntry *ce); -static int _test_me (ConfigFile *conf, ConfigEntry *ce); -static int _test_files (ConfigFile *conf, ConfigEntry *ce); -static int _test_oper (ConfigFile *conf, ConfigEntry *ce); -static int _test_operclass (ConfigFile *conf, ConfigEntry *ce); -static int _test_class (ConfigFile *conf, ConfigEntry *ce); -static int _test_drpass (ConfigFile *conf, ConfigEntry *ce); -static int _test_ulines (ConfigFile *conf, ConfigEntry *ce); -static int _test_include (ConfigFile *conf, ConfigEntry *ce); -static int _test_tld (ConfigFile *conf, ConfigEntry *ce); -static int _test_listen (ConfigFile *conf, ConfigEntry *ce); -static int _test_allow (ConfigFile *conf, ConfigEntry *ce); -static int _test_except (ConfigFile *conf, ConfigEntry *ce); -static int _test_link (ConfigFile *conf, ConfigEntry *ce); -static int _test_ban (ConfigFile *conf, ConfigEntry *ce); -static int _test_require (ConfigFile *conf, ConfigEntry *ce); -static int _test_set (ConfigFile *conf, ConfigEntry *ce); -static int _test_deny (ConfigFile *conf, ConfigEntry *ce); -static int _test_allow_channel (ConfigFile *conf, ConfigEntry *ce); -static int _test_loadmodule (ConfigFile *conf, ConfigEntry *ce); -static int _test_blacklist_module (ConfigFile *conf, ConfigEntry *ce); -static int _test_alias (ConfigFile *conf, ConfigEntry *ce); -static int _test_help (ConfigFile *conf, ConfigEntry *ce); -static int _test_offchans (ConfigFile *conf, ConfigEntry *ce); -static int _test_sni (ConfigFile *conf, ConfigEntry *ce); -extern int _test_security_group (ConfigFile *conf, ConfigEntry *ce); -static int _test_secret (ConfigFile *conf, ConfigEntry *ce); -static int _test_proxy (ConfigFile *conf, ConfigEntry *ce); +static int _test_admin(ConfigFile *conf, ConfigEntry *ce); +static int _test_me(ConfigFile *conf, ConfigEntry *ce); +static int _test_files(ConfigFile *conf, ConfigEntry *ce); +static int _test_oper(ConfigFile *conf, ConfigEntry *ce); +static int _test_operclass(ConfigFile *conf, ConfigEntry *ce); +static int _test_class(ConfigFile *conf, ConfigEntry *ce); +static int _test_drpass(ConfigFile *conf, ConfigEntry *ce); +static int _test_ulines(ConfigFile *conf, ConfigEntry *ce); +static int _test_include(ConfigFile *conf, ConfigEntry *ce); +static int _test_tld(ConfigFile *conf, ConfigEntry *ce); +static int _test_listen(ConfigFile *conf, ConfigEntry *ce); +static int _test_allow(ConfigFile *conf, ConfigEntry *ce); +static int _test_except(ConfigFile *conf, ConfigEntry *ce); +static int _test_link(ConfigFile *conf, ConfigEntry *ce); +static int _test_ban(ConfigFile *conf, ConfigEntry *ce); +static int _test_require(ConfigFile *conf, ConfigEntry *ce); +static int _test_set(ConfigFile *conf, ConfigEntry *ce); +static int _test_deny(ConfigFile *conf, ConfigEntry *ce); +static int _test_allow_channel(ConfigFile *conf, ConfigEntry *ce); +static int _test_loadmodule(ConfigFile *conf, ConfigEntry *ce); +static int _test_blacklist_module(ConfigFile *conf, ConfigEntry *ce); +static int _test_alias(ConfigFile *conf, ConfigEntry *ce); +static int _test_help(ConfigFile *conf, ConfigEntry *ce); +static int _test_offchans(ConfigFile *conf, ConfigEntry *ce); +static int _test_sni(ConfigFile *conf, ConfigEntry *ce); +extern int _test_security_group(ConfigFile *conf, ConfigEntry *ce); +static int _test_secret(ConfigFile *conf, ConfigEntry *ce); +static int _test_proxy(ConfigFile *conf, ConfigEntry *ce); /* This MUST be alphabetized */ /* clang-format off */ @@ -134,34 +133,34 @@ static ConfigCommand _ConfigCommands[] = { /* This MUST be alphabetized */ static NameValue _ListenerFlags[] = { - { LISTENER_CLIENTSONLY, "clientsonly"}, - { LISTENER_DEFER_ACCEPT, "defer-accept"}, - { LISTENER_SERVERSONLY, "serversonly"}, - { LISTENER_TLS, "ssl"}, - { LISTENER_NORMAL, "standard"}, - { LISTENER_TLS, "tls"}, + {LISTENER_CLIENTSONLY, "clientsonly"}, + {LISTENER_DEFER_ACCEPT, "defer-accept"}, + {LISTENER_SERVERSONLY, "serversonly"}, + {LISTENER_TLS, "ssl"}, + {LISTENER_NORMAL, "standard"}, + {LISTENER_TLS, "tls"}, }; /* This MUST be alphabetized */ static NameValue _LinkOutgoingFlags[] = { - { CONNECT_OUTGOING_AUTO, "autoconnect" }, - { CONNECT_OUTGOING_INSECURE, "insecure" }, - { CONNECT_QUARANTINE, "quarantine"}, - { CONNECT_OUTGOING_TLS, "ssl" }, - { CONNECT_OUTGOING_TLS, "tls" }, + {CONNECT_OUTGOING_AUTO, "autoconnect"}, + {CONNECT_OUTGOING_INSECURE, "insecure"}, + {CONNECT_QUARANTINE, "quarantine"}, + {CONNECT_OUTGOING_TLS, "ssl"}, + {CONNECT_OUTGOING_TLS, "tls"}, }; /* This MUST be alphabetized */ static NameValue _LinkFlags[] = { - { CONNECT_NO_CERTIFICATE_VERIFICATION, "no-certificate-verification"}, - { CONNECT_QUARANTINE, "quarantine"}, + {CONNECT_NO_CERTIFICATE_VERIFICATION, "no-certificate-verification"}, + {CONNECT_QUARANTINE, "quarantine"}, }; /* This MUST be alphabetized */ static NameValue _TLSFlags[] = { - { TLSFLAG_FAILIFNOCERT, "fail-if-no-clientcert" }, - { TLSFLAG_DISABLECLIENTCERT, "no-client-certificate" }, - { TLSFLAG_NOSTARTTLS, "no-starttls" }, + {TLSFLAG_FAILIFNOCERT, "fail-if-no-clientcert"}, + {TLSFLAG_DISABLECLIENTCERT, "no-client-certificate"}, + {TLSFLAG_NOSTARTTLS, "no-starttls"}, }; struct { @@ -177,18 +176,18 @@ struct SetCheck settings; * Utilities */ -void port_range(const char *string, int *start, int *end); -long config_checkval(const char *value, unsigned short flags); +void port_range(const char *string, int *start, int *end); +long config_checkval(const char *value, unsigned short flags); /* * Parser */ -ConfigFile *config_load(const char *filename, const char *displayname); -void config_free(ConfigFile *cfptr); -ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsigned int line_offset); -ConfigFile *config_parse(const char *filename, char *confdata); -ConfigEntry *config_find_entry(ConfigEntry *ce, const char *name); +ConfigFile *config_load(const char *filename, const char *displayname); +void config_free(ConfigFile *cfptr); +ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsigned int line_offset); +ConfigFile *config_parse(const char *filename, char *confdata); +ConfigEntry *config_find_entry(ConfigEntry *ce, const char *name); extern void add_entropy_configfile(struct stat *st, const char *buf); extern void unload_all_unused_umodes(void); @@ -209,47 +208,47 @@ void free_tls_options(TLSOptions *tlsoptions); /* * Config parser (IRCd) */ -int config_read_file(const char *filename, const char *display_name); -void config_rehash(void); -int config_run_blocks(void); -int config_test_blocks(); +int config_read_file(const char *filename, const char *display_name); +void config_rehash(void); +int config_run_blocks(void); +int config_test_blocks(); /* * Configuration linked lists */ -ConfigItem_me *conf_me = NULL; -ConfigItem_files *conf_files = NULL; -ConfigItem_class *conf_class = NULL; -ConfigItem_class *default_class = NULL; -ConfigItem_admin *conf_admin = NULL; -ConfigItem_admin *conf_admin_tail = NULL; -ConfigItem_drpass *conf_drpass = NULL; -ConfigItem_ulines *conf_ulines = NULL; -ConfigItem_tld *conf_tld = NULL; -ConfigItem_oper *conf_oper = NULL; -ConfigItem_operclass *conf_operclass = NULL; -ConfigItem_listen *conf_listen = NULL; -ConfigItem_sni *conf_sni = NULL; -ConfigItem_allow *conf_allow = NULL; -ConfigItem_link *conf_link = NULL; -ConfigItem_ban *conf_ban = NULL; +ConfigItem_me *conf_me = NULL; +ConfigItem_files *conf_files = NULL; +ConfigItem_class *conf_class = NULL; +ConfigItem_class *default_class = NULL; +ConfigItem_admin *conf_admin = NULL; +ConfigItem_admin *conf_admin_tail = NULL; +ConfigItem_drpass *conf_drpass = NULL; +ConfigItem_ulines *conf_ulines = NULL; +ConfigItem_tld *conf_tld = NULL; +ConfigItem_oper *conf_oper = NULL; +ConfigItem_operclass *conf_operclass = NULL; +ConfigItem_listen *conf_listen = NULL; +ConfigItem_sni *conf_sni = NULL; +ConfigItem_allow *conf_allow = NULL; +ConfigItem_link *conf_link = NULL; +ConfigItem_ban *conf_ban = NULL; ConfigItem_deny_channel *conf_deny_channel = NULL; ConfigItem_allow_channel *conf_allow_channel = NULL; ConfigItem_deny_version *conf_deny_version = NULL; -ConfigItem_alias *conf_alias = NULL; -ConfigResource *config_resources = NULL; -ConfigItem_blacklist_module *conf_blacklist_module = NULL; -ConfigItem_help *conf_help = NULL; -ConfigItem_offchans *conf_offchans = NULL; -ConfigItem_proxy *conf_proxy = NULL; +ConfigItem_alias *conf_alias = NULL; +ConfigResource *config_resources = NULL; +ConfigItem_blacklist_module *conf_blacklist_module = NULL; +ConfigItem_help *conf_help = NULL; +ConfigItem_offchans *conf_offchans = NULL; +ConfigItem_proxy *conf_proxy = NULL; -Secret *secrets = NULL; +Secret *secrets = NULL; -Configuration iConf; -Configuration tempiConf; -BestPractices bestpractices; -MODVAR ConfigFile *conf = NULL; -static ConfigEntry *server_linking_tlsoptions_ce = NULL; /* Hack to get set::server-linking::tls-options */ +Configuration iConf; +Configuration tempiConf; +BestPractices bestpractices; +MODVAR ConfigFile *conf = NULL; +static ConfigEntry *server_linking_tlsoptions_ce = NULL; /* Hack to get set::server-linking::tls-options */ extern NameValueList *config_defines; MODVAR int ipv6_disabled = 0; MODVAR Client *remote_rehash_client = NULL; @@ -257,7 +256,7 @@ MODVAR json_t *json_rehash_log = NULL; MODVAR DynamicSetBlock unknown_users_set; MODVAR DynamicSetBlock dynamic_set; -int config_verbose = 0; +int config_verbose = 0; int need_operclass_permissions_upgrade = 0; int invalid_snomasks_encountered = 0; @@ -300,7 +299,7 @@ const char *config_var(ConfigEntry *cep) } /* Now construct the xxx::yyy::zzz string */ - for (i = numel-1; i >= 0; i--) + for (i = numel - 1; i >= 0; i--) { strlcat(buf, elem[i], sizeof(buf)); if (i > 0) @@ -337,11 +336,12 @@ int config_detect_duplicate(int *var, ConfigEntry *ce, int *errors) if (*var) { config_error("%s:%d: Duplicate %s directive", - ce->file->filename, ce->line_number, - ce->name); + ce->file->filename, ce->line_number, + ce->name); (*errors)++; return 1; - } else { + } else + { *var = 1; } return 0; @@ -362,7 +362,7 @@ void port_range(const char *string, int *start, int *end) } *c = '\0'; *start = atoi(string); - *end = atoi((c+1)); + *end = atoi((c + 1)); *c = '-'; } @@ -383,12 +383,12 @@ int config_parse_flood(const char *orig, int *times, int *period) *times = *period = 0; x = strchr(buf, ':'); /* 'blah', ':blah', '1:' */ - if (!x || (x == buf) || (*(x+1) == '\0')) + if (!x || (x == buf) || (*(x + 1) == '\0')) return 0; *x = '\0'; *times = atoi(buf); - *period = config_checkval(x+1, CFG_TIME); + *period = config_checkval(x + 1, CFG_TIME); *x = ':'; /* restore */ return 1; } @@ -427,7 +427,7 @@ int text_in_array(const char *name, const char *list[]) { int i; - for (i=0; list[i]; i++) + for (i = 0; list[i]; i++) if (!strcmp(name, list[i])) return 1; @@ -437,21 +437,21 @@ int text_in_array(const char *name, const char *list[]) int flood_option_is_old(const char *name) { const char *opts[] = { - "max-concurrent-conversations", - "unknown-flood-amount", - "unknown-flood-bantime", - "handshake-data-flood", - "away-count", - "away-period", - "away-flood", - "nick-flood", - "join-flood", - "invite-flood", - "knock-flood", - "connect-flood", - "target-flood", - "multiline", - NULL, + "max-concurrent-conversations", + "unknown-flood-amount", + "unknown-flood-bantime", + "handshake-data-flood", + "away-count", + "away-period", + "away-flood", + "nick-flood", + "join-flood", + "invite-flood", + "knock-flood", + "connect-flood", + "target-flood", + "multiline", + NULL, }; return text_in_array(name, opts); @@ -460,11 +460,11 @@ int flood_option_is_old(const char *name) int flood_option_is_for_everyone(const char *name) { const char *opts[] = { - "connect-flood", - "handshake-data-flood", - "unknown-flood", - "target-flood", - NULL, + "connect-flood", + "handshake-data-flood", + "unknown-flood", + "target-flood", + NULL, }; return text_in_array(name, opts); @@ -509,7 +509,7 @@ int config_parse_flood_generic(const char *str, Configuration *conf, char *block p = strchr(buf, ':'); /* 'blah', ':blah', '1:' */ - if (!p || (p == buf) || (*(p+1) == '\0')) + if (!p || (p == buf) || (*(p + 1) == '\0')) return 0; *p++ = '\0'; @@ -536,22 +536,26 @@ long config_checkval(const char *orig, unsigned short flags) return 0; value = raw_strdup(orig); - if (flags == CFG_YESNO) { - for (text = value; *text; text++) { + if (flags == CFG_YESNO) + { + for (text = value; *text; text++) + { if (!isalnum(*text)) continue; - if (tolower(*text) == 'y' || (tolower(*text) == 'o' && - tolower(*(text+1)) == 'n') || *text == '1' || tolower(*text) == 't') { + if (tolower(*text) == 'y' || (tolower(*text) == 'o' && tolower(*(text + 1)) == 'n') || *text == '1' || tolower(*text) == 't') + { ret = 1; break; } } - } - else if (flags == CFG_SIZE) { + } else if (flags == CFG_SIZE) + { int mfactor = 1; char *sz; - for (text = value; *text; text++) { - if (isalpha(*text)) { + for (text = value; *text; text++) + { + if (isalpha(*text)) + { if (tolower(*text) == 'k') mfactor = 1024; else if (tolower(*text) == 'm') @@ -565,14 +569,16 @@ long config_checkval(const char *orig, unsigned short flags) text++; *sz = 0; - while (sz-- > value && *sz) { + while (sz-- > value && *sz) + { if (isspace(*sz)) *sz = 0; if (!isdigit(*sz)) break; } - ret += atoi(sz+1)*mfactor; - if (*text == '\0') { + ret += atoi(sz + 1) * mfactor; + if (*text == '\0') + { text++; break; } @@ -581,19 +587,22 @@ long config_checkval(const char *orig, unsigned short flags) mfactor = 1; sz = text; sz--; /* -1 because we are PAST the end of the string */ - while (sz-- > value) { + while (sz-- > value) + { if (isspace(*sz)) *sz = 0; if (!isdigit(*sz)) break; } - ret += atoi(sz+1)*mfactor; - } - else if (flags == CFG_TIME) { + ret += atoi(sz + 1) * mfactor; + } else if (flags == CFG_TIME) + { int mfactor = 1; char *sz; - for (text = value; *text; text++) { - if (isalpha(*text)) { + for (text = value; *text; text++) + { + if (isalpha(*text)) + { if (tolower(*text) == 'w') mfactor = 604800; else if (tolower(*text) == 'd') @@ -609,14 +618,16 @@ long config_checkval(const char *orig, unsigned short flags) text++; *sz = 0; - while (sz-- > value && *sz) { + while (sz-- > value && *sz) + { if (isspace(*sz)) *sz = 0; if (!isdigit(*sz)) break; } - ret += atoi(sz+1)*mfactor; - if (*text == '\0') { + ret += atoi(sz + 1) * mfactor; + if (*text == '\0') + { text++; break; } @@ -625,13 +636,14 @@ long config_checkval(const char *orig, unsigned short flags) mfactor = 1; sz = text; sz--; /* -1 because we are PAST the end of the string */ - while (sz-- > value) { + while (sz-- > value) + { if (isspace(*sz)) *sz = 0; if (!isdigit(*sz)) break; } - ret += atoi(sz+1)*mfactor; + ret += atoi(sz + 1) * mfactor; } safe_free(value); return ret; @@ -642,7 +654,7 @@ void free_conf_channelmodes(struct ChMode *store) { int i; - for (i=0; i <= 255; i++) + for (i = 0; i <= 255; i++) safe_free(store->extparams[i]); memset(store, 0, sizeof(struct ChMode)); @@ -686,7 +698,7 @@ void conf_channelmodes(const char *modes, struct ChMode *store) } found = 0; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (!(cm->letter)) continue; @@ -732,7 +744,7 @@ void chmode_str(struct ChMode *modes, char *mbuf, char *pbuf, size_t mbuf_size, *mbuf++ = '+'; mbuf_size--; - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (!(cm->letter)) continue; @@ -744,7 +756,7 @@ void chmode_str(struct ChMode *modes, char *mbuf, char *pbuf, size_t mbuf_size, *mbuf++ = cm->letter; if (!--mbuf_size) { - *--mbuf=0; + *--mbuf = 0; break; } } @@ -755,7 +767,7 @@ void chmode_str(struct ChMode *modes, char *mbuf, char *pbuf, size_t mbuf_size, } } } - *mbuf=0; + *mbuf = 0; } const char *channellevel_to_string(const char *s) @@ -829,7 +841,7 @@ AllowedChannelChars allowed_channelchars_strtoval(const char *str) const char *allowed_channelchars_valtostr(AllowedChannelChars v) { - switch(v) + switch (v) { case ALLOWED_CHANNELCHARS_ASCII: return "ascii"; @@ -865,7 +877,7 @@ BanTarget ban_target_strtoval(const char *str) /* Used for set::automatic-ban-target and set::manual-ban-target */ const char *ban_target_valtostr(BanTarget v) { - switch(v) + switch (v) { case BAN_TARGET_IP: return "ip"; @@ -899,7 +911,7 @@ HideIdleTimePolicy hideidletime_strtoval(const char *str) const char *hideidletime_valtostr(HideIdleTimePolicy v) { - switch(v) + switch (v) { case HIDE_IDLE_TIME_NEVER: return "never"; @@ -917,10 +929,10 @@ const char *hideidletime_valtostr(HideIdleTimePolicy v) ConfigFile *config_load(const char *filename, const char *displayname) { struct stat sb; - int fd; - int ret; - char *buf = NULL; - ConfigFile *cfptr; + int fd; + int ret; + char *buf = NULL; + ConfigFile *cfptr; if (!displayname) displayname = filename; @@ -928,7 +940,7 @@ ConfigFile *config_load(const char *filename, const char *displayname) #ifndef _WIN32 fd = open(filename, O_RDONLY); #else - fd = open(filename, O_RDONLY|O_BINARY); + fd = open(filename, O_RDONLY | O_BINARY); #endif if (fd == -1) { @@ -948,7 +960,7 @@ ConfigFile *config_load(const char *filename, const char *displayname) close(fd); return cfptr; } - buf = safe_alloc(sb.st_size+1); + buf = safe_alloc(sb.st_size + 1); if (buf == NULL) { config_error("Out of memory trying to load \"%s\"", filename); @@ -959,7 +971,7 @@ ConfigFile *config_load(const char *filename, const char *displayname) if (ret != sb.st_size) { config_error("Error reading \"%s\": %s", filename, - ret == -1 ? strerror(errno) : strerror(EFAULT)); + ret == -1 ? strerror(errno) : strerror(EFAULT)); safe_free(buf); close(fd); return NULL; @@ -981,9 +993,9 @@ ConfigFile *config_load(const char *filename, const char *displayname) void config_free(ConfigFile *cfptr) { - ConfigFile *nptr; + ConfigFile *nptr; - for(;cfptr;cfptr=nptr) + for (; cfptr; cfptr = nptr) { nptr = cfptr->next; if (cfptr->items) @@ -1019,7 +1031,7 @@ int unreal_add_quotes_r(const char *i, char *o, size_t len) { if (len == 0) return 0; - + len--; /* reserve room for nul byte */ if (len == 0) @@ -1027,7 +1039,7 @@ int unreal_add_quotes_r(const char *i, char *o, size_t len) *o = '\0'; return 0; } - + for (; *i; i++) { if ((*i == '"') || (*i == '\\')) /* only " and \ need to be quoted */ @@ -1046,15 +1058,15 @@ int unreal_add_quotes_r(const char *i, char *o, size_t len) } } *o = '\0'; - + return 1; -} +} /** Add quotes to a line, eg some"thing becomes some\"thing */ const char *unreal_add_quotes(const char *str) { static char qbuf[2048]; - + *qbuf = '\0'; unreal_add_quotes_r(str, qbuf, sizeof(qbuf)); return qbuf; @@ -1070,15 +1082,15 @@ ConfigFile *config_parse(const char *filename, char *confdata) */ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsigned int line_offset) { - char *ptr; - char *start; - int linenumber = 1+line_offset; + char *ptr; + char *start; + int linenumber = 1 + line_offset; int errors = 0; int n; - ConfigEntry *curce; - ConfigEntry **lastce; - ConfigEntry *cursection; - ConfigFile *curcf; + ConfigEntry *curce; + ConfigEntry **lastce; + ConfigEntry *cursection; + ConfigFile *curcf; int preprocessor_level = 0; ConditionalConfig *cc, *cc_list = NULL; @@ -1088,19 +1100,19 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig curce = NULL; cursection = NULL; /* Replace \r's with spaces .. ugly ugly -Stskeeps */ - for (ptr=confdata; *ptr; ptr++) + for (ptr = confdata; *ptr; ptr++) if (*ptr == '\r') *ptr = ' '; - for(ptr=confdata;*ptr;ptr++) + for (ptr = confdata; *ptr; ptr++) { - switch(*ptr) + switch (*ptr) { case ';': if (!curce) { config_status("%s:%i Ignoring extra semicolon", - filename, linenumber); + filename, linenumber); break; } *lastce = curce; @@ -1113,15 +1125,14 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig { config_error("%s:%i: New section start detected on line %d but the section has no name. " "Sections should start with a name like 'oper {' or 'set {'.", - filename, linenumber, linenumber); + filename, linenumber, linenumber); errors++; continue; - } - else if (curce->items) + } else if (curce->items) { config_error("%s:%i: New section start but previous section did not end properly. " "Check line %d and the line(s) before, you are likely missing a '};' there.", - filename, linenumber, linenumber); + filename, linenumber, linenumber); errors++; continue; } @@ -1134,17 +1145,16 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig if (curce) { config_error("%s:%i: Missing semicolon (';') before close brace. Check line %d and the line(s) before.", - filename, linenumber, linenumber); + filename, linenumber, linenumber); config_entry_free_all(curce); config_free(curcf); errors++; return NULL; - } - else if (!cursection) + } else if (!cursection) { config_error("%s:%i: You have a close brace ('};') too many. " - "Check line %d AND the lines above it from the previous block.", - filename, linenumber, linenumber); + "Check line %d AND the lines above it from the previous block.", + filename, linenumber, linenumber); errors++; continue; } @@ -1155,9 +1165,9 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig lastce = &(curcf->items); else lastce = &(cursection->items); - for(;*lastce;lastce = &((*lastce)->next)) + for (; *lastce; lastce = &((*lastce)->next)) continue; - if (*(ptr+1) != ';') + if (*(ptr + 1) != ';') { /* Simulate closing ; so you can get away with } instead of ugly }; */ *lastce = curce; @@ -1168,54 +1178,51 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig break; case '#': ptr++; - while(*ptr && (*ptr != '\n')) - ptr++; + while (*ptr && (*ptr != '\n')) + ptr++; if (!*ptr) break; ptr--; continue; case '/': - if (*(ptr+1) == '/') + if (*(ptr + 1) == '/') { ptr += 2; - while(*ptr && (*ptr != '\n')) + while (*ptr && (*ptr != '\n')) ptr++; if (!*ptr) break; ptr--; /* grab the \n on next loop thru */ continue; - } - else if (*(ptr+1) == '*') + } else if (*(ptr + 1) == '*') { int commentstart = linenumber; - for(ptr+=2;*ptr;ptr++) + for (ptr += 2; *ptr; ptr++) { if (*ptr == '\n') { linenumber++; - } else - if ((*ptr == '*') && (*(ptr+1) == '/')) + } else if ((*ptr == '*') && (*(ptr + 1) == '/')) { ptr++; break; - } else if ((*ptr == '/') && (*(ptr+1) == '*')) + } else if ((*ptr == '/') && (*(ptr + 1) == '*')) { config_warn("%s:%i nested comments are not supported (comment started at line %d)", - filename, linenumber, commentstart); + filename, linenumber, commentstart); } } if (!*ptr) { config_error("%s:%i Comment on line %d does not end", - filename, commentstart, commentstart); + filename, commentstart, commentstart); errors++; config_entry_free_all(curce); config_free(curcf); return NULL; } - } - else + } else { /* Something like /tmp/xyz */ goto processchar; @@ -1230,7 +1237,7 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig { config_error("%s:%i: Missing semicolon (';') at end of line. " "Line %d must end with a ; character", - filename, curce->line_number, curce->line_number); + filename, curce->line_number, curce->line_number); errors++; *lastce = curce; @@ -1240,7 +1247,7 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig } start = ++ptr; - for(;*ptr;ptr++) + for (; *ptr; ptr++) { if (*ptr == '\\') { @@ -1250,8 +1257,7 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig ptr++; /* skip */ continue; } - } - else if (*ptr == '\n') + } else if (*ptr == '\n') break; else if (curce && curce->escaped && (*ptr == '\'')) break; @@ -1261,7 +1267,7 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig if (!*ptr || (*ptr == '\n')) { config_error("%s:%i: Unterminated quote found", - filename, linenumber); + filename, linenumber); errors++; config_entry_free_all(curce); config_free(curcf); @@ -1272,24 +1278,22 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig if (curce->value) { config_error("%s:%i: Extra data detected. Perhaps missing a ';' or one too many?", - filename, linenumber); + filename, linenumber); errors++; - } - else + } else { - safe_strldup(curce->value, start, ptr-start+1); + safe_strldup(curce->value, start, ptr - start + 1); preprocessor_replace_defines(&curce->value, curce); unreal_del_quotes(curce->value); } - } - else + } else { curce = safe_alloc(sizeof(ConfigEntry)); curce->line_number = linenumber; curce->file = curcf; curce->parent = cursection; curce->file_position_start = (start - confdata); - safe_strldup(curce->name, start, ptr-start+1); + safe_strldup(curce->name, start, ptr - start + 1); preprocessor_replace_defines(&curce->name, curce); unreal_del_quotes(curce->name); preprocessor_cc_duplicate_list(cc_list, &curce->conditional_config); @@ -1306,7 +1310,7 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig case '@': /* Preprocessor item, such as @if, @define, etc. */ start = ptr; - for (;*ptr; ptr++) + for (; *ptr; ptr++) { if (*ptr == '\n') break; @@ -1332,14 +1336,13 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig preprocessor_level++; cc->priority = preprocessor_level; AddListItem(cc, cc_list); - } else - if (n == PREPROCESSOR_ELSE) + } else if (n == PREPROCESSOR_ELSE) { ConditionalConfig *cc_item; if (preprocessor_level == 0) { config_error("%s:%i: @else unexpected. There was no preceding unclosed @if.", - filename, linenumber); + filename, linenumber); errors++; } else { @@ -1351,7 +1354,7 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig if (cc_item->had_else) { config_error("%s:%i: duplicate @else for the same @if block.", - filename, linenumber); + filename, linenumber); errors++; goto breakout; } @@ -1361,24 +1364,21 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig } } } - } else - if (n == PREPROCESSOR_ENDIF) + } else if (n == PREPROCESSOR_ENDIF) { if (preprocessor_level == 0) { config_error("%s:%i: @endif unexpected. There was no preceding unclosed @if.", - filename, linenumber); + filename, linenumber); errors++; } preprocessor_cc_free_level(&cc_list, preprocessor_level); preprocessor_level--; - } else - if (n == PREPROCESSOR_ERROR) + } else if (n == PREPROCESSOR_ERROR) { errors++; goto breakout; - } else - if (n == PREPROCESSOR_USER_ERROR) + } else if (n == PREPROCESSOR_USER_ERROR) { errors++; } @@ -1390,7 +1390,7 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig break; default: processchar: - if ((*ptr == '*') && (*(ptr+1) == '/')) + if ((*ptr == '*') && (*(ptr + 1) == '/')) { config_status("%s:%i: Ignoring extra end comment", filename, linenumber); config_status("WARNING: Starting with UnrealIRCd 4.2.1 a /*-style comment stops as soon as the first */ is encountered. " @@ -1399,7 +1399,7 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig break; } start = ptr; - for(;*ptr;ptr++) + for (; *ptr; ptr++) { if ((*ptr == ' ') /*|| (*ptr == '=')*/ || (*ptr == '\t') || (*ptr == '\n') || (*ptr == ';')) break; @@ -1408,15 +1408,16 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig { if (curce) config_error("%s: End of file reached but directive or block at line %i did not end properly. " - "Perhaps a missing ; (semicolon) somewhere?", - filename, curce->line_number); + "Perhaps a missing ; (semicolon) somewhere?", + filename, curce->line_number); else if (cursection) config_error("%s: End of file reached but the section which starts at line %i did never end properly. " - "Perhaps a missing }; ?", - filename, cursection->section_linenumber); + "Perhaps a missing }; ?", + filename, cursection->section_linenumber); else config_error("%s: Unexpected end of file. Some line or block did not end properly. " - "Look for any missing } and };", filename); + "Look for any missing } and };", + filename); errors++; config_entry_free_all(curce); config_free(curcf); @@ -1427,16 +1428,14 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig if (curce->value) { config_error("%s:%i: Extra data detected. Check for a missing ; character at or around line %d", - filename, linenumber, linenumber-1); + filename, linenumber, linenumber - 1); errors++; - } - else + } else { - safe_strldup(curce->value, start, ptr-start+1); + safe_strldup(curce->value, start, ptr - start + 1); preprocessor_replace_defines(&curce->value, curce); } - } - else + } else { curce = safe_alloc(sizeof(ConfigEntry)); memset(curce, 0, sizeof(ConfigEntry)); @@ -1444,7 +1443,7 @@ ConfigFile *config_parse_with_offset(const char *filename, char *confdata, unsig curce->file = curcf; curce->parent = cursection; curce->file_position_start = (start - confdata); - safe_strldup(curce->name, start, ptr-start+1); + safe_strldup(curce->name, start, ptr - start + 1); preprocessor_replace_defines(&curce->name, curce); if (curce->conditional_config) abort(); @@ -1462,15 +1461,14 @@ breakout: { config_error("%s: End of file reached but directive or block at line %i did not end properly. " "Perhaps a missing ; (semicolon) somewhere?", - filename, curce->line_number); + filename, curce->line_number); errors++; config_entry_free_all(curce); - } - else if (cursection) + } else if (cursection) { config_error("%s: End of file reached but the section which starts at line %i did never end properly. " "Perhaps a missing }; ?", - filename, cursection->section_linenumber); + filename, cursection->section_linenumber); errors++; } @@ -1488,9 +1486,9 @@ breakout: */ void config_entry_free_all(ConfigEntry *ce) { - ConfigEntry *nptr; + ConfigEntry *nptr; - for(;ce;ce=nptr) + for (; ce; ce = nptr) { nptr = ce->next; if (ce->items) @@ -1534,9 +1532,9 @@ ConfigEntry *config_find_entry(ConfigEntry *ce, const char *name) */ void config_error(FORMAT_STRING(const char *format), ...) { - va_list ap; - char buffer[1024]; - char *ptr; + va_list ap; + char buffer[1024]; + char *ptr; va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); @@ -1563,19 +1561,19 @@ void config_error_missing(const char *filename, int line, const char *entry) * @param entry The unknown directive name */ void config_error_unknown(const char *filename, int line, const char *block, - const char *entry) + const char *entry) { config_error("%s:%d: Unknown directive '%s::%s'", filename, line, block, entry); } void config_error_unknownflag(const char *filename, int line, const char *block, - const char *entry) + const char *entry) { config_error("%s:%d: Unknown %s flag '%s'", filename, line, block, entry); } void config_error_unknownopt(const char *filename, int line, const char *block, - const char *entry) + const char *entry) { config_error("%s:%d: Unknown %s option '%s'", filename, line, block, entry); } @@ -1591,17 +1589,17 @@ void config_error_blank(const char *filename, int line, const char *block) } void config_error_empty(const char *filename, int line, const char *block, - const char *entry) + const char *entry) { config_error("%s:%d: %s::%s specified without a value", - filename, line, block, entry); + filename, line, block, entry); } void config_status(FORMAT_STRING(const char *format), ...) { - va_list ap; - char buffer[1024]; - char *ptr; + va_list ap; + char buffer[1024]; + char *ptr; va_start(ap, format); vsnprintf(buffer, 1023, format, ap); @@ -1617,9 +1615,9 @@ void config_status(FORMAT_STRING(const char *format), ...) */ void config_warn(FORMAT_STRING(const char *format), ...) { - va_list ap; - char buffer[1024]; - char *ptr; + va_list ap; + char buffer[1024]; + char *ptr; va_start(ap, format); vsnprintf(buffer, 1023, format, ap); @@ -1643,15 +1641,15 @@ int config_test_openfile(ConfigEntry *cep, int flags, mode_t mode, const char *e { if (fatal) config_error("%s:%i: %s: : no file specified", - cep->file->filename, - cep->line_number, - entry); + cep->file->filename, + cep->line_number, + entry); else config_warn("%s:%i: %s: : no file specified", - cep->file->filename, - cep->line_number, - entry); + cep->file->filename, + cep->line_number, + entry); return 1; } @@ -1663,9 +1661,9 @@ int config_test_openfile(ConfigEntry *cep, int flags, mode_t mode, const char *e /* but we can check if a URL is used wrongly :-) */ config_warn("%s:%i: %s: %s: URL used where not allowed", - cep->file->filename, - cep->line_number, - entry, cep->value); + cep->file->filename, + cep->line_number, + entry, cep->value); if (fatal) return 1; else @@ -1687,18 +1685,18 @@ int config_test_openfile(ConfigEntry *cep, int flags, mode_t mode, const char *e { if (fatal) config_error("%s:%i: %s: %s: %s", - cep->file->filename, - cep->line_number, - entry, - cep->value, - strerror(errno)); + cep->file->filename, + cep->line_number, + entry, + cep->value, + strerror(errno)); else config_warn("%s:%i: %s: %s: %s", - cep->file->filename, - cep->line_number, - entry, - cep->value, - strerror(errno)); + cep->file->filename, + cep->line_number, + entry, + cep->value, + strerror(errno)); return 1; } close(fd); @@ -1716,26 +1714,28 @@ int config_is_blankorempty(ConfigEntry *cep, const char *block) if (!cep->value) { config_error_empty(cep->file->filename, cep->line_number, block, - cep->name); + cep->name); return 1; } return 0; } -ConfigCommand *config_binary_search(const char *cmd) { +ConfigCommand *config_binary_search(const char *cmd) +{ int start = 0; - int stop = ARRAY_SIZEOF(_ConfigCommands)-1; + int stop = ARRAY_SIZEOF(_ConfigCommands) - 1; int mid; - while (start <= stop) { - mid = (start+stop)/2; - if (smycmp(cmd,_ConfigCommands[mid].name) < 0) { - stop = mid-1; - } - else if (strcmp(cmd,_ConfigCommands[mid].name) == 0) { + while (start <= stop) + { + mid = (start + stop) / 2; + if (smycmp(cmd, _ConfigCommands[mid].name) < 0) + { + stop = mid - 1; + } else if (strcmp(cmd, _ConfigCommands[mid].name) == 0) + { return &_ConfigCommands[mid]; - } - else - start = mid+1; + } else + start = mid + 1; } return NULL; } @@ -1873,7 +1873,8 @@ void config_setdefaultsettings(Configuration *i) /* Flood options */ /* - everyone */ - i->throttle_count = 3; i->throttle_period = 60; /* throttle protection: max 3 per 60s */ + i->throttle_count = 3; + i->throttle_period = 60; /* throttle protection: max 3 per 60s */ i->handshake_data_flood_amount = 4096; i->handshake_data_flood_ban_action = safe_alloc(sizeof(BanAction)); i->handshake_data_flood_ban_action->action = BAN_ACT_ZLINE; @@ -1916,7 +1917,7 @@ void config_setdefaultsettings(Configuration *i) safe_strdup(i->tls_options->trusted_ca_file, tmp); safe_strdup(i->tls_options->ciphers, UNREALIRCD_DEFAULT_CIPHERS); safe_strdup(i->tls_options->ciphersuites, UNREALIRCD_DEFAULT_CIPHERSUITES); - i->tls_options->protocols = TLS_PROTOCOL_TLSV1_2|TLS_PROTOCOL_TLSV1_3; /* TLSv1.2 & TLSv1.3 */ + i->tls_options->protocols = TLS_PROTOCOL_TLSV1_2 | TLS_PROTOCOL_TLSV1_3; /* TLSv1.2 & TLSv1.3 */ safe_strdup(i->tls_options->outdated_protocols, "TLSv1,TLSv1.1"); /* the following may look strange but "AES*" matches all * AES ciphersuites that do not have Forward Secrecy. @@ -2015,8 +2016,7 @@ void postconf_defaults(void) { addmultiline(&iConf.plaintext_policy_oper_message, "You need to use a secure connection (TLS) in order to /OPER."); addmultiline(&iConf.plaintext_policy_oper_message, "See https://www.unrealircd.org/docs/FAQ#oper-requires-tls"); - } - else if (iConf.plaintext_policy_oper == POLICY_WARN) + } else if (iConf.plaintext_policy_oper == POLICY_WARN) addmultiline(&iConf.plaintext_policy_oper_message, "WARNING: You /OPER'ed up from an insecure connection. Please consider using TLS."); } @@ -2047,7 +2047,7 @@ void postconf_defaults(void) */ static void do_weird_shun_stuff() { -RealCommand *cmptr; + RealCommand *cmptr; if ((cmptr = find_command_simple("PART"))) { @@ -2080,12 +2080,11 @@ void postconf(void) if (!has_any_trusted_cert()) { unreal_log(ULOG_ADVICE, "config", "BEST_PRACTICES_TRUSTED_CERT", NULL, - "You don't have any valid SSL/TLS certificate that is issued by a trusted Certificate Authority.\n" - "It is highly recommended to use a 'real certificate'. To get a free one, see: " - "https://www.unrealircd.org/docs/Using_Let's_Encrypt_with_UnrealIRCd"); + "You don't have any valid SSL/TLS certificate that is issued by a trusted Certificate Authority.\n" + "It is highly recommended to use a 'real certificate'. To get a free one, see: " + "https://www.unrealircd.org/docs/Using_Let's_Encrypt_with_UnrealIRCd"); bestpractices.trusted_cert_hits++; - } else - if (bestpractices.trusted_cert_valid_hostname && !has_any_trusted_cert_with_correct_hostname()) + } else if (bestpractices.trusted_cert_valid_hostname && !has_any_trusted_cert_with_correct_hostname()) { unreal_log(ULOG_ADVICE, "config", "BEST_PRACTICES_TRUSTED_CERT_VALID_HOSTNAME", NULL, "You have an SSL/TLS certificate that is issued by a trusted Certificate Authority " @@ -2140,7 +2139,7 @@ void applymeblock(void) /** Run config test and all post config tests. */ int config_test_all(void) { - if ((efunctions_check() < 0) || (config_test_blocks() < 0) || (callbacks_check() < 0) || + if ((efunctions_check() < 0) || (config_test_blocks() < 0) || (callbacks_check() < 0) || reloadable_perm_module_unloaded() || !tls_tests() || !log_tests()) { return 0; @@ -2178,7 +2177,7 @@ int config_loadmodules(void) if (cc->condition == IF_MODULE_LOADED) { config_error("%s:%d: You cannot use @if module-loaded() around a 'loadmodule' statement.", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 0; } } @@ -2373,8 +2372,7 @@ int config_test(void) /* loop.config_status = CONFIG_STATUS_LOAD is done by module_loadall() */ module_loadall(); RunHook(HOOKTYPE_REHASH_COMPLETE); - } else - if (!loop.booted) + } else if (!loop.booted) { /* This was moved from src/ircd.c to here, since we need TLS initialized * before we run the best practices tests in postconf(). @@ -2446,8 +2444,8 @@ void config_parse_and_queue_urls(ConfigEntry *ce) */ int config_read_file(const char *filename, const char *display_name) { - ConfigFile *cfptr, *cfptr2, **cfptr3; - ConfigEntry *ce; + ConfigFile *cfptr, *cfptr2, **cfptr3; + ConfigEntry *ce; ConfigResource *rs; int ret; int counter; @@ -2472,12 +2470,12 @@ int config_read_file(const char *filename, const char *display_name) if (rs->file && !strcasecmp(filename, rs->file)) #endif { - counter ++; + counter++; continue; } if (rs->url && !strcmp(display_name, rs->url)) { - counter ++; + counter++; continue; } } @@ -2506,14 +2504,14 @@ int config_read_file(const char *filename, const char *display_name) for (ce = cfptr->items; ce; ce = ce->next) if (!strcmp(ce->name, "blacklist-module")) - _test_blacklist_module(cfptr, ce); + _test_blacklist_module(cfptr, ce); preprocessor_resolve_conditionals_ce(&cfptr->items, PREPROCESSOR_PHASE_SECONDARY); /* Load urls */ config_parse_and_queue_urls(cfptr->items); - if(loop.config_load_failed) /* something bad happened while processing urls */ + if (loop.config_load_failed) /* something bad happened while processing urls */ return -1; /* Load includes */ @@ -2544,8 +2542,7 @@ int config_read_file(const char *filename, const char *display_name) } } return 1; - } - else + } else { unreal_log(ULOG_ERROR, "config", "CONFIG_LOAD_FILE_FAILED", NULL, "Could not load configuration file: $resource", @@ -2557,7 +2554,8 @@ int config_read_file(const char *filename, const char *display_name) if (file_exists("unrealircd.conf")) { config_error("Note that 'unrealircd.conf' now belongs in the 'conf' subdirectory! (So move it to there)"); - } else { + } else + { config_error("New to UnrealIRCd? Be sure to read https://www.unrealircd.org/docs/Installing_%%28Windows%%29"); } } @@ -2590,25 +2588,25 @@ void free_all_proxy_blocks(void) void config_rehash() { - ConfigItem_oper *oper_ptr; - ConfigItem_operclass *operclass_ptr; - ConfigItem_class *class_ptr; - ConfigItem_ulines *uline_ptr; - ConfigItem_allow *allow_ptr; - ConfigItem_ban *ban_ptr; - ConfigItem_link *link_ptr; - ConfigItem_listen *listen_ptr; - ConfigItem_tld *tld_ptr; - ConfigItem_deny_channel *deny_channel_ptr; - ConfigItem_allow_channel *allow_channel_ptr; - ConfigItem_admin *admin_ptr; - ConfigItem_deny_version *deny_version_ptr; - ConfigItem_alias *alias_ptr; - ConfigItem_help *help_ptr; - ConfigItem_offchans *of_ptr; - ConfigItem_sni *sni; - OperStat *os_ptr; - ListStruct *next, *next2; + ConfigItem_oper *oper_ptr; + ConfigItem_operclass *operclass_ptr; + ConfigItem_class *class_ptr; + ConfigItem_ulines *uline_ptr; + ConfigItem_allow *allow_ptr; + ConfigItem_ban *ban_ptr; + ConfigItem_link *link_ptr; + ConfigItem_listen *listen_ptr; + ConfigItem_tld *tld_ptr; + ConfigItem_deny_channel *deny_channel_ptr; + ConfigItem_allow_channel *allow_channel_ptr; + ConfigItem_admin *admin_ptr; + ConfigItem_deny_version *deny_version_ptr; + ConfigItem_alias *alias_ptr; + ConfigItem_help *help_ptr; + ConfigItem_offchans *of_ptr; + ConfigItem_sni *sni; + OperStat *os_ptr; + ListStruct *next, *next2; USE_BAN_VERSION = 0; @@ -2650,19 +2648,18 @@ void config_rehash() safe_free(operclass_ptr); } - for (link_ptr = conf_link; link_ptr; link_ptr = (ConfigItem_link *) next) + for (link_ptr = conf_link; link_ptr; link_ptr = (ConfigItem_link *)next) { next = (ListStruct *)link_ptr->next; if (link_ptr->refcount == 0) { delete_linkblock(link_ptr); - } - else + } else { link_ptr->flag.temporary = 1; } } - for (class_ptr = conf_class; class_ptr; class_ptr = (ConfigItem_class *) next) + for (class_ptr = conf_class; class_ptr; class_ptr = (ConfigItem_class *)next) { next = (ListStruct *)class_ptr->next; if (class_ptr->flag.permanent == 1) @@ -2674,7 +2671,7 @@ void config_rehash() delete_classblock(class_ptr); } } - for (uline_ptr = conf_ulines; uline_ptr; uline_ptr = (ConfigItem_ulines *) next) + for (uline_ptr = conf_ulines; uline_ptr; uline_ptr = (ConfigItem_ulines *)next) { next = (ListStruct *)uline_ptr->next; /* We'll wipe it out when it has no clients */ @@ -2682,7 +2679,7 @@ void config_rehash() DelListItem(uline_ptr, conf_ulines); safe_free(uline_ptr); } - for (allow_ptr = conf_allow; allow_ptr; allow_ptr = (ConfigItem_allow *) next) + for (allow_ptr = conf_allow; allow_ptr; allow_ptr = (ConfigItem_allow *)next) { next = (ListStruct *)allow_ptr->next; free_security_group(allow_ptr->match); @@ -2692,7 +2689,7 @@ void config_rehash() safe_free(allow_ptr); } /* Free ban realname { }, ban server { } and ban version { } */ - for (ban_ptr = conf_ban; ban_ptr; ban_ptr = (ConfigItem_ban *) next) + for (ban_ptr = conf_ban; ban_ptr; ban_ptr = (ConfigItem_ban *)next) { next = (ListStruct *)ban_ptr->next; if (ban_ptr->flag.type2 == CONF_BAN_TYPE_CONF || ban_ptr->flag.type2 == CONF_BAN_TYPE_TEMPORARY) @@ -2709,7 +2706,7 @@ void config_rehash() if (!(listen_ptr->options & LISTENER_CONTROL)) listen_ptr->flag.temporary = 1; } - for (tld_ptr = conf_tld; tld_ptr; tld_ptr = (ConfigItem_tld *) next) + for (tld_ptr = conf_tld; tld_ptr; tld_ptr = (ConfigItem_tld *)next) { next = (ListStruct *)tld_ptr->next; safe_free(tld_ptr->motd_file); @@ -2731,7 +2728,8 @@ void config_rehash() safe_free(tld_ptr); } - for (deny_version_ptr = conf_deny_version; deny_version_ptr; deny_version_ptr = (ConfigItem_deny_version *) next) { + for (deny_version_ptr = conf_deny_version; deny_version_ptr; deny_version_ptr = (ConfigItem_deny_version *)next) + { next = (ListStruct *)deny_version_ptr->next; safe_free(deny_version_ptr->mask); safe_free(deny_version_ptr->version); @@ -2739,7 +2737,7 @@ void config_rehash() DelListItem(deny_version_ptr, conf_deny_version); safe_free(deny_version_ptr); } - for (deny_channel_ptr = conf_deny_channel; deny_channel_ptr; deny_channel_ptr = (ConfigItem_deny_channel *) next) + for (deny_channel_ptr = conf_deny_channel; deny_channel_ptr; deny_channel_ptr = (ConfigItem_deny_channel *)next) { next = (ListStruct *)deny_channel_ptr->next; safe_free(deny_channel_ptr->redirect); @@ -2751,7 +2749,7 @@ void config_rehash() safe_free(deny_channel_ptr); } - for (allow_channel_ptr = conf_allow_channel; allow_channel_ptr; allow_channel_ptr = (ConfigItem_allow_channel *) next) + for (allow_channel_ptr = conf_allow_channel; allow_channel_ptr; allow_channel_ptr = (ConfigItem_allow_channel *)next) { next = (ListStruct *)allow_channel_ptr->next; safe_free(allow_channel_ptr->channel); @@ -2769,7 +2767,8 @@ void config_rehash() conf_drpass->dieauth = NULL; safe_free(conf_drpass); } - for (alias_ptr = conf_alias; alias_ptr; alias_ptr = (ConfigItem_alias *)next) { + for (alias_ptr = conf_alias; alias_ptr; alias_ptr = (ConfigItem_alias *)next) + { RealCommand *cmptr = find_command(alias_ptr->alias, 0); ConfigItem_alias_format *fmt; next = (ListStruct *)alias_ptr->next; @@ -2777,8 +2776,9 @@ void config_rehash() if (cmptr) CommandDelX(NULL, cmptr); safe_free(alias_ptr->alias); - if (alias_ptr->format && (alias_ptr->type == ALIAS_COMMAND)) { - for (fmt = (ConfigItem_alias_format *) alias_ptr->format; fmt; fmt = (ConfigItem_alias_format *) next2) + if (alias_ptr->format && (alias_ptr->type == ALIAS_COMMAND)) + { + for (fmt = (ConfigItem_alias_format *)alias_ptr->format; fmt; fmt = (ConfigItem_alias_format *)next2) { next2 = (ListStruct *)fmt->next; safe_free(fmt->format); @@ -2792,11 +2792,13 @@ void config_rehash() DelListItem(alias_ptr, conf_alias); safe_free(alias_ptr); } - for (help_ptr = conf_help; help_ptr; help_ptr = (ConfigItem_help *)next) { + for (help_ptr = conf_help; help_ptr; help_ptr = (ConfigItem_help *)next) + { MOTDLine *text; next = (ListStruct *)help_ptr->next; safe_free(help_ptr->command); - while (help_ptr->text) { + while (help_ptr->text) + { text = help_ptr->text->next; safe_free(help_ptr->text->line); safe_free(help_ptr->text); @@ -2823,11 +2825,11 @@ void config_rehash() /* Free sni { } blocks */ for (sni = conf_sni; sni; sni = (ConfigItem_sni *)next) { - next = (ListStruct *)sni->next; - SSL_CTX_free(sni->ssl_ctx); - free_tls_options(sni->tls_options); - safe_free(sni->name); - safe_free(sni); + next = (ListStruct *)sni->next; + SSL_CTX_free(sni->ssl_ctx); + free_tls_options(sni->tls_options); + safe_free(sni->name); + safe_free(sni); } conf_sni = NULL; @@ -2856,10 +2858,14 @@ void config_rehash() conf_files = NULL; } -int config_post_test() +int config_post_test() { -#define Error(x) { config_error((x)); errors++; } - int errors = 0; +#define Error(x) \ + { \ + config_error((x)); \ + errors++; \ + } + int errors = 0; Hook *h; if (!requiredstuff.conf_me) @@ -2883,7 +2889,7 @@ int config_post_test() { int value, errs = 0; if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && - !(h->owner->options & MOD_OPT_PERM)) + !(h->owner->options & MOD_OPT_PERM)) continue; value = (*(h->func.intfunc))(&errs); if (value == -1) @@ -2909,22 +2915,22 @@ void config_switchover(void) /** Priority of config blocks during CONFIG_TEST stage */ static const char *config_test_priority_blocks[] = { - "me", - "secret", - "log", /* "log" needs to be before "set" in CONFIG_TEST */ - "security-group", - "set", - "class", + "me", + "secret", + "log", /* "log" needs to be before "set" in CONFIG_TEST */ + "security-group", + "set", + "class", }; /** Priority of config blocks during CONFIG_RUN stage */ static const char *config_run_priority_blocks[] = { - "me", - "secret", - "security-group", - "set", - "log", /* "log" needs to be after "set" in CONFIG_RUN */ - "class", + "me", + "secret", + "security-group", + "set", + "log", /* "log" needs to be after "set" in CONFIG_RUN */ + "class", }; int config_item_allowed_for_config_file(const char *resource, const char *item) @@ -2974,7 +2980,7 @@ int config_test_blocks_generic(ConfigFile *cfptr, int skip_priority_blocks, int if (skip_priority_blocks) { char skip = 0; - for (i=0; i < ARRAY_SIZEOF(config_test_priority_blocks); i++) + for (i = 0; i < ARRAY_SIZEOF(config_test_priority_blocks); i++) { if (!strcmp(ce->name, config_test_priority_blocks[i])) { @@ -2989,11 +2995,11 @@ int config_test_blocks_generic(ConfigFile *cfptr, int skip_priority_blocks, int if (!config_item_allowed_for_config_file(cfptr->filename, ce->name)) continue; - if ((cc = config_binary_search(ce->name))) { + if ((cc = config_binary_search(ce->name))) + { if (cc->testfunc) errors += (cc->testfunc(cfptr, ce)); - } - else + } else { int used = 0; for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) @@ -3001,13 +3007,12 @@ int config_test_blocks_generic(ConfigFile *cfptr, int skip_priority_blocks, int int value, errs = 0; if (normalconf) { - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) { continue; } } - value = (*(h->func.intfunc))(cfptr,ce,CONFIG_MAIN,&errs); + value = (*(h->func.intfunc))(cfptr, ce, CONFIG_MAIN, &errs); if (value == 2) used = 1; if (value == 1) @@ -3026,19 +3031,18 @@ int config_test_blocks_generic(ConfigFile *cfptr, int skip_priority_blocks, int used = 1; errors += errs; } - } if (!used) { config_error("%s:%i: unknown directive %s", - ce->file->filename, ce->line_number, - ce->name); + ce->file->filename, ce->line_number, + ce->name); errors++; if (strchr(ce->name, ':')) { config_error("You cannot use :: in a directive, you have to write them out. " - "For example 'set::auto-join #something' needs to be written as: " - "set { auto-join \"#something\"; }"); + "For example 'set::auto-join #something' needs to be written as: " + "set { auto-join \"#something\"; }"); config_error("See also https://www.unrealircd.org/docs/Set_block#Syntax_used_in_this_documentation"); } } @@ -3049,10 +3053,10 @@ int config_test_blocks_generic(ConfigFile *cfptr, int skip_priority_blocks, int int config_test_blocks() { - ConfigEntry *ce; - ConfigFile *cfptr; - ConfigCommand *cc; - int errors = 0; + ConfigEntry *ce; + ConfigFile *cfptr; + ConfigCommand *cc; + int errors = 0; int i; Hook *h; @@ -3061,7 +3065,7 @@ int config_test_blocks() /* Stage 1: first the priority blocks, in the order as specified * in config_test_priority_blocks[] */ - for (i=0; i < ARRAY_SIZEOF(config_test_priority_blocks); i++) + for (i = 0; i < ARRAY_SIZEOF(config_test_priority_blocks); i++) { const char *config_block = config_test_priority_blocks[i]; cc = config_binary_search(config_block); @@ -3129,7 +3133,7 @@ int config_run_blocks_generic(ConfigFile *cfptr, int skip_priority_blocks) if (skip_priority_blocks) { char skip = 0; - for (i=0; i < ARRAY_SIZEOF(config_run_priority_blocks); i++) + for (i = 0; i < ARRAY_SIZEOF(config_run_priority_blocks); i++) { if (!strcmp(ce->name, config_run_priority_blocks[i])) { @@ -3151,13 +3155,12 @@ int config_run_blocks_generic(ConfigFile *cfptr, int skip_priority_blocks) cc->conffunc(cfptr, ce); processed++; } - } - else + } else { int value; for (h = Hooks[HOOKTYPE_CONFIGRUN]; h; h = h->next) { - value = (*(h->func.intfunc))(cfptr,ce,CONFIG_MAIN); + value = (*(h->func.intfunc))(cfptr, ce, CONFIG_MAIN); if (value == 1) { processed++; @@ -3181,10 +3184,10 @@ void set_server_linking_tlsoptions_ce(ConfigEntry *ce) int config_run_blocks(void) { - ConfigEntry *ce; - ConfigFile *cfptr; - ConfigCommand *cc; - int errors = 0; + ConfigEntry *ce; + ConfigFile *cfptr; + ConfigCommand *cc; + int errors = 0; int i; Hook *h; ConfigItem_allow *allow; @@ -3194,7 +3197,7 @@ int config_run_blocks(void) /* Stage 1: first the priority blocks, in the order as specified * in config_run_priority_blocks[] */ - for (i=0; i < ARRAY_SIZEOF(config_run_priority_blocks); i++) + for (i = 0; i < ARRAY_SIZEOF(config_run_priority_blocks); i++) { const char *config_block = config_run_priority_blocks[i]; cc = config_binary_search(config_block); @@ -3274,7 +3277,7 @@ int config_run_blocks(void) /* initialize conf_files with defaults if the block isn't set: */ if (!conf_files) - _conf_files(NULL, NULL); + _conf_files(NULL, NULL); if (errors > 0) { @@ -3318,9 +3321,9 @@ ConfigItem_class *find_class(const char *name) } -ConfigItem_oper *find_oper(const char *name) +ConfigItem_oper *find_oper(const char *name) { - ConfigItem_oper *e; + ConfigItem_oper *e; if (!name) return NULL; @@ -3342,7 +3345,7 @@ ConfigItem_operclass *find_operclass(const char *name) for (e = conf_operclass; e; e = e->next) { - if (!strcmp(name,e->classStruct->name)) + if (!strcmp(name, e->classStruct->name)) return e; } return NULL; @@ -3399,8 +3402,8 @@ ConfigItem_sni *find_sni(const char *name) for (e = conf_sni; e; e = e->next) { - if (match_simple(e->name, name)) - return e; + if (match_simple(e->name, name)) + return e; } return NULL; } @@ -3412,7 +3415,7 @@ ConfigItem_ulines *find_uline(const char *host) if (!host) return NULL; - for(ulines = conf_ulines; ulines; ulines = ulines->next) + for (ulines = conf_ulines; ulines; ulines = ulines->next) { if (!strcasecmp(host, ulines->servername)) return ulines; @@ -3443,13 +3446,13 @@ ConfigItem_tld *find_tld(Client *client) /** Find a link block by server name (but don't check any restrictions like IP or auth) */ ConfigItem_link *find_link(const char *servername) { - ConfigItem_link *link; + ConfigItem_link *link; for (link = conf_link; link; link = link->next) { if (!link->flag.temporary && match_simple(link->servername, servername)) { - return link; + return link; } } return NULL; @@ -3470,8 +3473,7 @@ ConfigItem_ban *find_ban(Client *client, const char *host, short type) { if (match_user(ban->mask, client, MATCH_CHECK_REAL)) return ban; - } - else if (match_simple(ban->mask, host)) + } else if (match_simple(ban->mask, host)) return ban; } } @@ -3482,7 +3484,7 @@ ConfigItem_ban *find_ban(Client *client, const char *host, short type) * CONF_BAN_SERVER, CONF_BAN_VERSION and CONF_BAN_REALNAME * This is the extended version, only used by cmd_svsnline. */ -ConfigItem_ban *find_banEx(Client *client, const char *host, short type, short type2) +ConfigItem_ban *find_banEx(Client *client, const char *host, short type, short type2) { ConfigItem_ban *ban; @@ -3494,8 +3496,7 @@ ConfigItem_ban *find_banEx(Client *client, const char *host, short type, short { if (match_user(ban->mask, client, MATCH_CHECK_REAL)) return ban; - } - else if (match_simple(ban->mask, host)) + } else if (match_simple(ban->mask, host)) return ban; } } @@ -3557,14 +3558,14 @@ const char *pretty_time_val_r(char *buf, size_t buflen, long timeval) buf[0] = 0; - if (timeval/86400) - snprintf(buf, buflen, "%ldd", timeval/86400); - if ((timeval/3600) % 24) - snprintf(buf+strlen(buf), buflen-strlen(buf), "%ldh", (timeval/3600)%24); - if ((timeval/60)%60) - snprintf(buf+strlen(buf), buflen-strlen(buf), "%ldm", (timeval/60)%60); - if ((timeval%60)) - snprintf(buf+strlen(buf), buflen-strlen(buf), "%lds", timeval%60); + if (timeval / 86400) + snprintf(buf, buflen, "%ldd", timeval / 86400); + if ((timeval / 3600) % 24) + snprintf(buf + strlen(buf), buflen - strlen(buf), "%ldh", (timeval / 3600) % 24); + if ((timeval / 60) % 60) + snprintf(buf + strlen(buf), buflen - strlen(buf), "%ldm", (timeval / 60) % 60); + if ((timeval % 60)) + snprintf(buf + strlen(buf), buflen - strlen(buf), "%lds", timeval % 60); return buf; } @@ -3637,7 +3638,7 @@ char *convert_to_absolute_path_duplicate(char *path, char *reldir) int _conf_include(ConfigFile *conf, ConfigEntry *ce) { - int ret = 0; + int ret = 0; #ifdef GLOBH glob_t files; int i; @@ -3649,8 +3650,8 @@ int _conf_include(ConfigFile *conf, ConfigEntry *ce) if (!ce->value) { config_status("%s:%i: include: no filename given", - ce->file->filename, - ce->line_number); + ce->file->filename, + ce->line_number); return -1; } @@ -3673,16 +3674,17 @@ int _conf_include(ConfigFile *conf, ConfigEntry *ce) (void)chmod(ce->value, DEFAULT_PERMISSIONS); #endif #ifdef GLOBH -#if defined(__OpenBSD__) && defined(GLOB_LIMIT) - glob(ce->value, GLOB_NOSORT|GLOB_NOCHECK|GLOB_LIMIT, NULL, &files); -#else - glob(ce->value, GLOB_NOSORT|GLOB_NOCHECK, NULL, &files); -#endif - if (!files.gl_pathc) { + #if defined(__OpenBSD__) && defined(GLOB_LIMIT) + glob(ce->value, GLOB_NOSORT | GLOB_NOCHECK | GLOB_LIMIT, NULL, &files); + #else + glob(ce->value, GLOB_NOSORT | GLOB_NOCHECK, NULL, &files); + #endif + if (!files.gl_pathc) + { globfree(&files); config_status("%s:%i: include %s: invalid file given", - ce->file->filename, ce->line_number, - ce->value); + ce->file->filename, ce->line_number, + ce->value); return -1; } for (i = 0; i < files.gl_pathc; i++) @@ -3700,22 +3702,24 @@ int _conf_include(ConfigFile *conf, ConfigEntry *ce) globfree(&files); #elif defined(_WIN32) memset(cPath, 0, MAX_PATH); - if (strchr(ce->value, '/') || strchr(ce->value, '\\')) { - strlcpy(cPath,ce->value,MAX_PATH); - cSlash=cPath+strlen(cPath); - while(*cSlash != '\\' && *cSlash != '/' && cSlash > cPath) + if (strchr(ce->value, '/') || strchr(ce->value, '\\')) + { + strlcpy(cPath, ce->value, MAX_PATH); + cSlash = cPath + strlen(cPath); + while (*cSlash != '\\' && *cSlash != '/' && cSlash > cPath) cSlash--; - *(cSlash+1)=0; + *(cSlash + 1) = 0; } - if ( (hFind = FindFirstFile(ce->value, &FindData)) == INVALID_HANDLE_VALUE ) + if ((hFind = FindFirstFile(ce->value, &FindData)) == INVALID_HANDLE_VALUE) { config_status("%s:%i: include %s: invalid file given", - ce->file->filename, ce->line_number, - ce->value); + ce->file->filename, ce->line_number, + ce->value); return -1; } - if (cPath) { - path = safe_alloc(strlen(cPath) + strlen(FindData.cFileName)+1); + if (cPath) + { + path = safe_alloc(strlen(cPath) + strlen(FindData.cFileName) + 1); strcpy(path, cPath); strcat(path, FindData.cFileName); @@ -3724,8 +3728,7 @@ int _conf_include(ConfigFile *conf, ConfigEntry *ce) ret = config_read_file(path, path); safe_free(path); } - } - else + } else { if (add_config_resource(FindData.cFileName, RESOURCE_INCLUDE, ce)) ret = config_read_file(FindData.cFileName, FindData.cFileName); @@ -3737,11 +3740,13 @@ int _conf_include(ConfigFile *conf, ConfigEntry *ce) } ret = 0; - while (FindNextFile(hFind, &FindData) != 0) { - if (cPath) { - path = safe_alloc(strlen(cPath) + strlen(FindData.cFileName)+1); - strcpy(path,cPath); - strcat(path,FindData.cFileName); + while (FindNextFile(hFind, &FindData) != 0) + { + if (cPath) + { + path = safe_alloc(strlen(cPath) + strlen(FindData.cFileName) + 1); + strcpy(path, cPath); + strcat(path, FindData.cFileName); if (add_config_resource(path, RESOURCE_INCLUDE, ce)) { @@ -3750,8 +3755,7 @@ int _conf_include(ConfigFile *conf, ConfigEntry *ce) if (ret < 0) break; } - } - else + } else { if (add_config_resource(FindData.cFileName, RESOURCE_INCLUDE, ce)) ret = config_read_file(FindData.cFileName, FindData.cFileName); @@ -3768,12 +3772,12 @@ int _conf_include(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_include(ConfigFile *conf, ConfigEntry *ce) +int _test_include(ConfigFile *conf, ConfigEntry *ce) { return 0; } -int _conf_admin(ConfigFile *conf, ConfigEntry *ce) +int _conf_admin(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigItem_admin *ca; @@ -3789,10 +3793,10 @@ int _conf_admin(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_admin(ConfigFile *conf, ConfigEntry *ce) +int _test_admin(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; - int errors = 0; + int errors = 0; if (requiredstuff.conf_admin) { @@ -3805,8 +3809,8 @@ int _test_admin(ConfigFile *conf, ConfigEntry *ce) if (strlen(cep->name) > 500) { config_error("%s:%i: oversized data in admin block", - cep->file->filename, - cep->line_number); + cep->file->filename, + cep->line_number); errors++; continue; } @@ -3815,7 +3819,7 @@ int _test_admin(ConfigFile *conf, ConfigEntry *ce) return errors; } -int _conf_me(ConfigFile *conf, ConfigEntry *ce) +int _conf_me(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; @@ -3827,12 +3831,10 @@ int _conf_me(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(cep->name, "name")) { safe_strdup(conf_me->name, cep->value); - } - else if (!strcmp(cep->name, "info")) + } else if (!strcmp(cep->name, "info")) { safe_strdup(conf_me->info, cep->value); - } - else if (!strcmp(cep->name, "sid")) + } else if (!strcmp(cep->name, "sid")) { safe_strdup(conf_me->sid, cep->value); } @@ -3840,11 +3842,11 @@ int _conf_me(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_me(ConfigFile *conf, ConfigEntry *ce) +int _test_me(ConfigFile *conf, ConfigEntry *ce) { char has_name = 0, has_info = 0, has_sid = 0; ConfigEntry *cep; - int errors = 0; + int errors = 0; if (requiredstuff.conf_me) { @@ -3863,29 +3865,29 @@ int _test_me(ConfigFile *conf, ConfigEntry *ce) if (has_name) { config_warn_duplicate(cep->file->filename, - cep->line_number, "me::name"); + cep->line_number, "me::name"); continue; } has_name = 1; if (!strchr(cep->value, '.')) { config_error("%s:%i: illegal me::name, must be fully qualified hostname", - cep->file->filename, - cep->line_number); + cep->file->filename, + cep->line_number); errors++; } if (strlen(cep->value) > HOSTLEN) { config_error("%s:%i: illegal me::name, must be less or equal to %i characters", - cep->file->filename, - cep->line_number, HOSTLEN); + cep->file->filename, + cep->line_number, HOSTLEN); errors++; } if (!valid_server_name(cep->value)) { config_error("%s:%i: illegal me::name contains invalid character(s) [only a-z, 0-9, _, -, . are allowed]", - cep->file->filename, - cep->line_number); + cep->file->filename, + cep->line_number); errors++; } } @@ -3897,20 +3899,20 @@ int _test_me(ConfigFile *conf, ConfigEntry *ce) if (has_info) { config_warn_duplicate(cep->file->filename, - cep->line_number, "me::info"); + cep->line_number, "me::info"); continue; } has_info = 1; - if (strlen(cep->value) > (REALLEN-1)) + if (strlen(cep->value) > (REALLEN - 1)) { config_error("%s:%i: too long me::info, must be max. %i characters", - cep->file->filename, cep->line_number, - REALLEN-1); + cep->file->filename, cep->line_number, + REALLEN - 1); errors++; } /* Valid me::info? Any data except spaces is ok */ - for (p=cep->value; *p; p++) + for (p = cep->value; *p; p++) { if (*p != ' ') { @@ -3921,24 +3923,22 @@ int _test_me(ConfigFile *conf, ConfigEntry *ce) if (!valid) { config_error("%s:%i: empty me::info, should be a server description.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "numeric")) + } else if (!strcmp(cep->name, "numeric")) { config_error("%s:%i: me::numeric has been removed, you must now specify a Server ID (SID) instead. " "Edit your configuration file and change 'numeric' to 'sid' and make up " "a server id of exactly 3 characters, starting with a digit, eg: \"001\" or \"0AB\".", cep->file->filename, cep->line_number); errors++; - } - else if (!strcmp(cep->name, "sid")) + } else if (!strcmp(cep->name, "sid")) { if (has_sid) { config_warn_duplicate(cep->file->filename, - cep->line_number, "me::sid"); + cep->line_number, "me::sid"); continue; } has_sid = 1; @@ -3955,7 +3955,7 @@ int _test_me(ConfigFile *conf, ConfigEntry *ce) if (!isdigit(*cep->value)) { config_error("%s:%i: me::sid must be 3 characters long and begin with a number", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } } @@ -3963,7 +3963,7 @@ int _test_me(ConfigFile *conf, ConfigEntry *ce) else { config_error_unknown(ce->file->filename, ce->line_number, - "me", cep->name); + "me", cep->name); errors++; } } @@ -3989,7 +3989,7 @@ int _test_me(ConfigFile *conf, ConfigEntry *ce) /* * The files {} block */ -int _conf_files(ConfigFile *conf, ConfigEntry *ce) +int _conf_files(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; @@ -4017,7 +4017,7 @@ int _conf_files(ConfigFile *conf, ConfigEntry *ce) * if config_run_blocks() calls us with a NULL ce, it's got a bug...but we can't detect that. */ if (!ce) - return 1; + return 1; for (cep = ce->items; cep; cep = cep->next) { @@ -4041,10 +4041,10 @@ int _conf_files(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_files(ConfigFile *conf, ConfigEntry *ce) +int _test_files(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; - int errors = 0; + int errors = 0; char has_motd = 0, has_smotd = 0, has_rules = 0; char has_botmotd = 0, has_opermotd = 0, has_svsmotd = 0; char has_pidfile = 0, has_tunefile = 0; @@ -4057,7 +4057,7 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) if (has_motd) { config_warn_duplicate(cep->file->filename, - cep->line_number, "files::motd"); + cep->line_number, "files::motd"); continue; } convert_to_absolute_path(&cep->value, CONFDIR); @@ -4070,7 +4070,7 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) if (has_smotd) { config_warn_duplicate(cep->file->filename, - cep->line_number, "files::shortmotd"); + cep->line_number, "files::shortmotd"); continue; } convert_to_absolute_path(&cep->value, CONFDIR); @@ -4083,7 +4083,7 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) if (has_rules) { config_warn_duplicate(cep->file->filename, - cep->line_number, "files::rules"); + cep->line_number, "files::rules"); continue; } convert_to_absolute_path(&cep->value, CONFDIR); @@ -4096,7 +4096,7 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) if (has_botmotd) { config_warn_duplicate(cep->file->filename, - cep->line_number, "files::botmotd"); + cep->line_number, "files::botmotd"); continue; } convert_to_absolute_path(&cep->value, CONFDIR); @@ -4109,7 +4109,7 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) if (has_opermotd) { config_warn_duplicate(cep->file->filename, - cep->line_number, "files::opermotd"); + cep->line_number, "files::opermotd"); continue; } convert_to_absolute_path(&cep->value, CONFDIR); @@ -4124,7 +4124,7 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) if (has_svsmotd) { config_warn_duplicate(cep->file->filename, - cep->line_number, "files::svsmotd"); + cep->line_number, "files::svsmotd"); continue; } convert_to_absolute_path(&cep->value, CONFDIR); @@ -4138,7 +4138,7 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) if (has_pidfile) { config_warn_duplicate(cep->file->filename, - cep->line_number, "files::pidfile"); + cep->line_number, "files::pidfile"); continue; } convert_to_absolute_path(&cep->value, PERMDATADIR); @@ -4151,7 +4151,7 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) if (has_tunefile) { config_warn_duplicate(cep->file->filename, - cep->line_number, "files::tunefile"); + cep->line_number, "files::tunefile"); continue; } convert_to_absolute_path(&cep->value, PERMDATADIR); @@ -4162,8 +4162,8 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) else { config_error("%s:%d: Unknown directive: \"%s\" in files {}", cep->file->filename, - cep->line_number, cep->name); - errors ++; + cep->line_number, cep->name); + errors++; } } return errors; @@ -4173,13 +4173,13 @@ int _test_files(ConfigFile *conf, ConfigEntry *ce) * The operclass {} block parser */ -OperClassACLEntry* _conf_parseACLEntry(ConfigEntry *ce) +OperClassACLEntry *_conf_parseACLEntry(ConfigEntry *ce) { ConfigEntry *cep; OperClassACLEntry *entry = NULL; entry = safe_alloc(sizeof(OperClassACLEntry)); - if (!strcmp(ce->name,"allow")) + if (!strcmp(ce->name, "allow")) entry->type = OPERCLASSENTRY_ALLOW; else entry->type = OPERCLASSENTRY_DENY; @@ -4192,13 +4192,13 @@ OperClassACLEntry* _conf_parseACLEntry(ConfigEntry *ce) { safe_strdup(var->value, cep->value); } - AddListItem(var,entry->variables); + AddListItem(var, entry->variables); } return entry; } -OperClassACL* _conf_parseACL(const char *name, ConfigEntry *ce) +OperClassACL *_conf_parseACL(const char *name, ConfigEntry *ce) { ConfigEntry *cep; OperClassACL *acl = NULL; @@ -4211,11 +4211,11 @@ OperClassACL* _conf_parseACL(const char *name, ConfigEntry *ce) if (!strcmp(cep->name, "deny") || !strcmp(cep->name, "allow")) { OperClassACLEntry *entry = _conf_parseACLEntry(cep); - AddListItem(entry,acl->entries); - } - else { - OperClassACL *subAcl = _conf_parseACL(cep->name,cep); - AddListItem(subAcl,acl->acls); + AddListItem(entry, acl->entries); + } else + { + OperClassACL *subAcl = _conf_parseACL(cep->name, cep); + AddListItem(subAcl, acl->acls); } } @@ -4274,7 +4274,7 @@ void free_operclass_struct(OperClass *o) safe_free(o); } -int _conf_operclass(ConfigFile *conf, ConfigEntry *ce) +int _conf_operclass(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigEntry *cepp; @@ -4288,13 +4288,12 @@ int _conf_operclass(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(cep->name, "parent")) { safe_strdup(operClass->classStruct->ISA, cep->value); - } - else if (!strcmp(cep->name, "permissions")) + } else if (!strcmp(cep->name, "permissions")) { for (cepp = cep->items; cepp; cepp = cepp->next) { - OperClassACL *acl = _conf_parseACL(cepp->name,cepp); - AddListItem(acl,operClass->classStruct->acls); + OperClassACL *acl = _conf_parseACL(cepp->name, cepp); + AddListItem(acl, operClass->classStruct->acls); } } } @@ -4321,18 +4320,17 @@ void new_permissions_system(ConfigFile *conf, ConfigEntry *ce) need_operclass_permissions_upgrade = 1; } -int _test_operclass(ConfigFile *conf, ConfigEntry *ce) +int _test_operclass(ConfigFile *conf, ConfigEntry *ce) { int has_permissions = 0, has_parent = 0; ConfigEntry *cep; - int errors = 0; + int errors = 0; if (!ce->value) { config_error_noname(ce->file->filename, ce->line_number, "operclass"); errors++; - } else - if (!valid_operclass_name(ce->value)) + } else if (!valid_operclass_name(ce->value)) { config_error("%s:%d: operclass name may only contain alphanumerical characters and " "characters _-", @@ -4353,17 +4351,15 @@ int _test_operclass(ConfigFile *conf, ConfigEntry *ce) if (ce->value && !strcmp(cep->value, ce->value)) { config_error("%s:%d: operclass %s has parent set to %s (same name).", - cep->file->filename, cep->line_number, ce->name, cep->value); + cep->file->filename, cep->line_number, ce->name, cep->value); errors++; } has_parent = 1; continue; - } else - if (!strcmp(cep->name, "permissions")) + } else if (!strcmp(cep->name, "permissions")) { config_detect_duplicate(&has_permissions, cep, &errors); - } else - if (!strcmp(cep->name, "privileges")) + } else if (!strcmp(cep->name, "privileges")) { new_permissions_system(conf, cep); errors++; @@ -4371,7 +4367,7 @@ int _test_operclass(ConfigFile *conf, ConfigEntry *ce) } else { config_error_unknown(cep->file->filename, - cep->line_number, "operclass", cep->name); + cep->line_number, "operclass", cep->name); errors++; } } @@ -4379,7 +4375,7 @@ int _test_operclass(ConfigFile *conf, ConfigEntry *ce) if (!has_permissions) { config_error_missing(ce->file->filename, ce->line_number, - "operclass::permissions"); + "operclass::permissions"); errors++; } @@ -4390,13 +4386,13 @@ int _test_operclass(ConfigFile *conf, ConfigEntry *ce) * The oper {} block parser */ -int _conf_oper(ConfigFile *conf, ConfigEntry *ce) +int _conf_oper(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigEntry *cepp; ConfigItem_oper *oper = NULL; - oper = safe_alloc(sizeof(ConfigItem_oper)); + oper = safe_alloc(sizeof(ConfigItem_oper)); safe_strdup(oper->name, ce->value); oper->match = safe_alloc(sizeof(SecurityGroup)); @@ -4416,12 +4412,11 @@ int _conf_oper(ConfigFile *conf, ConfigEntry *ce) if (!oper->class || (oper->class->flag.temporary == 1)) { config_status("%s:%i: illegal oper::class, unknown class '%s' using default of class 'default'", - cep->file->filename, cep->line_number, - cep->value); + cep->file->filename, cep->line_number, + cep->value); oper->class = default_class; } - } - else if (!strcmp(cep->name, "swhois")) + } else if (!strcmp(cep->name, "swhois")) { SWhois *s; if (cep->items) @@ -4433,52 +4428,41 @@ int _conf_oper(ConfigFile *conf, ConfigEntry *ce) safe_strdup(s->setby, "oper"); AddListItem(s, oper->swhois); } - } else - if (cep->value) + } else if (cep->value) { s = safe_alloc(sizeof(SWhois)); safe_strdup(s->line, cep->value); safe_strdup(s->setby, "oper"); AddListItem(s, oper->swhois); } - } - else if (!strcmp(cep->name, "snomask")) + } else if (!strcmp(cep->name, "snomask")) { safe_strdup(oper->snomask, cep->value); - } - else if (!strcmp(cep->name, "server-notice-colors")) + } else if (!strcmp(cep->name, "server-notice-colors")) { oper->server_notice_colors = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "server-notice-show-event")) + } else if (!strcmp(cep->name, "server-notice-show-event")) { oper->server_notice_show_event = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "auto-join")) + } else if (!strcmp(cep->name, "auto-join")) { safe_strdup(oper->auto_join, cep->value); - } - else if (!strcmp(cep->name, "auto-login")) + } else if (!strcmp(cep->name, "auto-login")) { oper->auto_login = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "modes")) + } else if (!strcmp(cep->name, "modes")) { oper->modes = set_usermode(cep->value); - } - else if (!strcmp(cep->name, "require-modes")) + } else if (!strcmp(cep->name, "require-modes")) { oper->require_modes = set_usermode(cep->value); - } - else if (!strcmp(cep->name, "maxlogins")) + } else if (!strcmp(cep->name, "maxlogins")) { oper->maxlogins = atoi(cep->value); - } - else if (!strcmp(cep->name, "mask") || !strcmp(cep->name, "match")) + } else if (!strcmp(cep->name, "mask") || !strcmp(cep->name, "match")) { conf_match_block(conf, cep, &oper->match); - } - else if (!strcmp(cep->name, "vhost")) + } else if (!strcmp(cep->name, "vhost")) { safe_strdup(oper->vhost, cep->value); } @@ -4487,7 +4471,7 @@ int _conf_oper(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_oper(ConfigFile *conf, ConfigEntry *ce) +int _test_oper(ConfigFile *conf, ConfigEntry *ce) { char has_class = 0, has_password = 0, has_snomask = 0; char has_modes = 0, has_require_modes = 0, has_mask = 0, has_match = 0, has_broad_match = 0; @@ -4516,12 +4500,12 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) has_password = 1; if (ce->value && cep->value && - !strcmp(ce->value, "bobsmith") && - (!strcmp(cep->value, "test") || !strcmp(cep->value, "$argon2id..etc.."))) + !strcmp(ce->value, "bobsmith") && + (!strcmp(cep->value, "test") || !strcmp(cep->value, "$argon2id..etc.."))) { config_error("%s:%i: please change the the name and password of the " - "default 'bobsmith' oper block", - ce->file->filename, ce->line_number); + "default 'bobsmith' oper block", + ce->file->filename, ce->line_number); errors++; continue; } @@ -4537,7 +4521,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (has_operclass) { config_warn_duplicate(cep->file->filename, - cep->line_number, "oper::operclass"); + cep->line_number, "oper::operclass"); continue; } has_operclass = 1; @@ -4549,7 +4533,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (has_class) { config_warn_duplicate(cep->file->filename, - cep->line_number, "oper::class"); + cep->line_number, "oper::class"); continue; } has_class = 1; @@ -4564,7 +4548,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (has_vhost) { config_warn_duplicate(cep->file->filename, - cep->line_number, "oper::vhost"); + cep->line_number, "oper::vhost"); continue; } if (!potentially_valid_vhost(cep->value)) @@ -4582,7 +4566,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (has_snomask) { config_warn_duplicate(cep->file->filename, - cep->line_number, "oper::snomask"); + cep->line_number, "oper::snomask"); continue; } if (!is_valid_snomask_string_testing(cep->value, &wrong_snomask)) @@ -4593,17 +4577,13 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) invalid_snomasks_encountered++; } has_snomask = 1; - } - else if (!strcmp(cep->name, "server-notice-colors")) + } else if (!strcmp(cep->name, "server-notice-colors")) { - } - else if (!strcmp(cep->name, "server-notice-show-event")) + } else if (!strcmp(cep->name, "server-notice-show-event")) { - } - else if (!strcmp(cep->name, "auto-join")) + } else if (!strcmp(cep->name, "auto-join")) { - } - else if (!strcmp(cep->name, "auto-login")) + } else if (!strcmp(cep->name, "auto-login")) { has_auto_login = config_checkval(cep->value, CFG_YESNO); } @@ -4615,13 +4595,13 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (strchr("orzS", *p)) { config_error("%s:%i: oper::modes may not include mode '%c'", - cep->file->filename, cep->line_number, *p); + cep->file->filename, cep->line_number, *p); errors++; } if (has_modes) { config_warn_duplicate(cep->file->filename, - cep->line_number, "oper::modes"); + cep->line_number, "oper::modes"); continue; } has_modes = 1; @@ -4634,12 +4614,12 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (strchr("o", *p)) { config_warn("%s:%i: oper::require-modes probably shouldn't include mode '%c'", - cep->file->filename, cep->line_number, *p); + cep->file->filename, cep->line_number, *p); } if (has_require_modes) { config_warn_duplicate(cep->file->filename, - cep->line_number, "oper::require-modes"); + cep->line_number, "oper::require-modes"); continue; } has_require_modes = 1; @@ -4652,7 +4632,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (has_maxlogins) { config_warn_duplicate(cep->file->filename, - cep->line_number, "oper::maxlogins"); + cep->line_number, "oper::maxlogins"); continue; } has_maxlogins = 1; @@ -4661,12 +4641,11 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if ((l < 0) || (l > 5000)) { config_error("%s:%i: oper::maxlogins: value out of range (%d) should be 0-5000", - cep->file->filename, cep->line_number, l); + cep->file->filename, cep->line_number, l); errors++; continue; } - } - else if (!strcmp(cep->name, "mask")) + } else if (!strcmp(cep->name, "mask")) { if (cep->value || cep->items) { @@ -4675,8 +4654,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (test_match_block_too_broad(conf, cep)) has_broad_match = 1; } - } - else if (!strcmp(cep->name, "match")) + } else if (!strcmp(cep->name, "match")) { if (cep->value || cep->items) { @@ -4685,11 +4663,10 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (test_match_block_too_broad(conf, cep)) has_broad_match = 1; } - } - else + } else { config_error_unknown(cep->file->filename, - cep->line_number, "oper", cep->name); + cep->line_number, "oper", cep->name); errors++; continue; } @@ -4700,8 +4677,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(cep->name, "swhois")) { /* ok */ - } - else if (!strcmp(cep->name, "mask")) + } else if (!strcmp(cep->name, "mask")) { if (cep->value || cep->items) { @@ -4710,8 +4686,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (test_match_block_too_broad(conf, cep)) has_broad_match = 1; } - } - else if (!strcmp(cep->name, "match")) + } else if (!strcmp(cep->name, "match")) { if (cep->value || cep->items) { @@ -4720,17 +4695,15 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (test_match_block_too_broad(conf, cep)) has_broad_match = 1; } - } - else if (!strcmp(cep->name, "password")) + } else if (!strcmp(cep->name, "password")) { has_password = 1; if (Auth_CheckError(cep, 1) < 0) errors++; - } - else + } else { config_error_unknown(cep->file->filename, - cep->line_number, "oper", cep->name); + cep->line_number, "oper", cep->name); errors++; continue; } @@ -4742,8 +4715,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) config_error("%s:%i: your oper block for '%s' has auto-login but is completely unrestricted (mask *@*)!", ce->file->filename, ce->line_number, ce->value); errors++; - } else - if (!has_password && has_broad_match) + } else if (!has_password && has_broad_match) { config_error("%s:%i: your oper block for '%s' has no password and is completely unrestricted (mask *@*)!", ce->file->filename, ce->line_number, ce->value); @@ -4761,7 +4733,7 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (!has_mask && !has_match) { config_error_missing(ce->file->filename, ce->line_number, - "oper::match"); + "oper::match"); errors++; } if (has_mask && has_match) @@ -4774,18 +4746,17 @@ int _test_oper(ConfigFile *conf, ConfigEntry *ce) if (!has_class) { config_error_missing(ce->file->filename, ce->line_number, - "oper::class"); + "oper::class"); errors++; } if (!has_operclass) { config_error_missing(ce->file->filename, ce->line_number, - "oper::operclass"); + "oper::operclass"); errors++; } return errors; - } ProxyType proxy_type_string_to_value(const char *s) @@ -4815,14 +4786,14 @@ int _test_proxy(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(ce->name, "webirc")) { proxy_type = PROXY_WEBIRC; - } else { + } else + { if (!ce->value) { config_error("%s:%i: proxy { } blocks need to have a name, like proxy myproxy { }", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; - } else - if (!security_group_valid_name(ce->value)) + } else if (!security_group_valid_name(ce->value)) { config_error("%s:%i: the name of the proxy block may only contain a-z, A-Z, 0-9, _ and -. " "Your block name is invalid: '%s'", @@ -4841,25 +4812,22 @@ int _test_proxy(ConfigFile *conf, ConfigEntry *ce) has_mask = 1; test_match_block(conf, cep, &errors); } - } else - if (!cep->value) + } else if (!cep->value) { config_error_empty(cep->file->filename, cep->line_number, - "proxy", cep->name); + "proxy", cep->name); errors++; - } else - if (!strcmp(cep->name, "password")) + } else if (!strcmp(cep->name, "password")) { has_password = 1; if (Auth_CheckError(cep, 0) < 0) errors++; - } - else if (!strcmp(cep->name, "type")) + } else if (!strcmp(cep->name, "type")) { if (has_type) { config_warn_duplicate(cep->file->filename, - cep->line_number, "proxy::type"); + cep->line_number, "proxy::type"); } has_type = 1; if (!strcmp(cep->value, "web")) @@ -4880,28 +4848,27 @@ int _test_proxy(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number, cep->value); errors++; } - } - else + } else { config_error_unknown(cep->file->filename, cep->line_number, - "webirc", cep->name); + "webirc", cep->name); errors++; } } if (!has_mask) { config_error_missing(ce->file->filename, ce->line_number, - "webirc::mask"); + "webirc::mask"); errors++; } if (!has_password && (proxy_type == PROXY_WEBIRC)) { config_error_missing(ce->file->filename, ce->line_number, - "webirc::password"); + "webirc::password"); errors++; } - + if (has_password && (proxy_type == PROXY_WEBIRC_PASS)) { config_error("%s:%i: webirc block has type set to 'old' but has a password set. " @@ -4949,7 +4916,7 @@ int _conf_proxy(ConfigFile *conf, ConfigEntry *ce) { SecurityGroup *sg = duplicate_security_group(proxy->mask); tkl_add_banexception(TKL_EXCEPTION, "-", "-", sg, "proxy { } block", - "-config-", 0, TStime(), 0, "bcd", TKL_FLAG_CONFIG); + "-config-", 0, TStime(), 0, "bcd", TKL_FLAG_CONFIG); } return 1; @@ -4958,7 +4925,7 @@ int _conf_proxy(ConfigFile *conf, ConfigEntry *ce) /* * The class {} block parser */ -int _conf_class(ConfigFile *conf, ConfigEntry *ce) +int _conf_class(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cep2; ConfigItem_class *class; @@ -4970,8 +4937,7 @@ int _conf_class(ConfigFile *conf, ConfigEntry *ce) class = safe_alloc(sizeof(ConfigItem_class)); safe_strdup(class->name, ce->value); isnew = 1; - } - else + } else { isnew = 0; class->flag.temporary = 0; @@ -4984,15 +4950,15 @@ int _conf_class(ConfigFile *conf, ConfigEntry *ce) for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "pingfreq")) - class->pingfreq = config_checkval(cep->value,CFG_TIME); + class->pingfreq = config_checkval(cep->value, CFG_TIME); else if (!strcmp(cep->name, "connfreq")) - class->connfreq = config_checkval(cep->value,CFG_TIME); + class->connfreq = config_checkval(cep->value, CFG_TIME); else if (!strcmp(cep->name, "maxclients")) class->maxclients = atol(cep->value); else if (!strcmp(cep->name, "sendq")) - class->sendq = config_checkval(cep->value,CFG_SIZE); + class->sendq = config_checkval(cep->value, CFG_SIZE); else if (!strcmp(cep->name, "recvq")) - class->recvq = config_checkval(cep->value,CFG_SIZE); + class->recvq = config_checkval(cep->value, CFG_SIZE); else if (!strcmp(cep->name, "options")) { for (cep2 = cep->items; cep2; cep2 = cep2->next) @@ -5011,10 +4977,10 @@ int _conf_class(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_class(ConfigFile *conf, ConfigEntry *ce) +int _test_class(ConfigFile *conf, ConfigEntry *ce) { - ConfigEntry *cep, *cep2; - int errors = 0; + ConfigEntry *cep, *cep2; + int errors = 0; char has_pingfreq = 0, has_connfreq = 0, has_maxclients = 0, has_sendq = 0; char has_recvq = 0; Hook *h; @@ -5027,7 +4993,7 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) if (!strcasecmp(ce->value, "default")) { config_error("%s:%d: Class cannot be named 'default', this class name is reserved for internal use.", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } @@ -5039,8 +5005,7 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) { continue; } @@ -5078,12 +5043,11 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) #endif { config_error("%s:%d: Unknown option '%s' in class::options", - cep2->file->filename, cep2->line_number, cep2->name); + cep2->file->filename, cep2->line_number, cep2->name); errors++; } } - } - else if (config_is_blankorempty(cep, "class")) + } else if (config_is_blankorempty(cep, "class")) { errors++; continue; @@ -5091,18 +5055,18 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) /* class::pingfreq */ else if (!strcmp(cep->name, "pingfreq")) { - int v = config_checkval(cep->value,CFG_TIME); + int v = config_checkval(cep->value, CFG_TIME); if (has_pingfreq) { config_warn_duplicate(cep->file->filename, - cep->line_number, "class::pingfreq"); + cep->line_number, "class::pingfreq"); continue; } has_pingfreq = 1; if ((v < 30) || (v > 600)) { config_error("%s:%i: class::pingfreq should be a reasonable value (30-600)", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } @@ -5114,7 +5078,7 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) if (has_maxclients) { config_warn_duplicate(cep->file->filename, - cep->line_number, "class::maxclients"); + cep->line_number, "class::maxclients"); continue; } has_maxclients = 1; @@ -5122,7 +5086,7 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) if ((l < 1) || (l > 1000000)) { config_error("%s:%i: class::maxclients with illegal value", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } } @@ -5133,15 +5097,15 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) if (has_connfreq) { config_warn_duplicate(cep->file->filename, - cep->line_number, "class::connfreq"); + cep->line_number, "class::connfreq"); continue; } has_connfreq = 1; - l = config_checkval(cep->value,CFG_TIME); + l = config_checkval(cep->value, CFG_TIME); if ((l < 5) || (l > 604800)) { config_error("%s:%i: class::connfreq with illegal value (must be >5 and <7d)", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } } @@ -5152,15 +5116,15 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) if (has_sendq) { config_warn_duplicate(cep->file->filename, - cep->line_number, "class::sendq"); + cep->line_number, "class::sendq"); continue; } has_sendq = 1; - l = config_checkval(cep->value,CFG_SIZE); + l = config_checkval(cep->value, CFG_SIZE); if ((l <= 0) || (l > 2000000000)) { config_error("%s:%i: class::sendq with illegal value", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } } @@ -5171,15 +5135,15 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) if (has_recvq) { config_warn_duplicate(cep->file->filename, - cep->line_number, "class::recvq"); + cep->line_number, "class::recvq"); continue; } has_recvq = 1; - l = config_checkval(cep->value,CFG_SIZE); + l = config_checkval(cep->value, CFG_SIZE); if ((l < 512) || (l > 32768)) { config_error("%s:%i: class::recvq with illegal value (must be >512 and <32k)", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } } @@ -5187,7 +5151,7 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) else { config_error_unknown(cep->file->filename, cep->line_number, - "class", cep->name); + "class", cep->name); errors++; continue; } @@ -5195,32 +5159,32 @@ int _test_class(ConfigFile *conf, ConfigEntry *ce) if (!has_pingfreq) { config_error_missing(ce->file->filename, ce->line_number, - "class::pingfreq"); + "class::pingfreq"); errors++; } if (!has_maxclients) { config_error_missing(ce->file->filename, ce->line_number, - "class::maxclients"); + "class::maxclients"); errors++; } if (!has_sendq) { config_error_missing(ce->file->filename, ce->line_number, - "class::sendq"); + "class::sendq"); errors++; } return errors; } -int _conf_drpass(ConfigFile *conf, ConfigEntry *ce) +int _conf_drpass(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; if (!conf_drpass) { - conf_drpass = safe_alloc(sizeof(ConfigItem_drpass)); + conf_drpass = safe_alloc(sizeof(ConfigItem_drpass)); } for (cep = ce->items; cep; cep = cep->next) @@ -5233,7 +5197,7 @@ int _conf_drpass(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_drpass(ConfigFile *conf, ConfigEntry *ce) +int _test_drpass(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; int errors = 0; @@ -5252,7 +5216,7 @@ int _test_drpass(ConfigFile *conf, ConfigEntry *ce) if (has_restart) { config_warn_duplicate(cep->file->filename, - cep->line_number, "drpass::restart"); + cep->line_number, "drpass::restart"); continue; } has_restart = 1; @@ -5266,7 +5230,7 @@ int _test_drpass(ConfigFile *conf, ConfigEntry *ce) if (has_die) { config_warn_duplicate(cep->file->filename, - cep->line_number, "drpass::die"); + cep->line_number, "drpass::die"); continue; } has_die = 1; @@ -5278,7 +5242,7 @@ int _test_drpass(ConfigFile *conf, ConfigEntry *ce) else { config_error_unknown(cep->file->filename, cep->line_number, - "drpass", cep->name); + "drpass", cep->name); errors++; continue; } @@ -5289,7 +5253,7 @@ int _test_drpass(ConfigFile *conf, ConfigEntry *ce) /* * The ulines {} block parser */ -int _conf_ulines(ConfigFile *conf, ConfigEntry *ce) +int _conf_ulines(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigItem_ulines *ca; @@ -5303,13 +5267,13 @@ int _conf_ulines(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_ulines(ConfigFile *conf, ConfigEntry *ce) +int _test_ulines(ConfigFile *conf, ConfigEntry *ce) { /* No check needed */ return 0; } -int _conf_tld(ConfigFile *conf, ConfigEntry *ce) +int _conf_tld(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigItem_tld *ca; @@ -5324,28 +5288,23 @@ int _conf_tld(ConfigFile *conf, ConfigEntry *ce) { safe_strdup(ca->motd_file, cep->value); read_motd(cep->value, &ca->motd); - } - else if (!strcmp(cep->name, "shortmotd")) + } else if (!strcmp(cep->name, "shortmotd")) { safe_strdup(ca->smotd_file, cep->value); read_motd(cep->value, &ca->smotd); - } - else if (!strcmp(cep->name, "opermotd")) + } else if (!strcmp(cep->name, "opermotd")) { safe_strdup(ca->opermotd_file, cep->value); read_motd(cep->value, &ca->opermotd); - } - else if (!strcmp(cep->name, "botmotd")) + } else if (!strcmp(cep->name, "botmotd")) { safe_strdup(ca->botmotd_file, cep->value); read_motd(cep->value, &ca->botmotd); - } - else if (!strcmp(cep->name, "rules")) + } else if (!strcmp(cep->name, "rules")) { safe_strdup(ca->rules_file, cep->value); read_motd(cep->value, &ca->rules); - } - else if (!strcmp(cep->name, "options")) + } else if (!strcmp(cep->name, "options")) { ConfigEntry *cepp; for (cepp = cep->items; cepp; cepp = cepp->next) @@ -5355,19 +5314,18 @@ int _conf_tld(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cepp->name, "remote")) ca->options |= TLD_REMOTE; } - } - else if (!strcmp(cep->name, "channel")) + } else if (!strcmp(cep->name, "channel")) safe_strdup(ca->channel, cep->value); } AddListItem(ca, conf_tld); return 1; } -int _test_tld(ConfigFile *conf, ConfigEntry *ce) +int _test_tld(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; - int errors = 0; - int fd = -1; + int errors = 0; + int fd = -1; char has_mask = 0, has_match = 0, has_motd = 0, has_rules = 0, has_shortmotd = 0; char has_channel = 0, has_opermotd = 0, has_botmotd = 0, has_options = 0; @@ -5376,7 +5334,7 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (!cep->value && strcmp(cep->name, "options") && strcmp(cep->name, "mask") && strcmp(cep->name, "match")) { config_error_empty(cep->file->filename, cep->line_number, - "tld", cep->name); + "tld", cep->name); errors++; continue; } @@ -5388,8 +5346,7 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) has_mask = 1; test_match_block(conf, cep, &errors); } - } - else if (!strcmp(cep->name, "match")) + } else if (!strcmp(cep->name, "match")) { if (cep->value || cep->items) { @@ -5403,7 +5360,7 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (has_motd) { config_warn_duplicate(cep->file->filename, - cep->line_number, "tld::motd"); + cep->line_number, "tld::motd"); continue; } has_motd = 1; @@ -5411,11 +5368,10 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (((fd = open(cep->value, O_RDONLY)) == -1)) { config_error("%s:%i: tld::motd: %s: %s", - cep->file->filename, cep->line_number, - cep->value, strerror(errno)); + cep->file->filename, cep->line_number, + cep->value, strerror(errno)); errors++; - } - else + } else close(fd); } /* tld::rules */ @@ -5424,7 +5380,7 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (has_rules) { config_warn_duplicate(cep->file->filename, - cep->line_number, "tld::rules"); + cep->line_number, "tld::rules"); continue; } has_rules = 1; @@ -5432,11 +5388,10 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (((fd = open(cep->value, O_RDONLY)) == -1)) { config_error("%s:%i: tld::rules: %s: %s", - cep->file->filename, cep->line_number, - cep->value, strerror(errno)); + cep->file->filename, cep->line_number, + cep->value, strerror(errno)); errors++; - } - else + } else close(fd); } /* tld::channel */ @@ -5445,7 +5400,7 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (has_channel) { config_warn_duplicate(cep->file->filename, - cep->line_number, "tld::channel"); + cep->line_number, "tld::channel"); continue; } has_channel = 1; @@ -5456,7 +5411,7 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (has_shortmotd) { config_warn_duplicate(cep->file->filename, - cep->line_number, "tld::shortmotd"); + cep->line_number, "tld::shortmotd"); continue; } has_shortmotd = 1; @@ -5464,11 +5419,10 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (((fd = open(cep->value, O_RDONLY)) == -1)) { config_error("%s:%i: tld::shortmotd: %s: %s", - cep->file->filename, cep->line_number, - cep->value, strerror(errno)); + cep->file->filename, cep->line_number, + cep->value, strerror(errno)); errors++; - } - else + } else close(fd); } /* tld::opermotd */ @@ -5477,7 +5431,7 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (has_opermotd) { config_warn_duplicate(cep->file->filename, - cep->line_number, "tld::opermotd"); + cep->line_number, "tld::opermotd"); continue; } has_opermotd = 1; @@ -5485,11 +5439,10 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (((fd = open(cep->value, O_RDONLY)) == -1)) { config_error("%s:%i: tld::opermotd: %s: %s", - cep->file->filename, cep->line_number, - cep->value, strerror(errno)); + cep->file->filename, cep->line_number, + cep->value, strerror(errno)); errors++; - } - else + } else close(fd); } /* tld::botmotd */ @@ -5498,7 +5451,7 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (has_botmotd) { config_warn_duplicate(cep->file->filename, - cep->line_number, "tld::botmotd"); + cep->line_number, "tld::botmotd"); continue; } has_botmotd = 1; @@ -5506,21 +5459,21 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (((fd = open(cep->value, O_RDONLY)) == -1)) { config_error("%s:%i: tld::botmotd: %s: %s", - cep->file->filename, cep->line_number, - cep->value, strerror(errno)); + cep->file->filename, cep->line_number, + cep->value, strerror(errno)); errors++; - } - else + } else close(fd); } /* tld::options */ - else if (!strcmp(cep->name, "options")) { + else if (!strcmp(cep->name, "options")) + { ConfigEntry *cep2; if (has_options) { config_warn_duplicate(cep->file->filename, - cep->line_number, "tld::options"); + cep->line_number, "tld::options"); continue; } has_options = 1; @@ -5532,15 +5485,14 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) strcmp(cep2->name, "remote")) { config_error_unknownopt(cep2->file->filename, - cep2->line_number, "tld", cep2->name); + cep2->line_number, "tld", cep2->name); errors++; } } - } - else + } else { config_error_unknown(cep->file->filename, cep->line_number, - "tld", cep->name); + "tld", cep->name); errors++; continue; } @@ -5548,7 +5500,7 @@ int _test_tld(ConfigFile *conf, ConfigEntry *ce) if (!has_mask && !has_match) { config_error_missing(ce->file->filename, ce->line_number, - "tld::match"); + "tld::match"); errors++; } if (has_mask && has_match) @@ -5575,7 +5527,8 @@ void conf_listen_configure(const char *ip, int port, SocketType socket_type, int if (socket_type == SOCKET_TYPE_UNIX) { safe_strdup(listen->file, ip); - } else { + } else + { safe_strdup(listen->ip, ip); listen->port = port; } @@ -5614,8 +5567,7 @@ void conf_listen_configure(const char *ip, int port, SocketType socket_type, int { listen->tls_options = safe_alloc(sizeof(TLSOptions)); conf_tlsblock(conf, tlsconfig, listen->tls_options, - ((options & LISTENER_SERVERSONLY) && tempiConf.server_linking_tls_options) ? - tempiConf.server_linking_tls_options : tempiConf.tls_options); + ((options & LISTENER_SERVERSONLY) && tempiConf.server_linking_tls_options) ? tempiConf.server_linking_tls_options : tempiConf.tls_options); listen->ssl_ctx = init_ctx(listen->tls_options, 1); } /* A serversonly listener with no tls-options of its own uses the shared @@ -5634,8 +5586,7 @@ void conf_listen_configure(const char *ip, int port, SocketType socket_type, int /* Yeah, we actually do something with this one.. */ if (cep->value) listen->mode = strtol(cep->value, NULL, 8); /* octal */ - } - else if (!strcmp(cep->name, "spoof-ip")) + } else if (!strcmp(cep->name, "spoof-ip")) safe_strdup(listen->spoof_ip, cep->value); else if (!strcmp(cep->name, "ip")) ; @@ -5656,8 +5607,7 @@ void conf_listen_configure(const char *ip, int port, SocketType socket_type, int } } } - } else - if (!strcmp(cep->name, "ssl-options") || !strcmp(cep->name, "tls-options")) + } else if (!strcmp(cep->name, "ssl-options") || !strcmp(cep->name, "tls-options")) ; else { @@ -5673,15 +5623,15 @@ void conf_listen_configure(const char *ip, int port, SocketType socket_type, int RunHook(HOOKTYPE_CONFIG_LISTENER, listen); } -int _conf_listen(ConfigFile *conf, ConfigEntry *ce) +int _conf_listen(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cepp; ConfigEntry *tlsconfig = NULL; char *file = NULL; char *ip = NULL; char *spoof_ip = NULL; - int start=0, end=0, port; - int listener_flags =0; + int start = 0, end = 0, port; + int listener_flags = 0; Hook *h; for (cep = ce->items; cep; cep = cep->next) @@ -5690,26 +5640,21 @@ int _conf_listen(ConfigFile *conf, ConfigEntry *ce) { convert_to_absolute_path(&cep->value, PERMDATADIR); file = cep->value; - } else - if (!strcmp(cep->name, "mode")) + } else if (!strcmp(cep->name, "mode")) { // Handled elsewhere, but need to be caught here as noop - } else - if (!strcmp(cep->name, "ip")) + } else if (!strcmp(cep->name, "ip")) { ip = cep->value; - } else - if (!strcmp(cep->name, "spoof-ip")) + } else if (!strcmp(cep->name, "spoof-ip")) { spoof_ip = cep->value; - } else - if (!strcmp(cep->name, "port")) + } else if (!strcmp(cep->name, "port")) { port_range(cep->value, &start, &end); if ((start < 0) || (start > 65535) || (end < 0) || (end > 65535)) return -1; /* this is already validated in _test_listen, but okay.. */ - } else - if (!strcmp(cep->name, "options")) + } else if (!strcmp(cep->name, "options")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -5717,7 +5662,8 @@ int _conf_listen(ConfigFile *conf, ConfigEntry *ce) if ((v = nv_find_by_name(_ListenerFlags, cepp->name))) { listener_flags |= v; - } else { + } else + { for (h = Hooks[HOOKTYPE_CONFIGRUN]; h; h = h->next) { int value = (*(h->func.intfunc))(conf, cepp, CONFIG_LISTEN_OPTIONS); @@ -5726,8 +5672,7 @@ int _conf_listen(ConfigFile *conf, ConfigEntry *ce) } } } - } else - if (!strcmp(cep->name, "ssl-options") || !strcmp(cep->name, "tls-options")) + } else if (!strcmp(cep->name, "ssl-options") || !strcmp(cep->name, "tls-options")) { tlsconfig = cep; } else @@ -5762,7 +5707,7 @@ int _conf_listen(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_listen(ConfigFile *conf, ConfigEntry *ce) +int _test_listen(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigEntry *cepp; @@ -5777,7 +5722,7 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) if (ce->value) { config_error("%s:%i: listen block has a new syntax, see https://www.unrealircd.org/docs/Listen_block", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; } @@ -5789,8 +5734,7 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) { continue; } @@ -5819,7 +5763,7 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) if (has_options) { config_warn_duplicate(cep->file->filename, - cep->line_number, "listen::options"); + cep->line_number, "listen::options"); continue; } has_options = 1; @@ -5835,8 +5779,7 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) { continue; } @@ -5863,7 +5806,7 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) if (!used_by_module) { config_error_unknownopt(cepp->file->filename, - cepp->line_number, "listen::options", cepp->name); + cepp->line_number, "listen::options", cepp->name); errors++; continue; } @@ -5874,30 +5817,24 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) tls_port = 1; } } - } - else - if (!strcmp(cep->name, "ssl-options") || !strcmp(cep->name, "tls-options")) + } else if (!strcmp(cep->name, "ssl-options") || !strcmp(cep->name, "tls-options")) { test_tlsblock(conf, cep, &errors); - } - else - if (!cep->value) + } else if (!cep->value) { if (!used_by_module) { config_error_empty(cep->file->filename, - cep->line_number, "listen", cep->name); + cep->line_number, "listen", cep->name); errors++; } continue; /* always */ - } else - if (!strcmp(cep->name, "file")) + } else if (!strcmp(cep->name, "file")) { has_file = 1; clientport = 0; file = cep->value; - } else - if (!strcmp(cep->name, "spoof-ip")) + } else if (!strcmp(cep->name, "spoof-ip")) { has_spoof_ip = 1; if (!is_valid_ip(cep->value)) @@ -5906,8 +5843,7 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number, cep->value); errors++; } - } else - if (!strcmp(cep->name, "mode")) + } else if (!strcmp(cep->name, "mode")) { int mode = strtol(cep->value, NULL, 8); if ((mode != 0700) && (mode != 0770) && (mode != 0777)) @@ -5918,26 +5854,23 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number); errors++; } - } else - if (!strcmp(cep->name, "ip")) + } else if (!strcmp(cep->name, "ip")) { has_ip = 1; if (strcmp(cep->value, "*") && !is_valid_ip(cep->value)) { config_error("%s:%i: listen: illegal listen::ip (%s). Must be either '*' or contain a valid IP.", - cep->file->filename, cep->line_number, cep->value); + cep->file->filename, cep->line_number, cep->value); return 1; } ip = cep->value; - } else - if (!strcmp(cep->name, "host")) + } else if (!strcmp(cep->name, "host")) { config_error("%s:%i: listen: unknown option listen::host, did you mean listen::ip?", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; - } else - if (!strcmp(cep->name, "port")) + } else if (!strcmp(cep->name, "port")) { port_start = port_end = 0; @@ -5956,33 +5889,32 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) if ((port_start < 1) || (port_start > 65535)) { config_error("%s:%i: listen: illegal port (must be 1..65535)", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } - } - else + } else { if (port_end < port_start) { config_error("%s:%i: listen: illegal port range end value is less than starting value", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } if (port_end - port_start >= 100) { config_error("%s:%i: listen: you requested port %d-%d, that's %d ports " - "(and thus consumes %d sockets) this is probably not what you want.", - cep->file->filename, cep->line_number, port_start, port_end, - port_end - port_start + 1, port_end - port_start + 1); + "(and thus consumes %d sockets) this is probably not what you want.", + cep->file->filename, cep->line_number, port_start, port_end, + port_end - port_start + 1, port_end - port_start + 1); errors++; continue; } if ((port_start < 1) || (port_start > 65535) || (port_end < 1) || (port_end > 65535)) { config_error("%s:%i: listen: illegal port range values must be between 1 and 65535", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } @@ -5995,7 +5927,7 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) if (!used_by_module) { config_error_unknown(cep->file->filename, cep->line_number, - "listen", cep->name); + "listen", cep->name); errors++; } continue; /* always */ @@ -6010,7 +5942,8 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) "OR have an 'ip' and 'port' (for IPv4/IPv6). You cannot combine both in one listen block.", ce->file->filename, ce->line_number); errors++; - } else { + } else + { // TODO: check if file can be created fresh etc. } } else @@ -6018,14 +5951,14 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) if (!has_ip) { config_error("%s:%d: listen block requires an listen::ip", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } if (!has_port) { config_error("%s:%d: listen block requires an listen::port", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } } @@ -6044,7 +5977,7 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) { has_client_port = 1; - if (!bestpractices.listen_nontls_port && !tls_port && (port_start>0)) + if (!bestpractices.listen_nontls_port && !tls_port && (port_start > 0)) bestpractices.listen_nontls_port = port_start; } @@ -6053,7 +5986,7 @@ int _test_listen(ConfigFile *conf, ConfigEntry *ce) } -int _conf_allow(ConfigFile *conf, ConfigEntry *ce) +int _conf_allow(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cepp; ConfigItem_allow *allow; @@ -6083,8 +6016,7 @@ int _conf_allow(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(cep->name, "match") || !strcmp(cep->name, "mask") || !strcmp(cep->name, "ip") || !strcmp(cep->name, "hostname")) { conf_match_block(conf, cep, &allow->match); - } - else if (!strcmp(cep->name, "password")) + } else if (!strcmp(cep->name, "password")) AuthBlockToAuthConfig(cep, &allow->auth); else if (!strcmp(cep->name, "class")) { @@ -6092,13 +6024,12 @@ int _conf_allow(ConfigFile *conf, ConfigEntry *ce) if (!allow->class || (allow->class->flag.temporary == 1)) { config_status("%s:%i: illegal allow::class, unknown class '%s' using default of class 'default'", - cep->file->filename, - cep->line_number, - cep->value); - allow->class = default_class; + cep->file->filename, + cep->line_number, + cep->value); + allow->class = default_class; } - } - else if (!strcmp(cep->name, "redirect-server")) + } else if (!strcmp(cep->name, "redirect-server")) safe_strdup(allow->server, cep->value); else if (!strcmp(cep->name, "redirect-port")) allow->port = atoi(cep->value); @@ -6128,10 +6059,10 @@ int _conf_allow(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_allow(ConfigFile *conf, ConfigEntry *ce) +int _test_allow(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cepp; - int errors = 0; + int errors = 0; Hook *h; int has_ip = 0, has_hostname = 0, has_mask = 0, has_match = 0; int has_password = 0, has_class = 0; @@ -6148,8 +6079,7 @@ int _test_allow(ConfigFile *conf, ConfigEntry *ce) for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) continue; value = (*(h->func.intfunc))(conf, ce, CONFIG_ALLOW, &errs); if (value == 2) @@ -6171,9 +6101,10 @@ int _test_allow(ConfigFile *conf, ConfigEntry *ce) errors += errs; } } - if (!used) { + if (!used) + { config_error("%s:%i: allow item with unknown type", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; } return errors; @@ -6188,8 +6119,7 @@ int _test_allow(ConfigFile *conf, ConfigEntry *ce) for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) { continue; } @@ -6229,96 +6159,87 @@ int _test_allow(ConfigFile *conf, ConfigEntry *ce) if (has_ip) { config_warn_duplicate(cep->file->filename, - cep->line_number, "allow::ip"); + cep->line_number, "allow::ip"); continue; } has_ip = 1; - } - else if (!strcmp(cep->name, "hostname")) + } else if (!strcmp(cep->name, "hostname")) { if (has_hostname) { config_warn_duplicate(cep->file->filename, - cep->line_number, "allow::hostname"); + cep->line_number, "allow::hostname"); continue; } has_hostname = 1; if (!strcmp(cep->value, "*@*") || !strcmp(cep->value, "*")) hostname_possible_silliness = 1; - } - else if (!strcmp(cep->name, "mask")) + } else if (!strcmp(cep->name, "mask")) { has_mask = 1; test_match_block(conf, cep, &errors); - } - else if (!strcmp(cep->name, "match")) + } else if (!strcmp(cep->name, "match")) { has_match = 1; test_match_block(conf, cep, &errors); - } - else if (!strcmp(cep->name, "ipv6-clone-mask")) + } else if (!strcmp(cep->name, "ipv6-clone-mask")) { config_error("%s:%d: allow::ipv6-clone-mask has no effect. " "Use the global set::default-ipv6-clone-mask setting instead.", cep->file->filename, cep->line_number); errors++; - } - else if (!strcmp(cep->name, "password")) + } else if (!strcmp(cep->name, "password")) { has_password = 1; if (Auth_CheckError(cep, 0) < 0) errors++; - } - else if (!strcmp(cep->name, "class")) + } else if (!strcmp(cep->name, "class")) { if (has_class) { config_warn_duplicate(cep->file->filename, - cep->line_number, "allow::class"); + cep->line_number, "allow::class"); continue; } has_class = 1; - } - else if (!strcmp(cep->name, "redirect-server")) + } else if (!strcmp(cep->name, "redirect-server")) { if (has_redirectserver) { config_warn_duplicate(cep->file->filename, - cep->line_number, "allow::redirect-server"); + cep->line_number, "allow::redirect-server"); continue; } has_redirectserver = 1; - } - else if (!strcmp(cep->name, "redirect-port")) + } else if (!strcmp(cep->name, "redirect-port")) { if (has_redirectport) { config_warn_duplicate(cep->file->filename, - cep->line_number, "allow::redirect-port"); + cep->line_number, "allow::redirect-port"); continue; } has_redirectport = 1; - } - else if (!strcmp(cep->name, "options")) + } else if (!strcmp(cep->name, "options")) { if (has_options) { config_warn_duplicate(cep->file->filename, - cep->line_number, "allow::options"); + cep->line_number, "allow::options"); continue; } has_options = 1; for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "noident")) - {} - else if (!strcmp(cepp->name, "useip")) - {} - else if (!strcmp(cepp->name, "ssl") || !strcmp(cepp->name, "tls")) - {} - else if (!strcmp(cepp->name, "reject-on-auth-failure")) - {} - else if (!strcmp(cepp->name, "sasl")) + { + } else if (!strcmp(cepp->name, "useip")) + { + } else if (!strcmp(cepp->name, "ssl") || !strcmp(cepp->name, "tls")) + { + } else if (!strcmp(cepp->name, "reject-on-auth-failure")) + { + } else if (!strcmp(cepp->name, "sasl")) { config_error("%s:%d: The option allow::options::sasl no longer exists. " "Please use a require authentication { } block instead, which " @@ -6326,19 +6247,17 @@ int _test_allow(ConfigFile *conf, ConfigEntry *ce) "https://www.unrealircd.org/docs/Require_authentication_block", cepp->file->filename, cepp->line_number); errors++; - } - else + } else { config_error_unknownopt(cepp->file->filename, - cepp->line_number, "allow", cepp->name); + cepp->line_number, "allow", cepp->name); errors++; } } - } - else + } else { config_error_unknown(cep->file->filename, cep->line_number, - "allow", cep->name); + "allow", cep->name); errors++; continue; } @@ -6347,31 +6266,27 @@ int _test_allow(ConfigFile *conf, ConfigEntry *ce) if ((has_mask || has_match) && (has_ip || has_hostname)) { config_error("%s:%d: The allow block uses allow::match, but you also have an allow::ip and allow::hostname.", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); config_error("Please delete your allow::ip and allow::hostname entries and/or integrate them into allow::match"); - } else - if (has_ip) + } else if (has_ip) { config_warn("%s:%d: The allow block uses allow::match nowadays. Rename your allow::ip item to allow::match.", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); config_warn("See https://www.unrealircd.org/docs/FAQ#allow-mask for more information"); - } else - if (has_hostname) + } else if (has_hostname) { config_warn("%s:%d: The allow block uses allow::match nowadays. Rename your allow::hostname item to allow::match.", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); config_warn("See https://www.unrealircd.org/docs/FAQ#allow-mask for more information"); - } else - if (has_mask && has_match) + } else if (has_mask && has_match) { config_error("%s:%d: You cannot have both ::mask and ::match. You should only use allow::match.", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; - } else - if (!has_match && !has_mask) + } else if (!has_match && !has_mask) { config_error("%s:%d: allow block needs an allow::match", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } @@ -6381,8 +6296,7 @@ int _test_allow(ConfigFile *conf, ConfigEntry *ce) ce->file->filename, ce->line_number); config_error("Please integrate your allow::ip and allow::hostname items into a single allow::mask block"); errors++; - } else - if (hostname_possible_silliness) + } else if (hostname_possible_silliness) { config_error("%s:%d: allow block contains 'hostname *;'. This means means that users " "without a valid hostname (unresolved IP's) will be unable to connect. " @@ -6393,17 +6307,17 @@ int _test_allow(ConfigFile *conf, ConfigEntry *ce) if (!has_class) { config_error_missing(ce->file->filename, ce->line_number, - "allow::class"); + "allow::class"); errors++; } return errors; } -int _conf_allow_channel(ConfigFile *conf, ConfigEntry *ce) +int _conf_allow_channel(ConfigFile *conf, ConfigEntry *ce) { - ConfigItem_allow_channel *allow = NULL; - ConfigEntry *cep; + ConfigItem_allow_channel *allow = NULL; + ConfigEntry *cep; char *class = NULL; ConfigEntry *match = NULL; @@ -6433,11 +6347,11 @@ int _conf_allow_channel(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _test_allow_channel(ConfigFile *conf, ConfigEntry *ce) +int _test_allow_channel(ConfigFile *conf, ConfigEntry *ce) { - ConfigEntry *cep; - int errors = 0; - char has_match = 0, has_mask = 0, has_channel = 0, has_class = 0; + ConfigEntry *cep; + int errors = 0; + char has_match = 0, has_mask = 0, has_channel = 0, has_class = 0; for (cep = ce->items; cep; cep = cep->next) { @@ -6445,36 +6359,31 @@ int _test_allow_channel(ConfigFile *conf, ConfigEntry *ce) { has_match = 1; test_match_block(conf, cep, &errors); - } - else if (!strcmp(cep->name, "mask")) + } else if (!strcmp(cep->name, "mask")) { has_mask = 1; test_match_block(conf, cep, &errors); - } - else if (config_is_blankorempty(cep, "allow channel")) + } else if (config_is_blankorempty(cep, "allow channel")) { errors++; continue; - } - else if (!strcmp(cep->name, "channel")) + } else if (!strcmp(cep->name, "channel")) { has_channel = 1; - } - else if (!strcmp(cep->name, "class")) + } else if (!strcmp(cep->name, "class")) { if (has_class) { config_warn_duplicate(cep->file->filename, - cep->line_number, "allow channel::class"); + cep->line_number, "allow channel::class"); continue; } has_class = 1; - } - else + } else { config_error_unknown(cep->file->filename, cep->line_number, - "allow channel", cep->name); + "allow channel", cep->name); errors++; } } @@ -6488,7 +6397,7 @@ int _test_allow_channel(ConfigFile *conf, ConfigEntry *ce) if (!has_channel) { config_error_missing(ce->file->filename, ce->line_number, - "allow channel::channel"); + "allow channel::channel"); errors++; } return errors; @@ -6501,7 +6410,7 @@ int _conf_except(ConfigFile *conf, ConfigEntry *ce) for (h = Hooks[HOOKTYPE_CONFIGRUN]; h; h = h->next) { - value = (*(h->func.intfunc))(conf,ce,CONFIG_EXCEPT); + value = (*(h->func.intfunc))(conf, ce, CONFIG_EXCEPT); if (value == 1) break; } @@ -6518,7 +6427,7 @@ int _test_except(ConfigFile *conf, ConfigEntry *ce) if (!ce->value) { config_error("%s:%i: except without type", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; } @@ -6534,10 +6443,9 @@ int _test_except(ConfigFile *conf, ConfigEntry *ce) for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) continue; - value = (*(h->func.intfunc))(conf,ce,CONFIG_EXCEPT,&errs); + value = (*(h->func.intfunc))(conf, ce, CONFIG_EXCEPT, &errs); if (value == 2) used = 1; if (value == 1) @@ -6561,15 +6469,15 @@ int _test_except(ConfigFile *conf, ConfigEntry *ce) if (!used) { config_error("%s:%i: unknown except type %s", - ce->file->filename, ce->line_number, - ce->value); + ce->file->filename, ce->line_number, + ce->value); return 1; } return errors; } -int _test_sni(ConfigFile *conf, ConfigEntry *ce) +int _test_sni(ConfigFile *conf, ConfigEntry *ce) { int errors = 0; ConfigEntry *cep; @@ -6577,7 +6485,7 @@ int _test_sni(ConfigFile *conf, ConfigEntry *ce) if (!ce->value) { config_error("%s:%i: sni block needs a name, eg: sni irc.xyz.com {", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } @@ -6589,7 +6497,7 @@ int _test_sni(ConfigFile *conf, ConfigEntry *ce) } else { config_error_unknown(cep->file->filename, cep->line_number, - "sni", cep->name); + "sni", cep->name); errors++; continue; } @@ -6598,7 +6506,7 @@ int _test_sni(ConfigFile *conf, ConfigEntry *ce) return errors; } -int _conf_sni(ConfigFile *conf, ConfigEntry *ce) +int _conf_sni(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigEntry *tlsconfig = NULL; @@ -6630,7 +6538,7 @@ int _conf_sni(ConfigFile *conf, ConfigEntry *ce) return 1; } -int _conf_help(ConfigFile *conf, ConfigEntry *ce) +int _conf_help(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigItem_help *ca; @@ -6655,16 +6563,16 @@ int _conf_help(ConfigFile *conf, ConfigEntry *ce) } AddListItem(ca, conf_help); return 1; - } -int _test_help(ConfigFile *conf, ConfigEntry *ce) { +int _test_help(ConfigFile *conf, ConfigEntry *ce) +{ int errors = 0; ConfigEntry *cep; if (!ce->items) { config_error("%s:%i: empty help block", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; } for (cep = ce->items; cep; cep = cep->next) @@ -6672,7 +6580,7 @@ int _test_help(ConfigFile *conf, ConfigEntry *ce) { if (strlen(cep->name) > 500) { config_error("%s:%i: oversized help item", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; continue; } @@ -6680,7 +6588,7 @@ int _test_help(ConfigFile *conf, ConfigEntry *ce) { return errors; } -int _conf_link(ConfigFile *conf, ConfigEntry *ce) +int _conf_link(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cepp, *ceppp; ConfigItem_link *link = NULL; @@ -6699,8 +6607,7 @@ int _conf_link(ConfigFile *conf, ConfigEntry *ce) conf_match_block(conf, cepp, &link->incoming.match); } } - } - else if (!strcmp(cep->name, "outgoing")) + } else if (!strcmp(cep->name, "outgoing")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -6721,18 +6628,15 @@ int _conf_link(ConfigFile *conf, ConfigEntry *ce) if ((v = nv_find_by_name(_LinkOutgoingFlags, ceppp->name))) link->outgoing.options |= v; } - } - else if (!strcmp(cepp->name, "ssl-options") || !strcmp(cepp->name, "tls-options")) + } else if (!strcmp(cepp->name, "ssl-options") || !strcmp(cepp->name, "tls-options")) { link->tls_options = safe_alloc(sizeof(TLSOptions)); conf_tlsblock(conf, cepp, link->tls_options, - tempiConf.server_linking_tls_options ? - tempiConf.server_linking_tls_options : tempiConf.tls_options); + tempiConf.server_linking_tls_options ? tempiConf.server_linking_tls_options : tempiConf.tls_options); link->ssl_ctx = init_ctx(link->tls_options, 0); } } - } - else if (!strcmp(cep->name, "password")) + } else if (!strcmp(cep->name, "password")) AuthBlockToAuthConfig(cep, &link->auth); else if (!strcmp(cep->name, "hub")) safe_strdup(link->hub, cep->value); @@ -6746,18 +6650,16 @@ int _conf_link(ConfigFile *conf, ConfigEntry *ce) if (!link->class || (link->class->flag.temporary == 1)) { config_status("%s:%i: illegal link::class, unknown class '%s' using default of class 'default'", - cep->file->filename, - cep->line_number, - cep->value); + cep->file->filename, + cep->line_number, + cep->value); link->class = default_class; } link->class->xrefcount++; - } - else if (!strcmp(cep->name, "verify-certificate")) + } else if (!strcmp(cep->name, "verify-certificate")) { link->verify_certificate = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "options")) + } else if (!strcmp(cep->name, "options")) { link->options = 0; for (cepp = cep->items; cepp; cepp = cepp->next) @@ -6782,7 +6684,7 @@ int _conf_link(ConfigFile *conf, ConfigEntry *ce) return 0; } -int _test_link(ConfigFile *conf, ConfigEntry *ce) +int _test_link(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cepp, *ceppp; int errors = 0; @@ -6795,15 +6697,14 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) if (!ce->value) { config_error("%s:%i: link without servername. Expected: link servername { ... }", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; - } if (!strchr(ce->value, '.')) { config_error("%s:%i: link: bogus server name. Expected: link servername { ... }", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; } @@ -6820,29 +6721,25 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) { has_incoming_match = 1; test_match_block(conf, cepp, &errors); - } else - if (config_is_blankorempty(cepp, "link::incoming")) + } else if (config_is_blankorempty(cepp, "link::incoming")) { errors++; continue; } - } else - if (!strcmp(cepp->name, "mask")) + } else if (!strcmp(cepp->name, "mask")) { if (cepp->value || cepp->items) { has_incoming_mask = 1; test_match_block(conf, cepp, &errors); - } else - if (config_is_blankorempty(cepp, "link::incoming")) + } else if (config_is_blankorempty(cepp, "link::incoming")) { errors++; continue; } } } - } - else if (!strcmp(cep->name, "outgoing")) + } else if (!strcmp(cep->name, "outgoing")) { config_detect_duplicate(&has_outgoing, cep, &errors); for (cepp = cep->items; cepp; cepp = cepp->next) @@ -6856,8 +6753,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) } config_detect_duplicate(&has_outgoing_bind_ip, cepp, &errors); // todo: ipv4 vs ipv6 - } - else if (!strcmp(cepp->name, "file")) + } else if (!strcmp(cepp->name, "file")) { if (config_is_blankorempty(cepp, "link::outgoing")) { @@ -6865,8 +6761,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) continue; } config_detect_duplicate(&has_outgoing_file, cepp, &errors); - } - else if (!strcmp(cepp->name, "hostname")) + } else if (!strcmp(cepp->name, "hostname")) { if (config_is_blankorempty(cepp, "link::outgoing")) { @@ -6877,11 +6772,10 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) if (strchr(cepp->value, '*') || strchr(cepp->value, '?')) { config_error("%s:%i: hostname in link::outgoing(!) cannot contain wildcards", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; } - } - else if (!strcmp(cepp->name, "port")) + } else if (!strcmp(cepp->name, "port")) { if (config_is_blankorempty(cepp, "link::outgoing")) { @@ -6889,8 +6783,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) continue; } config_detect_duplicate(&has_outgoing_port, cepp, &errors); - } - else if (!strcmp(cepp->name, "options")) + } else if (!strcmp(cepp->name, "options")) { config_detect_duplicate(&has_outgoing_options, cepp, &errors); for (ceppp = cepp->items; ceppp; ceppp = ceppp->next) @@ -6898,17 +6791,15 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) if (!nv_find_by_name(_LinkOutgoingFlags, ceppp->name)) { config_error_unknownopt(ceppp->file->filename, - ceppp->line_number, "link::outgoing", ceppp->name); + ceppp->line_number, "link::outgoing", ceppp->name); errors++; } } - } - else if (!strcmp(cepp->name, "ssl-options") || !strcmp(cepp->name, "tls-options")) + } else if (!strcmp(cepp->name, "ssl-options") || !strcmp(cepp->name, "tls-options")) { config_detect_duplicate(&has_tls_options, cepp, &errors); test_tlsblock(conf, cepp, &errors); - } - else + } else { config_error("%s:%d: Unknown directive '%s'", cepp->file->filename, cepp->line_number, @@ -6916,14 +6807,14 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) errors++; } } - } - else if (!strcmp(cep->name, "password")) + } else if (!strcmp(cep->name, "password")) { has_password = 1; if (Auth_CheckError(cep, 0) < 0) { errors++; - } else { + } else + { AuthConfig *auth = NULL; AuthBlockToAuthConfig(cep, &auth); /* hm. would be nicer if handled @auth-system I think. ah well.. */ @@ -6937,8 +6828,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) } Auth_FreeAuthConfig(auth); } - } - else if (!strcmp(cep->name, "hub")) + } else if (!strcmp(cep->name, "hub")) { if (config_is_blankorempty(cep, "link")) { @@ -6946,8 +6836,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) continue; } config_detect_duplicate(&has_hub, cep, &errors); - } - else if (!strcmp(cep->name, "leaf")) + } else if (!strcmp(cep->name, "leaf")) { if (config_is_blankorempty(cep, "link")) { @@ -6955,8 +6844,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) continue; } config_detect_duplicate(&has_leaf, cep, &errors); - } - else if (!strcmp(cep->name, "leaf-depth") || !strcmp(cep->name, "leafdepth")) + } else if (!strcmp(cep->name, "leaf-depth") || !strcmp(cep->name, "leafdepth")) { if (config_is_blankorempty(cep, "link")) { @@ -6964,8 +6852,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) continue; } config_detect_duplicate(&has_leaf_depth, cep, &errors); - } - else if (!strcmp(cep->name, "class")) + } else if (!strcmp(cep->name, "class")) { if (config_is_blankorempty(cep, "link")) { @@ -6973,15 +6860,13 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) continue; } config_detect_duplicate(&has_class, cep, &errors); - } - else if (!strcmp(cep->name, "ciphers")) + } else if (!strcmp(cep->name, "ciphers")) { config_error("%s:%d: link::ciphers has been moved to link::outgoing::ssl-options::ciphers, " "see https://www.unrealircd.org/docs/FAQ#link::ciphers_no_longer_works", cep->file->filename, cep->line_number); errors++; - } - else if (!strcmp(cep->name, "verify-certificate")) + } else if (!strcmp(cep->name, "verify-certificate")) { if (config_is_blankorempty(cep, "link")) { @@ -7003,8 +6888,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) log_data_string("file", cep->file->filename), log_data_integer("line_number", cep->line_number)); } - } - else if (!strcmp(cep->name, "options")) + } else if (!strcmp(cep->name, "options")) { config_detect_duplicate(&has_options, cep, &errors); for (cepp = cep->items; cepp; cepp = cepp->next) @@ -7019,11 +6903,10 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) errors++; } } - } - else + } else { config_error_unknown(cep->file->filename, - cep->line_number, "link", cep->name); + cep->line_number, "link", cep->name); errors++; continue; } @@ -7032,7 +6915,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) if (!has_incoming && !has_outgoing) { config_error("%s:%d: link block needs at least an incoming or outgoing section.", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } @@ -7047,8 +6930,8 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) if (has_incoming_mask && has_incoming_match) { config_error("%s:%d: You cannot have both link::incoming::mask and link::incoming::match. " - "You should only use link::incoming::match.", - ce->file->filename, ce->line_number); + "You should only use link::incoming::match.", + ce->file->filename, ce->line_number); errors++; } } @@ -7068,8 +6951,7 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) config_error_missing(ce->file->filename, ce->line_number, "link::outgoing::port"); errors++; } - } - else if (has_outgoing_file && (has_outgoing_hostname || has_outgoing_port)) + } else if (has_outgoing_file && (has_outgoing_hostname || has_outgoing_port)) { config_error("%s:%d: link block should either have a 'file' (for *NIX domain socket), " "OR have a 'hostname' and 'port' (for IPv4/IPv6). You cannot combine both in one link block.", @@ -7087,14 +6969,14 @@ int _test_link(ConfigFile *conf, ConfigEntry *ce) if (!has_class) { config_error_missing(ce->file->filename, ce->line_number, - "link::class"); + "link::class"); errors++; } return errors; } -int _conf_ban(ConfigFile *conf, ConfigEntry *ce) +int _conf_ban(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigItem_ban *ca; @@ -7109,13 +6991,13 @@ int _conf_ban(ConfigFile *conf, ConfigEntry *ce) { ca->flag.type = CONF_BAN_VERSION; tempiConf.use_ban_version = 1; /* enable CTCP VERSION on connect */ - } - else { + } else + { int value; safe_free(ca); /* ca isn't used, modules have their own list. */ for (h = Hooks[HOOKTYPE_CONFIGRUN]; h; h = h->next) { - value = (*(h->func.intfunc))(conf,ce,CONFIG_BAN); + value = (*(h->func.intfunc))(conf, ce, CONFIG_BAN); if (value == 1) break; } @@ -7126,8 +7008,7 @@ int _conf_ban(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(cep->name, "mask")) { safe_strdup(ca->mask, cep->value); - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) safe_strdup(ca->reason, cep->value); else if (!strcmp(cep->name, "action")) parse_ban_action_config(cep, &ca->action); @@ -7136,10 +7017,10 @@ int _conf_ban(ConfigFile *conf, ConfigEntry *ce) return 0; } -int _test_ban(ConfigFile *conf, ConfigEntry *ce) +int _test_ban(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; - int errors = 0; + int errors = 0; Hook *h; char type = 0; char has_mask = 0, has_action = 0, has_reason = 0; @@ -7147,14 +7028,13 @@ int _test_ban(ConfigFile *conf, ConfigEntry *ce) if (!ce->value) { config_error("%s:%i: ban without type", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; - } - else if (!strcmp(ce->value, "server")) - {} - else if (!strcmp(ce->value, "realname")) - {} - else if (!strcmp(ce->value, "version")) + } else if (!strcmp(ce->value, "server")) + { + } else if (!strcmp(ce->value, "realname")) + { + } else if (!strcmp(ce->value, "version")) type = 'v'; else { @@ -7162,10 +7042,9 @@ int _test_ban(ConfigFile *conf, ConfigEntry *ce) for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) continue; - value = (*(h->func.intfunc))(conf,ce,CONFIG_BAN, &errs); + value = (*(h->func.intfunc))(conf, ce, CONFIG_BAN, &errs); if (value == 2) used = 1; if (value == 1) @@ -7185,10 +7064,11 @@ int _test_ban(ConfigFile *conf, ConfigEntry *ce) errors += errs; } } - if (!used) { + if (!used) + { config_error("%s:%i: unknown ban type %s", - ce->file->filename, ce->line_number, - ce->value); + ce->file->filename, ce->line_number, + ce->value); return 1; } return errors; @@ -7206,27 +7086,25 @@ int _test_ban(ConfigFile *conf, ConfigEntry *ce) if (has_mask) { config_warn_duplicate(cep->file->filename, - cep->line_number, "ban::mask"); + cep->line_number, "ban::mask"); continue; } has_mask = 1; - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { if (has_reason) { config_warn_duplicate(cep->file->filename, - cep->line_number, "ban::reason"); + cep->line_number, "ban::reason"); continue; } has_reason = 1; - } - else if (!strcmp(cep->name, "action")) + } else if (!strcmp(cep->name, "action")) { if (has_action) { config_warn_duplicate(cep->file->filename, - cep->line_number, "ban::action"); + cep->line_number, "ban::action"); } has_action = 1; errors += test_ban_action_config(cep); @@ -7236,19 +7114,19 @@ int _test_ban(ConfigFile *conf, ConfigEntry *ce) if (!has_mask) { config_error_missing(ce->file->filename, ce->line_number, - "ban::mask"); + "ban::mask"); errors++; } if (!has_reason) { config_error_missing(ce->file->filename, ce->line_number, - "ban::reason"); + "ban::reason"); errors++; } if (has_action && type != 'v') { config_error("%s:%d: ban::action specified even though type is not 'version'", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } return errors; @@ -7267,7 +7145,7 @@ int _conf_require(ConfigFile *conf, ConfigEntry *ce) int value; for (h = Hooks[HOOKTYPE_CONFIGRUN]; h; h = h->next) { - value = (*(h->func.intfunc))(conf,ce,CONFIG_REQUIRE); + value = (*(h->func.intfunc))(conf, ce, CONFIG_REQUIRE); if (value == 1) break; } @@ -7300,26 +7178,24 @@ int _test_require(ConfigFile *conf, ConfigEntry *ce) if (!ce->value) { config_error("%s:%i: require without type, did you mean 'require authentication'?", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; } if (!strcmp(ce->value, "authentication")) - {} - else if (!strcmp(ce->value, "sasl")) + { + } else if (!strcmp(ce->value, "sasl")) { config_warn("%s:%i: the 'require sasl' block is now called 'require authentication'", ce->file->filename, ce->line_number); - } - else + } else { int used = 0; for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) continue; - value = (*(h->func.intfunc))(conf,ce,CONFIG_REQUIRE, &errs); + value = (*(h->func.intfunc))(conf, ce, CONFIG_REQUIRE, &errs); if (value == 2) used = 1; if (value == 1) @@ -7339,10 +7215,11 @@ int _test_require(ConfigFile *conf, ConfigEntry *ce) errors += errs; } } - if (!used) { + if (!used) + { config_error("%s:%i: unknown require type '%s'", - ce->file->filename, ce->line_number, - ce->value); + ce->file->filename, ce->line_number, + ce->value); return 1; } return errors; @@ -7357,33 +7234,30 @@ int _test_require(ConfigFile *conf, ConfigEntry *ce) has_mask = 1; test_match_block(conf, cep, &errors); } - } else - if (!strcmp(cep->name, "match")) + } else if (!strcmp(cep->name, "match")) { if (cep->value || cep->items) { has_match = 1; test_match_block(conf, cep, &errors); } - } else - if (config_is_blankorempty(cep, "require")) + } else if (config_is_blankorempty(cep, "require")) { errors++; continue; - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { if (has_reason) { config_warn_duplicate(cep->file->filename, - cep->line_number, "require::reason"); + cep->line_number, "require::reason"); continue; } has_reason = 1; } else { config_error_unknown(cep->file->filename, - cep->line_number, "require", cep->name); + cep->line_number, "require", cep->name); errors++; continue; } @@ -7392,7 +7266,7 @@ int _test_require(ConfigFile *conf, ConfigEntry *ce) if (!has_mask && !has_match) { config_error_missing(ce->file->filename, ce->line_number, - "require::mask"); + "require::mask"); errors++; } @@ -7407,13 +7281,19 @@ int _test_require(ConfigFile *conf, ConfigEntry *ce) if (!has_reason) { config_error_missing(ce->file->filename, ce->line_number, - "require::reason"); + "require::reason"); errors++; } return errors; } -#define CheckDuplicate(cep, name, display) if (settings.has_##name) { config_warn_duplicate((cep)->file->filename, cep->line_number, "set::" display); continue; } else settings.has_##name = 1 +#define CheckDuplicate(cep, name, display) \ + if (settings.has_##name) \ + { \ + config_warn_duplicate((cep)->file->filename, cep->line_number, "set::" display); \ + continue; \ + } else \ + settings.has_##name = 1 void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) { @@ -7425,34 +7305,29 @@ void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) { if (!strcmp(cepp->name, "renegotiate-timeout")) { - } - else if (!strcmp(cepp->name, "renegotiate-bytes")) + } else if (!strcmp(cepp->name, "renegotiate-bytes")) { - } - else if (!strcmp(cepp->name, "ciphers") || !strcmp(cepp->name, "server-cipher-list")) + } else if (!strcmp(cepp->name, "ciphers") || !strcmp(cepp->name, "server-cipher-list")) { CheckNull(cepp); - } - else if (!strcmp(cepp->name, "ciphersuites")) + } else if (!strcmp(cepp->name, "ciphersuites")) { CheckNull(cepp); - } - else if (!strcmp(cepp->name, "groups") || !strcmp(cepp->name, "ecdh-curves")) + } else if (!strcmp(cepp->name, "groups") || !strcmp(cepp->name, "ecdh-curves")) { CheckNull(cepp); #ifndef HAS_SSL_CTX_SET1_CURVES_LIST config_error("%s specified but your OpenSSL/LibreSSL library does not " "support setting groups or curves. Either upgrade to a " "newer library version or remove the '%s' directive " - "from your configuration file", cepp->name, cepp->name); + "from your configuration file", + cepp->name, cepp->name); errors++; #endif - } - else if (!strcmp(cepp->name, "signature-algorithms")) + } else if (!strcmp(cepp->name, "signature-algorithms")) { CheckNull(cepp); - } - else if (!strcmp(cepp->name, "protocols")) + } else if (!strcmp(cepp->name, "protocols")) { char copy[512], *p, *name; int v = 0; @@ -7486,12 +7361,12 @@ void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) { #ifdef SSL_OP_NO_TLSv1_3 config_warn("%s:%i: %s: unknown protocol '%s'. " - "Valid protocols are: TLSv1,TLSv1.1,TLSv1.2,TLSv1.3", - cepp->file->filename, cepp->line_number, config_var(cepp), name); + "Valid protocols are: TLSv1,TLSv1.1,TLSv1.2,TLSv1.3", + cepp->file->filename, cepp->line_number, config_var(cepp), name); #else config_warn("%s:%i: %s: unknown protocol '%s'. " - "Valid protocols are: TLSv1,TLSv1.1,TLSv1.2", - cepp->file->filename, cepp->line_number, config_var(cepp), name); + "Valid protocols are: TLSv1,TLSv1.1,TLSv1.2", + cepp->file->filename, cepp->line_number, config_var(cepp), name); #endif } @@ -7508,13 +7383,12 @@ void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) if (v == 0) { config_error("%s:%i: %s: no protocols enabled. Hint: set at least TLSv1.2", - cepp->file->filename, cepp->line_number, config_var(cepp)); + cepp->file->filename, cepp->line_number, config_var(cepp)); errors++; } - } - else if (!strcmp(cepp->name, "certificate") || - !strcmp(cepp->name, "key") || - !strcmp(cepp->name, "trusted-ca-file")) + } else if (!strcmp(cepp->name, "certificate") || + !strcmp(cepp->name, "key") || + !strcmp(cepp->name, "trusted-ca-file")) { char *path; CheckNull(cepp); @@ -7526,14 +7400,13 @@ void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) if (!file_exists(path)) { config_error("%s:%i: %s: could not open '%s': %s", - cepp->file->filename, cepp->line_number, config_var(cepp), - path, strerror(errno)); + cepp->file->filename, cepp->line_number, config_var(cepp), + path, strerror(errno)); safe_free(path); errors++; } safe_free(path); - } - else if (!strcmp(cepp->name, "dh")) + } else if (!strcmp(cepp->name, "dh")) { /* Support for this undocumented option was silently dropped in 5.0.0. * Since 5.0.7 we print a warning about it, since you never know @@ -7541,10 +7414,9 @@ void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) */ config_warn("%s:%d: Not reading DH file '%s'. UnrealIRCd does not support old DH(E), we use modern ECDHE/EECDH. " "Just remove the 'dh' directive from your config file to get rid of this warning.", - cepp->file->filename, cepp->line_number, - cepp->value ? cepp->value : ""); - } - else if (!strcmp(cepp->name, "outdated-protocols")) + cepp->file->filename, cepp->line_number, + cepp->value ? cepp->value : ""); + } else if (!strcmp(cepp->name, "outdated-protocols")) { char copy[512], *p, *name; int v = 0; @@ -7569,34 +7441,31 @@ void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) { #ifdef SSL_OP_NO_TLSv1_3 config_warn("%s:%i: %s: unknown protocol '%s'. " - "Valid protocols are: TLSv1,TLSv1.1,TLSv1.2,TLSv1.3", - cepp->file->filename, cepp->line_number, config_var(cepp), name); + "Valid protocols are: TLSv1,TLSv1.1,TLSv1.2,TLSv1.3", + cepp->file->filename, cepp->line_number, config_var(cepp), name); #else config_warn("%s:%i: %s: unknown protocol '%s'. " - "Valid protocols are: TLSv1,TLSv1.1,TLSv1.2", - cepp->file->filename, cepp->line_number, config_var(cepp), name); + "Valid protocols are: TLSv1,TLSv1.1,TLSv1.2", + cepp->file->filename, cepp->line_number, config_var(cepp), name); #endif - } + } } - } - else if (!strcmp(cepp->name, "outdated-ciphers")) + } else if (!strcmp(cepp->name, "outdated-ciphers")) { CheckNull(cepp); - } - else if (!strcmp(cepp->name, "options")) + } else if (!strcmp(cepp->name, "options")) { for (ceppp = cepp->items; ceppp; ceppp = ceppp->next) { if (!nv_find_by_name(_TLSFlags, ceppp->name)) { config_error("%s:%i: unknown TLS option '%s'", - ceppp->file->filename, - ceppp->line_number, ceppp->name); - errors ++; + ceppp->file->filename, + ceppp->line_number, ceppp->name); + errors++; } } - } - else if (!strcmp(cepp->name, "sts-policy")) + } else if (!strcmp(cepp->name, "sts-policy")) { int has_port = 0; int has_duration = 0; @@ -7615,8 +7484,7 @@ void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) errors++; } has_port = 1; - } - else if (!strcmp(ceppp->name, "duration")) + } else if (!strcmp(ceppp->name, "duration")) { long duration; CheckNull(ceppp); @@ -7628,8 +7496,7 @@ void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) errors++; } has_duration = 1; - } - else if (!strcmp(ceppp->name, "preload")) + } else if (!strcmp(ceppp->name, "preload")) { CheckNull(ceppp); } @@ -7646,15 +7513,13 @@ void test_tlsblock(ConfigFile *conf, ConfigEntry *cep, int *totalerrors) cepp->file->filename, cepp->line_number); errors++; } - } - else if (!strcmp(cepp->name, "certificate-expiry-notification")) + } else if (!strcmp(cepp->name, "certificate-expiry-notification")) { - } - else + } else { config_error("%s:%i: unknown directive %s", - cepp->file->filename, cepp->line_number, - config_var(cepp)); + cepp->file->filename, cepp->line_number, + config_var(cepp)); errors++; } } @@ -7745,20 +7610,16 @@ void conf_tlsblock(ConfigFile *conf, ConfigEntry *cep, TLSOptions *tlsoptions, T if (!strcmp(cepp->name, "ciphers") || !strcmp(cepp->name, "server-cipher-list")) { safe_strdup(tlsoptions->ciphers, cepp->value); - } - else if (!strcmp(cepp->name, "ciphersuites")) + } else if (!strcmp(cepp->name, "ciphersuites")) { safe_strdup(tlsoptions->ciphersuites, cepp->value); - } - else if (!strcmp(cepp->name, "groups") || !strcmp(cepp->name, "ecdh-curves")) + } else if (!strcmp(cepp->name, "groups") || !strcmp(cepp->name, "ecdh-curves")) { safe_strdup(tlsoptions->groups, cepp->value); - } - else if (!strcmp(cepp->name, "signature-algorithms")) + } else if (!strcmp(cepp->name, "signature-algorithms")) { safe_strdup(tlsoptions->signature_algorithms, cepp->value); - } - else if (!strcmp(cepp->name, "protocols")) + } else if (!strcmp(cepp->name, "protocols")) { char copy[512], *p, *name; int option; @@ -7798,39 +7659,31 @@ void conf_tlsblock(ConfigFile *conf, ConfigEntry *cep, TLSOptions *tlsoptions, T tlsoptions->protocols &= ~option; } } - } - else if (!strcmp(cepp->name, "certificate")) + } else if (!strcmp(cepp->name, "certificate")) { convert_to_absolute_path(&cepp->value, CONFDIR); append_name_list(tlsoptions->certificate_files, cepp->value); - } - else if (!strcmp(cepp->name, "key")) + } else if (!strcmp(cepp->name, "key")) { convert_to_absolute_path(&cepp->value, CONFDIR); append_name_list(tlsoptions->key_files, cepp->value); - } - else if (!strcmp(cepp->name, "trusted-ca-file")) + } else if (!strcmp(cepp->name, "trusted-ca-file")) { convert_to_absolute_path(&cepp->value, CONFDIR); safe_strdup(tlsoptions->trusted_ca_file, cepp->value); - } - else if (!strcmp(cepp->name, "outdated-protocols")) + } else if (!strcmp(cepp->name, "outdated-protocols")) { safe_strdup(tlsoptions->outdated_protocols, cepp->value); - } - else if (!strcmp(cepp->name, "outdated-ciphers")) + } else if (!strcmp(cepp->name, "outdated-ciphers")) { safe_strdup(tlsoptions->outdated_ciphers, cepp->value); - } - else if (!strcmp(cepp->name, "renegotiate-bytes")) + } else if (!strcmp(cepp->name, "renegotiate-bytes")) { tlsoptions->renegotiate_bytes = config_checkval(cepp->value, CFG_SIZE); - } - else if (!strcmp(cepp->name, "renegotiate-timeout")) + } else if (!strcmp(cepp->name, "renegotiate-timeout")) { tlsoptions->renegotiate_timeout = config_checkval(cepp->value, CFG_TIME); - } - else if (!strcmp(cepp->name, "options")) + } else if (!strcmp(cepp->name, "options")) { tlsoptions->options = 0; for (ceppp = cepp->items; ceppp; ceppp = ceppp->next) @@ -7838,8 +7691,7 @@ void conf_tlsblock(ConfigFile *conf, ConfigEntry *cep, TLSOptions *tlsoptions, T long v = nv_find_by_name(_TLSFlags, ceppp->name); tlsoptions->options |= v; } - } - else if (!strcmp(cepp->name, "sts-policy")) + } else if (!strcmp(cepp->name, "sts-policy")) { /* We do not inherit ::sts-policy if there is a specific block for this one... */ tlsoptions->sts_port = 0; @@ -7854,8 +7706,7 @@ void conf_tlsblock(ConfigFile *conf, ConfigEntry *cep, TLSOptions *tlsoptions, T else if (!strcmp(ceppp->name, "preload")) tlsoptions->sts_preload = config_checkval(ceppp->value, CFG_YESNO); } - } - else if (!strcmp(cepp->name, "certificate-expiry-notification")) + } else if (!strcmp(cepp->name, "certificate-expiry-notification")) { tlsoptions->certificate_expiry_notification = config_checkval(cepp->value, CFG_YESNO); } @@ -7877,7 +7728,7 @@ void conf_tlsblock(ConfigFile *conf, ConfigEntry *cep, TLSOptions *tlsoptions, T } } -int _conf_set(ConfigFile *conf, ConfigEntry *ce) +int _conf_set(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cepp, *ceppp, *cep4; Hook *h; @@ -7888,29 +7739,31 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) for (cep = ce->items; cep; cep = cep->next) { - if (!strcmp(cep->name, "kline-address")) { + if (!strcmp(cep->name, "kline-address")) + { safe_strdup(tempiConf.kline_address, cep->value); } - if (!strcmp(cep->name, "gline-address")) { + if (!strcmp(cep->name, "gline-address")) + { safe_strdup(tempiConf.gline_address, cep->value); - } - else if (!strcmp(cep->name, "modes-on-oper")) { - tempiConf.oper_modes = (long) set_usermode(cep->value); - } - else if (!strcmp(cep->name, "modes-on-join")) { + } else if (!strcmp(cep->name, "modes-on-oper")) + { + tempiConf.oper_modes = (long)set_usermode(cep->value); + } else if (!strcmp(cep->name, "modes-on-join")) + { conf_channelmodes(cep->value, &tempiConf.modes_on_join); tempiConf.modes_on_join_set = 1; - } - else if (!strcmp(cep->name, "snomask-on-oper")) { + } else if (!strcmp(cep->name, "snomask-on-oper")) + { safe_strdup(tempiConf.oper_snomask, cep->value); - } - else if (!strcmp(cep->name, "server-notice-colors")) { + } else if (!strcmp(cep->name, "server-notice-colors")) + { tempiConf.server_notice_colors = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "server-notice-show-event")) { + } else if (!strcmp(cep->name, "server-notice-show-event")) + { tempiConf.server_notice_show_event = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "level-on-join")) { + } else if (!strcmp(cep->name, "level-on-join")) + { const char *res = channellevel_to_string(cep->value); /* 'halfop', etc */ if (!res) { @@ -7933,35 +7786,35 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) res = cep->value; /* if we reach this.. then it is a single letter */ } safe_strdup(tempiConf.level_on_join, res); - } - else if (!strcmp(cep->name, "who-limit")) { + } else if (!strcmp(cep->name, "who-limit")) + { tempiConf.who_limit = atol(cep->value); - } - else if (!strcmp(cep->name, "maxbans")) { + } else if (!strcmp(cep->name, "maxbans")) + { tempiConf.maxbans = atol(cep->value); - } - else if (!strcmp(cep->name, "silence-limit")) { + } else if (!strcmp(cep->name, "silence-limit")) + { tempiConf.silence_limit = atol(cep->value); - } - else if (!strcmp(cep->name, "oper-auto-join")) { + } else if (!strcmp(cep->name, "oper-auto-join")) + { safe_strdup(tempiConf.oper_auto_join_chans, cep->value); - } - else if (!strcmp(cep->name, "oper-vhost")) { + } else if (!strcmp(cep->name, "oper-vhost")) + { safe_strdup(tempiConf.oper_vhost, cep->value); - } - else if (!strcmp(cep->name, "check-target-nick-bans")) { + } else if (!strcmp(cep->name, "check-target-nick-bans")) + { tempiConf.check_target_nick_bans = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "ping-cookie")) { + } else if (!strcmp(cep->name, "ping-cookie")) + { tempiConf.ping_cookie = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "watch-away-notification")) { + } else if (!strcmp(cep->name, "watch-away-notification")) + { tempiConf.watch_away_notification = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "uhnames")) { + } else if (!strcmp(cep->name, "uhnames")) + { tempiConf.uhnames = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "allow-userhost-change")) { + } else if (!strcmp(cep->name, "allow-userhost-change")) + { if (!strcasecmp(cep->value, "always")) tempiConf.userhost_allowed = UHALLOW_ALWAYS; else if (!strcasecmp(cep->value, "never")) @@ -7970,31 +7823,30 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) tempiConf.userhost_allowed = UHALLOW_NOCHANS; else tempiConf.userhost_allowed = UHALLOW_REJOIN; - } - else if (!strcmp(cep->name, "allow-setident")) { + } else if (!strcmp(cep->name, "allow-setident")) + { tempiConf.allow_setident = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "allow-setname")) { + } else if (!strcmp(cep->name, "allow-setname")) + { tempiConf.allow_setname = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "channel-command-prefix")) { + } else if (!strcmp(cep->name, "channel-command-prefix")) + { safe_strdup(tempiConf.channel_command_prefix, cep->value); - } - else if (!strcmp(cep->name, "restrict-channelmodes")) { + } else if (!strcmp(cep->name, "restrict-channelmodes")) + { safe_strdup(tempiConf.restrict_channelmodes, cep->value); - } - else if (!strcmp(cep->name, "named-extended-bans")) { + } else if (!strcmp(cep->name, "named-extended-bans")) + { tempiConf.named_extended_bans = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "anti-spam-quit-message-time")) { - tempiConf.anti_spam_quit_message_time = config_checkval(cep->value,CFG_TIME); - } - else if (!strcmp(cep->name, "allow-user-stats")) { + } else if (!strcmp(cep->name, "anti-spam-quit-message-time")) + { + tempiConf.anti_spam_quit_message_time = config_checkval(cep->value, CFG_TIME); + } else if (!strcmp(cep->name, "allow-user-stats")) + { if (!cep->items) { safe_strdup(tempiConf.allow_user_stats, cep->value); - } - else + } else { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -8003,14 +7855,13 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) AddListItem(os, tempiConf.allow_user_stats_ext); } } - } - else if (!strcmp(cep->name, "ping-warning")) { + } else if (!strcmp(cep->name, "ping-warning")) + { tempiConf.ping_warning = atoi(cep->value); - } - else if (!strcmp(cep->name, "maxdccallow")) { + } else if (!strcmp(cep->name, "maxdccallow")) + { tempiConf.maxdccallow = atoi(cep->value); - } - else if (!strcmp(cep->name, "max-targets-per-command")) + } else if (!strcmp(cep->name, "max-targets-per-command")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -8021,60 +7872,63 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) v = atoi(cepp->value); setmaxtargets(cepp->name, v); } - } - else if (!strcmp(cep->name, "network-name")) { + } else if (!strcmp(cep->name, "network-name")) + { char *tmp; safe_strdup(tempiConf.network_name, cep->value); - for (tmp = cep->value; *cep->value; cep->value++) { + for (tmp = cep->value; *cep->value; cep->value++) + { if (*cep->value == ' ') - *cep->value='-'; + *cep->value = '-'; } safe_strdup(tempiConf.network_name_005, tmp); cep->value = tmp; - } - else if (!strcmp(cep->name, "default-server")) { + } else if (!strcmp(cep->name, "default-server")) + { safe_strdup(tempiConf.default_server, cep->value); - } - else if (!strcmp(cep->name, "services-server")) { + } else if (!strcmp(cep->name, "services-server")) + { safe_strdup(tempiConf.services_name, cep->value); - } - else if (!strcmp(cep->name, "sasl-server")) { + } else if (!strcmp(cep->name, "sasl-server")) + { safe_strdup(tempiConf.sasl_server, cep->value); - } - else if (!strcmp(cep->name, "stats-server")) { + } else if (!strcmp(cep->name, "stats-server")) + { safe_strdup(tempiConf.stats_server, cep->value); - } - else if (!strcmp(cep->name, "help-channel")) { + } else if (!strcmp(cep->name, "help-channel")) + { safe_strdup(tempiConf.helpchan, cep->value); - } - else if (!strcmp(cep->name, "cloak-prefix") || !strcmp(cep->name, "hiddenhost-prefix")) { + } else if (!strcmp(cep->name, "cloak-prefix") || !strcmp(cep->name, "hiddenhost-prefix")) + { safe_strdup(tempiConf.cloak_prefix, cep->value); - } - else if (!strcmp(cep->name, "hide-ban-reason")) { + } else if (!strcmp(cep->name, "hide-ban-reason")) + { if (!strcmp(cep->value, "yes")) tempiConf.hide_ban_reason = HIDE_BAN_REASON_YES; else if (!strcmp(cep->value, "no")) tempiConf.hide_ban_reason = HIDE_BAN_REASON_NO; else if (!strcmp(cep->value, "auto")) tempiConf.hide_ban_reason = HIDE_BAN_REASON_AUTO; - } - else if (!strcmp(cep->name, "hide-killed-by")) { + } else if (!strcmp(cep->name, "hide-killed-by")) + { tempiConf.hide_killed_by = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "prefix-quit")) { + } else if (!strcmp(cep->name, "prefix-quit")) + { if (!strcmp(cep->value, "0") || !strcmp(cep->value, "no")) safe_free(tempiConf.prefix_quit); else safe_strdup(tempiConf.prefix_quit, cep->value); - } - else if (!strcmp(cep->name, "link")) { - for (cepp = cep->items; cepp; cepp = cepp->next) { - if (!strcmp(cepp->name, "bind-ip")) { + } else if (!strcmp(cep->name, "link")) + { + for (cepp = cep->items; cepp; cepp = cepp->next) + { + if (!strcmp(cepp->name, "bind-ip")) + { safe_strdup(tempiConf.link_bindip, cepp->value); } } - } - else if (!strcmp(cep->name, "anti-flood")) { + } else if (!strcmp(cep->name, "anti-flood")) + { for (cepp = cep->items; cepp; cepp = cepp->next) { int lag_penalty = -1; @@ -8085,7 +7939,7 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) int used = 0; for (h = Hooks[HOOKTYPE_CONFIGRUN]; h; h = h->next) { - used = (*(h->func.intfunc))(conf,ceppp,CONFIG_SET_ANTI_FLOOD); + used = (*(h->func.intfunc))(conf, ceppp, CONFIG_SET_ANTI_FLOOD); if (used == 1) break; } @@ -8104,69 +7958,57 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cep4->name, "ban-action") || !strcmp(cep4->name, "action")) parse_ban_action_config(cep4, &tempiConf.handshake_data_flood_ban_action); } - } - else if (!strcmp(ceppp->name, "away-flood")) + } else if (!strcmp(ceppp->name, "away-flood")) { config_parse_flood_generic(ceppp->value, &tempiConf, cepp->name, FLD_AWAY); - } - else if (!strcmp(ceppp->name, "nick-flood")) + } else if (!strcmp(ceppp->name, "nick-flood")) { config_parse_flood_generic(ceppp->value, &tempiConf, cepp->name, FLD_NICK); - } - else if (!strcmp(ceppp->name, "vhost-flood")) + } else if (!strcmp(ceppp->name, "vhost-flood")) { config_parse_flood_generic(ceppp->value, &tempiConf, cepp->name, FLD_VHOST); - } - else if (!strcmp(ceppp->name, "join-flood")) + } else if (!strcmp(ceppp->name, "join-flood")) { config_parse_flood_generic(ceppp->value, &tempiConf, cepp->name, FLD_JOIN); - } - else if (!strcmp(ceppp->name, "invite-flood")) + } else if (!strcmp(ceppp->name, "invite-flood")) { config_parse_flood_generic(ceppp->value, &tempiConf, cepp->name, FLD_INVITE); - } - else if (!strcmp(ceppp->name, "knock-flood")) + } else if (!strcmp(ceppp->name, "knock-flood")) { config_parse_flood_generic(ceppp->value, &tempiConf, cepp->name, FLD_KNOCK); - } - else if (!strcmp(ceppp->name, "lag-penalty")) + } else if (!strcmp(ceppp->name, "lag-penalty")) { lag_penalty = atoi(ceppp->value); - } - else if (!strcmp(ceppp->name, "lag-penalty-bytes")) + } else if (!strcmp(ceppp->name, "lag-penalty-bytes")) { lag_penalty_bytes = config_checkval(ceppp->value, CFG_SIZE); if (lag_penalty_bytes <= 0) lag_penalty_bytes = INT_MAX; - } - else if (!strcmp(ceppp->name, "connect-flood")) + } else if (!strcmp(ceppp->name, "connect-flood")) { int cnt, period; config_parse_flood(ceppp->value, &cnt, &period); tempiConf.throttle_count = cnt; tempiConf.throttle_period = period; - } - else if (!strcmp(ceppp->name, "max-concurrent-conversations")) + } else if (!strcmp(ceppp->name, "max-concurrent-conversations")) { /* We use a hack here to make it fit our storage format */ char buf[64]; - int users=0; - long every=0; + int users = 0; + long every = 0; for (cep4 = ceppp->items; cep4; cep4 = cep4->next) { if (!strcmp(cep4->name, "users")) { users = atoi(cep4->value); - } else - if (!strcmp(cep4->name, "new-user-every")) + } else if (!strcmp(cep4->name, "new-user-every")) { every = config_checkval(cep4->value, CFG_TIME); } } snprintf(buf, sizeof(buf), "%d:%ld", users, every); config_parse_flood_generic(buf, &tempiConf, cepp->name, FLD_CONVERSATIONS); - } - else if (!strcmp(ceppp->name, "multiline")) + } else if (!strcmp(ceppp->name, "multiline")) { /* Same hack: store max-lines in limit, max-bytes in period */ char buf[64]; @@ -8191,8 +8033,7 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) config_parse_flood_generic(buf, &tempiConf, cepp->name, FLD_LAG_PENALTY); } } - } - else if (!strcmp(cep->name, "log-throttle")) + } else if (!strcmp(cep->name, "log-throttle")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -8208,51 +8049,52 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) add_log_throttle_config(&tempiConf.log_throttle, cepp->name, cnt, period, 0); } } - } - else if (!strcmp(cep->name, "options")) { - for (cepp = cep->items; cepp; cepp = cepp->next) { - if (!strcmp(cepp->name, "hide-ulines")) { + } else if (!strcmp(cep->name, "options")) + { + for (cepp = cep->items; cepp; cepp = cepp->next) + { + if (!strcmp(cepp->name, "hide-ulines")) + { tempiConf.hide_ulines = 1; - } - else if (!strcmp(cepp->name, "flat-map")) { + } else if (!strcmp(cepp->name, "flat-map")) + { tempiConf.flat_map = 1; - } - else if (!strcmp(cepp->name, "show-opermotd")) { + } else if (!strcmp(cepp->name, "show-opermotd")) + { tempiConf.show_opermotd = 1; - } - else if (!strcmp(cepp->name, "identd-check")) { + } else if (!strcmp(cepp->name, "identd-check")) + { tempiConf.ident_check = 1; - } - else if (!strcmp(cepp->name, "fail-oper-warn")) { + } else if (!strcmp(cepp->name, "fail-oper-warn")) + { tempiConf.fail_oper_warn = 1; - } - else if (!strcmp(cepp->name, "show-connect-info")) { + } else if (!strcmp(cepp->name, "show-connect-info")) + { tempiConf.show_connect_info = 1; - } - else if (!strcmp(cepp->name, "no-connect-tls-info")) { + } else if (!strcmp(cepp->name, "no-connect-tls-info")) + { tempiConf.no_connect_tls_info = 1; - } - else if (!strcmp(cepp->name, "dont-resolve")) { + } else if (!strcmp(cepp->name, "dont-resolve")) + { tempiConf.dont_resolve = 1; - } - else if (!strcmp(cepp->name, "mkpasswd-for-everyone")) { + } else if (!strcmp(cepp->name, "mkpasswd-for-everyone")) + { tempiConf.mkpasswd_for_everyone = 1; - } - else if (!strcmp(cepp->name, "allow-insane-bans")) { + } else if (!strcmp(cepp->name, "allow-insane-bans")) + { tempiConf.allow_insane_bans = 1; - } - else if (!strcmp(cepp->name, "allow-part-if-shunned")) { + } else if (!strcmp(cepp->name, "allow-part-if-shunned")) + { tempiConf.allow_part_if_shunned = 1; - } - else if (!strcmp(cepp->name, "disable-cap")) { + } else if (!strcmp(cepp->name, "disable-cap")) + { tempiConf.disable_cap = 1; - } - else if (!strcmp(cepp->name, "disable-ipv6")) { + } else if (!strcmp(cepp->name, "disable-ipv6")) + { /* other code handles this */ } } - } - else if (!strcmp(cep->name, "cloak-keys")) + } else if (!strcmp(cep->name, "cloak-keys")) { for (h = Hooks[HOOKTYPE_CONFIGRUN]; h; h = h->next) { @@ -8261,29 +8103,27 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) if (value == 1) break; } - } - else if (!strcmp(cep->name, "ident")) + } else if (!strcmp(cep->name, "ident")) { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "connect-timeout")) - tempiConf.ident_connect_timeout = config_checkval(cepp->value,CFG_TIME); + tempiConf.ident_connect_timeout = config_checkval(cepp->value, CFG_TIME); if (!strcmp(cepp->name, "read-timeout")) - tempiConf.ident_read_timeout = config_checkval(cepp->value,CFG_TIME); + tempiConf.ident_read_timeout = config_checkval(cepp->value, CFG_TIME); } - } - else if (!strcmp(cep->name, "spamfilter")) + } else if (!strcmp(cep->name, "spamfilter")) { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "ban-time")) - tempiConf.spamfilter_ban_time = config_checkval(cepp->value,CFG_TIME); + tempiConf.spamfilter_ban_time = config_checkval(cepp->value, CFG_TIME); else if (!strcmp(cepp->name, "ban-reason")) safe_strdup(tempiConf.spamfilter_ban_reason, cepp->value); else if (!strcmp(cepp->name, "virus-help-channel")) safe_strdup(tempiConf.spamfilter_virus_help_channel, cepp->value); else if (!strcmp(cepp->name, "virus-help-channel-deny")) - tempiConf.spamfilter_vchan_deny = config_checkval(cepp->value,CFG_YESNO); + tempiConf.spamfilter_vchan_deny = config_checkval(cepp->value, CFG_YESNO); else if (!strcmp(cepp->name, "except")) { if (cepp->value && !tempiConf.spamfilter_except) @@ -8297,34 +8137,29 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) skip_whitespace(&name); add_name_list(tempiConf.spamfilter_except->destination, name); } - } else { + } else + { /* New set::spamfilter::except code, where it is a mask item */ conf_match_block(conf, cepp, &tempiConf.spamfilter_except); } - } - else if (!strcmp(cepp->name, "detect-slow-warn")) + } else if (!strcmp(cepp->name, "detect-slow-warn")) { tempiConf.spamfilter_detectslow_warn = atol(cepp->value); - } - else if (!strcmp(cepp->name, "detect-slow-fatal")) + } else if (!strcmp(cepp->name, "detect-slow-fatal")) { tempiConf.spamfilter_detectslow_fatal = atol(cepp->value); - } - else if (!strcmp(cepp->name, "stop-on-first-match")) + } else if (!strcmp(cepp->name, "stop-on-first-match")) { tempiConf.spamfilter_stop_on_first_match = config_checkval(cepp->value, CFG_YESNO); - } - else if (!strcmp(cepp->name, "utf8")) + } else if (!strcmp(cepp->name, "utf8")) { tempiConf.spamfilter_utf8 = config_checkval(cepp->value, CFG_YESNO); - } - else if (!strcmp(cepp->name, "show-message-content-on-hit")) + } else if (!strcmp(cepp->name, "show-message-content-on-hit")) { tempiConf.spamfilter_show_message_content_on_hit = spamfilter_show_message_content_on_hit_strtoval(cepp->value); } } - } - else if (!strcmp(cep->name, "central-spamfilter")) + } else if (!strcmp(cep->name, "central-spamfilter")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -8345,44 +8180,41 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cepp->name, "limit-ban-time")) tempiConf.central_spamfilter_limit_ban_time = config_checkval(cepp->value, CFG_TIME); } - } - else if (!strcmp(cep->name, "default-bantime")) + } else if (!strcmp(cep->name, "default-bantime")) { - tempiConf.default_bantime = config_checkval(cep->value,CFG_TIME); - } - else if (!strcmp(cep->name, "ban-version-tkl-time")) + tempiConf.default_bantime = config_checkval(cep->value, CFG_TIME); + } else if (!strcmp(cep->name, "ban-version-tkl-time")) + { + tempiConf.ban_version_tkl_time = config_checkval(cep->value, CFG_TIME); + } else if (!strcmp(cep->name, "min-nick-length")) { - tempiConf.ban_version_tkl_time = config_checkval(cep->value,CFG_TIME); - } - else if (!strcmp(cep->name, "min-nick-length")) { int v = atoi(cep->value); tempiConf.min_nick_length = v; - } - else if (!strcmp(cep->name, "nick-length")) { + } else if (!strcmp(cep->name, "nick-length")) + { int v = atoi(cep->value); tempiConf.nick_length = v; - } - else if (!strcmp(cep->name, "topic-length")) { + } else if (!strcmp(cep->name, "topic-length")) + { int v = atoi(cep->value); tempiConf.topic_length = v; - } - else if (!strcmp(cep->name, "away-length")) { + } else if (!strcmp(cep->name, "away-length")) + { int v = atoi(cep->value); tempiConf.away_length = v; - } - else if (!strcmp(cep->name, "kick-length")) { + } else if (!strcmp(cep->name, "kick-length")) + { int v = atoi(cep->value); tempiConf.kick_length = v; - } - else if (!strcmp(cep->name, "quit-length")) { + } else if (!strcmp(cep->name, "quit-length")) + { int v = atoi(cep->value); tempiConf.quit_length = v; - } - else if (!strcmp(cep->name, "ssl") || !strcmp(cep->name, "tls")) { + } else if (!strcmp(cep->name, "ssl") || !strcmp(cep->name, "tls")) + { /* no need to alloc tempiConf.tls_options since config_defaults() already ensures it exists */ conf_tlsblock(conf, cep, tempiConf.tls_options, tempiConf.tls_options); - } - else if (!strcmp(cep->name, "plaintext-policy")) + } else if (!strcmp(cep->name, "plaintext-policy")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -8397,8 +8229,7 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cepp->name, "oper-message")) addmultiline(&tempiConf.plaintext_policy_oper_message, cepp->value); } - } - else if (!strcmp(cep->name, "outdated-tls-policy")) + } else if (!strcmp(cep->name, "outdated-tls-policy")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -8413,12 +8244,11 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cepp->name, "oper-message")) safe_strdup(tempiConf.outdated_tls_policy_oper_message, cepp->value); } - } - else if (!strcmp(cep->name, "default-ipv6-clone-mask")) + } else if (!strcmp(cep->name, "default-ipv6-clone-mask")) { tempiConf.default_ipv6_clone_mask = atoi(cep->value); - } - else if (!strcmp(cep->name, "hide-list")) { + } else if (!strcmp(cep->name, "hide-list")) + { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "deny-channel")) @@ -8427,36 +8257,28 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) /* if we would expand this later then change this to a bitmask or struct or whatever */ } } - } - else if (!strcmp(cep->name, "max-unknown-connections-per-ip")) + } else if (!strcmp(cep->name, "max-unknown-connections-per-ip")) { tempiConf.max_unknown_connections_per_ip = atoi(cep->value); - } - else if (!strcmp(cep->name, "handshake-timeout")) + } else if (!strcmp(cep->name, "handshake-timeout")) { tempiConf.handshake_timeout = config_checkval(cep->value, CFG_TIME); - } - else if (!strcmp(cep->name, "sasl-timeout")) + } else if (!strcmp(cep->name, "sasl-timeout")) { tempiConf.sasl_timeout = config_checkval(cep->value, CFG_TIME); - } - else if (!strcmp(cep->name, "handshake-delay")) + } else if (!strcmp(cep->name, "handshake-delay")) { tempiConf.handshake_delay = config_checkval(cep->value, CFG_TIME); - } - else if (!strcmp(cep->name, "handshake-boot-delay")) + } else if (!strcmp(cep->name, "handshake-boot-delay")) { tempiConf.handshake_boot_delay = config_checkval(cep->value, CFG_TIME); - } - else if (!strcmp(cep->name, "automatic-ban-target")) + } else if (!strcmp(cep->name, "automatic-ban-target")) { tempiConf.automatic_ban_target = ban_target_strtoval(cep->value); - } - else if (!strcmp(cep->name, "manual-ban-target")) + } else if (!strcmp(cep->name, "manual-ban-target")) { tempiConf.manual_ban_target = ban_target_strtoval(cep->value); - } - else if (!strcmp(cep->name, "reject-message")) + } else if (!strcmp(cep->name, "reject-message")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -8475,30 +8297,25 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cepp->name, "gline")) safe_strdup(tempiConf.reject_message_gline, cepp->value); } - } - else if (!strcmp(cep->name, "topic-setter")) + } else if (!strcmp(cep->name, "topic-setter")) { if (!strcmp(cep->value, "nick")) tempiConf.topic_setter = SETTER_NICK; else if (!strcmp(cep->value, "nick-user-host")) tempiConf.topic_setter = SETTER_NICK_USER_HOST; - } - else if (!strcmp(cep->name, "ban-setter")) + } else if (!strcmp(cep->name, "ban-setter")) { if (!strcmp(cep->value, "nick")) tempiConf.ban_setter = SETTER_NICK; else if (!strcmp(cep->value, "nick-user-host")) tempiConf.ban_setter = SETTER_NICK_USER_HOST; - } - else if (!strcmp(cep->name, "ban-setter-sync") || !strcmp(cep->name, "ban-setter-synch")) + } else if (!strcmp(cep->name, "ban-setter-sync") || !strcmp(cep->name, "ban-setter-synch")) { tempiConf.ban_setter_sync = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "part-instead-of-quit-on-comment-change")) + } else if (!strcmp(cep->name, "part-instead-of-quit-on-comment-change")) { tempiConf.part_instead_of_quit_on_comment_change = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "broadcast-channel-messages")) + } else if (!strcmp(cep->name, "broadcast-channel-messages")) { if (!strcmp(cep->value, "auto")) tempiConf.broadcast_channel_messages = BROADCAST_CHANNEL_MESSAGES_AUTO; @@ -8506,12 +8323,10 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) tempiConf.broadcast_channel_messages = BROADCAST_CHANNEL_MESSAGES_ALWAYS; else if (!strcmp(cep->value, "never")) tempiConf.broadcast_channel_messages = BROADCAST_CHANNEL_MESSAGES_NEVER; - } - else if (!strcmp(cep->name, "allowed-channelchars")) + } else if (!strcmp(cep->name, "allowed-channelchars")) { tempiConf.allowed_channelchars = allowed_channelchars_strtoval(cep->value); - } - else if (!strcmp(cep->name, "hide-idle-time")) + } else if (!strcmp(cep->name, "hide-idle-time")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -8546,8 +8361,7 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(ceppp->name, "retry")) tempiConf.dns_client_retry = atoi(ceppp->value); } - } else - if (!strcmp(cepp->name, "dnsbl")) + } else if (!strcmp(cepp->name, "dnsbl")) { for (ceppp = cepp->items; ceppp; ceppp = ceppp->next) { @@ -8558,7 +8372,8 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) } } } - } else if (!strcmp(cep->name, "network-icon")) { + } else if (!strcmp(cep->name, "network-icon")) + { safe_strdup(tempiConf.network_icon, cep->value); } else if (config_set_dynamic_set_block_item(conf, &dynamic_set, cep)) { @@ -8569,7 +8384,7 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) int value; for (h = Hooks[HOOKTYPE_CONFIGRUN]; h; h = h->next) { - value = (*(h->func.intfunc))(conf,cep,CONFIG_SET); + value = (*(h->func.intfunc))(conf, cep, CONFIG_SET); if (value == 1) break; } @@ -8578,7 +8393,7 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) return 0; } -int _test_set(ConfigFile *conf, ConfigEntry *ce) +int _test_set(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cepp, *ceppp, *cep4; int tempi; @@ -8591,41 +8406,42 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) for (cep = ce->items; cep; cep = cep->next) { - if (!strcmp(cep->name, "kline-address")) { + if (!strcmp(cep->name, "kline-address")) + { CheckNull(cep); CheckDuplicate(cep, kline_address, "kline-address"); if (!strchr(cep->value, '@') && !strchr(cep->value, ':')) { config_error("%s:%i: set::kline-address must be an e-mail or an URL", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); + errors++; + continue; + } else if (match_simple("*@unrealircd.com", cep->value) || match_simple("*@unrealircd.org", cep->value) || match_simple("unreal-*@lists.sourceforge.net", cep->value)) + { + config_error("%s:%i: set::kline-address may not be an UnrealIRCd Team address", + cep->file->filename, cep->line_number); errors++; continue; } - else if (match_simple("*@unrealircd.com", cep->value) || match_simple("*@unrealircd.org",cep->value) || match_simple("unreal-*@lists.sourceforge.net",cep->value)) - { - config_error("%s:%i: set::kline-address may not be an UnrealIRCd Team address", - cep->file->filename, cep->line_number); - errors++; continue; - } - } - else if (!strcmp(cep->name, "gline-address")) { + } else if (!strcmp(cep->name, "gline-address")) + { CheckNull(cep); CheckDuplicate(cep, gline_address, "gline-address"); if (!strchr(cep->value, '@') && !strchr(cep->value, ':')) { config_error("%s:%i: set::gline-address must be an e-mail or an URL", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); + errors++; + continue; + } else if (match_simple("*@unrealircd.com", cep->value) || match_simple("*@unrealircd.org", cep->value) || match_simple("unreal-*@lists.sourceforge.net", cep->value)) + { + config_error("%s:%i: set::gline-address may not be an UnrealIRCd Team address", + cep->file->filename, cep->line_number); errors++; continue; } - else if (match_simple("*@unrealircd.com", cep->value) || match_simple("*@unrealircd.org",cep->value) || match_simple("unreal-*@lists.sourceforge.net",cep->value)) - { - config_error("%s:%i: set::gline-address may not be an UnrealIRCd Team address", - cep->file->filename, cep->line_number); - errors++; continue; - } - } - else if (!strcmp(cep->name, "modes-on-join")) { + } else if (!strcmp(cep->name, "modes-on-join")) + { char *c; struct ChMode temp; memset(&temp, 0, sizeof(temp)); @@ -8646,7 +8462,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) case 'e': case 'I': config_error("%s:%i: set::modes-on-join may not contain +%c", - cep->file->filename, cep->line_number, *c); + cep->file->filename, cep->line_number, *c); errors++; break; } @@ -8656,8 +8472,8 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) * yet at this point, so we can't really verify much * here. */ - } - else if (!strcmp(cep->name, "modes-on-oper")) { + } else if (!strcmp(cep->name, "modes-on-oper")) + { char *p; CheckNull(cep); CheckDuplicate(cep, modes_on_oper, "modes-on-oper"); @@ -8665,29 +8481,29 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (strchr("orzS", *p)) { config_error("%s:%i: set::modes-on-oper may not include mode '%c'", - cep->file->filename, cep->line_number, *p); + cep->file->filename, cep->line_number, *p); errors++; } - } - else if (!strcmp(cep->name, "snomask-on-oper")) { + } else if (!strcmp(cep->name, "snomask-on-oper")) + { char *wrong_snomask; CheckNull(cep); CheckDuplicate(cep, snomask_on_oper, "snomask-on-oper"); if (!is_valid_snomask_string_testing(cep->value, &wrong_snomask)) { config_error("%s:%i: set::snomask-on-oper contains unknown snomask letter(s) '%s'", - cep->file->filename, cep->line_number, wrong_snomask); + cep->file->filename, cep->line_number, wrong_snomask); errors++; invalid_snomasks_encountered++; } - } - else if (!strcmp(cep->name, "server-notice-colors")) { + } else if (!strcmp(cep->name, "server-notice-colors")) + { CheckNull(cep); - } - else if (!strcmp(cep->name, "server-notice-show-event")) { + } else if (!strcmp(cep->name, "server-notice-show-event")) + { CheckNull(cep); - } - else if (!strcmp(cep->name, "level-on-join")) { + } else if (!strcmp(cep->name, "level-on-join")) + { CheckNull(cep); CheckDuplicate(cep, level_on_join, "level-on-join"); if (!channellevel_to_string(cep->value) && (strlen(cep->value) != 1)) @@ -8697,68 +8513,68 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number, cep->value); errors++; } - } - else if (!strcmp(cep->name, "who-limit")) { + } else if (!strcmp(cep->name, "who-limit")) + { CheckNull(cep); CheckDuplicate(cep, who_limit, "who-limit"); - if (!config_checkval(cep->value,CFG_SIZE)) + if (!config_checkval(cep->value, CFG_SIZE)) { config_error("%s:%i: set::who-limit: value must be at least 1", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "maxbans")) { + } else if (!strcmp(cep->name, "maxbans")) + { CheckNull(cep); CheckDuplicate(cep, maxbans, "maxbans"); - } - else if (!strcmp(cep->name, "maxbanlength")) { + } else if (!strcmp(cep->name, "maxbanlength")) + { config_warn("%s:%d: set::maxbanlength no longer exists as it was not deemed useful, this setting is now ignored.", cep->file->filename, cep->line_number); - } - else if (!strcmp(cep->name, "silence-limit")) { + } else if (!strcmp(cep->name, "silence-limit")) + { CheckNull(cep); CheckDuplicate(cep, silence_limit, "silence-limit"); - } - else if (!strcmp(cep->name, "oper-auto-join")) { + } else if (!strcmp(cep->name, "oper-auto-join")) + { CheckNull(cep); CheckDuplicate(cep, oper_auto_join, "oper-auto-join"); - } - else if (!strcmp(cep->name, "oper-vhost")) { + } else if (!strcmp(cep->name, "oper-vhost")) + { CheckNull(cep); if (!potentially_valid_vhost(cep->value)) { config_error("%s:%i: set::oper-vhost contains illegal characters or is too long: '%s'", - cep->file->filename, cep->line_number, cep->value); + cep->file->filename, cep->line_number, cep->value); errors++; } - } - else if (!strcmp(cep->name, "check-target-nick-bans")) { + } else if (!strcmp(cep->name, "check-target-nick-bans")) + { CheckNull(cep); CheckDuplicate(cep, check_target_nick_bans, "check-target-nick-bans"); - } - else if (!strcmp(cep->name, "pingpong-warning")) { + } else if (!strcmp(cep->name, "pingpong-warning")) + { config_error("%s:%i: set::pingpong-warning no longer exists (the warning is always off)", cep->file->filename, cep->line_number); errors++; - } - else if (!strcmp(cep->name, "ping-cookie")) { + } else if (!strcmp(cep->name, "ping-cookie")) + { CheckNull(cep); CheckDuplicate(cep, ping_cookie, "ping-cookie"); - } - else if (!strcmp(cep->name, "watch-away-notification")) { + } else if (!strcmp(cep->name, "watch-away-notification")) + { CheckNull(cep); CheckDuplicate(cep, watch_away_notification, "watch-away-notification"); - } - else if (!strcmp(cep->name, "uhnames")) { + } else if (!strcmp(cep->name, "uhnames")) + { CheckNull(cep); CheckDuplicate(cep, uhnames, "uhnames"); - } - else if (!strcmp(cep->name, "channel-command-prefix")) { + } else if (!strcmp(cep->name, "channel-command-prefix")) + { CheckNullAllowEmpty(cep); CheckDuplicate(cep, channel_command_prefix, "channel-command-prefix"); - } - else if (!strcmp(cep->name, "allow-userhost-change")) { + } else if (!strcmp(cep->name, "allow-userhost-change")) + { CheckNull(cep); CheckDuplicate(cep, allow_userhost_change, "allow-userhost-change"); if (strcasecmp(cep->value, "always") && @@ -8767,39 +8583,37 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) strcasecmp(cep->value, "force-rejoin")) { config_error("%s:%i: set::allow-userhost-change is invalid", - cep->file->filename, - cep->line_number); + cep->file->filename, + cep->line_number); errors++; continue; } - } - else if (!strcmp(cep->name, "allow-setident")) { + } else if (!strcmp(cep->name, "allow-setident")) + { CheckNull(cep); CheckDuplicate(cep, allow_setident, "allow-setident"); - } - else if (!strcmp(cep->name, "allow-setname")) { + } else if (!strcmp(cep->name, "allow-setname")) + { CheckNull(cep); CheckDuplicate(cep, allow_setname, "allow-setname"); - } - else if (!strcmp(cep->name, "anti-spam-quit-message-time")) { + } else if (!strcmp(cep->name, "anti-spam-quit-message-time")) + { CheckNull(cep); CheckDuplicate(cep, anti_spam_quit_message_time, "anti-spam-quit-message-time"); - } - else if (!strcmp(cep->name, "oper-only-stats")) + } else if (!strcmp(cep->name, "oper-only-stats")) { config_warn("%s:%d: We no longer use a blacklist for stats (set::oper-only-stats) but " - "have a whitelist now instead (set::allow-user-stats). ", - cep->file->filename, cep->line_number); + "have a whitelist now instead (set::allow-user-stats). ", + cep->file->filename, cep->line_number); config_warn("Simply delete the oper-only-stats line from your configuration file %s around line %d to get rid of this warning", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); continue; - } - else if (!strcmp(cep->name, "allow-user-stats")) + } else if (!strcmp(cep->name, "allow-user-stats")) { CheckDuplicate(cep, allow_user_stats, "allow-user-stats"); CheckNull(cep); - } - else if (!strcmp(cep->name, "ping-warning")) { + } else if (!strcmp(cep->name, "ping-warning")) + { CheckNull(cep); CheckDuplicate(cep, ping_warning, "ping-warning"); tempi = atoi(cep->value); @@ -8807,17 +8621,16 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (tempi > 170) { config_error("%s:%i: set::ping-warning must be < 170", - cep->file->filename, - cep->line_number); + cep->file->filename, + cep->line_number); errors++; continue; } - } - else if (!strcmp(cep->name, "maxdccallow")) { + } else if (!strcmp(cep->name, "maxdccallow")) + { CheckNull(cep); CheckDuplicate(cep, maxdccallow, "maxdccallow"); - } - else if (!strcmp(cep->name, "max-targets-per-command")) + } else if (!strcmp(cep->name, "max-targets-per-command")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -8834,11 +8647,10 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) cepp->name); errors++; } - } else - if (!strcasecmp(cepp->name, "USERHOST") || - !strcasecmp(cepp->name, "USERIP") || - !strcasecmp(cepp->name, "ISON") || - !strcasecmp(cepp->name, "WATCH")) + } else if (!strcasecmp(cepp->name, "USERHOST") || + !strcasecmp(cepp->name, "USERIP") || + !strcasecmp(cepp->name, "ISON") || + !strcasecmp(cepp->name, "WATCH")) { if (strcmp(cepp->value, "max")) { @@ -8867,8 +8679,8 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) } } } - } - else if (!strcmp(cep->name, "network-name")) { + } else if (!strcmp(cep->name, "network-name")) + { char *p; CheckNull(cep); CheckDuplicate(cep, network_name, "network-name"); @@ -8876,12 +8688,12 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if ((*p < ' ') || (*p > '~')) { config_error("%s:%i: set::network-name can only contain ASCII characters 33-126. Invalid character = '%c'", - cep->file->filename, cep->line_number, *p); + cep->file->filename, cep->line_number, *p); errors++; break; } - } - else if (!strcmp(cep->name, "network-icon")) { + } else if (!strcmp(cep->name, "network-icon")) + { /* Maximum URL length is (with a few characters margin): * 510 (IRC protocol line) - 55 for the static text (whitespace, ":", "375", "draft/ICON=", ":are supported by this server", etc) * - HOSTLEN (lazy me.name max) - NICKLEN (max nick length) @@ -8891,53 +8703,55 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) CheckNull(cep); CheckDuplicate(cep, network_icon, "network-icon"); - if ((strncmp(cep->value, "https://", 8) != 0) || !valid_text_nospaces(cep->value)) { + if ((strncmp(cep->value, "https://", 8) != 0) || !valid_text_nospaces(cep->value)) + { config_error("%s:%i: set::network-icon URL must be single-quoted and start with 'https://' like 'https://example.com/image.jpg'", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - if (strlen(cep->value) > max_url_len) { + if (strlen(cep->value) > max_url_len) + { config_error("%s:%i: set::network-icon URL is too long (max %d characters)", - cep->file->filename, cep->line_number, max_url_len); + cep->file->filename, cep->line_number, max_url_len); errors++; } - } - else if (!strcmp(cep->name, "default-server")) { + } else if (!strcmp(cep->name, "default-server")) + { CheckNull(cep); CheckDuplicate(cep, default_server, "default-server"); - } - else if (!strcmp(cep->name, "services-server")) { + } else if (!strcmp(cep->name, "services-server")) + { CheckNull(cep); CheckDuplicate(cep, services_server, "services-server"); - } - else if (!strcmp(cep->name, "sasl-server")) { + } else if (!strcmp(cep->name, "sasl-server")) + { CheckNull(cep); CheckDuplicate(cep, sasl_server, "sasl-server"); - } - else if (!strcmp(cep->name, "stats-server")) { + } else if (!strcmp(cep->name, "stats-server")) + { CheckNull(cep); CheckDuplicate(cep, stats_server, "stats-server"); - } - else if (!strcmp(cep->name, "help-channel")) { + } else if (!strcmp(cep->name, "help-channel")) + { CheckNull(cep); CheckDuplicate(cep, help_channel, "help-channel"); - } - else if (!strcmp(cep->name, "cloak-prefix") || !strcmp(cep->name, "hiddenhost-prefix")) { + } else if (!strcmp(cep->name, "cloak-prefix") || !strcmp(cep->name, "hiddenhost-prefix")) + { CheckNull(cep); CheckDuplicate(cep, hiddenhost_prefix, "cloak-prefix"); if (strchr(cep->value, ' ') || (*cep->value == ':')) { config_error("%s:%i: set::cloak-prefix must not contain spaces or be prefixed with ':'", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } - } - else if (!strcmp(cep->name, "prefix-quit")) { + } else if (!strcmp(cep->name, "prefix-quit")) + { CheckNull(cep); CheckDuplicate(cep, prefix_quit, "prefix-quit"); - } - else if (!strcmp(cep->name, "hide-ban-reason")) { + } else if (!strcmp(cep->name, "hide-ban-reason")) + { CheckNull(cep); CheckDuplicate(cep, hide_ban_reason, "hide-ban-reason"); if (strcmp(cep->value, "yes") && @@ -8945,58 +8759,57 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) strcmp(cep->value, "auto")) { config_error("%s:%i: set::hide-ban-reason must be one of: yes, no, auto", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } - } - else if (!strcmp(cep->name, "hide-killed-by")) { + } else if (!strcmp(cep->name, "hide-killed-by")) + { CheckNull(cep); CheckDuplicate(cep, hide_killed_by, "hide-killed-by"); - } - else if (!strcmp(cep->name, "restrict-channelmodes")) + } else if (!strcmp(cep->name, "restrict-channelmodes")) { CheckNull(cep); CheckDuplicate(cep, restrict_channelmodes, "restrict-channelmodes"); if (strchr(cep->value, '+') || strchr(cep->value, '-')) { config_error("%s:%i: set::restrict-channelmodes: may only contain mode characters, no + or -.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "restrict-extendedbans")) + } else if (!strcmp(cep->name, "restrict-extendedbans")) { config_error("%s:%d: set::restrict-extendedbans has no effect since UnrealIRCd 6.0.0. " "If you don't want a particular extended ban then don't load the module. " "Use something like this: blacklist-module \"extbans/quiet\";", cep->file->filename, cep->line_number); errors++; - } - else if (!strcmp(cep->name, "named-extended-bans")) + } else if (!strcmp(cep->name, "named-extended-bans")) { CheckNull(cep); - } - else if (!strcmp(cep->name, "link")) { - for (cepp = cep->items; cepp; cepp = cepp->next) { - CheckNull(cepp); - if (!strcmp(cepp->name, "bind-ip")) { - CheckDuplicate(cepp, link_bind_ip, "link::bind-ip"); - if (strcmp(cepp->value, "*")) - { - if (!is_valid_ip(cepp->value)) - { - config_error("%s:%i: set::link::bind-ip (%s) is not a valid IP", - cepp->file->filename, cepp->line_number, - cepp->value); - errors++; - continue; - } - } + } else if (!strcmp(cep->name, "link")) + { + for (cepp = cep->items; cepp; cepp = cepp->next) + { + CheckNull(cepp); + if (!strcmp(cepp->name, "bind-ip")) + { + CheckDuplicate(cepp, link_bind_ip, "link::bind-ip"); + if (strcmp(cepp->value, "*")) + { + if (!is_valid_ip(cepp->value)) + { + config_error("%s:%i: set::link::bind-ip (%s) is not a valid IP", + cepp->file->filename, cepp->line_number, + cepp->value); + errors++; + continue; } } - } - else if (!strcmp(cep->name, "throttle")) { + } + } + } else if (!strcmp(cep->name, "throttle")) + { config_error("%s:%i: set::throttle has been renamed. you now use " "set::anti-flood::connect-flood :. " "Or just remove the throttle block and you get the default " @@ -9004,8 +8817,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number); errors++; continue; - } - else if (!strcmp(cep->name, "anti-flood")) + } else if (!strcmp(cep->name, "anti-flood")) { int anti_flood_old = 0; int anti_flood_old_and_default = 0; @@ -9043,27 +8855,23 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) continue; - value = (*(h->func.intfunc))(conf,ceppp,CONFIG_SET_ANTI_FLOOD,&errs); + value = (*(h->func.intfunc))(conf, ceppp, CONFIG_SET_ANTI_FLOOD, &errs); if (value == 2) { used = 2; break; - } else - if (value == 1) + } else if (value == 1) { used = 1; break; - } else - if (value == -1) + } else if (value == -1) { used = 1; errors += errs; break; - } else - if (value == -2) + } else if (value == -2) { used = 2; errors += errs; @@ -9084,16 +8892,15 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) { config_error("%s:%i: %s cannot be in the set::anti-flood::everyone block. " "You can put it in 'known-users' or 'unknown-users' instead.", - ceppp->file->filename, ceppp->line_number, - ceppp->name); + ceppp->file->filename, ceppp->line_number, + ceppp->name); errors++; continue; - } else - if (!everyone && for_everyone) + } else if (!everyone && for_everyone) { config_error("%s:%i: %s must be in the set::anti-flood::everyone block, not anywhere else.", - ceppp->file->filename, ceppp->line_number, - ceppp->name); + ceppp->file->filename, ceppp->line_number, + ceppp->name); errors++; continue; } @@ -9110,32 +8917,30 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if ((v < 1) || (v > MAXCCUSERS)) { config_error("%s:%i: set::anti-flood::max-concurrent-conversations::users: " - "value should be between 1 and %d", - cep4->file->filename, cep4->line_number, MAXCCUSERS); + "value should be between 1 and %d", + cep4->file->filename, cep4->line_number, MAXCCUSERS); errors++; } - } else - if (!strcmp(cep4->name, "new-user-every")) + } else if (!strcmp(cep4->name, "new-user-every")) { long v = config_checkval(cep4->value, CFG_TIME); if ((v < 1) || (v > 120)) { config_error("%s:%i: set::anti-flood::max-concurrent-conversations::new-user-every: " - "value should be between 1 and 120 seconds", - cep4->file->filename, cep4->line_number); + "value should be between 1 and 120 seconds", + cep4->file->filename, cep4->line_number); errors++; } } else { config_error_unknownopt(cep4->file->filename, - cep4->line_number, "set::anti-flood", - cep4->name); + cep4->line_number, "set::anti-flood", + cep4->name); errors++; } } continue; /* required here, due to checknull directly below */ - } - else if (!strcmp(ceppp->name, "multiline")) + } else if (!strcmp(ceppp->name, "multiline")) { for (cep4 = ceppp->items; cep4; cep4 = cep4->next) { @@ -9146,47 +8951,43 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if ((v < 2) || (v > MULTILINE_MAX_CONFIGURABLE_LINES)) { config_error("%s:%i: set::anti-flood::multiline::max-lines: " - "value should be between 2 and %d", - cep4->file->filename, cep4->line_number, - MULTILINE_MAX_CONFIGURABLE_LINES); + "value should be between 2 and %d", + cep4->file->filename, cep4->line_number, + MULTILINE_MAX_CONFIGURABLE_LINES); errors++; } - } else - if (!strcmp(cep4->name, "max-bytes")) + } else if (!strcmp(cep4->name, "max-bytes")) { int v = config_checkval(cep4->value, CFG_SIZE); if ((v < 256) || (v > MULTILINE_MAX_CONFIGURABLE_BYTES)) { config_error("%s:%i: set::anti-flood::multiline::max-bytes: " - "value should be between 256 and %d", - cep4->file->filename, cep4->line_number, - MULTILINE_MAX_CONFIGURABLE_BYTES); + "value should be between 256 and %d", + cep4->file->filename, cep4->line_number, + MULTILINE_MAX_CONFIGURABLE_BYTES); errors++; } } else { config_error_unknownopt(cep4->file->filename, - cep4->line_number, "set::anti-flood::multiline", - cep4->name); + cep4->line_number, "set::anti-flood::multiline", + cep4->name); errors++; } } continue; - } - else if (!strcmp(ceppp->name, "maxchannelsperuser")) + } else if (!strcmp(ceppp->name, "maxchannelsperuser")) { CheckNull(ceppp); - } - else if (!strcmp(ceppp->name, "unknown-flood-amount") || - !strcmp(ceppp->name, "unknown-flood-bantime")) + } else if (!strcmp(ceppp->name, "unknown-flood-amount") || + !strcmp(ceppp->name, "unknown-flood-bantime")) { config_error("%s:%i: set::anti-flood::%s: this setting has been moved. " - "See https://www.unrealircd.org/docs/Anti-flood_settings#handshake-data-flood", - ceppp->file->filename, ceppp->line_number, ceppp->name); + "See https://www.unrealircd.org/docs/Anti-flood_settings#handshake-data-flood", + ceppp->file->filename, ceppp->line_number, ceppp->name); errors++; continue; - } - else if (!strcmp(ceppp->name, "handshake-data-flood")) + } else if (!strcmp(ceppp->name, "handshake-data-flood")) { for (cep4 = ceppp->items; cep4; cep4 = cep4->next) { @@ -9198,28 +8999,25 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (v < 1024) { config_error("%s:%i: set::anti-flood::handshake-data-flood::amount must be at least 1024 bytes", - cep4->file->filename, cep4->line_number); + cep4->file->filename, cep4->line_number); errors++; } - } else - if (!strcmp(cep4->name, "ban-action") || !strcmp(cep4->name, "action")) + } else if (!strcmp(cep4->name, "ban-action") || !strcmp(cep4->name, "action")) { CheckNull(cep4); errors += test_ban_action_config(cep4); - } else - if (!strcmp(cep4->name, "ban-time")) + } else if (!strcmp(cep4->name, "ban-time")) { CheckNull(cep4); } else { config_error_unknownopt(cep4->file->filename, - cep4->line_number, "set::anti-flood::handshake-data-flood", - cep4->name); + cep4->line_number, "set::anti-flood::handshake-data-flood", + cep4->name); errors++; } } - } - else if (!strcmp(ceppp->name, "away-count")) + } else if (!strcmp(ceppp->name, "away-count")) { int temp; CheckNull(ceppp); @@ -9227,22 +9025,20 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (temp < 1 || temp > 255) { config_error("%s:%i: set::anti-flood::away-count must be between 1 and 255", - ceppp->file->filename, ceppp->line_number); + ceppp->file->filename, ceppp->line_number); errors++; } - } - else if (!strcmp(ceppp->name, "away-period")) + } else if (!strcmp(ceppp->name, "away-period")) { CheckNull(ceppp); int temp = config_checkval(ceppp->value, CFG_TIME); if (temp < 10) { config_error("%s:%i: set::anti-flood::away-period must be greater than 9", - ceppp->file->filename, ceppp->line_number); + ceppp->file->filename, ceppp->line_number); errors++; } - } - else if (!strcmp(ceppp->name, "away-flood")) + } else if (!strcmp(ceppp->name, "away-flood")) { int cnt, period; CheckNull(ceppp); @@ -9250,12 +9046,11 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) (cnt < 1) || (cnt > 255) || (period < 10)) { config_error("%s:%i: set::anti-flood::away-flood error. Syntax is ':' (eg 5:60), " - "count should be 1-255, period should be greater than 9", - ceppp->file->filename, ceppp->line_number); + "count should be 1-255, period should be greater than 9", + ceppp->file->filename, ceppp->line_number); errors++; } - } - else if (!strcmp(ceppp->name, "nick-flood")) + } else if (!strcmp(ceppp->name, "nick-flood")) { int cnt, period; CheckNull(ceppp); @@ -9263,12 +9058,11 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) (cnt < 1) || (cnt > 255) || (period < 5)) { config_error("%s:%i: set::anti-flood::nick-flood error. Syntax is ':' (eg 5:60), " - "count should be 1-255, period should be greater than 4", - ceppp->file->filename, ceppp->line_number); + "count should be 1-255, period should be greater than 4", + ceppp->file->filename, ceppp->line_number); errors++; } - } - else if (!strcmp(ceppp->name, "vhost-flood")) + } else if (!strcmp(ceppp->name, "vhost-flood")) { int cnt, period; CheckNull(ceppp); @@ -9276,12 +9070,11 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) (cnt < 1) || (cnt > 255) || (period < 5)) { config_error("%s:%i: set::anti-flood::vhost-flood error. Syntax is ':' (eg 5:60), " - "count should be 1-255, period should be greater than 4", - ceppp->file->filename, ceppp->line_number); + "count should be 1-255, period should be greater than 4", + ceppp->file->filename, ceppp->line_number); errors++; } - } - else if (!strcmp(ceppp->name, "join-flood")) + } else if (!strcmp(ceppp->name, "join-flood")) { int cnt, period; CheckNull(ceppp); @@ -9290,12 +9083,11 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) (cnt < 1) || (cnt > 255) || (period < 5)) { config_error("%s:%i: join-flood error. Syntax is ':' (eg 5:60), " - "count should be 1-255, period should be greater than 4", - ceppp->file->filename, ceppp->line_number); + "count should be 1-255, period should be greater than 4", + ceppp->file->filename, ceppp->line_number); errors++; } - } - else if (!strcmp(ceppp->name, "invite-flood")) + } else if (!strcmp(ceppp->name, "invite-flood")) { int cnt, period; CheckNull(ceppp); @@ -9303,12 +9095,11 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) (cnt < 1) || (cnt > 255) || (period < 5)) { config_error("%s:%i: set::anti-flood::invite-flood error. Syntax is ':' (eg 5:60), " - "count should be 1-255, period should be greater than 4", - ceppp->file->filename, ceppp->line_number); + "count should be 1-255, period should be greater than 4", + ceppp->file->filename, ceppp->line_number); errors++; } - } - else if (!strcmp(ceppp->name, "knock-flood")) + } else if (!strcmp(ceppp->name, "knock-flood")) { int cnt, period; CheckNull(ceppp); @@ -9316,12 +9107,11 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) (cnt < 1) || (cnt > 255) || (period < 5)) { config_error("%s:%i: set::anti-flood::knock-flood error. Syntax is ':' (eg 5:60), " - "count should be 1-255, period should be greater than 4", - ceppp->file->filename, ceppp->line_number); + "count should be 1-255, period should be greater than 4", + ceppp->file->filename, ceppp->line_number); errors++; } - } - else if (!strcmp(ceppp->name, "lag-penalty")) + } else if (!strcmp(ceppp->name, "lag-penalty")) { int v; CheckNull(ceppp); @@ -9330,23 +9120,21 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if ((v < 0) || (v > 10000)) { config_error("%s:%i: set::anti-flood::%s::lag-penalty: value is in milliseconds and should be between 0 and 10000", - ceppp->file->filename, ceppp->line_number, cepp->name); + ceppp->file->filename, ceppp->line_number, cepp->name); errors++; } - } - else if (!strcmp(ceppp->name, "lag-penalty-bytes")) + } else if (!strcmp(ceppp->name, "lag-penalty-bytes")) { has_lag_penalty_bytes = 1; CheckNull(ceppp); - } - else if (!strcmp(ceppp->name, "connect-flood")) + } else if (!strcmp(ceppp->name, "connect-flood")) { int cnt, period; CheckNull(ceppp); if (strcmp(cepp->name, "everyone")) { config_error("%s:%i: connect-flood must be in the set::anti-flood::everyone block, not anywhere else.", - ceppp->file->filename, ceppp->line_number); + ceppp->file->filename, ceppp->line_number); errors++; continue; } @@ -9354,27 +9142,25 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) (cnt < 1) || (cnt > 255) || (period < 1) || (period > 3600)) { config_error("%s:%i: set::anti-flood::connect-flood: Syntax is ':' (eg 5:60), " - "count should be 1-255, period should be 1-3600", - ceppp->file->filename, ceppp->line_number); + "count should be 1-255, period should be 1-3600", + ceppp->file->filename, ceppp->line_number); errors++; } - } - else if (!strcmp(ceppp->name, "maxchannelsperuser")) + } else if (!strcmp(ceppp->name, "maxchannelsperuser")) { CheckNull(ceppp); - } - else + } else { config_error_unknownopt(ceppp->file->filename, - ceppp->line_number, "set::anti-flood", - ceppp->name); + ceppp->line_number, "set::anti-flood", + ceppp->name); errors++; } } - if (has_lag_penalty+has_lag_penalty_bytes == 1) + if (has_lag_penalty + has_lag_penalty_bytes == 1) { config_error("%s:%i: set::anti-flood::%s: if you use lag-penalty then you must also add an lag-penalty-bytes item (and vice-versa)", - cepp->file->filename, cepp->line_number, cepp->name); + cepp->file->filename, cepp->line_number, cepp->name); errors++; } } @@ -9387,19 +9173,17 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) config_warn("See https://www.unrealircd.org/docs/Anti-flood_settings for the new block style,"); config_warn("OR: simply remove all the anti-flood options from the conf to get rid of this " "warning and use the built-in defaults."); - } else - if (anti_flood_old_and_default == 1) + } else if (anti_flood_old_and_default == 1) { config_warn("%s:%d: the set::anti-flood block has been reorganized to be more flexible.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); config_warn("To fix this warning, delete the anti-flood block from your configuration file " "(file %s around line %d), this will make UnrealIRCd use the built-in defaults.", cep->file->filename, cep->line_number); config_warn("If you want to learn more about the new functionality you can visit " "https://www.unrealircd.org/docs/Anti-flood_settings"); } - } - else if (!strcmp(cep->name, "log-throttle")) + } else if (!strcmp(cep->name, "log-throttle")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -9410,7 +9194,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) { config_error("%s:%i: set::log-throttle::%s: missing value " "(need 'count:period' or 'unlimited')", - cepp->file->filename, cepp->line_number, cepp->name); + cepp->file->filename, cepp->line_number, cepp->name); errors++; continue; } @@ -9418,7 +9202,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) { config_error("%s:%i: set::log-throttle::%s: invalid event_id name " "(must contain only uppercase A-Z, 0-9 and underscores)", - cepp->file->filename, cepp->line_number, cepp->name); + cepp->file->filename, cepp->line_number, cepp->name); errors++; continue; } @@ -9428,77 +9212,75 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) { config_error("%s:%i: set::log-throttle::%s: invalid value '%s'. " "Syntax is ':' (eg 100:60), or 'unlimited'", - cepp->file->filename, cepp->line_number, cepp->name, cepp->value); + cepp->file->filename, cepp->line_number, cepp->name, cepp->value); errors++; } } - } - else if (!strcmp(cep->name, "options")) { - for (cepp = cep->items; cepp; cepp = cepp->next) { + } else if (!strcmp(cep->name, "options")) + { + for (cepp = cep->items; cepp; cepp = cepp->next) + { if (!strcmp(cepp->name, "hide-ulines")) { CheckDuplicate(cepp, options_hide_ulines, "options::hide-ulines"); - } - else if (!strcmp(cepp->name, "flat-map")) { + } else if (!strcmp(cepp->name, "flat-map")) + { CheckDuplicate(cepp, options_flat_map, "options::flat-map"); - } - else if (!strcmp(cepp->name, "show-opermotd")) { + } else if (!strcmp(cepp->name, "show-opermotd")) + { CheckDuplicate(cepp, options_show_opermotd, "options::show-opermotd"); - } - else if (!strcmp(cepp->name, "identd-check")) { + } else if (!strcmp(cepp->name, "identd-check")) + { CheckDuplicate(cepp, options_identd_check, "options::identd-check"); - } - else if (!strcmp(cepp->name, "fail-oper-warn")) { + } else if (!strcmp(cepp->name, "fail-oper-warn")) + { CheckDuplicate(cepp, options_fail_oper_warn, "options::fail-oper-warn"); - } - else if (!strcmp(cepp->name, "show-connect-info")) { + } else if (!strcmp(cepp->name, "show-connect-info")) + { CheckDuplicate(cepp, options_show_connect_info, "options::show-connect-info"); - } - else if (!strcmp(cepp->name, "no-connect-tls-info")) { + } else if (!strcmp(cepp->name, "no-connect-tls-info")) + { CheckDuplicate(cepp, options_no_connect_tls_info, "options::no-connect-tls-info"); - } - else if (!strcmp(cepp->name, "dont-resolve")) { + } else if (!strcmp(cepp->name, "dont-resolve")) + { CheckDuplicate(cepp, options_dont_resolve, "options::dont-resolve"); - } - else if (!strcmp(cepp->name, "mkpasswd-for-everyone")) { + } else if (!strcmp(cepp->name, "mkpasswd-for-everyone")) + { CheckDuplicate(cepp, options_mkpasswd_for_everyone, "options::mkpasswd-for-everyone"); - } - else if (!strcmp(cepp->name, "allow-insane-bans")) { + } else if (!strcmp(cepp->name, "allow-insane-bans")) + { CheckDuplicate(cepp, options_allow_insane_bans, "options::allow-insane-bans"); - } - else if (!strcmp(cepp->name, "allow-part-if-shunned")) { + } else if (!strcmp(cepp->name, "allow-part-if-shunned")) + { CheckDuplicate(cepp, options_allow_part_if_shunned, "options::allow-part-if-shunned"); - } - else if (!strcmp(cepp->name, "disable-cap")) { + } else if (!strcmp(cepp->name, "disable-cap")) + { CheckDuplicate(cepp, options_disable_cap, "options::disable-cap"); - } - else if (!strcmp(cepp->name, "disable-ipv6")) { + } else if (!strcmp(cepp->name, "disable-ipv6")) + { CheckDuplicate(cepp, options_disable_ipv6, "options::disable-ipv6"); DISABLE_IPV6 = 1; /* ugly ugly. needs to be done here because at conf runtime is too late. */ - } - else + } else { config_error_unknownopt(cepp->file->filename, - cepp->line_number, "set::options", - cepp->name); + cepp->line_number, "set::options", + cepp->name); errors++; continue; } } - } - else if (!strcmp(cep->name, "hosts")) { + } else if (!strcmp(cep->name, "hosts")) + { config_error("%s:%i: set::hosts has been removed. You can use oper::vhost now.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; - } - else if (!strcmp(cep->name, "cloak-keys")) + } else if (!strcmp(cep->name, "cloak-keys")) { CheckDuplicate(cep, cloak_keys, "cloak-keys"); for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) continue; value = (*(h->func.intfunc))(conf, cep, CONFIG_CLOAKKEYS, &errs); @@ -9512,8 +9294,8 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (value == -2) errors += errs; } - } - else if (!strcmp(cep->name, "ident")) { + } else if (!strcmp(cep->name, "ident")) + { for (cepp = cep->items; cepp; cepp = cepp->next) { int is_ok = 0; @@ -9522,39 +9304,38 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) { is_ok = 1; CheckDuplicate(cepp, ident_connect_timeout, "ident::connect-timeout"); - } - else if (!strcmp(cepp->name, "read-timeout")) + } else if (!strcmp(cepp->name, "read-timeout")) { is_ok = 1; CheckDuplicate(cepp, ident_read_timeout, "ident::read-timeout"); } if (is_ok) { - int v = config_checkval(cepp->value,CFG_TIME); + int v = config_checkval(cepp->value, CFG_TIME); if ((v > 60) || (v < 1)) { config_error("%s:%i: set::ident::%s value out of range (%d), should be between 1 and 60.", - cepp->file->filename, cepp->line_number, cepp->name, v); + cepp->file->filename, cepp->line_number, cepp->name, v); errors++; continue; } - } else { + } else + { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::ident", - cepp->name); + cepp->line_number, "set::ident", + cepp->name); errors++; continue; } } - } - else if (!strcmp(cep->name, "timesync") || !strcmp(cep->name, "timesynch")) + } else if (!strcmp(cep->name, "timesync") || !strcmp(cep->name, "timesynch")) { config_warn("%s:%i: Timesync support has been removed from UnrealIRCd. " "Please remove any set::timesync blocks you may have.", cep->file->filename, cep->line_number); config_warn("Use the time synchronization feature of your OS/distro instead!"); - } - else if (!strcmp(cep->name, "spamfilter")) { + } else if (!strcmp(cep->name, "spamfilter")) + { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "except")) @@ -9569,7 +9350,8 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) "except { destination { \"#chan1\"; \"#chan2\"; \"SomeNick\"; } }", cepp->file->filename, cepp->line_number); config_warn("For more information, see https://www.unrealircd.org/docs/Set_block#set::spamfilter::except"); - } else { + } else + { test_match_block(conf, cepp, &errors); } continue; // needed, because we are above the CheckNull and the multiple if's below. @@ -9579,21 +9361,19 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) { long x; CheckDuplicate(cepp, spamfilter_ban_time, "spamfilter::ban-time"); - x = config_checkval(cepp->value,CFG_TIME); + x = config_checkval(cepp->value, CFG_TIME); if ((x < 0) > (x > 2000000000)) { config_error("%s:%i: set::spamfilter:ban-time: value '%ld' out of range", - cep->file->filename, cep->line_number, x); + cep->file->filename, cep->line_number, x); errors++; continue; } - } else - if (!strcmp(cepp->name, "ban-reason")) + } else if (!strcmp(cepp->name, "ban-reason")) { CheckDuplicate(cepp, spamfilter_ban_reason, "spamfilter::ban-reason"); - } - else if (!strcmp(cepp->name, "virus-help-channel")) + } else if (!strcmp(cepp->name, "virus-help-channel")) { CheckDuplicate(cepp, spamfilter_virus_help_channel, "spamfilter::virus-help-channel"); if ((cepp->value[0] != '#') || (strlen(cepp->value) > CHANNELLEN)) @@ -9605,27 +9385,23 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) errors++; continue; } - } else - if (!strcmp(cepp->name, "virus-help-channel-deny")) + } else if (!strcmp(cepp->name, "virus-help-channel-deny")) { CheckDuplicate(cepp, spamfilter_virus_help_channel_deny, "spamfilter::virus-help-channel-deny"); } else #ifdef SPAMFILTER_DETECTSLOW - if (!strcmp(cepp->name, "detect-slow-warn")) + if (!strcmp(cepp->name, "detect-slow-warn")) { - } else - if (!strcmp(cepp->name, "detect-slow-fatal")) + } else if (!strcmp(cepp->name, "detect-slow-fatal")) { } else #endif - if (!strcmp(cepp->name, "stop-on-first-match")) + if (!strcmp(cepp->name, "stop-on-first-match")) { - } else - if (!strcmp(cepp->name, "utf8")) + } else if (!strcmp(cepp->name, "utf8")) { tempiConf.spamfilter_utf8 = config_checkval(cepp->value, CFG_YESNO); - } else - if (!strcmp(cepp->name, "show-message-content-on-hit")) + } else if (!strcmp(cepp->name, "show-message-content-on-hit")) { if (!spamfilter_show_message_content_on_hit_strtoval(cepp->value)) { @@ -9637,47 +9413,40 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) } else { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::spamfilter", - cepp->name); + cepp->line_number, "set::spamfilter", + cepp->name); errors++; continue; } } - } - else if (!strcmp(cep->name, "central-spamfilter")) + } else if (!strcmp(cep->name, "central-spamfilter")) { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "except")) { test_match_block(conf, cepp, &errors); - } else - if (!cepp->value) + } else if (!cepp->value) { CheckNull(cepp); - } else - if (!strcmp(cepp->name, "url")) + } else if (!strcmp(cepp->name, "url")) { - } else - if (!strcmp(cepp->name, "refresh-time")) + } else if (!strcmp(cepp->name, "refresh-time")) { int v = config_checkval(cepp->value, CFG_TIME); #ifndef DEBUGMODE if (v < 180) { config_error("%s:%i: set::central-spamfilter::refresh-time needs to be more than 3 minutes", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; } #endif - } else - if (!strcmp(cepp->name, "verbose")) + } else if (!strcmp(cepp->name, "verbose")) { - } else - if (!strcmp(cepp->name, "enabled")) + } else if (!strcmp(cepp->name, "enabled")) { - } else - if (!strcmp(cepp->name, "feed")) + } else if (!strcmp(cepp->name, "feed")) { if (strcmp(cepp->value, "testing") && strcmp(cepp->value, "standard") && strcmp(cepp->value, "fast")) { @@ -9686,67 +9455,63 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) cepp->file->filename, cepp->line_number); errors++; } - } else - if (!strcmp(cepp->name, "limit-ban-action")) + } else if (!strcmp(cepp->name, "limit-ban-action")) { int n = banact_stringtoval(cepp->value); if (n == 0) { config_error("%s:%i: set::central-spamfilter::limit-ban-action: unknown ban action '%s'", - cepp->file->filename, cepp->line_number, cepp->value); + cepp->file->filename, cepp->line_number, cepp->value); errors++; - } else - if ((n == BAN_ACT_SET) || (n == BAN_ACT_REPORT)) + } else if ((n == BAN_ACT_SET) || (n == BAN_ACT_REPORT)) { config_error("%s:%i: set::central-spamfilter::limit-ban-action: you cannot use 'set' or 'report' here", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; } - } else - if (!strcmp(cepp->name, "limit-ban-time")) + } else if (!strcmp(cepp->name, "limit-ban-time")) { if (config_checkval(cepp->value, CFG_TIME) < 1) { config_error("%s:%i: set::central-spamfilter::limit-ban-time is zero or less (invalid)", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; } } else { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::central-spamfilter", - cepp->name); + cepp->line_number, "set::central-spamfilter", + cepp->name); errors++; continue; } } - } - else if (!strcmp(cep->name, "default-bantime")) + } else if (!strcmp(cep->name, "default-bantime")) { long x; CheckDuplicate(cep, default_bantime, "default-bantime"); CheckNull(cep); - x = config_checkval(cep->value,CFG_TIME); + x = config_checkval(cep->value, CFG_TIME); if ((x < 0) > (x > 2000000000)) { config_error("%s:%i: set::default-bantime: value '%ld' out of range", - cep->file->filename, cep->line_number, x); + cep->file->filename, cep->line_number, x); errors++; } - } - else if (!strcmp(cep->name, "ban-version-tkl-time")) { + } else if (!strcmp(cep->name, "ban-version-tkl-time")) + { long x; CheckDuplicate(cep, ban_version_tkl_time, "ban-version-tkl-time"); CheckNull(cep); - x = config_checkval(cep->value,CFG_TIME); + x = config_checkval(cep->value, CFG_TIME); if ((x < 0) > (x > 2000000000)) { config_error("%s:%i: set::ban-version-tkl-time: value '%ld' out of range", - cep->file->filename, cep->line_number, x); + cep->file->filename, cep->line_number, x); errors++; } - } - else if (!strcmp(cep->name, "min-nick-length")) { + } else if (!strcmp(cep->name, "min-nick-length")) + { int v; CheckDuplicate(cep, min_nick_length, "min-nick-length"); CheckNull(cep); @@ -9754,13 +9519,12 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if ((v <= 0) || (v > NICKLEN)) { config_error("%s:%i: set::min-nick-length: value '%d' out of range (should be 1-%d)", - cep->file->filename, cep->line_number, v, NICKLEN); + cep->file->filename, cep->line_number, v, NICKLEN); errors++; - } - else + } else nicklengths.min = v; - } - else if (!strcmp(cep->name, "nick-length")) { + } else if (!strcmp(cep->name, "nick-length")) + { int v; CheckDuplicate(cep, nick_length, "nick-length"); CheckNull(cep); @@ -9768,66 +9532,64 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if ((v <= 0) || (v > NICKLEN)) { config_error("%s:%i: set::nick-length: value '%d' out of range (should be 1-%d)", - cep->file->filename, cep->line_number, v, NICKLEN); + cep->file->filename, cep->line_number, v, NICKLEN); errors++; - } - else + } else nicklengths.max = v; - } - else if (!strcmp(cep->name, "topic-length")) { + } else if (!strcmp(cep->name, "topic-length")) + { int v; CheckNull(cep); v = atoi(cep->value); if ((v <= 0) || (v > MAXTOPICLEN)) { config_error("%s:%i: set::topic-length: value '%d' out of range (should be 1-%d)", - cep->file->filename, cep->line_number, v, MAXTOPICLEN); + cep->file->filename, cep->line_number, v, MAXTOPICLEN); errors++; } - } - else if (!strcmp(cep->name, "away-length")) { + } else if (!strcmp(cep->name, "away-length")) + { int v; CheckNull(cep); v = atoi(cep->value); if ((v <= 0) || (v > MAXAWAYLEN)) { config_error("%s:%i: set::away-length: value '%d' out of range (should be 1-%d)", - cep->file->filename, cep->line_number, v, MAXAWAYLEN); + cep->file->filename, cep->line_number, v, MAXAWAYLEN); errors++; } - } - else if (!strcmp(cep->name, "kick-length")) { + } else if (!strcmp(cep->name, "kick-length")) + { int v; CheckNull(cep); v = atoi(cep->value); if ((v <= 0) || (v > MAXKICKLEN)) { config_error("%s:%i: set::kick-length: value '%d' out of range (should be 1-%d)", - cep->file->filename, cep->line_number, v, MAXKICKLEN); + cep->file->filename, cep->line_number, v, MAXKICKLEN); errors++; } - } - else if (!strcmp(cep->name, "quit-length")) { + } else if (!strcmp(cep->name, "quit-length")) + { int v; CheckNull(cep); v = atoi(cep->value); if ((v <= 0) || (v > MAXQUITLEN)) { config_error("%s:%i: set::quit-length: value '%d' out of range (should be 1-%d)", - cep->file->filename, cep->line_number, v, MAXQUITLEN); + cep->file->filename, cep->line_number, v, MAXQUITLEN); errors++; } - } - else if (!strcmp(cep->name, "ssl") || !strcmp(cep->name, "tls")) { + } else if (!strcmp(cep->name, "ssl") || !strcmp(cep->name, "tls")) + { test_tlsblock(conf, cep, &errors); - } - else if (!strcmp(cep->name, "plaintext-policy")) + } else if (!strcmp(cep->name, "plaintext-policy")) { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "user") || - !strcmp(cepp->name, "oper") || - !strcmp(cepp->name, "server")) + !strcmp(cepp->name, "oper") || + !strcmp(cepp->name, "server")) { Policy policy; CheckNull(cepp); @@ -9835,29 +9597,29 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (!policy) { config_error("%s:%i: set::plaintext-policy::%s: needs to be one of: 'allow', 'warn' or 'reject'", - cepp->file->filename, cepp->line_number, cepp->name); + cepp->file->filename, cepp->line_number, cepp->name); errors++; } } else if (!strcmp(cepp->name, "user-message") || !strcmp(cepp->name, "oper-message")) { CheckNull(cepp); - } else { + } else + { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::plaintext-policy", - cepp->name); + cepp->line_number, "set::plaintext-policy", + cepp->name); errors++; continue; } } - } - else if (!strcmp(cep->name, "outdated-tls-policy")) + } else if (!strcmp(cep->name, "outdated-tls-policy")) { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "user") || - !strcmp(cepp->name, "oper") || - !strcmp(cepp->name, "server")) + !strcmp(cepp->name, "oper") || + !strcmp(cepp->name, "server")) { Policy policy; CheckNull(cepp); @@ -9865,23 +9627,23 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (!policy) { config_error("%s:%i: set::outdated-tls-policy::%s: needs to be one of: 'allow', 'warn' or 'reject'", - cepp->file->filename, cepp->line_number, cepp->name); + cepp->file->filename, cepp->line_number, cepp->name); errors++; } } else if (!strcmp(cepp->name, "user-message") || !strcmp(cepp->name, "oper-message")) { CheckNull(cepp); - } else { + } else + { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::outdated-tls-policy", - cepp->name); + cepp->line_number, "set::outdated-tls-policy", + cepp->name); errors++; continue; } } - } - else if (!strcmp(cep->name, "default-ipv6-clone-mask")) + } else if (!strcmp(cep->name, "default-ipv6-clone-mask")) { /* keep this in sync with _test_allow() */ int ipv6mask; @@ -9890,23 +9652,23 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (ipv6mask == 0) { config_error("%s:%d: set::default-ipv6-clone-mask given a value of zero. This cannnot be correct, as it would treat all IPv6 hosts as one host.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } if (ipv6mask > 128) { config_error("%s:%d: set::default-ipv6-clone-mask was set to %d. The maximum value is 128.", - cep->file->filename, cep->line_number, - ipv6mask); + cep->file->filename, cep->line_number, + ipv6mask); errors++; } if (ipv6mask <= 32) { config_warn("%s:%d: set::default-ipv6-clone-mask was given a very small value.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); } - } - else if (!strcmp(cep->name, "hide-list")) { + } else if (!strcmp(cep->name, "hide-list")) + { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "deny-channel")) @@ -9914,47 +9676,46 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) } else { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::hide-list", - cepp->name); + cepp->line_number, "set::hide-list", + cepp->name); errors++; continue; } } - } - else if (!strcmp(cep->name, "max-unknown-connections-per-ip")) { + } else if (!strcmp(cep->name, "max-unknown-connections-per-ip")) + { int v; CheckNull(cep); v = atoi(cep->value); if (v < 1) { config_error("%s:%i: set::max-unknown-connections-per-ip: value should be at least 1.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "handshake-timeout")) { + } else if (!strcmp(cep->name, "handshake-timeout")) + { int v; CheckNull(cep); v = config_checkval(cep->value, CFG_TIME); if (v < 5) { config_error("%s:%i: set::handshake-timeout: value should be at least 5 seconds.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "sasl-timeout")) { + } else if (!strcmp(cep->name, "sasl-timeout")) + { int v; CheckNull(cep); v = config_checkval(cep->value, CFG_TIME); if (v < 5) { config_error("%s:%i: set::sasl-timeout: value should be at least 5 seconds.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "handshake-delay")) + } else if (!strcmp(cep->name, "handshake-delay")) { int v; CheckNull(cep); @@ -9962,11 +9723,10 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (v >= 10) { config_error("%s:%i: set::handshake-delay: value should be less than 10 seconds.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "handshake-boot-delay")) + } else if (!strcmp(cep->name, "handshake-boot-delay")) { int v; CheckNull(cep); @@ -9974,11 +9734,10 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (v > 15) { config_error("%s:%i: set::handshake-boot-delay: value cannot be more than 15 seconds.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "ban-include-username")) + } else if (!strcmp(cep->name, "ban-include-username")) { config_error("%s:%i: set::ban-include-username is no longer supported. " "Use set { automatic-ban-target userip; }; instead.", @@ -9986,8 +9745,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) config_error("See https://www.unrealircd.org/docs/Set_block#set::automatic-ban-target " "for more information and options."); errors++; - } - else if (!strcmp(cep->name, "automatic-ban-target")) + } else if (!strcmp(cep->name, "automatic-ban-target")) { CheckNull(cep); if (!ban_target_strtoval(cep->value)) @@ -9997,8 +9755,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number, cep->value); errors++; } - } - else if (!strcmp(cep->name, "manual-ban-target")) + } else if (!strcmp(cep->name, "manual-ban-target")) { CheckNull(cep); if (!ban_target_strtoval(cep->value)) @@ -10008,8 +9765,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number, cep->value); errors++; } - } - else if (!strcmp(cep->name, "reject-message")) + } else if (!strcmp(cep->name, "reject-message")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -10033,42 +9789,37 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) else { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::reject-message", - cepp->name); + cepp->line_number, "set::reject-message", + cepp->name); errors++; continue; } } - } - else if (!strcmp(cep->name, "topic-setter")) + } else if (!strcmp(cep->name, "topic-setter")) { CheckNull(cep); if (strcmp(cep->value, "nick") && strcmp(cep->value, "nick-user-host")) { config_error("%s:%i: set::topic-setter: value should be 'nick' or 'nick-user-host'", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "ban-setter")) + } else if (!strcmp(cep->name, "ban-setter")) { CheckNull(cep); if (strcmp(cep->value, "nick") && strcmp(cep->value, "nick-user-host")) { config_error("%s:%i: set::ban-setter: value should be 'nick' or 'nick-user-host'", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "ban-setter-sync") || !strcmp(cep->name, "ban-setter-synch")) + } else if (!strcmp(cep->name, "ban-setter-sync") || !strcmp(cep->name, "ban-setter-synch")) { CheckNull(cep); - } - else if (!strcmp(cep->name, "part-instead-of-quit-on-comment-change")) + } else if (!strcmp(cep->name, "part-instead-of-quit-on-comment-change")) { CheckNull(cep); - } - else if (!strcmp(cep->name, "broadcast-channel-messages")) + } else if (!strcmp(cep->name, "broadcast-channel-messages")) { CheckNull(cep); if (strcmp(cep->value, "auto") && @@ -10079,8 +9830,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "allowed-channelchars")) + } else if (!strcmp(cep->name, "allowed-channelchars")) { CheckNull(cep); if (!allowed_channelchars_strtoval(cep->value)) @@ -10089,8 +9839,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "hide-idle-time")) + } else if (!strcmp(cep->name, "hide-idle-time")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -10100,15 +9849,14 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (!hideidletime_strtoval(cepp->value)) { config_error("%s:%i: set::hide-idle-time::policy: value should be one of: 'never', 'always', 'usermode' or 'oper-usermode'", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; } - } - else + } else { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::hide-idle-time", - cepp->name); + cepp->line_number, "set::hide-idle-time", + cepp->name); errors++; continue; } @@ -10136,23 +9884,20 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(cepp->name, "hashed-passwords")) { bestpractices.hashed_passwords = config_checkval(cepp->value, CFG_YESNO); - } else - if (!strcmp(cepp->name, "trusted-cert")) + } else if (!strcmp(cepp->name, "trusted-cert")) { bestpractices.trusted_cert = config_checkval(cepp->value, CFG_YESNO); - } else - if (!strcmp(cepp->name, "trusted-cert-valid-hostname")) + } else if (!strcmp(cepp->name, "trusted-cert-valid-hostname")) { bestpractices.trusted_cert_valid_hostname = config_checkval(cepp->value, CFG_YESNO); - } else - if (!strcmp(cepp->name, "listen-nontls-port") || !strcmp(cepp->name, "listen-tls-only")) + } else if (!strcmp(cepp->name, "listen-nontls-port") || !strcmp(cepp->name, "listen-tls-only")) { bestpractices.listen_tls_only = config_checkval(cepp->value, CFG_YESNO); } else { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::best-practices", - cepp->name); + cepp->line_number, "set::best-practices", + cepp->name); errors++; continue; } @@ -10175,8 +9920,7 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) ceppp->file->filename, ceppp->line_number); errors++; } - } else - if (!strcmp(ceppp->name, "retry")) + } else if (!strcmp(ceppp->name, "retry")) { int v = atoi(ceppp->value); if ((v < 0) || (v > 5)) @@ -10188,8 +9932,8 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) } else { config_error_unknown(ceppp->file->filename, - ceppp->line_number, "set::dns::..::", - ceppp->name); + ceppp->line_number, "set::dns::..::", + ceppp->name); errors++; continue; } @@ -10197,8 +9941,8 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) } else { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::dns", - cepp->name); + cepp->line_number, "set::dns", + cepp->name); errors++; continue; } @@ -10217,9 +9961,9 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) { int value, errs = 0; if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && - !(h->owner->options & MOD_OPT_PERM)) + !(h->owner->options & MOD_OPT_PERM)) continue; - value = (*(h->func.intfunc))(conf,cep,CONFIG_SET, &errs); + value = (*(h->func.intfunc))(conf, cep, CONFIG_SET, &errs); if (value == 2) used = 1; if (value == 1) @@ -10239,10 +9983,11 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) errors += errs; } } - if (!used) { + if (!used) + { config_error("%s:%i: unknown directive set::%s", - cep->file->filename, cep->line_number, - cep->name); + cep->file->filename, cep->line_number, + cep->name); errors++; } } @@ -10250,13 +9995,13 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) return errors; } -int _conf_loadmodule(ConfigFile *conf, ConfigEntry *ce) +int _conf_loadmodule(ConfigFile *conf, ConfigEntry *ce) { const char *ret; if (!ce->value) { config_status("%s:%i: loadmodule without filename", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return -1; } @@ -10267,21 +10012,22 @@ int _conf_loadmodule(ConfigFile *conf, ConfigEntry *ce) return 1; } - if ((ret = Module_Create(ce->value))) { + if ((ret = Module_Create(ce->value))) + { config_error("%s:%i: loadmodule %s: failed to load: %s", - ce->file->filename, ce->line_number, - ce->value, ret); + ce->file->filename, ce->line_number, + ce->value, ret); return -1; } return 1; } -int _test_loadmodule(ConfigFile *conf, ConfigEntry *ce) +int _test_loadmodule(ConfigFile *conf, ConfigEntry *ce) { return 0; } -int _test_blacklist_module(ConfigFile *conf, ConfigEntry *ce) +int _test_blacklist_module(ConfigFile *conf, ConfigEntry *ce) { const char *path; ConfigItem_blacklist_module *m; @@ -10289,7 +10035,7 @@ int _test_blacklist_module(ConfigFile *conf, ConfigEntry *ce) if (!ce->value) { config_status("%s:%i: blacklist-module: no module name given to blacklist", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return -1; } @@ -10335,39 +10081,42 @@ void start_listeners(void) /* Error already printed upstream */ failed = 1; last_errno = ERRNO; - } else { + } else + { if (loop.booted) { if (listener->socket_type == SOCKET_TYPE_UNIX) { unreal_log(ULOG_INFO, "listen", "LISTEN_ADDED", NULL, - "UnrealIRCd is now also listening on $listen_file [$protocol]", - log_data_string("listen_file", listener->file), - log_data_string("protocol", socket_type_valtostr(listener->socket_type))); - } else { + "UnrealIRCd is now also listening on $listen_file [$protocol]", + log_data_string("listen_file", listener->file), + log_data_string("protocol", socket_type_valtostr(listener->socket_type))); + } else + { unreal_log(ULOG_INFO, "listen", "LISTEN_ADDED", NULL, - "UnrealIRCd is now also listening on $listen_ip:$listen_port [$protocol]", - log_data_string("listen_ip", listener->ip), - log_data_integer("listen_port", listener->port), - log_data_string("protocol", socket_type_valtostr(listener->socket_type))); + "UnrealIRCd is now also listening on $listen_ip:$listen_port [$protocol]", + log_data_string("listen_ip", listener->ip), + log_data_integer("listen_port", listener->port), + log_data_string("protocol", socket_type_valtostr(listener->socket_type))); } - } else { + } else + { switch (listener->socket_type) { case SOCKET_TYPE_IPV4: - snprintf(boundmsg_ipv4+strlen(boundmsg_ipv4), sizeof(boundmsg_ipv4)-strlen(boundmsg_ipv4), - "%s:%d%s, ", listener->ip, listener->port, - listener->options & LISTENER_TLS ? "(TLS)" : ""); + snprintf(boundmsg_ipv4 + strlen(boundmsg_ipv4), sizeof(boundmsg_ipv4) - strlen(boundmsg_ipv4), + "%s:%d%s, ", listener->ip, listener->port, + listener->options & LISTENER_TLS ? "(TLS)" : ""); break; case SOCKET_TYPE_IPV6: - snprintf(boundmsg_ipv6+strlen(boundmsg_ipv6), sizeof(boundmsg_ipv6)-strlen(boundmsg_ipv6), - "%s:%d%s, ", listener->ip, listener->port, - listener->options & LISTENER_TLS ? "(TLS)" : ""); + snprintf(boundmsg_ipv6 + strlen(boundmsg_ipv6), sizeof(boundmsg_ipv6) - strlen(boundmsg_ipv6), + "%s:%d%s, ", listener->ip, listener->port, + listener->options & LISTENER_TLS ? "(TLS)" : ""); break; case SOCKET_TYPE_UNIX: - snprintf(boundmsg_unix+strlen(boundmsg_unix), sizeof(boundmsg_unix)-strlen(boundmsg_unix), - "%s%s, ", listener->file, - listener->options & LISTENER_TLS ? "(TLS)" : ""); + snprintf(boundmsg_unix + strlen(boundmsg_unix), sizeof(boundmsg_unix) - strlen(boundmsg_unix), + "%s%s, ", listener->file, + listener->options & LISTENER_TLS ? "(TLS)" : ""); break; default: break; @@ -10393,14 +10142,15 @@ void start_listeners(void) { /* We can be specific */ unreal_log(ULOG_FATAL, "listen", "ALL_LISTEN_PORTS_FAILED", NULL, - "Unable to listen on any ports. " - "Most likely UnrealIRCd is already running."); - } else { + "Unable to listen on any ports. " + "Most likely UnrealIRCd is already running."); + } else + { unreal_log(ULOG_FATAL, "listen", "ALL_LISTEN_PORTS_FAILED", NULL, - "Unable to listen on any ports. " - "Please verify that no other process is using the ports. " - "Also, on some IRCd shells you may have to use listen::bind-ip " - "with a specific IP assigned to you (rather than \"*\")."); + "Unable to listen on any ports. " + "Please verify that no other process is using the ports. " + "Also, on some IRCd shells you may have to use listen::bind-ip " + "with a specific IP assigned to you (rather than \"*\")."); } exit(-1); } @@ -10408,21 +10158,21 @@ void start_listeners(void) if (failed && !loop.booted) { unreal_log(ULOG_FATAL, "listen", "SOME_LISTEN_PORTS_FAILED", NULL, - "Unable to listen on all ports (some of them succeeded, some of them failed). " - "Please verify that no other process is using the port(s). " - "Also, on some IRCd shells you may have to use listen::bind-ip " - "with a specific IP assigned to you (rather than \"*\")."); + "Unable to listen on all ports (some of them succeeded, some of them failed). " + "Please verify that no other process is using the port(s). " + "Also, on some IRCd shells you may have to use listen::bind-ip " + "with a specific IP assigned to you (rather than \"*\")."); exit(-1); } if (!loop.booted) { if (strlen(boundmsg_ipv4) > 2) - boundmsg_ipv4[strlen(boundmsg_ipv4)-2] = '\0'; + boundmsg_ipv4[strlen(boundmsg_ipv4) - 2] = '\0'; if (strlen(boundmsg_ipv6) > 2) - boundmsg_ipv6[strlen(boundmsg_ipv6)-2] = '\0'; + boundmsg_ipv6[strlen(boundmsg_ipv6) - 2] = '\0'; if (strlen(boundmsg_unix) > 2) - boundmsg_unix[strlen(boundmsg_unix)-2] = '\0'; + boundmsg_unix[strlen(boundmsg_unix) - 2] = '\0'; if (!*boundmsg_ipv4) strlcpy(boundmsg_ipv4, "", sizeof(boundmsg_ipv4)); @@ -10460,14 +10210,14 @@ void config_run(void) tainted = 99; } -int _conf_offchans(ConfigFile *conf, ConfigEntry *ce) +int _conf_offchans(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cepp; for (cep = ce->items; cep; cep = cep->next) { ConfigItem_offchans *of = safe_alloc(sizeof(ConfigItem_offchans)); - strlcpy(of->name, cep->name, CHANNELLEN+1); + strlcpy(of->name, cep->name, CHANNELLEN + 1); for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "topic")) @@ -10478,7 +10228,7 @@ int _conf_offchans(ConfigFile *conf, ConfigEntry *ce) return 0; } -int _test_offchans(ConfigFile *conf, ConfigEntry *ce) +int _test_offchans(ConfigFile *conf, ConfigEntry *ce) { int errors = 0; ConfigEntry *cep, *cep2; @@ -10486,7 +10236,7 @@ int _test_offchans(ConfigFile *conf, ConfigEntry *ce) if (!ce->items) { config_error("%s:%i: empty official-channels block", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; } @@ -10500,14 +10250,14 @@ int _test_offchans(ConfigFile *conf, ConfigEntry *ce) if (strlen(cep->name) > CHANNELLEN) { config_error("%s:%i: official-channels: '%s' name too long (max %d characters).", - cep->file->filename, cep->line_number, cep->name, CHANNELLEN); + cep->file->filename, cep->line_number, cep->name, CHANNELLEN); errors++; continue; } if (!valid_channelname(cep->name)) { config_error("%s:%i: official-channels: '%s' is not a valid channel name.", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } @@ -10516,8 +10266,8 @@ int _test_offchans(ConfigFile *conf, ConfigEntry *ce) if (!cep2->value) { config_error_empty(cep2->file->filename, - cep2->line_number, "official-channels", - cep2->name); + cep2->line_number, "official-channels", + cep2->name); errors++; continue; } @@ -10526,14 +10276,15 @@ int _test_offchans(ConfigFile *conf, ConfigEntry *ce) if (strlen(cep2->value) > MAXTOPICLEN) { config_error("%s:%i: official-channels::%s: topic too long (max %d characters).", - cep2->file->filename, cep2->line_number, cep->name, MAXTOPICLEN); + cep2->file->filename, cep2->line_number, cep->name, MAXTOPICLEN); errors++; continue; } - } else { + } else + { config_error_unknown(cep2->file->filename, - cep2->line_number, "official-channels", - cep2->name); + cep2->line_number, "official-channels", + cep2->name); errors++; continue; } @@ -10562,11 +10313,11 @@ static int alias_type_strtoval(const char *s) return 0; } -int _conf_alias(ConfigFile *conf, ConfigEntry *ce) +int _conf_alias(ConfigFile *conf, ConfigEntry *ce) { ConfigItem_alias *alias = NULL; ConfigItem_alias_format *format; - ConfigEntry *cep, *cepp; + ConfigEntry *cep, *cepp; RealCommand *cmptr; if ((cmptr = find_command(ce->value, CMD_ALIAS))) @@ -10574,8 +10325,8 @@ int _conf_alias(ConfigFile *conf, ConfigEntry *ce) if (find_command_simple(ce->value)) { config_warn("%s:%i: Alias '%s' would conflict with command (or server token) '%s', alias not added.", - ce->file->filename, ce->line_number, - ce->value, ce->value); + ce->file->filename, ce->line_number, + ce->value, ce->value); return 0; } if ((alias = find_alias(ce->value))) @@ -10584,22 +10335,25 @@ int _conf_alias(ConfigFile *conf, ConfigEntry *ce) safe_strdup(alias->alias, ce->value); for (cep = ce->items; cep; cep = cep->next) { - if (!strcmp(cep->name, "format")) { + if (!strcmp(cep->name, "format")) + { format = safe_alloc(sizeof(ConfigItem_alias_format)); safe_strdup(format->format, cep->value); format->expr = unreal_create_match(MATCH_PCRE_REGEX, cep->value, NULL); if (!format->expr) abort(); /* Impossible due to _test_alias earlier */ - for (cepp = cep->items; cepp; cepp = cepp->next) { + for (cepp = cep->items; cepp; cepp = cepp->next) + { if (!strcmp(cepp->name, "nick") || !strcmp(cepp->name, "target") || - !strcmp(cepp->name, "command")) { + !strcmp(cepp->name, "command")) + { safe_strdup(format->nick, cepp->value); - } - else if (!strcmp(cepp->name, "parameters")) { + } else if (!strcmp(cepp->name, "parameters")) + { safe_strdup(format->parameters, cepp->value); - } - else if (!strcmp(cepp->name, "type")) { + } else if (!strcmp(cepp->name, "type")) + { format->type = alias_type_strtoval(cepp->value); } } @@ -10609,24 +10363,25 @@ int _conf_alias(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cep->name, "nick") || !strcmp(cep->name, "target")) { safe_strdup(alias->nick, cep->value); - } - else if (!strcmp(cep->name, "type")) { + } else if (!strcmp(cep->name, "type")) + { alias->type = alias_type_strtoval(cep->value); - } - else if (!strcmp(cep->name, "spamfilter")) + } else if (!strcmp(cep->name, "spamfilter")) alias->spamfilter = config_checkval(cep->value, CFG_YESNO); } - if (BadPtr(alias->nick) && alias->type != ALIAS_COMMAND) { + if (BadPtr(alias->nick) && alias->type != ALIAS_COMMAND) + { safe_strdup(alias->nick, alias->alias); } - AliasAdd(NULL, alias->alias, cmd_alias, 1, CMD_USER|CMD_ALIAS); + AliasAdd(NULL, alias->alias, cmd_alias, 1, CMD_USER | CMD_ALIAS); AddListItem(alias, conf_alias); return 0; } -int _test_alias(ConfigFile *conf, ConfigEntry *ce) { +int _test_alias(ConfigFile *conf, ConfigEntry *ce) +{ int errors = 0; ConfigEntry *cep, *cepp; char has_type = 0, has_target = 0, has_format = 0, has_spamfilter = 0; @@ -10635,18 +10390,18 @@ int _test_alias(ConfigFile *conf, ConfigEntry *ce) { if (!ce->items) { config_error("%s:%i: empty alias block", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; } if (!ce->value) { config_error("%s:%i: alias without name", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; - } - else if (!find_command(ce->value, CMD_ALIAS) && find_command(ce->value, 0)) { + } else if (!find_command(ce->value, CMD_ALIAS) && find_command(ce->value, 0)) + { config_status("%s:%i: %s is an existing command, can not add alias", - ce->file->filename, ce->line_number, ce->value); + ce->file->filename, ce->line_number, ce->value); errors++; } for (cep = ce->items; cep; cep = cep->next) @@ -10656,7 +10411,8 @@ int _test_alias(ConfigFile *conf, ConfigEntry *ce) { errors++; continue; } - if (!strcmp(cep->name, "format")) { + if (!strcmp(cep->name, "format")) + { const char *err = NULL; Match *expr; char has_type = 0, has_target = 0, has_parameters = 0; @@ -10666,12 +10422,14 @@ int _test_alias(ConfigFile *conf, ConfigEntry *ce) { if (!expr) { config_error("%s:%i: alias::format contains an invalid regex: %s", - cep->file->filename, cep->line_number, err); - } else { + cep->file->filename, cep->line_number, err); + } else + { unreal_delete_match(expr); } - for (cepp = cep->items; cepp; cepp = cepp->next) { + for (cepp = cep->items; cepp; cepp = cepp->next) + { if (config_is_blankorempty(cepp, "alias::format")) { errors++; @@ -10684,82 +10442,78 @@ int _test_alias(ConfigFile *conf, ConfigEntry *ce) { if (has_target) { config_warn_duplicate(cepp->file->filename, - cepp->line_number, - "alias::format::target"); + cepp->line_number, + "alias::format::target"); continue; } has_target = 1; - } - else if (!strcmp(cepp->name, "type")) + } else if (!strcmp(cepp->name, "type")) { if (has_type) { config_warn_duplicate(cepp->file->filename, - cepp->line_number, - "alias::format::type"); + cepp->line_number, + "alias::format::type"); continue; } has_type = 1; if (!alias_type_strtoval(cepp->value)) { config_error("%s:%i: unknown alias type", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; } - } - else if (!strcmp(cepp->name, "parameters")) + } else if (!strcmp(cepp->name, "parameters")) { if (has_parameters) { config_warn_duplicate(cepp->file->filename, - cepp->line_number, - "alias::format::parameters"); + cepp->line_number, + "alias::format::parameters"); continue; } has_parameters = 1; - } - else + } else { config_error_unknown(cepp->file->filename, - cepp->line_number, "alias::format", - cepp->name); + cepp->line_number, "alias::format", + cepp->name); errors++; } } if (!has_target) { config_error_missing(cep->file->filename, - cep->line_number, "alias::format::target"); + cep->line_number, "alias::format::target"); errors++; } if (!has_type) { config_error_missing(cep->file->filename, - cep->line_number, "alias::format::type"); + cep->line_number, "alias::format::type"); errors++; } if (!has_parameters) { config_error_missing(cep->file->filename, - cep->line_number, "alias::format::parameters"); + cep->line_number, "alias::format::parameters"); errors++; } - } - else if (!strcmp(cep->name, "nick") || !strcmp(cep->name, "target")) + } else if (!strcmp(cep->name, "nick") || !strcmp(cep->name, "target")) { if (has_target) { config_warn_duplicate(cep->file->filename, - cep->line_number, "alias::target"); + cep->line_number, "alias::target"); continue; } has_target = 1; - } - else if (!strcmp(cep->name, "type")) { + } else if (!strcmp(cep->name, "type")) + { if (has_type) { config_warn_duplicate(cep->file->filename, - cep->line_number, "alias::type"); + cep->line_number, "alias::type"); continue; } has_type = 1; @@ -10767,48 +10521,47 @@ int _test_alias(ConfigFile *conf, ConfigEntry *ce) { if (!type) { config_error("%s:%i: unknown alias type", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "spamfilter")) + } else if (!strcmp(cep->name, "spamfilter")) has_spamfilter = 1; - else { + else + { config_error_unknown(cep->file->filename, cep->line_number, - "alias", cep->name); + "alias", cep->name); errors++; } } if (!has_type) { config_error_missing(ce->file->filename, ce->line_number, - "alias::type"); + "alias::type"); errors++; } if (!has_format && (type == ALIAS_COMMAND)) { config_error("%s:%d: alias::type is 'command' but no alias::format was specified", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; - } - else if (has_format && (type != ALIAS_COMMAND)) + } else if (has_format && (type != ALIAS_COMMAND)) { config_error("%s:%d: alias::format specified when type is not 'command'", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } if (has_spamfilter && (type == ALIAS_CHANNEL)) { config_warn("%s:%d: alias::spamfilter has no effect for channel aliases, " - "spamfilter is always checked for channel messages", - ce->file->filename, ce->line_number); + "spamfilter is always checked for channel messages", + ce->file->filename, ce->line_number); } return errors; } -int _conf_deny(ConfigFile *conf, ConfigEntry *ce) +int _conf_deny(ConfigFile *conf, ConfigEntry *ce) { -Hook *h; + Hook *h; if (!strcmp(ce->value, "channel")) _conf_deny_channel(conf, ce); @@ -10819,7 +10572,7 @@ Hook *h; int value; for (h = Hooks[HOOKTYPE_CONFIGRUN]; h; h = h->next) { - value = (*(h->func.intfunc))(conf,ce,CONFIG_DENY); + value = (*(h->func.intfunc))(conf, ce, CONFIG_DENY); if (value == 1) break; } @@ -10828,10 +10581,10 @@ Hook *h; return 0; } -int _conf_deny_channel(ConfigFile *conf, ConfigEntry *ce) +int _conf_deny_channel(ConfigFile *conf, ConfigEntry *ce) { - ConfigItem_deny_channel *deny = NULL; - ConfigEntry *cep; + ConfigItem_deny_channel *deny = NULL; + ConfigEntry *cep; deny = safe_alloc(sizeof(ConfigItem_deny_channel)); for (cep = ce->items; cep; cep = cep->next) @@ -10839,24 +10592,19 @@ int _conf_deny_channel(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(cep->name, "channel")) { safe_strdup(deny->channel, cep->value); - } - else if (!strcmp(cep->name, "redirect")) + } else if (!strcmp(cep->name, "redirect")) { safe_strdup(deny->redirect, cep->value); - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { safe_strdup(deny->reason, cep->value); - } - else if (!strcmp(cep->name, "warn")) + } else if (!strcmp(cep->name, "warn")) { - deny->warn = config_checkval(cep->value,CFG_YESNO); - } - else if (!strcmp(cep->name, "class")) + deny->warn = config_checkval(cep->value, CFG_YESNO); + } else if (!strcmp(cep->name, "class")) { safe_strdup(deny->class, cep->value); - } - else if (!strcmp(cep->name, "match") || !strcmp(cep->name, "mask")) + } else if (!strcmp(cep->name, "match") || !strcmp(cep->name, "mask")) { conf_match_block(conf, cep, &deny->match); } @@ -10864,10 +10612,10 @@ int _conf_deny_channel(ConfigFile *conf, ConfigEntry *ce) AddListItem(deny, conf_deny_channel); return 0; } -int _conf_deny_version(ConfigFile *conf, ConfigEntry *ce) +int _conf_deny_version(ConfigFile *conf, ConfigEntry *ce) { ConfigItem_deny_version *deny = NULL; - ConfigEntry *cep; + ConfigEntry *cep; deny = safe_alloc(sizeof(ConfigItem_deny_version)); for (cep = ce->items; cep; cep = cep->next) @@ -10875,12 +10623,10 @@ int _conf_deny_version(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(cep->name, "mask")) { safe_strdup(deny->mask, cep->value); - } - else if (!strcmp(cep->name, "version")) + } else if (!strcmp(cep->name, "version")) { safe_strdup(deny->version, cep->value); - } - else if (!strcmp(cep->name, "flags")) + } else if (!strcmp(cep->name, "flags")) { safe_strdup(deny->flags, cep->value); } @@ -10889,16 +10635,16 @@ int _conf_deny_version(ConfigFile *conf, ConfigEntry *ce) return 0; } -int _test_deny(ConfigFile *conf, ConfigEntry *ce) +int _test_deny(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; - int errors = 0; - Hook *h; + int errors = 0; + Hook *h; if (!ce->value) { config_error("%s:%i: deny without type", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); return 1; } if (!strcmp(ce->value, "channel")) @@ -10911,95 +10657,86 @@ int _test_deny(ConfigFile *conf, ConfigEntry *ce) { has_match = 1; test_match_block(conf, cep, &errors); - } - else if (!strcmp(cep->name, "mask")) + } else if (!strcmp(cep->name, "mask")) { has_mask = 1; test_match_block(conf, cep, &errors); - } - else if (config_is_blankorempty(cep, "deny channel")) + } else if (config_is_blankorempty(cep, "deny channel")) { errors++; continue; - } - else if (!strcmp(cep->name, "channel")) + } else if (!strcmp(cep->name, "channel")) { if (has_channel) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny channel::channel"); + cep->line_number, "deny channel::channel"); continue; } has_channel = 1; - } - else if (!strcmp(cep->name, "redirect")) + } else if (!strcmp(cep->name, "redirect")) { if (has_redirect) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny channel::redirect"); + cep->line_number, "deny channel::redirect"); continue; } has_redirect = 1; - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { if (has_reason) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny channel::reason"); + cep->line_number, "deny channel::reason"); continue; } has_reason = 1; - } - else if (!strcmp(cep->name, "warn")) + } else if (!strcmp(cep->name, "warn")) { if (has_warn) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny channel::warn"); + cep->line_number, "deny channel::warn"); continue; } has_warn = 1; - } - else if (!strcmp(cep->name, "class")) + } else if (!strcmp(cep->name, "class")) { if (has_class) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny channel::class"); + cep->line_number, "deny channel::class"); continue; } has_class = 1; - } - else + } else { config_error_unknown(cep->file->filename, - cep->line_number, "deny channel", cep->name); + cep->line_number, "deny channel", cep->name); errors++; } } if (!has_channel) { config_error_missing(ce->file->filename, ce->line_number, - "deny channel::channel"); + "deny channel::channel"); errors++; } if (!has_reason) { config_error_missing(ce->file->filename, ce->line_number, - "deny channel::reason"); + "deny channel::reason"); errors++; } if (has_mask && has_match) { config_error("%s:%d: You cannot have both ::mask and ::match. " - "You should only use %s %s::match.", - ce->file->filename, ce->line_number, ce->name, ce->value); + "You should only use %s %s::match.", + ce->file->filename, ce->line_number, ce->name, ce->value); errors++; } - } - else if (!strcmp(ce->value, "version")) + } else if (!strcmp(ce->value, "version")) { char has_mask = 0, has_version = 0, has_flags = 0; for (cep = ce->items; cep; cep = cep->next) @@ -11014,67 +10751,62 @@ int _test_deny(ConfigFile *conf, ConfigEntry *ce) if (has_mask) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny version::mask"); + cep->line_number, "deny version::mask"); continue; } has_mask = 1; - } - else if (!strcmp(cep->name, "version")) + } else if (!strcmp(cep->name, "version")) { if (has_version) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny version::version"); + cep->line_number, "deny version::version"); continue; } has_version = 1; - } - else if (!strcmp(cep->name, "flags")) + } else if (!strcmp(cep->name, "flags")) { if (has_flags) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny version::flags"); + cep->line_number, "deny version::flags"); continue; } has_flags = 1; - } - else + } else { config_error_unknown(cep->file->filename, - cep->line_number, "deny version", cep->name); + cep->line_number, "deny version", cep->name); errors++; } } if (!has_mask) { config_error_missing(ce->file->filename, ce->line_number, - "deny version::mask"); + "deny version::mask"); errors++; } if (!has_version) { config_error_missing(ce->file->filename, ce->line_number, - "deny version::version"); + "deny version::version"); errors++; } if (!has_flags) { config_error_missing(ce->file->filename, ce->line_number, - "deny version::flags"); + "deny version::flags"); errors++; } - } - else + } else { int used = 0; for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) continue; - value = (*(h->func.intfunc))(conf,ce,CONFIG_DENY, &errs); + value = (*(h->func.intfunc))(conf, ce, CONFIG_DENY, &errs); if (value == 2) used = 1; if (value == 1) @@ -11094,10 +10826,11 @@ int _test_deny(ConfigFile *conf, ConfigEntry *ce) errors += errs; } } - if (!used) { + if (!used) + { config_error("%s:%i: unknown deny type %s", - ce->file->filename, ce->line_number, - ce->value); + ce->file->filename, ce->line_number, + ce->value); return 1; } return errors; @@ -11145,7 +10878,7 @@ char *_conf_secret_read_password_file(const char *fname) #ifndef _WIN32 fd = open(fname, O_RDONLY); #else - fd = open(fname, _O_RDONLY|_O_BINARY); + fd = open(fname, _O_RDONLY | _O_BINARY); #endif if (fd < 0) { @@ -11209,10 +10942,11 @@ int _test_secret(ConfigFile *conf, ConfigEntry *ce) if (!ce->value) { config_error("%s:%i: secret block needs a name, eg: secret xyz {", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; return errors; /* need to return here since we dereference ce->value later.. */ - } else { + } else + { if (!security_group_valid_name(ce->value)) { config_error("%s:%i: secret block name '%s' contains invalid characters or is too long. " @@ -11253,8 +10987,7 @@ int _test_secret(ConfigFile *conf, ConfigEntry *ce) cep->file->filename, cep->line_number, err); errors++; } - } else - if (!strcmp(cep->name, "password-file")) + } else if (!strcmp(cep->name, "password-file")) { char *str; has_password_file = 1; @@ -11273,17 +11006,16 @@ int _test_secret(ConfigFile *conf, ConfigEntry *ce) if (!str) { config_error("%s:%d: secret::password-file: error reading password from file, see error from above.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } safe_free_sensitive(str); } - } else - if (!strcmp(cep->name, "password-prompt")) + } else if (!strcmp(cep->name, "password-prompt")) { #ifdef _WIN32 config_error("%s:%d: secret::password-prompt is not implemented in Windows at the moment, sorry!", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); config_error("Choose a different method to enter passwords or use *NIX"); errors++; return errors; @@ -11301,27 +11033,26 @@ int _test_secret(ConfigFile *conf, ConfigEntry *ce) { config_error("ERROR: IRCd is not running interactively, but via a cron job or something similar."); config_error("%s:%d: unable to prompt for password since IRCd is not started in a terminal", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); config_error("Either use a different method to enter passwords or start the IRCd in a terminal/SSH/.."); } - } else - if (!strcmp(cep->name, "password-url")) + } else if (!strcmp(cep->name, "password-url")) { config_error("%s:%d: secret::password-url is not supported yet in this UnrealIRCd version.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } else { config_error_unknown(cep->file->filename, cep->line_number, - "secret", cep->name); + "secret", cep->name); errors++; continue; } if (cep->items) { config_error("%s:%d: secret::%s does not support sub-options (%s)", - cep->file->filename, cep->line_number, - cep->name, cep->items->name); + cep->file->filename, cep->line_number, + cep->name, cep->items->name); errors++; } } @@ -11329,7 +11060,7 @@ int _test_secret(ConfigFile *conf, ConfigEntry *ce) if (!has_password && !has_password_file && !has_password_prompt) { config_error("%s:%d: secret { } block must contain 1 of: password OR password-file OR password-prompt", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } @@ -11356,8 +11087,7 @@ int _conf_secret(ConfigFile *conf, ConfigEntry *ce) { safe_strdup_sensitive(s->password, cep->value); destroy_string(cep->value); /* destroy the original */ - } else - if (!strcmp(cep->name, "password-file")) + } else if (!strcmp(cep->name, "password-file")) { if (!file_exists(cep->value) && existing && existing->password) { @@ -11370,8 +11100,7 @@ int _conf_secret(ConfigFile *conf, ConfigEntry *ce) { s->password = _conf_secret_read_password_file(cep->value); } - } else - if (!strcmp(cep->name, "password-prompt")) + } else if (!strcmp(cep->name, "password-prompt")) { if (!loop.booted && running_interactively()) { @@ -11420,7 +11149,7 @@ void resource_download_complete(OutgoingWebRequest *request, OutgoingWebResponse rs->type &= ~RESOURCE_DLQUEUED; if (config_verbose) - config_status("resource_download_complete() for %s [%s]", request->url, response->errorbuf?response->errorbuf:"success"); + config_status("resource_download_complete() for %s [%s]", request->url, response->errorbuf ? response->errorbuf : "success"); if (!response->file && !response->cached) { @@ -11428,35 +11157,34 @@ void resource_download_complete(OutgoingWebRequest *request, OutgoingWebResponse if (rs->cache_file) { unreal_log(ULOG_ERROR, "config", "DOWNLOAD_FAILED_SOFT", NULL, - "$file:$line_number: Failed to download '$url': $error_message\n" - "Using a cached copy instead.", - log_data_string("file", rs->wce->ce->file->filename), - log_data_integer("line_number", rs->wce->ce->line_number), - log_data_string("url", displayurl(request->url)), - log_data_string("error_message", response->errorbuf)); + "$file:$line_number: Failed to download '$url': $error_message\n" + "Using a cached copy instead.", + log_data_string("file", rs->wce->ce->file->filename), + log_data_integer("line_number", rs->wce->ce->line_number), + log_data_string("url", displayurl(request->url)), + log_data_string("error_message", response->errorbuf)); safe_strdup(rs->file, rs->cache_file); - } else - if (rs->warn_only_on_fail) + } else if (rs->warn_only_on_fail) { const char *cache_file; unreal_log(ULOG_WARNING, "config", "DOWNLOAD_FAILED_WARN", NULL, - "$file:$line_number: Failed to download '$url': $error_message\n" - "Continuing anyway...", - log_data_string("file", rs->wce->ce->file->filename), - log_data_integer("line_number", rs->wce->ce->line_number), - log_data_string("url", displayurl(request->url)), - log_data_string("error_message", response->errorbuf)); + "$file:$line_number: Failed to download '$url': $error_message\n" + "Continuing anyway...", + log_data_string("file", rs->wce->ce->file->filename), + log_data_integer("line_number", rs->wce->ce->line_number), + log_data_string("url", displayurl(request->url)), + log_data_string("error_message", response->errorbuf)); cache_file = unreal_mkcache(request->url); unreal_touch(cache_file, 1577880000); /* 2020-01-01 12:00 GMT */ safe_strdup(rs->file, cache_file); } else { unreal_log(ULOG_ERROR, "config", "DOWNLOAD_FAILED_HARD", NULL, - "$file:$line_number: Failed to download '$url': $error_message", - log_data_string("file", rs->wce->ce->file->filename), - log_data_integer("line_number", rs->wce->ce->line_number), - log_data_string("url", displayurl(request->url)), - log_data_string("error_message", response->errorbuf)); + "$file:$line_number: Failed to download '$url': $error_message", + log_data_string("file", rs->wce->ce->file->filename), + log_data_integer("line_number", rs->wce->ce->line_number), + log_data_string("url", displayurl(request->url)), + log_data_string("error_message", response->errorbuf)); /* Set error condition, this so config_read_file() later will stop. */ loop.config_load_failed = 1; /* We keep the other transfers running since they may raise (more) errors. @@ -11464,14 +11192,14 @@ void resource_download_complete(OutgoingWebRequest *request, OutgoingWebResponse * include on one server, or complete lack of internet connectvitity. */ } - } - else + } else { if (response->cached) { /* Copy from cache */ safe_strdup(rs->file, rs->cache_file); - } else { + } else + { /* Copy to cache */ const char *cache_file = unreal_mkcache(request->url); unreal_copyfileex(response->file, cache_file, 1); @@ -11489,7 +11217,8 @@ void resource_download_complete_parse(ConfigResource *rs) { if (config_read_file(rs->file, (char *)displayurl(rs->url)) < 0) loop.config_load_failed = 1; - } else { + } else + { ConfigEntryWrapper *wce; for (wce = rs->wce; wce; wce = wce->next) safe_strdup(wce->ce->value, rs->file); // now information of url is lost, hm!! @@ -11603,7 +11332,7 @@ void link_cleanup(ConfigItem_link *link_ptr) { free_tls_options(link_ptr->tls_options); link_ptr->tls_options = NULL; - } + } } void delete_linkblock(ConfigItem_link *link_ptr) @@ -11661,7 +11390,8 @@ void listen_cleanup() free_entire_name_list(listener->websocket_origin); // NOTE: duplicate code overlap with conf_listen_configure() - but not 100% identical safe_free(listener); - } else { + } else + { /* Still has clients */ if (listener->webserver) { @@ -11760,12 +11490,13 @@ int add_config_resource(const char *resource, int type, ConfigEntry *ce) if (!url_is_valid(resource)) { safe_strdup(rs->file, resource); - } else { + } else + { const char *cache_file; time_t modtime; safe_strdup(rs->url, resource); - rs->type = type|RESOURCE_REMOTE|RESOURCE_DLQUEUED; + rs->type = type | RESOURCE_REMOTE | RESOURCE_DLQUEUED; cache_file = unreal_mkcache(rs->url); modtime = unreal_getfilemodtime(cache_file); @@ -11803,14 +11534,16 @@ int add_config_resource(const char *resource, int type, ConfigEntry *ce) rs->type &= ~RESOURCE_DLQUEUED; resource_download_complete_parse(rs); return 1; - } else { + } else + { //config_status("DEBUG: requires download attempt, out of date url-refresh %ld < %ld", refresh_time, TStime() - modtime); } break; // MUST break now as we touched the linked list. } prev = cep; } - } else { + } else + { /* CACHED COPY IS NOT AVAILABLE */ ConfigEntry *cep, *prev; /* Check if there is an "url-fail" argument */ @@ -11882,7 +11615,7 @@ int tls_tests(void) { config_error("Your server is not listening on any TLS ports."); config_status("Add this to your unrealircd.conf: listen { ip %s; port 6697; options { tls; }; };", - port_6667_ip ? port_6667_ip : "*"); + port_6667_ip ? port_6667_ip : "*"); config_status("See https://www.unrealircd.org/docs/FAQ#no-tls-ports"); return 0; } @@ -11896,9 +11629,9 @@ int tls_tests(void) */ int reloadable_perm_module_unloaded(void) { - Module *m, *m2; - extern Module *Modules; - int ret = 0; + Module *m, *m2; + extern Module *Modules; + int ret = 0; for (m = Modules; m; m = m->next) { @@ -12010,7 +11743,8 @@ int modules_default_conf_modified(const char *filebuf) if (!str_starts_with_case_sensitive(buf, "/* [")) { conf_version = "before 6.1.1"; - } else { + } else + { p = strchr(conf_version, ']'); if (p) *p = '\0'; @@ -12058,52 +11792,57 @@ void dynamic_set_number(DynamicSetBlock *s, int settingname, long long value) } #undef CheckNull -#define CheckNull(x) if ((!(x)->value) || (!(*((x)->value)))) { config_error("%s:%i: missing parameter", (x)->file->filename, (x)->line_number); return 1; } +#define CheckNull(x) \ + if ((!(x)->value) || (!(*((x)->value)))) \ + { \ + config_error("%s:%i: missing parameter", (x)->file->filename, (x)->line_number); \ + return 1; \ + } int test_dynamic_set_block_item(ConfigFile *conf, const char *security_group, ConfigEntry *cep) { int errors = 0; - if (!strcmp(cep->name, "modes-on-connect")) { + if (!strcmp(cep->name, "modes-on-connect")) + { char *p; CheckNull(cep); for (p = cep->value; *p; p++) if (strchr("orzSHqtW", *p)) { config_error("%s:%i: set::modes-on-connect may not include mode '%c'", - cep->file->filename, cep->line_number, *p); + cep->file->filename, cep->line_number, *p); errors++; } - } - else if (!strcmp(cep->name, "auto-join")) { + } else if (!strcmp(cep->name, "auto-join")) + { CheckNull(cep); - } - else if (!strcmp(cep->name, "maxchannelsperuser") || !strcmp(cep->name, "max-channels-per-user")) { + } else if (!strcmp(cep->name, "maxchannelsperuser") || !strcmp(cep->name, "max-channels-per-user")) + { int i; CheckNull(cep); i = atoi(cep->value); if (i < 1) { config_error("%s:%i: set::%s must be > 0", - cep->file->filename, - cep->line_number, - cep->name); + cep->file->filename, + cep->line_number, + cep->name); errors++; } - } - else if (!strcmp(cep->name, "static-quit")) { + } else if (!strcmp(cep->name, "static-quit")) + { CheckNull(cep); - } - else if (!strcmp(cep->name, "static-part")) { + } else if (!strcmp(cep->name, "static-part")) + { CheckNull(cep); - } - else if (!strcmp(cep->name, "restrict-usermodes")) + } else if (!strcmp(cep->name, "restrict-usermodes")) { CheckNull(cep); if (strchr(cep->value, '+') || strchr(cep->value, '-')) { config_error("%s:%i: set::restrict-usermodes: may only contain mode characters, no + or -.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } } else @@ -12117,35 +11856,36 @@ int test_dynamic_set_block_item(ConfigFile *conf, const char *security_group, Co int config_set_dynamic_set_block_item(ConfigFile *conf, DynamicSetBlock *s, ConfigEntry *cep) { - if (!strcmp(cep->name, "modes-on-connect")) { + if (!strcmp(cep->name, "modes-on-connect")) + { long v = set_usermode(cep->value); dynamic_set_number(s, SET_MODES_ON_CONNECT, v); return 1; - } - else if (!strcmp(cep->name, "auto-join")) { + } else if (!strcmp(cep->name, "auto-join")) + { dynamic_set_string(s, SET_AUTO_JOIN, cep->value); return 1; - } - else if (!strcmp(cep->name, "maxchannelsperuser") || !strcmp(cep->name, "max-channels-per-user")) { + } else if (!strcmp(cep->name, "maxchannelsperuser") || !strcmp(cep->name, "max-channels-per-user")) + { dynamic_set_number(s, SET_MAX_CHANNELS_PER_USER, atoi(cep->value)); return 1; - } - else if (!strcmp(cep->name, "static-quit")) { + } else if (!strcmp(cep->name, "static-quit")) + { dynamic_set_string(s, SET_STATIC_QUIT, cep->value); return 1; - } - else if (!strcmp(cep->name, "static-part")) { + } else if (!strcmp(cep->name, "static-part")) + { dynamic_set_string(s, SET_STATIC_PART, cep->value); return 1; - } - else if (!strcmp(cep->name, "restrict-usermodes")) { + } else if (!strcmp(cep->name, "restrict-usermodes")) + { int i; char buf[512]; char *p = buf; /* The data should be something like 'Gw' or something, * but just in case users use '+Gw' then ignore the + (and -). */ - for (i=0; i < MIN(strlen(cep->value),sizeof(buf)-1); i++) + for (i = 0; i < MIN(strlen(cep->value), sizeof(buf) - 1); i++) if ((cep->value[i] != '+') && (cep->value[i] != '-')) *p++ = cep->value[i]; *p = '\0'; @@ -12169,8 +11909,7 @@ int test_set_security_group(ConfigFile *conf, ConfigEntry *ce) config_error("%s:%i: set::%s is not allowed in a set { } block or is an unrecognized option", cep->file->filename, cep->line_number, ce->value); errors++; - } else - if (n > 0) + } else if (n > 0) { errors += n; } @@ -12234,9 +11973,8 @@ DynamicSetOption *get_setting_for_user(Client *client, SetOption opt) if (sg->settings.isset[opt]) return &sg->settings.settings[opt]; } - } else - if (user_allowed_by_security_group(client, sg) && - sg->settings.isset[opt]) + } else if (user_allowed_by_security_group(client, sg) && + sg->settings.isset[opt]) { return &sg->settings.settings[opt]; } @@ -12306,7 +12044,7 @@ void central_spamfilter_download_complete(OutgoingWebRequest *request, OutgoingW config_error("Central spamfilter URL fetch failed (this could be a temporary problem): %s: %s", request->url, response->errorbuf); return; } - + if (!(cfptr = config_load(response->file, "central_spamfilter.conf"))) { unreal_log(ULOG_ERROR, "central-spamfilter", "CENTRAL_SPAMFILTER_LOAD_FAILED", NULL, @@ -12320,7 +12058,7 @@ void central_spamfilter_download_complete(OutgoingWebRequest *request, OutgoingW if (errors) { unreal_log(ULOG_ERROR, "central-spamfilter", "CENTRAL_SPAMFILTER_LOAD_FAILED", NULL, - "[Central spamfilter] Errors in the central central_spamfilter.conf -- not loaded."); + "[Central spamfilter] Errors in the central central_spamfilter.conf -- not loaded."); config_free(cfptr); return; } @@ -12381,7 +12119,8 @@ void central_spamfilter_start_download(void) /* Use the restricted URL */ buildvarstring_nvp(DEFAULT_CENTRAL_SPAMFILTER_URL_RESTRICTED_ACCESS, url, sizeof(url), nvp, 0); add_nvplist(&request->headers, 0, "X-API-Key", apikey); - } else { + } else + { /* Use the open access URL */ buildvarstring_nvp(iConf.central_spamfilter_url, url, sizeof(url), nvp, 0); } @@ -12418,7 +12157,8 @@ const char *config_item_name(ConfigEntry *ce) { strlcpy(tmp, buf, sizeof(tmp)); snprintf(buf, sizeof(buf), "%s::%s", ce->name, tmp); - } else { + } else + { strlcpy(buf, ce->name, sizeof(buf)); } } diff --git a/src/conf_preprocessor.c b/src/conf_preprocessor.c index 258d0b611..33cc6f136 100644 --- a/src/conf_preprocessor.c +++ b/src/conf_preprocessor.c @@ -53,13 +53,13 @@ typedef struct { * since we use strncmp for matching. */ static IfFunction if_functions[] = { - { "module-loaded", IF_MODULE_LOADED, 0 }, - { "module-exists", IF_MODULE_EXISTS, 0 }, - { "minimum-version", IF_MINIMUM_VERSION, 0 }, - { "file-exists", IF_FILE_EXISTS, 0 }, - { "module-version", IF_MODULE_VERSION, 1 }, - { "environment", IF_ENVIRONMENT, 1 }, - { "defined", IF_DEFINED, 0 }, + {"module-loaded", IF_MODULE_LOADED, 0}, + {"module-exists", IF_MODULE_EXISTS, 0}, + {"minimum-version", IF_MINIMUM_VERSION, 0}, + {"file-exists", IF_FILE_EXISTS, 0}, + {"module-version", IF_MODULE_VERSION, 1}, + {"environment", IF_ENVIRONMENT, 1}, + {"defined", IF_DEFINED, 0}, }; static inline int ValidVarCharacter(char x) @@ -89,35 +89,30 @@ static int parse_compare_op_and_value(char **p, char *statement, { *compare_op_out = COMPARE_EQ; op_len = 2; - } else - if (!strncmp(*p, "!=", 2)) + } else if (!strncmp(*p, "!=", 2)) { *compare_op_out = COMPARE_NE; op_len = 2; - } else - if (!strncmp(*p, ">=", 2)) + } else if (!strncmp(*p, ">=", 2)) { *compare_op_out = COMPARE_GE; op_len = 2; - } else - if (!strncmp(*p, "<=", 2)) + } else if (!strncmp(*p, "<=", 2)) { *compare_op_out = COMPARE_LE; op_len = 2; - } else - if (**p == '>') + } else if (**p == '>') { *compare_op_out = COMPARE_GT; op_len = 1; - } else - if (**p == '<') + } else if (**p == '<') { *compare_op_out = COMPARE_LT; op_len = 1; } else { config_error("%s:%i: @if: expected comparison operator (==, !=, >, >=, <, <=): %s", - filename, linenumber, statement); + filename, linenumber, statement); return 0; } *p += op_len; @@ -130,7 +125,7 @@ static int parse_compare_op_and_value(char **p, char *statement, if (!**p) { config_error("%s:%i: invalid @if statement, missing \" at end perhaps?", - filename, linenumber); + filename, linenumber); return 0; } **p = '\0'; @@ -169,7 +164,7 @@ static PreprocessorItem parse_if_function(char *p, const char *funcname, ConfigI if (*p != '(') { config_error("%s:%i: expected '(' for %s(...", - filename, linenumber, funcname); + filename, linenumber, funcname); return PREPROCESSOR_ERROR; } p++; @@ -181,7 +176,7 @@ static PreprocessorItem parse_if_function(char *p, const char *funcname, ConfigI if (!*p) { config_error("%s:%i: invalid if statement (termination error): %s", - filename, linenumber, statement); + filename, linenumber, statement); return PREPROCESSOR_ERROR; } *p = '\0'; @@ -204,7 +199,7 @@ static PreprocessorItem parse_if_function(char *p, const char *funcname, ConfigI if (negative) { config_error("%s:%i: @if: the '!' prefix cannot be used with %s() comparisons, use != instead: %s", - filename, linenumber, funcname, statement); + filename, linenumber, funcname, statement); preprocessor_cc_free_entry(cc); return PREPROCESSOR_ERROR; } @@ -224,7 +219,7 @@ static PreprocessorItem parse_if_function(char *p, const char *funcname, ConfigI PreprocessorItem evaluate_preprocessor_if(char *statement, const char *filename, int linenumber, ConditionalConfig **cc_out) { - char *p=statement; + char *p = statement; int i, negative = 0; ConditionalConfig *cc; @@ -277,13 +272,13 @@ PreprocessorItem evaluate_preprocessor_if(char *statement, const char *filename, if (*p != '$') { config_error("%s:%i: invalid @if statement. Either an unknown function, or did you mean $VARNAME?: %s", - filename, linenumber, statement); + filename, linenumber, statement); return PREPROCESSOR_ERROR; } if (negative) { config_error("%s:%i: @if: the '!' prefix cannot be used with variable comparisons, use != instead: %s", - filename, linenumber, statement); + filename, linenumber, statement); return PREPROCESSOR_ERROR; } p++; @@ -293,7 +288,7 @@ PreprocessorItem evaluate_preprocessor_if(char *statement, const char *filename, if (!*p) { config_error("%s:%i: invalid if statement (termination error): %s", - filename, linenumber, statement); + filename, linenumber, statement); return PREPROCESSOR_ERROR; } name_terminate = p; @@ -310,7 +305,7 @@ PreprocessorItem evaluate_preprocessor_if(char *statement, const char *filename, } config_error("%s:%i: Error while evaluating '@if' statement '%s'", - filename, linenumber, statement); + filename, linenumber, statement); return PREPROCESSOR_ERROR; } @@ -337,7 +332,7 @@ static const char *resolve_define_function(char *p, char *statement, if (!if_functions[i].returns_value) { config_error("%s:%i: @define: function '%s' does not return a value", - filename, linenumber, if_functions[i].keyword); + filename, linenumber, if_functions[i].keyword); return NULL; } @@ -347,7 +342,7 @@ static const char *resolve_define_function(char *p, char *statement, if (*p != '(') { config_error("%s:%i: @define: expected '(' for %s(...", - filename, linenumber, if_functions[i].keyword); + filename, linenumber, if_functions[i].keyword); return NULL; } p++; @@ -359,7 +354,7 @@ static const char *resolve_define_function(char *p, char *statement, if (!*p) { config_error("%s:%i: @define: invalid function call (termination error): %s", - filename, linenumber, statement); + filename, linenumber, statement); return NULL; } *p = '\0'; @@ -371,7 +366,7 @@ static const char *resolve_define_function(char *p, char *statement, if (!env) { config_error("%s:%i: @define: environment variable '%s' is not set", - filename, linenumber, arg); + filename, linenumber, arg); return NULL; } return env; @@ -383,13 +378,13 @@ static const char *resolve_define_function(char *p, char *statement, if (!mod) { config_error("%s:%i: @define: module '%s' is not loaded", - filename, linenumber, arg); + filename, linenumber, arg); return NULL; } if (!mod->header->version) { config_error("%s:%i: @define: module '%s' has no version information", - filename, linenumber, arg); + filename, linenumber, arg); return NULL; } return mod->header->version; @@ -397,16 +392,16 @@ static const char *resolve_define_function(char *p, char *statement, /* Future value-returning functions go here */ config_error("%s:%i: @define: [BUG] unhandled value-returning function '%s'", - filename, linenumber, if_functions[i].keyword); + filename, linenumber, if_functions[i].keyword); return NULL; } config_error("%s:%i: @define: expected a quoted string or a value-returning function like environment(): %s", - filename, linenumber, statement); + filename, linenumber, statement); return NULL; } -PreprocessorItem evaluate_preprocessor_define(char *statement, const char *filename, int linenumber) +PreprocessorItem evaluate_preprocessor_define(char *statement, const char *filename, int linenumber) { char *p = statement; char *name, *name_terminator; @@ -418,7 +413,7 @@ PreprocessorItem evaluate_preprocessor_define(char *statement, const char *file if (!*p) { config_error("%s:%i: invalid @define statement", - filename, linenumber); + filename, linenumber); return PREPROCESSOR_ERROR; } name_terminator = p; @@ -433,7 +428,7 @@ PreprocessorItem evaluate_preprocessor_define(char *statement, const char *file if (!*p) { config_error("%s:%i: invalid @define statement, missing \" at end perhaps?", - filename, linenumber); + filename, linenumber); return PREPROCESSOR_ERROR; } *p = '\0'; @@ -484,7 +479,7 @@ PreprocessorItem evaluate_preprocessor_define(char *statement, const char *file * @returns PREPROCESSOR_USER_ERROR or PREPROCESSOR_USER_WARNING */ static PreprocessorItem evaluate_preprocessor_error_or_warning(char *statement, - int is_error, const char *filename, int linenumber) + int is_error, const char *filename, int linenumber) { char *p = statement; @@ -508,7 +503,7 @@ static PreprocessorItem evaluate_preprocessor_error_or_warning(char *statement, return PREPROCESSOR_USER_WARNING; } -PreprocessorItem parse_preprocessor_item(char *start, char *end, const char *filename, int linenumber, ConditionalConfig **cc) +PreprocessorItem parse_preprocessor_item(char *start, char *end, const char *filename, int linenumber, ConditionalConfig **cc) { char buf[512]; int max; @@ -521,17 +516,17 @@ PreprocessorItem parse_preprocessor_item(char *start, char *end, const char *fi strlcpy(buf, start, max); if (!strncmp(buf, "@define", 7)) - return evaluate_preprocessor_define(buf+7, filename, linenumber); + return evaluate_preprocessor_define(buf + 7, filename, linenumber); else if (!strncmp(buf, "@if ", 4)) - return evaluate_preprocessor_if(buf+4, filename, linenumber, cc); + return evaluate_preprocessor_if(buf + 4, filename, linenumber, cc); else if (!strncmp(buf, "@else", 5)) return PREPROCESSOR_ELSE; else if (!strncmp(buf, "@endif", 6)) return PREPROCESSOR_ENDIF; else if (!strncmp(buf, "@error ", 7)) - return evaluate_preprocessor_error_or_warning(buf+7, 1, filename, linenumber); + return evaluate_preprocessor_error_or_warning(buf + 7, 1, filename, linenumber); else if (!strncmp(buf, "@warning ", 9)) - return evaluate_preprocessor_error_or_warning(buf+9, 0, filename, linenumber); + return evaluate_preprocessor_error_or_warning(buf + 9, 0, filename, linenumber); config_error("%s:%i: Unknown preprocessor directive: %s", filename, linenumber, buf); return PREPROCESSOR_ERROR; /* ??? */ @@ -612,19 +607,16 @@ int preprocessor_resolve_if(ConditionalConfig *cc, PreprocessorPhase phase) { /* We cannot handle @if module-loaded() yet.. */ result = 1; - } else - if (phase == PREPROCESSOR_PHASE_SECONDARY) + } else if (phase == PREPROCESSOR_PHASE_SECONDARY) { /* We can only handle blacklisted modules at this point, so: */ if (!is_blacklisted_module(cc->name)) result = 1; - } else - if (is_module_loaded(cc->name)) + } else if (is_module_loaded(cc->name)) { result = 1; } - } else - if (cc->condition == IF_MODULE_VERSION) + } else if (cc->condition == IF_MODULE_VERSION) { if (phase == PREPROCESSOR_PHASE_INITIAL || phase == PREPROCESSOR_PHASE_SECONDARY) { @@ -640,12 +632,24 @@ int preprocessor_resolve_if(ConditionalConfig *cc, PreprocessorPhase phase) int cmp = strnatcasecmp(mod->header->version, cc->opt); switch (cc->compare_op) { - case COMPARE_EQ: result = (cmp == 0); break; - case COMPARE_NE: result = (cmp != 0); break; - case COMPARE_GT: result = (cmp > 0); break; - case COMPARE_GE: result = (cmp >= 0); break; - case COMPARE_LT: result = (cmp < 0); break; - case COMPARE_LE: result = (cmp <= 0); break; + case COMPARE_EQ: + result = (cmp == 0); + break; + case COMPARE_NE: + result = (cmp != 0); + break; + case COMPARE_GT: + result = (cmp > 0); + break; + case COMPARE_GE: + result = (cmp >= 0); + break; + case COMPARE_LT: + result = (cmp < 0); + break; + case COMPARE_LE: + result = (cmp <= 0); + break; } } else { @@ -654,34 +658,29 @@ int preprocessor_resolve_if(ConditionalConfig *cc, PreprocessorPhase phase) } } } - } else - if (cc->condition == IF_MODULE_EXISTS) + } else if (cc->condition == IF_MODULE_EXISTS) { const char *fullpath = Module_TransformPath(cc->name); if (file_exists(fullpath)) result = 1; - } else - if (cc->condition == IF_MINIMUM_VERSION) + } else if (cc->condition == IF_MINIMUM_VERSION) { if (strnatcasecmp(VERSIONONLY, cc->name) >= 0) result = 1; - } else - if (cc->condition == IF_FILE_EXISTS) + } else if (cc->condition == IF_FILE_EXISTS) { char *fullpath = convert_to_absolute_path_duplicate(cc->name, CONFDIR); if (file_exists(fullpath)) result = 1; safe_free(fullpath); - } else - if (cc->condition == IF_DEFINED) + } else if (cc->condition == IF_DEFINED) { NameValuePrioList *d = find_config_define(cc->name); if (d) { result = 1; } - } else - if (cc->condition == IF_ENVIRONMENT) + } else if (cc->condition == IF_ENVIRONMENT) { const char *env = getenv(cc->name); if (env) @@ -691,12 +690,24 @@ int preprocessor_resolve_if(ConditionalConfig *cc, PreprocessorPhase phase) int cmp = strnatcasecmp(env, cc->opt); switch (cc->compare_op) { - case COMPARE_EQ: result = (cmp == 0); break; - case COMPARE_NE: result = (cmp != 0); break; - case COMPARE_GT: result = (cmp > 0); break; - case COMPARE_GE: result = (cmp >= 0); break; - case COMPARE_LT: result = (cmp < 0); break; - case COMPARE_LE: result = (cmp <= 0); break; + case COMPARE_EQ: + result = (cmp == 0); + break; + case COMPARE_NE: + result = (cmp != 0); + break; + case COMPARE_GT: + result = (cmp > 0); + break; + case COMPARE_GE: + result = (cmp >= 0); + break; + case COMPARE_LT: + result = (cmp < 0); + break; + case COMPARE_LE: + result = (cmp <= 0); + break; } } else { @@ -704,8 +715,7 @@ int preprocessor_resolve_if(ConditionalConfig *cc, PreprocessorPhase phase) result = 1; } } - } else - if (cc->condition == IF_VALUE) + } else if (cc->condition == IF_VALUE) { NameValuePrioList *d = find_config_define(cc->name); if (d) @@ -713,12 +723,24 @@ int preprocessor_resolve_if(ConditionalConfig *cc, PreprocessorPhase phase) int cmp = strnatcasecmp(d->value, cc->opt); switch (cc->compare_op) { - case COMPARE_EQ: result = (cmp == 0); break; - case COMPARE_NE: result = (cmp != 0); break; - case COMPARE_GT: result = (cmp > 0); break; - case COMPARE_GE: result = (cmp >= 0); break; - case COMPARE_LT: result = (cmp < 0); break; - case COMPARE_LE: result = (cmp <= 0); break; + case COMPARE_EQ: + result = (cmp == 0); + break; + case COMPARE_NE: + result = (cmp != 0); + break; + case COMPARE_GT: + result = (cmp > 0); + break; + case COMPARE_GE: + result = (cmp >= 0); + break; + case COMPARE_LT: + result = (cmp < 0); + break; + case COMPARE_LE: + result = (cmp <= 0); + break; } } } else @@ -754,7 +776,8 @@ void preprocessor_resolve_conditionals_ce(ConfigEntry **ce_list, PreprocessorPha { /* we are head, so new head */ *ce_list = ce->next; /* can be NULL now */ - } else { + } else + { /* non-head */ ce_prev->next = ce->next; /* can be NULL now */ } @@ -822,7 +845,7 @@ void preprocessor_replace_defines(char **item, ConfigEntry *ce) char varname[512]; const char *i, *varstart, *varend; char *o; - int n = sizeof(buf)-2; + int n = sizeof(buf) - 2; int limit; char *value; @@ -843,7 +866,8 @@ void preprocessor_replace_defines(char **item, ConfigEntry *ce) /* $ encountered: */ varstart = i; i++; - for (; *i && ValidVarCharacter(*i); i++); + for (; *i && ValidVarCharacter(*i); i++) + ; varend = i; i--; limit = varend - varstart + 1; @@ -862,7 +886,7 @@ void preprocessor_replace_defines(char **item, ConfigEntry *ce) i++; /* skip extra $ in input */ } else { - value = get_config_define(varname+1); + value = get_config_define(varname + 1); if (!value) { #if 0 diff --git a/src/crashreport.c b/src/crashreport.c index dc6ee5fbe..edaeee6f0 100644 --- a/src/crashreport.c +++ b/src/crashreport.c @@ -21,9 +21,9 @@ char *find_best_coredump(void) if (!fd) return NULL; - + *best_fname = '\0'; - + while ((dir = readdir(fd))) { char *fname = dir->d_name; @@ -32,7 +32,7 @@ char *find_best_coredump(void) !strstr(fname, ".done")) { char buf[512]; - + snprintf(buf, sizeof(buf), "%s/%s", TMPDIR, fname); t = get_file_time(buf); if (t && (t > best_time)) @@ -47,11 +47,11 @@ char *find_best_coredump(void) /* Windows */ WIN32_FIND_DATA hData; HANDLE hFile; - + hFile = FindFirstFile("unrealircd.*.core", &hData); if (hFile == INVALID_HANDLE_VALUE) return NULL; - + do { char *fname = hData.cFileName; @@ -68,11 +68,11 @@ char *find_best_coredump(void) } } while (FindNextFile(hFile, &hData)); FindClose(hFile); -#endif - +#endif + if (*best_fname) return best_fname; - + return NULL; /* none found */ } @@ -118,13 +118,13 @@ char *find_best_asan_log(void) #define EL_AR_MAX MAXPARA char **explode(char *str, char *delimiter) { - static char *ret[EL_AR_MAX+1]; + static char *ret[EL_AR_MAX + 1]; static char buf[1024]; char *p, *name; int cnt = 0; - + memset(&ret, 0, sizeof(ret)); /* make sure all elements are NULL */ - + strlcpy(buf, str, sizeof(buf)); for (name = strtoken(&p, buf, delimiter); name; name = strtoken(&p, NULL, delimiter)) { @@ -133,7 +133,7 @@ char **explode(char *str, char *delimiter) break; } ret[cnt] = NULL; - + return ret; } @@ -150,13 +150,13 @@ void crash_report_fix_libs(char *coredump, int *thirdpartymods) setenv("LC_ALL", "C", 1); snprintf(cmd, sizeof(cmd), "echo info sharedlibrary|gdb %s/unrealircd %s 2>&1", - BINDIR, coredump); + BINDIR, coredump); fd = popen(cmd, "r"); if (!fd) return; - while((fgets(buf, sizeof(buf), fd))) + while ((fgets(buf, sizeof(buf), fd))) { char *file, *path; char target[512]; @@ -165,26 +165,26 @@ void crash_report_fix_libs(char *coredump, int *thirdpartymods) stripcrlf(buf); if (strstr(buf, ".third.")) - *thirdpartymods = 1; + *thirdpartymods = 1; /* Output we are interested is something like this: * No /home/blabla/unrealircd/tmp/5114DF16.m_kick.so */ if (!strstr(buf, " No ")) continue; - + path = strchr(buf, '/'); if (!path) continue; if (!strstr(path, TMPDIR)) continue; /* we only care about our TMPDIR stuff */ - + file = strrchr(path, '/'); if (!file) continue; file++; - + /* files have the following two formats: * 5BE7DF9.m_svsnline.so for modules/m_svsnline.so * 300AA138.chanmodes.nokick.so for modules/chanmodes/nokick.so @@ -194,15 +194,15 @@ void crash_report_fix_libs(char *coredump, int *thirdpartymods) snprintf(target, sizeof(target), "%s/%s.%s", MODULESDIR, arr[1], arr[2]); else snprintf(target, sizeof(target), "%s/%s/%s.%s", MODULESDIR, arr[1], arr[2], arr[3]); - + if (!file_exists(target)) { printf("WARNING: could not resolve %s: %s does not exist\n", path, target); - } else { + } else + { if (symlink(target, path) < 0) printf("WARNING: could not create symlink %s -> %s\n", path, target); } - } pclose(fd); #endif @@ -237,16 +237,16 @@ int crash_report_backtrace(FILE *reportfd, char *coredump) "quit\n"); fclose(fd); - + snprintf(cmd, sizeof(cmd), "gdb -batch -x %s %s/unrealircd %s 2>&1", - buf, BINDIR, coredump); - + buf, BINDIR, coredump); + fd = popen(cmd, "r"); if (!fd) return 0; - + fprintf(reportfd, "START OF BACKTRACE\n"); - while((fgets(buf, sizeof(buf), fd))) + while ((fgets(buf, sizeof(buf), fd))) { stripcrlf(buf); fprintf(reportfd, " %s\n", buf); @@ -264,7 +264,7 @@ int crash_report_backtrace(FILE *reportfd, char *coredump) if (!fd) return 0; fprintf(reportfd, "START OF CRASH DUMP\n"); - while((fgets(buf, sizeof(buf), fd))) + while ((fgets(buf, sizeof(buf), fd))) { stripcrlf(buf); fprintf(reportfd, " %s\n", buf); @@ -291,8 +291,8 @@ int crash_report_asan_log(FILE *reportfd, char *coredump) asantime = get_file_time(asan_log); fprintf(reportfd, "ASan log file found '%s' which is %ld seconds older than core file\n", - asan_log, - (long)((long)(coretime) - (long)asantime)); + asan_log, + (long)((long)(coretime) - (long)asantime)); fd = fopen(asan_log, "r"); if (!fd) @@ -301,7 +301,7 @@ int crash_report_asan_log(FILE *reportfd, char *coredump) return 0; } fprintf(reportfd, "START OF ASAN LOG\n"); - while((fgets(buf, sizeof(buf), fd))) + while ((fgets(buf, sizeof(buf), fd))) { stripcrlf(buf); fprintf(reportfd, " %s\n", buf); @@ -321,32 +321,33 @@ int crash_report_asan_log(FILE *reportfd, char *coredump) void crash_report_header(FILE *reportfd, char *coredump) { time_t t; - + fprintf(reportfd, "== UNREALIRCD CRASH REPORT ==\n" "\n" "SYSTEM INFORMATION:\n"); - + fprintf(reportfd, "UnrealIRCd version: %s\n", VERSIONONLY); #if defined(__VERSION__) fprintf(reportfd, " Compiler: %s\n", __VERSION__); #endif - + fprintf(reportfd, " Operating System: %s\n", MYOSNAME); - + fprintf(reportfd, "Using core file: %s\n", coredump); - + t = get_file_time(coredump); if (t != 0) { fprintf(reportfd, "Crash date/time: %s\n", myctime(t) ? myctime(t) : "???"); fprintf(reportfd, " Crash secs ago: %ld\n", - (long)(time(NULL) - t)); - } else { + (long)(time(NULL) - t)); + } else + { fprintf(reportfd, "Crash date/time: UNKNOWN\n"); fprintf(reportfd, " Crash secs ago: UNKNOWN\n"); } - + fprintf(reportfd, "\n"); } @@ -358,18 +359,18 @@ int corefile_vs_binary_mismatch(char *coredump) #ifndef _WIN32 time_t core, binary; char fname[512]; - + snprintf(fname, sizeof(fname), "%s/unrealircd", BINDIR); - + core = get_file_time(coredump); binary = get_file_time(fname); - + if (!core || !binary) return 0; /* don't know then */ - + if (binary > core) return 1; /* yup, mismatch ;/ */ - + return 0; /* GOOD! */ #else return 0; /* guess we don't check this on Windows? Or will we check UnrealIRCd.exe... hmm.. yeah maybe good idea */ @@ -383,7 +384,7 @@ int attach_file(FILE *fdi, FILE *fdo) size_t n, total = 0; fprintf(fdo, "\n*** ATTACHMENT ****\n"); - while((n = fread(binbuf, 1, sizeof(binbuf), fdi)) > 0) + while ((n = fread(binbuf, 1, sizeof(binbuf), fdi)) > 0) { b64_encode(binbuf, n, printbuf, sizeof(printbuf)); fprintf(fdo, "%s\n", printbuf); @@ -462,14 +463,14 @@ int attach_coredump(FILE *fdo, char *coredump) /* On *NIX we create a .tar.bz2 / .tar.gz (may take a couple of seconds) */ printf("Please wait...\n"); snprintf(fname, sizeof(fname), "tar c %s/unrealircd %s %s %s 2>/dev/null|(bzip2 || gzip) 2>/dev/null", - BINDIR, coredump, MODULESDIR, libcname); + BINDIR, coredump, MODULESDIR, libcname); fdi = popen(fname, "r"); #else /* On Windows we attach de .mdmp, the small minidump file */ strlcpy(fname, coredump, sizeof(fname)); if (strlen(fname) > 5) - fname[strlen(fname)-5] = '\0'; /* cut off the '.core' part */ + fname[strlen(fname) - 5] = '\0'; /* cut off the '.core' part */ strlcat(fname, ".mdmp", sizeof(fname)); /* and add '.mdmp' */ fprintf(fdo, "Windows MINIDUMP: %s\n", fname); fdi = fopen(fname, "rb"); @@ -496,15 +497,15 @@ char *generate_crash_report(char *coredump, int *thirdpartymods) if (coredump == NULL) coredump = find_best_coredump(); - + if (coredump == NULL) return NULL; /* nothing available */ if (corefile_vs_binary_mismatch(coredump)) return NULL; - + snprintf(reportfname, sizeof(reportfname), "%s/crash.report.%s.%ld.txt", - TMPDIR, unreal_getfilename(coredump), (long)time(NULL)); + TMPDIR, unreal_getfilename(coredump), (long)time(NULL)); reportfd = fopen(reportfname, "w"); if (!reportfd) @@ -515,7 +516,7 @@ char *generate_crash_report(char *coredump, int *thirdpartymods) crash_report_header(reportfd, coredump); crash_report_fix_libs(coredump, thirdpartymods); - + crash_report_backtrace(reportfd, coredump); crash_report_asan_log(reportfd, coredump); attach_coredump(reportfd, coredump); @@ -525,9 +526,9 @@ char *generate_crash_report(char *coredump, int *thirdpartymods) return reportfname; } -#define REPORT_NEVER -1 -#define REPORT_ASK 0 -#define REPORT_AUTO 1 +#define REPORT_NEVER -1 +#define REPORT_ASK 0 +#define REPORT_AUTO 1 #define CRASH_REPORT_HOST "crash.unrealircd.org" @@ -544,20 +545,20 @@ int crashreport_send(char *fname) BIO *socket = NULL; int xfr = 0; char *errstr = NULL; - + filesize = get_file_size(fname); if (filesize < 0) return 0; - + for (n = 0; n < sizeof(delimiter); n++) - delimiter[n] = getrandom8()%26 + 'a'; - delimiter[sizeof(delimiter)-1] = '\0'; - + delimiter[n] = getrandom8() % 26 + 'a'; + delimiter[sizeof(delimiter) - 1] = '\0'; + snprintf(header, sizeof(header), "--%s\r\n" - "Content-Disposition: form-data; name=\"upload\"; filename=\"crash.txt\"\r\n" - "Content-Type: text/plain\r\n" - "\r\n", - delimiter); + "Content-Disposition: form-data; name=\"upload\"; filename=\"crash.txt\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n", + delimiter); snprintf(footer, sizeof(footer), "\r\n--%s--\r\n", delimiter); ctx_client = https_new_ctx(); @@ -569,7 +570,7 @@ int crashreport_send(char *fname) /* We can safely require TLSv1.3+ on unrealircd.org infra */ #if defined(HAS_SSL_CTX_SET_MIN_PROTO_VERSION) && defined(TLS1_3_VERSION) - SSL_CTX_set_min_proto_version(ctx_client, TLS1_3_VERSION); + SSL_CTX_set_min_proto_version(ctx_client, TLS1_3_VERSION); #endif socket = BIO_new_ssl_connect(ctx_client); @@ -578,7 +579,7 @@ int crashreport_send(char *fname) printf("ERROR: TLS initalization failure (II)\n"); return 0; } - + BIO_get_ssl(socket, &ssl); if (!ssl) { @@ -595,7 +596,7 @@ int crashreport_send(char *fname) printf("ERROR: Could not connect to %s\n", CRASH_REPORT_HOST); return 0; } - + if (BIO_do_handshake(socket) != 1) { printf("ERROR: Could not connect to %s (TLS handshake failed)\n", CRASH_REPORT_HOST); @@ -610,21 +611,21 @@ int crashreport_send(char *fname) } snprintf(buf, sizeof(buf), "POST /crash.php HTTP/1.1\r\n" - "User-Agent: UnrealIRCd %s\r\n" - "Host: %s\r\n" - "Connection: close\r\n" - "Accept: */*\r\n" - "Content-Length: %d\r\n" - "Expect: 100-continue\r\n" - "Content-Type: multipart/form-data; boundary=%s\r\n" - "\r\n", - VERSIONONLY, - CRASH_REPORT_HOST, - (int)(filesize+strlen(header)+strlen(footer)), - delimiter); - + "User-Agent: UnrealIRCd %s\r\n" + "Host: %s\r\n" + "Connection: close\r\n" + "Accept: */*\r\n" + "Content-Length: %d\r\n" + "Expect: 100-continue\r\n" + "Content-Type: multipart/form-data; boundary=%s\r\n" + "\r\n", + VERSIONONLY, + CRASH_REPORT_HOST, + (int)(filesize + strlen(header) + strlen(footer)), + delimiter); + BIO_puts(socket, buf); - + memset(buf, 0, sizeof(buf)); n = BIO_read(socket, buf, 255); if ((n < 0) || strncmp(buf, "HTTP/1.1 100", 12)) @@ -639,7 +640,7 @@ int crashreport_send(char *fname) } return 0; } - + fd = fopen(fname, "rb"); if (!fd) return 0; @@ -664,7 +665,9 @@ int crashreport_send(char *fname) BIO_puts(socket, footer); - do { } while(BIO_should_retry(socket)); /* make sure we are really finished (you never know with TLS) */ + do + { + } while (BIO_should_retry(socket)); /* make sure we are really finished (you never know with TLS) */ /* Attempt to shut down gracefully (which is a two step process) */ if (SSL_shutdown(ssl) == 0) @@ -674,18 +677,18 @@ int crashreport_send(char *fname) printf("\n"); #endif BIO_free_all(socket); - + SSL_CTX_free(ctx_client); - + return 1; } void mark_coredump_as_read(char *coredump) { char buf[512]; - + snprintf(buf, sizeof(buf), "%s.%ld.done", coredump, (long)time(NULL)); - + (void)rename(coredump, buf); } @@ -693,11 +696,12 @@ static int report_pref = REPORT_ASK; void report_crash_not_sent(char *fname) { - printf("Crash report will not be sent to UnrealIRCd Team.\n" - "\n" - "Feel free to read the report at %s and delete it.\n" - "Or, if you change your mind, you can submit it anyway at https://bugs.unrealircd.org/\n" - " (if you do, please set the option 'View Status' at the end of the bug report page to 'private'!!)\n", fname); + printf("Crash report will not be sent to UnrealIRCd Team.\n" + "\n" + "Feel free to read the report at %s and delete it.\n" + "Or, if you change your mind, you can submit it anyway at https://bugs.unrealircd.org/\n" + " (if you do, please set the option 'View Status' at the end of the bug report page to 'private'!!)\n", + fname); } /** This checks if there are indications that 3rd party modules are @@ -742,11 +746,11 @@ void report_crash(void) return; /* no crashes */ crashed_secs_ago = time(NULL) - get_file_time(coredump); - if (crashed_secs_ago > 86400*7) + if (crashed_secs_ago > 86400 * 7) return; /* stop bothering about it after a while */ fname = generate_crash_report(coredump, &thirdpartymods); - + if (!fname) return; @@ -758,24 +762,23 @@ void report_crash(void) if (thirdpartymods) { - printf("** IMPORTANT **\n" - "Your UnrealIRCd crashed and you have 3rd party modules loaded (modules created\n" - "by someone other than the UnrealIRCd team). If you installed new 3rd party\n" - "module(s) in the past few weeks we suggest to unload these modules and see if\n" - "the crash issue dissapears. If so, that module is probably to blame.\n" - "If you keep crashing without any 3rd party modules loaded then please do report\n" - "it to the UnrealIRCd team.\n" - "The reason we ask you to do this is because MORE THAN 95%% OF ALL CRASH ISSUES\n" - "ARE CAUSED BY 3RD PARTY MODULES and not by an UnrealIRCd bug.\n" - "\n"); + printf("** IMPORTANT **\n" + "Your UnrealIRCd crashed and you have 3rd party modules loaded (modules created\n" + "by someone other than the UnrealIRCd team). If you installed new 3rd party\n" + "module(s) in the past few weeks we suggest to unload these modules and see if\n" + "the crash issue dissapears. If so, that module is probably to blame.\n" + "If you keep crashing without any 3rd party modules loaded then please do report\n" + "it to the UnrealIRCd team.\n" + "The reason we ask you to do this is because MORE THAN 95%% OF ALL CRASH ISSUES\n" + "ARE CAUSED BY 3RD PARTY MODULES and not by an UnrealIRCd bug.\n" + "\n"); } - + if (report_pref == REPORT_NEVER) { report_crash_not_sent(fname); return; - } else - if (report_pref == REPORT_ASK) + } else if (report_pref == REPORT_ASK) { char answerbuf[64], *answer; printf("Shall I send a crash report to the UnrealIRCd developers?\n"); @@ -784,13 +787,13 @@ void report_crash(void) else printf("NOTE: If the crash is caused by a 3rd party module then UnrealIRCd devs can't fix that.\n"); printf("\n"); - + do { printf("Answer (Y/N): "); *answerbuf = '\0'; answer = fgets(answerbuf, sizeof(answerbuf), stdin); - + if (answer && (toupper(*answer) == 'N')) { report_crash_not_sent(fname); @@ -800,9 +803,9 @@ void report_crash(void) { break; } - + printf("Invalid response. Please enter either Y or N\n\n"); - } while(1); + } while (1); } else if (report_pref != REPORT_AUTO) { printf("Huh. report_pref setting is weird. Aborting.\n"); @@ -817,7 +820,7 @@ void report_crash(void) "give you feedback about the crash? This is completely optional, just press ENTER to skip.\n\n" "E-mail address (optional): "); line = fgets(buf, sizeof(buf), stdin); - + if (line && *line && (*line != '\n')) { FILE *fd = fopen(fname, "a"); @@ -832,7 +835,7 @@ void report_crash(void) "Again, this is completely optional. Just press ENTER to skip.\n\n" "Additional information (optional): "); line = fgets(buf, sizeof(buf), stdin); - + if (line && *line && (*line != '\n')) { FILE *fd = fopen(fname, "a"); @@ -852,27 +855,27 @@ void report_crash(void) #else /* Windows */ if (MessageBox(NULL, "UnrealIRCd crashed. May I send a report about this to the UnrealIRCd developers? This helps us a lot.", - "UnrealIRCd crash", - MB_YESNO|MB_ICONQUESTION) == IDYES) + "UnrealIRCd crash", + MB_YESNO | MB_ICONQUESTION) == IDYES) { /* Yay */ - + if (crashreport_send(fname)) { MessageBox(NULL, "The crash report has been sent to the UnrealIRCd developers. " "If you have any additional information (like details surrounding " "the crash) then please e-mail syzop@unrealircd.org, such " "information is most welcome. Thanks!", - "UnrealIRCd crash report sent", MB_ICONINFORMATION|MB_OK); + "UnrealIRCd crash report sent", MB_ICONINFORMATION | MB_OK); } } #endif mark_coredump_as_read(coredump); - + #ifdef _WIN32 if (MessageBox(NULL, "Start UnrealIRCd again?", - "UnrealIRCd crash", - MB_YESNO|MB_ICONQUESTION) == IDYES) + "UnrealIRCd crash", + MB_YESNO | MB_ICONQUESTION) == IDYES) { StartUnrealAgain(); } diff --git a/src/dbuf.c b/src/dbuf.c index b80277d2a..6a237d780 100644 --- a/src/dbuf.c +++ b/src/dbuf.c @@ -129,7 +129,7 @@ void dbuf_delete(dbuf *dyn, size_t length) ** ** Partially based on extract_one_line() from ircd-hybrid. --kaniini */ -int dbuf_getmsg(dbuf *dyn, char *buf) +int dbuf_getmsg(dbuf *dyn, char *buf) { dbufbuf *block; int line_bytes = 0, empty_bytes = 0, phase = 0; @@ -159,17 +159,20 @@ int dbuf_getmsg(dbuf *dyn, char *buf) empty_bytes++; if (phase == 1) phase = 2; - } - else switch (phase) - { - case 0: phase = 1; /* FALLTHROUGH */ - case 1: if (line_bytes++ < READBUFSIZE - 2) - *p++ = c; - break; - case 2: *p = '\0'; - dbuf_delete(dyn, line_bytes + empty_bytes); - return MIN(line_bytes, READBUFSIZE - 2); - } + } else + switch (phase) + { + case 0: + phase = 1; /* FALLTHROUGH */ + case 1: + if (line_bytes++ < READBUFSIZE - 2) + *p++ = c; + break; + case 2: + *p = '\0'; + dbuf_delete(dyn, line_bytes + empty_bytes); + return MIN(line_bytes, READBUFSIZE - 2); + } } } @@ -180,7 +183,8 @@ int dbuf_getmsg(dbuf *dyn, char *buf) */ line_bytes = 0; *buf = '\0'; - } else { + } else + { /* Zero terminate the string */ *p = '\0'; } @@ -203,7 +207,7 @@ int dbuf_get(dbuf *dyn, char **buf) /* First calculate the room needed... */ list_for_each_entry2(block, dbufbuf, &dyn->dbuf_list, dbuf_node) - bytes += block->size; + bytes += block->size; d = *buf = safe_alloc(bytes + 1); diff --git a/src/debug.c b/src/debug.c index 2c7933ad0..d5eccdbc5 100644 --- a/src/debug.c +++ b/src/debug.c @@ -29,59 +29,58 @@ /** String of server options in this compile (eg 'D' for debug mode). */ MODVAR char serveropts[] = { -#ifdef DEBUGMODE - 'D', +#ifdef DEBUGMODE + 'D', #endif - /* FDLIST (always) */ - 'F', - /* Hub (always) */ - 'h', - /* NOSPOOF (always) */ - 'n', -#ifdef VALLOC - 'V', + /* FDLIST (always) */ + 'F', + /* Hub (always) */ + 'h', + /* NOSPOOF (always) */ + 'n', +#ifdef VALLOC + 'V', #endif -#ifdef _WIN32 - 'W', +#ifdef _WIN32 + 'W', #endif -#ifdef USE_SYSLOG - 'Y', +#ifdef USE_SYSLOG + 'Y', #endif - '6', + '6', #ifndef NO_OPEROVERRIDE - 'O', + 'O', #endif #ifndef OPEROVERRIDE_VERIFY - 'o', + 'o', #endif - 'E', + 'E', #ifdef USE_LIBCURL - 'r', + 'r', #endif - '\0', /* Don't change those nuls. -- Syzop */ - '\0', - '\0', - '\0', - '\0', + '\0', /* Don't change those nuls. -- Syzop */ + '\0', + '\0', + '\0', + '\0', }; char *extraflags = NULL; MODVAR int debugfd = 2; -void flag_add(char ch) +void flag_add(char ch) { char *newextra; if (extraflags) { - char tmp[2] = { ch, 0 }; + char tmp[2] = {ch, 0}; newextra = safe_alloc(strlen(extraflags) + 2); strcpy(newextra, extraflags); strcat(newextra, tmp); safe_free(extraflags); extraflags = newextra; - } - else + } else { extraflags = safe_alloc(2); extraflags[0] = ch; @@ -89,12 +88,12 @@ void flag_add(char ch) } } -void flag_del(char ch) +void flag_del(char ch) { int newsz; char *p, *op; char *newflags; - newsz = 0; + newsz = 0; p = extraflags; for (newsz = 0, p = extraflags; *p; p++) if (*p != ch) @@ -109,14 +108,13 @@ void flag_del(char ch) } - #ifdef DEBUGMODE -#ifndef _WIN32 -#define SET_ERRNO(x) errno = x -#else -#define SET_ERRNO(x) WSASetLastError(x) -#endif /* _WIN32 */ + #ifndef _WIN32 + #define SET_ERRNO(x) errno = x + #else + #define SET_ERRNO(x) WSASetLastError(x) + #endif /* _WIN32 */ static char debugbuf[4096]; @@ -131,17 +129,17 @@ void debug(int level, FORMAT_STRING(const char *form), ...) { (void)ircvsnprintf(debugbuf, sizeof(debugbuf), form, vl); -#ifndef _WIN32 + #ifndef _WIN32 strlcat(debugbuf, "\n", sizeof(debugbuf)); if (write(debugfd, debugbuf, strlen(debugbuf)) < 0) { /* Yeah.. what can we do if output isn't working? Outputting an error makes no sense */ ; } -#else + #else strlcat(debugbuf, "\r\n", sizeof(debugbuf)); OutputDebugString(debugbuf); -#endif + #endif } va_end(vl); SET_ERRNO(err); diff --git a/src/dispatch.c b/src/dispatch.c index c2e48e575..f7d3b7ecc 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -23,20 +23,20 @@ /* Do we even support this, poll on Windows? */ #ifdef BACKEND_POLL -#ifndef _WIN32 -# include -#else -# define poll WSAPoll -# define POLLRDHUP POLLHUP -#endif + #ifndef _WIN32 + #include + #else + #define poll WSAPoll + #define POLLRDHUP POLLHUP + #endif #endif #ifdef _WIN32 -#include + #include #endif #ifndef _WIN32 -#include -#include + #include + #include #endif /* Not sure if this is suitable for production, @@ -101,9 +101,9 @@ void fd_setselect_real(int fd, int flags, IOCallbackFunc iocb, void *data) ***************************************************************************************/ #ifdef BACKEND_SELECT -#ifndef _WIN32 -# include -#endif + #ifndef _WIN32 + #include + #endif static int highest_fd = -1; static fd_set read_fds, write_fds; @@ -118,8 +118,7 @@ void fd_refresh(int fd) flags |= FD_SELECT_READ; FD_SET(fd, &read_fds); - } - else + } else FD_CLR(fd, &read_fds); if (fde->write_callback) @@ -127,15 +126,14 @@ void fd_refresh(int fd) flags |= FD_SELECT_WRITE; FD_SET(fd, &write_fds); - } - else + } else FD_CLR(fd, &write_fds); if (flags && highest_fd < fd) highest_fd = fd; while (highest_fd > 0 && - !(FD_ISSET(highest_fd, &read_fds) || FD_ISSET(highest_fd, &write_fds))) + !(FD_ISSET(highest_fd, &read_fds) || FD_ISSET(highest_fd, &write_fds))) highest_fd--; fde->backend_flags = flags; @@ -154,8 +152,8 @@ void fd_debug(fd_set *f, int highest, char *name) if (ioctlsocket(i, FIONBIO, &nonb) < 0) { unreal_log(ULOG_ERROR, "io", "FD_DEBUG", NULL, - "[BUG] fd_debug: fd $fd is invalid!!!", - log_data_integer("fd", i)); + "[BUG] fd_debug: fd $fd is invalid!!!", + log_data_integer("fd", i)); } } } @@ -166,26 +164,26 @@ void fd_select(int delay) int num, fd; fd_set work_read_fds; fd_set work_write_fds; -#ifdef _WIN32 + #ifdef _WIN32 fd_set work_except_fds; /* only needed on windows as it may indicate a failed connect() */ -#endif + #endif /* copy the FD sets so that our master sets are untouched */ memcpy(&work_read_fds, &read_fds, sizeof(fd_set)); memcpy(&work_write_fds, &write_fds, sizeof(fd_set)); -#ifdef _WIN32 + #ifdef _WIN32 memcpy(&work_except_fds, &write_fds, sizeof(fd_set)); -#endif + #endif memset(&to, 0, sizeof(to)); to.tv_sec = delay / 1000; to.tv_usec = (delay % 1000) * 1000; -#ifdef _WIN32 + #ifdef _WIN32 num = select(highest_fd + 1, &work_read_fds, &work_write_fds, &work_except_fds, &to); -#else + #else num = select(highest_fd + 1, &work_read_fds, &work_write_fds, NULL, &to); -#endif + #endif if (num < 0) { unreal_log(ULOG_FATAL, "io", "SELECT_ERROR", NULL, @@ -194,11 +192,11 @@ void fd_select(int delay) /* DEBUG the actual problem: */ memcpy(&work_read_fds, &read_fds, sizeof(fd_set)); memcpy(&work_write_fds, &write_fds, sizeof(fd_set)); - fd_debug(&work_read_fds, highest_fd+1, "read"); - fd_debug(&work_write_fds, highest_fd+1, "write"); -#ifdef _WIN32 + fd_debug(&work_read_fds, highest_fd + 1, "read"); + fd_debug(&work_write_fds, highest_fd + 1, "write"); + #ifdef _WIN32 Sleep(500); -#endif + #endif } if (num <= 0) @@ -220,11 +218,11 @@ void fd_select(int delay) if (FD_ISSET(fd, &work_write_fds)) evflags |= FD_SELECT_WRITE; -#ifdef _WIN32 + #ifdef _WIN32 /* Exception may happen due to failed connect. Translate to write event, like on *NIX. */ if (FD_ISSET(fd, &work_except_fds)) evflags |= FD_SELECT_WRITE; -#endif + #endif if (!evflags) continue; @@ -260,7 +258,7 @@ void fd_fork() ***************************************************************************************/ #ifdef BACKEND_KQUEUE -#include + #include static int kqueue_fd = -1; static struct kevent kqueue_events[MAXCONNECTIONS * 2]; @@ -272,20 +270,20 @@ void fd_fork() kqueue_fd = kqueue(); int p; - for (p=0; p < MAXCONNECTIONS * 2; ++p) + for (p = 0; p < MAXCONNECTIONS * 2; ++p) { if (kqueue_enabled[p]) { - if (kevent(kqueue_fd, &kqueue_prepared[p], 1, NULL, 0, &(const struct timespec){ .tv_sec = 0, .tv_nsec = 0}) != 0) + if (kevent(kqueue_fd, &kqueue_prepared[p], 1, NULL, 0, &(const struct timespec){.tv_sec = 0, .tv_nsec = 0}) != 0) { if (ERRNO == P_EWOULDBLOCK || ERRNO == P_EAGAIN) continue; - -#ifdef DEBUGMODE + + #ifdef DEBUGMODE unreal_log(ULOG_ERROR, "io", "KEVENT_FAILED", NULL, "[io] fd_fork(): kevent returned error: $system_error", log_data_string("system_error", strerror(errno))); -#endif + #endif } } } @@ -298,18 +296,18 @@ void fd_refresh(int fd) if (kqueue_fd == -1) { kqueue_fd = kqueue(); - memset(kqueue_enabled,0,MAXCONNECTIONS*2); + memset(kqueue_enabled, 0, MAXCONNECTIONS * 2); } kqueue_enabled[fd] = 0; - kqueue_enabled[fd+MAXCONNECTIONS] = 0; + kqueue_enabled[fd + MAXCONNECTIONS] = 0; if (fde->read_callback != NULL || fde->backend_flags & EVFILT_READ) { - EV_SET(&kqueue_prepared[fd], (uintptr_t) fd, (short) EVFILT_READ, fde->read_callback != NULL ? EV_ADD : EV_DELETE, 0, 0, fde); - if (kevent(kqueue_fd, &kqueue_prepared[fd], 1, NULL, 0, &(const struct timespec){ .tv_sec = 0, .tv_nsec = 0}) != 0) + EV_SET(&kqueue_prepared[fd], (uintptr_t)fd, (short)EVFILT_READ, fde->read_callback != NULL ? EV_ADD : EV_DELETE, 0, 0, fde); + if (kevent(kqueue_fd, &kqueue_prepared[fd], 1, NULL, 0, &(const struct timespec){.tv_sec = 0, .tv_nsec = 0}) != 0) { -#ifdef DEBUGMODE + #ifdef DEBUGMODE if (ERRNO != P_EWOULDBLOCK && ERRNO != P_EAGAIN) { int save_err = errno; @@ -320,16 +318,16 @@ void fd_refresh(int fd) log_data_string("fd_action", (fde->read_callback ? "add" : "delete")), log_data_string("callback", "read_callback")); } -#endif + #endif } } if (fde->write_callback != NULL || fde->backend_flags & EVFILT_WRITE) { - EV_SET(&kqueue_prepared[fd+MAXCONNECTIONS], (uintptr_t) fd, (short) EVFILT_WRITE, fde->write_callback != NULL ? EV_ADD : EV_DELETE, 0, 0, fde); - if (kevent(kqueue_fd, &kqueue_prepared[fd+MAXCONNECTIONS], 1, NULL, 0, &(const struct timespec){ .tv_sec = 0, .tv_nsec = 0}) != 0) + EV_SET(&kqueue_prepared[fd + MAXCONNECTIONS], (uintptr_t)fd, (short)EVFILT_WRITE, fde->write_callback != NULL ? EV_ADD : EV_DELETE, 0, 0, fde); + if (kevent(kqueue_fd, &kqueue_prepared[fd + MAXCONNECTIONS], 1, NULL, 0, &(const struct timespec){.tv_sec = 0, .tv_nsec = 0}) != 0) { -#ifdef DEBUGMODE + #ifdef DEBUGMODE if (ERRNO != P_EWOULDBLOCK && ERRNO != P_EAGAIN && fde->write_callback) { int save_err = errno; @@ -340,7 +338,7 @@ void fd_refresh(int fd) log_data_string("fd_action", "add"), log_data_string("callback", "write_callback")); } -#endif + #endif } } @@ -350,13 +348,12 @@ void fd_refresh(int fd) { fde->backend_flags |= EVFILT_READ; kqueue_enabled[fd] = 1; - } if (fde->write_callback != NULL) { fde->backend_flags |= EVFILT_WRITE; - kqueue_enabled[fd+MAXCONNECTIONS] = 1; + kqueue_enabled[fd + MAXCONNECTIONS] = 1; } } @@ -369,7 +366,7 @@ void fd_select(int delay) if (kqueue_fd == -1) { kqueue_fd = kqueue(); - memset(kqueue_enabled,0,MAXCONNECTIONS*2); + memset(kqueue_enabled, 0, MAXCONNECTIONS * 2); } memset(&ts, 0, sizeof(ts)); @@ -415,7 +412,7 @@ void fd_select(int delay) ***************************************************************************************/ #ifdef BACKEND_EPOLL -#include + #include static int epoll_fd = -1; static struct epoll_event epfds[MAXCONNECTIONS + 1]; @@ -459,10 +456,10 @@ void fd_refresh(int fd) return; unreal_log(ULOG_ERROR, "io", "EPOLL_CTL_FAILED", NULL, - "[io] fd_refresh(): epoll_ctl returned error for fd $fd ($fd_description): $system_error", - log_data_string("system_error", strerror(save_errno)), - log_data_integer("fd", fd), - log_data_string("fd_description", fde->desc)); + "[io] fd_refresh(): epoll_ctl returned error for fd $fd ($fd_description): $system_error", + log_data_string("system_error", strerror(save_errno)), + log_data_integer("fd", fd), + log_data_string("fd_description", fde->desc)); return; } @@ -473,11 +470,11 @@ void fd_select(int delay) { int num, p, revents, fd; struct epoll_event *epfd; -#ifdef DETECT_HIGH_CPU + #ifdef DETECT_HIGH_CPU int read_callbacks = 0, write_callbacks = 0; struct timeval oldt, t; long long tdiff; -#endif + #endif if (epoll_fd == -1) epoll_fd = epoll_create(MAXCONNECTIONS); @@ -485,9 +482,9 @@ void fd_select(int delay) if (num <= 0) return; -#ifdef DETECT_HIGH_CPU + #ifdef DETECT_HIGH_CPU gettimeofday(&oldt, NULL); -#endif + #endif for (p = 0; p < num; p++) { @@ -517,9 +514,9 @@ void fd_select(int delay) if (iocb != NULL) iocb(fd, evflags, fde->data); -#ifdef DETECT_HIGH_CPU + #ifdef DETECT_HIGH_CPU read_callbacks++; -#endif + #endif } if (evflags & FD_SELECT_WRITE) @@ -529,20 +526,20 @@ void fd_select(int delay) if (iocb != NULL) iocb(fd, evflags, fde->data); -#ifdef DETECT_HIGH_CPU + #ifdef DETECT_HIGH_CPU write_callbacks++; -#endif + #endif } -#if 0 + #if 0 if (((read_callbacks + write_callbacks) % 100) == 0) { /* every 100 events.. set the internal clock so we don't screw up under extreme load */ timeofday = time(NULL); } -#endif + #endif } -#ifdef DETECT_HIGH_CPU + #ifdef DETECT_HIGH_CPU gettimeofday(&t, NULL); tdiff = ((t.tv_sec - oldt.tv_sec) * 1000000) + (t.tv_usec - oldt.tv_usec); @@ -551,11 +548,11 @@ void fd_select(int delay) unreal_log(ULOG_WARNING, "io", "HIGH_LOAD", NULL, "HIGH CPU LOAD! fd_select() took $time_msec msec " "(read: $num_read_callbacks, write: $num_write_callbacks)", - log_data_integer("time_msec", tdiff/1000), + log_data_integer("time_msec", tdiff / 1000), log_data_integer("num_read_callbacks", read_callbacks), log_data_integer("num_write_callbacks", write_callbacks)); } -#endif + #endif } @@ -570,12 +567,12 @@ void fd_fork() ***************************************************************************************/ #ifdef BACKEND_POLL -#ifndef POLLRDNORM -# define POLLRDNORM POLLIN -#endif -#ifndef POLLWRNORM -# define POLLWRNORM POLLOUT -#endif + #ifndef POLLRDNORM + #define POLLRDNORM POLLIN + #endif + #ifndef POLLWRNORM + #define POLLWRNORM POLLOUT + #endif static struct pollfd pollfds[FD_SETSIZE]; static nfds_t nfds = 0; diff --git a/src/dns.c b/src/dns.c index 9dcaaba16..361ba35e0 100644 --- a/src/dns.c +++ b/src/dns.c @@ -47,7 +47,7 @@ * and perhaps by then it is long enough that we don't need the fallback to older * functions. */ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif /* Forward declerations */ @@ -73,8 +73,8 @@ ares_channel resolver_channel_https; /**< The resolver channel for HTTPS request ares_channel resolver_channel_dnsbl; /**< The resolver channel for DNSBLs. */ #define RESOLVER_CHANNEL_CLIENT (void *)0x1 -#define RESOLVER_CHANNEL_HTTPS (void *)0x2 -#define RESOLVER_CHANNEL_DNSBL (void *)0x3 +#define RESOLVER_CHANNEL_HTTPS (void *)0x2 +#define RESOLVER_CHANNEL_DNSBL (void *)0x3 DNSStats dnsstats; @@ -124,7 +124,7 @@ static void unrealdns_sock_state_cb(void *data, ares_socket_t fd, int read, int fd_close(fd); return; } - + if (read) selflags |= FD_SELECT_READ; @@ -175,7 +175,7 @@ void init_resolver(int firsttime) if (requests) abort(); /* should never happen */ - + if (firsttime) { memset(&cache_hashtbl, 0, sizeof(cache_hashtbl)); @@ -185,14 +185,14 @@ void init_resolver(int firsttime) } memset(&options, 0, sizeof(options)); - options.flags |= ARES_FLAG_NOALIASES|ARES_FLAG_IGNTC; + options.flags |= ARES_FLAG_NOALIASES | ARES_FLAG_IGNTC; options.sock_state_cb = unrealdns_sock_state_cb; /* Don't search domains or you'll get lookups for like * 1.1.168.192.dnsbl.dronebl.org.mydomain.org which is a waste. */ options.domains = NULL; options.ndomains = 0; - optmask = ARES_OPT_TIMEOUTMS|ARES_OPT_TRIES|ARES_OPT_FLAGS|ARES_OPT_SOCK_STATE_CB|ARES_OPT_DOMAINS; + optmask = ARES_OPT_TIMEOUTMS | ARES_OPT_TRIES | ARES_OPT_FLAGS | ARES_OPT_SOCK_STATE_CB | ARES_OPT_DOMAINS; #ifndef _WIN32 /* on *NIX don't use the hosts file, since it causes countless useless reads. * on Windows we use it for now, this could be changed in the future. @@ -352,7 +352,8 @@ struct hostent *unrealdns_doclient(Client *client) memset(&addr, 0, sizeof(addr)); inet_pton(AF_INET6, client->ip, &addr); ares_gethostbyaddr(resolver_channel_client, &addr, 16, AF_INET6, unrealdns_cb_iptoname, r); - } else { + } else + { struct in_addr addr; memset(&addr, 0, sizeof(addr)); inet_pton(AF_INET, client->ip, &addr); @@ -394,8 +395,8 @@ void unrealdns_cb_iptoname(void *arg, int status, int timeouts, struct hostent * unrealdns_freeandremovereq(r); if (!client) - return; - + return; + /* Check for status and null name (yes, we must) */ if ((status != 0) || !he->h_name || !*he->h_name) { @@ -444,7 +445,8 @@ void unrealdns_cb_nametoip_verify(void *arg, int status, int timeouts, struct ho continue; /* something fucked */ if (!memcmp(he->h_addr_list[i], &addr, 16)) break; /* MATCH */ - } else { + } else + { struct in_addr addr; if (inet_pton(AF_INET, client->ip, &addr) != 1) continue; /* something fucked */ @@ -486,7 +488,7 @@ void unrealdns_cb_nametoip_link(void *arg, int status, int timeouts, struct host DNSReq *r = (DNSReq *)arg; int n; struct hostent *he2; - char ipbuf[HOSTLEN+1]; + char ipbuf[HOSTLEN + 1]; const char *ip = NULL; if (!r->linkblock) @@ -509,8 +511,8 @@ void unrealdns_cb_nametoip_link(void *arg, int status, int timeouts, struct host /* fatal error while resolving */ unreal_log(ULOG_ERROR, "link", "LINK_ERROR_RESOLVING", NULL, - "Unable to resolve hostname $link_block.hostname, when trying to connect to server $link_block.", - log_data_link_block(r->linkblock)); + "Unable to resolve hostname $link_block.hostname, when trying to connect to server $link_block.", + log_data_link_block(r->linkblock)); r->linkblock->refcount--; unrealdns_freeandremovereq(r); return; @@ -527,7 +529,7 @@ void unrealdns_cb_nametoip_link(void *arg, int status, int timeouts, struct host unrealdns_freeandremovereq(r); return; } - + /* Ok, since we got here, it seems things were actually succesfull */ /* Fill in [linkblockstruct]->ipnum */ @@ -543,7 +545,7 @@ void unrealdns_cb_nametoip_link(void *arg, int status, int timeouts, struct host static uint64_t unrealdns_hash_ip(const char *ip) { - return siphash(ip, siphashkey_dns_ip) % DNS_HASH_SIZE; + return siphash(ip, siphashkey_dns_ip) % DNS_HASH_SIZE; } static void unrealdns_addtocache(const char *name, const char *ip) @@ -557,7 +559,7 @@ static void unrealdns_addtocache(const char *name, const char *ip) /* Check first if it is already present in the cache. * This is possible, when 2 clients connect at the same time. - */ + */ for (c = cache_hashtbl[hashv]; c; c = c->hnext) if (!strcmp(ip, c->ip)) return; /* already present in cache */ @@ -565,7 +567,8 @@ static void unrealdns_addtocache(const char *name, const char *ip) /* Remove last item, if we got too many entries.. */ if (unrealdns_num_cache >= DNS_MAX_ENTRIES) { - for (c = cache_list; c->next; c = c->next); + for (c = cache_list; c->next; c = c->next) + ; unrealdns_removecacherecord(c); } @@ -577,7 +580,7 @@ static void unrealdns_addtocache(const char *name, const char *ip) c->expires = TStime() + DNS_NEGCACHE_TTL; else c->expires = TStime() + DNS_CACHE_TTL; - + /* Add to hash table */ if (cache_hashtbl[hashv]) { @@ -585,7 +588,7 @@ static void unrealdns_addtocache(const char *name, const char *ip) c->hnext = cache_hashtbl[hashv]; } cache_hashtbl[hashv] = c; - + /* Add to linked list */ if (cache_list) { @@ -607,7 +610,7 @@ static const char *unrealdns_findcache_ip(const char *ip, int *found) DNSCache *c; hashv = unrealdns_hash_ip(ip); - + for (c = cache_hashtbl[hashv]; c; c = c->hnext) { if (!strcmp(ip, c->ip)) @@ -617,7 +620,7 @@ static const char *unrealdns_findcache_ip(const char *ip, int *found) return c->name; } } - + dnsstats.cache_misses++; *found = 0; return NULL; @@ -627,7 +630,7 @@ static const char *unrealdns_findcache_ip(const char *ip, int *found) */ void unrealdns_removecacherecord(DNSCache *c) { -unsigned int hashv; + unsigned int hashv; /* We basically got 4 pointers to update: * ->next @@ -640,23 +643,24 @@ unsigned int hashv; c->prev->next = c->next; else cache_list = c->next; /* new list HEAD */ - + if (c->next) c->next->prev = c->prev; - + if (c->hprev) c->hprev->hnext = c->hnext; - else { + else + { /* new hash HEAD */ hashv = unrealdns_hash_ip(c->ip); if (cache_hashtbl[hashv] != c) abort(); /* impossible */ cache_hashtbl[hashv] = c->hnext; } - + if (c->hnext) c->hnext->hprev = c->hprev; - + safe_free(c->name); safe_free(c->ip); safe_free(c); @@ -667,7 +671,7 @@ unsigned int hashv; /** This regulary removes old dns records from the cache */ EVENT(unrealdns_removeoldrecords) { -DNSCache *c, *next; + DNSCache *c, *next; for (c = cache_list; c; c = next) { @@ -679,7 +683,7 @@ DNSCache *c, *next; struct hostent *unreal_create_hostent(const char *name, const char *ip) { -struct hostent *he; + struct hostent *he; /* Create a hostent structure (I HATE HOSTENTS) and return it.. */ he = safe_alloc(sizeof(struct hostent)); @@ -692,7 +696,8 @@ struct hostent *he; he->h_addr_list = safe_alloc(sizeof(char *) * 2); /* alocate an array of 2 pointers */ he->h_addr_list[0] = safe_alloc(sizeof(struct in6_addr)); inet_pton(AF_INET6, ip, he->h_addr_list[0]); - } else { + } else + { he->h_addrtype = AF_INET; he->h_length = sizeof(struct in_addr); he->h_addr_list = safe_alloc(sizeof(char *) * 2); /* alocate an array of 2 pointers */ @@ -717,7 +722,7 @@ static void unrealdns_freeandremovereq(DNSReq *r) r->prev->next = r->next; else requests = r->next; /* new HEAD */ - + if (r->next) r->next->prev = r->prev; @@ -744,7 +749,6 @@ void unrealdns_delasyncconnects(void) for (r = requests; r; r = r->next) if (r->type == DNSREQ_CONNECT) r->linkblock = NULL; - } void dns_check_for_changes(void) @@ -788,7 +792,7 @@ CMD_FUNC(cmd_dns) DNSReq *r; const char *param; - if (!ValidatePermissionsForPath("server:dns",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:dns", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -810,18 +814,16 @@ CMD_FUNC(cmd_dns) for (c = cache_list; c; c = c->next) if (!c->name) sendtxtnumeric(client, " %s", c->ip); - } else - if (*param == 'r') /* LIST REQUESTS */ + } else if (*param == 'r') /* LIST REQUESTS */ { sendtxtnumeric(client, "DNS Request List:"); for (r = requests; r; r = r->next) sendtxtnumeric(client, " %s", r->client ? r->client->ip : ""); - } else - if (*param == 'c') /* CLEAR CACHE */ + } else if (*param == 'c') /* CLEAR CACHE */ { unreal_log(ULOG_INFO, "dns", "DNS_CACHE_CLEARED", client, - "DNS cache cleared by $client"); - + "DNS cache cleared by $client"); + while (cache_list) { c = cache_list->next; @@ -833,8 +835,7 @@ CMD_FUNC(cmd_dns) memset(&cache_hashtbl, 0, sizeof(cache_hashtbl)); unrealdns_num_cache = 0; sendnotice(client, "DNS Cache has been cleared"); - } else - if (*param == 'i') /* INFORMATION */ + } else if (*param == 'i') /* INFORMATION */ { struct ares_options inf; struct ares_addr_node *serverlist = NULL, *ns; @@ -842,7 +843,7 @@ CMD_FUNC(cmd_dns) int optmask; sendtxtnumeric(client, "****** DNS Configuration Information ******"); - sendtxtnumeric(client, " c-ares version: %s",ares_version(NULL)); + sendtxtnumeric(client, " c-ares version: %s", ares_version(NULL)); // Duplicate code follows, because.. yeah.. we use a struct? :D @@ -918,8 +919,7 @@ CMD_FUNC(cmd_dns) } typedef struct ApiCallbackWrappedArg ApiCallbackWrappedArg; -struct ApiCallbackWrappedArg -{ +struct ApiCallbackWrappedArg { char *callback_name; void *callback_arg; }; diff --git a/src/fdlist.c b/src/fdlist.c index c38b8d27a..3354c1c59 100644 --- a/src/fdlist.c +++ b/src/fdlist.c @@ -60,9 +60,9 @@ int fd_open(int fd, const char *desc, FDCloseMethod close_method) } #ifndef _WIN32 -# define OPEN_MODES S_IRUSR|S_IWUSR + #define OPEN_MODES S_IRUSR | S_IWUSR #else -# define OPEN_MODES S_IREAD|S_IWRITE + #define OPEN_MODES S_IREAD | S_IWRITE #endif int fd_fileopen(const char *path, unsigned int flags) @@ -153,11 +153,11 @@ void fd_unnotify(int fd) if ((fd < 0) || (fd >= MAXCONNECTIONS)) return; - + fde = &fd_table[fd]; if (!fde || !fde->is_open) return; - + fde->read_callback = fde->write_callback = NULL; fd_refresh(fd); } @@ -215,4 +215,3 @@ void fd_desc(int fd, const char *desc) strlcpy(fde->desc, desc, FD_DESC_SZ); } - diff --git a/src/hash.c b/src/hash.c index 84bfb5152..4b0243387 100644 --- a/src/hash.c +++ b/src/hash.c @@ -42,49 +42,50 @@ #define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b)))) -#define U32TO8_LE(p, v) \ - (p)[0] = (char)((v)); \ - (p)[1] = (char)((v) >> 8); \ - (p)[2] = (char)((v) >> 16); \ - (p)[3] = (char)((v) >> 24); +#define U32TO8_LE(p, v) \ + (p)[0] = (char)((v)); \ + (p)[1] = (char)((v) >> 8); \ + (p)[2] = (char)((v) >> 16); \ + (p)[3] = (char)((v) >> 24); -#define U64TO8_LE(p, v) \ - U32TO8_LE((p), (uint32_t)((v))); \ - U32TO8_LE((p) + 4, (uint32_t)((v) >> 32)); +#define U64TO8_LE(p, v) \ + U32TO8_LE((p), (uint32_t)((v))); \ + U32TO8_LE((p) + 4, (uint32_t)((v) >> 32)); -#define U8TO64_LE(p) \ - (((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) | \ - ((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) | \ - ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) | \ - ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56)) +#define U8TO64_LE(p) \ + (((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) | \ + ((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) | \ + ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) | \ + ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56)) -#define U8TO64_LE_NOCASE(p) \ - (((uint64_t)(tolower((p)[0]))) | \ - ((uint64_t)(tolower((p)[1])) << 8) | \ - ((uint64_t)(tolower((p)[2])) << 16) | \ - ((uint64_t)(tolower((p)[3])) << 24) | \ - ((uint64_t)(tolower((p)[4])) << 32) | \ - ((uint64_t)(tolower((p)[5])) << 40) | \ - ((uint64_t)(tolower((p)[6])) << 48) | \ - ((uint64_t)(tolower((p)[7])) << 56)) +#define U8TO64_LE_NOCASE(p) \ + (((uint64_t)(tolower((p)[0]))) | \ + ((uint64_t)(tolower((p)[1])) << 8) | \ + ((uint64_t)(tolower((p)[2])) << 16) | \ + ((uint64_t)(tolower((p)[3])) << 24) | \ + ((uint64_t)(tolower((p)[4])) << 32) | \ + ((uint64_t)(tolower((p)[5])) << 40) | \ + ((uint64_t)(tolower((p)[6])) << 48) | \ + ((uint64_t)(tolower((p)[7])) << 56)) -#define SIPROUND \ - do { \ - v0 += v1; \ - v1 = ROTL(v1, 13); \ - v1 ^= v0; \ - v0 = ROTL(v0, 32); \ - v2 += v3; \ - v3 = ROTL(v3, 16); \ - v3 ^= v2; \ - v0 += v3; \ - v3 = ROTL(v3, 21); \ - v3 ^= v0; \ - v2 += v1; \ - v1 = ROTL(v1, 17); \ - v1 ^= v2; \ - v2 = ROTL(v2, 32); \ - } while (0) +#define SIPROUND \ + do \ + { \ + v0 += v1; \ + v1 = ROTL(v1, 13); \ + v1 ^= v0; \ + v0 = ROTL(v0, 32); \ + v2 += v3; \ + v3 = ROTL(v3, 16); \ + v3 ^= v2; \ + v0 += v3; \ + v3 = ROTL(v3, 21); \ + v3 ^= v0; \ + v2 += v1; \ + v1 = ROTL(v1, 17); \ + v1 ^= v2; \ + v2 = ROTL(v2, 32); \ + } while (0) /** Generic hash function in UnrealIRCd - raw version. * Note that you probably want siphash() or siphash_nocase() instead. @@ -102,61 +103,72 @@ */ uint64_t siphash_raw(const char *in, size_t inlen, const char *k) { - uint64_t hash; - char *out = (char*) &hash; - uint64_t v0 = 0x736f6d6570736575ULL; - uint64_t v1 = 0x646f72616e646f6dULL; - uint64_t v2 = 0x6c7967656e657261ULL; - uint64_t v3 = 0x7465646279746573ULL; - uint64_t k0 = U8TO64_LE(k); - uint64_t k1 = U8TO64_LE(k + 8); - uint64_t m; - const char *end = in + inlen - (inlen % sizeof(uint64_t)); - const int left = inlen & 7; - uint64_t b = ((uint64_t)inlen) << 56; - v3 ^= k1; - v2 ^= k0; - v1 ^= k1; - v0 ^= k0; + uint64_t hash; + char *out = (char *)&hash; + uint64_t v0 = 0x736f6d6570736575ULL; + uint64_t v1 = 0x646f72616e646f6dULL; + uint64_t v2 = 0x6c7967656e657261ULL; + uint64_t v3 = 0x7465646279746573ULL; + uint64_t k0 = U8TO64_LE(k); + uint64_t k1 = U8TO64_LE(k + 8); + uint64_t m; + const char *end = in + inlen - (inlen % sizeof(uint64_t)); + const int left = inlen & 7; + uint64_t b = ((uint64_t)inlen) << 56; + v3 ^= k1; + v2 ^= k0; + v1 ^= k1; + v0 ^= k0; - for (; in != end; in += 8) { - m = U8TO64_LE(in); - v3 ^= m; + for (; in != end; in += 8) + { + m = U8TO64_LE(in); + v3 ^= m; - SIPROUND; - SIPROUND; + SIPROUND; + SIPROUND; - v0 ^= m; - } + v0 ^= m; + } - switch (left) { - case 7: b |= ((uint64_t)in[6]) << 48; /* fallthrough */ - case 6: b |= ((uint64_t)in[5]) << 40; /* fallthrough */ - case 5: b |= ((uint64_t)in[4]) << 32; /* fallthrough */ - case 4: b |= ((uint64_t)in[3]) << 24; /* fallthrough */ - case 3: b |= ((uint64_t)in[2]) << 16; /* fallthrough */ - case 2: b |= ((uint64_t)in[1]) << 8; /* fallthrough */ - case 1: b |= ((uint64_t)in[0]); break; - case 0: break; - } + switch (left) + { + case 7: + b |= ((uint64_t)in[6]) << 48; /* fallthrough */ + case 6: + b |= ((uint64_t)in[5]) << 40; /* fallthrough */ + case 5: + b |= ((uint64_t)in[4]) << 32; /* fallthrough */ + case 4: + b |= ((uint64_t)in[3]) << 24; /* fallthrough */ + case 3: + b |= ((uint64_t)in[2]) << 16; /* fallthrough */ + case 2: + b |= ((uint64_t)in[1]) << 8; /* fallthrough */ + case 1: + b |= ((uint64_t)in[0]); + break; + case 0: + break; + } - v3 ^= b; + v3 ^= b; - SIPROUND; - SIPROUND; + SIPROUND; + SIPROUND; - v0 ^= b; - v2 ^= 0xff; + v0 ^= b; + v2 ^= 0xff; - SIPROUND; - SIPROUND; - SIPROUND; - SIPROUND; + SIPROUND; + SIPROUND; + SIPROUND; + SIPROUND; - b = v0 ^ v1 ^ v2 ^ v3; - U64TO8_LE(out, b); + b = v0 ^ v1 ^ v2 ^ v3; + U64TO8_LE(out, b); - return hash; + return hash; } /** Generic hash function in UnrealIRCd - case insensitive. @@ -172,62 +184,73 @@ uint64_t siphash_raw(const char *in, size_t inlen, const char *k) */ uint64_t siphash_nocase(const char *in, const char *k) { - uint64_t hash; - char *out = (char*) &hash; - size_t inlen = strlen(in); - uint64_t v0 = 0x736f6d6570736575ULL; - uint64_t v1 = 0x646f72616e646f6dULL; - uint64_t v2 = 0x6c7967656e657261ULL; - uint64_t v3 = 0x7465646279746573ULL; - uint64_t k0 = U8TO64_LE(k); - uint64_t k1 = U8TO64_LE(k + 8); - uint64_t m; - const char *end = in + inlen - (inlen % sizeof(uint64_t)); - const int left = inlen & 7; - uint64_t b = ((uint64_t)inlen) << 56; - v3 ^= k1; - v2 ^= k0; - v1 ^= k1; - v0 ^= k0; + uint64_t hash; + char *out = (char *)&hash; + size_t inlen = strlen(in); + uint64_t v0 = 0x736f6d6570736575ULL; + uint64_t v1 = 0x646f72616e646f6dULL; + uint64_t v2 = 0x6c7967656e657261ULL; + uint64_t v3 = 0x7465646279746573ULL; + uint64_t k0 = U8TO64_LE(k); + uint64_t k1 = U8TO64_LE(k + 8); + uint64_t m; + const char *end = in + inlen - (inlen % sizeof(uint64_t)); + const int left = inlen & 7; + uint64_t b = ((uint64_t)inlen) << 56; + v3 ^= k1; + v2 ^= k0; + v1 ^= k1; + v0 ^= k0; - for (; in != end; in += 8) { - m = U8TO64_LE_NOCASE(in); - v3 ^= m; + for (; in != end; in += 8) + { + m = U8TO64_LE_NOCASE(in); + v3 ^= m; - SIPROUND; - SIPROUND; + SIPROUND; + SIPROUND; - v0 ^= m; - } + v0 ^= m; + } - switch (left) { - case 7: b |= ((uint64_t)tolower(in[6])) << 48; /* fallthrough */ - case 6: b |= ((uint64_t)tolower(in[5])) << 40; /* fallthrough */ - case 5: b |= ((uint64_t)tolower(in[4])) << 32; /* fallthrough */ - case 4: b |= ((uint64_t)tolower(in[3])) << 24; /* fallthrough */ - case 3: b |= ((uint64_t)tolower(in[2])) << 16; /* fallthrough */ - case 2: b |= ((uint64_t)tolower(in[1])) << 8; /* fallthrough */ - case 1: b |= ((uint64_t)tolower(in[0])); break; - case 0: break; - } + switch (left) + { + case 7: + b |= ((uint64_t)tolower(in[6])) << 48; /* fallthrough */ + case 6: + b |= ((uint64_t)tolower(in[5])) << 40; /* fallthrough */ + case 5: + b |= ((uint64_t)tolower(in[4])) << 32; /* fallthrough */ + case 4: + b |= ((uint64_t)tolower(in[3])) << 24; /* fallthrough */ + case 3: + b |= ((uint64_t)tolower(in[2])) << 16; /* fallthrough */ + case 2: + b |= ((uint64_t)tolower(in[1])) << 8; /* fallthrough */ + case 1: + b |= ((uint64_t)tolower(in[0])); + break; + case 0: + break; + } - v3 ^= b; + v3 ^= b; - SIPROUND; - SIPROUND; + SIPROUND; + SIPROUND; - v0 ^= b; - v2 ^= 0xff; + v0 ^= b; + v2 ^= 0xff; - SIPROUND; - SIPROUND; - SIPROUND; - SIPROUND; + SIPROUND; + SIPROUND; + SIPROUND; + SIPROUND; - b = v0 ^ v1 ^ v2 ^ v3; - U64TO8_LE(out, b); + b = v0 ^ v1 ^ v2 ^ v3; + U64TO8_LE(out, b); - return hash; + return hash; } /* End of imported code */ @@ -243,9 +266,9 @@ uint64_t siphash_nocase(const char *in, const char *k) */ uint64_t siphash(const char *in, const char *k) { - size_t inlen = strlen(in); + size_t inlen = strlen(in); - return siphash_raw(in, inlen, k); + return siphash_raw(in, inlen, k); } /** Generate a key that is used by siphash() and siphash_nocase(). @@ -440,9 +463,9 @@ Client *hash_find_id(const char *name, Client *client) Client *hash_find_nickatserver(const char *str, Client *def) { char *serv; - char nick[NICKLEN+HOSTLEN+1]; + char nick[NICKLEN + HOSTLEN + 1]; Client *client; - + strlcpy(nick, str, sizeof(nick)); /* let's work on a copy */ serv = strchr(nick, '@'); @@ -452,14 +475,14 @@ Client *hash_find_nickatserver(const char *str, Client *def) client = find_user(nick, NULL); if (!client) return NULL; /* client not found */ - + if (!serv) return client; /* validated: was just 'nick' and not 'nick@serv' */ /* Now validate the server portion */ if (client->user && !smycmp(serv, client->user->server)) return client; /* validated */ - + return def; } /* @@ -590,7 +613,7 @@ Channel *hash_get_chan_bucket(uint64_t hashv) */ Client *find_server_by_uid(const char *uid) { - char sid[SIDLEN+1]; + char sid[SIDLEN + 1]; if (!isdigit(*uid)) return NULL; /* not a UID/SID */ @@ -606,7 +629,7 @@ Client *find_server_by_uid(const char *uid) * already handled real-time. This is just to catch the other cases * (we don't know what type of complex known-users rules people have). */ -#define UPDATE_KNOWN_USER_CACHE_TIMER_WORKPERITERATION (NICK_HASH_TABLE_SIZE/24) +#define UPDATE_KNOWN_USER_CACHE_TIMER_WORKPERITERATION (NICK_HASH_TABLE_SIZE / 24) EVENT(update_known_user_cache_timer) { @@ -614,9 +637,10 @@ EVENT(update_known_user_cache_timer) int work_done = 0; Client *client; - do { + do + { list_for_each_entry(client, &idTable[slot], id_hash) - update_known_user_cache(client); + update_known_user_cache(client); if (++slot >= NICK_HASH_TABLE_SIZE) slot = 0; diff --git a/src/ircd.c b/src/ircd.c index 2a90816b8..9f3257103 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -32,7 +32,8 @@ static void open_debugfile(), setup_signals(); EVENT(loop_event) { - if (loop.do_garbage_collect == 1) { + if (loop.do_garbage_collect == 1) + { garbage_collect(NULL); } } @@ -42,19 +43,22 @@ EVENT(garbage_collect) extern int freelinks; extern Link *freelink; Link p; - int ii; + int ii; if (loop.do_garbage_collect == 1) unreal_log(ULOG_INFO, "main", "GARBAGE_COLLECT_STARTED", NULL, "Doing garbage collection..."); - if (freelinks > HOW_MANY_FREELINKS_ALLOWED) { + if (freelinks > HOW_MANY_FREELINKS_ALLOWED) + { ii = freelinks; - while (freelink && (freelinks > HOW_MANY_FREELINKS_ALLOWED)) { + while (freelink && (freelinks > HOW_MANY_FREELINKS_ALLOWED)) + { freelinks--; p.next = freelink; freelink = freelink->next; safe_free(p.next); } - if (loop.do_garbage_collect == 1) { + if (loop.do_garbage_collect == 1) + { loop.do_garbage_collect = 0; unreal_log(ULOG_INFO, "main", "GARBAGE_COLLECT_STARTED", NULL, "Cleaned up $count garbage blocks", log_data_integer("count", (ii - freelinks))); @@ -79,19 +83,21 @@ int match_tkls(Client *client) if (IsUser(client)) { /* Check ban realname { } */ - if (!ValidatePermissionsForPath("immune",client,NULL,NULL,NULL) && (bconf = find_ban(NULL, client->info, CONF_BAN_REALNAME))) + if (!ValidatePermissionsForPath("immune", client, NULL, NULL, NULL) && (bconf = find_ban(NULL, client->info, CONF_BAN_REALNAME))) { unreal_log(ULOG_INFO, "tkl", "BAN_REALNAME", client, "Banned client $client.details due to realname ban: $reason", log_data_string("reason", bconf->reason ? bconf->reason : "no reason")); - if (bconf->reason) { + if (bconf->reason) + { if (IsUser(client)) snprintf(banbuf, sizeof(banbuf), "User has been banned (%s)", bconf->reason); else snprintf(banbuf, sizeof(banbuf), "Banned (%s)", bconf->reason); exit_client(client, NULL, banbuf); - } else { + } else + { if (IsUser(client)) exit_client(client, NULL, "User has been banned"); else @@ -165,14 +171,12 @@ void check_ping(Client *client) return; /* some recent command was executed */ if ( - /* If we have sent a ping */ - (IsPingSent(client) - /* And they had 2x ping frequency to respond */ - && ((TStime() - client->local->last_msg_received) >= (2 * ping))) - || - /* Or isn't registered and time spent is larger than ping (CONNECTTIMEOUT).. */ - (!IsRegistered(client) && (TStime() - client->local->fake_lag >= ping)) - ) + /* If we have sent a ping */ + (IsPingSent(client) + /* And they had 2x ping frequency to respond */ + && ((TStime() - client->local->last_msg_received) >= (2 * ping))) || + /* Or isn't registered and time spent is larger than ping (CONNECTTIMEOUT).. */ + (!IsRegistered(client) && (TStime() - client->local->fake_lag >= ping))) { if (IsServer(client) || IsConnecting(client) || IsHandshake(client) || IsTLSConnectHandshake(client)) @@ -183,11 +187,10 @@ void check_ping(Client *client) SetServerDisconnectLogged(client); } ircsnprintf(scratch, sizeof(scratch), "Ping timeout: %lld seconds", - (long long) (TStime() - client->local->last_msg_received)); + (long long)(TStime() - client->local->last_msg_received)); exit_client(client, NULL, scratch); return; - } - else if (IsRegistered(client) && !IsPingSent(client)) + } else if (IsRegistered(client) && !IsPingSent(client)) { /* Time to send a PING */ SetPingSent(client); @@ -195,17 +198,16 @@ void check_ping(Client *client) /* not nice but does the job */ client->local->last_msg_received = TStime() - ping; sendto_one(client, NULL, "PING :%s", me.name); - } - else if (!IsPingWarning(client) && PINGWARNING > 0 && - (IsServer(client) || IsHandshake(client) || IsConnecting(client) || - IsTLSConnectHandshake(client)) && - (TStime() - client->local->last_msg_received) >= (ping + PINGWARNING)) + } else if (!IsPingWarning(client) && PINGWARNING > 0 && + (IsServer(client) || IsHandshake(client) || IsConnecting(client) || + IsTLSConnectHandshake(client)) && + (TStime() - client->local->last_msg_received) >= (ping + PINGWARNING)) { SetPingWarning(client); unreal_log(ULOG_WARNING, "link", "LINK_UNRELIABLE", client, - "Warning, no response from $client for $time_delta seconds", - log_data_integer("time_delta", PINGWARNING), - client->server->conf ? log_data_link_block(client->server->conf) : NULL); + "Warning, no response from $client for $time_delta seconds", + log_data_integer("time_delta", PINGWARNING), + client->server->conf ? log_data_link_block(client->server->conf) : NULL); } return; @@ -290,13 +292,15 @@ static int bad_command(const char *argv0) printf("ERROR: Incorrect command line argument encountered (if you are looking for foreground mode, it is -F).\n" "IMPORTANT: This is the unrealircd BINARY. End-users should NOT call this binary directly.\n" - "Please run the SCRIPT instead: %s/unrealircd\n", SCRIPTDIR); + "Please run the SCRIPT instead: %s/unrealircd\n", + SCRIPTDIR); printf("Server not started\n\n"); #else - if (!IsService) { + if (!IsService) + { MessageBox(NULL, - "Usage: UnrealIRCd [-f configfile]\n", - "UnrealIRCD/32", MB_OK); + "Usage: UnrealIRCd [-f configfile]\n", + "UnrealIRCD/32", MB_OK); } #endif return (-1); @@ -345,7 +349,7 @@ void fix_timers(void) { if (e->last_run.tv_sec > TStime()) { - e->last_run.tv_sec = TStime()-1; + e->last_run.tv_sec = TStime() - 1; e->last_run.tv_usec = 0; } } @@ -369,14 +373,14 @@ void fix_timers(void) * This should work until 2038, and very likely after that as well * because 'long' should be 64 bit on all systems by then... -- Syzop */ -#define mytdiff(a, b) ((long)a - (long)b) +#define mytdiff(a, b) ((long)a - (long)b) -#define NEGATIVE_SHIFT_WARN -15 -#define POSITIVE_SHIFT_WARN 20 +#define NEGATIVE_SHIFT_WARN -15 +#define POSITIVE_SHIFT_WARN 20 void detect_timeshift_and_warn(void) { - static time_t highesttimeofday=0, oldtimeofday=0, lasthighwarn=0; + static time_t highesttimeofday = 0, oldtimeofday = 0, lasthighwarn = 0; if (oldtimeofday == 0) oldtimeofday = timeofday; /* pretend everything is ok the first time.. */ @@ -396,8 +400,7 @@ void detect_timeshift_and_warn(void) log_data_timestamp("time_from", oldtimeofday), log_data_timestamp("time_to", timeofday)); fix_timers(); - } else - if (mytdiff(timeofday, oldtimeofday) > POSITIVE_SHIFT_WARN) /* do not set too low or you get false positives */ + } else if (mytdiff(timeofday, oldtimeofday) > POSITIVE_SHIFT_WARN) /* do not set too low or you get false positives */ { /* tdiff = # of seconds of time set forward (eg: 60) */ time_t tdiff = timeofday - oldtimeofday; @@ -413,27 +416,28 @@ void detect_timeshift_and_warn(void) fix_timers(); } - if (highesttimeofday+NEGATIVE_SHIFT_WARN > timeofday) + if (highesttimeofday + NEGATIVE_SHIFT_WARN > timeofday) { if (lasthighwarn > timeofday) lasthighwarn = timeofday; if (timeofday - lasthighwarn > 300) { unreal_log(ULOG_WARNING, "system", "SYSTEM_CLOCK_JUMP_BACKWARDS_PREVIOUSLY", NULL, - "The system clock previously went backwards. Waiting for time to be OK again. This will be in $time_delta seconds.", - log_data_integer("time_delta", highesttimeofday - timeofday), - log_data_timestamp("time_from", highesttimeofday), - log_data_timestamp("time_to", timeofday)); + "The system clock previously went backwards. Waiting for time to be OK again. This will be in $time_delta seconds.", + log_data_integer("time_delta", highesttimeofday - timeofday), + log_data_timestamp("time_from", highesttimeofday), + log_data_timestamp("time_to", timeofday)); lasthighwarn = timeofday; } - } else { + } else + { highesttimeofday = timeofday; } oldtimeofday = timeofday; } -#define DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME 5 +#define DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME 5 EVENT(detect_high_connection_rate) { @@ -443,65 +447,67 @@ EVENT(detect_high_connection_rate) if (iConf.high_connection_rate == 0) { quick_close = 0; - connections_past_period=0; /* reset */ + connections_past_period = 0; /* reset */ return; } - if (connections_past_period > iConf.high_connection_rate*DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME) + if (connections_past_period > iConf.high_connection_rate * DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME) { quick_close = 1; - } else { + } else + { quick_close = 0; } - if (OpenFiles >= maxclients-10) + if (OpenFiles >= maxclients - 10) quick_close = 1; /* Send a warning to IRCOps every XYZ time */ if (quick_close && (TStime() - last_detect_high_connection_rate_warning > 600) && connections_past_period) { - if (connections_past_period >= iConf.high_connection_rate*DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME) + if (connections_past_period >= iConf.high_connection_rate * DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME) { unreal_log(ULOG_WARNING, "htm", "HIGH_CONNECTION_RATE", NULL, - "High rate of connection attempts detected: $connects_per_second/sec exceeds $limit/sec: some minor functionality is now disabled. " - "This could be an attack, or lots of genuine users connecting after a network outage.\n" - "This message will appear every 10 minutes for as long as this is the case. " - "You will NOT get a notification if all is normal again (which is evaluated every $sample_time seconds). " - "See https://www.unrealircd.org/docs/FAQ#hi-conn-rate", - log_data_integer("connects_per_second", connections_past_period/DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME), - log_data_integer("limit", iConf.high_connection_rate), - log_data_integer("sample_time", DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME)); - } else { + "High rate of connection attempts detected: $connects_per_second/sec exceeds $limit/sec: some minor functionality is now disabled. " + "This could be an attack, or lots of genuine users connecting after a network outage.\n" + "This message will appear every 10 minutes for as long as this is the case. " + "You will NOT get a notification if all is normal again (which is evaluated every $sample_time seconds). " + "See https://www.unrealircd.org/docs/FAQ#hi-conn-rate", + log_data_integer("connects_per_second", connections_past_period / DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME), + log_data_integer("limit", iConf.high_connection_rate), + log_data_integer("sample_time", DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME)); + } else + { unreal_log(ULOG_WARNING, "htm", "HIGH_CONNECTION_RATE", NULL, - "High amount of connections in use ($connections is near limit of $maxclients maximum clients). Some minor functionality is now disabled. " - "This could be an attack, or lots of genuine users connecting.\n" - "This message will appear every 10 minutes for as long as this is the case. " - "You will NOT get a notification if all is normal again (which is evaluated every $sample_time seconds). " - "See https://www.unrealircd.org/docs/FAQ#hi-conn-rate", - log_data_integer("connections", OpenFiles), - log_data_integer("maxclients", maxclients), - log_data_integer("sample_time", DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME)); + "High amount of connections in use ($connections is near limit of $maxclients maximum clients). Some minor functionality is now disabled. " + "This could be an attack, or lots of genuine users connecting.\n" + "This message will appear every 10 minutes for as long as this is the case. " + "You will NOT get a notification if all is normal again (which is evaluated every $sample_time seconds). " + "See https://www.unrealircd.org/docs/FAQ#hi-conn-rate", + log_data_integer("connections", OpenFiles), + log_data_integer("maxclients", maxclients), + log_data_integer("sample_time", DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME)); } last_detect_high_connection_rate_warning = TStime(); } - connections_past_period=0; /* reset */ + connections_past_period = 0; /* reset */ } void SetupEvents(void) { /* Start events */ - EventAdd(NULL, "tunefile", save_tunefile, NULL, 300*1000, 0); - EventAdd(NULL, "garbage", garbage_collect, NULL, GARBAGE_COLLECT_EVERY*1000, 0); + EventAdd(NULL, "tunefile", save_tunefile, NULL, 300 * 1000, 0); + EventAdd(NULL, "garbage", garbage_collect, NULL, GARBAGE_COLLECT_EVERY * 1000, 0); EventAdd(NULL, "loop", loop_event, NULL, 1000, 0); EventAdd(NULL, "unrealdns_removeoldrecords", unrealdns_removeoldrecords, NULL, 15000, 0); EventAdd(NULL, "check_pings", check_pings, NULL, 1000, 0); EventAdd(NULL, "check_deadsockets", check_deadsockets, NULL, 1000, 0); EventAdd(NULL, "handshake_timeout", handshake_timeout, NULL, 1000, 0); - EventAdd(NULL, "tls_check_expiry", tls_check_expiry, NULL, (86400/2)*1000, 0); + EventAdd(NULL, "tls_check_expiry", tls_check_expiry, NULL, (86400 / 2) * 1000, 0); EventAdd(NULL, "unrealdb_expire_secret_cache", unrealdb_expire_secret_cache, NULL, 61000, 0); EventAdd(NULL, "memory_log_cleaner", memory_log_cleaner, NULL, 61500, 0); - EventAdd(NULL, "detect_high_connection_rate", detect_high_connection_rate, NULL, 1000*DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME, 0); + EventAdd(NULL, "detect_high_connection_rate", detect_high_connection_rate, NULL, 1000 * DETECT_HIGH_CONNECTION_RATE_SAMPLE_TIME, 0); EventAdd(NULL, "central_spamfilter_download_evt", central_spamfilter_download_evt, NULL, 5000, 0); EventAdd(NULL, "update_known_user_cache_timer", update_known_user_cache_timer, NULL, 5000, 0); EventAdd(NULL, "log_throttle_flush", log_throttle_flush, NULL, 5000, 0); @@ -566,15 +572,15 @@ int InitUnrealIRCd(int argc, char *argv[]) if (euid == 0) { fprintf(stderr, - "** ERROR **\n" - "You attempted to run UnrealIRCd as root. This is VERY DANGEROUS\n" - "as any compromise of your UnrealIRCd will result in full\n" - "privileges to the attacker on the entire machine.\n" - "You MUST start UnrealIRCd as a different user!\n" - "\n" - "For more information, see:\n" - "https://www.unrealircd.org/docs/Do_not_run_as_root\n" - "\n"); + "** ERROR **\n" + "You attempted to run UnrealIRCd as root. This is VERY DANGEROUS\n" + "as any compromise of your UnrealIRCd will result in full\n" + "privileges to the attacker on the entire machine.\n" + "You MUST start UnrealIRCd as a different user!\n" + "\n" + "For more information, see:\n" + "https://www.unrealircd.org/docs/Do_not_run_as_root\n" + "\n"); exit(1); } #endif @@ -584,7 +590,7 @@ int InitUnrealIRCd(int argc, char *argv[]) cmdLine = GetCommandLine(); #endif #ifndef _WIN32 - (void)umask(077); /* better safe than sorry --SRB */ + (void)umask(077); /* better safe than sorry --SRB */ #else init_winsock(); #endif @@ -613,23 +619,25 @@ int InitUnrealIRCd(int argc, char *argv[]) init_sys(); #if !defined(_WIN32) -#ifndef _WIN32 - mkdir(TMPDIR, S_IRUSR|S_IWUSR|S_IXUSR); /* Create the tmp dir, if it doesn't exist */ - mkdir(CACHEDIR, S_IRUSR|S_IWUSR|S_IXUSR); /* Create the cache dir, if it doesn't exist */ -#else + #ifndef _WIN32 + mkdir(TMPDIR, S_IRUSR | S_IWUSR | S_IXUSR); /* Create the tmp dir, if it doesn't exist */ + mkdir(CACHEDIR, S_IRUSR | S_IWUSR | S_IXUSR); /* Create the cache dir, if it doesn't exist */ + #else mkdir(TMPDIR); mkdir(CACHEDIR); -#endif - if (chdir(TMPDIR)) { -# ifndef _WIN32 + #endif + if (chdir(TMPDIR)) + { + #ifndef _WIN32 perror("chdir"); fprintf(stderr, "ERROR: Unable to change to directory '%s'\n", TMPDIR); -# else - if (!IsService) { + #else + if (!IsService) + { MessageBox(NULL, strerror(GetLastError()), - "UnrealIRCD/32: chdir()", MB_OK); + "UnrealIRCD/32: chdir()", MB_OK); } -# endif + #endif exit(-1); } #endif @@ -640,11 +648,14 @@ int InitUnrealIRCd(int argc, char *argv[]) * ** be empty. Flag characters cannot be concatenated (like * ** "-fxyz"), it would conflict with the form "-fstring". */ - while (--argc > 0 && (*++argv)[0] == '-') { + while (--argc > 0 && (*++argv)[0] == '-') + { char *p = argv[0] + 1; - int flag = *p++; - if (flag == '\0' || *p == '\0') { - if (argc > 1 && argv[1][0] != '-') { + int flag = *p++; + if (flag == '\0' || *p == '\0') + { + if (argc > 1 && argv[1][0] != '-') + { p = *++argv; argc -= 1; } else @@ -672,79 +683,81 @@ int InitUnrealIRCd(int argc, char *argv[]) //unrealdb_test(); #endif #ifndef _WIN32 - case 't': - bootopt |= BOOT_TTY; - break; - case 'v': - (void)printf("%s\n", version); + case 't': + bootopt |= BOOT_TTY; + break; + case 'v': + (void)printf("%s\n", version); #else - case 'v': - if (!IsService) { - MessageBox(NULL, version, - "UnrealIRCD/Win32 version", MB_OK); - } + case 'v': + if (!IsService) + { + MessageBox(NULL, version, + "UnrealIRCD/Win32 version", MB_OK); + } #endif - exit(0); - case 'C': - config_verbose = atoi(p); - break; - case 'c': - loop.config_test = 1; - break; - case 'x': -#ifdef DEBUGMODE - debuglevel = atoi(p); - debugmode = *p ? p : "0"; - bootopt |= BOOT_DEBUG; - break; + exit(0); + case 'C': + config_verbose = atoi(p); + break; + case 'c': + loop.config_test = 1; + break; + case 'x': +#ifdef DEBUGMODE + debuglevel = atoi(p); + debugmode = *p ? p : "0"; + bootopt |= BOOT_DEBUG; + break; #else -# ifndef _WIN32 - (void)fprintf(stderr, - "%s: DEBUGMODE must be defined for -x y\n", - myargv[0]); -# else - if (!IsService) { - MessageBox(NULL, - "DEBUGMODE must be defined for -x option", - "UnrealIRCD/32", MB_OK); - } -# endif - exit(0); + #ifndef _WIN32 + (void)fprintf(stderr, + "%s: DEBUGMODE must be defined for -x y\n", + myargv[0]); + #else + if (!IsService) + { + MessageBox(NULL, + "DEBUGMODE must be defined for -x option", + "UnrealIRCD/32", MB_OK); + } + #endif + exit(0); #endif - case 'K': - { - char *p = NULL; - if (chdir(TMPDIR) < 0) - { - fprintf(stderr, "Could not change to directory '%s'\n", TMPDIR); - exit(1); - } - fprintf(stderr, "Starting crash test!\n"); - *p = 'a'; - fprintf(stderr, "It is impossible to get here\n"); - exit(0); - } - case 'R': - report_crash(); - exit(0); + case 'K': + { + char *p = NULL; + if (chdir(TMPDIR) < 0) + { + fprintf(stderr, "Could not change to directory '%s'\n", TMPDIR); + exit(1); + } + fprintf(stderr, "Starting crash test!\n"); + *p = 'a'; + fprintf(stderr, "It is impossible to get here\n"); + exit(0); + } + case 'R': + report_crash(); + exit(0); #ifndef _WIN32 - case 'm': - modulemanager(argc, argv); - exit(0); + case 'm': + modulemanager(argc, argv); + exit(0); #endif - case '8': - utf8_test(); - exit(0); - case 'L': - loop.boot_function = link_generator; - break; - default: + case '8': + utf8_test(); + exit(0); + case 'L': + loop.boot_function = link_generator; + break; + default: #ifndef _WIN32 - return bad_command(myargv[0]); + return bad_command(myargv[0]); #else - return bad_command(NULL); + return bad_command(NULL); #endif - break; + break; } } @@ -755,9 +768,10 @@ int InitUnrealIRCd(int argc, char *argv[]) /* * but asked for debugging output to tty */ - if ((debuglevel < 0) && (bootopt & BOOT_TTY)) { + if ((debuglevel < 0) && (bootopt & BOOT_TTY)) + { (void)fprintf(stderr, - "you specified -t without -x. use -x \n"); + "you specified -t without -x. use -x \n"); exit(-1); } #endif @@ -767,7 +781,7 @@ int InitUnrealIRCd(int argc, char *argv[]) */ #ifndef _WIN32 if (argc > 0) - return bad_command(myargv[0]); /* This should exit out */ + return bad_command(myargv[0]); /* This should exit out */ #endif #ifndef _WIN32 fprintf(stderr, "%s", unreallogo); @@ -783,9 +797,9 @@ int InitUnrealIRCd(int argc, char *argv[]) fprintf(stderr, "UnrealIRCd is using the following libraries:\n"); fprintf(stderr, "* %s\n", SSLeay_version(SSLEAY_VERSION)); fprintf(stderr, "* libsodium %s\n", sodium_version_string()); -#ifdef USE_LIBCURL + #ifdef USE_LIBCURL fprintf(stderr, "* %s\n", curl_version()); -#endif + #endif fprintf(stderr, "* c-ares %s\n", ares_version(NULL)); fprintf(stderr, "* %s\n", pcre2_version()); #endif @@ -796,7 +810,7 @@ int InitUnrealIRCd(int argc, char *argv[]) #ifndef _WIN32 fprintf(stderr, "\n"); fprintf(stderr, "This server can handle %d concurrent sockets (%d clients + %d reserve)\n\n", - maxclients+reserved_fds, maxclients, reserved_fds); + maxclients + reserved_fds, maxclients, reserved_fds); #endif init_CommandHash(); initwhowas(); @@ -892,7 +906,7 @@ int InitUnrealIRCd(int argc, char *argv[]) if (p < 0) { fprintf(stderr, "Could not create background job. Call to fork() failed: %s\n", - strerror(errno)); + strerror(errno)); exit(-1); } if (p > 0) @@ -1002,40 +1016,42 @@ void SocketLoop(void *dummy) */ static void open_debugfile(void) { -#ifdef DEBUGMODE - int fd; +#ifdef DEBUGMODE + int fd; Client *client; - if (debuglevel >= 0) { + if (debuglevel >= 0) + { client = make_client(NULL, NULL); client->local->fd = 2; SetLog(client); client->flags = 0; strlcpy(client->local->sockhost, me.local->sockhost, sizeof client->local->sockhost); -# ifndef _WIN32 + #ifndef _WIN32 /*(void)printf("isatty = %d ttyname = %#x\n", isatty(2), (u_int)ttyname(2)); */ - if (!(bootopt & BOOT_TTY)) { /* leave debugging output on fd 2 */ + if (!(bootopt & BOOT_TTY)) + { /* leave debugging output on fd 2 */ if (truncate(LOGFILE, 0) < 0) fprintf(stderr, "WARNING: could not truncate log file '%s'\n", LOGFILE); if ((fd = open(LOGFILE, O_WRONLY | O_CREAT, 0600)) < 0) if ((fd = open("/dev/null", O_WRONLY)) < 0) exit(-1); -#if 1 + #if 1 client->local->fd = fd; debugfd = fd; -#else - /* if (fd != 2) { + #else + /* if (fd != 2) { (void)dup2(fd, 2); (void)close(fd); } -- hands off stderr! */ -#endif + #endif strlcpy(client->name, LOGFILE, sizeof(client->name)); } else if (isatty(2) && ttyname(2)) strlcpy(client->name, ttyname(2), sizeof(client->name)); else -# endif + #endif strlcpy(client->name, "FD2-Pipe", sizeof(client->name)); } #endif @@ -1050,10 +1066,10 @@ static void setup_signals() (void)sigemptyset(&act.sa_mask); (void)sigaddset(&act.sa_mask, SIGPIPE); (void)sigaddset(&act.sa_mask, SIGALRM); -#ifdef SIGWINCH + #ifdef SIGWINCH (void)sigaddset(&act.sa_mask, SIGWINCH); (void)sigaction(SIGWINCH, &act, NULL); -#endif + #endif (void)sigaction(SIGPIPE, &act, NULL); act.sa_handler = ignore_this_signal; (void)sigaction(SIGALRM, &act, NULL); diff --git a/src/ircd_vars.c b/src/ircd_vars.c index c9668f40c..0641e4e99 100644 --- a/src/ircd_vars.c +++ b/src/ircd_vars.c @@ -15,17 +15,17 @@ struct timeval timeofday_tv; int tainted = 0; LoopStruct loop; MODVAR IRCCounts irccounts; -MODVAR Client me; /* That's me */ +MODVAR Client me; /* That's me */ MODVAR char *me_hash; -char *configfile = NULL; /* Server configuration file */ -int debuglevel = 0; /* Server debug level */ -int bootopt = 0; /* Server boot option flags */ -char *debugmode = ""; /* -"- -"- -"- */ -int dorehash = 0; /**< Rehash server on next socket loop */ -int dorestart = 0; /**< Restart server on next socket loop */ -int doreloadcert = 0; /**< Reload TLS certificate on next socket loop */ -MODVAR int quick_close = 0; /**< Quickly close client connections (1) or be friendly to TLS users (0) */ -MODVAR int connections_past_period=0; /**< Number of new connections past period, used for set::high-connection-rate */ +char *configfile = NULL; /* Server configuration file */ +int debuglevel = 0; /* Server debug level */ +int bootopt = 0; /* Server boot option flags */ +char *debugmode = ""; /* -"- -"- -"- */ +int dorehash = 0; /**< Rehash server on next socket loop */ +int dorestart = 0; /**< Restart server on next socket loop */ +int doreloadcert = 0; /**< Reload TLS certificate on next socket loop */ +MODVAR int quick_close = 0; /**< Quickly close client connections (1) or be friendly to TLS users (0) */ +MODVAR int connections_past_period = 0; /**< Number of new connections past period, used for set::high-connection-rate */ #ifndef _WIN32 char **myargv; #else diff --git a/src/ircsprintf.c b/src/ircsprintf.c index 4e0bcf1b9..eb7ab9696 100644 --- a/src/ircsprintf.c +++ b/src/ircsprintf.c @@ -37,12 +37,13 @@ char *ircvsnprintf(char *str, size_t size, const char *format, va_list vl) { char *str_begin = str; char c; - const char *end = str+size-1; /* for comparison, not dereferencing. It is the last position a null can go. */ + const char *end = str + size - 1; /* for comparison, not dereferencing. It is the last position a null can go. */ char scratch_buffer[32]; /* large enough for 64 bit integer as a string */ - if (!size) return str; + if (!size) + return str; - while (str!=end && (c = *format++)) + while (str != end && (c = *format++)) { if (c == '%') { @@ -51,52 +52,53 @@ char *ircvsnprintf(char *str, size_t size, const char *format, va_list vl) { /* %s - string */ const char *p1 = va_arg(vl, const char *); - while (str!=end && *p1) *str++ = *p1++; + while (str != end && *p1) + *str++ = *p1++; continue; - } - else if (c == 'c') + } else if (c == 'c') { /* %c - single character */ *str++ = (char)va_arg(vl, int); continue; - } - else if (c == 'd' || c == 'i') + } else if (c == 'd' || c == 'i') { /* %d and %i - integer */ char *t; int v = va_arg(vl, int); int i = 0; size_t len; - if (v==0) + if (v == 0) { *str++ = '0'; continue; } t = scratch_buffer + sizeof(scratch_buffer); - if (v<0) + if (v < 0) { *str++ = '-'; - if (str==end) break; + if (str == end) + break; while (v) { - *--t = '0' - (v%10); - v/=10; + *--t = '0' - (v % 10); + v /= 10; } - } else { + } else + { while (v) { - *--t = (v%10) + '0'; - v/=10; + *--t = (v % 10) + '0'; + v /= 10; } } - len = sizeof(scratch_buffer)-(t-scratch_buffer); - if ((str+len)>end) break; + len = sizeof(scratch_buffer) - (t - scratch_buffer); + if ((str + len) > end) + break; for (i = 0; i < len; i++) - *str++=t[i]; + *str++ = t[i]; continue; - } - else if (c == 'l') + } else if (c == 'l') { if (format[0] == 'l' && format[1] == 'd') { @@ -108,33 +110,36 @@ char *ircvsnprintf(char *str, size_t size, const char *format, va_list vl) format += 2; - if (v==0) + if (v == 0) { *str++ = '0'; continue; } t = scratch_buffer + sizeof(scratch_buffer); - if (v<0) + if (v < 0) { *str++ = '-'; - if (str==end) break; + if (str == end) + break; while (v) { - *--t = '0' - (v%10); - v/=10; + *--t = '0' - (v % 10); + v /= 10; } - } else { + } else + { while (v) { - *--t = (v%10) + '0'; - v/=10; + *--t = (v % 10) + '0'; + v /= 10; } } - len = sizeof(scratch_buffer)-(t-scratch_buffer); - if ((str+len)>end) break; + len = sizeof(scratch_buffer) - (t - scratch_buffer); + if ((str + len) > end) + break; for (i = 0; i < len; i++) - *str++=t[i]; + *str++ = t[i]; continue; } if (*format == 'u') @@ -146,7 +151,7 @@ char *ircvsnprintf(char *str, size_t size, const char *format, va_list vl) size_t len; format++; - if (v==0) + if (v == 0) { *str++ = '0'; continue; @@ -155,25 +160,25 @@ char *ircvsnprintf(char *str, size_t size, const char *format, va_list vl) t = scratch_buffer + sizeof(scratch_buffer); while (v) { - *--t = (v%10) + '0'; - v/=10; + *--t = (v % 10) + '0'; + v /= 10; } - len = sizeof(scratch_buffer)-(t-scratch_buffer); - if ((str+len)>end) break; + len = sizeof(scratch_buffer) - (t - scratch_buffer); + if ((str + len) > end) + break; for (i = 0; i < len; i++) - *str++=t[i]; + *str++ = t[i]; continue; } - } - else if (c == 'u') + } else if (c == 'u') { /* %u - unsigned integer */ char *t; unsigned int v = va_arg(vl, unsigned int); int i = 0; size_t len; - if (v==0) + if (v == 0) { *str++ = '0'; continue; @@ -182,30 +187,29 @@ char *ircvsnprintf(char *str, size_t size, const char *format, va_list vl) t = scratch_buffer + sizeof(scratch_buffer); while (v) { - *--t = (v%10) + '0'; - v/=10; + *--t = (v % 10) + '0'; + v /= 10; } - len = sizeof(scratch_buffer)-(t-scratch_buffer); - if ((str+len)>end) break; + len = sizeof(scratch_buffer) - (t - scratch_buffer); + if ((str + len) > end) + break; for (i = 0; i < len; i++) - *str++=t[i]; + *str++ = t[i]; continue; - } - else if (c == '%') + } else if (c == '%') { /* %% - literal percent character */ *str++ = '%'; continue; - } - else if (!c) + } else if (!c) break; /* A % at the end of the format string (illegal, skipped) */ - + /* The default case, when we cannot handle the % format: * Stop what we are doing and pass control to the real vsnprintf() */ format -= 2; - vsnprintf(str, (size_t)(end-str+1), format, vl); + vsnprintf(str, (size_t)(end - str + 1), format, vl); return str_begin; } *str++ = c; @@ -214,7 +218,8 @@ char *ircvsnprintf(char *str, size_t size, const char *format, va_list vl) return str_begin; } -char *ircsnprintf(char *str, size_t size, const char *format, ...) { +char *ircsnprintf(char *str, size_t size, const char *format, ...) +{ va_list vl; char *ret; va_start(vl, format); diff --git a/src/json.c b/src/json.c index 89ea6ca7a..b7f88cf4e 100644 --- a/src/json.c +++ b/src/json.c @@ -52,9 +52,10 @@ json_t *json_string_unreal(const char *s) if (log_json_filter) { - stripped = StripControlCodesEx(s, buf1, sizeof(buf1), UNRL_STRIP_LOW_ASCII|UNRL_STRIP_KEEP_LF); + stripped = StripControlCodesEx(s, buf1, sizeof(buf1), UNRL_STRIP_LOW_ASCII | UNRL_STRIP_KEEP_LF); verified_s = unrl_utf8_make_valid(buf1, buf2, sizeof(buf2), 0); - } else { + } else + { verified_s = unrl_utf8_make_valid(s, buf2, sizeof(buf2), 0); } @@ -140,13 +141,13 @@ const char *timestamp_iso8601_now(void) tm = gmtime(&sec); snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", - tm->tm_year + 1900, - tm->tm_mon + 1, - tm->tm_mday, - tm->tm_hour, - tm->tm_min, - tm->tm_sec, - (int)(t.tv_usec / 1000)); + tm->tm_year + 1900, + tm->tm_mon + 1, + tm->tm_mday, + tm->tm_hour, + tm->tm_min, + tm->tm_sec, + (int)(t.tv_usec / 1000)); return buf; } @@ -165,13 +166,13 @@ const char *timestamp_iso8601(time_t v) return NULL; snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", - tm->tm_year + 1900, - tm->tm_mon + 1, - tm->tm_mday, - tm->tm_hour, - tm->tm_min, - tm->tm_sec, - 0); + tm->tm_year + 1900, + tm->tm_mon + 1, + tm->tm_mday, + tm->tm_hour, + tm->tm_min, + tm->tm_sec, + 0); return buf; } @@ -206,7 +207,7 @@ void json_expand_client_security_groups(json_t *parent, Client *client) */ void json_expand_client(json_t *j, const char *key, Client *client, int detail) { - char buf[BUFSIZE+1]; + char buf[BUFSIZE + 1]; json_t *child; json_t *user = NULL; time_t ts; @@ -216,7 +217,8 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) { child = json_object(); json_object_set_new(j, key, child); - } else { + } else + { child = j; } @@ -253,32 +255,36 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) * but we don't know that, so we assume that is not the case). */ const char *ident; - char temp[USERLEN+1]; + char temp[USERLEN + 1]; if (IDENT_CHECK) { if (IsIdentSuccess(client)) { /* ident succeeded means: use the identd and no ~ prefix */ ident = client->ident; - } else { + } else + { /* ident check failed means ~ prefix */ snprintf(temp, sizeof(temp), "~%s", client->user->username); ident = temp; } - } else { + } else + { /* no ident check means no ~ prefix */ ident = client->user->username; } snprintf(buf, sizeof(buf), "%s!%s@%s", client->name, ident, client->user->realhost); } json_object_set_new(child, "details", json_string_unreal(buf)); - } else if (client->ip) { + } else if (client->ip) + { if (*client->name) snprintf(buf, sizeof(buf), "%s@%s", client->name, client->ip); else snprintf(buf, sizeof(buf), "[%s]", client->ip); json_object_set_new(child, "details", json_string_unreal(buf)); - } else { + } else + { json_object_set_new(child, "details", json_string_unreal(client->name)); } @@ -332,7 +338,7 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) /* user modes and snomasks */ get_usermode_string_r(client, buf, sizeof(buf)); - json_object_set_new(user, "modes", json_string_unreal(buf+1)); + json_object_set_new(user, "modes", json_string_unreal(buf + 1)); if (client->user->snomask) json_object_set_new(user, "snomasks", json_string_unreal(client->user->snomask)); @@ -370,7 +376,8 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) } json_array_append_new(channels, json_string_unreal(m->channel->name)); } - } else { + } else + { /* Long format for JSON-RPC */ for (m = client->user->channel; m; m = m->next) { @@ -383,8 +390,7 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) } } RunHook(HOOKTYPE_JSON_EXPAND_CLIENT_USER, client, detail, child, user); - } else - if (IsMe(client)) + } else if (IsMe(client)) { json_t *server = json_object(); json_t *features; @@ -419,14 +425,13 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) /* first one is special - wait.. is this still the case? lol. */ snprintf(buf, sizeof(buf), "%s%s", CHPAR1, EXPAR1); json_array_append_new(chanmodes, json_string_unreal(buf)); - for (i=1; i < 4; i++) + for (i = 1; i < 4; i++) json_array_append_new(chanmodes, json_string_unreal(extchmstr[i])); } if (!BadPtr(client->server->features.nickchars)) json_object_set_new(features, "nick_character_sets", json_string_unreal(charsys_get_current_languages())); RunHook(HOOKTYPE_JSON_EXPAND_CLIENT_SERVER, client, detail, child, server); - } else - if (IsServer(client) && client->server) + } else if (IsServer(client) && client->server) { /* client.server */ @@ -461,7 +466,7 @@ void json_expand_client(json_t *j, const char *key, Client *client, int detail) int i; json_t *chanmodes = json_array(); json_object_set_new(features, "chanmodes", chanmodes); - for (i=0; i < 4; i++) + for (i = 0; i < 4; i++) json_array_append_new(chanmodes, json_string_unreal(client->server->features.chanmodes[i])); } if (!BadPtr(client->server->features.nickchars)) @@ -502,7 +507,8 @@ void json_expand_channel(json_t *j, const char *key, Channel *channel, int detai { child = json_object(); json_object_set_new(j, key, child); - } else { + } else + { child = j; } @@ -523,10 +529,11 @@ void json_expand_channel(json_t *j, const char *key, Channel *channel, int detai channel_modes(NULL, mode1, mode2, sizeof(mode1), sizeof(mode2), channel, 0); if (*mode2) { - snprintf(modes, sizeof(modes), "%s %s", mode1+1, mode2); + snprintf(modes, sizeof(modes), "%s %s", mode1 + 1, mode2); json_object_set_new(child, "modes", json_string_unreal(modes)); - } else { - json_object_set_new(child, "modes", json_string_unreal(mode1+1)); + } else + { + json_object_set_new(child, "modes", json_string_unreal(mode1 + 1)); } if (detail > 1) @@ -547,7 +554,7 @@ void json_expand_channel(json_t *j, const char *key, Channel *channel, int detai json_t *e = json_object(); if (*u->member_modes) json_object_set_new(e, "level", json_string_unreal(u->member_modes)); - json_expand_client(e, NULL, u->client, detail-3); + json_expand_client(e, NULL, u->client, detail - 3); json_array_append_new(list, e); } } @@ -565,7 +572,8 @@ void json_expand_tkl(json_t *root, const char *key, TKL *tkl, int detail) { j = json_object(); json_object_set_new(root, key, j); - } else { + } else + { j = root; } @@ -584,7 +592,8 @@ void json_expand_tkl(json_t *root, const char *key, TKL *tkl, int detail) { json_object_set_new(j, "expire_at_string", json_string_unreal("Never")); json_object_set_new(j, "duration_string", json_string_unreal("permanent")); - } else { + } else + { *buf = '\0'; short_date(tkl->expire_at, buf); strlcat(buf, " GMT", sizeof(buf)); @@ -605,15 +614,13 @@ void json_expand_tkl(json_t *root, const char *key, TKL *tkl, int detail) json_object_set_new(j, "spamfilter_id", json_string_unreal(tkl->spamfilter_id)); json_object_set_new(j, "hits", json_integer(tkl->hits)); json_object_set_new(j, "last_hit_at", json_timestamp(tkl->lasthit)); - } else - if (TKLIsNameBan(tkl)) + } else if (TKLIsNameBan(tkl)) { json_object_set_new(j, "name", json_string_unreal(tkl->ptr.nameban->name)); json_object_set_new(j, "reason", json_string_unreal(tkl->ptr.nameban->reason)); json_object_set_new(j, "hits", json_integer(tkl->hits)); json_object_set_new(j, "last_hit_at", json_timestamp(tkl->lasthit)); - } else - if (TKLIsBanException(tkl)) + } else if (TKLIsBanException(tkl)) { if (tkl->ptr.banexception->match) json_expand_security_group(j, "match", tkl->ptr.banexception->match, 1); @@ -621,8 +628,7 @@ void json_expand_tkl(json_t *root, const char *key, TKL *tkl, int detail) json_object_set_new(j, "name", json_string_unreal(tkl_uhost(tkl, buf, sizeof(buf), 0))); json_object_set_new(j, "reason", json_string_unreal(tkl->ptr.banexception->reason)); json_object_set_new(j, "exception_types", json_string_unreal(tkl->ptr.banexception->bantypes)); - } else - if (TKLIsSpamfilter(tkl)) + } else if (TKLIsSpamfilter(tkl)) { if (tkl->ptr.spamfilter->match->str) { @@ -655,7 +661,8 @@ void json_expand_textanalysis(json_t *root, const char *key, TextAnalysis *ta, i { j = json_object(); json_object_set_new(root, key, j); - } else { + } else + { j = root; } @@ -667,7 +674,7 @@ void json_expand_textanalysis(json_t *root, const char *key, TextAnalysis *ta, i blk = json_object(); json_object_set_new(j, "unicode_blockmap", blk); - for (i=0; i < UNICODE_BLOCK_COUNT; i++) + for (i = 0; i < UNICODE_BLOCK_COUNT; i++) { if (ta->unicode_blockmap[i]) json_object_set_new(blk, utf8_get_block_name(i), json_integer(ta->unicode_blockmap[i])); @@ -807,8 +814,7 @@ void json_expand_security_group(json_t *j, const char *key, SecurityGroup *s, in { child = json_object(); json_object_set_new(j, key, child); - } - else + } else { child = j; } diff --git a/src/list.c b/src/list.c index 5e735a11c..a39ae1b7e 100644 --- a/src/list.c +++ b/src/list.c @@ -23,35 +23,34 @@ void free_link(Link *); Link *make_link(); -ID_Copyright - ("(C) 1988 University of Oulu, Computing Center and Jarkko Oikarinen"); +ID_Copyright("(C) 1988 University of Oulu, Computing Center and Jarkko Oikarinen"); ID_Notes("2.24 4/20/94"); -#ifdef DEBUGMODE +#ifdef DEBUGMODE static struct liststats { - int inuse; + int inuse; } cloc, crem, users, servs, links; #endif -MODVAR int flinks = 0; -MODVAR int freelinks = 0; +MODVAR int flinks = 0; +MODVAR int freelinks = 0; MODVAR Link *freelink = NULL; MODVAR Member *freemember = NULL; MODVAR Membership *freemembership = NULL; -MODVAR int numclients = 0; +MODVAR int numclients = 0; // TODO: Document whether servers are included or excluded in these lists... -MODVAR struct list_head unknown_list; /**< Local clients in handshake (may become a user or server later) */ -MODVAR struct list_head control_list; /**< Local "control channel" clients */ -MODVAR struct list_head lclient_list; /**< Local clients (users only, right?) */ -MODVAR struct list_head client_list; /**< All clients - local and remote (not in handshake) */ -MODVAR struct list_head server_list; /**< Locally connected servers */ -MODVAR struct list_head oper_list; /**< Locally connected IRC Operators */ -MODVAR struct list_head global_server_list; /**< All servers (local and remote) */ -MODVAR struct list_head dead_list; /**< All dead clients (local and remote) that will soon be freed in the main loop */ -MODVAR struct list_head rpc_remote_list; /**< All remote RPC clients (very specific use-case) */ +MODVAR struct list_head unknown_list; /**< Local clients in handshake (may become a user or server later) */ +MODVAR struct list_head control_list; /**< Local "control channel" clients */ +MODVAR struct list_head lclient_list; /**< Local clients (users only, right?) */ +MODVAR struct list_head client_list; /**< All clients - local and remote (not in handshake) */ +MODVAR struct list_head server_list; /**< Locally connected servers */ +MODVAR struct list_head oper_list; /**< Locally connected IRC Operators */ +MODVAR struct list_head global_server_list; /**< All servers (local and remote) */ +MODVAR struct list_head dead_list; /**< All dead clients (local and remote) that will soon be freed in the main loop */ +MODVAR struct list_head rpc_remote_list; /**< All remote RPC clients (very specific use-case) */ static mp_pool_t *client_pool = NULL; static mp_pool_t *local_client_pool = NULL; @@ -60,7 +59,7 @@ static mp_pool_t *link_pool = NULL; void initlists(void) { -#ifdef DEBUGMODE +#ifdef DEBUGMODE memset(&cloc, 0, sizeof(cloc)); memset(&crem, 0, sizeof(crem)); memset(&users, 0, sizeof(users)); @@ -99,7 +98,7 @@ Client *make_client(Client *from, Client *servr) Client *client = mp_pool_get(client_pool); memset(client, 0, sizeof(Client)); -#ifdef DEBUGMODE +#ifdef DEBUGMODE if (!from) cloc.inuse++; else @@ -107,7 +106,7 @@ Client *make_client(Client *from, Client *servr) #endif /* Note: all fields are already NULL/0, no need to set here */ - client->direction = from ? from : client; /* 'from' of local client is self! */ + client->direction = from ? from : client; /* 'from' of local client is self! */ client->uplink = servr; client->status = CLIENT_STATUS_UNKNOWN; @@ -120,16 +119,16 @@ Client *make_client(Client *from, Client *servr) { /* Local client */ const char *id; - + client->local = mp_pool_get(local_client_pool); memset(client->local, 0, sizeof(LocalClient)); - + INIT_LIST_HEAD(&client->lclient_node); INIT_LIST_HEAD(&client->special_node); client->local->fake_lag = client->local->last_msg_received = - client->lastnick = client->local->creationtime = - client->local->idle_since = TStime(); + client->lastnick = client->local->creationtime = + client->local->idle_since = TStime(); client->local->class = NULL; client->local->passwd = NULL; client->local->sockhost[0] = '\0'; @@ -196,7 +195,7 @@ void free_client(Client *client) dbuf_delete(&client->local->recvQ, DBufLength(&client->local->recvQ)); dbuf_delete(&client->local->sendQ, DBufLength(&client->local->sendQ)); free_all_tags(client); - + mp_pool_release(client->local); } if (*client->id) @@ -232,7 +231,7 @@ User *make_user(Client *client) memset(user, 0, sizeof(User)); client->user = user; -#ifdef DEBUGMODE +#ifdef DEBUGMODE users.inuse++; #endif @@ -253,7 +252,8 @@ User *make_user(Client *client) { /* initially set client->user->realhost to IP */ strlcpy(user->realhost, client->ip, sizeof(user->realhost)); - } else { + } else + { *user->realhost = '\0'; } /* These may change later (eg when using hostname instead of IP), @@ -272,7 +272,7 @@ Server *make_server(Client *client) if (!serv) { serv = safe_alloc(sizeof(Server)); -#ifdef DEBUGMODE +#ifdef DEBUGMODE servs.inuse++; #endif *serv->by = '\0'; @@ -316,7 +316,7 @@ void free_user(Client *client) safe_free(client->user->operlogin); safe_free(client->user->snomask); mp_pool_release(client->user); -#ifdef DEBUGMODE +#ifdef DEBUGMODE users.inuse--; #endif client->user = NULL; @@ -355,17 +355,15 @@ void remove_client_from_list(Client *client) if (client->uplink && client->uplink->server) client->uplink->server->users--; } - if (IsUnknown(client) || IsConnecting(client) || IsHandshake(client) - || IsTLSHandshake(client) - ) + if (IsUnknown(client) || IsConnecting(client) || IsHandshake(client) || IsTLSHandshake(client)) irccounts.unknown--; - if (IsUser(client)) /* Only persons can have been added before */ + if (IsUser(client)) /* Only persons can have been added before */ { add_history(client, 0, WHOWAS_EVENT_QUIT); - off_history(client); /* Remove all pointers to client */ + off_history(client); /* Remove all pointers to client */ } - + if (client->user) free_user(client); if (client->server) @@ -378,11 +376,11 @@ void remove_client_from_list(Client *client) safe_free(client->server->features.software); safe_free(client->server->features.nickchars); safe_free(client->server); -#ifdef DEBUGMODE +#ifdef DEBUGMODE servs.inuse--; #endif } -#ifdef DEBUGMODE +#ifdef DEBUGMODE if (client->local && client->local->fd == -2) cloc.inuse--; else @@ -422,7 +420,7 @@ Link *make_link(void) { Link *l = mp_pool_get(link_pool); memset(l, 0, sizeof(Link)); -#ifdef DEBUGMODE +#ifdef DEBUGMODE links.inuse++; #endif return l; @@ -433,7 +431,7 @@ void free_link(Link *lp) { mp_pool_release(lp); -#ifdef DEBUGMODE +#ifdef DEBUGMODE links.inuse--; #endif } @@ -441,7 +439,7 @@ void free_link(Link *lp) /** Returns the length (entry count) of a +beI list */ int link_list_length(Link *lp) { - int count = 0; + int count = 0; for (; lp; lp = lp->next) count++; @@ -453,7 +451,7 @@ Ban *make_ban(void) Ban *lp; lp = safe_alloc(sizeof(Ban)); -#ifdef DEBUGMODE +#ifdef DEBUGMODE links.inuse++; #endif return lp; @@ -462,7 +460,7 @@ Ban *make_ban(void) void free_ban(Ban *lp) { safe_free(lp); -#ifdef DEBUGMODE +#ifdef DEBUGMODE links.inuse--; #endif } @@ -489,7 +487,8 @@ void append_ListItem(ListStruct *item, ListStruct **list) return; } - for (l = *list; l->next; l = l->next); + for (l = *list; l->next; l = l->next) + ; l->next = item; item->prev = l; } @@ -516,14 +515,14 @@ void del_ListItem(ListStruct *item, ListStruct **list) void add_ListItemPrio(ListStructPrio *new, ListStructPrio **list, int priority) { ListStructPrio *x, *last = NULL; - + if (!*list) { /* We are the only item. Easy. */ *list = new; return; } - + for (x = *list; x; x = x->next) { last = x; @@ -540,7 +539,8 @@ void add_ListItemPrio(ListStructPrio *new, ListStructPrio **list, int priority) new->next = x; x->prev->next = new; x->prev = new; - } else { + } else + { /* We are the new head */ *list = new; new->next = x; @@ -558,14 +558,14 @@ void add_ListItemPrio(ListStructPrio *new, ListStructPrio **list, int priority) void _add_name_list(NameList **list, const char *name) { - NameList *e = safe_alloc(sizeof(NameList)+strlen(name)+1); + NameList *e = safe_alloc(sizeof(NameList) + strlen(name) + 1); strcpy(e->name, name); /* safe, allocated above */ AddListItem(e, *list); } void _append_name_list(NameList **list, const char *name) { - NameList *e = safe_alloc(sizeof(NameList)+strlen(name)+1); + NameList *e = safe_alloc(sizeof(NameList) + strlen(name) + 1); strcpy(e->name, name); /* safe, allocated above */ AppendListItem(e, *list); } @@ -588,7 +588,7 @@ NameList *duplicate_name_list(NameList *e) /* We do manual pointer tracking here to speed things up */ for (; e; e = e->next) { - n = safe_alloc(sizeof(NameList)+strlen(e->name)+1); + n = safe_alloc(sizeof(NameList) + strlen(e->name) + 1); strcpy(n->name, e->name); /* safe, allocated above */ if (tail) tail->next = n; @@ -739,34 +739,35 @@ NameValuePrioList *duplicate_nvplist_append(NameValuePrioList *e, NameValuePrioL return *list; } -#define nv_find_by_name(stru, name) do_nv_find_by_name(stru, name, ARRAY_SIZEOF((stru))) +#define nv_find_by_name(stru, name) do_nv_find_by_name(stru, name, ARRAY_SIZEOF((stru))) long do_nv_find_by_name(NameValue *table, const char *cmd, int numelements) { int start = 0; - int stop = numelements-1; + int stop = numelements - 1; int mid; - while (start <= stop) { - mid = (start+stop)/2; + while (start <= stop) + { + mid = (start + stop) / 2; - if (smycmp(cmd,table[mid].name) < 0) { - stop = mid-1; - } - else if (strcmp(cmd,table[mid].name) == 0) { + if (smycmp(cmd, table[mid].name) < 0) + { + stop = mid - 1; + } else if (strcmp(cmd, table[mid].name) == 0) + { return table[mid].value; - } - else - start = mid+1; + } else + start = mid + 1; } return 0; } -#define nv_find_by_value(stru, value) do_nv_find_by_value(stru, value, ARRAY_SIZEOF((stru))) +#define nv_find_by_value(stru, value) do_nv_find_by_value(stru, value, ARRAY_SIZEOF((stru))) const char *do_nv_find_by_value(NameValue *table, long value, int numelements) { int i; - for (i=0; i < numelements; i++) + for (i = 0; i < numelements; i++) if (table[i].value == value) return table[i].name; diff --git a/src/log.c b/src/log.c index 8b9bc63a1..745ddf643 100644 --- a/src/log.c +++ b/src/log.c @@ -30,7 +30,7 @@ // TODO: Make configurable at compile time (runtime won't do, as we haven't read the config file) #define show_event_console 0 -#define MAXLOGLENGTH 16384 /**< Maximum length of a log entry (which may be multiple lines) */ +#define MAXLOGLENGTH 16384 /**< Maximum length of a log entry (which may be multiple lines) */ #define LOG_THROTTLE_TABLE_SIZE 256 typedef struct LogThrottleEntry LogThrottleEntry; @@ -47,12 +47,12 @@ struct LogThrottleEntry { }; /* Variables */ -Log *logs[NUM_LOG_DESTINATIONS] = { NULL, NULL, NULL, NULL, NULL, NULL }; -Log *temp_logs[NUM_LOG_DESTINATIONS] = { NULL, NULL, NULL, NULL, NULL, NULL }; +Log *logs[NUM_LOG_DESTINATIONS] = {NULL, NULL, NULL, NULL, NULL, NULL}; +Log *temp_logs[NUM_LOG_DESTINATIONS] = {NULL, NULL, NULL, NULL, NULL, NULL}; static int snomask_num_destinations = 0; -static char snomasks_in_use[257] = { '\0' }; -static char snomasks_in_use_testing[257] = { '\0' }; +static char snomasks_in_use[257] = {'\0'}; +static char snomasks_in_use_testing[257] = {'\0'}; LogEntry *memory_log = NULL; /**< Log entries in memory (OLDEST entry) */ LogEntry *memory_log_tail = NULL; /**< Tail of log entries in memory (NEWEST entry) */ @@ -81,7 +81,7 @@ LogType log_type_stringtoval(const char *str) const char *log_type_valtostring(LogType v) { - switch(v) + switch (v) { case LOG_TYPE_TEXT: return "text"; @@ -119,7 +119,7 @@ LogSource *add_log_source(const char *str) if (*str == '!') { negative = 1; - strlcpy(buf, str+1, sizeof(buf)); + strlcpy(buf, str + 1, sizeof(buf)); } else { strlcpy(buf, str, sizeof(buf)); @@ -142,8 +142,7 @@ LogSource *add_log_source(const char *str) if (isupper(*p)) { event_id = p; - } else - if (loglevel == ULOG_INVALID) + } else if (loglevel == ULOG_INVALID) { loglevel = log_level_stringtoval(p); if ((loglevel == ULOG_INVALID) && !subsystem) @@ -195,8 +194,7 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) /* TODO: Validate the sources lightly for formatting issues */ any_sources = 1; } - } else - if (!strcmp(ce->name, "destination")) + } else if (!strcmp(ce->name, "destination")) { for (cep = ce->items; cep; cep = cep->next) { @@ -209,17 +207,16 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) { config_error_blank(cep->file->filename, cep->line_number, "set::logging::snomask"); errors++; - } else - if ((strlen(cep->value) != 1) || !(islower(cep->value[0]) || isupper(cep->value[0]))) + } else if ((strlen(cep->value) != 1) || !(islower(cep->value[0]) || isupper(cep->value[0]))) { config_error("%s:%d: snomask must be a single letter", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; - } else { + } else + { strlcat(snomasks_in_use_testing, cep->value, sizeof(snomasks_in_use_testing)); } - } else - if (!strcmp(cep->name, "channel")) + } else if (!strcmp(cep->name, "channel")) { destinations++; /* We need to validate the parameter here as well */ @@ -227,11 +224,10 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) { config_error_blank(cep->file->filename, cep->line_number, "set::logging::channel"); errors++; - } else - if (!valid_channelname(cep->value)) + } else if (!valid_channelname(cep->value)) { config_error("%s:%d: Invalid channel name '%s'", - cep->file->filename, cep->line_number, cep->value); + cep->file->filename, cep->line_number, cep->value); errors++; } for (cepp = cep->items; cepp; cepp = cepp->next) @@ -250,8 +246,7 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) errors++; } } - } else - if (!strcmp(cep->name, "file")) + } else if (!strcmp(cep->name, "file")) { destinations++; if (!cep->value) @@ -268,24 +263,23 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) if (!cepp->value) { config_error_empty(cepp->file->filename, - cepp->line_number, "log", cepp->name); + cepp->line_number, "log", cepp->name); errors++; continue; } if (!log_type_stringtoval(cepp->value)) { config_error("%s:%i: unknown log type '%s'", - cepp->file->filename, cepp->line_number, - cepp->value); + cepp->file->filename, cepp->line_number, + cepp->value); errors++; } - } else - if (!strcmp(cepp->name, "maxsize") || !strcmp(cepp->name, "max-size")) + } else if (!strcmp(cepp->name, "maxsize") || !strcmp(cepp->name, "max-size")) { if (!cepp->value) { config_error_empty(cepp->file->filename, - cepp->line_number, "log", cepp->name); + cepp->line_number, "log", cepp->name); errors++; } } else @@ -294,12 +288,10 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) errors++; } } - } else - if (!strcmp(cep->name, "remote")) + } else if (!strcmp(cep->name, "remote")) { destinations++; - } else - if (!strcmp(cep->name, "syslog")) + } else if (!strcmp(cep->name, "syslog")) { destinations++; for (cepp = cep->items; cepp; cepp = cepp->next) @@ -309,15 +301,15 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) if (!cepp->value) { config_error_empty(cepp->file->filename, - cepp->line_number, "log", cepp->name); + cepp->line_number, "log", cepp->name); errors++; continue; } if (!log_type_stringtoval(cepp->value)) { config_error("%s:%i: unknown log type '%s'", - cepp->file->filename, cepp->line_number, - cepp->value); + cepp->file->filename, cepp->line_number, + cepp->value); errors++; } } else @@ -326,8 +318,7 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) errors++; } } - } else - if (!strcmp(cep->name, "memory")) + } else if (!strcmp(cep->name, "memory")) { destinations++; for (cepp = cep->items; cepp; cepp = cepp->next) @@ -337,16 +328,15 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) if (!cepp->value) { config_error_empty(cepp->file->filename, - cepp->line_number, "log", cepp->name); + cepp->line_number, "log", cepp->name); errors++; } - } else - if (!strcmp(cepp->name, "max-time")) + } else if (!strcmp(cepp->name, "max-time")) { if (!cepp->value) { config_error_empty(cepp->file->filename, - cepp->line_number, "log", cepp->name); + cepp->line_number, "log", cepp->name); errors++; } } else @@ -361,12 +351,12 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) if (!cep->value) { config_error("%s:%i: webhook needs a url", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } else if (strncmp(cep->value, "http://", 7) != 0 && strncmp(cep->value, "https://", 8) != 0) { config_error("%s:%i: webhook url must be a HTTP/HTTPS URL (%s)", - cep->file->filename, cep->line_number, cep->value); + cep->file->filename, cep->line_number, cep->value); errors++; } } else @@ -399,19 +389,19 @@ int config_test_log(ConfigFile *conf, ConfigEntry *block) if (!any_sources) { config_error("%s:%d: log block contains no sources. Old log block perhaps?", - block->file->filename, block->line_number); + block->file->filename, block->line_number); errors++; } if (destinations == 0) { config_error("%s:%d: log block contains no destinations. Old log block perhaps?", - block->file->filename, block->line_number); + block->file->filename, block->line_number); errors++; } if (destinations > 1) { config_error("%s:%d: log block contains multiple destinations. This is not support... YET!", - block->file->filename, block->line_number); + block->file->filename, block->line_number); errors++; } return errors; @@ -458,8 +448,7 @@ int config_run_log(ConfigFile *conf, ConfigEntry *block) AddListItem(log, temp_logs[LOG_DEST_OPER]); else AddListItem(log, temp_logs[LOG_DEST_SNOMASK]); - } else - if (!strcmp(cep->name, "channel")) + } else if (!strcmp(cep->name, "channel")) { Log *log = safe_alloc(sizeof(Log)); strlcpy(log->destination, cep->value, sizeof(log->destination)); /* destination is the channel */ @@ -482,15 +471,13 @@ int config_run_log(ConfigFile *conf, ConfigEntry *block) else if (!strcmp(cepp->name, "oper-only")) log->oper_only = config_checkval(cepp->value, CFG_YESNO); } - } else - if (!strcmp(cep->name, "remote")) + } else if (!strcmp(cep->name, "remote")) { Log *log = safe_alloc(sizeof(Log)); /* destination stays empty */ log->sources = sources; AddListItem(log, temp_logs[LOG_DEST_REMOTE]); - } else - if (!strcmp(cep->name, "file") || !strcmp(cep->name, "syslog")) + } else if (!strcmp(cep->name, "file") || !strcmp(cep->name, "syslog")) { Log *log; @@ -506,9 +493,9 @@ int config_run_log(ConfigFile *conf, ConfigEntry *block) (log->filefmt && !strcmp(log->filefmt, cep->value))) { config_warn("%s:%d: Ignoring duplicate log block for file '%s'. " - "You cannot have multiple log blocks logging to the same file.", - cep->file->filename, cep->line_number, - cep->value); + "You cannot have multiple log blocks logging to the same file.", + cep->file->filename, cep->line_number, + cep->value); free_log_sources(sources); return 0; } @@ -528,22 +515,20 @@ int config_run_log(ConfigFile *conf, ConfigEntry *block) { if (!strcmp(cepp->name, "maxsize") || !strcmp(cepp->name, "max-size")) { - log->max_size = config_checkval(cepp->value,CFG_SIZE); - } - else if (!strcmp(cepp->name, "type")) + log->max_size = config_checkval(cepp->value, CFG_SIZE); + } else if (!strcmp(cepp->name, "type")) { log->type = log_type_stringtoval(cepp->value); } } AddListItem(log, temp_logs[LOG_DEST_DISK]); - } else - if (!strcmp(cep->name, "memory")) + } else if (!strcmp(cep->name, "memory")) { if (temp_logs[LOG_DEST_MEMORY]) { config_warn("%s:%d: Ignoring duplicate log block for memory. " - "You cannot have multiple log blocks logging to memory.", - cep->file->filename, cep->line_number); + "You cannot have multiple log blocks logging to memory.", + cep->file->filename, cep->line_number); free_log_sources(sources); return 0; } @@ -555,16 +540,14 @@ int config_run_log(ConfigFile *conf, ConfigEntry *block) { if (!strcmp(cepp->name, "max-lines")) { - log->max_lines = config_checkval(cepp->value,CFG_SIZE); - } - else if (!strcmp(cepp->name, "max-time")) + log->max_lines = config_checkval(cepp->value, CFG_SIZE); + } else if (!strcmp(cepp->name, "max-time")) { - log->max_time = config_checkval(cepp->value,CFG_TIME); + log->max_time = config_checkval(cepp->value, CFG_TIME); } } AddListItem(log, temp_logs[LOG_DEST_MEMORY]); - } else - if (!strcmp(cep->name, "webhook")) + } else if (!strcmp(cep->name, "webhook")) { Log *log = safe_alloc(sizeof(Log)); safe_strdup(log->url, cep->value); @@ -730,7 +713,8 @@ LogData *log_data_tls_error(void) json_object_set_new(j, "error_stack", error_stack); *all_errors = '\0'; - do { + do + { json_t *obj; e = ERR_get_error(); @@ -750,7 +734,7 @@ LogData *log_data_tls_error(void) } strlcat(all_errors, buf, sizeof(all_errors)); strlcat(all_errors, "\n", sizeof(all_errors)); - } while(e); + } while (e); json_object_set_new(j, "all", json_string_unreal(all_errors)); @@ -829,7 +813,7 @@ void log_data_free(LogData *d) const char *log_level_valtostring(LogLevel loglevel) { - switch(loglevel) + switch (loglevel) { case ULOG_DEBUG: return "debug"; @@ -849,23 +833,23 @@ const char *log_level_valtostring(LogLevel loglevel) } static NameValue log_colors_irc[] = { - { ULOG_INVALID, "\0030,01" }, - { ULOG_DEBUG, "\0030,01" }, - { ULOG_INFO, "\00303" }, - { ULOG_ADVICE, "\00312" }, - { ULOG_WARNING, "\00307" }, - { ULOG_ERROR, "\00304" }, - { ULOG_FATAL, "\00313" }, + {ULOG_INVALID, "\0030,01"}, + {ULOG_DEBUG, "\0030,01"}, + {ULOG_INFO, "\00303"}, + {ULOG_ADVICE, "\00312"}, + {ULOG_WARNING, "\00307"}, + {ULOG_ERROR, "\00304"}, + {ULOG_FATAL, "\00313"}, }; static NameValue log_colors_terminal[] = { - { ULOG_INVALID, "\033[90m" }, - { ULOG_DEBUG, "\033[37m" }, - { ULOG_INFO, "\033[92m" }, - { ULOG_ADVICE, "\033[94m" }, - { ULOG_WARNING, "\033[93m" }, - { ULOG_ERROR, "\033[91m" }, - { ULOG_FATAL, "\033[95m" }, + {ULOG_INVALID, "\033[90m"}, + {ULOG_DEBUG, "\033[37m"}, + {ULOG_INFO, "\033[92m"}, + {ULOG_ADVICE, "\033[94m"}, + {ULOG_WARNING, "\033[93m"}, + {ULOG_ERROR, "\033[91m"}, + {ULOG_FATAL, "\033[95m"}, }; const char *log_level_irc_color(LogLevel loglevel) @@ -895,8 +879,8 @@ LogLevel log_level_stringtoval(const char *str) return ULOG_INVALID; } -#define valideventidcharacter(x) (isupper((x)) || isdigit((x)) || ((x) == '_')) -#define validsubsystemcharacter(x) (islower((x)) || isdigit((x)) || ((x) == '_') || ((x) == '-')) +#define valideventidcharacter(x) (isupper((x)) || isdigit((x)) || ((x) == '_')) +#define validsubsystemcharacter(x) (islower((x)) || isdigit((x)) || ((x) == '_') || ((x) == '-')) int valid_event_id(const char *s) { @@ -978,7 +962,8 @@ void buildlogstring(const char *inbuf, char *outbuf, size_t len, json_t *details } /* find termination */ - for (p=i; validvarcharacter(*p) || ((*p == '.') && validvarcharacter(p[1])); p++); + for (p = i; validvarcharacter(*p) || ((*p == '.') && validvarcharacter(p[1])); p++) + ; /* find variable name in list */ strlncpy(varname, i, sizeof(varname), p - i); @@ -992,25 +977,24 @@ void buildlogstring(const char *inbuf, char *outbuf, size_t len, json_t *details if (varp) { char *varpp; - do { - varpp = strchr(varp+1, '.'); + do + { + varpp = strchr(varp + 1, '.'); if (varpp) *varpp = '\0'; /* Fetch explicit object.key */ - t = json_object_get(t, varp+1); + t = json_object_get(t, varp + 1); varp = varpp; - } while(t && varpp); + } while (t && varpp); if (t) output = json_get_value(t); - } else - if (!strcmp(varname, "socket_error")) + } else if (!strcmp(varname, "socket_error")) { /* Fetch socket_error.error_string */ t = json_object_get(t, "error_string"); if (t) output = json_get_value(t); - } else - if (json_is_object(t)) + } else if (json_is_object(t)) { /* Fetch object.name */ t = json_object_get(t, "name"); @@ -1038,8 +1022,7 @@ void buildlogstring(const char *inbuf, char *outbuf, size_t len, json_t *details if (left <= 0) return; /* return - don't write \0 to 'o'. ensured by strlcpy already */ o += strlen(output); /* value entirely written */ - } else - if (opt) + } else if (opt) { /* Optional field that is empty: show nothing and eat a * preceding space. */ @@ -1056,7 +1039,7 @@ void buildlogstring(const char *inbuf, char *outbuf, size_t len, json_t *details i = p - 1; continue; } -literal: + literal: if (!left) break; *o++ = *i; @@ -1090,7 +1073,7 @@ void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *ev { #ifdef _WIN32 if (show_event_console) - win_log("* %s.%s%s [%s] %s\n", subsystem, event_id, m->next?"+":"", log_level_valtostring(loglevel), m->line); + win_log("* %s.%s%s [%s] %s\n", subsystem, event_id, m->next ? "+" : "", log_level_valtostring(loglevel), m->line); else win_log("* [%s] %s\n", log_level_valtostring(loglevel), m->line); #else @@ -1099,17 +1082,19 @@ void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *ev if (show_event_console) { fprintf(stderr, "%s%s.%s%s %s[%s]%s %s\n", - log_level_terminal_color(ULOG_INVALID), subsystem, event_id, TERMINAL_COLOR_RESET, - log_level_terminal_color(loglevel), log_level_valtostring(loglevel), TERMINAL_COLOR_RESET, - m->line); - } else { + log_level_terminal_color(ULOG_INVALID), subsystem, event_id, TERMINAL_COLOR_RESET, + log_level_terminal_color(loglevel), log_level_valtostring(loglevel), TERMINAL_COLOR_RESET, + m->line); + } else + { fprintf(stderr, "%s[%s]%s %s\n", - log_level_terminal_color(loglevel), log_level_valtostring(loglevel), TERMINAL_COLOR_RESET, - m->line); + log_level_terminal_color(loglevel), log_level_valtostring(loglevel), TERMINAL_COLOR_RESET, + m->line); } - } else { + } else + { if (show_event_console) - fprintf(stderr, "%s.%s%s [%s] %s\n", subsystem, event_id, m->next?"+":"", log_level_valtostring(loglevel), m->line); + fprintf(stderr, "%s.%s%s [%s] %s\n", subsystem, event_id, m->next ? "+" : "", log_level_valtostring(loglevel), m->line); else fprintf(stderr, "[%s] %s\n", log_level_valtostring(loglevel), m->line); } @@ -1132,11 +1117,10 @@ void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *ev if (l->type == LOG_TYPE_JSON) { syslog(LOG_INFO, "%s", json_serialized); - } else - if (l->type == LOG_TYPE_TEXT) + } else if (l->type == LOG_TYPE_TEXT) { for (m = msg; m; m = m->next) - syslog(LOG_INFO, "%s.%s%s %s: %s", subsystem, event_id, m->next?"+":"", log_level_valtostring(loglevel), m->line); + syslog(LOG_INFO, "%s.%s%s %s: %s", subsystem, event_id, m->next ? "+" : "", log_level_valtostring(loglevel), m->line); } continue; } @@ -1162,7 +1146,7 @@ void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *ev if (l->logfd == -1) { /* Try to open, so we can write the 'Max file size reached' message. */ - l->logfd = fd_fileopen(l->file, O_CREAT|O_APPEND|O_WRONLY); + l->logfd = fd_fileopen(l->file, O_CREAT | O_APPEND | O_WRONLY); } if (l->logfd != -1) { @@ -1186,14 +1170,14 @@ void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *ev /* generic code for opening log if not open yet.. */ if (l->logfd == -1) { - l->logfd = fd_fileopen(l->file, O_CREAT|O_APPEND|O_WRONLY); + l->logfd = fd_fileopen(l->file, O_CREAT | O_APPEND | O_WRONLY); if (l->logfd == -1) { if (errno == ENOENT) { /* Create directory structure and retry */ unreal_create_directory_structure_for_file(l->file, 0777); - l->logfd = fd_fileopen(l->file, O_CREAT|O_APPEND|O_WRONLY); + l->logfd = fd_fileopen(l->file, O_CREAT | O_APPEND | O_WRONLY); } if (l->logfd == -1) { @@ -1201,7 +1185,8 @@ void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *ev if (!loop.booted) { config_status("WARNING: Unable to write to '%s': %s", l->file, strerror(errno)); - } else { + } else + { if (last_log_file_warning + 300 < TStime()) { config_status("WARNING: Unable to write to '%s': %s. This warning will not re-appear for at least 5 minutes.", l->file, strerror(errno)); @@ -1221,19 +1206,19 @@ void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *ev if (n < strlen(json_serialized)) { write_error = 1; - } else { + } else + { if (write(l->logfd, "\n", 1) < 1) // FIXME: no.. we should do it this way..... and why do we use direct I/O at all? write_error = 1; } - } else - if (l->type == LOG_TYPE_TEXT) + } else if (l->type == LOG_TYPE_TEXT) { for (m = msg; m; m = m->next) { static char text_buf[MAXLOGLENGTH]; snprintf(text_buf, sizeof(text_buf), "%s%s %s.%s%s %s: %s\n", - timebuf, from_server->name, - subsystem, event_id, m->next?"+":"", log_level_valtostring(loglevel), m->line); + timebuf, from_server->name, + subsystem, event_id, m->next ? "+" : "", log_level_valtostring(loglevel), m->line); n = write(l->logfd, text_buf, strlen(text_buf)); if (n < strlen(text_buf)) { @@ -1248,7 +1233,8 @@ void do_unreal_log_disk(LogLevel loglevel, const char *subsystem, const char *ev if (!loop.booted) { config_status("WARNING: Unable to write to '%s': %s", l->file, strerror(errno)); - } else { + } else + { if (last_log_file_warning + 300 < TStime()) { config_status("WARNING: Unable to write to '%s': %s. This warning will not re-appear for at least 5 minutes.", l->file, strerror(errno)); @@ -1345,7 +1331,7 @@ const char *log_to_snomask(LogLevel loglevel, const char *subsystem, const char return *snomasks ? snomasks : NULL; } -#define COLOR_NONE "\xf" +#define COLOR_NONE "\xf" #define COLOR_DARKGREY "\00314" /** Generic sendto function for logging to IRC. Used for notices to IRCOps and also for sending to individual users on channels */ @@ -1373,29 +1359,32 @@ void sendto_log(Client *client, const char *msgtype, const char *destination, in if (show_event) { sendto_one(client, mtags, ":%s %s %s :%s%s.%s%s%s %s[%s]%s %s", - from_server->name, msgtype, destination, - COLOR_DARKGREY, subsystem, event_id, m->next?"+":"", COLOR_NONE, - log_level_irc_color(loglevel), log_level_valtostring(loglevel), COLOR_NONE, - m->line); - } else { + from_server->name, msgtype, destination, + COLOR_DARKGREY, subsystem, event_id, m->next ? "+" : "", COLOR_NONE, + log_level_irc_color(loglevel), log_level_valtostring(loglevel), COLOR_NONE, + m->line); + } else + { sendto_one(client, mtags, ":%s %s %s :%s[%s]%s %s", - from_server->name, msgtype, destination, - log_level_irc_color(loglevel), log_level_valtostring(loglevel), COLOR_NONE, - m->line); + from_server->name, msgtype, destination, + log_level_irc_color(loglevel), log_level_valtostring(loglevel), COLOR_NONE, + m->line); } - } else { + } else + { if (show_event) { sendto_one(client, mtags, ":%s %s %s :%s.%s%s [%s] %s", - from_server->name, msgtype, destination, - subsystem, event_id, m->next?"+":"", - log_level_valtostring(loglevel), - m->line); - } else { + from_server->name, msgtype, destination, + subsystem, event_id, m->next ? "+" : "", + log_level_valtostring(loglevel), + m->line); + } else + { sendto_one(client, mtags, ":%s %s %s :[%s] %s", - from_server->name, msgtype, destination, - log_level_valtostring(loglevel), - m->line); + from_server->name, msgtype, destination, + log_level_valtostring(loglevel), + m->line); } } safe_free_message_tags(mtags); @@ -1543,7 +1532,7 @@ void webhook_send_async(const char *url, const char *json_data) { OutgoingWebRequest *request; NameValuePrioList *headers = NULL; - + request = safe_alloc(sizeof(OutgoingWebRequest)); safe_strdup(request->url, url); request->http_method = HTTP_METHOD_POST; @@ -1551,16 +1540,16 @@ void webhook_send_async(const char *url, const char *json_data) add_nvplist(&headers, 0, "Content-Type", "application/json"); add_nvplist(&headers, 0, "User-Agent", "UnrealIRCd-Webhook/1.0"); request->headers = headers; - + if (json_data && *json_data) { safe_strdup(request->body, json_data); } - + /* Use default callback that doesn't care about response */ request->callback = download_complete_dontcare; request->max_redirects = 3; - + url_start_async(request); } @@ -1577,10 +1566,8 @@ void do_unreal_log_control(LogLevel loglevel, const char *subsystem, const char if (!strcmp(subsystem, "rawtraffic")) return; - list_for_each_entry(client, &control_list, lclient_node) - if (IsMonitorRehash(client) && IsControl(client)) - for (m = msg; m; m = m->next) - sendto_one(client, NULL, "REPLY [%s] %s", log_level_valtostring(loglevel), m->line); + list_for_each_entry(client, &control_list, lclient_node) if (IsMonitorRehash(client) && IsControl(client)) for (m = msg; m; m = m->next) + sendto_one(client, NULL, "REPLY [%s] %s", log_level_valtostring(loglevel), m->line); if (json_rehash_log) { @@ -1651,8 +1638,7 @@ void log_throttle_init(void) static unsigned int hash_log_throttle_entry(const char *event_id) { - return (unsigned int)(siphash_nocase(event_id, log_throttle_siphashkey) - % LOG_THROTTLE_TABLE_SIZE); + return (unsigned int)(siphash_nocase(event_id, log_throttle_siphashkey) % LOG_THROTTLE_TABLE_SIZE); } static LogThrottleEntry *find_log_throttle_entry(const char *event_id, unsigned int idx) @@ -1665,8 +1651,8 @@ static LogThrottleEntry *find_log_throttle_entry(const char *event_id, unsigned } static LogThrottleEntry *add_log_throttle_entry(const char *event_id, const char *subsystem, - int threshold, int period, int unlimited, - unsigned int idx) + int threshold, int period, int unlimited, + unsigned int idx) { LogThrottleEntry *e = safe_alloc(sizeof(LogThrottleEntry)); safe_strdup(e->event_id, event_id); @@ -1695,12 +1681,12 @@ static void emit_log_throttle_summary(LogThrottleEntry *e) return; unreal_log(ULOG_INFO, "log", "LOG_RATE_LIMIT_SUMMARY", NULL, - "Suppressed $count log entries with event_id $throttled_event_id " - "(subsystem $throttled_subsystem) over the last $period seconds", - log_data_integer("count", suppressed), - log_data_string("throttled_event_id", e->event_id), - log_data_string("throttled_subsystem", log_throttle_subsystem_or(e)), - log_data_integer("period", period)); + "Suppressed $count log entries with event_id $throttled_event_id " + "(subsystem $throttled_subsystem) over the last $period seconds", + log_data_integer("count", suppressed), + log_data_string("throttled_event_id", e->event_id), + log_data_string("throttled_subsystem", log_throttle_subsystem_or(e)), + log_data_integer("period", period)); } /* Returns 1 if this log line should be suppressed. @@ -1785,8 +1771,7 @@ void log_throttle_rehash(void) e->threshold = threshold; e->period = period; e->unlimited = unlimited; - } - else + } else { e->unlimited = 1; } @@ -1878,31 +1863,31 @@ void do_unreal_log_internal(LogLevel loglevel, const char *subsystem, const char if (loglevel_string == NULL) { do_unreal_log_norecursioncheck(ULOG_ERROR, "log", "BUG_LOG_LOGLEVEL", NULL, - "[BUG] Next log message had an invalid log level -- corrected to ULOG_ERROR", - NULL); + "[BUG] Next log message had an invalid log level -- corrected to ULOG_ERROR", + NULL); loglevel = ULOG_ERROR; loglevel_string = log_level_valtostring(loglevel); } if (!valid_subsystem(subsystem)) { do_unreal_log_norecursioncheck(ULOG_ERROR, "log", "BUG_LOG_SUBSYSTEM", NULL, - "[BUG] Next log message had an invalid subsystem -- changed to 'unknown'", - NULL); + "[BUG] Next log message had an invalid subsystem -- changed to 'unknown'", + NULL); subsystem = "unknown"; } if (!valid_event_id(event_id)) { do_unreal_log_norecursioncheck(ULOG_ERROR, "log", "BUG_LOG_EVENT_ID", NULL, - "[BUG] Next log message had an invalid event id -- changed to 'unknown'", - NULL); + "[BUG] Next log message had an invalid event id -- changed to 'unknown'", + NULL); event_id = "unknown"; } /* This one is probably temporary since it should not be a real error, actually (but often is) */ if (expand_msg && strchr(msg, '%')) { do_unreal_log_norecursioncheck(ULOG_ERROR, "log", "BUG_LOG_MESSAGE_PERCENT", NULL, - "[BUG] Next log message contains a percent sign -- possibly accidental format string!", - NULL); + "[BUG] Next log message contains a percent sign -- possibly accidental format string!", + NULL); } j = json_object(); @@ -1924,7 +1909,7 @@ void do_unreal_log_internal(LogLevel loglevel, const char *subsystem, const char /* Additional details (if any) */ while ((d = va_arg(vl, LogData *))) { - switch(d->type) + switch (d->type) { case LOG_FIELD_INTEGER: json_object_set_new(j_details, d->key, json_integer(d->value.integer)); @@ -2029,8 +2014,7 @@ void do_unreal_log_internal(LogLevel loglevel, const char *subsystem, const char if (remote_rehash_client && ((!strcmp(event_id, "CONFIG_ERROR_GENERIC") || !strcmp(event_id, "CONFIG_WARNING_GENERIC") || - !strcmp(event_id, "CONFIG_INFO_GENERIC")) - || + !strcmp(event_id, "CONFIG_INFO_GENERIC")) || (loop.config_status >= CONFIG_STATUS_TEST)) && strcmp(subsystem, "rawtraffic")) { @@ -2164,7 +2148,7 @@ void config_pre_run_log(void) void log_blocks_switchover(void) { int i; - for (i=0; i < NUM_LOG_DESTINATIONS; i++) + for (i = 0; i < NUM_LOG_DESTINATIONS; i++) free_log_block(logs[i]); memcpy(logs, temp_logs, sizeof(logs)); memset(temp_logs, 0, sizeof(temp_logs)); @@ -2242,8 +2226,7 @@ void memory_log_do_add_message(time_t t, LogLevel loglevel, const char *subsyste memory_log_tail->next = e; e->prev = memory_log_tail; memory_log_tail = e; - } else - if (memory_log != memory_log_tail) + } else if (memory_log != memory_log_tail) { /* Impossible: memory_log NULL but memory_log_tail is not NULL, or vice versa */ abort(); diff --git a/src/match.c b/src/match.c index 22407f117..6e6b62820 100644 --- a/src/match.c +++ b/src/match.c @@ -33,7 +33,7 @@ ID_Copyright("(C) 1990 Jarkko Oikarinen"); u_char touppertab[], tolowertab[]; #define tolowertab2 tolowertab -#define lc(x) tolowertab2[x] +#define lc(x) tolowertab2[x] pcre2_match_context *unreal_pcre2_match_ctx = NULL; @@ -57,35 +57,35 @@ int match_esc(const char *mask, const char *name) const u_char *ma = NULL; const u_char *na = name; - while(1) + while (1) { if (*m == '*') { while (*m == '*') /* collapse.. */ m++; - ma = m; + ma = m; na = n; } - + if (!*m) { if (!*n) return 1; if (!ma) return 0; - for (m--; (m > (const u_char *)mask) && (*m == '?'); m--); + for (m--; (m > (const u_char *)mask) && (*m == '?'); m--) + ; if (*m == '*') return 1; m = ma; n = ++na; - } else - if (!*n) + } else if (!*n) { while (*m == '*') /* collapse.. */ m++; return (*m == 0); } - + if (*m != '?') { if (*m == '\\') @@ -119,35 +119,35 @@ int match_simple(const char *mask, const char *name) const u_char *ma = NULL; const u_char *na = name; - while(1) + while (1) { if (*m == '*') { while (*m == '*') /* collapse.. */ m++; - ma = m; + ma = m; na = n; } - + if (!*m) { if (!*n) return 1; if (!ma) return 0; - for (m--; (m > (const u_char *)mask) && (*m == '?'); m--); + for (m--; (m > (const u_char *)mask) && (*m == '?'); m--) + ; if (*m == '*') return 1; m = ma; n = ++na; - } else - if (!*n) + } else if (!*n) { while (*m == '*') /* collapse.. */ m++; return (*m == 0); } - + if ((lc(*m) != lc(*n)) && !((*m == '_') && (*n == ' ')) && (*m != '?')) { if (!ma) @@ -188,8 +188,7 @@ char *collapse(char *pattern) break; else s++; - } - else if (*s == '*') + } else if (*s == '*') { if (*(t = s1 = s + 1) == '*') while (*t == '*') @@ -214,11 +213,11 @@ char *collapse(char *pattern) * <0, if s1 lexicographically less than s2 * >0, if s1 lexicographically greater than s2 */ -int smycmp(const char *s1, const char *s2) +int smycmp(const char *s1, const char *s2) { u_char *str1; u_char *str2; - int res; + int res; str1 = (u_char *)s1; str2 = (u_char *)s2; @@ -412,23 +411,22 @@ Match *unreal_create_match(MatchType type, const char *str, const char **error) safe_strdup(m->str, str); m->type = type; - + if (m->type == MATCH_SIMPLE) { /* Nothing to do */ - } - else if (m->type == MATCH_PCRE_REGEX) + } else if (m->type == MATCH_PCRE_REGEX) { int errorcode = 0; PCRE2_SIZE erroroffset = 0; int options = 0; char buf2[512]; - + if ((loop.config_status < CONFIG_STATUS_LOAD) ? tempiConf.spamfilter_utf8 : iConf.spamfilter_utf8) - options = PCRE2_CASELESS|PCRE2_MATCH_INVALID_UTF; + options = PCRE2_CASELESS | PCRE2_MATCH_INVALID_UTF; else - options = PCRE2_CASELESS|PCRE2_NEVER_UTF|PCRE2_NEVER_UCP; - + options = PCRE2_CASELESS | PCRE2_NEVER_UTF | PCRE2_NEVER_UCP; + m->ext.pcre2_expr = pcre2_compile(str, PCRE2_ZERO_TERMINATED, options, &errorcode, &erroroffset, NULL); if (m->ext.pcre2_expr == NULL) { @@ -450,8 +448,8 @@ Match *unreal_create_match(MatchType type, const char *str, const char **error) } else if (m->type == MATCH_NONE) { /* Nothing to do */ - } - else { + } else + { /* Unknown type, how did that happen ? */ unreal_delete_match(m); return NULL; @@ -548,7 +546,7 @@ int fast_badword_match(ConfigItem_badword *badword, const char *line) return (our_strcasestr(line, badword->word) ? 1 : 0); p = line; - while((p = our_strcasestr(p, badword->word))) + while ((p = our_strcasestr(p, badword->word))) { if (!(badword->type & BADW_TYPE_FAST_L)) { @@ -562,7 +560,7 @@ int fast_badword_match(ConfigItem_badword *badword, const char *line) } /* Looks like it matched */ return 1; -next: + next: p += bwlen; } return 0; @@ -588,7 +586,8 @@ int fast_badword_replace(ConfigItem_badword *badword, const char *line, char *bu int run = 1; int cleaned = 0; - while(run) { + while (run) + { pold = our_strcasestr(pold, badword->word); if (!pold) break; @@ -597,15 +596,19 @@ int fast_badword_replace(ConfigItem_badword *badword, const char *line, char *bu if (searchn == -1) searchn = strlen(badword->word); /* Hunt for start of word */ - if (pold > line) { - for (startw = pold; (!iswseperator(*startw) && (startw != line)); startw--); + if (pold > line) + { + for (startw = pold; (!iswseperator(*startw) && (startw != line)); startw--) + ; if (iswseperator(*startw)) startw++; /* Don't point at the space/seperator but at the word! */ - } else { + } else + { startw = pold; } - if (!(badword->type & BADW_TYPE_FAST_L) && (pold != startw)) { + if (!(badword->type & BADW_TYPE_FAST_L) && (pold != startw)) + { /* not matched */ pold++; continue; @@ -615,9 +618,11 @@ int fast_badword_replace(ConfigItem_badword *badword, const char *line, char *bu * Fix for bug #4909: word will be at least 'searchn' long so we can skip * 'searchn' bytes and avoid stopping half-way the badword. */ - for (endw = pold+searchn; ((*endw != '\0') && (!iswseperator(*endw))); endw++); + for (endw = pold + searchn; ((*endw != '\0') && (!iswseperator(*endw))); endw++) + ; - if (!(badword->type & BADW_TYPE_FAST_R) && (pold+searchn != endw)) { + if (!(badword->type & BADW_TYPE_FAST_R) && (pold + searchn != endw)) + { /* not matched */ pold++; continue; @@ -626,9 +631,11 @@ int fast_badword_replace(ConfigItem_badword *badword, const char *line, char *bu cleaned = 1; /* still too soon? Syzop/20050227 */ /* Do we have any not-copied-yet data? */ - if (poldx != startw) { + if (poldx != startw) + { int tmp_n = startw - poldx; - if (pnew + tmp_n >= c_eol) { + if (pnew + tmp_n >= c_eol) + { /* Partial copy and return... */ memcpy(pnew, poldx, c_eol - pnew); *c_eol = '\0'; @@ -640,8 +647,10 @@ int fast_badword_replace(ConfigItem_badword *badword, const char *line, char *bu } /* Now update the word in buf (pnew is now something like startw-in-new-buffer */ - if (replacen) { - if ((pnew + replacen) >= c_eol) { + if (replacen) + { + if ((pnew + replacen) >= c_eol) + { /* Partial copy and return... */ memcpy(pnew, replacew, c_eol - pnew); *c_eol = '\0'; @@ -653,10 +662,12 @@ int fast_badword_replace(ConfigItem_badword *badword, const char *line, char *bu poldx = pold = endw; } /* Copy the last part */ - if (*poldx) { + if (*poldx) + { strncpy(pnew, poldx, c_eol - pnew); *(c_eol) = '\0'; - } else { + } else + { *pnew = '\0'; } return cleaned; @@ -699,8 +710,7 @@ const char *stripbadwords(const char *str, ConfigItem_badword *start_bw, int *bl *blocked = 1; return NULL; } - } - else + } else { int n; /* fast_badword_replace() does size checking so we can use 512 here instead of 4096 */ @@ -710,8 +720,7 @@ const char *stripbadwords(const char *str, ConfigItem_badword *start_bw, int *bl strcpy(cleanstr, buf); memset(buf, 0, sizeof(buf)); /* regexp likes this somehow */ } - } else - if (this_word->type & BADW_TYPE_REGEX) + } else if (this_word->type & BADW_TYPE_REGEX) { if (this_word->action == BADWORD_BLOCK) { @@ -725,8 +734,7 @@ const char *stripbadwords(const char *str, ConfigItem_badword *start_bw, int *bl *blocked = 1; return NULL; } - } - else + } else { pcre2_match_data *md; int ret; @@ -734,7 +742,8 @@ const char *stripbadwords(const char *str, ConfigItem_badword *start_bw, int *bl int start, end; ptr = cleanstr; /* set pointer to start of string */ - while(1) { + while (1) + { md = pcre2_match_data_create(9, NULL); /* ^^ we need to free 'md' in ALL circumstances. * remember this if you break or continue in this loop! @@ -745,7 +754,7 @@ const char *stripbadwords(const char *str, ConfigItem_badword *start_bw, int *bl dd = pcre2_get_ovector_pointer(md); start = (int)dd[0]; end = (int)dd[1]; - if ((start < 0) || (end < 0) || (start > strlen(ptr)) || (end > strlen(ptr)+1)) + if ((start < 0) || (end < 0) || (start > strlen(ptr)) || (end > strlen(ptr) + 1)) { unreal_log(ULOG_FATAL, "main", "BUG_STRIPBADWORDS_PCRE2_MATCH_OOB", NULL, "[BUG] pcre2_match() returned an ovector with OOB start/end: $start/$end, len $length: '$buf'", @@ -765,7 +774,7 @@ const char *stripbadwords(const char *str, ConfigItem_badword *start_bw, int *bl matchlen += m; strlncat(buf, ptr, sizeof buf, start); if (this_word->replace) - strlcat(buf, this_word->replace, sizeof buf); + strlcat(buf, this_word->replace, sizeof buf); else strlcat(buf, REPLACEWORD, sizeof buf); ptr += end; /* Set pointer after the match pos */ @@ -776,7 +785,7 @@ const char *stripbadwords(const char *str, ConfigItem_badword *start_bw, int *bl break; /* NOMATCH: we are done! */ } /* All the better to eat you with! */ - strlcat(buf, ptr, sizeof buf); + strlcat(buf, ptr, sizeof buf); memcpy(cleanstr, buf, sizeof cleanstr); memset(buf, 0, sizeof(buf)); if (matchlen == stringlen) @@ -798,14 +807,16 @@ const char *stripbadwords(const char *str, ConfigItem_badword *start_bw, int *bl */ const char *badword_config_check_regex(const char *str, int fastsupport, int check_broadness) { - int regex=0; + int regex = 0; const char *tmp; static char errorbuf[512]; if (fastsupport) { - for (tmp = str; *tmp; tmp++) { - if (!isalnum(*tmp) && !(*tmp >= 128)) { + for (tmp = str; *tmp; tmp++) + { + if (!isalnum(*tmp) && !(*tmp >= 128)) + { if ((str == tmp) && (*tmp == '*')) continue; if ((*(tmp + 1) == '\0') && (*tmp == '*')) @@ -823,7 +834,7 @@ const char *badword_config_check_regex(const char *str, int fastsupport, int che int options = 0; char buf2[512]; - options = PCRE2_CASELESS|PCRE2_NEVER_UTF|PCRE2_NEVER_UCP; + options = PCRE2_CASELESS | PCRE2_NEVER_UTF | PCRE2_NEVER_UCP; expr = pcre2_compile(str, PCRE2_ZERO_TERMINATED, options, &errorcode, &erroroffset, NULL); if (expr == NULL) @@ -849,13 +860,17 @@ int badword_config_process(ConfigItem_badword *ca, const char *str) /* The fast badwords routine can do: "blah" "*blah" "blah*" and "*blah*", * in all other cases use regex. */ - for (tmp = str; *tmp; tmp++) { - if (!isalnum(*tmp) && !(*tmp >= 128)) { - if ((str == tmp) && (*tmp == '*')) { + for (tmp = str; *tmp; tmp++) + { + if (!isalnum(*tmp) && !(*tmp >= 128)) + { + if ((str == tmp) && (*tmp == '*')) + { ast_l = 1; /* Asterisk at the left */ continue; } - if ((*(tmp + 1) == '\0') && (*tmp == '*')) { + if ((*(tmp + 1) == '\0') && (*tmp == '*')) + { ast_r = 1; /* Asterisk at the right */ continue; } @@ -872,7 +887,7 @@ int badword_config_process(ConfigItem_badword *ca, const char *str) ca->type = BADW_TYPE_REGEX; safe_strdup(ca->word, str); - options = PCRE2_CASELESS|PCRE2_NEVER_UTF|PCRE2_NEVER_UCP; + options = PCRE2_CASELESS | PCRE2_NEVER_UTF | PCRE2_NEVER_UCP; ca->pcre2_expr = pcre2_compile(str, PCRE2_ZERO_TERMINATED, options, &errorcode, &erroroffset, NULL); if (ca->pcre2_expr == NULL) @@ -884,8 +899,7 @@ int badword_config_process(ConfigItem_badword *ca, const char *str) abort(); } pcre2_jit_compile(ca->pcre2_expr, PCRE2_JIT_COMPLETE); - } - else + } else { char *tmpw; ca->type = BADW_TYPE_FAST; diff --git a/src/mempool.c b/src/mempool.c index 8d560b506..9ee85e7f1 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -56,23 +56,23 @@ void mp_pool_init(void) mp_pool_t *mp_pool_new(size_t sz, size_t ignored) { - mp_pool_t *m = safe_alloc(sizeof(mp_pool_t)); + mp_pool_t *m = safe_alloc(sizeof(mp_pool_t)); /* We (mis)use the item_alloc_size. It has a slightly different * meaning in the real mempool code where it's aligned, rounded, etc. * That is something we don't want as it would hide small overflows. */ - m->item_alloc_size = sz; - return m; + m->item_alloc_size = sz; + return m; } void *mp_pool_get(mp_pool_t *pool) { - return malloc(pool->item_alloc_size); + return malloc(pool->item_alloc_size); } void mp_pool_release(void *item) { - safe_free(item); + safe_free(item); } #else @@ -80,40 +80,40 @@ void mp_pool_release(void *item) static int tor_log2(uint64_t u64) { - int r = 0; + int r = 0; - if (u64 >= (1ULL << 32)) - { - u64 >>= 32; - r = 32; - } - if (u64 >= (1ULL << 16)) - { - u64 >>= 16; - r += 16; - } - if (u64 >= (1ULL << 8)) - { - u64 >>= 8; - r += 8; - } - if (u64 >= (1ULL << 4)) - { - u64 >>= 4; - r += 4; - } - if (u64 >= (1ULL << 2)) - { - u64 >>= 2; - r += 2; - } - if (u64 >= (1ULL << 1)) - { - u64 >>= 1; - r += 1; - } + if (u64 >= (1ULL << 32)) + { + u64 >>= 32; + r = 32; + } + if (u64 >= (1ULL << 16)) + { + u64 >>= 16; + r += 16; + } + if (u64 >= (1ULL << 8)) + { + u64 >>= 8; + r += 8; + } + if (u64 >= (1ULL << 4)) + { + u64 >>= 4; + r += 4; + } + if (u64 >= (1ULL << 2)) + { + u64 >>= 2; + r += 2; + } + if (u64 >= (1ULL << 1)) + { + u64 >>= 1; + r += 1; + } - return r; + return r; } /** Return the power of 2 in range [1,UINT64_MAX] closest to u64. If @@ -121,24 +121,24 @@ tor_log2(uint64_t u64) static uint64_t round_to_power_of_2(uint64_t u64) { - int lg2; - uint64_t low; - uint64_t high; + int lg2; + uint64_t low; + uint64_t high; - if (u64 == 0) - return 1; + if (u64 == 0) + return 1; - lg2 = tor_log2(u64); - low = 1ULL << lg2; + lg2 = tor_log2(u64); + low = 1ULL << lg2; - if (lg2 == 63) - return low; + if (lg2 == 63) + return low; - high = 1ULL << (lg2 + 1); - if (high - u64 < u64 - low) - return high; - else - return low; + high = 1ULL << (lg2 + 1); + if (high - u64 < u64 - low) + return high; + else + return low; } /* OVERVIEW: @@ -193,13 +193,13 @@ round_to_power_of_2(uint64_t u64) /* Tuning parameters */ /** Largest type that we need to ensure returned memory items are aligned to. * Change this to "double" if we need to be safe for structs with doubles. */ -#define ALIGNMENT_TYPE void * + #define ALIGNMENT_TYPE void * /** Increment that we need to align allocated. */ -#define ALIGNMENT sizeof(ALIGNMENT_TYPE) + #define ALIGNMENT sizeof(ALIGNMENT_TYPE) /** Largest memory chunk that we should allocate. */ -#define MAX_CHUNK (8 *(1L << 20)) + #define MAX_CHUNK (8 * (1L << 20)) /** Smallest memory chunk size that we should allocate. */ -#define MIN_CHUNK 4096 + #define MIN_CHUNK 4096 typedef struct mp_allocated_t mp_allocated_t; typedef struct mp_chunk_t mp_chunk_t; @@ -209,59 +209,58 @@ struct mp_allocated_t { /** The chunk that this item is allocated in. This adds overhead to each * allocated item, thus making this implementation inappropriate for * very small items. */ - mp_chunk_t *in_chunk; + mp_chunk_t *in_chunk; - union { + union { /** If this item is free, the next item on the free list. */ - mp_allocated_t *next_free; + mp_allocated_t *next_free; /** If this item is not free, the actual memory contents of this item. * (Not actual size.) */ - char mem[1]; + char mem[1]; /** An extra element to the union to insure correct alignment. */ - ALIGNMENT_TYPE dummy_; - } u; + ALIGNMENT_TYPE dummy_; + } u; }; /** 'Magic' value used to detect memory corruption. */ -#define MP_CHUNK_MAGIC 0x09870123 + #define MP_CHUNK_MAGIC 0x09870123 /** A chunk of memory. Chunks come from malloc; we use them */ struct mp_chunk_t { - uint32_t magic; /**< Must be MP_CHUNK_MAGIC if this chunk is valid. */ - mp_chunk_t *next; /**< The next free, used, or full chunk in sequence. */ - mp_chunk_t *prev; /**< The previous free, used, or full chunk in sequence. */ - mp_pool_t *pool; /**< The pool that this chunk is part of. */ + uint32_t magic; /**< Must be MP_CHUNK_MAGIC if this chunk is valid. */ + mp_chunk_t *next; /**< The next free, used, or full chunk in sequence. */ + mp_chunk_t *prev; /**< The previous free, used, or full chunk in sequence. */ + mp_pool_t *pool; /**< The pool that this chunk is part of. */ /** First free item in the freelist for this chunk. Note that this may be * NULL even if this chunk is not at capacity: if so, the free memory at * next_mem has not yet been carved into items. */ - mp_allocated_t *first_free; - int n_allocated; /**< Number of currently allocated items in this chunk. */ - int capacity; /**< Number of items that can be fit into this chunk. */ - size_t mem_size; /**< Number of usable bytes in mem. */ - char *next_mem; /**< Pointer into part of mem not yet carved up. */ - char mem[]; /**< Storage for this chunk. */ + mp_allocated_t *first_free; + int n_allocated; /**< Number of currently allocated items in this chunk. */ + int capacity; /**< Number of items that can be fit into this chunk. */ + size_t mem_size; /**< Number of usable bytes in mem. */ + char *next_mem; /**< Pointer into part of mem not yet carved up. */ + char mem[]; /**< Storage for this chunk. */ }; static mp_pool_t *mp_allocated_pools = NULL; /** Number of extra bytes needed beyond mem_size to allocate a chunk. */ -#define CHUNK_OVERHEAD offsetof(mp_chunk_t, mem[0]) + #define CHUNK_OVERHEAD offsetof(mp_chunk_t, mem[0]) /** Given a pointer to a mp_allocated_t, return a pointer to the memory * item it holds. */ -#define A2M(a) (&(a)->u.mem) + #define A2M(a) (&(a)->u.mem) /** Given a pointer to a memory_item_t, return a pointer to its enclosing * mp_allocated_t. */ -#define M2A(p) (((char *)p) - offsetof(mp_allocated_t, u.mem)) + #define M2A(p) (((char *)p) - offsetof(mp_allocated_t, u.mem)) -void -mp_pool_init(void) +void mp_pool_init(void) { - EventAdd(NULL, "mp_pool_garbage_collect", &mp_pool_garbage_collect, NULL, 119*1000, 0); + EventAdd(NULL, "mp_pool_garbage_collect", &mp_pool_garbage_collect, NULL, 119 * 1000, 0); } /** Helper: Allocate and return a new memory chunk for pool. Does not @@ -269,18 +268,18 @@ mp_pool_init(void) static mp_chunk_t * mp_chunk_new(mp_pool_t *pool) { - size_t sz = pool->new_chunk_capacity * pool->item_alloc_size; - mp_chunk_t *chunk = safe_alloc(CHUNK_OVERHEAD + sz); + size_t sz = pool->new_chunk_capacity * pool->item_alloc_size; + mp_chunk_t *chunk = safe_alloc(CHUNK_OVERHEAD + sz); -#ifdef MEMPOOL_STATS - ++pool->total_chunks_allocated; -#endif - chunk->magic = MP_CHUNK_MAGIC; - chunk->capacity = pool->new_chunk_capacity; - chunk->mem_size = sz; - chunk->next_mem = chunk->mem; - chunk->pool = pool; - return chunk; + #ifdef MEMPOOL_STATS + ++pool->total_chunks_allocated; + #endif + chunk->magic = MP_CHUNK_MAGIC; + chunk->capacity = pool->new_chunk_capacity; + chunk->mem_size = sz; + chunk->next_mem = chunk->mem; + chunk->pool = pool; + return chunk; } /** Take a chunk that has just been allocated or removed from @@ -289,161 +288,168 @@ mp_chunk_new(mp_pool_t *pool) static void add_newly_used_chunk_to_used_list(mp_pool_t *pool, mp_chunk_t *chunk) { - chunk->next = pool->used_chunks; - if (chunk->next) - chunk->next->prev = chunk; - pool->used_chunks = chunk; - assert(!chunk->prev); + chunk->next = pool->used_chunks; + if (chunk->next) + chunk->next->prev = chunk; + pool->used_chunks = chunk; + assert(!chunk->prev); } /** Return a newly allocated item from pool. */ void * mp_pool_get(mp_pool_t *pool) { - mp_chunk_t *chunk; - mp_allocated_t *allocated; + mp_chunk_t *chunk; + mp_allocated_t *allocated; - if (pool->used_chunks != NULL) { + if (pool->used_chunks != NULL) + { /* * Common case: there is some chunk that is neither full nor empty. Use * that one. (We can't use the full ones, obviously, and we should fill * up the used ones before we start on any empty ones. */ - chunk = pool->used_chunks; + chunk = pool->used_chunks; - } else if (pool->empty_chunks) { + } else if (pool->empty_chunks) + { /* * We have no used chunks, but we have an empty chunk that we haven't * freed yet: use that. (We pull from the front of the list, which should * get us the most recently emptied chunk.) */ - chunk = pool->empty_chunks; + chunk = pool->empty_chunks; /* Remove the chunk from the empty list. */ - pool->empty_chunks = chunk->next; - if (chunk->next) - chunk->next->prev = NULL; + pool->empty_chunks = chunk->next; + if (chunk->next) + chunk->next->prev = NULL; /* Put the chunk on the 'used' list*/ - add_newly_used_chunk_to_used_list(pool, chunk); + add_newly_used_chunk_to_used_list(pool, chunk); - assert(!chunk->prev); - --pool->n_empty_chunks; - if (pool->n_empty_chunks < pool->min_empty_chunks) - pool->min_empty_chunks = pool->n_empty_chunks; - } else { + assert(!chunk->prev); + --pool->n_empty_chunks; + if (pool->n_empty_chunks < pool->min_empty_chunks) + pool->min_empty_chunks = pool->n_empty_chunks; + } else + { /* We have no used or empty chunks: allocate a new chunk. */ - chunk = mp_chunk_new(pool); + chunk = mp_chunk_new(pool); /* Add the new chunk to the used list. */ - add_newly_used_chunk_to_used_list(pool, chunk); - } + add_newly_used_chunk_to_used_list(pool, chunk); + } - assert(chunk->n_allocated < chunk->capacity); + assert(chunk->n_allocated < chunk->capacity); - if (chunk->first_free) { + if (chunk->first_free) + { /* If there's anything on the chunk's freelist, unlink it and use it. */ - allocated = chunk->first_free; - chunk->first_free = allocated->u.next_free; - allocated->u.next_free = NULL; /* For debugging; not really needed. */ - assert(allocated->in_chunk == chunk); - } else { + allocated = chunk->first_free; + chunk->first_free = allocated->u.next_free; + allocated->u.next_free = NULL; /* For debugging; not really needed. */ + assert(allocated->in_chunk == chunk); + } else + { /* Otherwise, the chunk had better have some free space left on it. */ - assert(chunk->next_mem + pool->item_alloc_size <= - chunk->mem + chunk->mem_size); + assert(chunk->next_mem + pool->item_alloc_size <= + chunk->mem + chunk->mem_size); /* Good, it did. Let's carve off a bit of that free space, and use * that. */ - allocated = (void *)chunk->next_mem; - chunk->next_mem += pool->item_alloc_size; - allocated->in_chunk = chunk; - allocated->u.next_free = NULL; /* For debugging; not really needed. */ - } + allocated = (void *)chunk->next_mem; + chunk->next_mem += pool->item_alloc_size; + allocated->in_chunk = chunk; + allocated->u.next_free = NULL; /* For debugging; not really needed. */ + } - ++chunk->n_allocated; -#ifdef MEMPOOL_STATS - ++pool->total_items_allocated; -#endif + ++chunk->n_allocated; + #ifdef MEMPOOL_STATS + ++pool->total_items_allocated; + #endif - if (chunk->n_allocated == chunk->capacity) { + if (chunk->n_allocated == chunk->capacity) + { /* This chunk just became full. */ - assert(chunk == pool->used_chunks); - assert(chunk->prev == NULL); + assert(chunk == pool->used_chunks); + assert(chunk->prev == NULL); /* Take it off the used list. */ - pool->used_chunks = chunk->next; - if (chunk->next) - chunk->next->prev = NULL; + pool->used_chunks = chunk->next; + if (chunk->next) + chunk->next->prev = NULL; /* Put it on the full list. */ - chunk->next = pool->full_chunks; - if (chunk->next) - chunk->next->prev = chunk; - pool->full_chunks = chunk; - } + chunk->next = pool->full_chunks; + if (chunk->next) + chunk->next->prev = chunk; + pool->full_chunks = chunk; + } /* And return the memory portion of the mp_allocated_t. */ - return A2M(allocated); + return A2M(allocated); } /** Return an allocated memory item to its memory pool. */ -void -mp_pool_release(void *item) +void mp_pool_release(void *item) { - mp_allocated_t *allocated = (void *)M2A(item); - mp_chunk_t *chunk = allocated->in_chunk; + mp_allocated_t *allocated = (void *)M2A(item); + mp_chunk_t *chunk = allocated->in_chunk; - assert(chunk); - assert(chunk->magic == MP_CHUNK_MAGIC); - assert(chunk->n_allocated > 0); + assert(chunk); + assert(chunk->magic == MP_CHUNK_MAGIC); + assert(chunk->n_allocated > 0); - allocated->u.next_free = chunk->first_free; - chunk->first_free = allocated; + allocated->u.next_free = chunk->first_free; + chunk->first_free = allocated; - if (chunk->n_allocated == chunk->capacity) { + if (chunk->n_allocated == chunk->capacity) + { /* This chunk was full and is about to be used. */ - mp_pool_t *pool = chunk->pool; + mp_pool_t *pool = chunk->pool; /* unlink from the full list */ - if (chunk->prev) - chunk->prev->next = chunk->next; - if (chunk->next) - chunk->next->prev = chunk->prev; - if (chunk == pool->full_chunks) - pool->full_chunks = chunk->next; + if (chunk->prev) + chunk->prev->next = chunk->next; + if (chunk->next) + chunk->next->prev = chunk->prev; + if (chunk == pool->full_chunks) + pool->full_chunks = chunk->next; /* link to the used list. */ - chunk->next = pool->used_chunks; - chunk->prev = NULL; - if (chunk->next) - chunk->next->prev = chunk; - pool->used_chunks = chunk; - } else if (chunk->n_allocated == 1) { + chunk->next = pool->used_chunks; + chunk->prev = NULL; + if (chunk->next) + chunk->next->prev = chunk; + pool->used_chunks = chunk; + } else if (chunk->n_allocated == 1) + { /* This was used and is about to be empty. */ - mp_pool_t *pool = chunk->pool; + mp_pool_t *pool = chunk->pool; /* Unlink from the used list */ - if (chunk->prev) - chunk->prev->next = chunk->next; - if (chunk->next) - chunk->next->prev = chunk->prev; - if (chunk == pool->used_chunks) - pool->used_chunks = chunk->next; + if (chunk->prev) + chunk->prev->next = chunk->next; + if (chunk->next) + chunk->next->prev = chunk->prev; + if (chunk == pool->used_chunks) + pool->used_chunks = chunk->next; /* Link to the empty list */ - chunk->next = pool->empty_chunks; - chunk->prev = NULL; - if (chunk->next) - chunk->next->prev = chunk; - pool->empty_chunks = chunk; + chunk->next = pool->empty_chunks; + chunk->prev = NULL; + if (chunk->next) + chunk->next->prev = chunk; + pool->empty_chunks = chunk; /* Reset the guts of this chunk to defragment it, in case it gets * used again. */ - chunk->first_free = NULL; - chunk->next_mem = chunk->mem; + chunk->first_free = NULL; + chunk->next_mem = chunk->mem; - ++pool->n_empty_chunks; - } + ++pool->n_empty_chunks; + } - --chunk->n_allocated; + --chunk->n_allocated; } /** Allocate a new memory pool to hold items of size item_size. We'll @@ -451,62 +457,63 @@ mp_pool_release(void *item) mp_pool_t * mp_pool_new(size_t item_size, size_t chunk_capacity) { - mp_pool_t *pool; - size_t alloc_size, new_chunk_cap; + mp_pool_t *pool; + size_t alloc_size, new_chunk_cap; /* assert(item_size < SIZE_T_CEILING); assert(chunk_capacity < SIZE_T_CEILING); assert(SIZE_T_CEILING / item_size > chunk_capacity); */ - pool = safe_alloc(sizeof(mp_pool_t)); + pool = safe_alloc(sizeof(mp_pool_t)); /* * First, we figure out how much space to allow per item. We'll want to * use make sure we have enough for the overhead plus the item size. */ - alloc_size = (size_t)(offsetof(mp_allocated_t, u.mem) + item_size); + alloc_size = (size_t)(offsetof(mp_allocated_t, u.mem) + item_size); /* * If the item_size is less than sizeof(next_free), we need to make * the allocation bigger. */ - if (alloc_size < sizeof(mp_allocated_t)) - alloc_size = sizeof(mp_allocated_t); + if (alloc_size < sizeof(mp_allocated_t)) + alloc_size = sizeof(mp_allocated_t); /* If we're not an even multiple of ALIGNMENT, round up. */ - if (alloc_size % ALIGNMENT) { - alloc_size = alloc_size + ALIGNMENT - (alloc_size % ALIGNMENT); - } - if (alloc_size < ALIGNMENT) - alloc_size = ALIGNMENT; - assert((alloc_size % ALIGNMENT) == 0); + if (alloc_size % ALIGNMENT) + { + alloc_size = alloc_size + ALIGNMENT - (alloc_size % ALIGNMENT); + } + if (alloc_size < ALIGNMENT) + alloc_size = ALIGNMENT; + assert((alloc_size % ALIGNMENT) == 0); /* * Now we figure out how many items fit in each chunk. We need to fit at * least 2 items per chunk. No chunk can be more than MAX_CHUNK bytes long, * or less than MIN_CHUNK. */ - if (chunk_capacity > MAX_CHUNK) - chunk_capacity = MAX_CHUNK; + if (chunk_capacity > MAX_CHUNK) + chunk_capacity = MAX_CHUNK; /* * Try to be around a power of 2 in size, since that's what allocators like * handing out. 512K-1 byte is a lot better than 512K+1 byte. */ - chunk_capacity = (size_t) round_to_power_of_2(chunk_capacity); - while (chunk_capacity < alloc_size * 2 + CHUNK_OVERHEAD) - chunk_capacity *= 2; - if (chunk_capacity < MIN_CHUNK) - chunk_capacity = MIN_CHUNK; + chunk_capacity = (size_t)round_to_power_of_2(chunk_capacity); + while (chunk_capacity < alloc_size * 2 + CHUNK_OVERHEAD) + chunk_capacity *= 2; + if (chunk_capacity < MIN_CHUNK) + chunk_capacity = MIN_CHUNK; - new_chunk_cap = (chunk_capacity-CHUNK_OVERHEAD) / alloc_size; - assert(new_chunk_cap < INT_MAX); - pool->new_chunk_capacity = (int)new_chunk_cap; + new_chunk_cap = (chunk_capacity - CHUNK_OVERHEAD) / alloc_size; + assert(new_chunk_cap < INT_MAX); + pool->new_chunk_capacity = (int)new_chunk_cap; - pool->item_alloc_size = alloc_size; + pool->item_alloc_size = alloc_size; - pool->next = mp_allocated_pools; - mp_allocated_pools = pool; + pool->next = mp_allocated_pools; + mp_allocated_pools = pool; - return pool; + return pool; } /** Helper function for qsort: used to sort pointers to mp_chunk_t into @@ -514,9 +521,9 @@ mp_pool_new(size_t item_size, size_t chunk_capacity) static int mp_pool_sort_used_chunks_helper(const void *_a, const void *_b) { - mp_chunk_t *a = *(mp_chunk_t * const *)_a; - mp_chunk_t *b = *(mp_chunk_t * const *)_b; - return b->n_allocated - a->n_allocated; + mp_chunk_t *a = *(mp_chunk_t *const *)_a; + mp_chunk_t *b = *(mp_chunk_t *const *)_b; + return b->n_allocated - a->n_allocated; } /** Sort the used chunks in pool into descending order of fullness, @@ -525,35 +532,37 @@ mp_pool_sort_used_chunks_helper(const void *_a, const void *_b) static void mp_pool_sort_used_chunks(mp_pool_t *pool) { - int i, n = 0, inverted = 0; - mp_chunk_t **chunks, *chunk; + int i, n = 0, inverted = 0; + mp_chunk_t **chunks, *chunk; - for (chunk = pool->used_chunks; chunk; chunk = chunk->next) { - ++n; - if (chunk->next && chunk->next->n_allocated > chunk->n_allocated) - ++inverted; - } + for (chunk = pool->used_chunks; chunk; chunk = chunk->next) + { + ++n; + if (chunk->next && chunk->next->n_allocated > chunk->n_allocated) + ++inverted; + } - if (!inverted) - return; + if (!inverted) + return; - chunks = safe_alloc(sizeof(mp_chunk_t *) * n); + chunks = safe_alloc(sizeof(mp_chunk_t *) * n); - for (i=0,chunk = pool->used_chunks; chunk; chunk = chunk->next) - chunks[i++] = chunk; + for (i = 0, chunk = pool->used_chunks; chunk; chunk = chunk->next) + chunks[i++] = chunk; - qsort(chunks, n, sizeof(mp_chunk_t *), mp_pool_sort_used_chunks_helper); - pool->used_chunks = chunks[0]; - chunks[0]->prev = NULL; + qsort(chunks, n, sizeof(mp_chunk_t *), mp_pool_sort_used_chunks_helper); + pool->used_chunks = chunks[0]; + chunks[0]->prev = NULL; - for (i = 1; i < n; ++i) { - chunks[i - 1]->next = chunks[i]; - chunks[i]->prev = chunks[i - 1]; - } + for (i = 1; i < n; ++i) + { + chunks[i - 1]->next = chunks[i]; + chunks[i]->prev = chunks[i - 1]; + } - chunks[n - 1]->next = NULL; - safe_free(chunks); - mp_pool_assert_ok(pool); + chunks[n - 1]->next = NULL; + safe_free(chunks); + mp_pool_assert_ok(pool); } /** If there are more than n empty chunks in pool, free the @@ -561,158 +570,163 @@ mp_pool_sort_used_chunks(mp_pool_t *pool) * keep_recently_used is true, do not free chunks unless they have been * empty since the last call to this function. **/ -void -mp_pool_clean(mp_pool_t *pool, int n_to_keep, int keep_recently_used) +void mp_pool_clean(mp_pool_t *pool, int n_to_keep, int keep_recently_used) { - mp_chunk_t *chunk, **first_to_free; + mp_chunk_t *chunk, **first_to_free; - mp_pool_sort_used_chunks(pool); - assert(n_to_keep >= 0); + mp_pool_sort_used_chunks(pool); + assert(n_to_keep >= 0); - if (keep_recently_used) { - int n_recently_used = pool->n_empty_chunks - pool->min_empty_chunks; - if (n_to_keep < n_recently_used) - n_to_keep = n_recently_used; - } + if (keep_recently_used) + { + int n_recently_used = pool->n_empty_chunks - pool->min_empty_chunks; + if (n_to_keep < n_recently_used) + n_to_keep = n_recently_used; + } - assert(n_to_keep >= 0); + assert(n_to_keep >= 0); - first_to_free = &pool->empty_chunks; - while (*first_to_free && n_to_keep > 0) { - first_to_free = &(*first_to_free)->next; - --n_to_keep; - } - if (!*first_to_free) { - pool->min_empty_chunks = pool->n_empty_chunks; - return; - } + first_to_free = &pool->empty_chunks; + while (*first_to_free && n_to_keep > 0) + { + first_to_free = &(*first_to_free)->next; + --n_to_keep; + } + if (!*first_to_free) + { + pool->min_empty_chunks = pool->n_empty_chunks; + return; + } - chunk = *first_to_free; - while (chunk) { - mp_chunk_t *next = chunk->next; - chunk->magic = 0xdeadbeef; - safe_free(chunk); -#ifdef MEMPOOL_STATS - ++pool->total_chunks_freed; -#endif - --pool->n_empty_chunks; - chunk = next; - } + chunk = *first_to_free; + while (chunk) + { + mp_chunk_t *next = chunk->next; + chunk->magic = 0xdeadbeef; + safe_free(chunk); + #ifdef MEMPOOL_STATS + ++pool->total_chunks_freed; + #endif + --pool->n_empty_chunks; + chunk = next; + } - pool->min_empty_chunks = pool->n_empty_chunks; - *first_to_free = NULL; + pool->min_empty_chunks = pool->n_empty_chunks; + *first_to_free = NULL; } /** Helper: Given a list of chunks, free all the chunks in the list. */ static void destroy_chunks(mp_chunk_t *chunk) { - mp_chunk_t *next; + mp_chunk_t *next; - while (chunk) { - chunk->magic = 0xd3adb33f; - next = chunk->next; - safe_free(chunk); - chunk = next; - } + while (chunk) + { + chunk->magic = 0xd3adb33f; + next = chunk->next; + safe_free(chunk); + chunk = next; + } } /** Helper: make sure that a given chunk list is not corrupt. */ static int assert_chunks_ok(mp_pool_t *pool, mp_chunk_t *chunk, int empty, int full) { - mp_allocated_t *allocated; - int n = 0; + mp_allocated_t *allocated; + int n = 0; - if (chunk) - assert(chunk->prev == NULL); + if (chunk) + assert(chunk->prev == NULL); - while (chunk) { - n++; - assert(chunk->magic == MP_CHUNK_MAGIC); - assert(chunk->pool == pool); - for (allocated = chunk->first_free; allocated; - allocated = allocated->u.next_free) { - assert(allocated->in_chunk == chunk); - } - if (empty) - assert(chunk->n_allocated == 0); - else if (full) - assert(chunk->n_allocated == chunk->capacity); - else - assert(chunk->n_allocated > 0 && chunk->n_allocated < chunk->capacity); + while (chunk) + { + n++; + assert(chunk->magic == MP_CHUNK_MAGIC); + assert(chunk->pool == pool); + for (allocated = chunk->first_free; allocated; + allocated = allocated->u.next_free) + { + assert(allocated->in_chunk == chunk); + } + if (empty) + assert(chunk->n_allocated == 0); + else if (full) + assert(chunk->n_allocated == chunk->capacity); + else + assert(chunk->n_allocated > 0 && chunk->n_allocated < chunk->capacity); - assert(chunk->capacity == pool->new_chunk_capacity); + assert(chunk->capacity == pool->new_chunk_capacity); - assert(chunk->mem_size == - pool->new_chunk_capacity * pool->item_alloc_size); + assert(chunk->mem_size == + pool->new_chunk_capacity * pool->item_alloc_size); - assert(chunk->next_mem >= chunk->mem && - chunk->next_mem <= chunk->mem + chunk->mem_size); + assert(chunk->next_mem >= chunk->mem && + chunk->next_mem <= chunk->mem + chunk->mem_size); - if (chunk->next) - assert(chunk->next->prev == chunk); + if (chunk->next) + assert(chunk->next->prev == chunk); - chunk = chunk->next; - } + chunk = chunk->next; + } - return n; + return n; } /** Fail with an assertion if pool is not internally consistent. */ -void -mp_pool_assert_ok(mp_pool_t *pool) +void mp_pool_assert_ok(mp_pool_t *pool) { - int n_empty; + int n_empty; - n_empty = assert_chunks_ok(pool, pool->empty_chunks, 1, 0); - assert_chunks_ok(pool, pool->full_chunks, 0, 1); - assert_chunks_ok(pool, pool->used_chunks, 0, 0); + n_empty = assert_chunks_ok(pool, pool->empty_chunks, 1, 0); + assert_chunks_ok(pool, pool->full_chunks, 0, 1); + assert_chunks_ok(pool, pool->used_chunks, 0, 0); - assert(pool->n_empty_chunks == n_empty); + assert(pool->n_empty_chunks == n_empty); } -void -mp_pool_garbage_collect(void *arg) +void mp_pool_garbage_collect(void *arg) { - mp_pool_t *pool = mp_allocated_pools; + mp_pool_t *pool = mp_allocated_pools; - for (; pool; pool = pool->next) - mp_pool_clean(pool, 0, 1); + for (; pool; pool = pool->next) + mp_pool_clean(pool, 0, 1); } /** Dump information about pool's memory usage to the Tor log at level * severity. */ -void -mp_pool_log_status(mp_pool_t *pool) +void mp_pool_log_status(mp_pool_t *pool) { - unsigned long long bytes_used = 0; - unsigned long long bytes_allocated = 0; - unsigned long long bu = 0, ba = 0; - mp_chunk_t *chunk; - int n_full = 0, n_used = 0; + unsigned long long bytes_used = 0; + unsigned long long bytes_allocated = 0; + unsigned long long bu = 0, ba = 0; + mp_chunk_t *chunk; + int n_full = 0, n_used = 0; - assert(pool); + assert(pool); - for (chunk = pool->empty_chunks; chunk; chunk = chunk->next) - bytes_allocated += chunk->mem_size; + for (chunk = pool->empty_chunks; chunk; chunk = chunk->next) + bytes_allocated += chunk->mem_size; - for (chunk = pool->used_chunks; chunk; chunk = chunk->next) { - ++n_used; - bu += chunk->n_allocated * pool->item_alloc_size; - ba += chunk->mem_size; - } + for (chunk = pool->used_chunks; chunk; chunk = chunk->next) + { + ++n_used; + bu += chunk->n_allocated * pool->item_alloc_size; + ba += chunk->mem_size; + } - bytes_used += bu; - bytes_allocated += ba; - bu = ba = 0; + bytes_used += bu; + bytes_allocated += ba; + bu = ba = 0; - for (chunk = pool->full_chunks; chunk; chunk = chunk->next) { - ++n_full; - bu += chunk->n_allocated * pool->item_alloc_size; - ba += chunk->mem_size; - } + for (chunk = pool->full_chunks; chunk; chunk = chunk->next) + { + ++n_full; + bu += chunk->n_allocated * pool->item_alloc_size; + ba += chunk->mem_size; + } - bytes_used += bu; - bytes_allocated += ba; + bytes_used += bu; + bytes_allocated += ba; } #endif diff --git a/src/misc.c b/src/misc.c index 029847645..68fb08a68 100644 --- a/src/misc.c +++ b/src/misc.c @@ -44,18 +44,34 @@ static const char *weekdays[] = { /* clang-format on */ static const char *short_months[12] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec", }; static const char *short_weekdays[7] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", + "Sun", + "Mon", + "Tue", + "Wed", + "Thu", + "Fri", + "Sat", }; typedef struct { - int value; /** Unique integer value of item */ - char character; /** Unique character assigned to item */ - char *name; /** Name of item */ + int value; /** Unique integer value of item */ + char character; /** Unique character assigned to item */ + char *name; /** Name of item */ char config_only; } BanActTable; @@ -89,10 +105,10 @@ static BanActTable banacttable[] = { /* clang-format on */ typedef struct { - int value; /** Unique integer value of item */ - char character; /** Unique character assigned to item */ - char *name; /** Name of item */ - char *irccommand; /** Raw IRC command of item (not unique!) */ + int value; /** Unique integer value of item */ + char character; /** Unique character assigned to item */ + char *name; /** Name of item */ + char *irccommand; /** Raw IRC command of item (not unique!) */ } SpamfilterTargetTable; /* clang-format off */ @@ -122,7 +138,7 @@ const char *long_date(time_t clock) static char buf[80], plus; struct tm *lt, *gm; struct tm gmbuf; - int minswest; + int minswest; if (!clock) time(&clock); @@ -133,7 +149,7 @@ const char *long_date(time_t clock) #ifndef _WIN32 if (lt->tm_yday == gm->tm_yday) minswest = (gm->tm_hour - lt->tm_hour) * 60 + - (gm->tm_min - lt->tm_min); + (gm->tm_min - lt->tm_min); else if (lt->tm_yday > gm->tm_yday) minswest = (gm->tm_hour - (lt->tm_hour + 24)) * 60; else @@ -145,9 +161,9 @@ const char *long_date(time_t clock) if (minswest < 0) minswest = -minswest; ircsnprintf(buf, sizeof(buf), "%s %s %d %d -- %02d:%02d %c%02d:%02d", - weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday, - 1900 + lt->tm_year, - lt->tm_hour, lt->tm_min, plus, minswest / 60, minswest % 60); + weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday, + 1900 + lt->tm_year, + lt->tm_hour, lt->tm_min, plus, minswest / 60, minswest % 60); return buf; } @@ -232,9 +248,9 @@ char *make_user_host(const char *name, const char *host) { static char namebuf[USERLEN + HOSTLEN + 6]; - strlncpy(namebuf, check_string(name), sizeof(namebuf), USERLEN+1); + strlncpy(namebuf, check_string(name), sizeof(namebuf), USERLEN + 1); strlcat(namebuf, "@", sizeof(namebuf)); - strlncat(namebuf, check_string(host), sizeof(namebuf), HOSTLEN+1); + strlncat(namebuf, check_string(host), sizeof(namebuf), HOSTLEN + 1); return namebuf; } @@ -244,11 +260,11 @@ char *make_user_host(const char *name, const char *host) */ char *make_nick_user_host_r(char *namebuf, size_t namebuflen, const char *nick, const char *name, const char *host) { - strlncpy(namebuf, check_string(nick), namebuflen, NICKLEN+1); + strlncpy(namebuf, check_string(nick), namebuflen, NICKLEN + 1); strlcat(namebuf, "!", namebuflen); - strlncat(namebuf, check_string(name), namebuflen, USERLEN+1); + strlncat(namebuf, check_string(name), namebuflen, USERLEN + 1); strlcat(namebuf, "@", namebuflen); - strlncat(namebuf, check_string(host), namebuflen, HOSTLEN+1); + strlncat(namebuf, check_string(host), namebuflen, HOSTLEN + 1); return namebuf; } @@ -351,14 +367,15 @@ const char *get_client_name(Client *client, int showip) if (showip) { ircsnprintf(nbuf, sizeof(nbuf), "%s[%s@%s.%d]", - client->name, - IsIdentSuccess(client) ? client->ident : "", - client->ip ? client->ip : "???", - get_client_port(client)); - } else { + client->name, + IsIdentSuccess(client) ? client->ident : "", + client->ip ? client->ip : "???", + get_client_port(client)); + } else + { if (mycmp(client->name, client->local->sockhost)) ircsnprintf(nbuf, sizeof(nbuf), "%s[%s]", - client->name, client->local->sockhost); + client->name, client->local->sockhost); else return client->name; } @@ -376,9 +393,9 @@ const char *get_client_host(Client *client) if (!client->local->hostp) return get_client_name(client, FALSE); ircsnprintf(nbuf, sizeof(nbuf), "%s[%-.*s@%-.*s]", - client->name, USERLEN, - IsIdentSuccess(client) ? client->ident : "", - HOSTLEN, client->local->hostp->h_name); + client->name, USERLEN, + IsIdentSuccess(client) ? client->ident : "", + HOSTLEN, client->local->hostp->h_name); return nbuf; } @@ -400,7 +417,7 @@ int on_dccallow_list(Client *to, Client *from) { Link *lp; - for(lp = to->user->dccallow; lp; lp = lp->next) + for (lp = to->user->dccallow; lp; lp = lp->next) if (lp->flags == DCC_LINK_ME && lp->value.client == from) return 1; return 0; @@ -456,11 +473,12 @@ int valid_host(const char *host, int strict) if (strict) { - for (p=host; *p; p++) + for (p = host; *p; p++) if (!isalnum(*p) && !strchr("_-.", *p)) return 0; - } else { - for (p=host; *p; p++) + } else + { + for (p = host; *p; p++) if (!isalnum(*p) && !strchr("_-.:/", *p)) return 0; } @@ -500,7 +518,7 @@ int valid_vhost(const char *userhost) char uhost[512], *p; const char *host = userhost; - strlcpy(uhost, userhost, sizeof(uhost)); + strlcpy(uhost, userhost, sizeof(uhost)); if ((p = strchr(uhost, '@'))) { @@ -565,33 +583,29 @@ int parse_ban_action_set(const char *str, char **var, VarActionValue *op, int *v { *op = VAR_ACT_INCREASE; *p = '\0'; - p+=2; + p += 2; *value = 1; - } else - if (!strncmp(p, "--", 2)) + } else if (!strncmp(p, "--", 2)) { *op = VAR_ACT_DECREASE; *p = '\0'; - p+=2; + p += 2; *value = 1; - } else - if (!strncmp(p, "+=", 2)) + } else if (!strncmp(p, "+=", 2)) { *op = VAR_ACT_INCREASE; *p = '\0'; - p+=2; - } else - if (!strncmp(p, "-=", 2)) + p += 2; + } else if (!strncmp(p, "-=", 2)) { *op = VAR_ACT_DECREASE; *p = '\0'; - p+=2; - } else - if (!strncmp(p, "=", 1)) + p += 2; + } else if (!strncmp(p, "=", 1)) { *op = VAR_ACT_SET; *p = '\0'; - p+=1; + p += 1; } else { *error = "Unknown set action, should be one of: ++, --, +=, -= or ="; @@ -624,14 +638,14 @@ int test_ban_action_config_helper(ConfigEntry *ce, const char *name, const char if (!action) { config_error("%s:%d: unknown action: %s", - ce->file->filename, ce->line_number, name); + ce->file->filename, ce->line_number, name); errors++; } else if (action == BAN_ACT_SET) { if (!value) { config_error("%s:%d: action set is missing a value", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } else { @@ -642,7 +656,7 @@ int test_ban_action_config_helper(ConfigEntry *ce, const char *name, const char if (!parse_ban_action_set(value, &var, &op, &varvalue, &error)) { config_error("%s:%d: action: %s", - ce->file->filename, ce->line_number, error); + ce->file->filename, ce->line_number, error); errors++; } } @@ -667,8 +681,7 @@ int test_ban_action_config(ConfigEntry *ce) /* action { xxx; } */ for (cep = ce->items; cep; cep = cep->next) errors += test_ban_action_config_helper(cep, cep->name, cep->value); - } else - if (!ce->value) + } else if (!ce->value) { config_error("%s:%d: action has no value", ce->file->filename, ce->line_number); errors++; @@ -701,8 +714,7 @@ BanAction *parse_ban_action_config_helper(const char *name, const char *value) safe_strdup(action->var, var); action->value = varvalue; action->var_action = op; - } else - if (action->action == BAN_ACT_REPORT) + } else if (action->action == BAN_ACT_REPORT) { safe_strdup(action->var, value); // can be NULL, means all } @@ -738,8 +750,7 @@ void parse_ban_action_config(ConfigEntry *ce, BanAction **store_actions) if (action) append_ListItem((ListStruct *)action, (ListStruct **)store_actions); } - } else - if (ce->value) + } else if (ce->value) { /* action xxx; */ action = parse_ban_action_config_helper(ce->value, NULL); @@ -858,7 +869,7 @@ const char *ban_actions_to_string(BanAction *actions) /* Cut off trailing "," */ if (*buf) - buf[strlen(buf)-1] = '\0'; + buf[strlen(buf) - 1] = '\0'; return buf; } @@ -926,8 +937,8 @@ BanAction *duplicate_ban_actions(BanAction *actions) /** Extract target flags from string 's'. */ int spamfilter_gettargets(const char *s, Client *client) { -SpamfilterTargetTable *e; -int flags = 0; + SpamfilterTargetTable *e; + int flags = 0; for (; *s; s++) { @@ -949,7 +960,7 @@ int flags = 0; /** Convert a string with a targetname to an integer value */ int spamfilter_getconftargets(const char *s) { -SpamfilterTargetTable *e; + SpamfilterTargetTable *e; for (e = &spamfiltertargettable[0]; e->value; e++) if (!strcmp(s, e->name)) @@ -979,17 +990,17 @@ char *unreal_decodespace(const char *s) const char *i; static char buf[512], *o; - for (i = s, o = buf; (*i) && (o < buf+510); i++) + for (i = s, o = buf; (*i) && (o < buf + 510); i++) if (*i == '_') { if (i[1] != '_') *o++ = ' '; - else { + else + { *o++ = '_'; i++; } - } - else + } else *o++ = *i; *o = '\0'; return buf; @@ -1006,7 +1017,7 @@ char *unreal_encodespace(const char *s) if (!s) return NULL; /* NULL in = NULL out */ - for (i = s, o = buf; (*i) && (o < buf+509); i++) + for (i = s, o = buf; (*i) && (o < buf + 509); i++) { if (*i == ' ') *o++ = '_'; @@ -1014,8 +1025,7 @@ char *unreal_encodespace(const char *s) { *o++ = '_'; *o++ = '_'; - } - else + } else *o++ = *i; } *o = '\0'; @@ -1055,8 +1065,7 @@ void unreal_add_names(NameList **n, ConfigEntry *ce) ConfigEntry *cep; for (cep = ce->items; cep; cep = cep->next) _add_name_list(n, cep->value ? cep->value : cep->name); - } else - if (ce->value) + } else if (ce->value) { _add_name_list(n, ce->value); } @@ -1070,8 +1079,7 @@ void unreal_add_name_values(NameValuePrioList **n, const char *name, ConfigEntry ConfigEntry *cep; for (cep = ce->items; cep; cep = cep->next) add_nvplist(n, 0, name, cep->value ? cep->value : cep->name); - } else - if (ce->value) + } else if (ce->value) { add_nvplist(n, 0, name, ce->value); } @@ -1110,7 +1118,7 @@ const char *namevalue_nospaces(NameValuePrioList *n) snprintf(buf, sizeof(buf), "%s:%s", n->name, n->value); /* Replace spaces with underscores */ - for (p=buf; *p; p++) + for (p = buf; *p; p++) if (*p == ' ') *p = '_'; @@ -1137,7 +1145,7 @@ char *our_strcasestr(const char *haystack, const char *needle) for (i = 0; i <= (hlength - nlength); i++) { - if (strncasecmp (haystack + i, needle, nlength) == 0) + if (strncasecmp(haystack + i, needle, nlength) == 0) return (char *)(haystack + i); } @@ -1170,10 +1178,10 @@ int swhois_add(Client *client, const char *tag, int priority, const char *swhois AddListItemPrio(s, client->user->swhois, s->priority); sendto_server(skip, 0, PROTO_EXTSWHOIS, NULL, ":%s SWHOIS %s :%s", - from->id, client->id, swhois); + from->id, client->id, swhois); sendto_server(skip, PROTO_EXTSWHOIS, 0, NULL, ":%s SWHOIS %s + %s %d :%s", - from->id, client->id, tag, priority, swhois); + from->id, client->id, tag, priority, swhois); return 0; } @@ -1198,8 +1206,8 @@ int swhois_delete(Client *client, const char *tag, const char *swhois, Client *f s_next = s->next; /* If ( same swhois or "*" ) AND same tag */ - if ( ((!strcmp(s->line, swhois) || !strcmp(swhois, "*")) && - !strcmp(s->setby, tag))) + if (((!strcmp(s->line, swhois) || !strcmp(swhois, "*")) && + !strcmp(s->setby, tag))) { DelListItem(s, client->user->swhois); safe_free(s->line); @@ -1207,10 +1215,10 @@ int swhois_delete(Client *client, const char *tag, const char *swhois, Client *f safe_free(s); sendto_server(skip, 0, PROTO_EXTSWHOIS, NULL, ":%s SWHOIS %s :", - from->id, client->id); + from->id, client->id); sendto_server(skip, PROTO_EXTSWHOIS, 0, NULL, ":%s SWHOIS %s - %s %d :%s", - from->id, client->id, tag, 0, swhois); + from->id, client->id, tag, 0, swhois); ret = 0; } @@ -1426,7 +1434,8 @@ void new_message_special(Client *sender, MessageTag *recv_mtags, MessageTag **mt void parse_message_tags_default_handler(Client *client, char **str, MessageTag **mtag_list) { /* Just skip everything until the space character */ - for (; **str && **str != ' '; *str = *str + 1); + for (; **str && **str != ' '; *str = *str + 1) + ; } /** Default handler for mtags_to_string(). @@ -1686,7 +1695,8 @@ time_t my_timegm(struct tm *tm) { setenv("TZ", tz, 1); safe_free(tz); - } else { + } else + { unsetenv("TZ"); } tzset(); @@ -1710,13 +1720,13 @@ time_t server_time_to_unix_time(const char *tbuf) memset(&tm, 0, sizeof(tm)); ret = sscanf(tbuf, "%d-%d-%dT%d:%d:%d.%dZ", - &tm.tm_year, - &tm.tm_mon, - &tm.tm_mday, - &tm.tm_hour, - &tm.tm_min, - &tm.tm_sec, - &dontcare); + &tm.tm_year, + &tm.tm_mon, + &tm.tm_mday, + &tm.tm_hour, + &tm.tm_min, + &tm.tm_sec, + &dontcare); if (ret != 7) return 0; @@ -1752,7 +1762,7 @@ time_t rfc2616_time_to_unix_time(const char *tbuf) if (ret < 6) return 0; - for (i=0; i < 12; i++) + for (i = 0; i < 12; i++) { if (!strcmp(short_months[i], month)) { @@ -1776,7 +1786,7 @@ const char *rfc2616_time(time_t clock) static char buf[80], plus; struct tm *lt, *gm; struct tm gmbuf; - int minswest; + int minswest; if (!clock) time(&clock); @@ -1950,7 +1960,7 @@ void binarytohex(void *data, size_t len, char *str) char *datastr = (char *)data; int i, n = 0; - for (i=0; i> 4) & 0xF]; str[n++] = hexchars[datastr[i] & 0xF]; @@ -2060,7 +2070,7 @@ const char *sha256sum_file(const char *fname) char buf[2048]; SHA256_CTX hash; char binaryhash[SHA256_DIGEST_LENGTH]; - static char hexhash[SHA256_DIGEST_LENGTH*2+1]; + static char hexhash[SHA256_DIGEST_LENGTH * 2 + 1]; int n; #if OPENSSL_VERSION_NUMBER >= 0x30000000L unsigned int md_len; @@ -2137,10 +2147,11 @@ char *filename_strip_suffix(const char *fname, const char *suffix) int suffix_len = strlen(suffix); if (buf_len >= suffix_len) { - if (!strncmp(buf+buf_len-suffix_len, suffix, suffix_len)) - buf[buf_len-suffix_len] = '\0'; + if (!strncmp(buf + buf_len - suffix_len, suffix, suffix_len)) + buf[buf_len - suffix_len] = '\0'; } - } else { + } else + { char *p = strrchr(buf, '.'); if (p) *p = '\0'; @@ -2277,13 +2288,14 @@ MultiLine *line2multiline(const char *str) strlcpy(buf, str, sizeof(buf)); p = buf; - do { + do + { p2 = strchr(p, '\n'); if (p2) *p2++ = '\0'; addmultiline(&ml, p); p = p2; - } while(p2 && *p2); + } while (p2 && *p2); return ml; } @@ -2308,7 +2320,7 @@ const char *sendtype_to_cmd(SendType sendtype) int check_password_strength(const char *pass, int min_length, int strict, char **err) { static char buf[256]; - char has_lowercase=0, has_uppercase=0, has_digit=0; + char has_lowercase = 0, has_uppercase = 0, has_digit = 0; const char *p; if (err) @@ -2324,7 +2336,7 @@ int check_password_strength(const char *pass, int min_length, int strict, char * return 0; } - for (p=pass; *p; p++) + for (p = pass; *p; p++) { if (islower(*p)) has_lowercase = 1; @@ -2341,14 +2353,12 @@ int check_password_strength(const char *pass, int min_length, int strict, char * if (err) *err = "Password must contain at least 1 lowercase character"; return 0; - } else - if (!has_uppercase) + } else if (!has_uppercase) { if (err) *err = "Password must contain at least 1 UPPERcase character"; return 0; - } else - if (!has_digit) + } else if (!has_digit) { if (err) *err = "Password must contain at least 1 digit (number)"; @@ -2418,7 +2428,8 @@ int terminal_supports_color(void) /** Skip whitespace (if any) */ void skip_whitespace(char **p) { - for (; **p == ' ' || **p == '\t'; *p = *p + 1); + for (; **p == ' ' || **p == '\t'; *p = *p + 1) + ; } /** Keep reading '*p' until we hit any of the 'stopchars'. @@ -2427,16 +2438,17 @@ void skip_whitespace(char **p) */ void read_until(char **p, char *stopchars) { - for (; **p && !strchr(stopchars, **p); *p = *p + 1); + for (; **p && !strchr(stopchars, **p); *p = *p + 1) + ; } void write_pidfile_failed(void) { char *errstr = strerror(errno); unreal_log(ULOG_WARNING, "config", "WRITE_PID_FILE_FAILED", NULL, - "Unable to write to pid file '$filename': $system_error", - log_data_string("filename", conf_files->pid_file), - log_data_string("system_error", errstr)); + "Unable to write to pid file '$filename': $system_error", + log_data_string("filename", conf_files->pid_file), + log_data_string("system_error", errstr)); } /** Write PID file */ @@ -2534,8 +2546,7 @@ char *url_getfilename(const char *url) if (!*c) return raw_strdup(start); else - return raw_strldup(start, c-start+1); - + return raw_strldup(start, c - start + 1); } return raw_strdup("-"); } @@ -2554,7 +2565,8 @@ int is_file_readable(const char *file, const char *dir) { char *filename = strdup(file); convert_to_absolute_path(&filename, dir); - if (access(filename, R_OK)){ + if (access(filename, R_OK)) + { safe_free(filename); return 0; } @@ -2637,12 +2649,11 @@ void s_die() loop.terminating = 1; unload_all_modules(); - list_for_each_entry(client, &lclient_list, lclient_node) - (void) send_queued(client); + list_for_each_entry(client, &lclient_list, lclient_node)(void) send_queued(client); exit(-1); - } - else { + } else + { SERVICE_STATUS status; SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); SC_HANDLE hService = OpenService(hSCManager, "UnrealIRCd", SERVICE_STOP); @@ -2705,10 +2716,10 @@ void ignore_this_signal() (void)sigaddset(&act.sa_mask, SIGPIPE); (void)sigaction(SIGALRM, &act, (struct sigaction *)NULL); (void)sigaction(SIGPIPE, &act, (struct sigaction *)NULL); -#ifdef SIGWINCH + #ifdef SIGWINCH (void)sigaddset(&act.sa_mask, SIGWINCH); (void)sigaction(SIGWINCH, &act, (struct sigaction *)NULL); -#endif + #endif } #endif /* #ifndef _WIN32 */ @@ -2721,8 +2732,7 @@ void server_reboot(const char *mesg) "Restarting server: $reason", log_data_string("reason", mesg)); - list_for_each_entry(client, &lclient_list, lclient_node) - (void) send_queued(client); + list_for_each_entry(client, &lclient_list, lclient_node)(void) send_queued(client); /* * ** fd 0 must be 'preserved' if either the -d or -i options have @@ -2763,14 +2773,13 @@ void server_reboot(const char *mesg) SetServiceStatus(IRCDStatusHandle, &IRCDStatus); GetModuleFileName(GetModuleHandle(NULL), fname, MAX_PATH); CreateProcess(fname, "restartsvc", NULL, NULL, FALSE, - 0, NULL, NULL, &si, &pi); + 0, NULL, NULL, &si, &pi); IRCDStatus.dwCurrentState = SERVICE_STOPPED; SetServiceStatus(IRCDStatusHandle, &IRCDStatus); ExitProcess(0); - } - else + } else #endif - exit(-1); + exit(-1); } /** Check if at least 'minimum' seconds passed by since last run. @@ -2789,7 +2798,7 @@ int minimum_msec_since_last_run(struct timeval *tv_old, long minimum) tv_old->tv_usec = timeofday_tv.tv_usec; return 0; } - v = ((timeofday_tv.tv_sec - tv_old->tv_sec) * 1000) + ((timeofday_tv.tv_usec - tv_old->tv_usec)/1000); + v = ((timeofday_tv.tv_sec - tv_old->tv_sec) * 1000) + ((timeofday_tv.tv_usec - tv_old->tv_usec) / 1000); if (v >= minimum) { tv_old->tv_sec = timeofday_tv.tv_sec; @@ -2808,10 +2817,10 @@ int minimum_msec_since_last_run(struct timeval *tv_old, long minimum) */ const char *StripControlCodesEx(const char *text, char *output, size_t outputlen, int strip_flags) { - int i = 0, len = strlen(text), save_len=0; + int i = 0, len = strlen(text), save_len = 0; char nc = 0, col = 0, rgb = 0; char *o = output; - const char *save_text=NULL; + const char *save_text = NULL; /* Handle special cases first.. */ @@ -2827,7 +2836,7 @@ const char *StripControlCodesEx(const char *text, char *output, size_t outputlen /* Reserve room for the NUL byte */ outputlen--; - while (len > 0) + while (len > 0) { if ((col && isdigit(*text) && nc < 2) || ((col == 1) && (*text == ',') && isdigit(text[1]) && (nc > 0) && (nc < 3))) @@ -2848,8 +2857,7 @@ const char *StripControlCodesEx(const char *text, char *output, size_t outputlen nc++; if (*text == ',') nc = 0; - } - else + } else { if (col) col = 0; @@ -2857,8 +2865,8 @@ const char *StripControlCodesEx(const char *text, char *output, size_t outputlen { if (nc != 6) { - text = save_text+1; - len = save_len-1; + text = save_text + 1; + len = save_len - 1; rgb = 0; continue; } @@ -2866,63 +2874,62 @@ const char *StripControlCodesEx(const char *text, char *output, size_t outputlen } switch (*text) { - case 3: - /* color */ - col = 1; - nc = 0; - break; - case 4: - /* RGB */ - save_text = text; - save_len = len; - rgb = 1; - nc = 0; - break; - case 2: - /* bold */ - break; - case 31: - /* underline */ - break; - case 22: - /* reverse */ - break; - case 15: - /* plain */ - break; - case 29: - /* italic */ - break; - case 30: - /* strikethrough */ - break; - case 17: - /* monospace */ - break; - case 0xe2: - if (!strncmp(text+1, "\x80\x8b", 2)) - { - /* +2 means we skip 3 */ - text += 2; - len -= 2; + case 3: + /* color */ + col = 1; + nc = 0; break; - } - /*fallthrough*/ - default: - if ((*text >= ' ') || - !(strip_flags & UNRL_STRIP_LOW_ASCII) || - ((strip_flags & UNRL_STRIP_KEEP_LF) && (*text == '\n')) - ) - { - *o++ = *text; - outputlen--; - if (outputlen == 0) + case 4: + /* RGB */ + save_text = text; + save_len = len; + rgb = 1; + nc = 0; + break; + case 2: + /* bold */ + break; + case 31: + /* underline */ + break; + case 22: + /* reverse */ + break; + case 15: + /* plain */ + break; + case 29: + /* italic */ + break; + case 30: + /* strikethrough */ + break; + case 17: + /* monospace */ + break; + case 0xe2: + if (!strncmp(text + 1, "\x80\x8b", 2)) { - *o = '\0'; - return output; + /* +2 means we skip 3 */ + text += 2; + len -= 2; + break; } - } - break; + /*fallthrough*/ + default: + if ((*text >= ' ') || + !(strip_flags & UNRL_STRIP_LOW_ASCII) || + ((strip_flags & UNRL_STRIP_KEEP_LF) && (*text == '\n'))) + { + *o++ = *text; + outputlen--; + if (outputlen == 0) + { + *o = '\0'; + return output; + } + } + break; } } text++; @@ -3045,9 +3052,9 @@ void free_outgoingwebrequest(OutgoingWebRequest *r) safe_free(r->apicallback); safe_free(r->url); safe_free(r->actual_url); - safe_free(r->body); - safe_free_nvplist(r->headers); - safe_free(r); + safe_free(r->body); + safe_free_nvplist(r->headers); + safe_free(r); } /** Safely duplicate an OutgoingWebRequest struct (eg for https redirects) */ @@ -3157,7 +3164,8 @@ void synchronous_http_request_handle_response(OutgoingWebRequest *request, Outgo { strlcpy(synchronous_http_request_tmpfile, response->file, sizeof(synchronous_http_request_tmpfile)); synchronous_http_request_in_progress = 0; - } else { + } else + { config_error("%s: Unexpected error, no error but no file", request->url); synchronous_http_request_in_progress = -1; } diff --git a/src/modulemanager.c b/src/modulemanager.c index eab99bc06..b47f6ec06 100644 --- a/src/modulemanager.c +++ b/src/modulemanager.c @@ -7,13 +7,12 @@ #include "unrealircd.h" #ifndef _WIN32 -#define MODULEMANAGER_CONNECT_TIMEOUT 7 -#define MODULEMANAGER_TRANSFER_TIMEOUT 20 + #define MODULEMANAGER_CONNECT_TIMEOUT 7 + #define MODULEMANAGER_TRANSFER_TIMEOUT 20 typedef struct ManagedModule ManagedModule; -struct ManagedModule -{ +struct ManagedModule { ManagedModule *prev, *next; char *repo_url; char *name; @@ -44,24 +43,29 @@ static int no_make_install = 0; /* Forward declarations */ int mm_valid_module_name(char *name); -#define safe_free_managed_module(x) do { free_managed_module(x); x = NULL; } while(0) + #define safe_free_managed_module(x) \ + do \ + { \ + free_managed_module(x); \ + x = NULL; \ + } while (0) void free_managed_module(ManagedModule *m); typedef enum ParseModuleHeaderStage { - PMH_STAGE_LOOKING = 0, - PMH_STAGE_MODULEHEADER = 1, - PMH_STAGE_MOD_HEADER = 2, - PMH_STAGE_GOT_NAME = 3, - PMH_STAGE_GOT_VERSION = 4, - PMH_STAGE_GOT_DESCRIPTION = 5, - PMH_STAGE_GOT_AUTHOR = 6, - PMT_STAGE_DONE = 7, + PMH_STAGE_LOOKING = 0, + PMH_STAGE_MODULEHEADER = 1, + PMH_STAGE_MOD_HEADER = 2, + PMH_STAGE_GOT_NAME = 3, + PMH_STAGE_GOT_VERSION = 4, + PMH_STAGE_GOT_DESCRIPTION = 5, + PMH_STAGE_GOT_AUTHOR = 6, + PMT_STAGE_DONE = 7, } ParseModuleHeaderStage; typedef enum ParseModuleConfigStage { - PMC_STAGE_LOOKING = 0, - PMC_STAGE_STARTED = 1, - PMC_STAGE_FINISHED = 2, + PMC_STAGE_LOOKING = 0, + PMC_STAGE_STARTED = 1, + PMC_STAGE_FINISHED = 2, } ParseModuleConfigStage; int parse_quoted_string(char *buf, char *dest, size_t destlen) @@ -73,19 +77,24 @@ int parse_quoted_string(char *buf, char *dest, size_t destlen) p = strchr(buf, '"'); if (!p) return 0; - p2 = strrchr(p+1, '"'); + p2 = strrchr(p + 1, '"'); if (!p2) return 0; max = p2 - p; if (max > destlen) max = destlen; - strlcpy(dest, p+1, max); + strlcpy(dest, p + 1, max); unreal_del_quotes(dest); return 1; } -#undef CheckNull -#define CheckNull(x) if ((!(x)->value) || (!(*((x)->value)))) { config_error("%s:%i: missing parameter", m->name, (x)->line_number); return 0; } + #undef CheckNull + #define CheckNull(x) \ + if ((!(x)->value) || (!(*((x)->value)))) \ + { \ + config_error("%s:%i: missing parameter", m->name, (x)->line_number); \ + return 0; \ + } /** Parse a module { } line from a module (not repo!!) */ int mm_module_file_config(ManagedModule *m, ConfigEntry *ce) @@ -95,7 +104,7 @@ int mm_module_file_config(ManagedModule *m, ConfigEntry *ce) if (ce->value) { config_error("%s:%d: module { } block should not have a name.", - m->name, ce->line_number); + m->name, ce->line_number); return 0; } @@ -104,47 +113,41 @@ int mm_module_file_config(ManagedModule *m, ConfigEntry *ce) if (!strcmp(cep->name, "source") || !strcmp(cep->name, "version") || !strcmp(cep->name, "author") || - !strcmp(cep->name, "sha256sum") || - !strcmp(cep->name, "description") - ) + !strcmp(cep->name, "sha256sum") || + !strcmp(cep->name, "description")) { config_error("%s:%d: module::%s should not be in here (it only exists in repository entries)", - m->name, cep->line_number, cep->name); + m->name, cep->line_number, cep->name); return 0; - } - else if (!strcmp(cep->name, "troubleshooting")) + } else if (!strcmp(cep->name, "troubleshooting")) { CheckNull(cep); safe_strdup(m->troubleshooting, cep->value); - } - else if (!strcmp(cep->name, "documentation")) + } else if (!strcmp(cep->name, "documentation")) { CheckNull(cep); safe_strdup(m->documentation, cep->value); - } - else if (!strcmp(cep->name, "min-unrealircd-version")) + } else if (!strcmp(cep->name, "min-unrealircd-version")) { CheckNull(cep); safe_strdup(m->min_unrealircd_version, cep->value); - } - else if (!strcmp(cep->name, "max-unrealircd-version")) + } else if (!strcmp(cep->name, "max-unrealircd-version")) { CheckNull(cep); safe_strdup(m->max_unrealircd_version, cep->value); - } - else if (!strcmp(cep->name, "compile-flags")) + } else if (!strcmp(cep->name, "compile-flags")) { CheckNull(cep); safe_strdup(m->compile_flags, cep->value); - } - else if (!strcmp(cep->name, "post-install-text")) + } else if (!strcmp(cep->name, "post-install-text")) { if (cep->items) { ConfigEntry *cepp; for (cepp = cep->items; cepp; cepp = cepp->next) addmultiline(&m->post_install_text, cepp->name); - } else { + } else + { CheckNull(cep); addmultiline(&m->post_install_text, cep->value); } @@ -177,7 +180,7 @@ int mm_module_file_config(ManagedModule *m, ConfigEntry *ce) return 1; } -#undef CheckNull + #undef CheckNull int mm_parse_module_file(ManagedModule *m, char *buf, unsigned int line_offset) { @@ -204,7 +207,7 @@ int mm_parse_module_file(ManagedModule *m, char *buf, unsigned int line_offset) return 1; } -#define MODULECONFIGBUFFER 16384 + #define MODULECONFIGBUFFER 16384 ManagedModule *mm_parse_module_c_file(char *modulename, char *fname, int silent) { char buf[1024]; @@ -231,7 +234,7 @@ ManagedModule *mm_parse_module_c_file(char *modulename, char *fname, int silent) if (!fd) { fprintf(stderr, "Unable to open module '%s', file '%s': %s\n", - modulename, fname, strerror(errno)); + modulename, fname, strerror(errno)); return NULL; } @@ -276,7 +279,8 @@ ManagedModule *mm_parse_module_c_file(char *modulename, char *fname, int silent) switch (parse_module_config) { case PMC_STAGE_LOOKING: - if (strstr(buf, "<<>>")){ + if (strstr(buf, "<<>>")) + { module_config_start_line = linenr; parse_module_config = PMC_STAGE_STARTED; } @@ -309,7 +313,7 @@ ManagedModule *mm_parse_module_c_file(char *modulename, char *fname, int silent) if (strcmp(module_header_name, modulename)) { fprintf(stderr, "ERROR: Mismatch in module name in header (%s) and filename (%s)\n", - module_header_name, modulename); + module_header_name, modulename); safe_free(moduleconfig); return NULL; } @@ -319,7 +323,7 @@ ManagedModule *mm_parse_module_c_file(char *modulename, char *fname, int silent) if (!silent) { fprintf(stderr, "ERROR: Module does not contain module config data (<<>>)\n" - "This means it is not meant to be managed by the module manager\n"); + "This means it is not meant to be managed by the module manager\n"); } safe_free(moduleconfig); return NULL; @@ -336,12 +340,12 @@ ManagedModule *mm_parse_module_c_file(char *modulename, char *fname, int silent) { fprintf(stderr, "ERROR: Problem with module manager data block within the %s module C source file.\n" "You are suggested to contact the module author and paste the above to him/her\n", - m->name); + m->name); safe_free_managed_module(m); safe_free(moduleconfig); return NULL; } - + safe_free(moduleconfig); return m; } @@ -363,7 +367,7 @@ char *mm_sourceslist_file(void) { fprintf(stderr, "ERROR: Neither '%s' nor '%s' exist.\n" "No module repositories configured.\n", - buf1, buf2); + buf1, buf2); print_documentation(); exit(-1); } @@ -407,8 +411,13 @@ int mm_valid_module_name(char *name) return 1; } -#undef CheckNull -#define CheckNull(x) if ((!(x)->value) || (!(*((x)->value)))) { config_error("%s:%i: missing parameter", repo_url, (x)->line_number); goto fail_mm_repo_module_config; } + #undef CheckNull + #define CheckNull(x) \ + if ((!(x)->value) || (!(*((x)->value)))) \ + { \ + config_error("%s:%i: missing parameter", repo_url, (x)->line_number); \ + goto fail_mm_repo_module_config; \ + } /** Parse a module { } line from a repository */ ManagedModule *mm_repo_module_config(char *repo_url, ConfigEntry *ce) @@ -419,19 +428,19 @@ ManagedModule *mm_repo_module_config(char *repo_url, ConfigEntry *ce) if (!ce->value) { config_error("%s:%d: module { } with no name", - repo_url, ce->line_number); + repo_url, ce->line_number); goto fail_mm_repo_module_config; } if (!str_starts_with_case_sensitive(ce->value, "third/")) { config_error("%s:%d: module { } name must start with: third/", - repo_url, ce->line_number); + repo_url, ce->line_number); goto fail_mm_repo_module_config; } if (!mm_valid_module_name(ce->value)) { config_error("%s:%d: module { } with illegal name: %s", - repo_url, ce->line_number, ce->value); + repo_url, ce->line_number, ce->value); goto fail_mm_repo_module_config; } safe_strdup(m->name, ce->value); @@ -443,60 +452,51 @@ ManagedModule *mm_repo_module_config(char *repo_url, ConfigEntry *ce) { CheckNull(cep); safe_strdup(m->source, cep->value); - } - else if (!strcmp(cep->name, "sha256sum")) + } else if (!strcmp(cep->name, "sha256sum")) { CheckNull(cep); safe_strdup(m->sha256sum, cep->value); - } - else if (!strcmp(cep->name, "version")) + } else if (!strcmp(cep->name, "version")) { CheckNull(cep); safe_strdup(m->version, cep->value); - } - else if (!strcmp(cep->name, "author")) + } else if (!strcmp(cep->name, "author")) { CheckNull(cep); safe_strdup(m->author, cep->value); - } - else if (!strcmp(cep->name, "troubleshooting")) + } else if (!strcmp(cep->name, "troubleshooting")) { CheckNull(cep); safe_strdup(m->troubleshooting, cep->value); - } - else if (!strcmp(cep->name, "documentation")) + } else if (!strcmp(cep->name, "documentation")) { CheckNull(cep); safe_strdup(m->documentation, cep->value); - } - else if (!strcmp(cep->name, "min-unrealircd-version")) + } else if (!strcmp(cep->name, "min-unrealircd-version")) { CheckNull(cep); safe_strdup(m->min_unrealircd_version, cep->value); - } - else if (!strcmp(cep->name, "max-unrealircd-version")) + } else if (!strcmp(cep->name, "max-unrealircd-version")) { CheckNull(cep); safe_strdup(m->max_unrealircd_version, cep->value); - } - else if (!strcmp(cep->name, "compile-flags")) + } else if (!strcmp(cep->name, "compile-flags")) { CheckNull(cep); safe_strdup(m->compile_flags, cep->value); - } - else if (!strcmp(cep->name, "description")) + } else if (!strcmp(cep->name, "description")) { CheckNull(cep); safe_strdup(m->description, cep->value); - } - else if (!strcmp(cep->name, "post-install-text")) + } else if (!strcmp(cep->name, "post-install-text")) { if (cep->items) { ConfigEntry *cepp; for (cepp = cep->items; cepp; cepp = cepp->next) addmultiline(&m->post_install_text, cepp->name); - } else { + } else + { CheckNull(cep); addmultiline(&m->post_install_text, cep->value); } @@ -554,7 +554,7 @@ fail_mm_repo_module_config: return NULL; } -#undef CheckNull + #undef CheckNull int mm_parse_repo_db(char *url, const char *filename) { @@ -595,7 +595,7 @@ int mm_refresh_repository(void) if (!file_exists(TMPDIR)) { - (void)mkdir(TMPDIR, S_IRUSR|S_IWUSR|S_IXUSR); /* Create the tmp dir, if it doesn't exist */ + (void)mkdir(TMPDIR, S_IRUSR | S_IWUSR | S_IXUSR); /* Create the tmp dir, if it doesn't exist */ if (!file_exists(TMPDIR)) { /* This is possible if the directory structure does not exist, @@ -630,7 +630,7 @@ int mm_refresh_repository(void) if (!str_starts_with_case_sensitive(line, "https://")) { fprintf(stderr, "ERROR in %s on line %d: URL should start with https://", - sourceslist, linenr); + sourceslist, linenr); fclose(fd); return 0; } @@ -660,9 +660,9 @@ int mm_refresh_repository(void) return success ? 1 : 0; } -#define COLUMN_STATUS 0 -#define COLUMN_NAME 1 -#define COLUMN_VERSION 2 + #define COLUMN_STATUS 0 + #define COLUMN_NAME 1 + #define COLUMN_VERSION 2 void mm_list_print(char *status, char *name, char *version, char *description, int largest_column[3]) { @@ -710,10 +710,10 @@ int mm_check_module_compatibility(ManagedModule *m) return 1; } -#define MMMS_INSTALLED 0x0001 -#define MMMS_UPGRADE_AVAILABLE 0x0002 -#define MMMS_UNAVAILABLE 0x0004 -#define MMMS_LOCAL_VERSION_IS_NEWER 0x0008 + #define MMMS_INSTALLED 0x0001 + #define MMMS_UPGRADE_AVAILABLE 0x0002 + #define MMMS_UNAVAILABLE 0x0004 + #define MMMS_LOCAL_VERSION_IS_NEWER 0x0008 int mm_get_module_status(ManagedModule *m) { @@ -736,7 +736,7 @@ int mm_get_module_status(ManagedModule *m) if (our_module && our_module->version && (strnatcasecmp(m->version, our_module->version) < 0)) { safe_free_managed_module(our_module); - return MMMS_INSTALLED|MMMS_LOCAL_VERSION_IS_NEWER; + return MMMS_INSTALLED | MMMS_LOCAL_VERSION_IS_NEWER; } safe_free_managed_module(our_module); @@ -745,9 +745,9 @@ int mm_get_module_status(ManagedModule *m) return MMMS_INSTALLED; if (!mm_check_module_compatibility(m)) - return MMMS_INSTALLED|MMMS_UNAVAILABLE; + return MMMS_INSTALLED | MMMS_UNAVAILABLE; - return MMMS_INSTALLED|MMMS_UPGRADE_AVAILABLE; + return MMMS_INSTALLED | MMMS_UPGRADE_AVAILABLE; } char *mm_get_module_status_string(ManagedModule *m) @@ -759,11 +759,11 @@ char *mm_get_module_status_string(ManagedModule *m) return "unav"; else if (status == MMMS_INSTALLED) return "inst"; - else if (status == (MMMS_INSTALLED|MMMS_UNAVAILABLE)) + else if (status == (MMMS_INSTALLED | MMMS_UNAVAILABLE)) return "inst/UNAV"; - else if (status == (MMMS_INSTALLED|MMMS_UPGRADE_AVAILABLE)) + else if (status == (MMMS_INSTALLED | MMMS_UPGRADE_AVAILABLE)) return "inst/UPD"; - else if (status == (MMMS_INSTALLED|MMMS_LOCAL_VERSION_IS_NEWER)) + else if (status == (MMMS_INSTALLED | MMMS_LOCAL_VERSION_IS_NEWER)) return "inst/LOCAL"; return "UNKNOWN?"; } @@ -777,11 +777,11 @@ char *mm_get_module_status_string_long(ManagedModule *m) return "Unavailable for your UnrealIRCd version"; else if (status == MMMS_INSTALLED) return "Installed and up to date"; - else if (status == (MMMS_INSTALLED|MMMS_UNAVAILABLE)) + else if (status == (MMMS_INSTALLED | MMMS_UNAVAILABLE)) return "Installed, an upgrade is available but not for your UnrealIRCd version"; - else if (status == (MMMS_INSTALLED|MMMS_UPGRADE_AVAILABLE)) + else if (status == (MMMS_INSTALLED | MMMS_UPGRADE_AVAILABLE)) return "Installed, upgrade available"; - else if (status == (MMMS_INSTALLED|MMMS_LOCAL_VERSION_IS_NEWER)) + else if (status == (MMMS_INSTALLED | MMMS_LOCAL_VERSION_IS_NEWER)) return "Installed, local version is newer than online version"; return "UNKNOWN?"; } @@ -940,7 +940,6 @@ void mm_list(char *searchname) } - /* Helper to get compile flags. Do not return NULL but "" here if none */ const char *mm_get_compile_flags(ManagedModule *m) { @@ -953,7 +952,7 @@ const char *mm_get_compile_flags(ManagedModule *m) /* Simple as-is for now */ flags = m->compile_flags; - unreal_add_quotes_r(flags, retbuf, sizeof(retbuf)-1); + unreal_add_quotes_r(flags, retbuf, sizeof(retbuf) - 1); return retbuf; } @@ -994,8 +993,7 @@ int mm_compile(ManagedModule *m, const char *tmpfile, int test, int upgrade) "cd \"%s\"; $MAKE custommodule MODULEFILE=\"%s\" EXLIBS=\"%s\"", BUILDDIR, filename_strip_suffix(basename, ".c"), - mm_get_compile_flags(m) - ); + mm_get_compile_flags(m)); fd = popen(cmd, "r"); if (!fd) { @@ -1003,7 +1001,7 @@ int mm_compile(ManagedModule *m, const char *tmpfile, int test, int upgrade) unlink(newpath); return 0; } - while((fgets(buf, sizeof(buf), fd))) + while ((fgets(buf, sizeof(buf), fd))) { printf("%s", buf); } @@ -1014,7 +1012,7 @@ int mm_compile(ManagedModule *m, const char *tmpfile, int test, int upgrade) /* Remove the XXXXXXX.modname.c file */ unlink(newpath); /* Remove the XXXXXXX.modname.so file */ - newpath[strlen(newpath)-2] = '\0'; // cut off .c + newpath[strlen(newpath) - 2] = '\0'; // cut off .c strlcat(newpath, ".so", sizeof(newpath)); unlink(newpath); } @@ -1026,7 +1024,7 @@ int mm_compile(ManagedModule *m, const char *tmpfile, int test, int upgrade) if (m->author && m->troubleshooting) { fprintf(stderr, "You are suggested to contact the author (%s) of this module %s:\n%s\n", - m->author, m->name, m->troubleshooting); + m->author, m->name, m->troubleshooting); } return 0; @@ -1071,7 +1069,8 @@ int mm_compile_all(int argc, char *args[]) m->unmanaged = 1; n = mm_compile(m, NULL, 0, 0); safe_free_managed_module(m); - } else { + } else + { n = mm_compile(m, NULL, 0, 0); } @@ -1117,10 +1116,10 @@ int mm_install_module(ManagedModule *m) fprintf(stderr, "ERROR: SHA256 Checksum mismatch\n" "Expected (value in repository list): %s\n" "Received (value of downloaded file): %s\n", - m->sha256sum, sha256); + m->sha256sum, sha256); fprintf(stderr, "Fatal error encountered, see above. Try running the command again in 5-10 minutes.\n" "If the issue persists, contact the repository manager of %s\n", - m->repo_url); + m->repo_url); return 0; } if (!mm_compile(m, tmpfile, 1, 1)) @@ -1223,9 +1222,9 @@ int mm_install(int argc, char *args[], int upgrade) fprintf(stderr, "ERROR: Module '%s' exists, but is not compatible with your UnrealIRCd version:\n" "Your UnrealIRCd version : %s\n" "Minimum version required : %s\n", - name, - VERSIONONLY, - m->min_unrealircd_version); + name, + VERSIONONLY, + m->min_unrealircd_version); if (m->max_unrealircd_version) fprintf(stderr, "Maximum version : %s\n", m->max_unrealircd_version); return 0; @@ -1236,7 +1235,7 @@ int mm_install(int argc, char *args[], int upgrade) printf("Module %s is the latest version, no upgrade needed\n", m->name); return 1; } - if (upgrade && (status == (MMMS_INSTALLED|MMMS_LOCAL_VERSION_IS_NEWER))) + if (upgrade && (status == (MMMS_INSTALLED | MMMS_LOCAL_VERSION_IS_NEWER))) { /* If updating, and we are already on latest version, then don't upgrade */ printf("Module %s: local version is newer than the online version, not upgrading.\n", m->name); @@ -1252,7 +1251,8 @@ int mm_install(int argc, char *args[], int upgrade) for (l = m->post_install_text; l; l = l->next) printf(" %s\n", l->line); printf("---\n"); - } else { + } else + { printf("Don't forget to add a 'loadmodule' line for the module and rehash\n"); } return 1; @@ -1309,19 +1309,17 @@ void mm_upgrade(int argc, char *args[]) for (m = managed_modules; m; m = m->next) { int status = mm_get_module_status(m); - if (status == (MMMS_INSTALLED|MMMS_UPGRADE_AVAILABLE)) + if (status == (MMMS_INSTALLED | MMMS_UPGRADE_AVAILABLE)) { args[1] = m->name; if (mm_install(1, args, 1)) upgraded++; else failed++; - } else - if ((status == MMMS_INSTALLED) || (status == (MMMS_INSTALLED|MMMS_LOCAL_VERSION_IS_NEWER))) + } else if ((status == MMMS_INSTALLED) || (status == (MMMS_INSTALLED | MMMS_LOCAL_VERSION_IS_NEWER))) { uptodate_already++; - } else - if (status == (MMMS_INSTALLED|MMMS_UNAVAILABLE)) + } else if (status == (MMMS_INSTALLED | MMMS_UNAVAILABLE)) { update_unavailable++; } @@ -1334,10 +1332,11 @@ void mm_upgrade(int argc, char *args[]) if (failed) { printf("There was %d FAILED module upgrade. %d module(s) upgraded, %d already up-to-date\n", - failed, upgraded, uptodate_already); - } else { + failed, upgraded, uptodate_already); + } else + { printf("All actions were successful. %d module(s) upgraded, %d already up-to-date\n", - upgraded, uptodate_already); + upgraded, uptodate_already); } if (update_unavailable) printf("%d module(s) have updates but not for your UnrealIRCd version\n", update_unavailable); @@ -1468,7 +1467,7 @@ void mm_generate_repository(int argc, char *args[]) exit(-1); } - if ((strlen(urlbasepath) < 2) || (urlbasepath[strlen(urlbasepath)-1] != '/')) + if ((strlen(urlbasepath) < 2) || (urlbasepath[strlen(urlbasepath) - 1] != '/')) { fprintf(stderr, "Error: the URL base path must end with a slash\n"); mm_generate_repository_usage(); @@ -1602,16 +1601,17 @@ void mm_self_test(void) if (!file_exists(BUILDDIR)) { fprintf(stderr, "ERROR: Directory %s does not exist.\n" - "The UnrealIRCd source is required for the module manager to work!\n", - BUILDDIR); + "The UnrealIRCd source is required for the module manager to work!\n", + BUILDDIR); exit(-1); - } else { + } else + { snprintf(name, sizeof(name), "%s/src/modules/third/Makefile", BUILDDIR); if (!file_exists(name)) { fprintf(stderr, "ERROR: Directory %s exists, but your UnrealIRCd is not compiled yet.\n" - "You must compile your UnrealIRCd first (run './Config', then 'make install')\n", - BUILDDIR); + "You must compile your UnrealIRCd first (run './Config', then 'make install')\n", + BUILDDIR); exit(-1); } } @@ -1633,18 +1633,15 @@ void modulemanager(int argc, char *args[]) { mm_uninstall(argc, args); exit(0); - } - else if (!strcasecmp(args[0], "generate-repository")) + } else if (!strcasecmp(args[0], "generate-repository")) { mm_generate_repository(argc, args); exit(0); - } - else if (!strcasecmp(args[0], "parse-c-file")) + } else if (!strcasecmp(args[0], "parse-c-file")) { mm_parse_c_file(argc, args); exit(0); - } - else if (!strcasecmp(args[0], "compile-all")) + } else if (!strcasecmp(args[0], "compile-all")) { mm_compile_all(argc, args); exit(0); @@ -1678,8 +1675,7 @@ void modulemanager(int argc, char *args[]) fprintf(stderr, "All actions were successful.\n"); else exit(1); - } - else if (!strcasecmp(args[0], "upgrade")) + } else if (!strcasecmp(args[0], "upgrade")) mm_upgrade(argc, args); else mm_usage(); diff --git a/src/modules.c b/src/modules.c index 4f903ecf6..2ce075de4 100644 --- a/src/modules.c +++ b/src/modules.c @@ -23,32 +23,32 @@ #define UNREALCORE #include "unrealircd.h" #ifdef _WIN32 -#define RTLD_NOW 0 + #define RTLD_NOW 0 #elif defined(HPUX) -#include -#define RTLD_NOW BIND_IMMEDIATE + #include + #define RTLD_NOW BIND_IMMEDIATE #else -#include + #include #endif #ifndef RTLD_NOW -#define RTLD_NOW RTLD_LAZY + #define RTLD_NOW RTLD_LAZY #endif #include "modversion.h" -Hook *Hooks[MAXHOOKTYPES]; -Hooktype Hooktypes[MAXCUSTOMHOOKS]; -Callback *Callbacks[MAXCALLBACKS]; /* Callback objects for modules, used for rehashing etc (can be multiple) */ -Callback *RCallbacks[MAXCALLBACKS]; /* 'Real' callback function, used for callback function calls */ -MODVAR Module *Modules = NULL; -MODVAR Versionflag *Versionflags = NULL; +Hook *Hooks[MAXHOOKTYPES]; +Hooktype Hooktypes[MAXCUSTOMHOOKS]; +Callback *Callbacks[MAXCALLBACKS]; /* Callback objects for modules, used for rehashing etc (can be multiple) */ +Callback *RCallbacks[MAXCALLBACKS]; /* 'Real' callback function, used for callback function calls */ +MODVAR Module *Modules = NULL; +MODVAR Versionflag *Versionflags = NULL; -Module *Module_make(ModuleHeader *header, +Module *Module_make(ModuleHeader *header, #ifdef _WIN32 - HMODULE mod + HMODULE mod #else - void *mod + void *mod #endif - ); +); #ifdef UNDERSCORE /* dlsym for OpenBSD */ @@ -79,7 +79,7 @@ void deletetmp(const char *path) void DeleteTempModules(void) { - char tempbuf[PATH_MAX+1]; + char tempbuf[PATH_MAX + 1]; #ifndef _WIN32 DIR *fd = opendir(TMPDIR); struct dirent *dir; @@ -87,10 +87,10 @@ void DeleteTempModules(void) if (!fd) /* Ouch.. this is NOT good!! */ { config_error("Unable to open temp directory %s: %s, please create one with the appropriate permissions", - TMPDIR, strerror(errno)); + TMPDIR, strerror(errno)); if (!loop.booted) exit(7); - return; + return; } while ((dir = readdir(fd))) @@ -108,9 +108,9 @@ void DeleteTempModules(void) #else WIN32_FIND_DATA hData; HANDLE hFile; - + snprintf(tempbuf, sizeof(tempbuf), "%s/*", TMPDIR); - + hFile = FindFirstFile(tempbuf, &hData); if (hFile != INVALID_HANDLE_VALUE) { @@ -128,13 +128,13 @@ void DeleteTempModules(void) deletetmp(tempbuf); } FindClose(hFile); -#endif +#endif } Module *Module_Find(const char *name) { Module *p; - + for (p = Modules; p; p = p->next) { if (!(p->options & MOD_OPT_PERM) && @@ -146,7 +146,6 @@ Module *Module_Find(const char *name) } } return NULL; - } int parse_modsys_version(const char *version) @@ -165,11 +164,11 @@ void make_compiler_string(char *buf, size_t buflen, unsigned int ver) strlcpy(buf, "0", buflen); return; } - + maj = ver >> 16; min = (ver >> 8) & 0xff; plevel = ver & 0xff; - + if (plevel == 0) snprintf(buf, buflen, "%d.%d", maj, min); else @@ -190,7 +189,8 @@ const char *Module_TransformPath(const char *path_) if ((*path_ != '/') && (*path_ != '\\') && !(*path_ && (path_[1] == ':'))) { snprintf(path, sizeof(path), "%s/%s", MODULESDIR, path_); - } else { + } else + { strlcpy(path, path_, sizeof(path)); } @@ -238,7 +238,7 @@ static const char *validate_mod_header(const char *relpath, ModuleHeader *mod_he if (strcmp(mod_header->name, relpath)) { snprintf(buf, sizeof(buf), "Module has path '%s' but uses name '%s' in MOD_HEADER. These should be the same!", - relpath, mod_header->name); + relpath, mod_header->name); return buf; } /* This too, just to be sure.. we never ever want other characters @@ -309,21 +309,21 @@ const char *is_module_deprecated(const char *name) const char *Module_Create(const char *path_) { #ifdef _WIN32 - HMODULE Mod; + HMODULE Mod; #else /* _WIN32 */ - void *Mod; + void *Mod; #endif /* _WIN32 */ - int (*Mod_Test)(); - int (*Mod_Init)(); - int (*Mod_Load)(); - int (*Mod_Unload)(); - char *Mod_Version; - static char errorbuf[1024]; - const char *path, *relpath, *tmppath; - ModuleHeader *mod_header = NULL; - int ret = 0; - const char *reterr; - Module *mod = NULL, **Mod_Handle = NULL; + int (*Mod_Test)(); + int (*Mod_Init)(); + int (*Mod_Load)(); + int (*Mod_Unload)(); + char *Mod_Version; + static char errorbuf[1024]; + const char *path, *relpath, *tmppath; + ModuleHeader *mod_header = NULL; + int ret = 0; + const char *reterr; + Module *mod = NULL, **Mod_Handle = NULL; char *expectedmodversion = our_mod_version; long modsys_ver = 0; @@ -359,7 +359,8 @@ const char *Module_Create(const char *path_) { /* For './unrealircd configtest' we don't have to do any copying and shit */ tmppath = path; - } else { + } else + { tmppath = unreal_mktemp(TMPDIR, unreal_getmodfilename(path)); if (!tmppath) return "Unable to create temporary file!"; @@ -393,7 +394,7 @@ const char *Module_Create(const char *path_) if (!Mod_Version) { snprintf(errorbuf, sizeof(errorbuf), - "Module is lacking Mod_Version. Perhaps a very old one you forgot to recompile?"); + "Module is lacking Mod_Version. Perhaps a very old one you forgot to recompile?"); irc_dlclose(Mod); deletetmp(tmppath); return errorbuf; @@ -414,20 +415,20 @@ const char *Module_Create(const char *path_) if (!(modsys_ver = parse_modsys_version(mod_header->modversion))) { snprintf(errorbuf, 1023, "Unsupported module system version '%s'", - mod_header->modversion); + mod_header->modversion); irc_dlclose(Mod); deletetmp(tmppath); - return(errorbuf); + return (errorbuf); } if ((reterr = validate_mod_header(relpath, mod_header))) { irc_dlclose(Mod); deletetmp(tmppath); - return(reterr); + return (reterr); } if (Module_Find(mod_header->name)) { - irc_dlclose(Mod); + irc_dlclose(Mod); deletetmp(tmppath); return (NULL); } @@ -452,7 +453,7 @@ const char *Module_Create(const char *path_) if (!Mod_Load) { Module_free(mod); - return ("Unable to locate Mod_Load"); + return ("Unable to locate Mod_Load"); } irc_dlsym(Mod, "Mod_Handle", Mod_Handle); if (Mod_Handle) @@ -470,10 +471,9 @@ const char *Module_Create(const char *path_) return (errorbuf); } } - mod->flags = MODFLAG_TESTING; + mod->flags = MODFLAG_TESTING; return NULL; - } - else + } else { /* Return the error .. */ return irc_dlerror(); @@ -490,16 +490,16 @@ void Module_DelayChildren(Module *m) } } -Module *Module_make(ModuleHeader *header, +Module *Module_make(ModuleHeader *header, #ifdef _WIN32 - HMODULE mod + HMODULE mod #else - void *mod + void *mod #endif - ) +) { Module *modp = NULL; - + modp = safe_alloc(sizeof(Module)); modp->header = header; modp->dll = mod; @@ -510,13 +510,13 @@ Module *Module_make(ModuleHeader *header, modp->modinfo.size = sizeof(ModuleInfo); modp->modinfo.module_load = 0; modp->modinfo.handle = modp; - + return (modp); } void Init_all_testing_modules(void) { - + Module *mi, *next; int ret; iFP Mod_Init; @@ -526,76 +526,77 @@ void Init_all_testing_modules(void) if (!(mi->flags & MODFLAG_TESTING)) continue; irc_dlsym(mi->dll, "Mod_Init", Mod_Init); - if ((ret = (*Mod_Init)(&mi->modinfo)) < MOD_SUCCESS) { + if ((ret = (*Mod_Init)(&mi->modinfo)) < MOD_SUCCESS) + { config_error("Error loading %s: Mod_Init returned %i", - mi->header->name, ret); + mi->header->name, ret); Module_free(mi); continue; } mi->flags = MODFLAG_INIT; } -} +} void FreeModObj(ModuleObject *obj, Module *m) { - if (obj->type == MOBJ_EVENT) { + if (obj->type == MOBJ_EVENT) + { EventDel(obj->object.event); - } - else if (obj->type == MOBJ_HOOK) { + } else if (obj->type == MOBJ_HOOK) + { HookDel(obj->object.hook); - } - else if (obj->type == MOBJ_COMMAND) { + } else if (obj->type == MOBJ_COMMAND) + { CommandDel(obj->object.command); - } - else if (obj->type == MOBJ_HOOKTYPE) { + } else if (obj->type == MOBJ_HOOKTYPE) + { //HooktypeDel(obj->object.hooktype, m); -- reinstate if we audited this code - } - else if (obj->type == MOBJ_VERSIONFLAG) { + } else if (obj->type == MOBJ_VERSIONFLAG) + { VersionflagDel(obj->object.versionflag, m); - } - else if (obj->type == MOBJ_UMODE) { + } else if (obj->type == MOBJ_UMODE) + { UmodeDel(obj->object.umode); - } - else if (obj->type == MOBJ_CMODE) { + } else if (obj->type == MOBJ_CMODE) + { CmodeDel(obj->object.cmode); - } - else if (obj->type == MOBJ_COMMANDOVERRIDE) { + } else if (obj->type == MOBJ_COMMANDOVERRIDE) + { CommandOverrideDel(obj->object.cmdoverride); - } - else if (obj->type == MOBJ_EXTBAN) { + } else if (obj->type == MOBJ_EXTBAN) + { ExtbanDel(obj->object.extban); - } - else if (obj->type == MOBJ_CALLBACK) { + } else if (obj->type == MOBJ_CALLBACK) + { CallbackDel(obj->object.callback); - } - else if (obj->type == MOBJ_EFUNCTION) { + } else if (obj->type == MOBJ_EFUNCTION) + { EfunctionDel(obj->object.efunction); - } - else if (obj->type == MOBJ_ISUPPORT) { + } else if (obj->type == MOBJ_ISUPPORT) + { ISupportDel(obj->object.isupport); - } - else if (obj->type == MOBJ_MODDATA) { + } else if (obj->type == MOBJ_MODDATA) + { ModDataDel(obj->object.moddata); - } - else if (obj->type == MOBJ_VALIDATOR) { + } else if (obj->type == MOBJ_VALIDATOR) + { OperClassValidatorDel(obj->object.validator); - } - else if (obj->type == MOBJ_CLICAP) { + } else if (obj->type == MOBJ_CLICAP) + { ClientCapabilityDel(obj->object.clicap); - } - else if (obj->type == MOBJ_MTAG) { + } else if (obj->type == MOBJ_MTAG) + { MessageTagHandlerDel(obj->object.mtag); - } - else if (obj->type == MOBJ_HISTORY_BACKEND) { + } else if (obj->type == MOBJ_HISTORY_BACKEND) + { HistoryBackendDel(obj->object.history_backend); - } - else if (obj->type == MOBJ_RPC) { + } else if (obj->type == MOBJ_RPC) + { RPCHandlerDel(obj->object.rpc); - } - else if (obj->type == MOBJ_API_CALLBACK) { + } else if (obj->type == MOBJ_API_CALLBACK) + { APICallbackDel(obj->object.apicallback); - } - else + } else { unreal_log(ULOG_FATAL, "module", "FREEMODOBJ_UNKNOWN_TYPE", NULL, "[BUG] FreeModObj() called for unknown object (type $type)", @@ -627,17 +628,18 @@ void Unload_all_loaded_modules(void) Module_DelayChildren(mi); } } - for (objs = mi->objects; objs; objs = objnext) { + for (objs = mi->objects; objs; objs = objnext) + { objnext = objs->next; FreeModObj(objs, mi); } for (child = mi->children; child; child = childnext) { childnext = child->next; - DelListItem(child,mi->children); + DelListItem(child, mi->children); safe_free(child); } - DelListItem(mi,Modules); + DelListItem(mi, Modules); irc_dlclose(mi->dll); deletetmp(mi->tmp_file); safe_free(mi->tmp_file); @@ -657,17 +659,18 @@ void Unload_all_testing_modules(void) next = mi->next; if (!(mi->flags & MODFLAG_TESTING)) continue; - for (objs = mi->objects; objs; objs = objnext) { + for (objs = mi->objects; objs; objs = objnext) + { objnext = objs->next; FreeModObj(objs, mi); } for (child = mi->children; child; child = childnext) { childnext = child->next; - DelListItem(child,mi->children); + DelListItem(child, mi->children); safe_free(child); } - DelListItem(mi,Modules); + DelListItem(mi, Modules); irc_dlclose(mi->dll); deletetmp(mi->tmp_file); safe_free(mi->tmp_file); @@ -680,7 +683,7 @@ void Unload_all_testing_modules(void) * Returns -1 if you cannot unload due to children still alive * Returns 1 if successful */ -int Module_free(Module *mod) +int Module_free(Module *mod) { Module *p; ModuleChild *cp, *cpnext; @@ -691,7 +694,8 @@ int Module_free(Module *mod) { Module_Unload(cp->child->header->name); } - for (objs = mod->objects; objs; objs = next) { + for (objs = mod->objects; objs; objs = next) + { next = objs->next; FreeModObj(objs, mod); } @@ -728,15 +732,15 @@ int Module_free(Module *mod) int Module_Unload(const char *name) { Module *m; - int (*Mod_Unload)(); - int ret; + int (*Mod_Unload)(); + int ret; for (m = Modules; m; m = m->next) { if (!strcmp(m->header->name, name)) { - break; + break; } - } + } if (!m) return -1; irc_dlsym(m->dll, "Mod_Unload", Mod_Unload); @@ -763,9 +767,9 @@ int Module_Unload(const char *name) void module_loadall(void) { - iFP fp; + iFP fp; Module *mi, *next; - + loop.config_status = CONFIG_STATUS_LOAD; /* Run through all modules and check for module load */ @@ -780,28 +784,27 @@ void module_loadall(void) { config_status("cannot load module %s", mi->header->name); Module_free(mi); - } - else + } else mi->flags = MODFLAG_LOADED; } } -int Module_IsAlreadyChild(Module *parent, Module *child) +int Module_IsAlreadyChild(Module *parent, Module *child) { ModuleChild *mcp; - + for (mcp = parent->children; mcp; mcp = mcp->next) { - if (mcp->child == child) + if (mcp->child == child) return 1; } return 0; } -void Module_AddAsChild(Module *parent, Module *child) +void Module_AddAsChild(Module *parent, Module *child) { - ModuleChild *childp = NULL; - + ModuleChild *childp = NULL; + childp = safe_alloc(sizeof(ModuleChild)); childp->child = child; AddListItem(childp, parent->children); @@ -856,31 +859,31 @@ CMD_FUNC(cmd_module) strlcat(tmp, "[PERM] ", sizeof(tmp)); if (!(mi->options & MOD_OPT_OFFICIAL)) strlcat(tmp, "[3RD] ", sizeof(tmp)); - if (!ValidatePermissionsForPath("server:module",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:module", client, NULL, NULL, NULL)) sendtxtnumeric(client, "*** %s - %s - by %s %s", - mi->header->name, - mi->header->description, - mi->header->author, - mi->options & MOD_OPT_OFFICIAL ? "" : "[3RD]"); + mi->header->name, + mi->header->description, + mi->header->author, + mi->options & MOD_OPT_OFFICIAL ? "" : "[3RD]"); else sendtxtnumeric(client, "*** %s %s - %s - by %s %s", - mi->header->name, - mi->header->version, - mi->header->description, - mi->header->author, - tmp); + mi->header->name, + mi->header->version, + mi->header->description, + mi->header->author, + tmp); } sendtxtnumeric(client, "End of module list"); - if (!ValidatePermissionsForPath("server:module",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:module", client, NULL, NULL, NULL)) return; /* The rest are extra details (oper-only)... */ tmp[0] = '\0'; p = tmp; - for (i=0; i < MAXHOOKTYPES; i++) + for (i = 0; i < MAXHOOKTYPES; i++) { if (!Hooks[i]) continue; @@ -897,14 +900,14 @@ CMD_FUNC(cmd_module) tmp[0] = '\0'; p = tmp; - for (i=0; i < 256; i++) + for (i = 0; i < 256; i++) { for (mptr = CommandHash[i]; mptr; mptr = mptr->next) if (mptr->overriders) { - ircsnprintf(p, sizeof(tmp)-strlen(tmp), "%s ", mptr->cmd); + ircsnprintf(p, sizeof(tmp) - strlen(tmp), "%s ", mptr->cmd); p += strlen(p); - if (p > tmp+380) + if (p > tmp + 380) { sendtxtnumeric(client, "Override: %s", tmp); tmp[0] = '\0'; @@ -917,9 +920,11 @@ CMD_FUNC(cmd_module) moddatatype_dump(client); } -Hooktype *HooktypeFind(const char *string) { +Hooktype *HooktypeFind(const char *string) +{ Hooktype *hooktype; - for (hooktype = Hooktypes; hooktype->string ;hooktype++) { + for (hooktype = Hooktypes; hooktype->string; hooktype++) + { if (!strcasecmp(hooktype->string, string)) return hooktype; } @@ -949,7 +954,8 @@ Versionflag *VersionflagAdd(Module *module, char flag) if ((vflag = VersionflagFind(flag))) { ModuleChild *child; - for (child = vflag->parents; child; child = child->next) { + for (child = vflag->parents; child; child = child->next) + { if (child->child == module) break; } @@ -957,7 +963,8 @@ Versionflag *VersionflagAdd(Module *module, char flag) { parent = safe_alloc(sizeof(ModuleChild)); parent->child = module; - if (module) { + if (module) + { ModuleObject *vflagobj; vflagobj = safe_alloc(sizeof(ModuleObject)); vflagobj->type = MOBJ_VERSIONFLAG; @@ -965,7 +972,7 @@ Versionflag *VersionflagAdd(Module *module, char flag) AddListItem(vflagobj, module->objects); module->errorcode = MODERR_NOERROR; } - AddListItem(parent,vflag->parents); + AddListItem(parent, vflag->parents); } return vflag; } @@ -983,11 +990,11 @@ Versionflag *VersionflagAdd(Module *module, char flag) module->errorcode = MODERR_NOERROR; } flag_add(flag); - AddListItem(parent,vflag->parents); + AddListItem(parent, vflag->parents); AddListItem(vflag, Versionflags); return vflag; } - + /** Delete a version flag. * @param vflag The version flag to delete * @param module The module that owns this version flag @@ -1004,7 +1011,7 @@ void VersionflagDel(Versionflag *vflag, Module *module) { if (owner->child == module) { - DelListItem(owner,vflag->parents); + DelListItem(owner, vflag->parents); safe_free(owner); break; } @@ -1012,9 +1019,11 @@ void VersionflagDel(Versionflag *vflag, Module *module) if (module) { ModuleObject *objs; - for (objs = module->objects; objs; objs = objs->next) { - if (objs->type == MOBJ_VERSIONFLAG && objs->object.versionflag == vflag) { - DelListItem(objs,module->objects); + for (objs = module->objects; objs; objs = objs->next) + { + if (objs->type == MOBJ_VERSIONFLAG && objs->object.versionflag == vflag) + { + DelListItem(objs, module->objects); safe_free(objs); break; } @@ -1031,8 +1040,8 @@ void VersionflagDel(Versionflag *vflag, Module *module) Hook *HookAddMain(Module *module, int hooktype, int priority, int (*func)(), void (*vfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)()) { Hook *p; - - p = (Hook *) safe_alloc(sizeof(Hook)); + + p = (Hook *)safe_alloc(sizeof(Hook)); if (func) p->func.intfunc = func; if (vfunc) @@ -1045,14 +1054,15 @@ Hook *HookAddMain(Module *module, int hooktype, int priority, int (*func)(), voi p->owner = module; p->priority = priority; - if (module) { + if (module) + { ModuleObject *hookobj = (ModuleObject *)safe_alloc(sizeof(ModuleObject)); hookobj->object.hook = p; hookobj->type = MOBJ_HOOK; AddListItem(hookobj, module->objects); module->errorcode = MODERR_NOERROR; } - + AddListItemPrio(p, Hooks[hooktype], p->priority); return p; @@ -1067,14 +1077,19 @@ Hook *HookAddMain(Module *module, int hooktype, int priority, int (*func)(), voi Hook *HookDel(Hook *hook) { Hook *p, *q; - for (p = Hooks[hook->type]; p; p = p->next) { - if (p == hook) { + for (p = Hooks[hook->type]; p; p = p->next) + { + if (p == hook) + { q = p->next; DelListItem(p, Hooks[hook->type]); - if (p->owner) { + if (p->owner) + { ModuleObject *hookobj; - for (hookobj = p->owner->objects; hookobj; hookobj = hookobj->next) { - if (hookobj->type == MOBJ_HOOK && hookobj->object.hook == p) { + for (hookobj = p->owner->objects; hookobj; hookobj = hookobj->next) + { + if (hookobj->type == MOBJ_HOOK && hookobj->object.hook == p) + { DelListItem(hookobj, hook->owner->objects); safe_free(hookobj); break; @@ -1090,13 +1105,13 @@ Hook *HookDel(Hook *hook) static int num_callbacks(int cbtype) { -Callback *e; -int cnt = 0; + Callback *e; + int cnt = 0; for (e = Callbacks[cbtype]; e; e = e->next) if (!e->willberemoved) cnt++; - + return cnt; } @@ -1116,14 +1131,14 @@ int cnt = 0; Callback *CallbackAddMain(Module *module, int cbtype, int (*func)(), void (*vfunc)(), void *(*pvfunc)(), char *(*stringfunc)(), const char *(*conststringfunc)()) { Callback *p; - + if (num_callbacks(cbtype) > 0) { if (module) module->errorcode = MODERR_EXISTS; return NULL; } - + p = safe_alloc(sizeof(Callback)); if (func) p->func.intfunc = func; @@ -1138,7 +1153,8 @@ Callback *CallbackAddMain(Module *module, int cbtype, int (*func)(), void (*vfun p->type = cbtype; p->owner = module; AddListItem(p, Callbacks[cbtype]); - if (module) { + if (module) + { ModuleObject *cbobj = safe_alloc(sizeof(ModuleObject)); cbobj->object.callback = p; cbobj->type = MOBJ_CALLBACK; @@ -1157,16 +1173,21 @@ Callback *CallbackAddMain(Module *module, int cbtype, int (*func)(), void (*vfun Callback *CallbackDel(Callback *cb) { Callback *p, *q; - for (p = Callbacks[cb->type]; p; p = p->next) { - if (p == cb) { + for (p = Callbacks[cb->type]; p; p = p->next) + { + if (p == cb) + { q = p->next; DelListItem(p, Callbacks[cb->type]); if (RCallbacks[cb->type] == p) RCallbacks[cb->type] = NULL; - if (p->owner) { + if (p->owner) + { ModuleObject *cbobj; - for (cbobj = p->owner->objects; cbobj; cbobj = cbobj->next) { - if ((cbobj->type == MOBJ_CALLBACK) && (cbobj->object.callback == p)) { + for (cbobj = p->owner->objects; cbobj; cbobj = cbobj->next) + { + if ((cbobj->type == MOBJ_CALLBACK) && (cbobj->object.callback == p)) + { DelListItem(cbobj, cb->owner->objects); safe_free(cbobj); break; @@ -1211,7 +1232,7 @@ CommandOverride *CommandOverrideAdd(Module *module, const char *name, int priori module->errorcode = MODERR_NOTFOUND; return NULL; } - for (ovr=p->overriders; ovr; ovr=ovr->next) + for (ovr = p->overriders; ovr; ovr = ovr->next) { if ((ovr->owner == module) && (ovr->func == function)) { @@ -1294,7 +1315,7 @@ void CallCommandOverride(CommandOverride *ovr, ClientContext *clictx, Client *cl EVENT(e_unload_module_delayed) { char *name = (char *)data; - int i; + int i; isupport_snapshot(); i = Module_Unload(name); if (i == 1) @@ -1313,7 +1334,7 @@ EVENT(e_unload_module_delayed) void unload_all_modules(void) { Module *m; - int (*Mod_Unload)(); + int (*Mod_Unload)(); for (m = Modules; m; m = m->next) { #ifdef DEBUGMODE @@ -1336,7 +1357,8 @@ void ModuleSetOptions(Module *module, unsigned int options, int action) { DelListItem(module, Modules); AddListItemPrio(module, Modules, action); - } else { + } else + { /* Simple bit flag(s) */ if (action) module->options |= options; @@ -1356,16 +1378,16 @@ unsigned int ModuleGetError(Module *module) } static const char *module_error_str[] = { - "No error", - "Object already exists", - "No space available", - "Invalid parameter(s)", - "Object was not found", + "No error", + "Object already exists", + "No space available", + "Invalid parameter(s)", + "Object was not found", }; const char *ModuleGetErrorStr(Module *module) { - if (module->errorcode >= sizeof(module_error_str)/sizeof(module_error_str[0])) + if (module->errorcode >= sizeof(module_error_str) / sizeof(module_error_str[0])) return NULL; return module_error_str[module->errorcode]; @@ -1376,9 +1398,9 @@ const char *ModuleGetErrorStr(Module *module) */ int callbacks_check(void) { -int i; + int i; - for (i=0; i < MAXCALLBACKS; i++) + for (i = 0; i < MAXCALLBACKS; i++) { if (num_callbacks(i) > 1) { @@ -1404,14 +1426,14 @@ int i; void callbacks_switchover(void) { -Callback *e; -int i; + Callback *e; + int i; /* Now set the real callback, and tag the new one * as 'willberemoved' if needed. */ - for (i=0; i < MAXCALLBACKS; i++) + for (i = 0; i < MAXCALLBACKS; i++) for (e = Callbacks[i]; e; e = e->next) if (!e->willberemoved) { @@ -1427,12 +1449,12 @@ const char *our_dlerror(void) { static char errbuf[513]; DWORD err = GetLastError(); - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, - 0, errbuf, 512, NULL); + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, + 0, errbuf, 512, NULL); if (err == ERROR_MOD_NOT_FOUND) strlcat(errbuf, " This could be because the DLL depends on another DLL, for example if you " - "are trying to load a 3rd party module which was compiled with a different compiler version.", - sizeof(errbuf)); + "are trying to load a 3rd party module which was compiled with a different compiler version.", + sizeof(errbuf)); return errbuf; } #endif @@ -1489,7 +1511,8 @@ ModDataInfo *persistent_var_generic(ModuleInfo *modinfo, const char *varshortnam m->unloaded = 0; } return m; - } else { + } else + { ModDataInfo mreq; memset(&mreq, 0, sizeof(mreq)); mreq.type = MODDATATYPE_LOCAL_VARIABLE; diff --git a/src/modules/account-notify.c b/src/modules/account-notify.c index 9bd4100bc..94f7c3d27 100644 --- a/src/modules/account-notify.c +++ b/src/modules/account-notify.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "account-notify", /* Name of module */ - "5.0", /* Version */ - "account-notify CAP", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "account-notify", /* Name of module */ + "5.0", /* Version */ + "account-notify CAP", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ long CAP_ACCOUNT_NOTIFY = 0L; @@ -67,10 +66,10 @@ int account_notify_account_login(Client *client, MessageTag *recv_mtags) MessageTag *mtags = NULL; new_message(client, recv_mtags, &mtags); sendto_local_common_channels(client, client, - CAP_ACCOUNT_NOTIFY, mtags, - ":%s ACCOUNT %s", - client->name, - IsLoggedIn(client) ? client->user->account : "*"); + CAP_ACCOUNT_NOTIFY, mtags, + ":%s ACCOUNT %s", + client->name, + IsLoggedIn(client) ? client->user->account : "*"); free_message_tags(mtags); return 0; } diff --git a/src/modules/account-tag.c b/src/modules/account-tag.c index b23578ae5..165e2f8ed 100644 --- a/src/modules/account-tag.c +++ b/src/modules/account-tag.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "account-tag", - "5.0", - "account-tag CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "account-tag", + "5.0", + "account-tag CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ long CAP_ACCOUNT_TAG = 0L; diff --git a/src/modules/addmotd.c b/src/modules/addmotd.c index 6ba7f95fa..d52c112a0 100644 --- a/src/modules/addmotd.c +++ b/src/modules/addmotd.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_addmotd); -#define MSG_ADDMOTD "ADDMOTD" +#define MSG_ADDMOTD "ADDMOTD" -ModuleHeader MOD_HEADER - = { - "addmotd", - "5.0", - "command /addmotd", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "addmotd", + "5.0", + "command /addmotd", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -67,7 +66,7 @@ CMD_FUNC(cmd_addmotd) if (!MyConnect(client)) return; - if (!ValidatePermissionsForPath("server:addmotd",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:addmotd", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; diff --git a/src/modules/addomotd.c b/src/modules/addomotd.c index 140d04445..db8a64267 100644 --- a/src/modules/addomotd.c +++ b/src/modules/addomotd.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_addomotd); -#define MSG_ADDOMOTD "ADDOMOTD" +#define MSG_ADDOMOTD "ADDOMOTD" -ModuleHeader MOD_HEADER - = { - "addomotd", - "5.0", - "command /addomotd", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "addomotd", + "5.0", + "command /addomotd", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -67,7 +66,7 @@ CMD_FUNC(cmd_addomotd) if (!MyConnect(client)) return; - if (!ValidatePermissionsForPath("server:addomotd",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:addomotd", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; diff --git a/src/modules/admin.c b/src/modules/admin.c index 064dd9b03..684c6967a 100644 --- a/src/modules/admin.c +++ b/src/modules/admin.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_admin); -#define MSG_ADMIN "ADMIN" +#define MSG_ADMIN "ADMIN" -ModuleHeader MOD_HEADER - = { - "admin", - "5.0", - "command /admin", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "admin", + "5.0", + "command /admin", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_ADMIN, cmd_admin, MAXPARA, CMD_USER|CMD_SHUN|CMD_VIRUS); + CommandAdd(modinfo->handle, MSG_ADMIN, cmd_admin, MAXPARA, CMD_USER | CMD_SHUN | CMD_VIRUS); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } diff --git a/src/modules/antimixedutf8.c b/src/modules/antimixedutf8.c index 6987732ba..5098cacca 100644 --- a/src/modules/antimixedutf8.c +++ b/src/modules/antimixedutf8.c @@ -47,13 +47,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "antimixedutf8", - "1.0", - "Mixed UTF8 character filter (look-alike character spam) - by Syzop", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "antimixedutf8", + "1.0", + "Mixed UTF8 character filter (look-alike character spam) - by Syzop", + "UnrealIRCd Team", + "unrealircd-6", }; struct { @@ -84,14 +83,13 @@ int antimixedutf8_check(Client *client, TextAnalysis *txa, const char **errmsg) unreal_log(ULOG_INFO, "antimixedutf8", "ANTIMIXEDUTF8_HIT", client, "[antimixedutf8] Client $client.details hit score $score -- taking action", log_data_integer("score", txa->antimixedutf8_points), - log_data_textanalysis("text_analysis",txa)); + log_data_textanalysis("text_analysis", txa)); /* Take the action */ retval = take_action(client, cfg.ban_action, cfg.ban_reason, cfg.ban_time, 0, NULL); if ((retval == BAN_ACT_WARN) || (retval == BAN_ACT_SOFT_WARN)) { /* no action */ - } else - if ((retval == BAN_ACT_BLOCK) || (retval == BAN_ACT_SOFT_BLOCK)) + } else if ((retval == BAN_ACT_BLOCK) || (retval == BAN_ACT_SOFT_BLOCK)) { *errmsg = cfg.ban_reason; return HOOK_DENY; @@ -182,36 +180,31 @@ int antimixedutf8_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *er if (!strcmp(cep->name, "except")) { test_match_block(cf, cep, &errors); - } else - if (!cep->value) + } else if (!cep->value) { config_error("%s:%i: set::antimixedutf8::%s with no value", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "score")) + } else if (!strcmp(cep->name, "score")) { int v = atoi(cep->value); if ((v < 1) || (v > 99)) { config_error("%s:%i: set::antimixedutf8::score: must be between 1 - 99 (got: %d)", - cep->file->filename, cep->line_number, v); + cep->file->filename, cep->line_number, v); errors++; } - } else - if (!strcmp(cep->name, "ban-action")) + } else if (!strcmp(cep->name, "ban-action")) { errors += test_ban_action_config(cep); - } else - if (!strcmp(cep->name, "ban-reason")) + } else if (!strcmp(cep->name, "ban-reason")) { - } else - if (!strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-time")) { } else { config_error("%s:%i: unknown directive set::antimixedutf8::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; } } @@ -235,20 +228,16 @@ int antimixedutf8_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "score")) { cfg.score = atoi(cep->value); - } else - if (!strcmp(cep->name, "ban-action")) + } else if (!strcmp(cep->name, "ban-action")) { parse_ban_action_config(cep, &cfg.ban_action); - } else - if (!strcmp(cep->name, "ban-reason")) + } else if (!strcmp(cep->name, "ban-reason")) { safe_strdup(cfg.ban_reason, cep->value); - } else - if (!strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-time")) { cfg.ban_time = config_checkval(cep->value, CFG_TIME); - } else - if (!strcmp(cep->name, "except")) + } else if (!strcmp(cep->name, "except")) { conf_match_block(cf, cep, &cfg.except); } diff --git a/src/modules/antirandom.c b/src/modules/antirandom.c index 6f324c272..4dab3ea95 100644 --- a/src/modules/antirandom.c +++ b/src/modules/antirandom.c @@ -22,17 +22,16 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "antirandom", - "1.5", - "Detect and ban users with random names", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "antirandom", + "1.5", + "Detect and ban users with random names", + "UnrealIRCd Team", + "unrealircd-6", +}; #ifndef MAX - #define MAX(x,y) ((x) > (y) ? (x) : (y)) + #define MAX(x, y) ((x) > (y) ? (x) : (y)) #endif /* "" followed by "" */ @@ -482,7 +481,7 @@ static char *triples_txt[] = { /* clang-format on */ /* Used for parsed triples: */ -#define TRIPLES_REST_SIZE 32 +#define TRIPLES_REST_SIZE 32 typedef struct Triples Triples; struct Triples { Triples *next; @@ -576,21 +575,19 @@ int antirandom_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::antirandom... */ if (!ce || !ce->name || strcmp(ce->name, "antirandom")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "except")) { test_match_block(cf, cep, &errors); - } else - if (!strcmp(cep->name, "except-hosts")) + } else if (!strcmp(cep->name, "except-hosts")) { - } else - if (!strcmp(cep->name, "except-webirc")) + } else if (!strcmp(cep->name, "except-webirc")) { /* This should normally be UNDER the generic 'set::antirandom::%s with no value' * stuff but I put it here because people may think it's a hostlist and then @@ -602,39 +599,32 @@ int antirandom_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) cep->file->filename, cep->line_number); errors++; } - } else - if (!cep->value) + } else if (!cep->value) { config_error("%s:%i: set::antirandom::%s with no value", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "threshold")) + } else if (!strcmp(cep->name, "threshold")) { req.threshold = 1; - } else - if (!strcmp(cep->name, "ban-action") || !strcmp(cep->name, "action")) + } else if (!strcmp(cep->name, "ban-action") || !strcmp(cep->name, "action")) { req.ban_action = 1; errors += test_ban_action_config(cep); - } else - if (!strcmp(cep->name, "ban-reason")) + } else if (!strcmp(cep->name, "ban-reason")) { req.ban_reason = 1; - } else - if (!strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-time")) { req.ban_time = 1; - } else - if (!strcmp(cep->name, "convert-to-lowercase")) + } else if (!strcmp(cep->name, "convert-to-lowercase")) { - } else - if (!strcmp(cep->name, "show-failedconnects")) + } else if (!strcmp(cep->name, "show-failedconnects")) { } else { config_error("%s:%i: unknown directive set::antirandom::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; } } @@ -648,45 +638,38 @@ int antirandom_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::antirandom... */ if (!ce || !ce->name || strcmp(ce->name, "antirandom")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "except")) { conf_match_block(cf, cep, &cfg.except); - } else - if (!strcmp(cep->name, "except-hosts")) + } else if (!strcmp(cep->name, "except-hosts")) { /* backwards compatible with set::antirandom::except */ for (cep2 = cep->items; cep2; cep2 = cep2->next) unreal_add_masks(&cfg.except->mask, cep2); - } else - if (!strcmp(cep->name, "except-webirc")) + } else if (!strcmp(cep->name, "except-webirc")) { /* backwards compatible with set::antirandom::except */ cfg.except->webirc = config_checkval(cep->value, CFG_YESNO); - } else - if (!strcmp(cep->name, "threshold")) + } else if (!strcmp(cep->name, "threshold")) { cfg.threshold = atoi(cep->value); - } else - if (!strcmp(cep->name, "ban-action") || !strcmp(cep->name, "action")) + } else if (!strcmp(cep->name, "ban-action") || !strcmp(cep->name, "action")) { parse_ban_action_config(cep, &cfg.ban_action); - } else - if (!strcmp(cep->name, "ban-reason")) + } else if (!strcmp(cep->name, "ban-reason")) { safe_strdup(cfg.ban_reason, cep->value); - } else - if (!strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-time")) { cfg.ban_time = config_checkval(cep->value, CFG_TIME); - } else - if (!strcmp(cep->name, "convert-to-lowercase")) + } else if (!strcmp(cep->name, "convert-to-lowercase")) { cfg.convert_to_lowercase = config_checkval(cep->value, CFG_YESNO); } @@ -702,11 +685,27 @@ int antirandom_config_posttest(int *errs) { int errors = 0; - if (!req.threshold) { config_error("set::antirandom::threshold missing"); errors++; } - if (!req.ban_action) { config_error("set::antirandom::ban-action missing"); errors++; } - if (!req.ban_time) { config_error("set::antirandom::ban-time missing"); errors++; } - if (!req.ban_reason) { config_error("set::antirandom::ban-reason missing"); errors++; } - + if (!req.threshold) + { + config_error("set::antirandom::threshold missing"); + errors++; + } + if (!req.ban_action) + { + config_error("set::antirandom::ban-action missing"); + errors++; + } + if (!req.ban_time) + { + config_error("set::antirandom::ban-time missing"); + errors++; + } + if (!req.ban_reason) + { + config_error("set::antirandom::ban-reason missing"); + errors++; + } + *errs = errors; return errors ? -1 : 1; } @@ -722,17 +721,17 @@ static int init_stuff(void) static int init_triples(void) { char **s; - Triples *e, *last=NULL; - int cnt=0; + Triples *e, *last = NULL; + int cnt = 0; - for (s=triples_txt; *s; s++) + for (s = triples_txt; *s; s++) { cnt++; e = safe_alloc(sizeof(Triples)); if (strlen(*s) > 2) { config_error("init_triples: error parsing triples_txt, cnt=%d, item='%s' (length>2)", - cnt, *s); + cnt, *s); return 0; } strcpy(e->two, *s); /* (SAFE) */ @@ -740,13 +739,13 @@ static int init_triples(void) if (!*s) { config_error("init_triples: error parsing triples_txt, cnt=%d, got NULL expected param", - cnt); + cnt); return 0; } - if (strlen(*s) > TRIPLES_REST_SIZE-1) + if (strlen(*s) > TRIPLES_REST_SIZE - 1) { config_error("init_triples: error parsing triples_txt, cnt=%d, item='%s' (length>%d)", - cnt, *s, TRIPLES_REST_SIZE-1); + cnt, *s, TRIPLES_REST_SIZE - 1); return 0; } strcpy(e->rest, *s); /* (SAFE) */ @@ -772,27 +771,30 @@ static int internal_getscore(char *str) Triples *t; register char *s; int score = 0; - int highest_vowels=0, highest_consonants=0, highest_digits=0; - int vowels=0, consonants=0, digits=0; + int highest_vowels = 0, highest_consonants = 0, highest_digits = 0; + int vowels = 0, consonants = 0, digits = 0; /* Fast digit/consonant/vowel checks... */ - for (s=str; *s; s++) + for (s = str; *s; s++) { if ((*s >= '0') && (*s <= '9')) digits++; - else { + else + { highest_digits = MAX(highest_digits, digits); digits = 0; } if (strchr("bcdfghjklmnpqrstvwxz", *s)) consonants++; - else { + else + { highest_consonants = MAX(highest_consonants, consonants); consonants = 0; } if (strchr("aeiou", *s)) vowels++; - else { + else + { highest_vowels = MAX(highest_vowels, vowels); vowels = 0; } @@ -801,7 +803,7 @@ static int internal_getscore(char *str) digits = MAX(highest_digits, digits); consonants = MAX(highest_consonants, consonants); vowels = MAX(highest_vowels, vowels); - + if (digits >= 5) { score += digits; @@ -814,18 +816,17 @@ static int internal_getscore(char *str) { score += consonants; } - - for (t=triples; t; t=t->next) + + for (t = triples; t; t = t->next) { - for (s=str; *s; s++) + for (s = str; *s; s++) if ((t->two[0] == s[0]) && (t->two[1] == s[1]) && s[2] && strchr(t->rest, s[2])) { score++; /* OK */ } } - - + return score; } @@ -837,7 +838,7 @@ static int get_spam_score(Client *client) char *nick = client->name; char *user = client->user->username; char *gecos = client->info; - char nbuf[NICKLEN+1], ubuf[USERLEN+1], rbuf[REALLEN+1]; + char nbuf[NICKLEN + 1], ubuf[USERLEN + 1], rbuf[REALLEN + 1]; int nscore, uscore, gscore, score; if (cfg.convert_to_lowercase) @@ -874,8 +875,7 @@ int antirandom_preconnect(Client *client) unreal_log(ULOG_INFO, "antirandom", "ANTIRANDOM_DENIED_USER", client, "[antirandom] would have denied access to user with score $score: $client.details:$client.user.realname", log_data_integer("score", score)); - } else - if (n <= 0) + } else if (n <= 0) { /* No action / exempt */ } else @@ -883,8 +883,8 @@ int antirandom_preconnect(Client *client) if (cfg.show_failedconnects) { unreal_log(ULOG_INFO, "antirandom", "ANTIRANDOM_DENIED_USER", client, - "[antirandom] denied access to user with score $score: $client.details:$client.user.realname", - log_data_integer("score", score)); + "[antirandom] denied access to user with score $score: $client.details:$client.user.realname", + log_data_integer("score", score)); } return HOOK_DENY; } @@ -896,7 +896,7 @@ static void free_stuff(void) { Triples *t, *t_next; - for (t=triples; t; t=t_next) + for (t = triples; t; t = t_next) { t_next = t->next; safe_free(t); diff --git a/src/modules/authprompt.c b/src/modules/authprompt.c index 515220ed4..f35a4c0e6 100644 --- a/src/modules/authprompt.c +++ b/src/modules/authprompt.c @@ -19,13 +19,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "authprompt", - "1.0", - "SASL authentication for clients that don't support SASL", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "authprompt", + "1.0", + "SASL authentication for clients that don't support SASL", + "UnrealIRCd Team", + "unrealircd-6", }; /** Configuration settings */ @@ -62,9 +61,13 @@ CMD_FUNC(cmd_auth); void authprompt_md_free(ModData *md); /* Some macros */ -#define SetAPUser(x, y) do { moddata_local_client(x, authprompt_md).ptr = y; } while(0) -#define SEUSER(x) ((APUser *)moddata_local_client(x, authprompt_md).ptr) -#define AGENT_SID(agent_p) (agent_p->user != NULL ? agent_p->user->server : agent_p->name) +#define SetAPUser(x, y) \ + do \ + { \ + moddata_local_client(x, authprompt_md).ptr = y; \ + } while (0) +#define SEUSER(x) ((APUser *)moddata_local_client(x, authprompt_md).ptr) +#define AGENT_SID(agent_p) (agent_p->user != NULL ? agent_p->user->server : agent_p->name) MOD_TEST() { @@ -167,24 +170,20 @@ int authprompt_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!cep->value) { config_error("%s:%i: set::authentication-prompt::%s with no value", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "enabled")) + } else if (!strcmp(cep->name, "enabled")) { - } else - if (!strcmp(cep->name, "message")) + } else if (!strcmp(cep->name, "message")) { - } else - if (!strcmp(cep->name, "fail-message")) + } else if (!strcmp(cep->name, "fail-message")) { - } else - if (!strcmp(cep->name, "unconfirmed-message")) + } else if (!strcmp(cep->name, "unconfirmed-message")) { } else { config_error("%s:%i: unknown directive set::authentication-prompt::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; } } @@ -208,16 +207,13 @@ int authprompt_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "enabled")) { cfg.enabled = config_checkval(cep->value, CFG_YESNO); - } else - if (!strcmp(cep->name, "message")) + } else if (!strcmp(cep->name, "message")) { addmultiline(&cfg.message, cep->value); - } else - if (!strcmp(cep->name, "fail-message")) + } else if (!strcmp(cep->name, "fail-message")) { addmultiline(&cfg.fail_message, cep->value); - } else - if (!strcmp(cep->name, "unconfirmed-message")) + } else if (!strcmp(cep->name, "unconfirmed-message")) { addmultiline(&cfg.unconfirmed_message, cep->value); } @@ -273,14 +269,14 @@ char *make_authbuf(const char *username, const char *password) int size; size = strlen(username) + 1 + strlen(username) + 1 + strlen(password); - if (size >= sizeof(inbuf)-1) + if (size >= sizeof(inbuf) - 1) return NULL; /* too long */ /* Because size limits are already checked above, we can cut some corners here: */ memset(inbuf, 0, sizeof(inbuf)); strcpy(inbuf, username); - strcpy(inbuf+strlen(username)+1, username); - strcpy(inbuf+strlen(username)+1+strlen(username)+1, password); + strcpy(inbuf + strlen(username) + 1, username); + strcpy(inbuf + strlen(username) + 1 + strlen(username) + 1, password); /* ^ normal people use stpcpy here ;) */ if (b64_encode(inbuf, size, outbuf, sizeof(outbuf)) < 0) @@ -309,22 +305,23 @@ void send_first_auth(Client *client) /* Make them a user, needed for CHGHOST etc that we may receive */ if (!client->user) make_user(client); - + if (Hooks[HOOKTYPE_SASL_AUTHENTICATE] && (find_client(SASL_SERVER, NULL) == &me)) { /* We are the SASL server (some module handling auth) */ RunHook(HOOKTYPE_SASL_AUTHENTICATE, client, 1, "PLAIN"); RunHook(HOOKTYPE_SASL_AUTHENTICATE, client, 0, SEUSER(client)->authmsg); - } else { + } else + { sendto_one(sasl_server, NULL, ":%s SASL %s %s H %s %s", - me.id, SASL_SERVER, client->id, addr, addr); + me.id, SASL_SERVER, client->id, addr, addr); if (certfp) sendto_one(sasl_server, NULL, ":%s SASL %s %s S %s %s", - me.id, SASL_SERVER, client->id, "PLAIN", certfp); + me.id, SASL_SERVER, client->id, "PLAIN", certfp); else sendto_one(sasl_server, NULL, ":%s SASL %s %s S %s", - me.id, SASL_SERVER, client->id, "PLAIN"); + me.id, SASL_SERVER, client->id, "PLAIN"); } /* The rest is sent from authprompt_sasl_continuation() */ @@ -426,10 +423,10 @@ int authprompt_find_tkline_match(Client *client, TKL *tkl) * and the user is not yet online, then we will handle this user. */ if (cfg.enabled && - TKLIsServerBan(tkl) && - (tkl->ptr.serverban->subtype & TKL_SUBTYPE_SOFT) && - !IsLoggedIn(client) && - !IsUser(client)) + TKLIsServerBan(tkl) && + (tkl->ptr.serverban->subtype & TKL_SUBTYPE_SOFT) && + !IsLoggedIn(client) && + !IsUser(client)) { /* And tag the user */ authprompt_tag_as_auth_required(client, tkl->ptr.serverban->reason); @@ -463,7 +460,7 @@ int authprompt_sasl_continuation(Client *client, const char *buf) if (agent) { sendto_one(agent, NULL, ":%s SASL %s %s C %s", - me.id, AGENT_SID(agent), client->id, SEUSER(client)->authmsg); + me.id, AGENT_SID(agent), client->id, SEUSER(client)->authmsg); } safe_free(SEUSER(client)->authmsg); } diff --git a/src/modules/away.c b/src/modules/away.c index aa50f1b06..e471cb2c8 100644 --- a/src/modules/away.c +++ b/src/modules/away.c @@ -29,16 +29,15 @@ int away_join(Client *client, Channel *channel, MessageTag *mtags); long CAP_AWAY_NOTIFY = 0L; -#define MSG_AWAY "AWAY" +#define MSG_AWAY "AWAY" -ModuleHeader MOD_HEADER - = { - "away", - "5.0", - "command /away", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "away", + "5.0", + "command /away", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -46,7 +45,7 @@ MOD_INIT() memset(&c, 0, sizeof(c)); c.name = "away-notify"; ClientCapabilityAdd(modinfo->handle, &c, &CAP_AWAY_NOTIFY); - CommandAdd(modinfo->handle, MSG_AWAY, cmd_away, 1, CMD_USER|CMD_TEXTANALYSIS); + CommandAdd(modinfo->handle, MSG_AWAY, cmd_away, 1, CMD_USER | CMD_TEXTANALYSIS); HookAdd(modinfo->handle, HOOKTYPE_LOCAL_JOIN, 0, away_join); HookAdd(modinfo->handle, HOOKTYPE_REMOTE_JOIN, 0, away_join); @@ -137,7 +136,7 @@ CMD_FUNC(cmd_away) /* Check away-flood */ if (MyUser(client) && - !ValidatePermissionsForPath("immune:away-flood",client,NULL,NULL,NULL) && + !ValidatePermissionsForPath("immune:away-flood", client, NULL, NULL, NULL) && flood_limit_exceeded(client, FLD_AWAY)) { sendnumeric(client, ERR_TOOMANYAWAY); @@ -153,7 +152,7 @@ CMD_FUNC(cmd_away) client->user->away_since = t; else client->user->away_since = TStime(); - + new_message(client, recv_mtags, &mtags); sendto_server(client, 0, 0, mtags, ":%s AWAY :%s", client->id, reason); @@ -163,7 +162,7 @@ CMD_FUNC(cmd_away) safe_free(client->user->away); already_as_away = 1; } - + safe_strdup(client->user->away, reason); if (MyConnect(client)) diff --git a/src/modules/batch.c b/src/modules/batch.c index bd88a775f..e442c0ec4 100644 --- a/src/modules/batch.c +++ b/src/modules/batch.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "batch", - "5.0", - "Batch CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "batch", + "5.0", + "Batch CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ CMD_FUNC(cmd_batch); @@ -57,7 +56,7 @@ MOD_INIT() mtag.clicap_handler = c; MessageTagHandlerAdd(modinfo->handle, &mtag); - CommandAdd(modinfo->handle, "BATCH", cmd_batch, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, "BATCH", cmd_batch, MAXPARA, CMD_USER | CMD_SERVER); return MOD_SUCCESS; } @@ -116,7 +115,8 @@ CMD_FUNC(cmd_batch) parv[1] = "BATCH"; concat_params(buf, sizeof(buf), parc, parv); sendto_prefix_one(target, client, recv_mtags, ":%s %s", client->name, buf); - } else { + } else + { /* Relay the batch message to the server */ concat_params(buf, sizeof(buf), parc, parv); sendto_prefix_one(target, client, recv_mtags, ":%s BATCH %s", client->name, buf); diff --git a/src/modules/blacklist.c b/src/modules/blacklist.c index 1a9d1be75..b997e9389 100644 --- a/src/modules/blacklist.c +++ b/src/modules/blacklist.c @@ -19,13 +19,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "blacklist", - "5.0", - "Check connecting users against DNS Blacklists", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "blacklist", + "5.0", + "Check connecting users against DNS Blacklists", + "UnrealIRCd Team", + "unrealircd-6", }; /* In this module and the config syntax I tried to 'abstract' things @@ -40,13 +39,18 @@ static long BLACKLIST_RECHECK_TIME_FIRST = 120; /* After that, check every : */ static long BLACKLIST_RECHECK_TIME = 900; -#define LastBLCheck(x) (moddata_local_client(x, blacklistrecheck_md).l) -#define SetLastBLCheck(x, y) do { moddata_local_client(x, blacklistrecheck_md).l = y; } while(0) +#define LastBLCheck(x) (moddata_local_client(x, blacklistrecheck_md).l) +#define SetLastBLCheck(x, y) \ + do \ + { \ + moddata_local_client(x, blacklistrecheck_md).l = y; \ + } while (0) /* Types */ typedef enum { - DNSBL_RECORD=1, DNSBL_BITMASK=2 + DNSBL_RECORD = 1, + DNSBL_BITMASK = 2 } DNSBLType; typedef struct DNSBL DNSBL; @@ -57,8 +61,7 @@ struct DNSBL { }; typedef union BlacklistBackend BlacklistBackend; -union BlacklistBackend -{ +union BlacklistBackend { DNSBL *dns; }; @@ -124,8 +127,12 @@ void blacklist_set_handshake_delay(void); void blacklist_free_bluser_if_able(BLUser *bl); EVENT(blacklist_recheck); -#define SetBLUser(x, y) do { moddata_local_client(x, blacklist_md).ptr = y; } while(0) -#define BLUSER(x) ((BLUser *)moddata_local_client(x, blacklist_md).ptr) +#define SetBLUser(x, y) \ + do \ + { \ + moddata_local_client(x, blacklist_md).ptr = y; \ + } while (0) +#define BLUSER(x) ((BLUser *)moddata_local_client(x, blacklist_md).ptr) MOD_TEST() { @@ -142,7 +149,7 @@ MOD_INIT() ModDataInfo mreq; MARK_AS_OFFICIAL_MODULE(modinfo); - + memset(&mreq, 0, sizeof(mreq)); mreq.name = "blacklist"; mreq.type = MODDATATYPE_LOCAL_CLIENT; @@ -225,7 +232,7 @@ void blacklist_set_handshake_delay(void) Blacklist *blacklist_find_block_by_dns(char *name) { Blacklist *d; - + for (d = conf_blacklist; d; d = d->next) if ((d->backend_type == BLACKLIST_BACKEND_DNS) && !strcmp(name, d->backend->dns->name)) return d; @@ -256,7 +263,7 @@ void delete_blacklist_block(Blacklist *e) safe_free(e->backend->dns); } } - + safe_free(e->backend); safe_free(e->name); @@ -269,24 +276,24 @@ void delete_blacklist_block(Blacklist *e) int blacklist_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { - ConfigEntry *cep, *cepp, *ceppp; + ConfigEntry *cep, *cepp, *ceppp; int errors = 0; char has_reason = 0, has_ban_time = 0, has_action = 0; char has_dns_type = 0, has_dns_reply = 0, has_dns_name = 0, has_recheck = 0; if (type != CONFIG_MAIN) return 0; - + if (!ce) return 0; - + if (strcmp(ce->name, "blacklist")) return 0; /* not interested in non-blacklist stuff.. */ - + if (!ce->value) { config_error("%s:%i: blacklist block without name (use: blacklist somename { })", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); *errs = 1; return -1; } @@ -304,8 +311,8 @@ int blacklist_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { /* this is an error (not a warning) */ config_error("%s:%i: blacklist block may contain only one blacklist::dns::reply item. " - "You can specify multiple replies by using: reply { 1; 2; 4; };", - cepp->file->filename, cepp->line_number); + "You can specify multiple replies by using: reply { 1; 2; 4; };", + cepp->file->filename, cepp->line_number); errors++; continue; } @@ -319,8 +326,8 @@ int blacklist_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (cepp->value && cepp->items) { config_error("%s:%i: blacklist::dns::reply must be either using format 'reply 1;' or " - "'reply { 1; 2; 4; }; but not both formats at the same time.", - cepp->file->filename, cepp->line_number); + "'reply { 1; 2; 4; }; but not both formats at the same time.", + cepp->file->filename, cepp->line_number); errors++; continue; } @@ -329,46 +336,43 @@ int blacklist_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (atoi(cepp->value) <= 0) { config_error("%s:%i: blacklist::dns::reply must be >0", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; continue; } } if (cepp->items) { - for (ceppp = cepp->items; ceppp; ceppp=ceppp->next) + for (ceppp = cepp->items; ceppp; ceppp = ceppp->next) { if (atoi(ceppp->name) <= 0) { config_error("%s:%i: all items in blacklist::dns::reply must be >0", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; } } } - } else - if (!cepp->value) + } else if (!cepp->value) { config_error_empty(cepp->file->filename, cepp->line_number, - "blacklist::dns", cepp->name); + "blacklist::dns", cepp->name); errors++; continue; - } else - if (!strcmp(cepp->name, "name")) + } else if (!strcmp(cepp->name, "name")) { if (has_dns_name) { config_warn_duplicate(cepp->file->filename, - cepp->line_number, "blacklist::dns::name"); + cepp->line_number, "blacklist::dns::name"); } has_dns_name = 1; - } else - if (!strcmp(cepp->name, "type")) + } else if (!strcmp(cepp->name, "type")) { if (has_dns_type) { config_warn_duplicate(cepp->file->filename, - cepp->line_number, "blacklist::dns::type"); + cepp->line_number, "blacklist::dns::type"); } has_dns_type = 1; if (!strcmp(cepp->value, "record")) @@ -378,68 +382,61 @@ int blacklist_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) else { config_error("%s:%i: unknown blacklist::dns::type '%s', must be either 'record' or 'bitmask'", - cepp->file->filename, cepp->line_number, cepp->value); + cepp->file->filename, cepp->line_number, cepp->value); errors++; } } } - } else - if (!strcmp(cep->name, "except")) + } else if (!strcmp(cep->name, "except")) { test_match_block(cf, cep, &errors); - } else - if (!cep->value) + } else if (!cep->value) { config_error_empty(cep->file->filename, cep->line_number, - "blacklist", cep->name); + "blacklist", cep->name); errors++; continue; - } - else if (!strcmp(cep->name, "action")) + } else if (!strcmp(cep->name, "action")) { if (has_action) { config_warn_duplicate(cep->file->filename, - cep->line_number, "blacklist::action"); + cep->line_number, "blacklist::action"); continue; } has_action = 1; errors += test_ban_action_config(cep); - } - else if (!strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-time")) { if (has_ban_time) { config_warn_duplicate(cep->file->filename, - cep->line_number, "blacklist::ban-time"); + cep->line_number, "blacklist::ban-time"); continue; } has_ban_time = 1; - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { if (has_reason) { config_warn_duplicate(cep->file->filename, - cep->line_number, "blacklist::reason"); + cep->line_number, "blacklist::reason"); continue; } has_reason = 1; - } - else if (!strcmp(cep->name, "recheck")) + } else if (!strcmp(cep->name, "recheck")) { if (has_recheck) { config_warn_duplicate(cep->file->filename, - cep->line_number, "blacklist::recheck"); + cep->line_number, "blacklist::recheck"); continue; } has_recheck = 1; - } - else + } else { config_error_unknown(cep->file->filename, cep->line_number, - "blacklist", cep->name); + "blacklist", cep->name); errors++; } } @@ -447,35 +444,35 @@ int blacklist_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!has_action) { config_error_missing(ce->file->filename, ce->line_number, - "blacklist::action"); + "blacklist::action"); errors++; } if (!has_reason) { config_error_missing(ce->file->filename, ce->line_number, - "blacklist::reason"); + "blacklist::reason"); errors++; } if (!has_dns_name) { config_error_missing(ce->file->filename, ce->line_number, - "blacklist::dns::name"); + "blacklist::dns::name"); errors++; } if (!has_dns_type) { config_error_missing(ce->file->filename, ce->line_number, - "blacklist::dns::type"); + "blacklist::dns::type"); errors++; } if (!has_dns_reply) { config_error_missing(ce->file->filename, ce->line_number, - "blacklist::dns::reply"); + "blacklist::dns::reply"); errors++; } @@ -487,10 +484,10 @@ int blacklist_config_run(ConfigFile *cf, ConfigEntry *ce, int type) { ConfigEntry *cep, *cepp, *ceppp; Blacklist *d = NULL; - + if (type != CONFIG_MAIN) return 0; - + if (!ce || !ce->name || strcmp(ce->name, "blacklist")) return 0; /* not interested */ @@ -499,7 +496,7 @@ int blacklist_config_run(ConfigFile *cf, ConfigEntry *ce, int type) /* set some defaults */ d->ban_time = 3600; d->recheck = 1; - + /* assume dns for now ;) */ d->backend_type = BLACKLIST_BACKEND_DNS; d->backend = safe_alloc(sizeof(BlacklistBackend)); @@ -516,11 +513,10 @@ int blacklist_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (cepp->value) { /* single reply */ - d->backend->dns->reply = safe_alloc(sizeof(int)*2); + d->backend->dns->reply = safe_alloc(sizeof(int) * 2); d->backend->dns->reply[0] = atoi(cepp->value); d->backend->dns->reply[1] = 0; - } else - if (cepp->items) + } else if (cepp->items) { /* (potentially) multiple reply values */ int cnt = 0; @@ -529,12 +525,12 @@ int blacklist_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (ceppp->name) cnt++; } - + if (cnt == 0) abort(); /* impossible */ - - d->backend->dns->reply = safe_alloc(sizeof(int)*(cnt+1)); - + + d->backend->dns->reply = safe_alloc(sizeof(int) * (cnt + 1)); + cnt = 0; for (ceppp = cepp->items; ceppp; ceppp = ceppp->next) { @@ -542,44 +538,37 @@ int blacklist_config_run(ConfigFile *cf, ConfigEntry *ce, int type) } d->backend->dns->reply[cnt] = 0; } - } else - if (!strcmp(cepp->name, "type")) + } else if (!strcmp(cepp->name, "type")) { if (!strcmp(cepp->value, "record")) d->backend->dns->type = DNSBL_RECORD; else if (!strcmp(cepp->value, "bitmask")) d->backend->dns->type = DNSBL_BITMASK; - } else - if (!strcmp(cepp->name, "name")) + } else if (!strcmp(cepp->name, "name")) { safe_strdup(d->backend->dns->name, cepp->value); } } - } - else if (!strcmp(cep->name, "action")) + } else if (!strcmp(cep->name, "action")) { parse_ban_action_config(cep, &d->action); - } - else if (!strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-time")) { d->ban_time = config_checkval(cep->value, CFG_TIME); - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { safe_strdup(d->reason, cep->value); - } - else if (!strcmp(cep->name, "except")) + } else if (!strcmp(cep->name, "except")) { conf_match_block(cf, cep, &d->except); - } - else if (!strcmp(cep->name, "recheck")) + } else if (!strcmp(cep->name, "recheck")) { d->recheck = config_checkval(cep->value, CFG_YESNO); } } AddListItem(d, conf_blacklist); - + return 0; } @@ -591,11 +580,11 @@ int blacklist_set_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *er if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::blacklist.. */ if (!ce || !ce->name || strcmp(ce->name, "blacklist")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "recheck-time-first")) @@ -604,7 +593,7 @@ int blacklist_set_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *er if (!cep->value) { config_error("%s:%i: set::blacklist::recheck-time-first with no value", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } @@ -621,17 +610,16 @@ int blacklist_set_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *er if (v < 60) { config_error("%s:%i: set::blacklist::recheck-time-first cannot be less than 60 seconds", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } else - if (!strcmp(cep->name, "recheck-time")) + } else if (!strcmp(cep->name, "recheck-time")) { int v; if (!cep->value) { config_error("%s:%i: set::blacklist::recheck-time with no value", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } @@ -641,19 +629,19 @@ int blacklist_set_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *er if (v < 60) { config_error("%s:%i: set::blacklist::recheck-time cannot be less than 60 seconds", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } } } else { config_error("%s:%i: unknown directive set::blacklist::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } } - + *errs = errors; return errors ? -1 : 1; } @@ -665,11 +653,11 @@ int blacklist_set_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::blacklist.. */ if (!ce || !ce->name || strcmp(ce->name, "blacklist")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "recheck-time")) @@ -739,7 +727,7 @@ int blacklist_start_check(Client *client, int recheck) if (bl->backend_type == BLACKLIST_BACKEND_DNS) blacklist_dns_request(client, bl); } - + return 0; } @@ -748,7 +736,7 @@ int blacklist_dns_request(Client *client, Blacklist *d) char buf[256], wbuf[128]; unsigned int e[8]; char *ip = GetIP(client); - + if (!ip) return 0; @@ -759,16 +747,15 @@ int blacklist_dns_request(Client *client, Blacklist *d) /* IPv4 */ if (sscanf(ip, "%u.%u.%u.%u", &e[0], &e[1], &e[2], &e[3]) != 4) return 0; - + snprintf(buf, sizeof(buf), "%u.%u.%u.%u.%s", e[3], e[2], e[1], e[0], d->backend->dns->name); - } else - if (strchr(ip, ':')) + } else if (strchr(ip, ':')) { /* IPv6 */ int i; BLUSER(client)->is_ipv6 = 1; if (sscanf(ip, "%x:%x:%x:%x:%x:%x:%x:%x", - &e[0], &e[1], &e[2], &e[3], &e[4], &e[5], &e[6], &e[7]) != 8) + &e[0], &e[1], &e[2], &e[3], &e[4], &e[5], &e[6], &e[7]) != 8) { return 0; } @@ -776,21 +763,20 @@ int blacklist_dns_request(Client *client, Blacklist *d) for (i = 7; i >= 0; i--) { snprintf(wbuf, sizeof(wbuf), "%x.%x.%x.%x.", - (unsigned int)(e[i] & 0xf), - (unsigned int)((e[i] >> 4) & 0xf), - (unsigned int)((e[i] >> 8) & 0xf), - (unsigned int)((e[i] >> 12) & 0xf)); + (unsigned int)(e[i] & 0xf), + (unsigned int)((e[i] >> 4) & 0xf), + (unsigned int)((e[i] >> 8) & 0xf), + (unsigned int)((e[i] >> 12) & 0xf)); strlcat(buf, wbuf, sizeof(buf)); } strlcat(buf, d->backend->dns->name, sizeof(buf)); - } - else + } else return 0; /* unknown IP format */ BLUSER(client)->refcnt++; /* one (more) blacklist result remaining */ - + unreal_gethostbyname_api(buf, AF_INET, "blacklist_resolver_callback", BLUSER(client)); - + return 0; } @@ -850,7 +836,7 @@ char *getdnsblname(char *p, Client *client) { dots++; if (dots == dots_count) - return p+1; + return p + 1; } } return NULL; @@ -870,12 +856,12 @@ int blacklist_parse_reply(struct hostent *he, int entry) *ipbuf = '\0'; if (!inet_ntop(AF_INET, he->h_addr_list[entry], ipbuf, sizeof(ipbuf))) return 0; - + p = strrchr(ipbuf, '.'); if (!p) return 0; - - return atoi(p+1); + + return atoi(p + 1); } /** Take the actual ban action. @@ -908,10 +894,10 @@ void blacklist_hit(Client *client, Blacklist *bl, int reply) if (IsUser(client)) snprintf(opernotice, sizeof(opernotice), "[Blacklist] IP %s (%s) matches blacklist %s (%s/reply=%d)", - GetIP(client), client->name, bl->name, bl->backend->dns->name, reply); + GetIP(client), client->name, bl->name, bl->backend->dns->name, reply); else snprintf(opernotice, sizeof(opernotice), "[Blacklist] IP %s matches blacklist %s (%s/reply=%d)", - GetIP(client), bl->name, bl->backend->dns->name, reply); + GetIP(client), bl->name, bl->backend->dns->name, reply); snprintf(reply_num, sizeof(reply_num), "%d", reply); @@ -934,7 +920,8 @@ void blacklist_hit(Client *client, Blacklist *bl, int reply) safe_strdup(blu->save_blacklist_dns_name, bl->backend->dns->name); blu->save_blacklist_dns_reply = reply; } - } else { + } else + { /* Otherwise, execute the action immediately */ blacklist_action(client, opernotice, bl->action, banbuf, bl->ban_time, bl->name, bl->backend->dns->name, reply); } @@ -947,27 +934,27 @@ void blacklist_process_result(Client *client, int status, struct hostent *he) int reply; int i; int replycnt; - + if ((status != 0) || (he->h_length != 4) || !he->h_name) return; /* invalid reply */ - + domain = getdnsblname(he->h_name, client); if (!domain) return; /* odd */ bl = blacklist_find_block_by_dns(domain); if (!bl) return; /* possibly just rehashed and the blacklist block is gone now */ - + /* walk through all replies for this record... until we have a hit */ - for (replycnt=0; he->h_addr_list[replycnt]; replycnt++) + for (replycnt = 0; he->h_addr_list[replycnt]; replycnt++) { reply = blacklist_parse_reply(he, replycnt); for (i = 0; bl->backend->dns->reply[i]; i++) { if ((bl->backend->dns->reply[i] == -1) || - ( (bl->backend->dns->type == DNSBL_BITMASK) && (reply & bl->backend->dns->reply[i]) ) || - ( (bl->backend->dns->type == DNSBL_RECORD) && (bl->backend->dns->reply[i] == reply) ) ) + ((bl->backend->dns->type == DNSBL_BITMASK) && (reply & bl->backend->dns->reply[i])) || + ((bl->backend->dns->type == DNSBL_RECORD) && (bl->backend->dns->reply[i] == reply))) { blacklist_hit(client, bl, reply); return; @@ -1043,9 +1030,9 @@ EVENT(blacklist_recheck) /* First time: check after 60 seconds already */ blacklist_recheck_user(client); } else /* After that, check every <...> seconds */ - if (last_check && (TStime() - last_check) >= BLACKLIST_RECHECK_TIME) - { - blacklist_recheck_user(client); - } + if (last_check && (TStime() - last_check) >= BLACKLIST_RECHECK_TIME) + { + blacklist_recheck_user(client); + } } } diff --git a/src/modules/bot-tag.c b/src/modules/bot-tag.c index 403a6667a..51d07219b 100644 --- a/src/modules/bot-tag.c +++ b/src/modules/bot-tag.c @@ -27,14 +27,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "bot-tag", - "5.0", - "bot message tag", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "bot-tag", + "5.0", + "bot message tag", + "UnrealIRCd Team", + "unrealircd-6", +}; int bottag_mtag_is_ok(Client *client, const char *name, const char *value); void mtag_add_bottag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature); diff --git a/src/modules/botmotd.c b/src/modules/botmotd.c index bcca5f99d..1186bf555 100644 --- a/src/modules/botmotd.c +++ b/src/modules/botmotd.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_botmotd); -#define MSG_BOTMOTD "BOTMOTD" +#define MSG_BOTMOTD "BOTMOTD" -ModuleHeader MOD_HEADER - = { - "botmotd", - "5.0", - "command /botmotd", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "botmotd", + "5.0", + "command /botmotd", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_BOTMOTD, cmd_botmotd, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_BOTMOTD, cmd_botmotd, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } diff --git a/src/modules/cap.c b/src/modules/cap.c index f989de702..54b81b489 100644 --- a/src/modules/cap.c +++ b/src/modules/cap.c @@ -26,16 +26,15 @@ typedef int (*bqcmp)(const void *, const void *); CMD_FUNC(cmd_cap); -#define MSG_CAP "CAP" +#define MSG_CAP "CAP" -ModuleHeader MOD_HEADER - = { - "cap", /* Name of module */ - "5.0", /* Version */ - "command /cap", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "cap", /* Name of module */ + "5.0", /* Version */ + "command /cap", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int cap_is_handshake_finished(Client *client); @@ -48,9 +47,9 @@ long CAP_NOTIFY = 0L; MOD_INIT() { ClientCapabilityInfo c; - + MARK_AS_OFFICIAL_MODULE(modinfo); - CommandAdd(modinfo->handle, MSG_CAP, cmd_cap, MAXPARA, CMD_UNREGISTERED|CMD_USER|CMD_NOLAG); + CommandAdd(modinfo->handle, MSG_CAP, cmd_cap, MAXPARA, CMD_UNREGISTERED | CMD_USER | CMD_NOLAG); /* This first cap is special, in the sense that it is hidden * and indicates a cap exchange is in progress. @@ -100,7 +99,7 @@ static ClientCapability *clicap_find(Client *client, const char *data, int *nega return NULL; /* skip any whitespace */ - while(*p && isspace(*p)) + while (*p && isspace(*p)) p++; if (BadPtr(p)) @@ -125,7 +124,7 @@ static ClientCapability *clicap_find(Client *client, const char *data, int *nega cap = ClientCapabilityFind(p, client); if (!s) *finished = 1; - + p = s; /* point to next token for next iteration */ if (cap && (cap->flags & CLICAP_FLAGS_ADVERTISE_ONLY)) @@ -146,7 +145,7 @@ static void clicap_generate(Client *client, const char *subcmd, int flags) int buflen = 0; int curlen, mlen; - mlen = snprintf(buf, BUFSIZE, ":%s CAP %s %s", me.name, BadPtr(client->name) ? "*" : client->name, subcmd); + mlen = snprintf(buf, BUFSIZE, ":%s CAP %s %s", me.name, BadPtr(client->name) ? "*" : client->name, subcmd); p = capbuf; buflen = mlen; @@ -259,13 +258,13 @@ static void cap_req(Client *client, const char *arg) return; buflen = snprintf(buf, sizeof(buf), ":%s CAP %s ACK", - me.name, BadPtr(client->name) ? "*" : client->name); + me.name, BadPtr(client->name) ? "*" : client->name); pbuf[0][0] = '\0'; plen = 0; - for(cap = clicap_find(client, arg, &negate, &finished, &errors); cap; - cap = clicap_find(client, NULL, &negate, &finished, &errors)) + for (cap = clicap_find(client, arg, &negate, &finished, &errors); cap; + cap = clicap_find(client, NULL, &negate, &finished, &errors)) { /* filled the first array, but cant send it in case the * request fails. one REQ should never fill more than two @@ -284,8 +283,7 @@ static void cap_req(Client *client, const char *arg) plen++; capdel |= cap->cap; - } - else + } else { capadd |= cap->cap; } @@ -309,8 +307,7 @@ static void cap_req(Client *client, const char *arg) { sendto_one(client, NULL, "%s * :%s", buf, pbuf[0]); sendto_one(client, NULL, "%s :%s", buf, pbuf[1]); - } - else + } else sendto_one(client, NULL, "%s :%s", buf, pbuf[0]); client->local->caps |= capadd; @@ -323,10 +320,10 @@ struct clicap_cmd { }; static struct clicap_cmd clicap_cmdtable[] = { - { "END", cap_end }, - { "LIST", cap_list }, - { "LS", cap_ls }, - { "REQ", cap_req }, + {"END", cap_end}, + {"LIST", cap_list}, + {"LS", cap_ls}, + {"REQ", cap_req}, }; static int clicap_cmd_search(const char *command, struct clicap_cmd *entry) @@ -380,8 +377,8 @@ CMD_FUNC(cmd_cap) } if (!(cmd = bsearch(parv[1], clicap_cmdtable, - sizeof(clicap_cmdtable) / sizeof(struct clicap_cmd), - sizeof(struct clicap_cmd), (bqcmp) clicap_cmd_search))) + sizeof(clicap_cmdtable) / sizeof(struct clicap_cmd), + sizeof(struct clicap_cmd), (bqcmp)clicap_cmd_search))) { sendnumeric(client, ERR_INVALIDCAPCMD, parv[1]); diff --git a/src/modules/central-api.c b/src/modules/central-api.c index eb483aac1..0a55de867 100644 --- a/src/modules/central-api.c +++ b/src/modules/central-api.c @@ -5,14 +5,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "central-api", - "1.0.2", - "Acquire and set API key for unrealircd.org services", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "central-api", + "1.0.2", + "Acquire and set API key for unrealircd.org services", + "UnrealIRCd Team", + "unrealircd-6", +}; struct cfgstruct { char *request_key_challenge; @@ -83,20 +82,19 @@ int capi_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::central-api.. */ if (!ce || !ce->name || strcmp(ce->name, "central-api")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!cep->value) { config_error("%s:%i: set::central-api::%s with no value", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "request-key")) + } else if (!strcmp(cep->name, "request-key")) { char *p = strchr(cep->value, '-'); if (!p) @@ -107,29 +105,28 @@ int capi_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) errors++; } req.request_key = 1; - - } else - if (!strcmp(cep->name, "api-key")) + + } else if (!strcmp(cep->name, "api-key")) { if (!strchr(cep->value, ':')) { config_error("%s:%i: set::central-api::api-key: Invalid format. " - "Please check if you copy-pasted the api-key correctly. " - "You can log in at your account to view API keys at " - "https://www.unrealircd.org/central-api/account/", - cep->file->filename, cep->line_number); + "Please check if you copy-pasted the api-key correctly. " + "You can log in at your account to view API keys at " + "https://www.unrealircd.org/central-api/account/", + cep->file->filename, cep->line_number); errors++; } req.api_key = 1; } else { config_error("%s:%i: unknown directive set::central-api::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } } - + *errs = errors; return errors ? -1 : 1; } @@ -143,7 +140,7 @@ int capi_config_posttest(int *errs) config_error("You need to set either set::central-api::request-key or set::central-api::api-key (not both or none)."); config_error("See https://www.unrealircd.org/docs/Central_API for the documentation"); errors++; - } + } *errs = errors; return errors ? -1 : 1; @@ -166,9 +163,9 @@ char *capi_hash(const char *in) static char hashbuf[128]; snprintf(buf, sizeof(buf), "%s:%s:%s", - CAPI_HASH_STRING_PREFIX, - in, - CAPI_HASH_STRING_SUFFIX); + CAPI_HASH_STRING_PREFIX, + in, + CAPI_HASH_STRING_SUFFIX); return sha256hash(hashbuf, buf, strlen(buf)); } @@ -179,11 +176,11 @@ int capi_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::central-api.. */ if (!ce || !ce->name || strcmp(ce->name, "central-api")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "request-key")) @@ -198,8 +195,7 @@ int capi_config_run(ConfigFile *cf, ConfigEntry *ce, int type) safe_strdup(cfg.request_key_challenge, capi_hash(buf)); safe_strdup(cfg.request_key_response, capi_hash(p)); - } else - if (!strcmp(cep->name, "api-key")) + } else if (!strcmp(cep->name, "api-key")) { safe_strdup(cfg.api_key, cep->value); } diff --git a/src/modules/central-blocklist.c b/src/modules/central-blocklist.c index 9254cf004..151bcfdda 100644 --- a/src/modules/central-blocklist.c +++ b/src/modules/central-blocklist.c @@ -5,29 +5,27 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "central-blocklist", - "1.0.8", - "Check users at central blocklist", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "central-blocklist", + "1.0.8", + "Check users at central blocklist", + "UnrealIRCd Team", + "unrealircd-6", +}; ModDataInfo *centralblocklist_md = NULL; Module *cbl_module = NULL; -#define CBL_URL "https://centralblocklist.unrealircd-api.org/api/v1" -#define SPAMREPORT_URL "https://spamreport.unrealircd-api.org/api/spamreport-v1" -#define CBL_TRANSFER_TIMEOUT 10 +#define CBL_URL "https://centralblocklist.unrealircd-api.org/api/v1" +#define SPAMREPORT_URL "https://spamreport.unrealircd-api.org/api/spamreport-v1" +#define CBL_TRANSFER_TIMEOUT 10 #define SPAMREPORT_NUM_REMEMBERED_CMDS 20 -#define WEB(client) ((WebRequest *)moddata_local_client(client, webserver_md).ptr) -#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) +#define WEB(client) ((WebRequest *)moddata_local_client(client, webserver_md).ptr) +#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) typedef struct CBLUser CBLUser; -struct CBLUser -{ +struct CBLUser { json_t *handshake; time_t request_sent; char request_pending; @@ -39,8 +37,7 @@ struct CBLUser /* For tracking current HTTPS requests */ typedef struct CBLTransfer CBLTransfer; -struct CBLTransfer -{ +struct CBLTransfer { CBLTransfer *prev, *next; time_t started; NameList *clients; @@ -96,19 +93,26 @@ void send_request_for_pending_clients(void); const char *get_api_key(void); void set_tag(Client *client, const char *tag, int value); -#define CBLRAW(x) (moddata_local_client(x, centralblocklist_md).ptr) -#define CBL(x) ((CBLUser *)(moddata_local_client(x, centralblocklist_md).ptr)) +#define CBLRAW(x) (moddata_local_client(x, centralblocklist_md).ptr) +#define CBL(x) ((CBLUser *)(moddata_local_client(x, centralblocklist_md).ptr)) -#define alloc_cbl_if_needed(x) do { \ - if (!moddata_local_client(x, centralblocklist_md).ptr) \ - { \ - CBLUser *u = safe_alloc(sizeof(CBLUser)); \ - u->handshake = json_object(); \ - moddata_local_client(x, centralblocklist_md).ptr = u; \ - } \ - } while(0) +#define alloc_cbl_if_needed(x) \ + do \ + { \ + if (!moddata_local_client(x, centralblocklist_md).ptr) \ + { \ + CBLUser *u = safe_alloc(sizeof(CBLUser)); \ + u->handshake = json_object(); \ + moddata_local_client(x, centralblocklist_md).ptr = u; \ + } \ + } while (0) -#define AddScoreAction(item,list) do { item->priority = 0 - item->score; AddListItemPrio(item, list, item->priority); } while(0) +#define AddScoreAction(item, list) \ + do \ + { \ + item->priority = 0 - item->score; \ + AddListItemPrio(item, list, item->priority); \ + } while (0) CMD_OVERRIDE_FUNC(cbl_override); CMD_OVERRIDE_FUNC(cbl_override_spamreport_gather); @@ -244,7 +248,8 @@ MOD_LOAD() "Acquire a key via https://www.unrealircd.org/central-api/ and then " "make sure the central-api-key module is loaded and set::central-api::api-key set."); return MOD_SUCCESS; - } else { + } else + { safe_strdup(cfg.api_key, central_api_key); } @@ -284,11 +289,11 @@ int cbl_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::central-blocklist.. */ if (!ce || !ce->name || strcmp(ce->name, "central-blocklist")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "api-key")) @@ -298,18 +303,16 @@ int cbl_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) "central-api module and put the key in set::central-api::api-key", cep->file->filename, cep->line_number); errors++; - } else - if (!strcmp(cep->name, "except")) + } else if (!strcmp(cep->name, "except")) { test_match_block(cf, cep, &errors); - } else - if (!strcmp(cep->name, "score")) + } else if (!strcmp(cep->name, "score")) { int v = atoi(cep->value); if ((v < 1) || (v > 99)) { config_error("%s:%i: set::central-blocklist::score: must be between 1 - 99 (got: %d)", - cep->file->filename, cep->line_number, v); + cep->file->filename, cep->line_number, v); errors++; } if (cep->items) @@ -320,32 +323,27 @@ int cbl_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!strcmp(cepp->name, "ban-action")) { errors += test_ban_action_config(cepp); - } else - if (!strcmp(cepp->name, "ban-reason")) + } else if (!strcmp(cepp->name, "ban-reason")) { - } else - if (!strcmp(cepp->name, "ban-time")) + } else if (!strcmp(cepp->name, "ban-time")) { } else { config_error("%s:%i: unknown directive set::central-blocklist::score::%s", - cepp->file->filename, cepp->line_number, cepp->name); + cepp->file->filename, cepp->line_number, cepp->name); errors++; continue; } } } - } else - if (!cep->value) + } else if (!cep->value) { config_error("%s:%i: set::central-blocklist::%s with no value", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "url")) + } else if (!strcmp(cep->name, "url")) { - } else - if (!strcmp(cep->name, "spamreport") || !strcmp(cep->name, "spamreport-enabled")) + } else if (!strcmp(cep->name, "spamreport") || !strcmp(cep->name, "spamreport-enabled")) { config_error("%s:%i: set::central-blocklist::%s: This setting is deprecated. " "Please remove this setting, and, if you wish to use spamreport, add a " @@ -353,24 +351,20 @@ int cbl_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) "See https://www.unrealircd.org/docs/Central_spamreport", cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "blocklist") || !strcmp(cep->name, "blocklist-enabled")) + } else if (!strcmp(cep->name, "blocklist") || !strcmp(cep->name, "blocklist-enabled")) { - } else - if (!strcmp(cep->name, "spamreport-url")) + } else if (!strcmp(cep->name, "spamreport-url")) { - } else - if (!strcmp(cep->name, "max-downloads")) + } else if (!strcmp(cep->name, "max-downloads")) { int v = atoi(cep->value); if ((v < 1) || (v > 500)) { config_error("%s:%i: set::central-blocklist::score: must be between 1 - 500 (got: %d)", - cep->file->filename, cep->line_number, v); + cep->file->filename, cep->line_number, v); errors++; } - } else - if (!strcmp(cep->name, "ban-action") || !strcmp(cep->name, "ban-reason") || !strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-action") || !strcmp(cep->name, "ban-reason") || !strcmp(cep->name, "ban-time")) { config_error("%s:%i: set::central-blocklist: you cannot use ban-action/ban-reason/ban-time here. " "There are now multiple score blocks. " @@ -380,12 +374,12 @@ int cbl_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } else { config_error("%s:%i: unknown directive set::central-blocklist::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } } - + *errs = errors; return errors ? -1 : 1; } @@ -405,18 +399,17 @@ int cbl_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::central-blocklist.. */ if (!ce || !ce->name || strcmp(ce->name, "central-blocklist")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "api-key")) { safe_strdup(cfg.api_key, cep->value); - } else - if (!strcmp(cep->name, "score")) + } else if (!strcmp(cep->name, "score")) { if (!cep->items) { @@ -433,47 +426,37 @@ int cbl_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cepp->name, "ban-action")) { parse_ban_action_config(cepp, &action->ban_action); - } else - if (!strcmp(cepp->name, "ban-reason")) + } else if (!strcmp(cepp->name, "ban-reason")) { safe_strdup(action->ban_reason, cepp->value); - } else - if (!strcmp(cepp->name, "ban-time")) + } else if (!strcmp(cepp->name, "ban-time")) { action->ban_time = config_checkval(cepp->value, CFG_TIME); } } } - } else - if (!strcmp(cep->name, "url")) + } else if (!strcmp(cep->name, "url")) { safe_strdup(cfg.url, cep->value); - } else - if (!strcmp(cep->name, "blocklist-enabled")) + } else if (!strcmp(cep->name, "blocklist-enabled")) { cfg.blocklist_enabled = config_checkval(cep->value, CFG_YESNO); - } else - if (!strcmp(cep->name, "spamreport-url")) + } else if (!strcmp(cep->name, "spamreport-url")) { safe_strdup(cfg.spamreport_url, cep->value); - } else - if (!strcmp(cep->name, "max-downloads")) + } else if (!strcmp(cep->name, "max-downloads")) { cfg.max_downloads = atoi(cep->value); - } else - if (!strcmp(cep->name, "ban-action")) + } else if (!strcmp(cep->name, "ban-action")) { parse_ban_action_config(cep, &cfg.actions->ban_action); - } else - if (!strcmp(cep->name, "ban-reason")) + } else if (!strcmp(cep->name, "ban-reason")) { safe_strdup(cfg.actions->ban_reason, cep->value); - } else - if (!strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-time")) { cfg.actions->ban_time = config_checkval(cep->value, CFG_TIME); - } else - if (!strcmp(cep->name, "except")) + } else if (!strcmp(cep->name, "except")) { if (cfg.except) { @@ -543,9 +526,9 @@ EVENT(centralblocklist_timeout_evt) (TStime() - cbl->request_sent > CBL_TRANSFER_TIMEOUT)) { unreal_log(ULOG_WARNING, "central-blocklist", "CENTRAL_BLOCKLIST_TIMEOUT", client, - "Central blocklist too slow to respond. " - "Possible problem with infrastructure at unrealircd.org. " - "Allowing user $client.details in unchecked."); + "Central blocklist too slow to respond. " + "Possible problem with infrastructure at unrealircd.org. " + "Allowing user $client.details in unchecked."); cbl_allow(client); } } @@ -560,14 +543,14 @@ void show_client_json(Client *client) json_serialized = json_dumps(CBL(client)->handshake, JSON_COMPACT); unreal_log(ULOG_DEBUG, "central-blocklist", "DEBUG_CENTRAL_BLOCKLIST", client, - "OUT: $data", - log_data_string("data", json_serialized)); + "OUT: $data", + log_data_string("data", json_serialized)); safe_free(json_serialized); } void cbl_add_client_info(Client *client) { - char buf[BUFSIZE+1]; + char buf[BUFSIZE + 1]; json_t *cbl = CBL(client)->handshake; json_t *child = json_object(); const char *str; @@ -576,7 +559,7 @@ void cbl_add_client_info(Client *client) json_object_set_new(cbl, "client", child); //// THE FOLLOWING IS TAKEN FROM src/json.c AND MODIFIED ///// - + /* First the information that is available for ALL client types: */ json_object_set_new(child, "name", json_string_unreal(client->name)); json_object_set_new(child, "id", json_string_unreal(client->id)); @@ -599,13 +582,15 @@ void cbl_add_client_info(Client *client) { snprintf(buf, sizeof(buf), "%s!%s@%s", client->name, client->user->username, client->user->realhost); json_object_set_new(child, "details", json_string_unreal(buf)); - } else if (client->ip) { + } else if (client->ip) + { if (*client->name) snprintf(buf, sizeof(buf), "%s@%s", client->name, client->ip); else snprintf(buf, sizeof(buf), "[%s]", client->ip); json_object_set_new(child, "details", json_string_unreal(buf)); - } else { + } else + { json_object_set_new(child, "details", json_string_unreal(client->name)); } @@ -670,13 +655,13 @@ void cbl_add_client_info(Client *client) { json_t *j = json_object(); json_object_set_new(child, "tcp_info", j); - json_object_set_new(j, "rtt", json_integer(MAX(tcp_info.tcpi_rtt,1)/1000)); - json_object_set_new(j, "rtt_var", json_integer(MAX(tcp_info.tcpi_rttvar,1)/1000)); -#if defined(__FreeBSD__) + json_object_set_new(j, "rtt", json_integer(MAX(tcp_info.tcpi_rtt, 1) / 1000)); + json_object_set_new(j, "rtt_var", json_integer(MAX(tcp_info.tcpi_rttvar, 1) / 1000)); + #if defined(__FreeBSD__) json_object_set_new(j, "pmtu", json_integer(tcp_info.__tcpi_pmtu)); -#else + #else json_object_set_new(j, "pmtu", json_integer(tcp_info.tcpi_pmtu)); -#endif + #endif json_object_set_new(j, "snd_cwnd", json_integer(tcp_info.tcpi_snd_cwnd)); json_object_set_new(j, "snd_mss", json_integer(tcp_info.tcpi_snd_mss)); json_object_set_new(j, "rcv_mss", json_integer(tcp_info.tcpi_rcv_mss)); @@ -737,8 +722,7 @@ CMD_OVERRIDE_FUNC(cbl_override) { isnick = 1; nospoof = client->local->nospoof; - } else - if (!strcmp(ovr->command->cmd, "PONG") && (parc > 1) && !BadPtr(parv[1])) + } else if (!strcmp(ovr->command->cmd, "PONG") && (parc > 1) && !BadPtr(parv[1])) { unsigned long result = strtoul(parv[1], NULL, 16); if (client->local->nospoof && (client->local->nospoof == result)) @@ -858,12 +842,13 @@ void cbl_handle_response(Client *client, json_t *response) if (highest_ban_action(action->ban_action) <= BAN_ACT_WARN) { unreal_log(ULOG_INFO, "central-blocklist", "CBL_HIT", client, - "CBL: Client $client.details flagged by central-blocklist, but allowed in (score $spam_score)", - log_data_integer("spam_score", spam_score)); - } else { + "CBL: Client $client.details flagged by central-blocklist, but allowed in (score $spam_score)", + log_data_integer("spam_score", spam_score)); + } else + { unreal_log(ULOG_INFO, "central-blocklist", "CBL_HIT_REJECTED_USER", client, - "CBL: Client $client.details is rejected by central-blocklist (score $spam_score)", - log_data_integer("spam_score", spam_score)); + "CBL: Client $client.details is rejected by central-blocklist (score $spam_score)", + log_data_integer("spam_score", spam_score)); } if (take_action(client, action->ban_action, action->ban_reason, action->ban_time, 0, NULL) <= BAN_ACT_WARN) cbl_allow(client); @@ -871,8 +856,8 @@ void cbl_handle_response(Client *client, json_t *response) } } unreal_log(ULOG_DEBUG, "central-blocklist", "DEBUG_CENTRAL_BLOCKLIST", client, - "CBL: Client $client.details is allowed (score $spam_score)", - log_data_integer("spam_score", spam_score)); + "CBL: Client $client.details is allowed (score $spam_score)", + log_data_integer("spam_score", spam_score)); cbl_allow(client); } @@ -890,17 +875,17 @@ void cbl_error_response(CBLTransfer *transfer, const char *error) if (CBL(client) && CBL(client)->allowed_in) continue; /* Client allowed in already (eg due to timeout) */ unreal_log(ULOG_DEBUG, "central-blocklist", "DEBUG_CENTRAL_BLOCKLIST_ERROR", client, - "CBL: Client $client.details allowed in due to CBL error: $error", - log_data_string("error", error)); + "CBL: Client $client.details allowed in due to CBL error: $error", + log_data_string("error", error)); cbl_allow(client); num++; } if (num > 0) { unreal_log(ULOG_INFO, "central-blocklist", "CENTRAL_BLOCKLIST_ERROR", NULL, - "CBL: Allowed $num_clients client(s) in due to CBL error: $error", - log_data_integer("num_clients", num), - log_data_string("error", error)); + "CBL: Allowed $num_clients client(s) in due to CBL error: $error", + log_data_integer("num_clients", num), + log_data_string("error", error)); } del_cbl_transfer(transfer); } @@ -1021,8 +1006,8 @@ void send_request_for_pending_clients(void) if (num > cfg.max_downloads) { unreal_log(ULOG_WARNING, "central-blocklist", "CENTRAL_BLOCKLIST_TOO_MANY_CONCURRENT_REQUESTS", NULL, - "Already $num_requests HTTP(S) requests in progress.", - log_data_integer("num_requests", num)); + "Already $num_requests HTTP(S) requests in progress.", + log_data_integer("num_requests", num)); return; } @@ -1051,7 +1036,7 @@ void send_request_for_pending_clients(void) if (!json_serialized) { unreal_log(ULOG_WARNING, "central-blocklist", "CENTRAL_BLOCKLIST_BUG_SERIALIZE", client, - "Unable to serialize JSON request. Weird."); + "Unable to serialize JSON request. Weird."); json_decref(j); free_entire_name_list(clientlist); return; @@ -1116,7 +1101,8 @@ CMD_OVERRIDE_FUNC(cbl_override_spamreport_gather) if (clictx && clictx->textanalysis) { memcpy(&CBL(client)->last_cmds_textanalysis[slot], clictx->textanalysis, sizeof(TextAnalysis)); - } else { + } else + { memset(&CBL(client)->last_cmds_textanalysis[slot], 0, sizeof(TextAnalysis)); } CBL(client)->last_cmds_slot++; @@ -1149,8 +1135,8 @@ int _central_spamreport(Client *client, Client *by, const char *url) if (num > cfg.max_downloads) { unreal_log(ULOG_WARNING, "central-blocklist", "CENTRAL_BLOCKLIST_TOO_MANY_CONCURRENT_REQUESTS", NULL, - "Already $num_requests HTTP(S) requests in progress.", - log_data_integer("num_requests", num)); + "Already $num_requests HTTP(S) requests in progress.", + log_data_integer("num_requests", num)); return 0; } @@ -1206,7 +1192,7 @@ int _central_spamreport(Client *client, Client *by, const char *url) if (!json_serialized) { unreal_log(ULOG_WARNING, "central-blocklist", "CENTRAL_BLOCKLIST_BUG_SERIALIZE", client, - "Unable to serialize JSON request. Weird."); + "Unable to serialize JSON request. Weird."); json_decref(j); return 0; } diff --git a/src/modules/certfp.c b/src/modules/certfp.c index 4f8871238..9405c94dc 100644 --- a/src/modules/certfp.c +++ b/src/modules/certfp.c @@ -11,14 +11,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "certfp", - "5.0", - "Certificate fingerprint", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "certfp", + "5.0", + "Certificate fingerprint", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ void certfp_free(ModData *m); @@ -36,7 +35,7 @@ MOD_INIT() ModDataInfo mreq; MARK_AS_OFFICIAL_MODULE(modinfo); - + memset(&mreq, 0, sizeof(mreq)); mreq.name = "certfp"; mreq.free = certfp_free; @@ -83,12 +82,13 @@ char *get_fingerprint_for_client(Client *client) if (!MyConnect(client) || !client->local->ssl) return NULL; - + x509_clientcert = SSL_get_peer_certificate(client->local->ssl); if (x509_clientcert) { - if (X509_digest(x509_clientcert, digest, md, &n)) { + if (X509_digest(x509_clientcert, digest, md, &n)) + { binarytohex(md, n, hex); X509_free(x509_clientcert); return hex; @@ -117,7 +117,7 @@ int certfp_connect(Client *client) if (IsSecure(client)) { const char *fp = moddata_client_get(client, "certfp"); - + if (fp && !iConf.no_connect_tls_info) sendnotice(client, "*** Your TLS certificate fingerprint is %s", fp); } diff --git a/src/modules/chanmodes/censor.c b/src/modules/chanmodes/censor.c index 655e59a80..6d12a684f 100644 --- a/src/modules/chanmodes/censor.c +++ b/src/modules/chanmodes/censor.c @@ -6,14 +6,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/censor", - "4.2", - "Channel Mode +G", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/censor", + "4.2", + "Channel Mode +G", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTMODE_CENSOR = 0L; @@ -37,7 +36,7 @@ MOD_TEST() HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, censor_config_test); return MOD_SUCCESS; } - + MOD_INIT() { CmodeInfo req; @@ -87,24 +86,24 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (type != CONFIG_MAIN) return 0; - + if (!ce || !ce->name || strcmp(ce->name, "badword")) return 0; /* not interested */ if (!ce->value) { config_error("%s:%i: badword without type", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); *errs = 1; return -1; - } - else if (strcmp(ce->value, "channel") && - strcmp(ce->value, "quit") && strcmp(ce->value, "all")) { + } else if (strcmp(ce->value, "channel") && + strcmp(ce->value, "quit") && strcmp(ce->value, "all")) + { /* config_error("%s:%i: badword with unknown type", ce->file->filename, ce->line_number); -- can't do that.. */ return 0; /* unhandled */ } - + if (!strcmp(ce->value, "quit")) { config_error("%s:%i: badword quit has been removed. We just use the bad words from " @@ -125,36 +124,34 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) const char *errbuf; if (has_word) { - config_warn_duplicate(cep->file->filename, - cep->line_number, "badword::word"); + config_warn_duplicate(cep->file->filename, + cep->line_number, "badword::word"); continue; } has_word = 1; - if ((errbuf = badword_config_check_regex(cep->value,1,1))) + if ((errbuf = badword_config_check_regex(cep->value, 1, 1))) { config_error("%s:%i: badword::%s contains an invalid regex: %s", - cep->file->filename, - cep->line_number, - cep->name, errbuf); + cep->file->filename, + cep->line_number, + cep->name, errbuf); errors++; } - } - else if (!strcmp(cep->name, "replace")) + } else if (!strcmp(cep->name, "replace")) { if (has_replace) { - config_warn_duplicate(cep->file->filename, - cep->line_number, "badword::replace"); + config_warn_duplicate(cep->file->filename, + cep->line_number, "badword::replace"); continue; } has_replace = 1; - } - else if (!strcmp(cep->name, "action")) + } else if (!strcmp(cep->name, "action")) { if (has_action) { - config_warn_duplicate(cep->file->filename, - cep->line_number, "badword::action"); + config_warn_duplicate(cep->file->filename, + cep->line_number, "badword::action"); continue; } has_action = 1; @@ -165,16 +162,15 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) else { config_error("%s:%d: Unknown badword::action '%s'", - cep->file->filename, cep->line_number, - cep->value); + cep->file->filename, cep->line_number, + cep->value); errors++; } - - } - else + + } else { config_error_unknown(cep->file->filename, cep->line_number, - "badword", cep->name); + "badword", cep->name); errors++; } } @@ -182,7 +178,7 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!has_word) { config_error_missing(ce->file->filename, ce->line_number, - "badword::word"); + "badword::word"); errors++; } if (has_action) @@ -190,11 +186,11 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (has_replace && action == 'b') { config_error("%s:%i: badword::action is block but badword::replace exists", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } } - + *errs = errors; return errors ? -1 : 1; } @@ -207,12 +203,12 @@ int censor_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (type != CONFIG_MAIN) return 0; - + if (!ce || !ce->name || strcmp(ce->name, "badword")) return 0; /* not interested */ if (strcmp(ce->value, "channel") && strcmp(ce->value, "all")) - return 0; /* not for us */ + return 0; /* not for us */ ca = safe_alloc(sizeof(ConfigItem_badword)); ca->action = BADWORD_REPLACE; @@ -225,12 +221,10 @@ int censor_config_run(ConfigFile *cf, ConfigEntry *ce, int type) { ca->action = BADWORD_BLOCK; } - } - else if (!strcmp(cep->name, "replace")) + } else if (!strcmp(cep->name, "replace")) { safe_strdup(ca->replace, cep->value); - } else - if (!strcmp(cep->name, "word")) + } else if (!strcmp(cep->name, "word")) { word = cep; } @@ -330,9 +324,9 @@ int censor_stats_badwords_channel(Client *client, const char *para) for (words = conf_badword_channel; words; words = words->next) { sendtxtnumeric(client, "c %c %s%s%s %s", words->type & BADW_TYPE_REGEX ? 'R' : 'F', - (words->type & BADW_TYPE_FAST_L) ? "*" : "", words->word, - (words->type & BADW_TYPE_FAST_R) ? "*" : "", - words->action == BADWORD_REPLACE ? (words->replace ? words->replace : "") : ""); + (words->type & BADW_TYPE_FAST_L) ? "*" : "", words->word, + (words->type & BADW_TYPE_FAST_R) ? "*" : "", + words->action == BADWORD_REPLACE ? (words->replace ? words->replace : "") : ""); } return 1; } diff --git a/src/modules/chanmodes/chanadmin.c b/src/modules/chanmodes/chanadmin.c index 358557daf..5ba37e6bc 100644 --- a/src/modules/chanmodes/chanadmin.c +++ b/src/modules/chanmodes/chanadmin.c @@ -19,14 +19,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/chanadmin", - "6.0", - "Channel Mode +a", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/chanadmin", + "6.0", + "Channel Mode +a", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int cmode_chanadmin_is_ok(Client *client, Channel *channel, char mode, const char *para, int type, int what); diff --git a/src/modules/chanmodes/chanop.c b/src/modules/chanmodes/chanop.c index 3a08f3239..3c0878691 100644 --- a/src/modules/chanmodes/chanop.c +++ b/src/modules/chanmodes/chanop.c @@ -19,14 +19,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/chanop", - "6.0", - "Channel Mode +o", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/chanop", + "6.0", + "Channel Mode +o", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int cmode_chanop_is_ok(Client *client, Channel *channel, char mode, const char *para, int type, int what); diff --git a/src/modules/chanmodes/chanowner.c b/src/modules/chanmodes/chanowner.c index f449d9905..093ec790f 100644 --- a/src/modules/chanmodes/chanowner.c +++ b/src/modules/chanmodes/chanowner.c @@ -19,14 +19,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/chanowner", - "6.0", - "Channel Mode +q", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/chanowner", + "6.0", + "Channel Mode +q", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int cmode_chanowner_is_ok(Client *client, Channel *channel, char mode, const char *para, int type, int what); diff --git a/src/modules/chanmodes/delayjoin.c b/src/modules/chanmodes/delayjoin.c index 574eb3ce3..654f66153 100644 --- a/src/modules/chanmodes/delayjoin.c +++ b/src/modules/chanmodes/delayjoin.c @@ -5,16 +5,15 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/delayjoin", /* Name of module */ - "5.0", /* Version */ - "delayed join (+D,+d)", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/delayjoin", /* Name of module */ + "5.0", /* Version */ + "delayed join (+D,+d)", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; -#define MOD_DATA_STR "delayjoin" +#define MOD_DATA_STR "delayjoin" #define MOD_DATA_INVISIBLE "1" static long UMODE_PRIVDEAF = 0; @@ -130,12 +129,12 @@ void clear_user_invisible_announce(Channel *channel, Client *client, MessageTag set_user_invisible(client, channel, 0); ircsnprintf(joinbuf, sizeof(joinbuf), ":%s!%s@%s JOIN %s", - client->name, client->user->username, GetHost(client), channel->name); + client->name, client->user->username, GetHost(client), channel->name); ircsnprintf(exjoinbuf, sizeof(exjoinbuf), ":%s!%s@%s JOIN %s %s :%s", - client->name, client->user->username, GetHost(client), channel->name, - IsLoggedIn(client) ? client->user->account : "*", - client->info); + client->name, client->user->username, GetHost(client), channel->name, + IsLoggedIn(client) ? client->user->account : "*", + client->info); new_message_special(client, recv_mtags, &mtags, ":%s JOIN %s", client->name, channel->name); for (i = channel->members; i; i = i->next) @@ -153,7 +152,7 @@ void clear_user_invisible_announce(Channel *channel, Client *client, MessageTag /* If this was the last invisible user to become visible, then set -d */ if ((channel->mode.mode & EXTMODE_POST_DELAYED) && !channel_has_invisible_users(channel)) - clear_post_delayed(channel); + clear_post_delayed(channel); } int delayjoin_is_ok(Client *client, Channel *channel, char mode, const char *para, int checkt, int what) @@ -176,7 +175,7 @@ int moded_part(Client *client, Channel *channel, MessageTag *mtags, const char * { set_user_invisible(client, channel, 0); if (!channel_has_invisible_users(channel)) - clear_post_delayed(channel); + clear_post_delayed(channel); } return 0; } @@ -186,7 +185,7 @@ int moded_quit(Client *client, MessageTag *mtags, const char *comment) Membership *membership; Channel *channel; - for (membership = client->user->channel; membership; membership=membership->next) + for (membership = client->user->channel; membership; membership = membership->next) { channel = membership->channel; /* Identical to moded_part() */ @@ -244,8 +243,8 @@ int moded_chanmode(Client *client, Channel *channel, MessageTag *recv_mtags, con { if (pm.what == MODE_ADD && (pm.modechar == 'o' || pm.modechar == 'h' || pm.modechar == 'a' || pm.modechar == 'q' || pm.modechar == 'v')) { - Member* i; - Client *user = find_client(pm.param,NULL); + Member *i; + Client *user = find_client(pm.param, NULL); if (!user) continue; @@ -271,18 +270,18 @@ int moded_chanmode(Client *client, Channel *channel, MessageTag *recv_mtags, con channel->name, IsLoggedIn(i->client) ? i->client->user->account : "*", i->client->info); - } else { + } else + { sendto_one(user, mtags, ":%s!%s@%s JOIN :%s", i->client->name, i->client->user->username, GetHost(i->client), channel->name); } free_message_tags(mtags); } } - } if (pm.what == MODE_DEL && (pm.modechar == 'o' || pm.modechar == 'h' || pm.modechar == 'a' || pm.modechar == 'q' || pm.modechar == 'v')) { - Member* i; - Client *user = find_client(pm.param,NULL); + Member *i; + Client *user = find_client(pm.param, NULL); if (!user) continue; @@ -305,7 +304,6 @@ int moded_chanmode(Client *client, Channel *channel, MessageTag *recv_mtags, con free_message_tags(mtags); } } - } } } diff --git a/src/modules/chanmodes/floodprot.c b/src/modules/chanmodes/floodprot.c index 37edbb4b8..06d52fe15 100644 --- a/src/modules/chanmodes/floodprot.c +++ b/src/modules/chanmodes/floodprot.c @@ -19,26 +19,25 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/floodprot", - "6.0", - "Channel Mode +f and +F", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/floodprot", + "6.0", + "Channel Mode +f and +F", + "UnrealIRCd Team", + "unrealircd-6", +}; typedef enum Flood { - CHFLD_CTCP = 0, - CHFLD_JOIN = 1, - CHFLD_KNOCK = 2, - CHFLD_MSG = 3, - CHFLD_NICK = 4, - CHFLD_TEXT = 5, - CHFLD_REPEAT = 6, - CHFLD_PASTE = 7, + CHFLD_CTCP = 0, + CHFLD_JOIN = 1, + CHFLD_KNOCK = 2, + CHFLD_MSG = 3, + CHFLD_NICK = 4, + CHFLD_TEXT = 5, + CHFLD_REPEAT = 6, + CHFLD_PASTE = 7, } Flood; -#define NUMFLD 8 /* 8 flood types */ +#define NUMFLD 8 /* 8 flood types */ /** Configuration settings */ struct { @@ -77,8 +76,8 @@ FloodType floodtypes[] = { }; /* clang-format on */ -#define MODEF_DEFAULT_UNSETTIME cfg.modef_default_unsettime -#define MODEF_MAX_UNSETTIME cfg.modef_max_unsettime +#define MODEF_DEFAULT_UNSETTIME cfg.modef_default_unsettime +#define MODEF_MAX_UNSETTIME cfg.modef_max_unsettime typedef struct ChannelFloodProtection ChannelFloodProtection; typedef struct ChannelFloodProfile ChannelFloodProfile; @@ -109,14 +108,14 @@ struct MemberFlood { /** Per-channel flood protection settings and counters */ struct ChannelFloodProtection { - unsigned short per; /**< setting: per seconds */ - time_t timer[NUMFLD]; /**< runtime: timers */ - unsigned short counter[NUMFLD]; /**< runtime: counters */ - unsigned short counter_unknown_users[NUMFLD]; /**< runtime: counters */ - unsigned short limit[NUMFLD]; /**< setting: limit */ - unsigned char action[NUMFLD]; /**< setting: action */ - unsigned char remove_after[NUMFLD]; /**< setting: remove-after minutes */ - unsigned char timers_running[MAXCHMODEFACTIONS+1]; /**< if for example a '-m' timer is running then this contains 'm' */ + unsigned short per; /**< setting: per seconds */ + time_t timer[NUMFLD]; /**< runtime: timers */ + unsigned short counter[NUMFLD]; /**< runtime: counters */ + unsigned short counter_unknown_users[NUMFLD]; /**< runtime: counters */ + unsigned short limit[NUMFLD]; /**< setting: limit */ + unsigned char action[NUMFLD]; /**< setting: action */ + unsigned char remove_after[NUMFLD]; /**< setting: remove-after minutes */ + unsigned char timers_running[MAXCHMODEFACTIONS + 1]; /**< if for example a '-m' timer is running then this contains 'm' */ char *profile; }; @@ -132,18 +131,20 @@ ModDataInfo *mdflood = NULL; * protection (+f/+F), per flood type. Read via the channel_flood_blocked_count efunc * (eg the total_channel_flood_count() crule). Local-only, freed on disconnect. */ -typedef struct ChannelFloodBlocks { int blocked[NUMFLD]; } ChannelFloodBlocks; +typedef struct ChannelFloodBlocks { + int blocked[NUMFLD]; +} ChannelFloodBlocks; ModDataInfo *md_channelflood_blocked = NULL; /* Friendly type names for the efunc/crule, indexed by enum Flood. KEEP IN SYNC. */ static const char *channelfloodtype_names[NUMFLD] = { - "ctcp", /* CHFLD_CTCP */ - "join", /* CHFLD_JOIN */ - "knock", /* CHFLD_KNOCK */ - "msg", /* CHFLD_MSG */ - "nick", /* CHFLD_NICK */ - "text", /* CHFLD_TEXT */ - "repeat", /* CHFLD_REPEAT */ - "paste", /* CHFLD_PASTE */ + "ctcp", /* CHFLD_CTCP */ + "join", /* CHFLD_JOIN */ + "knock", /* CHFLD_KNOCK */ + "msg", /* CHFLD_MSG */ + "nick", /* CHFLD_NICK */ + "text", /* CHFLD_TEXT */ + "repeat", /* CHFLD_REPEAT */ + "paste", /* CHFLD_PASTE */ }; Cmode_t EXTMODE_FLOODLIMIT = 0L; Cmode_t EXTMODE_FLOOD_PROFILE = 0L; @@ -153,7 +154,7 @@ ChannelFloodProfile *channel_flood_profiles = NULL; char *floodprot_msghash_key = NULL; long long floodprot_splittime = 0; -#define IsFloodLimit(x) (((x)->mode.mode & EXTMODE_FLOODLIMIT) || ((x)->mode.mode & EXTMODE_FLOOD_PROFILE) || (cfg.default_profile && GETPARASTRUCT((x), 'F'))) +#define IsFloodLimit(x) (((x)->mode.mode & EXTMODE_FLOODLIMIT) || ((x)->mode.mode & EXTMODE_FLOOD_PROFILE) || (cfg.default_profile && GETPARASTRUCT((x), 'F'))) /* Forward declarations */ static void init_config(void); @@ -199,7 +200,7 @@ void floodprot_free_msghash_key(ModData *m); CMD_OVERRIDE_FUNC(floodprot_override_mode); ChannelFloodProtection *get_channel_flood_profile(const char *name); int parse_channel_mode_flood(const char *param, ChannelFloodProtection *fld, int strict, Client *client, const char **error_out); -int parse_channel_mode_flood_failed(const char **error_out, ChannelFloodProtection *fld, FORMAT_STRING(const char *fmt), ...) __attribute__((format(printf,3,4))); +int parse_channel_mode_flood_failed(const char **error_out, ChannelFloodProtection *fld, FORMAT_STRING(const char *fmt), ...) __attribute__((format(printf, 3, 4))); int floodprot_server_quit(Client *client, MessageTag *mtags); void inherit_settings(ChannelFloodProtection *from, ChannelFloodProtection *to); void reapply_profiles(void); @@ -267,7 +268,7 @@ MOD_INIT() mreq.free = memberflood_free; mdflood = ModDataAdd(modinfo->handle, mreq); if (!mdflood) - abort(); + abort(); memset(&mreq, 0, sizeof(mreq)); mreq.name = "channelfloodblocks"; @@ -429,36 +430,36 @@ int floodprot_config_test_set_block(ConfigFile *cf, ConfigEntry *ce, int type, i if (!ce->value) { config_error_empty(ce->file->filename, ce->line_number, - "set", ce->name); + "set", ce->name); errors++; - } else { + } else + { int v = atoi(ce->value); if ((v <= 0) || (v > 255)) { config_error("%s:%i: set::modef-default-unsettime: value '%d' out of range (should be 1-255)", - ce->file->filename, ce->line_number, v); + ce->file->filename, ce->line_number, v); errors++; } } - } else - if (!strcmp(ce->name, "modef-max-unsettime")) + } else if (!strcmp(ce->name, "modef-max-unsettime")) { if (!ce->value) { config_error_empty(ce->file->filename, ce->line_number, - "set", ce->name); + "set", ce->name); errors++; - } else { + } else + { int v = atoi(ce->value); if ((v <= 0) || (v > 255)) { config_error("%s:%i: set::modef-max-unsettime: value '%d' out of range (should be 1-255)", - ce->file->filename, ce->line_number, v); + ce->file->filename, ce->line_number, v); errors++; } } - } else - if (!strcmp(ce->name, "modef-boot-delay")) + } else if (!strcmp(ce->name, "modef-boot-delay")) { config_error("%s:%i: set::modef-boot-delay is now called set::anti-flood::channel::boot-delay. " "See https://www.unrealircd.org/docs/Channel_anti-flood_settings#config", @@ -521,27 +522,26 @@ int floodprot_config_test_antiflood_block(ConfigFile *cf, ConfigEntry *ce, int t errors++; continue; } - } else - if (!strcmp(ce->name, "boot-delay") || !strcmp(ce->name, "split-delay")) + } else if (!strcmp(ce->name, "boot-delay") || !strcmp(ce->name, "split-delay")) { if (!ce->value) { config_error_empty(ce->file->filename, ce->line_number, - "set", ce->name); + "set", ce->name); errors++; - } else { + } else + { long v = config_checkval(ce->value, CFG_TIME); if ((v < 0) || (v > 600)) { config_error("%s:%i: set::anti-flood::channel::%s: value '%ld' out of range (should be 0-600)", - ce->file->filename, ce->line_number, - ce->name, - v); + ce->file->filename, ce->line_number, + ce->name, + v); errors++; } } - } else - if (!strcmp(ce->name, "profile")) + } else if (!strcmp(ce->name, "profile")) { if (!ce->value) { @@ -583,9 +583,9 @@ int floodprot_config_test_antiflood_block(ConfigFile *cf, ConfigEntry *ce, int t } else if (!BadPtr(err)) { config_warn("%s:%i: set::anti-flood::channel::profile %s::flood-mode: %s", - cep->file->filename, cep->line_number, - ce->value, - err); + cep->file->filename, cep->line_number, + ce->value, + err); } if (fld.limit[CHFLD_TEXT] || fld.limit[CHFLD_REPEAT]) { @@ -595,9 +595,10 @@ int floodprot_config_test_antiflood_block(ConfigFile *cf, ConfigEntry *ce, int t ce->value); errors++; } - } else { + } else + { config_error_unknown(cep->file->filename, cep->line_number, - "set::anti-flood::channel::profile", cep->name); + "set::anti-flood::channel::profile", cep->name); errors++; } } @@ -629,16 +630,13 @@ int floodprot_config_run_antiflood_block(ConfigFile *cf, ConfigEntry *ce, int ty /* Let's handle 'off' in a special way -> becomes NULL */ if (!strcmp(cfg.default_profile, "off")) safe_free(cfg.default_profile); - } else - if (!strcmp(ce->name, "boot-delay")) + } else if (!strcmp(ce->name, "boot-delay")) { cfg.boot_delay = config_checkval(ce->value, CFG_TIME); - } else - if (!strcmp(ce->name, "split-delay")) + } else if (!strcmp(ce->name, "split-delay")) { cfg.split_delay = config_checkval(ce->value, CFG_TIME); - } else - if (!strcmp(ce->name, "profile")) + } else if (!strcmp(ce->name, "profile")) { for (cep = ce->items; cep; cep = cep->next) { @@ -653,7 +651,7 @@ int floodprot_config_run_antiflood_block(ConfigFile *cf, ConfigEntry *ce, int ty FloodType *find_floodprot_by_letter(char c) { int i; - for (i=0; i < ARRAY_SIZEOF(floodtypes); i++) + for (i = 0; i < ARRAY_SIZEOF(floodtypes); i++) if (floodtypes[i].letter == c) return &floodtypes[i]; @@ -663,7 +661,7 @@ FloodType *find_floodprot_by_letter(char c) FloodType *find_floodprot_by_index(Flood index) { int i; - for (i=0; i < ARRAY_SIZEOF(floodtypes); i++) + for (i = 0; i < ARRAY_SIZEOF(floodtypes); i++) if (floodtypes[i].index == index) return &floodtypes[i]; @@ -693,7 +691,7 @@ int parse_channel_mode_flood_failed(const char **error_out, ChannelFloodProtecti va_end(vl); /* Zero out all settings */ - for (v=0; v < NUMFLD; v++) + for (v = 0; v < NUMFLD; v++) { fld->limit[v] = 0; fld->action[v] = 0; @@ -736,7 +734,7 @@ int floodprot_valid_alternate_action(char action, FloodType *floodtype) int parse_channel_mode_flood(const char *param, ChannelFloodProtection *fld, int strict, Client *client, const char **error_out) { static char retbuf[512]; - char xbuf[256], c, a, *p, *p2, *x = xbuf+1; + char xbuf[256], c, a, *p, *p2, *x = xbuf + 1; int v; unsigned short breakit; unsigned char r; @@ -750,7 +748,7 @@ int parse_channel_mode_flood(const char *param, ChannelFloodProtection *fld, int *error_out = NULL; /* always reset settings (l, a, r) */ - for (v=0; v < NUMFLD; v++) + for (v = 0; v < NUMFLD; v++) { fld->limit[v] = 0; fld->action[v] = 0; @@ -763,19 +761,22 @@ int parse_channel_mode_flood(const char *param, ChannelFloodProtection *fld, int return parse_channel_mode_flood_failed(error_out, fld, "Invalid format (brackets missing)"); /* '['<1 letter>[optional: '#'+1 letter],[next..]']'':' */ - p2 = strchr(xbuf+1, ']'); + p2 = strchr(xbuf + 1, ']'); if (!p2) return parse_channel_mode_flood_failed(error_out, fld, "Invalid format (brackets missing)"); *p2 = '\0'; - if (*(p2+1) != ':') + if (*(p2 + 1) != ':') return parse_channel_mode_flood_failed(error_out, fld, "Invalid format (:XX period missing)"); breakit = 0; - for (x = strtok(xbuf+1, ","); x; x = strtok(NULL, ",")) + for (x = strtok(xbuf + 1, ","); x; x = strtok(NULL, ",")) { /* <1 letter>[optional: '#'+1 letter] */ p = x; - while(isdigit(*p)) { p++; } + while (isdigit(*p)) + { + p++; + } /* letter */ c = *p; @@ -850,7 +851,7 @@ int parse_channel_mode_flood(const char *param, ChannelFloodProtection *fld, int if (v < fld->per) { int i; - for (i=0; i < NUMFLD; i++) + for (i = 0; i < NUMFLD; i++) { fld->timer[i] = 0; fld->counter[i] = 0; @@ -861,9 +862,9 @@ int parse_channel_mode_flood(const char *param, ChannelFloodProtection *fld, int /* Is anything turned on? (to stop things like '+f []:15' */ breakit = 1; - for (v=0; v < NUMFLD; v++) + for (v = 0; v < NUMFLD; v++) if (fld->limit[v]) - breakit=0; + breakit = 0; if (breakit) { /* Nothing is turned on.. */ @@ -891,8 +892,7 @@ int cmodef_is_ok(Client *client, Channel *channel, char mode, const char *param, if (type == EXCHK_ACCESS_ERR) /* can only be due to being halfop */ sendnumeric(client, ERR_NOTFORHALFOPS, 'f'); return EX_DENY; - } else - if (type == EXCHK_PARAM) + } else if (type == EXCHK_PARAM) { ChannelFloodProtection fld; const char *err; @@ -1014,7 +1014,7 @@ int cmodef_sjoin_check(Channel *channel, void *ourx, void *theirx) return EXSJ_SAME; our->per = MAX(our->per, their->per); - for (i=0; i < NUMFLD; i++) + for (i = 0; i < NUMFLD; i++) { our->limit[i] = MAX(our->limit[i], their->limit[i]); our->action[i] = MAX(our->action[i], their->action[i]); @@ -1061,8 +1061,7 @@ int cmodef_profile_is_ok(Client *client, Channel *channel, char mode, const char if (type == EXCHK_ACCESS_ERR) /* can only be due to being halfop */ sendnumeric(client, ERR_NOTFORHALFOPS, 'f'); return EX_DENY; - } else - if (type == EXCHK_PARAM) + } else if (type == EXCHK_PARAM) { if (get_channel_flood_profile(param)) return EX_ALLOW; @@ -1082,7 +1081,7 @@ void inherit_settings(ChannelFloodProtection *from, ChannelFloodProtection *to) /* If new 'per xxx seconds' is smaller than current 'per' then reset timers/counters (t, c) */ if (from->per < to->per) { - for (i=0; i < NUMFLD; i++) + for (i = 0; i < NUMFLD; i++) { to->timer[i] = 0; to->counter[i] = 0; @@ -1091,7 +1090,7 @@ void inherit_settings(ChannelFloodProtection *from, ChannelFloodProtection *to) } /* inherit settings (limit/action/remove_after) */ - for (i=0; i < NUMFLD; i++) + for (i = 0; i < NUMFLD; i++) { to->limit[i] = from->limit[i]; to->action[i] = from->action[i]; @@ -1174,7 +1173,7 @@ int is_floodprot_exempt(Client *client, Channel *channel, char flood_type_letter b->channel = channel; b->ban_check_types = BANCHK_MSG; - for (ban = channel->exlist; ban; ban=ban->next) + for (ban = channel->exlist; ban; ban = ban->next) { char *p, *x; char *matchby; @@ -1234,7 +1233,7 @@ int floodprot_join(Client *client, Channel *channel, MessageTag *mtags) #endif !IsULine(client)) { - do_floodprot(channel, client, CHFLD_JOIN); + do_floodprot(channel, client, CHFLD_JOIN); } return 0; } @@ -1273,8 +1272,8 @@ int cmodef_channel_destroy(Channel *channel, int *should_destroy) /* [just a helper for channel_modef_string()] */ static inline char *chmodefstrhelper(char *buf, char t, char tdef, unsigned short l, unsigned char a, unsigned char r) { -char *p; -char tmpbuf[16], *p2 = tmpbuf; + char *p; + char tmpbuf[16], *p2 = tmpbuf; sprintf(buf, "%hd", l); p = buf + strlen(buf); @@ -1305,7 +1304,7 @@ char *channel_modef_string(ChannelFloodProtection *x, char *retbuf) *p++ = '['; - for (i=0; i < ARRAY_SIZEOF(floodtypes); i++) + for (i = 0; i < ARRAY_SIZEOF(floodtypes); i++) { f = &floodtypes[i]; if (x->limit[f->index]) @@ -1387,7 +1386,7 @@ int floodprot_can_send_to_channel(Client *client, Channel *channel, Membership * ChannelFloodProtection *fld; MemberFlood *memberflood; uint64_t msghash; - unsigned char is_flooding_text=0, is_flooding_repeat=0; + unsigned char is_flooding_text = 0, is_flooding_repeat = 0; static char errbuf[256]; /* This is redundant, right? */ @@ -1397,7 +1396,7 @@ int floodprot_can_send_to_channel(Client *client, Channel *channel, Membership * if (sendtype == SEND_TYPE_TAGMSG) return 0; // TODO: some TAGMSG specific limit? (1 of 2) - if (ValidatePermissionsForPath("channel:override:flood",client,NULL,channel,NULL) || !IsFloodLimit(channel) || check_channel_access(client, channel, "hoaq")) + if (ValidatePermissionsForPath("channel:override:flood", client, NULL, channel, NULL) || !IsFloodLimit(channel) || check_channel_access(client, channel, "hoaq")) return HOOK_CONTINUE; #ifdef TESTSUITE @@ -1508,7 +1507,8 @@ int floodprot_can_send_to_channel(Client *client, Channel *channel, Membership * snprintf(mask, sizeof(mask), "~time:%d:*!*@%s", fld->remove_after[flood_type], GetHost(client)); else snprintf(mask, sizeof(mask), "~t:%d:*!*@%s", fld->remove_after[flood_type], GetHost(client)); - } else { + } else + { snprintf(mask, sizeof(mask), "*!*@%s", GetHost(client)); } if (add_listmode(&channel->banlist, &me, channel, mask) == 1) @@ -1517,7 +1517,7 @@ int floodprot_can_send_to_channel(Client *client, Channel *channel, Membership * new_message(&me, NULL, &mtags); sendto_server(NULL, 0, 0, mtags, ":%s MODE %s +b %s 0", me.id, channel->name, mask); sendto_channel(channel, &me, NULL, 0, 0, SEND_LOCAL, mtags, - ":%s MODE %s +b %s", me.name, channel->name, mask); + ":%s MODE %s +b %s", me.name, channel->name, mask); free_message_tags(mtags); } /* else.. ban list is full or already exists */ } @@ -1546,7 +1546,7 @@ int floodprot_post_chanmsg(Client *client, Channel *channel, int sendflags, cons do_floodprot(channel, client, CHFLD_MSG); - if ((text[0] == '\001') && strncmp(text+1, "ACTION ", 7)) + if ((text[0] == '\001') && strncmp(text + 1, "ACTION ", 7)) do_floodprot(channel, client, CHFLD_CTCP); return 0; @@ -1585,7 +1585,7 @@ int floodprot_nickchange(Client *client, MessageTag *mtags, const char *oldnick) void floodprot_chanmode_del_helper(ChannelFloodProtection *fld, char modechar) { /* reset joinflood on -i, reset msgflood on -m, etc.. */ - switch(modechar) + switch (modechar) { case 'C': fld->counter[CHFLD_CTCP] = 0; @@ -1652,7 +1652,7 @@ RemoveChannelModeTimer *floodprottimer_find(Channel *channel, char mflag) { RemoveChannelModeTimer *e; - for (e=removechannelmodetimer_list; e; e=e->next) + for (e = removechannelmodetimer_list; e; e = e->next) { if ((e->channel == channel) && (e->m == mflag)) return e; @@ -1663,7 +1663,8 @@ RemoveChannelModeTimer *floodprottimer_find(Channel *channel, char mflag) /** strcat-like */ void strccat(char *s, char c) { - for (; *s; s++); + for (; *s; s++) + ; *s++ = c; *s++ = '\0'; } @@ -1683,7 +1684,7 @@ void strccat(char *s, char c) void floodprottimer_add(Channel *channel, ChannelFloodProtection *fld, char mflag, time_t when) { RemoveChannelModeTimer *e = NULL; - unsigned char add=1; + unsigned char add = 1; if (strchr(fld->timers_running, mflag)) { @@ -1695,7 +1696,7 @@ void floodprottimer_add(Channel *channel, ChannelFloodProtection *fld, char mfla if (!strchr(fld->timers_running, mflag)) { - if (strlen(fld->timers_running)+1 >= sizeof(fld->timers_running)) + if (strlen(fld->timers_running) + 1 >= sizeof(fld->timers_running)) { unreal_log(ULOG_WARNING, "flood", "BUG_FLOODPROTTIMER_ADD", NULL, "[BUG] floodprottimer_add: too many timers running for $channel ($timers_running)", @@ -1731,15 +1732,15 @@ void floodprottimer_del(Channel *channel, ChannelFloodProtection *fld, char mfla safe_free(e); if (fld) - { - char newtf[MAXCHMODEFACTIONS+1]; - char *i, *o; - for (i=fld->timers_running, o=newtf; *i; i++) - if (*i != mflag) - *o++ = *i; - *o = '\0'; - strcpy(fld->timers_running, newtf); /* always shorter (or equal) */ - } + { + char newtf[MAXCHMODEFACTIONS + 1]; + char *i, *o; + for (i = fld->timers_running, o = newtf; *i; i++) + if (*i != mflag) + *o++ = *i; + *o = '\0'; + strcpy(fld->timers_running, newtf); /* always shorter (or equal) */ + } } EVENT(modef_event) @@ -1850,8 +1851,8 @@ void do_floodprot_action_standard(Channel *channel, int what, FloodType *floodty text, fld->limit[what], fld->per, m, channel->name); ircsnprintf(target, sizeof(target), "%%%s", channel->name); sendto_channel(channel, &me, NULL, "ho", - 0, SEND_ALL, mtags, - ":%s NOTICE %s :%s", me.name, target, comment); + 0, SEND_ALL, mtags, + ":%s NOTICE %s :%s", me.name, target, comment); free_message_tags(mtags); /* Then the MODE broadcast */ @@ -1897,11 +1898,11 @@ int do_floodprot_action_alternative(Channel *channel, int what, FloodType *flood ircsnprintf(comment, sizeof(comment), "*** Channel %s detected (limit is %d per %d seconds), " "mostly caused by 'unknown-users', setting mode +b %s", - text, fld->limit[what], fld->per, ban); + text, fld->limit[what], fld->per, ban); ircsnprintf(target, sizeof(target), "%%%s", channel->name); sendto_channel(channel, &me, NULL, "ho", - 0, SEND_ALL, mtags, - ":%s NOTICE %s :%s", me.name, target, comment); + 0, SEND_ALL, mtags, + ":%s NOTICE %s :%s", me.name, target, comment); free_message_tags(mtags); /* Then the MODE broadcast */ @@ -1956,7 +1957,7 @@ void do_floodprot_action(Channel *channel, int what) if (!ban_exists) { /* Calculate the percentage of unknown-users that is responsible for the action trigger */ - perc = ((double)fld->counter_unknown_users[what] / (double)fld->counter[what])*100; + perc = ((double)fld->counter_unknown_users[what] / (double)fld->counter[what]) * 100; if (perc >= cfg.modef_alternate_action_percentage_threshold) { /* ACTION: We need to add the ban (+b) */ @@ -2132,7 +2133,7 @@ void floodprot_free_removechannelmodetimer_list(ModData *m) { RemoveChannelModeTimer *e, *e_next; - for (e=removechannelmodetimer_list; e; e=e_next) + for (e = removechannelmodetimer_list; e; e = e_next) { e_next = e->next; safe_free(e); @@ -2166,19 +2167,18 @@ CMD_OVERRIDE_FUNC(floodprot_override_mode) if (!advanced && !profile) { sendnotice(client, "No channel mode +f/+F is active on %s", channel->name); - } else - if (advanced && !profile) + } else if (advanced && !profile) { channel_modef_string(advanced, buf); sendnotice(client, "Channel '%s' has effective flood setting '%s' (custom settings via +f)", channel->name, buf); - } else - if (profile && !advanced) + } else if (profile && !advanced) { channel_modef_string(profile, buf); sendnotice(client, "Channel '%s' has effective flood setting '%s' (flood profile '%s')", channel->name, buf, profile->profile); - } else { + } else + { /* Both +f and +F are set */ int v; ChannelFloodProtection mix; @@ -2186,9 +2186,9 @@ CMD_OVERRIDE_FUNC(floodprot_override_mode) char overridden[64]; *overridden = '\0'; memcpy(&mix, profile, sizeof(mix)); - for (v=0; v < NUMFLD; v++) + for (v = 0; v < NUMFLD; v++) { - if ((advanced->limit[v]>0) && (mix.limit[v]>0)) + if ((advanced->limit[v] > 0) && (mix.limit[v] > 0)) { mix.limit[v] = 0; mix.action[v] = 0; @@ -2201,11 +2201,12 @@ CMD_OVERRIDE_FUNC(floodprot_override_mode) if (*overridden) { sendnotice(client, "Channel '%s' uses flood profile '%s', without action(s) '%s' as they are overridden by +f.", - channel->name, profile->profile, overridden); + channel->name, profile->profile, overridden); sendnotice(client, "Effective flood setting via +F: '%s'", buf); - } else { + } else + { sendnotice(client, "Channel '%s' has effective flood setting '%s' (flood profile '%s')", - channel->name, buf, profile->profile); + channel->name, buf, profile->profile); } channel_modef_string(advanced, buf); sendnotice(client, "Plus flood setting via +f: '%s'", buf); @@ -2238,7 +2239,7 @@ void reapply_profiles(void) { Channel *channel; - for (channel = channels; channel; channel=channel->nextch) + for (channel = channels; channel; channel = channel->nextch) { ChannelFloodProtection *fld = GETPARASTRUCT(channel, 'F'); ChannelFloodProtection *base; @@ -2260,7 +2261,8 @@ void reapply_profiles(void) if (!fld) { cmodef_channel_create(channel); - } else { + } else + { base = get_channel_flood_profile(cfg.default_profile); if (base) { @@ -2268,7 +2270,8 @@ void reapply_profiles(void) safe_strdup(fld->profile, cfg.default_profile); } } - } else { + } else + { if (fld) { /* Not +F, previously we had a default profile diff --git a/src/modules/chanmodes/halfop.c b/src/modules/chanmodes/halfop.c index a7e6b6fe6..b8adb2ad0 100644 --- a/src/modules/chanmodes/halfop.c +++ b/src/modules/chanmodes/halfop.c @@ -19,14 +19,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/halfop", - "6.0", - "Channel Mode +h", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/halfop", + "6.0", + "Channel Mode +h", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int cmode_halfop_is_ok(Client *client, Channel *channel, char mode, const char *para, int type, int what); diff --git a/src/modules/chanmodes/history.c b/src/modules/chanmodes/history.c index 5f9bbca17..b1811eab0 100644 --- a/src/modules/chanmodes/history.c +++ b/src/modules/chanmodes/history.c @@ -5,14 +5,13 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/history", - "1.0", - "Channel Mode +H", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/history", + "1.0", + "Channel Mode +H", + "UnrealIRCd Team", + "unrealircd-6", +}; typedef struct ConfigHistoryExt ConfigHistoryExt; struct ConfigHistoryExt { @@ -40,7 +39,7 @@ static cfgstruct test; /* Externally looked up */ long CAP_CHATHISTORY_DRAFT = 0; -#define HistoryEnabled(channel) (channel->mode.mode & EXTMODE_HISTORY) +#define HistoryEnabled(channel) (channel->mode.mode & EXTMODE_HISTORY) /* Forward declarations */ static void init_config(cfgstruct *cfg); @@ -125,17 +124,17 @@ static void init_config(cfgstruct *cfg) cfg->playback_on_join.lines = 15; cfg->playback_on_join.time = 86400; cfg->max_storage_per_channel_unregistered.lines = 200; - cfg->max_storage_per_channel_unregistered.time = 86400*31; + cfg->max_storage_per_channel_unregistered.time = 86400 * 31; cfg->max_storage_per_channel_registered.lines = 5000; - cfg->max_storage_per_channel_registered.time = 86400*31; + cfg->max_storage_per_channel_registered.time = 86400 * 31; } int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { int errors = 0; ConfigEntry *cep, *cepp, *cep4, *cep5; - int on_join_lines=0, maximum_storage_lines_registered=0, maximum_storage_lines_unregistered=0; - long on_join_time=0L, maximum_storage_time_registered=0L, maximum_storage_time_unregistered=0L; + int on_join_lines = 0, maximum_storage_lines_registered = 0, maximum_storage_lines_unregistered = 0; + long on_join_time = 0L, maximum_storage_time_registered = 0L, maximum_storage_time_unregistered = 0L; /* We only care about set::history */ if ((type != CONFIG_SET) || strcmp(ce->name, "history")) @@ -165,8 +164,7 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) continue; } test.playback_on_join.lines = v; - } else - if (!strcmp(cep4->name, "time")) + } else if (!strcmp(cep4->name, "time")) { long v; CheckNull(cep4); @@ -182,12 +180,11 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } else { config_error_unknown(cep4->file->filename, - cep4->line_number, "set::history::channel::playback-on-join", cep4->name); + cep4->line_number, "set::history::channel::playback-on-join", cep4->name); errors++; } } - } else - if (!strcmp(cepp->name, "max-storage-per-channel")) + } else if (!strcmp(cepp->name, "max-storage-per-channel")) { for (cep4 = cepp->items; cep4; cep4 = cep4->next) { @@ -203,13 +200,12 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (v < 1) { config_error("%s:%i: set::history::channel::max-storage-per-channel::registered::lines must be a positive number.", - cep5->file->filename, cep5->line_number); + cep5->file->filename, cep5->line_number); errors++; continue; } test.max_storage_per_channel_registered.lines = v; - } else - if (!strcmp(cep5->name, "time")) + } else if (!strcmp(cep5->name, "time")) { long v; CheckNull(cep5); @@ -217,7 +213,7 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (v < 1) { config_error("%s:%i: set::history::channel::max-storage-per-channel::registered::time must be a positive number.", - cep5->file->filename, cep5->line_number); + cep5->file->filename, cep5->line_number); errors++; continue; } @@ -225,12 +221,11 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } else { config_error_unknown(cep5->file->filename, - cep5->line_number, "set::history::channel::max-storage-per-channel::registered", cep5->name); + cep5->line_number, "set::history::channel::max-storage-per-channel::registered", cep5->name); errors++; } } - } else - if (!strcmp(cep4->name, "unregistered")) + } else if (!strcmp(cep4->name, "unregistered")) { for (cep5 = cep4->items; cep5; cep5 = cep5->next) { @@ -242,13 +237,12 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (v < 1) { config_error("%s:%i: set::history::channel::max-storage-per-channel::unregistered::lines must be a positive number.", - cep5->file->filename, cep5->line_number); + cep5->file->filename, cep5->line_number); errors++; continue; } test.max_storage_per_channel_unregistered.lines = v; - } else - if (!strcmp(cep5->name, "time")) + } else if (!strcmp(cep5->name, "time")) { long v; CheckNull(cep5); @@ -256,7 +250,7 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (v < 1) { config_error("%s:%i: set::history::channel::max-storage-per-channel::unregistered::time must be a positive number.", - cep5->file->filename, cep5->line_number); + cep5->file->filename, cep5->line_number); errors++; continue; } @@ -264,14 +258,14 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } else { config_error_unknown(cep5->file->filename, - cep5->line_number, "set::history::channel::max-storage-per-channel::unregistered", cep5->name); + cep5->line_number, "set::history::channel::max-storage-per-channel::unregistered", cep5->name); errors++; } } } else { config_error_unknown(cep->file->filename, - cep->line_number, "set::history::max-storage-per-channel", cep->name); + cep->line_number, "set::history::max-storage-per-channel", cep->name); errors++; } } @@ -283,8 +277,7 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) for (h = Hooks[HOOKTYPE_CONFIGTEST]; h; h = h->next) { int value, errs = 0; - if (h->owner && !(h->owner->flags & MODFLAG_TESTING) - && !(h->owner->options & MOD_OPT_PERM)) + if (h->owner && !(h->owner->flags & MODFLAG_TESTING) && !(h->owner->options & MOD_OPT_PERM)) continue; value = (*(h->func.intfunc))(cf, cepp, CONFIG_SET_HISTORY_CHANNEL, &errs); if (value == 2) @@ -309,14 +302,15 @@ int history_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!used) { config_error_unknown(cepp->file->filename, - cepp->line_number, "set::history::channel", cepp->name); + cepp->line_number, "set::history::channel", cepp->name); errors++; } } } - } else { + } else + { config_error_unknown(cep->file->filename, - cep->line_number, "set::history", cep->name); + cep->line_number, "set::history", cep->name); errors++; } } @@ -357,14 +351,12 @@ int history_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep4->name, "lines")) { cfg.playback_on_join.lines = atoi(cep4->value); - } else - if (!strcmp(cep4->name, "time")) + } else if (!strcmp(cep4->name, "time")) { cfg.playback_on_join.time = config_checkval(cep4->value, CFG_TIME); } } - } else - if (!strcmp(cepp->name, "max-storage-per-channel")) + } else if (!strcmp(cepp->name, "max-storage-per-channel")) { for (cep4 = cepp->items; cep4; cep4 = cep4->next) { @@ -375,22 +367,19 @@ int history_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep5->name, "lines")) { cfg.max_storage_per_channel_registered.lines = atoi(cep5->value); - } else - if (!strcmp(cep5->name, "time")) + } else if (!strcmp(cep5->name, "time")) { cfg.max_storage_per_channel_registered.time = config_checkval(cep5->value, CFG_TIME); } } - } else - if (!strcmp(cep4->name, "unregistered")) + } else if (!strcmp(cep4->name, "unregistered")) { for (cep5 = cep4->items; cep5; cep5 = cep5->next) { if (!strcmp(cep5->name, "lines")) { cfg.max_storage_per_channel_unregistered.lines = atoi(cep5->value); - } else - if (!strcmp(cep5->name, "time")) + } else if (!strcmp(cep5->name, "time")) { cfg.max_storage_per_channel_unregistered.time = config_checkval(cep5->value, CFG_TIME); } @@ -441,7 +430,7 @@ int history_parse_chanmode(Channel *channel, const char *param, int *lines, long /* Parse time value */ /* If it is all digits then it is in minutes */ - for (q=p; *q; q++) + for (q = p; *q; q++) { if (!isdigit(*q)) { @@ -469,7 +458,8 @@ int history_parse_chanmode(Channel *channel, const char *param, int *lines, long if (*t > cfg.max_storage_per_channel_registered.time) *t = cfg.max_storage_per_channel_registered.time; - } else { + } else + { if (*lines > cfg.max_storage_per_channel_unregistered.lines) *lines = cfg.max_storage_per_channel_unregistered.lines; @@ -492,8 +482,7 @@ int history_chanmode_is_ok(Client *client, Channel *channel, char mode, const ch if (type == EXCHK_ACCESS_ERR) /* can only be due to being halfop */ sendnumeric(client, ERR_NOTFORHALFOPS, 'H'); return EX_DENY; - } else - if (type == EXCHK_PARAM) + } else if (type == EXCHK_PARAM) { int lines = 0; long t = 0L; @@ -518,8 +507,7 @@ static void history_chanmode_helper(char *buf, size_t bufsize, int lines, long t { /* Can be represented in full days, eg "1d" */ snprintf(buf, bufsize, "%d:%ldd", lines, t / 86400); - } else - if ((t % 3600) == 0) + } else if ((t % 3600) == 0) { /* Can be represented in hours, eg "8h" */ snprintf(buf, bufsize, "%d:%ldh", lines, t / 3600); @@ -659,7 +647,7 @@ int history_chanmsg(Client *client, Channel *channel, int sendflags, const char return 0; /* Filter out CTCP / CTCP REPLY */ - if ((*text == '\001') && strncmp(text+1, "ACTION", 6)) + if ((*text == '\001') && strncmp(text + 1, "ACTION", 6)) return 0; /* Filter out TAGMSG */ @@ -678,10 +666,10 @@ int history_chanmsg(Client *client, Channel *channel, int sendflags, const char strlcpy(source, client->name, sizeof(source)); snprintf(buf, sizeof(buf), ":%s %s %s :%s", - source, - sendtype_to_cmd(sendtype), - channel->name, - text); + source, + sendtype_to_cmd(sendtype), + channel->name, + text); history_add(channel->name, mtags, buf); @@ -704,7 +692,7 @@ int history_chanmsg_multiline(Client *client, Channel *channel, int sendflags, c return 0; /* Filter out CTCP (except ACTION) based on first line */ - if (lines && lines->text && (*lines->text == '\001') && strncmp(lines->text+1, "ACTION", 6)) + if (lines && lines->text && (*lines->text == '\001') && strncmp(lines->text + 1, "ACTION", 6)) return 0; if (IsUser(client)) @@ -820,11 +808,11 @@ CMD_OVERRIDE_FUNC(override_mode) new_message(&me, NULL, &mtags); sendto_channel(channel, &me, &me, 0, 0, SEND_LOCAL, mtags, - ":%s MODE %s %s %s", - me.name, channel->name, modebuf, parabuf); + ":%s MODE %s %s %s", + me.name, channel->name, modebuf, parabuf); sendto_server(NULL, 0, 0, mtags, ":%s MODE %s %s %s %lld", - me.id, channel->name, modebuf, parabuf, - (long long)channel->creationtime); + me.id, channel->name, modebuf, parabuf, + (long long)channel->creationtime); /* Activate this hook just like cmd_mode.c */ RunHook(HOOKTYPE_REMOTE_CHANMODE, &me, channel, mtags, modebuf, parabuf, 0, 0, &destroy_channel); diff --git a/src/modules/chanmodes/inviteonly.c b/src/modules/chanmodes/inviteonly.c index d7548f93e..1ff7af735 100644 --- a/src/modules/chanmodes/inviteonly.c +++ b/src/modules/chanmodes/inviteonly.c @@ -20,18 +20,17 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/inviteonly", - "6.0", - "Channel Mode +i", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/inviteonly", + "6.0", + "Channel Mode +i", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_INVITE_ONLY; -#define IsInviteOnly(channel) (channel->mode.mode & EXTCMODE_INVITE_ONLY) +#define IsInviteOnly(channel) (channel->mode.mode & EXTCMODE_INVITE_ONLY) int inviteonly_can_join(Client *client, Channel *channel, const char *key, char **errmsg); @@ -62,7 +61,7 @@ MOD_UNLOAD() return MOD_SUCCESS; } -int inviteonly_can_join (Client *client, Channel *channel, const char *key, char **errmsg) +int inviteonly_can_join(Client *client, Channel *channel, const char *key, char **errmsg) { if (IsInviteOnly(channel)) { diff --git a/src/modules/chanmodes/isregistered.c b/src/modules/chanmodes/isregistered.c index 4d8675fa9..0177bc7a8 100644 --- a/src/modules/chanmodes/isregistered.c +++ b/src/modules/chanmodes/isregistered.c @@ -20,18 +20,17 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/isregistered", - "6.0", - "Channel Mode +r", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/isregistered", + "6.0", + "Channel Mode +r", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_REGISTERED; -#define IsRegisteredChannel(channel) (channel->mode.mode & EXTCMODE_REGISTERED) +#define IsRegisteredChannel(channel) (channel->mode.mode & EXTCMODE_REGISTERED) int isregistered_chanmode_is_ok(Client *client, Channel *channel, char mode, const char *param, int type, int what); diff --git a/src/modules/chanmodes/issecure.c b/src/modules/chanmodes/issecure.c index 4e45d2cac..f6d8513b2 100644 --- a/src/modules/chanmodes/issecure.c +++ b/src/modules/chanmodes/issecure.c @@ -28,18 +28,17 @@ CMD_FUNC(issecure); -ModuleHeader MOD_HEADER - = { - "chanmodes/issecure", - "4.2", - "Channel Mode +Z", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/issecure", + "4.2", + "Channel Mode +Z", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_ISSECURE; -#define IsSecureChanIndicated(channel) (channel->mode.mode & EXTCMODE_ISSECURE) +#define IsSecureChanIndicated(channel) (channel->mode.mode & EXTCMODE_ISSECURE) int IsSecureJoin(Channel *channel); int modeZ_is_ok(Client *client, Channel *channel, char mode, const char *para, int checkt, int what); @@ -48,8 +47,8 @@ int issecure_part(Client *client, Channel *channel, MessageTag *mtags, const cha int issecure_quit(Client *client, MessageTag *mtags, const char *comment); int issecure_kick(Client *client, Client *victim, Channel *channel, MessageTag *mtags, const char *comment); int issecure_chanmode(Client *client, Channel *channel, MessageTag *mtags, - const char *modebuf, const char *parabuf, time_t sendts, int samode, int *destroy_channel); - + const char *modebuf, const char *parabuf, time_t sendts, int samode, int *destroy_channel); + MOD_TEST() { @@ -58,7 +57,7 @@ MOD_TEST() MOD_INIT() { -CmodeInfo req; + CmodeInfo req; /* Channel mode */ memset(&req, 0, sizeof(req)); @@ -67,7 +66,7 @@ CmodeInfo req; req.letter = 'Z'; req.local = 1; /* local channel mode */ CmodeAdd(modinfo->handle, req, &EXTCMODE_ISSECURE); - + HookAdd(modinfo->handle, HOOKTYPE_LOCAL_JOIN, 0, issecure_join); HookAdd(modinfo->handle, HOOKTYPE_REMOTE_JOIN, 0, issecure_join); HookAdd(modinfo->handle, HOOKTYPE_LOCAL_PART, 0, issecure_part); @@ -78,7 +77,7 @@ CmodeInfo req; HookAdd(modinfo->handle, HOOKTYPE_REMOTE_KICK, 0, issecure_kick); HookAdd(modinfo->handle, HOOKTYPE_LOCAL_CHANMODE, 0, issecure_chanmode); HookAdd(modinfo->handle, HOOKTYPE_REMOTE_CHANMODE, 0, issecure_chanmode); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -116,7 +115,7 @@ int modeZ_is_ok(Client *client, Channel *channel, char mode, const char *para, i int channel_has_insecure_users_butone(Channel *channel, Client *skip) { -Member *member; + Member *member; for (member = channel->members; member; member = member->next) { @@ -149,7 +148,7 @@ void issecure_unset(Channel *channel, Client *client, MessageTag *recv_mtags, in me.name, channel->name, client->name); free_message_tags(mtags); } - + channel->mode.mode &= ~EXTCMODE_ISSECURE; mtags = NULL; new_message_special(&me, recv_mtags, &mtags, "MODE %s -Z", channel->name); @@ -224,14 +223,14 @@ int issecure_part(Client *client, Channel *channel, MessageTag *mtags, const cha int issecure_quit(Client *client, MessageTag *mtags, const char *comment) { -Membership *membership; -Channel *channel; + Membership *membership; + Channel *channel; - for (membership = client->user->channel; membership; membership=membership->next) + for (membership = client->user->channel; membership; membership = membership->next) { channel = membership->channel; /* Identical to part */ - if (IsSecureJoin(channel) && !IsSecureChanIndicated(channel) && + if (IsSecureJoin(channel) && !IsSecureChanIndicated(channel) && !IsSecureConnect(client) && !channel_has_insecure_users_butone(channel, client)) issecure_set(channel, client, mtags, 1); } @@ -248,7 +247,7 @@ int issecure_kick(Client *client, Client *victim, Channel *channel, MessageTag * } int issecure_chanmode(Client *client, Channel *channel, MessageTag *mtags, - const char *modebuf, const char *parabuf, time_t sendts, int samode, int *destroy_channel) + const char *modebuf, const char *parabuf, time_t sendts, int samode, int *destroy_channel) { if (!strchr(modebuf, 'z')) return 0; /* don't care */ @@ -264,12 +263,14 @@ int issecure_chanmode(Client *client, Channel *channel, MessageTag *mtags, /* Should be -Z, if not already */ if (IsSecureChanIndicated(channel)) issecure_unset(channel, NULL, mtags, 0); /* would be odd if we got here ;) */ - } else { + } else + { /* Should be +Z, but check if it isn't already.. */ if (!IsSecureChanIndicated(channel)) issecure_set(channel, NULL, mtags, 0); } - } else { + } else + { /* there was a -z, check if the channel is currently +Z and if so, set it -Z */ if (IsSecureChanIndicated(channel)) issecure_unset(channel, NULL, mtags, 0); diff --git a/src/modules/chanmodes/key.c b/src/modules/chanmodes/key.c index 030a2140f..d14b827fb 100644 --- a/src/modules/chanmodes/key.c +++ b/src/modules/chanmodes/key.c @@ -19,25 +19,24 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/key", - "6.0", - "Channel Mode +k", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/key", + "6.0", + "Channel Mode +k", + "UnrealIRCd Team", + "unrealircd-6", +}; typedef struct ChannelKey ChannelKey; struct ChannelKey { - char key[KEYLEN+1]; + char key[KEYLEN + 1]; }; /* Global variables */ ModDataInfo *mdkey = NULL; Cmode_t EXTMODE_KEY = 0L; -#define IsKey(x) ((x)->mode.mode & EXTMODE_KEY) +#define IsKey(x) ((x)->mode.mode & EXTMODE_KEY) /* Forward declarations */ int key_can_join(Client *client, Channel *channel, const char *key, char **errmsg); @@ -110,13 +109,12 @@ int cmode_key_is_ok(Client *client, Channel *channel, char mode, const char *par if (IsUser(client) && check_channel_access(client, channel, "hoaq")) return EX_ALLOW; return EX_DENY; - } else - if (type == EXCHK_PARAM) + } else if (type == EXCHK_PARAM) { if (!is_valid_key(param)) { sendnumeric(client, ERR_INVALIDMODEPARAM, - channel->name, 'k', "*", "Channel key contains forbidden characters or is too long"); + channel->name, 'k', "*", "Channel key contains forbidden characters or is too long"); return EX_DENY; } return EX_ALLOW; @@ -141,7 +139,7 @@ void *cmode_key_put_param(void *k_in, const char *param) const char *cmode_key_get_param(void *r_in) { ChannelKey *r = (ChannelKey *)r_in; - static char retbuf[KEYLEN+1]; + static char retbuf[KEYLEN + 1]; if (!r) return NULL; @@ -152,7 +150,7 @@ const char *cmode_key_get_param(void *r_in) const char *cmode_key_conv_param(const char *param, Client *client, Channel *channel) { - static char retbuf[KEYLEN+1]; + static char retbuf[KEYLEN + 1]; transform_channel_key(param, retbuf, sizeof(retbuf)); diff --git a/src/modules/chanmodes/limit.c b/src/modules/chanmodes/limit.c index 253e01f73..26bd2e74e 100644 --- a/src/modules/chanmodes/limit.c +++ b/src/modules/chanmodes/limit.c @@ -19,14 +19,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/limit", - "6.0", - "Channel Mode +l", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/limit", + "6.0", + "Channel Mode +l", + "UnrealIRCd Team", + "unrealircd-6", +}; typedef struct ChannelLimit ChannelLimit; struct ChannelLimit { @@ -37,10 +36,10 @@ struct ChannelLimit { ModDataInfo *mdlimit = NULL; Cmode_t EXTMODE_LIMIT = 0L; -#define IsLimit(x) ((x)->mode.mode & EXTMODE_LIMIT) +#define IsLimit(x) ((x)->mode.mode & EXTMODE_LIMIT) /* Just for buffers, nothing else */ -#define LIMITLEN 32 +#define LIMITLEN 32 /* Forward declarations */ int limit_can_join(Client *client, Channel *channel, const char *key, char **errmsg); @@ -95,9 +94,9 @@ int limit_can_join(Client *client, Channel *channel, const char *key, char **err if (r && r->limit && (channel->users >= r->limit)) { Hook *h; - for (h = Hooks[HOOKTYPE_CAN_JOIN_LIMITEXCEEDED]; h; h = h->next) + for (h = Hooks[HOOKTYPE_CAN_JOIN_LIMITEXCEEDED]; h; h = h->next) { - int i = (*(h->func.intfunc))(client,channel,key,errmsg); + int i = (*(h->func.intfunc))(client, channel, key, errmsg); if (i != 0) return i; } @@ -116,14 +115,13 @@ int cmode_limit_is_ok(Client *client, Channel *channel, char mode, const char *p if (IsUser(client) && check_channel_access(client, channel, "hoaq")) return EX_ALLOW; return EX_DENY; - } else - if (type == EXCHK_PARAM) + } else if (type == EXCHK_PARAM) { /* When coming from an IRC client, we reject limit <=0 explicitly, as it makes no sense */ if (atoi(param) <= 0) { sendnumeric(client, ERR_INVALIDMODEPARAM, - channel->name, 'l', "*", "Channel limit (+l) needs to be a positive number"); + channel->name, 'l', "*", "Channel limit (+l) needs to be a positive number"); return EX_DENY; } /* Any other value is valid, we just morph it */ diff --git a/src/modules/chanmodes/link.c b/src/modules/chanmodes/link.c index c55a6f164..2f6db083c 100644 --- a/src/modules/chanmodes/link.c +++ b/src/modules/chanmodes/link.c @@ -22,11 +22,11 @@ #define MAX_EB_LEN 128 // Max extban length ModuleHeader MOD_HEADER = { - "chanmodes/link", - "5.0", - "Channel Mode +L", - "UnrealIRCd Team", - "unrealircd-6", + "chanmodes/link", + "5.0", + "Channel Mode +L", + "UnrealIRCd Team", + "unrealircd-6", }; Cmode_t EXTMODE_LINK = 0L; @@ -115,8 +115,7 @@ int cmodeL_is_ok(Client *client, Channel *channel, char mode, const char *para, if (type == EXCHK_ACCESS_ERR) /* can only be due to being halfop */ sendnumeric(client, ERR_NOTFORHALFOPS, 'L'); return EX_DENY; - } else - if (type == EXCHK_PARAM) + } else if (type == EXCHK_PARAM) { /* Check parameter.. syntax is +L #channel */ if (strchr(para, ',')) @@ -132,7 +131,7 @@ int cmodeL_is_ok(Client *client, Channel *channel, char mode, const char *para, { if (MyUser(client)) sendnumeric(client, ERR_CANNOTCHANGECHANMODE, 'L', - "a channel cannot be linked to itself"); + "a channel cannot be linked to itself"); return EX_DENY; } return EX_ALLOW; @@ -158,7 +157,7 @@ void *cmodeL_put_param(void *r_in, const char *param) const char *cmodeL_get_param(void *r_in) { aModeLEntry *r = (aModeLEntry *)r_in; - static char retbuf[CHANNELLEN+1]; + static char retbuf[CHANNELLEN + 1]; if (!r) return NULL; @@ -284,7 +283,7 @@ const char *extban_link_conv_param(BanContext *b, Extban *extban) int link_doforward(Client *client, Channel *channel, const char *linked, linkType type) { - char linked_channel_buffer[CHANNELLEN+1]; + char linked_channel_buffer[CHANNELLEN + 1]; char desc[64]; const char *parv[3]; @@ -368,12 +367,10 @@ int link_pre_localjoin_cb(Client *client, Channel *channel, const char *key) if (!strncmp(ban->banstr, "~f:", 3)) { strlcpy(bantmp, ban->banstr + 3, sizeof(bantmp)); - } else - if (!strncmp(ban->banstr, "~forward:", 9)) + } else if (!strncmp(ban->banstr, "~forward:", 9)) { strlcpy(bantmp, ban->banstr + 9, sizeof(bantmp)); - } else - if (!strncmp(ban->banstr, "~t:", 3)) + } else if (!strncmp(ban->banstr, "~t:", 3)) { /* A timed ban, but is it for us? Need to parse a little: * ~t:dddd:~f:... @@ -382,16 +379,15 @@ int link_pre_localjoin_cb(Client *client, Channel *channel, const char *key) if (p && !strncmp(p, ":~f:", 4)) { strlcpy(bantmp, p + 4, sizeof(bantmp)); - } else - if (p && !strncmp(p, ":~forward:", 10)) + } else if (p && !strncmp(p, ":~forward:", 10)) { strlcpy(bantmp, p + 10, sizeof(bantmp)); - } else { + } else + { /* Not for us - some other ~t ban */ continue; } - } else - if (!strncmp(ban->banstr, "~time:", 6)) + } else if (!strncmp(ban->banstr, "~time:", 6)) { /* A timed ban, but is it for us? Need to parse a little: * ~t:dddd:~f:... @@ -400,11 +396,11 @@ int link_pre_localjoin_cb(Client *client, Channel *channel, const char *key) if (p && !strncmp(p, ":~f:", 4)) { strlcpy(bantmp, p + 4, sizeof(bantmp)); - } else - if (p && !strncmp(p, ":~forward:", 10)) + } else if (p && !strncmp(p, ":~forward:", 10)) { strlcpy(bantmp, p + 10, sizeof(bantmp)); - } else { + } else + { /* Not for us - some other ~t ban */ continue; } @@ -439,7 +435,8 @@ int link_pre_localjoin_cb(Client *client, Channel *channel, const char *key) /* A ~forward ban matched, go for it.. */ safe_free(b); return link_doforward(client, channel, banchan, LINKTYPE_BAN); - } else { + } else + { /* Break the outer loop as well: the user is exempt, * so it makes no sense to check other bans anymore. * no "safe_free(b);" here because that is taken @@ -474,7 +471,8 @@ int link_pre_localjoin_cb(Client *client, Channel *channel, const char *key) return link_doforward(client, channel, linked, LINKTYPE_REG); // For a couple of conditions we can use the return value from can_join() =] - switch(canjoin) { + switch (canjoin) + { // Any ban other than our own ~f: extban case ERR_BANNEDFROMCHAN: return link_doforward(client, channel, linked, LINKTYPE_BAN); diff --git a/src/modules/chanmodes/moderated.c b/src/modules/chanmodes/moderated.c index 28beda28e..94d8dd962 100644 --- a/src/modules/chanmodes/moderated.c +++ b/src/modules/chanmodes/moderated.c @@ -20,14 +20,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/moderated", - "6.0", - "Channel Mode +m", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/moderated", + "6.0", + "Channel Mode +m", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Global variables */ Cmode_t EXTCMODE_MODERATED; @@ -38,7 +37,7 @@ const char *moderated_pre_local_part(Client *client, Channel *channel, const cha int moderated_can_set_topic(Client *client, Channel *channel, const char *topic, const char **errmsg); /* Macros */ -#define IsModerated(channel) (channel->mode.mode & EXTCMODE_MODERATED) +#define IsModerated(channel) (channel->mode.mode & EXTCMODE_MODERATED) MOD_INIT() { @@ -72,7 +71,7 @@ MOD_UNLOAD() int moderated_can_send_to_channel(Client *client, Channel *channel, Membership *m, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx) { if (IsModerated(channel) && (!m || !check_channel_access_membership(m, "vhoaq")) && - !op_can_override("channel:override:message:moderated",client,channel,NULL)) + !op_can_override("channel:override:message:moderated", client, channel, NULL)) { Hook *h; for (h = Hooks[HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION]; h; h = h->next) @@ -101,7 +100,7 @@ const char *moderated_pre_local_part(Client *client, Channel *channel, const cha int moderated_can_set_topic(Client *client, Channel *channel, const char *topic, const char **errmsg) { - static char errmsg_buf[NICKLEN+256]; + static char errmsg_buf[NICKLEN + 256]; /* Channel is +m but user is not +vhoaq: reject the topic change */ if (has_channel_mode(channel, 'm') && !check_channel_access(client, channel, "vhoaq")) diff --git a/src/modules/chanmodes/nocolor.c b/src/modules/chanmodes/nocolor.c index e391ac06f..3289c88a9 100644 --- a/src/modules/chanmodes/nocolor.c +++ b/src/modules/chanmodes/nocolor.c @@ -21,18 +21,17 @@ CMD_FUNC(nocolor); -ModuleHeader MOD_HEADER - = { - "chanmodes/nocolor", - "4.2", - "Channel Mode +c", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/nocolor", + "4.2", + "Channel Mode +c", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_NOCOLOR; -#define IsNoColor(channel) (channel->mode.mode & EXTCMODE_NOCOLOR) +#define IsNoColor(channel) (channel->mode.mode & EXTCMODE_NOCOLOR) int nocolor_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx); const char *nocolor_prelocalpart(Client *client, Channel *channel, const char *comment); @@ -45,7 +44,7 @@ MOD_TEST() MOD_INIT() { -CmodeInfo req; + CmodeInfo req; /* Channel mode */ memset(&req, 0, sizeof(req)); @@ -53,12 +52,12 @@ CmodeInfo req; req.letter = 'c'; req.is_ok = extcmode_default_requirechop; CmodeAdd(modinfo->handle, req, &EXTCMODE_NOCOLOR); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 0, nocolor_can_send_to_channel); HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_PART, 0, nocolor_prelocalpart); HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_QUIT_CHAN, 0, nocolor_prelocalpart); HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_QUIT, 0, nocolor_prelocalquit); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -75,14 +74,14 @@ MOD_UNLOAD() static int IsUsingColor(const char *s) { - if (!s) - return 0; + if (!s) + return 0; - for (; *s; s++) - if (*s == 3 || *s == 27 || *s == 4 || *s == 22) /* mirc color, ansi, rgb, reverse */ - return 1; + for (; *s; s++) + if (*s == 3 || *s == 27 || *s == 4 || *s == 22) /* mirc color, ansi, rgb, reverse */ + return 1; - return 0; + return 0; } int nocolor_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx) diff --git a/src/modules/chanmodes/noctcp.c b/src/modules/chanmodes/noctcp.c index 5dad8cbc4..6c2d37da4 100644 --- a/src/modules/chanmodes/noctcp.c +++ b/src/modules/chanmodes/noctcp.c @@ -21,18 +21,17 @@ CMD_FUNC(noctcp); -ModuleHeader MOD_HEADER - = { - "chanmodes/noctcp", - "4.2", - "Channel Mode +C", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/noctcp", + "4.2", + "Channel Mode +C", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_NOCTCP; -#define IsNoCTCP(channel) (channel->mode.mode & EXTCMODE_NOCTCP) +#define IsNoCTCP(channel) (channel->mode.mode & EXTCMODE_NOCTCP) int noctcp_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx); @@ -43,16 +42,16 @@ MOD_TEST() MOD_INIT() { -CmodeInfo req; + CmodeInfo req; memset(&req, 0, sizeof(req)); req.paracount = 0; req.letter = 'C'; req.is_ok = extcmode_default_requirehalfop; CmodeAdd(modinfo->handle, req, &EXTCMODE_NOCTCP); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 0, noctcp_can_send_to_channel); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } diff --git a/src/modules/chanmodes/noexternalmsgs.c b/src/modules/chanmodes/noexternalmsgs.c index 2a612d182..37e2d389d 100644 --- a/src/modules/chanmodes/noexternalmsgs.c +++ b/src/modules/chanmodes/noexternalmsgs.c @@ -20,18 +20,17 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/noexternalmsgs", - "6.0", - "Channel Mode +n", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/noexternalmsgs", + "6.0", + "Channel Mode +n", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_NO_EXTERNAL_MESSAGES; -#define IsNoExternalMessages(channel) (channel->mode.mode & EXTCMODE_NO_EXTERNAL_MESSAGES) +#define IsNoExternalMessages(channel) (channel->mode.mode & EXTCMODE_NO_EXTERNAL_MESSAGES) int noexternalmsgs_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx); @@ -64,7 +63,7 @@ MOD_UNLOAD() int noexternalmsgs_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx) { - if (IsNoExternalMessages(channel) && !IsMember(client,channel)) + if (IsNoExternalMessages(channel) && !IsMember(client, channel)) { /* Channel does not accept external messages (+n). * Reject, unless HOOKTYPE_CAN_BYPASS_NO_EXTERNAL_MSGS tells otherwise. diff --git a/src/modules/chanmodes/noinvite.c b/src/modules/chanmodes/noinvite.c index 2d81825df..c8428fb3d 100644 --- a/src/modules/chanmodes/noinvite.c +++ b/src/modules/chanmodes/noinvite.c @@ -21,18 +21,17 @@ CMD_FUNC(noinvite); -ModuleHeader MOD_HEADER - = { - "chanmodes/noinvite", - "4.2", - "Channel Mode +V", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/noinvite", + "4.2", + "Channel Mode +V", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_NOINVITE; -#define IsNoInvite(channel) (channel->mode.mode & EXTCMODE_NOINVITE) +#define IsNoInvite(channel) (channel->mode.mode & EXTCMODE_NOINVITE) int noinvite_pre_knock(Client *client, Channel *channel, const char **reason); int noinvite_pre_invite(Client *client, Client *target, Channel *channel, int *override); @@ -51,10 +50,10 @@ MOD_INIT() req.letter = 'V'; req.is_ok = extcmode_default_requirechop; CmodeAdd(modinfo->handle, req, &EXTCMODE_NOINVITE); - + HookAdd(modinfo->handle, HOOKTYPE_PRE_KNOCK, 0, noinvite_pre_knock); HookAdd(modinfo->handle, HOOKTYPE_PRE_INVITE, 0, noinvite_pre_invite); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -86,10 +85,11 @@ int noinvite_pre_invite(Client *client, Client *target, Channel *channel, int *o { if (MyUser(client) && IsNoInvite(channel)) { - if (ValidatePermissionsForPath("channel:override:invite:noinvite",client,NULL,channel,NULL) && client == target) + if (ValidatePermissionsForPath("channel:override:invite:noinvite", client, NULL, channel, NULL) && client == target) { *override = 1; - } else { + } else + { sendnumeric(client, ERR_NOINVITE, channel->name); return HOOK_DENY; } diff --git a/src/modules/chanmodes/nokick.c b/src/modules/chanmodes/nokick.c index 56cb115ae..17ef78941 100644 --- a/src/modules/chanmodes/nokick.c +++ b/src/modules/chanmodes/nokick.c @@ -20,20 +20,19 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/nokick", - "4.2", - "Channel Mode +Q", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/nokick", + "4.2", + "Channel Mode +Q", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_NOKICK; -#define IsNoKick(channel) (channel->mode.mode & EXTCMODE_NOKICK) +#define IsNoKick(channel) (channel->mode.mode & EXTCMODE_NOKICK) -int nokick_check (Client *client, Client *target, Channel *channel, const char *comment, const char *client_member_modes, const char *target_member_modes, const char **reject_reason); +int nokick_check(Client *client, Client *target, Channel *channel, const char *comment, const char *client_member_modes, const char *target_member_modes, const char **reject_reason); MOD_TEST() { @@ -49,10 +48,10 @@ MOD_INIT() req.letter = 'Q'; req.is_ok = extcmode_default_requirechop; CmodeAdd(modinfo->handle, req, &EXTCMODE_NOKICK); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_KICK, 0, nokick_check); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -67,7 +66,7 @@ MOD_UNLOAD() return MOD_SUCCESS; } -int nokick_check (Client *client, Client *target, Channel *channel, const char *comment, const char *client_member_modes, const char *target_member_modes, const char **reject_reason) +int nokick_check(Client *client, Client *target, Channel *channel, const char *comment, const char *client_member_modes, const char *target_member_modes, const char **reject_reason) { static char errmsg[256]; @@ -82,4 +81,3 @@ int nokick_check (Client *client, Client *target, Channel *channel, const char * return EX_ALLOW; } - diff --git a/src/modules/chanmodes/noknock.c b/src/modules/chanmodes/noknock.c index ac5f1f6b6..82103f4a0 100644 --- a/src/modules/chanmodes/noknock.c +++ b/src/modules/chanmodes/noknock.c @@ -19,22 +19,21 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/noknock", - "4.2", - "Channel Mode +K", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/noknock", + "4.2", + "Channel Mode +K", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_NOKNOCK; -#define IsNoKnock(channel) (channel->mode.mode & EXTCMODE_NOKNOCK) +#define IsNoKnock(channel) (channel->mode.mode & EXTCMODE_NOKNOCK) int noknock_check_knock(Client *client, Channel *channel, const char **reason); int noknock_mode_allow(Client *client, Channel *channel, char mode, const char *para, int checkt, int what); -int noknock_mode_del (Channel *channel, int modeChar); +int noknock_mode_del(Channel *channel, int modeChar); MOD_TEST() { @@ -43,18 +42,18 @@ MOD_TEST() MOD_INIT() { -CmodeInfo req; + CmodeInfo req; memset(&req, 0, sizeof(req)); req.paracount = 0; req.letter = 'K'; req.is_ok = noknock_mode_allow; CmodeAdd(modinfo->handle, req, &EXTCMODE_NOKNOCK); - + HookAdd(modinfo->handle, HOOKTYPE_PRE_KNOCK, 0, noknock_check_knock); HookAdd(modinfo->handle, HOOKTYPE_MODECHAR_DEL, 0, noknock_mode_del); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -70,7 +69,7 @@ MOD_UNLOAD() } -int noknock_check_knock (Client *client, Channel *channel, const char **reason) +int noknock_check_knock(Client *client, Channel *channel, const char **reason) { if (MyUser(client) && IsNoKnock(channel)) { @@ -81,7 +80,7 @@ int noknock_check_knock (Client *client, Channel *channel, const char **reason) return HOOK_CONTINUE; } -int noknock_mode_del (Channel *channel, int modeChar) +int noknock_mode_del(Channel *channel, int modeChar) { // Remove noknock when we're removing invite only if (modeChar == 'i') diff --git a/src/modules/chanmodes/nonickchange.c b/src/modules/chanmodes/nonickchange.c index 88a411cb3..961abd40d 100644 --- a/src/modules/chanmodes/nonickchange.c +++ b/src/modules/chanmodes/nonickchange.c @@ -20,20 +20,19 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/nonickchange", - "4.2", - "Channel Mode +N", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/nonickchange", + "4.2", + "Channel Mode +N", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_NONICKCHANGE; -#define IsNoNickChange(channel) (channel->mode.mode & EXTCMODE_NONICKCHANGE) +#define IsNoNickChange(channel) (channel->mode.mode & EXTCMODE_NONICKCHANGE) -int nonickchange_check (Client *client, Channel *channel); +int nonickchange_check(Client *client, Channel *channel); MOD_TEST() { @@ -42,17 +41,17 @@ MOD_TEST() MOD_INIT() { -CmodeInfo req; + CmodeInfo req; memset(&req, 0, sizeof(req)); req.paracount = 0; req.letter = 'N'; req.is_ok = extcmode_default_requirehalfop; CmodeAdd(modinfo->handle, req, &EXTCMODE_NONICKCHANGE); - + HookAdd(modinfo->handle, HOOKTYPE_CHAN_PERMIT_NICK_CHANGE, 0, nonickchange_check); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -67,15 +66,12 @@ MOD_UNLOAD() return MOD_SUCCESS; } -int nonickchange_check (Client *client, Channel *channel) +int nonickchange_check(Client *client, Channel *channel) { - if (!IsOper(client) && !IsULine(client) - && IsNoNickChange(channel) - && !check_channel_access(client, channel, "oaq")) + if (!IsOper(client) && !IsULine(client) && IsNoNickChange(channel) && !check_channel_access(client, channel, "oaq")) { return HOOK_DENY; } return HOOK_ALLOW; } - diff --git a/src/modules/chanmodes/nonotice.c b/src/modules/chanmodes/nonotice.c index 00b94cf72..ed30d7c22 100644 --- a/src/modules/chanmodes/nonotice.c +++ b/src/modules/chanmodes/nonotice.c @@ -19,18 +19,17 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/nonotice", - "4.2", - "Channel Mode +T", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/nonotice", + "4.2", + "Channel Mode +T", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_NONOTICE; -#define IsNoNotice(channel) (channel->mode.mode & EXTCMODE_NONOTICE) +#define IsNoNotice(channel) (channel->mode.mode & EXTCMODE_NONOTICE) int nonotice_check_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx); @@ -48,7 +47,7 @@ MOD_INIT() req.letter = 'T'; req.is_ok = extcmode_default_requirechop; CmodeAdd(modinfo->handle, req, &EXTCMODE_NONOTICE); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 0, nonotice_check_can_send_to_channel); MARK_AS_OFFICIAL_MODULE(modinfo); diff --git a/src/modules/chanmodes/operonly.c b/src/modules/chanmodes/operonly.c index a140a8573..10bee3d72 100644 --- a/src/modules/chanmodes/operonly.c +++ b/src/modules/chanmodes/operonly.c @@ -21,14 +21,13 @@ CMD_FUNC(operonly); -ModuleHeader MOD_HEADER - = { - "chanmodes/operonly", - "4.2", - "Channel Mode +O", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/operonly", + "4.2", + "Channel Mode +O", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_OPERONLY; @@ -44,19 +43,19 @@ MOD_TEST() MOD_INIT() { -CmodeInfo req; + CmodeInfo req; memset(&req, 0, sizeof(req)); req.paracount = 0; req.letter = 'O'; req.is_ok = operonly_require_oper; CmodeAdd(modinfo->handle, req, &EXTCMODE_OPERONLY); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_JOIN, 0, operonly_can_join); HookAdd(modinfo->handle, HOOKTYPE_INVITE_BYPASS, 0, operonly_invite_bypass); HookAdd(modinfo->handle, HOOKTYPE_VIEW_TOPIC_OUTSIDE_CHANNEL, 0, operonly_view_topic_outside_channel); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -73,7 +72,7 @@ MOD_UNLOAD() int operonly_can_join(Client *client, Channel *channel, const char *key, char **errmsg) { - if ((channel->mode.mode & EXTCMODE_OPERONLY) && !ValidatePermissionsForPath("channel:operonly:join",client,NULL,channel,NULL)) + if ((channel->mode.mode & EXTCMODE_OPERONLY) && !ValidatePermissionsForPath("channel:operonly:join", client, NULL, channel, NULL)) { *errmsg = STR_ERR_OPERONLY; return ERR_OPERONLY; @@ -83,15 +82,15 @@ int operonly_can_join(Client *client, Channel *channel, const char *key, char ** int operonly_invite_bypass(Client *client, Channel *channel) { - if ((channel->mode.mode & EXTCMODE_OPERONLY) && !ValidatePermissionsForPath("channel:operonly:ban",client,NULL,NULL,NULL)) - return HOOK_DENY; + if ((channel->mode.mode & EXTCMODE_OPERONLY) && !ValidatePermissionsForPath("channel:operonly:ban", client, NULL, NULL, NULL)) + return HOOK_DENY; - return HOOK_CONTINUE; + return HOOK_CONTINUE; } int operonly_view_topic_outside_channel(Client *client, Channel *channel) { - if (channel->mode.mode & EXTCMODE_OPERONLY && !ValidatePermissionsForPath("channel:operonly:topic",client,NULL,channel,NULL)) + if (channel->mode.mode & EXTCMODE_OPERONLY && !ValidatePermissionsForPath("channel:operonly:topic", client, NULL, channel, NULL)) return HOOK_DENY; return HOOK_CONTINUE; @@ -99,7 +98,7 @@ int operonly_view_topic_outside_channel(Client *client, Channel *channel) int operonly_require_oper(Client *client, Channel *channel, char mode, const char *para, int checkt, int what) { - if (!MyUser(client) || ValidatePermissionsForPath("channel:operonly:set",client,NULL,channel,NULL)) + if (!MyUser(client) || ValidatePermissionsForPath("channel:operonly:set", client, NULL, channel, NULL)) return EX_ALLOW; if (checkt == EXCHK_ACCESS_ERR) @@ -107,4 +106,3 @@ int operonly_require_oper(Client *client, Channel *channel, char mode, const cha return EX_DENY; } - diff --git a/src/modules/chanmodes/permanent.c b/src/modules/chanmodes/permanent.c index e52c9f71e..e44b87292 100644 --- a/src/modules/chanmodes/permanent.c +++ b/src/modules/chanmodes/permanent.c @@ -19,14 +19,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/permanent", - "4.2", - "Permanent channel mode (+P)", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/permanent", + "4.2", + "Permanent channel mode (+P)", + "UnrealIRCd Team", + "unrealircd-6", +}; static Cmode_t EXTMODE_PERMANENT = 0L; @@ -34,7 +33,7 @@ static int permanent_channel_destroy(Channel *channel, int *should_destroy) { if (channel->mode.mode & EXTMODE_PERMANENT) *should_destroy = 0; - + return 0; } @@ -62,14 +61,14 @@ int permanent_chanmode(Client *client, Channel *channel, MessageTag *mtags, cons sub1_from_channel(channel); *destroy_channel = 1; } - + return 0; } /* This is called on module init, before Server Ready */ MOD_INIT() { -CmodeInfo req; + CmodeInfo req; MARK_AS_OFFICIAL_MODULE(modinfo); @@ -97,4 +96,3 @@ MOD_UNLOAD() { return MOD_SUCCESS; } - diff --git a/src/modules/chanmodes/private.c b/src/modules/chanmodes/private.c index d29205065..2017e117e 100644 --- a/src/modules/chanmodes/private.c +++ b/src/modules/chanmodes/private.c @@ -20,18 +20,17 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/private", - "6.0", - "Channel Mode +p", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/private", + "6.0", + "Channel Mode +p", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_PRIVATE; -#define IsPrivate(channel) (channel->mode.mode & EXTCMODE_PRIVATE) +#define IsPrivate(channel) (channel->mode.mode & EXTCMODE_PRIVATE) int private_modechar_add(Channel *channel, int modechar); diff --git a/src/modules/chanmodes/regonly.c b/src/modules/chanmodes/regonly.c index b35100c7e..a047591b2 100644 --- a/src/modules/chanmodes/regonly.c +++ b/src/modules/chanmodes/regonly.c @@ -20,18 +20,17 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/regonly", - "4.2", - "Channel Mode +R", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/regonly", + "4.2", + "Channel Mode +R", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_REGONLY; -#define IsRegOnly(channel) (channel->mode.mode & EXTCMODE_REGONLY) +#define IsRegOnly(channel) (channel->mode.mode & EXTCMODE_REGONLY) int regonly_check(Client *client, Channel *channel, const char *key, char **errmsg); @@ -43,17 +42,17 @@ MOD_TEST() MOD_INIT() { -CmodeInfo req; + CmodeInfo req; memset(&req, 0, sizeof(req)); req.paracount = 0; req.letter = 'R'; req.is_ok = extcmode_default_requirehalfop; CmodeAdd(modinfo->handle, req, &EXTCMODE_REGONLY); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_JOIN, 0, regonly_check); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -68,7 +67,7 @@ MOD_UNLOAD() return MOD_SUCCESS; } -int regonly_check (Client *client, Channel *channel, const char *key, char **errmsg) +int regonly_check(Client *client, Channel *channel, const char *key, char **errmsg) { if (IsRegOnly(channel) && !IsLoggedIn(client)) { @@ -77,4 +76,3 @@ int regonly_check (Client *client, Channel *channel, const char *key, char **err } return 0; } - diff --git a/src/modules/chanmodes/regonlyspeak.c b/src/modules/chanmodes/regonlyspeak.c index bdb2b41e9..5ade6feac 100644 --- a/src/modules/chanmodes/regonlyspeak.c +++ b/src/modules/chanmodes/regonlyspeak.c @@ -20,22 +20,21 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/regonlyspeak", - "4.2", - "Channel Mode +M", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/regonlyspeak", + "4.2", + "Channel Mode +M", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_REGONLYSPEAK; static char errMsg[2048]; -#define IsRegOnlySpeak(channel) (channel->mode.mode & EXTCMODE_REGONLYSPEAK) +#define IsRegOnlySpeak(channel) (channel->mode.mode & EXTCMODE_REGONLYSPEAK) int regonlyspeak_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx); -const char *regonlyspeak_part_message (Client *client, Channel *channel, const char *comment); +const char *regonlyspeak_part_message(Client *client, Channel *channel, const char *comment); MOD_TEST() { @@ -51,11 +50,11 @@ MOD_INIT() req.letter = 'M'; req.is_ok = extcmode_default_requirehalfop; CmodeAdd(modinfo->handle, req, &EXTCMODE_REGONLYSPEAK); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 0, regonlyspeak_can_send_to_channel); HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_PART, 0, regonlyspeak_part_message); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -70,12 +69,12 @@ MOD_UNLOAD() return MOD_SUCCESS; } -const char *regonlyspeak_part_message (Client *client, Channel *channel, const char *comment) +const char *regonlyspeak_part_message(Client *client, Channel *channel, const char *comment) { if (!comment) return NULL; - if (IsRegOnlySpeak(channel) && !IsLoggedIn(client) && !ValidatePermissionsForPath("channel:override:message:regonlyspeak",client,NULL,NULL,NULL)) + if (IsRegOnlySpeak(channel) && !IsLoggedIn(client) && !ValidatePermissionsForPath("channel:override:message:regonlyspeak", client, NULL, NULL, NULL)) return NULL; return comment; @@ -87,7 +86,7 @@ int regonlyspeak_can_send_to_channel(Client *client, Channel *channel, Membershi int i; if (IsRegOnlySpeak(channel) && - !op_can_override("channel:override:message:regonlyspeak",client,channel,NULL) && + !op_can_override("channel:override:message:regonlyspeak", client, channel, NULL) && !IsLoggedIn(client) && !check_channel_access_membership(lp, "vhoaq")) { diff --git a/src/modules/chanmodes/secret.c b/src/modules/chanmodes/secret.c index 0487a299c..b564802c6 100644 --- a/src/modules/chanmodes/secret.c +++ b/src/modules/chanmodes/secret.c @@ -20,18 +20,17 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/secret", - "6.0", - "Channel Mode +s", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/secret", + "6.0", + "Channel Mode +s", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_SECRET; -#define IsSecret(channel) (channel->mode.mode & EXTCMODE_SECRET) +#define IsSecret(channel) (channel->mode.mode & EXTCMODE_SECRET) int secret_modechar_add(Channel *channel, int modechar); diff --git a/src/modules/chanmodes/secureonly.c b/src/modules/chanmodes/secureonly.c index 084997bd1..c709908b8 100644 --- a/src/modules/chanmodes/secureonly.c +++ b/src/modules/chanmodes/secureonly.c @@ -19,21 +19,20 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/secureonly", - "4.2", - "Channel Mode +z", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/secureonly", + "4.2", + "Channel Mode +z", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_SECUREONLY; -#define IsSecureOnly(channel) (channel->mode.mode & EXTCMODE_SECUREONLY) +#define IsSecureOnly(channel) (channel->mode.mode & EXTCMODE_SECUREONLY) int secureonly_check_join(Client *client, Channel *channel, const char *key, char **errmsg); -int secureonly_channel_sync (Channel *channel, int merge, int removetheirs, int nomode); +int secureonly_channel_sync(Channel *channel, int merge, int removetheirs, int nomode); int secureonly_check_secure(Channel *channel); int secureonly_check_sajoin(Client *target, Channel *channel, Client *requester); int secureonly_pre_local_join(Client *client, Channel *channel, const char *key); @@ -109,10 +108,10 @@ static int secureonly_kick_insecure_users(Channel *channel) RunHook(HOOKTYPE_LOCAL_KICK, &me, &me, client, channel, mtags, comment); sendto_channel(channel, &me, client, - prefix, 0, - SEND_LOCAL, mtags, - ":%s KICK %s %s :%s", - me.name, channel->name, client->name, comment); + prefix, 0, + SEND_LOCAL, mtags, + ":%s KICK %s %s :%s", + me.name, channel->name, client->name, comment); sendto_prefix_one(client, &me, mtags, ":%s KICK %s %s :%s", me.name, channel->name, client->name, comment); @@ -133,7 +132,7 @@ int secureonly_check_join(Client *client, Channel *channel, const char *key, cha if (IsSecureOnly(channel) && !(client->umodes & UMODE_SECURE)) { - if (ValidatePermissionsForPath("channel:override:secureonly",client,NULL,channel,NULL)) + if (ValidatePermissionsForPath("channel:override:secureonly", client, NULL, channel, NULL)) { /* if the channel is +z we still allow an ircop to bypass it * if they are invited. @@ -169,7 +168,7 @@ int secureonly_check_sajoin(Client *target, Channel *channel, Client *requester) if (IsSecureOnly(channel) && !IsSecure(target)) { sendnotice(requester, "You cannot SAJOIN %s to %s because the channel is +z and the user is not connected via TLS", - target->name, channel->name); + target->name, channel->name); return HOOK_DENY; } diff --git a/src/modules/chanmodes/stripcolor.c b/src/modules/chanmodes/stripcolor.c index c65b4342e..dbe2a19c0 100644 --- a/src/modules/chanmodes/stripcolor.c +++ b/src/modules/chanmodes/stripcolor.c @@ -21,18 +21,17 @@ CMD_FUNC(stripcolor); -ModuleHeader MOD_HEADER - = { - "chanmodes/stripcolor", - "4.2", - "Channel Mode +S", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/stripcolor", + "4.2", + "Channel Mode +S", + "UnrealIRCd Team", + "unrealircd-6", +}; Cmode_t EXTCMODE_STRIPCOLOR; -#define IsStripColor(channel) (channel->mode.mode & EXTCMODE_STRIPCOLOR) +#define IsStripColor(channel) (channel->mode.mode & EXTCMODE_STRIPCOLOR) int stripcolor_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx); const char *stripcolor_prelocalpart(Client *client, Channel *channel, const char *comment); @@ -45,7 +44,7 @@ MOD_TEST() MOD_INIT() { -CmodeInfo req; + CmodeInfo req; /* Channel mode */ memset(&req, 0, sizeof(req)); @@ -53,12 +52,12 @@ CmodeInfo req; req.letter = 'S'; req.is_ok = extcmode_default_requirechop; CmodeAdd(modinfo->handle, req, &EXTCMODE_STRIPCOLOR); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 0, stripcolor_can_send_to_channel); HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_PART, 0, stripcolor_prelocalpart); HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_QUIT_CHAN, 0, stripcolor_prelocalpart); HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_QUIT, 0, stripcolor_prelocalquit); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -125,7 +124,6 @@ const char *stripcolor_prelocalquit(Client *client, const char *comment) if (MyUser(client) && !BadPtr(comment) && IsAnyChannelStripColor(client)) comment = StripColors(comment); - + return comment; } - diff --git a/src/modules/chanmodes/topiclimit.c b/src/modules/chanmodes/topiclimit.c index f16583a0e..fc4060168 100644 --- a/src/modules/chanmodes/topiclimit.c +++ b/src/modules/chanmodes/topiclimit.c @@ -20,14 +20,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/topiclimit", - "6.0", - "Channel Mode +t", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/topiclimit", + "6.0", + "Channel Mode +t", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Global variables */ Cmode_t EXTCMODE_TOPIC_LIMIT; @@ -36,7 +35,7 @@ Cmode_t EXTCMODE_TOPIC_LIMIT; int topiclimit_can_set_topic(Client *client, Channel *channel, const char *topic, const char **errmsg); /* Macros */ -#define IsTopicLimit(channel) (channel->mode.mode & EXTCMODE_TOPIC_LIMIT) +#define IsTopicLimit(channel) (channel->mode.mode & EXTCMODE_TOPIC_LIMIT) MOD_INIT() { @@ -66,7 +65,7 @@ MOD_UNLOAD() int topiclimit_can_set_topic(Client *client, Channel *channel, const char *topic, const char **errmsg) { - static char errmsg_buf[NICKLEN+256]; + static char errmsg_buf[NICKLEN + 256]; if (has_channel_mode(channel, 't') && !check_channel_access(client, channel, "hoaq") && diff --git a/src/modules/chanmodes/voice.c b/src/modules/chanmodes/voice.c index 7233c53b2..f8352c4e5 100644 --- a/src/modules/chanmodes/voice.c +++ b/src/modules/chanmodes/voice.c @@ -19,14 +19,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "chanmodes/voice", - "6.0", - "Channel Mode +v", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chanmodes/voice", + "6.0", + "Channel Mode +v", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int cmode_voice_is_ok(Client *client, Channel *channel, char mode, const char *para, int type, int what); diff --git a/src/modules/channel-context.c b/src/modules/channel-context.c index cc21391ff..6d6ba6de4 100644 --- a/src/modules/channel-context.c +++ b/src/modules/channel-context.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "channel-context", - "1.0", - "Channel Context (IRCv3)", - "UnrealIRCd team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "channel-context", + "1.0", + "Channel Context (IRCv3)", + "UnrealIRCd team", + "unrealircd-6", +}; int chancontext_mtag_is_ok(Client *client, const char *name, const char *value); void mtag_add_chancontext(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature); diff --git a/src/modules/channeldb.c b/src/modules/channeldb.c index fabc6acd1..32425e30f 100644 --- a/src/modules/channeldb.c +++ b/src/modules/channeldb.c @@ -7,11 +7,11 @@ #include "unrealircd.h" ModuleHeader MOD_HEADER = { - "channeldb", - "1.0", - "Stores and retrieves channel settings for persistent (+P) channels", - "UnrealIRCd Team", - "unrealircd-6", + "channeldb", + "1.0", + "Stores and retrieves channel settings for persistent (+P) channels", + "UnrealIRCd Team", + "unrealircd-6", }; /* Database version */ @@ -24,35 +24,40 @@ ModuleHeader MOD_HEADER = { */ #define CHANNELDB_SAVE_EVERY_DELTA -15 -#define MAGIC_CHANNEL_START 0x11111111 -#define MAGIC_CHANNEL_END 0x22222222 +#define MAGIC_CHANNEL_START 0x11111111 +#define MAGIC_CHANNEL_END 0x22222222 // #undef BENCHMARK #define WARN_WRITE_ERROR(fname) \ - do { \ + do \ + { \ unreal_log(ULOG_ERROR, "channeldb", "CHANNELDB_FILE_WRITE_ERROR", NULL, \ - "[channeldb] Error writing to temporary database file $filename: $system_error", \ - log_data_string("filename", fname), \ - log_data_string("system_error", unrealdb_get_error_string())); \ - } while(0) + "[channeldb] Error writing to temporary database file $filename: $system_error", \ + log_data_string("filename", fname), \ + log_data_string("system_error", unrealdb_get_error_string())); \ + } while (0) #define W_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ WARN_WRITE_ERROR(tmpfname); \ unrealdb_close(db); \ return 0; \ } \ - } while(0) + } while (0) #define IsMDErr(x, y, z) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ config_error("A critical error occurred when registering ModData for %s: %s", MOD_HEADER.name, ModuleGetErrorStr((z)->handle)); \ return MOD_FAILED; \ } \ - } while(0) + } while (0) /* Structs */ struct cfgstruct { @@ -175,13 +180,11 @@ int channeldb_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { config_error("%s:%i: blank set::channeldb::%s without value", cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "database")) + } else if (!strcmp(cep->name, "database")) { convert_to_absolute_path(&cep->value, PERMDATADIR); safe_strdup(test.database, cep->value); - } else - if (!strcmp(cep->name, "db-secret")) + } else if (!strcmp(cep->name, "db-secret")) { const char *err; if ((err = unrealdb_test_secret(cep->value))) @@ -270,12 +273,12 @@ int write_channeldb(void) W_SAFE(unrealdb_write_int32(db, channeldb_version)); /* First, count +P channels and write the count to the database */ - for (channel = channels; channel; channel=channel->nextch) + for (channel = channels; channel; channel = channel->nextch) if (has_channel_mode(channel, 'P')) cnt++; W_SAFE(unrealdb_write_int64(db, cnt)); - for (channel = channels; channel; channel=channel->nextch) + for (channel = channels; channel; channel = channel->nextch) { /* We only care about +P (persistent) channels */ if (has_channel_mode(channel, 'P')) @@ -304,7 +307,7 @@ int write_channeldb(void) #ifdef BENCHMARK gettimeofday(&tv_beta, NULL); config_status("[channeldb] Benchmark: SAVE DB: %ld microseconds", - ((tv_beta.tv_sec - tv_alpha.tv_sec) * 1000000) + (tv_beta.tv_usec - tv_alpha.tv_usec)); + ((tv_beta.tv_sec - tv_alpha.tv_sec) * 1000000) + (tv_beta.tv_usec - tv_alpha.tv_usec)); #endif return 1; } @@ -360,8 +363,10 @@ int write_channel_entry(UnrealDB *db, const char *tmpfname, Channel *channel) } #define R_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ config_warn("[channeldb] Read error from database file '%s' (possible corruption): %s", cfg.database, unrealdb_get_error_string()); \ if (e) \ { \ @@ -371,7 +376,7 @@ int write_channel_entry(UnrealDB *db, const char *tmpfname, Channel *channel) } \ return 0; \ } \ - } while(0) + } while (0) int read_listmode(UnrealDB *db, Channel *channel, ExtbanType ban_type, Ban **lst) { @@ -407,7 +412,8 @@ int read_listmode(UnrealDB *db, Channel *channel, ExtbanType ban_type, Ban **lst safe_free(e->banstr); safe_free(e->who); safe_free(e); - } else { + } else + { /* Add to list */ e->when = when; e->next = *lst; @@ -420,7 +426,8 @@ int read_listmode(UnrealDB *db, Channel *channel, ExtbanType ban_type, Ban **lst #undef R_SAFE #define FreeChannelEntry() \ - do { \ + do \ + { \ /* Some of these might be NULL */ \ safe_free(chname); \ safe_free(topic); \ @@ -428,17 +435,19 @@ int read_listmode(UnrealDB *db, Channel *channel, ExtbanType ban_type, Ban **lst safe_free(modes1); \ safe_free(modes2); \ safe_free(mode_lock); \ - } while(0) + } while (0) #define R_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ config_warn("[channeldb] Read error from database file '%s' (possible corruption): %s", cfg.database, unrealdb_get_error_string()); \ unrealdb_close(db); \ FreeChannelEntry(); \ return 0; \ } \ - } while(0) + } while (0) int read_channeldb(void) { @@ -472,8 +481,7 @@ int read_channeldb(void) /* Database does not exist. Could be first boot */ config_warn("[channeldb] No database present at '%s', will start a new one", cfg.database); return 1; - } else - if (unrealdb_get_error_code() == UNREALDB_ERROR_NOTCRYPTED) + } else if (unrealdb_get_error_code() == UNREALDB_ERROR_NOTCRYPTED) { /* Re-open as unencrypted */ db = unrealdb_open(cfg.database, UNREALDB_MODE_READ, NULL); @@ -500,7 +508,7 @@ int read_channeldb(void) R_SAFE(unrealdb_read_int64(db, &count)); - for (i=1; i <= count; i++) + for (i = 1; i <= count; i++) { // Variables chname = NULL; @@ -511,7 +519,7 @@ int read_channeldb(void) modes1 = NULL; modes2 = NULL; mode_lock = NULL; - + Channel *channel; R_SAFE(unrealdb_read_int32(db, &magic)); if (magic != MAGIC_CHANNEL_START) diff --git a/src/modules/charsys.c b/src/modules/charsys.c index e896b660a..00f0d9dfd 100644 --- a/src/modules/charsys.c +++ b/src/modules/charsys.c @@ -23,16 +23,15 @@ #include "unrealircd.h" #ifndef ARRAY_SIZEOF - #define ARRAY_SIZEOF(x) (sizeof((x))/sizeof((x)[0])) + #define ARRAY_SIZEOF(x) (sizeof((x)) / sizeof((x)[0])) #endif -ModuleHeader MOD_HEADER -= { - "charsys", /* Name of module */ - "5.0", /* Version */ - "Character System (set::allowed-nickchars)", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "charsys", /* Name of module */ + "5.0", /* Version */ + "Character System (set::allowed-nickchars)", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", }; /* NOTE: it is guaranteed that char is unsigned by compiling options @@ -43,8 +42,7 @@ ModuleHeader MOD_HEADER /** Our multibyte structure */ typedef struct MBList MBList; -struct MBList -{ +struct MBList { MBList *next; char s1, e1, s2, e2; }; @@ -57,26 +55,25 @@ static int langav = 0; char langsinuse[4096]; /* bitmasks: */ -#define LANGAV_ASCII 0x000001 /* 8 bit ascii */ -#define LANGAV_LATIN1 0x000002 /* latin1 (western europe) */ -#define LANGAV_LATIN2 0x000004 /* latin2 (eastern europe, eg: polish) */ -#define LANGAV_ISO8859_7 0x000008 /* greek */ -#define LANGAV_ISO8859_8I 0x000010 /* hebrew */ -#define LANGAV_ISO8859_9 0x000020 /* turkish */ -#define LANGAV_W1250 0x000040 /* windows-1250 (eg: polish-w1250) */ -#define LANGAV_W1251 0x000080 /* windows-1251 (eg: russian) */ -#define LANGAV_LATIN2W1250 0x000100 /* Compatible with both latin2 AND windows-1250 (eg: hungarian) */ -#define LANGAV_ISO8859_6 0x000200 /* arabic */ -#define LANGAV_GBK 0x001000 /* (Chinese) GBK encoding */ -#define LANGAV_UTF8 0x002000 /* any UTF8 encoding */ -#define LANGAV_LATIN_UTF8 0x004000 /* UTF8: latin script */ -#define LANGAV_CYRILLIC_UTF8 0x008000 /* UTF8: cyrillic script */ -#define LANGAV_GREEK_UTF8 0x010000 /* UTF8: greek script */ -#define LANGAV_HEBREW_UTF8 0x020000 /* UTF8: hebrew script */ -#define LANGAV_ARABIC_UTF8 0x040000 /* UTF8: arabic script */ +#define LANGAV_ASCII 0x000001 /* 8 bit ascii */ +#define LANGAV_LATIN1 0x000002 /* latin1 (western europe) */ +#define LANGAV_LATIN2 0x000004 /* latin2 (eastern europe, eg: polish) */ +#define LANGAV_ISO8859_7 0x000008 /* greek */ +#define LANGAV_ISO8859_8I 0x000010 /* hebrew */ +#define LANGAV_ISO8859_9 0x000020 /* turkish */ +#define LANGAV_W1250 0x000040 /* windows-1250 (eg: polish-w1250) */ +#define LANGAV_W1251 0x000080 /* windows-1251 (eg: russian) */ +#define LANGAV_LATIN2W1250 0x000100 /* Compatible with both latin2 AND windows-1250 (eg: hungarian) */ +#define LANGAV_ISO8859_6 0x000200 /* arabic */ +#define LANGAV_GBK 0x001000 /* (Chinese) GBK encoding */ +#define LANGAV_UTF8 0x002000 /* any UTF8 encoding */ +#define LANGAV_LATIN_UTF8 0x004000 /* UTF8: latin script */ +#define LANGAV_CYRILLIC_UTF8 0x008000 /* UTF8: cyrillic script */ +#define LANGAV_GREEK_UTF8 0x010000 /* UTF8: greek script */ +#define LANGAV_HEBREW_UTF8 0x020000 /* UTF8: hebrew script */ +#define LANGAV_ARABIC_UTF8 0x040000 /* UTF8: arabic script */ typedef struct LangList LangList; -struct LangList -{ +struct LangList { char *directive; char *code; int setflags; @@ -149,8 +146,7 @@ static LangList langlist[] = { /* For temporary use during config_run */ typedef struct ILangList ILangList; -struct ILangList -{ +struct ILangList { ILangList *prev, *next; char *name; }; @@ -237,20 +233,20 @@ int charsys_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (ce->value) { config_error("%s:%i: set::allowed-nickchars: please use 'allowed-nickchars { name; };' " - "and not 'allowed-nickchars name;'", - ce->file->filename, ce->line_number); + "and not 'allowed-nickchars name;'", + ce->file->filename, ce->line_number); /* Give up immediately. Don't bother the user with any other errors. */ errors++; *errs = errors; return -1; } - for (cep = ce->items; cep; cep=cep->next) + for (cep = ce->items; cep; cep = cep->next) { if (!charsys_test_language(cep->name)) { config_error("%s:%i: set::allowed-nickchars: Unknown (sub)language '%s'", - ce->file->filename, ce->line_number, cep->name); + ce->file->filename, ce->line_number, cep->name); errors++; } } @@ -283,7 +279,7 @@ int charsys_config_run(ConfigFile *cf, ConfigEntry *ce, int type) int charsys_config_posttest(int *errs) { int errors = 0; - int x=0; + int x = 0; if ((langav & LANGAV_ASCII) && (langav & LANGAV_GBK)) { @@ -315,7 +311,7 @@ int charsys_config_posttest(int *errs) if (langav & LANGAV_W1251) x++; if ((langav & LANGAV_LATIN2W1250) && !(langav & LANGAV_LATIN2) && !(langav & LANGAV_W1250)) - x++; + x++; if (x > 1) { #if 0 @@ -356,12 +352,12 @@ int charsys_config_posttest(int *errs) void charsys_free_mblist(void) { MBList *m, *m_next; - for (m=mblist; m; m=m_next) + for (m = mblist; m; m = m_next) { m_next = m->next; safe_free(m); } - mblist=mblist_tail=NULL; + mblist = mblist_tail = NULL; } /** Called on boot and just before config run */ @@ -371,7 +367,7 @@ void charsys_reset(void) MBList *m, *m_next; /* First, reset everything */ - for (i=0; i < 256; i++) + for (i = 0; i < 256; i++) char_atribs[i] &= ~ALLOWN; charsys_free_mblist(); /* Then add the default which will always be allowed */ @@ -404,9 +400,9 @@ static void ilang_sort(void) /* Selection sort -- perhaps optimize to qsort/whatever if * possible? ;) */ - for (outer=ilanglist; outer; outer=outer->next) + for (outer = ilanglist; outer; outer = outer->next) { - for (inner=outer->next; inner; inner=inner->next) + for (inner = outer->next; inner; inner = inner->next) { if (strcmp(outer->name, inner->name) > 0) ilang_swap(outer, inner); @@ -423,7 +419,7 @@ void charsys_finish(void) /* [note: this can be optimized] */ langsinuse[0] = '\0'; - for (e=ilanglist; e; e=e->next) + for (e = ilanglist; e; e = e->next) { strlcat(langsinuse, e->name, sizeof(langsinuse)); if (e->next) @@ -431,9 +427,9 @@ void charsys_finish(void) } /* Free everything */ - for (e=ilanglist; e; e=e_next) + for (e = ilanglist; e; e = e_next) { - e_next=e->next; + e_next = e->next; safe_free(e->name); safe_free(e); } @@ -454,7 +450,7 @@ void charsys_finish(void) */ void charsys_addmultibyterange(char s1, char e1, char s2, char e2) { -MBList *m = safe_alloc(sizeof(MBList)); + MBList *m = safe_alloc(sizeof(MBList)); m->s1 = s1; m->e1 = e1; @@ -508,7 +504,7 @@ static int do_nick_name_standard(char *nick) if ((*nick == '-') || isdigit(*nick)) return 0; - for (ch=nick,len=0; *ch && len <= NICKLEN; ch++, len++) + for (ch = nick, len = 0; *ch && len <= NICKLEN; ch++, len++) if (!isvalid(*ch)) return 0; /* reject the full nick */ *ch = '\0'; @@ -519,11 +515,11 @@ static int isvalidmbyte(unsigned char c1, unsigned char c2) { MBList *m; - for (m=mblist; m; m=m->next) + for (m = mblist; m; m = m->next) { if ((c1 >= m->s1) && (c1 <= m->e1) && (c2 >= m->s2) && (c2 <= m->e2)) - return 1; + return 1; } return 0; } @@ -541,7 +537,7 @@ static int do_nick_name_multibyte(char *nick) if ((*nick == '-') || isdigit(*nick)) return 0; - for (ch=nick,len=0; *ch && len <= NICKLEN; ch++, len++) + for (ch = nick, len = 0; *ch && len <= NICKLEN; ch++, len++) { /* Some characters are ALWAYS illegal, so they have to be disallowed here */ if ((*ch <= 32) || strchr(illegalnickchars, *ch)) @@ -580,7 +576,7 @@ int _do_remote_nick_name(char *nick) return 0; /* Now the other, more relaxed checks.. */ - for (c=nick; *c; c++) + for (c = nick; *c; c++) if ((*c <= 32) || strchr(illegalnickchars, *c)) return 0; @@ -590,18 +586,18 @@ int _do_remote_nick_name(char *nick) static LangList *charsys_find_language(char *name) { int start = 0; - int stop = ARRAY_SIZEOF(langlist)-1; + int stop = ARRAY_SIZEOF(langlist) - 1; int mid; while (start <= stop) { - mid = (start+stop)/2; + mid = (start + stop) / 2; if (!langlist[mid].directive || smycmp(name, langlist[mid].directive) < 0) - stop = mid-1; + stop = mid - 1; else if (strcmp(name, langlist[mid].directive) == 0) return &langlist[mid]; else - start = mid+1; + start = mid + 1; } return NULL; } @@ -637,10 +633,10 @@ int charsys_test_language(char *name) static void charsys_doadd_language(char *name) { -LangList *l; -ILangList *li; -int found; -char tmp[512], *lang, *p; + LangList *l; + ILangList *li; + int found; + char tmp[512], *lang, *p; l = charsys_find_language(name); if (!l) @@ -655,8 +651,8 @@ char tmp[512], *lang, *p; for (lang = strtoken(&p, tmp, ","); lang; lang = strtoken(&p, NULL, ",")) { /* Check if present... */ - found=0; - for (li=ilanglist; li; li=li->next) + found = 0; + for (li = ilanglist; li; li = li->next) if (!strcmp(li->name, lang)) { found = 1; @@ -674,8 +670,8 @@ char tmp[512], *lang, *p; void charsys_add_language(char *name) { - char latin1=0, latin2=0, w1250=0, w1251=0, chinese=0; - char latin_utf8=0, cyrillic_utf8=0; + char latin1 = 0, latin2 = 0, w1250 = 0, w1251 = 0, chinese = 0; + char latin_utf8 = 0, cyrillic_utf8 = 0; /** Note: there could well be some characters missing in the lists below. * While I've seen other altnernatives that just allow pretty much @@ -1245,9 +1241,9 @@ char *charsys_displaychars(void) * try this instead (lazy).. this is only used in DEBUGMODE * via a command line option anyway: */ - for (i=0; i <= 255; i++) + for (i = 0; i <= 255; i++) { - for (j=0; j <= 255; j++) + for (j = 0; j <= 255; j++) { if (isvalidmbyte(i, j)) { diff --git a/src/modules/chathistory.c b/src/modules/chathistory.c index 1eebbc70c..36e482f05 100644 --- a/src/modules/chathistory.c +++ b/src/modules/chathistory.c @@ -7,13 +7,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "chathistory", - "1.0", - "IRCv3 CHATHISTORY command", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "chathistory", + "1.0", + "IRCv3 CHATHISTORY command", + "UnrealIRCd Team", + "unrealircd-6", }; /* Structs */ @@ -123,7 +122,8 @@ static void add_chathistory_target_list(ChatHistoryTarget *new, ChatHistoryTarge new->next = x; x->prev->next = new; x->prev = new; - } else { + } else + { /* We are the new head */ *list = new; new->next = x; @@ -167,7 +167,7 @@ static void chathistory_targets_send_line(Client *client, ChatHistoryTarget *r, } sendto_one(client, mtags, ":%s CHATHISTORY TARGETS %s %s", - me.name, r->object, r->datetime); + me.name, r->object, r->datetime); if (mtags) free_message_tags(mtags); @@ -177,7 +177,7 @@ void chathistory_targets(Client *client, HistoryFilter *filter, int limit) { Membership *mp; HistoryResult *r; - char batch[BATCHLEN+1]; + char batch[BATCHLEN + 1]; int sent = 0; ChatHistoryTarget *targets = NULL, *targets_next; @@ -247,7 +247,7 @@ void chathistory_targets(Client *client, HistoryFilter *filter, int limit) void send_empty_batch(Client *client, const char *target) { - char batch[BATCHLEN+1]; + char batch[BATCHLEN + 1]; if (HasCapability(client, "batch")) { @@ -294,13 +294,13 @@ CMD_FUNC(cmd_chathistory) if (!chathistory_token(parv[2], "timestamp", &filter->timestamp_a)) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s %s :Invalid parameter, must be timestamp=xxx", - me.name, parv[1], parv[3]); + me.name, parv[1], parv[3]); goto end; } if (!chathistory_token(parv[3], "timestamp", &filter->timestamp_b)) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s %s :Invalid parameter, must be timestamp=xxx", - me.name, parv[1], parv[4]); + me.name, parv[1], parv[4]); goto end; } limit = atoi(parv[4]); @@ -319,14 +319,14 @@ CMD_FUNC(cmd_chathistory) if (!channel) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_TARGET %s %s :Messages could not be retrieved, not an existing channel", - me.name, parv[1], parv[2]); + me.name, parv[1], parv[2]); return; } if (!IsMember(client, channel)) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_TARGET %s %s :Messages could not be retrieved, you are not a member", - me.name, parv[1], parv[2]); + me.name, parv[1], parv[2]); return; } @@ -347,24 +347,22 @@ CMD_FUNC(cmd_chathistory) !chathistory_token(parv[3], "msgid", &filter->msgid_a)) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s %s :Invalid parameter, must be timestamp=xxx or msgid=xxx", - me.name, parv[1], parv[3]); + me.name, parv[1], parv[3]); goto end; } filter->limit = atoi(parv[4]); - } else - if (!strcasecmp(parv[1], "AFTER")) + } else if (!strcasecmp(parv[1], "AFTER")) { filter->cmd = HFC_AFTER; if (!chathistory_token(parv[3], "timestamp", &filter->timestamp_a) && !chathistory_token(parv[3], "msgid", &filter->msgid_a)) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s %s :Invalid parameter, must be timestamp=xxx or msgid=xxx", - me.name, parv[1], parv[3]); + me.name, parv[1], parv[3]); goto end; } filter->limit = atoi(parv[4]); - } else - if (!strcasecmp(parv[1], "LATEST")) + } else if (!strcasecmp(parv[1], "LATEST")) { filter->cmd = HFC_LATEST; if (!chathistory_token(parv[3], "timestamp", &filter->timestamp_a) && @@ -372,24 +370,22 @@ CMD_FUNC(cmd_chathistory) strcmp(parv[3], "*")) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s %s :Invalid parameter, must be timestamp=xxx or msgid=xxx or *", - me.name, parv[1], parv[3]); + me.name, parv[1], parv[3]); goto end; } filter->limit = atoi(parv[4]); - } else - if (!strcasecmp(parv[1], "AROUND")) + } else if (!strcasecmp(parv[1], "AROUND")) { filter->cmd = HFC_AROUND; if (!chathistory_token(parv[3], "timestamp", &filter->timestamp_a) && !chathistory_token(parv[3], "msgid", &filter->msgid_a)) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s %s :Invalid parameter, must be timestamp=xxx or msgid=xxx", - me.name, parv[1], parv[3]); + me.name, parv[1], parv[3]); goto end; } filter->limit = atoi(parv[4]); - } else - if (!strcasecmp(parv[1], "BETWEEN")) + } else if (!strcasecmp(parv[1], "BETWEEN")) { filter->cmd = HFC_BETWEEN; if (BadPtr(parv[5])) @@ -401,18 +397,19 @@ CMD_FUNC(cmd_chathistory) !chathistory_token(parv[3], "msgid", &filter->msgid_a)) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s %s :Invalid parameter, must be timestamp=xxx or msgid=xxx", - me.name, parv[1], parv[3]); + me.name, parv[1], parv[3]); goto end; } if (!chathistory_token(parv[4], "timestamp", &filter->timestamp_b) && !chathistory_token(parv[4], "msgid", &filter->msgid_b)) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s %s :Invalid parameter, must be timestamp=xxx or msgid=xxx", - me.name, parv[1], parv[4]); + me.name, parv[1], parv[4]); goto end; } filter->limit = atoi(parv[5]); - } else { + } else + { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s :Invalid subcommand", me.name, parv[1]); goto end; } @@ -420,7 +417,7 @@ CMD_FUNC(cmd_chathistory) if (filter->limit <= 0) { sendto_one(client, NULL, ":%s FAIL CHATHISTORY INVALID_PARAMS %s %d :Specified limit is =<0", - me.name, parv[1], filter->limit); + me.name, parv[1], filter->limit); goto end; } @@ -429,14 +426,15 @@ CMD_FUNC(cmd_chathistory) if ((r = history_request(channel->name, filter))) { - if ((r->num_bytes*1.5) > get_sendq(client)) + if ((r->num_bytes * 1.5) > get_sendq(client)) { /* This would get rather close to max sendq. We reject * the request as to not cause "Max SendQ exceeded". */ sendto_one(client, NULL, ":%s FAIL CHATHISTORY MESSAGE_ERROR %s %s :History too large to deliver", - me.name, parv[1], channel->name); - } else { + me.name, parv[1], channel->name); + } else + { /* All ok, bump fake lag and add the result. * The fakelag bump under normal circumstances is tiny * at like 400ms worst-case without multiline. However, it diff --git a/src/modules/chghost.c b/src/modules/chghost.c index b5acd1f03..54fc5861c 100644 --- a/src/modules/chghost.c +++ b/src/modules/chghost.c @@ -22,7 +22,7 @@ #include "unrealircd.h" -#define MSG_CHGHOST "CHGHOST" +#define MSG_CHGHOST "CHGHOST" CMD_FUNC(cmd_chghost); void _userhost_save_current(Client *client); @@ -30,14 +30,13 @@ void _userhost_changed(Client *client); long CAP_CHGHOST = 0L; -ModuleHeader MOD_HEADER - = { - "chghost", /* Name of module */ - "5.0", /* Version */ - "/chghost", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chghost", /* Name of module */ + "5.0", /* Version */ + "/chghost", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_TEST() { @@ -51,7 +50,7 @@ MOD_INIT() { ClientCapabilityInfo c; - CommandAdd(modinfo->handle, MSG_CHGHOST, cmd_chghost, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_CHGHOST, cmd_chghost, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); memset(&c, 0, sizeof(c)); @@ -64,18 +63,17 @@ MOD_INIT() MOD_LOAD() { return MOD_SUCCESS; - } MOD_UNLOAD() { - return MOD_SUCCESS; + return MOD_SUCCESS; } -static char remember_nick[NICKLEN+1]; -static char remember_user[USERLEN+1]; -static char remember_host[HOSTLEN+1]; +static char remember_nick[NICKLEN + 1]; +static char remember_user[USERLEN + 1]; +static char remember_host[HOSTLEN + 1]; /** Save current nick/user/host. Used later by userhost_changed(). */ void _userhost_save_current(Client *client) @@ -143,17 +141,17 @@ void _userhost_changed(Client *client) /* Prepare buffers for PART, JOIN, MODE */ ircsnprintf(partbuf, sizeof(partbuf), ":%s!%s@%s PART %s :%s", - remember_nick, remember_user, remember_host, - channel->name, - "Changing host"); + remember_nick, remember_user, remember_host, + channel->name, + "Changing host"); ircsnprintf(joinbuf, sizeof(joinbuf), ":%s!%s@%s JOIN %s", - client->name, client->user->username, GetHost(client), channel->name); + client->name, client->user->username, GetHost(client), channel->name); ircsnprintf(exjoinbuf, sizeof(exjoinbuf), ":%s!%s@%s JOIN %s %s :%s", - client->name, client->user->username, GetHost(client), channel->name, - IsLoggedIn(client) ? client->user->account : "*", - client->info); + client->name, client->user->username, GetHost(client), channel->name, + IsLoggedIn(client) ? client->user->account : "*", + client->info); modes = get_chmodes_for_user(client, channels->member_modes); if (!BadPtr(modes)) @@ -218,7 +216,7 @@ void _userhost_changed(Client *client) } } } - + RunHook(HOOKTYPE_USERHOST_CHANGE, client, remember_user, remember_host); if (MyUser(client)) @@ -258,7 +256,7 @@ CMD_FUNC(cmd_chghost) { Client *target; - if (MyUser(client) && !ValidatePermissionsForPath("client:set:host",client,NULL,NULL,NULL)) + if (MyUser(client) && !ValidatePermissionsForPath("client:set:host", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -322,7 +320,7 @@ CMD_FUNC(cmd_chghost) if (MyUser(client)) { sendnumeric(client, ERR_DISABLED, "CHGHOST", - "This command is disabled on this server"); + "This command is disabled on this server"); return; } break; @@ -346,17 +344,18 @@ CMD_FUNC(cmd_chghost) if (issuer) { unreal_log(ULOG_INFO, "chgcmds", "CHGHOST_COMMAND", client, - "CHGHOST: $issuer changed the virtual hostname of $target.details to be $new_hostname", - log_data_string("issuer", issuer), - log_data_string("change_type", "hostname"), - log_data_client("target", target), - log_data_string("new_hostname", parv[2])); - } else { + "CHGHOST: $issuer changed the virtual hostname of $target.details to be $new_hostname", + log_data_string("issuer", issuer), + log_data_string("change_type", "hostname"), + log_data_client("target", target), + log_data_string("new_hostname", parv[2])); + } else + { unreal_log(ULOG_INFO, "chgcmds", "CHGHOST_COMMAND", client, - "CHGHOST: $client changed the virtual hostname of $target.details to be $new_hostname", - log_data_string("change_type", "hostname"), - log_data_client("target", target), - log_data_string("new_hostname", parv[2])); + "CHGHOST: $client changed the virtual hostname of $target.details to be $new_hostname", + log_data_string("change_type", "hostname"), + log_data_client("target", target), + log_data_string("new_hostname", parv[2])); } } diff --git a/src/modules/chgident.c b/src/modules/chgident.c index 41555dc79..ae40367fa 100644 --- a/src/modules/chgident.c +++ b/src/modules/chgident.c @@ -22,22 +22,21 @@ #include "unrealircd.h" -#define MSG_CHGIDENT "CHGIDENT" +#define MSG_CHGIDENT "CHGIDENT" CMD_FUNC(cmd_chgident); -ModuleHeader MOD_HEADER - = { - "chgident", /* Name of module */ - "5.0", /* Version */ - "/chgident", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chgident", /* Name of module */ + "5.0", /* Version */ + "/chgident", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_CHGIDENT, cmd_chgident, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_CHGIDENT, cmd_chgident, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -66,7 +65,7 @@ CMD_FUNC(cmd_chgident) const char *s; int legalident = 1; - if (!ValidatePermissionsForPath("client:set:ident",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("client:set:ident", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -118,7 +117,7 @@ CMD_FUNC(cmd_chgident) if (MyUser(client)) { sendnumeric(client, ERR_DISABLED, "CHGIDENT", - "This command is disabled on this server"); + "This command is disabled on this server"); return; } break; @@ -141,17 +140,18 @@ CMD_FUNC(cmd_chgident) if (issuer) { unreal_log(ULOG_INFO, "chgcmds", "CHGIDENT_COMMAND", client, - "CHGIDENT: $issuer changed the username of $target.details to be $new_username", - log_data_string("issuer", issuer), - log_data_string("change_type", "username"), - log_data_client("target", target), - log_data_string("new_username", parv[2])); - } else { + "CHGIDENT: $issuer changed the username of $target.details to be $new_username", + log_data_string("issuer", issuer), + log_data_string("change_type", "username"), + log_data_client("target", target), + log_data_string("new_username", parv[2])); + } else + { unreal_log(ULOG_INFO, "chgcmds", "CHGIDENT_COMMAND", client, - "CHGIDENT: $client changed the username of $target.details to be $new_username", - log_data_string("change_type", "username"), - log_data_client("target", target), - log_data_string("new_username", parv[2])); + "CHGIDENT: $client changed the username of $target.details to be $new_username", + log_data_string("change_type", "username"), + log_data_client("target", target), + log_data_string("new_username", parv[2])); } } diff --git a/src/modules/chgname.c b/src/modules/chgname.c index b4b628f9b..1528e6646 100644 --- a/src/modules/chgname.c +++ b/src/modules/chgname.c @@ -20,26 +20,25 @@ #include "unrealircd.h" -#define MSG_CHGNAME "CHGNAME" -#define MSG_SVSNAME "SVSNAME" +#define MSG_CHGNAME "CHGNAME" +#define MSG_SVSNAME "SVSNAME" CMD_FUNC(cmd_chgname); -ModuleHeader MOD_HEADER - = { - "chgname", /* Name of module */ - "5.0", /* Version */ - "command /chgname", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "chgname", /* Name of module */ + "5.0", /* Version */ + "command /chgname", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() { - CommandAdd(modinfo->handle, MSG_CHGNAME, cmd_chgname, 2, CMD_USER|CMD_SERVER); - CommandAdd(modinfo->handle, MSG_SVSNAME, cmd_chgname, 2, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_CHGNAME, cmd_chgname, 2, CMD_USER | CMD_SERVER); + CommandAdd(modinfo->handle, MSG_SVSNAME, cmd_chgname, 2, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -70,7 +69,7 @@ CMD_FUNC(cmd_chgname) Client *target; ConfigItem_ban *bconf; - if (!ValidatePermissionsForPath("client:set:name",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("client:set:name", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -101,17 +100,18 @@ CMD_FUNC(cmd_chgname) if (issuer) { unreal_log(ULOG_INFO, "chgcmds", "CHGNAME_COMMAND", client, - "CHGNAME: $issuer changed the realname of $target.details to be $new_realname", - log_data_string("issuer", issuer), - log_data_string("change_type", "realname"), - log_data_client("target", target), - log_data_string("new_realname", parv[2])); - } else { + "CHGNAME: $issuer changed the realname of $target.details to be $new_realname", + log_data_string("issuer", issuer), + log_data_string("change_type", "realname"), + log_data_client("target", target), + log_data_string("new_realname", parv[2])); + } else + { unreal_log(ULOG_INFO, "chgcmds", "CHGNAME_COMMAND", client, - "CHGNAME: $client changed the realname of $target.details to be $new_realname", - log_data_string("change_type", "realname"), - log_data_client("target", target), - log_data_string("new_realname", parv[2])); + "CHGNAME: $client changed the realname of $target.details to be $new_realname", + log_data_string("change_type", "realname"), + log_data_client("target", target), + log_data_string("new_realname", parv[2])); } } @@ -121,14 +121,14 @@ CMD_FUNC(cmd_chgname) if (MyUser(target)) { /* only check for realname bans if the person who's name is being changed is NOT an oper */ - if (!ValidatePermissionsForPath("immune:server-ban:ban-realname",target,NULL,NULL,NULL) && + if (!ValidatePermissionsForPath("immune:server-ban:ban-realname", target, NULL, NULL, NULL) && ((bconf = find_ban(NULL, target->info, CONF_BAN_REALNAME)))) { - banned_client(target, "realname", bconf->reason?bconf->reason:"", NULL, 0, 0); + banned_client(target, "realname", bconf->reason ? bconf->reason : "", NULL, 0, 0); return; } } sendto_server(client, 0, 0, recv_mtags, ":%s CHGNAME %s :%s", - client->id, target->name, parv[2]); + client->id, target->name, parv[2]); } diff --git a/src/modules/clienttagdeny.c b/src/modules/clienttagdeny.c index a2752c7f9..6a1e9a187 100644 --- a/src/modules/clienttagdeny.c +++ b/src/modules/clienttagdeny.c @@ -28,20 +28,22 @@ int tags_rehash_complete(void); Module *module; ModuleHeader MOD_HEADER = { - "clienttagdeny", - "5.0", - "Informs clients about supported client tags", - "k4be", - "unrealircd-6", + "clienttagdeny", + "5.0", + "Informs clients about supported client tags", + "k4be", + "unrealircd-6", }; -MOD_INIT(){ +MOD_INIT() +{ MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } -MOD_LOAD(){ +MOD_LOAD() +{ module = modinfo->handle; ISupportAdd(module, "CLIENTTAGDENY", ct_isupport_param()); HookAdd(module, HOOKTYPE_REHASH_COMPLETE, 0, tags_rehash_complete); @@ -49,29 +51,33 @@ MOD_LOAD(){ return MOD_SUCCESS; } -MOD_UNLOAD(){ +MOD_UNLOAD() +{ return MOD_SUCCESS; } #define BUFLEN 500 -char *ct_isupport_param(void){ +char *ct_isupport_param(void) +{ static char buf[BUFLEN]; MessageTagHandler *m; - + strlcpy(buf, "*", sizeof(buf)); - for (m = mtaghandlers; m; m = m->next) { - if (!m->unloaded && m->name[0] == '+'){ + for (m = mtaghandlers; m; m = m->next) + { + if (!m->unloaded && m->name[0] == '+') + { strlcat(buf, ",-", sizeof(buf)); - strlcat(buf, m->name+1, sizeof(buf)); + strlcat(buf, m->name + 1, sizeof(buf)); } } return buf; } -int tags_rehash_complete(void){ +int tags_rehash_complete(void) +{ ISupportSet(module, "CLIENTTAGDENY", ct_isupport_param()); return HOOK_CONTINUE; } - diff --git a/src/modules/cloak_md5.c b/src/modules/cloak_md5.c index 202d55487..2642cf847 100644 --- a/src/modules/cloak_md5.c +++ b/src/modules/cloak_md5.c @@ -47,11 +47,11 @@ static char *hidehost_normalhost(char *host); static inline unsigned int downsample(char *i); ModuleHeader MOD_HEADER = { - "cloak_md5", - "1.0", - "Old cloaking module (MD5)", - "UnrealIRCd Team", - "unrealircd-6", + "cloak_md5", + "1.0", + "Old cloaking module (MD5)", + "UnrealIRCd Team", + "unrealircd-6", }; MOD_TEST() @@ -110,9 +110,9 @@ MOD_UNLOAD() static int check_badrandomness(char *key) { -char gotlowcase=0, gotupcase=0, gotdigit=0; -char *p; - for (p=key; *p; p++) + char gotlowcase = 0, gotupcase = 0, gotdigit = 0; + char *p; + for (p = key; *p; p++) if (islower(*p)) gotlowcase = 1; else if (isupper(*p)) @@ -141,13 +141,12 @@ int cloak_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!ce->value) { config_error("%s:%i: set::cloak-method: no method specified. The only supported methods are: 'ip' and 'host'", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; - } else - if (strcmp(ce->value, "ip") && strcmp(ce->value, "host")) + } else if (strcmp(ce->value, "ip") && strcmp(ce->value, "host")) { config_error("%s:%i: set::cloak-method: unknown method '%s'. The only supported methods are: 'ip' and 'host'", - ce->file->filename, ce->line_number, ce->value); + ce->file->filename, ce->line_number, ce->value); errors++; } @@ -165,34 +164,35 @@ int cloak_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (check_badrandomness(cep->name)) { config_error("%s:%i: set::cloak-keys: (key %d) Keys should be mixed a-zA-Z0-9, " - "like \"a2JO6fh3Q6w4oN3s7\"", cep->file->filename, cep->line_number, keycnt); + "like \"a2JO6fh3Q6w4oN3s7\"", + cep->file->filename, cep->line_number, keycnt); errors++; } if (strlen(cep->name) < 5) { config_error("%s:%i: set::cloak-keys: (key %d) Each key should be at least 5 characters", - cep->file->filename, cep->line_number, keycnt); + cep->file->filename, cep->line_number, keycnt); errors++; } if (strlen(cep->name) > 100) { config_error("%s:%i: set::cloak-keys: (key %d) Each key should be less than 100 characters", - cep->file->filename, cep->line_number, keycnt); + cep->file->filename, cep->line_number, keycnt); errors++; } if (keycnt < 4) - keys[keycnt-1] = cep->name; + keys[keycnt - 1] = cep->name; } if (keycnt != 3) { config_error("%s:%i: set::cloak-keys: we want 3 values, not %i!", - ce->file->filename, ce->line_number, keycnt); + ce->file->filename, ce->line_number, keycnt); errors++; } if ((keycnt == 3) && (!strcmp(keys[0], keys[1]) || !strcmp(keys[1], keys[2]))) { config_error("%s:%i: set::cloak-keys: All your 3 keys should be RANDOM, they should not be equal", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } *errs = errors; @@ -201,7 +201,7 @@ int cloak_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) int cloak_config_posttest(int *errs) { -int errors = 0; + int errors = 0; if (nokeys) { @@ -215,8 +215,8 @@ int errors = 0; int cloak_config_run(ConfigFile *cf, ConfigEntry *ce, int type) { -ConfigEntry *cep; -char buf[512], result[16]; + ConfigEntry *cep; + char buf[512], result[16]; if (type == CONFIG_SET) { @@ -245,23 +245,23 @@ char buf[512], result[16]; ircsnprintf(buf, sizeof(buf), "%s:%s:%s", KEY1, KEY2, KEY3); DoMD5(result, buf, strlen(buf)); ircsnprintf(cloak_checksum, sizeof(cloak_checksum), - "MD5:%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x", - (u_int)(result[0] & 0xf), (u_int)(result[0] >> 4), - (u_int)(result[1] & 0xf), (u_int)(result[1] >> 4), - (u_int)(result[2] & 0xf), (u_int)(result[2] >> 4), - (u_int)(result[3] & 0xf), (u_int)(result[3] >> 4), - (u_int)(result[4] & 0xf), (u_int)(result[4] >> 4), - (u_int)(result[5] & 0xf), (u_int)(result[5] >> 4), - (u_int)(result[6] & 0xf), (u_int)(result[6] >> 4), - (u_int)(result[7] & 0xf), (u_int)(result[7] >> 4), - (u_int)(result[8] & 0xf), (u_int)(result[8] >> 4), - (u_int)(result[9] & 0xf), (u_int)(result[9] >> 4), - (u_int)(result[10] & 0xf), (u_int)(result[10] >> 4), - (u_int)(result[11] & 0xf), (u_int)(result[11] >> 4), - (u_int)(result[12] & 0xf), (u_int)(result[12] >> 4), - (u_int)(result[13] & 0xf), (u_int)(result[13] >> 4), - (u_int)(result[14] & 0xf), (u_int)(result[14] >> 4), - (u_int)(result[15] & 0xf), (u_int)(result[15] >> 4)); + "MD5:%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x", + (u_int)(result[0] & 0xf), (u_int)(result[0] >> 4), + (u_int)(result[1] & 0xf), (u_int)(result[1] >> 4), + (u_int)(result[2] & 0xf), (u_int)(result[2] >> 4), + (u_int)(result[3] & 0xf), (u_int)(result[3] >> 4), + (u_int)(result[4] & 0xf), (u_int)(result[4] >> 4), + (u_int)(result[5] & 0xf), (u_int)(result[5] >> 4), + (u_int)(result[6] & 0xf), (u_int)(result[6] >> 4), + (u_int)(result[7] & 0xf), (u_int)(result[7] >> 4), + (u_int)(result[8] & 0xf), (u_int)(result[8] >> 4), + (u_int)(result[9] & 0xf), (u_int)(result[9] >> 4), + (u_int)(result[10] & 0xf), (u_int)(result[10] >> 4), + (u_int)(result[11] & 0xf), (u_int)(result[11] >> 4), + (u_int)(result[12] & 0xf), (u_int)(result[12] >> 4), + (u_int)(result[13] & 0xf), (u_int)(result[13] >> 4), + (u_int)(result[14] & 0xf), (u_int)(result[14] >> 4), + (u_int)(result[15] & 0xf), (u_int)(result[15] >> 4)); return 1; } @@ -291,25 +291,25 @@ char *cloakcsum() /** Downsamples a 128bit result to 32bits (md5 -> unsigned int) */ static inline unsigned int downsample(char *i) { -char r[4]; + char r[4]; r[0] = i[0] ^ i[1] ^ i[2] ^ i[3]; r[1] = i[4] ^ i[5] ^ i[6] ^ i[7]; r[2] = i[8] ^ i[9] ^ i[10] ^ i[11]; r[3] = i[12] ^ i[13] ^ i[14] ^ i[15]; - - return ( ((unsigned int)r[0] << 24) + - ((unsigned int)r[1] << 16) + - ((unsigned int)r[2] << 8) + - (unsigned int)r[3]); + + return (((unsigned int)r[0] << 24) + + ((unsigned int)r[1] << 16) + + ((unsigned int)r[2] << 8) + + (unsigned int)r[3]); } static char *hidehost_ipv4(char *host) { -unsigned int a, b, c, d; -static char buf[512], res[512], res2[512], result[128]; -unsigned long n; -unsigned int alpha, beta, gamma; + unsigned int a, b, c, d; + static char buf[512], res[512], res2[512], result[128]; + unsigned long n; + unsigned int alpha, beta, gamma; /* * Output: ALPHA.BETA.GAMMA.IP @@ -326,24 +326,24 @@ unsigned int alpha, beta, gamma; /* ALPHA... */ ircsnprintf(buf, sizeof(buf), "%s:%s:%s", KEY2, host, KEY3); DoMD5(res, buf, strlen(buf)); - strlcpy(res+16, KEY1, sizeof(res)-16); /* first 16 bytes are filled, append our key.. */ - n = strlen(res+16) + 16; + strlcpy(res + 16, KEY1, sizeof(res) - 16); /* first 16 bytes are filled, append our key.. */ + n = strlen(res + 16) + 16; DoMD5(res2, res, n); alpha = downsample(res2); /* BETA... */ ircsnprintf(buf, sizeof(buf), "%s:%d.%d.%d:%s", KEY3, a, b, c, KEY1); DoMD5(res, buf, strlen(buf)); - strlcpy(res+16, KEY2, sizeof(res)-16); /* first 16 bytes are filled, append our key.. */ - n = strlen(res+16) + 16; + strlcpy(res + 16, KEY2, sizeof(res) - 16); /* first 16 bytes are filled, append our key.. */ + n = strlen(res + 16) + 16; DoMD5(res2, res, n); beta = downsample(res2); /* GAMMA... */ ircsnprintf(buf, sizeof(buf), "%s:%d.%d:%s", KEY1, a, b, KEY2); DoMD5(res, buf, strlen(buf)); - strlcpy(res+16, KEY3, sizeof(res)-16); /* first 16 bytes are filled, append our key.. */ - n = strlen(res+16) + 16; + strlcpy(res + 16, KEY3, sizeof(res) - 16); /* first 16 bytes are filled, append our key.. */ + n = strlen(res + 16) + 16; DoMD5(res2, res, n); gamma = downsample(res2); @@ -353,10 +353,10 @@ unsigned int alpha, beta, gamma; static char *hidehost_ipv6(char *host) { -unsigned int a, b, c, d, e, f, g, h; -static char buf[512], res[512], res2[512], result[128]; -unsigned long n; -unsigned int alpha, beta, gamma; + unsigned int a, b, c, d, e, f, g, h; + static char buf[512], res[512], res2[512], result[128]; + unsigned long n; + unsigned int alpha, beta, gamma; /* * Output: ALPHA:BETA:GAMMA:IP @@ -369,29 +369,29 @@ unsigned int alpha, beta, gamma; * GAMMA = downsample(md5(md5("KEY1:a:b:c:d:KEY2")+"KEY3")); */ sscanf(host, "%x:%x:%x:%x:%x:%x:%x:%x", - &a, &b, &c, &d, &e, &f, &g, &h); + &a, &b, &c, &d, &e, &f, &g, &h); /* ALPHA... */ ircsnprintf(buf, sizeof(buf), "%s:%s:%s", KEY2, host, KEY3); DoMD5(res, buf, strlen(buf)); - strlcpy(res+16, KEY1, sizeof(res)-16); /* first 16 bytes are filled, append our key.. */ - n = strlen(res+16) + 16; + strlcpy(res + 16, KEY1, sizeof(res) - 16); /* first 16 bytes are filled, append our key.. */ + n = strlen(res + 16) + 16; DoMD5(res2, res, n); alpha = downsample(res2); /* BETA... */ ircsnprintf(buf, sizeof(buf), "%s:%x:%x:%x:%x:%x:%x:%x:%s", KEY3, a, b, c, d, e, f, g, KEY1); DoMD5(res, buf, strlen(buf)); - strlcpy(res+16, KEY2, sizeof(res)-16); /* first 16 bytes are filled, append our key.. */ - n = strlen(res+16) + 16; + strlcpy(res + 16, KEY2, sizeof(res) - 16); /* first 16 bytes are filled, append our key.. */ + n = strlen(res + 16) + 16; DoMD5(res2, res, n); beta = downsample(res2); /* GAMMA... */ ircsnprintf(buf, sizeof(buf), "%s:%x:%x:%x:%x:%s", KEY1, a, b, c, d, KEY2); DoMD5(res, buf, strlen(buf)); - strlcpy(res+16, KEY3, sizeof(res)-16); /* first 16 bytes are filled, append our key.. */ - n = strlen(res+16) + 16; + strlcpy(res + 16, KEY3, sizeof(res) - 16); /* first 16 bytes are filled, append our key.. */ + n = strlen(res + 16) + 16; DoMD5(res2, res, n); gamma = downsample(res2); @@ -401,14 +401,14 @@ unsigned int alpha, beta, gamma; static char *hidehost_normalhost(char *host) { -char *p; -static char buf[512], res[512], res2[512], result[HOSTLEN+1]; -unsigned int alpha, n; + char *p; + static char buf[512], res[512], res2[512], result[HOSTLEN + 1]; + unsigned int alpha, n; ircsnprintf(buf, sizeof(buf), "%s:%s:%s", KEY1, host, KEY2); DoMD5(res, buf, strlen(buf)); - strlcpy(res+16, KEY3, sizeof(res)-16); /* first 16 bytes are filled, append our key.. */ - n = strlen(res+16) + 16; + strlcpy(res + 16, KEY3, sizeof(res) - 16); /* first 16 bytes are filled, append our key.. */ + n = strlen(res + 16) + 16; DoMD5(res2, res, n); alpha = downsample(res2); @@ -428,7 +428,7 @@ unsigned int alpha, n; else strlcat(result, p + (len - HOSTLEN), sizeof(result)); } else - ircsnprintf(result, sizeof(result), "%s-%X", CLOAK_PREFIX, alpha); + ircsnprintf(result, sizeof(result), "%s-%X", CLOAK_PREFIX, alpha); return result; } diff --git a/src/modules/cloak_none.c b/src/modules/cloak_none.c index 4cb627d8f..67f84f52a 100644 --- a/src/modules/cloak_none.c +++ b/src/modules/cloak_none.c @@ -26,11 +26,11 @@ char *cloakcsum(); int cloak_config_test(ConfigFile *, ConfigEntry *, int, int *); ModuleHeader MOD_HEADER = { - "cloak_none", - "1.0", - "Cloaking module that does nothing", - "UnrealIRCd Team", - "unrealircd-6", + "cloak_none", + "1.0", + "Cloaking module that does nothing", + "UnrealIRCd Team", + "unrealircd-6", }; MOD_TEST() diff --git a/src/modules/cloak_sha256.c b/src/modules/cloak_sha256.c index 3200a8604..b8da2ff88 100644 --- a/src/modules/cloak_sha256.c +++ b/src/modules/cloak_sha256.c @@ -35,7 +35,7 @@ int CLOAK_IP_ONLY = 0; #define KEY2 cloak_key2 #define KEY3 cloak_key3 -#define SHA256_HASH_SIZE (256/8) +#define SHA256_HASH_SIZE (256 / 8) char *hidehost(Client *client, char *host); char *cloakcsum(); @@ -49,11 +49,11 @@ static char *hidehost_normalhost(char *host); static inline unsigned int downsample(char *i); ModuleHeader MOD_HEADER = { - "cloak_sha256", - "1.0", - "Cloaking module (SHA256)", - "UnrealIRCd Team", - "unrealircd-6", + "cloak_sha256", + "1.0", + "Cloaking module (SHA256)", + "UnrealIRCd Team", + "unrealircd-6", }; MOD_TEST() @@ -100,10 +100,10 @@ MOD_UNLOAD() static int check_badrandomness(char *key) { - char gotlowcase=0, gotupcase=0, gotdigit=0; + char gotlowcase = 0, gotupcase = 0, gotdigit = 0; char *p; - for (p=key; *p; p++) + for (p = key; *p; p++) { if (islower(*p)) gotlowcase = 1; @@ -135,13 +135,12 @@ int cloak_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!ce->value) { config_error("%s:%i: set::cloak-method: no method specified. The only supported methods are: 'ip' and 'host'", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; - } else - if (strcmp(ce->value, "ip") && strcmp(ce->value, "host")) + } else if (strcmp(ce->value, "ip") && strcmp(ce->value, "host")) { config_error("%s:%i: set::cloak-method: unknown method '%s'. The only supported methods are: 'ip' and 'host'", - ce->file->filename, ce->line_number, ce->value); + ce->file->filename, ce->line_number, ce->value); errors++; } @@ -159,34 +158,35 @@ int cloak_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (check_badrandomness(cep->name)) { config_error("%s:%i: set::cloak-keys: (key %d) Keys should be mixed a-zA-Z0-9, " - "like \"a2JO6fh3Q6w4oN3s7\"", cep->file->filename, cep->line_number, keycnt); + "like \"a2JO6fh3Q6w4oN3s7\"", + cep->file->filename, cep->line_number, keycnt); errors++; } if (strlen(cep->name) < 80) { config_error("%s:%i: set::cloak-keys: (key %d) Each key should be at least 80 characters", - cep->file->filename, cep->line_number, keycnt); + cep->file->filename, cep->line_number, keycnt); errors++; } if (strlen(cep->name) > 1000) { config_error("%s:%i: set::cloak-keys: (key %d) Each key should be less than 1000 characters", - cep->file->filename, cep->line_number, keycnt); + cep->file->filename, cep->line_number, keycnt); errors++; } if (keycnt < 4) - keys[keycnt-1] = cep->name; + keys[keycnt - 1] = cep->name; } if (keycnt != 3) { config_error("%s:%i: set::cloak-keys: we want 3 values, not %i!", - ce->file->filename, ce->line_number, keycnt); + ce->file->filename, ce->line_number, keycnt); errors++; } if ((keycnt == 3) && (!strcmp(keys[0], keys[1]) || !strcmp(keys[1], keys[2]))) { config_error("%s:%i: set::cloak-keys: All your 3 keys should be RANDOM, they should not be equal", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } *errs = errors; @@ -274,11 +274,11 @@ static inline unsigned int downsample(char *i) r[1] = i[8] ^ i[9] ^ i[10] ^ i[11] ^ i[12] ^ i[13] ^ i[14] ^ i[15]; r[2] = i[16] ^ i[17] ^ i[18] ^ i[19] ^ i[20] ^ i[21] ^ i[22] ^ i[23]; r[3] = i[24] ^ i[25] ^ i[26] ^ i[27] ^ i[28] ^ i[29] ^ i[30] ^ i[31]; - - return ( ((unsigned int)r[0] << 24) + - ((unsigned int)r[1] << 16) + - ((unsigned int)r[2] << 8) + - (unsigned int)r[3]); + + return (((unsigned int)r[0] << 24) + + ((unsigned int)r[1] << 16) + + ((unsigned int)r[2] << 8) + + (unsigned int)r[3]); } static char *hidehost_ipv4(char *host) @@ -303,24 +303,24 @@ static char *hidehost_ipv4(char *host) /* ALPHA... */ ircsnprintf(buf, sizeof(buf), "%s:%s:%s", KEY2, host, KEY3); sha256hash_binary(res, buf, strlen(buf)); - strlcpy(res+SHA256_HASH_SIZE, KEY1, sizeof(res)-SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ - n = strlen(res+SHA256_HASH_SIZE) + SHA256_HASH_SIZE; + strlcpy(res + SHA256_HASH_SIZE, KEY1, sizeof(res) - SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ + n = strlen(res + SHA256_HASH_SIZE) + SHA256_HASH_SIZE; sha256hash_binary(res2, res, n); alpha = downsample(res2); /* BETA... */ ircsnprintf(buf, sizeof(buf), "%s:%d.%d.%d:%s", KEY3, a, b, c, KEY1); sha256hash_binary(res, buf, strlen(buf)); - strlcpy(res+SHA256_HASH_SIZE, KEY2, sizeof(res)-SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ - n = strlen(res+SHA256_HASH_SIZE) + SHA256_HASH_SIZE; + strlcpy(res + SHA256_HASH_SIZE, KEY2, sizeof(res) - SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ + n = strlen(res + SHA256_HASH_SIZE) + SHA256_HASH_SIZE; sha256hash_binary(res2, res, n); beta = downsample(res2); /* GAMMA... */ ircsnprintf(buf, sizeof(buf), "%s:%d.%d:%s", KEY1, a, b, KEY2); sha256hash_binary(res, buf, strlen(buf)); - strlcpy(res+SHA256_HASH_SIZE, KEY3, sizeof(res)-SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ - n = strlen(res+SHA256_HASH_SIZE) + SHA256_HASH_SIZE; + strlcpy(res + SHA256_HASH_SIZE, KEY3, sizeof(res) - SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ + n = strlen(res + SHA256_HASH_SIZE) + SHA256_HASH_SIZE; sha256hash_binary(res2, res, n); gamma = downsample(res2); @@ -346,29 +346,29 @@ static char *hidehost_ipv6(char *host) * GAMMA = downsample(sha256(sha256("KEY1:a:b:c:d:KEY2")+"KEY3")); */ sscanf(host, "%x:%x:%x:%x:%x:%x:%x:%x", - &a, &b, &c, &d, &e, &f, &g, &h); + &a, &b, &c, &d, &e, &f, &g, &h); /* ALPHA... */ ircsnprintf(buf, sizeof(buf), "%s:%s:%s", KEY2, host, KEY3); sha256hash_binary(res, buf, strlen(buf)); - strlcpy(res+SHA256_HASH_SIZE, KEY1, sizeof(res)-SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ - n = strlen(res+SHA256_HASH_SIZE) + SHA256_HASH_SIZE; + strlcpy(res + SHA256_HASH_SIZE, KEY1, sizeof(res) - SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ + n = strlen(res + SHA256_HASH_SIZE) + SHA256_HASH_SIZE; sha256hash_binary(res2, res, n); alpha = downsample(res2); /* BETA... */ ircsnprintf(buf, sizeof(buf), "%s:%x:%x:%x:%x:%x:%x:%x:%s", KEY3, a, b, c, d, e, f, g, KEY1); sha256hash_binary(res, buf, strlen(buf)); - strlcpy(res+SHA256_HASH_SIZE, KEY2, sizeof(res)-SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ - n = strlen(res+SHA256_HASH_SIZE) + SHA256_HASH_SIZE; + strlcpy(res + SHA256_HASH_SIZE, KEY2, sizeof(res) - SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ + n = strlen(res + SHA256_HASH_SIZE) + SHA256_HASH_SIZE; sha256hash_binary(res2, res, n); beta = downsample(res2); /* GAMMA... */ ircsnprintf(buf, sizeof(buf), "%s:%x:%x:%x:%x:%s", KEY1, a, b, c, d, KEY2); sha256hash_binary(res, buf, strlen(buf)); - strlcpy(res+SHA256_HASH_SIZE, KEY3, sizeof(res)-SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ - n = strlen(res+SHA256_HASH_SIZE) + SHA256_HASH_SIZE; + strlcpy(res + SHA256_HASH_SIZE, KEY3, sizeof(res) - SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ + n = strlen(res + SHA256_HASH_SIZE) + SHA256_HASH_SIZE; sha256hash_binary(res2, res, n); gamma = downsample(res2); @@ -379,13 +379,13 @@ static char *hidehost_ipv6(char *host) static char *hidehost_normalhost(char *host) { char *p; - static char buf[512], res[512], res2[512], result[HOSTLEN+1]; + static char buf[512], res[512], res2[512], result[HOSTLEN + 1]; unsigned int alpha, n; ircsnprintf(buf, sizeof(buf), "%s:%s:%s", KEY1, host, KEY2); sha256hash_binary(res, buf, strlen(buf)); - strlcpy(res+SHA256_HASH_SIZE, KEY3, sizeof(res)-SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ - n = strlen(res+SHA256_HASH_SIZE) + SHA256_HASH_SIZE; + strlcpy(res + SHA256_HASH_SIZE, KEY3, sizeof(res) - SHA256_HASH_SIZE); /* first bytes are filled, append our key.. */ + n = strlen(res + SHA256_HASH_SIZE) + SHA256_HASH_SIZE; sha256hash_binary(res2, res, n); alpha = downsample(res2); @@ -405,7 +405,7 @@ static char *hidehost_normalhost(char *host) else strlcat(result, p + (len - HOSTLEN), sizeof(result)); } else - ircsnprintf(result, sizeof(result), "%s-%X", CLOAK_PREFIX, alpha); + ircsnprintf(result, sizeof(result), "%s-%X", CLOAK_PREFIX, alpha); return result; } diff --git a/src/modules/close.c b/src/modules/close.c index a73299099..a42b244dc 100644 --- a/src/modules/close.c +++ b/src/modules/close.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_close); -#define MSG_CLOSE "CLOSE" +#define MSG_CLOSE "CLOSE" -ModuleHeader MOD_HEADER - = { - "close", - "5.0", - "command /close", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "close", + "5.0", + "command /close", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -58,9 +57,9 @@ MOD_UNLOAD() CMD_FUNC(cmd_close) { Client *target, *next; - int closed = 0; + int closed = 0; - if (!ValidatePermissionsForPath("server:close",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:close", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -69,7 +68,7 @@ CMD_FUNC(cmd_close) list_for_each_entry_safe(target, next, &unknown_list, lclient_node) { sendnumeric(client, RPL_CLOSING, - get_client_name(target, TRUE), target->status); + get_client_name(target, TRUE), target->status); exit_client(target, NULL, "Oper Closing"); closed++; } diff --git a/src/modules/connect-flood.c b/src/modules/connect-flood.c index 38e6ed60e..15d217557 100644 --- a/src/modules/connect-flood.c +++ b/src/modules/connect-flood.c @@ -6,22 +6,20 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "connect-flood", - "6.0.0", - "set::anti-flood::connect-flood", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "connect-flood", + "6.0.0", + "set::anti-flood::connect-flood", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Defines */ #define THROTTLING_HASH_TABLE_SIZE 8192 /* Structs */ typedef struct ThrottlingBucket ThrottlingBucket; -struct ThrottlingBucket -{ +struct ThrottlingBucket { ThrottlingBucket *prev, *next; char *ip; time_t since; @@ -100,9 +98,9 @@ int connect_flood_throttle(Client *client, int exitflags) if (!(val = throttle_can_connect(client))) { ircsnprintf(zlinebuf, sizeof(zlinebuf), - "Throttled: Reconnecting too fast - " - "Email %s for more information.", - KLINE_ADDRESS); + "Throttled: Reconnecting too fast - " + "Email %s for more information.", + KLINE_ADDRESS); /* There are two reasons why we can't use exit_client() here: * 1) Because the HOOKTYPE_IP_CHANGE call may be too deep. * Eg: read_packet -> webserver_packet_in -> @@ -114,8 +112,7 @@ int connect_flood_throttle(Client *client, int exitflags) */ dead_socket(client, zlinebuf); return HOOK_DENY; - } - else if (val == 1) + } else if (val == 1) add_throttling_bucket(client); return 0; @@ -153,10 +150,10 @@ void add_throttling_timeout_timer(ModuleInfo *modinfo) if (!THROTTLING_PERIOD) { - v = 120*1000; + v = 120 * 1000; } else { - v = (THROTTLING_PERIOD*1000)/2; + v = (THROTTLING_PERIOD * 1000) / 2; if (v > 5000) v = 5000; /* run at least every 5s */ if (v < 1000) @@ -175,7 +172,7 @@ ThrottlingBucket *find_throttling_bucket(Client *client) { int hash; ThrottlingBucket *p; - char ip[HOSTLEN+1]; + char ip[HOSTLEN + 1]; /* Apply set::default-ipv6-clone-mask: bucket is keyed by the network * portion of the IP, so all addresses in the same /64 share one bucket. @@ -218,7 +215,7 @@ void add_throttling_bucket(Client *client) { int hash; ThrottlingBucket *n; - char ip[HOSTLEN+1]; + char ip[HOSTLEN + 1]; /* Apply set::default-ipv6-clone-mask: bucket is keyed by the network * portion of the IP, so all addresses in the same /64 share one bucket. @@ -255,7 +252,7 @@ int throttle_can_connect(Client *client) { if (find_tkl_exception(TKL_CONNECT_FLOOD, client)) return 2; - if (b->count+1 > (THROTTLING_COUNT ? THROTTLING_COUNT : 3)) + if (b->count + 1 > (THROTTLING_COUNT ? THROTTLING_COUNT : 3)) return 0; b->count++; return 2; diff --git a/src/modules/connect.c b/src/modules/connect.c index 14306f02b..c48360918 100644 --- a/src/modules/connect.c +++ b/src/modules/connect.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_connect); -#define MSG_CONNECT "CONNECT" +#define MSG_CONNECT "CONNECT" -ModuleHeader MOD_HEADER - = { - "connect", - "5.0", - "command /connect", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "connect", + "5.0", + "command /connect", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_CONNECT, cmd_connect, MAXPARA, CMD_USER|CMD_SERVER); /* hmm.. server.. really? */ + CommandAdd(modinfo->handle, MSG_CONNECT, cmd_connect, MAXPARA, CMD_USER | CMD_SERVER); /* hmm.. server.. really? */ MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -54,24 +53,25 @@ MOD_UNLOAD() /*********************************************************************** * cmd_connect() - Added by Jto 11 Feb 1989 - ***********************************************************************//* + ***********************************************************************/ + /* ** cmd_connect ** parv[1] = servername */ CMD_FUNC(cmd_connect) { - int retval; - ConfigItem_link *aconf; + int retval; + ConfigItem_link *aconf; Client *server; const char *str; - if (!IsServer(client) && MyConnect(client) && !ValidatePermissionsForPath("route:global",client,NULL,NULL,NULL) && parc > 3) - { /* Only allow LocOps to make */ + if (!IsServer(client) && MyConnect(client) && !ValidatePermissionsForPath("route:global", client, NULL, NULL, NULL) && parc > 3) + { /* Only allow LocOps to make */ /* local CONNECTS --SRB */ sendnumeric(client, ERR_NOPRIVILEGES); return; } - if (!IsServer(client) && MyUser(client) && !ValidatePermissionsForPath("route:local",client,NULL,NULL,NULL) && parc <= 3) + if (!IsServer(client) && MyUser(client) && !ValidatePermissionsForPath("route:local", client, NULL, NULL, NULL) && parc <= 3) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -88,7 +88,7 @@ CMD_FUNC(cmd_connect) if ((server = find_server_quick(parv[1]))) { sendnotice(client, "*** Connect: Server %s already exists from %s.", - parv[1], server->direction->name); + parv[1], server->direction->name); return; } @@ -96,16 +96,16 @@ CMD_FUNC(cmd_connect) if (!aconf) { sendnotice(client, - "*** Connect: Server %s is not configured for linking", - parv[1]); + "*** Connect: Server %s is not configured for linking", + parv[1]); return; } if (!aconf->outgoing.hostname && !aconf->outgoing.file) { sendnotice(client, - "*** Connect: Server %s is not configured to be an outgoing link (has a link block, but no link::outgoing::hostname or link::outgoing::file)", - parv[1]); + "*** Connect: Server %s is not configured to be an outgoing link (has a link block, but no link::outgoing::hostname or link::outgoing::file)", + parv[1]); return; } @@ -116,8 +116,8 @@ CMD_FUNC(cmd_connect) } unreal_log(ULOG_INFO, "link", "LINK_REQUEST", client, - "CONNECT: Link to $link_block requested by $client", - log_data_link_block(aconf)); + "CONNECT: Link to $link_block requested by $client", + log_data_link_block(aconf)); connect_server(aconf, client, NULL); } diff --git a/src/modules/connthrottle.c b/src/modules/connthrottle.c index 0afa26578..1936bfc1c 100644 --- a/src/modules/connthrottle.c +++ b/src/modules/connthrottle.c @@ -13,14 +13,13 @@ #define CALLBACKTYPE_REPUTATION_STARTTIME 5 #endif -ModuleHeader MOD_HEADER - = { - "connthrottle", - CONNTHROTTLE_VERSION, - "Connection throttler - by Syzop", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "connthrottle", + CONNTHROTTLE_VERSION, + "Connection throttler - by Syzop", + "UnrealIRCd Team", + "unrealircd-6", +}; typedef struct { int count; @@ -50,16 +49,16 @@ typedef struct { typedef struct UCounter UCounter; struct UCounter { - ThrottleCounter local; /**< Local counter */ - ThrottleCounter global; /**< Global counter */ - int rejected_clients; /**< Number of rejected clients this minute */ - int allowed_except; /**< Number of allowed clients - on except list */ - int allowed_unknown_users; /**< Number of allowed clients - not on except list */ - char disabled; /**< Module disabled by oper? */ - int throttling_this_minute; /**< Did we do any throttling this minute? */ - int throttling_previous_minute; /**< Did we do any throttling previous minute? */ + ThrottleCounter local; /**< Local counter */ + ThrottleCounter global; /**< Global counter */ + int rejected_clients; /**< Number of rejected clients this minute */ + int allowed_except; /**< Number of allowed clients - on except list */ + int allowed_unknown_users; /**< Number of allowed clients - not on except list */ + char disabled; /**< Module disabled by oper? */ + int throttling_this_minute; /**< Did we do any throttling this minute? */ + int throttling_previous_minute; /**< Did we do any throttling previous minute? */ int throttling_banner_displayed;/**< Big we-are-now-throttling banner displayed? */ - time_t next_event; /**< When is next event? (for "last 60 seconds" stats) */ + time_t next_event; /**< When is next event? (for "last 60 seconds" stats) */ }; UCounter *ucounter = NULL; @@ -81,12 +80,12 @@ RPC_CALL_FUNC(rpc_connthrottle_reset); /* IPv6 wider-prefix bucket tracking (/56, /48, /32) */ -#define CT_NUM_TIERS 3 +#define CT_NUM_TIERS 3 #define CT_BUCKET_HASH_SIZE 2048 #ifdef DEBUGMODE /** Self-check of IPv6 CIDR limits every msec */ -#define CONNTHROTTLE_CHECK 1000 + #define CONNTHROTTLE_CHECK 1000 #endif /* Per-client classification stored in our ModData slot. @@ -94,10 +93,10 @@ RPC_CALL_FUNC(rpc_connthrottle_reset); * "this client has not been added to our buckets yet". */ typedef enum { - CT_CATEGORY_NONE = 0, - CT_CATEGORY_KNOWN_USERS = 1, + CT_CATEGORY_NONE = 0, + CT_CATEGORY_KNOWN_USERS = 1, CT_CATEGORY_EXCEPTED_UNKNOWNS = 2, - CT_CATEGORY_UNKNOWN_USERS = 3, + CT_CATEGORY_UNKNOWN_USERS = 3, } ConnThrottleCategory; typedef struct ConnThrottleBucket ConnThrottleBucket; @@ -114,7 +113,7 @@ struct ConnThrottleBucket { #endif }; -static const int ct_tier_prefix[CT_NUM_TIERS] = { 56, 48, 32 }; +static const int ct_tier_prefix[CT_NUM_TIERS] = {56, 48, 32}; static ConnThrottleBucket **ct_bucket_hash[CT_NUM_TIERS]; static char *siphashkey_ct_buckets = NULL; static ModDataInfo *connthrottle_md = NULL; @@ -122,7 +121,7 @@ static ModDataInfo *connthrottle_md = NULL; /* Per-client classification cached in ModData. CT_CATEGORY_NONE means * "this client has not been added to our buckets yet" (or has been removed). */ -#define CT_CATEGORY(client) moddata_client((client), connthrottle_md).l +#define CT_CATEGORY(client) moddata_client((client), connthrottle_md).l static void ct_make_rawip(Client *client, int tier, char *out); static uint64_t ct_hash_bucket(const char *masked); @@ -148,24 +147,26 @@ EVENT(ct_check); MOD_TEST() { memset(&cfg, 0, sizeof(cfg)); - + /* Defaults: */ - cfg.local.count = 20; cfg.local.period = 60; - cfg.global.count = 30; cfg.global.period = 60; - cfg.start_delay = 180; /* 3 minutes */ - cfg.reputation_gathering = 7*86400; /* 1 week */ + cfg.local.count = 20; + cfg.local.period = 60; + cfg.global.count = 30; + cfg.global.period = 60; + cfg.start_delay = 180; /* 3 minutes */ + cfg.reputation_gathering = 7 * 86400; /* 1 week */ safe_strdup(cfg.reason, "Throttled: Too many users trying to connect, please wait a while and try again"); cfg.except = safe_alloc(sizeof(SecurityGroup)); cfg.except->reputation_score = 24; cfg.except->identified = 1; cfg.except->webirc = 0; - cfg.ipv6_unknown_users_limit[0] = 8; /* /56 */ - cfg.ipv6_unknown_users_limit[1] = 32; /* /48 */ - cfg.ipv6_unknown_users_limit[2] = 256; /* /32 */ + cfg.ipv6_unknown_users_limit[0] = 8; /* /56 */ + cfg.ipv6_unknown_users_limit[1] = 32; /* /48 */ + cfg.ipv6_unknown_users_limit[2] = 256; /* /32 */ HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, ct_config_test); HookAdd(modinfo->handle, HOOKTYPE_CONFIGPOSTTEST, 0, ct_config_posttest); - + return MOD_SUCCESS; } @@ -187,7 +188,7 @@ MOD_INIT() memset(&mreq, 0, sizeof(mreq)); mreq.name = "connthrottle_category"; mreq.type = MODDATATYPE_CLIENT; - mreq.sync = 0; /* local only, no S2S sync */ + mreq.sync = 0; /* local only, no S2S sync */ connthrottle_md = ModDataAdd(modinfo->handle, mreq); if (!connthrottle_md) { @@ -207,7 +208,7 @@ MOD_INIT() HookAdd(modinfo->handle, HOOKTYPE_KNOWN_USER_CACHE_CHANGE, 0, ct_known_user_cache_change); HookAdd(modinfo->handle, HOOKTYPE_STATS, 0, stats_connthrottle); - CommandAdd(modinfo->handle, MSG_THROTTLE, ct_throttle, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_THROTTLE, ct_throttle, MAXPARA, CMD_USER | CMD_SERVER); /* RPC handlers */ memset(&r, 0, sizeof(r)); @@ -295,18 +296,17 @@ int ct_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::connthrottle.. */ if (!ce || !ce->name || strcmp(ce->name, "connthrottle")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "except")) { test_match_block(cf, cep, &errors); - } else - if (!strcmp(cep->name, "known-users")) + } else if (!strcmp(cep->name, "known-users")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -317,15 +317,13 @@ int ct_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (cnt < 1) { config_error("%s:%i: set::connthrottle::known-users::minimum-reputation-score should be at least 1", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; continue; } - } else - if (!strcmp(cepp->name, "sasl-bypass")) + } else if (!strcmp(cepp->name, "sasl-bypass")) { - } else - if (!strcmp(cepp->name, "webirc-bypass")) + } else if (!strcmp(cepp->name, "webirc-bypass")) { } else { @@ -334,8 +332,7 @@ int ct_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) errors++; } } - } else - if (!strcmp(cep->name, "new-users")) + } else if (!strcmp(cep->name, "new-users")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -347,23 +344,22 @@ int ct_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) (cnt < 1) || (cnt > 2000000000) || (period > 2000000000)) { config_error("%s:%i: set::connthrottle::new-users::local-throttle error. " - "Syntax is : (eg 6:60), " - "and count and period should be non-zero.", - cepp->file->filename, cepp->line_number); + "Syntax is : (eg 6:60), " + "and count and period should be non-zero.", + cepp->file->filename, cepp->line_number); errors++; continue; } - } else - if (!strcmp(cepp->name, "global-throttle")) + } else if (!strcmp(cepp->name, "global-throttle")) { int cnt, period; if (!config_parse_flood(cepp->value, &cnt, &period) || (cnt < 1) || (cnt > 2000000000) || (period > 2000000000)) { config_error("%s:%i: set::connthrottle::new-users::global-throttle error. " - "Syntax is : (eg 6:60), " - "and count and period should be non-zero.", - cepp->file->filename, cepp->line_number); + "Syntax is : (eg 6:60), " + "and count and period should be non-zero.", + cepp->file->filename, cepp->line_number); errors++; continue; } @@ -374,8 +370,7 @@ int ct_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) errors++; } } - } else - if (!strcmp(cep->name, "disabled-when")) + } else if (!strcmp(cep->name, "disabled-when")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -386,12 +381,11 @@ int ct_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if ((cnt < 0) || (cnt > 3600)) { config_error("%s:%i: set::connthrottle::disabled-when::start-delay should be in range 0-3600", - cepp->file->filename, cepp->line_number); + cepp->file->filename, cepp->line_number); errors++; continue; } - } else - if (!strcmp(cepp->name, "reputation-gathering")) + } else if (!strcmp(cepp->name, "reputation-gathering")) { } else { @@ -400,12 +394,10 @@ int ct_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) errors++; } } - } else - if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { CheckNull(cep); - } else - if (!strcmp(cep->name, "ipv6-unknown-users-limit")) + } else if (!strcmp(cep->name, "ipv6-unknown-users-limit")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -441,12 +433,12 @@ int ct_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } else { config_error("%s:%i: unknown directive set::connthrottle::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } } - + *errs = errors; return errors ? -1 : 1; } @@ -458,18 +450,17 @@ int ct_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::connthrottle.. */ if (!ce || !ce->name || strcmp(ce->name, "connthrottle")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "except")) { conf_match_block(cf, cep, &cfg.except); - } else - if (!strcmp(cep->name, "known-users")) + } else if (!strcmp(cep->name, "known-users")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -480,8 +471,7 @@ int ct_config_run(ConfigFile *cf, ConfigEntry *ce, int type) else if (!strcmp(cepp->name, "webirc-bypass")) cfg.except->webirc = config_checkval(cepp->value, CFG_YESNO); } - } else - if (!strcmp(cep->name, "new-users")) + } else if (!strcmp(cep->name, "new-users")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -490,8 +480,7 @@ int ct_config_run(ConfigFile *cf, ConfigEntry *ce, int type) else if (!strcmp(cepp->name, "global-throttle")) config_parse_flood(cepp->value, &cfg.global.count, &cfg.global.period); } - } else - if (!strcmp(cep->name, "disabled-when")) + } else if (!strcmp(cep->name, "disabled-when")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -500,14 +489,12 @@ int ct_config_run(ConfigFile *cf, ConfigEntry *ce, int type) else if (!strcmp(cepp->name, "reputation-gathering")) cfg.reputation_gathering = config_checkval(cepp->value, CFG_TIME); } - } else - if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { safe_free(cfg.reason); - cfg.reason = safe_alloc(strlen(cep->value)+16); + cfg.reason = safe_alloc(strlen(cep->value) + 16); sprintf(cfg.reason, "Throttled: %s", cep->value); - } else - if (!strcmp(cep->name, "ipv6-unknown-users-limit")) + } else if (!strcmp(cep->name, "ipv6-unknown-users-limit")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -580,11 +567,11 @@ EVENT(connthrottle_evt) ucounter->throttling_banner_displayed = 0; /* reset */ } -#define THROT_LOCAL 1 +#define THROT_LOCAL 1 #define THROT_GLOBAL 2 int ct_pre_lconnect(Client *client) { - int throttle=0; + int throttle = 0; int score; if (me.local->creationtime + cfg.start_delay > TStime()) @@ -603,11 +590,11 @@ int ct_pre_lconnect(Client *client) /* If we reach this then the user is NEW */ /* +1 global client would reach global limit? */ - if ((TStime() - ucounter->global.t < cfg.global.period) && (ucounter->global.count+1 > cfg.global.count)) + if ((TStime() - ucounter->global.t < cfg.global.period) && (ucounter->global.count + 1 > cfg.global.count)) throttle |= THROT_GLOBAL; /* +1 local client would reach local limit? */ - if ((TStime() - ucounter->local.t < cfg.local.period) && (ucounter->local.count+1 > cfg.local.count)) + if ((TStime() - ucounter->local.t < cfg.local.period) && (ucounter->local.count + 1 > cfg.local.count)) throttle |= THROT_LOCAL; if (throttle) @@ -640,7 +627,8 @@ void bump_connect_counter(int local_connect) { ucounter->local.t = TStime(); ucounter->local.count = 1; - } else { + } else + { ucounter->local.count++; } } @@ -650,7 +638,8 @@ void bump_connect_counter(int local_connect) { ucounter->global.t = TStime(); ucounter->global.count = 1; - } else { + } else + { ucounter->global.count++; } } @@ -750,7 +739,7 @@ void ct_off(Client *client) ucounter->disabled = 1; unreal_log(ULOG_WARNING, "connthrottle", "CONNTHROTTLE_MODULE_DISABLED", client, - "[ConnThrottle] $client.details DISABLED the connthrottle module."); + "[ConnThrottle] $client.details DISABLED the connthrottle module."); } void ct_on(Client *client) @@ -759,7 +748,7 @@ void ct_on(Client *client) return; /* Already on */ unreal_log(ULOG_WARNING, "connthrottle", "CONNTHROTTLE_MODULE_ENABLED", client, - "[ConnThrottle] $client.details ENABLED the connthrottle module."); + "[ConnThrottle] $client.details ENABLED the connthrottle module."); ucounter->disabled = 0; } @@ -767,7 +756,7 @@ void ct_reset(Client *client) { memset(ucounter, 0, sizeof(UCounter)); unreal_log(ULOG_WARNING, "connthrottle", "CONNTHROTTLE_RESET", client, - "[ConnThrottle] $client.details did a RESET on the statistics/counters."); + "[ConnThrottle] $client.details did a RESET on the statistics/counters."); } CMD_FUNC(ct_throttle) @@ -788,8 +777,7 @@ CMD_FUNC(ct_throttle) { sendnotice(client, "STATUS:"); sendnotice(client, "%s", ct_module_status_text()); - } else - if (!strcasecmp(parv[1], "OFF")) + } else if (!strcasecmp(parv[1], "OFF")) { if (ucounter->disabled == 1) { @@ -797,8 +785,7 @@ CMD_FUNC(ct_throttle) return; } ct_off(client); - } else - if (!strcasecmp(parv[1], "ON")) + } else if (!strcasecmp(parv[1], "ON")) { if (ucounter->disabled == 0) { @@ -806,8 +793,7 @@ CMD_FUNC(ct_throttle) return; } ct_on(client); - } else - if (!strcasecmp(parv[1], "RESET")) + } else if (!strcasecmp(parv[1], "RESET")) { ct_reset(client); } else @@ -877,14 +863,14 @@ static void ct_check_walk_one(Client *client) category = CT_CATEGORY(client); if (category == CT_CATEGORY_NONE) - return; /* not in our buckets */ + return; /* not in our buckets */ if (!IsIPV6(client) || !client->ip) { unreal_log(ULOG_ERROR, "connthrottle", "BUG_CT_CHECK_NO_IP", client, "[BUG] connthrottle counter check: client has category but no IPv6 IP"); -#ifdef DEBUGMODE + #ifdef DEBUGMODE abort(); -#endif + #endif return; } for (tier = 0; tier < CT_NUM_TIERS; tier++) @@ -896,17 +882,24 @@ static void ct_check_walk_one(Client *client) unreal_log(ULOG_ERROR, "connthrottle", "BUG_CT_CHECK_NO_BUCKET", client, "[BUG] connthrottle counter check: client has category but no bucket at /$prefix", log_data_integer("prefix", ct_tier_prefix[tier])); -#ifdef DEBUGMODE + #ifdef DEBUGMODE abort(); -#endif + #endif continue; } switch (category) { - case CT_CATEGORY_KNOWN_USERS: b->check_known++; break; - case CT_CATEGORY_EXCEPTED_UNKNOWNS: b->check_excepted++; break; - case CT_CATEGORY_UNKNOWN_USERS: b->check_unknown++; break; - case CT_CATEGORY_NONE: break; /* unreachable per filter */ + case CT_CATEGORY_KNOWN_USERS: + b->check_known++; + break; + case CT_CATEGORY_EXCEPTED_UNKNOWNS: + b->check_excepted++; + break; + case CT_CATEGORY_UNKNOWN_USERS: + b->check_unknown++; + break; + case CT_CATEGORY_NONE: + break; /* unreachable per filter */ } } } @@ -923,9 +916,9 @@ EVENT(ct_check) b->check_known = b->check_excepted = b->check_unknown = 0; list_for_each_entry(client, &client_list, client_node) - ct_check_walk_one(client); + ct_check_walk_one(client); list_for_each_entry(client, &unknown_list, lclient_node) - ct_check_walk_one(client); + ct_check_walk_one(client); for (tier = 0; tier < CT_NUM_TIERS; tier++) { @@ -933,9 +926,9 @@ EVENT(ct_check) { for (b = ct_bucket_hash[tier][i]; b; b = b->next) { - if (b->check_known != b->known_users || + if (b->check_known != b->known_users || b->check_excepted != b->excepted_unknowns || - b->check_unknown != b->unknown_users) + b->check_unknown != b->unknown_users) { unreal_log(ULOG_ERROR, "connthrottle", "BUG_CT_CHECK_DRIFT", NULL, "[BUG] connthrottle bucket counter drift at /$prefix: " @@ -948,9 +941,9 @@ EVENT(ct_check) log_data_integer("exp_k", b->check_known), log_data_integer("exp_e", b->check_excepted), log_data_integer("exp_u", b->check_unknown)); -#ifdef DEBUGMODE + #ifdef DEBUGMODE abort(); -#endif + #endif } } } @@ -1100,10 +1093,17 @@ static void ct_bucket_increment(ConnThrottleBucket *b, ConnThrottleCategory cate { switch (category) { - case CT_CATEGORY_NONE: break; /* not classified: no-op */ - case CT_CATEGORY_KNOWN_USERS: b->known_users++; break; - case CT_CATEGORY_EXCEPTED_UNKNOWNS: b->excepted_unknowns++; break; - case CT_CATEGORY_UNKNOWN_USERS: b->unknown_users++; break; + case CT_CATEGORY_NONE: + break; /* not classified: no-op */ + case CT_CATEGORY_KNOWN_USERS: + b->known_users++; + break; + case CT_CATEGORY_EXCEPTED_UNKNOWNS: + b->excepted_unknowns++; + break; + case CT_CATEGORY_UNKNOWN_USERS: + b->unknown_users++; + break; } } @@ -1111,10 +1111,17 @@ static void ct_bucket_decrement(ConnThrottleBucket *b, ConnThrottleCategory cate { switch (category) { - case CT_CATEGORY_NONE: break; /* not classified: no-op */ - case CT_CATEGORY_KNOWN_USERS: b->known_users--; break; - case CT_CATEGORY_EXCEPTED_UNKNOWNS: b->excepted_unknowns--; break; - case CT_CATEGORY_UNKNOWN_USERS: b->unknown_users--; break; + case CT_CATEGORY_NONE: + break; /* not classified: no-op */ + case CT_CATEGORY_KNOWN_USERS: + b->known_users--; + break; + case CT_CATEGORY_EXCEPTED_UNKNOWNS: + b->excepted_unknowns--; + break; + case CT_CATEGORY_UNKNOWN_USERS: + b->unknown_users--; + break; } if ((b->known_users < 0) || (b->excepted_unknowns < 0) || (b->unknown_users < 0)) { @@ -1251,13 +1258,13 @@ const char *ct_allow_client(Client *client, ConfigItem_allow *aconf) if (b && (b->unknown_users > effective_limit)) { unreal_log(ULOG_INFO, "connthrottle", "CONNTHROTTLE_IPV6_LIMIT", client, - "Client $client.name with IP $client.ip rejected: connthrottle ipv6-unknown-users-limit (cidr-$prefix_len, max $max) exceeded for $prefix_addr/$prefix_len ($unknown_users unknown / $excepted_users excepted / $known_users known)", - log_data_string("prefix_addr", format_ipv6_addr(masked)), - log_data_integer("prefix_len", ct_tier_prefix[tier]), - log_data_integer("max", effective_limit), - log_data_integer("unknown_users", b->unknown_users), - log_data_integer("excepted_users", b->excepted_unknowns), - log_data_integer("known_users", b->known_users)); + "Client $client.name with IP $client.ip rejected: connthrottle ipv6-unknown-users-limit (cidr-$prefix_len, max $max) exceeded for $prefix_addr/$prefix_len ($unknown_users unknown / $excepted_users excepted / $known_users known)", + log_data_string("prefix_addr", format_ipv6_addr(masked)), + log_data_integer("prefix_len", ct_tier_prefix[tier]), + log_data_integer("max", effective_limit), + log_data_integer("unknown_users", b->unknown_users), + log_data_integer("excepted_users", b->excepted_unknowns), + log_data_integer("known_users", b->known_users)); return format_ipv6_prefix_reject_message( iConf.reject_message_too_many_new_connections_ipv6_range, masked, ct_tier_prefix[tier]); @@ -1276,7 +1283,7 @@ int ct_remote_connect_buckets(Client *client) ConnThrottleCategory category; if (IsULine(client)) - return 0; /* U-lined service: skip */ + return 0; /* U-lined service: skip */ if (!IsIPV6(client) || !client->ip) return 0; if (CT_CATEGORY(client) != CT_CATEGORY_NONE) @@ -1355,7 +1362,7 @@ static void ct_buckets_rebuild(void) list_for_each_entry(client, &client_list, client_node) { if (!IsUser(client) || IsULine(client)) - continue; /* only regular IRC users; skip servers, services, pre-registration */ + continue; /* only regular IRC users; skip servers, services, pre-registration */ if (!IsIPV6(client) || !client->ip) continue; category = ct_classify(client); @@ -1365,7 +1372,7 @@ static void ct_buckets_rebuild(void) list_for_each_entry(client, &unknown_list, lclient_node) { if (!IsUser(client) || IsULine(client)) - continue; /* only regular IRC users; skip servers, services, pre-registration */ + continue; /* only regular IRC users; skip servers, services, pre-registration */ if (!IsIPV6(client) || !client->ip) continue; category = ct_classify(client); diff --git a/src/modules/creationtime.c b/src/modules/creationtime.c index f89eee985..bf51f9fce 100644 --- a/src/modules/creationtime.c +++ b/src/modules/creationtime.c @@ -6,14 +6,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "creationtime", - "6.1", - "Store and retrieve creation time of clients", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "creationtime", + "6.1", + "Store and retrieve creation time of clients", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ void creationtime_free(ModData *m); @@ -25,7 +24,11 @@ int creationtime_whois(Client *client, Client *target); ModDataInfo *creationtime_md; /* Module Data structure which we acquire */ -#define SetCreationTime(x,y) do { moddata_client(x, creationtime_md).ll = y; } while(0) +#define SetCreationTime(x, y) \ + do \ + { \ + moddata_client(x, creationtime_md).ll = y; \ + } while (0) MOD_INIT() { diff --git a/src/modules/crule.c b/src/modules/crule.c index fea0f2994..7e4374d87 100644 --- a/src/modules/crule.c +++ b/src/modules/crule.c @@ -21,13 +21,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "crule", - "1.0.1", - "Crule support for and deny link::rule and spamfilter::rule", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "crule", + "1.0.1", + "Crule support for and deny link::rule and spamfilter::rule", + "UnrealIRCd Team", + "unrealircd-6", }; /* Originally by Tony Vencill (Tonto on IRC) @@ -88,7 +87,7 @@ enum crule_token { CR_WORD /**< Something that looks like a hostmask (alphanumerics, "*?.-"). */ }; -#define IsComparisson(x) ((x == CR_EQUAL) || (x == CR_LESS_THAN) || (x == CR_MORE_THAN)) +#define IsComparisson(x) ((x == CR_EQUAL) || (x == CR_LESS_THAN) || (x == CR_MORE_THAN)) /** Parser error codes. */ typedef enum crule_errcode crule_errcode; @@ -110,7 +109,7 @@ enum crule_errcode { int _crule_test(const char *rule); CRuleNode *_crule_parse(const char *rule); -void _crule_free(CRuleNode**); +void _crule_free(CRuleNode **); int _crule_eval(crule_context *context, CRuleNode *rule); const char *_crule_errstring(int errcode); @@ -190,17 +189,17 @@ static int crule_parsearglist(CRuleNode *, crule_token *, const char **); /* error messages */ char *crule_errstr[] = { - "Unknown error", /* NOERR? - for completeness */ - "Unexpected token", /* UNEXPCTTOK */ - "Unknown token", /* UNKNWTOK */ - "And expr expected", /* EXPCTAND */ - "Or expr expected", /* EXPCTOR */ - "Primary expected", /* EXPCTPRIM */ - "( expected", /* EXPCTOPEN */ - ") expected", /* EXPCTCLOSE */ - "Unknown function", /* UNKNWFUNC */ - "Argument mismatch", /* ARGMISMAT */ - "Missing value in comparisson", /* CR_EXPCTVALUE */ + "Unknown error", /* NOERR? - for completeness */ + "Unexpected token", /* UNEXPCTTOK */ + "Unknown token", /* UNKNWTOK */ + "And expr expected", /* EXPCTAND */ + "Or expr expected", /* EXPCTOR */ + "Primary expected", /* EXPCTPRIM */ + "( expected", /* EXPCTOPEN */ + ") expected", /* EXPCTCLOSE */ + "Unknown function", /* UNKNWFUNC */ + "Argument mismatch", /* ARGMISMAT */ + "Missing value in comparisson", /* CR_EXPCTVALUE */ }; /* function table - null terminated */ @@ -212,67 +211,67 @@ struct crule_funclistent { /* This table MUST remain sorted alphabetically (due to binary search) */ struct crule_funclistent crule_funclist[] = { - {"bytes_received", 0, crule_bytes_received}, - {"bytes_sent", 0, crule_bytes_sent}, - {"cap_set", 1, crule_cap_set}, - {"cap_version", 0, crule_cap_version}, - {"channel_count", 0, crule_channel_count}, - {"channel_member_count", 0, crule_channel_member_count}, - {"connected", 1, crule_connected}, - {"connections_from_ip", 0, crule_connections_from_ip}, - {"destination", 1, crule_destination}, - {"digit_percentage", 0, crule_digit_percentage}, - {"directcon", 1, crule_directcon}, - {"directop", 0, crule_directop}, - {"has_channel_mode", 1, crule_has_channel_mode}, - {"has_swhois", 0, crule_has_swhois}, - {"has_user_mode", 1, crule_has_user_mode}, - {"idle_time", 0, crule_idle_time}, - {"in_channel", 1, crule_in_channel}, - {"in_security_group", 1, crule_in_security_group}, - {"inchannel", 1, crule_in_channel}, // old name, keep it around for now.. - {"is_away", 0, crule_away}, - {"is_identified", 0, crule_is_identified}, - {"is_local", 0, crule_is_local}, - {"is_oper", 0, crule_is_oper}, - {"is_tls", 0, crule_tls}, - {"is_webirc", 0, crule_is_webirc}, - {"is_websocket", 0, crule_is_websocket}, - {"match_account", 1, crule_match_account}, - {"match_asn", 1, crule_match_asn}, - {"match_asname", 1, crule_match_asname}, - {"match_away", 1, crule_match_away}, - {"match_certfp", 1, crule_match_certfp}, - {"match_class", 1, crule_match_class}, - {"match_country", 1, crule_match_country}, - {"match_ip", 1, crule_match_ip}, - {"match_mask", 1, crule_match_mask}, - {"match_operclass", 1, crule_match_operclass}, - {"match_operlogin", 1, crule_match_operlogin}, - {"match_realhost", 1, crule_match_realhost}, - {"match_realname", 1, crule_match_realname}, - {"match_server", 1, crule_match_server}, - {"match_sni", 1, crule_match_sni}, - {"match_tls_cipher", 1, crule_match_tls_cipher}, - {"match_vhost", 1, crule_match_vhost}, - {"max_repeat_count", 0, crule_max_repeat_count}, - {"messages_received", 0, crule_messages_received}, - {"messages_sent", 0, crule_messages_sent}, - {"mixed_utf8_score", 0, crule_mixed_utf8_score}, - {"non_ascii_percentage", 0, crule_non_ascii_percentage}, - {"online_time", 0, crule_online_time}, - {"reputation", 0, crule_reputation}, - {"server_flood_count", 1, crule_server_flood_count}, - {"server_port", 0, crule_server_port}, - {"tag", 1, crule_tag}, - {"text_byte_count", 0, crule_text_byte_count}, - {"text_character_count", 0, crule_text_character_count}, - {"total_channel_flood_count", 1, crule_total_channel_flood_count}, - {"unicode_block_count", 0, crule_unicode_block_count}, - {"unicode_count", 1, crule_unicode_count}, - {"uppercase_percentage", 0, crule_uppercase_percentage}, - {"via", 2, crule_via}, - {"word_count", 0, crule_word_count}, + {"bytes_received", 0, crule_bytes_received}, + {"bytes_sent", 0, crule_bytes_sent}, + {"cap_set", 1, crule_cap_set}, + {"cap_version", 0, crule_cap_version}, + {"channel_count", 0, crule_channel_count}, + {"channel_member_count", 0, crule_channel_member_count}, + {"connected", 1, crule_connected}, + {"connections_from_ip", 0, crule_connections_from_ip}, + {"destination", 1, crule_destination}, + {"digit_percentage", 0, crule_digit_percentage}, + {"directcon", 1, crule_directcon}, + {"directop", 0, crule_directop}, + {"has_channel_mode", 1, crule_has_channel_mode}, + {"has_swhois", 0, crule_has_swhois}, + {"has_user_mode", 1, crule_has_user_mode}, + {"idle_time", 0, crule_idle_time}, + {"in_channel", 1, crule_in_channel}, + {"in_security_group", 1, crule_in_security_group}, + {"inchannel", 1, crule_in_channel}, // old name, keep it around for now.. + {"is_away", 0, crule_away}, + {"is_identified", 0, crule_is_identified}, + {"is_local", 0, crule_is_local}, + {"is_oper", 0, crule_is_oper}, + {"is_tls", 0, crule_tls}, + {"is_webirc", 0, crule_is_webirc}, + {"is_websocket", 0, crule_is_websocket}, + {"match_account", 1, crule_match_account}, + {"match_asn", 1, crule_match_asn}, + {"match_asname", 1, crule_match_asname}, + {"match_away", 1, crule_match_away}, + {"match_certfp", 1, crule_match_certfp}, + {"match_class", 1, crule_match_class}, + {"match_country", 1, crule_match_country}, + {"match_ip", 1, crule_match_ip}, + {"match_mask", 1, crule_match_mask}, + {"match_operclass", 1, crule_match_operclass}, + {"match_operlogin", 1, crule_match_operlogin}, + {"match_realhost", 1, crule_match_realhost}, + {"match_realname", 1, crule_match_realname}, + {"match_server", 1, crule_match_server}, + {"match_sni", 1, crule_match_sni}, + {"match_tls_cipher", 1, crule_match_tls_cipher}, + {"match_vhost", 1, crule_match_vhost}, + {"max_repeat_count", 0, crule_max_repeat_count}, + {"messages_received", 0, crule_messages_received}, + {"messages_sent", 0, crule_messages_sent}, + {"mixed_utf8_score", 0, crule_mixed_utf8_score}, + {"non_ascii_percentage", 0, crule_non_ascii_percentage}, + {"online_time", 0, crule_online_time}, + {"reputation", 0, crule_reputation}, + {"server_flood_count", 1, crule_server_flood_count}, + {"server_port", 0, crule_server_port}, + {"tag", 1, crule_tag}, + {"text_byte_count", 0, crule_text_byte_count}, + {"text_character_count", 0, crule_text_character_count}, + {"total_channel_flood_count", 1, crule_total_channel_flood_count}, + {"unicode_block_count", 0, crule_unicode_block_count}, + {"unicode_count", 1, crule_unicode_count}, + {"uppercase_percentage", 0, crule_uppercase_percentage}, + {"via", 2, crule_via}, + {"word_count", 0, crule_word_count}, }; MOD_TEST() @@ -558,7 +557,7 @@ static int crule_cap_set(crule_context *context, int numargs, void *crulearg[]) { const char *capname = (char *)crulearg[0]; - if (!context || !context->client || !context->client->local ) + if (!context || !context->client || !context->client->local) return 0; if (HasCapability(context->client, capname)) @@ -586,7 +585,7 @@ static int crule_match_mask(crule_context *context, int numargs, void *crulearg[ if (!context || !context->client) return 0; - if (match_user(arg, context->client, MATCH_CHECK_REAL_HOST|MATCH_CHECK_IP|MATCH_CHECK_EXTENDED)) + if (match_user(arg, context->client, MATCH_CHECK_REAL_HOST | MATCH_CHECK_IP | MATCH_CHECK_EXTENDED)) return 1; return 0; @@ -599,7 +598,7 @@ static int crule_match_ip(crule_context *context, int numargs, void *crulearg[]) if (!context || !context->client) return 0; - if (match_user(arg, context->client, MATCH_CHECK_IP|MATCH_MASK_IS_HOST)) + if (match_user(arg, context->client, MATCH_CHECK_IP | MATCH_MASK_IS_HOST)) return 1; return 0; @@ -1011,7 +1010,8 @@ static int crule_max_repeat_count(crule_context *context, int numargs, void *cru if (*p == *(p - 1)) { cur++; - } else { + } else + { if (cur > max) max = cur; cur = 1; @@ -1026,7 +1026,7 @@ static int crule_max_repeat_count(crule_context *context, int numargs, void *cru * @param[in] rule Rule to evalute. * @return Non-zero if the rule allows the connection, zero otherwise. */ -int _crule_eval(crule_context *context, CRuleNode* rule) +int _crule_eval(crule_context *context, CRuleNode *rule) { int ret = rule->funcptr(context, rule->numargs, rule->arg); switch (rule->func_test_type) @@ -1146,7 +1146,7 @@ static int crule_gettoken(crule_token *next_tokp, const char **ruleptr) break; default: if ((isalnum(*(--(*ruleptr)))) || (**ruleptr == '*') || - (**ruleptr == '?') || (**ruleptr == '.') || (**ruleptr == '-') || (**ruleptr == '_') || (**ruleptr == '\'')) + (**ruleptr == '?') || (**ruleptr == '.') || (**ruleptr == '-') || (**ruleptr == '_') || (**ruleptr == '\'')) *next_tokp = CR_WORD; else return CR_UNKNWTOK; @@ -1174,11 +1174,7 @@ static void crule_getword(char *word, int *wordlenp, size_t maxlen, const char * quoted = 1; } - while ((size_t)(word_ptr - word) < maxlen - && (isalnum(**ruleptr) - || **ruleptr == '*' || **ruleptr == '?' - || **ruleptr == '.' || **ruleptr == '-' - || **ruleptr == '_' || (quoted && (**ruleptr != '\'')))) + while ((size_t)(word_ptr - word) < maxlen && (isalnum(**ruleptr) || **ruleptr == '*' || **ruleptr == '?' || **ruleptr == '.' || **ruleptr == '-' || **ruleptr == '_' || (quoted && (**ruleptr != '\'')))) { *word_ptr++ = *(*ruleptr)++; } @@ -1198,18 +1194,20 @@ CRuleNode *_crule_parse(const char *rule) { const char *ruleptr = rule; crule_token next_tok; - CRuleNode* ruleroot = 0; + CRuleNode *ruleroot = 0; int errcode = CR_NOERR; - if ((errcode = crule_gettoken(&next_tok, &ruleptr)) == CR_NOERR) { - if ((errcode = crule_parseorexpr(&ruleroot, &next_tok, &ruleptr)) == CR_NOERR) { - if (ruleroot != NULL) { + if ((errcode = crule_gettoken(&next_tok, &ruleptr)) == CR_NOERR) + { + if ((errcode = crule_parseorexpr(&ruleroot, &next_tok, &ruleptr)) == CR_NOERR) + { + if (ruleroot != NULL) + { if (next_tok == CR_END) return ruleroot; else errcode = CR_UNEXPCTTOK; - } - else + } else errcode = CR_EXPCTOR; } } @@ -1226,22 +1224,25 @@ int _crule_test(const char *rule) { const char *ruleptr = rule; crule_token next_tok; - CRuleNode* ruleroot = 0; + CRuleNode *ruleroot = 0; int errcode = CR_NOERR; - if ((errcode = crule_gettoken(&next_tok, &ruleptr)) == CR_NOERR) { - if ((errcode = crule_parseorexpr(&ruleroot, &next_tok, &ruleptr)) == CR_NOERR) { - if (ruleroot != NULL) { + if ((errcode = crule_gettoken(&next_tok, &ruleptr)) == CR_NOERR) + { + if ((errcode = crule_parseorexpr(&ruleroot, &next_tok, &ruleptr)) == CR_NOERR) + { + if (ruleroot != NULL) + { if (next_tok == CR_END) { /* PASS */ crule_free(&ruleroot); return 0; - } else { + } else + { errcode = CR_UNEXPCTTOK; } - } - else + } else errcode = CR_EXPCTOR; } } @@ -1255,7 +1256,7 @@ const char *_crule_errstring(int errcode) if (errcode == 0) return "No error"; else - return crule_errstr[errcode-1]; + return crule_errstr[errcode - 1]; } /** Parse an or expression. @@ -1285,12 +1286,10 @@ static int crule_parseorexpr(CRuleNode **orrootp, crule_token *next_tokp, const { (*orrootp)->arg[1] = andexpr; orptr->arg[0] = *orrootp; - } - else + } else orptr->arg[0] = andexpr; *orrootp = orptr; - } - else + } else { if (*orrootp != NULL) { @@ -1298,14 +1297,12 @@ static int crule_parseorexpr(CRuleNode **orrootp, crule_token *next_tokp, const { (*orrootp)->arg[1] = andexpr; return errcode; - } - else + } else { - (*orrootp)->arg[1] = NULL; /* so free doesn't seg fault */ + (*orrootp)->arg[1] = NULL; /* so free doesn't seg fault */ return CR_EXPCTAND; } - } - else + } else { *orrootp = andexpr; return errcode; @@ -1343,12 +1340,10 @@ static int crule_parseandexpr(CRuleNode **androotp, crule_token *next_tokp, cons { (*androotp)->arg[1] = primary; andptr->arg[0] = *androotp; - } - else + } else andptr->arg[0] = primary; *androotp = andptr; - } - else + } else { if (*androotp != NULL) { @@ -1356,14 +1351,12 @@ static int crule_parseandexpr(CRuleNode **androotp, crule_token *next_tokp, cons { (*androotp)->arg[1] = primary; return errcode; - } - else + } else { - (*androotp)->arg[1] = NULL; /* so free doesn't seg fault */ + (*androotp)->arg[1] = NULL; /* so free doesn't seg fault */ return CR_EXPCTPRIM; } - } - else + } else { *androotp = primary; return errcode; @@ -1414,7 +1407,7 @@ static int crule_parseprimary(CRuleNode **primrootp, crule_token *next_tokp, con (*insertionp)->flags |= CRULE_FLAG_NOT; (*insertionp)->numargs = 1; (*insertionp)->arg[0] = NULL; - insertionp = (CRuleNode **) & ((*insertionp)->arg[0]); + insertionp = (CRuleNode **)&((*insertionp)->arg[0]); if ((errcode = crule_gettoken(next_tokp, ruleptr)) != CR_NOERR) break; continue; @@ -1466,9 +1459,9 @@ static int crule_parsefunction(CRuleNode **funcrootp, crule_token *next_tokp, co if ((errcode = crule_gettoken(next_tokp, ruleptr)) != CR_NOERR) return errcode; *funcrootp = safe_alloc(sizeof(CRuleNode)); - (*funcrootp)->funcptr = NULL; /* for freeing aborted trees */ + (*funcrootp)->funcptr = NULL; /* for freeing aborted trees */ if ((errcode = - crule_parsearglist(*funcrootp, next_tokp, ruleptr)) != CR_NOERR) + crule_parsearglist(*funcrootp, next_tokp, ruleptr)) != CR_NOERR) return errcode; if (*next_tokp != CR_CLOSEPAREN) return CR_EXPCTCLOSE; @@ -1494,8 +1487,7 @@ static int crule_parsefunction(CRuleNode **funcrootp, crule_token *next_tokp, co } (*funcrootp)->funcptr = func->funcptr; return CR_NOERR; - } - else + } else return CR_EXPCTOPEN; } @@ -1530,8 +1522,7 @@ static int crule_parsearglist(CRuleNode *argrootp, crule_token *next_tokp, const strcat(currarg, word); arglen += wordlen + 1; } - } - else + } else { strcpy(currarg, word); arglen = wordlen; @@ -1576,16 +1567,14 @@ void _crule_free(CRuleNode **elem) { /* type conversions and ()'s are fun! ;) here have an aspirin.. */ if ((*(elem))->arg[0] != NULL) - crule_free((CRuleNode**) &((*(elem))->arg[0])); - } - else if ((*(elem))->flags & CRULE_FLAG_AND_OR) + crule_free((CRuleNode **)&((*(elem))->arg[0])); + } else if ((*(elem))->flags & CRULE_FLAG_AND_OR) { if ((*(elem))->arg[0] != NULL) - crule_free((CRuleNode**) &((*(elem))->arg[0])); + crule_free((CRuleNode **)&((*(elem))->arg[0])); if ((*(elem))->arg[1] != NULL) - crule_free((CRuleNode**) &((*(elem))->arg[1])); - } - else + crule_free((CRuleNode **)&((*(elem))->arg[1])); + } else { numargs = (*(elem))->numargs; for (arg = 0; arg < numargs; arg++) diff --git a/src/modules/cycle.c b/src/modules/cycle.c index f1af457ef..1e7a07a47 100644 --- a/src/modules/cycle.c +++ b/src/modules/cycle.c @@ -22,16 +22,15 @@ CMD_FUNC(cmd_cycle); /* Place includes here */ -#define MSG_CYCLE "CYCLE" +#define MSG_CYCLE "CYCLE" -ModuleHeader MOD_HEADER - = { - "cycle", /* Name of module */ - "5.0", /* Version */ - "command /cycle", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "cycle", /* Name of module */ + "5.0", /* Version */ + "command /cycle", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() @@ -45,13 +44,12 @@ MOD_INIT() MOD_LOAD() { return MOD_SUCCESS; - } /* Called when module is unloaded */ MOD_UNLOAD() { - return MOD_SUCCESS; + return MOD_SUCCESS; } /* @@ -64,7 +62,7 @@ CMD_FUNC(cmd_cycle) char channels[BUFSIZE]; const char *parx[3]; int n; - + if (parc < 2) return; diff --git a/src/modules/dccallow.c b/src/modules/dccallow.c index 6b64c05a9..5e3161d8a 100644 --- a/src/modules/dccallow.c +++ b/src/modules/dccallow.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_dccallow); -#define MSG_DCCALLOW "DCCALLOW" +#define MSG_DCCALLOW "DCCALLOW" -ModuleHeader MOD_HEADER - = { - "dccallow", - "5.0", - "command /dccallow", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "dccallow", + "5.0", + "command /dccallow", + "UnrealIRCd Team", + "unrealircd-6", +}; int dccallow_user_quit(Client *client, MessageTag *mtags, const char *comment); @@ -68,11 +67,11 @@ void remove_dcc_references(Client *client) int found; lp = client->user->dccallow; - while(lp) + while (lp) { nextlp = lp->next; acptr = lp->value.client; - for(found = 0, lpp = &(acptr->user->dccallow); *lpp; lpp=&((*lpp)->next)) + for (found = 0, lpp = &(acptr->user->dccallow); *lpp; lpp = &((*lpp)->next)) { if (lp->flags == (*lpp)->flags) continue; /* match only opposite types for sanity */ @@ -81,8 +80,8 @@ void remove_dcc_references(Client *client) if ((*lpp)->flags == DCC_LINK_ME) { sendto_one(acptr, NULL, ":%s %d %s :%s has been removed from " - "your DCC allow list for signing off", - me.name, RPL_DCCINFO, acptr->name, client->name); + "your DCC allow list for signing off", + me.name, RPL_DCCINFO, acptr->name, client->name); } tmp = *lpp; *lpp = tmp->next; @@ -129,27 +128,27 @@ CMD_FUNC(cmd_dccallow) int ntargets = 0; int maxtargets = max_targets_for_command("WHOIS"); static char *dcc_help[] = { - "/DCCALLOW [<+|->nick[,<+|->nick, ...]] [list] [help]", - "You may allow DCCs of files which are otherwise blocked by the IRC server", - "by specifying a DCC allow for the user you want to recieve files from.", - "For instance, to allow the user Bob to send you file.exe, you would type:", - "/DCCALLOW +bob", - "and Bob would then be able to send you files. Bob will have to resend the file", - "if the server gave him an error message before you added him to your allow list.", - "/DCCALLOW -bob", - "Will do the exact opposite, removing him from your dcc allow list.", - "/dccallow list", - "Will list the users currently on your dcc allow list.", - NULL, + "/DCCALLOW [<+|->nick[,<+|->nick, ...]] [list] [help]", + "You may allow DCCs of files which are otherwise blocked by the IRC server", + "by specifying a DCC allow for the user you want to recieve files from.", + "For instance, to allow the user Bob to send you file.exe, you would type:", + "/DCCALLOW +bob", + "and Bob would then be able to send you files. Bob will have to resend the file", + "if the server gave him an error message before you added him to your allow list.", + "/DCCALLOW -bob", + "Will do the exact opposite, removing him from your dcc allow list.", + "/dccallow list", + "Will list the users currently on your dcc allow list.", + NULL, }; if (!MyUser(client)) return; - + if (parc < 2) { sendnotice(client, "No command specified for DCCALLOW. " - "Type '/DCCALLOW HELP' for more information."); + "Type '/DCCALLOW HELP' for more information."); return; } @@ -166,25 +165,24 @@ CMD_FUNC(cmd_dccallow) didanything = 1; if (!*++s) continue; - + friend = find_user(s, NULL); - + if (friend == client) continue; - + if (!friend) { sendnumeric(client, ERR_NOSUCHNICK, s); continue; } add_dccallow(client, friend); - } else - if (*s == '-') + } else if (*s == '-') { didanything = 1; if (!*++s) continue; - + friend = find_user(s, NULL); if (friend == client) continue; @@ -194,25 +192,23 @@ CMD_FUNC(cmd_dccallow) continue; } del_dccallow(client, friend); - } else - if (!didlist && !strncasecmp(s, "list", 4)) + } else if (!didlist && !strncasecmp(s, "list", 4)) { didanything = didlist = 1; sendnumeric(client, RPL_DCCINFO, "The following users are on your dcc allow list:"); - for(lp = client->user->dccallow; lp; lp = lp->next) + for (lp = client->user->dccallow; lp; lp = lp->next) { if (lp->flags == DCC_LINK_REMOTE) continue; sendnumericfmt(client, RPL_DCCLIST, ":%s (%s@%s)", lp->value.client->name, - lp->value.client->user->username, - GetHost(lp->value.client)); + lp->value.client->user->username, + GetHost(lp->value.client)); } sendnumeric(client, RPL_ENDOFDCCLIST, s); - } else - if (!didhelp && !strncasecmp(s, "help", 4)) + } else if (!didhelp && !strncasecmp(s, "help", 4)) { didanything = didhelp = 1; - for(ptr = dcc_help; *ptr; ptr++) + for (ptr = dcc_help; *ptr; ptr++) sendnumeric(client, RPL_DCCINFO, *ptr); sendnumeric(client, RPL_ENDOFDCCLIST, s); } @@ -246,7 +242,7 @@ int add_dccallow(Client *client, Client *optr) if (cnt >= MAXDCCALLOW) { sendnumeric(client, ERR_TOOMANYDCC, - optr->name, MAXDCCALLOW); + optr->name, MAXDCCALLOW); return 0; } @@ -272,7 +268,7 @@ int del_dccallow(Client *client, Client *optr) Link **lpp, *lp; int found = 0; - for (lpp = &(client->user->dccallow); *lpp; lpp=&((*lpp)->next)) + for (lpp = &(client->user->dccallow); *lpp; lpp = &((*lpp)->next)) { if ((*lpp)->flags != DCC_LINK_ME) continue; @@ -291,7 +287,7 @@ int del_dccallow(Client *client, Client *optr) return 0; } - for (found = 0, lpp = &(optr->user->dccallow); *lpp; lpp=&((*lpp)->next)) + for (found = 0, lpp = &(optr->user->dccallow); *lpp; lpp = &((*lpp)->next)) { if ((*lpp)->flags != DCC_LINK_REMOTE) continue; diff --git a/src/modules/dccdeny.c b/src/modules/dccdeny.c index dbe6ee910..2325df16e 100644 --- a/src/modules/dccdeny.c +++ b/src/modules/dccdeny.c @@ -22,18 +22,17 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "dccdeny", - "6.0.2", - "command /dccdeny", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "dccdeny", + "6.0.2", + "command /dccdeny", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ -ConfigItem_deny_dcc *conf_deny_dcc = NULL; -ConfigItem_allow_dcc *conf_allow_dcc = NULL; +ConfigItem_deny_dcc *conf_deny_dcc = NULL; +ConfigItem_allow_dcc *conf_allow_dcc = NULL; /* Forward declarions */ int dccdeny_configtest_deny_dcc(ConfigFile *cf, ConfigEntry *ce, int type, int *errs); @@ -122,48 +121,45 @@ int dccdeny_configtest_deny_dcc(ConfigFile *cf, ConfigEntry *ce, int type, int * if (has_filename) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny dcc::filename"); + cep->line_number, "deny dcc::filename"); continue; } has_filename = 1; - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { if (has_reason) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny dcc::reason"); + cep->line_number, "deny dcc::reason"); continue; } has_reason = 1; - } - else if (!strcmp(cep->name, "soft")) + } else if (!strcmp(cep->name, "soft")) { if (has_soft) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny dcc::soft"); + cep->line_number, "deny dcc::soft"); continue; } has_soft = 1; - } - else + } else { config_error_unknown(cep->file->filename, - cep->line_number, "deny dcc", cep->name); + cep->line_number, "deny dcc", cep->name); errors++; } } if (!has_filename) { config_error_missing(ce->file->filename, ce->line_number, - "deny dcc::filename"); + "deny dcc::filename"); errors++; } if (!has_reason) { config_error_missing(ce->file->filename, ce->line_number, - "deny dcc::reason"); + "deny dcc::reason"); errors++; } @@ -192,32 +188,30 @@ int dccdeny_configtest_allow_dcc(ConfigFile *cf, ConfigEntry *ce, int type, int if (has_filename) { config_warn_duplicate(cep->file->filename, - cep->line_number, "allow dcc::filename"); + cep->line_number, "allow dcc::filename"); continue; } has_filename = 1; - } - else if (!strcmp(cep->name, "soft")) + } else if (!strcmp(cep->name, "soft")) { if (has_soft) { config_warn_duplicate(cep->file->filename, - cep->line_number, "allow dcc::soft"); + cep->line_number, "allow dcc::soft"); continue; } has_soft = 1; - } - else + } else { config_error_unknown(cep->file->filename, cep->line_number, - "allow dcc", cep->name); + "allow dcc", cep->name); errors++; } } if (!has_filename) { config_error_missing(ce->file->filename, ce->line_number, - "allow dcc::filename"); + "allow dcc::filename"); errors++; } @@ -227,8 +221,8 @@ int dccdeny_configtest_allow_dcc(ConfigFile *cf, ConfigEntry *ce, int type, int int dccdeny_configrun_deny_dcc(ConfigFile *cf, ConfigEntry *ce, int type) { - ConfigItem_deny_dcc *deny = NULL; - ConfigEntry *cep; + ConfigItem_deny_dcc *deny = NULL; + ConfigEntry *cep; /* We are only interested in deny dcc { } */ if ((type != CONFIG_DENY) || strcmp(ce->value, "dcc")) @@ -240,14 +234,12 @@ int dccdeny_configrun_deny_dcc(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "filename")) { safe_strdup(deny->filename, cep->value); - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { safe_strdup(deny->reason, cep->value); - } - else if (!strcmp(cep->name, "soft")) + } else if (!strcmp(cep->name, "soft")) { - int x = config_checkval(cep->value,CFG_YESNO); + int x = config_checkval(cep->value, CFG_YESNO); if (x == 1) deny->flag.type = DCCDENY_SOFT; } @@ -280,7 +272,7 @@ int dccdeny_configrun_allow_dcc(ConfigFile *cf, ConfigEntry *ce, int type) safe_strdup(allow->filename, cep->value); else if (!strcmp(cep->name, "soft")) { - int x = config_checkval(cep->value,CFG_YESNO); + int x = config_checkval(cep->value, CFG_YESNO); if (x) allow->flag.type = DCCDENY_SOFT; } @@ -360,7 +352,7 @@ CMD_FUNC(cmd_dccdeny) if (!MyUser(client)) return; - if (!ValidatePermissionsForPath("server-ban:dccdeny",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:dccdeny", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -396,7 +388,7 @@ CMD_FUNC(cmd_undccdeny) if (!MyUser(client)) return; - if (!ValidatePermissionsForPath("server-ban:dccdeny",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:dccdeny", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -443,7 +435,7 @@ CMD_FUNC(cmd_svsfline) if (IsULine(client)) { sendto_server(client, 0, 0, NULL, ":%s SVSFLINE + %s :%s", - client->id, parv[2], parv[3]); + client->id, parv[2], parv[3]); } break; @@ -491,7 +483,7 @@ int dccdeny_server_sync(Client *client) { if (p->flag.type2 == CONF_BAN_TYPE_AKILL) sendto_one(client, NULL, ":%s SVSFLINE + %s :%s", me.id, - p->filename, p->reason); + p->filename, p->reason); } return 0; } @@ -565,14 +557,14 @@ static const char *dcc_displayfile(const char *f) } /* Else, we show it as: [first 256 chars]+"[..TRUNCATED..]"+[last 20 chars] */ - for (i = f; i < f+256; i++) + for (i = f; i < f + 256; i++) if (*i < 32) *o++ = '?'; else *o++ = *i; strcpy(o, "[..TRUNCATED..]"); o += sizeof("[..TRUNCATED..]"); - for (i = f+n-20; *i; i++) + for (i = f + n - 20; *i; i++) if (*i < 32) *o++ = '?'; else @@ -583,24 +575,25 @@ static const char *dcc_displayfile(const char *f) static const char *get_dcc_filename(const char *text) { - static char filename[BUFSIZE+1]; + static char filename[BUFSIZE + 1]; char *end; int size_string; if (*text != '\001') return 0; - if (!strncasecmp(text+1, "DCC SEND ", 9)) + if (!strncasecmp(text + 1, "DCC SEND ", 9)) text = text + 10; - else if (!strncasecmp(text+1, "DCC RESUME ", 11)) + else if (!strncasecmp(text + 1, "DCC RESUME ", 11)) text = text + 12; else return 0; - for (; *text == ' '; text++); /* skip leading spaces */ + for (; *text == ' '; text++) + ; /* skip leading spaces */ - if (*text == '"' && *(text+1)) - end = strchr(text+1, '"'); + if (*text == '"' && *(text + 1)) + end = strchr(text + 1, '"'); else end = strchr(text, ' '); @@ -612,7 +605,7 @@ static const char *get_dcc_filename(const char *text) if (!size_string || (size_string > (BUFSIZE - 1))) return 0; - strlcpy(filename, text, size_string+1); + strlcpy(filename, text, size_string + 1); return filename; } @@ -630,11 +623,11 @@ static int can_dcc(Client *client, const char *target, Client *targetcli, const int size_string, ret; /* User (IRCOp) may bypass send restrictions */ - if (ValidatePermissionsForPath("immune:dcc",client,targetcli,NULL,NULL)) + if (ValidatePermissionsForPath("immune:dcc", client, targetcli, NULL, NULL)) return 1; /* User (IRCOp) likes to receive bad dcc's */ - if (targetcli && ValidatePermissionsForPath("self:getbaddcc",targetcli,NULL,NULL,NULL)) + if (targetcli && ValidatePermissionsForPath("self:getbaddcc", targetcli, NULL, NULL, NULL)) return 1; /* Check if user is already blocked (from the past) */ @@ -692,11 +685,11 @@ static int can_dcc_soft(Client *from, Client *to, const char *filename, const ch static char errbuf[256]; /* User (IRCOp) may bypass send restrictions */ - if (ValidatePermissionsForPath("immune:dcc",from,to,NULL,NULL)) + if (ValidatePermissionsForPath("immune:dcc", from, to, NULL, NULL)) return 1; /* User (IRCOp) likes to receive bad dcc's */ - if (ValidatePermissionsForPath("self:getbaddcc",to,NULL,NULL,NULL)) + if (ValidatePermissionsForPath("self:getbaddcc", to, NULL, NULL, NULL)) return 1; /* On the 'soft' blocklist ? */ @@ -715,14 +708,15 @@ static int can_dcc_soft(Client *from, Client *to, const char *filename, const ch /* Inform target ('to') about the /DCCALLOW functionality */ sendnotice(to, "%s (%s@%s) tried to DCC SEND you a file named '%s', the request has been blocked.", - from->name, from->user->username, GetHost(from), displayfile); + from->name, from->user->username, GetHost(from), displayfile); if (!IsDCCNotice(to)) { SetDCCNotice(to); sendnotice(to, "Files like these might contain malicious content (viruses, trojans). " - "Therefore, you must explicitly allow anyone that tries to send you such files."); + "Therefore, you must explicitly allow anyone that tries to send you such files."); sendnotice(to, "If you trust %s, and want him/her to send you this file, you may obtain " - "more information on using the dccallow system by typing '/DCCALLOW HELP'", from->name); + "more information on using the dccallow system by typing '/DCCALLOW HELP'", + from->name); } return 0; } @@ -799,7 +793,7 @@ static void DCCdeny_del(ConfigItem_deny_dcc *deny) ConfigItem_deny_dcc *find_deny_dcc(const char *name) { - ConfigItem_deny_dcc *e; + ConfigItem_deny_dcc *e; if (!name) return NULL; @@ -827,7 +821,6 @@ static void dcc_wipe_services(void) safe_free(dconf); } } - } int dccdeny_stats(Client *client, const char *para) @@ -853,7 +846,7 @@ int dccdeny_stats(Client *client, const char *para) a = 'o'; /* */ sendtxtnumeric(client, "d %c %c %s %s", (denytmp->flag.type == DCCDENY_SOFT) ? 's' : 'h', - a, filemask, reason); + a, filemask, reason); } for (allowtmp = conf_allow_dcc; allowtmp; allowtmp = allowtmp->next) { @@ -866,7 +859,7 @@ int dccdeny_stats(Client *client, const char *para) a = 'o'; /* */ sendtxtnumeric(client, "a %c %c %s", (allowtmp->flag.type == DCCDENY_SOFT) ? 's' : 'h', - a, filemask); + a, filemask); } return 1; } diff --git a/src/modules/echo-message.c b/src/modules/echo-message.c index 2e814643e..9eec185cb 100644 --- a/src/modules/echo-message.c +++ b/src/modules/echo-message.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "echo-message", - "5.0", - "echo-message CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "echo-message", + "5.0", + "echo-message CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ long CAP_ECHO_MESSAGE = 0L; @@ -73,15 +72,16 @@ int em_chanmsg(Client *client, Channel *channel, int sendflags, const char *pref if (sendtype != SEND_TYPE_TAGMSG) { sendto_prefix_one(client, client, mtags, ":%s %s %s :%s", - client->name, - sendtype_to_cmd(sendtype), - target, - text); - } else { + client->name, + sendtype_to_cmd(sendtype), + target, + text); + } else + { sendto_prefix_one(client, client, mtags, ":%s %s %s", - client->name, - sendtype_to_cmd(sendtype), - target); + client->name, + sendtype_to_cmd(sendtype), + target); } } return 0; @@ -96,15 +96,16 @@ int em_usermsg(Client *client, Client *to, MessageTag *mtags, const char *text, if (sendtype != SEND_TYPE_TAGMSG) { sendto_prefix_one(client, client, mtags, ":%s %s %s :%s", - client->name, - sendtype_to_cmd(sendtype), - to->name, - text); - } else { + client->name, + sendtype_to_cmd(sendtype), + to->name, + text); + } else + { sendto_prefix_one(client, client, mtags, ":%s %s %s", - client->name, - sendtype_to_cmd(sendtype), - to->name); + client->name, + sendtype_to_cmd(sendtype), + to->name); } } return 0; diff --git a/src/modules/eos.c b/src/modules/eos.c index c3e0707d4..47e482b3f 100644 --- a/src/modules/eos.c +++ b/src/modules/eos.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_eos); -#define MSG_EOS "EOS" +#define MSG_EOS "EOS" -ModuleHeader MOD_HEADER - = { - "eos", - "5.0", - "command /eos", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "eos", + "5.0", + "command /eos", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { diff --git a/src/modules/extbans/account.c b/src/modules/extbans/account.c index 1d1d2d51d..d034521cb 100644 --- a/src/modules/extbans/account.c +++ b/src/modules/extbans/account.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/account", - "4.2", - "ExtBan ~a - Ban/exempt by services account name", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/account", + "4.2", + "ExtBan ~a - Ban/exempt by services account name", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -41,8 +40,8 @@ Extban *register_account_extban(ModuleInfo *modinfo) req.is_ok = NULL; req.conv_param = extban_account_conv_param; req.is_banned = extban_account_is_banned; - req.is_banned_events = BANCHK_ALL|BANCHK_TKL; - req.options = EXTBOPT_INVEX|EXTBOPT_TKL; + req.is_banned_events = BANCHK_ALL | BANCHK_TKL; + req.options = EXTBOPT_INVEX | EXTBOPT_TKL; return ExtbanAdd(modinfo->handle, req); } diff --git a/src/modules/extbans/asn.c b/src/modules/extbans/asn.c index 17bfb6175..36a01a567 100644 --- a/src/modules/extbans/asn.c +++ b/src/modules/extbans/asn.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/asn", - "6.0", - "ExtBan ~asn - Ban/exempt by ASN (geoip)", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/asn", + "6.0", + "ExtBan ~asn - Ban/exempt by ASN (geoip)", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -42,8 +41,8 @@ Extban *register_asn_extban(ModuleInfo *modinfo) req.is_ok = extban_asn_is_ok; req.conv_param = extban_asn_conv_param; req.is_banned = extban_asn_is_banned; - req.is_banned_events = BANCHK_ALL|BANCHK_TKL; - req.options = EXTBOPT_INVEX|EXTBOPT_TKL; + req.is_banned_events = BANCHK_ALL | BANCHK_TKL; + req.options = EXTBOPT_INVEX | EXTBOPT_TKL; return ExtbanAdd(modinfo->handle, req); } @@ -90,7 +89,7 @@ int extban_asn_usage(Client *client) if (client) { sendnotice(client, "ERROR: ExtBan ~asn expects the AS number (all digits). " - "For example: +b ~asn:64496"); + "For example: +b ~asn:64496"); } return EX_DENY; } @@ -121,7 +120,7 @@ const char *extban_asn_conv_param(BanContext *b, Extban *extban) { static char retbuf[32]; unsigned int asn; - char *p=NULL; + char *p = NULL; if (!isdigit(b->banstr[0])) return NULL; diff --git a/src/modules/extbans/certfp.c b/src/modules/extbans/certfp.c index df2887f58..a3e9e4ca5 100644 --- a/src/modules/extbans/certfp.c +++ b/src/modules/extbans/certfp.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/certfp", - "4.2", - "ExtBan ~certfp - Ban/exempt by SHA256 TLS certificate fingerprint", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/certfp", + "4.2", + "ExtBan ~certfp - Ban/exempt by SHA256 TLS certificate fingerprint", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -42,8 +41,8 @@ Extban *register_certfp_extban(ModuleInfo *modinfo) req.is_ok = extban_certfp_is_ok; req.conv_param = extban_certfp_conv_param; req.is_banned = extban_certfp_is_banned; - req.is_banned_events = BANCHK_ALL|BANCHK_TKL; - req.options = EXTBOPT_INVEX|EXTBOPT_TKL; + req.is_banned_events = BANCHK_ALL | BANCHK_TKL; + req.options = EXTBOPT_INVEX | EXTBOPT_TKL; return ExtbanAdd(modinfo->handle, req); } @@ -92,7 +91,7 @@ int extban_certfp_usage(Client *client) if (client) { sendnotice(client, "ERROR: ExtBan ~certfp expects an SHA256 fingerprint in hexadecimal format (no colons). " - "For example: +e ~certfp:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef)"); + "For example: +e ~certfp:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef)"); } return EX_DENY; } diff --git a/src/modules/extbans/country.c b/src/modules/extbans/country.c index a7878dc1e..44adf4835 100644 --- a/src/modules/extbans/country.c +++ b/src/modules/extbans/country.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/country", - "6.0", - "ExtBan ~country - Ban/exempt by country (geoip)", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/country", + "6.0", + "ExtBan ~country - Ban/exempt by country (geoip)", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -42,8 +41,8 @@ Extban *register_country_extban(ModuleInfo *modinfo) req.is_ok = extban_country_is_ok; req.conv_param = extban_country_conv_param; req.is_banned = extban_country_is_banned; - req.is_banned_events = BANCHK_ALL|BANCHK_TKL; - req.options = EXTBOPT_INVEX|EXTBOPT_TKL; + req.is_banned_events = BANCHK_ALL | BANCHK_TKL; + req.options = EXTBOPT_INVEX | EXTBOPT_TKL; return ExtbanAdd(modinfo->handle, req); } @@ -90,7 +89,7 @@ int extban_country_usage(Client *client) if (client) { sendnotice(client, "ERROR: ExtBan ~country expects a two letter country code, or * to ban unknown countries. " - "For example: +b ~country:UK"); + "For example: +b ~country:UK"); } return EX_DENY; } diff --git a/src/modules/extbans/flood.c b/src/modules/extbans/flood.c index fd83822da..efedd7bba 100644 --- a/src/modules/extbans/flood.c +++ b/src/modules/extbans/flood.c @@ -19,13 +19,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/flood", - "1.0", - "Extban ~flood - exempt from +f/+F checks", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/flood", + "1.0", + "Extban ~flood - exempt from +f/+F checks", + "UnrealIRCd Team", + "unrealircd-6", }; /** Maximum length of the ~flood ban exemption */ @@ -90,9 +89,9 @@ static int flood_type_ok(char *str) const char *flood_extban_conv_param(BanContext *b, Extban *extban) { - static char retbuf[MAX_FLOODBAN_LENGTH+1]; - char para[MAX_FLOODBAN_LENGTH+1]; - char tmpmask[MAX_FLOODBAN_LENGTH+1]; + static char retbuf[MAX_FLOODBAN_LENGTH + 1]; + char para[MAX_FLOODBAN_LENGTH + 1]; + char tmpmask[MAX_FLOODBAN_LENGTH + 1]; char *type; /**< Type(s), such as 'j' */ char *matchby; /**< Matching method, such as 'n!u@h' */ const char *newmask; /**< Cleaned matching method, such as 'n!u@h' */ @@ -140,7 +139,7 @@ int flood_extban_syntax(Client *client, int checkt, char *reason) int flood_extban_is_ok(BanContext *b) { - static char para[MAX_FLOODBAN_LENGTH+1]; + static char para[MAX_FLOODBAN_LENGTH + 1]; char *type; /**< Type(s), such as 'j' */ char *matchby; /**< Matching method, such as 'n!u@h' */ char *newmask; /**< Cleaned matching method, such as 'n!u@h' */ diff --git a/src/modules/extbans/inchannel.c b/src/modules/extbans/inchannel.c index 95b86107c..92dcd44be 100644 --- a/src/modules/extbans/inchannel.c +++ b/src/modules/extbans/inchannel.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/inchannel", - "4.2", - "ExtBan ~channel - banned when in specified channel", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/inchannel", + "4.2", + "ExtBan ~channel - banned when in specified channel", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -42,8 +41,8 @@ Extban *register_channel_extban(ModuleInfo *modinfo) req.is_ok = extban_inchannel_is_ok; req.conv_param = extban_inchannel_conv_param; req.is_banned = extban_inchannel_is_banned; - req.is_banned_events = BANCHK_ALL|BANCHK_TKL; - req.options = EXTBOPT_INVEX|EXTBOPT_TKL; + req.is_banned_events = BANCHK_ALL | BANCHK_TKL; + req.options = EXTBOPT_INVEX | EXTBOPT_TKL; return ExtbanAdd(modinfo->handle, req); } @@ -83,15 +82,15 @@ MOD_UNLOAD() const char *extban_inchannel_conv_param(BanContext *b, Extban *extban) { - static char retbuf[CHANNELLEN+6]; - char *chan, *p, symbol='\0'; + static char retbuf[CHANNELLEN + 6]; + char *chan, *p, symbol = '\0'; strlcpy(retbuf, b->banstr, sizeof(retbuf)); chan = retbuf; if ((*chan == '+') || (*chan == '%') || (*chan == '%') || (*chan == '@') || (*chan == '&') || (*chan == '~')) - chan++; + chan++; if ((*chan != '#') && (*chan != '*') && (*chan != '?')) return NULL; @@ -116,7 +115,7 @@ int extban_inchannel_is_ok(BanContext *b) { if ((*p == '+') || (*p == '%') || (*p == '%') || (*p == '@') || (*p == '&') || (*p == '~')) - p++; + p++; if (*p != '#') { @@ -159,4 +158,3 @@ int extban_inchannel_is_banned(BanContext *b) return 0; } - diff --git a/src/modules/extbans/inherit.c b/src/modules/extbans/inherit.c index abcaf1616..e303a3fcb 100644 --- a/src/modules/extbans/inherit.c +++ b/src/modules/extbans/inherit.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/inherit", - "1.0", - "ExtBan ~inherit - inherit bans from another channel", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/inherit", + "1.0", + "ExtBan ~inherit - inherit bans from another channel", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -56,7 +55,7 @@ Extban *register_channel_extban(ModuleInfo *modinfo) * We don't allow things like ~nick:~inherit, as we only work * on JOINs (option EXTBOPT_NOSTACKCHILD). */ - req.options = EXTBOPT_INVEX|EXTBOPT_NOSTACKCHILD; + req.options = EXTBOPT_INVEX | EXTBOPT_NOSTACKCHILD; return ExtbanAdd(modinfo->handle, req); } @@ -120,11 +119,12 @@ static int inherit_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (v < 0) { config_error("%s:%i: set::max-inherit-extended-bans::%s item has a value, which is unexpected. Check your syntax!", - cep->file->filename, cep->line_number, cep->name); - errors++; + cep->file->filename, cep->line_number, cep->name); + errors++; continue; } - } else { + } else + { config_error_unknown(cep->file->filename, cep->line_number, "set::max-inherit-extended-bans", cep->name); errors++; @@ -213,14 +213,13 @@ static int exceeds_inherit_ban_count(BanContext *b) /* Pretend time does not exist... */ if (!strncmp(banstr, "~t:", 3)) { - banstr = strchr(banstr+3, ':'); + banstr = strchr(banstr + 3, ':'); if (!banstr) continue; banstr++; - } - else if (!strncmp(banstr, "~time:", 6)) + } else if (!strncmp(banstr, "~time:", 6)) { - banstr = strchr(banstr+6, ':'); + banstr = strchr(banstr + 6, ':'); if (!banstr) continue; banstr++; @@ -229,7 +228,7 @@ static int exceeds_inherit_ban_count(BanContext *b) /* Now check against ~inherit */ if ((!strncasecmp(banstr, "~inherit:", 9) || !strncmp(banstr, "~i:", 3)) && - ++cnt >= limit) + ++cnt >= limit) { return 1; } @@ -240,7 +239,7 @@ static int exceeds_inherit_ban_count(BanContext *b) const char *extban_inherit_conv_param(BanContext *b, Extban *extban) { - static char retbuf[CHANNELLEN+1]; + static char retbuf[CHANNELLEN + 1]; strlcpy(retbuf, b->banstr, sizeof(retbuf)); @@ -258,7 +257,7 @@ const char *extban_inherit_conv_param(BanContext *b, Extban *extban) int extban_inherit_is_ok(BanContext *b) { - char retbuf[CHANNELLEN+1]; + char retbuf[CHANNELLEN + 1]; if (b->is_ok_check != EXBCHK_PARAM) return 1; @@ -286,10 +285,10 @@ int extban_inherit_is_ok(BanContext *b) if (exceeds_inherit_ban_count(b)) { sendnotice(b->client, "Your ExtBan ~inherit:%s was not accepted because " - "this channel already contains the maximum " - "amount of ~inherit entries (%d).", - b->banstr, - maximum_ban_inherit_limit(b->ban_type)); + "this channel already contains the maximum " + "amount of ~inherit entries (%d).", + b->banstr, + maximum_ban_inherit_limit(b->ban_type)); return 0; } } diff --git a/src/modules/extbans/join.c b/src/modules/extbans/join.c index 440636248..b97685fd0 100644 --- a/src/modules/extbans/join.c +++ b/src/modules/extbans/join.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/join", - "4.2", - "Extban ~join - prevent join only", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/join", + "4.2", + "Extban ~join - prevent join only", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -34,7 +33,7 @@ int extban_modej_is_banned(BanContext *b); MOD_INIT() { ExtbanInfo req; - + memset(&req, 0, sizeof(req)); req.letter = 'j'; req.name = "join"; @@ -50,7 +49,7 @@ MOD_INIT() } MARK_AS_OFFICIAL_MODULE(modinfo); - + return MOD_SUCCESS; } diff --git a/src/modules/extbans/msgbypass.c b/src/modules/extbans/msgbypass.c index 58ec9b7ee..0a0d8c555 100644 --- a/src/modules/extbans/msgbypass.c +++ b/src/modules/extbans/msgbypass.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/msgbypass", - "4.2", - "ExtBan ~msgbypass - bypass +m/+n/+c/+S/+T (msgbypass)", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/msgbypass", + "4.2", + "ExtBan ~msgbypass - bypass +m/+n/+c/+S/+T (msgbypass)", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -36,7 +35,7 @@ const char *msgbypass_extban_conv_param(BanContext *b, Extban *extban); MOD_INIT() { ExtbanInfo req; - + memset(&req, 0, sizeof(req)); req.letter = 'm'; req.name = "msgbypass"; @@ -50,7 +49,7 @@ MOD_INIT() } MARK_AS_OFFICIAL_MODULE(modinfo); - + return MOD_SUCCESS; } @@ -78,7 +77,7 @@ int msgbypass_can_bypass(Client *client, Channel *channel, BypassChannelMessageR b->channel = channel; b->ban_check_types = BANCHK_MSG; b->ban_type = EXBTYPE_EXCEPT; - for (ban = channel->exlist; ban; ban=ban->next) + for (ban = channel->exlist; ban; ban = ban->next) { char *type; char *matchby; @@ -100,7 +99,7 @@ int msgbypass_can_bypass(Client *client, Channel *channel, BypassChannelMessageR if (!matchby) continue; matchby++; - + b->banstr = matchby; if (ban_check_mask(b)) { @@ -131,15 +130,15 @@ int msgbypass_extban_type_ok(char *type) #define MAX_LENGTH 128 const char *msgbypass_extban_conv_param(BanContext *b, Extban *extban) { - static char retbuf[MAX_LENGTH+1]; - char para[MAX_LENGTH+1]; - char tmpmask[MAX_LENGTH+1]; + static char retbuf[MAX_LENGTH + 1]; + char para[MAX_LENGTH + 1]; + char tmpmask[MAX_LENGTH + 1]; char *type; /**< Type, such as 'external' */ char *matchby; /**< Matching method, such as 'n!u@h' */ const char *newmask; /**< Cleaned matching method, such as 'n!u@h' */ strlcpy(para, b->banstr, sizeof(para)); /* work on a copy (and truncate it) */ - + /* ~m:type:n!u@h for direct matching * ~m:type:~x:.... when calling another bantype */ @@ -178,7 +177,7 @@ int msgbypass_extban_syntax(Client *client, int checkt, char *reason) int msgbypass_extban_is_ok(BanContext *b) { - static char para[MAX_LENGTH+1]; + static char para[MAX_LENGTH + 1]; char *type; /**< Type, such as 'external' */ char *matchby; /**< Matching method, such as 'n!u@h' */ char *newmask; /**< Cleaned matching method, such as 'n!u@h' */ @@ -186,7 +185,7 @@ int msgbypass_extban_is_ok(BanContext *b) /* Always permit deletion */ if (b->what == MODE_DEL) return 1; - + if (b->ban_type != EXBTYPE_EXCEPT) { if (b->is_ok_check == EXBCHK_PARAM) @@ -195,7 +194,7 @@ int msgbypass_extban_is_ok(BanContext *b) } strlcpy(para, b->banstr, sizeof(para)); /* work on a copy (and truncate it) */ - + /* ~m:type:n!u@h for direct matching * ~m:type:~x:.... when calling another bantype */ @@ -221,4 +220,3 @@ int msgbypass_extban_is_ok(BanContext *b) return 1; /* OK */ } - diff --git a/src/modules/extbans/nickchange.c b/src/modules/extbans/nickchange.c index 3507c186e..e54b7b719 100644 --- a/src/modules/extbans/nickchange.c +++ b/src/modules/extbans/nickchange.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/nickchange", - "4.2", - "ExtBan ~nickchange - prevent nick-changes only", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/nickchange", + "4.2", + "ExtBan ~nickchange - prevent nick-changes only", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -34,7 +33,7 @@ int extban_nickchange_is_banned(BanContext *b); MOD_INIT() { ExtbanInfo req; - + memset(&req, 0, sizeof(req)); req.letter = 'n'; req.name = "nickchange"; @@ -50,7 +49,7 @@ MOD_INIT() } MARK_AS_OFFICIAL_MODULE(modinfo); - + return MOD_SUCCESS; } diff --git a/src/modules/extbans/operclass.c b/src/modules/extbans/operclass.c index 67701fc93..05b548c90 100644 --- a/src/modules/extbans/operclass.c +++ b/src/modules/extbans/operclass.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/operclass", - "4.2", - "ExtBan ~O - Ban/exempt operclass", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/operclass", + "4.2", + "ExtBan ~O - Ban/exempt operclass", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -35,15 +34,15 @@ int extban_operclass_is_banned(BanContext *b); MOD_INIT() { ExtbanInfo req; - + memset(&req, 0, sizeof(req)); req.letter = 'O'; req.name = "operclass"; req.is_ok = NULL; req.conv_param = extban_operclass_conv_param; req.is_banned = extban_operclass_is_banned; - req.is_banned_events = BANCHK_ALL|BANCHK_TKL; - req.options = EXTBOPT_INVEX|EXTBOPT_TKL; + req.is_banned_events = BANCHK_ALL | BANCHK_TKL; + req.options = EXTBOPT_INVEX | EXTBOPT_TKL; if (!ExtbanAdd(modinfo->handle, req)) { config_error("could not register extended ban type"); @@ -51,7 +50,7 @@ MOD_INIT() } MARK_AS_OFFICIAL_MODULE(modinfo); - + return MOD_SUCCESS; } diff --git a/src/modules/extbans/partmsg.c b/src/modules/extbans/partmsg.c index 4b6f57d14..4ea64896d 100644 --- a/src/modules/extbans/partmsg.c +++ b/src/modules/extbans/partmsg.c @@ -19,13 +19,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/partmsg", - "4.2", - "ExtBan ~partmsg - Ban/exempt Part/Quit message", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/partmsg", + "4.2", + "ExtBan ~partmsg - Ban/exempt Part/Quit message", + "UnrealIRCd Team", + "unrealircd-6", }; int extban_partmsg_is_banned(BanContext *b); @@ -69,6 +68,6 @@ int extban_partmsg_is_banned(BanContext *b) { if (ban_check_mask(b)) b->msg = NULL; - + return 0; } diff --git a/src/modules/extbans/quiet.c b/src/modules/extbans/quiet.c index e40f513b5..a578545ff 100644 --- a/src/modules/extbans/quiet.c +++ b/src/modules/extbans/quiet.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/quiet", - "4.2", - "ExtBan ~quiet - prevent messages only (quiet)", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/quiet", + "4.2", + "ExtBan ~quiet - prevent messages only (quiet)", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -34,7 +33,7 @@ int extban_quiet_is_banned(BanContext *b); MOD_INIT() { ExtbanInfo req; - + memset(&req, 0, sizeof(req)); req.letter = 'q'; req.name = "quiet"; @@ -50,7 +49,7 @@ MOD_INIT() } MARK_AS_OFFICIAL_MODULE(modinfo); - + return MOD_SUCCESS; } diff --git a/src/modules/extbans/realname.c b/src/modules/extbans/realname.c index 975ddae74..186b63dd6 100644 --- a/src/modules/extbans/realname.c +++ b/src/modules/extbans/realname.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/realname", - "4.2", - "ExtBan ~realname - Ban based on realname/gecos field", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/realname", + "4.2", + "ExtBan ~realname - Ban based on realname/gecos field", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -41,8 +40,8 @@ Extban *register_realname_extban(ModuleInfo *modinfo) req.is_ok = NULL; req.conv_param = extban_realname_conv_param; req.is_banned = extban_realname_is_banned; - req.is_banned_events = BANCHK_ALL|BANCHK_TKL; - req.options = EXTBOPT_INVEX|EXTBOPT_TKL; + req.is_banned_events = BANCHK_ALL | BANCHK_TKL; + req.options = EXTBOPT_INVEX | EXTBOPT_TKL; return ExtbanAdd(modinfo->handle, req); } diff --git a/src/modules/extbans/securitygroup.c b/src/modules/extbans/securitygroup.c index db9d2ace2..f53c7dff9 100644 --- a/src/modules/extbans/securitygroup.c +++ b/src/modules/extbans/securitygroup.c @@ -18,13 +18,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "extbans/securitygroup", - "4.2", - "ExtBan ~G - Ban based on security-group", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "extbans/securitygroup", + "4.2", + "ExtBan ~G - Ban based on security-group", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -42,8 +41,8 @@ Extban *register_securitygroup_extban(ModuleInfo *modinfo) req.conv_param = extban_securitygroup_conv_param; req.is_ok = extban_securitygroup_is_ok; req.is_banned = extban_securitygroup_is_banned; - req.is_banned_events = BANCHK_ALL|BANCHK_TKL; - req.options = EXTBOPT_INVEX|EXTBOPT_TKL; + req.is_banned_events = BANCHK_ALL | BANCHK_TKL; + req.options = EXTBOPT_INVEX | EXTBOPT_TKL; return ExtbanAdd(modinfo->handle, req); } @@ -69,7 +68,7 @@ MOD_INIT() } MARK_AS_OFFICIAL_MODULE(modinfo); - + return MOD_SUCCESS; } @@ -99,7 +98,8 @@ int extban_securitygroup_generic(char *mask, int strict) { if (!security_group_exists(mask)) return 0; /* security group does not exist */ - } else { + } else + { if (!security_group_valid_name(mask)) return 0; /* invalid characters or too long */ } @@ -114,7 +114,7 @@ int extban_securitygroup_is_ok(BanContext *b) { if (b->client && MyUser(b->client) && (b->what == MODE_ADD) && (b->is_ok_check == EXBCHK_PARAM)) { - char banbuf[SECURITYGROUPLEN+8]; + char banbuf[SECURITYGROUPLEN + 8]; strlcpy(banbuf, b->banstr, sizeof(banbuf)); if (!extban_securitygroup_generic(banbuf, 1)) { @@ -148,6 +148,6 @@ const char *extban_securitygroup_conv_param(BanContext *b, Extban *extban) int extban_securitygroup_is_banned(BanContext *b) { if (*b->banstr == '!') - return !user_allowed_by_security_group_name(b->client, b->banstr+1); + return !user_allowed_by_security_group_name(b->client, b->banstr + 1); return user_allowed_by_security_group_name(b->client, b->banstr); } diff --git a/src/modules/extbans/textban.c b/src/modules/extbans/textban.c index 27c3d0cf1..9678bfd0b 100644 --- a/src/modules/extbans/textban.c +++ b/src/modules/extbans/textban.c @@ -32,13 +32,13 @@ * textbans set. * UPDATE: The speed impact for 15 bans per channel is 42 usec PEAK. */ -#define MAX_EXTBANT_PER_CHAN 15 /* Max number of ~T bans in a channel. */ +#define MAX_EXTBANT_PER_CHAN 15 /* Max number of ~T bans in a channel. */ /** Max length of a ban. * NOTE: This is mainly for 'cosmetic' purposes. Lowering it does not * decrease CPU usage for text processing. */ -#define MAX_LENGTH 150 /* Max length of a ban */ +#define MAX_LENGTH 150 /* Max length of a ban */ /** Allow user@host in the textban? This changes the syntax! */ #undef UHOSTFEATURE @@ -57,14 +57,13 @@ /** Which censor replace word to use when CENSORFEATURE is enabled. */ #define CENSORWORD "" -ModuleHeader MOD_HEADER - = { - "extbans/textban", - "2.2", - "ExtBan ~textban", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "extbans/textban", + "2.2", + "ExtBan ~textban", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ const char *extban_modeT_conv_param(BanContext *b, Extban *extban); @@ -111,8 +110,8 @@ MOD_UNLOAD() static char *my_strcasestr(char *haystack, char *needle) { int i; - int nlength = strlen (needle); - int hlength = strlen (haystack); + int nlength = strlen(needle); + int hlength = strlen(haystack); if (nlength > hlength) return NULL; @@ -122,14 +121,14 @@ static char *my_strcasestr(char *haystack, char *needle) return haystack; for (i = 0; i <= (hlength - nlength); i++) { - if (strncasecmp (haystack + i, needle, nlength) == 0) + if (strncasecmp(haystack + i, needle, nlength) == 0) return haystack + i; } return NULL; /* not found */ } -#define TEXTBAN_WORD_LEFT 0x1 -#define TEXTBAN_WORD_RIGHT 0x2 + #define TEXTBAN_WORD_LEFT 0x1 + #define TEXTBAN_WORD_RIGHT 0x2 /* textban_replace: * a fast replace routine written by Syzop used for replacing. @@ -149,7 +148,7 @@ int textban_replace(int type, char *badword, char *line, char *buf) int cleaned = 0; replacew = CENSORWORD; - replacen = sizeof(CENSORWORD)-1; + replacen = sizeof(CENSORWORD) - 1; while (1) { @@ -159,12 +158,14 @@ int textban_replace(int type, char *badword, char *line, char *buf) if (searchn == -1) searchn = strlen(badword); /* Hunt for start of word */ - if (pold > line) - { - for (startw = pold; (!iswseperator(*startw) && (startw != line)); startw--); + if (pold > line) + { + for (startw = pold; (!iswseperator(*startw) && (startw != line)); startw--) + ; if (iswseperator(*startw)) startw++; /* Don't point at the space/seperator but at the word! */ - } else { + } else + { startw = pold; } @@ -179,9 +180,10 @@ int textban_replace(int type, char *badword, char *line, char *buf) * Fix for bug #4909: word will be at least 'searchn' long so we can skip * 'searchn' bytes and avoid stopping half-way the badword. */ - for (endw = pold+searchn; ((*endw != '\0') && (!iswseperator(*endw))); endw++); + for (endw = pold + searchn; ((*endw != '\0') && (!iswseperator(*endw))); endw++) + ; - if (!(type & TEXTBAN_WORD_RIGHT) && (pold+searchn != endw)) + if (!(type & TEXTBAN_WORD_RIGHT) && (pold + searchn != endw)) { /* not matched */ pold++; @@ -226,7 +228,8 @@ int textban_replace(int type, char *badword, char *line, char *buf) { strncpy(pnew, poldx, c_eol - pnew); *(c_eol) = '\0'; - } else { + } else + { *pnew = '\0'; } return cleaned; @@ -238,10 +241,10 @@ unsigned int counttextbans(Channel *channel) Ban *ban; unsigned int cnt = 0; - for (ban = channel->banlist; ban; ban=ban->next) + for (ban = channel->banlist; ban; ban = ban->next) if ((ban->banstr[0] == '~') && (ban->banstr[1] == 'T') && (ban->banstr[2] == ':')) cnt++; - for (ban = channel->exlist; ban; ban=ban->next) + for (ban = channel->exlist; ban; ban = ban->next) if ((ban->banstr[0] == '~') && (ban->banstr[1] == 'T') && (ban->banstr[2] == ':')) cnt++; return cnt; @@ -257,7 +260,7 @@ int extban_modeT_is_ok(BanContext *b) /* We check the # of bans in the channel, may not exceed MAX_EXTBANT_PER_CHAN */ if ((b->what == MODE_ADD) && (b->is_ok_check == EXBCHK_PARAM) && - MyUser(b->client) && !IsOper(b->client) && + MyUser(b->client) && !IsOper(b->client) && ((n = counttextbans(b->channel)) >= MAX_EXTBANT_PER_CHAN)) { /* We check the # of bans in the channel, may not exceed MAX_EXTBANT_PER_CHAN */ @@ -274,20 +277,20 @@ char *conv_pattern_asterisks(const char *pattern) char missing_prefix = 0, missing_suffix = 0; if (*pattern != '*') missing_prefix = 1; - if (*pattern && (pattern[strlen(pattern)-1] != '*')) + if (*pattern && (pattern[strlen(pattern) - 1] != '*')) missing_suffix = 1; snprintf(buf, sizeof(buf), "%s%s%s", - missing_prefix ? "*" : "", - pattern, - missing_suffix ? "*" : ""); + missing_prefix ? "*" : "", + pattern, + missing_suffix ? "*" : ""); return buf; } /** Ban callbacks */ const char *extban_modeT_conv_param(BanContext *b, Extban *extban) { - static char retbuf[MAX_LENGTH+1]; - char para[MAX_LENGTH+1], *action, *text, *p; + static char retbuf[MAX_LENGTH + 1]; + char para[MAX_LENGTH + 1], *action, *text, *p; #ifdef UHOSTFEATURE char *uhost; int ap = 0; @@ -354,9 +357,9 @@ const char *extban_modeT_conv_param(BanContext *b, Extban *extban) return NULL; /* unknown action */ /* check the string.. */ - for (p=text; *p; p++) + for (p = text; *p; p++) { - if ((*p == '\003') || (*p == '\002') || + if ((*p == '\003') || (*p == '\002') || (*p == '\037') || (*p == '\026') || (*p == ' ')) { @@ -387,21 +390,20 @@ int textban_can_send_to_channel(Client *client, Channel *channel, Membership *lp return HOOK_CONTINUE; /* Now we have to manually walk the banlist and check if things match */ - for (ban = channel->banlist; ban; ban=ban->next) + for (ban = channel->banlist; ban; ban = ban->next) { const char *banstr = ban->banstr; /* Pretend time does not exist... */ if (!strncmp(banstr, "~t:", 3)) { - banstr = strchr(banstr+3, ':'); + banstr = strchr(banstr + 3, ':'); if (!banstr) continue; banstr++; - } - else if (!strncmp(banstr, "~time:", 6)) + } else if (!strncmp(banstr, "~time:", 6)) { - banstr = strchr(banstr+6, ':'); + banstr = strchr(banstr + 6, ':'); if (!banstr) continue; banstr++; @@ -424,7 +426,7 @@ int textban_check_ban(Client *client, Channel *channel, const char *ban, const c static char retbuf[512]; char filtered[512]; /* temp input buffer */ long fl; - int cleaned=0; + int cleaned = 0; const char *p; #ifdef UHOSTFEATURE char buf[512], uhost[USERLEN + HOSTLEN + 16]; @@ -462,7 +464,7 @@ int textban_check_ban(Client *client, Channel *channel, const char *ban, const c { if (!strncasecmp(p, "block:", 6)) { - if (match_simple(p+6, filtered)) + if (match_simple(p + 6, filtered)) { if (errmsg) *errmsg = "Message blocked due to a text ban"; @@ -472,7 +474,7 @@ int textban_check_ban(Client *client, Channel *channel, const char *ban, const c #ifdef CENSORFEATURE else if (!strncasecmp(p, "censor:", 7)) { - parse_word(p+7, &word, &type); + parse_word(p + 7, &word, &type); if (textban_replace(type, word, filtered, tmp)) { strlcpy(filtered, tmp, sizeof(filtered)); diff --git a/src/modules/extbans/timedban.c b/src/modules/extbans/timedban.c index e9925f786..421a60e07 100644 --- a/src/modules/extbans/timedban.c +++ b/src/modules/extbans/timedban.c @@ -20,11 +20,11 @@ * then look at another extended ban * module as this module is not a * good starting point ;) */ - + #include "unrealircd.h" /* Maximum time (in minutes) for a ban */ -#define TIMEDBAN_MAX_TIME 9999 +#define TIMEDBAN_MAX_TIME 9999 /* Maximum length of a ban */ #define MAX_LENGTH 128 @@ -36,23 +36,22 @@ * NOTE: until all channels are processed it takes * TIMEDBAN_TIMER_ITERATION_SPLIT * TIMEDBAN_TIMER. */ -#define TIMEDBAN_TIMER 2 +#define TIMEDBAN_TIMER 2 /* We allow a ban to (potentially) expire slightly before the deadline. * For example with TIMEDBAN_TIMER_ITERATION_SPLIT=4 and TIMEDBAN_TIMER=2 * a 1 minute ban would expire at 56-63 seconds, rather than 60-67 seconds. * This is usually preferred. */ -#define TIMEDBAN_TIMER_DELTA ((TIMEDBAN_TIMER_ITERATION_SPLIT*TIMEDBAN_TIMER)/2) +#define TIMEDBAN_TIMER_DELTA ((TIMEDBAN_TIMER_ITERATION_SPLIT * TIMEDBAN_TIMER) / 2) -ModuleHeader MOD_HEADER - = { - "extbans/timedban", - "1.0", - "ExtBan ~time: automatically removed timed bans", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "extbans/timedban", + "1.0", + "ExtBan ~time: automatically removed timed bans", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ const char *timedban_extban_conv_param(BanContext *b, Extban *extban); @@ -89,8 +88,8 @@ MOD_INIT() config_error("timedban: unable to register 't' extban type!!"); return MOD_FAILED; } - - EventAdd(modinfo->handle, "timedban_timeout", timedban_timeout, NULL, TIMEDBAN_TIMER*1000, 0); + + EventAdd(modinfo->handle, "timedban_timeout", timedban_timeout, NULL, TIMEDBAN_TIMER * 1000, 0); return MOD_SUCCESS; } @@ -124,7 +123,8 @@ const char *generic_clean_ban_mask(BanContext *b, Extban *extban) *cp = '\0'; /* Strip any ':' at beginning since that would cause a desync */ - for (; (*mask && (*mask == ':')); mask++); + for (; (*mask && (*mask == ':')); mask++) + ; if (!*mask) return NULL; @@ -157,7 +157,7 @@ const char *generic_clean_ban_mask(BanContext *b, Extban *extban) } /* else, do some basic sanity checks and cut it off at 80 bytes */ if ((mask[1] != ':') || (mask[2] == '\0')) - return NULL; /* require a ":" after extban type */ + return NULL; /* require a ":" after extban type */ if (strlen(mask) > 80) mask[80] = '\0'; return mask; @@ -169,20 +169,20 @@ const char *generic_clean_ban_mask(BanContext *b, Extban *extban) /** Convert ban to an acceptable format (or return NULL to fully reject it) */ const char *timedban_extban_conv_param(BanContext *b, Extban *extban) { - static char retbuf[MAX_LENGTH+1]; - char para[MAX_LENGTH+1]; - char tmpmask[MAX_LENGTH+1]; + static char retbuf[MAX_LENGTH + 1]; + char para[MAX_LENGTH + 1]; + char tmpmask[MAX_LENGTH + 1]; char *durationstr; /**< Duration, such as '5' */ int duration; char *matchby; /**< Matching method, such as 'n!u@h' */ const char *newmask; /**< Cleaned matching method, such as 'n!u@h' */ static int timedban_extban_conv_param_recursion = 0; - + if (timedban_extban_conv_param_recursion) return NULL; /* reject: recursion detected! */ strlcpy(para, b->banstr, sizeof(para)); /* work on a copy (and truncate it) */ - + /* ~time:duration:n!u@h for direct matching * ~time:duration:~x:.... when calling another bantype */ @@ -192,7 +192,7 @@ const char *timedban_extban_conv_param(BanContext *b, Extban *extban) if (!matchby || !matchby[1]) return NULL; *matchby++ = '\0'; - + duration = atoi(durationstr); if ((duration <= 0) || (duration > TIMEDBAN_MAX_TIME)) @@ -244,12 +244,11 @@ int generic_ban_is_ok(BanContext *b) if ((b->is_ok_check == EXBCHK_ACCESS) || (b->is_ok_check == EXBCHK_ACCESS_ERR)) { if (!extban->is_ok(b) && - !ValidatePermissionsForPath("channel:override:mode:extban",b->client,NULL,b->channel,NULL)) + !ValidatePermissionsForPath("channel:override:mode:extban", b->client, NULL, b->channel, NULL)) { return 0; /* REJECT */ } - } else - if (b->is_ok_check == EXBCHK_PARAM) + } else if (b->is_ok_check == EXBCHK_PARAM) { if (!extban->is_ok(b)) { @@ -259,7 +258,7 @@ int generic_ban_is_ok(BanContext *b) } } } - + /* ACCEPT: * - not an extban; OR * - extban with NULL is_ok; OR @@ -271,8 +270,8 @@ int generic_ban_is_ok(BanContext *b) /** Validate ban ("is this ban ok?") */ int timedban_extban_is_ok(BanContext *b) { - char para[MAX_LENGTH+1]; - char tmpmask[MAX_LENGTH+1]; + char para[MAX_LENGTH + 1]; + char tmpmask[MAX_LENGTH + 1]; char *durationstr; /**< Duration, such as '5' */ int duration; char *matchby; /**< Matching method, such as 'n!u@h' */ @@ -288,7 +287,7 @@ int timedban_extban_is_ok(BanContext *b) return 0; /* Recursion detected (~time:1:~time:....) */ strlcpy(para, b->banstr, sizeof(para)); /* work on a copy (and truncate it) */ - + /* ~time:duration:n!u@h for direct matching * ~time:duration:~x:.... when calling another bantype */ @@ -352,15 +351,15 @@ int timedban_has_ban_expired(Ban *ban) p1 = banstr + 6; else return 0; /* not for us */ - p2 = strchr(p1+1, ':'); /* skip time argument */ + p2 = strchr(p1 + 1, ':'); /* skip time argument */ if (!p2) return 0; /* invalid fmt */ *p2 = '\0'; /* danger.. must restore!! */ t = atoi(p1); *p2 = ':'; /* restored.. */ - + expire_on = ban->when + (t * 60) - TIMEDBAN_TIMER_DELTA; - + if (expire_on < TStime()) return 1; return 0; @@ -391,30 +390,30 @@ EVENT(timedban_timeout) continue; /* not this time, maybe next */ *mbuf = *pbuf = '\0'; - for (ban = channel->banlist; ban; ban=nextban) + for (ban = channel->banlist; ban; ban = nextban) { nextban = ban->next; if (!strncmp(ban->banstr, "~t", 2) && timedban_has_ban_expired(ban)) { - add_send_mode_param(channel, &me, '-', 'b', ban->banstr); + add_send_mode_param(channel, &me, '-', 'b', ban->banstr); del_listmode(&channel->banlist, channel, ban->banstr); } } - for (ban = channel->exlist; ban; ban=nextban) + for (ban = channel->exlist; ban; ban = nextban) { nextban = ban->next; if (!strncmp(ban->banstr, "~t", 2) && timedban_has_ban_expired(ban)) { - add_send_mode_param(channel, &me, '-', 'e', ban->banstr); + add_send_mode_param(channel, &me, '-', 'e', ban->banstr); del_listmode(&channel->exlist, channel, ban->banstr); } } - for (ban = channel->invexlist; ban; ban=nextban) + for (ban = channel->invexlist; ban; ban = nextban) { nextban = ban->next; if (!strncmp(ban->banstr, "~t", 2) && timedban_has_ban_expired(ban)) { - add_send_mode_param(channel, &me, '-', 'I', ban->banstr); + add_send_mode_param(channel, &me, '-', 'I', ban->banstr); del_listmode(&channel->invexlist, channel, ban->banstr); } } @@ -434,14 +433,17 @@ EVENT(timedban_timeout) #error "add_send_mode_param() is not made for MODEBUFLEN > 512" #endif -void add_send_mode_param(Channel *channel, Client *from, char what, char mode, char *param) { +void add_send_mode_param(Channel *channel, Client *from, char what, char mode, char *param) +{ static char *modes = NULL, lastwhat; static short count = 0; short send = 0; - - if (!modes) modes = mbuf; - - if (!mbuf[0]) { + + if (!modes) + modes = mbuf; + + if (!mbuf[0]) + { modes = mbuf; *modes++ = what; *modes = 0; @@ -449,20 +451,21 @@ void add_send_mode_param(Channel *channel, Client *from, char what, char mode, c *pbuf = 0; count = 0; } - if (lastwhat != what) { + if (lastwhat != what) + { *modes++ = what; *modes = 0; lastwhat = what; } - if (strlen(pbuf) + strlen(param) + 11 < MODEBUFLEN) { - if (*pbuf) + if (strlen(pbuf) + strlen(param) + 11 < MODEBUFLEN) + { + if (*pbuf) strcat(pbuf, " "); strcat(pbuf, param); *modes++ = mode; *modes = 0; count++; - } - else if (*pbuf) + } else if (*pbuf) send = 1; if (count == MAXMODEPARAMS) @@ -486,7 +489,8 @@ void add_send_mode_param(Channel *channel, Client *from, char what, char mode, c strlcpy(pbuf, param, sizeof(pbuf)); *modes++ = mode; count = 1; - } else { + } else + { count = 0; } *modes = 0; diff --git a/src/modules/extended-isupport.c b/src/modules/extended-isupport.c index 0967b05f9..a6f232bc2 100644 --- a/src/modules/extended-isupport.c +++ b/src/modules/extended-isupport.c @@ -29,13 +29,12 @@ CMD_FUNC(cmd_isupport); /* Variables */ long CAP_EXTISUPPORT = 0L; -ModuleHeader MOD_HEADER -={ - "extended-isupport", /* Name of module */ - "5.0", /* Version */ - "Implements IRCv3 draft/extended-isupport", /* Short description of module */ - "UnrealIRCd Team", /* Author */ - "unrealircd-6", /* Version of UnrealIRCd */ +ModuleHeader MOD_HEADER = { + "extended-isupport", /* Name of module */ + "5.0", /* Version */ + "Implements IRCv3 draft/extended-isupport", /* Short description of module */ + "UnrealIRCd Team", /* Author */ + "unrealircd-6", /* Version of UnrealIRCd */ }; // Module initialization @@ -48,7 +47,7 @@ MOD_INIT() cap.name = "draft/extended-isupport"; ClientCapabilityAdd(modinfo->handle, &cap, &CAP_EXTISUPPORT); - CommandAdd(modinfo->handle, "ISUPPORT", cmd_isupport, 0, CMD_USER|CMD_UNREGISTERED); + CommandAdd(modinfo->handle, "ISUPPORT", cmd_isupport, 0, CMD_USER | CMD_UNREGISTERED); return MOD_SUCCESS; } diff --git a/src/modules/extended-monitor.c b/src/modules/extended-monitor.c index 12b78c75a..cefb8128b 100644 --- a/src/modules/extended-monitor.c +++ b/src/modules/extended-monitor.c @@ -38,20 +38,19 @@ int extended_monitor_userhost_change(Client *client, const char *olduser, const int extended_monitor_realname_change(Client *client, const char *oldinfo); int extended_monitor_notification(Client *client, Watch *watch, Link *lp, int event, void *data); -ModuleHeader MOD_HEADER - = { - "extended-monitor", - "5.0", - "extended functionality for /monitor", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "extended-monitor", + "5.0", + "extended functionality for /monitor", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { ClientCapabilityInfo cap; ClientCapability *c; - + MARK_AS_OFFICIAL_MODULE(modinfo); ModDataInfo mreq; @@ -159,7 +158,6 @@ int extended_monitor_notification(Client *client, Watch *watch, Link *lp, int ev default: break; } - + return 0; } - diff --git a/src/modules/extjwt.c b/src/modules/extjwt.c index 35192c9b6..ced1426b9 100644 --- a/src/modules/extjwt.c +++ b/src/modules/extjwt.c @@ -24,29 +24,29 @@ /* internal definitions */ -#define MSG_EXTJWT "EXTJWT" -#define MYCONF "extjwt" +#define MSG_EXTJWT "EXTJWT" +#define MYCONF "extjwt" #undef NEW_ISUPPORT /* enable this for https://github.com/ircv3/ircv3-specifications/pull/341#issuecomment-617038799 */ #define EXTJWT_METHOD_NOT_SET 0 -#define EXTJWT_METHOD_HS256 1 -#define EXTJWT_METHOD_HS384 2 -#define EXTJWT_METHOD_HS512 3 -#define EXTJWT_METHOD_RS256 4 -#define EXTJWT_METHOD_RS384 5 -#define EXTJWT_METHOD_RS512 6 -#define EXTJWT_METHOD_ES256 7 -#define EXTJWT_METHOD_ES384 8 -#define EXTJWT_METHOD_ES512 9 -#define EXTJWT_METHOD_NONE 10 +#define EXTJWT_METHOD_HS256 1 +#define EXTJWT_METHOD_HS384 2 +#define EXTJWT_METHOD_HS512 3 +#define EXTJWT_METHOD_RS256 4 +#define EXTJWT_METHOD_RS384 5 +#define EXTJWT_METHOD_RS512 6 +#define EXTJWT_METHOD_ES256 7 +#define EXTJWT_METHOD_ES384 8 +#define EXTJWT_METHOD_ES512 9 +#define EXTJWT_METHOD_NONE 10 -#define NEEDS_KEY(x) (x>=EXTJWT_METHOD_RS256 && x<=EXTJWT_METHOD_ES512) +#define NEEDS_KEY(x) (x >= EXTJWT_METHOD_RS256 && x <= EXTJWT_METHOD_ES512) -#define URL_LENGTH 4096 -#define MODES_SIZE 41 /* about 10 mode chars */ -#define TS_LENGTH 19 /* 64-bit integer */ -#define MAX_TOKEN_CHUNK (510-sizeof(extjwt_message_pattern)-HOSTLEN-CHANNELLEN) +#define URL_LENGTH 4096 +#define MODES_SIZE 41 /* about 10 mode chars */ +#define TS_LENGTH 19 /* 64-bit integer */ +#define MAX_TOKEN_CHUNK (510 - sizeof(extjwt_message_pattern) - HOSTLEN - CHANNELLEN) /* OpenSSL 1.0.x compatibility */ @@ -58,8 +58,8 @@ void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) if (ps != NULL) *ps = sig->s; } -#define EVP_MD_CTX_new EVP_MD_CTX_create -#define EVP_MD_CTX_free EVP_MD_CTX_destroy + #define EVP_MD_CTX_new EVP_MD_CTX_create + #define EVP_MD_CTX_free EVP_MD_CTX_destroy #endif /* struct definitions */ @@ -83,9 +83,9 @@ CMD_FUNC(cmd_extjwt); char *extjwt_make_payload(Client *client, Channel *channel, struct extjwt_config *config); char *extjwt_generate_token(const char *payload, struct extjwt_config *config); void b64url(char *b64); -unsigned char *extjwt_hmac_extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int* resultlen); -unsigned char *extjwt_sha_pem_extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int* resultlen); -unsigned char *extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int* resultlen); +unsigned char *extjwt_hmac_extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int *resultlen); +unsigned char *extjwt_sha_pem_extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int *resultlen); +unsigned char *extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int *resultlen); char *extjwt_gen_header(int method); int extjwt_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs); int extjwt_configrun(ConfigFile *cf, ConfigEntry *ce, int type); @@ -107,11 +107,11 @@ const char extjwt_message_pattern[] = ":%s EXTJWT %s %s %s%s"; /* global structs */ ModuleHeader MOD_HEADER = { - "extjwt", - "6.1", - "Command /EXTJWT (web service authorization)", - "UnrealIRCd Team", - "unrealircd-6", + "extjwt", + "6.1", + "Command /EXTJWT (web service authorization)", + "UnrealIRCd Team", + "unrealircd-6", }; struct { @@ -174,7 +174,7 @@ char *extjwt_isupport_param(void) strlcpy(buf, "V:1", sizeof(buf)); while (services) { - strlcat(buf, count?",":"&S:", sizeof(buf)); + strlcat(buf, count ? "," : "&S:", sizeof(buf)); strlcat(buf, services->name, sizeof(buf)); count++; services = services->next; @@ -183,7 +183,8 @@ char *extjwt_isupport_param(void) } #endif -void extjwt_free_services(struct jwt_service **services){ +void extjwt_free_services(struct jwt_service **services) +{ struct jwt_service *ss, *next; ss = *services; while (ss) @@ -217,7 +218,8 @@ int extjwt_valid_integer_string(const char *in, int min, int max) int i, val; if (BadPtr(in)) return 0; - for (i=0; in[i]; i++){ + for (i = 0; in[i]; i++) + { if (!isdigit(in[i])) return 0; } @@ -245,13 +247,18 @@ char *extjwt_test_key(const char *file, int method) BIO *bufkey = NULL; EVP_PKEY *pkey = NULL; int type, pkey_type; - do { + do + { switch (method) { - case EXTJWT_METHOD_RS256: case EXTJWT_METHOD_RS384: case EXTJWT_METHOD_RS512: + case EXTJWT_METHOD_RS256: + case EXTJWT_METHOD_RS384: + case EXTJWT_METHOD_RS512: type = EVP_PKEY_RSA; break; - case EXTJWT_METHOD_ES256: case EXTJWT_METHOD_ES384: case EXTJWT_METHOD_ES512: + case EXTJWT_METHOD_ES256: + case EXTJWT_METHOD_ES384: + case EXTJWT_METHOD_ES512: type = EVP_PKEY_EC; break; default: @@ -569,7 +576,8 @@ int extjwt_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) errors++; continue; } - if (!have_scert && NEEDS_KEY(have_smethod)) { + if (!have_scert && NEEDS_KEY(have_smethod)) + { config_error("%s:%i: invalid %s::service entry (must contain %s::service::key option)", cep->file->filename, cep->line_number, MYCONF, MYCONF); errors++; continue; @@ -629,7 +637,7 @@ int extjwt_configposttest(int *errs) if (NEEDS_KEY(cfg_state.have_method) && cfg_state.have_key && cfg_state.key_filename) { char *keyerr; - + keyerr = extjwt_test_key(cfg_state.key_filename, cfg_state.have_method); if (keyerr) { @@ -769,7 +777,7 @@ CMD_FUNC(cmd_extjwt) struct jwt_service *service = NULL; struct extjwt_config *config; int last = 0; - char message[MAX_TOKEN_CHUNK+1]; + char message[MAX_TOKEN_CHUNK + 1]; if (parc < 2 || BadPtr(parv[1])) { sendnumeric(client, ERR_NEEDMOREPARAMS, MSG_EXTJWT); @@ -796,9 +804,11 @@ CMD_FUNC(cmd_extjwt) return; } } - if (service){ + if (service) + { config = service->cfg; /* service config */ - } else { + } else + { config = &cfg; /* default config */ } if (!(payload = extjwt_make_payload(client, channel, config)) || !(full_token = extjwt_generate_token(payload, config))) @@ -816,10 +826,10 @@ CMD_FUNC(cmd_extjwt) strcpy(message, token); } else { /* send a chunk and shift buffer */ - strlcpy(message, token, MAX_TOKEN_CHUNK+1); + strlcpy(message, token, MAX_TOKEN_CHUNK + 1); token += MAX_TOKEN_CHUNK; } - sendto_one(client, NULL, extjwt_message_pattern, me.name, parv[1], "*", last?"":"* ", message); + sendto_one(client, NULL, extjwt_message_pattern, me.name, parv[1], "*", last ? "" : "* ", message); } while (!last); safe_free(full_token); } @@ -831,7 +841,7 @@ char *extjwt_make_payload(Client *client, Channel *channel, struct extjwt_config json_t *modes = NULL; json_t *umodes = NULL; char *modestring; - char singlemode[2] = { '\0' }; + char singlemode[2] = {'\0'}; char *result; if (!IsUser(client)) @@ -839,12 +849,12 @@ char *extjwt_make_payload(Client *client, Channel *channel, struct extjwt_config payload = json_object(); umodes = json_array(); - - json_object_set_new(payload, "exp", json_integer(TStime()+config->exp_delay)); + + json_object_set_new(payload, "exp", json_integer(TStime() + config->exp_delay)); json_object_set_new(payload, "iss", json_string_unreal(me.name)); json_object_set_new(payload, "sub", json_string_unreal(client->name)); - json_object_set_new(payload, "account", json_string_unreal(IsLoggedIn(client)?client->user->account:"")); - + json_object_set_new(payload, "account", json_string_unreal(IsLoggedIn(client) ? client->user->account : "")); + if (config->vfy) /* also add the URL */ json_object_set_new(payload, "vfy", json_string_unreal(config->vfy)); @@ -867,7 +877,7 @@ char *extjwt_make_payload(Client *client, Channel *channel, struct extjwt_config } } json_object_set_new(payload, "channel", json_string_unreal(channel->name)); - json_object_set_new(payload, "joined", json_integer(lp?1:0)); + json_object_set_new(payload, "joined", json_integer(lp ? 1 : 0)); json_object_set_new(payload, "cmodes", modes); } result = json_dumps(payload, JSON_COMPACT); @@ -892,19 +902,26 @@ void b64url(char *b64) } } -unsigned char *extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int* resultlen) +unsigned char *extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int *resultlen) { - switch(method) + switch (method) { - case EXTJWT_METHOD_HS256: case EXTJWT_METHOD_HS384: case EXTJWT_METHOD_HS512: + case EXTJWT_METHOD_HS256: + case EXTJWT_METHOD_HS384: + case EXTJWT_METHOD_HS512: return extjwt_hmac_extjwt_hash(method, key, keylen, data, datalen, resultlen); - case EXTJWT_METHOD_RS256: case EXTJWT_METHOD_RS384: case EXTJWT_METHOD_RS512: case EXTJWT_METHOD_ES256: case EXTJWT_METHOD_ES384: case EXTJWT_METHOD_ES512: + case EXTJWT_METHOD_RS256: + case EXTJWT_METHOD_RS384: + case EXTJWT_METHOD_RS512: + case EXTJWT_METHOD_ES256: + case EXTJWT_METHOD_ES384: + case EXTJWT_METHOD_ES512: return extjwt_sha_pem_extjwt_hash(method, key, keylen, data, datalen, resultlen); } return NULL; } -unsigned char* extjwt_sha_pem_extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int* resultlen) +unsigned char *extjwt_sha_pem_extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int *resultlen) { EVP_MD_CTX *mdctx = NULL; ECDSA_SIG *ec_sig = NULL; @@ -1005,13 +1022,13 @@ unsigned char* extjwt_sha_pem_extjwt_hash(int method, const void *key, int keyle ECDSA_SIG_get0(ec_sig, &ec_sig_r, &ec_sig_s); r_len = BN_num_bytes(ec_sig_r); s_len = BN_num_bytes(ec_sig_s); - bn_len = (degree+7)/8; + bn_len = (degree + 7) / 8; if (r_len > bn_len || s_len > bn_len) break; - buf_len = bn_len*2; + buf_len = bn_len * 2; raw_buf = safe_alloc(buf_len); - BN_bn2bin(ec_sig_r, raw_buf+bn_len-r_len); - BN_bn2bin(ec_sig_s, raw_buf+buf_len-s_len); + BN_bn2bin(ec_sig_r, raw_buf + bn_len - r_len); + BN_bn2bin(ec_sig_s, raw_buf + buf_len - s_len); output = safe_alloc(buf_len); *resultlen = buf_len; memcpy(output, raw_buf, buf_len); @@ -1032,9 +1049,9 @@ unsigned char* extjwt_sha_pem_extjwt_hash(int method, const void *key, int keyle return retval; } -unsigned char* extjwt_hmac_extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int* resultlen) +unsigned char *extjwt_hmac_extjwt_hash(int method, const void *key, int keylen, const unsigned char *data, int datalen, unsigned int *resultlen) { - const EVP_MD* typ; + const EVP_MD *typ; char *hmac = safe_alloc(EVP_MAX_MD_SIZE); switch (method) { @@ -1052,7 +1069,8 @@ unsigned char* extjwt_hmac_extjwt_hash(int method, const void *key, int keylen, if (HMAC(typ, key, keylen, data, datalen, hmac, resultlen)) { /* openssl call */ return hmac; - } else { + } else + { safe_free(hmac); return NULL; } @@ -1110,9 +1128,9 @@ char *extjwt_gen_header(int method) char *extjwt_generate_token(const char *payload, struct extjwt_config *config) { char *header = extjwt_gen_header(config->method); - size_t b64header_size = strlen(header)*4/3 + 8; // base64 has 4/3 overhead - size_t b64payload_size = strlen(payload)*4/3 + 8; - size_t b64sig_size = 4096*4/3 + 8; + size_t b64header_size = strlen(header) * 4 / 3 + 8; // base64 has 4/3 overhead + size_t b64payload_size = strlen(payload) * 4 / 3 + 8; + size_t b64sig_size = 4096 * 4 / 3 + 8; size_t b64data_size = b64header_size + b64payload_size + b64sig_size + 4; char *b64header = safe_alloc(b64header_size); char *b64payload = safe_alloc(b64payload_size); diff --git a/src/modules/geoip-tag.c b/src/modules/geoip-tag.c index fdcb4d885..3b868977d 100644 --- a/src/modules/geoip-tag.c +++ b/src/modules/geoip-tag.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "geoip-tag", - "6.0", - "geoip message tag", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "geoip-tag", + "6.0", + "geoip message tag", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int geoip_mtag_is_ok(Client *client, const char *name, const char *value); @@ -80,7 +79,7 @@ int geoip_mtag_is_ok(Client *client, const char *name, const char *value) void mtag_add_geoip(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature) { MessageTag *m; - + GeoIPResult *geoip; if (IsUser(client) && ((geoip = geoip_client(client)))) @@ -89,7 +88,8 @@ void mtag_add_geoip(Client *client, MessageTag *recv_mtags, MessageTag **mtag_li if (m) { m = duplicate_mtag(m); - } else { + } else + { m = safe_alloc(sizeof(MessageTag)); safe_strdup(m->name, "unrealircd.org/geoip"); safe_strdup(m->value, geoip->country_code); diff --git a/src/modules/geoip_base.c b/src/modules/geoip_base.c index 3e846b9c0..1433eb915 100644 --- a/src/modules/geoip_base.c +++ b/src/modules/geoip_base.c @@ -7,14 +7,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "geoip_base", - "5.0", - "Base module for geoip", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "geoip_base", + "5.0", + "Base module for geoip", + "UnrealIRCd Team", + "unrealircd-6", +}; struct geoip_base_config_s { int check_on_load; @@ -43,15 +42,15 @@ struct geoip_base_config_s geoip_base_config; * should use geoip_client(client) ! */ -#define GEOIPDATARAW(x) (moddata_client((x), geoip_md).ptr) -#define GEOIPDATA(x) ((GeoIPResult *)moddata_client((x), geoip_md).ptr) +#define GEOIPDATARAW(x) (moddata_client((x), geoip_md).ptr) +#define GEOIPDATA(x) ((GeoIPResult *)moddata_client((x), geoip_md).ptr) int geoip_base_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { ConfigEntry *cep; int errors = 0; int i; - + if (type != CONFIG_SET) return 0; @@ -70,7 +69,7 @@ int geoip_base_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } config_warn("%s:%i: unknown item geoip::%s", cep->file->filename, cep->line_number, cep->name); } - + *errs = errors; return errors ? -1 : 1; } @@ -126,7 +125,7 @@ MOD_INIT() HookAdd(modinfo->handle, HOOKTYPE_IP_CHANGE, 0, geoip_base_ip_change); HookAdd(modinfo->handle, HOOKTYPE_SERVER_HANDSHAKE_OUT, 0, geoip_base_handshake); HookAdd(modinfo->handle, HOOKTYPE_CONNECT_EXTINFO, 1, geoip_connect_extinfo); /* (prio: near-first) */ - HookAdd(modinfo->handle, HOOKTYPE_PRE_LOCAL_CONNECT, 0,geoip_base_handshake); /* in case the IP changed in registration phase (WEBIRC, HTTP Forwarded) */ + HookAdd(modinfo->handle, HOOKTYPE_PRE_LOCAL_CONNECT, 0, geoip_base_handshake); /* in case the IP changed in registration phase (WEBIRC, HTTP Forwarded) */ HookAdd(modinfo->handle, HOOKTYPE_WHOIS, 0, geoip_base_whois_country); HookAdd(modinfo->handle, HOOKTYPE_WHOIS, 0, geoip_base_whois_asn); HookAdd(modinfo->handle, HOOKTYPE_JSON_EXPAND_CLIENT, 0, geoip_json_expand_client); @@ -224,22 +223,23 @@ const char *geoip_base_serialize(ModData *m) if (geo->asname) { snprintf(buf, sizeof(buf), "cc=%s|cd=%s|asn=%u|asname=%s", - geo->country_code, - geo->country_name, - geo->asn, - geoip_sanitized_asname(geo->asname)); - } else { + geo->country_code, + geo->country_name, + geo->asn, + geoip_sanitized_asname(geo->asname)); + } else + { snprintf(buf, sizeof(buf), "cc=%s|cd=%s|asn=%u", - geo->country_code, - geo->country_name, - geo->asn); + geo->country_code, + geo->country_name, + geo->asn); } return buf; } void geoip_base_unserialize(const char *str, ModData *m) { - char buf[512], *p=NULL, *varname, *value; + char buf[512], *p = NULL, *varname, *value; char *country_name = NULL; char *country_code = NULL; long asn = 0; @@ -370,11 +370,11 @@ int geoip_base_whois_asn(Client *client, Client *target, NameValuePrioList **lis // WHOIS_CONFIG_DETAILS_LIMITED / WHOIS_CONFIG_DETAILS_FULL distinction makes no sense here add_nvplist_numeric_fmt(list, 0, "asn", client, RPL_WHOISASN, - "%s %u :is connecting from AS%u [%s]", - target->name, - geo->asn, - geo->asn, - geo->asname ? geo->asname : "UNKNOWN"); + "%s %u :is connecting from AS%u [%s]", + target->name, + geo->asn, + geo->asn, + geo->asname ? geo->asname : "UNKNOWN"); return 0; } @@ -399,7 +399,8 @@ CMD_FUNC(cmd_geoip) if (strchr(parv[1], '.') || strchr(parv[1], ':')) { ip = parv[1]; - } else { + } else + { target = find_user(parv[1], NULL); if (!target) { @@ -421,7 +422,8 @@ CMD_FUNC(cmd_geoip) { sendnotice(client, "- No information available"); return; - } else { + } else + { if (res->country_code) sendnotice(client, "- Country code: %s", res->country_code); if (res->country_name) diff --git a/src/modules/geoip_classic.c b/src/modules/geoip_classic.c index 2b6306123..841e8bca6 100644 --- a/src/modules/geoip_classic.c +++ b/src/modules/geoip_classic.c @@ -6,14 +6,13 @@ #include "unrealircd.h" #include -ModuleHeader MOD_HEADER - = { - "geoip_classic", - "5.0", - "GEOIP using classic databases", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "geoip_classic", + "5.0", + "GEOIP using classic databases", + "UnrealIRCd Team", + "unrealircd-6", +}; struct geoip_classic_config_s { char *v4_db_file; @@ -48,7 +47,7 @@ int geoip_classic_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *err ConfigEntry *cep; int errors = 0; int i; - + if (type != CONFIG_SET) return 0; @@ -128,7 +127,7 @@ int geoip_classic_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *err } config_warn("%s:%i: unknown item set::geoip-classic::%s", cep->file->filename, cep->line_number, cep->name); } - + *errs = errors; return errors ? -1 : 1; } @@ -189,7 +188,8 @@ int geoip_classic_configposttest(int *errs) if (!geoip_classic_config.have_ipv4_database && !geoip_classic_config.have_ipv6_database) { config_error("[geoip_classic] couldn't read any database! Either put these in %s location " - "or specify another in set::geoip-classic config block", PERMDATADIR); + "or specify another in set::geoip-classic config block", + PERMDATADIR); errors++; } /* The ASN ones are optional */ @@ -269,9 +269,9 @@ MOD_LOAD() { int save_err = errno; unreal_log(ULOG_WARNING, "geoip_classic", "GEOIP_CANNOT_OPEN_DB", NULL, - "[IPv4] Could not open '$filename': $system_error", - log_data_string("filename", geoip_classic_config.v4_db_file), - log_data_string("system_error", strerror(save_err))); + "[IPv4] Could not open '$filename': $system_error", + log_data_string("filename", geoip_classic_config.v4_db_file), + log_data_string("system_error", strerror(save_err))); } } if (geoip_classic_config.v6_db_file) @@ -285,9 +285,9 @@ MOD_LOAD() { int save_err = errno; unreal_log(ULOG_WARNING, "geoip_classic", "GEOIP_CANNOT_OPEN_DB", NULL, - "[IPv6] Could not open '$filename': $system_error", - log_data_string("filename", geoip_classic_config.v6_db_file), - log_data_string("system_error", strerror(save_err))); + "[IPv6] Could not open '$filename': $system_error", + log_data_string("filename", geoip_classic_config.v6_db_file), + log_data_string("system_error", strerror(save_err))); } convert_to_absolute_path(&geoip_classic_config.v6_db_file, PERMDATADIR); } @@ -295,7 +295,7 @@ MOD_LOAD() if (!found_good_file) { unreal_log(ULOG_ERROR, "geoip_classic", "GEOIP_CANNOT_OPEN_DB", NULL, - "could not open any database!"); + "could not open any database!"); return MOD_FAILED; } @@ -308,9 +308,9 @@ MOD_LOAD() { int save_err = errno; unreal_log(ULOG_WARNING, "geoip_classic", "GEOIP_CANNOT_OPEN_DB", NULL, - "[ASN IPv4] Could not open '$filename': $system_error", - log_data_string("filename", geoip_classic_config.asn_v4_db_file), - log_data_string("system_error", strerror(save_err))); + "[ASN IPv4] Could not open '$filename': $system_error", + log_data_string("filename", geoip_classic_config.asn_v4_db_file), + log_data_string("system_error", strerror(save_err))); } } @@ -322,9 +322,9 @@ MOD_LOAD() { int save_err = errno; unreal_log(ULOG_WARNING, "geoip_classic", "GEOIP_CANNOT_OPEN_DB", NULL, - "[ASN IPv6] Could not open '$filename': $system_error", - log_data_string("filename", geoip_classic_config.asn_v6_db_file), - log_data_string("system_error", strerror(save_err))); + "[ASN IPv6] Could not open '$filename': $system_error", + log_data_string("filename", geoip_classic_config.asn_v6_db_file), + log_data_string("system_error", strerror(save_err))); } } @@ -359,7 +359,7 @@ GeoIPResult *geoip_lookup_classic(char *ip) { static char buf[256]; const char *country_code, *country_name; - char *isp=NULL; + char *isp = NULL; GeoIPLookup gl, asn_gl; GeoIP *gi; int geoid; @@ -414,7 +414,7 @@ GeoIPResult *geoip_lookup_classic(char *ip) if ((isp[0] == 'A') && (isp[1] == 'S') && isdigit(isp[2])) { char *p; - r->asn = strtoul(isp+2, NULL, 10); + r->asn = strtoul(isp + 2, NULL, 10); p = strchr(isp, ' '); if (p) { diff --git a/src/modules/geoip_csv.c b/src/modules/geoip_csv.c index 3cc90f5ee..fe899f489 100644 --- a/src/modules/geoip_csv.c +++ b/src/modules/geoip_csv.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "geoip_csv", - "5.0", - "GEOIP using csv data files", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "geoip_csv", + "5.0", + "GEOIP using csv data files", + "UnrealIRCd Team", + "unrealircd-6", +}; struct geoip_csv_config_s { char *v4_db_file; @@ -94,7 +93,7 @@ int geoip_csv_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) ConfigEntry *cep; int errors = 0; int i; - + if (type != CONFIG_SET) return 0; @@ -158,7 +157,7 @@ int geoip_csv_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } config_warn("%s:%i: unknown item set::geoip-csv::%s", cep->file->filename, cep->line_number, cep->name); } - + *errs = errors; return errors ? -1 : 1; } @@ -209,7 +208,8 @@ int geoip_csv_configposttest(int *errs) if (!geoip_csv_config.have_ipv4_database && !geoip_csv_config.have_ipv6_database) { config_error("[geoip_csv] couldn't read any blocks file! Either put these in %s location " - "or specify another in set::geoip-csv config block", PERMDATADIR); + "or specify another in set::geoip-csv config block", + PERMDATADIR); errors++; } } @@ -295,7 +295,7 @@ MOD_LOAD() if (!geoip_csv_config.countries_db_file) { unreal_log(ULOG_DEBUG, "geoip_csv", "GEOIP_NO_COUNTRIES", NULL, - "[BUG] No countries file specified"); + "[BUG] No countries file specified"); geoip_csv_free(); return MOD_FAILED; } @@ -303,7 +303,7 @@ MOD_LOAD() if (geoip_csv_read_countries(geoip_csv_config.countries_db_file)) { unreal_log(ULOG_ERROR, "geoip_csv", "GEOIP_CANNOT_OPEN_DB", NULL, - "could not open required countries file!"); + "could not open required countries file!"); geoip_csv_free(); return MOD_FAILED; } @@ -311,7 +311,7 @@ MOD_LOAD() if (!found_good_file) { unreal_log(ULOG_ERROR, "geoip_csv", "GEOIP_CANNOT_OPEN_DB", NULL, - "could not open any database!"); + "could not open any database!"); geoip_csv_free(); return MOD_FAILED; } @@ -328,7 +328,7 @@ static void geoip_csv_free_ipv4(void) { struct geoip_csv_ip_range *ptr, *oldptr; int i; - for (i=0; i<256; i++) + for (i = 0; i < 256; i++) { ptr = geoip_csv_ip_range_list[i]; geoip_csv_ip_range_list[i] = NULL; @@ -377,13 +377,13 @@ static void geoip_csv_free(void) /* reading data from files */ #define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) -#define BUFLEN 8191 +#define STR(x) STR_HELPER(x) +#define BUFLEN 8191 static int geoip_csv_read_ipv4(char *file) { FILE *u; - char buf[BUFLEN+1]; + char buf[BUFLEN + 1]; int cidr, geoid; char ip[24]; char netmask[24]; @@ -394,7 +394,7 @@ static int geoip_csv_read_ipv4(char *file) memset(curr, 0, sizeof(curr)); int i; char *filename = NULL; - + safe_strdup(filename, file); convert_to_absolute_path(&filename, CONFDIR); u = fopen(filename, "r"); @@ -404,7 +404,7 @@ static int geoip_csv_read_ipv4(char *file) config_warn("[geoip_csv] Cannot open IPv4 ranges list file"); return 1; } - + if (!fgets(buf, BUFLEN, u)) { config_warn("[geoip_csv] IPv4 list file is empty"); @@ -432,19 +432,19 @@ static int geoip_csv_read_ipv4(char *file) continue; } addr = htonl(addr); - + mask = 0; while (cidr) { /* calculate netmask */ mask >>= 1; - mask |= (1<<31); + mask |= (1 << 31); cidr--; } - - i=0; + + i = 0; do { /* multiple iterations in case CIDR is <8 and we have multiple first octets matching */ - uint8_t index = addr>>24; + uint8_t index = addr >> 24; if (!curr[index]) { geoip_csv_ip_range_list[index] = safe_alloc(sizeof(struct geoip_csv_ip_range)); @@ -461,7 +461,7 @@ static int geoip_csv_read_ipv4(char *file) ptr->geoid = geoid; i++; index++; - } while (i<=((~mask)>>24)); + } while (i <= ((~mask) >> 24)); } fclose(u); return 0; @@ -473,19 +473,19 @@ static int geoip_csv_ip6_convert(char *ip, uint16_t out[8]) int i; if (inet_pton(AF_INET6, ip, out) < 1) return 0; - for (i=0; i<8; i++) + for (i = 0; i < 8; i++) { out[i] = htons(out[i]); } return 1; } -#define IPV6_STRING_SIZE 40 +#define IPV6_STRING_SIZE 40 static int geoip_csv_read_ipv6(char *file) { FILE *u; - char buf[BUFLEN+1]; + char buf[BUFLEN + 1]; char *bptr, *optr; int cidr, geoid; char ip[IPV6_STRING_SIZE]; @@ -527,7 +527,7 @@ static int geoip_csv_read_ipv6(char *file) } if (++length >= IPV6_STRING_SIZE) { - ip[IPV6_STRING_SIZE-1] = '\0'; + ip[IPV6_STRING_SIZE - 1] = '\0'; config_warn("[geoip_csv] Too long IPv6 address found, starts with %s. Bad CSV file?", ip); error = 1; break; @@ -551,11 +551,11 @@ static int geoip_csv_read_ipv6(char *file) } memset(mask, 0, 16); - + int mask_bit = 0; while (cidr) { /* calculate netmask */ - mask[mask_bit/16] |= 1<<(15-(mask_bit%16)); + mask[mask_bit / 16] |= 1 << (15 - (mask_bit % 16)); mask_bit++; cidr--; } @@ -580,14 +580,14 @@ static int geoip_csv_read_ipv6(char *file) } /* CSV fields; no STATE_GEONAME_ID because of using %d in fscanf */ -#define STATE_LOCALE_CODE 0 -#define STATE_CONTINENT_CODE 1 -#define STATE_CONTINENT_NAME 2 -#define STATE_COUNTRY_ISO_CODE 3 -#define STATE_COUNTRY_NAME 4 -#define STATE_IS_IN_EU 5 +#define STATE_LOCALE_CODE 0 +#define STATE_CONTINENT_CODE 1 +#define STATE_CONTINENT_NAME 2 +#define STATE_COUNTRY_ISO_CODE 3 +#define STATE_COUNTRY_NAME 4 +#define STATE_IS_IN_EU 5 -#define MEMBER_SIZE(type,member) sizeof(((type *)0)->member) +#define MEMBER_SIZE(type, member) sizeof(((type *)0)->member) static int geoip_csv_read_countries(char *file) { @@ -595,7 +595,7 @@ static int geoip_csv_read_countries(char *file) char code[MEMBER_SIZE(struct geoip_csv_country, code)]; char continent[MEMBER_SIZE(struct geoip_csv_country, continent)]; char name[MEMBER_SIZE(struct geoip_csv_country, name)]; - char buf[BUFLEN+1]; + char buf[BUFLEN + 1]; int state; int id; struct geoip_csv_country *curr = NULL; @@ -610,7 +610,7 @@ static int geoip_csv_read_countries(char *file) config_warn("[geoip_csv] Cannot open countries list file"); return 1; } - + if (!fgets(buf, BUFLEN, u)) { config_warn("[geoip_csv] Countries list file is empty"); @@ -644,8 +644,8 @@ static int geoip_csv_read_countries(char *file) length++; break; case STATE_COUNTRY_ISO_CODE: - if (*ptr == ',') /* country code is empty */ - goto next_line; /* -- that means only the continent is specified - we ignore it completely */ + if (*ptr == ',') /* country code is empty */ + goto next_line; /* -- that means only the continent is specified - we ignore it completely */ if (length >= MEMBER_SIZE(struct geoip_csv_country, code) - 1) { *codeptr = '\0'; @@ -669,7 +669,7 @@ static int geoip_csv_read_countries(char *file) state++; } } - read_country_name: + read_country_name: *codeptr = '\0'; *contptr = '\0'; length = 0; @@ -697,7 +697,7 @@ static int geoip_csv_read_countries(char *file) break; // scan for country name } } - end_country_name: + end_country_name: *nptr = '\0'; if (geoip_csv_country_list) { @@ -713,7 +713,8 @@ static int geoip_csv_read_countries(char *file) strcpy(curr->name, name); strcpy(curr->continent, continent); curr->id = id; - next_line: continue; + next_line: + continue; } fclose(u); return 0; @@ -725,7 +726,7 @@ static struct geoip_csv_country *geoip_csv_get_country(int id) if (!curr) return NULL; int found = 0; - for (;curr;curr = curr->next) + for (; curr; curr = curr->next) { if (curr->id == id) { @@ -750,11 +751,11 @@ static int geoip_csv_get_v4_geoid(char *iip) return 0; } addr = htonl(addr); - curr = geoip_csv_ip_range_list[addr>>24]; + curr = geoip_csv_ip_range_list[addr >> 24]; if (curr) { i = 0; - for (;curr;curr = curr->next) + for (; curr; curr = curr->next) { tmp_addr = addr; tmp_addr &= curr->mask; /* mask the address to filter out net prefix only */ @@ -777,7 +778,7 @@ static int geoip_csv_get_v6_geoid(char *iip) struct geoip_csv_ip6_range *curr; int i; int found = 0; - + if (!geoip_csv_ip6_convert(iip, addr)) { unreal_log(ULOG_WARNING, "geoip_csv", "UNSUPPORTED_IP", NULL, "Invalid or unsupported client IP $ip", log_data_string("ip", iip)); @@ -786,10 +787,10 @@ static int geoip_csv_get_v6_geoid(char *iip) curr = geoip_csv_ip6_range_list; if (curr) { - for (;curr;curr = curr->next) + for (; curr; curr = curr->next) { found = 1; - for (i=0; i<8; i++) + for (i = 0; i < 8; i++) { if (curr->addr[i] != (addr[i] & curr->mask[i])) { /* compare net address to loaded data */ @@ -797,7 +798,7 @@ static int geoip_csv_get_v6_geoid(char *iip) break; } } - if(found) + if (found) break; } } @@ -836,4 +837,3 @@ GeoIPResult *geoip_lookup_csv(char *ip) safe_strdup(r->country_name, country->name); return r; } - diff --git a/src/modules/geoip_mmdb.c b/src/modules/geoip_mmdb.c index a6bb2ad88..c70cd63e4 100644 --- a/src/modules/geoip_mmdb.c +++ b/src/modules/geoip_mmdb.c @@ -6,14 +6,13 @@ #include "unrealircd.h" #include "mmdb.h" -ModuleHeader MOD_HEADER - = { - "geoip_mmdb", - "5.2", - "GEOIP using mmdb databases", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "geoip_mmdb", + "5.2", + "GEOIP using mmdb databases", + "UnrealIRCd Team", + "unrealircd-6", +}; struct geoip_mmdb_config_s { char *db_file; @@ -88,7 +87,7 @@ int geoip_mmdb_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } config_warn("%s:%i: unknown item set::geoip-mmdb::%s", cep->file->filename, cep->line_number, cep->name); } - + *errs = errors; return errors ? -1 : 1; } @@ -159,9 +158,9 @@ MOD_TEST() if (!CallbackAddPVoid(modinfo->handle, CALLBACKTYPE_GEOIP_LOOKUP, TO_PVOIDFUNC(geoip_lookup_mmdb))) { unreal_log(ULOG_ERROR, "geoip_mmdb", "GEOIP_ADD_CALLBACK_FAILED", NULL, - "geoip_mmdb: Could not install GEOIP_LOOKUP callback. " - "Most likely another geoip module is already loaded. " - "You can only load one!"); + "geoip_mmdb: Could not install GEOIP_LOOKUP callback. " + "Most likely another geoip module is already loaded. " + "You can only load one!"); return MOD_FAILED; } @@ -193,9 +192,9 @@ MOD_LOAD() if (status != MMDB_OK) { unreal_log(ULOG_WARNING, "geoip_mmdb", "GEOIP_CANNOT_OPEN_DB", NULL, - "Could not open '$filename' - $mmdb_error", - log_data_string("filename", geoip_mmdb_config.db_file), - log_data_string("mmdb_error", mmdb_strerror(status))); + "Could not open '$filename' - $mmdb_error", + log_data_string("filename", geoip_mmdb_config.db_file), + log_data_string("mmdb_error", mmdb_strerror(status))); geoip_mmdb_config.have_database = 0; } } @@ -207,9 +206,9 @@ MOD_LOAD() if (status != MMDB_OK) { unreal_log(ULOG_WARNING, "geoip_mmdb", "GEOIP_CANNOT_OPEN_ASN_DB", NULL, - "Could not open '$filename' - $mmdb_error", - log_data_string("filename", geoip_mmdb_config.asn_db_file), - log_data_string("mmdb_error", mmdb_strerror(status))); + "Could not open '$filename' - $mmdb_error", + log_data_string("filename", geoip_mmdb_config.asn_db_file), + log_data_string("mmdb_error", mmdb_strerror(status))); geoip_mmdb_config.have_asn_database = 0; } } @@ -248,9 +247,9 @@ GeoIPResult *geoip_lookup_mmdb(char *ip) if (status != MMDB_OK) { unreal_log(ULOG_DEBUG, "geoip_mmdb", "GEOIP_DB_ERROR", NULL, - "mmdb: lookup error for $ip: $error", - log_data_string("ip", ip), - log_data_string("error", mmdb_strerror(status))); + "mmdb: lookup error for $ip: $error", + log_data_string("ip", ip), + log_data_string("error", mmdb_strerror(status))); return NULL; } @@ -280,9 +279,9 @@ GeoIPResult *geoip_lookup_mmdb(char *ip) if (status != MMDB_OK) { unreal_log(ULOG_DEBUG, "geoip_mmdb", "GEOIP_ASN_DB_ERROR", NULL, - "mmdb: lookup error for $ip: $error", - log_data_string("ip", ip), - log_data_string("error", mmdb_strerror(status))); + "mmdb: lookup error for $ip: $error", + log_data_string("ip", ip), + log_data_string("error", mmdb_strerror(status))); return r; } diff --git a/src/modules/globops.c b/src/modules/globops.c index 284e62c1e..28dbf4890 100644 --- a/src/modules/globops.c +++ b/src/modules/globops.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_globops); -#define MSG_GLOBOPS "GLOBOPS" +#define MSG_GLOBOPS "GLOBOPS" -ModuleHeader MOD_HEADER - = { - "globops", - "5.0", - "command /globops", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "globops", + "5.0", + "command /globops", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_GLOBOPS, cmd_globops, 1, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_GLOBOPS, cmd_globops, 1, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -65,7 +64,7 @@ CMD_FUNC(cmd_globops) return; } - if (MyUser(client) && !ValidatePermissionsForPath("chat:globops",client,NULL,NULL,NULL)) + if (MyUser(client) && !ValidatePermissionsForPath("chat:globops", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -80,6 +79,6 @@ CMD_FUNC(cmd_globops) /* Backward-compatible (3.2.x) */ sendto_umode(UMODE_OPER, "from %s: %s", client->name, message); sendto_server(client, 0, 0, NULL, ":%s SENDUMODE o :from %s: %s", - me.id, client->name, message); + me.id, client->name, message); } } diff --git a/src/modules/help.c b/src/modules/help.c index 7d0e49627..b872a8775 100644 --- a/src/modules/help.c +++ b/src/modules/help.c @@ -24,17 +24,16 @@ CMD_FUNC(cmd_help); -#define MSG_HELP "HELP" -#define MSG_HELPOP "HELPOP" +#define MSG_HELP "HELP" +#define MSG_HELPOP "HELPOP" -ModuleHeader MOD_HEADER - = { - "help", - "5.0", - "command /help", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "help", + "5.0", + "command /help", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -74,7 +73,7 @@ ConfigItem_help *find_Help(const char *command) { if (help->command == NULL) continue; - else if (!strcasecmp(command,help->command)) + else if (!strcasecmp(command, help->command)) return help; } return NULL; @@ -93,32 +92,34 @@ void parse_help(Client *client, const char *help) HDR(" ***** UnrealIRCd Help System *****"); SND(" -"); text = helpitem->text; - while (text) { + while (text) + { SND(text->line); text = text->next; } SND(" -"); return; - } helpitem = find_Help(help); - if (!helpitem) { + if (!helpitem) + { SND(" -"); HDR(" ***** No Help Available *****"); SND(" -"); SND(" We're sorry, we don't have help available for the command you requested."); SND(" -"); sendto_one(client, NULL, ":%s 292 %s : ***** Go to %s if you have any further questions *****", - me.name, client->name, HELP_CHANNEL); + me.name, client->name, HELP_CHANNEL); SND(" -"); return; } text = helpitem->text; SND(" -"); sendto_one(client, NULL, ":%s 290 %s :***** %s *****", - me.name, client->name, helpitem->command); + me.name, client->name, helpitem->command); SND(" -"); - while (text) { + while (text) + { SND(text->line); text = text->next; } @@ -137,7 +138,7 @@ CMD_FUNC(cmd_help) return; /* never remote */ helptopic = parc > 1 ? parv[1] : NULL; - + if (helptopic && (*helptopic == '?')) helptopic++; diff --git a/src/modules/hideserver.c b/src/modules/hideserver.c index d11d00f19..f79564d88 100644 --- a/src/modules/hideserver.c +++ b/src/modules/hideserver.c @@ -33,40 +33,39 @@ ConfigItem_ulines *HiddenServers; static struct { - unsigned disable_map : 1; - unsigned disable_links : 1; - char *map_deny_message; - char *links_deny_message; + unsigned disable_map : 1; + unsigned disable_links : 1; + char *map_deny_message; + char *links_deny_message; } Settings; -static ModuleInfo *MyModInfo; -#define MyMod MyModInfo->handle -#define SAVE_MODINFO MyModInfo = modinfo; +static ModuleInfo *MyModInfo; +#define MyMod MyModInfo->handle +#define SAVE_MODINFO MyModInfo = modinfo; static int lmax = 0; static int umax = 0; static int dcount(int n) { - int cnt = 0; + int cnt = 0; - while (n != 0) - { - n = n/10; - cnt++; - } + while (n != 0) + { + n = n / 10; + cnt++; + } - return cnt; + return cnt; } -ModuleHeader MOD_HEADER - = { - "hideserver", - "5.0", - "Hide servers from /MAP & /LINKS", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "hideserver", + "5.0", + "Hide servers from /MAP & /LINKS", + "UnrealIRCd Team", + "unrealircd-6", +}; static void InitConf() { @@ -75,7 +74,7 @@ static void InitConf() static void FreeConf() { - ConfigItem_ulines *h, *next; + ConfigItem_ulines *h, *next; safe_free(Settings.map_deny_message); safe_free(Settings.links_deny_message); @@ -141,17 +140,15 @@ static int cb_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!strcmp(cep->name, "hide")) { /* No checking needed */ - } - else if (!cep->value) + } else if (!cep->value) { config_error("%s:%i: %s::%s without value", - cep->file->filename, - cep->line_number, - ce->name, cep->name); + cep->file->filename, + cep->line_number, + ce->name, cep->name); errors++; continue; - } - else if (!strcmp(cep->name, "disable-map")) + } else if (!strcmp(cep->name, "disable-map")) ; else if (!strcmp(cep->name, "disable-links")) ; @@ -162,7 +159,7 @@ static int cb_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) else { config_error("%s:%i: unknown directive hideserver::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; } } @@ -176,8 +173,8 @@ static int cb_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) static int cb_conf(ConfigFile *cf, ConfigEntry *ce, int type) { - ConfigEntry *cep, *cepp; - ConfigItem_ulines *ca; + ConfigEntry *cep, *cepp; + ConfigItem_ulines *ca; if (type == CONFIG_MAIN) { @@ -192,12 +189,10 @@ static int cb_conf(ConfigFile *cf, ConfigEntry *ce, int type) else if (!strcmp(cep->name, "map-deny-message")) { safe_strdup(Settings.map_deny_message, cep->value); - } - else if (!strcmp(cep->name, "links-deny-message")) + } else if (!strcmp(cep->name, "links-deny-message")) { safe_strdup(Settings.links_deny_message, cep->value); - } - else if (!strcmp(cep->name, "hide")) + } else if (!strcmp(cep->name, "hide")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -237,7 +232,7 @@ static void dump_map(Client *client, Client *server, char *mask, int prompt_leng { static char prompt[64]; char *p = &prompt[prompt_length]; - int cnt = 0; + int cnt = 0; Client *acptr; *p = '\0'; @@ -261,9 +256,10 @@ static void dump_map(Client *client, Client *server, char *mask, int prompt_leng if (IsOper(client)) snprintf(sid, sizeof(sid), " [%s]", server->id); sendnumeric(client, RPL_MAP, prompt, server->name, tbuf, umax, - server->server->users, (double)(lmax < 10) ? 4 : (lmax == 100) ? 6 : 5, - (server->server->users * 100.0 / irccounts.clients), - IsOper(client) ? sid : ""); + server->server->users, (double)(lmax < 10) ? 4 : (lmax == 100) ? 6 + : 5, + (server->server->users * 100.0 / irccounts.clients), + IsOper(client) ? sid : ""); cnt = 0; } @@ -281,7 +277,7 @@ static void dump_map(Client *client, Client *server, char *mask, int prompt_leng list_for_each_entry(acptr, &global_server_list, client_node) { if (acptr->uplink != server || - (IsULine(acptr) && HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines",client,NULL,NULL,NULL))) + (IsULine(acptr) && HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines", client, NULL, NULL, NULL))) continue; if (FindHiddenServer(acptr->name)) break; @@ -291,7 +287,7 @@ static void dump_map(Client *client, Client *server, char *mask, int prompt_leng list_for_each_entry(acptr, &global_server_list, client_node) { - if (IsULine(acptr) && HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines",client,NULL,NULL,NULL)) + if (IsULine(acptr) && HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines", client, NULL, NULL, NULL)) continue; if (FindHiddenServer(acptr->name)) break; @@ -315,7 +311,7 @@ void dump_flat_map(Client *client, Client *server, int length) Client *acptr; int cnt = 0, len = 0, hide_ulines; - hide_ulines = (HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines",client,NULL,NULL,NULL)) ? 1 : 0; + hide_ulines = (HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines", client, NULL, NULL, NULL)) ? 1 : 0; len = length - strlen(server->name) + 3; if (len < 0) @@ -328,8 +324,9 @@ void dump_flat_map(Client *client, Client *server, int length) tbuf[len--] = '-'; sendnumeric(client, RPL_MAP, "", server->name, tbuf, umax, server->server->users, - (lmax < 10) ? 4 : (lmax == 100) ? 6 : 5, - (server->server->users * 100.0 / irccounts.clients), ""); + (lmax < 10) ? 4 : (lmax == 100) ? 6 + : 5, + (server->server->users * 100.0 / irccounts.clients), ""); list_for_each_entry(acptr, &global_server_list, client_node) { @@ -361,8 +358,9 @@ void dump_flat_map(Client *client, Client *server, int length) tbuf[len--] = '-'; sendnumeric(client, RPL_MAP, buf, acptr->name, tbuf, umax, acptr->server->users, - (lmax < 10) ? 4 : (lmax == 100) ? 6 : 5, - (acptr->server->users * 100.0 / irccounts.clients), ""); + (lmax < 10) ? 4 : (lmax == 100) ? 6 + : 5, + (acptr->server->users * 100.0 / irccounts.clients), ""); } } @@ -383,7 +381,7 @@ CMD_OVERRIDE_FUNC(override_map) if (parc < 2) parv[1] = "*"; - + if (IsOper(client)) { CALL_NEXT_COMMAND_OVERRIDE(); @@ -417,14 +415,14 @@ CMD_OVERRIDE_FUNC(override_map) longest = 60; longest += 2; - if (FLAT_MAP && !ValidatePermissionsForPath("server:info:map:real-map",client,NULL,NULL,NULL)) + if (FLAT_MAP && !ValidatePermissionsForPath("server:info:map:real-map", client, NULL, NULL, NULL)) dump_flat_map(client, &me, longest); else dump_map(client, &me, "*", 0, longest); avg_users = irccounts.clients * 1.0 / irccounts.servers; sendnumeric(client, RPL_MAPUSERS, irccounts.servers, (irccounts.servers > 1 ? "s" : ""), irccounts.clients, - (irccounts.clients > 1 ? "s" : ""), avg_users); + (irccounts.clients > 1 ? "s" : ""), avg_users); sendnumeric(client, RPL_MAPEND); } @@ -451,16 +449,16 @@ CMD_OVERRIDE_FUNC(override_links) list_for_each_entry(acptr, &global_server_list, client_node) { /* Some checks */ - if (HIDE_ULINES && IsULine(acptr) && !ValidatePermissionsForPath("server:info:map:ulines",client,NULL,NULL,NULL)) + if (HIDE_ULINES && IsULine(acptr) && !ValidatePermissionsForPath("server:info:map:ulines", client, NULL, NULL, NULL)) continue; if (FindHiddenServer(acptr->name)) continue; if (flat) sendnumeric(client, RPL_LINKS, acptr->name, me.name, - 1, (acptr->info[0] ? acptr->info : "(Unknown Location)")); + 1, (acptr->info[0] ? acptr->info : "(Unknown Location)")); else sendnumeric(client, RPL_LINKS, acptr->name, acptr->uplink ? acptr->uplink->name : me.name, - acptr->hopcount, (acptr->info[0] ? acptr->info : "(Unknown Location)")); + acptr->hopcount, (acptr->info[0] ? acptr->info : "(Unknown Location)")); } sendnumeric(client, RPL_ENDOFLINKS, "*"); diff --git a/src/modules/history.c b/src/modules/history.c index 5d6f6f012..f00c8d787 100644 --- a/src/modules/history.c +++ b/src/modules/history.c @@ -28,17 +28,16 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "history", - "5.0", - "Simple history command for end-users", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "history", + "5.0", + "Simple history command for end-users", + "UnrealIRCd Team", + "unrealircd-6", +}; #define HISTORY_LINES_DEFAULT 100 -#define HISTORY_LINES_MAX 100 +#define HISTORY_LINES_MAX 100 CMD_FUNC(cmd_history); @@ -65,7 +64,7 @@ void history_usage(Client *client) sendnotice(client, " Ex: /HISTORY #lobby"); sendnotice(client, " Ex: /HISTORY #lobby 50"); sendnotice(client, "The lines-to-display value must be 1-%d, the default is %d", - HISTORY_LINES_MAX, HISTORY_LINES_DEFAULT); + HISTORY_LINES_MAX, HISTORY_LINES_DEFAULT); sendnotice(client, "Naturally, the line count and time limits in channel mode +H are obeyed"); } diff --git a/src/modules/history_backend_mem.c b/src/modules/history_backend_mem.c index 6cbbe1c3c..6f2d8ccd5 100644 --- a/src/modules/history_backend_mem.c +++ b/src/modules/history_backend_mem.c @@ -11,17 +11,16 @@ * are executed as fast as possible. */ -ModuleHeader MOD_HEADER -= { - "history_backend_mem", - "2.0", - "History backend: memory", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "history_backend_mem", + "2.0", + "History backend: memory", + "UnrealIRCd Team", + "unrealircd-6", }; /* Defines */ -#define OBJECTLEN ((NICKLEN > CHANNELLEN) ? NICKLEN : CHANNELLEN) +#define OBJECTLEN ((NICKLEN > CHANNELLEN) ? NICKLEN : CHANNELLEN) #define HISTORY_BACKEND_MEM_HASH_TABLE_SIZE 1019 /* The regular history cleaning (by timer) is spread out @@ -41,20 +40,20 @@ ModuleHeader MOD_HEADER * in case of persistent it will save every 5 minutes. */ #if 0 //was: DEBUGMODE -#define HISTORY_CLEAN_PER_LOOP HISTORY_BACKEND_MEM_HASH_TABLE_SIZE -#define HISTORY_TIMER_EVERY 5 + #define HISTORY_CLEAN_PER_LOOP HISTORY_BACKEND_MEM_HASH_TABLE_SIZE + #define HISTORY_TIMER_EVERY 5 #else -#define HISTORY_SPREAD 60 -#define HISTORY_MAX_OFF_SECS 300 -#define HISTORY_CLEAN_PER_LOOP (HISTORY_BACKEND_MEM_HASH_TABLE_SIZE/HISTORY_SPREAD) -#define HISTORY_TIMER_EVERY (HISTORY_MAX_OFF_SECS/HISTORY_SPREAD) + #define HISTORY_SPREAD 60 + #define HISTORY_MAX_OFF_SECS 300 + #define HISTORY_CLEAN_PER_LOOP (HISTORY_BACKEND_MEM_HASH_TABLE_SIZE / HISTORY_SPREAD) + #define HISTORY_TIMER_EVERY (HISTORY_MAX_OFF_SECS / HISTORY_SPREAD) #endif /* Some magic numbers used in the database format */ -#define HISTORYDB_MAGIC_FILE_START 0xFEFEFEFE -#define HISTORYDB_MAGIC_FILE_END 0xEFEFEFEF -#define HISTORYDB_MAGIC_ENTRY_START 0xFFFFFFFF -#define HISTORYDB_MAGIC_ENTRY_END 0xEEEEEEEE +#define HISTORYDB_MAGIC_FILE_START 0xFEFEFEFE +#define HISTORYDB_MAGIC_FILE_END 0xEFEFEFEF +#define HISTORYDB_MAGIC_ENTRY_START 0xFFFFFFFF +#define HISTORYDB_MAGIC_ENTRY_END 0xEEEEEEEE /* Definitions (structs, etc.) -- all for persistent history */ struct cfgstruct { @@ -74,7 +73,7 @@ struct HistoryLogObject { int max_lines; /**< Maximum number of lines permitted */ long max_time; /**< Maximum number of seconds to retain history */ int dirty; /**< Dirty flag, used for disk writing */ - char name[OBJECTLEN+1]; + char name[OBJECTLEN + 1]; }; /* Global variables */ @@ -180,7 +179,7 @@ MOD_LOAD() SavePersistentPointer(modinfo, hbm_posthash); EventAdd(modinfo->handle, "history_mem_init", history_mem_init, NULL, 1, 1); - EventAdd(modinfo->handle, "history_mem_clean", history_mem_clean, NULL, HISTORY_TIMER_EVERY*1000, 0); + EventAdd(modinfo->handle, "history_mem_clean", history_mem_clean, NULL, HISTORY_TIMER_EVERY * 1000, 0); init_history_storage(modinfo); return MOD_SUCCESS; } @@ -277,13 +276,13 @@ int hbm_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!ce->value) { config_error("%s:%i: missing parameter", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; - } else { + } else + { test.persist = config_checkval(ce->value, CFG_YESNO); } - } else - if (!strcmp(ce->name, "db-secret")) + } else if (!strcmp(ce->name, "db-secret")) { const char *err; if ((err = unrealdb_test_secret(ce->value))) @@ -292,13 +291,12 @@ int hbm_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) errors++; } safe_strdup(test.db_secret, ce->value); - } else - if (!strcmp(ce->name, "directory")) // or "path" ? + } else if (!strcmp(ce->name, "directory")) // or "path" ? { if (!ce->value) { config_error("%s:%i: missing parameter", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } else { @@ -322,15 +320,13 @@ int hbm_config_posttest(int *errs) if (test.db_secret && !test.persist) { config_error("set::history::channel::db-secret is set but set::history::channel::persist is disabled, this makes no sense. " - "Either use 'persist yes' or comment out / delete 'db-secret'."); + "Either use 'persist yes' or comment out / delete 'db-secret'."); errors++; - } else - if (!test.db_secret && test.persist) + } else if (!test.db_secret && test.persist) { config_error("set::history::channel::db-secret needs to be set."); errors++; - } else - if (test.db_secret && test.persist) + } else if (test.db_secret && test.persist) { /* Configuration is good, now check if the password is correct * (if we can check at all, that is)... @@ -347,12 +343,12 @@ int hbm_config_posttest(int *errs) #ifdef _WIN32 (void)mkdir(test.directory); /* (errors ignored) */ #else - (void)mkdir(test.directory, S_IRUSR|S_IWUSR|S_IXUSR); /* (errors ignored) */ + (void)mkdir(test.directory, S_IRUSR | S_IWUSR | S_IXUSR); /* (errors ignored) */ #endif if (!file_exists(test.directory)) { config_error("[history] Directory %s does not exist and could not be created", - test.directory); + test.directory); errors++; } else { @@ -378,14 +374,12 @@ int hbm_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(ce->name, "persist")) { cfg.persist = config_checkval(ce->value, CFG_YESNO); - } else - if (!strcmp(ce->name, "directory")) // or "path" ? + } else if (!strcmp(ce->name, "directory")) // or "path" ? { safe_strdup(cfg.directory, ce->value); convert_to_absolute_path(&cfg.directory, PERMDATADIR); hbm_set_masterdb_filename(&cfg); - } else - if (!strcmp(ce->name, "db-secret")) + } else if (!strcmp(ce->name, "db-secret")) { safe_strdup(cfg.db_secret, ce->value); } else @@ -526,13 +520,13 @@ void hbm_duplicate_mtags(HistoryLogLine *l, MessageTag *m) sec = t.tv_sec; tm = gmtime(&sec); snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", - tm->tm_year + 1900, - tm->tm_mon + 1, - tm->tm_mday, - tm->tm_hour, - tm->tm_min, - tm->tm_sec, - (int)(t.tv_usec / 1000)); + tm->tm_year + 1900, + tm->tm_mon + 1, + tm->tm_mday, + tm->tm_hour, + tm->tm_min, + tm->tm_sec, + (int)(t.tv_usec / 1000)); n = safe_alloc(sizeof(MessageTag)); safe_strdup(n->name, "time"); @@ -549,7 +543,8 @@ void hbm_duplicate_mtags(HistoryLogLine *l, MessageTag *m) if (n && n->value) { l->msgid = n->value; - } else { + } else + { /* This shouldn't happen. The privmsg/notice layer should always add a msgid. * So this shouldn't happen even for server/services messages that had no msgid, * as the first unrealircd server would have added a msgid to it. @@ -566,7 +561,7 @@ void hbm_duplicate_mtags(HistoryLogLine *l, MessageTag *m) #endif n = safe_alloc(sizeof(MessageTag)); safe_strdup(n->name, "msgid"); - n->value = safe_alloc(MSGIDLEN+1); + n->value = safe_alloc(MSGIDLEN + 1); gen_random_alnum(n->value, MSGIDLEN); AddListItem(n, l->mtags); l->msgid = n->value; @@ -587,8 +582,7 @@ void hbm_history_add_line_after_position(HistoryLogObject *h, HistoryLogLine *af n->next = h->head; h->head->prev = n; h->head = n; - } else - if (after->next == NULL) + } else if (after->next == NULL) { /* New tail */ if (after != h->tail) @@ -660,7 +654,8 @@ HistoryLogLine *hbm_history_add_line(HistoryLogObject *h, MessageTag *mtags, con h->tail->next = l; l->prev = h->tail; h->tail = l; - } else { + } else + { /* message has same (rounded) time as tail or is from before */ if (!hbm_history_add_line_in_time(h, l)) { @@ -670,7 +665,8 @@ HistoryLogLine *hbm_history_add_line(HistoryLogObject *h, MessageTag *mtags, con return NULL; } } - } else { + } else + { /* no tail, no head */ h->head = h->tail = l; } @@ -905,8 +901,7 @@ static int hbm_return_after(HistoryResult *r, HistoryLogObject *h, HistoryFilter if (filter->timestamp_a && (strcmp(l->time, filter->timestamp_a) > 0)) { started = 1; - } else - if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) + } else if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) { started = 1; continue; @@ -918,8 +913,7 @@ static int hbm_return_after(HistoryResult *r, HistoryLogObject *h, HistoryFilter if (filter->timestamp_b && (strcmp(l->time, filter->timestamp_b) >= 0)) { break; - } else - if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) + } else if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) { break; } @@ -965,8 +959,7 @@ static int hbm_return_before(HistoryResult *r, HistoryLogObject *h, HistoryFilte if (filter->timestamp_a && (strcmp(l->time, filter->timestamp_a) < 0)) { started = 1; - } else - if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) + } else if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) { started = 1; continue; @@ -978,8 +971,7 @@ static int hbm_return_before(HistoryResult *r, HistoryLogObject *h, HistoryFilte if (filter->timestamp_b && (strcmp(l->time, filter->timestamp_b) < 0)) { break; - } else - if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) + } else if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) { break; } @@ -1019,8 +1011,7 @@ static int hbm_return_latest(HistoryResult *r, HistoryLogObject *h, HistoryFilte { if (filter->timestamp_a && (strcmp(l->time, filter->timestamp_a) <= 0)) break; /* Stop now */ - else - if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) + else if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) break; /* Stop now */ /* Limit reached but there are more lines available */ @@ -1109,8 +1100,7 @@ static int hbm_return_around(HistoryResult *r, HistoryLogObject *h, HistoryFilte if (filter->timestamp_a && (strcmp(l->time, filter->timestamp_a) < 0)) { started = l->next; - } else - if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) + } else if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) { started = l; continue; @@ -1122,8 +1112,7 @@ static int hbm_return_around(HistoryResult *r, HistoryLogObject *h, HistoryFilte if (filter->timestamp_b && (strcmp(l->time, filter->timestamp_b) < 0)) { break; - } else - if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) + } else if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) { break; } @@ -1136,7 +1125,8 @@ static int hbm_return_around(HistoryResult *r, HistoryLogObject *h, HistoryFilte /* Normal case */ if (++written >= filter->limit / 2) break; - } else { + } else + { /* Special case: if started->next is NULL then started is the end * of the buffer, so fill just /under/ the limit */ @@ -1206,8 +1196,7 @@ static int hbm_return_between_figure_out_direction(HistoryLogObject *h, HistoryF if (filter->timestamp_a && (strcmp(l->time, filter->timestamp_a) >= 0)) { found_a = 1; - } else - if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) + } else if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) { found_a = 1; } @@ -1231,8 +1220,7 @@ static int hbm_return_between_figure_out_direction(HistoryLogObject *h, HistoryF if (filter->timestamp_b && (strcmp(l->time, filter->timestamp_b) >= 0)) { found_b = 1; - } else - if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) + } else if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) { found_b = 1; } @@ -1275,8 +1263,7 @@ static int hbm_return_between(HistoryResult *r, HistoryLogObject *h, HistoryFilt if (direction == 1) { return hbm_return_after(r, h, filter); - } else - if (direction == 0) + } else if (direction == 0) { /* Create a temporary filter, swapping directions */ char *x, *y; @@ -1317,7 +1304,7 @@ HistoryResult *hbm_history_request(const char *object, HistoryFilter *filter) r = safe_alloc(sizeof(HistoryResult)); safe_strdup(r->object, object); - switch(filter->cmd) + switch (filter->cmd) { case HFC_BEFORE: hbm_return_before(r, h, filter); @@ -1376,8 +1363,7 @@ int hbm_history_delete(const char *object, HistoryFilter *filter, int *rejected_ if (filter->timestamp_a && (strcmp(l->time, filter->timestamp_a) > 0)) { started = 1; - } else - if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) + } else if (filter->msgid_a && !strcmp(l->msgid, filter->msgid_a)) { started = 1; } @@ -1388,8 +1374,7 @@ int hbm_history_delete(const char *object, HistoryFilter *filter, int *rejected_ if (filter->timestamp_b && (strcmp(l->time, filter->timestamp_b) >= 0)) { break; - } else - if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) + } else if (filter->msgid_b && !strcmp(l->msgid, filter->msgid_b)) { break; } @@ -1399,10 +1384,12 @@ int hbm_history_delete(const char *object, HistoryFilter *filter, int *rejected_ * This means filter->account should probably not be filled directly * from user input. */ - if (filter->account) { + if (filter->account) + { // TODO: check account-tag module is loaded? m = find_mtag(l->mtags, "account"); - if (!m || strcmp(m->value, filter->account)) { + if (!m || strcmp(m->value, filter->account)) + { if (rejected_deletes) (*rejected_deletes)++; continue; @@ -1551,7 +1538,7 @@ static int hbm_read_masterdb(void) !unrealdb_read_str(db, &posthash)) { config_error("[history] Read error from database file '%s': %s", - test.masterdb, unrealdb_get_error_string()); + test.masterdb, unrealdb_get_error_string()); safe_free(prehash); safe_free(posthash); unrealdb_close(db); @@ -1562,7 +1549,7 @@ static int hbm_read_masterdb(void) if (!prehash || !posthash) { config_error("[history] Read error from database file '%s': unexpected values encountered", - test.masterdb); + test.masterdb); safe_free(prehash); safe_free(posthash); return 0; @@ -1574,7 +1561,8 @@ static int hbm_read_masterdb(void) /* Identical sets */ safe_free(prehash); safe_free(posthash); - } else { + } else + { /* Diffferent */ safe_free(hbm_prehash); safe_free(hbm_posthash); @@ -1598,7 +1586,7 @@ static int hbm_write_masterdb(void) if (!db) { config_error("[history] Unable to write to '%s': %s", - test.masterdb, unrealdb_get_error_string()); + test.masterdb, unrealdb_get_error_string()); return 0; } @@ -1611,7 +1599,7 @@ static int hbm_write_masterdb(void) !unrealdb_write_str(db, hbm_posthash)) { config_error("[history] Unable to write to '%s': %s", - test.masterdb, unrealdb_get_error_string()); + test.masterdb, unrealdb_get_error_string()); return 0; } unrealdb_close(db); @@ -1664,7 +1652,7 @@ static void hbm_read_dbs(void) #ifdef _WIN32 (void)mkdir(buf2); /* (errors ignored) */ #else - (void)mkdir(buf2, S_IRUSR|S_IWUSR|S_IXUSR); /* (errors ignored) */ + (void)mkdir(buf2, S_IRUSR | S_IWUSR | S_IXUSR); /* (errors ignored) */ #endif snprintf(buf2, sizeof(buf2), "%s/bad/%s", cfg.directory, fname); unlink(buf2); @@ -1682,31 +1670,37 @@ static void hbm_read_dbs(void) #endif } -#define RESET_VALUES_LOOP() do { \ - safe_free(mtag_name); \ - safe_free(mtag_value); \ - safe_free(line); \ - free_message_tags(mtags); \ - mtags = NULL; \ - magic = 0; \ - line_ts = 0; \ - } while(0) +#define RESET_VALUES_LOOP() \ + do \ + { \ + safe_free(mtag_name); \ + safe_free(mtag_value); \ + safe_free(line); \ + free_message_tags(mtags); \ + mtags = NULL; \ + magic = 0; \ + line_ts = 0; \ + } while (0) -#define R_SAFE_CLEANUP() do { \ - unrealdb_close(db); \ - RESET_VALUES_LOOP(); \ - safe_free(prehash); \ - safe_free(posthash); \ - safe_free(object); \ - } while(0) +#define R_SAFE_CLEANUP() \ + do \ + { \ + unrealdb_close(db); \ + RESET_VALUES_LOOP(); \ + safe_free(prehash); \ + safe_free(posthash); \ + safe_free(object); \ + } while (0) #define R_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ config_warn("[history] Read error from database file '%s' (possible corruption): %s", fname, unrealdb_get_error_string()); \ R_SAFE_CLEANUP(); \ return 0; \ } \ - } while(0) + } while (0) /** Read a channel history db file */ @@ -1741,7 +1735,7 @@ static int hbm_read_db(const char *fname) if (magic != HISTORYDB_MAGIC_FILE_START) { config_warn("[history] Database '%s' has wrong magic value, possibly corrupt (0x%lx), expected HISTORYDB_MAGIC_FILE_START.", - fname, (long)magic); + fname, (long)magic); unrealdb_close(db); return 0; } @@ -1757,7 +1751,7 @@ static int hbm_read_db(const char *fname) if (version > 5001) { config_warn("[history] Database '%s' has version %lu while we only support %lu. Did you just downgrade UnrealIRCd? Sorry this is not suported", - fname, (unsigned long)version, (unsigned long)5001); + fname, (unsigned long)version, (unsigned long)5001); unrealdb_close(db); return 0; } @@ -1768,7 +1762,7 @@ static int hbm_read_db(const char *fname) if (!prehash || !posthash || strcmp(prehash, hbm_prehash) || strcmp(posthash, hbm_posthash)) { config_warn("[history] Database '%s' does not belong to our 'master.db'. Are you mixing old with new .db files perhaps? This is not supported. File ignored.", - fname); + fname); R_SAFE_CLEANUP(); return 0; } @@ -1785,7 +1779,7 @@ static int hbm_read_db(const char *fname) return 1; /* No problem */ } - while(1) + while (1) { RESET_VALUES_LOOP(); R_SAFE(unrealdb_read_int32(db, &magic)); @@ -1794,13 +1788,13 @@ static int hbm_read_db(const char *fname) if (magic != HISTORYDB_MAGIC_ENTRY_START) { config_warn("[history] Read error from database file '%s': wrong magic value in entry (0x%lx), expected HISTORYDB_MAGIC_ENTRY_START", - fname, (long)magic); + fname, (long)magic); R_SAFE_CLEANUP(); return 0; } R_SAFE(unrealdb_read_int64(db, &line_ts)); - while(1) + while (1) { R_SAFE(unrealdb_read_str(db, &mtag_name)); R_SAFE(unrealdb_read_str(db, &mtag_value)); @@ -1861,14 +1855,15 @@ static int hbm_read_db(const char *fname) safe_free(cl_line); } } - } else { + } else + { hbm_history_add_line(h, mtags, line); } R_SAFE(unrealdb_read_int32(db, &magic)); if (magic != HISTORYDB_MAGIC_ENTRY_END) { config_warn("[history] Read error from database file '%s': wrong magic value in entry (0x%lx), expected HISTORYDB_MAGIC_ENTRY_END", - fname, (long)magic); + fname, (long)magic); R_SAFE_CLEANUP(); return 0; } @@ -1956,13 +1951,13 @@ EVENT(history_mem_clean) if (hashnum >= HISTORY_BACKEND_MEM_HASH_TABLE_SIZE) hashnum = 0; - } while(loopcnt++ < HISTORY_CLEAN_PER_LOOP); + } while (loopcnt++ < HISTORY_CLEAN_PER_LOOP); } const char *hbm_history_filename(HistoryLogObject *h) { static char fname[512]; - char oname[OBJECTLEN+1]; + char oname[OBJECTLEN + 1]; char hashdata[512]; char hash[128]; @@ -1978,21 +1973,24 @@ const char *hbm_history_filename(HistoryLogObject *h) } #define WARN_WRITE_ERROR(fname) \ - do { \ + do \ + { \ unreal_log(ULOG_ERROR, "history", "HISTORYDB_FILE_WRITE_ERROR", NULL, \ - "[historydb] Error writing to temporary database file $filename: $system_error", \ - log_data_string("filename", fname), \ - log_data_string("system_error", unrealdb_get_error_string())); \ - } while(0) + "[historydb] Error writing to temporary database file $filename: $system_error", \ + log_data_string("filename", fname), \ + log_data_string("system_error", unrealdb_get_error_string())); \ + } while (0) #define W_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ WARN_WRITE_ERROR(tmpfname); \ unrealdb_close(db); \ return 0; \ } \ - } while(0) + } while (0) // FIXME: the code below will cause massive floods on disk or I/O errors if hundreds of @@ -2075,7 +2073,7 @@ static int hbm_write_db(HistoryLogObject *h) if (rename(tmpfname, realfname) < 0) { config_error("[history] Error renaming '%s' to '%s': %s (HISTORY NOT SAVED)", - tmpfname, realfname, strerror(errno)); + tmpfname, realfname, strerror(errno)); return 0; } diff --git a/src/modules/history_backend_null.c b/src/modules/history_backend_null.c index 3abbc6080..131c6aca2 100644 --- a/src/modules/history_backend_null.c +++ b/src/modules/history_backend_null.c @@ -10,13 +10,12 @@ * channel mode +H. */ -ModuleHeader MOD_HEADER -= { - "history_backend_null", - "2.0", - "History backend: null/none", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "history_backend_null", + "2.0", + "History backend: null/none", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ diff --git a/src/modules/ident_lookup.c b/src/modules/ident_lookup.c index 6c45668c1..c9657da98 100644 --- a/src/modules/ident_lookup.c +++ b/src/modules/ident_lookup.c @@ -4,13 +4,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "ident_lookup", - "1.0", - "Ident lookups (RFC1413)", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "ident_lookup", + "1.0", + "Ident lookups (RFC1413)", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -105,7 +104,7 @@ static int ident_lookup_connect(Client *client) ident_lookup_failed(client); return 0; } - if (++OpenFiles >= maxclients+1) + if (++OpenFiles >= maxclients + 1) { unreal_log(ULOG_FATAL, "io", "IDENT_ERROR_MAXCLIENTS", client, "Cannot do ident connection for $client.details: All connections in use"); @@ -144,8 +143,8 @@ static void ident_lookup_send(int fd, int revents, void *data) Client *client = data; ircsnprintf(authbuf, sizeof(authbuf), "%d , %d\r\n", - get_client_port(client), - get_server_port(client)); + get_client_port(client), + get_server_port(client)); if (WRITE_SOCK(client->local->authfd, authbuf, strlen(authbuf)) != strlen(authbuf)) { @@ -170,7 +169,7 @@ static void ident_lookup_receive(int fd, int revents, void *userdata) char buf[512]; int len; - len = READ_SOCK(client->local->authfd, buf, sizeof(buf)-1); + len = READ_SOCK(client->local->authfd, buf, sizeof(buf) - 1); /* We received a response. We don't bother with fragmentation * since that is not going to happen for such a short string. @@ -199,7 +198,8 @@ static void ident_lookup_receive(int fd, int revents, void *userdata) strlcpy(client->ident, ident, USERLEN + 1); SetIdentSuccess(client); ircstats.is_asuc++; - } else { + } else + { ircstats.is_abad++; } return; @@ -248,7 +248,7 @@ static char *ident_lookup_parse(Client *client, char *buf) return NULL; /* */ - buf = p+1; + buf = p + 1; skip_whitespace(&buf); /* Username */ @@ -257,7 +257,7 @@ static char *ident_lookup_parse(Client *client, char *buf) if (!strchr("~^", *buf) && (*buf > 32)) break; // B) Stop at the end, IOTW stop at newline, space, etc. - for (p=buf; *p; p++) + for (p = buf; *p; p++) { if (strchr("\n\r@:", *p) || (*p <= 32)) { diff --git a/src/modules/invite.c b/src/modules/invite.c index ddf7671ea..2f9922ad6 100644 --- a/src/modules/invite.c +++ b/src/modules/invite.c @@ -22,10 +22,10 @@ #include "unrealircd.h" -#define MSG_INVITE "INVITE" +#define MSG_INVITE "INVITE" -#define CLIENT_INVITES(client) (moddata_local_client(client, userInvitesMD).ptr) -#define CHANNEL_INVITES(channel) (moddata_channel(channel, channelInvitesMD).ptr) +#define CLIENT_INVITES(client) (moddata_local_client(client, userInvitesMD).ptr) +#define CHANNEL_INVITES(channel) (moddata_channel(channel, channelInvitesMD).ptr) ModDataInfo *userInvitesMD; ModDataInfo *channelInvitesMD; @@ -44,14 +44,13 @@ int invite_user_quit(Client *client, MessageTag *mtags, const char *comment); int invite_user_join(Client *client, Channel *channel, MessageTag *mtags); int invite_is_invited(Client *client, Channel *channel, int *invited); -ModuleHeader MOD_HEADER - = { - "invite", - "5.0", - "command /invite", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "invite", + "5.0", + "command /invite", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_TEST() { @@ -67,7 +66,7 @@ MOD_INIT() MARK_AS_OFFICIAL_MODULE(modinfo); - CommandAdd(modinfo->handle, MSG_INVITE, cmd_invite, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_INVITE, cmd_invite, MAXPARA, CMD_USER | CMD_SERVER); memset(&cap, 0, sizeof(cap)); cap.name = "invite-notify"; @@ -78,7 +77,7 @@ MOD_INIT() return MOD_FAILED; } - memset(&mreq, 0 , sizeof(mreq)); + memset(&mreq, 0, sizeof(mreq)); mreq.type = MODDATATYPE_LOCAL_CLIENT; mreq.name = "invite", mreq.free = invite_free; @@ -88,8 +87,8 @@ MOD_INIT() config_error("[%s] Failed to request user invite moddata: %s", MOD_HEADER.name, ModuleGetErrorStr(modinfo->handle)); return MOD_FAILED; } - - memset(&mreq, 0 , sizeof(mreq)); + + memset(&mreq, 0, sizeof(mreq)); mreq.type = MODDATATYPE_CHANNEL; mreq.name = "invite", mreq.free = invite_free; @@ -106,7 +105,7 @@ MOD_INIT() HookAdd(modinfo->handle, HOOKTYPE_LOCAL_QUIT, 0, invite_user_quit); HookAdd(modinfo->handle, HOOKTYPE_LOCAL_JOIN, 0, invite_user_join); HookAdd(modinfo->handle, HOOKTYPE_IS_INVITED, 0, invite_is_invited); - + return MOD_SUCCESS; } @@ -200,7 +199,7 @@ void send_invite_list(Client *client) for (inv = CLIENT_INVITES(client); inv; inv = inv->next) { sendnumeric(client, RPL_INVITELIST, - inv->value.channel->name); + inv->value.channel->name); } sendnumeric(client, RPL_ENDOFINVITELIST); } @@ -208,7 +207,7 @@ void send_invite_list(Client *client) int invite_is_invited(Client *client, Channel *channel, int *invited) { Link *lp; - + if (!MyConnect(client)) return 0; // not handling invite lists for remote clients @@ -231,46 +230,37 @@ void invite_process(Client *client, Client *target, Channel *channel, MessageTag sendto_server(client, 0, 0, mtags, ":%s INVITE %s %s %d", client->id, target->id, channel->name, override); /* send chanops notifications */ - if (IsUser(client) && (check_channel_access(client, channel, "oaq") - || IsULine(client) - || ValidatePermissionsForPath("channel:override:invite:self",client,NULL,channel,NULL) - || invite_always_notify - )) + if (IsUser(client) && (check_channel_access(client, channel, "oaq") || IsULine(client) || ValidatePermissionsForPath("channel:override:invite:self", client, NULL, channel, NULL) || invite_always_notify)) { if (override == 1) { sendto_channel(channel, &me, NULL, "o", - 0, SEND_LOCAL, mtags, - ":%s NOTICE @%s :OperOverride -- %s invited him/herself into the channel.", - me.name, channel->name, client->name); + 0, SEND_LOCAL, mtags, + ":%s NOTICE @%s :OperOverride -- %s invited him/herself into the channel.", + me.name, channel->name, client->name); } if (override == 0) { sendto_channel(channel, &me, NULL, "o", - CAP_INVITE_NOTIFY | CAP_INVERT, SEND_LOCAL, mtags, - ":%s NOTICE @%s :%s invited %s into the channel.", - me.name, channel->name, client->name, target->name); + CAP_INVITE_NOTIFY | CAP_INVERT, SEND_LOCAL, mtags, + ":%s NOTICE @%s :%s invited %s into the channel.", + me.name, channel->name, client->name, target->name); } /* always send IRCv3 invite-notify if possible */ sendto_channel(channel, client, NULL, "o", - CAP_INVITE_NOTIFY, SEND_LOCAL, mtags, - ":%s INVITE %s %s", - client->name, target->name, channel->name); + CAP_INVITE_NOTIFY, SEND_LOCAL, mtags, + ":%s INVITE %s %s", + client->name, target->name, channel->name); } /* add to list and notify the person who got invited */ if (MyConnect(target)) { - if (IsUser(client) && (check_channel_access(client, channel, "oaq") - || IsULine(client) - || ValidatePermissionsForPath("channel:override:invite:self",client,NULL,channel,NULL) + if (IsUser(client) && (check_channel_access(client, channel, "oaq") || IsULine(client) || ValidatePermissionsForPath("channel:override:invite:self", client, NULL, channel, NULL) #ifdef OPEROVERRIDE_VERIFY - || (override - && ValidatePermissionsForPath("channel:override:privsecret",client,NULL,channel,NULL) - && client == target - && (SecretChannel(channel) || HiddenChannel(channel))) + || (override && ValidatePermissionsForPath("channel:override:privsecret", client, NULL, channel, NULL) && client == target && (SecretChannel(channel) || HiddenChannel(channel))) #endif - )) + )) { add_invite(client, target, channel, mtags); } @@ -278,7 +268,7 @@ void invite_process(Client *client, Client *target, Channel *channel, MessageTag if (!is_silenced(client, target)) { sendto_prefix_one(target, client, mtags, ":%s INVITE %s :%s", client->name, - target->name, channel->name); + target->name, channel->name); } } free_message_tags(mtags); @@ -287,11 +277,11 @@ void invite_process(Client *client, Client *target, Channel *channel, MessageTag void invite_operoverride_msg(Client *client, Channel *channel, char *override_mode, char *override_mode_text) { unreal_log(ULOG_INFO, "operoverride", "OPEROVERRIDE_INVITE", client, - "OperOverride: $client.details invited him/herself into $channel (Overriding $override_mode_text)", - log_data_string("override_type", "join"), - log_data_string("override_mode", override_mode), - log_data_string("override_mode_text", override_mode_text), - log_data_channel("channel", channel)); + "OperOverride: $client.details invited him/herself into $channel (Overriding $override_mode_text)", + log_data_string("override_type", "join"), + log_data_string("override_mode", override_mode), + log_data_string("override_mode_text", override_mode_text), + log_data_channel("channel", channel)); } /* @@ -315,7 +305,7 @@ CMD_FUNC(cmd_invite) target = find_user(parv[1], NULL); channel = find_channel(parv[2]); } - + if (!MyConnect(client)) /*** remote invite ***/ { @@ -374,7 +364,7 @@ CMD_FUNC(cmd_invite) /* proceed with the command */ for (h = Hooks[HOOKTYPE_PRE_INVITE]; h; h = h->next) { - i = (*(h->func.intfunc))(client,target,channel,&override); + i = (*(h->func.intfunc))(client, target, channel, &override); if (i == HOOK_DENY) return; if (i == HOOK_ALLOW) @@ -383,18 +373,16 @@ CMD_FUNC(cmd_invite) if (!IsMember(client, channel) && !IsULine(client)) { - if (ValidatePermissionsForPath("channel:override:invite:notinchannel",client,NULL,channel,NULL) && client == target) + if (ValidatePermissionsForPath("channel:override:invite:notinchannel", client, NULL, channel, NULL) && client == target) { override = 1; #ifdef OPEROVERRIDE_VERIFY - } - else if (ValidatePermissionsForPath("channel:override:privsecret",client,NULL,channel,NULL) - && client == target - && (SecretChannel(channel) || HiddenChannel(channel))) + } else if (ValidatePermissionsForPath("channel:override:privsecret", client, NULL, channel, NULL) && client == target && (SecretChannel(channel) || HiddenChannel(channel))) { override = 1; #endif - } else { + } else + { sendnumeric(client, ERR_NOTONCHANNEL, parv[2]); return; } @@ -410,20 +398,21 @@ CMD_FUNC(cmd_invite) { if (!check_channel_access(client, channel, "oaq") && !IsULine(client)) { - if (ValidatePermissionsForPath("channel:override:invite:invite-only",client,NULL,channel,NULL) && client == target) + if (ValidatePermissionsForPath("channel:override:invite:invite-only", client, NULL, channel, NULL) && client == target) { override = 1; - } else { + } else + { sendnumeric(client, ERR_CHANOPRIVSNEEDED, channel->name); return; } - } - else if (!IsMember(client, channel) && !IsULine(client)) + } else if (!IsMember(client, channel) && !IsULine(client)) { - if (ValidatePermissionsForPath("channel:override:invite:invite-only",client,NULL,channel,NULL) && client == target) + if (ValidatePermissionsForPath("channel:override:invite:invite-only", client, NULL, channel, NULL) && client == target) { override = 1; - } else { + } else + { sendnumeric(client, ERR_CHANOPRIVSNEEDED, channel->name); return; } @@ -432,7 +421,7 @@ CMD_FUNC(cmd_invite) if (SPAMFILTER_VIRUSCHANDENY && SPAMFILTER_VIRUSCHAN && !strcasecmp(channel->name, SPAMFILTER_VIRUSCHAN) && - !check_channel_access(client, channel, "oaq") && !ValidatePermissionsForPath("immune:server-ban:viruschan",client,NULL,NULL,NULL)) + !check_channel_access(client, channel, "oaq") && !ValidatePermissionsForPath("immune:server-ban:viruschan", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_CHANOPRIVSNEEDED, channel->name); return; @@ -441,7 +430,7 @@ CMD_FUNC(cmd_invite) if (target_limit_exceeded(client, target, target->name)) return; - if (!ValidatePermissionsForPath("immune:invite-flood",client,NULL,NULL,NULL) && + if (!ValidatePermissionsForPath("immune:invite-flood", client, NULL, NULL, NULL) && flood_limit_exceeded(client, FLD_INVITE)) { sendnumeric(client, RPL_TRYAGAIN, "INVITE"); @@ -455,8 +444,7 @@ CMD_FUNC(cmd_invite) { sendnumeric(client, RPL_AWAY, target->name, target->user->away); } - } - else + } else { /* Send OperOverride messages */ char override_what = '\0'; @@ -501,7 +489,6 @@ void add_invite(Client *from, Client *to, Channel *channel, MessageTag *mtags) for (tmp = CLIENT_INVITES(to); tmp->next; tmp = tmp->next) ; del_invite(to, tmp->value.channel); - } /* We get pissy over too many invites per channel as well now, * since otherwise mass-inviters could take up some major @@ -555,4 +542,3 @@ void del_invite(Client *client, Channel *channel) break; } } - diff --git a/src/modules/ircops.c b/src/modules/ircops.c index 4b71eb025..81c22b8b0 100644 --- a/src/modules/ircops.c +++ b/src/modules/ircops.c @@ -20,19 +20,18 @@ #include "unrealircd.h" -#define MSG_IRCOPS "IRCOPS" -#define IsAway(x) (x)->user->away +#define MSG_IRCOPS "IRCOPS" +#define IsAway(x) (x)->user->away CMD_FUNC(cmd_ircops); -ModuleHeader MOD_HEADER - = { - "ircops", - "3.71", - "/IRCOPS command that lists IRC Operators", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "ircops", + "3.71", + "/IRCOPS command that lists IRC Operators", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -47,7 +46,7 @@ MOD_INIT() if (ModuleGetError(modinfo->handle) != MODERR_NOERROR) { config_error("Error adding command " MSG_IRCOPS ": %s", - ModuleGetErrorStr(modinfo->handle)); + ModuleGetErrorStr(modinfo->handle)); return MOD_FAILED; } @@ -114,27 +113,27 @@ CMD_FUNC(cmd_ircops) if (!IsOper(client) && IsHideOper(acptr)) continue; - sendto_one(client, NULL, ":%s %d %s :\2%s\2 is %s on %s" "%s", - me.name, RPL_TEXT, client->name, - acptr->name, - "an IRC Operator", /* find_otype(acptr->umodes), */ - acptr->user->server, - (IsAway(acptr) ? " [Away]" : "")); + sendto_one(client, NULL, ":%s %d %s :\2%s\2 is %s on %s" + "%s", + me.name, RPL_TEXT, client->name, + acptr->name, + "an IRC Operator", /* find_otype(acptr->umodes), */ + acptr->user->server, + (IsAway(acptr) ? " [Away]" : "")); if (IsAway(acptr)) aways++; else opers++; - } total = opers + aways; snprintf(buf, sizeof(buf), - "Total: \2%d\2 IRCOP%s online - \2%d\2 Oper%s available and \2%d\2 Away", - total, (total) != 1 ? "s" : "", - opers, opers != 1 ? "s" : "", - aways); + "Total: \2%d\2 IRCOP%s online - \2%d\2 Oper%s available and \2%d\2 Away", + total, (total) != 1 ? "s" : "", + opers, opers != 1 ? "s" : "", + aways); sendnumericfmt(client, RPL_TEXT, ":%s", buf); sendnumericfmt(client, RPL_TEXT, ":End of /IRCOPS list"); diff --git a/src/modules/ison.c b/src/modules/ison.c index 7a2832cc6..5ec4ba7ef 100644 --- a/src/modules/ison.c +++ b/src/modules/ison.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_ison); -#define MSG_ISON "ISON" +#define MSG_ISON "ISON" -ModuleHeader MOD_HEADER - = { - "ison", - "5.0", - "command /ison", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "ison", + "5.0", + "command /ison", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -92,7 +91,8 @@ CMD_FUNC(cmd_ison) if (user) { ircsnprintf(namebuf, sizeof(namebuf), "%s@%s", acptr->user->username, GetHost(acptr)); - if (!match_simple(user, namebuf)) continue; + if (!match_simple(user, namebuf)) + continue; *--user = '!'; } diff --git a/src/modules/issued-by-tag.c b/src/modules/issued-by-tag.c index ece5d1585..3a1f9c499 100644 --- a/src/modules/issued-by-tag.c +++ b/src/modules/issued-by-tag.c @@ -7,14 +7,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "issued-by-tag", - "6.0", - "unrealircd.org/issued-by message tag", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "issued-by-tag", + "6.0", + "unrealircd.org/issued-by message tag", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int issued_by_mtag_is_ok(Client *client, const char *name, const char *value); @@ -125,18 +124,17 @@ void _mtag_add_issued_by(MessageTag **mtags, Client *client, MessageTag *recv_mt if (client->rpc->issuer) { snprintf(buf, sizeof(buf), "RPC:%s@%s:%s", client->rpc->rpc_user, client->uplink->name, client->rpc->issuer); - } else { + } else + { snprintf(buf, sizeof(buf), "RPC:%s@%s", client->rpc->rpc_user, client->uplink->name); } - } else - if (IsULine(client)) + } else if (IsULine(client)) { if (IsUser(client)) snprintf(buf, sizeof(buf), "SERVICES:%s@%s", client->name, client->uplink->name); else snprintf(buf, sizeof(buf), "SERVICES:%s", client->name); - } else - if (IsOper(client)) + } else if (IsOper(client)) { const char *operlogin = moddata_client_get(client, "operlogin"); if (operlogin) diff --git a/src/modules/isupport.c b/src/modules/isupport.c index 8c96d8915..c8944ca0b 100644 --- a/src/modules/isupport.c +++ b/src/modules/isupport.c @@ -29,13 +29,12 @@ void _send_isupport(Client *client); void _isupport_check_for_changes(void); -ModuleHeader MOD_HEADER -={ - "isupport", /* Name of module */ - "5.0", /* Version */ - "Implement ISUPPORT (numeric 005) sending", /* Short description of module */ - "UnrealIRCd Team", /* Author */ - "unrealircd-6", /* Version of UnrealIRCd */ +ModuleHeader MOD_HEADER = { + "isupport", /* Name of module */ + "5.0", /* Version */ + "Implement ISUPPORT (numeric 005) sending", /* Short description of module */ + "UnrealIRCd Team", /* Author */ + "unrealircd-6", /* Version of UnrealIRCd */ }; MOD_TEST() @@ -76,7 +75,7 @@ MOD_UNLOAD() */ void _send_isupport(Client *client) { - char batch[BATCHLEN+1]; + char batch[BATCHLEN + 1]; int i; MessageTag *mtags = NULL, *m; @@ -130,7 +129,8 @@ void isupport_check_for_changes_send(const char *addstr, char *buf, size_t bufle if (HasCapability(acptr, "draft/extended-isupport") && HasCapability(acptr, "batch")) { sendtaggednumericfmt(acptr, mtags, RPL_ISUPPORT, "%s :are supported by this server", buf); - } else { + } else + { sendnumeric(acptr, RPL_ISUPPORT, buf); } } @@ -145,9 +145,8 @@ void isupport_check_for_changes_one(const char *addstr, char *buf, size_t buflen if (*changes == 0) { /* First change, need to start the batch */ - list_for_each_entry(acptr, &lclient_list, lclient_node) - if (HasCapability(acptr, "draft/extended-isupport") && HasCapability(acptr, "batch")) - sendto_one(acptr, NULL, ":%s BATCH +%s draft/isupport", me.name, batch); + list_for_each_entry(acptr, &lclient_list, lclient_node) if (HasCapability(acptr, "draft/extended-isupport") && HasCapability(acptr, "batch")) + sendto_one(acptr, NULL, ":%s BATCH +%s draft/isupport", me.name, batch); } *changes = *changes + 1; @@ -166,7 +165,7 @@ void _isupport_check_for_changes(void) { Client *acptr; MessageTag *mtags = NULL; - char batch[BATCHLEN+1]; + char batch[BATCHLEN + 1]; ISupport *n; // iterator for "new isupports" ISupport *o; // iterator for "old isupports" char buf[512], addstr[512]; @@ -196,7 +195,8 @@ void _isupport_check_for_changes(void) { snprintf(addstr, sizeof(addstr), "%s=%s", n->token, n->value); - } else { + } else + { strlcpy(addstr, n->token, sizeof(addstr)); } isupport_check_for_changes_one(addstr, buf, sizeof(buf), batch, mtags, &changes, &bc); @@ -221,9 +221,8 @@ void _isupport_check_for_changes(void) if (changes) { /* End the batch (for those clients who received a batch, that is) */ - list_for_each_entry(acptr, &lclient_list, lclient_node) - if (HasCapability(acptr, "draft/extended-isupport") && HasCapability(acptr, "batch")) - sendto_one(acptr, NULL, ":%s BATCH -%s", me.name, batch); + list_for_each_entry(acptr, &lclient_list, lclient_node) if (HasCapability(acptr, "draft/extended-isupport") && HasCapability(acptr, "batch")) + sendto_one(acptr, NULL, ":%s BATCH -%s", me.name, batch); } safe_free_message_tags(mtags); diff --git a/src/modules/join.c b/src/modules/join.c index 06dcdf809..be3d22462 100644 --- a/src/modules/join.c +++ b/src/modules/join.c @@ -40,17 +40,16 @@ static int bouncedtimes = 0; long CAP_EXTENDED_JOIN = 0L; /* Macros */ -#define MAXBOUNCE 5 /** Most sensible */ -#define MSG_JOIN "JOIN" +#define MAXBOUNCE 5 /** Most sensible */ +#define MSG_JOIN "JOIN" -ModuleHeader MOD_HEADER - = { - "join", - "5.0", - "command /join", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "join", + "5.0", + "command /join", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_TEST() { @@ -102,7 +101,7 @@ int _can_join(Client *client, Channel *channel, const char *key, char **errmsg) int j = 0; for (h = Hooks[HOOKTYPE_INVITE_BYPASS]; h; h = h->next) { - j = (*(h->func.intfunc))(client,channel); + j = (*(h->func.intfunc))(client, channel); if (j != 0) break; } @@ -113,7 +112,7 @@ int _can_join(Client *client, Channel *channel, const char *key, char **errmsg) for (h = Hooks[HOOKTYPE_CAN_JOIN]; h; h = h->next) { - int i = (*(h->func.intfunc))(client,channel,key, errmsg); + int i = (*(h->func.intfunc))(client, channel, key, errmsg); if (i != 0) return i; } @@ -126,14 +125,13 @@ int _can_join(Client *client, Channel *channel, const char *key, char **errmsg) } #ifndef NO_OPEROVERRIDE -#ifdef OPEROVERRIDE_VERIFY - if (ValidatePermissionsForPath("channel:override:privsecret",client,NULL,channel,NULL) - && (SecretChannel(channel) || HiddenChannel(channel))) + #ifdef OPEROVERRIDE_VERIFY + if (ValidatePermissionsForPath("channel:override:privsecret", client, NULL, channel, NULL) && (SecretChannel(channel) || HiddenChannel(channel))) { *errmsg = STR_ERR_OPERSPVERIFY; return (ERR_OPERSPVERIFY); } -#endif + #endif #endif return 0; @@ -175,20 +173,20 @@ CMD_FUNC(cmd_join) void _send_join_to_local_users(Client *client, Channel *channel, MessageTag *mtags) { sendto_channel(channel, client, NULL, NULL, - CAP_EXTENDED_JOIN|CAP_INVERT, - CHECK_INVISIBLE|SEND_LOCAL, + CAP_EXTENDED_JOIN | CAP_INVERT, + CHECK_INVISIBLE | SEND_LOCAL, mtags, - ":%s JOIN :%s", - client->name, channel->name); + ":%s JOIN :%s", + client->name, channel->name); sendto_channel(channel, client, NULL, NULL, CAP_EXTENDED_JOIN, - CHECK_INVISIBLE|SEND_LOCAL, + CHECK_INVISIBLE | SEND_LOCAL, mtags, - ":%s JOIN %s %s :%s", - client->name, channel->name, - IsLoggedIn(client) ? client->user->account : "*", - client->info); + ":%s JOIN %s %s :%s", + client->name, channel->name, + IsLoggedIn(client) ? client->user->account : "*", + client->info); } /* Routine that actually makes a user join the channel @@ -211,8 +209,8 @@ void _join_channel(Channel *channel, Client *client, MessageTag *recv_mtags, con send_join_to_local_users(client, channel, mtags); sendto_server(client, 0, 0, mtags_sjoin, ":%s SJOIN %lld %s :%s%s ", - me.id, (long long)channel->creationtime, - channel->name, modes_to_sjoin_prefix(member_modes), client->id); + me.id, (long long)channel->creationtime, + channel->name, modes_to_sjoin_prefix(member_modes), client->id); if (MyUser(client)) { @@ -225,7 +223,7 @@ void _join_channel(Channel *channel, Client *client, MessageTag *recv_mtags, con { channel->creationtime = TStime(); sendto_server(client, 0, 0, NULL, ":%s MODE %s + %lld", - me.id, channel->name, (long long)channel->creationtime); + me.id, channel->name, (long long)channel->creationtime); } if (channel->topic) @@ -233,7 +231,7 @@ void _join_channel(Channel *channel, Client *client, MessageTag *recv_mtags, con sendnumeric(client, RPL_TOPIC, channel->name, channel->topic); sendnumeric(client, RPL_TOPICWHOTIME, channel->name, channel->topic_nick, (long long)channel->topic_time); } - + /* Set default channel modes (set::modes-on-join). * Set only if it's the 1st user and only if no other modes have been set * already (eg: +P, permanent). @@ -248,12 +246,12 @@ void _join_channel(Channel *channel, Client *client, MessageTag *recv_mtags, con channel->mode.mode = MODES_ON_JOIN; /* Param fun */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (!cm->letter || !cm->paracount) continue; if (channel->mode.mode & cm->mode) - cm_putparameter(channel, cm->letter, iConf.modes_on_join.extparams[cm->letter]); + cm_putparameter(channel, cm->letter, iConf.modes_on_join.extparams[cm->letter]); } *modebuf = *parabuf = 0; @@ -261,7 +259,7 @@ void _join_channel(Channel *channel, Client *client, MessageTag *recv_mtags, con /* This should probably be in the SJOIN stuff */ new_message_special(&me, recv_mtags, &mtags_mode, ":%s MODE %s %s %s", me.name, channel->name, modebuf, parabuf); sendto_server(NULL, 0, 0, mtags_mode, ":%s MODE %s %s %s %lld", - me.id, channel->name, modebuf, parabuf, (long long)channel->creationtime); + me.id, channel->name, modebuf, parabuf, (long long)channel->creationtime); sendto_one(client, mtags_mode, ":%s MODE %s %s %s", me.name, channel->name, modebuf, parabuf); RunHook(HOOKTYPE_LOCAL_CHANMODE, &me, channel, mtags_mode, modebuf, parabuf, 0, 0, &should_destroy); free_message_tags(mtags_mode); @@ -270,22 +268,24 @@ void _join_channel(Channel *channel, Client *client, MessageTag *recv_mtags, con parv[0] = NULL; parv[1] = channel->name; parv[2] = NULL; - if (!HasCapability(client,"draft/no-implicit-names") && !HasCapability(client, "no-implicit-names")) - do_cmd(client, NULL, "NAMES", 2, parv);; + if (!HasCapability(client, "draft/no-implicit-names") && !HasCapability(client, "no-implicit-names")) + do_cmd(client, NULL, "NAMES", 2, parv); + ; unreal_log(ULOG_INFO, "join", "LOCAL_CLIENT_JOIN", client, - "User $client joined $channel", - log_data_channel("channel", channel), - log_data_string("modes", member_modes)); + "User $client joined $channel", + log_data_channel("channel", channel), + log_data_string("modes", member_modes)); RunHook(HOOKTYPE_LOCAL_JOIN, client, channel, mtags); - } else { + } else + { if (IsSynched(client->uplink)) { unreal_log(ULOG_INFO, "join", "REMOTE_CLIENT_JOIN", client, - "User $client joined $channel", - log_data_channel("channel", channel), - log_data_string("modes", member_modes)); + "User $client joined $channel", + log_data_channel("channel", channel), + log_data_string("modes", member_modes)); } RunHook(HOOKTYPE_REMOTE_JOIN, client, channel, mtags); } @@ -317,7 +317,13 @@ void _do_join(Client *client, int parc, const char *parv[]) int maxtargets = max_targets_for_command("JOIN"); const char *member_modes = ""; -#define RET() do { bouncedtimes--; parv[1] = orig_parv1; return; } while(0) +#define RET() \ + do \ + { \ + bouncedtimes--; \ + parv[1] = orig_parv1; \ + return; \ + } while (0) if (parc < 2 || *parv[1] == '\0') { @@ -365,8 +371,7 @@ void _do_join(Client *client, int parc, const char *parv[]) continue; strlcpy(jbuf, "0", sizeof(jbuf)); continue; - } else - if (MyConnect(client) && !valid_channelname(name)) + } else if (MyConnect(client) && !valid_channelname(name)) { send_invalid_channelname(client, name); if (IsOper(client) && find_channel(name)) @@ -376,11 +381,10 @@ void _do_join(Client *client, int parc, const char *parv[]) "However, it does exist because another server in your " "network, which has a more loose restriction, created it. " "See https://www.unrealircd.org/docs/Set_block#set::allowed-channelchars", - name); + name); } continue; - } - else if (!IsChannelName(name)) + } else if (!IsChannelName(name)) { if (MyUser(client)) sendnumeric(client, ERR_NOSUCHCHANNEL, name); @@ -404,7 +408,7 @@ void _do_join(Client *client, int parc, const char *parv[]) strlcpy(request_key, parv[2], sizeof(request_key)); key = strtoken(&p2, request_key, ","); } - parv[2] = NULL; /* for cmd_names call later, parv[parc] must == NULL */ + parv[2] = NULL; /* for cmd_names call later, parv[parc] must == NULL */ for (name = strtoken(&p, jbuf, ","); name; @@ -446,7 +450,7 @@ void _do_join(Client *client, int parc, const char *parv[]) { member_modes = (ChannelExists(name)) ? "" : LEVEL_ON_JOIN; - if (!ValidatePermissionsForPath("immune:maxchannelsperuser",client,NULL,NULL,NULL)) /* opers can join unlimited chans */ + if (!ValidatePermissionsForPath("immune:maxchannelsperuser", client, NULL, NULL, NULL)) /* opers can join unlimited chans */ { if (client->user->joined >= get_setting_for_user_number(client, SET_MAX_CHANNELS_PER_USER)) { @@ -458,7 +462,7 @@ void _do_join(Client *client, int parc, const char *parv[]) /* RESTRICTCHAN */ if (conf_deny_channel) { - if (!ValidatePermissionsForPath("immune:server-ban:deny-channel",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("immune:server-ban:deny-channel", client, NULL, NULL, NULL)) { ConfigItem_deny_channel *d; if ((d = find_channel_allowed(client, name))) @@ -484,7 +488,7 @@ void _do_join(Client *client, int parc, const char *parv[]) } } } - if (!ValidatePermissionsForPath("immune:server-ban:deny-channel",client,NULL,NULL,NULL) && (tklban = find_qline(client, name, &ishold))) + if (!ValidatePermissionsForPath("immune:server-ban:deny-channel", client, NULL, NULL, NULL) && (tklban = find_qline(client, name, &ishold))) { tkl_hit(client, tklban); sendnumeric(client, ERR_FORBIDDENCHANNEL, name, tklban->ptr.nameban->reason); @@ -493,14 +497,15 @@ void _do_join(Client *client, int parc, const char *parv[]) /* ugly set::spamfilter::virus-help-channel-deny hack.. */ if (SPAMFILTER_VIRUSCHANDENY && SPAMFILTER_VIRUSCHAN && !strcasecmp(name, SPAMFILTER_VIRUSCHAN) && - !ValidatePermissionsForPath("immune:server-ban:viruschan",client,NULL,NULL,NULL) && !spamf_ugly_vchanoverride) + !ValidatePermissionsForPath("immune:server-ban:viruschan", client, NULL, NULL, NULL) && !spamf_ugly_vchanoverride) { Channel *channel = find_channel(name); - + if (!channel || !is_invited(client, channel)) { sendnotice(client, "*** Cannot join '%s' because it's the virus-help-channel " - "which is reserved for infected users only", name); + "which is reserved for infected users only", + name); continue; } } @@ -520,9 +525,9 @@ void _do_join(Client *client, int parc, const char *parv[]) { Hook *h; char *errmsg = NULL; - for (h = Hooks[HOOKTYPE_PRE_LOCAL_JOIN]; h; h = h->next) + for (h = Hooks[HOOKTYPE_PRE_LOCAL_JOIN]; h; h = h->next) { - i = (*(h->func.intfunc))(client,channel,key); + i = (*(h->func.intfunc))(client, channel, key); if (i == HOOK_DENY || i == HOOK_ALLOW) break; } @@ -535,8 +540,8 @@ void _do_join(Client *client, int parc, const char *parv[]) continue; } /* If they are allowed, don't check can_join */ - if (i != HOOK_ALLOW && - (i = can_join(client, channel, key, &errmsg))) + if (i != HOOK_ALLOW && + (i = can_join(client, channel, key, &errmsg))) { if (i != -1) send_cannot_join_error(client, i, errmsg, name); @@ -566,8 +571,8 @@ void _do_join(Client *client, int parc, const char *parv[]) } #if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif void send_cannot_join_error(Client *client, int numeric, char *fmtstr, char *channel_name) { @@ -575,7 +580,7 @@ void send_cannot_join_error(Client *client, int numeric, char *fmtstr, char *cha sendnumericfmt(client, numeric, fmtstr, channel_name); } #if defined(__GNUC__) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif /* Additional channel-related functions. I've put it here instead @@ -596,7 +601,7 @@ char *_get_chmodes_for_user(Client *client, const char *member_flags) n = strlen(member_flags); if (n) { - for (i=0; i < n; i++) + for (i = 0; i < n; i++) { strlcat(parabuf, client->name, sizeof(parabuf)); if (i < n - 1) diff --git a/src/modules/jointhrottle.c b/src/modules/jointhrottle.c index 0f8044a09..d3eef949d 100644 --- a/src/modules/jointhrottle.c +++ b/src/modules/jointhrottle.c @@ -23,14 +23,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "jointhrottle", - "5.0", - "Join flood protection (set::anti-flood::join-flood)", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "jointhrottle", + "5.0", + "Join flood protection (set::anti-flood::join-flood)", + "UnrealIRCd Team", + "unrealircd-6", +}; ModuleInfo *ModInfo = NULL; @@ -40,7 +39,7 @@ typedef struct JoinFlood JoinFlood; struct JoinFlood { JoinFlood *prev, *next; - char name[CHANNELLEN+1]; + char name[CHANNELLEN + 1]; time_t firstjoin; unsigned short numjoins; }; @@ -79,7 +78,7 @@ MOD_INIT() HookAdd(modinfo->handle, HOOKTYPE_CAN_JOIN, 0, jointhrottle_can_join); HookAdd(modinfo->handle, HOOKTYPE_LOCAL_JOIN, 0, jointhrottle_local_join); - + return MOD_SUCCESS; } @@ -103,10 +102,10 @@ static int isjthrottled(Client *client, Channel *channel) return 0; /* Grab user<->chan entry.. */ - for (e = moddata_local_client(client, jointhrottle_md).ptr; e; e=e->next) + for (e = moddata_local_client(client, jointhrottle_md).ptr; e; e = e->next) if (!strcasecmp(e->name, channel->name)) break; - + if (!e) return 0; /* Not present, so cannot be throttled */ @@ -126,23 +125,23 @@ static void jointhrottle_increase_usercounter(Client *client, Channel *channel) if (!MyUser(client)) return; - + /* Grab user<->chan entry.. */ - for (e = moddata_local_client(client, jointhrottle_md).ptr; e; e=e->next) + for (e = moddata_local_client(client, jointhrottle_md).ptr; e; e = e->next) if (!strcasecmp(e->name, channel->name)) break; - + if (!e) { /* Allocate one */ e = jointhrottle_addentry(client, channel); e->firstjoin = TStime(); e->numjoins = 1; - } else - if ((TStime() - e->firstjoin) < iConf.floodsettings->period[FLD_JOIN]) /* still valid? */ + } else if ((TStime() - e->firstjoin) < iConf.floodsettings->period[FLD_JOIN]) /* still valid? */ { e->numjoins++; - } else { + } else + { /* reset :p */ e->firstjoin = TStime(); e->numjoins = 1; @@ -151,7 +150,7 @@ static void jointhrottle_increase_usercounter(Client *client, Channel *channel) int jointhrottle_can_join(Client *client, Channel *channel, const char *key, char **errmsg) { - if (!ValidatePermissionsForPath("immune:join-flood",client,NULL,channel,NULL) && isjthrottled(client, channel)) + if (!ValidatePermissionsForPath("immune:join-flood", client, NULL, channel, NULL) && isjthrottled(client, channel)) { flood_blocked_increment(client, FLD_JOIN); *errmsg = STR_ERR_TOOMANYJOINS; @@ -178,7 +177,7 @@ JoinFlood *jointhrottle_addentry(Client *client, Channel *channel) if (!IsUser(client)) abort(); - for (e=moddata_local_client(client, jointhrottle_md).ptr; e; e=e->next) + for (e = moddata_local_client(client, jointhrottle_md).ptr; e; e = e->next) if (!strcasecmp(e->name, channel->name)) abort(); /* already exists -- should never happen */ #endif @@ -203,7 +202,7 @@ EVENT(jointhrottle_cleanup_structs) { Client *client; JoinFlood *jf, *jf_next; - + list_for_each_entry(client, &lclient_list, lclient_node) { if (!MyUser(client)) @@ -212,7 +211,7 @@ EVENT(jointhrottle_cleanup_structs) for (jf = moddata_local_client(client, jointhrottle_md).ptr; jf; jf = jf_next) { jf_next = jf->next; - + if (jf->firstjoin + iConf.floodsettings->period[FLD_JOIN] > TStime()) continue; /* still valid entry */ if (moddata_local_client(client, jointhrottle_md).ptr == jf) @@ -221,7 +220,8 @@ EVENT(jointhrottle_cleanup_structs) moddata_local_client(client, jointhrottle_md).ptr = jf->next; /* could be set to NULL now */ if (jf->next) jf->next->prev = NULL; - } else { + } else + { /* change non-head entries */ jf->prev->next = jf->next; /* could be set to NULL now */ if (jf->next) @@ -243,7 +243,7 @@ void jointhrottle_md_free(ModData *m) { j_next = j->next; safe_free(j); - } + } m->ptr = NULL; } diff --git a/src/modules/json-log-tag.c b/src/modules/json-log-tag.c index 92e758a01..2535797f0 100644 --- a/src/modules/json-log-tag.c +++ b/src/modules/json-log-tag.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "json-log-tag", - "5.0", - "unrealircd.org/json-log tag for S2S and ircops", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "json-log-tag", + "5.0", + "unrealircd.org/json-log tag for S2S and ircops", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ long CAP_JSON_LOG = 0L; diff --git a/src/modules/jumpserver.c b/src/modules/jumpserver.c index 77436248e..96cc6eb1d 100644 --- a/src/modules/jumpserver.c +++ b/src/modules/jumpserver.c @@ -19,14 +19,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "jumpserver", - "1.1", - "/jumpserver command", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "jumpserver", + "1.1", + "/jumpserver command", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ CMD_FUNC(cmd_jumpserver); @@ -35,8 +34,7 @@ void jumpserver_free_jss(ModData *m); /* Jumpserver status struct */ typedef struct JSS JSS; -struct JSS -{ +struct JSS { char *reason; char *server; int port; @@ -44,7 +42,7 @@ struct JSS int tls_port; }; -JSS *jss=NULL; /**< JumpServer Status. NULL=disabled. */ +JSS *jss = NULL; /**< JumpServer Status. NULL=disabled. */ MOD_INIT() { @@ -122,9 +120,9 @@ void jumpserver_free_jss(ModData *m) CMD_FUNC(cmd_jumpserver) { - char *serv, *tlsserv=NULL, *p; + char *serv, *tlsserv = NULL, *p; const char *reason; - int all=0, port=6667, sslport=6697; + int all = 0, port = 6667, sslport = 6697; char request[BUFSIZE]; char logbuf[512]; @@ -138,11 +136,10 @@ CMD_FUNC(cmd_jumpserver) { if (jss && jss->tls_server) sendnotice(client, "JumpServer is \002ENABLED\002 to %s:%d (TLS: %s:%d) with reason '%s'", - jss->server, jss->port, jss->tls_server, jss->tls_port, jss->reason); - else - if (jss) + jss->server, jss->port, jss->tls_server, jss->tls_port, jss->reason); + else if (jss) sendnotice(client, "JumpServer is \002ENABLED\002 to %s:%d with reason '%s'", - jss->server, jss->port, jss->reason); + jss->server, jss->port, jss->reason); else sendnotice(client, "JumpServer is \002DISABLED\002"); return; @@ -179,14 +176,14 @@ CMD_FUNC(cmd_jumpserver) strlcpy(request, parv[1], sizeof(request)); serv = request; - + p = strchr(serv, '/'); if (p) { *p = '\0'; - tlsserv = p+1; + tlsserv = p + 1; } - + p = strchr(serv, ':'); if (p) { @@ -218,7 +215,8 @@ CMD_FUNC(cmd_jumpserver) all = 0; else if (!strcasecmp(parv[2], "all")) all = 1; - else { + else + { sendnotice(client, "ERROR: Invalid action '%s', should be 'NEW' or 'ALL' (see /jumpserver help for usage)", parv[2]); return; } @@ -255,7 +253,8 @@ CMD_FUNC(cmd_jumpserver) log_data_string("jumpserver_tls_server", jss->tls_server), log_data_integer("jumpserver_tls_port", jss->tls_port), log_data_string("reason", jss->reason)); - } else { + } else + { unreal_log(ULOG_INFO, "jumpserver", "JUMPSERVER_ENABLED", client, "[jumpserver] $client.details turned jumpserver ON for $jumpserver_who " "to $jumpserver_server:$jumpserver_port " diff --git a/src/modules/kick.c b/src/modules/kick.c index b3e9bad81..3e74cd66d 100644 --- a/src/modules/kick.c +++ b/src/modules/kick.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "kick", - "5.0", - "command /kick", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "kick", + "5.0", + "command /kick", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ CMD_FUNC(cmd_kick); @@ -44,7 +43,7 @@ MOD_TEST() MOD_INIT() { - CommandAdd(modinfo->handle, "KICK", cmd_kick, 3, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, "KICK", cmd_kick, 3, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -62,11 +61,11 @@ MOD_UNLOAD() void kick_operoverride_msg(Client *client, Channel *channel, Client *target, char *reason) { unreal_log(ULOG_INFO, "operoverride", "OPEROVERRIDE_KICK", client, - "OperOverride: $client.details kicked $target from $channel ($reason)", - log_data_string("override_type", "kick"), - log_data_string("reason", reason), - log_data_client("target", target), - log_data_channel("channel", channel)); + "OperOverride: $client.details kicked $target from $channel ($reason)", + log_data_string("override_type", "kick"), + log_data_string("reason", reason), + log_data_client("target", target), + log_data_channel("channel", channel)); } /** Kick a user from a channel. @@ -106,25 +105,26 @@ void _kick_user(MessageTag *initial_mtags, Channel *channel, Client *client, Cli { /* Send it only to chanops & victim */ sendto_channel(channel, client, victim, - "h", 0, - SEND_LOCAL, mtags, - ":%s KICK %s %s :%s", - client->name, channel->name, victim->name, comment); + "h", 0, + SEND_LOCAL, mtags, + ":%s KICK %s %s :%s", + client->name, channel->name, victim->name, comment); if (MyUser(victim)) { sendto_prefix_one(victim, client, mtags, ":%s KICK %s %s :%s", - client->name, channel->name, victim->name, comment); + client->name, channel->name, victim->name, comment); } - } else { + } else + { /* NORMAL */ sendto_channel(channel, client, NULL, 0, 0, SEND_LOCAL, mtags, - ":%s KICK %s %s :%s", - client->name, channel->name, victim->name, comment); + ":%s KICK %s %s :%s", + client->name, channel->name, victim->name, comment); } sendto_server(client, 0, 0, mtags, ":%s KICK %s %s :%s", - client->id, channel->name, victim->id, comment); + client->id, channel->name, victim->id, comment); free_message_tags(mtags); if (initial_mtags_generated) @@ -138,7 +138,8 @@ void _kick_user(MessageTag *initial_mtags, Channel *channel, Client *client, Cli unreal_log(ULOG_INFO, "kick", "LOCAL_CLIENT_KICK", victim, "User $client kicked from $channel", log_data_channel("channel", channel)); - } else { + } else + { unreal_log(ULOG_INFO, "kick", "REMOTE_CLIENT_KICK", victim, "User $client kicked from $channel", log_data_channel("channel", channel)); @@ -158,9 +159,9 @@ CMD_FUNC(cmd_kick) { Client *target; Channel *channel; - int chasing = 0; + int chasing = 0; char *p = NULL, *user, *p2 = NULL, *badkick; - char comment[MAXKICKLEN+1]; + char comment[MAXKICKLEN + 1]; Membership *lp; Hook *h; int ret; @@ -198,7 +199,7 @@ CMD_FUNC(cmd_kick) if (IsUser(client)) client_member_modes = get_channel_access(client, channel); if (MyUser(client) && !IsULine(client) && - !op_can_override("channel:override:kick:no-ops",client,channel,NULL) && + !op_can_override("channel:override:kick:no-ops", client, channel, NULL) && !check_channel_access(client, channel, "hoaq")) { sendnumeric(client, ERR_CHANOPRIVSNEEDED, channel->name); @@ -215,7 +216,7 @@ CMD_FUNC(cmd_kick) } if (!(target = find_chasing(client, user, &chasing))) - continue; /* No such user left! */ + continue; /* No such user left! */ if (!target->user) continue; /* non-user */ @@ -243,7 +244,8 @@ CMD_FUNC(cmd_kick) badkick = NULL; ret = EX_ALLOW; - for (h = Hooks[HOOKTYPE_CAN_KICK]; h; h = h->next) { + for (h = Hooks[HOOKTYPE_CAN_KICK]; h; h = h->next) + { int n = (*(h->func.intfunc))(client, target, channel, comment, client_member_modes, target_member_modes, &badkick); if (n == EX_DENY) @@ -267,11 +269,12 @@ CMD_FUNC(cmd_kick) if (ret == EX_DENY) { /* If set it means 'not allowed to kick'.. now check if (s)he can override that.. */ - if (op_can_override("channel:override:kick:no-ops",client,channel,NULL)) + if (op_can_override("channel:override:kick:no-ops", client, channel, NULL)) { kick_operoverride_msg(client, channel, target, comment); goto attack; /* all other checks don't matter anymore (and could cause double msgs) */ - } else { + } else + { /* Not an oper overriding */ if (MyUser(client) && badkick) sendto_one(client, NULL, "%s", badkick); /* send error, if any */ @@ -288,15 +291,14 @@ CMD_FUNC(cmd_kick) { if (client == target) goto attack; /* kicking self == ok */ - if (op_can_override("channel:override:kick:owner",client,channel,NULL)) /* (and f*ck local ops) */ + if (op_can_override("channel:override:kick:owner", client, channel, NULL)) /* (and f*ck local ops) */ { /* IRCop kicking owner/prot */ kick_operoverride_msg(client, channel, target, comment); goto attack; - } - else if (!IsULine(client) && (target != client) && MyUser(client)) + } else if (!IsULine(client) && (target != client) && MyUser(client)) { - char errbuf[NICKLEN+25]; + char errbuf[NICKLEN + 25]; if (check_channel_access_string(target_member_modes, "q")) ircsnprintf(errbuf, sizeof(errbuf), "%s is a channel owner", target->name); else @@ -311,17 +313,17 @@ CMD_FUNC(cmd_kick) check_channel_access_string(target_member_modes, "oaq") && !IsULine(client)) { - if (op_can_override("channel:override:kick:no-ops",client,channel,NULL)) + if (op_can_override("channel:override:kick:no-ops", client, channel, NULL)) { kick_operoverride_msg(client, channel, target, comment); goto attack; } if (MyUser(client)) { - char errbuf[NICKLEN+30]; + char errbuf[NICKLEN + 30]; ircsnprintf(errbuf, sizeof(errbuf), "%s is a channel operator", target->name); sendnumeric(client, ERR_CANNOTDOCOMMAND, "KICK", - errbuf); + errbuf); goto deny; } } @@ -331,17 +333,17 @@ CMD_FUNC(cmd_kick) check_channel_access_string(target_member_modes, "h") && !IsULine(client)) { - if (op_can_override("channel:override:kick:no-ops",client,channel,NULL)) + if (op_can_override("channel:override:kick:no-ops", client, channel, NULL)) { kick_operoverride_msg(client, channel, target, comment); goto attack; } if (MyUser(client)) { - char errbuf[NICKLEN+30]; + char errbuf[NICKLEN + 30]; ircsnprintf(errbuf, sizeof(errbuf), "%s is a halfop", target->name); sendnumeric(client, ERR_CANNOTDOCOMMAND, "KICK", - errbuf); + errbuf); goto deny; } } @@ -349,15 +351,18 @@ CMD_FUNC(cmd_kick) /* allowed (either coz access granted or a remote kick), so attack! */ goto attack; - deny: + deny: continue; - attack: - if (MyConnect(client)) { + attack: + if (MyConnect(client)) + { int breakit = 0; Hook *h; - for (h = Hooks[HOOKTYPE_PRE_LOCAL_KICK]; h; h = h->next) { - if ((*(h->func.intfunc))(client,target,channel,comment) > 0) { + for (h = Hooks[HOOKTYPE_PRE_LOCAL_KICK]; h; h = h->next) + { + if ((*(h->func.intfunc))(client, target, channel, comment) > 0) + { breakit = 1; break; } diff --git a/src/modules/kill.c b/src/modules/kill.c index a72bdf4f6..b5d87c46c 100644 --- a/src/modules/kill.c +++ b/src/modules/kill.c @@ -22,18 +22,17 @@ CMD_FUNC(cmd_kill); -ModuleHeader MOD_HEADER - = { - "kill", - "5.0", - "command /kill", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "kill", + "5.0", + "command /kill", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, "KILL", cmd_kill, 2, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, "KILL", cmd_kill, 2, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -71,7 +70,7 @@ CMD_FUNC(cmd_kill) return; } - if (!IsServer(client->direction) && !ValidatePermissionsForPath("kill:global",client,NULL,NULL,NULL) && !ValidatePermissionsForPath("kill:local",client,NULL,NULL,NULL)) + if (!IsServer(client->direction) && !ValidatePermissionsForPath("kill:global", client, NULL, NULL, NULL) && !ValidatePermissionsForPath("kill:local", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -113,9 +112,7 @@ CMD_FUNC(cmd_kill) continue; } - if ((!MyConnect(target) && MyUser(client) && !ValidatePermissionsForPath("kill:global",client,target,NULL,NULL)) - || (MyConnect(target) && MyUser(client) - && !ValidatePermissionsForPath("kill:local",client,target,NULL,NULL))) + if ((!MyConnect(target) && MyUser(client) && !ValidatePermissionsForPath("kill:global", client, target, NULL, NULL)) || (MyConnect(target) && MyUser(client) && !ValidatePermissionsForPath("kill:local", client, target, NULL, NULL))) { sendnumeric(client, ERR_NOPRIVILEGES); continue; @@ -149,14 +146,13 @@ CMD_FUNC(cmd_kill) if (MyConnect(target)) { sendto_prefix_one(target, client, NULL, ":%s KILL %s :%s", - client->name, target->name, reason); + client->name, target->name, reason); } if (MyConnect(target) && MyConnect(client)) { /* Local kill. This is handled as if it were a QUIT */ - } - else + } else { /* Kill from one server to another (we may be src, victim or something in-between) */ diff --git a/src/modules/knock.c b/src/modules/knock.c index 16d2a7f8e..9f78d6039 100644 --- a/src/modules/knock.c +++ b/src/modules/knock.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_knock); -#define MSG_KNOCK "KNOCK" +#define MSG_KNOCK "KNOCK" -ModuleHeader MOD_HEADER - = { - "knock", - "5.0", - "command /knock", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "knock", + "5.0", + "command /knock", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -133,7 +132,7 @@ CMD_FUNC(cmd_knock) return; if (MyUser(client) && - !ValidatePermissionsForPath("immune:knock-flood",client,NULL,NULL,NULL) && + !ValidatePermissionsForPath("immune:knock-flood", client, NULL, NULL, NULL) && flood_limit_exceeded(client, FLD_KNOCK)) { sendnumeric(client, ERR_CANNOTKNOCK, parv[1], "You are KNOCK flooding"); @@ -154,7 +153,7 @@ CMD_FUNC(cmd_knock) if (MyUser(client)) sendnotice(client, "Knocked on %s", channel->name); - RunHook(HOOKTYPE_KNOCK, client, channel, mtags, parv[2]); + RunHook(HOOKTYPE_KNOCK, client, channel, mtags, parv[2]); free_message_tags(mtags); } diff --git a/src/modules/labeled-response.c b/src/modules/labeled-response.c index e2faae633..354ffe9bf 100644 --- a/src/modules/labeled-response.c +++ b/src/modules/labeled-response.c @@ -22,21 +22,20 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "labeled-response", - "5.0", - "Labeled response CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "labeled-response", + "5.0", + "Labeled response CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Data structures */ typedef struct LabeledResponseContext LabeledResponseContext; struct LabeledResponseContext { Client *client; /**< The client who issued the original command with a label */ char label[256]; /**< The label attached to this command */ - char batch[BATCHLEN+1]; /**< The generated batch id */ + char batch[BATCHLEN + 1]; /**< The generated batch id */ int responses; /**< Number of lines sent back to client */ int sent_remote; /**< Command has been sent to remote server */ char firstbuf[MAXLINELENGTH]; /**< First buffered response */ @@ -53,14 +52,14 @@ void _labeled_response_set_context(void *ctx); void _labeled_response_force_end(void); /* Our special version of SupportBatch() assumes that remote servers always handle it */ -#define SupportBatch(x) (MyConnect(x) ? HasCapability((x), "batch") : 1) -#define SupportLabel(x) (HasCapabilityFast((x), CAP_LABELED_RESPONSE)) +#define SupportBatch(x) (MyConnect(x) ? HasCapability((x), "batch") : 1) +#define SupportLabel(x) (HasCapabilityFast((x), CAP_LABELED_RESPONSE)) /* Variables */ static LabeledResponseContext currentcmd; static long CAP_LABELED_RESPONSE = 0L; -static char packet[MAXLINELENGTH*2]; +static char packet[MAXLINELENGTH * 2]; int labeled_response_mtag_is_ok(Client *client, const char *name, const char *value); @@ -161,16 +160,17 @@ char *gen_start_batch(void) { /* Local connection */ snprintf(buf, sizeof(buf), "@label=%s :%s BATCH +%s labeled-response", - currentcmd.label, - me.name, - currentcmd.batch); - } else { + currentcmd.label, + me.name, + currentcmd.batch); + } else + { /* Remote connection: requires intra-server BATCH syntax */ snprintf(buf, sizeof(buf), "@label=%s :%s BATCH %s +%s labeled-response", - currentcmd.label, - me.name, - currentcmd.client->name, - currentcmd.batch); + currentcmd.label, + me.name, + currentcmd.client->name, + currentcmd.batch); } return buf; } @@ -207,19 +207,18 @@ int lr_post_command(Client *from, MessageTag *mtags, const char *buf) free_message_tags(m); lr_clear(); return 0; - } else - if (currentcmd.responses == 1) + } else if (currentcmd.responses == 1) { /* We have buffered this response earlier, * now we will send it */ int more_tags = currentcmd.firstbuf[0] == '@'; currentcmd.client = NULL; /* prevent lr_packet from interfering */ - snprintf(packet, sizeof(packet)-3, - "@label=%s%s%s", - currentcmd.label, - more_tags ? ";" : " ", - more_tags ? currentcmd.firstbuf+1 : currentcmd.firstbuf); + snprintf(packet, sizeof(packet) - 3, + "@label=%s%s%s", + currentcmd.label, + more_tags ? ";" : " ", + more_tags ? currentcmd.firstbuf + 1 : currentcmd.firstbuf); /* Format the IRC message correctly here, so we can take the * quick path through sendbufto_one(). */ @@ -266,7 +265,7 @@ char *skip_tags(char *msg) if ((*p == ';') || (*p == ' ')) return p; } - return msg+1; /* just skip the '@' */ + return msg + 1; /* just skip the '@' */ } int lr_packet(Client *from, Client *to, Client *intended_to, char **msg, int *len) @@ -284,8 +283,7 @@ int lr_packet(Client *from, Client *to, Client *intended_to, char **msg, int *le /* Don't send anything -- yet */ *msg = NULL; *len = 0; - } else - if (currentcmd.responses == 1) + } else if (currentcmd.responses == 1) { /* Start the batch now, normally this would be a sendto_one() * but doing so is not possible since we are in the sending code :( @@ -303,49 +301,50 @@ int lr_packet(Client *from, Client *to, Client *intended_to, char **msg, int *le { /* Special case: current message (*msg) already contains a batch */ snprintf(packet, sizeof(packet), - "%s\r\n" - "@batch=%s%s%s\r\n" - "%s", - batchstr, - currentcmd.batch, - more_tags_one ? ";" : " ", - more_tags_one ? currentcmd.firstbuf+1 : currentcmd.firstbuf, - *msg); + "%s\r\n" + "@batch=%s%s%s\r\n" + "%s", + batchstr, + currentcmd.batch, + more_tags_one ? ";" : " ", + more_tags_one ? currentcmd.firstbuf + 1 : currentcmd.firstbuf, + *msg); } else { /* Regular case: current message (*msg) contains no batch yet, add one.. */ snprintf(packet, sizeof(packet), - "%s\r\n" - "@batch=%s%s%s\r\n" - "@batch=%s%s%s", - batchstr, - currentcmd.batch, - more_tags_one ? ";" : " ", - more_tags_one ? currentcmd.firstbuf+1 : currentcmd.firstbuf, - currentcmd.batch, - more_tags_two ? ";" : " ", - more_tags_two ? *msg+1 : *msg); + "%s\r\n" + "@batch=%s%s%s\r\n" + "@batch=%s%s%s", + batchstr, + currentcmd.batch, + more_tags_one ? ";" : " ", + more_tags_one ? currentcmd.firstbuf + 1 : currentcmd.firstbuf, + currentcmd.batch, + more_tags_two ? ";" : " ", + more_tags_two ? *msg + 1 : *msg); } *msg = packet; *len = strlen(*msg); - } else { + } else + { /* >2 responses.... the first 2 have already been sent */ if (!strncmp(*msg, "@batch", 6)) { /* No buffer change needed, already contains a (now inner) batch */ - } else { + } else + { int more_tags = **msg == '@'; snprintf(packet, sizeof(packet), "@batch=%s%s%s", - currentcmd.batch, - more_tags ? ";" : " ", - more_tags ? *msg+1 : *msg); + currentcmd.batch, + more_tags ? ";" : " ", + more_tags ? *msg + 1 : *msg); *msg = packet; *len = strlen(*msg); } } currentcmd.responses++; - } - else if (IsServer(to) || !MyUser(to)) + } else if (IsServer(to) || !MyUser(to)) { currentcmd.sent_remote = 1; } @@ -402,7 +401,8 @@ void _labeled_response_set_context(void *ctx) { /* This means: clear the current context */ memset(¤tcmd, 0, sizeof(currentcmd)); - } else { + } else + { /* Set the current context to the provided one */ memcpy(¤tcmd, ctx, sizeof(LabeledResponseContext)); } diff --git a/src/modules/lag.c b/src/modules/lag.c index 90183038b..28594a8bb 100644 --- a/src/modules/lag.c +++ b/src/modules/lag.c @@ -23,21 +23,20 @@ CMD_FUNC(cmd_lag); /* Place includes here */ -#define MSG_LAG "LAG" /* Lag detect */ +#define MSG_LAG "LAG" /* Lag detect */ -ModuleHeader MOD_HEADER - = { - "lag", /* Name of module */ - "5.0", /* Version */ - "command /lag", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "lag", /* Name of module */ + "5.0", /* Version */ + "command /lag", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() { - CommandAdd(modinfo->handle, MSG_LAG, cmd_lag, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_LAG, cmd_lag, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -60,7 +59,7 @@ MOD_UNLOAD() CMD_FUNC(cmd_lag) { - if (!ValidatePermissionsForPath("server:info:lag",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:info:lag", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; diff --git a/src/modules/link-security.c b/src/modules/link-security.c index 30fac0fba..71a58c400 100644 --- a/src/modules/link-security.c +++ b/src/modules/link-security.c @@ -23,14 +23,13 @@ #include "unrealircd.h" /* Module header */ -ModuleHeader MOD_HEADER - = { - "link-security", - "5.0", - "Link Security CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "link-security", + "5.0", + "Link Security CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ const char *link_security_md_serialize(ModData *m); @@ -52,7 +51,7 @@ MOD_INIT() MARK_AS_OFFICIAL_MODULE(modinfo); ModuleSetOptions(modinfo->handle, MOD_OPT_PERM_RELOADABLE, 1); - + memset(&mreq, 0, sizeof(mreq)); mreq.name = "link-security"; mreq.type = MODDATATYPE_CLIENT; @@ -66,7 +65,7 @@ MOD_INIT() config_error("Unable to ModDataAdd() -- too many 3rd party modules loaded perhaps?"); abort(); } - + CommandAdd(modinfo->handle, "LINKSECURITY", cmd_linksecurity, MAXPARA, CMD_USER); return MOD_SUCCESS; @@ -119,14 +118,14 @@ void link_security_md_unserialize(const char *str, ModData *m) int certificate_verification_active(Client *client) { ConfigItem_link *conf; - + if (!client->server || !client->server->conf) return 0; /* wtf? */ conf = client->server->conf; - + if (conf->verify_certificate) return 1; /* yes, verify-certificate is 'yes' */ - + if ((conf->auth->type == AUTHTYPE_TLS_CLIENTCERT) || (conf->auth->type == AUTHTYPE_TLS_CLIENTCERTFP) || (conf->auth->type == AUTHTYPE_SPKIFP)) @@ -134,7 +133,7 @@ int certificate_verification_active(Client *client) /* yes, verified by link::password being a * certificate fingerprint or certificate file. */ - return 1; + return 1; } return 0; /* no, certificate is not verified in any way */ @@ -150,7 +149,7 @@ int our_link_security(void) { Client *client; int level = 2; /* safest */ - + list_for_each_entry(client, &server_list, special_node) { if (IsLocalhost(client)) @@ -160,7 +159,7 @@ int our_link_security(void) if (!certificate_verification_active(client)) level = 1; /* downgrade to level 1 */ } - + return level; } @@ -181,7 +180,7 @@ EVENT(checklinksec) Client *client; int v; int warning_sent = 0; - + local_link_security = our_link_security(); if (local_link_security != last_local_link_security) { @@ -207,7 +206,7 @@ EVENT(checklinksec) global_link_security = 1; } } - + if (local_link_security < last_local_link_security) { unreal_log(ULOG_INFO, "link-security", "LOCAL_LINK_SECURITY_DOWNGRADED", NULL, @@ -216,7 +215,7 @@ EVENT(checklinksec) log_data_integer("new_level", local_link_security)); warning_sent = 1; } - + if (global_link_security < last_global_link_security) { unreal_log(ULOG_INFO, "link-security", "GLOBAL_LINK_SECURITY_DOWNGRADED", NULL, @@ -225,7 +224,7 @@ EVENT(checklinksec) log_data_integer("new_level", global_link_security)); warning_sent = 1; } - + effective_link_security = MIN(local_link_security, global_link_security); if (warning_sent) @@ -246,15 +245,15 @@ const char *link_security_capability_parameter(Client *client) CMD_FUNC(cmd_linksecurity) { Client *acptr; - + if (!IsOper(client)) { sendnumeric(client, ERR_NOPRIVILEGES); return; } - + sendtxtnumeric(client, "== Link Security Report =="); - + sendtxtnumeric(client, "= By server ="); list_for_each_entry(acptr, &global_server_list, client_node) { @@ -264,7 +263,7 @@ CMD_FUNC(cmd_linksecurity) else sendtxtnumeric(client, "%s: level UNKNOWN", acptr->name); } - + sendtxtnumeric(client, "-"); sendtxtnumeric(client, "= Network ="); sendtxtnumeric(client, "This results in an effective (network-wide) link-security of level %d", effective_link_security); diff --git a/src/modules/links.c b/src/modules/links.c index 041bd9790..da98a390c 100644 --- a/src/modules/links.c +++ b/src/modules/links.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_links); -#define MSG_LINKS "LINKS" +#define MSG_LINKS "LINKS" -ModuleHeader MOD_HEADER - = { - "links", - "5.0", - "command /links", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "links", + "5.0", + "command /links", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -63,14 +62,14 @@ CMD_FUNC(cmd_links) list_for_each_entry(acptr, &global_server_list, client_node) { /* Some checks */ - if (HIDE_ULINES && IsULine(acptr) && !ValidatePermissionsForPath("server:info:map:ulines",client,NULL,NULL,NULL)) + if (HIDE_ULINES && IsULine(acptr) && !ValidatePermissionsForPath("server:info:map:ulines", client, NULL, NULL, NULL)) continue; if (flat) sendnumeric(client, RPL_LINKS, acptr->name, me.name, - 1, (acptr->info[0] ? acptr->info : "(Unknown Location)")); + 1, (acptr->info[0] ? acptr->info : "(Unknown Location)")); else sendnumeric(client, RPL_LINKS, acptr->name, acptr->uplink ? acptr->uplink->name : me.name, - acptr->hopcount, (acptr->info[0] ? acptr->info : "(Unknown Location)")); + acptr->hopcount, (acptr->info[0] ? acptr->info : "(Unknown Location)")); } sendnumeric(client, RPL_ENDOFLINKS, "*"); diff --git a/src/modules/list.c b/src/modules/list.c index eb57e006c..8c22c1f21 100644 --- a/src/modules/list.c +++ b/src/modules/list.c @@ -25,16 +25,15 @@ CMD_FUNC(cmd_list); int send_list(Client *client); -#define MSG_LIST "LIST" +#define MSG_LIST "LIST" -ModuleHeader MOD_HEADER - = { - "list", - "5.0", - "command /LIST", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "list", + "5.0", + "command /LIST", + "UnrealIRCd Team", + "unrealircd-6", +}; typedef struct ChannelListOptions ChannelListOptions; struct ChannelListOptions { @@ -43,7 +42,7 @@ struct ChannelListOptions { unsigned int starthash; short int showall; unsigned short usermin; - int usermax; + int usermax; time_t currenttime; time_t chantimemin; time_t chantimemax; @@ -57,12 +56,16 @@ ModDataInfo *list_md = NULL; char modebuf[BUFSIZE], parabuf[BUFSIZE]; /* Macros */ -#define CHANNELLISTOPTIONS(x) ((ChannelListOptions *)moddata_local_client(x, list_md).ptr) -#define ALLOCATE_CHANNELLISTOPTIONS(client) do { moddata_local_client(client, list_md).ptr = safe_alloc(sizeof(ChannelListOptions)); } while(0) -#define free_list_options(client) list_md_free(&moddata_local_client(client, list_md)) +#define CHANNELLISTOPTIONS(x) ((ChannelListOptions *)moddata_local_client(x, list_md).ptr) +#define ALLOCATE_CHANNELLISTOPTIONS(client) \ + do \ + { \ + moddata_local_client(client, list_md).ptr = safe_alloc(sizeof(ChannelListOptions)); \ + } while (0) +#define free_list_options(client) list_md_free(&moddata_local_client(client, list_md)) -#define DoList(x) (MyUser((x)) && CHANNELLISTOPTIONS((x))) -#define IsSendable(x) (DBufLength(&x->local->sendQ) < 2048) +#define DoList(x) (MyUser((x)) && CHANNELLISTOPTIONS((x))) +#define IsSendable(x) (DBufLength(&x->local->sendQ) < 2048) /* Forward declarations */ EVENT(send_queued_list_data); @@ -129,21 +132,21 @@ CMD_FUNC(cmd_list) char request[BUFSIZE]; static char *usage[] = { - " Usage: /LIST ", - "", - "If you don't include any options, the default is to send you the", - "entire unfiltered list of channels. Below are the options you can", - "use, and what channels LIST will return when you use them.", - ">number List channels with more than people.", - " people.", - "C>number List channels created more than minutes ago.", - "C minutes ago.", - "T>number List channels whose topics are older than minutes", - " (Ie, they have not changed in the last minutes.", - "T minutes.", - "*mask* List channels that match *mask*", - "!*mask* List channels that do not match *mask*", - NULL, + " Usage: /LIST ", + "", + "If you don't include any options, the default is to send you the", + "entire unfiltered list of channels. Below are the options you can", + "use, and what channels LIST will return when you use them.", + ">number List channels with more than people.", + " people.", + "C>number List channels created more than minutes ago.", + "C minutes ago.", + "T>number List channels whose topics are older than minutes", + " (Ie, they have not changed in the last minutes.", + "T minutes.", + "*mask* List channels that match *mask*", + "!*mask* List channels that do not match *mask*", + NULL, }; /* Remote /LIST is not supported */ @@ -186,8 +189,8 @@ CMD_FUNC(cmd_list) chantimemax = topictimemax = currenttime + 86400; chantimemin = topictimemin = 0; - usermin = 0; /* Minimum of 0 */ - usermax = -1; /* No maximum */ + usermin = 0; /* Minimum of 0 */ + usermax = -1; /* No maximum */ strlcpy(request, parv[1], sizeof(request)); for (name = strtoken(&p, request, ","); name && !error; name = strtoken(&p, NULL, ",")) @@ -208,7 +211,7 @@ CMD_FUNC(cmd_list) doall = 1; break; case 'C': - case 'c': /* Channel time -- creation time? */ + case 'c': /* Channel time -- creation time? */ ++name; switch (*name++) { @@ -260,21 +263,19 @@ CMD_FUNC(cmd_list) /* Negative matching by name */ doall = 1; add_name_list(nolist, name + 1); - } - else if (strchr(name, '*') || strchr(name, '?')) + } else if (strchr(name, '*') || strchr(name, '?')) { /* Channel with wildcards */ doall = 1; add_name_list(yeslist, name); - } - else + } else { /* A specific channel name without wildcards */ channel = find_channel(name); - if (channel && (ShowChannel(client, channel) || ValidatePermissionsForPath("channel:see:list:secret",client,NULL,channel,NULL))) + if (channel && (ShowChannel(client, channel) || ValidatePermissionsForPath("channel:see:list:secret", client, NULL, channel, NULL))) { modebuf[0] = '['; - channel_modes(client, modebuf+1, parabuf, sizeof(modebuf)-1, sizeof(parabuf), channel, 0); + channel_modes(client, modebuf + 1, parabuf, sizeof(modebuf) - 1, sizeof(parabuf), channel, 0); if (modebuf[2] == '\0') modebuf[0] = '\0'; @@ -282,7 +283,7 @@ CMD_FUNC(cmd_list) strlcat(modebuf, "]", sizeof modebuf); sendnumeric(client, RPL_LIST, name, channel->users, modebuf, - channel->topic ? channel->topic : ""); + channel->topic ? channel->topic : ""); } } } /* switch */ @@ -322,7 +323,7 @@ int send_list(Client *client) { Channel *channel; ChannelListOptions *lopt = CHANNELLISTOPTIONS(client); - unsigned int hashnum; + unsigned int hashnum; int numsend = (get_sendq(client) / 768) + 1; /* (was previously hard-coded) */ /* ^ * numsend = Number (roughly) of lines to send back. Once this number has @@ -332,7 +333,7 @@ int send_list(Client *client) * back more lines than specified by numsend (though not by much, * assuming the hashing algorithm works well). Be conservative in your * choice of numsend. -Rak - */ + */ /* Begin of /LIST? then send official channels first. */ if ((lopt->starthash == 0) && conf_offchans) @@ -352,9 +353,7 @@ int send_list(Client *client) if (numsend > 0) for (channel = hash_get_chan_bucket(hashnum); channel; channel = channel->hnextch) { - if (SecretChannel(channel) - && !IsMember(client, channel) - && !ValidatePermissionsForPath("channel:see:list:secret",client,NULL,channel,NULL)) + if (SecretChannel(channel) && !IsMember(client, channel) && !ValidatePermissionsForPath("channel:see:list:secret", client, NULL, channel, NULL)) continue; /* set::hide-list { deny-channel } */ @@ -392,26 +391,28 @@ int send_list(Client *client) continue; } modebuf[0] = '['; - channel_modes(client, modebuf+1, parabuf, sizeof(modebuf)-1, sizeof(parabuf), channel, 0); + channel_modes(client, modebuf + 1, parabuf, sizeof(modebuf) - 1, sizeof(parabuf), channel, 0); if (modebuf[2] == '\0') modebuf[0] = '\0'; else strlcat(modebuf, "]", sizeof modebuf); - if (!ValidatePermissionsForPath("channel:see:list:secret",client,NULL,channel,NULL)) + if (!ValidatePermissionsForPath("channel:see:list:secret", client, NULL, channel, NULL)) sendnumeric(client, RPL_LIST, - ShowChannel(client, - channel) ? channel->name : - "*", channel->users, - ShowChannel(client, channel) ? - modebuf : "", - ShowChannel(client, - channel) ? (channel->topic ? - channel->topic : "") : ""); + ShowChannel(client, + channel) + ? channel->name + : "*", + channel->users, + ShowChannel(client, channel) ? modebuf : "", + ShowChannel(client, + channel) + ? (channel->topic ? channel->topic : "") + : ""); else sendnumeric(client, RPL_LIST, channel->name, - channel->users, - modebuf, - (channel->topic ? channel->topic : "")); + channel->users, + modebuf, + (channel->topic ? channel->topic : "")); numsend--; } else diff --git a/src/modules/locops.c b/src/modules/locops.c index 1943d872c..bdff62d49 100644 --- a/src/modules/locops.c +++ b/src/modules/locops.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_locops); -#define MSG_LOCOPS "LOCOPS" +#define MSG_LOCOPS "LOCOPS" -ModuleHeader MOD_HEADER - = { - "locops", - "5.0", - "command /locops", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "locops", + "5.0", + "command /locops", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -65,7 +64,7 @@ CMD_FUNC(cmd_locops) sendnumeric(client, ERR_NEEDMOREPARAMS, "LOCOPS"); return; } - if (MyUser(client) && !ValidatePermissionsForPath("chat:locops",client,NULL,NULL,NULL)) + if (MyUser(client) && !ValidatePermissionsForPath("chat:locops", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; diff --git a/src/modules/lusers.c b/src/modules/lusers.c index 3f0780559..d06d56567 100644 --- a/src/modules/lusers.c +++ b/src/modules/lusers.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_lusers); -#define MSG_LUSERS "LUSERS" +#define MSG_LUSERS "LUSERS" -ModuleHeader MOD_HEADER - = { - "lusers", - "5.0", - "command /lusers", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "lusers", + "5.0", + "command /lusers", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_LUSERS, cmd_lusers, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_LUSERS, cmd_lusers, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -57,12 +56,12 @@ MOD_UNLOAD() */ CMD_FUNC(cmd_lusers) { -char flatmap; + char flatmap; if (hunt_server(client, recv_mtags, "LUSERS", 1, parc, parv) != HUNTED_ISME) return; - flatmap = (FLAT_MAP && !ValidatePermissionsForPath("server:info:lusers",client,NULL,NULL,NULL)) ? 1 : 0; + flatmap = (FLAT_MAP && !ValidatePermissionsForPath("server:info:lusers", client, NULL, NULL, NULL)) ? 1 : 0; /* Just to correct results ---Stskeeps */ if (irccounts.clients > irccounts.global_max) @@ -71,8 +70,8 @@ char flatmap; irccounts.me_max = irccounts.me_clients; sendnumeric(client, RPL_LUSERCLIENT, - irccounts.clients - irccounts.invisible, irccounts.invisible, - irccounts.servers); + irccounts.clients - irccounts.invisible, irccounts.invisible, + irccounts.servers); if (irccounts.operators) sendnumeric(client, RPL_LUSEROP, irccounts.operators); @@ -86,7 +85,7 @@ char flatmap; if (irccounts.me_clients > max_connection_count) { max_connection_count = irccounts.me_clients; - if (max_connection_count % 10 == 0) /* only send on even tens */ + if (max_connection_count % 10 == 0) /* only send on even tens */ { unreal_log(ULOG_INFO, "client", "NEW_USER_RECORD", NULL, "New record on this server: $num_users connections", diff --git a/src/modules/map.c b/src/modules/map.c index f74394113..42ccb2feb 100644 --- a/src/modules/map.c +++ b/src/modules/map.c @@ -24,32 +24,31 @@ CMD_FUNC(cmd_map); -#define MSG_MAP "MAP" +#define MSG_MAP "MAP" static int lmax = 0; static int umax = 0; static int dcount(int n) { - int cnt = 0; + int cnt = 0; - while (n != 0) - { - n = n/10; - cnt++; - } + while (n != 0) + { + n = n / 10; + cnt++; + } - return cnt; + return cnt; } -ModuleHeader MOD_HEADER - = { - "map", - "5.0", - "command /map", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "map", + "5.0", + "command /map", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -77,7 +76,7 @@ static void dump_map(Client *client, Client *server, char *mask, int prompt_leng { static char prompt[64]; char *p = &prompt[prompt_length]; - int cnt = 0; + int cnt = 0; Client *acptr; *p = '\0'; @@ -101,9 +100,10 @@ static void dump_map(Client *client, Client *server, char *mask, int prompt_leng if (IsOper(client)) snprintf(sid, sizeof(sid), " [%s]", server->id); sendnumeric(client, RPL_MAP, prompt, server->name, tbuf, umax, - server->server->users, (double)(lmax < 10) ? 4 : (lmax == 100) ? 6 : 5, - (server->server->users * 100.0 / irccounts.clients), - IsOper(client) ? sid : ""); + server->server->users, (double)(lmax < 10) ? 4 : (lmax == 100) ? 6 + : 5, + (server->server->users * 100.0 / irccounts.clients), + IsOper(client) ? sid : ""); cnt = 0; } @@ -121,7 +121,7 @@ static void dump_map(Client *client, Client *server, char *mask, int prompt_leng list_for_each_entry(acptr, &global_server_list, client_node) { if (acptr->uplink != server || - (IsULine(acptr) && HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines",client,NULL,NULL,NULL))) + (IsULine(acptr) && HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines", client, NULL, NULL, NULL))) continue; SetMap(acptr); cnt++; @@ -129,7 +129,7 @@ static void dump_map(Client *client, Client *server, char *mask, int prompt_leng list_for_each_entry(acptr, &global_server_list, client_node) { - if (IsULine(acptr) && HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines",client,NULL,NULL,NULL)) + if (IsULine(acptr) && HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines", client, NULL, NULL, NULL)) continue; if (acptr->uplink != server) continue; @@ -151,7 +151,7 @@ void dump_flat_map(Client *client, Client *server, int length) Client *acptr; int cnt = 0, len = 0, hide_ulines; - hide_ulines = (HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines",client,NULL,NULL,NULL)) ? 1 : 0; + hide_ulines = (HIDE_ULINES && !ValidatePermissionsForPath("server:info:map:ulines", client, NULL, NULL, NULL)) ? 1 : 0; len = length - strlen(server->name) + 3; if (len < 0) @@ -164,8 +164,9 @@ void dump_flat_map(Client *client, Client *server, int length) tbuf[len--] = '-'; sendnumeric(client, RPL_MAP, "", server->name, tbuf, umax, server->server->users, - (lmax < 10) ? 4 : (lmax == 100) ? 6 : 5, - (server->server->users * 100.0 / irccounts.clients), ""); + (lmax < 10) ? 4 : (lmax == 100) ? 6 + : 5, + (server->server->users * 100.0 / irccounts.clients), ""); list_for_each_entry(acptr, &global_server_list, client_node) { @@ -193,8 +194,9 @@ void dump_flat_map(Client *client, Client *server, int length) tbuf[len--] = '-'; sendnumeric(client, RPL_MAP, buf, acptr->name, tbuf, umax, acptr->server->users, - (lmax < 10) ? 4 : (lmax == 100) ? 6 : 5, - (acptr->server->users * 100.0 / irccounts.clients), ""); + (lmax < 10) ? 4 : (lmax == 100) ? 6 + : 5, + (acptr->server->users * 100.0 / irccounts.clients), ""); } } @@ -207,7 +209,7 @@ void dump_flat_map(Client *client, Client *server, int length) CMD_FUNC(cmd_map) { Client *acptr; - int longest = strlen(me.name); + int longest = strlen(me.name); float avg_users; umax = 0; @@ -231,13 +233,13 @@ CMD_FUNC(cmd_map) longest = 60; longest += 2; - if (FLAT_MAP && !ValidatePermissionsForPath("server:info:map:real-map",client,NULL,NULL,NULL)) + if (FLAT_MAP && !ValidatePermissionsForPath("server:info:map:real-map", client, NULL, NULL, NULL)) dump_flat_map(client, &me, longest); else dump_map(client, &me, "*", 0, longest); avg_users = irccounts.clients * 1.0 / irccounts.servers; sendnumeric(client, RPL_MAPUSERS, irccounts.servers, (irccounts.servers > 1 ? "s" : ""), irccounts.clients, - (irccounts.clients > 1 ? "s" : ""), avg_users); + (irccounts.clients > 1 ? "s" : ""), avg_users); sendnumeric(client, RPL_MAPEND); } diff --git a/src/modules/max-unknown-connections-per-ip.c b/src/modules/max-unknown-connections-per-ip.c index 53e389f8d..eb3c423fd 100644 --- a/src/modules/max-unknown-connections-per-ip.c +++ b/src/modules/max-unknown-connections-per-ip.c @@ -6,14 +6,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "max-unknown-connections-per-ip", - "6.0.0", - "set::max-unknown-connections-per-ip", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "max-unknown-connections-per-ip", + "6.0.0", + "set::max-unknown-connections-per-ip", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declaration */ int max_unknown_connections_accept(Client *client); @@ -56,7 +55,7 @@ static int check_too_many_unknown_connections(Client *client) { continue; } - if (!strcmp(client->ip,GetIP(c))) + if (!strcmp(client->ip, GetIP(c))) { cnt++; if (cnt > iConf.max_unknown_connections_per_ip) diff --git a/src/modules/maxperip.c b/src/modules/maxperip.c index c12ddd792..ec7152c01 100644 --- a/src/modules/maxperip.c +++ b/src/modules/maxperip.c @@ -19,22 +19,20 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "maxperip", - "2.0.0", - "Limit user connections based on ip address", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "maxperip", + "2.0.0", + "Limit user connections based on ip address", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Defines and macros */ #define IPUSERS_HASH_TABLE_SIZE 8192 /* Structs */ typedef struct IpUsersBucket IpUsersBucket; -struct IpUsersBucket -{ +struct IpUsersBucket { IpUsersBucket *prev, *next; char rawip[16]; int local_clients; @@ -53,12 +51,12 @@ static int known_cloud_services = 1; /* default: enabled */ * See https://www.irccloud.com/networks and https://www.irccloud.com/static/hosts.json */ static const char *irccloud_cidrs[] = { - "5.254.36.56/29", - "5.254.36.104/29", - "2a03:5180:f::/62", - "2a03:5180:f:4::/63", - "2a03:5180:f:6::/64", - NULL, + "5.254.36.56/29", + "5.254.36.104/29", + "2a03:5180:f::/62", + "2a03:5180:f:4::/63", + "2a03:5180:f:6::/64", + NULL, }; /* Forward declarations */ @@ -139,16 +137,18 @@ int maxperip_config_test_allow(ConfigFile *cf, ConfigEntry *ce, int type, int *e { config_error("%s:%i: missing parameter", ce->file->filename, ce->line_number); errors++; - } else { + } else + { int v = atoi(ce->value); if ((v <= 0) || (v > 1000000)) { config_error("%s:%i: allow::%s with illegal value (must be 1-1000000)", - ce->file->filename, ce->line_number, ce->name); + ce->file->filename, ce->line_number, ce->name); errors++; } } - } else { + } else + { return 0; /* Unknown option for us */ } @@ -167,8 +167,7 @@ int maxperip_config_run_allow(ConfigFile *cf, ConfigEntry *ce, int type, void *p if (!strcmp(ce->name, "maxperip")) { allow->maxperip = atoi(ce->value); - } else - if (!strcmp(ce->name, "global-maxperip")) + } else if (!strcmp(ce->name, "global-maxperip")) { allow->global_maxperip = atoi(ce->value); } else @@ -186,7 +185,7 @@ void maxperip_postconf(void) { /* Default: global-maxperip = maxperip+1 */ if (allow->global_maxperip == 0) - allow->global_maxperip = allow->maxperip+1; + allow->global_maxperip = allow->maxperip + 1; /* global-maxperip < maxperip makes no sense */ if (allow->global_maxperip < allow->maxperip) @@ -233,7 +232,8 @@ IpUsersBucket *find_ipusers_bucket(Client *client) for (p = IpUsersHash_ipv6[hash]; p; p = p->next) if (memcmp(p->rawip, rawip, 16) == 0) return p; - } else { + } else + { for (p = IpUsersHash_ipv4[hash]; p; p = p->next) if (memcmp(p->rawip, rawip, 4) == 0) return p; @@ -263,7 +263,8 @@ IpUsersBucket *add_ipusers_bucket(Client *client) { memcpy(n->rawip, rawip, 16); AddListItem(n, IpUsersHash_ipv6[hash]); - } else { + } else + { memcpy(n->rawip, rawip, 4); AddListItem(n, IpUsersHash_ipv4[hash]); } @@ -289,7 +290,8 @@ void decrease_ipusers_bucket(Client *client) for (p = IpUsersHash_ipv6[hash]; p; p = p->next) if (memcmp(p->rawip, rawip, 16) == 0) break; - } else { + } else + { for (p = IpUsersHash_ipv4[hash]; p; p = p->next) if (memcmp(p->rawip, rawip, 4) == 0) break; @@ -389,7 +391,7 @@ int maxperip_config_test_set(ConfigFile *cf, ConfigEntry *ce, int type, int *err if (!ce->value) { config_error("%s:%i: set::known-cloud-services: no value specified", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } *errs = errors; @@ -451,14 +453,14 @@ int stats_maxperip(Client *client, const char *para) if (strcmp(para, "8") && strcasecmp(para, "maxperip")) return 0; - if (!ValidatePermissionsForPath("server:info:stats",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:info:stats", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return 0; } sendtxtnumeric(client, "MaxPerIp IPv4 hash table:"); - for (i=0; i < IPUSERS_HASH_TABLE_SIZE; i++) + for (i = 0; i < IPUSERS_HASH_TABLE_SIZE; i++) { for (e = IpUsersHash_ipv4[i]; e; e = e->next) { @@ -466,12 +468,12 @@ int stats_maxperip(Client *client, const char *para) if (!ip) ip = ""; sendtxtnumeric(client, "IPv4 #%d %s: %d local / %d global", - i, ip, e->local_clients, e->global_clients); + i, ip, e->local_clients, e->global_clients); } } sendtxtnumeric(client, "MaxPerIp IPv6 hash table:"); - for (i=0; i < IPUSERS_HASH_TABLE_SIZE; i++) + for (i = 0; i < IPUSERS_HASH_TABLE_SIZE; i++) { for (e = IpUsersHash_ipv6[i]; e; e = e->next) { @@ -479,8 +481,8 @@ int stats_maxperip(Client *client, const char *para) if (!ip) ip = ""; sendtxtnumeric(client, "IPv6 #%d %s/%d: %d local / %d global", - i, ip, iConf.default_ipv6_clone_mask, - e->local_clients, e->global_clients); + i, ip, iConf.default_ipv6_clone_mask, + e->local_clients, e->global_clients); } } @@ -554,32 +556,32 @@ const char *maxperip_allow_client(Client *client, ConfigItem_allow *aconf) mask_ipv6_rawip(client->rawip, iConf.default_ipv6_clone_mask, masked); if (bucket && bucket->local_clients > aconf->maxperip) unreal_log(ULOG_INFO, "maxperip", "MAXPERIP_LIMIT", client, - "Client $client.name with IP $client.ip rejected: maxperip limit exceeded for $prefix_addr/$prefix_len ($count local, max $max)", - log_data_string("prefix_addr", format_ipv6_addr(masked)), - log_data_integer("prefix_len", iConf.default_ipv6_clone_mask), - log_data_integer("count", bucket->local_clients), - log_data_integer("max", aconf->maxperip)); + "Client $client.name with IP $client.ip rejected: maxperip limit exceeded for $prefix_addr/$prefix_len ($count local, max $max)", + log_data_string("prefix_addr", format_ipv6_addr(masked)), + log_data_integer("prefix_len", iConf.default_ipv6_clone_mask), + log_data_integer("count", bucket->local_clients), + log_data_integer("max", aconf->maxperip)); else unreal_log(ULOG_INFO, "maxperip", "MAXPERIP_LIMIT", client, - "Client $client.name with IP $client.ip rejected: maxperip limit exceeded for $prefix_addr/$prefix_len ($count global, max $max)", - log_data_string("prefix_addr", format_ipv6_addr(masked)), - log_data_integer("prefix_len", iConf.default_ipv6_clone_mask), - log_data_integer("count", bucket ? bucket->global_clients : 0), - log_data_integer("max", aconf->global_maxperip)); + "Client $client.name with IP $client.ip rejected: maxperip limit exceeded for $prefix_addr/$prefix_len ($count global, max $max)", + log_data_string("prefix_addr", format_ipv6_addr(masked)), + log_data_integer("prefix_len", iConf.default_ipv6_clone_mask), + log_data_integer("count", bucket ? bucket->global_clients : 0), + log_data_integer("max", aconf->global_maxperip)); return format_ipv6_prefix_reject_message( iConf.reject_message_too_many_connections_ipv6_range, masked, iConf.default_ipv6_clone_mask); } if (bucket && bucket->local_clients > aconf->maxperip) unreal_log(ULOG_INFO, "maxperip", "MAXPERIP_LIMIT", client, - "Client $client.name with IP $client.ip rejected: maxperip limit exceeded ($count local, max $max)", - log_data_integer("count", bucket->local_clients), - log_data_integer("max", aconf->maxperip)); + "Client $client.name with IP $client.ip rejected: maxperip limit exceeded ($count local, max $max)", + log_data_integer("count", bucket->local_clients), + log_data_integer("max", aconf->maxperip)); else unreal_log(ULOG_INFO, "maxperip", "MAXPERIP_LIMIT", client, - "Client $client.name with IP $client.ip rejected: maxperip limit exceeded ($count global, max $max)", - log_data_integer("count", bucket ? bucket->global_clients : 0), - log_data_integer("max", aconf->global_maxperip)); + "Client $client.name with IP $client.ip rejected: maxperip limit exceeded ($count global, max $max)", + log_data_integer("count", bucket ? bucket->global_clients : 0), + log_data_integer("max", aconf->global_maxperip)); return iConf.reject_message_too_many_connections; } return NULL; diff --git a/src/modules/md.c b/src/modules/md.c index f01a608df..fc6310a02 100644 --- a/src/modules/md.c +++ b/src/modules/md.c @@ -8,14 +8,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "md", - "5.0", - "command /MD (S2S only)", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "md", + "5.0", + "command /MD (S2S only)", + "UnrealIRCd Team", + "unrealircd-6", +}; CMD_FUNC(cmd_md); void _broadcast_md_client(ModDataInfo *mdi, Client *client, ModData *md); @@ -35,7 +34,7 @@ void _send_moddata_channel(Client *srv, Channel *channel); void _send_moddata_members(Client *srv); void _broadcast_moddata_client(Client *client); -extern MODVAR ModDataInfo *MDInfo[HIGHESTMODDATATYPE+1]; +extern MODVAR ModDataInfo *MDInfo[HIGHESTMODDATATYPE + 1]; MOD_TEST() { @@ -61,7 +60,7 @@ MOD_TEST() MOD_INIT() { - CommandAdd(modinfo->handle, "MD", cmd_md, MAXPARA, CMD_SERVER|CMD_BIGLINES); + CommandAdd(modinfo->handle, "MD", cmd_md, MAXPARA, CMD_SERVER | CMD_BIGLINES); return MOD_SUCCESS; } @@ -149,8 +148,7 @@ CMD_FUNC(cmd_md) } /* Pass on to other servers */ broadcast_md_client_cmd(client->direction, client, target, varname, value); - } else - if (!strcmp(type, "channel")) + } else if (!strcmp(type, "channel")) { Channel *channel = find_channel(objname); md = findmoddata_byname(varname, MODDATATYPE_CHANNEL); @@ -166,8 +164,7 @@ CMD_FUNC(cmd_md) } /* Pass on to other servers */ broadcast_md_channel_cmd(client->direction, client, channel, varname, value); - } else - if (!strcmp(type, "member")) + } else if (!strcmp(type, "member")) { Client *target; Channel *channel; @@ -214,8 +211,7 @@ CMD_FUNC(cmd_md) } /* Pass on to other servers */ broadcast_md_member_cmd(client->direction, client, channel, target, varname, value); - } else - if (!strcmp(type, "membership")) + } else if (!strcmp(type, "membership")) { Client *target; Channel *channel; @@ -257,8 +253,7 @@ CMD_FUNC(cmd_md) } /* Pass on to other servers */ broadcast_md_membership_cmd(client->direction, client, target, channel, varname, value); - } else - if (!strcmp(type, "globalvar")) + } else if (!strcmp(type, "globalvar")) { /* objname is ignored */ md = findmoddata_byname(varname, MODDATATYPE_GLOBAL_VARIABLE); @@ -282,12 +277,11 @@ void _broadcast_md_client_cmd(Client *except, Client *sender, Client *client, co if (value) { sendto_server(except, 0, 0, NULL, ":%s MD %s %s %s :%s", - sender->id, "client", client->id, varname, value); - } - else + sender->id, "client", client->id, varname, value); + } else { sendto_server(except, 0, 0, NULL, ":%s MD %s %s %s", - sender->id, "client", client->id, varname); + sender->id, "client", client->id, varname); } } @@ -295,10 +289,10 @@ void _broadcast_md_channel_cmd(Client *except, Client *sender, Channel *channel, { if (value) sendto_server(except, 0, 0, NULL, ":%s MD %s %s %s :%s", - sender->id, "channel", channel->name, varname, value); + sender->id, "channel", channel->name, varname, value); else sendto_server(except, 0, 0, NULL, ":%s MD %s %s %s", - sender->id, "channel", channel->name, varname); + sender->id, "channel", channel->name, varname); } void _broadcast_md_member_cmd(Client *except, Client *sender, Channel *channel, Client *client, const char *varname, const char *value) @@ -306,12 +300,11 @@ void _broadcast_md_member_cmd(Client *except, Client *sender, Channel *channel, if (value) { sendto_server(except, 0, 0, NULL, ":%s MD %s %s:%s %s :%s", - sender->id, "member", channel->name, client->id, varname, value); - } - else + sender->id, "member", channel->name, client->id, varname, value); + } else { sendto_server(except, 0, 0, NULL, ":%s MD %s %s:%s %s", - sender->id, "member", channel->name, client->id, varname); + sender->id, "member", channel->name, client->id, varname); } } @@ -320,12 +313,11 @@ void _broadcast_md_membership_cmd(Client *except, Client *sender, Client *client if (value) { sendto_server(except, 0, 0, NULL, ":%s MD %s %s:%s %s :%s", - sender->id, "membership", client->id, channel->name, varname, value); - } - else + sender->id, "membership", client->id, channel->name, varname, value); + } else { sendto_server(except, 0, 0, NULL, ":%s MD %s %s:%s %s", - sender->id, "membership", client->id, channel->name, varname); + sender->id, "membership", client->id, channel->name, varname); } } @@ -334,12 +326,11 @@ void _broadcast_md_globalvar_cmd(Client *except, Client *sender, const char *var if (value) { sendto_server(except, 0, 0, NULL, ":%s MD %s %s :%s", - sender->id, "globalvar", varname, value); - } - else + sender->id, "globalvar", varname, value); + } else { sendto_server(except, 0, 0, NULL, ":%s MD %s %s", - sender->id, "globalvar", varname); + sender->id, "globalvar", varname); } } @@ -348,7 +339,7 @@ void _broadcast_md_globalvar_cmd(Client *except, Client *sender, const char *var * @param client The affected client * @param md The ModData. May be NULL for unset. */ - + void _broadcast_md_client(ModDataInfo *mdi, Client *client, ModData *md) { const char *value = md ? mdi->serialize(md) : NULL; @@ -396,7 +387,7 @@ void _send_moddata_client(Client *srv, Client *client) const char *value = mdi->serialize(&moddata_client(client, mdi)); if (value) sendto_one(srv, NULL, ":%s MD %s %s %s :%s", - me.id, "client", client->id, mdi->name, value); + me.id, "client", client->id, mdi->name, value); } } } @@ -469,7 +460,7 @@ void _send_moddata_channel(Client *srv, Channel *channel) const char *value = mdi->serialize(&moddata_channel(channel, mdi)); if (value) sendto_one(srv, NULL, ":%s MD %s %s %s :%s", - me.id, "channel", channel->name, mdi->name, value); + me.id, "channel", channel->name, mdi->name, value); } } } @@ -496,7 +487,7 @@ void _send_moddata_members(Client *srv) const char *value = mdi->serialize(&moddata_member(m, mdi)); if (value) sendto_one(srv, NULL, ":%s MD %s %s:%s %s :%s", - me.id, "member", channel->name, client->id, mdi->name, value); + me.id, "member", channel->name, client->id, mdi->name, value); } } } @@ -520,7 +511,7 @@ void _send_moddata_members(Client *srv) const char *value = mdi->serialize(&moddata_membership(m, mdi)); if (value) sendto_one(srv, NULL, ":%s MD %s %s:%s %s :%s", - me.id, "membership", client->id, m->channel->name, mdi->name, value); + me.id, "membership", client->id, m->channel->name, mdi->name, value); } } } diff --git a/src/modules/message-ids.c b/src/modules/message-ids.c index 3fe0c97fd..0c655453c 100644 --- a/src/modules/message-ids.c +++ b/src/modules/message-ids.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "message-ids", - "5.0", - "msgid CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "message-ids", + "5.0", + "msgid CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ long CAP_ACCOUNT_TAG = 0L; @@ -97,7 +96,7 @@ MessageTag *mtag_generate_msgid(void) { MessageTag *m = safe_alloc(sizeof(MessageTag)); safe_strdup(m->name, "msgid"); - m->value = safe_alloc(MSGIDLEN+1); + m->value = safe_alloc(MSGIDLEN + 1); gen_random_alnum(m->value, MSGIDLEN); return m; } @@ -124,7 +123,7 @@ void mtag_add_or_inherit_msgid(Client *sender, MessageTag *recv_mtags, MessageTa * The hash is the first half of a SHA256 hash, then * base64'd, and with the == suffix removed. */ - char prefix[MSGIDLEN+1], *p; + char prefix[MSGIDLEN + 1], *p; strlcpy(prefix, m->value, sizeof(prefix)); p = strchr(prefix, '-'); if (p) @@ -142,12 +141,12 @@ void mtag_add_or_inherit_msgid(Client *sender, MessageTag *recv_mtags, MessageTa } SHA256_CTX hash; char binaryhash[SHA256_DIGEST_LENGTH]; - char b64hash[SHA256_DIGEST_LENGTH*2+1]; + char b64hash[SHA256_DIGEST_LENGTH * 2 + 1]; char newbuf[256]; memset(&binaryhash, 0, sizeof(binaryhash)); memset(&b64hash, 0, sizeof(b64hash)); sha256hash_binary(binaryhash, signature, strlen(signature)); - b64_encode(binaryhash, sizeof(binaryhash)/2, b64hash, sizeof(b64hash)); + b64_encode(binaryhash, sizeof(binaryhash) / 2, b64hash, sizeof(b64hash)); b64hash[22] = '\0'; /* cut off at '=' */ snprintf(newbuf, sizeof(newbuf), "%s-%s", prefix, b64hash); safe_strdup(m->value, newbuf); diff --git a/src/modules/message-tags.c b/src/modules/message-tags.c index e1fda9431..1992e3510 100644 --- a/src/modules/message-tags.c +++ b/src/modules/message-tags.c @@ -26,14 +26,13 @@ #define SERVER_TAG_SIZE_LIMIT 8191 #define CLIENT_TAG_SIZE_LIMIT 4094 -ModuleHeader MOD_HEADER - = { - "message-tags", - "5.0", - "Message tags CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "message-tags", + "5.0", + "Message tags CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; long CAP_MESSAGE_TAGS = 0L; const char *_mtags_to_string(MessageTag *m, Client *client); @@ -134,7 +133,8 @@ void message_tag_escape(char *in, char *out, size_t outsize) *o++ = 'r'; else *o++ = 'n'; - } else { + } else + { if (end - o < 2) /* 1 byte + NUL */ break; *o++ = *in; @@ -169,7 +169,7 @@ void _parse_message_tags(Client *client, char **str, MessageTag **mtag_list) char *remainder; char *element, *p, *x; - static char name[SERVER_TAG_SIZE_LIMIT+1], value[SERVER_TAG_SIZE_LIMIT+1]; + static char name[SERVER_TAG_SIZE_LIMIT + 1], value[SERVER_TAG_SIZE_LIMIT + 1]; MessageTag *m; int lenstr; @@ -193,12 +193,13 @@ void _parse_message_tags(Client *client, char **str, MessageTag **mtag_list) * This is also used by a line-length-check above to force the * same error condition ("don't parse this"). */ - for (; **str; *str += 1); + for (; **str; *str += 1) + ; return; } /* Now actually parse the tags: */ - for (element = strtoken(&p, *str+1, ";"); element; element = strtoken(&p, NULL, ";")) + for (element = strtoken(&p, *str + 1, ";"); element; element = strtoken(&p, NULL, ";")) { *name = *value = '\0'; @@ -300,7 +301,8 @@ const char *_mtags_to_string(MessageTag *m, Client *client) message_tag_escape(m->name, name, sizeof(name)); message_tag_escape(m->value, value, sizeof(value)); snprintf(tbuf, sizeof(tbuf), "%s=%s;", name, value); - } else { + } else + { message_tag_escape(m->name, name, sizeof(name)); snprintf(tbuf, sizeof(tbuf), "%s;", name); } @@ -311,7 +313,7 @@ const char *_mtags_to_string(MessageTag *m, Client *client) return NULL; /* Strip off the final semicolon */ - buf[strlen(buf)-1] = '\0'; + buf[strlen(buf) - 1] = '\0'; return buf; } diff --git a/src/modules/message.c b/src/modules/message.c index 954d93648..57914d803 100644 --- a/src/modules/message.c +++ b/src/modules/message.c @@ -33,14 +33,13 @@ int _can_send_to_user(Client *client, Client *target, const char **msgtext, cons /* Variables */ long CAP_MESSAGE_TAGS = 0; /**< Looked up at MOD_LOAD, may stay 0 if message-tags support is absent */ -ModuleHeader MOD_HEADER - = { - "message", /* Name of module */ - "6.0.2", /* Version */ - "private message and notice", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "message", /* Name of module */ + "6.0.2", /* Version */ + "private message and notice", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_TEST() { @@ -54,9 +53,9 @@ MOD_TEST() /* This is called on module init, before Server Ready */ MOD_INIT() { - CommandAdd(modinfo->handle, "PRIVMSG", cmd_private, 2, CMD_USER|CMD_SERVER|CMD_RESETIDLE|CMD_VIRUS|CMD_TEXTANALYSIS); - CommandAdd(modinfo->handle, "NOTICE", cmd_notice, 2, CMD_USER|CMD_SERVER|CMD_TEXTANALYSIS); - CommandAdd(modinfo->handle, "TAGMSG", cmd_tagmsg, 1, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, "PRIVMSG", cmd_private, 2, CMD_USER | CMD_SERVER | CMD_RESETIDLE | CMD_VIRUS | CMD_TEXTANALYSIS); + CommandAdd(modinfo->handle, "NOTICE", cmd_notice, 2, CMD_USER | CMD_SERVER | CMD_TEXTANALYSIS); + CommandAdd(modinfo->handle, "TAGMSG", cmd_tagmsg, 1, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -75,8 +74,8 @@ MOD_UNLOAD() return MOD_SUCCESS; } -#define CANPRIVMSG_CONTINUE 100 -#define CANPRIVMSG_SEND 101 +#define CANPRIVMSG_CONTINUE 100 +#define CANPRIVMSG_SEND 101 /** Check if PRIVMSG's are permitted from a person to another person. * client: source client * target: target client @@ -156,7 +155,7 @@ int can_send_to_member_mode(Client *client, Channel *channel, char mode) { Membership *lp; - if (op_can_override("channel:override:message:prefix",client,channel,NULL)) + if (op_can_override("channel:override:message:prefix", client, channel, NULL)) return 1; lp = find_membership_link(client->user->channel, channel); @@ -314,7 +313,7 @@ void cmd_message(ClientContext *clictx, Client *client, MessageTag *recv_mtags, mtags = NULL; sendflags = SEND_ALL; - if (!strchr(CHANCMDPFX,parv[2][0])) + if (!strchr(CHANCMDPFX, parv[2][0])) sendflags |= SKIP_DEAF; if ((*parv[2] == '\001') && strncmp(&parv[2][1], "ACTION ", 7)) @@ -334,10 +333,11 @@ void cmd_message(ClientContext *clictx, Client *client, MessageTag *recv_mtags, { /* PRIVMSG or NOTICE */ sendto_channel(channel, client, client->direction, - member_modes, 0, sendflags, mtags, - ":%s %s %s :%s", - client->name, cmd, targetstr, text); - } else { + member_modes, 0, sendflags, mtags, + ":%s %s %s :%s", + client->name, cmd, targetstr, text); + } else + { /* TAGMSG: * Only send if the message includes any user message tags * and if the 'message-tags' module is loaded. @@ -349,9 +349,9 @@ void cmd_message(ClientContext *clictx, Client *client, MessageTag *recv_mtags, continue; } sendto_channel(channel, client, client->direction, - member_modes, CAP_MESSAGE_TAGS, sendflags, mtags, - ":%s TAGMSG %s", - client->name, targetstr); + member_modes, CAP_MESSAGE_TAGS, sendflags, mtags, + ":%s TAGMSG %s", + client->name, targetstr); } RunHook(HOOKTYPE_CHANMSG, client, channel, sendflags, member_modes, targetstr, mtags, text, sendtype); @@ -359,8 +359,7 @@ void cmd_message(ClientContext *clictx, Client *client, MessageTag *recv_mtags, free_message_tags(mtags); continue; - } - else if (p2) + } else if (p2) { sendnumeric(client, ERR_NOSUCHNICK, p2); continue; @@ -383,11 +382,10 @@ void cmd_message(ClientContext *clictx, Client *client, MessageTag *recv_mtags, } new_message(client, recv_mtags, &mtags); sendto_match_butone(IsServer(client->direction) ? client->direction : NULL, - client, targetstr + 1, - (*targetstr == '#') ? MATCH_HOST : - MATCH_SERVER, - mtags, - ":%s %s %s :%s", client->name, cmd, targetstr, parv[2]); + client, targetstr + 1, + (*targetstr == '#') ? MATCH_HOST : MATCH_SERVER, + mtags, + ":%s %s %s :%s", client->name, cmd, targetstr, parv[2]); free_message_tags(mtags); continue; } @@ -429,21 +427,24 @@ void cmd_message(ClientContext *clictx, Client *client, MessageTag *recv_mtags, if (HasCapability(target, "message-tags")) { sendto_prefix_one(target, client, mtags, ":%s %s %s", - client->name, cmd, target->name); + client->name, cmd, target->name); } - } else { + } else + { sendto_prefix_one(target, client, mtags, ":%s %s %s :%s", - client->name, cmd, target->name, text); + client->name, cmd, target->name, text); } - } else { + } else + { /* Send to another server */ if (sendtype == SEND_TYPE_TAGMSG) { sendto_prefix_one(target, client, mtags, ":%s %s %s", - client->id, cmd, target->id); - } else { + client->id, cmd, target->id); + } else + { sendto_prefix_one(target, client, mtags, ":%s %s %s :%s", - client->id, cmd, target->id, text); + client->id, cmd, target->id, text); } } labeled_response_inhibit = 0; @@ -512,12 +513,12 @@ CMD_FUNC(cmd_tagmsg) */ const char *_StripColors(const char *text) { - int i = 0, len = strlen(text), save_len=0; + int i = 0, len = strlen(text), save_len = 0; char nc = 0, col = 0, rgb = 0; - const char *save_text=NULL; + const char *save_text = NULL; static char new_str[4096]; - while (len > 0) + while (len > 0) { if ((col && isdigit(*text) && nc < 2) || ((col == 1) && (*text == ',') && isdigit(text[1]) && (nc > 0) && (nc < 3))) @@ -538,8 +539,7 @@ const char *_StripColors(const char *text) nc++; if (*text == ',') nc = 0; - } - else + } else { if (col) col = 0; @@ -547,26 +547,24 @@ const char *_StripColors(const char *text) { if (nc != 6) { - text = save_text+1; - len = save_len-1; + text = save_text + 1; + len = save_len - 1; rgb = 0; continue; } rgb = 0; } - if (*text == '\003') + if (*text == '\003') { col = 1; nc = 0; - } - else if (*text == '\004') + } else if (*text == '\004') { save_text = text; save_len = len; rgb = 1; nc = 0; - } - else if (*text != '\026') /* (strip reverse too) */ + } else if (*text != '\026') /* (strip reverse too) */ { new_str[i] = *text; i++; @@ -592,9 +590,9 @@ int ban_version(Client *client, const char *text) len = strlen(ctcp_reply); if (!len) return 0; - - if (ctcp_reply[len-1] == '\1') - ctcp_reply[len-1] = '\0'; /* remove CTCP REPLY terminator (ASCII 1) */ + + if (ctcp_reply[len - 1] == '\1') + ctcp_reply[len - 1] = '\0'; /* remove CTCP REPLY terminator (ASCII 1) */ if ((ban = find_ban(NULL, ctcp_reply, CONF_BAN_VERSION))) { @@ -625,7 +623,7 @@ int _can_send_to_channel(Client *client, Channel *channel, const char **msgtext, { static char errbuf[256]; Membership *lp; - int member, i = 0; + int member, i = 0; Hook *h; if (!MyUser(client)) @@ -665,8 +663,8 @@ int _can_send_to_channel(Client *client, Channel *channel, const char **msgtext, if (!*errmsg) { unreal_log(ULOG_ERROR, "main", "BUG_CAN_SEND_TO_CHANNEL_NO_ERRMSG", client, - "[BUG] Module $module did not set errmsg!!!", - log_data_string("module", h->owner->header->name)); + "[BUG] Module $module did not set errmsg!!!", + log_data_string("module", h->owner->header->name)); abort(); } break; @@ -695,7 +693,7 @@ int _can_send_to_channel(Client *client, Channel *channel, const char **msgtext, /* Now we are going to check bans */ /* ..but first: exempt ircops */ - if (op_can_override("channel:override:message:ban",client,channel,NULL)) + if (op_can_override("channel:override:message:ban", client, channel, NULL)) return 1; /* If local client is banned and not +vhoaq... */ diff --git a/src/modules/mkpasswd.c b/src/modules/mkpasswd.c index ca750c61e..6dc01add3 100644 --- a/src/modules/mkpasswd.c +++ b/src/modules/mkpasswd.c @@ -26,16 +26,15 @@ CMD_FUNC(cmd_mkpasswd); -#define MSG_MKPASSWD "MKPASSWD" +#define MSG_MKPASSWD "MKPASSWD" -ModuleHeader MOD_HEADER - = { - "mkpasswd", - "5.0", - "command /mkpasswd", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "mkpasswd", + "5.0", + "command /mkpasswd", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -102,5 +101,5 @@ CMD_FUNC(cmd_mkpasswd) } sendnotice(client, "*** Authentication phrase (method=%s, para=%s) is: %s", - parv[1], parv[2], result); + parv[1], parv[2], result); } diff --git a/src/modules/mmdb.c b/src/modules/mmdb.c index e322efe2a..cffef05df 100644 --- a/src/modules/mmdb.c +++ b/src/modules/mmdb.c @@ -35,19 +35,20 @@ #include #ifdef _WIN32 -#include -#include + #include + #include #else -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include #endif /* Constants */ -static const uint8_t METADATA_MARKER[] = "\xAB\xCD\xEF" "MaxMind.com"; +static const uint8_t METADATA_MARKER[] = "\xAB\xCD\xEF" + "MaxMind.com"; #define METADATA_MARKER_LEN 14 #define METADATA_MAX_SIZE (128 * 1024) #define DATA_SEPARATOR_SIZE 16 @@ -56,19 +57,19 @@ static const uint8_t METADATA_MARKER[] = "\xAB\xCD\xEF" "MaxMind.com"; /* MMDB data types from the spec */ enum { DT_EXTENDED = 0, - DT_POINTER = 1, - DT_STRING = 2, - DT_FLOAT64 = 3, - DT_BYTES = 4, - DT_UINT16 = 5, - DT_UINT32 = 6, - DT_MAP = 7, - DT_INT32 = 8, - DT_UINT64 = 9, - DT_UINT128 = 10, - DT_ARRAY = 11, - DT_BOOL = 14, - DT_FLOAT32 = 15, + DT_POINTER = 1, + DT_STRING = 2, + DT_FLOAT64 = 3, + DT_BYTES = 4, + DT_UINT16 = 5, + DT_UINT32 = 6, + DT_MAP = 7, + DT_INT32 = 8, + DT_UINT64 = 9, + DT_UINT128 = 10, + DT_ARRAY = 11, + DT_BOOL = 14, + DT_FLOAT32 = 15, }; /* Platform: mmap / file I/O */ @@ -255,10 +256,16 @@ static int decode_pointer(const uint8_t *buf, size_t buflen, /* Add base offset per pointer size */ switch (ptr_size) { - case 1: break; - case 2: pointer += 2048; break; - case 3: pointer += 526336; break; - case 4: break; + case 1: + break; + case 2: + pointer += 2048; + break; + case 3: + pointer += 526336; + break; + case 4: + break; } *pointer_out = pointer; @@ -312,7 +319,10 @@ static int decode_uint16(const uint8_t *buf, size_t buflen, static int decode_float64(const uint8_t *buf, size_t buflen, uint32_t size, size_t offset, double *out) { - union { uint64_t u; double d; } conv; + union { + uint64_t u; + double d; + } conv; int i; if (size != 8 || offset + 8 > buflen) @@ -328,7 +338,10 @@ static int decode_float64(const uint8_t *buf, size_t buflen, static int decode_float32(const uint8_t *buf, size_t buflen, uint32_t size, size_t offset, float *out) { - union { uint32_t u; float f; } conv; + union { + uint32_t u; + float f; + } conv; int i; if (size != 4 || offset + 4 > buflen) @@ -683,46 +696,46 @@ static int read_node(const uint8_t *buf, size_t buflen, switch (record_size) { - case 24: - { - o = offset + bit * 3; - if (o + 3 > buflen) - return MMDB_ERR_CORRUPT; - *value = ((uint32_t)buf[o] << 16) | - ((uint32_t)buf[o + 1] << 8) | - (uint32_t)buf[o + 2]; - return MMDB_OK; - } - case 28: - { - if (offset + 7 > buflen) - return MMDB_ERR_CORRUPT; - if (bit == 0) + case 24: { - *value = (((uint32_t)buf[offset + 3] & 0xF0) << 20) | - ((uint32_t)buf[offset] << 16) | - ((uint32_t)buf[offset + 1] << 8) | - (uint32_t)buf[offset + 2]; - } else - { - *value = (((uint32_t)buf[offset + 3] & 0x0F) << 24) | - ((uint32_t)buf[offset + 4] << 16) | - ((uint32_t)buf[offset + 5] << 8) | - (uint32_t)buf[offset + 6]; + o = offset + bit * 3; + if (o + 3 > buflen) + return MMDB_ERR_CORRUPT; + *value = ((uint32_t)buf[o] << 16) | + ((uint32_t)buf[o + 1] << 8) | + (uint32_t)buf[o + 2]; + return MMDB_OK; + } + case 28: + { + if (offset + 7 > buflen) + return MMDB_ERR_CORRUPT; + if (bit == 0) + { + *value = (((uint32_t)buf[offset + 3] & 0xF0) << 20) | + ((uint32_t)buf[offset] << 16) | + ((uint32_t)buf[offset + 1] << 8) | + (uint32_t)buf[offset + 2]; + } else + { + *value = (((uint32_t)buf[offset + 3] & 0x0F) << 24) | + ((uint32_t)buf[offset + 4] << 16) | + ((uint32_t)buf[offset + 5] << 8) | + (uint32_t)buf[offset + 6]; + } + return MMDB_OK; + } + case 32: + { + o = offset + bit * 4; + if (o + 4 > buflen) + return MMDB_ERR_CORRUPT; + *value = ((uint32_t)buf[o] << 24) | + ((uint32_t)buf[o + 1] << 16) | + ((uint32_t)buf[o + 2] << 8) | + (uint32_t)buf[o + 3]; + return MMDB_OK; } - return MMDB_OK; - } - case 32: - { - o = offset + bit * 4; - if (o + 4 > buflen) - return MMDB_ERR_CORRUPT; - *value = ((uint32_t)buf[o] << 24) | - ((uint32_t)buf[o + 1] << 16) | - ((uint32_t)buf[o + 2] << 8) | - (uint32_t)buf[o + 3]; - return MMDB_OK; - } } return MMDB_ERR_CORRUPT; } @@ -956,7 +969,7 @@ MMDB_Status mmdb_lookup(MMDB_DB *db, const char *ip_str, MMDB_Result *result) } MMDB_Status mmdb_lookup_sockaddr(MMDB_DB *db, const struct sockaddr *sa, - MMDB_Result *result) + MMDB_Result *result) { uint8_t ip128[16]; const struct sockaddr_in *sa4; diff --git a/src/modules/mode.c b/src/modules/mode.c index a198d31b8..fe1da9a39 100644 --- a/src/modules/mode.c +++ b/src/modules/mode.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "mode", - "5.0", - "command /mode", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "mode", + "5.0", + "command /mode", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int list_mode_request(Client *client, Channel *channel, const char *req); @@ -37,7 +36,7 @@ CMD_FUNC(cmd_mode); CMD_FUNC(cmd_mlock); void _do_mode(Channel *channel, Client *client, MessageTag *recv_mtags, int parc, const char *parv[], time_t sendts, int samode); MultiLineMode *_set_mode(Channel *channel, Client *client, int parc, const char *parv[], u_int *pcount, - char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]); + char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]); void _set_channel_mode(Channel *channel, MessageTag *mtags, const char *modes, const char *parameters); CMD_FUNC(_cmd_umode); @@ -48,7 +47,7 @@ int do_mode_char(Channel *channel, long modetype, char modechar, const char *par int do_extmode_char(Channel *channel, Cmode *handler, const char *param, u_int what, Client *client, u_int *pcount, char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]); void do_mode_char_member_mode_new(Channel *channel, Cmode *handler, const char *param, u_int what, - Client *client, u_int *pcount, char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]); + Client *client, u_int *pcount, char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]); MultiLineMode *make_mode_str(Client *client, Channel *channel, Cmode_t oldem, int pcount, char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]); static char *mode_cutoff(const char *s); @@ -68,7 +67,7 @@ MOD_TEST() MOD_INIT() { - CommandAdd(modinfo->handle, "MODE", cmd_mode, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, "MODE", cmd_mode, MAXPARA, CMD_USER | CMD_SERVER); CommandAdd(modinfo->handle, MSG_MLOCK, cmd_mlock, MAXPARA, CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; @@ -147,7 +146,7 @@ CMD_FUNC(cmd_mode) #ifndef NO_OPEROVERRIDE if (IsUser(client) && !IsULine(client) && !check_channel_access(client, channel, "oaq") && - !check_channel_access(client, channel, "h") && ValidatePermissionsForPath("channel:override:mode",client,NULL,channel,NULL)) + !check_channel_access(client, channel, "h") && ValidatePermissionsForPath("channel:override:mode", client, NULL, channel, NULL)) { sendts = 0; opermode = 1; @@ -155,7 +154,7 @@ CMD_FUNC(cmd_mode) } if (IsUser(client) && !IsULine(client) && !check_channel_access(client, channel, "oaq") && - check_channel_access(client, channel, "h") && ValidatePermissionsForPath("channel:override:mode",client,NULL,channel,NULL)) + check_channel_access(client, channel, "h") && ValidatePermissionsForPath("channel:override:mode", client, NULL, channel, NULL)) { opermode = 2; goto aftercheck; @@ -164,7 +163,7 @@ CMD_FUNC(cmd_mode) /* User does not have permission to use the MODE command */ if (MyUser(client) && !IsULine(client) && !check_channel_access(client, channel, "hoaq") && - !ValidatePermissionsForPath("channel:override:mode",client,NULL,channel,NULL)) + !ValidatePermissionsForPath("channel:override:mode", client, NULL, channel, NULL)) { sendnumeric(client, ERR_CHANOPRIVSNEEDED, channel->name); return; @@ -189,7 +188,7 @@ CMD_FUNC(cmd_mode) if (IsServer(client) && !sendts && *parv[parc - 1] != '0') sendts = -1; if (IsServer(client) && sendts != -1) - parc--; /* server supplied a time stamp, remove it now */ + parc--; /* server supplied a time stamp, remove it now */ aftercheck: @@ -235,7 +234,7 @@ void _do_mode(Channel *channel, Client *client, MessageTag *recv_mtags, int parc { Client *orig_client = client; /* (needed for samode replacement in a loop) */ char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]; - int pcount; + int pcount; int i; char tschange = 0; MultiLineMode *m; @@ -256,27 +255,25 @@ void _do_mode(Channel *channel, Client *client, MessageTag *recv_mtags, int parc "Buffer: $modebuf $parabuf", log_data_channel("channel", channel), log_data_integer("send_timestamp", sendts), - log_data_string("modebuf", m?m->modeline[0]:""), - log_data_string("parabuf", m?m->modeline[0]:"")); + log_data_string("modebuf", m ? m->modeline[0] : ""), + log_data_string("parabuf", m ? m->modeline[0] : "")); /* Yeah, so what to do in this case? * Don't set channel->creationtime * and assume merging. */ sendts = channel->creationtime; - } else - if (sendts < channel->creationtime) + } else if (sendts < channel->creationtime) { /* Our timestamp is wrong or this is a new channel */ tschange = 1; channel->creationtime = sendts; - } if (sendts > channel->creationtime && channel->creationtime) { /* Their timestamp is wrong */ sendts = channel->creationtime; sendto_one(client, NULL, ":%s MODE %s + %lld", me.name, - channel->name, (long long)channel->creationtime); + channel->name, (long long)channel->creationtime); } } if (sendts == -1) @@ -295,8 +292,8 @@ void _do_mode(Channel *channel, Client *client, MessageTag *recv_mtags, int parc * (all except from where it came from, client). */ sendto_server(client, 0, 0, NULL, ":%s MODE %s + %lld", - me.id, channel->name, - (long long)channel->creationtime); + me.id, channel->name, + (long long)channel->creationtime); } /* Nothing to send */ safe_free_multilinemode(m); @@ -319,9 +316,9 @@ void _do_mode(Channel *channel, Client *client, MessageTag *recv_mtags, int parc char buf[512]; snprintf(buf, sizeof(buf), "%s%s%s", modebuf, *parabuf ? " " : "", parabuf); unreal_log(ULOG_INFO, "samode", "SAMODE_COMMAND", orig_client, - "Client $client used SAMODE $channel ($mode)", - log_data_channel("channel", channel), - log_data_string("mode", buf)); + "Client $client used SAMODE $channel ($mode)", + log_data_channel("channel", channel), + log_data_string("mode", buf)); } client = &me; @@ -332,7 +329,8 @@ void _do_mode(Channel *channel, Client *client, MessageTag *recv_mtags, int parc { /* Single mode lines are easy: retain original msgid etc */ new_message(client, recv_mtags, &mtags); - } else { + } else + { /* We have a multi-mode line: * This only happens when the input was a single mode line * that got expanded into a multi mode line due to expansion @@ -367,22 +365,22 @@ void _do_mode(Channel *channel, Client *client, MessageTag *recv_mtags, int parc #endif sendto_channel(channel, client, NULL, 0, 0, SEND_LOCAL, mtags, - ":%s MODE %s %s %s", - client->name, channel->name, modebuf, parabuf); + ":%s MODE %s %s %s", + client->name, channel->name, modebuf, parabuf); if (IsServer(client) || IsMe(client)) { sendto_server(client, 0, 0, mtags, - ":%s MODE %s %s %s %lld", - client->id, channel->name, - modebuf, parabuf, - (sendts != -1) ? (long long)sendts : 0LL); + ":%s MODE %s %s %s %lld", + client->id, channel->name, + modebuf, parabuf, + (sendts != -1) ? (long long)sendts : 0LL); } else { sendto_server(client, 0, 0, mtags, - ":%s MODE %s %s %s", - client->id, channel->name, - modebuf, parabuf); + ":%s MODE %s %s %s", + client->id, channel->name, + modebuf, parabuf); } if (MyConnect(client)) @@ -421,7 +419,7 @@ MultiLineMode *make_mode_str(Client *client, Channel *channel, Cmode_t oldem, in curr = 0; m->modeline[curr] = safe_alloc(BUFSIZE); m->paramline[curr] = safe_alloc(BUFSIZE); - m->numlines = curr+1; + m->numlines = curr + 1; what = 0; /* The first element will be filled with all paramless modes. @@ -430,7 +428,7 @@ MultiLineMode *make_mode_str(Client *client, Channel *channel, Cmode_t oldem, in */ /* Which paramless modes got set? Eg +snt */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (!cm->letter || cm->paracount) continue; @@ -448,7 +446,7 @@ MultiLineMode *make_mode_str(Client *client, Channel *channel, Cmode_t oldem, in } /* Which paramless modes got unset? Eg -r */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (!cm->letter || cm->unset_with_param) continue; @@ -482,7 +480,7 @@ MultiLineMode *make_mode_str(Client *client, Channel *channel, Cmode_t oldem, in curr++; m->modeline[curr] = safe_alloc(BUFSIZE); m->paramline[curr] = safe_alloc(BUFSIZE); - m->numlines = curr+1; + m->numlines = curr + 1; what = 0; } if ((*(pvar[cnt]) == '+') && what != MODE_ADD) @@ -570,10 +568,11 @@ const char *mode_ban_handler(Client *client, Channel *channel, const char *param b->banstr = nextbanstr; if (!extban->is_ok(b)) { - if (ValidatePermissionsForPath("channel:override:mode:extban",client,NULL,channel,NULL)) + if (ValidatePermissionsForPath("channel:override:mode:extban", client, NULL, channel, NULL)) { /* TODO: send operoverride notice */ - } else { + } else + { b->banstr = nextbanstr; b->is_ok_check = EXBCHK_ACCESS_ERR; extban->is_ok(b); @@ -593,10 +592,10 @@ const char *mode_ban_handler(Client *client, Channel *channel, const char *param } } - if ( (what == MODE_ADD && (add_listmode(banlist, client, channel, tmpstr) != 1)) || - (what == MODE_DEL && del_listmode(banlist, channel, tmpstr))) + if ((what == MODE_ADD && (add_listmode(banlist, client, channel, tmpstr) != 1)) || + (what == MODE_DEL && del_listmode(banlist, channel, tmpstr))) { - return NULL; /* ban to be added already exists, or ban to be deleted does not exist */ + return NULL; /* ban to be added already exists, or ban to be deleted does not exist */ } return tmpstr; @@ -683,16 +682,17 @@ int do_extmode_char(Channel *channel, Cmode *handler, const char *param, u_int w { x = handler->is_ok(client, channel, mode, param, EXCHK_ACCESS, what); if ((x == EX_ALWAYS_DENY) || - ((x == EX_DENY) && !op_can_override("channel:override:mode:del",client,channel,handler) && !samode_in_progress)) + ((x == EX_DENY) && !op_can_override("channel:override:mode:del", client, channel, handler) && !samode_in_progress)) { handler->is_ok(client, channel, mode, param, EXCHK_ACCESS_ERR, what); return paracnt; /* Denied & error msg sent */ } if ((x == EX_DENY) && !samode_in_progress) opermode = 1; /* override in progress... */ - } else { + } else + { /* remote user: we only need to check if we need to generate an operoverride msg */ - if (!IsULine(client) && IsUser(client) && op_can_override("channel:override:mode:del",client,channel,handler) && + if (!IsULine(client) && IsUser(client) && op_can_override("channel:override:mode:del", client, channel, handler) && (handler->is_ok(client, channel, mode, param, EXCHK_ACCESS, what) != EX_ALLOW)) { opermode = 1; /* override in progress... */ @@ -731,12 +731,14 @@ int do_extmode_char(Channel *channel, Cmode *handler, const char *param, u_int w * Any provided parameter is ok, the current one (that is set) will be used. */ do_mode_char_write(pvar, pcount, what, handler->letter, cm_getparameter(channel, handler->letter)); - } else { + } else + { /* Normal extended channel mode: deleting is just -X, no parameter. * Nothing needs to be done here. */ } - } else { + } else + { /* add: is the parameter ok? */ if (handler->is_ok(client, channel, mode, param, EXCHK_PARAM, what) == FALSE) return paracnt; /* rejected by is_ok */ @@ -761,13 +763,13 @@ int do_extmode_char(Channel *channel, Cmode *handler, const char *param, u_int w } if (what == MODE_ADD) - { /* + */ + { /* + */ channel->mode.mode |= handler->mode; if (handler->paracount) cm_putparameter(channel, handler->letter, param); RunHook(HOOKTYPE_MODECHAR_ADD, channel, (int)mode); } else - { /* - */ + { /* - */ channel->mode.mode &= ~(handler->mode); RunHook(HOOKTYPE_MODECHAR_DEL, channel, (int)mode); if (handler->paracount) @@ -778,7 +780,7 @@ int do_extmode_char(Channel *channel, Cmode *handler, const char *param, u_int w /** Set or unset a mode on a member (eg +vhoaq/-vhoaq) */ void do_mode_char_member_mode_new(Channel *channel, Cmode *handler, const char *param, u_int what, - Client *client, u_int *pcount, char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]) + Client *client, u_int *pcount, char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]) { Member *member = NULL; Membership *membership = NULL; @@ -829,8 +831,7 @@ void do_mode_char_member_mode_new(Channel *channel, Cmode *handler, const char * if (n == EX_DENY) { ret = n; - } else - if (n == EX_ALWAYS_DENY) + } else if (n == EX_ALWAYS_DENY) { ret = n; break; @@ -849,12 +850,13 @@ void do_mode_char_member_mode_new(Channel *channel, Cmode *handler, const char * /* This probably should work but is completely untested (the operoverride stuff, I mean): */ if (ret == EX_DENY) { - if (!op_can_override("channel:override:mode:del",client,channel,handler)) + if (!op_can_override("channel:override:mode:del", client, channel, handler)) { if (badmode) sendto_one(client, NULL, "%s", badmode); /* send error message, if any */ return; /* stop processing this mode */ - } else { + } else + { opermode = 1; } } @@ -866,7 +868,8 @@ void do_mode_char_member_mode_new(Channel *channel, Cmode *handler, const char * return; /* already set */ /* Set the mode */ add_member_mode_fast(member, membership, modechar); - } else { + } else + { if (!strchr(member->member_modes, modechar)) return; /* already unset */ del_member_mode_fast(member, membership, modechar); @@ -949,13 +952,13 @@ int paracount_for_chanmode(u_int what, char mode) } MultiLineMode *_set_mode(Channel *channel, Client *client, int parc, const char *parv[], u_int *pcount, - char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]) + char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]) { Cmode *cm = NULL; MultiLineMode *mlm = NULL; const char *curchr; const char *argument; - char argumentbuf[MODEBUFLEN+1]; + char argumentbuf[MODEBUFLEN + 1]; u_int what = MODE_ADD; long modetype = 0; int paracount = 1; @@ -972,7 +975,7 @@ MultiLineMode *_set_mode(Channel *channel, Client *client, int parc, const char *pcount = 0; oldem = channel->mode.mode; - if (RESTRICT_CHANNELMODES && !ValidatePermissionsForPath("immune:restrict-channelmodes",client,NULL,channel,NULL)) /* "cache" this */ + if (RESTRICT_CHANNELMODES && !ValidatePermissionsForPath("immune:restrict-channelmodes", client, NULL, channel, NULL)) /* "cache" this */ checkrestr = 1; for (curchr = parv[0]; *curchr; curchr++) @@ -989,7 +992,7 @@ MultiLineMode *_set_mode(Channel *channel, Client *client, int parc, const char if (MyUser(client) && channel->mode_lock && strchr(channel->mode_lock, *curchr) != NULL) { if (!IsOper(client) || find_server(SERVICES_NAME, NULL) || - !ValidatePermissionsForPath("channel:override:mlock",client,NULL,channel,NULL)) + !ValidatePermissionsForPath("channel:override:mlock", client, NULL, channel, NULL)) { if (!sent_mlock_warning) { @@ -1013,9 +1016,10 @@ MultiLineMode *_set_mode(Channel *channel, Client *client, int parc, const char if (found == 1) { modetype = foundat.mode; - } else { + } else + { /* Maybe in extmodes */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (cm->letter == *curchr) { @@ -1038,7 +1042,7 @@ MultiLineMode *_set_mode(Channel *channel, Client *client, int parc, const char if (warnrestr) { sendnotice(client, "Setting/removing of channelmode(s) '%s' has been disabled.", - RESTRICT_CHANNELMODES); + RESTRICT_CHANNELMODES); warnrestr = 0; } paracount += paracount_for_chanmode(what, *curchr); @@ -1049,7 +1053,8 @@ MultiLineMode *_set_mode(Channel *channel, Client *client, int parc, const char { strlcpy(argumentbuf, parv[paracount], sizeof(argumentbuf)); argument = argumentbuf; - } else { + } else + { argument = NULL; } @@ -1123,7 +1128,7 @@ CMD_FUNC(_cmd_umode) oldumodes = client->umodes; - if (MyUser(client) && !ValidatePermissionsForPath("immune:restrict-usermodes",client,NULL,NULL,NULL)) + if (MyUser(client) && !ValidatePermissionsForPath("immune:restrict-usermodes", client, NULL, NULL, NULL)) restrict_usermodes = get_setting_for_user_string(client, SET_RESTRICT_USERMODES); if (client->user->snomask) @@ -1139,7 +1144,7 @@ CMD_FUNC(_cmd_umode) if (!umode_restrict_err) { sendnotice(client, "Setting/removing of usermode(s) '%s' has been disabled.", - restrict_usermodes); + restrict_usermodes); umode_restrict_err = 1; } continue; @@ -1167,7 +1172,8 @@ CMD_FUNC(_cmd_umode) if (client->user->snomask == NULL) goto def; break; - } else { + } else + { set_snomask(client, NULL); goto def; } @@ -1204,8 +1210,8 @@ CMD_FUNC(_cmd_umode) /* set::anti-flood::vhost-flood */ if (MyUser(client)) { - if ((what == MODE_DEL) && !ValidatePermissionsForPath("immune:vhost-flood",client,NULL,NULL,NULL) && - flood_limit_exceeded(client, FLD_VHOST)) + if ((what == MODE_DEL) && !ValidatePermissionsForPath("immune:vhost-flood", client, NULL, NULL, NULL) && + flood_limit_exceeded(client, FLD_VHOST)) { /* Throttle... */ if (!modex_err) @@ -1219,35 +1225,35 @@ CMD_FUNC(_cmd_umode) switch (UHOST_ALLOWED) { - case UHALLOW_ALWAYS: - goto def; - case UHALLOW_NEVER: - if (MyUser(client)) - { - if (!modex_err) + case UHALLOW_ALWAYS: + goto def; + case UHALLOW_NEVER: + if (MyUser(client)) { - sendnotice(client, "*** Setting %c%c is disabled", - what == MODE_ADD ? '+' : '-', *m); - modex_err = 1; + if (!modex_err) + { + sendnotice(client, "*** Setting %c%c is disabled", + what == MODE_ADD ? '+' : '-', *m); + modex_err = 1; + } + break; } - break; - } - goto def; - case UHALLOW_NOCHANS: - if (MyUser(client) && client->user->joined) - { - if (!modex_err) + goto def; + case UHALLOW_NOCHANS: + if (MyUser(client) && client->user->joined) { - sendnotice(client, "*** Setting %c%c can not be done while you are on channels", - what == MODE_ADD ? '+' : '-', *m); - modex_err = 1; + if (!modex_err) + { + sendnotice(client, "*** Setting %c%c can not be done while you are on channels", + what == MODE_ADD ? '+' : '-', *m); + modex_err = 1; + } + break; } - break; - } - goto def; - case UHALLOW_REJOIN: - /* Handled later */ - goto def; + goto def; + case UHALLOW_REJOIN: + /* Handled later */ + goto def; } break; default: @@ -1256,7 +1262,7 @@ CMD_FUNC(_cmd_umode) { if (um->letter == *m) { - if (um->allowed && !um->allowed(client,what)) + if (um->allowed && !um->allowed(client, what)) break; if (what == MODE_ADD) client->umodes |= um->mode; @@ -1275,7 +1281,7 @@ CMD_FUNC(_cmd_umode) } /* for */ /* Don't let non-ircops set ircop-only modes or snomasks */ - if (!ValidatePermissionsForPath("self:opermodes",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("self:opermodes", client, NULL, NULL, NULL)) { if ((oldumodes & UMODE_OPER) && IsOper(client)) { @@ -1303,7 +1309,8 @@ CMD_FUNC(_cmd_umode) if (client->user->snomask) { char rerun; - do { + do + { char *p; rerun = 0; @@ -1320,12 +1327,13 @@ CMD_FUNC(_cmd_umode) break; } } - } while(rerun); + } while (rerun); /* And make sure an empty snomask ("") becomes a NULL pointer */ if (client->user->snomask && !*client->user->snomask) remove_all_snomasks(client); } - } else { + } else + { /* User isn't an ircop at all. The solution is simple: */ remove_oper_privileges(client, 0); } @@ -1350,7 +1358,7 @@ CMD_FUNC(_cmd_umode) { if (!dontspread) sendto_server(client, PROTO_VHP, 0, NULL, ":%s SETHOST :%s", - client->name, client->user->virthost); + client->name, client->user->virthost); /* Set the vhost */ safe_strdup(client->user->virthost, client->user->cloakedhost); @@ -1397,11 +1405,11 @@ CMD_FUNC(_cmd_umode) irccounts.operators--; VERIFY_OPERCOUNT(client, "umode1"); } else /* YES this 'else' must be here, otherwise we can decrease twice. fixes opercount bug. */ - if (!(oldumodes & UMODE_HIDEOPER) && IsHideOper(client)) - { - irccounts.operators--; - VERIFY_OPERCOUNT(client, "umode2"); - } + if (!(oldumodes & UMODE_HIDEOPER) && IsHideOper(client)) + { + irccounts.operators--; + VERIFY_OPERCOUNT(client, "umode2"); + } /* end of dealing with opercounts */ if ((oldumodes & UMODE_HIDEOPER) && !IsHideOper(client)) @@ -1437,7 +1445,7 @@ CMD_FUNC(cmd_mlock) if ((parc < 3) || BadPtr(parv[2])) return; - t = (time_t) atol(parv[1]); + t = (time_t)atol(parv[1]); /* Now, try to find the channel in question */ channel = find_channel(parv[2]); @@ -1465,10 +1473,10 @@ void mode_operoverride_msg(Client *client, Channel *channel, char *modebuf, char snprintf(buf, sizeof(buf), "%s %s", modebuf, parabuf); unreal_log(ULOG_INFO, "operoverride", "OPEROVERRIDE_MODE", client, - "OperOverride: $client.details changed channel mode of $channel to: $channel_mode", - log_data_string("override_type", "mode"), - log_data_string("channel_mode", buf), - log_data_channel("channel", channel)); + "OperOverride: $client.details changed channel mode of $channel to: $channel_mode", + log_data_string("override_type", "mode"), + log_data_string("channel_mode", buf), + log_data_channel("channel", channel)); } /* Deal with information requests from local users, such as: @@ -1496,20 +1504,21 @@ int list_mode_request(Client *client, Channel *channel, const char *req) /* First, check access */ if (strchr("beI", *p)) { - if (!IsMember(client, channel) && !ValidatePermissionsForPath("channel:see:mode:remotebanlist",client,NULL,channel,NULL)) + if (!IsMember(client, channel) && !ValidatePermissionsForPath("channel:see:mode:remotebanlist", client, NULL, channel, NULL)) { sendnumeric(client, ERR_NOTONCHANNEL, channel->name); return 1; /* handled */ } - } else { - if (!IsMember(client, channel) && !ValidatePermissionsForPath("channel:see:mode:remoteownerlist",client,NULL,channel,NULL)) + } else + { + if (!IsMember(client, channel) && !ValidatePermissionsForPath("channel:see:mode:remoteownerlist", client, NULL, channel, NULL)) { sendnumeric(client, ERR_NOTONCHANNEL, channel->name); return 1; /* handled */ } } - switch(*p) + switch (*p) { case 'b': for (ban = channel->banlist; ban; ban = ban->next) diff --git a/src/modules/monitor.c b/src/modules/monitor.c index e15b669f2..101c9c96d 100644 --- a/src/modules/monitor.c +++ b/src/modules/monitor.c @@ -22,10 +22,10 @@ #include "unrealircd.h" -#define MSG_MONITOR "MONITOR" +#define MSG_MONITOR "MONITOR" #define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define STR(x) STR_HELPER(x) CMD_FUNC(cmd_monitor); char *monitor_isupport_param(void); @@ -39,19 +39,18 @@ int monitor_notification(Client *client, Watch *watch, Link *lp, int event, void ModDataInfo *watchCounterMD = NULL; ModDataInfo *watchListMD = NULL; -ModuleHeader MOD_HEADER - = { - "monitor", - "5.0", - "command /monitor", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "monitor", + "5.0", + "command /monitor", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() -{ +{ MARK_AS_OFFICIAL_MODULE(modinfo); - + CommandAdd(modinfo->handle, MSG_MONITOR, cmd_monitor, 2, CMD_USER); HookAdd(modinfo->handle, HOOKTYPE_LOCAL_NICKCHANGE, 0, monitor_nickchange); HookAdd(modinfo->handle, HOOKTYPE_REMOTE_NICKCHANGE, 0, monitor_nickchange); @@ -132,7 +131,7 @@ int monitor_notification(Client *client, Watch *watch, Link *lp, int event, void default: break; /* may be handled by other modules */ } - + return 0; } @@ -142,16 +141,18 @@ void send_status(Client *client, MessageTag *recv_mtags, const char *nick) Client *user; user = find_user(nick, NULL); new_message(client, recv_mtags, &mtags); - if (!user){ + if (!user) + { sendnumeric(client, RPL_MONOFFLINE, nick); - } else { + } else + { sendnumeric(client, RPL_MONONLINE, user->name, user->user->username, GetHost(user)); } free_message_tags(mtags); } #define WATCHES(client) (moddata_local_client(client, watchCounterMD).i) -#define WATCH(client) (moddata_local_client(client, watchListMD).ptr) +#define WATCH(client) (moddata_local_client(client, watchListMD).ptr) CMD_FUNC(cmd_monitor) { @@ -177,8 +178,8 @@ CMD_FUNC(cmd_monitor) sendnotice(client, "MONITOR command is not available at this moment. Please try again later."); return; } - - switch(cmd) + + switch (cmd) { case 'c': watch_del_list(client, WATCH_FLAG_TYPE_MONITOR); @@ -218,9 +219,11 @@ CMD_FUNC(cmd_monitor) strlcpy(request, parv[2], sizeof(request)); for (s = strtoken(&p, request, ","); s; s = strtoken(&p, NULL, ",")) { - if (cmd == '-') { + if (cmd == '-') + { watch_del(s, client, WATCH_FLAG_TYPE_MONITOR); - } else { + } else + { if (WATCHES(client) >= MAXWATCH) { sendnumeric(client, ERR_MONLISTFULL, MAXWATCH, s); @@ -234,4 +237,3 @@ CMD_FUNC(cmd_monitor) break; } } - diff --git a/src/modules/motd.c b/src/modules/motd.c index 6a777100c..68833048e 100644 --- a/src/modules/motd.c +++ b/src/modules/motd.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_motd); -#define MSG_MOTD "MOTD" +#define MSG_MOTD "MOTD" -ModuleHeader MOD_HEADER - = { - "motd", - "5.0", - "command /motd", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "motd", + "5.0", + "command /motd", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_MOTD, cmd_motd, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_MOTD, cmd_motd, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -61,7 +60,7 @@ CMD_FUNC(cmd_motd) ConfigItem_tld *tld; MOTDFile *themotd; MOTDLine *motdline; - int svsnofile = 0; + int svsnofile = 0; if (IsServer(client)) return; @@ -93,11 +92,11 @@ CMD_FUNC(cmd_motd) if (themotd && themotd->lines && themotd->last_modified.tm_year) { sendnumericfmt(client, RPL_MOTD, ":- %.04d-%.02d-%.02d %.02d:%02d", - themotd->last_modified.tm_year + 1900, - themotd->last_modified.tm_mon + 1, - themotd->last_modified.tm_mday, - themotd->last_modified.tm_hour, - themotd->last_modified.tm_min); + themotd->last_modified.tm_year + 1900, + themotd->last_modified.tm_mon + 1, + themotd->last_modified.tm_mday, + themotd->last_modified.tm_hour, + themotd->last_modified.tm_min); } motdline = NULL; @@ -106,16 +105,16 @@ CMD_FUNC(cmd_motd) while (motdline) { sendnumeric(client, RPL_MOTD, - motdline->line); + motdline->line); motdline = motdline->next; } - svsmotd: +svsmotd: motdline = svsmotd.lines; while (motdline) { sendnumeric(client, RPL_MOTD, - motdline->line); + motdline->line); motdline = motdline->next; } diff --git a/src/modules/multiline.c b/src/modules/multiline.c index 0ceee5443..0703a4e3b 100644 --- a/src/modules/multiline.c +++ b/src/modules/multiline.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "multiline", - "1.0", - "IRCv3 draft/multiline", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "multiline", + "1.0", + "IRCv3 draft/multiline", + "UnrealIRCd Team", + "unrealircd-6", +}; /* ===================== CONFIGURATION ===================== */ @@ -42,18 +41,18 @@ struct { /** State for a locally-initiated multiline batch (one per local client) */ typedef struct MultilineBatch MultilineBatch; struct MultilineBatch { - char batch_id[MAXBATCHREFLEN+1]; /**< Client-chosen batch reference tag */ - char *target; /**< Target channel or nick */ - SendType sendtype; /**< SEND_TYPE_PRIVMSG or SEND_TYPE_NOTICE */ - int sendtype_set; /**< Has sendtype been determined (from first line)? */ - char member_modes[2]; /**< Member mode filter from STATUSMSG prefix (e.g. "o"), or empty string */ - MessageTag *client_mtags; /**< Tags from the opening BATCH command */ + char batch_id[MAXBATCHREFLEN + 1]; /**< Client-chosen batch reference tag */ + char *target; /**< Target channel or nick */ + SendType sendtype; /**< SEND_TYPE_PRIVMSG or SEND_TYPE_NOTICE */ + int sendtype_set; /**< Has sendtype been determined (from first line)? */ + char member_modes[2]; /**< Member mode filter from STATUSMSG prefix (e.g. "o"), or empty string */ + MessageTag *client_mtags; /**< Tags from the opening BATCH command */ int line_count; - int received_bytes; /**< Total user-sent content bytes (for max-bytes policy) */ + int received_bytes; /**< Total user-sent content bytes (for max-bytes policy) */ time_t start_time; - int failed; /**< Batch marked as failed — consume remaining lines, send error at BATCH close */ - char *fail_message; /**< FAIL response to send at BATCH close (if failed) */ - char label[256]; /**< Saved label for echo-message + labeled-response interaction */ + int failed; /**< Batch marked as failed — consume remaining lines, send error at BATCH close */ + char *fail_message; /**< FAIL response to send at BATCH close (if failed) */ + char label[256]; /**< Saved label for echo-message + labeled-response interaction */ /* Buffered lines */ MLine *lines; MLine *lines_tail; @@ -63,15 +62,15 @@ struct MultilineBatch { typedef struct S2SMultilineBatch S2SMultilineBatch; struct S2SMultilineBatch { S2SMultilineBatch *prev, *next; - Client *sender; /**< Remote user who initiated */ - Client *direction; /**< Server link it came from */ - char batch_id[BATCHLEN+1]; + Client *sender; /**< Remote user who initiated */ + Client *direction; /**< Server link it came from */ + char batch_id[BATCHLEN + 1]; char *target; - int is_channel; /**< 1 if target is a channel, 0 if user */ + int is_channel; /**< 1 if target is a channel, 0 if user */ SendType sendtype; int sendtype_set; - char member_modes[2]; /**< Member mode filter from STATUSMSG prefix */ - MessageTag *first_mtags; /**< Message tags from the opening BATCH (for relay) */ + char member_modes[2]; /**< Member mode filter from STATUSMSG prefix */ + MessageTag *first_mtags; /**< Message tags from the opening BATCH (for relay) */ int line_count; int received_bytes; time_t start_time; @@ -230,8 +229,8 @@ const char *multiline_capability_parameter(Client *client) FloodSettings *f = get_floodsettings_for_user(client, FLD_MULTILINE); snprintf(buf, sizeof(buf), "max-bytes=%d,max-lines=%d", - (int)f->period[FLD_MULTILINE], - (int)f->limit[FLD_MULTILINE]); + (int)f->period[FLD_MULTILINE], + (int)f->limit[FLD_MULTILINE]); return buf; } @@ -251,10 +250,11 @@ int multiline_known_user_cache_change(Client *client) { const char *args = multiline_capability_parameter(client); sendto_one(client, NULL, ":%s CAP %s NEW :draft/multiline=%s", - me.name, (*client->name ? client->name : "*"), args); - } else { + me.name, (*client->name ? client->name : "*"), args); + } else + { sendto_one(client, NULL, ":%s CAP %s NEW :draft/multiline", - me.name, (*client->name ? client->name : "*")); + me.name, (*client->name ? client->name : "*")); } return HOOK_CONTINUE; @@ -399,16 +399,16 @@ static void multiline_run_chanmsg_hooks(Client *sender, Channel *channel, for (line = lines; line; line = line->next) { RunHook(HOOKTYPE_CHANMSG, sender, channel, sendflags, - member_modes, targetstr, - (line == lines) ? mtags : NULL, - line->text, sendtype); + member_modes, targetstr, + (line == lines) ? mtags : NULL, + line->text, sendtype); } history_inhibit = 0; echo_message_inhibit = 0; /* Fire multiline hook for atomic history storage etc. */ RunHook(HOOKTYPE_CHANMSG_MULTILINE, sender, channel, sendflags, - member_modes, targetstr, mtags, lines, sendtype); + member_modes, targetstr, mtags, lines, sendtype); } /** Run HOOKTYPE_USERMSG per-line for a multiline batch. @@ -424,8 +424,8 @@ static void multiline_run_usermsg_hooks(Client *sender, Client *target, for (line = lines; line; line = line->next) { RunHook(HOOKTYPE_USERMSG, sender, target, - (line == lines) ? mtags : NULL, - line->text, sendtype); + (line == lines) ? mtags : NULL, + line->text, sendtype); } history_inhibit = 0; echo_message_inhibit = 0; @@ -743,7 +743,8 @@ CMD_OVERRIDE_FUNC(multiline_override_batch) /* Store member mode */ batch->member_modes[0] = prefix_to_mode(prefix); batch->member_modes[1] = '\0'; - } else { + } else + { safe_strdup(batch->target, target); batch->member_modes[0] = '\0'; } @@ -935,7 +936,8 @@ CMD_OVERRIDE_FUNC(multiline_override_msg) { batch->sendtype = sendtype; batch->sendtype_set = 1; - } else if (batch->sendtype != sendtype) { + } else if (batch->sendtype != sendtype) + { char buf[512]; snprintf(buf, sizeof(buf), "FAIL BATCH MULTILINE_INVALID :Cannot mix PRIVMSG and NOTICE in a multiline batch"); multiline_fail_batch(client, batch, buf); @@ -1053,11 +1055,13 @@ static void multiline_deliver(Client *client, MultilineBatch *batch) if (channel) { multiline_deliver_channel(client, batch, channel); - } else if (strchr(batch->target, '#')) { + } else if (strchr(batch->target, '#')) + { /* Target had a '#' but channel not found (parted/destroyed during batch) */ sendnumeric(client, ERR_NOSUCHNICK, batch->target); return; - } else { + } else + { target = hash_find_nickatserver(batch->target, NULL); if (!target) { @@ -1175,7 +1179,7 @@ static void multiline_deliver_channel(Client *client, MultilineBatch *batch, Cha /* Deliver to local channel members */ multiline_deliver_to_local_members(channel, client, batch, mtags, - batch->target, cmd, filter_modes, client, sendflags); + batch->target, cmd, filter_modes, client, sendflags); /* Echo-message for sender */ multiline_echo_to_sender(client, batch, mtags, batch->target, cmd); @@ -1184,8 +1188,8 @@ static void multiline_deliver_channel(Client *client, MultilineBatch *batch, Cha multiline_send_s2s_channel(client, batch, channel, mtags, cmd, client->direction, batch->target); multiline_run_chanmsg_hooks(client, channel, sendflags, - batch->member_modes[0] ? batch->member_modes : NULL, - batch->target, mtags, batch->lines, batch->sendtype); + batch->member_modes[0] ? batch->member_modes : NULL, + batch->target, mtags, batch->lines, batch->sendtype); free_message_tags(mtags); } @@ -1260,10 +1264,12 @@ static void multiline_deliver_user(Client *client, MultilineBatch *batch, Client if (HasMultiline(target)) { multiline_send_batch_to_client(target, client, batch, mtags, target->name, cmd); - } else { + } else + { multiline_send_fallback_to_client(target, client, batch, mtags, target->name, cmd); } - } else { + } else + { /* Target is remote - relay as S2S batch */ multiline_send_s2s_user(client, batch, target, mtags, cmd); } @@ -1301,7 +1307,8 @@ static void multiline_echo_to_sender(Client *client, MultilineBatch *batch, if (HasMultiline(client)) { multiline_send_batch_to_client(client, client, batch, echo_mtags, targetstr, cmd); - } else { + } else + { multiline_send_fallback_to_client(client, client, batch, echo_mtags, targetstr, cmd); } @@ -1319,7 +1326,7 @@ static void multiline_echo_to_sender(Client *client, MultilineBatch *batch, static void multiline_send_batch_to_client(Client *to, Client *from, MultilineBatch *batch, MessageTag *base_mtags, const char *targetstr, const char *cmd) { - char server_batch_id[BATCHLEN+1]; + char server_batch_id[BATCHLEN + 1]; MLine *l; MessageTag *m; @@ -1396,7 +1403,8 @@ static void multiline_send_fallback_to_client(Client *to, Client *from, Multilin ":%s %s %s :%s", from->name, cmd, targetstr, l->text); first = 0; - } else { + } else + { /* Subsequent lines get all tags except msgid */ sendto_prefix_one(to, from, rest_mtags, ":%s %s %s :%s", @@ -1428,7 +1436,7 @@ static void multiline_deliver_to_local_members(Channel *channel, Client *from, LineCache *cache_batch_close; // cache for "BATCH -id" LineCache **cache_lines = NULL; // one cache per multiline content line LineCache **cache_fb = NULL; // one cache per non-blank fallback line - char server_batch_id[BATCHLEN+1]; // shared across all multiline recipients + char server_batch_id[BATCHLEN + 1]; // shared across all multiline recipients int i; int fallback_count = 0; // number of non-blank fallback lines int first; // tracks first non-blank line in fallback pass @@ -1581,7 +1589,8 @@ static void multiline_send_s2s_to_direction(Client *direction, Client *from, /* First line carries all base_mtags (msgid, time, etc.) */ line_mtags = duplicate_mtags(base_mtags); first = 0; - } else { + } else + { /* Subsequent lines carry base_mtags minus msgid */ line_mtags = duplicate_mtags_for_subsequent_lines(base_mtags); } @@ -1613,7 +1622,7 @@ static void multiline_send_s2s_to_direction(Client *direction, Client *from, static void multiline_send_s2s_channel(Client *from, MultilineBatch *batch, Channel *channel, MessageTag *base_mtags, const char *cmd, Client *skip_direction, const char *targetstr) { - char ref[BATCHLEN+1]; + char ref[BATCHLEN + 1]; Member *lp; Client *acptr; char expanded_modes[64]; @@ -1674,7 +1683,7 @@ static void multiline_send_s2s_channel(Client *from, MultilineBatch *batch, Chan static void multiline_send_s2s_user(Client *from, MultilineBatch *batch, Client *target, MessageTag *base_mtags, const char *cmd) { - char ref[BATCHLEN+1]; + char ref[BATCHLEN + 1]; generate_batch_id(ref); multiline_send_s2s_to_direction(target->direction, from, batch, base_mtags, cmd, target->id, ref); @@ -1803,7 +1812,8 @@ static void multiline_handle_s2s_msg(Client *client, MessageTag *recv_mtags, { s2s->sendtype = sendtype; s2s->sendtype_set = 1; - } else if (s2s->sendtype != sendtype) { + } else if (s2s->sendtype != sendtype) + { /* Mismatch - discard batch */ multiline_free_s2s_batch(s2s); return; @@ -1902,16 +1912,17 @@ static void multiline_deliver_s2s_batch(S2SMultilineBatch *s2s) /* Deliver to local members */ multiline_deliver_to_local_members(channel, s2s->sender, batch, mtags, - s2s->target, cmd, filter_modes, NULL, 0); + s2s->target, cmd, filter_modes, NULL, 0); /* Relay to further server directions (excluding where it came from) */ multiline_send_s2s_channel(s2s->sender, batch, channel, mtags, cmd, s2s->direction, s2s->target); multiline_run_chanmsg_hooks(s2s->sender, channel, SEND_ALL, - s2s->member_modes[0] ? s2s->member_modes : NULL, - s2s->target, mtags, s2s->lines, s2s->sendtype); + s2s->member_modes[0] ? s2s->member_modes : NULL, + s2s->target, mtags, s2s->lines, s2s->sendtype); } - } else { + } else + { /* User-to-user */ Client *target = find_client(s2s->target, NULL); @@ -1925,7 +1936,8 @@ static void multiline_deliver_s2s_batch(S2SMultilineBatch *s2s) multiline_send_batch_to_client(target, s2s->sender, batch, mtags, target->name, cmd); else multiline_send_fallback_to_client(target, s2s->sender, batch, mtags, target->name, cmd); - } else { + } else + { /* Relay further */ multiline_send_s2s_user(s2s->sender, batch, target, mtags, cmd); } diff --git a/src/modules/names.c b/src/modules/names.c index e16877571..2126c701a 100644 --- a/src/modules/names.c +++ b/src/modules/names.c @@ -27,16 +27,15 @@ CMD_FUNC(cmd_names); long CAP_MULTI_PREFIX = 0L; long CAP_USERHOST_IN_NAMES = 0L; -#define MSG_NAMES "NAMES" +#define MSG_NAMES "NAMES" -ModuleHeader MOD_HEADER - = { - "names", - "5.0", - "command /names", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "names", + "5.0", + "command /names", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -48,7 +47,7 @@ MOD_INIT() c.name = "userhost-in-names"; ClientCapabilityAdd(modinfo->handle, &c, &CAP_USERHOST_IN_NAMES); - CommandAdd(modinfo->handle, MSG_NAMES, cmd_names, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_NAMES, cmd_names, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -85,7 +84,7 @@ CMD_FUNC(cmd_names) Member *cm; int idx, flag = 1, spos; const char *para = parv[1], *s; - char nuhBuffer[NICKLEN+USERLEN+HOSTLEN+3]; + char nuhBuffer[NICKLEN + USERLEN + HOSTLEN + 3]; char buf[BUFSIZE]; char can_see_invisible; @@ -99,14 +98,14 @@ CMD_FUNC(cmd_names) { if (*s == ',') { - sendnumeric(client, ERR_TOOMANYTARGETS, s+1, 1, "NAMES"); + sendnumeric(client, ERR_TOOMANYTARGETS, s + 1, 1, "NAMES"); return; } } channel = find_channel(para); - if (!channel || (!ShowChannel(client, channel) && !ValidatePermissionsForPath("channel:see:names:secret",client,NULL,channel,NULL))) + if (!channel || (!ShowChannel(client, channel) && !ValidatePermissionsForPath("channel:see:names:secret", client, NULL, channel, NULL))) { sendnumeric(client, RPL_ENDOFNAMES, para); return; @@ -137,9 +136,9 @@ CMD_FUNC(cmd_names) LAST /names call get stuck in there.. - lucas */ buf[idx] = '\0'; - spos = idx; /* starting point in buffer for names! */ + spos = idx; /* starting point in buffer for names! */ - can_see_invisible = ValidatePermissionsForPath("channel:see:names:invisible",client,NULL,channel,NULL); + can_see_invisible = ValidatePermissionsForPath("channel:see:names:invisible", client, NULL, channel, NULL); for (cm = channel->members; cm; cm = cm->next) { @@ -156,18 +155,21 @@ CMD_FUNC(cmd_names) char c = mode_to_prefix(*cm->member_modes); if (c) buf[idx++] = c; - } else { + } else + { /* NAMES reply with all rights included (multi-prefix / NAMESX) */ strcpy(&buf[idx], modes_to_prefix(cm->member_modes)); idx += strlen(&buf[idx]); } - if (!uhnames) { + if (!uhnames) + { s = acptr->name; - } else { + } else + { strlcpy(nuhBuffer, make_nick_user_host(acptr->name, acptr->user->username, GetHost(acptr)), - bufLen + 1); + bufLen + 1); s = nuhBuffer; } /* 's' is intialized above to point to either acptr->name (normal), diff --git a/src/modules/netinfo.c b/src/modules/netinfo.c index 9cbd17dac..ef5b8af2e 100644 --- a/src/modules/netinfo.c +++ b/src/modules/netinfo.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_netinfo); -#define MSG_NETINFO "NETINFO" +#define MSG_NETINFO "NETINFO" -ModuleHeader MOD_HEADER - = { - "netinfo", - "5.0", - "command /netinfo", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "netinfo", + "5.0", + "command /netinfo", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -69,9 +68,9 @@ MOD_UNLOAD() */ CMD_FUNC(cmd_netinfo) { - long lmax; - long endsync, protocol; - char buf[512]; + long lmax; + long endsync, protocol; + char buf[512]; if (parc < 9) return; diff --git a/src/modules/nick.c b/src/modules/nick.c index 54b9e222b..b53c44593 100644 --- a/src/modules/nick.c +++ b/src/modules/nick.c @@ -22,20 +22,19 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "nick", - "5.0", - "command /nick", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "nick", + "5.0", + "command /nick", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Defines */ -#define NICKCOL_EQUAL 0 -#define NICKCOL_NEW_WON 1 -#define NICKCOL_EXISTING_WON 2 +#define NICKCOL_EQUAL 0 +#define NICKCOL_NEW_WON 1 +#define NICKCOL_EXISTING_WON 2 /* Assume that on collision a NICK is in flight and the other server will take * the exact same decision we would do, and thus we don't send a KILL to cptr? @@ -69,7 +68,7 @@ MOD_INIT() { MARK_AS_OFFICIAL_MODULE(modinfo); - CommandAdd(modinfo->handle, "NICK", cmd_nick, MAXPARA, CMD_USER|CMD_SERVER|CMD_UNREGISTERED); + CommandAdd(modinfo->handle, "NICK", cmd_nick, MAXPARA, CMD_USER | CMD_SERVER | CMD_UNREGISTERED); CommandAdd(modinfo->handle, "UID", cmd_uid, MAXPARA, CMD_SERVER); return MOD_SUCCESS; @@ -167,11 +166,11 @@ CMD_FUNC(cmd_nick_remote) if (!IsULine(client) && (tklban = find_qline(client, nick, &ishold)) && !ishold) { unreal_log(ULOG_INFO, "nick", "QLINE_NICK_REMOTE", client, - "Banned nick $nick used by $client.details, allowed through by server $server ($reason)", - log_data_string("nick", parv[1]), - log_data_string("ip", GetIP(client)), - log_data_client("server", client->uplink), - log_data_string("reason", tklban->ptr.nameban->reason)); + "Banned nick $nick used by $client.details, allowed through by server $server ($reason)", + log_data_string("nick", parv[1]), + log_data_string("ip", GetIP(client)), + log_data_client("server", client->uplink), + log_data_string("reason", tklban->ptr.nameban->reason)); /* Let it through */ } @@ -182,8 +181,7 @@ CMD_FUNC(cmd_nick_remote) { SetKilled(acptr); exit_client(acptr, NULL, "Overridden"); - } else - if (acptr == client) + } else if (acptr == client) { /* 100% identical? Must be a bug, but ok */ if (!strcmp(acptr->name, nick)) @@ -202,21 +200,19 @@ CMD_FUNC(cmd_nick_remote) { nick_collision(client, parv[1], client->id, client, acptr, NICKCOL_EQUAL); return; /* Now that I killed them both, ignore the NICK */ - } else - if ((differ && (acptr->lastnick > lastnick)) || - (!differ && (acptr->lastnick < lastnick))) + } else if ((differ && (acptr->lastnick > lastnick)) || + (!differ && (acptr->lastnick < lastnick))) { nick_collision(client, parv[1], client->id, client, acptr, NICKCOL_NEW_WON); /* fallthrough: their user won, continue and proceed with the nick change */ - } else - if ((differ && (acptr->lastnick < lastnick)) || - (!differ && (acptr->lastnick > lastnick))) + } else if ((differ && (acptr->lastnick < lastnick)) || + (!differ && (acptr->lastnick > lastnick))) { nick_collision(client, parv[1], client->id, client, acptr, NICKCOL_EXISTING_WON); return; /* their user lost, ignore the NICK */ } else { - return; /* just in case */ + return; /* just in case */ } } } @@ -235,7 +231,7 @@ CMD_FUNC(cmd_nick_remote) client->lastnick = lastnick ? lastnick : TStime(); add_history(client, 1, WHOWAS_EVENT_NICK_CHANGE); sendto_server(client, 0, 0, mtags, ":%s NICK %s %lld", - client->id, nick, (long long)client->lastnick); + client->id, nick, (long long)client->lastnick); sendto_local_common_channels(client, client, 0, mtags, ":%s NICK :%s", client->name, nick); if (removemoder) client->umodes &= ~UMODE_REGNICK; @@ -312,23 +308,23 @@ CMD_FUNC(cmd_nick_local) sendnumeric(client, ERR_ERRONEUSNICKNAME, nick, tklban->ptr.nameban->reason); return; } - if (!ValidatePermissionsForPath("immune:server-ban:ban-nick",client,NULL,NULL,nick)) + if (!ValidatePermissionsForPath("immune:server-ban:ban-nick", client, NULL, NULL, nick)) { tkl_hit(client, tklban); add_fake_lag(client, 4000); /* lag them up */ sendnumeric(client, ERR_ERRONEUSNICKNAME, nick, tklban->ptr.nameban->reason); unreal_log(ULOG_INFO, "nick", "QLINE_NICK_LOCAL_ATTEMPT", client, - "Attempt to use banned nick $nick by $client.details blocked ($reason)", - log_data_string("nick", parv[1]), - log_data_string("ip", GetIP(client)), - log_data_client("server", client->uplink), - log_data_string("reason", tklban->ptr.nameban->reason)); - return; /* NICK message ignored */ + "Attempt to use banned nick $nick by $client.details blocked ($reason)", + log_data_string("nick", parv[1]), + log_data_string("ip", GetIP(client)), + log_data_client("server", client->uplink), + log_data_string("reason", tklban->ptr.nameban->reason)); + return; /* NICK message ignored */ } /* fallthrough for ircops that have sufficient privileges */ } - if (!ValidatePermissionsForPath("immune:nick-flood",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("immune:nick-flood", client, NULL, NULL, NULL)) add_fake_lag(client, 3000); if ((acptr = find_client(nick, NULL))) @@ -347,22 +343,22 @@ CMD_FUNC(cmd_nick_local) /* Changing cAsE */ removemoder = 0; } else - /* Collision with a nick of a session that is still in handshake */ - if (IsUnknown(acptr) && MyConnect(acptr)) - { - /* Kill the other connection that is still in progress */ - SetKilled(acptr); - exit_client(acptr, NULL, "Overridden"); - } else - { - sendnumeric(client, ERR_NICKNAMEINUSE, nick); - return; /* NICK message ignored */ - } + /* Collision with a nick of a session that is still in handshake */ + if (IsUnknown(acptr) && MyConnect(acptr)) + { + /* Kill the other connection that is still in progress */ + SetKilled(acptr); + exit_client(acptr, NULL, "Overridden"); + } else + { + sendnumeric(client, ERR_NICKNAMEINUSE, nick); + return; /* NICK message ignored */ + } } /* set::anti-flood::nick-flood */ if (client->user && - !ValidatePermissionsForPath("immune:nick-flood",client,NULL,NULL,NULL) && + !ValidatePermissionsForPath("immune:nick-flood", client, NULL, NULL, NULL) && flood_limit_exceeded(client, FLD_NICK)) { /* Throttle... */ @@ -409,13 +405,13 @@ CMD_FUNC(cmd_nick_local) /* ..otherwise.. fallthrough so we run the same code * as in case of !is_handshake_finished() */ - } else { + } else + { /* New user! */ strlcpy(nick, client->name, sizeof(nick)); /* don't ask, but I need this. do not remove! -- Syzop */ } } - } else - if (MyUser(client)) + } else if (MyUser(client)) { MessageTag *mtags = NULL; int ret; @@ -436,7 +432,7 @@ CMD_FUNC(cmd_nick_local) if (!check_channel_access(client, mp->channel, "hoaq") && is_banned(client, mp->channel, BANCHK_NICK, NULL, NULL)) { sendnumeric(client, ERR_BANNICKCHANGE, - mp->channel->name); + mp->channel->name); return; } if (CHECK_TARGET_NICK_BANS && !check_channel_access(client, mp->channel, "hoaq") && is_banned_with_nick(client, mp->channel, BANCHK_NICK, nick, NULL, NULL)) @@ -447,7 +443,7 @@ CMD_FUNC(cmd_nick_local) for (h = Hooks[HOOKTYPE_CHAN_PERMIT_NICK_CHANGE]; h; h = h->next) { - ret = (*(h->func.intfunc))(client,mp->channel); + ret = (*(h->func.intfunc))(client, mp->channel); if (ret != HOOK_CONTINUE) break; } @@ -468,7 +464,7 @@ CMD_FUNC(cmd_nick_local) add_history(client, 1, WHOWAS_EVENT_NICK_CHANGE); client->lastnick = TStime(); /* needs to be done AFTER add_history() */ sendto_server(client, 0, 0, mtags, ":%s NICK %s %lld", - client->id, nick, (long long)client->lastnick); + client->id, nick, (long long)client->lastnick); sendto_local_common_channels(client, client, 0, mtags, ":%s NICK :%s", client->name, nick); sendto_one(client, mtags, ":%s NICK :%s", client->name, nick); free_message_tags(mtags); @@ -608,9 +604,9 @@ CMD_FUNC(cmd_uid) { ircstats.is_kill++; unreal_log(ULOG_ERROR, "link", "BAD_IP", client, - "Server link $client ($client.id) introduced user $nick with bad IP: $bad_ip.", - log_data_string("nick", nick), - log_data_string("bad_ip", ip_raw)); + "Server link $client ($client.id) introduced user $nick with bad IP: $bad_ip.", + log_data_string("nick", nick), + log_data_string("bad_ip", ip_raw)); /* Send kill to uplink only, hasn't been broadcasted to the rest, anyway */ sendto_one(client, NULL, ":%s KILL %s :Bad IP in UID command", me.id, parv[6]); return; @@ -633,11 +629,11 @@ CMD_FUNC(cmd_uid) if (!IsULine(client) && (tklban = find_qline(client, nick, &ishold))) { unreal_log(ULOG_INFO, "nick", "QLINE_NICK_REMOTE", client, - "Banned nick $nick [$nick.ip] from server $server ($reason)", - log_data_string("nick", parv[1]), - log_data_string("ip", ip), - log_data_client("server", client->uplink), - log_data_string("reason", tklban->ptr.nameban->reason)); + "Banned nick $nick [$nick.ip] from server $server ($reason)", + log_data_string("nick", parv[1]), + log_data_string("ip", ip), + log_data_client("server", client->uplink), + log_data_string("reason", tklban->ptr.nameban->reason)); /* Let it through */ } @@ -660,11 +656,11 @@ CMD_FUNC(cmd_uid) if (acptr->lastnick == lastnick) { nick_collision(client, parv[1], parv[6], NULL, acptr, NICKCOL_EQUAL); - return; /* We killed both users, now stop the process. */ + return; /* We killed both users, now stop the process. */ } if ((differ && (acptr->lastnick > lastnick)) || - (!differ && (acptr->lastnick < lastnick)) || acptr->direction == client->direction) /* we missed a QUIT somewhere ? */ + (!differ && (acptr->lastnick < lastnick)) || acptr->direction == client->direction) /* we missed a QUIT somewhere ? */ { nick_collision(client, parv[1], parv[6], NULL, acptr, NICKCOL_NEW_WON); /* We got rid of the "wrong" user. Introduce the correct one. */ @@ -675,7 +671,7 @@ CMD_FUNC(cmd_uid) if ((differ && (acptr->lastnick < lastnick)) || (!differ && (acptr->lastnick > lastnick))) { nick_collision(client, parv[1], parv[6], NULL, acptr, NICKCOL_EXISTING_WON); - return; /* Ignore the NICK */ + return; /* Ignore the NICK */ } return; /* just in case */ } @@ -689,7 +685,7 @@ nickkill2done: add_client_to_list(client); add_to_id_hash_table(client->id, client); client->lastnick = atol(parv[3]); - strlcpy(client->name, nick, NICKLEN+1); + strlcpy(client->name, nick, NICKLEN + 1); add_to_client_hash_table(nick, client); make_user(client); @@ -706,8 +702,8 @@ nickkill2done: * the call to decode_ip() about 100 lines up. */ unreal_log(ULOG_ERROR, "nick", "REMOTE_CLIENT_IP_BUG", client, - "[BUG] client $client has invalid ip $ip -- rejected", - log_data_string("ip", ip)); + "[BUG] client $client has invalid ip $ip -- rejected", + log_data_string("ip", ip)); #ifdef DEBUGMODE abort(); #endif @@ -745,7 +741,7 @@ nickkill2done: if (*virthost != '*') safe_strdup(client->user->virthost, virthost); - build_umode_string(client, 0, SEND_UMODES|UMODE_SERVNOTICE, buf); + build_umode_string(client, 0, SEND_UMODES | UMODE_SERVNOTICE, buf); sendto_serv_butone_nickcmd(client->direction, recv_mtags, client, (*buf == '\0' ? "+" : buf)); @@ -766,8 +762,8 @@ nickkill2done: if (!IsULine(serv) && IsSynched(serv)) { unreal_log(ULOG_INFO, "connect", "REMOTE_CLIENT_CONNECT", client, - "Client connecting: $client ($client.user.username@$client.hostname) [$client.ip] $extended_client_info", - log_data_string("extended_client_info", get_connect_extinfo(client)), + "Client connecting: $client ($client.user.username@$client.hostname) [$client.ip] $extended_client_info", + log_data_string("extended_client_info", get_connect_extinfo(client)), log_data_string("from_server_name", client->user->server)); } } @@ -790,8 +786,7 @@ CMD_FUNC(cmd_nick) if (MyConnect(client) && !IsServer(client)) { CALL_CMD_FUNC(cmd_nick_local); - } else - if (!IsUser(client)) + } else if (!IsUser(client)) { unreal_log(ULOG_ERROR, "link", "LINK_OLD_PROTOCOL_NICK", client->direction, "Server link $client tried to introduce $nick using NICK command. " @@ -852,7 +847,7 @@ void welcome_user(Client *client, TKL *viruschan_tkl) if (client->local->ssl && !iConf.no_connect_tls_info) { sendnotice(client, "*** You are connected to %s with %s", - me.name, tls_get_cipher(client)); + me.name, tls_get_cipher(client)); } } @@ -873,15 +868,15 @@ void welcome_user(Client *client, TKL *viruschan_tkl) #ifdef EXPERIMENTAL sendnotice(client, - "*** \2NOTE:\2 This server is running experimental IRC server software (UnrealIRCd %s). " - "If you find any bugs or problems, please report them at https://bugs.unrealircd.org/", - VERSIONONLY); + "*** \2NOTE:\2 This server is running experimental IRC server software (UnrealIRCd %s). " + "If you find any bugs or problems, please report them at https://bugs.unrealircd.org/", + VERSIONONLY); #endif if (client->umodes & UMODE_INVISIBLE) irccounts.invisible++; - build_umode_string(client, 0, SEND_UMODES|UMODE_SERVNOTICE, buf); + build_umode_string(client, 0, SEND_UMODES | UMODE_SERVNOTICE, buf); sendto_serv_butone_nickcmd(client->direction, NULL, client, (*buf == '\0' ? "+" : buf)); @@ -889,7 +884,7 @@ void welcome_user(Client *client, TKL *viruschan_tkl) if (buf[0] != '\0' && buf[1] != '\0') sendto_one(client, NULL, ":%s MODE %s :%s", client->name, - client->name, buf); + client->name, buf); if (client->user->snomask) sendnumeric(client, RPL_SNOMASK, client->user->snomask); @@ -926,22 +921,21 @@ void welcome_user(Client *client, TKL *viruschan_tkl) { char *chans = strdup(tld->channel); const char *args[3] = { - NULL, - chans, - NULL, + NULL, + chans, + NULL, }; do_cmd(client, NULL, "JOIN", 3, args); safe_free(chans); if (IsDead(client)) return; - } - else if ((chans = (char *)get_setting_for_user_string(client, SET_AUTO_JOIN)) && strcmp(chans, "0")) + } else if ((chans = (char *)get_setting_for_user_string(client, SET_AUTO_JOIN)) && strcmp(chans, "0")) { chans = strdup(chans); // work on a copy (wait, is this still needed? we have a const guarantee now right?) const char *args[3] = { - NULL, - chans, - NULL, + NULL, + chans, + NULL, }; do_cmd(client, NULL, "JOIN", 3, args); safe_free(chans); @@ -982,7 +976,7 @@ int make_valid_username(Client *client, int noident) if (*stripuser == '\0') return 0; /* Zero valid characters, reject it */ - strlcpy(client->user->username + 1, stripuser, sizeof(client->user->username)-1); + strlcpy(client->user->username + 1, stripuser, sizeof(client->user->username) - 1); client->user->username[0] = '~'; client->user->username[USERLEN] = '\0'; return 1; /* Filtered, but OK */ @@ -1074,11 +1068,10 @@ int _register_user(Client *client) { /* ident succeeded: overwite client->user->username with the ident reply */ strlcpy(client->user->username, client->ident, sizeof(client->user->username)); - } else - if (IDENT_CHECK) + } else if (IDENT_CHECK) { /* ident check is enabled and it failed: prefix the username with ~ */ - char temp[USERLEN+1]; + char temp[USERLEN + 1]; strlcpy(temp, client->user->username, sizeof(temp)); snprintf(client->user->username, sizeof(client->user->username), "~%s", temp); noident = 1; @@ -1098,7 +1091,7 @@ int _register_user(Client *client) if ((bconf = find_ban(NULL, client->info, CONF_BAN_REALNAME))) { ircstats.is_ref++; - banned_client(client, "realname", bconf->reason?bconf->reason:"", NULL, 0, 0); + banned_client(client, "realname", bconf->reason ? bconf->reason : "", NULL, 0, 0); return 0; } /* Check G/Z lines before shuns -- kill before quite -- codemastr */ @@ -1127,7 +1120,8 @@ int _register_user(Client *client) * of this function we will do the actual joining to the * virus channel. */ - } else { + } else + { /* Client is either dead or blocked (will hang, on purpose, and timeout) */ return 0; } @@ -1189,8 +1183,8 @@ int _register_user(Client *client) update_known_user_cache(client); unreal_log(ULOG_INFO, "connect", "LOCAL_CLIENT_CONNECT", client, - "Client connecting: $client ($client.user.username@$client.hostname) [$client.ip] $extended_client_info", - log_data_string("extended_client_info", get_connect_extinfo(client))); + "Client connecting: $client ($client.user.username@$client.hostname) [$client.ip] $extended_client_info", + log_data_string("extended_client_info", get_connect_extinfo(client))); /* Send the RPL_WELCOME, LUSERS, MOTD, auto join channels, everything... */ welcome_user(client, savetkl); @@ -1336,7 +1330,8 @@ int AllowClient(Client *client) { exit_client(client, NULL, iConf.reject_message_unauthorized); return 0; - } else { + } else + { continue; /* Continue (this is the default behavior) */ } } @@ -1363,8 +1358,7 @@ int AllowClient(Client *client) { client->local->class = aconf->class; client->local->class->clients++; - } - else + } else { /* Class is full */ sendnumeric(client, RPL_REDIR, aconf->server ? aconf->server : DEFAULT_SERVER, aconf->port ? aconf->port : 6667); @@ -1436,7 +1430,8 @@ char *_unreal_expand_string(const char *str, char *buf, size_t buflen, NameValue */ snprintf(asn, sizeof(asn), "%d", geo->asn); add_nvplist(&nvp, 0, "asn", asn); - } else { + } else + { add_nvplist(&nvp, 0, "country_code", "XX"); add_nvplist(&nvp, 0, "asn", "0"); } diff --git a/src/modules/no-implicit-names.c b/src/modules/no-implicit-names.c index 213ec0e71..b01f8c0e7 100644 --- a/src/modules/no-implicit-names.c +++ b/src/modules/no-implicit-names.c @@ -19,17 +19,16 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "no-implicit-names", - "1.0", - "Opt out of receiving an implicit NAMES list on JOIN", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "no-implicit-names", + "1.0", + "Opt out of receiving an implicit NAMES list on JOIN", + "UnrealIRCd Team", + "unrealircd-6", }; #define NO_IMPLICIT_NAMES_CAP_DRAFT "draft/no-implicit-names" -#define NO_IMPLICIT_NAMES_CAP "no-implicit-names" +#define NO_IMPLICIT_NAMES_CAP "no-implicit-names" long CAP_NO_IMPLICIT_NAMES_DRAFT = 0L; long CAP_NO_IMPLICIT_NAMES = 0L; @@ -62,4 +61,3 @@ MOD_UNLOAD() { return MOD_SUCCESS; } - diff --git a/src/modules/nocodes.c b/src/modules/nocodes.c index f9d7db719..2fa307145 100644 --- a/src/modules/nocodes.c +++ b/src/modules/nocodes.c @@ -20,13 +20,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "nocodes", /* Name of module */ - "1.3", /* Version */ - "Strip/block color/bold/underline/italic/reverse - by Syzop", /* Short description of module */ - "UnrealIRCd Team", /* Author */ - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "nocodes", /* Name of module */ + "1.3", /* Version */ + "Strip/block color/bold/underline/italic/reverse - by Syzop", /* Short description of module */ + "UnrealIRCd Team", /* Author */ + "unrealircd-6", }; int nocodes_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype, ClientContext *clictx); @@ -80,8 +79,7 @@ int nocodes_can_send_to_channel(Client *client, Channel *channel, Membership *lp strlcpy(retbuf, StripControlCodes(*msg), sizeof(retbuf)); *msg = retbuf; return HOOK_CONTINUE; - } else - if (has_channel_mode(channel, 'c')) + } else if (has_channel_mode(channel, 'c')) { if (!has_controlcodes(*msg)) return HOOK_CONTINUE; diff --git a/src/modules/oper.c b/src/modules/oper.c index a91da2668..bc0b07006 100644 --- a/src/modules/oper.c +++ b/src/modules/oper.c @@ -20,16 +20,15 @@ #include "unrealircd.h" -#define MSG_OPER "OPER" /* OPER */ +#define MSG_OPER "OPER" /* OPER */ -ModuleHeader MOD_HEADER - = { - "oper", /* Name of module */ - "5.0", /* Version */ - "command /oper", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "oper", /* Name of module */ + "5.0", /* Version */ + "command /oper", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ CMD_FUNC(cmd_oper); @@ -65,7 +64,7 @@ void set_oper_host(Client *client, const char *host) { char uhost[HOSTLEN + USERLEN + 1]; char *p; - char newhost[HOSTLEN+1]; + char newhost[HOSTLEN + 1]; *newhost = '\0'; unreal_expand_string(host, newhost, sizeof(newhost), NULL, 0, client); @@ -94,7 +93,7 @@ void set_oper_host(Client *client, const char *host) safe_strdup(client->user->virthost, host); if (MyConnect(client)) sendto_server(NULL, 0, 0, NULL, ":%s SETHOST :%s", client->id, client->user->virthost); - client->umodes |= UMODE_SETHOST|UMODE_HIDE; + client->umodes |= UMODE_SETHOST | UMODE_HIDE; } int _make_oper(Client *client, const char *operblock_name, const char *operclass, ConfigItem_class *clientclass, long modes, const char *snomask, const char *vhost, const char *autojoin_channels) @@ -126,12 +125,10 @@ int _make_oper(Client *client, const char *operblock_name, const char *operclass if (vhost) { set_oper_host(client, vhost); - } else - if (iConf.oper_vhost) + } else if (iConf.oper_vhost) { set_oper_host(client, iConf.oper_vhost); - } else - if (IsHidden(client) && !client->user->virthost) + } else if (IsHidden(client) && !client->user->virthost) { /* +x has just been set by modes-on-oper and no vhost. cloak the oper! */ safe_strdup(client->user->virthost, client->user->cloakedhost); @@ -140,9 +137,9 @@ int _make_oper(Client *client, const char *operblock_name, const char *operclass userhost_changed(client); unreal_log(ULOG_INFO, "oper", "OPER_SUCCESS", client, - "$client.details is now an IRC Operator [oper-block: $oper_block] [operclass: $operclass]", - log_data_string("oper_block", operblock_name), - log_data_string("operclass", operclass)); + "$client.details is now an IRC Operator [oper-block: $oper_block] [operclass: $operclass]", + log_data_string("oper_block", operblock_name), + log_data_string("operclass", operclass)); /* set oper snomasks */ if (snomask) @@ -168,7 +165,7 @@ int _make_oper(Client *client, const char *operblock_name, const char *operclass if (SHOWOPERMOTD == 1) { - const char *args[1] = { NULL }; + const char *args[1] = {NULL}; do_cmd(client, NULL, "OPERMOTD", 1, args); } @@ -176,9 +173,9 @@ int _make_oper(Client *client, const char *operblock_name, const char *operclass { char *chans = strdup(autojoin_channels); const char *args[3] = { - client->name, - chans, - NULL, + client->name, + chans, + NULL, }; do_cmd(client, NULL, "JOIN", 3, args); safe_free(chans); @@ -212,7 +209,7 @@ CMD_FUNC(cmd_oper) if (SVSNOOP) { sendnotice(client, - "*** This server is in NOOP mode, you cannot /oper"); + "*** This server is in NOOP mode, you cannot /oper"); return; } @@ -284,7 +281,7 @@ CMD_FUNC(cmd_oper) sendnumeric(client, ERR_PASSWDMISMATCH); if (FAILOPER_WARN) sendnotice(client, - "*** Your attempt has been logged."); + "*** Your attempt has been logged."); unreal_log(ULOG_ERROR, "oper", "OPER_FAILED", client, "Failed OPER attempt by $client.details [reason: $reason] [oper-block: $oper_block]", log_data_string("reason", "Authentication failed"), @@ -327,7 +324,7 @@ CMD_FUNC(cmd_oper) { sendnumeric(client, ERR_NOOPERHOST); sendnotice(client, "Your maximum number of concurrent oper logins has been reached (%d)", - operblock->maxlogins); + operblock->maxlogins); unreal_log(ULOG_WARNING, "oper", "OPER_FAILED", client, "Failed OPER attempt by $client.details [reason: $reason] [oper-block: $oper_block]", log_data_string("reason", "oper::maxlogins limit reached"), @@ -357,8 +354,8 @@ CMD_FUNC(cmd_oper) { sendnotice_multiline(client, iConf.plaintext_policy_oper_message); unreal_log(ULOG_WARNING, "oper", "OPER_UNSAFE", client, - "Insecure (non-TLS) connection used to OPER up by $client.details [oper-block: $oper_block]", - log_data_string("oper_block", parv[1]), + "Insecure (non-TLS) connection used to OPER up by $client.details [oper-block: $oper_block]", + log_data_string("oper_block", parv[1]), log_data_string("warn_type", "NO_TLS")); } @@ -367,8 +364,8 @@ CMD_FUNC(cmd_oper) { sendnotice(client, "%s", outdated_tls_client_build_string(iConf.outdated_tls_policy_oper_message, client)); unreal_log(ULOG_WARNING, "oper", "OPER_UNSAFE", client, - "Outdated TLS protocol/cipher used to OPER up by $client.details [oper-block: $oper_block]", - log_data_string("oper_block", parv[1]), + "Outdated TLS protocol/cipher used to OPER up by $client.details [oper-block: $oper_block]", + log_data_string("oper_block", parv[1]), log_data_string("warn_type", "OUTDATED_TLS_PROTOCOL_OR_CIPHER")); } } diff --git a/src/modules/operinfo.c b/src/modules/operinfo.c index e91b1c6f8..c2bd18543 100644 --- a/src/modules/operinfo.c +++ b/src/modules/operinfo.c @@ -6,14 +6,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "operinfo", - "5.0", - "Store oper login in ModData", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "operinfo", + "5.0", + "Store oper login in ModData", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int operinfo_local_oper(Client *client, int up, const char *oper_block, const char *operclass); @@ -76,7 +75,8 @@ int operinfo_local_oper(Client *client, int up, const char *oper_block, const ch { moddata_client_set(client, "operlogin", oper_block); moddata_client_set(client, "operclass", operclass); - } else { + } else + { moddata_client_set(client, "operlogin", NULL); moddata_client_set(client, "operclass", NULL); } diff --git a/src/modules/opermotd.c b/src/modules/opermotd.c index 2186c642a..7327bb714 100644 --- a/src/modules/opermotd.c +++ b/src/modules/opermotd.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_opermotd); -#define MSG_OPERMOTD "OPERMOTD" +#define MSG_OPERMOTD "OPERMOTD" -ModuleHeader MOD_HEADER - = { - "opermotd", - "5.0", - "command /opermotd", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "opermotd", + "5.0", + "command /opermotd", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_OPERMOTD, cmd_opermotd, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_OPERMOTD, cmd_opermotd, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -60,7 +59,7 @@ CMD_FUNC(cmd_opermotd) MOTDLine *motdline; ConfigItem_tld *tld; - if (!ValidatePermissionsForPath("server:opermotd",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:opermotd", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -83,7 +82,7 @@ CMD_FUNC(cmd_opermotd) while (motdline) { sendnumeric(client, RPL_MOTD, - motdline->line); + motdline->line); motdline = motdline->next; } sendnumericfmt(client, RPL_ENDOFMOTD, ":End of /OPERMOTD command."); diff --git a/src/modules/part.c b/src/modules/part.c index ba4e54bba..a0ed0dbfc 100644 --- a/src/modules/part.c +++ b/src/modules/part.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_part); -#define MSG_PART "PART" +#define MSG_PART "PART" -ModuleHeader MOD_HEADER - = { - "part", - "5.0", - "command /part", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "part", + "5.0", + "command /part", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -68,7 +67,7 @@ CMD_FUNC(cmd_part) int n; int ntargets = 0; int maxtargets = max_targets_for_command("PART"); - + if (parc < 2 || parv[1][0] == '\0') { sendnumeric(client, ERR_NEEDMOREPARAMS, "PART"); @@ -133,7 +132,8 @@ CMD_FUNC(cmd_part) continue; } - if (!ValidatePermissionsForPath("channel:override:banpartmsg",client,NULL,channel,NULL) && !check_channel_access(client, channel, "oaq")) { + if (!ValidatePermissionsForPath("channel:override:banpartmsg", client, NULL, channel, NULL) && !check_channel_access(client, channel, "oaq")) + { /* Banned? No comment allowed ;) */ if (comment && is_banned(client, channel, BANCHK_MSG, &comment, NULL)) comment = NULL; @@ -144,7 +144,8 @@ CMD_FUNC(cmd_part) if (MyConnect(client)) { Hook *tmphook; - for (tmphook = Hooks[HOOKTYPE_PRE_LOCAL_PART]; tmphook; tmphook = tmphook->next) { + for (tmphook = Hooks[HOOKTYPE_PRE_LOCAL_PART]; tmphook; tmphook = tmphook->next) + { comment = (*(tmphook->func.stringfunc))(client, channel, comment); if (!comment) break; @@ -156,7 +157,7 @@ CMD_FUNC(cmd_part) /* Send to other servers... */ sendto_server(client, 0, 0, mtags, ":%s PART %s :%s", - client->id, channel->name, comment ? comment : ""); + client->id, channel->name, comment ? comment : ""); if (invisible_user_in_channel(client, channel)) { @@ -164,33 +165,31 @@ CMD_FUNC(cmd_part) if (!comment) { sendto_channel(channel, client, client, - "ho", 0, - SEND_LOCAL, mtags, - ":%s PART %s", - client->name, channel->name); + "ho", 0, + SEND_LOCAL, mtags, + ":%s PART %s", + client->name, channel->name); if (MyUser(client)) { sendto_one(client, mtags, ":%s!%s@%s PART %s", - client->name, client->user->username, GetHost(client), channel->name); + client->name, client->user->username, GetHost(client), channel->name); } - } - else + } else { sendto_channel(channel, client, client, - "ho", 0, - SEND_LOCAL, mtags, - ":%s PART %s %s", - client->name, channel->name, comment); + "ho", 0, + SEND_LOCAL, mtags, + ":%s PART %s %s", + client->name, channel->name, comment); if (MyUser(client)) { sendto_one(client, mtags, - ":%s!%s@%s PART %s %s", - client->name, client->user->username, GetHost(client), - channel->name, comment); + ":%s!%s@%s PART %s %s", + client->name, client->user->username, GetHost(client), + channel->name, comment); } } - } - else + } else { /* Show PART to all users in channel */ if (!comment) @@ -198,7 +197,8 @@ CMD_FUNC(cmd_part) sendto_channel(channel, client, NULL, 0, 0, SEND_LOCAL, mtags, ":%s PART %s", client->name, channel->name); - } else { + } else + { sendto_channel(channel, client, NULL, 0, 0, SEND_LOCAL, mtags, ":%s PART %s :%s", client->name, channel->name, comment); diff --git a/src/modules/pass.c b/src/modules/pass.c index 7de36d3df..e7b6f07a2 100644 --- a/src/modules/pass.c +++ b/src/modules/pass.c @@ -24,21 +24,20 @@ CMD_FUNC(cmd_pass); -#define MSG_PASS "PASS" +#define MSG_PASS "PASS" -ModuleHeader MOD_HEADER - = { - "pass", - "5.0", - "command /pass", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "pass", + "5.0", + "command /pass", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_PASS, cmd_pass, 1, CMD_UNREGISTERED|CMD_USER|CMD_SERVER); - + CommandAdd(modinfo->handle, MSG_PASS, cmd_pass, 1, CMD_UNREGISTERED | CMD_USER | CMD_SERVER); + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -77,8 +76,8 @@ CMD_FUNC(cmd_pass) } /* Store the password */ - safe_strldup(client->local->passwd, password, PASSWDLEN+1); + safe_strldup(client->local->passwd, password, PASSWDLEN + 1); /* note: the original non-truncated password is supplied as 2nd parameter. */ - RunHookReturn(HOOKTYPE_LOCAL_PASS, !=0, client, password); + RunHookReturn(HOOKTYPE_LOCAL_PASS, != 0, client, password); } diff --git a/src/modules/pingpong.c b/src/modules/pingpong.c index 9c8557734..324448ab6 100644 --- a/src/modules/pingpong.c +++ b/src/modules/pingpong.c @@ -25,22 +25,21 @@ CMD_FUNC(cmd_pong); CMD_FUNC(cmd_nospoof); /* Place includes here */ -#define MSG_PING "PING" /* PING */ -#define MSG_PONG "PONG" /* PONG */ +#define MSG_PING "PING" /* PING */ +#define MSG_PONG "PONG" /* PONG */ -ModuleHeader MOD_HEADER - = { - "pingpong", /* Name of module */ - "5.0", /* Version */ - "ping, pong and nospoof", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "pingpong", /* Name of module */ + "5.0", /* Version */ + "ping, pong and nospoof", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() { - CommandAdd(modinfo->handle, MSG_PING, cmd_ping, MAXPARA, CMD_USER|CMD_SERVER|CMD_SHUN); - CommandAdd(modinfo->handle, MSG_PONG, cmd_pong, MAXPARA, CMD_UNREGISTERED|CMD_USER|CMD_SERVER|CMD_SHUN|CMD_VIRUS); + CommandAdd(modinfo->handle, MSG_PING, cmd_ping, MAXPARA, CMD_USER | CMD_SERVER | CMD_SHUN); + CommandAdd(modinfo->handle, MSG_PONG, cmd_pong, MAXPARA, CMD_UNREGISTERED | CMD_USER | CMD_SERVER | CMD_SHUN | CMD_VIRUS); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -75,7 +74,7 @@ CMD_FUNC(cmd_ping) } origin = parv[1]; - destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ + destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ if (!MyUser(client)) origin = client->name; @@ -91,13 +90,12 @@ CMD_FUNC(cmd_ping) sendnumeric(client, ERR_NOSUCHSERVER, destination); return; } - } - else + } else { MessageTag *mtags = NULL; new_message(&me, recv_mtags, &mtags); sendto_one(client, mtags, ":%s PONG %s :%s", me.name, - (destination) ? destination : me.name, origin); + (destination) ? destination : me.name, origin); free_message_tags(mtags); } } @@ -144,7 +142,7 @@ CMD_FUNC(cmd_nospoof) if (USE_BAN_VERSION && MyConnect(client)) sendto_one(client, NULL, ":IRC!IRC@%s PRIVMSG %s :\1VERSION\1", - me.name, client->name); + me.name, client->name); if (is_handshake_finished(client)) register_user(client); @@ -198,8 +196,7 @@ CMD_FUNC(cmd_pong) sendto_one(target, mtags, ":%s PONG %s %s", client->name, origin, destination); free_message_tags(mtags); } - } - else + } else { sendnumeric(client, ERR_NOSUCHSERVER, destination); return; diff --git a/src/modules/plaintext-policy.c b/src/modules/plaintext-policy.c index dd82b655c..cb45d1229 100644 --- a/src/modules/plaintext-policy.c +++ b/src/modules/plaintext-policy.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "plaintext-policy", - "5.0", - "Plaintext Policy CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "plaintext-policy", + "5.0", + "Plaintext Policy CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -55,11 +54,11 @@ MOD_UNLOAD() const char *plaintext_policy_capability_parameter(Client *client) { static char buf[128]; - + snprintf(buf, sizeof(buf), "user=%s,oper=%s,server=%s", - policy_valtostr(iConf.plaintext_policy_user), - policy_valtostr(iConf.plaintext_policy_oper), - policy_valtostr(iConf.plaintext_policy_server)); + policy_valtostr(iConf.plaintext_policy_user), + policy_valtostr(iConf.plaintext_policy_oper), + policy_valtostr(iConf.plaintext_policy_server)); return buf; } diff --git a/src/modules/portinfo.c b/src/modules/portinfo.c index 820a7adf0..ee6b5d3c9 100644 --- a/src/modules/portinfo.c +++ b/src/modules/portinfo.c @@ -6,14 +6,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "portinfo", - "1.0.0", - "Store port info in ModData", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "portinfo", + "1.0.0", + "Store port info in ModData", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ void portinfo_free(ModData *m); diff --git a/src/modules/protoctl.c b/src/modules/protoctl.c index f73242596..a7e33cbf7 100644 --- a/src/modules/protoctl.c +++ b/src/modules/protoctl.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_protoctl); -#define MSG_PROTOCTL "PROTOCTL" +#define MSG_PROTOCTL "PROTOCTL" -ModuleHeader MOD_HEADER - = { - "protoctl", - "5.0", - "command /protoctl", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "protoctl", + "5.0", + "command /protoctl", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_PROTOCTL, cmd_protoctl, MAXPARA, CMD_UNREGISTERED|CMD_SERVER|CMD_USER); + CommandAdd(modinfo->handle, MSG_PROTOCTL, cmd_protoctl, MAXPARA, CMD_UNREGISTERED | CMD_SERVER | CMD_USER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -62,7 +61,7 @@ MOD_UNLOAD() */ CMD_FUNC(cmd_protoctl) { - int i; + int i; int first_protoctl = IsProtoctlReceived(client) ? 0 : 1; /**< First PROTOCTL we receive? Special ;) */ char proto[512]; char *name, *value, *p; @@ -81,7 +80,8 @@ CMD_FUNC(cmd_protoctl) name = proto; *p++ = '\0'; value = p; - } else { + } else + { name = proto; value = NULL; } @@ -89,44 +89,34 @@ CMD_FUNC(cmd_protoctl) if (!strcmp(name, "NAMESX")) { SetCapability(client, "multi-prefix"); - } - else if (!strcmp(name, "UHNAMES") && UHNAMES_ENABLED) + } else if (!strcmp(name, "UHNAMES") && UHNAMES_ENABLED) { SetCapability(client, "userhost-in-names"); - } - else if (IsUser(client)) + } else if (IsUser(client)) { return; - } - else if (!strcmp(name, "VL")) + } else if (!strcmp(name, "VL")) { SetVL(client); - } - else if (!strcmp(name, "VHP")) + } else if (!strcmp(name, "VHP")) { SetVHP(client); - } - else if (!strcmp(name, "CLK")) + } else if (!strcmp(name, "CLK")) { SetCLK(client); - } - else if (!strcmp(name, "SJSBY") && iConf.ban_setter_sync) + } else if (!strcmp(name, "SJSBY") && iConf.ban_setter_sync) { SetSJSBY(client); - } - else if (!strcmp(name, "MTAGS")) + } else if (!strcmp(name, "MTAGS")) { SetMTAGS(client); - } - else if (!strcmp(name, "NEXTBANS")) + } else if (!strcmp(name, "NEXTBANS")) { SetNEXTBANS(client); - } - else if (!strcmp(name, "BIGLINES")) + } else if (!strcmp(name, "BIGLINES")) { SetBIGLINES(client); - } - else if (!strcmp(name, "NICKCHARS") && value) + } else if (!strcmp(name, "NICKCHARS") && value) { if (!IsServer(client) && !IsEAuth(client) && !IsHandshake(client)) continue; @@ -137,8 +127,8 @@ CMD_FUNC(cmd_protoctl) if (strstr(charsys_get_current_languages(), "utf8") && !strstr(value, "utf8")) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_CHARSYS_INCOMPATIBLE", client, - "Server link $client rejected. Server $me_name has utf8 in set::allowed-nickchars but $client does not.", - log_data_string("me_name", me.name)); + "Server link $client rejected. Server $me_name has utf8 in set::allowed-nickchars but $client does not.", + log_data_string("me_name", me.name)); exit_client(client, NULL, "Incompatible set::allowed-nickchars setting"); return; } @@ -146,10 +136,10 @@ CMD_FUNC(cmd_protoctl) if (strcmp(value, charsys_get_current_languages())) { unreal_log(ULOG_WARNING, "link", "LINK_WARNING_CHARSYS", client, - "Server link $client does not have the same set::allowed-nickchars settings, " - "this may possibly cause display issues. Our charset: '$our_charsys', theirs: '$their_charsys'", - log_data_string("our_charsys", charsys_get_current_languages()), - log_data_string("their_charsys", value)); + "Server link $client does not have the same set::allowed-nickchars settings, " + "this may possibly cause display issues. Our charset: '$our_charsys', theirs: '$their_charsys'", + log_data_string("our_charsys", charsys_get_current_languages()), + log_data_string("their_charsys", value)); } if (client->server) safe_strdup(client->server->features.nickchars, value); @@ -157,8 +147,7 @@ CMD_FUNC(cmd_protoctl) /* If this is a runtime change (so post-handshake): */ if (IsServer(client)) broadcast_sinfo(client, NULL, client); - } - else if (!strcmp(name, "CHANNELCHARS") && value) + } else if (!strcmp(name, "CHANNELCHARS") && value) { int their_value; @@ -169,16 +158,15 @@ CMD_FUNC(cmd_protoctl) if (their_value != iConf.allowed_channelchars) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_ALLOWED_CHANNELCHARS_INCOMPATIBLE", client, - "Server link $client rejected. Server has set::allowed-channelchars setting " - "of $their_allowed_channelchars, while we have $our_allowed_channelchars.\n" - "Please set set::allowed-channelchars to the same value on all servers.", - log_data_string("their_allowed_channelchars", value), - log_data_string("our_allowed_channelchars", allowed_channelchars_valtostr(iConf.allowed_channelchars))); + "Server link $client rejected. Server has set::allowed-channelchars setting " + "of $their_allowed_channelchars, while we have $our_allowed_channelchars.\n" + "Please set set::allowed-channelchars to the same value on all servers.", + log_data_string("their_allowed_channelchars", value), + log_data_string("our_allowed_channelchars", allowed_channelchars_valtostr(iConf.allowed_channelchars))); exit_client(client, NULL, "Incompatible set::allowed-channelchars setting"); return; } - } - else if (!strcmp(name, "SID") && value) + } else if (!strcmp(name, "SID") && value) { Client *aclient; char *sid = value; @@ -189,7 +177,7 @@ CMD_FUNC(cmd_protoctl) return; } - if (*client->id && (strlen(client->id)==3)) + if (*client->id && (strlen(client->id) == 3)) { exit_client(client, NULL, "Got PROTOCTL SID twice"); return; @@ -210,9 +198,9 @@ CMD_FUNC(cmd_protoctl) if ((aclient = hash_find_id(sid, NULL)) != NULL) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_SID_COLLISION", client, - "Server link $client rejected. Server with SID $sid already exist via uplink $existing_client.server.uplink.", - log_data_string("sid", sid), - log_data_client("existing_client", aclient)); + "Server link $client rejected. Server with SID $sid already exist via uplink $existing_client.server.uplink.", + log_data_string("sid", sid), + log_data_client("existing_client", aclient)); exit_client(client, NULL, "SID collision"); return; } @@ -221,8 +209,7 @@ CMD_FUNC(cmd_protoctl) del_from_id_hash_table(client->id, client); /* delete old UID entry (created on connect) */ strlcpy(client->id, sid, sizeof(client->id)); add_to_id_hash_table(client->id, client); /* add SID */ - } - else if (!strcmp(name, "EAUTH") && value) + } else if (!strcmp(name, "EAUTH") && value) { /* Early authorization: EAUTH=servername,protocol,flags,software * (Only servername is mandatory, rest is optional) @@ -246,15 +233,15 @@ CMD_FUNC(cmd_protoctl) *p = '\0'; p = NULL; } - + servername = strtoken_noskip(&p, buf, ","); if (!servername || !valid_server_name(servername)) { exit_client(client, NULL, "Bogus server name"); return; } - - + + protocol = strtoken_noskip(&p, NULL, ","); if (protocol) { @@ -262,7 +249,7 @@ CMD_FUNC(cmd_protoctl) if (flags) software = strtoken_noskip(&p, NULL, ","); } - + /* Set client->name but don't add to hash list, this gives better * log messages and should be safe. See CMTSRV941 in server.c. */ @@ -288,18 +275,17 @@ CMD_FUNC(cmd_protoctl) } if (!IsHandshake(client) && aconf) /* Send PASS early... */ sendto_one(client, NULL, "PASS :%s", (aconf->auth->type == AUTHTYPE_PLAINTEXT) ? aconf->auth->data : "*"); - } - else if (!strcmp(name, "SERVERS") && value) + } else if (!strcmp(name, "SERVERS") && value) { Client *aclient, *srv; char *sid = NULL; - + if (!IsEAuth(client)) continue; - + if (client->server->features.protocol < 2351) continue; /* old SERVERS= version */ - + /* Other side lets us know which servers are behind it. * SERVERS=[, MAX_SERVER_TIME_OFFSET) + } else if ((t - TStime()) > MAX_SERVER_TIME_OFFSET) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_CLOCK_INCORRECT", client, "Denied server $client: clock on server $client is $time_delta " @@ -367,30 +351,25 @@ CMD_FUNC(cmd_protoctl) (long long)(t - TStime())); return; } - } - else if (!strcmp(name, "MLOCK")) + } else if (!strcmp(name, "MLOCK")) { client->local->proto |= PROTO_MLOCK; - } - else if (!strcmp(name, "CHANMODES") && value && client->server) + } else if (!strcmp(name, "CHANMODES") && value && client->server) { parse_chanmodes_protoctl(client, value); /* If this is a runtime change (so post-handshake): */ if (IsServer(client)) broadcast_sinfo(client, NULL, client); - } - else if (!strcmp(name, "USERMODES") && value && client->server) + } else if (!strcmp(name, "USERMODES") && value && client->server) { safe_strdup(client->server->features.usermodes, value); /* If this is a runtime change (so post-handshake): */ if (IsServer(client)) broadcast_sinfo(client, NULL, client); - } - else if (!strcmp(name, "BOOTED") && value && client->server) + } else if (!strcmp(name, "BOOTED") && value && client->server) { client->server->boottime = atol(value); - } - else if (!strcmp(name, "EXTSWHOIS")) + } else if (!strcmp(name, "EXTSWHOIS")) { client->local->proto |= PROTO_EXTSWHOIS; } diff --git a/src/modules/quit.c b/src/modules/quit.c index 7f949d06a..5563f8cc3 100644 --- a/src/modules/quit.c +++ b/src/modules/quit.c @@ -21,17 +21,16 @@ #include "unrealircd.h" /* Defines */ -#define MSG_QUIT "QUIT" /* QUIT */ +#define MSG_QUIT "QUIT" /* QUIT */ /* Structs */ -ModuleHeader MOD_HEADER - = { - "quit", /* Name of module */ - "5.0", /* Version */ - "command /quit", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "quit", /* Name of module */ + "5.0", /* Version */ + "command /quit", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ CMD_FUNC(cmd_quit); @@ -56,7 +55,7 @@ MOD_TEST() MOD_INIT() { MARK_AS_OFFICIAL_MODULE(modinfo); - CommandAdd(modinfo->handle, MSG_QUIT, cmd_quit, 1, CMD_UNREGISTERED|CMD_USER|CMD_VIRUS|CMD_TEXTANALYSIS); + CommandAdd(modinfo->handle, MSG_QUIT, cmd_quit, 1, CMD_UNREGISTERED | CMD_USER | CMD_VIRUS | CMD_TEXTANALYSIS); return MOD_SUCCESS; } @@ -84,7 +83,8 @@ CMD_FUNC(cmd_quit) { strlncpy(commentbuf, parv[1], sizeof(commentbuf), iConf.quit_length); comment = commentbuf; - } else { + } else + { comment = client->name; } @@ -112,10 +112,10 @@ CMD_FUNC(cmd_quit) if (IsDead(client)) return; } - - if (!ValidatePermissionsForPath("immune:anti-spam-quit-message-time",client,NULL,NULL,NULL) && ANTI_SPAM_QUIT_MSG_TIME) + + if (!ValidatePermissionsForPath("immune:anti-spam-quit-message-time", client, NULL, NULL, NULL) && ANTI_SPAM_QUIT_MSG_TIME) { - if (client->local->creationtime+ANTI_SPAM_QUIT_MSG_TIME > TStime()) + if (client->local->creationtime + ANTI_SPAM_QUIT_MSG_TIME > TStime()) comment = client->name; } @@ -156,7 +156,8 @@ CMD_FUNC(cmd_quit) strlcpy(tmp, newcomment, sizeof(tmp)); parx[2] = tmp; parx[3] = NULL; - } else { + } else + { parx[2] = NULL; } @@ -172,7 +173,7 @@ CMD_FUNC(cmd_quit) { comment = (*(tmphook->func.stringfunc))(client, comment); if (!comment) - { + { comment = client->name; break; } @@ -184,8 +185,7 @@ CMD_FUNC(cmd_quit) strlcpy(commentbuf2, comment, sizeof(commentbuf2)); exit_client(client, recv_mtags, commentbuf2); - } - else + } else { /* Remote quits and non-person quits always use their original comment. * Also pass recv_mtags so to keep the msgid and such. @@ -261,8 +261,7 @@ void _exit_client_ex(Client *client, Client *origin, MessageTag *recv_mtags, con if (client->server && client->server->conf) { client->server->conf->refcount--; - if (!client->server->conf->refcount - && client->server->conf->flag.temporary) + if (!client->server->conf->refcount && client->server->conf->flag.temporary) { delete_linkblock(client->server->conf); client->server->conf = NULL; @@ -274,8 +273,8 @@ void _exit_client_ex(Client *client, Client *origin, MessageTag *recv_mtags, con if (!IsServerDisconnectLogged(client)) { unreal_log(ULOG_ERROR, "link", "LINK_DISCONNECTED", client, - "Lost server link to $client [$client.ip]: $reason", - log_data_string("reason", comment)); + "Lost server link to $client [$client.ip]: $reason", + log_data_string("reason", comment)); } } free_pending_net(client); @@ -285,12 +284,11 @@ void _exit_client_ex(Client *client, Client *origin, MessageTag *recv_mtags, con long connected_time = TStime() - client->local->creationtime; RunHook(HOOKTYPE_LOCAL_QUIT, client, recv_mtags, comment); unreal_log(ULOG_INFO, "connect", "LOCAL_CLIENT_DISCONNECT", client, - "Client exiting: $client ($client.user.username@$client.hostname) [$client.ip] ($reason)", - log_data_string("extended_client_info", get_connect_extinfo(client)), - log_data_string("reason", comment), - log_data_integer("connected_time", connected_time)); - } else - if (IsUnknown(client)) + "Client exiting: $client ($client.user.username@$client.hostname) [$client.ip] ($reason)", + log_data_string("extended_client_info", get_connect_extinfo(client)), + log_data_string("reason", comment), + log_data_integer("connected_time", connected_time)); + } else if (IsUnknown(client)) { RunHook(HOOKTYPE_UNKUSER_QUIT, client, recv_mtags, comment); } @@ -301,16 +299,15 @@ void _exit_client_ex(Client *client, Client *origin, MessageTag *recv_mtags, con sendto_one(client, NULL, "ERROR :Closing Link: %s (%s)", get_client_name(client, FALSE), comment); } close_connection(client); - } - else if (IsUser(client) && !IsULine(client)) + } else if (IsUser(client) && !IsULine(client)) { if (client->uplink != &me) { unreal_log(ULOG_INFO, "connect", "REMOTE_CLIENT_DISCONNECT", client, - "Client exiting: $client ($client.user.username@$client.hostname) [$client.ip] ($reason)", - log_data_string("extended_client_info", get_connect_extinfo(client)), - log_data_string("reason", comment), - log_data_string("from_server_name", client->user->server)); + "Client exiting: $client ($client.user.username@$client.hostname) [$client.ip] ($reason)", + log_data_string("extended_client_info", get_connect_extinfo(client)), + log_data_string("reason", comment), + log_data_string("from_server_name", client->user->server)); } } @@ -334,13 +331,11 @@ void _exit_client_ex(Client *client, Client *origin, MessageTag *recv_mtags, con remove_dependents(client, origin, recv_mtags, comment, splitstr); /* Special case for remote async RPC, server.rehash in particular.. */ - list_for_each_entry_safe(acptr, next, &rpc_remote_list, client_node) - if (!strncmp(client->id, acptr->id, SIDLEN)) - free_client(acptr); + list_for_each_entry_safe(acptr, next, &rpc_remote_list, client_node) if (!strncmp(client->id, acptr->id, SIDLEN)) + free_client(acptr); RunHook(HOOKTYPE_SERVER_QUIT, client, recv_mtags); - } - else if (IsUser(client) && !IsKilled(client)) + } else if (IsUser(client) && !IsKilled(client)) { sendto_server(client, 0, 0, recv_mtags, ":%s QUIT :%s", client->id, comment); } @@ -374,7 +369,8 @@ static int should_hide_ban_reason(Client *client, const char *reason) return 1; } return 0; - } else { + } else + { return HIDE_BAN_REASON == HIDE_BAN_REASON_YES ? 1 : 0; } } @@ -513,7 +509,8 @@ void _banned_client(Client *client, const char *bantype, const char *reason, con { snprintf(idbuf, sizeof(idbuf), " [ID: %s]", tklid); banid = idbuf + 1; - } else { + } else + { idbuf[0] = '\0'; banid = idbuf; } @@ -559,14 +556,16 @@ void _banned_client(Client *client, const char *bantype, const char *reason, con AddListItem(m, mtags); /* And the quit reason for anyone else, goes here.. */ snprintf(buf, sizeof(buf), "Banned (%s)%s", bantype, idbuf); - } else { + } else + { snprintf(buf, sizeof(buf), "Banned (%s): %s%s", bantype, reason, idbuf); } if (noexit != NO_EXIT_CLIENT) { exit_client(client, mtags, buf); - } else { + } else + { /* Special handling for direct Z-line code */ client->flags |= CLIENT_FLAG_DEADSOCKET_IS_BANNED; dead_socket(client, buf); diff --git a/src/modules/real-quit-reason.c b/src/modules/real-quit-reason.c index a786346f5..046c5a174 100644 --- a/src/modules/real-quit-reason.c +++ b/src/modules/real-quit-reason.c @@ -7,14 +7,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "real-quit-reason", - "6.0", - "unrealircd.org/real-quit-reason message tag", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "real-quit-reason", + "6.0", + "unrealircd.org/real-quit-reason message tag", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int real_quit_reason_mtag_is_ok(Client *client, const char *name, const char *value); diff --git a/src/modules/reply-tag.c b/src/modules/reply-tag.c index 14b521f05..2aa753742 100644 --- a/src/modules/reply-tag.c +++ b/src/modules/reply-tag.c @@ -24,14 +24,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "reply-tag", - "5.0", - "+reply client tag", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "reply-tag", + "5.0", + "+reply client tag", + "UnrealIRCd Team", + "unrealircd-6", +}; int replytag_mtag_is_ok(Client *client, const char *name, const char *value); void mtag_add_replytag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature); diff --git a/src/modules/reputation.c b/src/modules/reputation.c index 7cbd7b03e..4960d3a47 100644 --- a/src/modules/reputation.c +++ b/src/modules/reputation.c @@ -43,29 +43,28 @@ * 3MB, so not big, which likely means the timing will be similar * for a broad number of (storage) systems. */ - + #ifndef TEST - #define BUMP_SCORE_EVERY 300 - #define DELETE_OLD_EVERY 605 - #define SAVE_DB_EVERY 902 + #define BUMP_SCORE_EVERY 300 + #define DELETE_OLD_EVERY 605 + #define SAVE_DB_EVERY 902 #else - #define BUMP_SCORE_EVERY 3 - #define DELETE_OLD_EVERY 3 - #define SAVE_DB_EVERY 3 + #define BUMP_SCORE_EVERY 3 + #define DELETE_OLD_EVERY 3 + #define SAVE_DB_EVERY 3 #endif #ifndef CALLBACKTYPE_REPUTATION_STARTTIME #define CALLBACKTYPE_REPUTATION_STARTTIME 5 #endif -ModuleHeader MOD_HEADER - = { - "reputation", - REPUTATION_VERSION, - "Known IP's scoring system", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "reputation", + REPUTATION_VERSION, + "Known IP's scoring system", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Defines */ @@ -77,24 +76,27 @@ ModuleHeader MOD_HEADER #define REPUTATION_HASH_TABLE_SIZE 2048 -#define Reputation(client) moddata_client(client, reputation_md).l +#define Reputation(client) moddata_client(client, reputation_md).l #define WARN_WRITE_ERROR(fname) \ - do { \ + do \ + { \ unreal_log(ULOG_ERROR, "reputation", "REPUTATION_FILE_WRITE_ERROR", NULL, \ - "[reputation] Error writing to temporary database file $filename: $system_error", \ - log_data_string("filename", fname), \ - log_data_string("system_error", unrealdb_get_error_string())); \ - } while(0) + "[reputation] Error writing to temporary database file $filename: $system_error", \ + log_data_string("filename", fname), \ + log_data_string("system_error", unrealdb_get_error_string())); \ + } while (0) #define W_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ WARN_WRITE_ERROR(tmpfname); \ unrealdb_close(db); \ return 0; \ } \ - } while(0) + } while (0) /* Definitions (structs, etc.) */ @@ -202,8 +204,8 @@ MOD_INIT() HookAdd(modinfo->handle, HOOKTYPE_PRE_LOCAL_CONNECT, 2000000000, reputation_pre_lconnect); /* (prio: last) */ HookAdd(modinfo->handle, HOOKTYPE_REMOTE_CONNECT, -1000000000, reputation_set_on_connect); /* (prio: near-first) */ HookAdd(modinfo->handle, HOOKTYPE_CONNECT_EXTINFO, 0, reputation_connect_extinfo); /* (prio: near-first) */ - CommandAdd(ModInf.handle, "REPUTATION", reputation_cmd, MAXPARA, CMD_USER|CMD_SERVER); - CommandAdd(ModInf.handle, "REPUTATIONUNPERM", reputationunperm, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(ModInf.handle, "REPUTATION", reputation_cmd, MAXPARA, CMD_USER | CMD_SERVER); + CommandAdd(ModInf.handle, "REPUTATIONUNPERM", reputationunperm, MAXPARA, CMD_USER | CMD_SERVER); return MOD_SUCCESS; } @@ -219,8 +221,8 @@ void reputation_benchmark(int entries) for (i = 0; i < entries; i++) { ReputationEntry *e = safe_alloc(sizeof(ReputationEntry) + 64); - snprintf(e->ip, 63, "%d.%d.%d.%d", rand()%255, rand()%255, rand()%255, rand()%255); - e->score = rand()%255 + 1; + snprintf(e->ip, 63, "%d.%d.%d.%d", rand() % 255, rand() % 255, rand() % 255, rand() % 255); + e->score = rand() % 255 + 1; e->last_seen = TStime(); if (find_reputation_entry(e->ip)) { @@ -236,9 +238,9 @@ MOD_LOAD() reputation_load_db(); if (reputation_starttime == 0) reputation_starttime = TStime(); - EventAdd(ModInf.handle, "delete_old_records", delete_old_records, NULL, DELETE_OLD_EVERY*1000, 0); - EventAdd(ModInf.handle, "add_scores", add_scores, NULL, BUMP_SCORE_EVERY*1000, 0); - EventAdd(ModInf.handle, "reputation_save_db", reputation_save_db_evt, NULL, SAVE_DB_EVERY*1000, 0); + EventAdd(ModInf.handle, "delete_old_records", delete_old_records, NULL, DELETE_OLD_EVERY * 1000, 0); + EventAdd(ModInf.handle, "add_scores", add_scores, NULL, BUMP_SCORE_EVERY * 1000, 0); + EventAdd(ModInf.handle, "reputation_save_db", reputation_save_db_evt, NULL, SAVE_DB_EVERY * 1000, 0); #ifdef BENCHMARK reputation_benchmark(10000); #endif @@ -264,19 +266,19 @@ void reputation_config_setdefaults(struct cfgstruct *cfg) /* <=2 points after 1 hour */ cfg->expire_score[0] = 2; #ifndef TEST - cfg->expire_time[0] = 3600; + cfg->expire_time[0] = 3600; #else - cfg->expire_time[0] = 36; + cfg->expire_time[0] = 36; #endif /* <=6 points after 7 days */ cfg->expire_score[1] = 6; - cfg->expire_time[1] = 86400*7; + cfg->expire_time[1] = 86400 * 7; /* <=12 points after 30 days */ cfg->expire_score[2] = 12; - cfg->expire_time[2] = 86400*30; + cfg->expire_time[2] = 86400 * 30; /* ANY result that has not been seen for 90 days */ cfg->expire_score[3] = -1; - cfg->expire_time[3] = 86400*90; + cfg->expire_time[3] = 86400 * 90; /* The 'require' settings */ cfg->require_minimum_channel_members = 3; @@ -305,24 +307,20 @@ int reputation_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!strcmp(cep->name, "score-bump-timer") || !strcmp(cep->name, "target")) { config_error("%s:%i: this feature is not implemented yet in this UnrealIRCd version", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; - } else - if (!cep->value) + } else if (!cep->value) { config_error("%s:%i: blank set::reputation::%s without value", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "score-bump-timer-minimum-channel-members")) + } else if (!strcmp(cep->name, "score-bump-timer-minimum-channel-members")) { - } else - if (!strcmp(cep->name, "database")) + } else if (!strcmp(cep->name, "database")) { convert_to_absolute_path(&cep->value, PERMDATADIR); safe_strdup(test.database, cep->value); - } else - if (!strcmp(cep->name, "db-secret")) + } else if (!strcmp(cep->name, "db-secret")) { const char *err; if ((err = unrealdb_test_secret(cep->value))) @@ -335,7 +333,7 @@ int reputation_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } else { config_error("%s:%i: unknown directive set::reputation::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } @@ -361,12 +359,10 @@ int reputation_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "score-bump-timer-minimum-channel-members")) { cfg.require_minimum_channel_members = atoi(cep->value); - } else - if (!strcmp(cep->name, "database")) + } else if (!strcmp(cep->name, "database")) { safe_strdup(cfg.database, cep->value); - } else - if (!strcmp(cep->name, "db-secret")) + } else if (!strcmp(cep->name, "db-secret")) { safe_strdup(cfg.db_secret, cep->value); } @@ -392,8 +388,8 @@ int reputation_config_posttest(int *errs) /** Parse database header and set variables appropriately */ int parse_db_header_old(char *buf) { - char *header=NULL, *version=NULL, *starttime=NULL, *writtentime=NULL; - char *p=NULL; + char *header = NULL, *version = NULL, *starttime = NULL, *writtentime = NULL; + char *p = NULL; if (strncmp(buf, "REPDB", 5)) return 0; @@ -463,7 +459,7 @@ void reputation_load_db_old(void) return; } - while(fgets(buf, 512, fd) != NULL) + while (fgets(buf, 512, fd) != NULL) { char *ip = NULL, *score = NULL, *last_seen = NULL; ReputationEntry *e; @@ -480,7 +476,7 @@ void reputation_load_db_old(void) if (!last_seen) continue; - e = safe_alloc(sizeof(ReputationEntry)+strlen(ip)+1); + e = safe_alloc(sizeof(ReputationEntry) + strlen(ip) + 1); strcpy(e->ip, ip); /* safe, see alloc above */ e->score = atoi(score); e->last_seen = atol(last_seen); @@ -498,14 +494,16 @@ void reputation_load_db_old(void) } #define R_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ config_warn("[reputation] Read error from database file '%s' (possible corruption): %s", cfg.database, unrealdb_get_error_string()); \ unrealdb_close(db); \ safe_free(ip); \ return 0; \ } \ - } while(0) + } while (0) int reputation_load_db_new(UnrealDB *db) { @@ -540,13 +538,13 @@ int reputation_load_db_new(UnrealDB *db) reputation_starttime = l_starttime; reputation_writtentime = l_writtentime; - for (i=0; i < count; i++) + for (i = 0; i < count; i++) { R_SAFE(unrealdb_read_str(db, &ip)); R_SAFE(unrealdb_read_int16(db, &score)); R_SAFE(unrealdb_read_int64(db, &last_seen)); - e = safe_alloc(sizeof(ReputationEntry)+strlen(ip)+1); + e = safe_alloc(sizeof(ReputationEntry) + strlen(ip) + 1); strcpy(e->ip, ip); /* safe, see alloc above */ e->score = score; e->last_seen = last_seen; @@ -607,8 +605,7 @@ int reputation_load_db(void) /* Database does not exist. Could be first boot */ config_warn("[reputation] No database present at '%s', will start a new one", cfg.database); return 1; - } else - if (unrealdb_get_error_code() == UNREALDB_ERROR_NOTCRYPTED) + } else if (unrealdb_get_error_code() == UNREALDB_ERROR_NOTCRYPTED) { db = unrealdb_open(cfg.database, UNREALDB_MODE_READ, NULL); } @@ -652,7 +649,7 @@ int reputation_save_db_old(void) { if (fprintf(fd, "%s %d %lld\n", e->ip, (int)e->score, (long long)e->last_seen) < 0) { -write_fail: + write_fail: config_error("ERROR writing to '%s': %s -- DATABASE *NOT* SAVED!!!", tmpfname, strerror(ERRNO)); fclose(fd); return 0; @@ -676,7 +673,7 @@ write_fail: if (rename(tmpfname, cfg.database) < 0) { config_error("ERROR renaming '%s' to '%s': %s -- DATABASE *NOT* SAVED!!!", - tmpfname, cfg.database, strerror(ERRNO)); + tmpfname, cfg.database, strerror(ERRNO)); return 0; } @@ -762,7 +759,7 @@ int reputation_save_db(void) if (rename(tmpfname, cfg.database) < 0) { config_error("ERROR renaming '%s' to '%s': %s -- DATABASE *NOT* SAVED!!!", - tmpfname, cfg.database, strerror(ERRNO)); + tmpfname, cfg.database, strerror(ERRNO)); return 0; } @@ -871,8 +868,8 @@ EVENT(add_scores) /* These macros make the code below easier to read. Also, * this explains why we just did marker+=2 and not marker++. */ - #define MARKER_UNREGISTERED_USER (marker) - #define MARKER_REGISTERED_USER (marker+1) +#define MARKER_UNREGISTERED_USER (marker) +#define MARKER_REGISTERED_USER (marker + 1) list_for_each_entry(client, &client_list, client_node) { @@ -896,7 +893,7 @@ EVENT(add_scores) if (!e) { /* Create */ - e = safe_alloc(sizeof(ReputationEntry)+strlen(ip)+1); + e = safe_alloc(sizeof(ReputationEntry) + strlen(ip) + 1); strcpy(e->ip, ip); /* safe, allocated above */ add_reputation_entry(e); } @@ -916,8 +913,7 @@ EVENT(add_scores) e->marker = MARKER_REGISTERED_USER; } } - } else - if ((e->marker == MARKER_UNREGISTERED_USER) && IsLoggedIn(client) && (e->score < REPUTATION_SCORE_CAP)) + } else if ((e->marker == MARKER_UNREGISTERED_USER) && IsLoggedIn(client) && (e->score < REPUTATION_SCORE_CAP)) { /* This is to catch a special case: * If there are 2 or more users with the same IP @@ -942,7 +938,7 @@ EVENT(add_scores) * Ah well, it is a cache, not some precise thingy. */ if (!IsLoggedIn(client) && known_users && - ((e->score == known_users->reputation_score) || (e->score == known_users->reputation_score+1))) + ((e->score == known_users->reputation_score) || (e->score == known_users->reputation_score + 1))) { update_known_user_cache(client); } @@ -962,7 +958,8 @@ static inline int is_reputation_expired(ReputationEntry *e) /* For -1 it means ANY score will expire after this time.. */ if (TStime() - e->last_seen > cfg.expire_time[i]) return 1; - } else { + } else + { /* Otherwise we only expire if the score is less than */ if ((e->score <= cfg.expire_score[i]) && (TStime() - e->last_seen > cfg.expire_time[i])) return 1; @@ -1081,8 +1078,8 @@ void reputation_channel_query(Client *client, Channel *channel) sendtxtnumeric(client, "Users and reputation scores for %s:", channel->name); /* Step 1: build a list of nicks and their reputation */ - nicks = safe_alloc((channel->users+1) * sizeof(char *)); - scores = safe_alloc((channel->users+1) * sizeof(int)); + nicks = safe_alloc((channel->users + 1) * sizeof(char *)); + scores = safe_alloc((channel->users + 1) * sizeof(int)); for (m = channel->members; m; m = m->next) { nicks[cnt] = m->client->name; @@ -1095,10 +1092,10 @@ void reputation_channel_query(Client *client, Channel *channel) if (++cnt > channel->users) { unreal_log(ULOG_WARNING, "bug", "REPUTATION_CHANNEL_QUERY_BUG", client, - "[BUG] reputation_channel_query() expected $expected_users users, but $found_users (or more) users were present in $channel", - log_data_integer("expected_users", channel->users), - log_data_integer("found_users", cnt), - log_data_string("channel", channel->name)); + "[BUG] reputation_channel_query() expected $expected_users users, but $found_users (or more) users were present in $channel", + log_data_integer("expected_users", channel->users), + log_data_integer("found_users", cnt), + log_data_string("channel", channel->name)); #ifdef DEBUGMODE abort(); #endif @@ -1109,7 +1106,7 @@ void reputation_channel_query(Client *client, Channel *channel) /* Step 2: lazy selection sort */ for (i = 0; i < cnt && nicks[i]; i++) { - for (j = i+1; j < cnt && nicks[j]; j++) + for (j = i + 1; j < cnt && nicks[j]; j++) { if (scores[i] < scores[j]) { @@ -1130,11 +1127,12 @@ void reputation_channel_query(Client *client, Channel *channel) for (i = 0; i < cnt && nicks[i]; i++) { snprintf(tbuf, sizeof(tbuf), "%s\00314(%d)\003 ", nicks[i], scores[i]); - if ((strlen(tbuf)+strlen(buf) > 400) || !nicks[i+1]) + if ((strlen(tbuf) + strlen(buf) > 400) || !nicks[i + 1]) { sendtxtnumeric(client, "%s%s", buf, tbuf); *buf = '\0'; - } else { + } else + { strlcat(buf, tbuf, sizeof(buf)); } } @@ -1163,11 +1161,11 @@ void reputation_list_query(Client *client, int maxscore) if (score >= maxscore) continue; sendtxtnumeric(client, "%s!%s@%s [%s] \017(score: %d)", - target->name, - target->user->username, - target->user->realhost, - target->ip, - score); + target->name, + target->user->username, + target->user->realhost, + target->ip, + score); } sendtxtnumeric(client, "End of list."); } @@ -1187,14 +1185,15 @@ CMD_FUNC(reputation_user_cmd) { sendnotice(client, "Reputation module statistics:"); sendnotice(client, "Recording for: %lld seconds (since unixtime %lld)", - (long long)(TStime() - reputation_starttime), - (long long)reputation_starttime); + (long long)(TStime() - reputation_starttime), + (long long)reputation_starttime); if (reputation_writtentime) { sendnotice(client, "Last successful db write: %lld seconds ago (unixtime %lld)", - (long long)(TStime() - reputation_writtentime), - (long long)reputation_writtentime); - } else { + (long long)(TStime() - reputation_writtentime), + (long long)reputation_writtentime); + } else + { sendnotice(client, "Last successful db write: never"); } sendnotice(client, "Current number of records (IP's): %d", count_reputation_records()); @@ -1212,8 +1211,7 @@ CMD_FUNC(reputation_user_cmd) if (strchr(parv[1], '.') || strchr(parv[1], ':')) { ip = parv[1]; - } else - if (parv[1][0] == '#') + } else if (parv[1][0] == '#') { Channel *channel = find_channel(parv[1]); if (!channel) @@ -1222,15 +1220,14 @@ CMD_FUNC(reputation_user_cmd) return; } /* corner case: ircop without proper permissions and not in channel */ - if (!ValidatePermissionsForPath("channel:see:names:invisible",client,NULL,NULL,NULL) && !IsMember(client,channel)) + if (!ValidatePermissionsForPath("channel:see:names:invisible", client, NULL, NULL, NULL) && !IsMember(client, channel)) { sendnumeric(client, ERR_NOTONCHANNEL, channel->name); return; } reputation_channel_query(client, channel); return; - } else - if (parv[1][0] == '<') + } else if (parv[1][0] == '<') { int max = atoi(parv[1] + 1); if (max < 1) @@ -1240,7 +1237,8 @@ CMD_FUNC(reputation_user_cmd) } reputation_list_query(client, max); return; - } else { + } else + { Client *target = find_user(parv[1], NULL); if (!target) { @@ -1265,7 +1263,7 @@ CMD_FUNC(reputation_user_cmd) if ((parc > 2) && !BadPtr(parv[2])) { /* Request to change value */ - if (!ValidatePermissionsForPath("client:set:reputation",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("client:set:reputation", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -1278,10 +1276,10 @@ CMD_FUNC(reputation_user_cmd) e->score = v; reputation_changed_update_users(e); sendto_server(&me, 0, 0, NULL, - ":%s REPUTATION %s *%d*", - me.id, - e->ip, - e->score); + ":%s REPUTATION %s *%d*", + me.id, + e->ip, + e->score); sendnotice(client, "Reputation of IP %s set to %hd", e->ip, e->score); return; } @@ -1290,8 +1288,8 @@ CMD_FUNC(reputation_user_cmd) sendnotice(client, "Reputation record for IP %s:", ip); sendnotice(client, " Score: %hd", e->score); sendnotice(client, "Last seen: %lld seconds ago (unixtime: %lld)", - (long long)(TStime() - e->last_seen), - (long long)e->last_seen); + (long long)(TStime() - e->last_seen), + (long long)e->last_seen); sendnotice(client, "****************************************************"); } @@ -1349,10 +1347,11 @@ CMD_FUNC(reputation_server_cmd) if (parv[2][0] == '*') { allow_reply = 0; - score = atoi(parv[2]+1); - if (parv[2][1] && (parv[2][strlen(parv[2])-1] == '*')) + score = atoi(parv[2] + 1); + if (parv[2][1] && (parv[2][strlen(parv[2]) - 1] == '*')) forced = 1; - } else { + } else + { allow_reply = 1; score = atoi(parv[2]); } @@ -1371,10 +1370,10 @@ CMD_FUNC(reputation_server_cmd) sendto_one(client, NULL, ":%s REPUTATION %s *%d", me.id, parv[1], e->score); #ifdef DEBUGMODE unreal_log(ULOG_DEBUG, "reputation", "REPUTATION_DIFFERS", client, - "Reputation score for for $ip from $client is $their_score, but we have $score, sending back $score", - log_data_string("ip", ip), - log_data_integer("their_score", score), - log_data_integer("score", e->score)); + "Reputation score for for $ip from $client is $their_score, but we have $score, sending back $score", + log_data_string("ip", ip), + log_data_integer("their_score", score), + log_data_integer("score", e->score)); #endif score = e->score; /* Update for propagation in the non-client direction */ } @@ -1384,22 +1383,21 @@ CMD_FUNC(reputation_server_cmd) { #ifdef DEBUGMODE unreal_log(ULOG_DEBUG, "reputation", "REPUTATION_DIFFERS", client, - "Reputation score for for $ip from $client is $their_score, but we have $score, updating our score to $score", - log_data_string("ip", ip), - log_data_integer("their_score", score), - log_data_integer("score", e->score)); + "Reputation score for for $ip from $client is $their_score, but we have $score, updating our score to $score", + log_data_string("ip", ip), + log_data_integer("their_score", score), + log_data_integer("score", e->score)); #endif e->score = score; reputation_changed_update_users(e); - } else - if (e && forced) + } else if (e && forced) { #ifdef DEBUGMODE unreal_log(ULOG_DEBUG, "reputation", "REPUTATION_DECREASE", client, - "Reputation score for for $ip from $client is $score, force-setting to $their_score.", - log_data_string("ip", ip), - log_data_integer("their_score", score), - log_data_integer("score", e->score)); + "Reputation score for for $ip from $client is $score, force-setting to $their_score.", + log_data_string("ip", ip), + log_data_integer("their_score", score), + log_data_integer("score", e->score)); #endif e->score = score; reputation_changed_update_users(e); @@ -1410,12 +1408,12 @@ CMD_FUNC(reputation_server_cmd) { #ifdef DEBUGMODE unreal_log(ULOG_DEBUG, "reputation", "REPUTATION_NEW", client, - "Reputation score for for $ip from $client is $their_score, we had no entry, adding it", - log_data_string("ip", ip), - log_data_integer("their_score", score), - log_data_integer("score", 0)); + "Reputation score for for $ip from $client is $their_score, we had no entry, adding it", + log_data_string("ip", ip), + log_data_integer("their_score", score), + log_data_integer("score", 0)); #endif - e = safe_alloc(sizeof(ReputationEntry)+strlen(ip)+1); + e = safe_alloc(sizeof(ReputationEntry) + strlen(ip) + 1); strcpy(e->ip, ip); /* safe, see alloc above */ e->score = score; e->last_seen = TStime(); @@ -1514,7 +1512,7 @@ void _ban_act_set_reputation(Client *client, BanAction *action) if (!e) { /* Create */ - e = safe_alloc(sizeof(ReputationEntry)+strlen(client->ip)+1); + e = safe_alloc(sizeof(ReputationEntry) + strlen(client->ip) + 1); strcpy(e->ip, client->ip); /* safe, allocated above */ add_reputation_entry(e); } diff --git a/src/modules/require-module.c b/src/modules/require-module.c index ab80469a8..bbdabc147 100644 --- a/src/modules/require-module.c +++ b/src/modules/require-module.c @@ -20,17 +20,17 @@ #include "unrealircd.h" -#define MSG_SMOD "SMOD" +#define MSG_SMOD "SMOD" #define SMOD_FLAG_REQUIRED 'R' -#define SMOD_FLAG_GLOBAL 'G' -#define SMOD_FLAG_LOCAL 'L' +#define SMOD_FLAG_GLOBAL 'G' +#define SMOD_FLAG_LOCAL 'L' ModuleHeader MOD_HEADER = { - "require-module", - "5.0.1", - "Require/deny modules across the network", - "UnrealIRCd Team", - "unrealircd-6", + "require-module", + "5.0.1", + "Require/deny modules across the network", + "UnrealIRCd Team", + "unrealircd-6", }; typedef struct _denymod DenyMod; @@ -278,7 +278,7 @@ int reqmods_configrun_deny(ConfigFile *cf, ConfigEntry *ce, int type) // Just use a default reason if none was specified (since it's optional) if (!dmod->reason || !strlen(dmod->reason)) - safe_strdup(dmod->reason, "no reason"); + safe_strdup(dmod->reason, "no reason"); AddListItem(dmod, DenyModList); return 1; } @@ -431,7 +431,7 @@ CMD_FUNC(cmd_smod) if (!p) continue; /* malformed request */ modflag = *modbuf; // Get the module flag (FIXME: parses only first letter atm) - modbuf = p+1; + modbuf = p + 1; strlcpy(name, modbuf, sizeof(name)); // Let's work on a copy of the param version = strchr(name, ':'); @@ -468,8 +468,7 @@ CMD_FUNC(cmd_smod) log_data_client("me", &me), log_data_string("module_name", name)); abort = 1; // Always SQUIT here too (explicitly required by admins) - } - else if (modflag == 'G') + } else if (modflag == 'G') { unreal_log(ULOG_WARNING, "link", "LINK_MISSING_GLOBAL_MODULE", client, "Server $me is missing module '$module_name', which is " diff --git a/src/modules/restrict-commands.c b/src/modules/restrict-commands.c index 29c733702..bd43135fd 100644 --- a/src/modules/restrict-commands.c +++ b/src/modules/restrict-commands.c @@ -20,11 +20,11 @@ #include "unrealircd.h" ModuleHeader MOD_HEADER = { - "restrict-commands", - "1.0.2", - "Restrict specific commands unless certain conditions have been met", - "UnrealIRCd Team", - "unrealircd-6", + "restrict-commands", + "1.0.2", + "Restrict specific commands unless certain conditions have been met", + "UnrealIRCd Team", + "unrealircd-6", }; typedef struct RestrictedCommand RestrictedCommand; @@ -57,13 +57,13 @@ CMD_OVERRIDE_FUNC(rcmd_override); static ModuleInfo ModInf; RestrictedCommand *RestrictedCommandList = NULL; CmdMap conf_cmdmaps[] = { - // These are special cases in which we can't override the command, so they are handled through hooks instead - { "channel-message", "PRIVMSG" }, - { "channel-notice", "NOTICE" }, - { "channel-create", "JOIN" }, - { "private-message", "PRIVMSG" }, - { "private-notice", "NOTICE" }, - { NULL, NULL }, // REQUIRED for the loop to properly work + // These are special cases in which we can't override the command, so they are handled through hooks instead + {"channel-message", "PRIVMSG"}, + {"channel-notice", "NOTICE"}, + {"channel-create", "JOIN"}, + {"private-message", "PRIVMSG"}, + {"private-notice", "NOTICE"}, + {NULL, NULL}, // REQUIRED for the loop to properly work }; MOD_TEST() @@ -112,7 +112,8 @@ MOD_UNLOAD() return MOD_SUCCESS; } -const char *find_cmd_byconftag(const char *conftag) { +const char *find_cmd_byconftag(const char *conftag) +{ CmdMap *cmap; for (cmap = conf_cmdmaps; cmap->conftag; cmap++) { @@ -122,7 +123,8 @@ const char *find_cmd_byconftag(const char *conftag) { return NULL; } -RestrictedCommand *find_restrictions_bycmd(const char *cmd) { +RestrictedCommand *find_restrictions_bycmd(const char *cmd) +{ RestrictedCommand *rcmd; for (rcmd = RestrictedCommandList; rcmd; rcmd = rcmd->next) { @@ -132,7 +134,8 @@ RestrictedCommand *find_restrictions_bycmd(const char *cmd) { return NULL; } -RestrictedCommand *find_restrictions_byconftag(const char *conftag) { +RestrictedCommand *find_restrictions_byconftag(const char *conftag) +{ RestrictedCommand *rcmd; for (rcmd = RestrictedCommandList; rcmd; rcmd = rcmd->next) { @@ -166,7 +169,7 @@ int rcmd_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!warn_disable) { config_warn("Simply remove 'disable yes;' from the configuration file and " - "it will have the same effect without it (will disable the command)."); + "it will have the same effect without it (will disable the command)."); warn_disable = 1; } continue; @@ -373,12 +376,13 @@ int rcmd_block_message(Client *client, const char *destination, const char *text if (rcmd->except->connect_time) { ircsnprintf(errbuf, sizeof(errbuf), - "You cannot send %ss to %ss until you've been connected for %ld seconds or more", - (notice ? "notice" : "message"), display, rcmd->except->connect_time); - } else { + "You cannot send %ss to %ss until you've been connected for %ld seconds or more", + (notice ? "notice" : "message"), display, rcmd->except->connect_time); + } else + { ircsnprintf(errbuf, sizeof(errbuf), - "Sending of %ss to %ss been disabled by the network administrators", - (notice ? "notice" : "message"), display); + "Sending of %ss to %ss been disabled by the network administrators", + (notice ? "notice" : "message"), display); } *errmsg = errbuf; return 1; @@ -410,7 +414,8 @@ CMD_OVERRIDE_FUNC(rcmd_override) sendnumericfmt(client, ERR_UNKNOWNCOMMAND, "%s :You must be connected for at least %ld seconds before you can use this command", ovr->command->cmd, rcmd->except->connect_time); - } else { + } else + { sendnumericfmt(client, ERR_UNKNOWNCOMMAND, "%s :This command is disabled by the network administrator", ovr->command->cmd); @@ -461,10 +466,11 @@ int rcmd_block_join(Client *client, Channel *channel, const char **errmsg) if (rcmd->except->connect_time) { ircsnprintf(errbuf, sizeof(errbuf), - "You cannot create new channels until you have been connected for %ld seconds or more.", rcmd->except->connect_time); - } else { + "You cannot create new channels until you have been connected for %ld seconds or more.", rcmd->except->connect_time); + } else + { ircsnprintf(errbuf, sizeof(errbuf), - "Creation of new channels has been restricted by the network administrator."); + "Creation of new channels has been restricted by the network administrator."); } *errmsg = errbuf; return 1; diff --git a/src/modules/rmtkl.c b/src/modules/rmtkl.c index bb25ddb15..8061b5db3 100644 --- a/src/modules/rmtkl.c +++ b/src/modules/rmtkl.c @@ -20,14 +20,14 @@ #include "unrealircd.h" ModuleHeader MOD_HEADER = { - "rmtkl", - "1.4", - "Adds /rmtkl command to easily remove *-Lines in bulk", - "Gottem and the UnrealIRCd Team", - "unrealircd-6", + "rmtkl", + "1.4", + "Adds /rmtkl command to easily remove *-Lines in bulk", + "Gottem and the UnrealIRCd Team", + "unrealircd-6", }; -#define IsParam(x) (parc > (x) && !BadPtr(parv[(x)])) +#define IsParam(x) (parc > (x) && !BadPtr(parv[(x)])) #define IsNotParam(x) (parc <= (x) || BadPtr(parv[(x)])) typedef struct { @@ -44,37 +44,37 @@ int rmtkl_tryremove(Client *client, TKLType *tkltype, TKL *tkl, const char *uhma CMD_FUNC(rmtkl); TKLType tkl_types[] = { - { TKL_KILL, 'k', "K-Line", "server-ban:kline:remove" }, - { TKL_ZAP, 'z', "Z-Line", "server-ban:zline:local:remove" }, - { TKL_KILL | TKL_GLOBAL, 'G', "G-Line", "server-ban:gline:remove" }, - { TKL_ZAP | TKL_GLOBAL, 'Z', "Global Z-Line", "server-ban:zline:global:remove" }, - { TKL_SHUN | TKL_GLOBAL, 's', "Shun", "server-ban:shun:remove" }, + {TKL_KILL, 'k', "K-Line", "server-ban:kline:remove"}, + {TKL_ZAP, 'z', "Z-Line", "server-ban:zline:local:remove"}, + {TKL_KILL | TKL_GLOBAL, 'G', "G-Line", "server-ban:gline:remove"}, + {TKL_ZAP | TKL_GLOBAL, 'Z', "Global Z-Line", "server-ban:zline:global:remove"}, + {TKL_SHUN | TKL_GLOBAL, 's', "Shun", "server-ban:shun:remove"}, // { TKL_SPAMF | TKL_GLOBAL, 'F', "Global Spamfilter", "server-ban:spamfilter:remove" }, TODO: re-add spamfilter support - { 0, 0, "Unknown *-Line", 0 }, + {0, 0, "Unknown *-Line", 0}, }; static const char *rmtkl_help[] = { - "*** \002Help on /rmtkl\002 *** ", - "Removes all TKLs matching the given conditions from the local server, or the entire", - "network if it's a global-type ban.", - "Syntax:", - " \002/rmtkl\002 \037user@host\037 \037type\037 [\037comment\037] [\037-skipperm\037] [\037-silent\037]", - "The \037user@host\037 field is a wildcard mask to match the target of a ban.", - "The \037type\037 field may contain any number of the following characters:", - " k, z, G, Z, s, F and *", - " These correspond to (local) K-Line, (local) Z-Line, G-Line, Global Z-Line, (global) Shun and (global) Spamfilter", - " (asterisk includes every type besides F)", - "The \037comment\037 field is also a wildcard mask to match the reason text of a ban. If specified, it must always", - "come \037before\037 the options starting with \002-\002.", - "Examples:", - " - \002/rmtkl * *\002", - " [remove \037all\037 supported TKLs except spamfilters]", - " - \002/rmtkl *@*.mx GZ\002 * -skipperm", - " [remove all Mexican G/Z-Lines while skipping over permanent ones]", + "*** \002Help on /rmtkl\002 *** ", + "Removes all TKLs matching the given conditions from the local server, or the entire", + "network if it's a global-type ban.", + "Syntax:", + " \002/rmtkl\002 \037user@host\037 \037type\037 [\037comment\037] [\037-skipperm\037] [\037-silent\037]", + "The \037user@host\037 field is a wildcard mask to match the target of a ban.", + "The \037type\037 field may contain any number of the following characters:", + " k, z, G, Z, s, F and *", + " These correspond to (local) K-Line, (local) Z-Line, G-Line, Global Z-Line, (global) Shun and (global) Spamfilter", + " (asterisk includes every type besides F)", + "The \037comment\037 field is also a wildcard mask to match the reason text of a ban. If specified, it must always", + "come \037before\037 the options starting with \002-\002.", + "Examples:", + " - \002/rmtkl * *\002", + " [remove \037all\037 supported TKLs except spamfilters]", + " - \002/rmtkl *@*.mx GZ\002 * -skipperm", + " [remove all Mexican G/Z-Lines while skipping over permanent ones]", /* " - \002/rmtkl * * *Zombie*\002", " [remove all non-spamfilter bans having \037Zombie\037 in the reason field]", TODO: re-add spamfilter support */ - "*** \002End of help\002 ***", - NULL, + "*** \002End of help\002 ***", + NULL, }; MOD_INIT() @@ -126,7 +126,8 @@ static TKLType *find_TKLType_by_flag(char flag) return t; } -void rmtkl_check_options(const char *param, int *skipperm, int *silent) { +void rmtkl_check_options(const char *param, int *skipperm, int *silent) +{ if (!strcasecmp("-skipperm", param)) *skipperm = 1; if (!strcasecmp("-silent", param)) @@ -154,8 +155,7 @@ int rmtkl_tryremove(Client *client, TKLType *tkltype, TKL *tkl, const char *uhma if (!match_simple(uhmask, tkl->reason)) return 0; #endif - } else - if (TKLIsServerBan(tkl)) + } else if (TKLIsServerBan(tkl)) { if (!match_simple(uhmask, make_user_host(tkl->ptr.serverban->usermask, tkl->ptr.serverban->hostmask))) return 0; @@ -261,7 +261,8 @@ CMD_FUNC(rmtkl) sendto_server(NULL, 0, 0, NULL, "%s", broadcast); // Loop over all supported types - for (tkltype = tkl_types; tkltype->type; tkltype++) { + for (tkltype = tkl_types; tkltype->type; tkltype++) + { if (!strchr(types, tkltype->flag)) continue; diff --git a/src/modules/rpc/channel.c b/src/modules/rpc/channel.c index 13559c718..98969767c 100644 --- a/src/modules/rpc/channel.c +++ b/src/modules/rpc/channel.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/channel", - "1.0.5", - "channel.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/channel", + "1.0.5", + "channel.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -100,7 +99,7 @@ void rpc_channel_list(Client *client, json_t *request, json_t *params) list = json_array(); json_object_set_new(result, "list", list); - for (channel = channels; channel; channel=channel->nextch) + for (channel = channels; channel; channel = channel->nextch) { item = json_object(); json_expand_channel(item, NULL, channel, details); @@ -163,7 +162,7 @@ void rpc_channel_set_mode(Client *client, json_t *request, json_t *params) void rpc_channel_set_topic(Client *client, json_t *request, json_t *params) { json_t *result, *item; - const char *channelname, *topic, *set_by=NULL, *str; + const char *channelname, *topic, *set_by = NULL, *str; Channel *channel; time_t set_at = 0; MessageTag *mtags = NULL; diff --git a/src/modules/rpc/log.c b/src/modules/rpc/log.c index 9f99e6bb6..1aaa34a87 100644 --- a/src/modules/rpc/log.c +++ b/src/modules/rpc/log.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/log", - "1.0.2", - "log.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/log", + "1.0.2", + "log.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -231,7 +230,7 @@ void rpc_log_send(Client *client, json_t *request, json_t *params) new_message(&me, NULL, &mtags); - MessageTag *json_mtag = safe_alloc(sizeof(MessageTag)); + MessageTag *json_mtag = safe_alloc(sizeof(MessageTag)); safe_strdup(json_mtag->name, "unrealircd.org/json-log"); safe_strdup(json_mtag->value, serialized); AddListItem(json_mtag, mtags); @@ -239,12 +238,12 @@ void rpc_log_send(Client *client, json_t *request, json_t *params) safe_free(serialized); const char *cmd_params[6] = { - me.name, - level, - subsystem, - event_id, - msg, - NULL, + me.name, + level, + subsystem, + event_id, + msg, + NULL, }; do_cmd(&me, mtags, "SLOG", 5, cmd_params); diff --git a/src/modules/rpc/message.c b/src/modules/rpc/message.c index 08c7c96b6..694186f18 100644 --- a/src/modules/rpc/message.c +++ b/src/modules/rpc/message.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/message", - "1.0.0", - "message.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/message", + "1.0.0", + "message.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; void rpc_send_privmsgnotice(json_t *request, json_t *params, Client *client, int is_notice) @@ -166,7 +165,7 @@ RPC_CALL_FUNC(rpc_message_standardreply) if (context) sendto_one(acptr, NULL, ":%s %s * %s %s :%s", me.name, type, code, context, description); - + else sendto_one(acptr, NULL, ":%s %s * %s :%s", me.name, type, code, description); diff --git a/src/modules/rpc/name_ban.c b/src/modules/rpc/name_ban.c index 2d35b70bf..e6d31736d 100644 --- a/src/modules/rpc/name_ban.c +++ b/src/modules/rpc/name_ban.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/name_ban", - "1.0.1", - "name_ban.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/name_ban", + "1.0.1", + "name_ban.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -167,7 +166,8 @@ RPC_CALL_FUNC(rpc_name_ban_del) if (!my_find_tkl_nameban(name)) { rpc_response(client, request, result); - } else { + } else + { /* Actually this may not be an internal error, it could be an * incorrect request, such as asking to remove a config-based ban. */ @@ -196,8 +196,7 @@ RPC_CALL_FUNC(rpc_name_ban_add) tkl_expire_at = config_checkval(str, CFG_TIME); if (tkl_expire_at > 0) tkl_expire_at = TStime() + tkl_expire_at; - } else - if ((str = json_object_get_string(params, "expire_at"))) + } else if ((str = json_object_get_string(params, "expire_at"))) { tkl_expire_at = server_time_to_unix_time(str); } else @@ -222,7 +221,7 @@ RPC_CALL_FUNC(rpc_name_ban_add) return; } - tkl = tkl_add_nameban(TKL_NAME|TKL_GLOBAL, name, 0, reason, + tkl = tkl_add_nameban(TKL_NAME | TKL_GLOBAL, name, 0, reason, set_by, tkl_expire_at, tkl_set_at, 0); diff --git a/src/modules/rpc/rpc.c b/src/modules/rpc/rpc.c index fec689d85..8077f05c1 100644 --- a/src/modules/rpc/rpc.c +++ b/src/modules/rpc/rpc.c @@ -3,28 +3,27 @@ * (C)Copyright 2022 Bram Matthys and the UnrealIRCd team * License: GPLv2 or later */ - + #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "rpc/rpc", - "1.0.5", - "RPC module for remote management", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "rpc/rpc", + "1.0.5", + "RPC module for remote management", + "UnrealIRCd Team", + "unrealircd-6", +}; /** Maximum length of an rpc-user THIS { }. * As we use the "RPC:" prefix it is nicklen minus that. */ -#define RPCUSERLEN (NICKLEN-4) +#define RPCUSERLEN (NICKLEN - 4) /** Timers can be minimum every msec */ #define RPC_MINIMUM_TIMER_MSEC 250 -#define RRPC_PACKET_SMALL 450 -#define RRPC_PACKET_BIGLINES 16000 +#define RRPC_PACKET_SMALL 450 +#define RRPC_PACKET_BIGLINES 16000 /* Structs */ typedef struct RPCUser RPCUser; @@ -40,8 +39,8 @@ typedef struct RRPC RRPC; struct RRPC { RRPC *prev, *next; int request; - char source[IDLEN+1]; - char destination[IDLEN+1]; + char source[IDLEN + 1]; + char destination[IDLEN + 1]; char *requestid; dbuf data; }; @@ -50,8 +49,8 @@ typedef struct OutstandingRRPC OutstandingRRPC; struct OutstandingRRPC { OutstandingRRPC *prev, *next; time_t sent; - char source[IDLEN+1]; - char destination[IDLEN+1]; + char source[IDLEN + 1]; + char destination[IDLEN + 1]; char *requestid; }; @@ -88,7 +87,7 @@ void rpc_call_text(Client *client, const char *buf, int len); void rpc_call_json(Client *client, json_t *request); void _rpc_response(Client *client, json_t *request, json_t *result); void _rpc_error(Client *client, json_t *request, JsonRpcError error_code, const char *error_message); -void _rpc_error_fmt(Client *client, json_t *request, JsonRpcError error_code, FORMAT_STRING(const char *fmt), ...) __attribute__((format(printf,4,5))); +void _rpc_error_fmt(Client *client, json_t *request, JsonRpcError error_code, FORMAT_STRING(const char *fmt), ...) __attribute__((format(printf, 4, 5))); void _rpc_send_request_to_remote(Client *source, Client *target, json_t *request); void _rpc_send_response_to_remote(Client *source, Client *target, json_t *response); int _rrpc_supported_simple(Client *target, char **problem_server); @@ -119,8 +118,8 @@ void rrpc_md_free(ModData *m); int rpc_config_listener(ConfigItem_listen *listener); /* Macros */ -#define RPC_PORT(client) ((client->local && client->local->listener) ? client->local->listener->rpc_options : 0) -#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) +#define RPC_PORT(client) ((client->local && client->local->listener) ? client->local->listener->rpc_options : 0) +#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) /* Global variables */ ModDataInfo *websocket_md = NULL; /* (imported) */ @@ -146,7 +145,7 @@ MOD_TEST() EfunctionAdd(modinfo->handle, EFUNC_RRPC_SUPPORTED_SIMPLE, _rrpc_supported_simple); /* Call MOD_INIT very early, since we manage sockets, but depend on websocket_common */ - ModuleSetOptions(modinfo->handle, MOD_OPT_PRIORITY, WEBSOCKET_MODULE_PRIORITY_INIT+1); + ModuleSetOptions(modinfo->handle, MOD_OPT_PRIORITY, WEBSOCKET_MODULE_PRIORITY_INIT + 1); return MOD_SUCCESS; } @@ -230,19 +229,19 @@ MOD_INIT() LoadPersistentPointer(modinfo, outstanding_rrpc_list, free_outstanding_rrpc_list); LoadPersistentPointer(modinfo, rpc_timer_list, free_rpc_timer_list); - CommandAdd(modinfo->handle, "RRPC", cmd_rrpc, MAXPARA, CMD_SERVER|CMD_BIGLINES); + CommandAdd(modinfo->handle, "RRPC", cmd_rrpc, MAXPARA, CMD_SERVER | CMD_BIGLINES); EventAdd(modinfo->handle, "rpc_remote_timeout", rpc_remote_timeout, NULL, 1000, 0); EventAdd(modinfo->handle, "rpc_do_timers", rpc_do_timers, NULL, RPC_MINIMUM_TIMER_MSEC, 0); /* Call MOD_LOAD very late, since we manage sockets, but depend on websocket_common */ - ModuleSetOptions(modinfo->handle, MOD_OPT_PRIORITY, WEBSOCKET_MODULE_PRIORITY_UNLOAD-1); + ModuleSetOptions(modinfo->handle, MOD_OPT_PRIORITY, WEBSOCKET_MODULE_PRIORITY_UNLOAD - 1); return MOD_SUCCESS; } -#define MYRRPCMODULES me.moddata[rrpc_md->slot].ptr -#define RRPCMODULES(client) ((NameValuePrioList *)moddata_client(client, rrpc_md).ptr) +#define MYRRPCMODULES me.moddata[rrpc_md->slot].ptr +#define RRPCMODULES(client) ((NameValuePrioList *)moddata_client(client, rrpc_md).ptr) void rpc_do_moddata(void) { @@ -320,7 +319,8 @@ void rpc_listener_set_handler(ConfigItem_listen *l) if (l->socket_type == SOCKET_TYPE_UNIX) { l->start_handshake = rpc_client_handshake_unix_socket; - } else { + } else + { l->options |= LISTENER_TLS; l->start_handshake = rpc_client_handshake_web; l->webserver = safe_alloc(sizeof(WebServer)); @@ -401,26 +401,24 @@ int rpc_config_test_rpc_user(ConfigFile *cf, ConfigEntry *ce, int type, int *err { has_match = 1; test_match_block(cf, cep, &errors); - } else - if (!strcmp(cep->name, "password")) + } else if (!strcmp(cep->name, "password")) { has_password = 1; if (Auth_CheckError(cep, 0) < 0) errors++; - } else - if (!strcmp(cep->name, "rpc-class")) + } else if (!strcmp(cep->name, "rpc-class")) { has_rpc_class = 1; if (!cep->value) { config_error_empty(cep->file->filename, - cep->line_number, "rpc-user", cep->name); + cep->line_number, "rpc-user", cep->name); errors++; } } else { config_error_unknown(cep->file->filename, - cep->line_number, "rpc-user", cep->name); + cep->line_number, "rpc-user", cep->name); errors++; } } @@ -428,14 +426,14 @@ int rpc_config_test_rpc_user(ConfigFile *cf, ConfigEntry *ce, int type, int *err if (!has_match) { config_error_missing(ce->file->filename, ce->line_number, - "rpc-user::mask"); + "rpc-user::mask"); errors++; } if (!has_password) { config_error_missing(ce->file->filename, ce->line_number, - "rpc-user::password"); + "rpc-user::password"); errors++; } @@ -471,12 +469,10 @@ int rpc_config_run_rpc_user(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "match") || !strcmp(cep->name, "mask")) { conf_match_block(cf, cep, &e->match); - } else - if (!strcmp(cep->name, "password")) + } else if (!strcmp(cep->name, "password")) { AuthBlockToAuthConfig(cep, &e->auth); - } else - if (!strcmp(cep->name, "rpc-class")) + } else if (!strcmp(cep->name, "rpc-class")) { safe_strdup(e->rpc_class, cep->value); } @@ -498,8 +494,7 @@ int rpc_config_test_rpc_class(ConfigFile *cf, ConfigEntry *ce, int type, int *er { config_error_noname(ce->file->filename, ce->line_number, "rpc-class"); errors++; - } else - if (!valid_operclass_name(ce->value)) + } else if (!valid_operclass_name(ce->value)) { config_error("%s:%d: rpc-class name may only contain alphanumerical characters and " "characters _-", @@ -514,18 +509,17 @@ int rpc_config_test_rpc_class(ConfigFile *cf, ConfigEntry *ce, int type, int *er if (has_parent) { config_warn_duplicate(cep->file->filename, - cep->line_number, "rpc-class::parent"); + cep->line_number, "rpc-class::parent"); continue; } has_parent = 1; continue; - } else - if (!strcmp(cep->name, "permissions")) + } else if (!strcmp(cep->name, "permissions")) { if (has_permissions) { config_warn_duplicate(cep->file->filename, - cep->line_number, "rpc-class::permissions"); + cep->line_number, "rpc-class::permissions"); continue; } has_permissions = 1; @@ -533,7 +527,7 @@ int rpc_config_test_rpc_class(ConfigFile *cf, ConfigEntry *ce, int type, int *er } else { config_error_unknown(cep->file->filename, - cep->line_number, "rpc-class", cep->name); + cep->line_number, "rpc-class", cep->name); errors++; continue; } @@ -542,7 +536,7 @@ int rpc_config_test_rpc_class(ConfigFile *cf, ConfigEntry *ce, int type, int *er if (!has_permissions) { config_error_missing(ce->file->filename, ce->line_number, - "rpc-class::permissions"); + "rpc-class::permissions"); errors++; } @@ -569,13 +563,12 @@ int rpc_config_run_rpc_class(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "parent")) { safe_strdup(rpc_class->classStruct->ISA, cep->value); - } - else if (!strcmp(cep->name, "permissions")) + } else if (!strcmp(cep->name, "permissions")) { for (cepp = cep->items; cepp; cepp = cepp->next) { - OperClassACL *acl = _conf_parseACL(cepp->name,cepp); - AddListItem(acl,rpc_class->classStruct->acls); + OperClassACL *acl = _conf_parseACL(cepp->name, cepp); + AddListItem(acl, rpc_class->classStruct->acls); } } } @@ -647,7 +640,7 @@ OperPermission ValidatePermissionsForJSONRPC(const char *path, Client *client) operPath = OperClass_parsePath(path); while (oc && operPath) { - OperClassACL *acl = OperClass_FindACL(oc->acls,operPath->identifier); + OperClassACL *acl = OperClass_FindACL(oc->acls, operPath->identifier); if (acl) { OperPermission perm; @@ -666,7 +659,8 @@ OperPermission ValidatePermissionsForJSONRPC(const char *path, Client *client) if (ce_operClass) { oc = ce_operClass->classStruct; - } else { + } else + { break; /* parent not found */ } } @@ -878,7 +872,7 @@ void rpc_sendto(Client *client, const char *buf, int len) if (MyConnect(client) && IsRPC(client) && WSU(client) && WSU(client)->handshake_completed) { /* Websocket */ - int utf8bufsize = len*2 + 16; + int utf8bufsize = len * 2 + 16; char *utf8buf = safe_alloc(utf8bufsize); char *newbuf = unrl_utf8_make_valid(buf, utf8buf, utf8bufsize, 1); int newlen = strlen(newbuf); @@ -888,7 +882,8 @@ void rpc_sendto(Client *client, const char *buf, int len) dbuf_put(&client->local->sendQ, newbuf, newlen); safe_free(ws_sendbuf); safe_free(utf8buf); - } else { + } else + { /* Unix domain socket or HTTP */ dbuf_put(&client->local->sendQ, buf, len); dbuf_put(&client->local->sendQ, "\n", 1); @@ -948,8 +943,8 @@ void _rpc_error(Client *client, json_t *request, JsonRpcError error_code, const #ifdef DEBUGMODE unreal_log(ULOG_DEBUG, "rpc", "RPC_CALL_DEBUG", client, - "[rpc] Client $client: RPC result error: $response", - log_data_string("response", json_serialized)); + "[rpc] Client $client: RPC result error: $response", + log_data_string("response", json_serialized)); #endif json_decref(j); safe_free(json_serialized); @@ -997,8 +992,8 @@ void _rpc_response(Client *client, json_t *request, json_t *result) #ifdef DEBUGMODE unreal_log(ULOG_DEBUG, "rpc", "RPC_CALL_DEBUG", client, - "[rpc] Client $client: RPC response result: $response", - log_data_string("response", json_serialized)); + "[rpc] Client $client: RPC response result: $response", + log_data_string("response", json_serialized)); #endif json_decref(j); safe_free(json_serialized); @@ -1042,8 +1037,7 @@ int sanitize_params(Client *client, json_t *request, json_t *j) if (!sanitize_params(client, request, value)) return 0; } - } else - if (json_is_object(j)) + } else if (json_is_object(j)) { const char *key; json_t *value; @@ -1077,7 +1071,7 @@ void rpc_call_log(Client *client, RPCHandler *handler, json_t *request, const ch } } if (*params_string) - params_string[strlen(params_string)-2] = '\0'; /* cut off last comma */ + params_string[strlen(params_string) - 2] = '\0'; /* cut off last comma */ // TODO: pass log_data_json() or something, pass the entire 'request' ? For JSON logging @@ -1086,27 +1080,30 @@ void rpc_call_log(Client *client, RPCHandler *handler, json_t *request, const ch if (*params_string) { unreal_log(handler->loglevel, "rpc", "RPC_CALL", client, - "[rpc] RPC call $method by $client ($issuer): $params_string", - log_data_string("issuer", client->rpc->issuer), - log_data_string("method", method), - log_data_string("params_string", params_string)); - } else { + "[rpc] RPC call $method by $client ($issuer): $params_string", + log_data_string("issuer", client->rpc->issuer), + log_data_string("method", method), + log_data_string("params_string", params_string)); + } else + { unreal_log(handler->loglevel, "rpc", "RPC_CALL", client, - "[rpc] RPC call $method by $client ($issuer)", - log_data_string("issuer", client->rpc->issuer), - log_data_string("method", method)); + "[rpc] RPC call $method by $client ($issuer)", + log_data_string("issuer", client->rpc->issuer), + log_data_string("method", method)); } - } else { + } else + { if (*params_string) { unreal_log(handler->loglevel, "rpc", "RPC_CALL", client, - "[rpc] RPC call $method by $client: $params_string", - log_data_string("method", method), - log_data_string("params_string", params_string)); - } else { + "[rpc] RPC call $method by $client: $params_string", + log_data_string("method", method), + log_data_string("params_string", params_string)); + } else + { unreal_log(handler->loglevel, "rpc", "RPC_CALL", client, - "[rpc] RPC call $method by $client", - log_data_string("method", method)); + "[rpc] RPC call $method by $client", + log_data_string("method", method)); } } } @@ -1178,7 +1175,7 @@ int parse_rpc_call(Client *client, json_t *mainrequest, json_t *request, const c /* Convert e.g. "server_ban.list" to "server_ban:list" which is used by rpc-class/operclass */ strlcpy(path, *method, sizeof(path)); - for (s=path; *s; s++) + for (s = path; *s; s++) if (*s == '.') *s = ':'; @@ -1226,8 +1223,8 @@ void rpc_call_json(Client *client, json_t *request) if (call) { unreal_log(ULOG_DEBUG, "rpc", "RPC_CALL_DEBUG", client, - "[rpc] Client $client: RPC call: $call", - log_data_string("call", call)); + "[rpc] Client $client: RPC call: $call", + log_data_string("call", call)); safe_free(call); } } @@ -1304,12 +1301,11 @@ int rpc_pre_local_handshake_timeout(Client *client, const char **comment) if (IsRPC(client) && WSU(client) && WSU(client)->handshake_completed) { long t = TStime() - client->local->last_msg_received; - if ((t > RPC_WEBSOCKET_PING_TIME*2) && IsPingSent(client)) + if ((t > RPC_WEBSOCKET_PING_TIME * 2) && IsPingSent(client)) { *comment = "No websocket PONG received in time."; return HOOK_CONTINUE; - } else - if ((t > RPC_WEBSOCKET_PING_TIME) && !IsPingSent(client) && !IsDead(client)) + } else if ((t > RPC_WEBSOCKET_PING_TIME) && !IsPingSent(client) && !IsDead(client)) { char pingbuf[4]; const char *pkt = pingbuf; @@ -1392,7 +1388,7 @@ int rpc_parse_auth_basic_auth(Client *client, WebRequest *web, char **username, p = strchr(auth_header, ' '); skip_whitespace(&p); - n = b64_decode(p, buf, sizeof(buf)-1); + n = b64_decode(p, buf, sizeof(buf) - 1); if (n <= 1) return 0; buf[n] = '\0'; @@ -1690,7 +1686,8 @@ void rrpc_pass_on_split(Client *client, Client *dest, MessageTag *recv_mtags, co saved = data[RRPC_PACKET_SMALL]; data[RRPC_PACKET_SMALL] = '\0'; remaining -= RRPC_PACKET_SMALL; - } else { + } else + { saved = 0; remaining = 0; continuation = 0; @@ -1709,14 +1706,13 @@ void rrpc_pass_on_split(Client *client, Client *dest, MessageTag *recv_mtags, co * last chunk (caveat :D). */ strlcat_letter(status, 'F', sizeof(status)); - } else - if (!first) + } else if (!first) { strlcat_letter(status, 'C', sizeof(status)); } sendto_one(dest, recv_mtags, ":%s RRPC %s %s %s %s %s :%s", - client->id, parv[1], parv[2], parv[3], parv[4], status, data); + client->id, parv[1], parv[2], parv[3], parv[4], status, data); if (!saved) break; /* done! */ @@ -1737,8 +1733,8 @@ CMD_FUNC(cmd_rrpc) const char *source, *destination, *requestid, *type, *data; RRPC *r; Client *dest; - char sid[SIDLEN+1]; - char binarydata[BUFSIZE+1]; + char sid[SIDLEN + 1]; + char binarydata[BUFSIZE + 1]; int binarydatalen; if ((parc < 7) || BadPtr(parv[6])) @@ -1753,7 +1749,8 @@ CMD_FUNC(cmd_rrpc) } else if (!strcmp(parv[1], "RES")) { request = 0; - } else { + } else + { sendnumeric(client, ERR_CANNOTDOCOMMAND, "RRPC", "Invalid parameter"); return; } @@ -1783,7 +1780,8 @@ CMD_FUNC(cmd_rrpc) { /* Hard case */ rrpc_pass_on_split(client, dest, recv_mtags, parv); - } else { + } else + { /* Simple case */ sendto_one(dest, recv_mtags, ":%s RRPC %s %s %s %s %s :%s", client->id, parv[1], parv[2], parv[3], parv[4], parv[5], parv[6]); @@ -1816,8 +1814,7 @@ CMD_FUNC(cmd_rrpc) r->request = request; dbuf_queue_init(&r->data); AddListItem(r, rrpc_list); - } else - if (strchr(type, 'C') || strchr(type, 'F')) + } else if (strchr(type, 'C') || strchr(type, 'F')) { r = find_rrpc(source, destination, requestid); if (!r) @@ -1867,7 +1864,7 @@ void rpc_call_remote(RRPC *r) json_t *request = NULL; Client *server; Client *client; - char sid[SIDLEN+1]; + char sid[SIDLEN + 1]; request = rrpc_data(r); if (!request) @@ -1973,7 +1970,7 @@ void rpc_send_generic_to_remote(Client *source, Client *target, const char *requ int bytes_remaining; /* bytes remaining overall */ int start_frame = 1; /* set to 1 if this is the start frame */ int packet_split_size; /* chunk size of outgoing packets (depends on BIGLINES support) */ - char data[RRPC_PACKET_BIGLINES+1]; + char data[RRPC_PACKET_BIGLINES + 1]; requestid = rpc_id(json); if (!requestid) @@ -2007,15 +2004,15 @@ void rpc_send_generic_to_remote(Client *source, Client *target, const char *requ type = "S"; /* start (with later continuation frames) */ else type = "SF"; /* start and finish */ - } else - if (bytes_remaining > 0) + } else if (bytes_remaining > 0) { type = "C"; /* continuation frame (with later a finish frame) */ - } else { + } else + { type = "F"; /* finish frame (the last frame) */ } - strlncpy(data, str, packet_split_size+1, bytes); + strlncpy(data, str, packet_split_size + 1, bytes); sendto_one(target, NULL, ":%s RRPC %s %s %s %s %s :%s", me.id, @@ -2148,7 +2145,7 @@ const char *rrpc_md_serialize(ModData *m) strlcat(buf, tmp, sizeof(buf)); } if (*buf) - buf[strlen(buf)-1] = '\0'; // strip last comma + buf[strlen(buf) - 1] = '\0'; // strip last comma return buf; } diff --git a/src/modules/rpc/security_group.c b/src/modules/rpc/security_group.c index 164b2739d..67061a120 100644 --- a/src/modules/rpc/security_group.c +++ b/src/modules/rpc/security_group.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/security_group", - "1.0.0", - "security_group.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/security_group", + "1.0.0", + "security_group.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ diff --git a/src/modules/rpc/server.c b/src/modules/rpc/server.c index 5cbad3fe1..39647f374 100644 --- a/src/modules/rpc/server.c +++ b/src/modules/rpc/server.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/server", - "1.0.0", - "server.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/server", + "1.0.0", + "server.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -134,7 +133,8 @@ RPC_CALL_FUNC(rpc_server_get) rpc_error(client, request, JSON_RPC_ERROR_NOT_FOUND, "Server not found"); return; } - } else { + } else + { acptr = &me; } @@ -158,7 +158,8 @@ RPC_CALL_FUNC(rpc_server_rehash) rpc_error(client, request, JSON_RPC_ERROR_NOT_FOUND, "Server not found"); return; } - } else { + } else + { acptr = &me; } @@ -169,7 +170,8 @@ RPC_CALL_FUNC(rpc_server_rehash) { /* Server supports RRPC and will handle the response */ rpc_send_request_to_remote(client, acptr, request); - } else { + } else + { /* Server does not support RRPC, so we can only do best effort: */ sendto_one(acptr, NULL, ":%s REHASH %s", me.id, acptr->name); result = json_boolean(1); @@ -244,7 +246,8 @@ RPC_CALL_FUNC(rpc_server_connect) rpc_error(client, request, JSON_RPC_ERROR_NOT_FOUND, "Server not found"); return; } - } else { + } else + { acptr = &me; } REQUIRE_PARAM_STRING("link", link_name); @@ -283,8 +286,8 @@ RPC_CALL_FUNC(rpc_server_connect) } unreal_log(ULOG_INFO, "link", "LINK_REQUEST", client, - "CONNECT: Link to $link_block requested by $client", - log_data_link_block(link)); + "CONNECT: Link to $link_block requested by $client", + log_data_link_block(link)); connect_server(link, client, NULL); result = json_boolean(1); @@ -307,7 +310,8 @@ RPC_CALL_FUNC(rpc_server_disconnect) rpc_error(client, request, JSON_RPC_ERROR_NOT_FOUND, "Server not found"); return; } - } else { + } else + { acptr = &me; } REQUIRE_PARAM_STRING("link", link_name); @@ -353,14 +357,15 @@ RPC_CALL_FUNC(rpc_server_disconnect) void json_expand_module(json_t *j, const char *key, Module *m, int detail) { - char buf[BUFSIZE+1]; + char buf[BUFSIZE + 1]; json_t *child; if (key) { child = json_object(); json_object_set_new(j, key, child); - } else { + } else + { child = j; } @@ -388,7 +393,8 @@ RPC_CALL_FUNC(rpc_server_module_list) rpc_error(client, request, JSON_RPC_ERROR_NOT_FOUND, "Server not found"); return; } - } else { + } else + { acptr = &me; } diff --git a/src/modules/rpc/server_ban.c b/src/modules/rpc/server_ban.c index c9a022b19..380a38883 100644 --- a/src/modules/rpc/server_ban.c +++ b/src/modules/rpc/server_ban.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/server_ban", - "1.0.3", - "server_ban.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/server_ban", + "1.0.3", + "server_ban.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -242,7 +241,8 @@ RPC_CALL_FUNC(rpc_server_ban_del) */ snprintf(usermask_mess, sizeof(usermask_mess), "%%%s", usermask); tkllayer[3] = usermask_mess; - } else { + } else + { tkllayer[3] = usermask; } tkllayer[4] = hostmask; @@ -253,7 +253,8 @@ RPC_CALL_FUNC(rpc_server_ban_del) if (!find_tkl_serverban(tkl_type_int, usermask, hostmask, soft)) { rpc_response(client, request, result); - } else { + } else + { /* Actually this may not be an internal error, it could be an * incorrect request, such as asking to remove a config-based ban. */ @@ -297,8 +298,7 @@ RPC_CALL_FUNC(rpc_server_ban_add) tkl_expire_at = config_checkval(str, CFG_TIME); if (tkl_expire_at > 0) tkl_expire_at = TStime() + tkl_expire_at; - } else - if ((str = json_object_get_string(params, "expire_at"))) + } else if ((str = json_object_get_string(params, "expire_at"))) { tkl_expire_at = server_time_to_unix_time(str); } else diff --git a/src/modules/rpc/server_ban_exception.c b/src/modules/rpc/server_ban_exception.c index 5f91a98ff..3d42a007b 100644 --- a/src/modules/rpc/server_ban_exception.c +++ b/src/modules/rpc/server_ban_exception.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/server_ban_exception", - "1.0.1", - "server_ban_exception.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/server_ban_exception", + "1.0.1", + "server_ban_exception.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -115,11 +114,11 @@ RPC_CALL_FUNC(rpc_server_ban_exception_list) /** Shared code for selecting a server ban, for .add/.del/.get */ int server_ban_exception_select_criteria(Client *client, json_t *request, json_t *params, int add, - const char **name, - const char **exception_types, - char **usermask, - char **hostmask, - int *soft) + const char **name, + const char **exception_types, + char **usermask, + char **hostmask, + int *soft) { const char *error; @@ -138,7 +137,8 @@ int server_ban_exception_select_criteria(Client *client, json_t *request, json_t rpc_error(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: 'exception_types'"); return 0; } - } else { + } else + { *exception_types = NULL; } @@ -160,13 +160,13 @@ RPC_CALL_FUNC(rpc_server_ban_exception_get) TKL *tkl; if (!server_ban_exception_select_criteria(client, request, params, 0, - &name, &exception_types, - &usermask, &hostmask, &soft)) + &name, &exception_types, + &usermask, &hostmask, &soft)) { return; } - if (!(tkl = find_tkl_banexception(TKL_EXCEPTION|TKL_GLOBAL, usermask, hostmask, soft)) && + if (!(tkl = find_tkl_banexception(TKL_EXCEPTION | TKL_GLOBAL, usermask, hostmask, soft)) && !(tkl = find_tkl_banexception(TKL_EXCEPTION, usermask, hostmask, soft))) { rpc_error(client, request, JSON_RPC_ERROR_NOT_FOUND, "Ban exception not found"); @@ -191,13 +191,13 @@ RPC_CALL_FUNC(rpc_server_ban_exception_del) const char *tkllayer[11]; if (!server_ban_exception_select_criteria(client, request, params, 0, - &name, &exception_types, - &usermask, &hostmask, &soft)) + &name, &exception_types, + &usermask, &hostmask, &soft)) { return; } - if (!(tkl = find_tkl_banexception(TKL_EXCEPTION|TKL_GLOBAL, usermask, hostmask, soft)) && + if (!(tkl = find_tkl_banexception(TKL_EXCEPTION | TKL_GLOBAL, usermask, hostmask, soft)) && !(tkl = find_tkl_banexception(TKL_EXCEPTION, usermask, hostmask, soft))) { rpc_error(client, request, JSON_RPC_ERROR_NOT_FOUND, "Ban exception not found"); @@ -223,11 +223,12 @@ RPC_CALL_FUNC(rpc_server_ban_exception_del) tkllayer[10] = NULL; cmd_tkl(NULL, &me, NULL, 6, tkllayer); - if (!find_tkl_banexception(TKL_EXCEPTION|TKL_GLOBAL, usermask, hostmask, soft) && + if (!find_tkl_banexception(TKL_EXCEPTION | TKL_GLOBAL, usermask, hostmask, soft) && !find_tkl_banexception(TKL_EXCEPTION, usermask, hostmask, soft)) { rpc_response(client, request, result); - } else { + } else + { /* Actually this may not be an internal error, it could be an * incorrect request, such as asking to remove a config-based ban. */ @@ -251,8 +252,8 @@ RPC_CALL_FUNC(rpc_server_ban_exception_add) time_t tkl_set_at = TStime(); if (!server_ban_exception_select_criteria(client, request, params, 1, - &name, &exception_types, - &usermask, &hostmask, &soft)) + &name, &exception_types, + &usermask, &hostmask, &soft)) { return; } @@ -267,8 +268,7 @@ RPC_CALL_FUNC(rpc_server_ban_exception_add) tkl_expire_at = config_checkval(str, CFG_TIME); if (tkl_expire_at > 0) tkl_expire_at = TStime() + tkl_expire_at; - } else - if ((str = json_object_get_string(params, "expire_at"))) + } else if ((str = json_object_get_string(params, "expire_at"))) { tkl_expire_at = server_time_to_unix_time(str); } else @@ -287,14 +287,14 @@ RPC_CALL_FUNC(rpc_server_ban_exception_add) return; } - if (find_tkl_banexception(TKL_EXCEPTION|TKL_GLOBAL, usermask, hostmask, soft) || + if (find_tkl_banexception(TKL_EXCEPTION | TKL_GLOBAL, usermask, hostmask, soft) || find_tkl_banexception(TKL_EXCEPTION, usermask, hostmask, soft)) { rpc_error(client, request, JSON_RPC_ERROR_ALREADY_EXISTS, "A ban exception with that mask already exists"); return; } - tkl = tkl_add_banexception(TKL_EXCEPTION|TKL_GLOBAL, usermask, hostmask, + tkl = tkl_add_banexception(TKL_EXCEPTION | TKL_GLOBAL, usermask, hostmask, NULL, reason, set_by, tkl_expire_at, tkl_set_at, soft, exception_types, 0); diff --git a/src/modules/rpc/spamfilter.c b/src/modules/rpc/spamfilter.c index bae953101..03216a76f 100644 --- a/src/modules/rpc/spamfilter.c +++ b/src/modules/rpc/spamfilter.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/spamfilter", - "1.0.3", - "spamfilter.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/spamfilter", + "1.0.3", + "spamfilter.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -177,7 +176,7 @@ RPC_CALL_FUNC(rpc_spamfilter_get) return; /* Error already communicated to client */ /* For spamfilter.get we first try global spamfilters, then local. */ - tkl = find_tkl_spamfilter(TKL_SPAMF|TKL_GLOBAL, name, action, targets); + tkl = find_tkl_spamfilter(TKL_SPAMF | TKL_GLOBAL, name, action, targets); if (!tkl) { tkl = find_tkl_spamfilter(TKL_SPAMF, name, action, targets); @@ -197,7 +196,7 @@ RPC_CALL_FUNC(rpc_spamfilter_get) RPC_CALL_FUNC(rpc_spamfilter_add) { json_t *result; - int type = TKL_SPAMF|TKL_GLOBAL; + int type = TKL_SPAMF | TKL_GLOBAL; const char *str; const char *name, *reason; const char *set_by; @@ -277,7 +276,7 @@ RPC_CALL_FUNC(rpc_spamfilter_add) RPC_CALL_FUNC(rpc_spamfilter_del) { json_t *result; - int type = TKL_SPAMF|TKL_GLOBAL; + int type = TKL_SPAMF | TKL_GLOBAL; const char *name; const char *set_by; TKL *tkl; @@ -325,7 +324,8 @@ RPC_CALL_FUNC(rpc_spamfilter_del) if (!tkl) { rpc_response(client, request, result); - } else { + } else + { /* Spamfilter still exists so failure to remove. * Actually this may not be an internal error, it could be an * incorrect request, such as asking to remove a config-based spamfilter. diff --git a/src/modules/rpc/stats.c b/src/modules/rpc/stats.c index dac96891a..c83c06d7c 100644 --- a/src/modules/rpc/stats.c +++ b/src/modules/rpc/stats.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/stats", - "1.0.2", - "stats.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/stats", + "1.0.2", + "stats.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -93,7 +92,8 @@ void rpc_stats_user(json_t *main, int detail) DelListItem(e, countries); e->priority--; AddListItemPrio(e, countries, e->priority); - } else { + } else + { add_nvplist(&countries, -1, geo->country_code, NULL); } } diff --git a/src/modules/rpc/user.c b/src/modules/rpc/user.c index 3d03d9c37..193419900 100644 --- a/src/modules/rpc/user.c +++ b/src/modules/rpc/user.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/user", - "1.0.7", - "user.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/user", + "1.0.7", + "user.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -245,7 +244,7 @@ RPC_CALL_FUNC(rpc_user_set_nick) const char *args[5]; const char *nick, *newnick_requested, *str; int force = 0; - char newnick[NICKLEN+1]; + char newnick[NICKLEN + 1]; char tsbuf[32]; Client *acptr; @@ -523,7 +522,7 @@ RPC_CALL_FUNC(rpc_user_set_oper) json_t *result, *list, *item; const char *args[9]; const char *nick, *oper_account, *oper_class; - const char *class=NULL, *modes=NULL, *snomask=NULL, *vhost=NULL; + const char *class = NULL, *modes = NULL, *snomask = NULL, *vhost = NULL; MessageTag *mtags = NULL; Client *acptr; char default_modes[64]; @@ -639,7 +638,7 @@ RPC_CALL_FUNC(rpc_user_join) { json_t *result, *list, *item; const char *args[5]; - const char *nick, *channel, *key=NULL; + const char *nick, *channel, *key = NULL; Client *acptr; MessageTag *mtags = NULL; int force = 0; @@ -666,7 +665,8 @@ RPC_CALL_FUNC(rpc_user_join) args[3] = key; args[4] = NULL; do_cmd(&me, mtags, "SVSJOIN", key ? 4 : 3, args); - } else { + } else + { args[3] = NULL; do_cmd(&me, mtags, "SAJOIN", 3, args); } @@ -687,7 +687,7 @@ RPC_CALL_FUNC(rpc_user_part) { json_t *result, *list, *item; const char *args[5]; - const char *nick, *channel, *reason=NULL; + const char *nick, *channel, *reason = NULL; Client *acptr; MessageTag *mtags = NULL; int force = 0; diff --git a/src/modules/rpc/whowas.c b/src/modules/rpc/whowas.c index 317ae46c2..5253c7b96 100644 --- a/src/modules/rpc/whowas.c +++ b/src/modules/rpc/whowas.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "rpc/whowas", - "1.0.1", - "whowas.* RPC calls", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "rpc/whowas", + "1.0.1", + "whowas.* RPC calls", + "UnrealIRCd Team", + "unrealircd-6", }; /* Externals */ @@ -64,13 +63,14 @@ void json_expand_whowas(json_t *j, const char *key, WhoWas *e, int detail) { json_t *child; json_t *user = NULL; - char buf[BUFSIZE+1]; + char buf[BUFSIZE + 1]; if (key) { child = json_object(); json_object_set_new(j, key, child); - } else { + } else + { child = j; } @@ -146,7 +146,7 @@ RPC_CALL_FUNC(rpc_whowas_get) list = json_array(); json_object_set_new(result, "list", list); - for (i=0; i < NICKNAMEHISTORYLENGTH; i++) + for (i = 0; i < NICKNAMEHISTORYLENGTH; i++) { WhoWas *e = &WHOWAS[i]; if (!e->name) diff --git a/src/modules/rules.c b/src/modules/rules.c index f7dc317bf..79e307a49 100644 --- a/src/modules/rules.c +++ b/src/modules/rules.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_rules); -#define MSG_RULES "RULES" +#define MSG_RULES "RULES" -ModuleHeader MOD_HEADER - = { - "rules", - "5.0", - "command /rules", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "rules", + "5.0", + "command /rules", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -74,7 +73,6 @@ CMD_FUNC(cmd_rules) { sendnumeric(client, ERR_NORULES); return; - } sendnumeric(client, RPL_RULESSTART, me.name); @@ -82,7 +80,7 @@ CMD_FUNC(cmd_rules) while (temp) { sendnumeric(client, RPL_RULES, - temp->line); + temp->line); temp = temp->next; } sendnumeric(client, RPL_ENDOFRULES); diff --git a/src/modules/sajoin.c b/src/modules/sajoin.c index ddacd9e17..d62b89f2a 100644 --- a/src/modules/sajoin.c +++ b/src/modules/sajoin.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_sajoin); -#define MSG_SAJOIN "SAJOIN" +#define MSG_SAJOIN "SAJOIN" -ModuleHeader MOD_HEADER - = { - "sajoin", - "5.0", - "command /sajoin", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sajoin", + "5.0", + "command /sajoin", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SAJOIN, cmd_sajoin, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_SAJOIN, cmd_sajoin, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -58,13 +57,14 @@ static void log_sajoin(Client *client, MessageTag *mtags, Client *target, const if (issuer) { unreal_log(ULOG_INFO, "sacmds", "SAJOIN_COMMAND", client, "SAJOIN: $issuer used SAJOIN to make $target join $channels", - log_data_string("issuer", issuer), - log_data_client("target", target), - log_data_string("channels", channels)); - } else { + log_data_string("issuer", issuer), + log_data_client("target", target), + log_data_string("channels", channels)); + } else + { unreal_log(ULOG_INFO, "sacmds", "SAJOIN_COMMAND", client, "SAJOIN: $client used SAJOIN to make $target join $channels", - log_data_client("target", target), - log_data_string("channels", channels)); + log_data_client("target", target), + log_data_string("channels", channels)); } } @@ -97,7 +97,7 @@ CMD_FUNC(cmd_sajoin) } /* Is this user disallowed from operating on this victim at all? */ - if (!IsULine(client) && !ValidatePermissionsForPath("sacmd:sajoin",client,target,NULL,NULL)) + if (!IsULine(client) && !ValidatePermissionsForPath("sacmd:sajoin", client, target, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -121,7 +121,7 @@ CMD_FUNC(cmd_sajoin) { char *name, *p = NULL; int parted = 0; - + *jbuf = 0; /* Now works like cmd_join */ @@ -168,7 +168,7 @@ CMD_FUNC(cmd_sajoin) channel = make_channel(name); /* If this _specific_ channel is not permitted, skip it */ - if (!IsULine(client) && !ValidatePermissionsForPath("sacmd:sajoin",client,target,channel,NULL)) + if (!IsULine(client) && !ValidatePermissionsForPath("sacmd:sajoin", client, target, channel, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); continue; @@ -242,7 +242,7 @@ CMD_FUNC(cmd_sajoin) i = HOOK_CONTINUE; for (h = Hooks[HOOKTYPE_CAN_SAJOIN]; h; h = h->next) { - i = (*(h->func.intfunc))(target,channel,client); + i = (*(h->func.intfunc))(target, channel, client); if (i != HOOK_CONTINUE) break; } @@ -284,7 +284,7 @@ CMD_FUNC(cmd_sajoin) strlcat(jbuf, ",", sizeof jbuf); strlcat(jbuf, name, sizeof jbuf); } - + if (did_anything) { sendnotice(target, "*** You were forced to join %s", jbuf); diff --git a/src/modules/samode.c b/src/modules/samode.c index c5b3d8642..76a866c9c 100644 --- a/src/modules/samode.c +++ b/src/modules/samode.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_samode); -#define MSG_SAMODE "SAMODE" +#define MSG_SAMODE "SAMODE" -ModuleHeader MOD_HEADER - = { - "samode", - "5.0", - "command /samode", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "samode", + "5.0", + "command /samode", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { diff --git a/src/modules/sapart.c b/src/modules/sapart.c index 2c70cfc69..2f2d4ce0c 100644 --- a/src/modules/sapart.c +++ b/src/modules/sapart.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_sapart); -#define MSG_SAPART "SAPART" +#define MSG_SAPART "SAPART" -ModuleHeader MOD_HEADER - = { - "sapart", - "5.0", - "command /sapart", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sapart", + "5.0", + "command /sapart", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SAPART, cmd_sapart, 3, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_SAPART, cmd_sapart, 3, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -61,31 +60,30 @@ static void log_sapart(Client *client, MessageTag *mtags, Client *target, const if (comment) { unreal_log(ULOG_INFO, "sacmds", "SAPART_COMMAND", client, "SAPART: $issuer used SAPART to make $target part $channels ($reason)", - log_data_string("issuer", issuer), - log_data_client("target", target), - log_data_string("channels", channels), - log_data_string("reason", comment)); - } - else + log_data_string("issuer", issuer), + log_data_client("target", target), + log_data_string("channels", channels), + log_data_string("reason", comment)); + } else { unreal_log(ULOG_INFO, "sacmds", "SAPART_COMMAND", client, "SAPART: $issuer used SAPART to make $target part $channels", - log_data_string("issuer", issuer), - log_data_client("target", target), - log_data_string("channels", channels)); + log_data_string("issuer", issuer), + log_data_client("target", target), + log_data_string("channels", channels)); } - } else { + } else + { if (comment) { unreal_log(ULOG_INFO, "sacmds", "SAPART_COMMAND", client, "SAPART: $client used SAPART to make $target part $channels ($reason)", - log_data_client("target", target), - log_data_string("channels", channels), - log_data_string("reason", comment)); - } - else + log_data_client("target", target), + log_data_string("channels", channels), + log_data_string("reason", comment)); + } else { unreal_log(ULOG_INFO, "sacmds", "SAPART_COMMAND", client, "SAPART: $client used SAPART to make $target part $channels", - log_data_client("target", target), - log_data_string("channels", channels)); + log_data_client("target", target), + log_data_string("channels", channels)); } } } @@ -116,19 +114,19 @@ CMD_FUNC(cmd_sapart) int maxtargets = max_targets_for_command("SAPART"); if ((parc < 3) || BadPtr(parv[2])) - { - sendnumeric(client, ERR_NEEDMOREPARAMS, "SAPART"); - return; - } + { + sendnumeric(client, ERR_NEEDMOREPARAMS, "SAPART"); + return; + } - if (!(target = find_user(parv[1], NULL))) - { - sendnumeric(client, ERR_NOSUCHNICK, parv[1]); - return; - } + if (!(target = find_user(parv[1], NULL))) + { + sendnumeric(client, ERR_NOSUCHNICK, parv[1]); + return; + } /* See if we can operate on this vicim/this command */ - if (!ValidatePermissionsForPath("sacmd:sapart",client,target,NULL,NULL)) + if (!ValidatePermissionsForPath("sacmd:sapart", client, target, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -165,7 +163,7 @@ CMD_FUNC(cmd_sapart) } /* Validate oper can do this on chan/victim */ - if (!IsULine(client) && !ValidatePermissionsForPath("sacmd:sapart",client,target,channel,NULL)) + if (!IsULine(client) && !ValidatePermissionsForPath("sacmd:sapart", client, target, channel, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); continue; @@ -193,7 +191,8 @@ CMD_FUNC(cmd_sapart) { snprintf(commentx, sizeof(commentx), "SAPart: %s", comment); sendnotice(target, "*** You were forced to part %s (%s)", request, commentx); - } else { + } else + { sendnotice(target, "*** You were forced to part %s", request); } diff --git a/src/modules/sasl.c b/src/modules/sasl.c index 85c6ed68c..587506e45 100644 --- a/src/modules/sasl.c +++ b/src/modules/sasl.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "sasl", - "5.2.1", - "SASL", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sasl", + "5.2.1", + "SASL", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ void saslmechlist_free(ModData *m); @@ -42,9 +41,9 @@ int sasl_is_handshake_finished(Client *client); EVENT(sasl_timeout); /* Macros */ -#define MSG_AUTHENTICATE "AUTHENTICATE" -#define MSG_SASL "SASL" -#define AGENT_SID(agent_p) (agent_p->user != NULL ? agent_p->user->server : agent_p->name) +#define MSG_AUTHENTICATE "AUTHENTICATE" +#define MSG_SASL "SASL" +#define AGENT_SID(agent_p) (agent_p->user != NULL ? agent_p->user->server : agent_p->name) /* Variables */ long CAP_SASL = 0L; @@ -74,17 +73,16 @@ int sasl_account_login(Client *client, MessageTag *mtags) if (IsLoggedIn(client)) { sendnumeric(client, RPL_LOGGEDIN, - BadPtr(client->name) ? "*" : client->name, - BadPtr(client->user->username) ? "*" : client->user->username, - BadPtr(client->user->realhost) ? "*" : client->user->realhost, - client->user->account, client->user->account); - } - else + BadPtr(client->name) ? "*" : client->name, + BadPtr(client->user->username) ? "*" : client->user->username, + BadPtr(client->user->realhost) ? "*" : client->user->realhost, + client->user->account, client->user->account); + } else { sendnumeric(client, RPL_LOGGEDOUT, - BadPtr(client->name) ? "*" : client->name, - BadPtr(client->user->username) ? "*" : client->user->username, - BadPtr(client->user->realhost) ? "*" : client->user->realhost); + BadPtr(client->name) ? "*" : client->name, + BadPtr(client->user->username) ? "*" : client->user->username, + BadPtr(client->user->realhost) ? "*" : client->user->realhost); } return 0; } @@ -93,7 +91,7 @@ void _sasl_succeeded(Client *client) { client->local->sasl_sent_time = 0; client->local->sasl_complete++; - RunHookReturn(HOOKTYPE_SASL_RESULT, !=0, client, 1); + RunHookReturn(HOOKTYPE_SASL_RESULT, != 0, client, 1); sendnumeric(client, RPL_SASLSUCCESS); } @@ -101,7 +99,7 @@ void _sasl_failed(Client *client) { client->local->sasl_sent_time = 0; add_fake_lag(client, 7000); /* bump fakelag due to failed authentication attempt */ - RunHookReturn(HOOKTYPE_SASL_RESULT, !=0, client, 0); + RunHookReturn(HOOKTYPE_SASL_RESULT, != 0, client, 0); sendnumeric(client, ERR_SASLFAIL); } @@ -185,10 +183,9 @@ CMD_FUNC(cmd_sasl) if (*parv[3] == 'C') { - RunHookReturn(HOOKTYPE_SASL_CONTINUATION, !=0, target, parv[4]); + RunHookReturn(HOOKTYPE_SASL_CONTINUATION, != 0, target, parv[4]); sendto_one(target, NULL, "AUTHENTICATE %s", parv[4]); - } - else if (*parv[3] == 'D') + } else if (*parv[3] == 'D') { *target->local->sasl_agent = '\0'; if (*parv[4] == 'F') @@ -201,8 +198,7 @@ CMD_FUNC(cmd_sasl) register_user(target); /* User MAY be killed now, that's okay, we don't deal with 'target' below */ } - } - else if (*parv[3] == 'M') + } else if (*parv[3] == 'M') sendnumeric(target, RPL_SASLMECHS, parv[4]); return; @@ -210,7 +206,7 @@ CMD_FUNC(cmd_sasl) /* not for us; propagate. */ sendto_server(client, 0, 0, NULL, ":%s SASL %s %s %c %s %s", - client->name, parv[1], parv[2], *parv[3], parv[4], parc > 5 ? parv[5] : ""); + client->name, parv[1], parv[2], *parv[3], parv[4], parc > 5 ? parv[5] : ""); } /* @@ -256,16 +252,17 @@ CMD_FUNC(cmd_authenticate) { /* We are the SASL server (some module handling auth) */ RunHook(HOOKTYPE_SASL_AUTHENTICATE, client, 1, parv[1]); - } else { + } else + { sendto_server(NULL, 0, 0, NULL, ":%s SASL %s %s H %s %s", - me.name, SASL_SERVER, client->id, addr, addr); + me.name, SASL_SERVER, client->id, addr, addr); if (certfp) sendto_server(NULL, 0, 0, NULL, ":%s SASL %s %s S %s %s", - me.name, SASL_SERVER, client->id, parv[1], certfp); + me.name, SASL_SERVER, client->id, parv[1], certfp); else sendto_server(NULL, 0, 0, NULL, ":%s SASL %s %s S %s", - me.name, SASL_SERVER, client->id, parv[1]); + me.name, SASL_SERVER, client->id, parv[1]); } } else { @@ -273,9 +270,10 @@ CMD_FUNC(cmd_authenticate) { /* We are the SASL server (some module handling auth) */ RunHook(HOOKTYPE_SASL_AUTHENTICATE, client, 0, parv[1]); - } else { + } else + { sendto_server(NULL, 0, 0, NULL, ":%s SASL %s %s C %s", - me.name, AGENT_SID(agent_p), client->id, parv[1]); + me.name, AGENT_SID(agent_p), client->id, parv[1]); } } } @@ -297,7 +295,7 @@ static int abort_sasl(Client *client) if (agent_p != NULL) { sendto_server(NULL, 0, 0, NULL, ":%s SASL %s %s D A", - me.name, AGENT_SID(agent_p), client->id); + me.name, AGENT_SID(agent_p), client->id); return 0; } } @@ -405,8 +403,8 @@ MOD_INIT() MARK_AS_OFFICIAL_MODULE(modinfo); - CommandAdd(modinfo->handle, MSG_SASL, cmd_sasl, MAXPARA, CMD_USER|CMD_SERVER); - CommandAdd(modinfo->handle, MSG_AUTHENTICATE, cmd_authenticate, MAXPARA, CMD_UNREGISTERED|CMD_USER); + CommandAdd(modinfo->handle, MSG_SASL, cmd_sasl, MAXPARA, CMD_USER | CMD_SERVER); + CommandAdd(modinfo->handle, MSG_AUTHENTICATE, cmd_authenticate, MAXPARA, CMD_UNREGISTERED | CMD_USER); HookAdd(modinfo->handle, HOOKTYPE_LOCAL_CONNECT, 0, sasl_connect); HookAdd(modinfo->handle, HOOKTYPE_LOCAL_QUIT, 0, sasl_quit); diff --git a/src/modules/sdesc.c b/src/modules/sdesc.c index 685c04477..6c921ffa4 100644 --- a/src/modules/sdesc.c +++ b/src/modules/sdesc.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_sdesc); -#define MSG_SDESC "SDESC" /* sdesc */ +#define MSG_SDESC "SDESC" /* sdesc */ -ModuleHeader MOD_HEADER - = { - "sdesc", /* Name of module */ - "5.0", /* Version */ - "command /sdesc", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sdesc", /* Name of module */ + "5.0", /* Version */ + "command /sdesc", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -60,12 +59,12 @@ MOD_UNLOAD() CMD_FUNC(cmd_sdesc) { - if (!ValidatePermissionsForPath("server:description",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:description", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; } - + if ((parc < 2) || BadPtr(parv[1])) { sendnumeric(client, ERR_NEEDMOREPARAMS, "SDESC"); @@ -77,7 +76,7 @@ CMD_FUNC(cmd_sdesc) if (MyConnect(client)) { sendnotice(client, "*** /SDESC Error: \"Server info\" may maximum be %i characters of length", - REALLEN); + REALLEN); return; } } diff --git a/src/modules/sendsno.c b/src/modules/sendsno.c index 1f1d52f0f..cde9f0281 100644 --- a/src/modules/sendsno.c +++ b/src/modules/sendsno.c @@ -22,16 +22,15 @@ CMD_FUNC(cmd_sendsno); -#define MSG_SENDSNO "SENDSNO" +#define MSG_SENDSNO "SENDSNO" -ModuleHeader MOD_HEADER - = { - "sendsno", /* Name of module */ - "5.0", /* Version */ - "command /sendsno", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sendsno", /* Name of module */ + "5.0", /* Version */ + "command /sendsno", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() diff --git a/src/modules/sendumode.c b/src/modules/sendumode.c index 18c7c4092..c290fbdfd 100644 --- a/src/modules/sendumode.c +++ b/src/modules/sendumode.c @@ -23,17 +23,16 @@ CMD_FUNC(cmd_sendumode); /* Place includes here */ -#define MSG_SENDUMODE "SENDUMODE" -#define MSG_SMO "SMO" +#define MSG_SENDUMODE "SENDUMODE" +#define MSG_SMO "SMO" -ModuleHeader MOD_HEADER - = { - "sendumode", /* Name of module */ - "5.0", /* Version */ - "command /sendumode", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sendumode", /* Name of module */ + "5.0", /* Version */ + "command /sendumode", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() diff --git a/src/modules/server-time.c b/src/modules/server-time.c index 6dfdcda0a..08f93ac6f 100644 --- a/src/modules/server-time.c +++ b/src/modules/server-time.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "server-time", - "5.0", - "server-time CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "server-time", + "5.0", + "server-time CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ long CAP_SERVER_TIME = 0L; diff --git a/src/modules/server.c b/src/modules/server.c index 1794de21b..9731758a2 100644 --- a/src/modules/server.c +++ b/src/modules/server.c @@ -40,7 +40,7 @@ typedef struct ConfigItem_deny_link ConfigItem_deny_link; struct ConfigItem_deny_link { ConfigItem_deny_link *prev, *next; ConfigFlag_except flag; - ConfigItem_mask *mask; + ConfigItem_mask *mask; CRuleNode *rule; /**< parsed crule */ char *prettyrule; /**< human printable version */ char *reason; /**< Reason for the deny link */ @@ -80,14 +80,13 @@ static cfgstruct cfg; static char *last_autoconnect_server = NULL; static ConfigItem_deny_link *conf_deny_link = NULL; -ModuleHeader MOD_HEADER - = { - "server", - "5.0", - "command /server", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "server", + "5.0", + "command /server", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_TEST() { @@ -116,7 +115,7 @@ MOD_INIT() HookAdd(modinfo->handle, HOOKTYPE_STATS, 0, server_stats_denylink_auto); HookAdd(modinfo->handle, HOOKTYPE_SERVER_QUIT, 0, server_quit_reset_autoconnect_time); HookAdd(modinfo->handle, HOOKTYPE_POSTCONF, 0, check_server_linking_cert_consistency); - CommandAdd(modinfo->handle, "SERVER", cmd_server, MAXPARA, CMD_UNREGISTERED|CMD_SERVER); + CommandAdd(modinfo->handle, "SERVER", cmd_server, MAXPARA, CMD_UNREGISTERED | CMD_SERVER); CommandAdd(modinfo->handle, "SID", cmd_sid, MAXPARA, CMD_SERVER); return MOD_SUCCESS; @@ -209,11 +208,10 @@ int server_config_test_set_server_linking(ConfigFile *cf, ConfigEntry *ce, int t if (!cep->value) { config_error("%s:%i: blank set::server-linking::%s without value", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; - } else - if (!strcmp(cep->name, "autoconnect-strategy")) + } else if (!strcmp(cep->name, "autoconnect-strategy")) { if (autoconnect_strategy_strtoval(cep->value) < 0) { @@ -223,40 +221,36 @@ int server_config_test_set_server_linking(ConfigFile *cf, ConfigEntry *ce, int t errors++; continue; } - } else - if (!strcmp(cep->name, "connect-timeout")) + } else if (!strcmp(cep->name, "connect-timeout")) { long v = config_checkval(cep->value, CFG_TIME); if ((v < 5) || (v > 30)) { config_error("%s:%i: set::server-linking::connect-timeout should be between 5 and 60 seconds", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } - } else - if (!strcmp(cep->name, "handshake-timeout")) + } else if (!strcmp(cep->name, "handshake-timeout")) { long v = config_checkval(cep->value, CFG_TIME); if ((v < 10) || (v > 120)) { config_error("%s:%i: set::server-linking::handshake-timeout should be between 10 and 120 seconds", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; continue; } - } else - if (!strcmp(cep->name, "mixed-certificates")) + } else if (!strcmp(cep->name, "mixed-certificates")) { /* yes/no, applied at config run */ - } else - if (!strcmp(cep->name, "allow-ca-certificate")) + } else if (!strcmp(cep->name, "allow-ca-certificate")) { /* yes/no, applied at config run */ } else { config_error("%s:%i: unknown directive set::server-linking::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } @@ -278,24 +272,19 @@ int server_config_run_set_server_linking(ConfigFile *cf, ConfigEntry *ce, int ty * finalized, so it inherits the same way listen/link do. */ set_server_linking_tlsoptions_ce(cep); - } else - if (!strcmp(cep->name, "autoconnect-strategy")) + } else if (!strcmp(cep->name, "autoconnect-strategy")) { cfg.autoconnect_strategy = autoconnect_strategy_strtoval(cep->value); - } else - if (!strcmp(cep->name, "connect-timeout")) + } else if (!strcmp(cep->name, "connect-timeout")) { cfg.connect_timeout = config_checkval(cep->value, CFG_TIME); - } else - if (!strcmp(cep->name, "handshake-timeout")) + } else if (!strcmp(cep->name, "handshake-timeout")) { cfg.handshake_timeout = config_checkval(cep->value, CFG_TIME); - } else - if (!strcmp(cep->name, "mixed-certificates")) + } else if (!strcmp(cep->name, "mixed-certificates")) { tempiConf.server_linking_mixed_certificates = config_checkval(cep->value, CFG_YESNO); - } else - if (!strcmp(cep->name, "allow-ca-certificate")) + } else if (!strcmp(cep->name, "allow-ca-certificate")) { tempiConf.server_linking_allow_ca_certificate = config_checkval(cep->value, CFG_YESNO); } @@ -339,9 +328,9 @@ static void check_server_linking_cert_consistency_suggest_fix(TLSOptions *opts, "%s" " }\n" " }\n" - "}", inner); - } - else + "}", + inner); + } else { /* Nothing self-signed is in use, so do not name an existing file (it * may be the CA certificate). Recommend generating a dedicated one. @@ -359,7 +348,8 @@ static void check_server_linking_cert_consistency_suggest_fix(TLSOptions *opts, " key \"tls/server-linking.key.pem\";\n" " }\n" " }\n" - "}", CONFDIR); + "}", + CONFDIR); } } @@ -392,7 +382,7 @@ int check_server_linking_cert_consistency(void) struct { char desc[128]; int trusted; - int has_own_tls_options; /* explicit per-block tls-options, vs the global default */ + int has_own_tls_options; /* explicit per-block tls-options, vs the global default */ TLSOptions *opts; } s2s[128]; int n = 0, i, capped = 0, mismatch = 0, diff = -1, rec = -1, ca = -1; @@ -419,7 +409,11 @@ int check_server_linking_cert_consistency(void) */ if (!(listen->options & LISTENER_SERVERSONLY)) continue; - if (n >= (int)(sizeof(s2s)/sizeof(s2s[0]))) { capped = 1; break; } + if (n >= (int)(sizeof(s2s) / sizeof(s2s[0]))) + { + capped = 1; + break; + } /* A serversonly listener may also be reached plaintext and upgraded via * STARTTLS, which still presents listener->ssl_ctx, so no LISTENER_TLS check. */ @@ -451,7 +445,11 @@ int check_server_linking_cert_consistency(void) continue; if (link->auth && link->auth->type == AUTHTYPE_PLAINTEXT) continue; - if (n >= (int)(sizeof(s2s)/sizeof(s2s[0]))) { capped = 1; break; } + if (n >= (int)(sizeof(s2s) / sizeof(s2s[0]))) + { + capped = 1; + break; + } opts = tls_options_for_outgoing_link(link); if (!opts || !opts->spkifp) continue; /* no certificate loaded, nothing to compare */ @@ -534,8 +532,7 @@ int check_server_linking_cert_consistency(void) log_data_string("desc1", s2s[0].desc), log_data_string("desc2", s2s[diff >= 0 ? diff : 0].desc), log_data_string("offenders", offenders[0] ? offenders : "the relevant link/listen blocks")); - } - else + } else { /* set::server-linking is not configured. Adding it fixes blocks that * use the global/default certificate, but any block with its OWN @@ -608,8 +605,8 @@ int check_server_linking_cert_consistency(void) int server_config_test_deny_link(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { - int errors = 0; - ConfigEntry *cep; + int errors = 0; + ConfigEntry *cep; int has_mask = 0, has_rule = 0, has_type = 0; for (cep = ce->items; cep; cep = cep->next) @@ -620,8 +617,7 @@ int server_config_test_deny_link(ConfigFile *cf, ConfigEntry *ce, int type, int { errors++; continue; - } - else if (!strcmp(cep->name, "mask")) + } else if (!strcmp(cep->name, "mask")) { has_mask = 1; } else if (!strcmp(cep->name, "rule")) @@ -631,52 +627,49 @@ int server_config_test_deny_link(ConfigFile *cf, ConfigEntry *ce, int type, int if ((val = crule_test(cep->value))) { config_error("%s:%i: deny link::rule contains an invalid expression: %s", - cep->file->filename, - cep->line_number, - crule_errstring(val)); + cep->file->filename, + cep->line_number, + crule_errstring(val)); errors++; } - } - else if (!strcmp(cep->name, "type")) + } else if (!strcmp(cep->name, "type")) { if (has_type) { config_warn_duplicate(cep->file->filename, - cep->line_number, "deny link::type"); + cep->line_number, "deny link::type"); continue; } has_type = 1; if (!strcmp(cep->value, "auto")) - ; + ; else if (!strcmp(cep->value, "all")) - ; - else { + ; + else + { config_status("%s:%i: unknown deny link type", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } } else if (!strcmp(cep->name, "reason")) { - } - else + } else { config_error_unknown(cep->file->filename, - cep->line_number, "deny link", cep->name); + cep->line_number, "deny link", cep->name); errors++; } - } - else + } else { // Sections if (!strcmp(cep->name, "mask")) { if (cep->value || cep->items) has_mask = 1; - } - else + } else { config_error_unknown(cep->file->filename, - cep->line_number, "deny link", cep->name); + cep->line_number, "deny link", cep->name); errors++; continue; } @@ -685,19 +678,19 @@ int server_config_test_deny_link(ConfigFile *cf, ConfigEntry *ce, int type, int if (!has_mask) { config_error_missing(ce->file->filename, ce->line_number, - "deny link::mask"); + "deny link::mask"); errors++; } if (!has_rule) { config_error_missing(ce->file->filename, ce->line_number, - "deny link::rule"); + "deny link::rule"); errors++; } if (!has_type) { config_error_missing(ce->file->filename, ce->line_number, - "deny link::type"); + "deny link::type"); errors++; } @@ -717,17 +710,15 @@ int server_config_run_deny_link(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "mask")) { unreal_add_masks(&deny->mask, cep); - } - else if (!strcmp(cep->name, "rule")) + } else if (!strcmp(cep->name, "rule")) { deny->rule = crule_parse(cep->value); safe_strdup(deny->prettyrule, cep->value); - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { safe_strdup(deny->reason, cep->value); - } - else if (!strcmp(cep->name, "type")) { + } else if (!strcmp(cep->name, "type")) + { if (!strcmp(cep->value, "all")) deny->flag.type = CRULE_ALL; else if (!strcmp(cep->value, "auto")) @@ -1031,13 +1022,13 @@ EVENT(server_handshake_timeout) int _check_deny_version(Client *cptr, const char *software, int protocol, const char *flags) { ConfigItem_deny_version *vlines; - + for (vlines = conf_deny_version; vlines; vlines = vlines->next) { if (match_simple(vlines->mask, cptr->name)) break; } - + if (vlines) { char *proto = vlines->version; @@ -1086,15 +1077,15 @@ int _check_deny_version(Client *cptr, const char *software, int protocol, const if (vflags[i] == '!') { i++; - if (strchr(flags, vflags[i])) { + if (strchr(flags, vflags[i])) + { result = 1; break; } - } - else if (!strchr(flags, vflags[i])) + } else if (!strchr(flags, vflags[i])) { - result = 1; - break; + result = 1; + break; } } @@ -1108,7 +1099,7 @@ int _check_deny_version(Client *cptr, const char *software, int protocol, const return 0; } } - + return 1; } @@ -1122,28 +1113,28 @@ void _send_protoctl_servers(Client *client, int response) int sendit = 1; sendto_one(client, NULL, "PROTOCTL EAUTH=%s,%d,%s%s,UnrealIRCd-%s", - me.name, UnrealProtocol, serveropts, extraflags ? extraflags : "", buildid); - + me.name, UnrealProtocol, serveropts, extraflags ? extraflags : "", buildid); + ircsnprintf(buf, sizeof(buf), "PROTOCTL SERVERS=%s", response ? "*" : ""); list_for_each_entry(acptr, &global_server_list, client_node) { - snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%s,", acptr->id); + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s,", acptr->id); sendit = 1; - if (strlen(buf) > sizeof(buf)-12) + if (strlen(buf) > sizeof(buf) - 12) { - if (buf[strlen(buf)-1] == ',') - buf[strlen(buf)-1] = '\0'; + if (buf[strlen(buf) - 1] == ',') + buf[strlen(buf) - 1] = '\0'; sendto_one(client, NULL, "%s", buf); /* We use the asterisk here too for continuation lines */ ircsnprintf(buf, sizeof(buf), "PROTOCTL SERVERS=*"); sendit = 0; } } - + /* Remove final comma (if any) */ - if (buf[strlen(buf)-1] == ',') - buf[strlen(buf)-1] = '\0'; + if (buf[strlen(buf) - 1] == ',') + buf[strlen(buf) - 1] = '\0'; if (sendit) sendto_one(client, NULL, "%s", buf); @@ -1160,7 +1151,7 @@ void _send_server_message(Client *client) } sendto_one(client, NULL, "SERVER %s 1 :U%d-%s%s-%s %s", - me.name, UnrealProtocol, serveropts, extraflags ? extraflags : "", me.id, me.info); + me.name, UnrealProtocol, serveropts, extraflags ? extraflags : "", me.id, me.info); if (client->server) client->server->flags.server_sent = 1; @@ -1188,7 +1179,7 @@ ConfigItem_link *_verify_link(Client *client) if (!client->local->passwd) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_NO_PASSWORD", client, - "Link with server $client.details denied: No password provided. Protocol error."); + "Link with server $client.details denied: No password provided. Protocol error."); exit_client(client, NULL, "Missing password"); return NULL; } @@ -1213,11 +1204,12 @@ ConfigItem_link *_verify_link(Client *client) } link = client->server->conf; goto skip_host_check; - } else { + } else + { /* Hunt the linkblock down ;) */ link = find_link(client->name); } - + if (!link) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_UNKNOWN_SERVER", client, @@ -1225,7 +1217,7 @@ ConfigItem_link *_verify_link(Client *client) exit_client(client, NULL, LINK_DEFAULT_ERROR_MSG); return NULL; } - + if (!link->incoming.match) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_NO_INCOMING", client, @@ -1264,22 +1256,19 @@ skip_host_check: log_data_string("auth_failure_msg", "different password types on both sides of the link\n" "Read https://www.unrealircd.org/docs/FAQ#auth-fail-mixed for more information"), log_data_link_block(link)); - } else - if (link->auth->type == AUTHTYPE_SPKIFP) + } else if (link->auth->type == AUTHTYPE_SPKIFP) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_AUTH_FAILED", client, "Link with server $client.details denied: Authentication failed: $auth_failure_msg", log_data_string("auth_failure_msg", "spkifp mismatch"), log_data_link_block(link)); - } else - if (link->auth->type == AUTHTYPE_TLS_CLIENTCERT) + } else if (link->auth->type == AUTHTYPE_TLS_CLIENTCERT) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_AUTH_FAILED", client, "Link with server $client.details denied: Authentication failed: $auth_failure_msg", log_data_string("auth_failure_msg", "tlsclientcert mismatch"), log_data_link_block(link)); - } else - if (link->auth->type == AUTHTYPE_TLS_CLIENTCERTFP) + } else if (link->auth->type == AUTHTYPE_TLS_CLIENTCERTFP) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_AUTH_FAILED", client, "Link with server $client.details denied: Authentication failed: $auth_failure_msg", @@ -1358,7 +1347,7 @@ skip_host_check: "Server is using an outdated TLS protocol or cipher ($tls_cipher) and set::outdated-tls-policy::server is 'deny'.\n" "See https://www.unrealircd.org/docs/FAQ#server-outdated-tls", log_data_link_block(link), - log_data_string("tls_cipher", tls_get_cipher(client))); + log_data_string("tls_cipher", tls_get_cipher(client))); exit_client(client, NULL, "Server using outdates TLS protocol or cipher (set::outdated-tls-policy::server is 'deny')"); return NULL; } @@ -1377,8 +1366,7 @@ skip_host_check: log_data_link_block(link)); exit_client(client, NULL, "Server Exists (server trying to link with same name as myself)"); return NULL; - } else - if (IsULine(acptr->uplink)) + } else if (IsULine(acptr->uplink)) { /* Is behind a u-lined server: likely juped so we don't want to * allow it in with the new algo further below (bug #0006498). @@ -1389,7 +1377,8 @@ skip_host_check: log_data_link_block(link)); exit_client(client, NULL, "Server Exists (Juped)"); return NULL; - } else if (acptr->direction == acptr) { + } else if (acptr->direction == acptr) + { /* If both the old and the new server are locally connected then * we opt to allow the NEW link in and kill the OLD. * Downside is if a user runs two irc servers (or two processes) @@ -1402,22 +1391,23 @@ skip_host_check: * and fine-tuned for localonly+localonly in UnrealIRCd 6.2.3. */ unreal_log(ULOG_ERROR, "link", "LINK_DROPPED_REINTRODUCED", client, - "Link with server $client.details causes older link " - "with same server via $existing_client.server.uplink to be dropped.", - log_data_client("existing_client", acptr), + "Link with server $client.details causes older link " + "with same server via $existing_client.server.uplink to be dropped.", + log_data_client("existing_client", acptr), log_data_link_block(link)); exit_client_ex(acptr, client->direction, NULL, "Old link dropped, resyncing"); - } else { + } else + { /* Server already exists on the network via a remote path. * We cannot do the same "allow NEW, drop OLD" stuff as above, * because that is never guaranteed to be correct in such a case. * So we drop the NEW link, keep the OLD. Classic style. */ unreal_log(ULOG_ERROR, "link", "LINK_DENIED_SERVER_EXISTS", client, - "Link with server $client.details denied: " - "Server already exists via $existing_client.server.uplink.", - log_data_client("existing_client", acptr), - log_data_link_block(link)); + "Link with server $client.details denied: " + "Server already exists via $existing_client.server.uplink.", + log_data_client("existing_client", acptr), + log_data_link_block(link)); exit_client(client, NULL, "Server Exists"); return NULL; } @@ -1433,10 +1423,10 @@ skip_host_check: */ CMD_FUNC(cmd_server) { - const char *servername = NULL; /* Pointer for servername */ - char *ch = NULL; /* */ + const char *servername = NULL; /* Pointer for servername */ + char *ch = NULL; /* */ char descbuf[BUFSIZE]; - int hop = 0; + int hop = 0; char info[REALLEN + 61]; ConfigItem_link *aconf = NULL; char *flags = NULL, *protocol = NULL, *inf = NULL, *num = NULL; @@ -1452,7 +1442,7 @@ CMD_FUNC(cmd_server) if (parc < 4 || (!*parv[3])) { - exit_client(client, NULL, "Not enough SERVER parameters"); + exit_client(client, NULL, "Not enough SERVER parameters"); return; } @@ -1552,19 +1542,21 @@ CMD_FUNC(cmd_server) if (!_check_deny_version(client, NULL, atoi(protocol), flags)) return; /* Rejected */ - } else { + } else + { strlcpy(client->info, info[0] ? info : "server", sizeof(client->info)); } - } else { + } else + { strlcpy(client->info, info[0] ? info : "server", sizeof(client->info)); } if ((err = check_deny_link(aconf, 0))) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_DENY_LINK_BLOCK", client, - "Server link $servername rejected by deny link { } block: $reason", - log_data_string("servername", servername), - log_data_string("reason", err)); + "Server link $servername rejected by deny link { } block: $reason", + log_data_string("servername", servername), + log_data_string("reason", err)); exit_client_fmt(client, NULL, "Disallowed by connection rule: %s", err); return; } @@ -1614,8 +1606,7 @@ CMD_FUNC(cmd_server) log_data_string("tls_cipher", tls_get_cipher(client)), log_data_client("me", &me)); tls_link_notification_verify(client, aconf); - } - else + } else { unreal_log(ULOG_INFO, "link", "SERVER_LINKED", client, "Server linked: $me -> $client", @@ -1627,18 +1618,18 @@ CMD_FUNC(cmd_server) if (!IsLocalhost(client) && (iConf.plaintext_policy_server == POLICY_WARN)) { unreal_log(ULOG_WARNING, "link", "LINK_WARNING_NO_TLS", client, - "Link with server $client.details is unencrypted (not TLS). " - "We highly recommend to use TLS for server linking. " - "See https://www.unrealircd.org/docs/Linking_servers", - log_data_link_block(aconf)); + "Link with server $client.details is unencrypted (not TLS). " + "We highly recommend to use TLS for server linking. " + "See https://www.unrealircd.org/docs/Linking_servers", + log_data_link_block(aconf)); } if (IsSecure(client) && (iConf.outdated_tls_policy_server == POLICY_WARN) && outdated_tls_client(client)) { unreal_log(ULOG_WARNING, "link", "LINK_WARNING_OUTDATED_TLS", client, - "Link with server $client.details is using an outdated " - "TLS protocol or cipher ($tls_cipher).", - log_data_link_block(aconf), - log_data_string("tls_cipher", tls_get_cipher(client))); + "Link with server $client.details is using an outdated " + "TLS protocol or cipher ($tls_cipher).", + log_data_link_block(aconf), + log_data_string("tls_cipher", tls_get_cipher(client))); } } @@ -1665,7 +1656,7 @@ CMD_FUNC(cmd_server) CMD_FUNC(cmd_sid) { Client *acptr; - ConfigItem_link *aconf; + ConfigItem_link *aconf; ConfigItem_ban *bconf; int hop; const char *servername = parv[1]; @@ -1690,10 +1681,10 @@ CMD_FUNC(cmd_sid) if (!valid_sid(parv[3])) { unreal_log(ULOG_ERROR, "link", "REMOTE_LINK_DENIED_INVALID_SID", client, - "Denied remote server $servername which was introduced by $client: " - "Invalid SID.", - log_data_string("servername", servername), - log_data_string("sid", parv[3])); + "Denied remote server $servername which was introduced by $client: " + "Invalid SID.", + log_data_string("servername", servername), + log_data_string("sid", parv[3])); /* Since we cannot SQUIT via SID (since it is invalid), this gives * us huge doubts about the accuracy of the uplink, so in this case * we terminate the entire uplink. @@ -1724,10 +1715,10 @@ CMD_FUNC(cmd_sid) } unreal_log(ULOG_ERROR, "link", "REMOTE_LINK_DENIED_DUPLICATE_SERVER", client, - "Denied remote server $servername which was introduced by $client: " - "Already linked via $existing_client.server.uplink.", - log_data_string("servername", servername), - log_data_client("existing_client", acptr)); + "Denied remote server $servername which was introduced by $client: " + "Already linked via $existing_client.server.uplink.", + log_data_string("servername", servername), + log_data_client("existing_client", acptr)); sendto_one(client, NULL, "SQUIT %s :Server already exists", parv[3]); return; } @@ -1735,10 +1726,10 @@ CMD_FUNC(cmd_sid) if ((acptr = find_client(parv[3], NULL))) { unreal_log(ULOG_ERROR, "link", "LINK_DENIED_DUPLICATE_SID_SERVER", client, - "Denied server $servername with SID $sid: Server with SID $existing_client.id ($existing_client) is already linked.", - log_data_string("servername", servername), - log_data_string("sid", parv[3]), - log_data_client("existing_client", acptr)); + "Denied server $servername with SID $sid: Server with SID $existing_client.id ($existing_client) is already linked.", + log_data_string("servername", servername), + log_data_string("sid", parv[3]), + log_data_client("existing_client", acptr)); sendto_one(client, NULL, "SQUIT %s :Server with this SID (%s) already exists (%s)", parv[3], parv[3], acptr->name); return; } @@ -1763,9 +1754,9 @@ CMD_FUNC(cmd_sid) if (!valid_server_name(servername)) { unreal_log(ULOG_ERROR, "link", "REMOTE_LINK_DENIED_INVALID_SERVERNAME", client, - "Denied remote server $servername which was introduced by $client: " - "Invalid server name.", - log_data_string("servername", servername)); + "Denied remote server $servername which was introduced by $client: " + "Invalid server name.", + log_data_string("servername", servername)); sendto_one(client, NULL, "SQUIT %s :Invalid servername", parv[3]); return; } @@ -1774,10 +1765,10 @@ CMD_FUNC(cmd_sid) if (hop < 2) { unreal_log(ULOG_ERROR, "link", "REMOTE_LINK_DENIED_INVALID_HOP_COUNT", client, - "Denied remote server $servername which was introduced by $client: " - "Invalid server name.", - log_data_string("servername", servername), - log_data_integer("hop_count", hop)); + "Denied remote server $servername which was introduced by $client: " + "Invalid server name.", + log_data_string("servername", servername), + log_data_integer("hop_count", hop)); sendto_one(client, NULL, "SQUIT %s :Invalid hop count (%d)", parv[3], hop); return; } @@ -1785,8 +1776,8 @@ CMD_FUNC(cmd_sid) if (!client->direction->server->conf) { unreal_log(ULOG_ERROR, "link", "BUG_LOST_CONFIG", client, - "[BUG] Lost link conf record for link $direction.", - log_data_client("direction", direction)); + "[BUG] Lost link conf record for link $direction.", + log_data_client("direction", direction)); exit_client(client->direction, NULL, "BUG: lost link configuration"); return; } @@ -1796,24 +1787,24 @@ CMD_FUNC(cmd_sid) if (!aconf->hub) { unreal_log(ULOG_ERROR, "link", "REMOTE_LINK_DENIED_NO_HUB", client, - "Denied remote server $servername which was introduced by $client: " - "Server may not introduce this server ($direction is not a hub).", - log_data_string("servername", servername), - log_data_client("direction", client->direction)); + "Denied remote server $servername which was introduced by $client: " + "Server may not introduce this server ($direction is not a hub).", + log_data_string("servername", servername), + log_data_client("direction", client->direction)); sendto_one(client, NULL, "SQUIT %s :Server is not permitted to be a hub: %s", - parv[3], client->direction->name); + parv[3], client->direction->name); return; } if (!match_simple(aconf->hub, servername)) { unreal_log(ULOG_ERROR, "link", "REMOTE_LINK_DENIED_NO_MATCHING_HUB", client, - "Denied remote server $servername which was introduced by $client: " - "Server may not introduce this server ($direction hubmask does not allow it).", - log_data_string("servername", servername), - log_data_client("direction", client->direction)); + "Denied remote server $servername which was introduced by $client: " + "Server may not introduce this server ($direction hubmask does not allow it).", + log_data_string("servername", servername), + log_data_client("direction", client->direction)); sendto_one(client, NULL, "SQUIT %s :Hub config for %s does not allow introducing this server", - parv[3], client->direction->name); + parv[3], client->direction->name); return; } @@ -1822,12 +1813,12 @@ CMD_FUNC(cmd_sid) if (!match_simple(aconf->leaf, servername)) { unreal_log(ULOG_ERROR, "link", "REMOTE_LINK_DENIED_NO_MATCHING_LEAF", client, - "Denied remote server $servername which was introduced by $client: " - "Server may not introduce this server ($direction leaf config does not allow it).", - log_data_string("servername", servername), - log_data_client("direction", client->direction)); + "Denied remote server $servername which was introduced by $client: " + "Server may not introduce this server ($direction leaf config does not allow it).", + log_data_string("servername", servername), + log_data_client("direction", client->direction)); sendto_one(client, NULL, "SQUIT %s :Leaf config for %s does not allow introducing this server", - parv[3], client->direction->name); + parv[3], client->direction->name); return; } } @@ -1835,12 +1826,12 @@ CMD_FUNC(cmd_sid) if (aconf->leaf_depth && (hop > aconf->leaf_depth)) { unreal_log(ULOG_ERROR, "link", "REMOTE_LINK_DENIED_LEAF_DEPTH", client, - "Denied remote server $servername which was introduced by $client: " - "Server may not introduce this server ($direction leaf depth config does not allow it).", - log_data_string("servername", servername), - log_data_client("direction", client->direction)); + "Denied remote server $servername which was introduced by $client: " + "Server may not introduce this server ($direction leaf depth config does not allow it).", + log_data_string("servername", servername), + log_data_client("direction", client->direction)); sendto_one(client, NULL, "SQUIT %s :Leaf depth config for %s does not allow introducing this server", - parv[3], client->direction->name); + parv[3], client->direction->name); return; } @@ -1866,14 +1857,14 @@ CMD_FUNC(cmd_sid) { /* Log these (but don't show when still syncing) */ unreal_log(ULOG_INFO, "link", "SERVER_LINKED_REMOTE", acptr, - "Server linked: $client -> $other_server", - log_data_client("other_server", client)); + "Server linked: $client -> $other_server", + log_data_client("other_server", client)); } RunHook(HOOKTYPE_SERVER_CONNECT, acptr); sendto_server(client, 0, 0, NULL, ":%s SID %s %d %s :%s", - acptr->uplink->id, acptr->name, hop + 1, acptr->id, acptr->info); + acptr->uplink->id, acptr->name, hop + 1, acptr->id, acptr->info); RunHook(HOOKTYPE_POST_SERVER_CONNECT, acptr); } @@ -1885,7 +1876,7 @@ void _introduce_user(Client *to, Client *acptr) build_umode_string(acptr, 0, SEND_UMODES, buf); sendto_one_nickcmd(to, NULL, acptr, buf); - + send_moddata_client(to, acptr); if (acptr->user->away) @@ -1905,17 +1896,17 @@ void _introduce_user(Client *to, Client *acptr) if (CHECKSERVERPROTO(to, PROTO_EXTSWHOIS)) { sendto_one(to, NULL, ":%s SWHOIS %s + %s %d :%s", - me.id, acptr->name, s->setby, s->priority, s->line); + me.id, acptr->name, s->setby, s->priority, s->line); } else { sendto_one(to, NULL, ":%s SWHOIS %s :%s", - me.id, acptr->name, s->line); + me.id, acptr->name, s->line); } } } } -#define SafeStr(x) ((x && *(x)) ? (x) : "*") +#define SafeStr(x) ((x && *(x)) ? (x) : "*") /** Broadcast SINFO. * @param cptr The server to send the information about. @@ -1932,27 +1923,29 @@ void _broadcast_sinfo(Client *acptr, Client *to, Client *except) if (acptr->server->features.chanmodes[0]) { snprintf(chanmodes, sizeof(chanmodes), "%s,%s,%s,%s", - acptr->server->features.chanmodes[0], - acptr->server->features.chanmodes[1], - acptr->server->features.chanmodes[2], - acptr->server->features.chanmodes[3]); - } else { + acptr->server->features.chanmodes[0], + acptr->server->features.chanmodes[1], + acptr->server->features.chanmodes[2], + acptr->server->features.chanmodes[3]); + } else + { strlcpy(chanmodes, "*", sizeof(chanmodes)); } snprintf(buf, sizeof(buf), "%lld %d %s %s %s :%s", - (long long)acptr->server->boottime, - acptr->server->features.protocol, - SafeStr(acptr->server->features.usermodes), - chanmodes, - SafeStr(acptr->server->features.nickchars), - SafeStr(acptr->server->features.software)); + (long long)acptr->server->boottime, + acptr->server->features.protocol, + SafeStr(acptr->server->features.usermodes), + chanmodes, + SafeStr(acptr->server->features.nickchars), + SafeStr(acptr->server->features.software)); if (to) { /* Targetted to one server */ sendto_one(to, NULL, ":%s SINFO %s", acptr->id, buf); - } else { + } else + { /* Broadcast (except one side...) */ sendto_server(except, 0, 0, NULL, ":%s SINFO %s", acptr->id, buf); } @@ -1985,7 +1978,7 @@ int server_sync(Client *client, ConfigItem_link *aconf, int incoming) /* Broadcast new server to the rest of the network */ sendto_server(client, 0, 0, NULL, ":%s SID %s 2 %s :%s", - client->uplink->id, client->name, client->id, client->info); + client->uplink->id, client->name, client->id, client->info); /* Broadcast the just-linked-in featureset to other servers on our side */ broadcast_sinfo(client, NULL, client); @@ -2002,9 +1995,9 @@ int server_sync(Client *client, ConfigItem_link *aconf, int incoming) if (IsServer(acptr)) { sendto_one(client, NULL, ":%s SID %s %d %s :%s", - acptr->uplink->id, - acptr->name, acptr->hopcount + 1, - acptr->id, acptr->info); + acptr->uplink->id, + acptr->name, acptr->hopcount + 1, + acptr->id, acptr->info); /* Also signal to the just-linked server which * servers are fully linked. @@ -2042,24 +2035,24 @@ int server_sync(Client *client, ConfigItem_link *aconf, int incoming) send_channel_modes_sjoin3(client, channel); if (channel->topic_time) sendto_one(client, NULL, "TOPIC %s %s %lld :%s", - channel->name, channel->topic_nick, - (long long)channel->topic_time, channel->topic); + channel->name, channel->topic_nick, + (long long)channel->topic_time, channel->topic); send_moddata_channel(client, channel); } } - + /* Send ModData for all member(ship) structs */ send_moddata_members(client); - + /* pass on TKLs */ tkl_sync(client); RunHook(HOOKTYPE_SERVER_SYNC, client); sendto_one(client, NULL, "NETINFO %i %lld %i %s 0 0 0 :%s", - irccounts.global_max, (long long)TStime(), UnrealProtocol, - CLOAK_KEY_CHECKSUM, - NETWORK_NAME); + irccounts.global_max, (long long)TStime(), UnrealProtocol, + CLOAK_KEY_CHECKSUM, + NETWORK_NAME); /* Send EOS (End Of Sync) to the just linked server... */ sendto_one(client, NULL, ":%s EOS", me.id); @@ -2098,14 +2091,14 @@ void tls_link_notification_verify(Client *client, ConfigItem_link *aconf) return; /* wtf ? */ unreal_log(ULOG_WARNING, "link", "WARN_UNVERIFIED_LINK_CERTIFICATE", client, - "This server link is not verified (and hence is susceptible to an active MITM attack). " - "In future UnrealIRCd versions this will become a fatal error!\n" - "More information about this can be found on https://www.unrealircd.org/Link_verification\n" - "In short: in the configuration file, change the 'link $client {' block to use this as a password:\n" - "password \"$spki_fingerprint\" { spkifp; };\n" - "And follow the instructions on the other side of the link as well (which will be similar, but will use a different hash)", - log_data_link_block(aconf), - log_data_string("spki_fingerprint", spki_fp)); + "This server link is not verified (and hence is susceptible to an active MITM attack). " + "In future UnrealIRCd versions this will become a fatal error!\n" + "More information about this can be found on https://www.unrealircd.org/Link_verification\n" + "In short: in the configuration file, change the 'link $client {' block to use this as a password:\n" + "password \"$spki_fingerprint\" { spkifp; };\n" + "And follow the instructions on the other side of the link as well (which will be similar, but will use a different hash)", + log_data_link_block(aconf), + log_data_string("spki_fingerprint", spki_fp)); } /** This will send "to" a full list of the modes for channel channel, @@ -2142,8 +2135,8 @@ void send_channel_modes_sjoin3(Client *to, Channel *channel) channel_modes(to, modebuf, parabuf, sizeof(modebuf), sizeof(parabuf), channel, 1); /* Strip final space if needed */ - if (*parabuf && (parabuf[strlen(parabuf)-1] == ' ')) - parabuf[strlen(parabuf)-1] = '\0'; + if (*parabuf && (parabuf[strlen(parabuf) - 1] == ' ')) + parabuf[strlen(parabuf) - 1] = '\0'; if (!modebuf[1]) nomode = 1; @@ -2161,20 +2154,20 @@ void send_channel_modes_sjoin3(Client *to, Channel *channel) if (nomode && nopara) { ircsnprintf(buf, sizeof(buf), - ":%s SJOIN %lld %s :", me.id, - (long long)channel->creationtime, channel->name); + ":%s SJOIN %lld %s :", me.id, + (long long)channel->creationtime, channel->name); } if (nopara && !nomode) { ircsnprintf(buf, sizeof(buf), - ":%s SJOIN %lld %s %s :", me.id, - (long long)channel->creationtime, channel->name, modebuf); + ":%s SJOIN %lld %s %s :", me.id, + (long long)channel->creationtime, channel->name, modebuf); } if (!nopara && !nomode) { ircsnprintf(buf, sizeof(buf), - ":%s SJOIN %lld %s %s %s :", me.id, - (long long)channel->creationtime, channel->name, modebuf, parabuf); + ":%s SJOIN %lld %s %s %s :", me.id, + (long long)channel->creationtime, channel->name, modebuf, parabuf); } prebuflen = strlen(buf); @@ -2216,8 +2209,8 @@ void send_channel_modes_sjoin3(Client *to, Channel *channel) sendto_one(to, mtags, "%s", buf); sent++; ircsnprintf(buf, sizeof(buf), - ":%s SJOIN %lld %s :", me.id, - (long long)channel->creationtime, channel->name); + ":%s SJOIN %lld %s :", me.id, + (long long)channel->creationtime, channel->name); prebuflen = strlen(buf); bufptr = buf + prebuflen; *bufptr = '\0'; @@ -2235,7 +2228,7 @@ void send_channel_modes_sjoin3(Client *to, Channel *channel) p = mystpcpy(p, ban->banstr); *p++ = ' '; *p = '\0'; - + /* this is: if (strlen(tbuf) + strlen(buf) > BUFSIZE - 8) */ if ((p - tbuf) + (bufptr - buf) > BUFSIZE - 8) { @@ -2243,8 +2236,8 @@ void send_channel_modes_sjoin3(Client *to, Channel *channel) sendto_one(to, mtags, "%s", buf); sent++; ircsnprintf(buf, sizeof(buf), - ":%s SJOIN %lld %s :", me.id, - (long long)channel->creationtime, channel->name); + ":%s SJOIN %lld %s :", me.id, + (long long)channel->creationtime, channel->name); prebuflen = strlen(buf); bufptr = buf + prebuflen; *bufptr = '\0'; @@ -2262,7 +2255,7 @@ void send_channel_modes_sjoin3(Client *to, Channel *channel) p = mystpcpy(p, ban->banstr); *p++ = ' '; *p = '\0'; - + /* this is: if (strlen(tbuf) + strlen(buf) > BUFSIZE - 8) */ if ((p - tbuf) + (bufptr - buf) > BUFSIZE - 8) { @@ -2270,8 +2263,8 @@ void send_channel_modes_sjoin3(Client *to, Channel *channel) sendto_one(to, mtags, "%s", buf); sent++; ircsnprintf(buf, sizeof(buf), - ":%s SJOIN %lld %s :", me.id, - (long long)channel->creationtime, channel->name); + ":%s SJOIN %lld %s :", me.id, + (long long)channel->creationtime, channel->name); prebuflen = strlen(buf); bufptr = buf + prebuflen; *bufptr = '\0'; @@ -2289,7 +2282,7 @@ void send_channel_modes_sjoin3(Client *to, Channel *channel) p = mystpcpy(p, ban->banstr); *p++ = ' '; *p = '\0'; - + /* this is: if (strlen(tbuf) + strlen(buf) > BUFSIZE - 8) */ if ((p - tbuf) + (bufptr - buf) > BUFSIZE - 8) { @@ -2297,8 +2290,8 @@ void send_channel_modes_sjoin3(Client *to, Channel *channel) sendto_one(to, mtags, "%s", buf); sent++; ircsnprintf(buf, sizeof(buf), - ":%s SJOIN %lld %s :", me.id, - (long long)channel->creationtime, channel->name); + ":%s SJOIN %lld %s :", me.id, + (long long)channel->creationtime, channel->name); prebuflen = strlen(buf); bufptr = buf + prebuflen; *bufptr = '\0'; @@ -2318,9 +2311,9 @@ void server_generic_free(ModData *m) safe_free(m->ptr); } -int server_post_connect(Client *client) { - if (cfg.autoconnect_strategy == AUTOCONNECT_SEQUENTIAL_FALLBACK && last_autoconnect_server - && !strcmp(last_autoconnect_server, client->name)) +int server_post_connect(Client *client) +{ + if (cfg.autoconnect_strategy == AUTOCONNECT_SEQUENTIAL_FALLBACK && last_autoconnect_server && !strcmp(last_autoconnect_server, client->name)) { last_autoconnect_server = NULL; } @@ -2372,7 +2365,7 @@ void _connect_server(ConfigItem_link *aconf, Client *by, struct hostent *hp) log_data_link_block(aconf)); return; } - + if (!hp) { /* Remove "cache" */ @@ -2395,7 +2388,7 @@ void _connect_server(ConfigItem_link *aconf, Client *by, struct hostent *hp) if (aconf->outgoing.bind_ip && (is_valid_ip(aconf->outgoing.bind_ip) == 4)) ipv4_explicit_bind = 1; - + /* We need this 'aconf->refcount++' or else there's a race condition between * starting resolving the host and the result of the resolver (we could * REHASH in that timeframe) leading to an invalid (freed!) 'aconf'. @@ -2404,8 +2397,8 @@ void _connect_server(ConfigItem_link *aconf, Client *by, struct hostent *hp) aconf->refcount++; unrealdns_gethostbyname_link(aconf->outgoing.hostname, aconf, ipv4_explicit_bind); unreal_log(ULOG_INFO, "link", "LINK_RESOLVING", NULL, - "Resolving hostname $link_block.hostname...", - log_data_link_block(aconf)); + "Resolving hostname $link_block.hostname...", + log_data_link_block(aconf)); /* Going to resolve the hostname, in the meantime we return (asynchronous operation) */ return; } @@ -2446,15 +2439,14 @@ void _connect_server(ConfigItem_link *aconf, Client *by, struct hostent *hp) { SetTLSConnectHandshake(client); fd_setselect(client->local->fd, FD_SELECT_WRITE, unreal_tls_client_handshake, client); - } - else + } else fd_setselect(client->local->fd, FD_SELECT_WRITE, completed_connection, client); unreal_log(ULOG_INFO, "link", "LINK_CONNECTING", client, - aconf->outgoing.file - ? "Trying to activate link with server $client ($link_block.file)..." - : "Trying to activate link with server $client ($link_block.ip:$link_block.port)...", - log_data_link_block(aconf)); + aconf->outgoing.file + ? "Trying to activate link with server $client ($link_block.file)..." + : "Trying to activate link with server $client ($link_block.ip:$link_block.port)...", + log_data_link_block(aconf)); } /** Helper function for connect_server() to prepare the actual bind()'ing and connect(). @@ -2478,7 +2470,7 @@ static int connect_server_helper(ConfigItem_link *aconf, Client *client) /* Tag outgoing localhost connections as localhost as well */ if (aconf->connect_ip && is_loopback_ip(aconf->connect_ip)) - SetLocalhost(client); + SetLocalhost(client); if (aconf->outgoing.file) SetUnixSocket(client); @@ -2487,7 +2479,7 @@ static int connect_server_helper(ConfigItem_link *aconf, Client *client) if (!set_client_ip(client, aconf->connect_ip ? aconf->connect_ip : "127.0.0.1")) return 0; /* Killed (would be odd) */ - + snprintf(buf, sizeof buf, "Outgoing connection: %s", get_client_name(client, TRUE)); client->local->fd = fd_socket(IsUnixSocket(client) ? AF_UNIX : (IsIPV6(client) ? AF_INET6 : AF_INET), SOCK_STREAM, 0, buf); if (client->local->fd < 0) @@ -2495,21 +2487,21 @@ static int connect_server_helper(ConfigItem_link *aconf, Client *client) if (ERRNO == P_EMFILE) { unreal_log(ULOG_ERROR, "link", "LINK_ERROR_MAXCLIENTS", client, - "Connect to $client failed: no more sockets available", - log_data_link_block(aconf)); + "Connect to $client failed: no more sockets available", + log_data_link_block(aconf)); return 0; } unreal_log(ULOG_ERROR, "link", "LINK_ERROR_SOCKET", client, - "Connect to $client failed: could not create socket: $socket_error", - log_data_socket_error(-1), - log_data_link_block(aconf)); + "Connect to $client failed: could not create socket: $socket_error", + log_data_socket_error(-1), + log_data_link_block(aconf)); return 0; } if (++OpenFiles >= maxclients) { unreal_log(ULOG_ERROR, "link", "LINK_ERROR_MAXCLIENTS", client, - "Connect to $client failed: no more connections available", - log_data_link_block(aconf)); + "Connect to $client failed: no more connections available", + log_data_link_block(aconf)); return 0; } @@ -2525,10 +2517,10 @@ static int connect_server_helper(ConfigItem_link *aconf, Client *client) if (!unreal_bind(client->local->fd, bindip, 0, client->local->socket_type)) { unreal_log(ULOG_ERROR, "link", "LINK_ERROR_SOCKET_BIND", client, - "Connect to $client failed: could not bind socket to $link_block.bind_ip: $socket_error -- " - "Your link::outgoing::bind-ip is probably incorrect.", - log_data_socket_error(client->local->fd), - log_data_link_block(aconf)); + "Connect to $client failed: could not bind socket to $link_block.bind_ip: $socket_error -- " + "Your link::outgoing::bind-ip is probably incorrect.", + log_data_socket_error(client->local->fd), + log_data_link_block(aconf)); return 0; } } @@ -2536,15 +2528,15 @@ static int connect_server_helper(ConfigItem_link *aconf, Client *client) set_sock_opts(client->local->fd, client, client->local->socket_type); if (!unreal_connect(client->local->fd, - aconf->outgoing.file ? aconf->outgoing.file : client->ip, - aconf->outgoing.port, client->local->socket_type)) + aconf->outgoing.file ? aconf->outgoing.file : client->ip, + aconf->outgoing.port, client->local->socket_type)) { - unreal_log(ULOG_ERROR, "link", "LINK_ERROR_CONNECT", client, - aconf->outgoing.file - ? "Connect to $client ($link_block.file) failed: $socket_error" - : "Connect to $client ($link_block.ip:$link_block.port) failed: $socket_error", - log_data_socket_error(client->local->fd), - log_data_link_block(aconf)); + unreal_log(ULOG_ERROR, "link", "LINK_ERROR_CONNECT", client, + aconf->outgoing.file + ? "Connect to $client ($link_block.file) failed: $socket_error" + : "Connect to $client ($link_block.ip:$link_block.port) failed: $socket_error", + log_data_socket_error(client->local->fd), + log_data_link_block(aconf)); return 0; } diff --git a/src/modules/sethost.c b/src/modules/sethost.c index fdffaf08f..274593e20 100644 --- a/src/modules/sethost.c +++ b/src/modules/sethost.c @@ -25,16 +25,15 @@ CMD_FUNC(cmd_sethost); /* Place includes here */ -#define MSG_SETHOST "SETHOST" /* sethost */ +#define MSG_SETHOST "SETHOST" /* sethost */ -ModuleHeader MOD_HEADER - = { - "sethost", /* Name of module */ - "5.0", /* Version */ - "command /sethost", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sethost", /* Name of module */ + "5.0", /* Version */ + "command /sethost", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -63,9 +62,9 @@ CMD_FUNC(cmd_sethost) { const char *vhost; - if (MyUser(client) && !ValidatePermissionsForPath("self:set:host",client,NULL,NULL,NULL)) + if (MyUser(client) && !ValidatePermissionsForPath("self:set:host", client, NULL, NULL, NULL)) { - sendnumeric(client, ERR_NOPRIVILEGES); + sendnumeric(client, ERR_NOPRIVILEGES); return; } @@ -75,7 +74,7 @@ CMD_FUNC(cmd_sethost) vhost = parv[1]; if (BadPtr(vhost)) - { + { if (MyConnect(client)) sendnotice(client, "*** Syntax: /SetHost "); return; @@ -143,9 +142,9 @@ CMD_FUNC(cmd_sethost) if (MyConnect(client)) { sendto_one(client, NULL, ":%s MODE %s :+xt", client->name, client->name); - sendnotice(client, - "Your nick!user@host-mask is now (%s!%s@%s) - To disable it type /mode %s -x", - client->name, client->user->username, vhost, - client->name); + sendnotice(client, + "Your nick!user@host-mask is now (%s!%s@%s) - To disable it type /mode %s -x", + client->name, client->user->username, vhost, + client->name); } } diff --git a/src/modules/setident.c b/src/modules/setident.c index 1c0448185..3ae71a0ee 100644 --- a/src/modules/setident.c +++ b/src/modules/setident.c @@ -22,18 +22,17 @@ #include "unrealircd.h" -#define MSG_SETIDENT "SETIDENT" /* set ident */ +#define MSG_SETIDENT "SETIDENT" /* set ident */ CMD_FUNC(cmd_setident); -ModuleHeader MOD_HEADER - = { - "setident", /* Name of module */ - "5.0", /* Version */ - "/setident", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "setident", /* Name of module */ + "5.0", /* Version */ + "/setident", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -126,6 +125,6 @@ CMD_FUNC(cmd_setident) if (MyConnect(client)) { sendnotice(client, "Your nick!user@host-mask is now (%s!%s@%s)", - client->name, client->user->username, GetHost(client)); + client->name, client->user->username, GetHost(client)); } } diff --git a/src/modules/setname.c b/src/modules/setname.c index 426ad6832..813899d2c 100644 --- a/src/modules/setname.c +++ b/src/modules/setname.c @@ -25,20 +25,19 @@ CMD_FUNC(cmd_setname); char *setname_isupport_param(void); -#define MSG_SETNAME "SETNAME" /* setname */ +#define MSG_SETNAME "SETNAME" /* setname */ #define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define STR(x) STR_HELPER(x) long CAP_SETNAME = 0L; -ModuleHeader MOD_HEADER - = { - "setname", /* Name of module */ - "5.0", /* Version */ - "command /setname", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "setname", /* Name of module */ + "5.0", /* Version */ + "command /setname", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -46,7 +45,7 @@ MOD_INIT() ClientCapability *c; MARK_AS_OFFICIAL_MODULE(modinfo); - CommandAdd(modinfo->handle, MSG_SETNAME, cmd_setname, 1, CMD_USER|CMD_TEXTANALYSIS); + CommandAdd(modinfo->handle, MSG_SETNAME, cmd_setname, 1, CMD_USER | CMD_TEXTANALYSIS); memset(&cap, 0, sizeof(cap)); cap.name = "setname"; @@ -71,7 +70,8 @@ MOD_UNLOAD() return MOD_SUCCESS; } -char *setname_isupport_param(void){ +char *setname_isupport_param(void) +{ return STR(REALLEN); } @@ -80,7 +80,7 @@ char *setname_isupport_param(void){ * parv[1] - gecos * D: This will set your gecos to be (like (/setname :The lonely wanderer)) this is now compatible with IRCv3 SETNAME --k4be -*/ +*/ CMD_FUNC(cmd_setname) { int xx; @@ -110,8 +110,7 @@ CMD_FUNC(cmd_setname) new_message(client, recv_mtags, &mtags); sendto_one(client, mtags, ":%s FAIL SETNAME INVALID_REALNAME :\"Real names\" may maximum be %i characters of length", me.name, REALLEN); free_message_tags(mtags); - } - else + } else { sendnotice(client, "*** /SetName Error: \"Real names\" may maximum be %i characters of length", REALLEN); } @@ -128,7 +127,7 @@ CMD_FUNC(cmd_setname) if (match_spamfilter(client, spamfilter_user, SPAMF_USER, "SETNAME", NULL, 0, clictx, NULL)) { if (IsDead(client)) - return; /* Killed, don't bother anymore */ + return; /* Killed, don't bother anymore */ /* Was rejected by spamfilter, restore the realname */ if (HasCapabilityFast(client, CAP_SETNAME)) @@ -142,13 +141,14 @@ CMD_FUNC(cmd_setname) } /* Check for realname bans here too */ - if (!ValidatePermissionsForPath("immune:server-ban:ban-realname",client,NULL,NULL,NULL) && + if (!ValidatePermissionsForPath("immune:server-ban:ban-realname", client, NULL, NULL, NULL) && ((bconf = find_ban(NULL, client->info, CONF_BAN_REALNAME)))) { - banned_client(client, "realname", bconf->reason?bconf->reason:"", NULL, 0, 0); + banned_client(client, "realname", bconf->reason ? bconf->reason : "", NULL, 0, 0); return; } - } else { + } else + { /* remote user */ strlcpy(client->info, parv[1], sizeof(client->info)); } @@ -166,6 +166,6 @@ CMD_FUNC(cmd_setname) sendnotice(client, "Your \"real name\" is now set to be %s - you have to set it manually to undo it", parv[1]); } free_message_tags(mtags); - + RunHook(HOOKTYPE_REALNAME_CHANGE, client, oldinfo); } diff --git a/src/modules/silence.c b/src/modules/silence.c index 7bb999dbf..15f55d149 100644 --- a/src/modules/silence.c +++ b/src/modules/silence.c @@ -24,20 +24,18 @@ CMD_FUNC(cmd_silence); -ModuleHeader MOD_HEADER - = { - "silence", - "5.0", - "command /silence", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "silence", + "5.0", + "command /silence", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Structs */ typedef struct Silence Silence; /** A /SILENCE entry */ -struct Silence -{ +struct Silence { Silence *prev, *next; char mask[]; /**< user!nick@host mask of silence entry */ }; @@ -46,7 +44,7 @@ struct Silence ModDataInfo *silence_md = NULL; /* Macros */ -#define SILENCELIST(x) ((Silence *)moddata_local_client(x, silence_md).ptr) +#define SILENCELIST(x) ((Silence *)moddata_local_client(x, silence_md).ptr) /* Forward declarations */ int _is_silenced(Client *, Client *); @@ -121,8 +119,7 @@ CMD_FUNC(cmd_silence) if (action == '-' || action == '+') { p++; - } else - if (!strchr(p, '@') && !strchr(p, '.') && !strchr(p, '!') && !strchr(p, '*') && !find_user(p, NULL)) + } else if (!strchr(p, '@') && !strchr(p, '.') && !strchr(p, '!') && !strchr(p, '*') && !find_user(p, NULL)) { sendnumeric(client, ERR_NOSUCHNICK, parv[1]); return; @@ -135,7 +132,7 @@ CMD_FUNC(cmd_silence) (action != '-' && add_silence(client, p, 1))) { sendto_prefix_one(client, client, NULL, ":%s SILENCE %c%s", - client->name, action, p); + client->name, action, p); } return; } @@ -187,8 +184,7 @@ int _add_silence(Client *client, const char *mask, int senderr) if (senderr) sendnumeric(client, ERR_SILELISTFULL, mask); return 0; - } - else + } else { if (match_simple(s->mask, mask)) return 0; @@ -196,7 +192,7 @@ int _add_silence(Client *client, const char *mask, int senderr) } /* Add the new entry */ - s = safe_alloc(sizeof(Silence)+strlen(mask)+1); + s = safe_alloc(sizeof(Silence) + strlen(mask) + 1); strcpy(s->mask, mask); /* safe, allocated above */ AddListItemUnchecked(s, moddata_local_client(client, silence_md).ptr); return 1; diff --git a/src/modules/sinfo.c b/src/modules/sinfo.c index 15235a2f5..6eb076a46 100644 --- a/src/modules/sinfo.c +++ b/src/modules/sinfo.c @@ -6,14 +6,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "sinfo", - "5.0", - "Server information", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sinfo", + "5.0", + "Server information", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ CMD_FUNC(cmd_sinfo); @@ -21,7 +20,7 @@ CMD_FUNC(cmd_sinfo); MOD_INIT() { MARK_AS_OFFICIAL_MODULE(modinfo); - CommandAdd(modinfo->handle, "SINFO", cmd_sinfo, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, "SINFO", cmd_sinfo, MAXPARA, CMD_USER | CMD_SERVER); return MOD_SUCCESS; } @@ -87,7 +86,8 @@ CMD_FUNC(sinfo_server) safe_free(client->server->features.chanmodes[1]); safe_free(client->server->features.chanmodes[2]); safe_free(client->server->features.chanmodes[3]); - } else { + } else + { parse_chanmodes_protoctl(client, parv[4]); } @@ -99,10 +99,10 @@ CMD_FUNC(sinfo_server) /* Software is always the last parameter. It is currently parv[6] * but may change later. So always use parv[parc-1]. */ - if (!strcmp(parv[parc-1], "*")) + if (!strcmp(parv[parc - 1], "*")) safe_free(client->server->features.software); else - safe_strdup(client->server->features.software, parv[parc-1]); + safe_strdup(client->server->features.software, parv[parc - 1]); if (is_services_but_not_ulined(client)) { @@ -117,7 +117,7 @@ CMD_FUNC(sinfo_server) sendto_server(client, 0, 0, NULL, ":%s SINFO %s", client->id, buf); } -#define SafeDisplayStr(x) ((x && *(x)) ? (x) : "-") +#define SafeDisplayStr(x) ((x && *(x)) ? (x) : "-") CMD_FUNC(sinfo_user) { Client *acptr; @@ -139,7 +139,8 @@ CMD_FUNC(sinfo_user) { sendtxtnumeric(client, "Up since: -"); sendtxtnumeric(client, "Uptime: -"); - } else { + } else + { sendtxtnumeric(client, "Up since: %s", pretty_date(acptr->server->boottime)); sendtxtnumeric(client, "Uptime: %s", @@ -150,7 +151,8 @@ CMD_FUNC(sinfo_user) if (!acptr->server->features.chanmodes[0]) { sendtxtnumeric(client, "Channel modes: -"); - } else { + } else + { sendtxtnumeric(client, "Channel modes: %s,%s,%s,%s", SafeDisplayStr(acptr->server->features.chanmodes[0]), SafeDisplayStr(acptr->server->features.chanmodes[1]), diff --git a/src/modules/sjoin.c b/src/modules/sjoin.c index 814460e8d..372e7a5e4 100644 --- a/src/modules/sjoin.c +++ b/src/modules/sjoin.c @@ -24,22 +24,21 @@ CMD_FUNC(cmd_sjoin); -#define MSG_SJOIN "SJOIN" +#define MSG_SJOIN "SJOIN" -ModuleHeader MOD_HEADER - = { - "sjoin", - "5.1", - "command /sjoin", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sjoin", + "5.1", + "command /sjoin", + "UnrealIRCd Team", + "unrealircd-6", +}; char modebuf[BUFSIZE], parabuf[BUFSIZE]; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SJOIN, cmd_sjoin, MAXPARA, CMD_SERVER|CMD_BIGLINES); + CommandAdd(modinfo->handle, MSG_SJOIN, cmd_sjoin, MAXPARA, CMD_SERVER | CMD_BIGLINES); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -56,7 +55,7 @@ MOD_UNLOAD() typedef struct xParv aParv; struct xParv { - int parc; + int parc; const char *parv[256]; }; @@ -64,12 +63,12 @@ aParv pparv; aParv *mp2parv(char *xmbuf, char *parmbuf) { - int c; + int c; char *p, *s; pparv.parv[0] = xmbuf; c = 1; - + for (s = strtoken(&p, parmbuf, " "); s; s = strtoken(&p, NULL, " ")) { pparv.parv[c] = s; @@ -134,23 +133,38 @@ static void send_local_chan_mode_mlm(MessageTag *recv_mtags, Client *client, Cha */ /* Some ugly macros, but useful */ -#define Addit(mode,param) if ((strlen(parabuf) + strlen(param) + 11 < MODEBUFLEN) && (b <= MAXMODEPARAMS)) { \ - if (*parabuf) \ - strcat(parabuf, " ");\ - strcat(parabuf, param);\ - modebuf[b++] = mode;\ - modebuf[b] = 0;\ -}\ -else {\ - send_local_chan_mode(recv_mtags, client, channel, modebuf, parabuf); \ - strcpy(parabuf,param);\ - /* modebuf[0] should stay what it was ('+' or '-') */ \ - modebuf[1] = mode;\ - modebuf[2] = '\0';\ - b = 2;\ -} -#define Addsingle(x) do { modebuf[b] = x; b++; modebuf[b] = '\0'; } while(0) -#define CheckStatus(x,y) do { if (modeflags & (y)) { Addit((x), acptr->name); } } while(0) +#define Addit(mode, param) \ + if ((strlen(parabuf) + strlen(param) + 11 < MODEBUFLEN) && (b <= MAXMODEPARAMS)) \ + { \ + if (*parabuf) \ + strcat(parabuf, " "); \ + strcat(parabuf, param); \ + modebuf[b++] = mode; \ + modebuf[b] = 0; \ + } else \ + { \ + send_local_chan_mode(recv_mtags, client, channel, modebuf, parabuf); \ + strcpy(parabuf, param); \ + /* modebuf[0] should stay what it was ('+' or '-') */ \ + modebuf[1] = mode; \ + modebuf[2] = '\0'; \ + b = 2; \ + } +#define Addsingle(x) \ + do \ + { \ + modebuf[b] = x; \ + b++; \ + modebuf[b] = '\0'; \ + } while (0) +#define CheckStatus(x, y) \ + do \ + { \ + if (modeflags & (y)) \ + { \ + Addit((x), acptr->name); \ + } \ + } while (0) CMD_FUNC(cmd_sjoin) { @@ -158,7 +172,7 @@ CMD_FUNC(cmd_sjoin) unsigned short nomode; /**< An SJOIN without MODE? */ unsigned short removeours; /**< Remove our modes */ unsigned short removetheirs; /**< Remove their modes (or actually: do not ADD their modes, the MODE -... line will be sent later by the other side) */ - unsigned short merge; /**< same timestamp: merge their & our modes */ + unsigned short merge; /**< same timestamp: merge their & our modes */ char pvar[MAXMODEPARAMS][MODEBUFLEN + 3]; char cbuf[MAXLINELENGTH]; char scratch_buf[MAXLINELENGTH]; /**< scratch buffer */ @@ -175,9 +189,9 @@ CMD_FUNC(cmd_sjoin) Hook *h; Cmode *cm; time_t ts, oldts; - unsigned short b=0; + unsigned short b = 0; char *tp, *p, *saved = NULL; - + if (!IsServer(client) || parc < 4) return; @@ -197,7 +211,8 @@ CMD_FUNC(cmd_sjoin) { channel = make_channel(parv[2]); oldts = -1; - } else { + } else + { oldts = channel->creationtime; } @@ -206,9 +221,9 @@ CMD_FUNC(cmd_sjoin) if (IsInvalidChannelTS(ts)) { unreal_log(ULOG_WARNING, "sjoin", "SJOIN_INVALID_TIMESTAMP", client, - "SJOIN for channel $channel has invalid timestamp $send_timestamp (from $client)", - log_data_channel("channel", channel), - log_data_integer("send_timestamp", ts)); + "SJOIN for channel $channel has invalid timestamp $send_timestamp (from $client)", + log_data_channel("channel", channel), + log_data_integer("send_timestamp", ts)); /* Pretend they match our creation time (matches U6 behavior in m_mode.c) */ ts = channel->creationtime; } @@ -217,17 +232,14 @@ CMD_FUNC(cmd_sjoin) { /* Newly created channel (from our POV), so set the correct creationtime here */ channel->creationtime = ts; - } else - if (channel->creationtime > ts) + } else if (channel->creationtime > ts) { removeours = 1; channel->creationtime = ts; - } - else if (channel->creationtime < ts) + } else if (channel->creationtime < ts) { removetheirs = 1; - } - else if (channel->creationtime == ts) + } else if (channel->creationtime == ts) { merge = 1; } @@ -262,7 +274,7 @@ CMD_FUNC(cmd_sjoin) modebuf[1] = '\0'; parabuf[0] = '\0'; b = 1; - while(channel->banlist) + while (channel->banlist) { Ban *ban = channel->banlist; Addit('b', ban->banstr); @@ -271,7 +283,7 @@ CMD_FUNC(cmd_sjoin) safe_free(ban->who); free_ban(ban); } - while(channel->exlist) + while (channel->exlist) { Ban *ban = channel->exlist; Addit('e', ban->banstr); @@ -280,7 +292,7 @@ CMD_FUNC(cmd_sjoin) safe_free(ban->who); free_ban(ban); } - while(channel->invexlist) + while (channel->invexlist) { Ban *ban = channel->invexlist; Addit('I', ban->banstr); @@ -315,7 +327,7 @@ CMD_FUNC(cmd_sjoin) modebuf[0] = '+'; modebuf[1] = '\0'; b = 1; - strlcpy(cbuf, parv[parc-1], sizeof cbuf); + strlcpy(cbuf, parv[parc - 1], sizeof cbuf); sj3_parabuf[0] = '\0'; for (i = 2; i <= (parc - 2); i++) @@ -354,9 +366,9 @@ CMD_FUNC(cmd_sjoin) { /* this obviously should never happen */ unreal_log(ULOG_WARNING, "sjoin", "SJOIN_INVALID_SJSBY", client, - "SJOIN for channel $channel has invalid SJSBY in item '$item' (from $client)", - log_data_channel("channel", channel), - log_data_string("item", s)); + "SJOIN for channel $channel has invalid SJSBY in item '$item' (from $client)", + log_data_channel("channel", channel), + log_data_string("item", s)); continue; } *end++ = '\0'; @@ -366,14 +378,14 @@ CMD_FUNC(cmd_sjoin) { /* missing setby parameter */ unreal_log(ULOG_WARNING, "sjoin", "SJOIN_INVALID_SJSBY", client, - "SJOIN for channel $channel has invalid SJSBY in item '$item' (from $client)", - log_data_channel("channel", channel), - log_data_string("item", s)); + "SJOIN for channel $channel has invalid SJSBY in item '$item' (from $client)", + log_data_channel("channel", channel), + log_data_string("item", s)); continue; } *p++ = '\0'; - setat = atol(tp+1); + setat = atol(tp + 1); setby = p; sjsby_info = 1; @@ -432,10 +444,10 @@ CMD_FUNC(cmd_sjoin) /* Nick collision, don't kick or it desyncs -Griever*/ continue; } - + sendto_one(client, NULL, - ":%s KICK %s %s :Fake direction", - me.id, channel->name, acptr->name); + ":%s KICK %s %s :Fake direction", + me.id, channel->name, acptr->name); unreal_log(ULOG_WARNING, "sjoin", "SJOIN_FAKE_DIRECTION", client, "Fake direction from server $client in SJOIN " "for user $existing_client on $existing_client.user.servername " @@ -458,9 +470,9 @@ CMD_FUNC(cmd_sjoin) if (IsSynched(acptr->uplink)) { unreal_log(ULOG_INFO, "join", "REMOTE_CLIENT_JOIN", acptr, - "User $client joined $channel", - log_data_channel("channel", channel), - log_data_string("modes", item_modes)); + "User $client joined $channel", + log_data_channel("channel", channel), + log_data_string("modes", item_modes)); } RunHook(HOOKTYPE_REMOTE_JOIN, acptr, channel, recv_mtags); new_message_special(acptr, recv_mtags, &mtags, ":%s JOIN %s", acptr->name, channel->name); @@ -482,7 +494,7 @@ CMD_FUNC(cmd_sjoin) { unreal_log(ULOG_ERROR, "sjoin", "BUG_OVERSIZED_SJOIN", client, "Oversized SJOIN [$sjoin_place] in channel $channel when adding '$str$str2' to '$buf'", - log_data_channel("channel", channel), + log_data_channel("channel", channel), log_data_string("sjoin_place", "UID-MEMBER"), log_data_string("str", prefix), log_data_string("str2", acptr->id), @@ -490,7 +502,7 @@ CMD_FUNC(cmd_sjoin) continue; } } - sprintf(uid_buf+strlen(uid_buf), "%s%s ", prefix, acptr->id); + sprintf(uid_buf + strlen(uid_buf), "%s%s ", prefix, acptr->id); if (strlen(uid_sjsby_buf) + strlen(prefix) + IDLEN > BUFSIZE - 10) { @@ -502,7 +514,7 @@ CMD_FUNC(cmd_sjoin) { unreal_log(ULOG_ERROR, "sjoin", "BUG_OVERSIZED_SJOIN", client, "Oversized SJOIN [$sjoin_place] in channel $channel when adding '$str$str2' to '$buf'", - log_data_channel("channel", channel), + log_data_channel("channel", channel), log_data_string("sjoin_place", "SJS-MEMBER"), log_data_string("str", prefix), log_data_string("str2", acptr->id), @@ -510,14 +522,13 @@ CMD_FUNC(cmd_sjoin) continue; } } - sprintf(uid_sjsby_buf+strlen(uid_sjsby_buf), "%s%s ", prefix, acptr->id); - } - else + sprintf(uid_sjsby_buf + strlen(uid_sjsby_buf), "%s%s ", prefix, acptr->id); + } else { /* It's a list mode................ */ const char *str; ExtbanType ban_type; - + if (removetheirs) continue; @@ -532,7 +543,7 @@ CMD_FUNC(cmd_sjoin) if (!str) continue; /* invalid ban syntax */ strlcpy(item, str, sizeof(item)); - + /* Adding of list modes */ if (*item_modes == 'b') { @@ -566,7 +577,7 @@ CMD_FUNC(cmd_sjoin) { unreal_log(ULOG_ERROR, "sjoin", "BUG_OVERSIZED_SJOIN", client, "Oversized SJOIN [$sjoin_place] in channel $channel when adding '$str$str2' to '$buf'", - log_data_channel("channel", channel), + log_data_channel("channel", channel), log_data_string("sjoin_place", "UID-LMODE"), log_data_string("str", prefix), log_data_string("str2", item), @@ -574,7 +585,7 @@ CMD_FUNC(cmd_sjoin) continue; } } - sprintf(uid_buf+strlen(uid_buf), "%s%s ", prefix, item); + sprintf(uid_buf + strlen(uid_buf), "%s%s ", prefix, item); *scratch_buf = '\0'; if (sjsby_info) @@ -592,14 +603,14 @@ CMD_FUNC(cmd_sjoin) { unreal_log(ULOG_ERROR, "sjoin", "BUG_OVERSIZED_SJOIN", client, "Oversized SJOIN [$sjoin_place] in channel $channel when adding '$str' to '$buf'", - log_data_channel("channel", channel), + log_data_channel("channel", channel), log_data_string("sjoin_place", "SJS-LMODE"), log_data_string("str", scratch_buf), log_data_string("buf", uid_sjsby_buf)); continue; } } - strcpy(uid_sjsby_buf+strlen(uid_sjsby_buf), scratch_buf); /* size already checked above */ + strcpy(uid_sjsby_buf + strlen(uid_sjsby_buf), scratch_buf); /* size already checked above */ } continue; } @@ -613,7 +624,7 @@ CMD_FUNC(cmd_sjoin) modebuf[b] = '\0'; send_local_chan_mode(recv_mtags, client, channel, modebuf, parabuf); } - + if (!merge && !removetheirs && !nomode) { MessageTag *mtags = NULL; @@ -689,7 +700,7 @@ CMD_FUNC(cmd_sjoin) /* First, check if we had something that is now gone * note that: oldmode.* = us, channel->mode.* = merged. */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (cm->letter && !cm->local && @@ -701,7 +712,8 @@ CMD_FUNC(cmd_sjoin) const char *parax = cm_getparameter_ex(oldmode.mode_params, cm->letter); //char *parax = cm->get_param(extcmode_get_struct(oldmode.modeparam, cm->letter)); Addit(cm->letter, parax); - } else { + } else + { Addsingle(cm->letter); } } @@ -710,8 +722,7 @@ CMD_FUNC(cmd_sjoin) if (b > 1) { Addsingle('+'); - } - else + } else { strlcpy(modebuf, "+", sizeof modebuf); b = 1; @@ -722,7 +733,7 @@ CMD_FUNC(cmd_sjoin) * * First the simple single letter modes... */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if ((cm->letter) && !(oldmode.mode & cm->mode) && @@ -735,7 +746,8 @@ CMD_FUNC(cmd_sjoin) { Addit(cm->letter, parax); } - } else { + } else + { Addsingle(cm->letter); } } @@ -747,7 +759,7 @@ CMD_FUNC(cmd_sjoin) * note that: oldmode.* = us before, channel->mode.* = merged. * if we win: copy oldmode to channel mode, if they win: send the mode */ - for (cm=channelmodes; cm; cm = cm->next) + for (cm = channelmodes; cm; cm = cm->next) { if (cm->letter && cm->paracount && (oldmode.mode & cm->mode) && @@ -758,7 +770,7 @@ CMD_FUNC(cmd_sjoin) char flag = cm->letter; void *ourm = GETPARASTRUCTEX(oldmode.mode_params, flag); void *theirm = GETPARASTRUCT(channel, flag); - + r = cm->sjoin_check(channel, ourm, theirm); switch (r) { @@ -801,7 +813,7 @@ CMD_FUNC(cmd_sjoin) for (h = Hooks[HOOKTYPE_CHANNEL_SYNCED]; h; h = h->next) { - int i = (*(h->func.intfunc))(channel,merge,removetheirs,nomode); + int i = (*(h->func.intfunc))(channel, merge, removetheirs, nomode); if (i == 1) return; /* channel no longer exists */ } diff --git a/src/modules/slog.c b/src/modules/slog.c index 3df066d98..4729746e8 100644 --- a/src/modules/slog.c +++ b/src/modules/slog.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "slog", - "5.0", - "S2S logging", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "slog", + "5.0", + "S2S logging", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ CMD_FUNC(cmd_slog); @@ -43,7 +42,7 @@ MOD_TEST() } MOD_INIT() -{ +{ MARK_AS_OFFICIAL_MODULE(modinfo); CommandAdd(modinfo->handle, "SLOG", cmd_slog, MAXPARA, CMD_SERVER); diff --git a/src/modules/spamreport.c b/src/modules/spamreport.c index d611e2d5f..4e06d7577 100644 --- a/src/modules/spamreport.c +++ b/src/modules/spamreport.c @@ -4,13 +4,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "spamreport", - "1.0.1", - "Send spam reports via SPAMREPORT and spamreport { } blocks", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "spamreport", + "1.0.1", + "Send spam reports via SPAMREPORT and spamreport { } blocks", + "UnrealIRCd Team", + "unrealircd-6", }; /** For rate limiting the rate limit message :D */ @@ -98,8 +97,8 @@ int tkl_config_test_spamreport(ConfigFile *cf, ConfigEntry *ce, int type, int *e { ConfigEntry *cep, *cepp; int errors = 0; - char has_url=0, has_type=0, has_type_dronebl=0, has_http_method=0; - char has_dronebl_type=0, has_dronebl_rpckey=0; + char has_url = 0, has_type = 0, has_type_dronebl = 0, has_http_method = 0; + char has_dronebl_type = 0, has_dronebl_rpckey = 0; /* We are only interested in spamreport { } blocks */ if ((type != CONFIG_MAIN) || strcmp(ce->name, "spamreport")) @@ -108,7 +107,7 @@ int tkl_config_test_spamreport(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (!ce->value) { config_error("%s:%i: spamreport block has no name, should be like: spamfilter { }", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } @@ -117,91 +116,82 @@ int tkl_config_test_spamreport(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (!strcmp(cep->name, "except")) { test_match_block(cf, cep, &errors); - } else - if (!strcmp(cep->name, "parameters")) + } else if (!strcmp(cep->name, "parameters")) { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!cepp->value) { config_error_empty(cepp->file->filename, cepp->line_number, - "spamreport::parameters", cepp->name); + "spamreport::parameters", cepp->name); errors++; - } - else if (!strcmp(cepp->name, "rpckey")) + } else if (!strcmp(cepp->name, "rpckey")) has_dronebl_rpckey = 1; else if (!strcmp(cepp->name, "type")) has_dronebl_type = 1; else if (!strcmp(cepp->name, "staging")) ; } - } - else if (!cep->value) + } else if (!cep->value) { config_error_empty(cep->file->filename, cep->line_number, - "spamreport", cep->name); + "spamreport", cep->name); errors++; continue; - } else - if (!strcmp(cep->name, "url")) + } else if (!strcmp(cep->name, "url")) { if (has_url) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamreport::url"); + cep->line_number, "spamreport::url"); continue; } has_url = 1; - } - else if (!strcmp(cep->name, "type")) + } else if (!strcmp(cep->name, "type")) { if (has_type) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamreport::type"); + cep->line_number, "spamreport::type"); continue; } has_type = parse_spamreport_type(cep->value); if (!has_type) { config_error("%s:%i: spamreport::type: unknown type '%s', supported types are: simple, dronebl, central-spamreport.", - cep->file->filename, cep->line_number, cep->value); + cep->file->filename, cep->line_number, cep->value); errors++; } - } - else if (!strcmp(cep->name, "http-method")) + } else if (!strcmp(cep->name, "http-method")) { if (has_http_method) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamreport::http-method"); + cep->line_number, "spamreport::http-method"); continue; } has_http_method = 1; if (strcmp(cep->value, "get") && strcmp(cep->value, "post")) { config_error("%s:%i: spamreport::http-method: only 'get' and 'post' are supported", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "rate-limit")) + } else if (!strcmp(cep->name, "rate-limit")) { int count = 0, period = 0; if (!config_parse_flood(cep->value, &count, &period)) { config_error("%s:%i: spamreport::rate-limit: invalid format, must be count:time.", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } - } - else if (!strcmp(cep->name, "on-server-ban")) + } else if (!strcmp(cep->name, "on-server-ban")) { - } - else + } else { config_error_unknown(cep->file->filename, cep->line_number, - "spamreport", cep->name); + "spamreport", cep->name); errors++; continue; } @@ -216,8 +206,7 @@ int tkl_config_test_spamreport(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (has_type == SPAMREPORT_TYPE_CENTRAL_SPAMREPORT) { /* Nothing required */ - } else - if (has_type == SPAMREPORT_TYPE_DRONEBL) + } else if (has_type == SPAMREPORT_TYPE_DRONEBL) { if (!has_dronebl_rpckey || !has_dronebl_type) { @@ -270,8 +259,7 @@ int tkl_config_run_spamreport(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "url")) { safe_strdup(s->url, cep->value); - } - else if (!strcmp(cep->name, "type")) + } else if (!strcmp(cep->name, "type")) { s->type = parse_spamreport_type(cep->value); @@ -279,37 +267,32 @@ int tkl_config_run_spamreport(ConfigFile *cf, ConfigEntry *ce, int type) !is_module_loaded("central-blocklist")) { config_warn("%s:%d: blacklist block with type 'central-spamreport' but the 'central-blocklist' module is not loaded.", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); } - } - else if (!strcmp(cep->name, "http-method")) + } else if (!strcmp(cep->name, "http-method")) { if (!strcmp(cep->value, "get")) s->http_method = HTTP_METHOD_GET; else if (!strcmp(cep->value, "post")) s->http_method = HTTP_METHOD_POST; - } - else if (!strcmp(cep->name, "rate-limit")) + } else if (!strcmp(cep->name, "rate-limit")) { config_parse_flood(cep->value, &s->rate_limit_count, &s->rate_limit_period); - } - else if (!strcmp(cep->name, "parameters")) + } else if (!strcmp(cep->name, "parameters")) { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!strcmp(cepp->name, "staging")) { - if (cepp->value && config_checkval(cepp->value, CFG_YESNO)==0) + if (cepp->value && config_checkval(cepp->value, CFG_YESNO) == 0) continue; /* skip on 'staging no;' */ } add_nvplist(&s->parameters, 0, cepp->name, cepp->value); } - } - else if (!strcmp(cep->name, "except")) + } else if (!strcmp(cep->name, "except")) { conf_match_block(cf, cep, &s->except); - } - else if (!strcmp(cep->name, "on-server-ban")) + } else if (!strcmp(cep->name, "on-server-ban")) { s->on_server_ban = config_checkval(cep->value, CFG_YESNO); } @@ -399,11 +382,11 @@ int spamfilter_block_rate_limited(Spamreport *spamreport) if (s->last_warning_sent + SPAMREPORT_RATE_LIMIT_WARNING_EVERY < TStime()) { unreal_log(ULOG_WARNING, "spamreport", "SPAMREPORT_RATE_LIMIT", NULL, - "[spamreport] Rate limit of $rate_limit_count:$rate_limit_period hit " - "for block $spamreport_block -- further requests dropped (throttled).", - log_data_integer("rate_limit_count", spamreport->rate_limit_count), - log_data_integer("rate_limit_period", spamreport->rate_limit_period), - log_data_string("spamreport_block", spamreport->name)); + "[spamreport] Rate limit of $rate_limit_count:$rate_limit_period hit " + "for block $spamreport_block -- further requests dropped (throttled).", + log_data_integer("rate_limit_count", spamreport->rate_limit_count), + log_data_integer("rate_limit_period", spamreport->rate_limit_period), + log_data_string("spamreport_block", spamreport->name)); s->last_warning_sent = TStime(); } return 1; /* Limit exceeded */ @@ -466,7 +449,7 @@ int _spamreport(Client *client, const char *ip, NameValuePrioList *details, cons NameValuePrioList *list = NULL; list = duplicate_nvplist(details); add_nvplist(&list, -1, "ip", ip); - buildvarstring_nvp(s->url, urlbuf, sizeof(urlbuf), list, BUILDVARSTRING_URLENCODE|BUILDVARSTRING_UNKNOWN_VAR_IS_EMPTY|BUILDVARSTRING_KEEP_SPACE_FOR_EMPTY_VAR); + buildvarstring_nvp(s->url, urlbuf, sizeof(urlbuf), list, BUILDVARSTRING_URLENCODE | BUILDVARSTRING_UNKNOWN_VAR_IS_EMPTY | BUILDVARSTRING_KEEP_SPACE_FOR_EMPTY_VAR); url = urlbuf; safe_free_nvplist(list); if (s->http_method == HTTP_METHOD_POST) @@ -475,8 +458,7 @@ int _spamreport(Client *client, const char *ip, NameValuePrioList *details, cons if (body) *body++ = '\0'; } - } else - if (s->type == SPAMREPORT_TYPE_DRONEBL) + } else if (s->type == SPAMREPORT_TYPE_DRONEBL) { NameValuePrioList *list = NULL; NameValuePrioList *list2 = NULL; @@ -491,12 +473,11 @@ int _spamreport(Client *client, const char *ip, NameValuePrioList *details, cons " \n" "\n", find_nvplist(s->parameters, "staging") ? " staging='1'" : ""); - buildvarstring_nvp(fmtstring, bodybuf, sizeof(bodybuf), list, BUILDVARSTRING_XML|BUILDVARSTRING_UNKNOWN_VAR_IS_EMPTY|BUILDVARSTRING_KEEP_SPACE_FOR_EMPTY_VAR); + buildvarstring_nvp(fmtstring, bodybuf, sizeof(bodybuf), list, BUILDVARSTRING_XML | BUILDVARSTRING_UNKNOWN_VAR_IS_EMPTY | BUILDVARSTRING_KEEP_SPACE_FOR_EMPTY_VAR); body = bodybuf; safe_free_nvplist(list); // frees all the duplicated lists add_nvplist(&headers, 0, "Content-Type", "text/xml"); - } else - if (s->type == SPAMREPORT_TYPE_CENTRAL_SPAMREPORT) + } else if (s->type == SPAMREPORT_TYPE_CENTRAL_SPAMREPORT) { return central_spamreport(client, by, s->url); } else @@ -529,7 +510,7 @@ CMD_FUNC(cmd_spamreport) const char *ip; int n; - if (!ValidatePermissionsForPath("server-ban:spamreport",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:spamreport", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -551,10 +532,11 @@ CMD_FUNC(cmd_spamreport) if (parc > 2) { sendto_one(target, NULL, ":%s SPAMREPORT %s %s", - client->id, parv[1], parv[2]); - } else { + client->id, parv[1], parv[2]); + } else + { sendto_one(target, NULL, ":%s SPAMREPORT %s", - client->id, parv[1]); + client->id, parv[1]); } return; } diff --git a/src/modules/sqline.c b/src/modules/sqline.c index 2af6e991b..2a7fa001e 100644 --- a/src/modules/sqline.c +++ b/src/modules/sqline.c @@ -23,18 +23,16 @@ CMD_FUNC(cmd_sqline); /* Place includes here */ -#define MSG_SQLINE "SQLINE" /* SQLINE */ +#define MSG_SQLINE "SQLINE" /* SQLINE */ - -ModuleHeader MOD_HEADER - = { - "sqline", /* Name of module */ - "5.0", /* Version */ - "command /sqline", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sqline", /* Name of module */ + "5.0", /* Version */ + "command /sqline", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() @@ -66,15 +64,15 @@ CMD_FUNC(cmd_sqline) char mo[32]; const char *comment = (parc == 3) ? parv[2] : NULL; const char *tkllayer[9] = { - me.name, /*0 server.name */ - "+", /*1 +|- */ - "Q", /*2 G */ - "*" , /*3 user */ - parv[1], /*4 host */ - client->name, /*5 setby */ - "0", /*6 expire_at */ - NULL, /*7 set_at */ - "no reason", /*8 reason */ + me.name, /*0 server.name */ + "+", /*1 +|- */ + "Q", /*2 G */ + "*", /*3 user */ + parv[1], /*4 host */ + client->name, /*5 setby */ + "0", /*6 expire_at */ + NULL, /*7 set_at */ + "no reason", /*8 reason */ }; if (parc < 2) diff --git a/src/modules/squit.c b/src/modules/squit.c index e17ac497e..51a96f0f6 100644 --- a/src/modules/squit.c +++ b/src/modules/squit.c @@ -24,20 +24,19 @@ CMD_FUNC(cmd_squit); -#define MSG_SQUIT "SQUIT" +#define MSG_SQUIT "SQUIT" -ModuleHeader MOD_HEADER - = { - "squit", - "5.0", - "command /squit", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "squit", + "5.0", + "command /squit", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SQUIT, cmd_squit, 2, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_SQUIT, cmd_squit, 2, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -65,7 +64,7 @@ CMD_FUNC(cmd_squit) // FIXME: this function is way too confusing, and full of old shit? - if (!ValidatePermissionsForPath("route:local",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("route:local", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -119,8 +118,8 @@ CMD_FUNC(cmd_squit) sendnumeric(client, ERR_NOSUCHSERVER, server); return; } - if (MyUser(client) && ((!ValidatePermissionsForPath("route:global",client,NULL,NULL,NULL) && !MyConnect(target)) || - (!ValidatePermissionsForPath("route:local",client,NULL,NULL,NULL) && MyConnect(target)))) + if (MyUser(client) && ((!ValidatePermissionsForPath("route:global", client, NULL, NULL, NULL) && !MyConnect(target)) || + (!ValidatePermissionsForPath("route:local", client, NULL, NULL, NULL) && MyConnect(target)))) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -134,8 +133,7 @@ CMD_FUNC(cmd_squit) "SQUIT: Forced server disconnect of $target by $client ($reason)", log_data_client("target", target), log_data_string("reason", comment)); - } - else if (MyConnect(target)) + } else if (MyConnect(target)) { if (target->user) { diff --git a/src/modules/sreply.c b/src/modules/sreply.c index f02f7ea2a..9f08747ef 100644 --- a/src/modules/sreply.c +++ b/src/modules/sreply.c @@ -24,14 +24,13 @@ CMD_FUNC(cmd_sreply); -ModuleHeader MOD_HEADER - = { - "sreply", /* Name of module */ - "1.0", /* Version */ - "Server command SREPLY", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sreply", /* Name of module */ + "1.0", /* Version */ + "Server command SREPLY", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() @@ -50,7 +49,7 @@ MOD_LOAD() /* Called when module is unloaded */ MOD_UNLOAD() { - return MOD_SUCCESS; + return MOD_SUCCESS; } /** @@ -78,10 +77,10 @@ CMD_FUNC(cmd_sreply) } /* For a locally connected user... */ - if (!strcmp(parv[2],"F")) + if (!strcmp(parv[2], "F")) sendto_one(target, recv_mtags, ":%s FAIL %s", client->name, parv[3]); - else if (!strcmp(parv[2],"W")) + else if (!strcmp(parv[2], "W")) sendto_one(target, recv_mtags, ":%s WARN %s", client->name, parv[3]); - else if (!strcmp(parv[2],"N")) + else if (!strcmp(parv[2], "N")) sendto_one(target, recv_mtags, ":%s NOTE %s", client->name, parv[3]); } diff --git a/src/modules/staff.c b/src/modules/staff.c index af8bc81e4..78b97f9c1 100644 --- a/src/modules/staff.c +++ b/src/modules/staff.c @@ -20,24 +20,23 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "staff", - "3.8", - "/STAFF command", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "staff", + "3.8", + "/STAFF command", + "UnrealIRCd Team", + "unrealircd-6", +}; -#define MSG_STAFF "STAFF" +#define MSG_STAFF "STAFF" -#define DEF_STAFF_FILE CONFDIR "/network.staff" -#define STAFF_FILE (staff_file ? staff_file : DEF_STAFF_FILE) +#define DEF_STAFF_FILE CONFDIR "/network.staff" +#define STAFF_FILE (staff_file ? staff_file : DEF_STAFF_FILE) -#define RPL_STAFF ":%s 700 %s :- %s" -#define RPL_STAFFSTART ":%s 701 %s :- %s IRC Network Staff Information -" -#define RPL_ENDOFSTAFF ":%s 702 %s :End of /STAFF command." -#define RPL_NOSTAFF ":%s 703 %s :Network Staff File is missing" +#define RPL_STAFF ":%s 700 %s :- %s" +#define RPL_STAFFSTART ":%s 701 %s :- %s IRC Network Staff Information -" +#define RPL_ENDOFSTAFF ":%s 702 %s :End of /STAFF command." +#define RPL_NOSTAFF ":%s 703 %s :Network Staff File is missing" /* Forward declarations */ static void unload_motd_file(MOTDFile *list); diff --git a/src/modules/standard-replies.c b/src/modules/standard-replies.c index c60b78490..e4e89dfce 100644 --- a/src/modules/standard-replies.c +++ b/src/modules/standard-replies.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "standard-replies", - "6.0", - "standard-replies CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "standard-replies", + "6.0", + "standard-replies CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ long CAP_STANDARD_REPLIES = 0L; diff --git a/src/modules/starttls.c b/src/modules/starttls.c index 7bcfc6856..8503304c3 100644 --- a/src/modules/starttls.c +++ b/src/modules/starttls.c @@ -24,23 +24,22 @@ CMD_FUNC(cmd_starttls); -#define MSG_STARTTLS "STARTTLS" +#define MSG_STARTTLS "STARTTLS" -ModuleHeader MOD_HEADER - = { - "starttls", - "5.0", - "command /starttls", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "starttls", + "5.0", + "command /starttls", + "UnrealIRCd Team", + "unrealircd-6", +}; long CLICAP_STARTTLS; MOD_INIT() { ClientCapabilityInfo cap; - + MARK_AS_OFFICIAL_MODULE(modinfo); CommandAdd(modinfo->handle, MSG_STARTTLS, cmd_starttls, MAXPARA, CMD_UNREGISTERED); memset(&cap, 0, sizeof(cap)); diff --git a/src/modules/stats.c b/src/modules/stats.c index b78caaff9..e406f735a 100644 --- a/src/modules/stats.c +++ b/src/modules/stats.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_stats); -#define MSG_STATS "STATS" +#define MSG_STATS "STATS" -ModuleHeader MOD_HEADER - = { - "stats", - "5.0", - "command /stats", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "stats", + "5.0", + "command /stats", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -52,7 +51,7 @@ MOD_UNLOAD() return MOD_SUCCESS; } -extern MODVAR int max_connection_count; +extern MODVAR int max_connection_count; int stats_banversion(Client *, const char *); int stats_links(Client *, const char *); @@ -85,7 +84,7 @@ int stats_fdtable(Client *, const char *); int stats_linecache(Client *client, const char *para); #define SERVER_AS_PARA 0x1 -#define FLAGS_AS_PARA 0x2 +#define FLAGS_AS_PARA 0x2 struct statstab { char flag; @@ -152,34 +151,37 @@ int stats_compare(const char *s1, const char *s2) return 1; } -static inline struct statstab *stats_binary_search(char c) { +static inline struct statstab *stats_binary_search(char c) +{ int start = 0; - int stop = sizeof(StatsTable)/sizeof(StatsTable[0])-1; + int stop = sizeof(StatsTable) / sizeof(StatsTable[0]) - 1; int mid; - while (start <= stop) { - mid = (start+stop)/2; + while (start <= stop) + { + mid = (start + stop) / 2; if (c < StatsTable[mid].flag) - stop = mid-1; + stop = mid - 1; else if (StatsTable[mid].flag == c) return &StatsTable[mid]; else - start = mid+1; + start = mid + 1; } return NULL; } -static inline struct statstab *stats_search(const char *s) { +static inline struct statstab *stats_search(const char *s) +{ int i; for (i = 0; StatsTable[i].flag; i++) - if (!stats_compare(StatsTable[i].longflag,s)) + if (!stats_compare(StatsTable[i].longflag, s)) return &StatsTable[i]; return NULL; } static inline char *stats_combine_parv(const char *p1, const char *p2) { - static char buf[BUFSIZE+1]; - ircsnprintf(buf, sizeof(buf), "%s %s", p1, p2); + static char buf[BUFSIZE + 1]; + ircsnprintf(buf, sizeof(buf), "%s %s", p1, p2); return buf; } @@ -238,7 +240,7 @@ static inline int allow_user_stats_short(char c) l = tolower(c); /* Hack for the flags that are case insensitive */ if (l == 'o' || l == 'y' || l == 'k' || l == 'g' || l == 'x' || l == 'c' || - l =='f' || l == 'i' || l == 'h' || l == 'm') + l == 'f' || l == 'i' || l == 'h' || l == 'm') { if (islower(c) && strchr(ALLOW_USER_STATS, toupper(c))) return 1; @@ -270,7 +272,7 @@ static inline int allow_user_stats_long(const char *s) /* This is pretty slow, but it isn't used often so it isn't a big deal */ static inline char *allow_user_stats_long_to_short() { - static char buffer[BUFSIZE+1]; + static char buffer[BUFSIZE + 1]; int i = 0; OperStat *os; for (os = iConf.allow_user_stats_ext; os; os = os->next) @@ -294,8 +296,7 @@ CMD_FUNC(cmd_stats) { if (hunt_server(client, recv_mtags, "STATS", 2, parc, parv) != HUNTED_ISME) return; - } - else if (parc == 4 && parv[2][0] != '+' && parv[2][0] != '-') + } else if (parc == 4 && parv[2][0] != '+' && parv[2][0] != '-') { if (hunt_server(client, recv_mtags, "STATS", 2, parc, parv) != HUNTED_ISME) return; @@ -310,17 +311,16 @@ CMD_FUNC(cmd_stats) /* Decide if we are looking for 1 char or a string */ if (parv[1][0] && !parv[1][1]) { - if (!ValidatePermissionsForPath("server:info:stats",client,NULL,NULL,NULL) && !allow_user_stats_short(parv[1][0])) + if (!ValidatePermissionsForPath("server:info:stats", client, NULL, NULL, NULL) && !allow_user_stats_short(parv[1][0])) { sendnumeric(client, ERR_NOPRIVILEGES); return; } /* Old style, we can use a binary search here */ stat = stats_binary_search(parv[1][0]); - } - else + } else { - if (!ValidatePermissionsForPath("server:info:stats",client,NULL,NULL,NULL) && !allow_user_stats_long(parv[1])) + if (!ValidatePermissionsForPath("server:info:stats", client, NULL, NULL, NULL) && !allow_user_stats_long(parv[1])) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -354,23 +354,20 @@ CMD_FUNC(cmd_stats) if (parc > 2 && (parv[2][0] == '+' || parv[2][0] == '-')) { if (parc > 3) - stat->func(client, stats_combine_parv(parv[2],parv[3])); + stat->func(client, stats_combine_parv(parv[2], parv[3])); else stat->func(client, parv[2]); - } - else if (parc > 3) + } else if (parc > 3) stat->func(client, parv[3]); else stat->func(client, NULL); - } - else if (stat->options & SERVER_AS_PARA) + } else if (stat->options & SERVER_AS_PARA) { if (parc > 2) stat->func(client, parv[2]); else stat->func(client, NULL); - } - else + } else stat->func(client, NULL); /* Modules can append data: @@ -393,7 +390,7 @@ int stats_banversion(Client *client, const char *para) if (bans->flag.type != CONF_BAN_VERSION) continue; sendnumeric(client, RPL_STATSBANVER, - bans->mask, bans->reason ? bans->reason : "No Reason"); + bans->mask, bans->reason ? bans->reason : "No Reason"); } return 0; } @@ -407,37 +404,36 @@ int stats_links(Client *client, const char *para) for (link_p = conf_link; link_p; link_p = link_p->next) { sendnumericfmt(client, RPL_STATSCLINE, "C - * %s %i %s %s%s%s", - link_p->servername, - link_p->outgoing.port, - link_p->class->name, - (link_p->outgoing.options & CONNECT_OUTGOING_AUTO) ? "a" : "", - (link_p->outgoing.options & CONNECT_OUTGOING_TLS) ? "S" : "", - (link_p->flag.temporary == 1) ? "T" : ""); + link_p->servername, + link_p->outgoing.port, + link_p->class->name, + (link_p->outgoing.options & CONNECT_OUTGOING_AUTO) ? "a" : "", + (link_p->outgoing.options & CONNECT_OUTGOING_TLS) ? "S" : "", + (link_p->flag.temporary == 1) ? "T" : ""); #ifdef DEBUGMODE sendnotice(client, "%s (%p) has refcount %d", - link_p->servername, link_p, link_p->refcount); + link_p->servername, link_p, link_p->refcount); #endif if (link_p->hub) sendnumericfmt(client, RPL_STATSHLINE, "H %s * %s", - link_p->hub, link_p->servername); + link_p->hub, link_p->servername); else if (link_p->leaf) sendnumericfmt(client, RPL_STATSLLINE, "L %s * %s %d", - link_p->leaf, link_p->servername, link_p->leaf_depth); + link_p->leaf, link_p->servername, link_p->leaf_depth); } #ifdef DEBUGMODE - list_for_each_entry(acptr, &client_list, client_node) - if (MyConnect(acptr) && acptr->server && !IsMe(acptr)) - { - if (!acptr->server->conf) - sendnotice(client, "client '%s' (%p) has NO CONF attached (? :P)", - acptr->name, acptr); - else - sendnotice(client, "client '%s' (%p) has conf %p attached, refcount: %d, temporary: %s", - acptr->name, acptr, - acptr->server->conf, - acptr->server->conf->refcount, - acptr->server->conf->flag.temporary ? "YES" : "NO"); - } + list_for_each_entry(acptr, &client_list, client_node) if (MyConnect(acptr) && acptr->server && !IsMe(acptr)) + { + if (!acptr->server->conf) + sendnotice(client, "client '%s' (%p) has NO CONF attached (? :P)", + acptr->name, acptr); + else + sendnotice(client, "client '%s' (%p) has conf %p attached, refcount: %d, temporary: %s", + acptr->name, acptr, + acptr->server->conf, + acptr->server->conf->refcount, + acptr->server->conf->flag.temporary ? "YES" : "NO"); + } #endif return 0; } @@ -445,8 +441,8 @@ int stats_links(Client *client, const char *para) int stats_gline(Client *client, const char *para) { int cnt = 0; - tkl_stats(client, TKL_GLOBAL|TKL_KILL, para, &cnt); - tkl_stats(client, TKL_GLOBAL|TKL_ZAP, para, &cnt); + tkl_stats(client, TKL_GLOBAL | TKL_KILL, para, &cnt); + tkl_stats(client, TKL_GLOBAL | TKL_ZAP, para, &cnt); return 0; } @@ -454,7 +450,7 @@ int stats_spamfilter(Client *client, const char *para) { int cnt = 0; tkl_stats(client, TKL_SPAMF, para, &cnt); - tkl_stats(client, TKL_GLOBAL|TKL_SPAMF, para, &cnt); + tkl_stats(client, TKL_GLOBAL | TKL_SPAMF, para, &cnt); return 0; } @@ -462,7 +458,7 @@ int stats_except(Client *client, const char *para) { int cnt = 0; tkl_stats(client, TKL_EXCEPTION, para, &cnt); - tkl_stats(client, TKL_EXCEPTION|TKL_GLOBAL, para, &cnt); + tkl_stats(client, TKL_EXCEPTION | TKL_GLOBAL, para, &cnt); return 0; } @@ -476,12 +472,12 @@ int stats_allow(Client *client, const char *para) for (m = allows->match->printable_list; m; m = m->next) { sendnumeric(client, RPL_STATSILINE, - namevalue_nospaces(m), "-", - allows->maxperip, - allows->global_maxperip, - allows->class->name, - allows->server ? allows->server : DEFAULT_SERVER, - allows->port ? allows->port : 6667); + namevalue_nospaces(m), "-", + allows->maxperip, + allows->global_maxperip, + allows->class->name, + allows->server ? allows->server : DEFAULT_SERVER, + allows->port ? allows->port : 6667); } } return 0; @@ -494,8 +490,8 @@ int stats_command(Client *client, const char *para) for (i = 0; i < 256; i++) for (mptr = CommandHash[i]; mptr; mptr = mptr->next) if (mptr->count) - sendnumeric(client, RPL_STATSCOMMANDS, mptr->cmd, - mptr->count, mptr->bytes); + sendnumeric(client, RPL_STATSCOMMANDS, mptr->cmd, + mptr->count, mptr->bytes); return 0; } @@ -511,7 +507,7 @@ int stats_oper(Client *client, const char *para) { sendnumeric(client, RPL_STATSOLINE, 'O', namevalue_nospaces(m), o->name, - o->operclass ? o->operclass: "", + o->operclass ? o->operclass : "", o->class->name ? o->class->name : ""); } } @@ -523,9 +519,9 @@ static char *stats_port_helper(ConfigItem_listen *listener) static char buf[256]; ircsnprintf(buf, sizeof(buf), "%s%s%s", - (listener->options & LISTENER_CLIENTSONLY)? "clientsonly ": "", - (listener->options & LISTENER_SERVERSONLY)? "serversonly ": "", - (listener->options & LISTENER_DEFER_ACCEPT)? "defer-accept ": ""); + (listener->options & LISTENER_CLIENTSONLY) ? "clientsonly " : "", + (listener->options & LISTENER_SERVERSONLY) ? "serversonly " : "", + (listener->options & LISTENER_DEFER_ACCEPT) ? "defer-accept " : ""); /* And one of these.. */ if (listener->options & LISTENER_CONTROL) @@ -547,28 +543,30 @@ int stats_port(Client *client, const char *para) { if (!(listener->options & LISTENER_BOUND)) continue; - if ((listener->options & LISTENER_SERVERSONLY) && !ValidatePermissionsForPath("server:info:stats",client,NULL,NULL,NULL)) + if ((listener->options & LISTENER_SERVERSONLY) && !ValidatePermissionsForPath("server:info:stats", client, NULL, NULL, NULL)) continue; if (listener->socket_type == SOCKET_TYPE_UNIX) { sendtxtnumeric(client, "Listener on %s (UNIX): has %i client(s), options: %s %s", - listener->file, - listener->clients, - stats_port_helper(listener), - listener->flag.temporary ? "[TEMPORARY]" : ""); - } else { + listener->file, + listener->clients, + stats_port_helper(listener), + listener->flag.temporary ? "[TEMPORARY]" : ""); + } else + { sendtxtnumeric(client, "Listener on %s:%i (%s): has %i client(s), options: %s %s", - listener->ip, - listener->port, - listener->socket_type == SOCKET_TYPE_IPV6 ? "IPv6" : "IPv4", - listener->clients, - stats_port_helper(listener), - listener->flag.temporary ? "[TEMPORARY]" : ""); + listener->ip, + listener->port, + listener->socket_type == SOCKET_TYPE_IPV6 ? "IPv6" : "IPv4", + listener->clients, + stats_port_helper(listener), + listener->flag.temporary ? "[TEMPORARY]" : ""); } if (listener->options & LISTENER_TLS) { TLSOptions *o = tls_options_for_listener(listener); - const char *kind = listener->tls_options ? "" : (o == iConf.server_linking_tls_options) ? "server-linking " : "default "; + const char *kind = listener->tls_options ? "" : (o == iConf.server_linking_tls_options) ? "server-linking " + : "default "; NameList *n, *n2; for (n = o->certificate_files, n2 = o->key_files; n && n2; n = n->next, n2 = n2->next) sendtxtnumeric(client, "- using %stls certificate %s + key %s", kind, n->name, n2->name); @@ -581,7 +579,7 @@ int stats_bannick(Client *client, const char *para) { int cnt = 0; tkl_stats(client, TKL_NAME, para, &cnt); - tkl_stats(client, TKL_GLOBAL|TKL_NAME, para, &cnt); + tkl_stats(client, TKL_GLOBAL | TKL_NAME, para, &cnt); return 0; } @@ -601,13 +599,11 @@ int stats_traffic(Client *client, const char *para) { sp->is_sti += now - acptr->local->creationtime; sp->is_sv++; - } - else if (IsUser(acptr)) + } else if (IsUser(acptr)) { sp->is_cti += now - acptr->local->creationtime; sp->is_cl++; - } - else if (IsUnknown(acptr)) + } else if (IsUnknown(acptr)) sp->is_ni++; } @@ -625,7 +621,7 @@ int stats_traffic(Client *client, const char *para) sendnumericfmt(client, RPL_STATSDEBUG, "bytes sent %lld", me.local->traffic.bytes_sent); sendnumericfmt(client, RPL_STATSDEBUG, "bytes received %lld", me.local->traffic.bytes_received); sendnumericfmt(client, RPL_STATSDEBUG, "time connected %lld %lld", - (long long)sp->is_cti, (long long)sp->is_sti); + (long long)sp->is_cti, (long long)sp->is_sti); return 0; } @@ -643,12 +639,12 @@ int stats_fdtable(Client *client, const char *para) #ifndef DEBUGMODE sendnumericfmt(client, RPL_STATSDEBUG, - "fd %3d, desc '%s', read-hdl %d, write-hdl %d, cbdata %d", - fde->fd, fde->desc, fde->read_callback ? 1 : 0, fde->write_callback ? 1 : 0, fde->data ? 1 : 0); + "fd %3d, desc '%s', read-hdl %d, write-hdl %d, cbdata %d", + fde->fd, fde->desc, fde->read_callback ? 1 : 0, fde->write_callback ? 1 : 0, fde->data ? 1 : 0); #else sendnumericfmt(client, RPL_STATSDEBUG, - "fd %3d, desc '%s', read-hdl %p, write-hdl %p, cbdata %p", - fde->fd, fde->desc, fde->read_callback, fde->write_callback, fde->data); + "fd %3d, desc '%s', read-hdl %p, write-hdl %p, cbdata %p", + fde->fd, fde->desc, fde->read_callback, fde->write_callback, fde->data); #endif } @@ -678,8 +674,7 @@ int stats_banrealname(Client *client, const char *para) { if (bans->flag.type == CONF_BAN_REALNAME) { - sendnumeric(client, RPL_STATSNLINE, bans->mask, bans->reason - ? bans->reason : ""); + sendnumeric(client, RPL_STATSNLINE, bans->mask, bans->reason ? bans->reason : ""); } } return 0; @@ -688,7 +683,7 @@ int stats_banrealname(Client *client, const char *para) int stats_sqline(Client *client, const char *para) { int cnt = 0; - tkl_stats(client, TKL_NAME|TKL_GLOBAL, para, &cnt); + tkl_stats(client, TKL_NAME | TKL_GLOBAL, para, &cnt); return 0; } @@ -700,8 +695,8 @@ int stats_chanrestrict(Client *client, const char *para) { sendtxtnumeric(client, "deny %s %c %s", dchans->channel, dchans->warn ? 'w' : '-', dchans->reason); } - for (achans = conf_allow_channel; achans; achans = achans->next) - { + for (achans = conf_allow_channel; achans; achans = achans->next) + { sendtxtnumeric(client, "allow %s", achans->channel); } return 0; @@ -710,7 +705,7 @@ int stats_chanrestrict(Client *client, const char *para) int stats_shun(Client *client, const char *para) { int cnt = 0; - tkl_stats(client, TKL_GLOBAL|TKL_SHUN, para, &cnt); + tkl_stats(client, TKL_GLOBAL | TKL_SHUN, para, &cnt); return 0; } @@ -726,42 +721,40 @@ int stats_officialchannels(Client *client, const char *para) return 0; } -#define SafePrint(x) ((x) ? (x) : "") +#define SafePrint(x) ((x) ? (x) : "") /** Helper for stats_set() */ static void stats_set_anti_flood(Client *client, FloodSettings *f) { int i; - for (i=0; floodoption_names[i]; i++) + for (i = 0; floodoption_names[i]; i++) { if (f->limit[i] == 0) continue; /* unconfigured */ if (i == FLD_CONVERSATIONS) { sendtxtnumeric(client, "anti-flood::%s::%s: %d users, new user every %s", - f->name, floodoption_names[i], - (int)f->limit[i], pretty_time_val(f->period[i])); - } else - if (i == FLD_LAG_PENALTY) + f->name, floodoption_names[i], + (int)f->limit[i], pretty_time_val(f->period[i])); + } else if (i == FLD_LAG_PENALTY) { sendtxtnumeric(client, "anti-flood::%s::lag-penalty: %d msec", - f->name, (int)f->period[i]); + f->name, (int)f->period[i]); sendtxtnumeric(client, "anti-flood::%s::lag-penalty-bytes: %d", - f->name, - f->limit[i] == INT_MAX ? 0 : (int)f->limit[i]); - } else - if (i == FLD_MULTILINE) + f->name, + f->limit[i] == INT_MAX ? 0 : (int)f->limit[i]); + } else if (i == FLD_MULTILINE) { sendtxtnumeric(client, "anti-flood::%s::multiline::max-lines: %d", - f->name, (int)f->limit[i]); + f->name, (int)f->limit[i]); sendtxtnumeric(client, "anti-flood::%s::multiline::max-bytes: %d", - f->name, (int)f->period[i]); + f->name, (int)f->period[i]); } else { sendtxtnumeric(client, "anti-flood::%s::%s: %d per %s", - f->name, floodoption_names[i], - (int)f->limit[i], pretty_time_val(f->period[i])); + f->name, floodoption_names[i], + (int)f->limit[i], pretty_time_val(f->period[i])); } } } @@ -774,7 +767,7 @@ int stats_set(Client *client, const char *para) NameList *n; char modebuf[BUFSIZE], parabuf[BUFSIZE]; - if (!ValidatePermissionsForPath("server:info:stats",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:info:stats", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return 0; @@ -901,7 +894,7 @@ int stats_set(Client *client, const char *para) RunHook(HOOKTYPE_STATS, client, "S"); #ifndef _WIN32 sendtxtnumeric(client, "This server can handle %d concurrent sockets (%d clients + %d reserve)", - maxclients+reserved_fds, maxclients, reserved_fds); + maxclients + reserved_fds, maxclients, reserved_fds); #endif return 1; } @@ -930,10 +923,10 @@ int stats_uptime(Client *client, const char *para) uptime = TStime() - me.local->fake_lag; sendnumeric(client, RPL_STATSUPTIME, - uptime / 86400, (uptime / 3600) % 24, (uptime / 60) % 60, - uptime % 60); + uptime / 86400, (uptime / 3600) % 24, (uptime / 60) % 60, + uptime % 60); sendnumeric(client, RPL_STATSCONN, - max_connection_count, irccounts.me_max); + max_connection_count, irccounts.me_max); return 0; } @@ -943,7 +936,7 @@ int stats_denyver(Client *client, const char *para) for (versions = conf_deny_version; versions; versions = versions->next) { sendnumeric(client, RPL_STATSVLINE, - versions->version, versions->flags, versions->mask); + versions->version, versions->flags, versions->mask); } return 0; } @@ -957,7 +950,7 @@ int stats_notlink(Client *client, const char *para) if (!find_server_quick(link_p->servername)) { sendnumeric(client, RPL_STATSXLINE, link_p->servername, - link_p->outgoing.port); + link_p->outgoing.port); } } return 0; @@ -970,10 +963,10 @@ int stats_class(Client *client, const char *para) for (classes = conf_class; classes; classes = classes->next) { sendnumeric(client, RPL_STATSYLINE, classes->name, classes->pingfreq, classes->connfreq, - classes->maxclients, classes->sendq, classes->recvq ? classes->recvq : DEFAULT_RECVQ); + classes->maxclients, classes->sendq, classes->recvq ? classes->recvq : DEFAULT_RECVQ); #ifdef DEBUGMODE sendnotice(client, "class '%s' has clients=%d, xrefcount=%d", - classes->name, classes->clients, classes->xrefcount); + classes->name, classes->clients, classes->xrefcount); #endif } return 0; @@ -1010,8 +1003,7 @@ int stats_linkinfoint(Client *client, const char *para, int all) doall = 1; if (strchr(para, '*') || strchr(para, '?')) wilds = 1; - } - else + } else para = me.name; sendnumericfmt(client, RPL_STATSLINKINFO, "Name SendQ SendM SendBytes RcveM RcveBytes Open_since :Idle"); @@ -1025,7 +1017,7 @@ int stats_linkinfoint(Client *client, const char *para, int all) list_for_each_entry(acptr, &lclient_list, lclient_node) { if (IsInvisible(acptr) && (doall || wilds) && - !IsOper(acptr) && (acptr != client)) + !IsOper(acptr) && (acptr != client)) continue; if (remote && doall && !IsServer(acptr) && !IsMe(acptr)) continue; @@ -1041,22 +1033,22 @@ int stats_linkinfoint(Client *client, const char *para, int all) } sendnumericfmt(client, RPL_STATSLINKINFO, - "%s%s %lld %lld %lld %lld %lld %lld :%lld", - acptr->name, get_client_status(acptr), - (long long)DBufLength(&acptr->local->sendQ), - (long long)acptr->local->traffic.messages_sent, - (long long)acptr->local->traffic.bytes_sent, - (long long)acptr->local->traffic.messages_received, - (long long)acptr->local->traffic.bytes_received, - (long long)(TStime() - acptr->local->creationtime), - (long long)(TStime() - acptr->local->last_msg_received)); + "%s%s %lld %lld %lld %lld %lld %lld :%lld", + acptr->name, get_client_status(acptr), + (long long)DBufLength(&acptr->local->sendQ), + (long long)acptr->local->traffic.messages_sent, + (long long)acptr->local->traffic.bytes_sent, + (long long)acptr->local->traffic.messages_received, + (long long)acptr->local->traffic.bytes_received, + (long long)(TStime() - acptr->local->creationtime), + (long long)(TStime() - acptr->local->last_msg_received)); } #ifdef DEBUGMODE list_for_each_entry(acptr, &client_list, client_node) { if (IsServer(acptr)) sendnotice(client, "Server %s is %s", - acptr->name, acptr->server->flags.synced ? "SYNCED" : "NOT SYNCED!!"); + acptr->name, acptr->server->flags.synced ? "SYNCED" : "NOT SYNCED!!"); } #endif return 0; @@ -1066,7 +1058,7 @@ int stats_linecache(Client *client, const char *para) { ClientCapability *e; - if (!ValidatePermissionsForPath("server:info:stats",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:info:stats", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return 0; @@ -1078,7 +1070,7 @@ int stats_linecache(Client *client, const char *para) sendtxtnumeric(client, "CAP %s", e->name); //sendtxtnumeric(client, " "); - //sendtxtnumeric(client, "Line statistics:"); + //sendtxtnumeric(client, "Line statistics:"); return 0; } diff --git a/src/modules/sts.c b/src/modules/sts.c index 35a8c78a2..1fa99d2bd 100644 --- a/src/modules/sts.c +++ b/src/modules/sts.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "sts", - "5.0", - "Strict Transport Security CAP", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "sts", + "5.0", + "Strict Transport Security CAP", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { diff --git a/src/modules/svsjoin.c b/src/modules/svsjoin.c index bc451c4aa..9e6c451e6 100644 --- a/src/modules/svsjoin.c +++ b/src/modules/svsjoin.c @@ -22,21 +22,20 @@ CMD_FUNC(cmd_svsjoin); /* Place includes here */ -#define MSG_SVSJOIN "SVSJOIN" +#define MSG_SVSJOIN "SVSJOIN" -ModuleHeader MOD_HEADER - = { - "svsjoin", /* Name of module */ - "5.0", /* Version */ - "command /svsjoin", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svsjoin", /* Name of module */ + "5.0", /* Version */ + "command /svsjoin", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SVSJOIN, cmd_svsjoin, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_SVSJOIN, cmd_svsjoin, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -50,7 +49,7 @@ MOD_LOAD() /* Called when module is unloaded */ MOD_UNLOAD() { - return MOD_SUCCESS; + return MOD_SUCCESS; } /* cmd_svsjoin() - Lamego - Wed Jul 21 20:04:48 1999 @@ -78,20 +77,20 @@ CMD_FUNC(cmd_svsjoin) parv[2] = NULL; do_cmd(target, NULL, "JOIN", 2, parv); /* NOTE: 'target' may be killed if we ever implement spamfilter join channel target */ - } else { + } else + { parv[2] = parv[3]; parv[3] = NULL; do_cmd(target, NULL, "JOIN", 3, parv); /* NOTE: 'target' may be killed if we ever implement spamfilter join channel target */ } - } - else + } else { if (parc == 3) sendto_one(target, NULL, ":%s SVSJOIN %s %s", client->name, - parv[1], parv[2]); + parv[1], parv[2]); else sendto_one(target, NULL, ":%s SVSJOIN %s %s %s", client->name, - parv[1], parv[2], parv[3]); + parv[1], parv[2], parv[3]); } } diff --git a/src/modules/svskill.c b/src/modules/svskill.c index afcd23003..a4ba7af42 100644 --- a/src/modules/svskill.c +++ b/src/modules/svskill.c @@ -21,22 +21,21 @@ CMD_FUNC(cmd_svskill); -#define MSG_SVSKILL "SVSKILL" +#define MSG_SVSKILL "SVSKILL" -ModuleHeader MOD_HEADER - = { - "svskill", /* Name of module */ - "5.0", /* Version */ - "command /svskill", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svskill", /* Name of module */ + "5.0", /* Version */ + "command /svskill", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SVSKILL, cmd_svskill, MAXPARA, CMD_SERVER|CMD_USER); + CommandAdd(modinfo->handle, MSG_SVSKILL, cmd_svskill, MAXPARA, CMD_SERVER | CMD_USER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } diff --git a/src/modules/svslogin.c b/src/modules/svslogin.c index c6a1ce3d5..dab8ae90c 100644 --- a/src/modules/svslogin.c +++ b/src/modules/svslogin.c @@ -26,18 +26,17 @@ CMD_FUNC(cmd_svslogin); -ModuleHeader MOD_HEADER - = { - "svslogin", - "6.0", - "command /SVSLOGIN", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svslogin", + "6.0", + "command /SVSLOGIN", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SVSLOGIN, cmd_svslogin, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_SVSLOGIN, cmd_svslogin, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -84,7 +83,8 @@ CMD_FUNC(cmd_svslogin) user_account_login(recv_mtags, target); if (MyConnect(target) && IsDead(target)) return; /* was killed due to *LINE on ~a probably */ - } else { + } else + { /* It is perfectly normal for target to be NULL as this * happens during registration phase (pre-connect). * It just means we cannot set any properties for this user, diff --git a/src/modules/svslusers.c b/src/modules/svslusers.c index a995ef236..1b1fbda1f 100644 --- a/src/modules/svslusers.c +++ b/src/modules/svslusers.c @@ -26,16 +26,15 @@ CMD_FUNC(cmd_svslusers); -#define MSG_SVSLUSERS "SVSLUSERS" +#define MSG_SVSLUSERS "SVSLUSERS" -ModuleHeader MOD_HEADER - = { - "svslusers", - "5.0", - "command /svslusers", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svslusers", + "5.0", + "command /svslusers", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -64,16 +63,16 @@ MOD_UNLOAD() */ CMD_FUNC(cmd_svslusers) { - if (!IsSvsCmdOk(client) || parc < 4) - return; - if (hunt_server(client, NULL, "SVSLUSERS", 1, parc, parv) == HUNTED_ISME) - { + if (!IsSvsCmdOk(client) || parc < 4) + return; + if (hunt_server(client, NULL, "SVSLUSERS", 1, parc, parv) == HUNTED_ISME) + { int temp; temp = atoi(parv[2]); if (temp >= 0) irccounts.global_max = temp; temp = atoi(parv[3]); - if (temp >= 0) + if (temp >= 0) irccounts.me_max = temp; - } + } } diff --git a/src/modules/svsmode.c b/src/modules/svsmode.c index 0a6b3de75..15be95b29 100644 --- a/src/modules/svsmode.c +++ b/src/modules/svsmode.c @@ -30,24 +30,23 @@ void add_send_mode_param(Channel *channel, Client *from, char what, char mode, c CMD_FUNC(cmd_svsmode); CMD_FUNC(cmd_svs2mode); -#define MSG_SVSMODE "SVSMODE" -#define MSG_SVS2MODE "SVS2MODE" +#define MSG_SVSMODE "SVSMODE" +#define MSG_SVS2MODE "SVS2MODE" -ModuleHeader MOD_HEADER - = { - "svsmode", - "5.0", - "command /svsmode and svs2mode", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svsmode", + "5.0", + "command /svsmode and svs2mode", + "UnrealIRCd Team", + "unrealircd-6", +}; char modebuf[BUFSIZE], parabuf[BUFSIZE]; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SVSMODE, cmd_svsmode, MAXPARA, CMD_SERVER|CMD_USER); - CommandAdd(modinfo->handle, MSG_SVS2MODE, cmd_svs2mode, MAXPARA, CMD_SERVER|CMD_USER); + CommandAdd(modinfo->handle, MSG_SVSMODE, cmd_svsmode, MAXPARA, CMD_SERVER | CMD_USER); + CommandAdd(modinfo->handle, MSG_SVS2MODE, cmd_svs2mode, MAXPARA, CMD_SERVER | CMD_USER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -69,35 +68,31 @@ void unban_user(Client *client, Channel *channel, Client *acptr, char chmode) Ban *ban, *bnext; Ban **banlist; BanContext *b; - char uhost[NICKLEN+USERLEN+HOSTLEN+6], vhost[NICKLEN+USERLEN+HOSTLEN+6]; - char ihost[NICKLEN+USERLEN+HOSTLEN+6], chost[NICKLEN+USERLEN+HOSTLEN+6]; + char uhost[NICKLEN + USERLEN + HOSTLEN + 6], vhost[NICKLEN + USERLEN + HOSTLEN + 6]; + char ihost[NICKLEN + USERLEN + HOSTLEN + 6], chost[NICKLEN + USERLEN + HOSTLEN + 6]; /* BUILD HOSTS */ *uhost = *vhost = *ihost = *chost = '\0'; - strlcpy(uhost, make_nick_user_host(acptr->name, - acptr->user->username, acptr->user->realhost), - sizeof uhost); + strlcpy(uhost, make_nick_user_host(acptr->name, acptr->user->username, acptr->user->realhost), + sizeof uhost); if (GetIP(acptr)) /* only if we actually have an IP */ - strlcpy(ihost, make_nick_user_host(acptr->name, - acptr->user->username, GetIP(acptr)), - sizeof ihost); + strlcpy(ihost, make_nick_user_host(acptr->name, acptr->user->username, GetIP(acptr)), + sizeof ihost); /* The next could have been an IsSetHost(), but I'm playing it safe with regards to backward compat. */ if (IsHidden(acptr) && - !(*acptr->user->cloakedhost && !strcasecmp(acptr->user->virthost, acptr->user->cloakedhost))) + !(*acptr->user->cloakedhost && !strcasecmp(acptr->user->virthost, acptr->user->cloakedhost))) { - strlcpy(vhost, make_nick_user_host(acptr->name, - acptr->user->username, acptr->user->virthost), - sizeof vhost); + strlcpy(vhost, make_nick_user_host(acptr->name, acptr->user->username, acptr->user->virthost), + sizeof vhost); } if (*acptr->user->cloakedhost) /* only if we know the cloaked host */ - strlcpy(chost, make_nick_user_host(acptr->name, - acptr->user->username, acptr->user->cloakedhost), - sizeof chost); + strlcpy(chost, make_nick_user_host(acptr->name, acptr->user->username, acptr->user->cloakedhost), + sizeof chost); b = safe_alloc(sizeof(BanContext)); @@ -135,10 +130,9 @@ void unban_user(Client *client, Channel *channel, Client *acptr, char chmode) (*ihost && match_simple(ban->banstr, ihost)) || (*chost && match_simple(ban->banstr, chost))) { - add_send_mode_param(channel, client, '-', chmode, ban->banstr); + add_send_mode_param(channel, client, '-', chmode, ban->banstr); del_listmode(banlist, channel, ban->banstr); - } - else if (chmode != 'I' && *ban->banstr == '~' && (extban = findmod_by_bantype(ban->banstr, &nextbanstr))) + } else if (chmode != 'I' && *ban->banstr == '~' && (extban = findmod_by_bantype(ban->banstr, &nextbanstr))) { if (extban->is_banned_events & b->ban_check_types) { @@ -174,7 +168,7 @@ void clear_bans(Client *client, Channel *channel, char chmode) default: abort(); } - + for (ban = *banlist; ban; ban = bnext) { bnext = ban->next; @@ -183,7 +177,7 @@ void clear_bans(Client *client, Channel *channel, char chmode) if (!(extban->is_banned_events & BANCHK_JOIN)) continue; } - add_send_mode_param(channel, client, '-', chmode, ban->banstr); + add_send_mode_param(channel, client, '-', chmode, ban->banstr); del_listmode(banlist, channel, ban->banstr); } } @@ -209,7 +203,7 @@ void clear_bans(Client *client, Channel *channel, char chmode) * * OLD syntax had a 'ts' parameter. No services are known to use this. */ -void channel_svsmode(Client *client, int parc, const char *parv[]) +void channel_svsmode(Client *client, int parc, const char *parv[]) { Channel *channel; Client *target; @@ -229,19 +223,17 @@ void channel_svsmode(Client *client, int parc, const char *parv[]) for (m = parv[2]; *m; m++) { - if (*m == '+') + if (*m == '+') { what = MODE_ADD; - } else - if (*m == '-') + } else if (*m == '-') { what = MODE_DEL; - } else - if ((*m == 'b') || (*m == 'e') || (*m == 'I')) + } else if ((*m == 'b') || (*m == 'e') || (*m == 'I')) { if (parc >= i) { - if (!(target = find_user(parv[i-1], NULL))) + if (!(target = find_user(parv[i - 1], NULL))) { i++; break; @@ -249,8 +241,8 @@ void channel_svsmode(Client *client, int parc, const char *parv[]) i++; unban_user(client, channel, target, *m); - } - else { + } else + { clear_bans(client, channel, *m); } } else @@ -280,10 +272,10 @@ void channel_svsmode(Client *client, int parc, const char *parv[]) Membership *mb = find_membership_link(member->client->user->channel, channel); if (!mb) continue; /* bug */ - + /* Send the -x out */ add_send_mode_param(channel, client, '-', *m, member->client->name); - + /* And remove from memory */ del_member_mode_fast(member, mb, *m); } @@ -301,8 +293,8 @@ void channel_svsmode(Client *client, int parc, const char *parv[]) sendto_channel(channel, client, client, 0, 0, SEND_LOCAL, mtags, ":%s MODE %s %s %s", - client->name, channel->name, modebuf, parabuf); - sendto_server(NULL, 0, 0, mtags, ":%s MODE %s %s %s%s", client->id, channel->name, modebuf, parabuf, IsServer(client)?" 0":""); + client->name, channel->name, modebuf, parabuf); + sendto_server(NULL, 0, 0, mtags, ":%s MODE %s %s %s%s", client->id, channel->name, modebuf, parabuf, IsServer(client) ? " 0" : ""); /* Activate this hook just like cmd_mode.c */ RunHook(HOOKTYPE_REMOTE_CHANMODE, client, channel, mtags, modebuf, parabuf, 0, 0, &destroy_channel); @@ -327,7 +319,7 @@ void do_svsmode(Client *client, MessageTag *recv_mtags, int parc, const char *pa Umode *um; const char *m; Client *target; - int what; + int what; long oldumodes = 0; if (!IsSvsCmdOk(client)) @@ -338,7 +330,7 @@ void do_svsmode(Client *client, MessageTag *recv_mtags, int parc, const char *pa if (parc < 3) return; - if (parv[1][0] == '#') + if (parv[1][0] == '#') { channel_svsmode(client, parc, parv); return; @@ -388,13 +380,14 @@ void do_svsmode(Client *client, MessageTag *recv_mtags, int parc, const char *pa { /* clear 'H' too, and opercount stays the same.. */ target->umodes &= ~UMODE_HIDEOPER; - } else { + } else + { irccounts.operators--; } if (MyUser(target) && !list_empty(&target->special_node)) list_del(&target->special_node); - + /* User is no longer oper (after the goto below, anyway)... * so remove all oper-only modes and snomasks. */ @@ -436,14 +429,14 @@ void do_svsmode(Client *client, MessageTag *recv_mtags, int parc, const char *pa * to not logged in, which is something that can happen * from 0 to 123456, eg from no account to unconfirmed account. */ - } else { + } else + { /* LOGIN or LOGOUT (or account change) */ user_account_login(recv_mtags, target); } if (MyConnect(target) && IsDead(target)) return; /* was killed due to *LINE on ~a probably */ - } - else + } else { /* setting deaf */ goto setmodex; @@ -478,7 +471,7 @@ void do_svsmode(Client *client, MessageTag *recv_mtags, int parc, const char *pa */ if (MyUser(target) && !strcasecmp(target->user->virthost, target->user->cloakedhost)) sendto_server(NULL, PROTO_VHP, 0, NULL, ":%s SETHOST :%s", target->id, - target->user->virthost); + target->user->virthost); } goto setmodex; case 't': @@ -499,7 +492,7 @@ void do_svsmode(Client *client, MessageTag *recv_mtags, int parc, const char *pa /* And broadcast the change to VHP servers */ if (MyUser(target)) sendto_server(NULL, PROTO_VHP, 0, NULL, ":%s SETHOST :%s", target->id, - target->user->virthost); + target->user->virthost); } goto setmodex; } @@ -508,7 +501,7 @@ void do_svsmode(Client *client, MessageTag *recv_mtags, int parc, const char *pa /* Setting and unsetting user mode 'z' remotely is not supported */ break; default: - setmodex: + setmodex: for (um = usermodes; um; um = um->next) { if (um->letter == *m) @@ -525,12 +518,12 @@ void do_svsmode(Client *client, MessageTag *recv_mtags, int parc, const char *pa if (parc > 3) sendto_server(client, 0, 0, recv_mtags, ":%s %s %s %s %s", - client->id, show_change ? "SVS2MODE" : "SVSMODE", - parv[1], parv[2], parv[3]); + client->id, show_change ? "SVS2MODE" : "SVSMODE", + parv[1], parv[2], parv[3]); else sendto_server(client, 0, 0, recv_mtags, ":%s %s %s %s", - client->id, show_change ? "SVS2MODE" : "SVSMODE", - parv[1], parv[2]); + client->id, show_change ? "SVS2MODE" : "SVSMODE", + parv[1], parv[2]); /* Here we trigger the same hooks that cmd_mode does and, likewise, only if the old flags (oldumodes) are different than the newly- @@ -583,9 +576,10 @@ void add_send_mode_param(Channel *channel, Client *from, char what, char mode, c static char *modes = NULL, lastwhat; static short count = 0; short send = 0; - - if (!modes) modes = modebuf; - + + if (!modes) + modes = modebuf; + if (!modebuf[0]) { modes = modebuf; @@ -603,14 +597,13 @@ void add_send_mode_param(Channel *channel, Client *from, char what, char mode, c } if (strlen(parabuf) + strlen(param) + 11 < MODEBUFLEN) { - if (*parabuf) + if (*parabuf) strcat(parabuf, " "); strcat(parabuf, param); *modes++ = mode; *modes = 0; count++; - } - else if (*parabuf) + } else if (*parabuf) send = 1; if (count == MAXMODEPARAMS) @@ -624,7 +617,7 @@ void add_send_mode_param(Channel *channel, Client *from, char what, char mode, c sendto_channel(channel, from, from, 0, 0, SEND_LOCAL, mtags, ":%s MODE %s %s %s", from->name, channel->name, modebuf, parabuf); - sendto_server(NULL, 0, 0, mtags, ":%s MODE %s %s %s%s", from->id, channel->name, modebuf, parabuf, IsServer(from)?" 0":""); + sendto_server(NULL, 0, 0, mtags, ":%s MODE %s %s %s%s", from->id, channel->name, modebuf, parabuf, IsServer(from) ? " 0" : ""); free_message_tags(mtags); send = 0; *parabuf = 0; @@ -636,8 +629,7 @@ void add_send_mode_param(Channel *channel, Client *from, char what, char mode, c strcpy(parabuf, param); *modes++ = mode; count = 1; - } - else + } else count = 0; *modes = 0; } diff --git a/src/modules/svsmotd.c b/src/modules/svsmotd.c index 3f8abaa82..8ca8126a9 100644 --- a/src/modules/svsmotd.c +++ b/src/modules/svsmotd.c @@ -26,16 +26,15 @@ CMD_FUNC(cmd_svsmotd); -#define MSG_SVSMOTD "SVSMOTD" +#define MSG_SVSMOTD "SVSMOTD" -ModuleHeader MOD_HEADER - = { - "svsmotd", - "5.0", - "command /svsmotd", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svsmotd", + "5.0", + "command /svsmotd", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { diff --git a/src/modules/svsnick.c b/src/modules/svsnick.c index aef0bef91..774061261 100644 --- a/src/modules/svsnick.c +++ b/src/modules/svsnick.c @@ -26,16 +26,15 @@ CMD_FUNC(cmd_svsnick); -#define MSG_SVSNICK "SVSNICK" +#define MSG_SVSNICK "SVSNICK" -ModuleHeader MOD_HEADER - = { - "svsnick", - "5.0", - "command /svsnick", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svsnick", + "5.0", + "command /svsnick", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -64,8 +63,8 @@ CMD_FUNC(cmd_svsnick) Client *acptr; Client *ocptr; /* Other client */ MessageTag *mtags = NULL; - char nickname[NICKLEN+1]; - char oldnickname[NICKLEN+1]; + char nickname[NICKLEN + 1]; + char oldnickname[NICKLEN + 1]; time_t ts; if (!IsSvsCmdOk(client) || parc < 4 || (strlen(parv[2]) > NICKLEN)) @@ -84,8 +83,8 @@ CMD_FUNC(cmd_svsnick) if ((ocptr = find_client(nickname, NULL)) && ocptr != acptr) /* Collision */ { exit_client(acptr, NULL, - "Nickname collision due to forced " - "nickname change, your nick was overruled"); + "Nickname collision due to forced " + "nickname change, your nick was overruled"); return; } diff --git a/src/modules/svsnline.c b/src/modules/svsnline.c index e5cdcdba2..c230f1520 100644 --- a/src/modules/svsnline.c +++ b/src/modules/svsnline.c @@ -26,16 +26,15 @@ CMD_FUNC(cmd_svsnline); -#define MSG_SVSNLINE "SVSNLINE" /* svsnline */ +#define MSG_SVSNLINE "SVSNLINE" /* svsnline */ -ModuleHeader MOD_HEADER - = { - "svsnline", /* Name of module */ - "5.0", /* Version */ - "command /svsnline", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svsnline", /* Name of module */ + "5.0", /* Version */ + "command /svsnline", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() @@ -60,12 +59,12 @@ MOD_UNLOAD() void wipe_svsnlines(void) { ConfigItem_ban *bconf, *next; - + for (bconf = conf_ban; bconf; bconf = next) { next = bconf->next; if ((bconf->flag.type == CONF_BAN_REALNAME) && - (bconf->flag.type2 == CONF_BAN_TYPE_AKILL)) + (bconf->flag.type2 == CONF_BAN_TYPE_AKILL)) { DelListItem(bconf, conf_ban); safe_free(bconf->mask); @@ -85,73 +84,71 @@ void wipe_svsnlines(void) CMD_FUNC(cmd_svsnline) { ConfigItem_ban *bconf; - char *s; + char *s; if (parc < 2) return; switch (*parv[1]) { - /* Allow non-U-Lines to send ONLY SVSNLINE +, but don't send it out + /* Allow non-U-Lines to send ONLY SVSNLINE +, but don't send it out * unless it is from a U-Line -- codemastr */ - case '+': - { - if (parc < 4) - return; - - if (!find_banEx(NULL, parv[3], CONF_BAN_REALNAME, CONF_BAN_TYPE_AKILL)) - { - bconf = safe_alloc(sizeof(ConfigItem_ban)); - bconf->flag.type = CONF_BAN_REALNAME; - safe_strdup(bconf->mask, parv[3]); - safe_strdup(bconf->reason, parv[2]); - for (s = bconf->reason; *s; s++) - if (*s == '_') - *s = ' '; - bconf->flag.type2 = CONF_BAN_TYPE_AKILL; - AddListItem(bconf, conf_ban); - } - - if (IsSvsCmdOk(client)) - sendto_server(client, 0, 0, NULL, ":%s SVSNLINE + %s :%s", - client->id, parv[2], parv[3]); - break; - } - case '-': - { - if (!IsSvsCmdOk(client)) - return; - if (parc < 3) - return; - - for (bconf = conf_ban; bconf; bconf = bconf->next) - { - if (bconf->flag.type != CONF_BAN_REALNAME) - continue; - if (bconf->flag.type2 != CONF_BAN_TYPE_AKILL) - continue; - if (!strcasecmp(bconf->mask, parv[2])) - break; - } - if (bconf) - { - DelListItem(bconf, conf_ban); - safe_free(bconf->mask); - safe_free(bconf->reason); - safe_free(bconf); - - } - sendto_server(client, 0, 0, NULL, ":%s SVSNLINE - %s", client->id, parv[2]); - break; - } - case '*': - { - if (!IsSvsCmdOk(client)) - return; - wipe_svsnlines(); - sendto_server(client, 0, 0, NULL, ":%s SVSNLINE *", client->id); - break; - } + case '+': + { + if (parc < 4) + return; + if (!find_banEx(NULL, parv[3], CONF_BAN_REALNAME, CONF_BAN_TYPE_AKILL)) + { + bconf = safe_alloc(sizeof(ConfigItem_ban)); + bconf->flag.type = CONF_BAN_REALNAME; + safe_strdup(bconf->mask, parv[3]); + safe_strdup(bconf->reason, parv[2]); + for (s = bconf->reason; *s; s++) + if (*s == '_') + *s = ' '; + bconf->flag.type2 = CONF_BAN_TYPE_AKILL; + AddListItem(bconf, conf_ban); + } + + if (IsSvsCmdOk(client)) + sendto_server(client, 0, 0, NULL, ":%s SVSNLINE + %s :%s", + client->id, parv[2], parv[3]); + break; + } + case '-': + { + if (!IsSvsCmdOk(client)) + return; + if (parc < 3) + return; + + for (bconf = conf_ban; bconf; bconf = bconf->next) + { + if (bconf->flag.type != CONF_BAN_REALNAME) + continue; + if (bconf->flag.type2 != CONF_BAN_TYPE_AKILL) + continue; + if (!strcasecmp(bconf->mask, parv[2])) + break; + } + if (bconf) + { + DelListItem(bconf, conf_ban); + safe_free(bconf->mask); + safe_free(bconf->reason); + safe_free(bconf); + } + sendto_server(client, 0, 0, NULL, ":%s SVSNLINE - %s", client->id, parv[2]); + break; + } + case '*': + { + if (!IsSvsCmdOk(client)) + return; + wipe_svsnlines(); + sendto_server(client, 0, 0, NULL, ":%s SVSNLINE *", client->id); + break; + } } } diff --git a/src/modules/svsnolag.c b/src/modules/svsnolag.c index 1ffbe5f4a..64fe967bc 100644 --- a/src/modules/svsnolag.c +++ b/src/modules/svsnolag.c @@ -24,17 +24,16 @@ CMD_FUNC(cmd_svsnolag); CMD_FUNC(cmd_svs2nolag); -#define MSG_SVSNOLAG "SVSNOLAG" -#define MSG_SVS2NOLAG "SVS2NOLAG" +#define MSG_SVSNOLAG "SVSNOLAG" +#define MSG_SVS2NOLAG "SVS2NOLAG" -ModuleHeader MOD_HEADER - = { - "svsnolag", - "5.0", - "commands /svsnolag and /svs2nolag", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svsnolag", + "5.0", + "commands /svsnolag and /svs2nolag", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { diff --git a/src/modules/svsnoop.c b/src/modules/svsnoop.c index e2b6c4b7a..7981c0bc2 100644 --- a/src/modules/svsnoop.c +++ b/src/modules/svsnoop.c @@ -26,17 +26,16 @@ CMD_FUNC(cmd_svsnoop); -#define MSG_SVSNOOP "SVSNOOP" +#define MSG_SVSNOOP "SVSNOOP" -ModuleHeader MOD_HEADER - = { - "svsnoop", - "5.0", - "command /svsnoop", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svsnoop", + "5.0", + "command /svsnoop", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -86,8 +85,7 @@ CMD_FUNC(cmd_svsnoop) remove_oper_privileges(acptr, 1); } } - } - else + } else { SVSNOOP = 0; unreal_log(ULOG_INFO, "svsnoop", "SVSNOOP_ENABLED", client, diff --git a/src/modules/svso.c b/src/modules/svso.c index 3cbd34627..f74ff3051 100644 --- a/src/modules/svso.c +++ b/src/modules/svso.c @@ -4,13 +4,12 @@ */ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "svso", - "6.0.0", - "Grant oper privileges via SVSO services command", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "svso", + "6.0.0", + "Grant oper privileges via SVSO services command", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -20,7 +19,7 @@ MOD_INIT() { MARK_AS_OFFICIAL_MODULE(modinfo); - CommandAdd(modinfo->handle, "SVSO", cmd_svso, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, "SVSO", cmd_svso, MAXPARA, CMD_USER | CMD_SERVER); return MOD_SUCCESS; } @@ -119,7 +118,6 @@ CMD_FUNC(cmd_svso) if (!was_hidden_oper) irccounts.operators--; VERIFY_OPERCOUNT(acptr, "svso"); - } if (vhost && !valid_vhost(vhost)) diff --git a/src/modules/svspart.c b/src/modules/svspart.c index 2b2080a2d..181db2afe 100644 --- a/src/modules/svspart.c +++ b/src/modules/svspart.c @@ -21,21 +21,20 @@ CMD_FUNC(cmd_svspart); -#define MSG_SVSPART "SVSPART" +#define MSG_SVSPART "SVSPART" -ModuleHeader MOD_HEADER - = { - "svspart", /* Name of module */ - "5.0", /* Version */ - "command /svspart", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svspart", /* Name of module */ + "5.0", /* Version */ + "command /svspart", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SVSPART, cmd_svspart, 3, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_SVSPART, cmd_svspart, 3, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -49,7 +48,7 @@ MOD_LOAD() /* Called when module is unloaded */ MOD_UNLOAD() { - return MOD_SUCCESS; + return MOD_SUCCESS; } /* cmd_svspart() - Lamego - Wed Jul 21 20:04:48 1999 @@ -66,7 +65,7 @@ CMD_FUNC(cmd_svspart) if (!IsSvsCmdOk(client)) return; - if (parc < 3 || !(target = find_user(parv[1], NULL))) + if (parc < 3 || !(target = find_user(parv[1], NULL))) return; if (MyUser(target)) @@ -77,14 +76,13 @@ CMD_FUNC(cmd_svspart) parv[3] = NULL; do_cmd(target, NULL, "PART", comment ? 3 : 2, parv); /* NOTE: target may be killed now by spamfilter due to the part reason */ - } - else + } else { if (comment) sendto_one(target, NULL, ":%s SVSPART %s %s :%s", client->name, - parv[1], parv[2], parv[3]); + parv[1], parv[2], parv[3]); else sendto_one(target, NULL, ":%s SVSPART %s %s", client->name, - parv[1], parv[2]); + parv[1], parv[2]); } } diff --git a/src/modules/svssilence.c b/src/modules/svssilence.c index f1c154cbc..81f83e07f 100644 --- a/src/modules/svssilence.c +++ b/src/modules/svssilence.c @@ -21,14 +21,13 @@ CMD_FUNC(cmd_svssilence); -ModuleHeader MOD_HEADER - = { - "svssilence", /* Name of module */ - "5.0", /* Version */ - "command /svssilence", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svssilence", /* Name of module */ + "5.0", /* Version */ + "command /svssilence", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -44,7 +43,7 @@ MOD_LOAD() MOD_UNLOAD() { - return MOD_SUCCESS; + return MOD_SUCCESS; } /* cmd_svssilence() @@ -61,13 +60,13 @@ CMD_FUNC(cmd_svssilence) int mine; char *p, *cp, c; char request[BUFSIZE]; - + if (!IsSvsCmdOk(client)) return; if (parc < 3 || BadPtr(parv[2]) || !(target = find_user(parv[1], NULL))) return; - + if (!MyUser(target)) { sendto_one(target, NULL, ":%s SVSSILENCE %s :%s", client->name, parv[1], parv[2]); @@ -85,8 +84,7 @@ CMD_FUNC(cmd_svssilence) { /* "no such nick" */ continue; - } - else + } else c = '+'; cp = pretty_mask(p); if ((c == '-' && !del_silence(target, cp)) || diff --git a/src/modules/svssno.c b/src/modules/svssno.c index 41b57fecb..66b6f2fb9 100644 --- a/src/modules/svssno.c +++ b/src/modules/svssno.c @@ -25,22 +25,21 @@ CMD_FUNC(cmd_svssno); CMD_FUNC(cmd_svs2sno); -#define MSG_SVSSNO "SVSSNO" -#define MSG_SVS2SNO "SVS2SNO" +#define MSG_SVSSNO "SVSSNO" +#define MSG_SVS2SNO "SVS2SNO" -ModuleHeader MOD_HEADER - = { - "svssno", - "5.0", - "command /svssno", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svssno", + "5.0", + "command /svssno", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { - CommandAdd(modinfo->handle, MSG_SVSSNO, cmd_svssno, MAXPARA, CMD_USER|CMD_SERVER); - CommandAdd(modinfo->handle, MSG_SVS2SNO, cmd_svs2sno, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_SVSSNO, cmd_svssno, MAXPARA, CMD_USER | CMD_SERVER); + CommandAdd(modinfo->handle, MSG_SVS2SNO, cmd_svs2sno, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -73,7 +72,7 @@ void do_svssno(Client *client, MessageTag *recv_mtags, int parc, const char *par if (parc < 2) return; - if (parv[1][0] == '#') + if (parv[1][0] == '#') return; if (!(target = find_user(parv[1], NULL))) diff --git a/src/modules/svswatch.c b/src/modules/svswatch.c index 8f5ccfe31..150e2c17b 100644 --- a/src/modules/svswatch.c +++ b/src/modules/svswatch.c @@ -22,16 +22,15 @@ CMD_FUNC(cmd_svswatch); /* Place includes here */ -#define MSG_SVSWATCH "SVSWATCH" +#define MSG_SVSWATCH "SVSWATCH" -ModuleHeader MOD_HEADER - = { - "svswatch", /* Name of module */ - "5.0", /* Version */ - "command /svswatch", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "svswatch", /* Name of module */ + "5.0", /* Version */ + "command /svswatch", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() @@ -45,13 +44,12 @@ MOD_INIT() MOD_LOAD() { return MOD_SUCCESS; - } /* Called when module is unloaded */ MOD_UNLOAD() { - return MOD_SUCCESS; + return MOD_SUCCESS; } /* cmd_svswatch() - written by Syzop, suggested by Griever. @@ -74,7 +72,6 @@ CMD_FUNC(cmd_svswatch) parv[1] = parv[2]; parv[2] = NULL; do_cmd(target, NULL, "WATCH", 2, parv); - } - else + } else sendto_one(target, NULL, ":%s SVSWATCH %s :%s", client->name, parv[1], parv[2]); } diff --git a/src/modules/swhois.c b/src/modules/swhois.c index 8d8c71b9e..be003e3f6 100644 --- a/src/modules/swhois.c +++ b/src/modules/swhois.c @@ -26,16 +26,15 @@ CMD_FUNC(cmd_swhois); -#define MSG_SWHOIS "SWHOIS" +#define MSG_SWHOIS "SWHOIS" -ModuleHeader MOD_HEADER - = { - "swhois", - "5.0", - "command /swhois", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "swhois", + "5.0", + "command /swhois", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -67,8 +66,8 @@ MOD_UNLOAD() CMD_FUNC(cmd_swhois) { Client *target; - char tag[HOSTLEN+1]; - char swhois[SWHOISLEN+1]; + char tag[HOSTLEN + 1]; + char swhois[SWHOISLEN + 1]; int add; int priority = 0; @@ -88,7 +87,8 @@ CMD_FUNC(cmd_swhois) strlcpy(tag, parv[3], sizeof(tag)); priority = atoi(parv[4]); strlcpy(swhois, parv[5], sizeof(swhois)); - } else { + } else + { /* Old syntax */ strlcpy(tag, client->name, sizeof(tag)); if (BadPtr(parv[2])) @@ -96,7 +96,8 @@ CMD_FUNC(cmd_swhois) /* Delete. Hmmmm. Let's just delete anything with that tag. */ strcpy(swhois, "*"); add = 0; - } else { + } else + { /* Add */ add = 1; strlcpy(swhois, parv[2], sizeof(swhois)); diff --git a/src/modules/targetfloodprot.c b/src/modules/targetfloodprot.c index 70d69329e..948389d5c 100644 --- a/src/modules/targetfloodprot.c +++ b/src/modules/targetfloodprot.c @@ -2,22 +2,21 @@ * (C)Copyright 2020 Bram Matthys and the UnrealIRCd team * License: GPLv2 or later */ - + #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "targetfloodprot", - "5.0", - "Target flood protection (set::anti-flood::target-flood)", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "targetfloodprot", + "5.0", + "Target flood protection (set::anti-flood::target-flood)", + "UnrealIRCd Team", + "unrealircd-6", +}; -#define TFP_PRIVMSG 0 -#define TFP_NOTICE 1 -#define TFP_TAGMSG 2 -#define TFP_MAX 3 +#define TFP_PRIVMSG 0 +#define TFP_NOTICE 1 +#define TFP_TAGMSG 2 +#define TFP_MAX 3 typedef struct TargetFlood TargetFlood; struct TargetFlood { @@ -160,7 +159,7 @@ int targetfloodprot_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int * } else { config_error("%s:%i: unknown directive set::anti-flood::target-flood:%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } @@ -235,7 +234,7 @@ int targetfloodprot_can_send_to_channel(Client *client, Channel *channel, Member return HOOK_CONTINUE; /* U-Lines, servers and IRCOps override */ - if (IsULine(client) || !IsUser(client) || (IsOper(client) && ValidatePermissionsForPath("immune:target-flood",client,NULL,channel,NULL))) + if (IsULine(client) || !IsUser(client) || (IsOper(client) && ValidatePermissionsForPath("immune:target-flood", client, NULL, channel, NULL))) return HOOK_CONTINUE; what = sendtypetowhat(sendtype); @@ -260,10 +259,10 @@ int targetfloodprot_can_send_to_channel(Client *client, Channel *channel, Member { /* Flood detected */ unreal_log(ULOG_INFO, "flood", "FLOOD_BLOCKED", client, - "Flood blocked ($flood_type) from $client.details [$client.ip] to $channel ($message_type)", - log_data_string("flood_type", "target-flood-channel"), - log_data_channel("channel", channel), - log_data_string("message_type", sendtype_to_cmd(sendtype))); + "Flood blocked ($flood_type) from $client.details [$client.ip] to $channel ($message_type)", + log_data_string("flood_type", "target-flood-channel"), + log_data_channel("channel", channel), + log_data_string("message_type", sendtype_to_cmd(sendtype))); snprintf(errbuf, sizeof(errbuf), "Channel is being flooded. Message not delivered."); *errmsg = errbuf; return HOOK_DENY; @@ -286,7 +285,7 @@ int targetfloodprot_can_send_to_user(Client *client, Client *target, const char return HOOK_CONTINUE; /* U-Lines, servers and IRCOps override */ - if (IsULine(client) || !IsUser(client) || (IsOper(client) && ValidatePermissionsForPath("immune:target-flood",client,target,NULL,NULL))) + if (IsULine(client) || !IsUser(client) || (IsOper(client) && ValidatePermissionsForPath("immune:target-flood", client, target, NULL, NULL))) return HOOK_CONTINUE; what = sendtypetowhat(sendtype); @@ -311,10 +310,10 @@ int targetfloodprot_can_send_to_user(Client *client, Client *target, const char { /* Flood detected */ unreal_log(ULOG_INFO, "flood", "FLOOD_BLOCKED", client, - "Flood blocked ($flood_type) from $client.details [$client.ip] to $target ($message_type)", - log_data_string("flood_type", "target-flood-user"), - log_data_client("target", target), - log_data_string("message_type", sendtype_to_cmd(sendtype))); + "Flood blocked ($flood_type) from $client.details [$client.ip] to $target ($message_type)", + log_data_string("flood_type", "target-flood-user"), + log_data_client("target", target), + log_data_string("message_type", sendtype_to_cmd(sendtype))); snprintf(errbuf, sizeof(errbuf), "User is being flooded. Message not delivered."); *errmsg = errbuf; return HOOK_DENY; diff --git a/src/modules/time.c b/src/modules/time.c index 945aa4714..0fc724489 100644 --- a/src/modules/time.c +++ b/src/modules/time.c @@ -22,16 +22,15 @@ CMD_FUNC(cmd_time); /* Place includes here */ -#define MSG_TIME "TIME" +#define MSG_TIME "TIME" -ModuleHeader MOD_HEADER - = { - "time", /* Name of module */ - "5.0", /* Version */ - "command /time", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "time", /* Name of module */ + "5.0", /* Version */ + "command /time", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ diff --git a/src/modules/tkl.c b/src/modules/tkl.c index 8c1a1d3c4..6f4653adc 100644 --- a/src/modules/tkl.c +++ b/src/modules/tkl.c @@ -23,13 +23,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "tkl", - "5.0", - "Server ban commands such as /GLINE, /SPAMFILTER, etc.", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "tkl", + "5.0", + "Server ban commands such as /GLINE, /SPAMFILTER, etc.", + "UnrealIRCd Team", + "unrealircd-6", }; /* Forward declarations */ @@ -64,13 +63,13 @@ const char *_tkl_type_string(TKL *tk); const char *_tkl_type_config_string(TKL *tk); char *tkl_banexception_configname_to_chars(char *name); TKL *_tkl_add_serverban(int type, const char *usermask, const char *hostmask, SecurityGroup *match, - const char *reason, const char *set_by, - time_t expire_at, time_t set_at, int soft, int flags); + const char *reason, const char *set_by, + time_t expire_at, time_t set_at, int soft, int flags); TKL *_tkl_add_banexception(int type, const char *usermask, const char *hostmask, SecurityGroup *match, const char *reason, const char *set_by, time_t expire_at, time_t set_at, int soft, const char *bantypes, int flags); TKL *_tkl_add_nameban(int type, const char *name, int hold, const char *reason, const char *set_by, - time_t expire_at, time_t set_at, int flags); + time_t expire_at, time_t set_at, int flags); TKL *_tkl_add_spamfilter(int type, const char *id, unsigned short target, BanAction *action, Match *match, const char *rule, SecurityGroup *except, const char *set_by, @@ -85,7 +84,7 @@ void _free_tkl(TKL *tkl); void _tkl_del_line(TKL *tkl); static void _tkl_check_local_remove_shun(TKL *tmp); char *_tkl_uhost(TKL *tkl, char *buf, size_t buflen, int options); -void tkl_expire_entry(TKL * tmp); +void tkl_expire_entry(TKL *tmp); EVENT(tkl_check_expire); int _find_tkline_match(Client *client, int skip_soft); int _find_shun(Client *client); @@ -129,15 +128,14 @@ int spamfilter_pre_command(Client *from, MessageTag *mtags, const char *buf); extern int MODVAR spamf_ugly_vchanoverride; typedef struct TKLTypeTable TKLTypeTable; -struct TKLTypeTable -{ +struct TKLTypeTable { char *config_name; /**< The name as used in the configuration file */ char letter; /**< The letter ised in the TKL S2S command */ int type; /**< TKL_xxx, optionally OR'ed with TKL_GLOBAL */ char *log_name; /**< Used for logging and server notices */ - unsigned tkltype:1; /**< Is a type available in cmd_tkl() and friends */ - unsigned exceptiontype:1; /**< Is a type available for exceptions */ - unsigned needip:1; /**< When using this exempt option, only IP addresses are permitted (processed before DNS/ident lookups etc) */ + unsigned tkltype : 1; /**< Is a type available in cmd_tkl() and friends */ + unsigned exceptiontype : 1; /**< Is a type available for exceptions */ + unsigned needip : 1; /**< When using this exempt option, only IP addresses are permitted (processed before DNS/ident lookups etc) */ char *id_prefix; /**< Prefix for generated TKL ids, eg "G", "K", "SPAM". NULL for exempt-only options. Note that shun has "H" here while its type.letter is 's'. */ }; @@ -220,9 +218,9 @@ static void tkl_s2s_set_id(TKL *tkl, const char *value); static const char *tkl_s2s_get_spamfilter_id(TKL *tkl); static void tkl_s2s_set_spamfilter_id(TKL *tkl, const char *value); static const TKLS2SField tkl_s2s_fields[] = { - { "id", tkl_s2s_get_id, tkl_s2s_set_id }, - { "spamfilter_id", tkl_s2s_get_spamfilter_id, tkl_s2s_set_spamfilter_id }, - { NULL, NULL, NULL }, + {"id", tkl_s2s_get_id, tkl_s2s_set_id}, + {"spamfilter_id", tkl_s2s_get_spamfilter_id, tkl_s2s_set_spamfilter_id}, + {NULL, NULL, NULL}, }; MOD_TEST() @@ -234,14 +232,14 @@ MOD_TEST() HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, tkl_config_test_set); EfunctionAdd(modinfo->handle, EFUNC_TKL_HASH, _tkl_hash); #if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-function-type" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-function-type" #endif EfunctionAdd(modinfo->handle, EFUNC_TKL_TYPETOCHAR, TO_INTFUNC(_tkl_typetochar)); EfunctionAdd(modinfo->handle, EFUNC_TKL_CHARTOTYPE, TO_INTFUNC(_tkl_chartotype)); EfunctionAdd(modinfo->handle, EFUNC_TKL_CONFIGTYPETOCHAR, TO_INTFUNC(_tkl_configtypetochar)); #if defined(__GNUC__) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif EfunctionAddConstString(modinfo->handle, EFUNC_TKL_TYPE_STRING, _tkl_type_string); EfunctionAddConstString(modinfo->handle, EFUNC_TKL_TYPE_CONFIG_STRING, _tkl_type_config_string); @@ -309,8 +307,8 @@ MOD_INIT() CommandAdd(modinfo->handle, "GZLINE", cmd_gzline, 3, CMD_OPER); CommandAdd(modinfo->handle, "SPAMFILTER", cmd_spamfilter, 7, CMD_OPER); CommandAdd(modinfo->handle, "ELINE", cmd_eline, 4, CMD_OPER); - CommandAdd(modinfo->handle, "TKL", _cmd_tkl, MAXPARA, CMD_OPER|CMD_SERVER); - CommandAdd(modinfo->handle, "SPAMINFO", cmd_spaminfo, 1, CMD_OPER|CMD_TEXTANALYSIS); + CommandAdd(modinfo->handle, "TKL", _cmd_tkl, MAXPARA, CMD_OPER | CMD_SERVER); + CommandAdd(modinfo->handle, "SPAMINFO", cmd_spaminfo, 1, CMD_OPER | CMD_TEXTANALYSIS); add_default_exempts(); return MOD_SUCCESS; } @@ -375,7 +373,7 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (has_id) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::id"); + cep->line_number, "spamfilter::id"); continue; } has_id = 1; @@ -383,16 +381,15 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e { config_error("%s:%i: spamfilter::id invalid: maximum size (%d chars) exceeded " "or forbidden characters encountered: only A-Z, 0-9 and _ are permitted.", - cep->file->filename, cep->line_number, TKLIDLEN-1); + cep->file->filename, cep->line_number, TKLIDLEN - 1); errors++; } - } else - if (!strcmp(cep->name, "target")) + } else if (!strcmp(cep->name, "target")) { if (has_target) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::target"); + cep->line_number, "spamfilter::target"); continue; } has_target = 1; @@ -401,149 +398,136 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (!spamfilter_getconftargets(cep->value)) { config_error("%s:%i: unknown spamfiler target type '%s'", - cep->file->filename, cep->line_number, cep->value); + cep->file->filename, cep->line_number, cep->value); errors++; } - } - else if (cep->items) + } else if (cep->items) { for (cepp = cep->items; cepp; cepp = cepp->next) { if (!spamfilter_getconftargets(cepp->name)) { config_error("%s:%i: unknown spamfiler target type '%s'", - cepp->file->filename, - cepp->line_number, cepp->name); + cepp->file->filename, + cepp->line_number, cepp->name); errors++; } } - } - else + } else { config_error_empty(cep->file->filename, - cep->line_number, "spamfilter", cep->name); + cep->line_number, "spamfilter", cep->name); errors++; } continue; - } else - if (!strcmp(cep->name, "input-conversion")) + } else if (!strcmp(cep->name, "input-conversion")) { if (has_input_conversion) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::input-conversion"); + cep->line_number, "spamfilter::input-conversion"); continue; } has_input_conversion = 1; if (cep->value) { - if (input_conversion_strtoval(cep->value)<0) + if (input_conversion_strtoval(cep->value) < 0) { config_error("%s:%i: unknown input-conversion method '%s'", - cep->file->filename, cep->line_number, cep->value); + cep->file->filename, cep->line_number, cep->value); errors++; } - } - else if (cep->items) + } else if (cep->items) { for (cepp = cep->items; cepp; cepp = cepp->next) { - if (input_conversion_strtoval(cepp->name)<0) + if (input_conversion_strtoval(cepp->name) < 0) { config_error("%s:%i: unknown input-conversion method '%s'", - cepp->file->filename, - cepp->line_number, cepp->name); + cepp->file->filename, + cepp->line_number, cepp->name); errors++; } } - } - else + } else { config_error_empty(cep->file->filename, - cep->line_number, "spamfilter", cep->name); + cep->line_number, "spamfilter", cep->name); errors++; } continue; - } - else if (!strcmp(cep->name, "action")) + } else if (!strcmp(cep->name, "action")) { if (has_action) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::action"); + cep->line_number, "spamfilter::action"); continue; } has_action = 1; errors += test_ban_action_config(cep); - } - else if (!strcmp(cep->name, "except")) + } else if (!strcmp(cep->name, "except")) { test_match_block(cf, cep, &errors); - } - else if (!cep->value) + } else if (!cep->value) { config_error_empty(cep->file->filename, cep->line_number, - "spamfilter", cep->name); + "spamfilter", cep->name); errors++; continue; - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { if (has_reason) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::reason"); + cep->line_number, "spamfilter::reason"); continue; } has_reason = 1; reason = cep->value; - } - else if (!strcmp(cep->name, "match") || !strcmp(cep->name, "match-string")) + } else if (!strcmp(cep->name, "match") || !strcmp(cep->name, "match-string")) { if (has_match) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::match-string"); + cep->line_number, "spamfilter::match-string"); continue; } has_match = 1; match = cep->value; - } - else if (!strcmp(cep->name, "rule")) + } else if (!strcmp(cep->name, "rule")) { int val; if (has_rule) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::rule"); + cep->line_number, "spamfilter::rule"); continue; } has_rule = 1; if ((val = crule_test(cep->value))) { config_error("%s:%i: spamfilter::rule contains an invalid expression: %s", - cep->file->filename, - cep->line_number, - crule_errstring(val)); + cep->file->filename, + cep->line_number, + crule_errstring(val)); errors++; } - } - else if (!strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-time")) { if (has_bantime) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::ban-time"); + cep->line_number, "spamfilter::ban-time"); continue; } has_bantime = 1; - } - else if (!strcmp(cep->name, "match-type")) + } else if (!strcmp(cep->name, "match-type")) { if (has_match_type) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::match-type"); + cep->line_number, "spamfilter::match-type"); continue; } if (!strcasecmp(cep->value, "posix")) @@ -567,13 +551,12 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e continue; } has_match_type = 1; - } - else if (!strcmp(cep->name, "show-message-content-on-hit")) + } else if (!strcmp(cep->name, "show-message-content-on-hit")) { if (has_show_message_content_on_hit) { config_warn_duplicate(cep->file->filename, - cep->line_number, "spamfilter::show-message-content-on-hit"); + cep->line_number, "spamfilter::show-message-content-on-hit"); continue; } has_show_message_content_on_hit = 1; @@ -583,11 +566,10 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e cep->file->filename, cep->line_number, cep->value); errors++; } - } - else + } else { config_error_unknown(cep->file->filename, cep->line_number, - "spamfilter", cep->name); + "spamfilter", cep->name); errors++; continue; } @@ -602,9 +584,9 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (!m) { config_error("%s:%i: spamfilter::match contains an invalid regex: %s", - ce->file->filename, - ce->line_number, - err); + ce->file->filename, + ce->line_number, + err); errors++; } else { @@ -615,7 +597,7 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (!has_match && !has_rule) { config_error_missing(ce->file->filename, ce->line_number, - "spamfilter::match or spamfilter::rule"); + "spamfilter::match or spamfilter::rule"); errors++; } if (!has_match && has_match_type && has_rule) @@ -627,13 +609,13 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (!has_target && match) { config_error_missing(ce->file->filename, ce->line_number, - "spamfilter::target"); + "spamfilter::target"); errors++; } if (!has_action) { config_error_missing(ce->file->filename, ce->line_number, - "spamfilter::action"); + "spamfilter::action"); errors++; } if (match && reason && (strlen(match) + strlen(reason) > 505)) @@ -646,7 +628,7 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e if (!has_match_type && match) { config_error_missing(ce->file->filename, ce->line_number, - "spamfilter::match-type"); + "spamfilter::match-type"); errors++; } @@ -654,7 +636,7 @@ int tkl_config_test_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type, int *e { config_warn("*** IMPORTANT ***"); config_warn("You have old examples in your spamfilter.conf. " - "We suggest you to edit this file and replace the examples."); + "We suggest you to edit this file and replace the examples."); config_warn("Please read https://www.unrealircd.org/docs/FAQ#old-spamfilter-conf !!!"); config_warn("*****************"); } @@ -724,12 +706,10 @@ int tkl_config_run_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "match") || !strcmp(cep->name, "match-string")) { match = cep->value; - } - else if (!strcmp(cep->name, "rule")) + } else if (!strcmp(cep->name, "rule")) { rule = cep->value; - } - else if (!strcmp(cep->name, "target")) + } else if (!strcmp(cep->name, "target")) { if (cep->value) target = spamfilter_getconftargets(cep->value); @@ -738,8 +718,7 @@ int tkl_config_run_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type) for (cepp = cep->items; cepp; cepp = cepp->next) target |= spamfilter_getconftargets(cepp->name); } - } - else if (!strcmp(cep->name, "input-conversion")) + } else if (!strcmp(cep->name, "input-conversion")) { if (cep->value) input_conversion = input_conversion_strtoval(cep->value); @@ -753,28 +732,22 @@ int tkl_config_run_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type) input_conversion |= input_conversion_strtoval(cepp->name); } } - } - else if (!strcmp(cep->name, "action")) + } else if (!strcmp(cep->name, "action")) { parse_ban_action_config(cep, &action); - } - else if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { banreason = cep->value; - } - else if (!strcmp(cep->name, "ban-time")) + } else if (!strcmp(cep->name, "ban-time")) { bantime = config_checkval(cep->value, CFG_TIME); - } - else if (!strcmp(cep->name, "match-type")) + } else if (!strcmp(cep->name, "match-type")) { match_type = unreal_match_method_strtoval(cep->value); - } - else if (!strcmp(cep->name, "except")) + } else if (!strcmp(cep->name, "except")) { conf_match_block(cf, cep, &except); - } - else if (!strcmp(cep->name, "show-message-content-on-hit")) + } else if (!strcmp(cep->name, "show-message-content-on-hit")) { show_message_content_on_hit = spamfilter_show_message_content_on_hit_strtoval(cep->value); } @@ -790,7 +763,8 @@ int tkl_config_run_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type) lower_ban_action_to_maximum(action, iConf.central_spamfilter_limit_ban_action); if (iConf.central_spamfilter_limit_ban_time && (bantime > iConf.central_spamfilter_limit_ban_time)) bantime = iConf.central_spamfilter_limit_ban_time; - } else { + } else + { id = NULL; } @@ -801,9 +775,9 @@ int tkl_config_run_spamfilter(ConfigFile *cf, ConfigEntry *ce, int type) if (!m) { config_warn("%s:%i: This spamfilter block is ignored because spamfilter::match contained an invalid regex: %s", - ce->file->filename, - ce->line_number, - err); + ce->file->filename, + ce->line_number, + err); /* This is great, now we need to undo everything.. */ free_security_group(except); safe_free_all_ban_actions(action); @@ -862,18 +836,18 @@ int tkl_config_test_ban(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) has_mask = 1; test_match_block(cf, cep, &errors); } - } else { + } else + { if (!cep->value && !(cep->items && cep->items->name)) { config_error("%s:%d: ban %s with invalid or no mask", - cep->file->filename, cep->line_number, - ce->value); + cep->file->filename, cep->line_number, + ce->value); errors++; } has_mask = 1; } - } else - if (!strcmp(cep->name, "match")) + } else if (!strcmp(cep->name, "match")) { if (test_match) { @@ -882,40 +856,38 @@ int tkl_config_test_ban(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) has_match = 1; test_match_block(cf, cep, &errors); } - } else { + } else + { config_error("%s:%d: ban %s only supports simple mask and not match.", - cep->file->filename, cep->line_number, ce->value); + cep->file->filename, cep->line_number, ce->value); errors++; has_match = 1; } - } else - if (!strcmp(cep->name, "soft")) + } else if (!strcmp(cep->name, "soft")) { if (config_is_blankorempty(cep, "ban::soft")) errors++; if (strcmp(ce->value, "user")) { config_error("%s:%d: ban %s::soft can only be used in a ban user { } block", - cep->file->filename, cep->line_number, ce->value); + cep->file->filename, cep->line_number, ce->value); errors++; } - } else - if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { if (has_reason) { config_warn_duplicate(cep->file->filename, - cep->line_number, "ban::reason"); + cep->line_number, "ban::reason"); continue; } has_reason = 1; - } - else + } else { config_error("%s:%i: unknown directive ban %s::%s", - cep->file->filename, cep->line_number, - ce->value, - cep->name); + cep->file->filename, cep->line_number, + ce->value, + cep->name); errors++; } } @@ -923,7 +895,7 @@ int tkl_config_test_ban(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!has_mask && !has_match) { config_error_missing(ce->file->filename, ce->line_number, - "ban::mask"); + "ban::mask"); errors++; } @@ -938,7 +910,7 @@ int tkl_config_test_ban(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!has_reason) { config_error_missing(ce->file->filename, ce->line_number, - "ban::reason"); + "ban::reason"); errors++; } @@ -962,7 +934,7 @@ void tkl_config_run_ban_nickip_helper(ConfigFile *cf, ConfigEntry *cep, const ch if (!parse_extended_server_ban(mask, NULL, &err, 0, mask1buf, sizeof(mask1buf), mask2buf, sizeof(mask2buf))) { config_warn("%s:%d: Could not add extended server ban '%s': %s", - cep->file->filename, cep->line_number, mask, err); + cep->file->filename, cep->line_number, mask, err); return; } safe_strdup(usermask, mask1buf); @@ -979,7 +951,8 @@ void tkl_config_run_ban_nickip_helper(ConfigFile *cf, ConfigEntry *cep, const ch *p++ = '\0'; safe_strdup(usermask, buf); safe_strdup(hostmask, p); - } else { + } else + { safe_strdup(hostmask, mask); } } @@ -1050,12 +1023,10 @@ int tkl_config_run_ban_user(ConfigFile *cf, ConfigEntry *ce, int configtype) if (!strcmp(cep->name, "match") || !strcmp(cep->name, "mask")) { conf_match_block(cf, cep, &match); - } else - if (!strcmp(cep->name, "reason")) + } else if (!strcmp(cep->name, "reason")) { safe_strdup(reason, cep->value); - } else - if (!strcmp(cep->name, "soft")) + } else if (!strcmp(cep->name, "soft")) { soft = config_checkval(cep->value, CFG_YESNO); } @@ -1104,7 +1075,7 @@ int tkl_config_test_except(ConfigFile *cf, ConfigEntry *ce, int configtype, int if (!strcmp(ce->value, "tkl")) { config_error("%s:%d: except tkl { } has been renamed to except ban { }", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); config_status("Please rename your block in the configuration file."); *errs = 1; return -1; @@ -1119,16 +1090,14 @@ int tkl_config_test_except(ConfigFile *cf, ConfigEntry *ce, int configtype, int has_mask = 1; test_match_block(cf, cep, &errors); } - } else - if (!strcmp(cep->name, "match")) + } else if (!strcmp(cep->name, "match")) { if (cep->value || cep->items) { has_match = 1; test_match_block(cf, cep, &errors); } - } else - if (!strcmp(cep->name, "type")) + } else if (!strcmp(cep->name, "type")) { if (cep->items) { @@ -1137,25 +1106,25 @@ int tkl_config_test_except(ConfigFile *cf, ConfigEntry *ce, int configtype, int if (!tkl_banexception_configname_to_chars(cepp->name)) { config_error("%s:%d: except ban::type '%s' unknown. Must be one of: %s", - cepp->file->filename, cepp->line_number, cepp->name, - ALL_VALID_EXCEPTION_TYPES); + cepp->file->filename, cepp->line_number, cepp->name, + ALL_VALID_EXCEPTION_TYPES); errors++; } - } else - if (cep->value) + } else if (cep->value) { /* type x; */ if (!tkl_banexception_configname_to_chars(cep->value)) { config_error("%s:%d: except ban::type '%s' unknown. Must be one of: %s", - cep->file->filename, cep->line_number, cep->value, - ALL_VALID_EXCEPTION_TYPES); + cep->file->filename, cep->line_number, cep->value, + ALL_VALID_EXCEPTION_TYPES); errors++; } } - } else { + } else + { config_error_unknown(cep->file->filename, - cep->line_number, "except", cep->name); + cep->line_number, "except", cep->name); errors++; continue; } @@ -1164,7 +1133,7 @@ int tkl_config_test_except(ConfigFile *cf, ConfigEntry *ce, int configtype, int if (!has_mask && !has_match) { config_error_missing(ce->file->filename, ce->line_number, - "except ban::match"); + "except ban::match"); errors++; } if (has_mask && has_match) @@ -1212,15 +1181,13 @@ int tkl_config_run_except(ConfigFile *cf, ConfigEntry *ce, int configtype) char *str = tkl_banexception_configname_to_chars(cepp->name); strlcat(bantypes, str, sizeof(bantypes)); } - } else - if (cep->value) + } else if (cep->value) { /* type x; */ char *str = tkl_banexception_configname_to_chars(cep->value); strlcat(bantypes, str, sizeof(bantypes)); } - } else - if (!strcmp(cep->name, "match") || !strcmp(cep->name, "mask")) + } else if (!strcmp(cep->name, "match") || !strcmp(cep->name, "mask")) { conf_match_block(cf, cep, &match); } @@ -1260,7 +1227,7 @@ int tkl_config_test_set(ConfigFile *cf, ConfigEntry *ce, int configtype, int *er if (!ce->value) { config_error("%s:%i: set::max-stats-matches: no value specified", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } // allow any other value, including 0 and negative. @@ -1584,7 +1551,8 @@ static void spamfilter_regex_error(TKL *tkl, const char *regex_error) "To delete, use: /SPAMFILTER del $tkl.id", log_data_string("regex_error", regex_error), log_data_tkl("tkl", tkl)); - } else { + } else + { unreal_log(ULOG_WARNING, "tkl", "SPAMFILTER_REGEX_ERROR", NULL, "[Spamfilter] Regex aborted ($regex_error) for '$tkl'. Possibly too complex regex? " "To remove it, edit your config file", @@ -1599,7 +1567,7 @@ int tkl_ip_change(Client *client, const char *oldip) if ((tkl = find_tkline_match_zap(client))) { tkl_hit(client, tkl); - banned_client(client, "Z-Lined", tkl->ptr.serverban->reason, tkl->id, (tkl->type & TKL_GLOBAL)?1:0, NO_EXIT_CLIENT); + banned_client(client, "Z-Lined", tkl->ptr.serverban->reason, tkl->id, (tkl->type & TKL_GLOBAL) ? 1 : 0, NO_EXIT_CLIENT); } return 0; } @@ -1610,7 +1578,7 @@ int tkl_accept(Client *client) if ((tkl = find_tkline_match_zap(client))) { tkl_hit(client, tkl); - banned_client(client, "Z-Lined", tkl->ptr.serverban->reason, tkl->id, (tkl->type & TKL_GLOBAL)?1:0, NO_EXIT_CLIENT); + banned_client(client, "Z-Lined", tkl->ptr.serverban->reason, tkl->id, (tkl->type & TKL_GLOBAL) ? 1 : 0, NO_EXIT_CLIENT); return 2; // TODO: HOOK_DENY_ALWAYS; } return 0; @@ -1628,7 +1596,7 @@ CMD_FUNC(cmd_gline) if (IsServer(client)) return; - if (!ValidatePermissionsForPath("server-ban:gline",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:gline", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -1654,7 +1622,7 @@ CMD_FUNC(cmd_gzline) if (IsServer(client)) return; - if (!ValidatePermissionsForPath("server-ban:zline:global",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:zline:global", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -1667,7 +1635,8 @@ CMD_FUNC(cmd_gzline) parv[1] = "gline"; /* (there's no /STATS gzline, it's included in /STATS gline output) */ parv[2] = NULL; do_cmd(client, recv_mtags, "STATS", 2, parv); - } else { + } else + { cmd_tkl_line(client, parc, parv, "Z"); } } @@ -1679,7 +1648,7 @@ CMD_FUNC(cmd_shun) if (IsServer(client)) return; - if (!ValidatePermissionsForPath("server-ban:shun",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:shun", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -1692,7 +1661,8 @@ CMD_FUNC(cmd_shun) parv[1] = "shun"; parv[2] = NULL; do_cmd(client, recv_mtags, "STATS", 2, parv); - } else { + } else + { cmd_tkl_line(client, parc, parv, "s"); } } @@ -1707,7 +1677,7 @@ CMD_FUNC(cmd_tempshun) const char *name; int remove = 0; - if (MyUser(client) && (!ValidatePermissionsForPath("server-ban:shun:temporary",client,NULL,NULL,NULL))) + if (MyUser(client) && (!ValidatePermissionsForPath("server-ban:shun:temporary", client, NULL, NULL, NULL))) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -1718,10 +1688,10 @@ CMD_FUNC(cmd_tempshun) return; } if (parv[1][0] == '+') - name = parv[1]+1; + name = parv[1] + 1; else if (parv[1][0] == '-') { - name = parv[1]+1; + name = parv[1] + 1; remove = 1; } else name = parv[1]; @@ -1736,33 +1706,36 @@ CMD_FUNC(cmd_tempshun) { sendto_one(target, NULL, ":%s TEMPSHUN %c%s :%s", client->id, remove ? '-' : '+', target->id, comment); - } else { + } else + { char buf[1024]; if (!remove) { if (IsShunned(target)) { sendnotice(client, "User '%s' already shunned", target->name); - } else if (ValidatePermissionsForPath("immune:server-ban:shun",target,NULL,NULL,NULL)) + } else if (ValidatePermissionsForPath("immune:server-ban:shun", target, NULL, NULL, NULL)) { sendnotice(client, "You cannot tempshun '%s' because (s)he is an oper with 'immune:server-ban:shun' privilege", target->name); } else { SetShunned(target); unreal_log(ULOG_INFO, "tkl", "TKL_ADD_TEMPSHUN", client, - "Temporary shun added on user $target.details [reason: $shun_reason] [by: $client]", - log_data_string("shun_reason", comment), - log_data_client("target", target)); + "Temporary shun added on user $target.details [reason: $shun_reason] [by: $client]", + log_data_string("shun_reason", comment), + log_data_client("target", target)); } - } else { + } else + { if (!IsShunned(target)) { sendnotice(client, "User '%s' is not shunned", target->name); - } else { + } else + { ClearShunned(target); unreal_log(ULOG_INFO, "tkl", "TKL_DEL_TEMPSHUN", client, - "Temporary shun removed from user $target.details [by: $client]", - log_data_client("target", target)); + "Temporary shun removed from user $target.details [by: $client]", + log_data_client("target", target)); } } } @@ -1775,7 +1748,7 @@ CMD_FUNC(cmd_kline) if (IsServer(client)) return; - if (!ValidatePermissionsForPath("server-ban:kline:local:add",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:kline:local:add", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -1791,7 +1764,7 @@ CMD_FUNC(cmd_kline) return; } - if (!ValidatePermissionsForPath("server-ban:kline:remove",client,NULL,NULL,NULL) && *parv[1] == '-') + if (!ValidatePermissionsForPath("server-ban:kline:remove", client, NULL, NULL, NULL) && *parv[1] == '-') { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -1844,7 +1817,7 @@ CMD_FUNC(cmd_zline) if (IsServer(client)) return; - if (!ValidatePermissionsForPath("server-ban:zline:local:add",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:zline:local:add", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -1888,12 +1861,13 @@ int ban_too_broad(char *usermask, char *hostmask) p = strchr(hostmask, '/'); if (p) { - int cidrlen = atoi(p+1); + int cidrlen = atoi(p + 1); if (strchr(hostmask, ':')) { if (cidrlen < 48) return 1; /* too broad IPv6 CIDR mask */ - } else { + } else + { if (cidrlen < 16) return 1; /* too broad IPv4 CIDR mask */ } @@ -1950,7 +1924,7 @@ int parse_extended_server_ban(const char *mask_in, Client *client, char **error, const char *str; char *p; BanContext *b = NULL; - char mask[USERLEN + NICKLEN + HOSTLEN + 32]; // same as extban_conv_param_nuh_or_extban() + char mask[USERLEN + NICKLEN + HOSTLEN + 32]; // same as extban_conv_param_nuh_or_extban() char newmask[USERLEN + NICKLEN + HOSTLEN + 32]; char soft_ban = 0; @@ -1961,9 +1935,10 @@ int parse_extended_server_ban(const char *mask_in, Client *client, char **error, /* Work on a copy */ if (*mask_in == '%') { - strlcpy(mask, mask_in+1, sizeof(mask)); + strlcpy(mask, mask_in + 1, sizeof(mask)); soft_ban = 1; - } else { + } else + { strlcpy(mask, mask_in, sizeof(mask)); } @@ -2142,7 +2117,8 @@ int _server_ban_parse_mask(Client *client, int add, char type, const char *str, { /* Check if it's a hostmask and legal .. */ p = strchr(mask, '@'); - if (p) { + if (p) + { if ((p == mask) || !p[1]) { *error = "No user@host specified"; @@ -2177,7 +2153,7 @@ int _server_ban_parse_mask(Client *client, int add, char type, const char *str, "If you want to use usermasks, use a KLINE/GLINE instead."; return 0; } - for (p=hostmask; *p; p++) + for (p = hostmask; *p; p++) { if (isalpha(*p) && !isxdigit(*p)) { @@ -2189,8 +2165,7 @@ int _server_ban_parse_mask(Client *client, int add, char type, const char *str, } } } - } - else + } else { /* It's seemingly a nick .. let's see if we can find the user */ Client *acptr; @@ -2200,8 +2175,7 @@ int _server_ban_parse_mask(Client *client, int add, char type, const char *str, if ((type == 'z') || (type == 'Z')) action = BAN_ACT_ZLINE; // to indicate zline (no hostname, no dns, etc) ban_target_to_tkl_layer(iConf.manual_ban_target, action, acptr, (const char **)&usermask, (const char **)&hostmask); - } - else + } else { *error = "Nickname not found"; return 0; @@ -2231,16 +2205,16 @@ void cmd_tkl_line(Client *client, int parc, const char *parv[], char *type) char mo[64], mo2[64], reasonbuf[512]; char *p, *usermask, *hostmask; const char *tkllayer[10] = { - me.name, /*0 server.name */ - NULL, /*1 +|- */ - NULL, /*2 G */ - NULL, /*3 user */ - NULL, /*4 host */ - NULL, /*5 set_by */ - "0", /*6 expire_at */ - NULL, /*7 set_at */ - "no reason", /*8 reason */ - NULL, + me.name, /*0 server.name */ + NULL, /*1 +|- */ + NULL, /*2 G */ + NULL, /*3 user */ + NULL, /*4 host */ + NULL, /*5 set_by */ + "0", /*6 expire_at */ + NULL, /*7 set_at */ + "no reason", /*8 reason */ + NULL, }; struct tm *t; @@ -2253,8 +2227,7 @@ void cmd_tkl_line(Client *client, int parc, const char *parv[], char *type) { add = 0; mask++; - } - else if (*mask == '+') + } else if (*mask == '+') { add = 1; mask++; @@ -2295,8 +2268,7 @@ void cmd_tkl_line(Client *client, int parc, const char *parv[], char *type) ircsnprintf(mo, sizeof(mo), "%lld", (long long)(DEFAULT_BANTIME + TStime())); else ircsnprintf(mo, sizeof(mo), "%lld", (long long)secs); /* "0" */ - } - else + } else ircsnprintf(mo, sizeof(mo), "%lld", (long long)(secs + TStime())); ircsnprintf(mo2, sizeof(mo2), "%lld", (long long)TStime()); tkllayer[6] = mo; @@ -2308,11 +2280,11 @@ void cmd_tkl_line(Client *client, int parc, const char *parv[], char *type) { snprintf(reasonbuf, sizeof(reasonbuf), "%s %s", parv[2], parv[3]); tkllayer[8] = reasonbuf; - } else { + } else + { tkllayer[8] = parv[2]; } - } - else if (parc > 3) + } else if (parc > 3) { tkllayer[8] = parv[3]; } @@ -2335,12 +2307,10 @@ void cmd_tkl_line(Client *client, int parc, const char *parv[], char *type) /* call the tkl layer .. */ cmd_tkl(NULL, &me, NULL, 9, tkllayer); - } - else + } else { /* call the tkl layer .. */ cmd_tkl(NULL, &me, NULL, 6, tkllayer); - } } @@ -2376,7 +2346,7 @@ TKLTypeTable *eline_type_requires_ip(const char *bantypes) { int i; - for (i=0; tkl_types[i].config_name; i++) + for (i = 0; tkl_types[i].config_name; i++) if (tkl_types[i].needip && strchr(bantypes, tkl_types[i].letter)) return &tkl_types[i]; return NULL; @@ -2479,7 +2449,8 @@ int _server_ban_exception_parse_mask(Client *client, int add, const char *bantyp snprintf(errbuf, sizeof(errbuf), "ERROR: Ban exception with type '%c' does not work on extended server bans. " "This is because checking for %s takes places BEFORE " - "extended bans can be checked.", t->letter, t->log_name); + "extended bans can be checked.", + t->letter, t->log_name); *error = errbuf; return 0; } @@ -2489,7 +2460,8 @@ int _server_ban_exception_parse_mask(Client *client, int add, const char *bantyp { /* Check if it's a hostmask and legal .. */ p = strchr(mask, '@'); - if (p) { + if (p) + { if ((p == mask) || !p[1]) { *error = "No user@host specified"; @@ -2526,7 +2498,7 @@ int _server_ban_exception_parse_mask(Client *client, int add, const char *bantyp *error = errbuf; return 0; } - for (p=hostmask; *p; p++) + for (p = hostmask; *p; p++) { if (isalpha(*p) && !isxdigit(*p)) { @@ -2540,8 +2512,7 @@ int _server_ban_exception_parse_mask(Client *client, int add, const char *bantyp } } } - } - else + } else { /* It's seemingly a nick .. let's see if we can find the user */ Client *acptr; @@ -2551,8 +2522,7 @@ int _server_ban_exception_parse_mask(Client *client, int add, const char *bantyp if (add && eline_type_requires_ip(bantypes)) action = BAN_ACT_ZLINE; // to indicate zline (no hostname, no dns, etc) ban_target_to_tkl_layer(iConf.manual_ban_target, action, acptr, (const char **)&usermask, (const char **)&hostmask); - } - else + } else { *error = "Nickname not found"; return 0; @@ -2578,27 +2548,27 @@ CMD_FUNC(cmd_eline) char maskbuf[BUFSIZE]; char mask1buf[BUFSIZE]; char mask2buf[BUFSIZE]; - const char *p, *bantypes=NULL, *reason=NULL; + const char *p, *bantypes = NULL, *reason = NULL; char *usermask, *hostmask; const char *tkllayer[11] = { - me.name, /*0 server.name */ - NULL, /*1 +|- */ - NULL, /*2 E */ - NULL, /*3 user */ - NULL, /*4 host */ - NULL, /*5 set_by */ - "0", /*6 expire_at */ - "-", /*7 set_at */ - "-", /*8 ban types */ - "-", /*9 reason */ - NULL, + me.name, /*0 server.name */ + NULL, /*1 +|- */ + NULL, /*2 E */ + NULL, /*3 user */ + NULL, /*4 host */ + NULL, /*5 set_by */ + "0", /*6 expire_at */ + "-", /*7 set_at */ + "-", /*8 ban types */ + "-", /*9 reason */ + NULL, }; TKLTypeTable *t; if (IsServer(client)) return; - if (!ValidatePermissionsForPath("server-ban:eline",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:eline", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -2620,8 +2590,7 @@ CMD_FUNC(cmd_eline) { add = 0; mask++; - } - else if (*mask == '+') + } else if (*mask == '+') { add = 1; mask++; @@ -2681,19 +2650,17 @@ CMD_FUNC(cmd_eline) sendnotice(client, "ERROR: bantype '%c' is unrecognized (in '%s'). " "Note that the bantypes are case sensitive. " "Type /ELINE to see a list of all possible bantypes.", - c, bantypes); + c, bantypes); return; } tkllayer[9] = reason; /* call the tkl layer .. */ cmd_tkl(NULL, &me, NULL, 10, tkllayer); - } - else + } else { /* Remove ELINE */ /* call the tkl layer .. */ cmd_tkl(NULL, &me, NULL, 10, tkllayer); - } } @@ -2710,8 +2677,8 @@ void spamfilter_usage(Client *client) void spamfilter_new_usage(Client *client, const char *parv[]) { sendnotice(client, "Unknown match-type '%s'. Must be one of: -regex (new fast PCRE regexes) or " - "-simple (simple text with ? and * wildcards)", - parv[2]); + "-simple (simple text with ? and * wildcards)", + parv[2]); if (*parv[2] != '-') sendnotice(client, "Using the old 3.2.x /SPAMFILTER syntax? Note the new -regex/-simple field!!"); @@ -2728,26 +2695,26 @@ void spamfilter_del_by_id(Client *client, const char *id) TKL *match = NULL; char mo[32], mo2[32]; const char *tkllayer[13] = { - me.name, /* 0 server.name */ - NULL, /* 1 +|- */ - "F", /* 2 F */ - NULL, /* 3 usermask (targets) */ - NULL, /* 4 hostmask (action) */ - NULL, /* 5 set_by */ - "0", /* 6 expire_at */ - "0", /* 7 set_at */ - "", /* 8 tkl time */ - "", /* 9 tkl reason */ - "", /* 10 match method */ - "", /* 11 regex */ - NULL, + me.name, /* 0 server.name */ + NULL, /* 1 +|- */ + "F", /* 2 F */ + NULL, /* 3 usermask (targets) */ + NULL, /* 4 hostmask (action) */ + NULL, /* 5 set_by */ + "0", /* 6 expire_at */ + "0", /* 7 set_at */ + "", /* 8 tkl time */ + "", /* 9 tkl reason */ + "", /* 10 match method */ + "", /* 11 regex */ + NULL, }; for (index = 0; index < TKLISTLEN; index++) { for (tk = tklines[index]; tk; tk = tk->next) { - if ((tk->type & (TKL_GLOBAL|TKL_SPAMF)) != (TKL_GLOBAL|TKL_SPAMF)) + if ((tk->type & (TKL_GLOBAL | TKL_SPAMF)) != (TKL_GLOBAL | TKL_SPAMF)) continue; /* Match the real id, or for an id-less spamfilter (eg from an old server) * its locally-computed fallback handle. @@ -2800,19 +2767,19 @@ CMD_FUNC(cmd_spamfilter) int add = 1; char mo[32], mo2[32]; const char *tkllayer[13] = { - me.name, /* 0 server.name */ - NULL, /* 1 +|- */ - "F", /* 2 F */ - NULL, /* 3 usermask (targets) */ - NULL, /* 4 hostmask (action) */ - NULL, /* 5 set_by */ - "0", /* 6 expire_at */ - "0", /* 7 set_at */ - "", /* 8 tkl time */ - "", /* 9 tkl reason */ - "", /* 10 match method */ - "", /* 11 regex */ - NULL, + me.name, /* 0 server.name */ + NULL, /* 1 +|- */ + "F", /* 2 F */ + NULL, /* 3 usermask (targets) */ + NULL, /* 4 hostmask (action) */ + NULL, /* 5 set_by */ + "0", /* 6 expire_at */ + "0", /* 7 set_at */ + "", /* 8 tkl time */ + "", /* 9 tkl reason */ + "", /* 10 match method */ + "", /* 11 regex */ + NULL, }; int targets = 0, action = 0; char targetbuf[64], actionbuf[2]; @@ -2825,7 +2792,7 @@ CMD_FUNC(cmd_spamfilter) if (IsServer(client)) return; - if (!ValidatePermissionsForPath("server-ban:spamfilter",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server-ban:spamfilter", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -2861,7 +2828,7 @@ CMD_FUNC(cmd_spamfilter) if ((parc == 7) && (*parv[2] != '-')) { - spamfilter_new_usage(client,parv); + spamfilter_new_usage(client, parv); return; } @@ -2890,14 +2857,14 @@ CMD_FUNC(cmd_spamfilter) return; } - if (add && !strcasecmp(parv[2]+1, "posix")) + if (add && !strcasecmp(parv[2] + 1, "posix")) { sendnotice(client, "ERROR: Spamfilter type 'posix' is DEPRECATED. You must use type 'regex' instead."); sendnotice(client, "See https://www.unrealircd.org/docs/FAQ#spamfilter-posix-deprecated"); return; } - match_type = unreal_match_method_strtoval(parv[2]+1); + match_type = unreal_match_method_strtoval(parv[2] + 1); if (!match_type) { spamfilter_new_usage(client, parv); @@ -2944,8 +2911,7 @@ CMD_FUNC(cmd_spamfilter) { ircsnprintf(mo, sizeof(mo), "%lld", (long long)SPAMFILTER_BAN_TIME); tkllayer[8] = mo; - } - else + } else tkllayer[8] = parv[5]; if (parv[6][0] == '-') @@ -2954,7 +2920,7 @@ CMD_FUNC(cmd_spamfilter) strlcpy(reason, parv[6], sizeof(reason)); tkllayer[9] = reason; - tkllayer[10] = parv[2]+1; /* +1 to skip the '-' */ + tkllayer[10] = parv[2] + 1; /* +1 to skip the '-' */ tkllayer[11] = parv[7]; /* SPAMFILTER LENGTH CHECK. @@ -2969,7 +2935,8 @@ CMD_FUNC(cmd_spamfilter) if ((n > 500) && add) { sendnotice(client, "Sorry, spamfilter too long. You'll either have to trim down the " - "reason or the regex (exceeded by %d bytes)", n - 500); + "reason or the regex (exceeded by %d bytes)", + n - 500); return; } @@ -2992,17 +2959,18 @@ int _tkl_hash(unsigned int c) { #ifdef DEBUGMODE if ((c >= 'a') && (c <= 'z')) - return c-'a'; + return c - 'a'; else if ((c >= 'A') && (c <= 'Z')) - return c-'A'; - else { + return c - 'A'; + else + { unreal_log(ULOG_ERROR, "bug", "TKL_HASH_INVALID", NULL, "tkl_hash() called with out of range parameter (c = '$tkl_char') !!!", log_data_char("tkl_char", c)); return 0; } #else - return (isupper(c) ? c-'A' : c-'a'); + return (isupper(c) ? c - 'A' : c - 'a'); #endif } @@ -3012,7 +2980,7 @@ int _tkl_hash(unsigned int c) char _tkl_typetochar(int type) { int i; - for (i=0; tkl_types[i].config_name; i++) + for (i = 0; tkl_types[i].config_name; i++) if ((tkl_types[i].type == type) && tkl_types[i].tkltype) return tkl_types[i].letter; unreal_log(ULOG_ERROR, "bug", "TKL_TYPETOCHAR_INVALID", NULL, @@ -3027,7 +2995,7 @@ char _tkl_typetochar(int type) int _tkl_chartotype(char c) { int i; - for (i=0; tkl_types[i].config_name; i++) + for (i = 0; tkl_types[i].config_name; i++) if ((tkl_types[i].letter == c) && tkl_types[i].tkltype) return tkl_types[i].type; return 0; @@ -3036,7 +3004,7 @@ int _tkl_chartotype(char c) char _tkl_configtypetochar(const char *name) { int i; - for (i=0; tkl_types[i].config_name; i++) + for (i = 0; tkl_types[i].config_name; i++) if (!strcmp(tkl_types[i].config_name, name)) return tkl_types[i].letter; return 0; @@ -3045,7 +3013,7 @@ char _tkl_configtypetochar(const char *name) int tkl_banexception_chartotype(char c) { int i; - for (i=0; tkl_types[i].config_name; i++) + for (i = 0; tkl_types[i].config_name; i++) if ((tkl_types[i].letter == c) && tkl_types[i].exceptiontype) return tkl_types[i].type; return 0; @@ -3060,7 +3028,7 @@ char *tkl_banexception_configname_to_chars(char *name) { /* 'all' means everything except qline: */ char *p = buf; - for (i=0; tkl_types[i].config_name; i++) + for (i = 0; tkl_types[i].config_name; i++) { if (tkl_types[i].exceptiontype && !(tkl_types[i].type & TKL_NAME)) *p++ = tkl_types[i].letter; @@ -3069,7 +3037,7 @@ char *tkl_banexception_configname_to_chars(char *name) return buf; } - for (i=0; tkl_types[i].config_name; i++) + for (i = 0; tkl_types[i].config_name; i++) { if (!strcasecmp(name, tkl_types[i].config_name) && tkl_types[i].exceptiontype) { @@ -3092,7 +3060,7 @@ const char *_tkl_type_string(TKL *tkl) if (TKLIsServerBan(tkl) && (tkl->ptr.serverban->subtype == TKL_SUBTYPE_SOFT)) strlcpy(txt, "Soft ", sizeof(txt)); - for (i=0; tkl_types[i].config_name; i++) + for (i = 0; tkl_types[i].config_name; i++) { if ((tkl_types[i].type == tkl->type) && tkl_types[i].tkltype) { @@ -3110,7 +3078,7 @@ const char *_tkl_type_config_string(TKL *tkl) { int i; - for (i=0; tkl_types[i].config_name; i++) + for (i = 0; tkl_types[i].config_name; i++) if ((tkl_types[i].type == tkl->type) && tkl_types[i].tkltype) return tkl_types[i].config_name; @@ -3137,7 +3105,8 @@ int tkl_banexception_matches_type(TKL *except, int bantype) extype &= ~TKL_GLOBAL; if (bantype & extype) return 1; - } else { + } else + { /* Rest requires an exact match */ if (bantype == extype) return 1; @@ -3166,21 +3135,20 @@ int _tkl_ip_hash(const char *ip) /* IPv4 */ unsigned int v = (ipbuf[0] << 24) + (ipbuf[1] << 16) + - (ipbuf[2] << 8) + + (ipbuf[2] << 8) + ipbuf[3]; return v % TKLIPHASHLEN2; - } else - if (inet_pton(AF_INET6, ip, &ipbuf) == 1) + } else if (inet_pton(AF_INET6, ip, &ipbuf) == 1) { /* IPv6 (only upper 64 bits) */ unsigned int v1 = (ipbuf[0] << 24) + - (ipbuf[1] << 16) + - (ipbuf[2] << 8) + - ipbuf[3]; + (ipbuf[1] << 16) + + (ipbuf[2] << 8) + + ipbuf[3]; unsigned int v2 = (ipbuf[4] << 24) + - (ipbuf[5] << 16) + - (ipbuf[6] << 8) + - ipbuf[7]; + (ipbuf[5] << 16) + + (ipbuf[6] << 8) + + ipbuf[7]; return (v1 ^ v2) % TKLIPHASHLEN2; } else { @@ -3380,7 +3348,8 @@ TKL *_tkl_add_serverban(int type, const char *usermask, const char *hostmask, Se if (match) { tkl->ptr.serverban->match = match; - } else { + } else + { safe_strdup(tkl->ptr.serverban->usermask, usermask); safe_strdup(tkl->ptr.serverban->hostmask, hostmask); /* For ip hash table TKL's... */ @@ -3485,7 +3454,7 @@ TKL *_tkl_add_banexception(int type, const char *usermask, const char *hostmask, * qlines or exempts, which have their own function! */ TKL *_tkl_add_nameban(int type, const char *name, int hold, const char *reason, const char *set_by, - time_t expire_at, time_t set_at, int flags) + time_t expire_at, time_t set_at, int flags) { TKL *tkl; int index; @@ -3531,14 +3500,12 @@ void _free_tkl(TKL *tkl) safe_free(tkl->ptr.serverban->reason); safe_free_security_group(tkl->ptr.serverban->match); safe_free(tkl->ptr.serverban); - } else - if (TKLIsNameBan(tkl) && tkl->ptr.nameban) + } else if (TKLIsNameBan(tkl) && tkl->ptr.nameban) { safe_free(tkl->ptr.nameban->name); safe_free(tkl->ptr.nameban->reason); safe_free(tkl->ptr.nameban); - } else - if (TKLIsSpamfilter(tkl) && tkl->ptr.spamfilter) + } else if (TKLIsSpamfilter(tkl) && tkl->ptr.spamfilter) { /* Spamfilter */ safe_free(tkl->ptr.spamfilter->tkl_reason); @@ -3550,8 +3517,7 @@ void _free_tkl(TKL *tkl) safe_free(tkl->ptr.spamfilter->id); safe_free_security_group(tkl->ptr.spamfilter->except); safe_free(tkl->ptr.spamfilter); - } else - if (TKLIsBanException(tkl) && tkl->ptr.banexception) + } else if (TKLIsBanException(tkl) && tkl->ptr.banexception) { safe_free(tkl->ptr.banexception->usermask); safe_free(tkl->ptr.banexception->hostmask); @@ -3818,51 +3784,47 @@ void _tkl_check_local_remove_shun(TKL *tmp) for (i = 0; i <= 5; i++) { - list_for_each_entry(client, &lclient_list, lclient_node) - if (MyUser(client) && IsShunned(client)) + list_for_each_entry(client, &lclient_list, lclient_node) if (MyUser(client) && IsShunned(client)) + { + chost = client->local->sockhost; + cname = client->user->username; + + cip = GetIP(client); + + if ((*tmp->ptr.serverban->hostmask >= '0') && (*tmp->ptr.serverban->hostmask <= '9')) + is_ip = 1; + else + is_ip = 0; + + if (is_ip == 0 ? (match_simple(tmp->ptr.serverban->hostmask, chost) && match_simple(tmp->ptr.serverban->usermask, cname)) : (match_simple(tmp->ptr.serverban->hostmask, chost) || match_simple(tmp->ptr.serverban->hostmask, cip)) && match_simple(tmp->ptr.serverban->usermask, cname)) { - chost = client->local->sockhost; - cname = client->user->username; - - cip = GetIP(client); - - if ((*tmp->ptr.serverban->hostmask >= '0') && (*tmp->ptr.serverban->hostmask <= '9')) - is_ip = 1; - else - is_ip = 0; - - if (is_ip == 0 ? - (match_simple(tmp->ptr.serverban->hostmask, chost) && match_simple(tmp->ptr.serverban->usermask, cname)) : - (match_simple(tmp->ptr.serverban->hostmask, chost) || match_simple(tmp->ptr.serverban->hostmask, cip)) - && match_simple(tmp->ptr.serverban->usermask, cname)) - { - /* + /* before blindly marking this user as un-shunned, we need to check if the user is under any other existing shuns. (#0003906) Unfortunately, this requires crazy amounts of indentation ;-). This enumeration code is based off of _tkl_stats() */ - keep_shun = 0; - for(tk = tklines[tkl_hash('s')]; tk && !keep_shun; tk = tk->next) - if (tk != tmp && match_simple(tk->ptr.serverban->usermask, cname)) - { - if ((*tk->ptr.serverban->hostmask >= '0') && (*tk->ptr.serverban->hostmask <= '9') - /* the hostmask is an IP */ - && (match_simple(tk->ptr.serverban->hostmask, chost) || match_simple(tk->ptr.serverban->hostmask, cip))) - keep_shun = 1; - else - /* the hostmask is not an IP */ - if (match_simple(tk->ptr.serverban->hostmask, chost) && match_simple(tk->ptr.serverban->usermask, cname)) - keep_shun = 1; - } - - if (!keep_shun) + keep_shun = 0; + for (tk = tklines[tkl_hash('s')]; tk && !keep_shun; tk = tk->next) + if (tk != tmp && match_simple(tk->ptr.serverban->usermask, cname)) { - ClearShunned(client); + if ((*tk->ptr.serverban->hostmask >= '0') && (*tk->ptr.serverban->hostmask <= '9') + /* the hostmask is an IP */ + && (match_simple(tk->ptr.serverban->hostmask, chost) || match_simple(tk->ptr.serverban->hostmask, cip))) + keep_shun = 1; + else + /* the hostmask is not an IP */ + if (match_simple(tk->ptr.serverban->hostmask, chost) && match_simple(tk->ptr.serverban->usermask, cname)) + keep_shun = 1; } + + if (!keep_shun) + { + ClearShunned(client); } } + } } } @@ -3870,7 +3832,7 @@ void _tkl_check_local_remove_shun(TKL *tmp) /** This returns something like user@host, or %user@host, or ~a:Trusted * that can be used in oper notices like expiring kline, added kline, etc. */ -#define NO_SOFT_PREFIX 1 +#define NO_SOFT_PREFIX 1 char *_tkl_uhost(TKL *tkl, char *buf, size_t buflen, int options) { if (TKLIsServerBan(tkl)) @@ -3878,33 +3840,32 @@ char *_tkl_uhost(TKL *tkl, char *buf, size_t buflen, int options) if (tkl->ptr.serverban->match) { ircsnprintf(buf, buflen, ""); - } else - if (is_extended_server_ban(tkl->ptr.serverban->usermask)) + } else if (is_extended_server_ban(tkl->ptr.serverban->usermask)) { ircsnprintf(buf, buflen, "%s%s%s", - (!(options & NO_SOFT_PREFIX) && (tkl->ptr.serverban->subtype & TKL_SUBTYPE_SOFT)) ? "%" : "", - tkl->ptr.serverban->usermask, tkl->ptr.serverban->hostmask); - } else { + (!(options & NO_SOFT_PREFIX) && (tkl->ptr.serverban->subtype & TKL_SUBTYPE_SOFT)) ? "%" : "", + tkl->ptr.serverban->usermask, tkl->ptr.serverban->hostmask); + } else + { ircsnprintf(buf, buflen, "%s%s@%s", - (!(options & NO_SOFT_PREFIX) && (tkl->ptr.serverban->subtype & TKL_SUBTYPE_SOFT)) ? "%" : "", - tkl->ptr.serverban->usermask, tkl->ptr.serverban->hostmask); + (!(options & NO_SOFT_PREFIX) && (tkl->ptr.serverban->subtype & TKL_SUBTYPE_SOFT)) ? "%" : "", + tkl->ptr.serverban->usermask, tkl->ptr.serverban->hostmask); } - } else - if (TKLIsBanException(tkl)) + } else if (TKLIsBanException(tkl)) { if (tkl->ptr.banexception->match) { ircsnprintf(buf, buflen, ""); - } else - if (is_extended_server_ban(tkl->ptr.banexception->usermask)) + } else if (is_extended_server_ban(tkl->ptr.banexception->usermask)) { ircsnprintf(buf, buflen, "%s%s%s", - (!(options & NO_SOFT_PREFIX) && (tkl->ptr.banexception->subtype & TKL_SUBTYPE_SOFT)) ? "%" : "", - tkl->ptr.banexception->usermask, tkl->ptr.banexception->hostmask); - } else { + (!(options & NO_SOFT_PREFIX) && (tkl->ptr.banexception->subtype & TKL_SUBTYPE_SOFT)) ? "%" : "", + tkl->ptr.banexception->usermask, tkl->ptr.banexception->hostmask); + } else + { ircsnprintf(buf, buflen, "%s%s@%s", - (!(options & NO_SOFT_PREFIX) && (tkl->ptr.banexception->subtype & TKL_SUBTYPE_SOFT)) ? "%" : "", - tkl->ptr.banexception->usermask, tkl->ptr.banexception->hostmask); + (!(options & NO_SOFT_PREFIX) && (tkl->ptr.banexception->subtype & TKL_SUBTYPE_SOFT)) ? "%" : "", + tkl->ptr.banexception->usermask, tkl->ptr.banexception->hostmask); } } else abort(); @@ -3924,23 +3885,21 @@ void tkl_expire_entry(TKL *tkl) log_data_tkl("tkl", tkl), log_data_optional_name_value("id", "id", tkl->id), log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->spamfilter_id)); - } - else if (TKLIsNameBan(tkl)) + } else if (TKLIsNameBan(tkl)) { if (!tkl->ptr.nameban->hold) { unreal_log(ULOG_INFO, "tkl", "TKL_EXPIRE", NULL, "Expiring $tkl.type_string '$tkl' [reason: $tkl.reason] [by: $tkl.set_by] [duration: $tkl.duration_string] $id", - log_data_tkl("tkl", tkl), - log_data_optional_name_value("id", "id", tkl->id)); + log_data_tkl("tkl", tkl), + log_data_optional_name_value("id", "id", tkl->id)); } - } - else if (TKLIsBanException(tkl)) + } else if (TKLIsBanException(tkl)) { unreal_log(ULOG_INFO, "tkl", "TKL_EXPIRE", NULL, - "Expiring $tkl.type_string '$tkl' [type: $tkl.exception_types] [reason: $tkl.reason] [by: $tkl.set_by] [duration: $tkl.duration_string] $id", - log_data_tkl("tkl", tkl), - log_data_optional_name_value("id", "id", tkl->id)); + "Expiring $tkl.type_string '$tkl' [type: $tkl.exception_types] [reason: $tkl.reason] [by: $tkl.set_by] [duration: $tkl.duration_string] $id", + log_data_tkl("tkl", tkl), + log_data_optional_name_value("id", "id", tkl->id)); } // FIXME: so.. this isn't logged? or what? @@ -3993,7 +3952,7 @@ EVENT(tkl_check_expire) /* This is just a helper function for find_tkl_exception() */ static int find_tkl_exception_matcher(Client *client, int ban_type, TKL *except_tkl) { - char uhost[NICKLEN+HOSTLEN+1]; + char uhost[NICKLEN + HOSTLEN + 1]; if (!TKLIsBanException(except_tkl)) return 0; @@ -4053,8 +4012,8 @@ int _find_tkl_exception(int ban_type, Client *client) /* If not banned (yet), then check regular entries.. */ for (tkl = tklines[tkl_hash('e')]; tkl; tkl = tkl->next) { - if (find_tkl_exception_matcher(client, ban_type, tkl)) - return 1; /* exempt */ + if (find_tkl_exception_matcher(client, ban_type, tkl)) + return 1; /* exempt */ } for (hook = Hooks[HOOKTYPE_TKL_EXCEPT]; hook; hook = hook->next) @@ -4068,7 +4027,7 @@ int _find_tkl_exception(int ban_type, Client *client) /** Helper function for find_tkline_match() */ int find_tkline_match_matcher(Client *client, int skip_soft, TKL *tkl) { - char uhost[NICKLEN+HOSTLEN+1]; + char uhost[NICKLEN + HOSTLEN + 1]; if (!TKLIsServerBan(tkl) || (tkl->type & TKL_SHUN)) return 0; @@ -4163,7 +4122,7 @@ int _find_tkline_match(Client *client, int skip_soft) /* User is banned... */ - RunHookReturnInt(HOOKTYPE_FIND_TKLINE_MATCH, !=99, client, tkl); + RunHookReturnInt(HOOKTYPE_FIND_TKLINE_MATCH, != 99, client, tkl); if (tkl->type & TKL_KILL) { @@ -4174,12 +4133,11 @@ int _find_tkline_match(Client *client, int skip_soft) else banned_client(client, "K-Lined", tkl->ptr.serverban->reason, tkl->id, 0, 0); return 1; /* killed */ - } else - if (tkl->type & TKL_ZAP) + } else if (tkl->type & TKL_ZAP) { ircstats.is_ref++; tkl_hit(client, tkl); - banned_client(client, "Z-Lined", tkl->ptr.serverban->reason, tkl->id, (tkl->type & TKL_GLOBAL)?1:0, 0); + banned_client(client, "Z-Lined", tkl->ptr.serverban->reason, tkl->id, (tkl->type & TKL_GLOBAL) ? 1 : 0, 0); return 1; /* killed */ } @@ -4200,12 +4158,12 @@ int _find_shun(Client *client) if (IsShunned(client)) return 1; - if (ValidatePermissionsForPath("immune:server-ban:shun",client,NULL,NULL,NULL)) + if (ValidatePermissionsForPath("immune:server-ban:shun", client, NULL, NULL, NULL)) return 0; for (tkl = tklines[tkl_hash('s')]; tkl; tkl = tkl->next) { - char uhost[NICKLEN+HOSTLEN+1]; + char uhost[NICKLEN + HOSTLEN + 1]; if (!(tkl->type & TKL_SHUN)) continue; @@ -4254,8 +4212,8 @@ char *SpamfilterMagicHost(char *i) */ void _spamfilter_build_user_string(char *buf, const char *nick, Client *client) { - snprintf(buf, NICKLEN+USERLEN+HOSTLEN+REALLEN+1, "%s!%s@%s:%s", - nick, client->user->username, SpamfilterMagicHost(client->user->realhost), client->info); + snprintf(buf, NICKLEN + USERLEN + HOSTLEN + REALLEN + 1, "%s!%s@%s:%s", + nick, client->user->username, SpamfilterMagicHost(client->user->realhost), client->info); } @@ -4269,7 +4227,7 @@ int _find_spamfilter_user(Client *client, int flags) { char spamfilter_user[NICKLEN + USERLEN + HOSTLEN + REALLEN + 64]; /* n!u@h:r */ - if (ValidatePermissionsForPath("immune:server-ban:spamfilter",client,NULL,NULL,NULL)) + if (ValidatePermissionsForPath("immune:server-ban:spamfilter", client, NULL, NULL, NULL)) return 0; spamfilter_build_user_string(spamfilter_user, client->name, client); @@ -4303,10 +4261,10 @@ int spamfilter_check_users(TKL *tkl) /* matched! */ unreal_log(ULOG_INFO, "tkl", "SPAMFILTER_MATCH", client, "[Spamfilter] $client.details matches filter '$tkl': [cmd: $command: '$str'] [reason: $tkl.reason] [action: $tkl.ban_action] $spamfilter_id", - log_data_tkl("tkl", tkl), - log_data_string("command", "USER"), - log_data_string("str", spamfilter_user), - log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->id)); + log_data_tkl("tkl", tkl), + log_data_string("command", "USER"), + log_data_string("str", spamfilter_user), + log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->id)); RunHook(HOOKTYPE_LOCAL_SPAMFILTER, client, spamfilter_user, spamfilter_user, SPAMF_USER, NULL, tkl); matches++; @@ -4328,7 +4286,7 @@ int spamfilter_check_users(TKL *tkl) TKL *_find_qline(Client *client, const char *name, int *ishold) { TKL *tkl; - int points = 0; + int points = 0; *ishold = 0; if (IsServer(client) || IsMe(client)) @@ -4341,8 +4299,7 @@ TKL *_find_qline(Client *client, const char *name, int *ishold) if (!TKLIsNameBan(tkl)) continue; - if (((*tkl->ptr.nameban->name == '#' && *name == '#') || (*tkl->ptr.nameban->name != '#' && *name != '#')) - && match_simple(tkl->ptr.nameban->name, name)) + if (((*tkl->ptr.nameban->name == '#' && *name == '#') || (*tkl->ptr.nameban->name != '#' && *name != '#')) && match_simple(tkl->ptr.nameban->name, name)) { points = 1; break; @@ -4417,14 +4374,14 @@ TKL *_find_tkline_match_zap(Client *client) return NULL; } -#define BY_MASK 0x1 -#define BY_REASON 0x2 -#define NOT_BY_MASK 0x4 +#define BY_MASK 0x1 +#define BY_REASON 0x2 +#define NOT_BY_MASK 0x4 #define NOT_BY_REASON 0x8 -#define BY_SETBY 0x10 -#define NOT_BY_SETBY 0x20 -#define BY_ID 0x40 -#define NOT_BY_ID 0x80 +#define BY_SETBY 0x10 +#define NOT_BY_SETBY 0x20 +#define BY_ID 0x40 +#define NOT_BY_ID 0x80 typedef struct { int flags; @@ -4541,8 +4498,7 @@ int tkl_stats_matcher(Client *client, int type, const char *para, TKLFlag *tklfl if (tklflags->flags & NOT_BY_REASON) if (match_simple(tklflags->reason, tkl->ptr.serverban->reason)) return 0; - } else - if (TKLIsNameBan(tkl)) + } else if (TKLIsNameBan(tkl)) { if (tklflags->flags & BY_MASK) { @@ -4560,8 +4516,7 @@ int tkl_stats_matcher(Client *client, int type, const char *para, TKLFlag *tklfl if (tklflags->flags & NOT_BY_REASON) if (match_simple(tklflags->reason, tkl->ptr.nameban->reason)) return 0; - } else - if (TKLIsBanException(tkl)) + } else if (TKLIsBanException(tkl)) { if (tklflags->flags & BY_MASK) { @@ -4592,63 +4547,58 @@ int tkl_stats_matcher(Client *client, int type, const char *para, TKLFlag *tklfl for (m = tkl->ptr.serverban->match->printable_list; m; m = m->next) { sendnumeric(client, RPL_STATSGLINE, 'K', namevalue_nospaces(m), - (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, - (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); - + (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, + (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); } - } else { + } else + { char uhostbuf[BUFSIZE]; char *uhost = tkl_uhost(tkl, uhostbuf, sizeof(uhostbuf), 0); if (tkl->type == (TKL_KILL | TKL_GLOBAL)) { sendnumeric(client, RPL_STATSGLINE, 'G', uhost, - (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, - (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); - } else - if (tkl->type == (TKL_ZAP | TKL_GLOBAL)) + (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, + (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); + } else if (tkl->type == (TKL_ZAP | TKL_GLOBAL)) { sendnumeric(client, RPL_STATSGLINE, 'Z', uhost, - (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, - (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); - } else - if (tkl->type == (TKL_SHUN | TKL_GLOBAL)) + (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, + (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); + } else if (tkl->type == (TKL_SHUN | TKL_GLOBAL)) { sendnumeric(client, RPL_STATSGLINE, 's', uhost, - (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, - (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); - } else - if (tkl->type == (TKL_KILL)) + (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, + (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); + } else if (tkl->type == (TKL_KILL)) { sendnumeric(client, RPL_STATSGLINE, 'K', uhost, - (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, - (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); - } else - if (tkl->type == (TKL_ZAP)) + (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, + (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); + } else if (tkl->type == (TKL_ZAP)) { sendnumeric(client, RPL_STATSGLINE, 'z', uhost, - (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, - (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); + (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, + (long long)(TStime() - tkl->set_at), tkl->set_by, tkl->hits, (long long)tkl->lasthit, spamfilter_id_str, id_str, tkl->ptr.serverban->reason); } } - } else - if (TKLIsSpamfilter(tkl)) + } else if (TKLIsSpamfilter(tkl)) { sendnumeric(client, RPL_STATSSPAMF, - (tkl->type & TKL_GLOBAL) ? 'F' : 'f', - unreal_match_method_valtostr(tkl->ptr.spamfilter->match->type), - spamfilter_target_inttostring(tkl->ptr.spamfilter->target), - ban_actions_to_string(tkl->ptr.spamfilter->action), - (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, - (long long)(TStime() - tkl->set_at), - (long long)tkl->ptr.spamfilter->tkl_duration, - tkl->ptr.spamfilter->tkl_reason, - tkl->set_by, - tkl->hits, - tkl->ptr.spamfilter->hits_except, - (long long)tkl->lasthit, - (long long)tkl->ptr.spamfilter->lasthit_except, - id_str, - tkl->ptr.spamfilter->match->str); + (tkl->type & TKL_GLOBAL) ? 'F' : 'f', + unreal_match_method_valtostr(tkl->ptr.spamfilter->match->type), + spamfilter_target_inttostring(tkl->ptr.spamfilter->target), + ban_actions_to_string(tkl->ptr.spamfilter->action), + (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, + (long long)(TStime() - tkl->set_at), + (long long)tkl->ptr.spamfilter->tkl_duration, + tkl->ptr.spamfilter->tkl_reason, + tkl->set_by, + tkl->hits, + tkl->ptr.spamfilter->hits_except, + (long long)tkl->lasthit, + (long long)tkl->ptr.spamfilter->lasthit_except, + id_str, + tkl->ptr.spamfilter->match->str); if (para && !strcasecmp(para, "del")) { if (!(tkl->type & TKL_GLOBAL)) @@ -4657,8 +4607,7 @@ int tkl_stats_matcher(Client *client, int type, const char *para, TKLFlag *tklfl sendtxtnumeric(client, "To delete this spamfilter, use /SPAMFILTER del %s", tkl->id[0] ? tkl->id : spamfilter_fallback_id(tkl)); sendtxtnumeric(client, "-"); } - } else - if (TKLIsNameBan(tkl)) + } else if (TKLIsNameBan(tkl)) { sendnumeric(client, RPL_STATSQLINE, (tkl->type & TKL_GLOBAL) ? 'Q' : 'q', @@ -4670,8 +4619,7 @@ int tkl_stats_matcher(Client *client, int type, const char *para, TKLFlag *tklfl (long long)tkl->lasthit, id_str, tkl->ptr.nameban->reason); - } else - if (TKLIsBanException(tkl)) + } else if (TKLIsBanException(tkl)) { if (tkl->ptr.banexception->match) { @@ -4680,18 +4628,19 @@ int tkl_stats_matcher(Client *client, int type, const char *para, TKLFlag *tklfl for (m = tkl->ptr.banexception->match->printable_list; m; m = m->next) { sendnumeric(client, RPL_STATSEXCEPTTKL, namevalue_nospaces(m), - tkl->ptr.banexception->bantypes, - (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, - (long long)(TStime() - tkl->set_at), tkl->set_by, id_str, tkl->ptr.banexception->reason); + tkl->ptr.banexception->bantypes, + (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, + (long long)(TStime() - tkl->set_at), tkl->set_by, id_str, tkl->ptr.banexception->reason); } - } else { + } else + { /* IRC-added: uses simple user/host mask */ char uhostbuf[BUFSIZE]; char *uhost = tkl_uhost(tkl, uhostbuf, sizeof(uhostbuf), 0); sendnumeric(client, RPL_STATSEXCEPTTKL, uhost, - tkl->ptr.banexception->bantypes, - (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, - (long long)(TStime() - tkl->set_at), tkl->set_by, id_str, tkl->ptr.banexception->reason); + tkl->ptr.banexception->bantypes, + (tkl->expire_at != 0) ? (long long)(tkl->expire_at - TStime()) : 0, + (long long)(TStime() - tkl->set_at), tkl->set_by, id_str, tkl->ptr.banexception->reason); } } else { @@ -4758,7 +4707,7 @@ void _tkl_stats(Client *client, int type, const char *para, int *cnt) } } - if ((type == (TKL_SPAMF|TKL_GLOBAL)) && (!para || strcasecmp(para, "del"))) + if ((type == (TKL_SPAMF | TKL_GLOBAL)) && (!para || strcasecmp(para, "del"))) { /* If requesting spamfilter stats and not spamfilter del, then suggest it. */ sendnotice(client, "Tip: if you are looking for an easy way to remove a spamfilter, run '/SPAMFILTER del'."); @@ -4787,55 +4736,52 @@ void tkl_sync_send_entry(int add, Client *sender, Client *to, TKL *tkl) if (TKLIsServerBan(tkl)) { sendto_one(to, mtags, ":%s TKL %c %c %s%s %s %s %lld %lld :%s", sender->name, - add ? '+' : '-', - typ, - (tkl->ptr.serverban->subtype & TKL_SUBTYPE_SOFT) ? "%" : "", - *tkl->ptr.serverban->usermask ? tkl->ptr.serverban->usermask : "*", - tkl->ptr.serverban->hostmask, tkl->set_by, - (long long)tkl->expire_at, (long long)tkl->set_at, - tkl->ptr.serverban->reason); - } else - if (TKLIsNameBan(tkl)) + add ? '+' : '-', + typ, + (tkl->ptr.serverban->subtype & TKL_SUBTYPE_SOFT) ? "%" : "", + *tkl->ptr.serverban->usermask ? tkl->ptr.serverban->usermask : "*", + tkl->ptr.serverban->hostmask, tkl->set_by, + (long long)tkl->expire_at, (long long)tkl->set_at, + tkl->ptr.serverban->reason); + } else if (TKLIsNameBan(tkl)) { sendto_one(to, mtags, ":%s TKL %c %c %c %s %s %lld %lld :%s", sender->name, - add ? '+' : '-', - typ, - tkl->ptr.nameban->hold ? 'H' : '*', - tkl->ptr.nameban->name, - tkl->set_by, - (long long)tkl->expire_at, (long long)tkl->set_at, - tkl->ptr.nameban->reason); - } else - if (TKLIsSpamfilter(tkl)) + add ? '+' : '-', + typ, + tkl->ptr.nameban->hold ? 'H' : '*', + tkl->ptr.nameban->name, + tkl->set_by, + (long long)tkl->expire_at, (long long)tkl->set_at, + tkl->ptr.nameban->reason); + } else if (TKLIsSpamfilter(tkl)) { sendto_one(to, mtags, ":%s TKL %c %c %s %c %s %lld %lld %lld %s %s :%s", sender->name, - add ? '+' : '-', - typ, - spamfilter_target_inttostring(tkl->ptr.spamfilter->target), - banact_valtochar(tkl->ptr.spamfilter->action->action), - tkl->set_by, - (long long)tkl->expire_at, (long long)tkl->set_at, - (long long)tkl->ptr.spamfilter->tkl_duration, tkl->ptr.spamfilter->tkl_reason, - unreal_match_method_valtostr(tkl->ptr.spamfilter->match->type), - tkl->ptr.spamfilter->match->str); - } else - if (TKLIsBanException(tkl)) + add ? '+' : '-', + typ, + spamfilter_target_inttostring(tkl->ptr.spamfilter->target), + banact_valtochar(tkl->ptr.spamfilter->action->action), + tkl->set_by, + (long long)tkl->expire_at, (long long)tkl->set_at, + (long long)tkl->ptr.spamfilter->tkl_duration, tkl->ptr.spamfilter->tkl_reason, + unreal_match_method_valtostr(tkl->ptr.spamfilter->match->type), + tkl->ptr.spamfilter->match->str); + } else if (TKLIsBanException(tkl)) { sendto_one(to, mtags, ":%s TKL %c %c %s%s %s %s %lld %lld %s :%s", sender->name, - add ? '+' : '-', - typ, - (tkl->ptr.banexception->subtype & TKL_SUBTYPE_SOFT) ? "%" : "", - *tkl->ptr.banexception->usermask ? tkl->ptr.banexception->usermask : "*", - tkl->ptr.banexception->hostmask, tkl->set_by, - (long long)tkl->expire_at, (long long)tkl->set_at, - tkl->ptr.banexception->bantypes, - tkl->ptr.banexception->reason); + add ? '+' : '-', + typ, + (tkl->ptr.banexception->subtype & TKL_SUBTYPE_SOFT) ? "%" : "", + *tkl->ptr.banexception->usermask ? tkl->ptr.banexception->usermask : "*", + tkl->ptr.banexception->hostmask, tkl->set_by, + (long long)tkl->expire_at, (long long)tkl->set_at, + tkl->ptr.banexception->bantypes, + tkl->ptr.banexception->reason); } else { unreal_log(ULOG_FATAL, "tkl", "BUG_TKL_SYNC_SEND_ENTRY", NULL, - "[BUG] tkl_sync_send_entry() called, but unknown type: $tkl.type_string ($tkl_type_int)", - log_data_tkl("tkl", tkl), - log_data_integer("tkl_type_int", typ)); + "[BUG] tkl_sync_send_entry() called, but unknown type: $tkl.type_string ($tkl_type_int)", + log_data_tkl("tkl", tkl), + log_data_integer("tkl_type_int", typ)); abort(); } @@ -4997,32 +4943,29 @@ void _sendnotice_tkl_add(TKL *tkl) if (TKLIsServerBan(tkl)) { unreal_log(ULOG_INFO, "tkl", "TKL_ADD", NULL, - "$tkl.type_string added: '$tkl' [reason: $tkl.reason] [by: $tkl.set_by] [duration: $tkl.duration_string] $id $spamfilter_id", - log_data_tkl("tkl", tkl), - log_data_optional_name_value("id", "id", tkl->id), - log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->spamfilter_id)); - } else - if (TKLIsNameBan(tkl)) + "$tkl.type_string added: '$tkl' [reason: $tkl.reason] [by: $tkl.set_by] [duration: $tkl.duration_string] $id $spamfilter_id", + log_data_tkl("tkl", tkl), + log_data_optional_name_value("id", "id", tkl->id), + log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->spamfilter_id)); + } else if (TKLIsNameBan(tkl)) { unreal_log(ULOG_INFO, "tkl", "TKL_ADD", NULL, - "$tkl.type_string added: '$tkl' [reason: $tkl.reason] [by: $tkl.set_by] [duration: $tkl.duration_string] $id", - log_data_tkl("tkl", tkl), - log_data_optional_name_value("id", "id", tkl->id)); - } else - if (TKLIsSpamfilter(tkl)) + "$tkl.type_string added: '$tkl' [reason: $tkl.reason] [by: $tkl.set_by] [duration: $tkl.duration_string] $id", + log_data_tkl("tkl", tkl), + log_data_optional_name_value("id", "id", tkl->id)); + } else if (TKLIsSpamfilter(tkl)) { unreal_log(ULOG_INFO, "tkl", "TKL_ADD", NULL, - "Spamfilter added: '$tkl' [type: $tkl.match_type] [targets: $tkl.spamfilter_targets] " - "[action: $tkl.ban_action] [reason: $tkl.reason] [by: $tkl.set_by] $id", - log_data_tkl("tkl", tkl), - log_data_optional_name_value("id", "id", tkl->id)); - } else - if (TKLIsBanException(tkl)) + "Spamfilter added: '$tkl' [type: $tkl.match_type] [targets: $tkl.spamfilter_targets] " + "[action: $tkl.ban_action] [reason: $tkl.reason] [by: $tkl.set_by] $id", + log_data_tkl("tkl", tkl), + log_data_optional_name_value("id", "id", tkl->id)); + } else if (TKLIsBanException(tkl)) { unreal_log(ULOG_INFO, "tkl", "TKL_ADD", NULL, - "$tkl.type_string added: '$tkl' [types: $tkl.exception_types] [by: $tkl.set_by] [duration: $tkl.duration_string] $id", - log_data_tkl("tkl", tkl), - log_data_optional_name_value("id", "id", tkl->id)); + "$tkl.type_string added: '$tkl' [types: $tkl.exception_types] [by: $tkl.set_by] [duration: $tkl.duration_string] $id", + log_data_tkl("tkl", tkl), + log_data_optional_name_value("id", "id", tkl->id)); } else { unreal_log(ULOG_ERROR, "tkl", "BUG_UNKNOWN_TKL", NULL, @@ -5040,36 +4983,33 @@ void _sendnotice_tkl_del(const char *removed_by, TKL *tkl) if (TKLIsServerBan(tkl)) { unreal_log(ULOG_INFO, "tkl", "TKL_DEL", NULL, - "$tkl.type_string removed: '$tkl' [reason: $tkl.reason] [by: $removed_by] [set at: $tkl.set_at_string] $id $spamfilter_id", - log_data_tkl("tkl", tkl), - log_data_string("removed_by", removed_by), - log_data_optional_name_value("id", "id", tkl->id), - log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->spamfilter_id)); - } else - if (TKLIsNameBan(tkl)) + "$tkl.type_string removed: '$tkl' [reason: $tkl.reason] [by: $removed_by] [set at: $tkl.set_at_string] $id $spamfilter_id", + log_data_tkl("tkl", tkl), + log_data_string("removed_by", removed_by), + log_data_optional_name_value("id", "id", tkl->id), + log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->spamfilter_id)); + } else if (TKLIsNameBan(tkl)) { unreal_log(ULOG_INFO, "tkl", "TKL_DEL", NULL, - "$tkl.type_string removed: '$tkl' [reason: $tkl.reason] [by: $removed_by] [set at: $tkl.set_at_string] $id", - log_data_tkl("tkl", tkl), - log_data_string("removed_by", removed_by), - log_data_optional_name_value("id", "id", tkl->id)); - } else - if (TKLIsSpamfilter(tkl)) + "$tkl.type_string removed: '$tkl' [reason: $tkl.reason] [by: $removed_by] [set at: $tkl.set_at_string] $id", + log_data_tkl("tkl", tkl), + log_data_string("removed_by", removed_by), + log_data_optional_name_value("id", "id", tkl->id)); + } else if (TKLIsSpamfilter(tkl)) { unreal_log(ULOG_INFO, "tkl", "TKL_DEL", NULL, - "Spamfilter removed: '$tkl' [type: $tkl.match_type] [targets: $tkl.spamfilter_targets] " - "[action: $tkl.ban_action] [reason: $tkl.reason] [by: $removed_by] [set at: $tkl.set_at_string] $id", - log_data_tkl("tkl", tkl), - log_data_string("removed_by", removed_by), - log_data_optional_name_value("id", "id", tkl->id)); - } else - if (TKLIsBanException(tkl)) + "Spamfilter removed: '$tkl' [type: $tkl.match_type] [targets: $tkl.spamfilter_targets] " + "[action: $tkl.ban_action] [reason: $tkl.reason] [by: $removed_by] [set at: $tkl.set_at_string] $id", + log_data_tkl("tkl", tkl), + log_data_string("removed_by", removed_by), + log_data_optional_name_value("id", "id", tkl->id)); + } else if (TKLIsBanException(tkl)) { unreal_log(ULOG_INFO, "tkl", "TKL_DEL", NULL, - "$tkl.type_string removed: '$tkl' [types: $tkl.exception_types] [by: $removed_by] [set at: $tkl.set_at_string] $id", - log_data_tkl("tkl", tkl), - log_data_string("removed_by", removed_by), - log_data_optional_name_value("id", "id", tkl->id)); + "$tkl.type_string removed: '$tkl' [types: $tkl.exception_types] [by: $removed_by] [set at: $tkl.set_at_string] $id", + log_data_tkl("tkl", tkl), + log_data_string("removed_by", removed_by), + log_data_optional_name_value("id", "id", tkl->id)); } else { unreal_log(ULOG_ERROR, "tkl", "BUG_UNKNOWN_TKL", NULL, @@ -5136,17 +5076,17 @@ CMD_FUNC(cmd_tkl_add) if ((set_at < 0) || !short_date(set_at, NULL)) { unreal_log(ULOG_WARNING, "tkl", "TKL_ADD_INVALID", client, - "Invalid TKL entry from $client: " - "The set-at time is out of range ($set_at). Clock on other server incorrect or bogus entry.", - log_data_integer("set_at", set_at)); + "Invalid TKL entry from $client: " + "The set-at time is out of range ($set_at). Clock on other server incorrect or bogus entry.", + log_data_integer("set_at", set_at)); return; } if ((expire_at < 0) || !short_date(expire_at, NULL)) { unreal_log(ULOG_WARNING, "tkl", "TKL_ADD_INVALID", client, - "Invalid TKL entry from $client: " - "The expire-at time is out of range ($expire_at). Clock on other server incorrect or bogus entry.", - log_data_integer("expire_at", expire_at)); + "Invalid TKL entry from $client: " + "The expire-at time is out of range ($expire_at). Clock on other server incorrect or bogus entry.", + log_data_integer("expire_at", expire_at)); return; } @@ -5169,10 +5109,10 @@ CMD_FUNC(cmd_tkl_add) if (strchr(usermask, '@') || strchr(hostmask, '@')) { unreal_log(ULOG_WARNING, "tkl", "TKL_ADD_INVALID", client, - "Invalid TKL entry from $client: " - "Invalid user@host $usermask@$hostmask", - log_data_string("usermask", usermask), - log_data_string("hostmask", hostmask)); + "Invalid TKL entry from $client: " + "Invalid user@host $usermask@$hostmask", + log_data_string("usermask", usermask), + log_data_string("hostmask", hostmask)); return; } @@ -5190,12 +5130,12 @@ CMD_FUNC(cmd_tkl_add) if (tkl) { tkl_entry_exists = 1; - } else { + } else + { tkl = tkl_add_serverban(type, usermask, hostmask, NULL, reason, set_by, expire_at, set_at, softban, 0); } - } else - if (TKLIsBanExceptionType(type)) + } else if (TKLIsBanExceptionType(type)) { /* Validate ban exception TKL fields */ int softban = 0; @@ -5216,10 +5156,10 @@ CMD_FUNC(cmd_tkl_add) if (strchr(usermask, '@') || strchr(hostmask, '@')) { unreal_log(ULOG_WARNING, "tkl", "TKL_ADD_INVALID", client, - "Invalid TKL entry from $client: " - "Invalid TKL except user@host $usermask@$hostmask", - log_data_string("usermask", usermask), - log_data_string("hostmask", hostmask)); + "Invalid TKL entry from $client: " + "Invalid TKL except user@host $usermask@$hostmask", + log_data_string("usermask", usermask), + log_data_string("hostmask", hostmask)); return; } @@ -5240,12 +5180,12 @@ CMD_FUNC(cmd_tkl_add) if (tkl) { tkl_entry_exists = 1; - } else { + } else + { tkl = tkl_add_banexception(type, usermask, hostmask, NULL, reason, set_by, expire_at, set_at, softban, bantypes, 0); } - } else - if (TKLIsNameBanType(type)) + } else if (TKLIsNameBanType(type)) { /* Validate name ban TKL fields */ int hold = 0; @@ -5259,12 +5199,12 @@ CMD_FUNC(cmd_tkl_add) if (tkl) { tkl_entry_exists = 1; - } else { + } else + { tkl = tkl_add_nameban(type, name, hold, reason, set_by, expire_at, set_at, 0); } - } else - if (TKLIsSpamfilterType(type)) + } else if (TKLIsSpamfilterType(type)) { /* Validate spamfilter-specific TKL fields */ MatchType match_method; @@ -5280,8 +5220,8 @@ CMD_FUNC(cmd_tkl_add) if (parc < 12) { unreal_log(ULOG_WARNING, "tkl", "TKL_ADD_INVALID", client, - "Invalid TKL entry from $client: " - "Spamfilter with too few parameters. Running very old UnrealIRCd protocol (3.2.X?)"); + "Invalid TKL entry from $client: " + "Spamfilter with too few parameters. Running very old UnrealIRCd protocol (3.2.X?)"); return; } @@ -5291,30 +5231,30 @@ CMD_FUNC(cmd_tkl_add) if (match_method == 0) { unreal_log(ULOG_WARNING, "tkl", "TKL_ADD_INVALID", client, - "Invalid TKL entry from $client: " - "Spamfilter '$spamfilter_string' has unknown match-type '$spamfilter_type'", - log_data_string("spamfilter_string", match_string), - log_data_string("spamfilter_type", parv[10])); + "Invalid TKL entry from $client: " + "Spamfilter '$spamfilter_string' has unknown match-type '$spamfilter_type'", + log_data_string("spamfilter_string", match_string), + log_data_string("spamfilter_type", parv[10])); return; } if (!(target = spamfilter_gettargets(parv[3], NULL))) { unreal_log(ULOG_WARNING, "tkl", "TKL_ADD_INVALID", client, - "Invalid TKL entry from $client: " - "Spamfilter '$spamfilter_string' has unknown targets '$spamfilter_targets'", - log_data_string("spamfilter_string", match_string), - log_data_string("spamfilter_targets", parv[3])); + "Invalid TKL entry from $client: " + "Spamfilter '$spamfilter_string' has unknown targets '$spamfilter_targets'", + log_data_string("spamfilter_string", match_string), + log_data_string("spamfilter_targets", parv[3])); return; } if (!(action = banact_chartoval(*parv[4])) || banact_config_only(action)) { unreal_log(ULOG_WARNING, "tkl", "TKL_ADD_INVALID", client, - "Invalid TKL entry from $client: " - "Spamfilter '$spamfilter_string' has unknown action '$spamfilter_action'", - log_data_string("spamfilter_string", match_string), - log_data_string("spamfilter_action", parv[4])); + "Invalid TKL entry from $client: " + "Spamfilter '$spamfilter_string' has unknown action '$spamfilter_action'", + log_data_string("spamfilter_string", match_string), + log_data_string("spamfilter_action", parv[4])); return; } @@ -5326,15 +5266,16 @@ CMD_FUNC(cmd_tkl_add) if (tkl) { tkl_entry_exists = 1; - } else { + } else + { m = unreal_create_match(match_method, match_string, &err); if (!m) { unreal_log(ULOG_WARNING, "tkl", "TKL_ADD_INVALID", client, - "Invalid TKL entry from $client: " - "Spamfilter '$spamfilter_string': regex does not compile: $spamfilter_regex_error", - log_data_string("spamfilter_string", match_string), - log_data_string("spamfilter_regex_error", err)); + "Invalid TKL entry from $client: " + "Spamfilter '$spamfilter_string': regex does not compile: $spamfilter_regex_error", + log_data_string("spamfilter_string", match_string), + log_data_string("spamfilter_regex_error", err)); return; } tkl = tkl_add_spamfilter(type, NULL, target, banact_value_to_struct(action), m, NULL, NULL, @@ -5453,8 +5394,7 @@ CMD_FUNC(cmd_tkl_del) } tkl = find_tkl_serverban(type, usermask, hostmask, softban); - } - else if (TKLIsBanExceptionType(type)) + } else if (TKLIsBanExceptionType(type)) { const char *usermask = parv[3]; const char *hostmask = parv[4]; @@ -5468,8 +5408,7 @@ CMD_FUNC(cmd_tkl_del) } tkl = find_tkl_banexception(type, usermask, hostmask, softban); - } - else if (TKLIsNameBanType(type)) + } else if (TKLIsNameBanType(type)) { int hold = 0; const char *name = parv[4]; @@ -5477,8 +5416,7 @@ CMD_FUNC(cmd_tkl_del) if (*parv[3] == 'H') hold = 1; tkl = find_tkl_nameban(type, name, hold); - } - else if (TKLIsSpamfilterType(type)) + } else if (TKLIsSpamfilterType(type)) { const char *match_string; unsigned short target; @@ -5487,8 +5425,8 @@ CMD_FUNC(cmd_tkl_del) if (parc < 9) { unreal_log(ULOG_WARNING, "tkl", "TKL_DEL_INVALID", client, - "Invalid TKL deletion request from $client: " - "Spamfilter with too few parameters. Running very old UnrealIRCd protocol (3.2.X?)"); + "Invalid TKL deletion request from $client: " + "Spamfilter with too few parameters. Running very old UnrealIRCd protocol (3.2.X?)"); return; /* bogus */ } if (parc >= 12) @@ -5501,20 +5439,20 @@ CMD_FUNC(cmd_tkl_del) if (!(target = spamfilter_gettargets(parv[3], NULL))) { unreal_log(ULOG_WARNING, "tkl", "TKL_DEL_INVALID", client, - "Invalid TKL deletion request from $client: " - "Spamfilter '$spamfilter_string' has unknown targets '$spamfilter_targets'", - log_data_string("spamfilter_string", match_string), - log_data_string("spamfilter_targets", parv[3])); + "Invalid TKL deletion request from $client: " + "Spamfilter '$spamfilter_string' has unknown targets '$spamfilter_targets'", + log_data_string("spamfilter_string", match_string), + log_data_string("spamfilter_targets", parv[3])); return; } if (!(action = banact_chartoval(*parv[4]))) { unreal_log(ULOG_WARNING, "tkl", "TKL_DEL_INVALID", client, - "Invalid TKL deletion request from $client: " - "Spamfilter '$spamfilter_string' has unknown action '$spamfilter_action'", - log_data_string("spamfilter_string", match_string), - log_data_string("spamfilter_action", parv[4])); + "Invalid TKL deletion request from $client: " + "Spamfilter '$spamfilter_string' has unknown action '$spamfilter_action'", + log_data_string("spamfilter_string", match_string), + log_data_string("spamfilter_action", parv[4])); return; } tkl = find_tkl_spamfilter(type, match_string, action, target); @@ -5614,8 +5552,8 @@ CMD_FUNC(_cmd_tkl) /** Configure the username/hostname TKL layer based on the BAN_TARGET_* configuration */ void ban_target_to_tkl_layer(BanTarget ban_target, BanActionValue action, Client *client, const char **tkl_username, const char **tkl_hostname) { - static char username[USERLEN+1]; - static char hostname[HOSTLEN+8]; + static char username[USERLEN + 1]; + static char hostname[HOSTLEN + 8]; if ((action == BAN_ACT_ZLINE) || (action == BAN_ACT_GZLINE)) ban_target = BAN_TARGET_IP; /* The only possible choice with ZLINE/GZLINE, other info is unavailable */ @@ -5632,8 +5570,7 @@ void ban_target_to_tkl_layer(BanTarget ban_target, BanActionValue action, Client return; } ban_target = BAN_TARGET_IP; /* fallback */ - } else - if (ban_target == BAN_TARGET_CERTFP) + } else if (ban_target == BAN_TARGET_CERTFP) { const char *fp = moddata_client_get(client, "certfp"); if (fp) @@ -5767,7 +5704,7 @@ static int take_action_ex(Client *client, BanAction *actions, const char *reason if ((action->action > highest) && (action->action != BAN_ACT_SET) && (action->action != BAN_ACT_REPORT)) highest = action->action; - switch(action->action) + switch (action->action) { case BAN_ACT_GZLINE: case BAN_ACT_GLINE: @@ -5778,17 +5715,17 @@ static int take_action_ex(Client *client, BanAction *actions, const char *reason case BAN_ACT_SHUN: case BAN_ACT_SOFT_SHUN: { - char ip[128], user[USERLEN+3], mo[100], mo2[100]; + char ip[128], user[USERLEN + 3], mo[100], mo2[100]; const char *tkllayer[9] = { - me.name, /*0 server.name */ - "+", /*1 +|- */ - "?", /*2 type */ - "*", /*3 user */ - NULL, /*4 host */ - NULL, - NULL, /*6 expire_at */ - NULL, /*7 set_at */ - NULL, /*8 reason */ + me.name, /*0 server.name */ + "+", /*1 +|- */ + "?", /*2 type */ + "*", /*3 user */ + NULL, /*4 host */ + NULL, + NULL, /*6 expire_at */ + NULL, /*7 set_at */ + NULL, /*8 reason */ }; if (take_action_flags & TAKE_ACTION_SIMULATE_USER_ACTION) @@ -5798,7 +5735,7 @@ static int take_action_ex(Client *client, BanAction *actions, const char *reason /* For soft bans we need to prefix the % in the username */ if (IsSoftBanAction(action->action)) { - char tmp[USERLEN+3]; + char tmp[USERLEN + 3]; snprintf(tmp, sizeof(tmp), "%%%s", tkllayer[3]); strlcpy(user, tmp, sizeof(user)); tkllayer[3] = user; @@ -5828,7 +5765,7 @@ static int take_action_ex(Client *client, BanAction *actions, const char *reason cmd_tkl(NULL, &me, m, 9, tkllayer); safe_free_message_tags(m); } - RunHookReturnInt(HOOKTYPE_TAKE_ACTION, !=99, client, action->action, reason, duration); + RunHookReturnInt(HOOKTYPE_TAKE_ACTION, != 99, client, action->action, reason, duration); if ((action->action == BAN_ACT_SHUN) || (action->action == BAN_ACT_SOFT_SHUN)) { find_shun(client); @@ -5845,7 +5782,7 @@ static int take_action_ex(Client *client, BanAction *actions, const char *reason case BAN_ACT_KILL: if (take_action_flags & TAKE_ACTION_SIMULATE_USER_ACTION) break; - RunHookReturnInt(HOOKTYPE_TAKE_ACTION, !=99, client, action->action, reason, duration); + RunHookReturnInt(HOOKTYPE_TAKE_ACTION, != 99, client, action->action, reason, duration); exit_client(client, NULL, reason); break; case BAN_ACT_SOFT_TEMPSHUN: @@ -5854,9 +5791,9 @@ static int take_action_ex(Client *client, BanAction *actions, const char *reason break; /* We simply mark this connection as shunned and do not add a ban record */ unreal_log(ULOG_INFO, "tkl", "TKL_ADD_TEMPSHUN", &me, - "Temporary shun added on user $target.details [reason: $shun_reason] [by: $client]", - log_data_string("shun_reason", reason), - log_data_client("target", client)); + "Temporary shun added on user $target.details [reason: $shun_reason] [by: $client]", + log_data_string("shun_reason", reason), + log_data_client("target", client)); SetShunned(client); break; case BAN_ACT_REPORT: @@ -5956,7 +5893,7 @@ int _join_viruschan(Client *client, TKL *tkl, int type) return 0; /* killed due to JOIN */ sendnotice(client, "You are now restricted to talking in %s: %s", - SPAMFILTER_VIRUSCHAN, unreal_decodespace(tkl->ptr.spamfilter->tkl_reason)); + SPAMFILTER_VIRUSCHAN, unreal_decodespace(tkl->ptr.spamfilter->tkl_reason)); channel = find_channel(SPAMFILTER_VIRUSCHAN); if (channel) @@ -5964,11 +5901,11 @@ int _join_viruschan(Client *client, TKL *tkl, int type) MessageTag *mtags = NULL; ircsnprintf(chbuf, sizeof(chbuf), "@%s", channel->name); ircsnprintf(buf, sizeof(buf), "[Spamfilter] %s matched filter '%s' [%s] [%s]", - client->name, tkl->ptr.spamfilter->match->str, cmdname_by_spamftarget(type), - unreal_decodespace(tkl->ptr.spamfilter->tkl_reason)); + client->name, tkl->ptr.spamfilter->match->str, cmdname_by_spamftarget(type), + unreal_decodespace(tkl->ptr.spamfilter->tkl_reason)); new_message(&me, NULL, &mtags); sendto_channel(channel, &me, NULL, "o", - 0, SEND_ALL|SKIP_DEAF, mtags, + 0, SEND_ALL | SKIP_DEAF, mtags, ":%s NOTICE %s :%s", me.name, chbuf, buf); free_message_tags(mtags); } @@ -5993,8 +5930,7 @@ static int spamfilter_hide_content(int target, SpamfilterShowMessageContentOnHit if (setting == SPAMFILTER_SHOW_MESSAGE_CONTENT_ON_HIT_ALWAYS) return 0; return 1; - } else - if ((target == SPAMF_CHANMSG) || (target == SPAMF_CHANNOTICE)) + } else if ((target == SPAMF_CHANMSG) || (target == SPAMF_CHANNOTICE)) { if ((setting == SPAMFILTER_SHOW_MESSAGE_CONTENT_ON_HIT_ALWAYS) || (setting == SPAMFILTER_SHOW_MESSAGE_CONTENT_ON_HIT_CHANNEL_ONLY)) @@ -6017,9 +5953,7 @@ static void match_spamfilter_hit(Client *client, const char *str_in, const char char no_stop_first_match) { int hide_content = spamfilter_hide_content(target, - tkl->ptr.spamfilter->show_message_content_on_hit ? - tkl->ptr.spamfilter->show_message_content_on_hit : - iConf.spamfilter_show_message_content_on_hit); + tkl->ptr.spamfilter->show_message_content_on_hit ? tkl->ptr.spamfilter->show_message_content_on_hit : iConf.spamfilter_show_message_content_on_hit); int stopped; int highest_action; @@ -6037,33 +5971,33 @@ static void match_spamfilter_hit(Client *client, const char *str_in, const char { /* On-tag-change has no context, so log without the [cmd: ...] part */ unreal_log(ULOG_INFO, "tkl", "SPAMFILTER_MATCH", client, - "[Spamfilter] $client.details matches filter '$tkl': [reason: $tkl.reason] [action: $tkl.ban_action] $spamfilter_id", - log_data_tkl("tkl", tkl), - log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->id)); - } else - if (hide_content || (target == SPAMF_RAW)) + "[Spamfilter] $client.details matches filter '$tkl': [reason: $tkl.reason] [action: $tkl.ban_action] $spamfilter_id", + log_data_tkl("tkl", tkl), + log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->id)); + } else if (hide_content || (target == SPAMF_RAW)) { unreal_log(ULOG_INFO, "tkl", "SPAMFILTER_MATCH", client, - "[Spamfilter] $client.details matches filter '$tkl': [cmd: $command$_space$destination] [reason: $tkl.reason] [action: $tkl.ban_action] $spamfilter_id", - log_data_tkl("tkl", tkl), - log_data_string("command", cmd), - log_data_string("_space", destination ? " " : ""), - log_data_string("destination", destination ? destination : ""), - log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->id)); - } else { + "[Spamfilter] $client.details matches filter '$tkl': [cmd: $command$_space$destination] [reason: $tkl.reason] [action: $tkl.ban_action] $spamfilter_id", + log_data_tkl("tkl", tkl), + log_data_string("command", cmd), + log_data_string("_space", destination ? " " : ""), + log_data_string("destination", destination ? destination : ""), + log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->id)); + } else + { // Yeah we are re-running the text analysis. TextAnalysis textanalysis; memset(&textanalysis, 0, sizeof(textanalysis)); RunHook(HOOKTYPE_ANALYZE_TEXT, client, str, &textanalysis); unreal_log(ULOG_INFO, "tkl", "SPAMFILTER_MATCH", client, - "[Spamfilter] $client.details matches filter '$tkl': [cmd: $command$_space$destination: '$str'] [reason: $tkl.reason] [action: $tkl.ban_action] $spamfilter_id", - log_data_tkl("tkl", tkl), - log_data_string("command", cmd), - log_data_string("_space", destination ? " " : ""), - log_data_string("destination", destination ? destination : ""), - log_data_string("str", str), - log_data_textanalysis("text_analysis", &textanalysis), - log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->id)); + "[Spamfilter] $client.details matches filter '$tkl': [cmd: $command$_space$destination: '$str'] [reason: $tkl.reason] [action: $tkl.ban_action] $spamfilter_id", + log_data_tkl("tkl", tkl), + log_data_string("command", cmd), + log_data_string("_space", destination ? " " : ""), + log_data_string("destination", destination ? destination : ""), + log_data_string("str", str), + log_data_textanalysis("text_analysis", &textanalysis), + log_data_optional_name_value("spamfilter_id", "spamfilter-id", tkl->id)); *content_revealed = 1; } @@ -6094,7 +6028,6 @@ static void match_spamfilter_hit(Client *client, const char *str_in, const char else *stop_processing_general_spamfilters = 1; } - } /** Run rule-only spamfilters: ones with no ::match/::target, only a ::rule. @@ -6134,7 +6067,8 @@ static void run_rule_only_spamfilter_loop(Client *client, const char *str_in, co { if (*stop_processing_central_spamfilters) continue; - } else { + } else + { if (*stop_processing_general_spamfilters) continue; } @@ -6188,7 +6122,7 @@ void _run_deferred_rule_only_spamfilters(Client *client) */ client->local->spamfilter_run_tags_serial = client->local->tags_serial; - if (!client->user || ValidatePermissionsForPath("immune:server-ban:spamfilter",client,NULL,NULL,NULL) || IsULine(client)) + if (!client->user || ValidatePermissionsForPath("immune:server-ban:spamfilter", client, NULL, NULL, NULL) || IsULine(client)) return; memset(&context, 0, sizeof(context)); @@ -6271,7 +6205,7 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char /* (note: using client->user check here instead of IsUser() * due to SPAMF_USER where user isn't marked as client/person yet. */ - if (!client->user || ValidatePermissionsForPath("immune:server-ban:spamfilter",client,NULL,NULL,NULL) || IsULine(client)) + if (!client->user || ValidatePermissionsForPath("immune:server-ban:spamfilter", client, NULL, NULL, NULL) || IsULine(client)) return 0; memset(&context, 0, sizeof(context)); @@ -6306,7 +6240,8 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char { if (stop_processing_central_spamfilters) continue; - } else { + } else + { if (stop_processing_general_spamfilters) continue; } @@ -6358,31 +6293,31 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char getrusage(RUSAGE_SELF, &rnow); ms_past = ((rnow.ru_utime.tv_sec - rprev.ru_utime.tv_sec) * 1000) + - ((rnow.ru_utime.tv_usec - rprev.ru_utime.tv_usec) / 1000); + ((rnow.ru_utime.tv_usec - rprev.ru_utime.tv_usec) / 1000); if ((SPAMFILTER_DETECTSLOW_FATAL > 0) && (ms_past > SPAMFILTER_DETECTSLOW_FATAL)) { unreal_log(ULOG_ERROR, "tkl", "SPAMFILTER_SLOW_FATAL", NULL, - "[Spamfilter] WARNING: Too slow spamfilter detected (took $msec_time msec to execute) " - "-- spamfilter will be \002REMOVED!\002: $tkl", - log_data_tkl("tkl", tkl), - log_data_integer("msec_time", ms_past)); + "[Spamfilter] WARNING: Too slow spamfilter detected (took $msec_time msec to execute) " + "-- spamfilter will be \002REMOVED!\002: $tkl", + log_data_tkl("tkl", tkl), + log_data_integer("msec_time", ms_past)); tkl_del_line(tkl); return 0; /* Act as if it didn't match, even if it did.. it's gone now anyway.. */ - } else - if ((SPAMFILTER_DETECTSLOW_WARN > 0) && (ms_past > SPAMFILTER_DETECTSLOW_WARN)) + } else if ((SPAMFILTER_DETECTSLOW_WARN > 0) && (ms_past > SPAMFILTER_DETECTSLOW_WARN)) { unreal_log(ULOG_WARNING, "tkl", "SPAMFILTER_SLOW_WARN", NULL, - "[Spamfilter] WARNING: Slow spamfilter detected (took $msec_time msec to execute): $tkl", - log_data_tkl("tkl", tkl), - log_data_integer("msec_time", ms_past)); + "[Spamfilter] WARNING: Slow spamfilter detected (took $msec_time msec to execute): $tkl", + log_data_tkl("tkl", tkl), + log_data_integer("msec_time", ms_past)); } } #endif if (regex_error) spamfilter_regex_error(tkl, regex_error); - } else { + } else + { /* There is no ::match but there was a ::rule, and that is enough for a match.. */ if (tkl->ptr.spamfilter->rule) ret = 1; @@ -6425,7 +6360,7 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char { if ((ret == BAN_ACT_BLOCK) || (ret == BAN_ACT_SOFT_BLOCK)) { - switch(target) + switch (target) { case SPAMF_USERMSG: case SPAMF_USERNOTICE: @@ -6440,13 +6375,13 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char case SPAMF_CHANMSG: { sendto_one(client, NULL, ":%s 404 %s %s :Message blocked: %s", - me.name, client->name, destination, reason); + me.name, client->name, destination, reason); break; } case SPAMF_MTAG: { sendnumericfmt(client, ERR_CANNOTDOCOMMAND, "%s :Command blocked: %s", - cmd, reason); + cmd, reason); break; } case SPAMF_DCC: @@ -6469,14 +6404,13 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char case SPAMF_TOPIC: //... sendnotice(client, "Setting of topic on %s to that text is blocked: %s", - destination, reason); + destination, reason); break; default: break; } return ret; - } else - if ((ret == BAN_ACT_WARN) || (ret == BAN_ACT_SOFT_WARN)) + } else if ((ret == BAN_ACT_WARN) || (ret == BAN_ACT_SOFT_WARN)) { if (content_revealed && ((target == SPAMF_USERMSG) || (target == SPAMF_USERNOTICE) || @@ -6485,8 +6419,7 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char sendnumeric(client, RPL_SPAMCMDFWD, cmd, reason); } return 0; - } else - if ((ret == BAN_ACT_DCCBLOCK) || (ret == BAN_ACT_SOFT_DCCBLOCK)) + } else if ((ret == BAN_ACT_DCCBLOCK) || (ret == BAN_ACT_SOFT_DCCBLOCK)) { if (target == SPAMF_DCC) { @@ -6495,8 +6428,7 @@ int _match_spamfilter(Client *client, const char *str_in, int target, const char SetDCCBlock(client); } return ret; - } else - if ((ret == BAN_ACT_VIRUSCHAN) || (ret == BAN_ACT_SOFT_VIRUSCHAN)) + } else if ((ret == BAN_ACT_VIRUSCHAN) || (ret == BAN_ACT_SOFT_VIRUSCHAN)) { if (IsVirus(client)) /* Already tagged */ return ret; // this was 0, but the action should be blocked, right? @@ -6544,7 +6476,8 @@ int _match_spamfilter_mtags(Client *client, MessageTag *mtags, const char *cmd) { snprintf(buf, sizeof(buf), "%s=%s", m->name, m->value); str = buf; - } else { + } else + { str = m->name; } if (match_spamfilter(client, str, SPAMF_MTAG, cmd, NULL, 0, NULL, NULL)) @@ -6586,7 +6519,7 @@ static int comp_with_mask(void *addr, void *dest, u_int mask) { int n = mask / 8; int m = (0xffff << (8 - (mask % 8))); - if (mask % 8 == 0 || (((u_char *) addr)[n] & m) == (((u_char *) dest)[n] & m)) + if (mask % 8 == 0 || (((u_char *)addr)[n] & m) == (((u_char *)dest)[n] & m)) { return (1); } @@ -6604,7 +6537,7 @@ static int comp_with_mask(void *addr, void *dest, u_int mask) */ int _match_user(const char *rmask, Client *client, int options) { - char mask[NICKLEN+USERLEN+HOSTLEN+8]; + char mask[NICKLEN + USERLEN + HOSTLEN + 8]; char clientip[IPSZ], maskip[IPSZ]; char *p = NULL; char *nmask = NULL, *umask = NULL, *hmask = NULL; @@ -6654,12 +6587,14 @@ int _match_user(const char *rmask, Client *client, int options) /* Check user portion right away */ if (!match_simple(umask, client_username)) return 0; /* NOMATCH: user mask did not match */ - } else { + } else + { if (nmask) return 0; /* NOMATCH: 'abc!def' (or even just 'abc!') */ hmask = mask; } - } else { + } else + { hmask = mask; } @@ -6699,8 +6634,7 @@ int _match_user(const char *rmask, Client *client, int options) /* Wildcards */ if (client->ip && match_simple(hmask, client->ip)) return 1; /* MATCH (IP with wildcards) */ - } else - if (strchr(hmask, ':')) + } else if (strchr(hmask, ':')) { /* IPv6 hostmask */ @@ -6736,8 +6670,7 @@ int _match_user(const char *rmask, Client *client, int options) { if (comp_with_mask(clientip, maskip, 32)) return 1; /* MATCH: exact IP */ - } - else if (cidr > 32) + } else if (cidr > 32) return 0; /* NOMATCH: invalid CIDR */ else return comp_with_mask(clientip, maskip, cidr); /* MATCH/NOMATCH by CIDR */ @@ -6776,7 +6709,8 @@ int _unreal_match_iplist(Client *client, NameList *l) client_ipv6 = 1; if (!inet_pton(AF_INET6, client->ip, clientip)) return 0; /* unusual failure */ - } else { + } else + { if (!inet_pton(AF_INET, client->ip, clientip)) return 0; /* unusual failure */ } @@ -6803,8 +6737,7 @@ int _unreal_match_iplist(Client *client, NameList *l) /* Wildcards */ if (match_simple(mask, client->ip)) return 1; /* MATCH by wildcard IP */ - } - else if (strchr(mask, ':')) + } else if (strchr(mask, ':')) { /* IPv6 */ if (!client_ipv6) @@ -6816,12 +6749,10 @@ int _unreal_match_iplist(Client *client, NameList *l) /* Try to match by exact IP */ if (comp_with_mask(clientip, maskip, 128)) return 1; /* MATCH by exact IP */ - } else - if (cidr > 128) + } else if (cidr > 128) { continue; /* NOMATCH: invalid CIDR */ - } else - if (comp_with_mask(clientip, maskip, cidr)) + } else if (comp_with_mask(clientip, maskip, cidr)) { return 1; /* MATCH by CIDR */ } @@ -6837,12 +6768,10 @@ int _unreal_match_iplist(Client *client, NameList *l) /* Try to match by exact IP */ if (comp_with_mask(clientip, maskip, 32)) return 1; /* MATCH: by exact IP */ - } else - if (cidr > 32) + } else if (cidr > 32) { continue; /* NOMATCH: invalid CIDR */ - } else - if (comp_with_mask(clientip, maskip, cidr)) + } else if (comp_with_mask(clientip, maskip, cidr)) { return 1; /* MATCH by CIDR */ } @@ -6963,6 +6892,6 @@ CMD_FUNC(cmd_spaminfo) if (clictx->textanalysis->num_unicode_characters != cnt) { sendnotice(client, "- Non-alpha ASCII characters (digits/spaces/etc.): %d", - clictx->textanalysis->num_unicode_characters - cnt); + clictx->textanalysis->num_unicode_characters - cnt); } } diff --git a/src/modules/tkldb.c b/src/modules/tkldb.c index aadfda947..8232502a3 100644 --- a/src/modules/tkldb.c +++ b/src/modules/tkldb.c @@ -20,11 +20,11 @@ #include "unrealircd.h" ModuleHeader MOD_HEADER = { - "tkldb", - "1.10", - "Stores active TKL entries (*-Lines) persistently/across IRCd restarts", - "UnrealIRCd Team", - "unrealircd-6", + "tkldb", + "1.10", + "Stores active TKL entries (*-Lines) persistently/across IRCd restarts", + "UnrealIRCd Team", + "unrealircd-6", }; #define TKLDB_MAGIC 0x10101010 @@ -49,46 +49,54 @@ ModuleHeader MOD_HEADER = { */ #define FreeTKLRead() \ - do { \ + do \ + { \ /* Some of these might be NULL */ \ if (tkl) \ free_tkl(tkl); \ - } while(0) + } while (0) #define WARN_WRITE_ERROR(fname) \ - do { \ + do \ + { \ unreal_log(ULOG_ERROR, "tkldb", "TKLDB_FILE_WRITE_ERROR", NULL, \ - "[tkldb] Error writing to temporary database file $filename: $system_error", \ - log_data_string("filename", fname), \ - log_data_string("system_error", unrealdb_get_error_string())); \ - } while(0) + "[tkldb] Error writing to temporary database file $filename: $system_error", \ + log_data_string("filename", fname), \ + log_data_string("system_error", unrealdb_get_error_string())); \ + } while (0) #define R_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ config_warn("[tkldb] Read error from database file '%s' (possible corruption): %s", cfg.database, unrealdb_get_error_string()); \ unrealdb_close(db); \ FreeTKLRead(); \ return 0; \ } \ - } while(0) + } while (0) #define W_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ WARN_WRITE_ERROR(tmpfname); \ unrealdb_close(db); \ return 0; \ } \ - } while(0) + } while (0) #define IsMDErr(x, y, z) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ config_error("A critical error occurred when registering ModData for %s: %s", MOD_HEADER.name, ModuleGetErrorStr((z)->handle)); \ return MOD_FAILED; \ } \ - } while(0) + } while (0) /* Structs */ struct cfgstruct { @@ -207,13 +215,11 @@ int tkldb_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { config_error("%s:%i: blank set::tkldb::%s without value", cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "database")) + } else if (!strcmp(cep->name, "database")) { convert_to_absolute_path(&cep->value, PERMDATADIR); safe_strdup(test.database, cep->value); - } else - if (!strcmp(cep->name, "db-secret")) + } else if (!strcmp(cep->name, "db-secret")) { const char *err; if ((err = unrealdb_test_secret(cep->value))) @@ -383,7 +389,7 @@ int write_tkldb(void) #ifdef BENCHMARK gettimeofday(&tv_beta, NULL); config_status("[tkldb] Benchmark: SAVE DB: %lld microseconds", - (long long)(((tv_beta.tv_sec - tv_alpha.tv_sec) * 1000000) + (tv_beta.tv_usec - tv_alpha.tv_usec))); + (long long)(((tv_beta.tv_sec - tv_alpha.tv_sec) * 1000000) + (tv_beta.tv_usec - tv_alpha.tv_usec))); #endif return 1; } @@ -419,8 +425,7 @@ int write_tkline(UnrealDB *db, const char *tmpfname, TKL *tkl) W_SAFE(unrealdb_write_str(db, usermask)); W_SAFE(unrealdb_write_str(db, tkl->ptr.serverban->hostmask)); W_SAFE(unrealdb_write_str(db, tkl->ptr.serverban->reason)); - } else - if (TKLIsBanException(tkl)) + } else if (TKLIsBanException(tkl)) { char *usermask = tkl->ptr.banexception->usermask; if (tkl->ptr.banexception->subtype & TKL_SUBTYPE_SOFT) @@ -432,15 +437,13 @@ int write_tkline(UnrealDB *db, const char *tmpfname, TKL *tkl) W_SAFE(unrealdb_write_str(db, tkl->ptr.banexception->hostmask)); W_SAFE(unrealdb_write_str(db, tkl->ptr.banexception->bantypes)); W_SAFE(unrealdb_write_str(db, tkl->ptr.banexception->reason)); - } else - if (TKLIsNameBan(tkl)) + } else if (TKLIsNameBan(tkl)) { char *hold = tkl->ptr.nameban->hold ? "H" : "*"; W_SAFE(unrealdb_write_str(db, hold)); W_SAFE(unrealdb_write_str(db, tkl->ptr.nameban->name)); W_SAFE(unrealdb_write_str(db, tkl->ptr.nameban->reason)); - } else - if (TKLIsSpamfilter(tkl)) + } else if (TKLIsSpamfilter(tkl)) { char *match_type = unreal_match_method_valtostr(tkl->ptr.spamfilter->match->type); char *target = spamfilter_target_inttostring(tkl->ptr.spamfilter->target); @@ -488,8 +491,7 @@ int read_tkldb(void) /* Database does not exist. Could be first boot */ config_warn("[tkldb] No database present at '%s', will start a new one", cfg.database); return 1; - } else - if (unrealdb_get_error_code() == UNREALDB_ERROR_NOTCRYPTED) + } else if (unrealdb_get_error_code() == UNREALDB_ERROR_NOTCRYPTED) { /* Re-open as unencrypted */ db = unrealdb_open(cfg.database, UNREALDB_MODE_READ, NULL); @@ -529,7 +531,7 @@ int read_tkldb(void) if (version > tkldb_version) { config_warn("[tkldb] Database '%s' has version %lu while we only support %lu. Did you just downgrade UnrealIRCd? Sorry this is not suported", - cfg.database, (unsigned long)tkldb_version, (unsigned long)version); + cfg.database, (unsigned long)tkldb_version, (unsigned long)version); unrealdb_close(db); return 0; } @@ -600,8 +602,9 @@ int read_tkldb(void) if (*str == '%') { softban = 1; - safe_strdup(tkl->ptr.serverban->usermask, str+1); - } else { + safe_strdup(tkl->ptr.serverban->usermask, str + 1); + } else + { safe_strdup(tkl->ptr.serverban->usermask, str); } safe_free(str); @@ -626,14 +629,13 @@ int read_tkldb(void) if (!do_not_add) { added = tkl_add_serverban(tkl->type, tkl->ptr.serverban->usermask, - tkl->ptr.serverban->hostmask, - NULL, - tkl->ptr.serverban->reason, - tkl->set_by, tkl->expire_at, - tkl->set_at, softban, 0); + tkl->ptr.serverban->hostmask, + NULL, + tkl->ptr.serverban->reason, + tkl->set_by, tkl->expire_at, + tkl->set_at, softban, 0); } - } else - if (TKLIsBanException(tkl)) + } else if (TKLIsBanException(tkl)) { int softban = 0; @@ -646,8 +648,9 @@ int read_tkldb(void) if (*str == '%') { softban = 1; - safe_strdup(tkl->ptr.banexception->usermask, str+1); - } else { + safe_strdup(tkl->ptr.banexception->usermask, str + 1); + } else + { safe_strdup(tkl->ptr.banexception->usermask, str); } safe_free(str); @@ -666,16 +669,15 @@ int read_tkldb(void) if (!do_not_add) { added = tkl_add_banexception(tkl->type, tkl->ptr.banexception->usermask, - tkl->ptr.banexception->hostmask, - NULL, - tkl->ptr.banexception->reason, - tkl->set_by, tkl->expire_at, - tkl->set_at, softban, - tkl->ptr.banexception->bantypes, - 0); + tkl->ptr.banexception->hostmask, + NULL, + tkl->ptr.banexception->reason, + tkl->set_by, tkl->expire_at, + tkl->set_at, softban, + tkl->ptr.banexception->bantypes, + 0); } - } else - if (TKLIsNameBan(tkl)) + } else if (TKLIsNameBan(tkl)) { tkl->ptr.nameban = safe_alloc(sizeof(NameBan)); @@ -695,13 +697,12 @@ int read_tkldb(void) if (!do_not_add) { added = tkl_add_nameban(tkl->type, tkl->ptr.nameban->name, - tkl->ptr.nameban->hold, - tkl->ptr.nameban->reason, - tkl->set_by, tkl->expire_at, - tkl->set_at, 0); + tkl->ptr.nameban->hold, + tkl->ptr.nameban->reason, + tkl->set_by, tkl->expire_at, + tkl->set_at, 0); } - } else - if (TKLIsSpamfilter(tkl)) + } else if (TKLIsSpamfilter(tkl)) { int match_method; const char *err = NULL; @@ -734,7 +735,7 @@ int read_tkldb(void) if (!tkl->ptr.spamfilter->target) { config_warn("[tkldb] Spamfilter '%s' without any valid targets (%s) -- spamfilter entry not added", - tkl->ptr.spamfilter->match->str, str); + tkl->ptr.spamfilter->match->str, str); do_not_add = 1; } safe_free(str); @@ -745,7 +746,7 @@ int read_tkldb(void) if (!tkl->ptr.spamfilter->action || banact_config_only(tkl->ptr.spamfilter->action->action)) { config_warn("[tkldb] Spamfilter '%s' without valid action (%c) -- spamfilter entry not added", - tkl->ptr.spamfilter->match->str, c); + tkl->ptr.spamfilter->match->str, c); do_not_add = 1; } @@ -779,14 +780,14 @@ int read_tkldb(void) if (!do_not_add) { added = tkl_add_spamfilter(tkl->type, NULL, tkl->ptr.spamfilter->target, - tkl->ptr.spamfilter->action, - tkl->ptr.spamfilter->match, - NULL, - NULL, - tkl->set_by, tkl->expire_at, tkl->set_at, - tkl->ptr.spamfilter->tkl_duration, - tkl->ptr.spamfilter->tkl_reason, - INPUT_CONVERSION_DEFAULT, 0, 0); + tkl->ptr.spamfilter->action, + tkl->ptr.spamfilter->match, + NULL, + NULL, + tkl->set_by, tkl->expire_at, tkl->set_at, + tkl->ptr.spamfilter->tkl_duration, + tkl->ptr.spamfilter->tkl_reason, + INPUT_CONVERSION_DEFAULT, 0, 0); /* Further down in the code we free fields of the TKL entry, * this is generally fine since almost all fields are copied * by tkl_add_spamfilter(), however some are not. @@ -837,4 +838,3 @@ int read_tkldb(void) #endif return 1; } - diff --git a/src/modules/tline.c b/src/modules/tline.c index 33d7e203e..202a97604 100644 --- a/src/modules/tline.c +++ b/src/modules/tline.c @@ -26,14 +26,13 @@ CMD_FUNC(cmd_tline); -ModuleHeader MOD_HEADER - = { - "tline", - "1.0", - "TLINE command to show amount of clients matching a server ban mask", - "UnrealIRCd team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "tline", + "1.0", + "TLINE command to show amount of clients matching a server ban mask", + "UnrealIRCd team", + "unrealircd-6", +}; MOD_INIT() { @@ -95,9 +94,9 @@ CMD_FUNC(cmd_tline) } sendnotice(client, - "*** TLINE: Users matching mask '%s': global: %d/%d (%.2f%%), local: %d/%d (%.2f%%).", - serverban, matching_clients, irccounts.clients, - (double)matching_clients / irccounts.clients * 100, - matching_lclients, irccounts.me_clients, - (double)matching_lclients / irccounts.me_clients * 100); + "*** TLINE: Users matching mask '%s': global: %d/%d (%.2f%%), local: %d/%d (%.2f%%).", + serverban, matching_clients, irccounts.clients, + (double)matching_clients / irccounts.clients * 100, + matching_lclients, irccounts.me_clients, + (double)matching_lclients / irccounts.me_clients * 100); } diff --git a/src/modules/tls_antidos.c b/src/modules/tls_antidos.c index a06ae13c6..aac712d6b 100644 --- a/src/modules/tls_antidos.c +++ b/src/modules/tls_antidos.c @@ -10,17 +10,16 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "tls_antidos", - "5.0", - "TLS Renegotiation DoS protection", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "tls_antidos", + "5.0", + "TLS Renegotiation DoS protection", + "UnrealIRCd Team", + "unrealircd-6", +}; #define HANDSHAKE_LIMIT_COUNT 3 -#define HANDSHAKE_LIMIT_SECS 300 +#define HANDSHAKE_LIMIT_SECS 300 typedef struct SAD SAD; struct SAD { @@ -41,14 +40,14 @@ MOD_INIT() HookAdd(modinfo->handle, HOOKTYPE_HANDSHAKE, 0, tls_antidos_handshake); MARK_AS_OFFICIAL_MODULE(modinfo); - + ModuleSetOptions(modinfo->handle, MOD_OPT_PERM, 1); /* Note that we cannot be MOD_OPT_PERM_RELOADABLE as we use OpenSSL functions to register * an index and callback function. */ - + tls_antidos_index = SSL_get_ex_new_index(0, "tls_antidos", NULL, NULL, tls_antidos_free); - + return MOD_SUCCESS; } @@ -69,7 +68,7 @@ void ssl_info_callback(const SSL *ssl, int where, int ret) { SAD *e = SSL_get_ex_data(ssl, tls_antidos_index); Client *client = e->client; - + if (IsServer(client) || IsDeadSocket(client)) return; /* if it's a server, or already pending to be killed off then we don't care */ @@ -77,7 +76,8 @@ void ssl_info_callback(const SSL *ssl, int where, int ret) { e->ts = TStime(); e->n = 1; - } else { + } else + { e->n++; if (e->n >= HANDSHAKE_LIMIT_COUNT) { diff --git a/src/modules/tls_cipher.c b/src/modules/tls_cipher.c index 85c38afa6..6257a327c 100644 --- a/src/modules/tls_cipher.c +++ b/src/modules/tls_cipher.c @@ -6,14 +6,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "tls_cipher", - "5.0", - "Store and retrieve TLS cipher string", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "tls_cipher", + "5.0", + "Store and retrieve TLS cipher string", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ void tls_cipher_free(ModData *m); @@ -28,10 +27,10 @@ ModDataInfo *tls_cipher_md; /* Module Data structure which we acquire */ MOD_INIT() { -ModDataInfo mreq; + ModDataInfo mreq; MARK_AS_OFFICIAL_MODULE(modinfo); - + memset(&mreq, 0, sizeof(mreq)); mreq.name = "tls_cipher"; mreq.free = tls_cipher_free; diff --git a/src/modules/topic.c b/src/modules/topic.c index 8d33fcd03..3f938b061 100644 --- a/src/modules/topic.c +++ b/src/modules/topic.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_topic); -#define MSG_TOPIC "TOPIC" +#define MSG_TOPIC "TOPIC" -ModuleHeader MOD_HEADER - = { - "topic", - "5.0", - "command /topic", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "topic", + "5.0", + "command /topic", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ void _set_channel_topic(Client *client, Channel *channel, MessageTag *recv_mtags, const char *topic, const char *set_by, time_t set_at); @@ -47,7 +46,7 @@ MOD_TEST() MOD_INIT() { - CommandAdd(modinfo->handle, MSG_TOPIC, cmd_topic, 4, CMD_USER|CMD_SERVER|CMD_TEXTANALYSIS); + CommandAdd(modinfo->handle, MSG_TOPIC, cmd_topic, 4, CMD_USER | CMD_SERVER | CMD_TEXTANALYSIS); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -65,10 +64,10 @@ MOD_UNLOAD() void topic_operoverride_msg(Client *client, Channel *channel, const char *topic) { unreal_log(ULOG_INFO, "operoverride", "OPEROVERRIDE_TOPIC", client, - "OperOverride: $client.details changed the topic of $channel to '$topic'", - log_data_string("override_type", "topic"), - log_data_string("topic", topic), - log_data_channel("channel", channel)); + "OperOverride: $client.details changed the topic of $channel to '$topic'", + log_data_string("override_type", "topic"), + log_data_string("topic", topic), + log_data_channel("channel", channel)); } /** Query or change the channel topic. @@ -89,7 +88,7 @@ CMD_FUNC(cmd_topic) const char *topic = NULL; const char *name, *tnick = client->name; const char *errmsg = NULL; - char topicbuf[MAXTOPICLEN+1]; + char topicbuf[MAXTOPICLEN + 1]; time_t ttime = 0; int i = 0; Hook *h; @@ -112,8 +111,7 @@ CMD_FUNC(cmd_topic) if (parc > 2 || SecretChannel(channel)) { - if (!IsMember(client, channel) && !IsServer(client) - && !ValidatePermissionsForPath("channel:see:list:secret",client,NULL,channel,NULL) && !IsULine(client)) + if (!IsMember(client, channel) && !IsServer(client) && !ValidatePermissionsForPath("channel:see:list:secret", client, NULL, channel, NULL) && !IsULine(client)) { sendnumeric(client, ERR_NOTONCHANNEL, name); return; @@ -142,15 +140,15 @@ CMD_FUNC(cmd_topic) for (h = Hooks[HOOKTYPE_VIEW_TOPIC_OUTSIDE_CHANNEL]; h; h = h->next) { - i = (*(h->func.intfunc))(client,channel); + i = (*(h->func.intfunc))(client, channel); if (i != HOOK_CONTINUE) break; } /* If you're not a member, and you can't view outside channel, deny */ if ((!IsMember(client, channel) && i == HOOK_DENY) || - (is_banned(client,channel,BANCHK_JOIN,NULL,NULL) && - !ValidatePermissionsForPath("channel:see:topic",client,NULL,channel,NULL))) + (is_banned(client, channel, BANCHK_JOIN, NULL, NULL) && + !ValidatePermissionsForPath("channel:see:topic", client, NULL, channel, NULL))) { sendnumeric(client, ERR_NOTONCHANNEL, name); return; @@ -179,18 +177,18 @@ CMD_FUNC(cmd_topic) */ { /* Set the topic */ - safe_strldup(channel->topic, topic, iConf.topic_length+1); - safe_strldup(channel->topic_nick, tnick, NICKLEN+USERLEN+HOSTLEN+5); + safe_strldup(channel->topic, topic, iConf.topic_length + 1); + safe_strldup(channel->topic_nick, tnick, NICKLEN + USERLEN + HOSTLEN + 5); channel->topic_time = ttime; new_message(client, recv_mtags, &mtags); RunHook(HOOKTYPE_TOPIC, client, channel, mtags, channel->topic); sendto_server(client, 0, 0, mtags, ":%s TOPIC %s %s %lld :%s", - client->id, channel->name, channel->topic_nick, - (long long)channel->topic_time, channel->topic); + client->id, channel->name, channel->topic_nick, + (long long)channel->topic_time, channel->topic); sendto_channel(channel, client, NULL, 0, 0, SEND_LOCAL, mtags, - ":%s TOPIC %s :%s", - client->name, channel->name, channel->topic); + ":%s TOPIC %s :%s", + client->name, channel->name, channel->topic); free_message_tags(mtags); } return; @@ -211,8 +209,7 @@ CMD_FUNC(cmd_topic) if (n == EX_DENY) { ret = n; - } else - if (n == EX_ALWAYS_DENY) + } else if (n == EX_ALWAYS_DENY) { ret = n; break; @@ -235,7 +232,8 @@ CMD_FUNC(cmd_topic) if (errmsg) sendto_one(client, NULL, "%s", errmsg); return; /* reject */ - } else { + } else + { operoverride = 1; /* allow */ } } @@ -249,7 +247,7 @@ CMD_FUNC(cmd_topic) if (MyUser(client) && !ValidatePermissionsForPath("channel:override:topic", client, NULL, channel, NULL)) { ircsnprintf(buf, sizeof(buf), "You cannot change the topic on %s while being banned", channel->name); - sendnumeric(client, ERR_CANNOTDOCOMMAND, "TOPIC", buf); + sendnumeric(client, ERR_CANNOTDOCOMMAND, "TOPIC", buf); return; } operoverride = 1; @@ -270,7 +268,8 @@ CMD_FUNC(cmd_topic) if (match_spamfilter(client, topic, SPAMF_TOPIC, "TOPIC", channel->name, 0, clictx, NULL)) return; - for (tmphook = Hooks[HOOKTYPE_PRE_LOCAL_TOPIC]; tmphook; tmphook = tmphook->next) { + for (tmphook = Hooks[HOOKTYPE_PRE_LOCAL_TOPIC]; tmphook; tmphook = tmphook->next) + { topic = (*(tmphook->func.stringfunc))(client, channel, topic); if (!topic) return; @@ -307,18 +306,18 @@ void _set_channel_topic(Client *client, Channel *channel, MessageTag *recv_mtags set_at = TStime(); /* Set the topic */ - safe_strldup(channel->topic, topic, iConf.topic_length+1); - safe_strldup(channel->topic_nick, set_by, NICKLEN+USERLEN+HOSTLEN+5); + safe_strldup(channel->topic, topic, iConf.topic_length + 1); + safe_strldup(channel->topic_nick, set_by, NICKLEN + USERLEN + HOSTLEN + 5); channel->topic_time = set_at; /* And broadcast the change - locally and remote */ new_message(client, recv_mtags, &mtags); RunHook(HOOKTYPE_TOPIC, client, channel, mtags, topic); sendto_server(client, 0, 0, mtags, ":%s TOPIC %s %s %lld :%s", - client->id, channel->name, channel->topic_nick, - (long long)channel->topic_time, channel->topic); + client->id, channel->name, channel->topic_nick, + (long long)channel->topic_time, channel->topic); sendto_channel(channel, client, NULL, 0, 0, SEND_LOCAL, mtags, - ":%s TOPIC %s :%s", - client->name, channel->name, channel->topic); + ":%s TOPIC %s :%s", + client->name, channel->name, channel->topic); free_message_tags(mtags); } diff --git a/src/modules/trace.c b/src/modules/trace.c index 028cbd2cb..6413d0e92 100644 --- a/src/modules/trace.c +++ b/src/modules/trace.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_trace); -#define MSG_TRACE "TRACE" +#define MSG_TRACE "TRACE" -ModuleHeader MOD_HEADER - = { - "trace", - "5.0", - "command /trace", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "trace", + "5.0", + "command /trace", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -58,12 +57,12 @@ MOD_UNLOAD() */ CMD_FUNC(cmd_trace) { - int i; + int i; Client *acptr; ConfigItem_class *cltmp; const char *tname; - int doall, link_s[MAXCONNECTIONS], link_u[MAXCONNECTIONS]; - int cnt = 0, wilds, dow; + int doall, link_s[MAXCONNECTIONS], link_u[MAXCONNECTIONS]; + int cnt = 0, wilds, dow; time_t now; /* This is one of the (few) commands that cannot be handled @@ -81,9 +80,9 @@ CMD_FUNC(cmd_trace) else tname = me.name; - if (!ValidatePermissionsForPath("client:see:trace:global",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("client:see:trace:global", client, NULL, NULL, NULL)) { - if (ValidatePermissionsForPath("client:see:trace:local",client,NULL,NULL,NULL)) + if (ValidatePermissionsForPath("client:see:trace:local", client, NULL, NULL, NULL)) { /* local opers may not /TRACE remote servers! */ if (strcasecmp(tname, me.name)) @@ -92,7 +91,8 @@ CMD_FUNC(cmd_trace) sendnumeric(client, ERR_NOPRIVILEGES); return; } - } else { + } else + { sendnumeric(client, ERR_NOPRIVILEGES); return; } @@ -100,19 +100,19 @@ CMD_FUNC(cmd_trace) switch (hunt_server(client, NULL, "TRACE", 1, parc, parv)) { - case HUNTED_PASS: /* note: gets here only if parv[1] exists */ - { - Client *ac2ptr; + case HUNTED_PASS: /* note: gets here only if parv[1] exists */ + { + Client *ac2ptr; - ac2ptr = find_client(tname, NULL); - sendnumeric(client, RPL_TRACELINK, - version, debugmode, tname, ac2ptr->direction->name); - return; - } - case HUNTED_ISME: - break; - default: - return; + ac2ptr = find_client(tname, NULL); + sendnumeric(client, RPL_TRACELINK, + version, debugmode, tname, ac2ptr->direction->name); + return; + } + case HUNTED_ISME: + break; + default: + return; } doall = (parv[1] && (parc > 1)) ? match_simple(tname, me.name) : TRUE; @@ -123,7 +123,8 @@ CMD_FUNC(cmd_trace) link_s[i] = 0, link_u[i] = 0; - if (doall) { + if (doall) + { list_for_each_entry(acptr, &client_list, client_node) { if (acptr->direction->local->fd < 0) @@ -143,7 +144,7 @@ CMD_FUNC(cmd_trace) const char *name; const char *class; - if (!ValidatePermissionsForPath("client:see:trace:invisible-users",client,acptr,NULL,NULL) && (acptr != client)) + if (!ValidatePermissionsForPath("client:see:trace:invisible-users", client, acptr, NULL, NULL) && (acptr != client)) continue; if (!doall && wilds && !match_simple(tname, acptr->name)) continue; @@ -175,28 +176,27 @@ CMD_FUNC(cmd_trace) /* Only opers see users if there is a wildcard * but anyone can see all the opers. */ - if (ValidatePermissionsForPath("client:see:trace:invisible-users",client,acptr,NULL,NULL) || - (!IsInvisible(acptr) && ValidatePermissionsForPath("client:see:trace",client,acptr,NULL,NULL))) + if (ValidatePermissionsForPath("client:see:trace:invisible-users", client, acptr, NULL, NULL) || + (!IsInvisible(acptr) && ValidatePermissionsForPath("client:see:trace", client, acptr, NULL, NULL))) { - if (ValidatePermissionsForPath("client:see:trace",client,acptr,NULL,NULL) || ValidatePermissionsForPath("client:see:trace:invisible-users",client,acptr,NULL,NULL)) + if (ValidatePermissionsForPath("client:see:trace", client, acptr, NULL, NULL) || ValidatePermissionsForPath("client:see:trace:invisible-users", client, acptr, NULL, NULL)) sendnumeric(client, RPL_TRACEOPERATOR, - class, acptr->name, - GetHost(acptr), - (long long)(now - acptr->local->last_msg_received)); + class, acptr->name, + GetHost(acptr), + (long long)(now - acptr->local->last_msg_received)); else sendnumeric(client, RPL_TRACEUSER, - class, acptr->name, - acptr->user->realhost, - (long long)(now - acptr->local->last_msg_received)); + class, acptr->name, + acptr->user->realhost, + (long long)(now - acptr->local->last_msg_received)); cnt++; } break; case CLIENT_STATUS_SERVER: sendnumeric(client, RPL_TRACESERVER, class, acptr->local->fd >= 0 ? link_s[acptr->local->fd] : -1, - acptr->local->fd >= 0 ? link_u[acptr->local->fd] : -1, name, *(acptr->server->by) ? - acptr->server->by : "*", "*", me.name, - (long long)(now - acptr->local->last_msg_received)); + acptr->local->fd >= 0 ? link_u[acptr->local->fd] : -1, name, *(acptr->server->by) ? acptr->server->by : "*", "*", me.name, + (long long)(now - acptr->local->last_msg_received)); cnt++; break; @@ -215,7 +215,7 @@ CMD_FUNC(cmd_trace) cnt++; break; - default: /* ...we actually shouldn't come here... --msa */ + default: /* ...we actually shouldn't come here... --msa */ sendnumeric(client, RPL_TRACENEWTYPE, "", name); cnt++; break; @@ -225,10 +225,10 @@ CMD_FUNC(cmd_trace) * Add these lines to summarize the above which can get rather long * and messy when done remotely - Avalon */ - if (!ValidatePermissionsForPath("client:see:trace",client,acptr,NULL,NULL) || !cnt) + if (!ValidatePermissionsForPath("client:see:trace", client, acptr, NULL, NULL) || !cnt) return; for (cltmp = conf_class; doall && cltmp; cltmp = cltmp->next) - /* if (cltmp->clients > 0) */ - sendnumeric(client, RPL_TRACECLASS, cltmp->name ? cltmp->name : "[noname]", cltmp->clients); + /* if (cltmp->clients > 0) */ + sendnumeric(client, RPL_TRACECLASS, cltmp->name ? cltmp->name : "[noname]", cltmp->clients); } diff --git a/src/modules/tsctl.c b/src/modules/tsctl.c index 39aebf669..cda062ee8 100644 --- a/src/modules/tsctl.c +++ b/src/modules/tsctl.c @@ -20,20 +20,19 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "tsctl", /* Name of module */ - "5.0", /* Version */ - "command /tsctl", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "tsctl", /* Name of module */ + "5.0", /* Version */ + "command /tsctl", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; CMD_FUNC(cmd_tsctl); MOD_INIT() { - CommandAdd(modinfo->handle, "TSCTL", cmd_tsctl, MAXPARA, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, "TSCTL", cmd_tsctl, MAXPARA, CMD_USER | CMD_SERVER); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -50,7 +49,7 @@ MOD_UNLOAD() CMD_FUNC(cmd_tsctl) { - if (!ValidatePermissionsForPath("server:tsctl:view",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:tsctl:view", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -67,7 +66,7 @@ CMD_FUNC(cmd_tsctl) struct timeval currenttime_tv; gettimeofday(¤ttime_tv, NULL); sendnotice(client, "*** Server=%s TStime=%lld.%ld", - me.name, (long long)currenttime_tv.tv_sec, (long)currenttime_tv.tv_usec); + me.name, (long long)currenttime_tv.tv_sec, (long)currenttime_tv.tv_usec); sendto_server(client, 0, 0, NULL, ":%s TSCTL alltime", client->id); return; } diff --git a/src/modules/typing-indicator.c b/src/modules/typing-indicator.c index 76f0320f4..2ce1f5541 100644 --- a/src/modules/typing-indicator.c +++ b/src/modules/typing-indicator.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "typing-indicator", - "5.0", - "+typing client tag", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "typing-indicator", + "5.0", + "+typing client tag", + "UnrealIRCd Team", + "unrealircd-6", +}; int ti_mtag_is_ok(Client *client, const char *name, const char *value); void mtag_add_ti(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature); diff --git a/src/modules/umode2.c b/src/modules/umode2.c index 232d4b306..1b8327035 100644 --- a/src/modules/umode2.c +++ b/src/modules/umode2.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_umode2); -#define MSG_UMODE2 "UMODE2" +#define MSG_UMODE2 "UMODE2" -ModuleHeader MOD_HEADER - = { - "umode2", - "5.0", - "command /umode2", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "umode2", + "5.0", + "command /umode2", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -61,11 +60,11 @@ MOD_UNLOAD() CMD_FUNC(cmd_umode2) { const char *xparv[5] = { - client->name, - client->name, - parv[1], - (parc > 3) ? parv[3] : NULL, - NULL, + client->name, + client->name, + parv[1], + (parc > 3) ? parv[3] : NULL, + NULL, }; if (!parv[1]) diff --git a/src/modules/unreal_server_compat.c b/src/modules/unreal_server_compat.c index e826de5d5..79cfe3039 100644 --- a/src/modules/unreal_server_compat.c +++ b/src/modules/unreal_server_compat.c @@ -27,14 +27,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "unreal_server_compat", - "1.0.0", - "Provides compatibility with non-U6 servers", - "Bram Matthys (Syzop)", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "unreal_server_compat", + "1.0.0", + "Provides compatibility with non-U6 servers", + "Bram Matthys (Syzop)", + "unrealircd-6", +}; /* Forward declarations */ int usc_packet(Client *from, Client *to, Client *intended_to, char **msg, int *length); @@ -170,7 +169,7 @@ int usc_reparse_mode(char **msg, char *p, int *length) if ((pm.modechar == 'b') || (pm.modechar == 'e') || (pm.modechar == 'I')) { const char *result = clean_ban_mask(pm.param, pm.what, mode_letter_to_extbantype(pm.modechar), &me, NULL, 1); // some context lost - strlcat(obuf, result?result:"", sizeof(obuf)); + strlcat(obuf, result ? result : "", sizeof(obuf)); strlcat(obuf, " ", sizeof(obuf)); } else { @@ -186,8 +185,8 @@ int usc_reparse_mode(char **msg, char *p, int *length) return 0; /* Strip final whitespace */ - if (obuf[strlen(obuf)-1] == ' ') - obuf[strlen(obuf)-1] = '\0'; + if (obuf[strlen(obuf) - 1] == ' ') + obuf[strlen(obuf) - 1] = '\0'; if (pm.parabuf && *pm.parabuf) { @@ -196,7 +195,7 @@ int usc_reparse_mode(char **msg, char *p, int *length) } /* Add CRLF */ - if (obuf[strlen(obuf)-1] != '\n') + if (obuf[strlen(obuf) - 1] != '\n') strlcat(obuf, "\r\n", sizeof(obuf)); /* Line modified, use it! */ @@ -245,12 +244,12 @@ int usc_reparse_sjoin(char **msg, char *p, int *length) if (!strchr("&\"'", next[1])) goto fallback_usc_reparse_sjoin; *next++ = '\0'; - result = clean_ban_mask(next+1, MODE_ADD, listmode_sjoin_prefix_to_extbantype(*next), &me, NULL, 1); // some context lost + result = clean_ban_mask(next + 1, MODE_ADD, listmode_sjoin_prefix_to_extbantype(*next), &me, NULL, 1); // some context lost if (!result) { unreal_log(ULOG_WARNING, "unreal_server_compat", "USC_REPARSE_SJOIN_FAILURE", NULL, "[unreal_server_compat] usc_reparse_sjoin(): ban '$ban' could not be converted", - log_data_string("ban", s+1)); + log_data_string("ban", s + 1)); continue; } strlcat(obuf, s, sizeof(obuf)); /* "<123,nick" */ @@ -258,34 +257,34 @@ int usc_reparse_sjoin(char **msg, char *p, int *length) strlncat(obuf, next, sizeof(obuf), 1); /* & or \" or \\ */ strlcat(obuf, result, sizeof(obuf)); /* the converted result */ strlcat(obuf, " ", sizeof(obuf)); - } else - if (strchr("&\"'", *s)) + } else if (strchr("&\"'", *s)) { /* +b / +e / +I */ - const char *result = clean_ban_mask(s+1, MODE_ADD, listmode_sjoin_prefix_to_extbantype(*s), &me, NULL, 1); // some context lost + const char *result = clean_ban_mask(s + 1, MODE_ADD, listmode_sjoin_prefix_to_extbantype(*s), &me, NULL, 1); // some context lost if (!result) { unreal_log(ULOG_WARNING, "unreal_server_compat", "USC_REPARSE_SJOIN_FAILURE", NULL, "[unreal_server_compat] usc_reparse_sjoin(): ban '$ban' could not be converted", - log_data_string("ban", s+1)); + log_data_string("ban", s + 1)); continue; } strlncat(obuf, s, sizeof(obuf), 1); strlcat(obuf, result, sizeof(obuf)); strlcat(obuf, " ", sizeof(obuf)); - } else { -fallback_usc_reparse_sjoin: + } else + { + fallback_usc_reparse_sjoin: strlcat(obuf, s, sizeof(obuf)); strlcat(obuf, " ", sizeof(obuf)); } } /* Strip final whitespace */ - if (obuf[strlen(obuf)-1] == ' ') - obuf[strlen(obuf)-1] = '\0'; + if (obuf[strlen(obuf) - 1] == ' ') + obuf[strlen(obuf) - 1] = '\0'; /* Add CRLF */ - if (obuf[strlen(obuf)-1] != '\n') + if (obuf[strlen(obuf) - 1] != '\n') strlcat(obuf, "\r\n", sizeof(obuf)); /* And use it! */ @@ -298,13 +297,15 @@ fallback_usc_reparse_sjoin: /** Skip space(s), if any. */ void skip_spaces(char **p) { - for (; **p == ' '; *p = *p + 1); + for (; **p == ' '; *p = *p + 1) + ; } /** Keep reading until we hit space. */ void read_until_space(char **p) { - for (; **p && (**p != ' '); *p = *p + 1); + for (; **p && (**p != ' '); *p = *p + 1) + ; } int eat_parameter(char **p) diff --git a/src/modules/unsqline.c b/src/modules/unsqline.c index ed3f7c0a0..8c196e33a 100644 --- a/src/modules/unsqline.c +++ b/src/modules/unsqline.c @@ -22,16 +22,15 @@ CMD_FUNC(cmd_unsqline); -#define MSG_UNSQLINE "UNSQLINE" /* UNSQLINE */ +#define MSG_UNSQLINE "UNSQLINE" /* UNSQLINE */ -ModuleHeader MOD_HEADER - = { - "unsqline", /* Name of module */ - "5.0", /* Version */ - "command /unsqline", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "unsqline", /* Name of module */ + "5.0", /* Version */ + "command /unsqline", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() @@ -59,12 +58,12 @@ MOD_UNLOAD() CMD_FUNC(cmd_unsqline) { const char *tkllayer[6] = { - me.name, /*0 server.name */ - "-", /*1 - */ - "Q", /*2 Q */ - "*", /*3 unused */ - parv[1], /*4 host */ - client->name, /*5 whoremoved */ + me.name, /*0 server.name */ + "-", /*1 - */ + "Q", /*2 Q */ + "*", /*3 unused */ + parv[1], /*4 host */ + client->name, /*5 whoremoved */ }; if (parc < 2) diff --git a/src/modules/user.c b/src/modules/user.c index e0b39a695..316960e74 100644 --- a/src/modules/user.c +++ b/src/modules/user.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_user); -#define MSG_USER "USER" +#define MSG_USER "USER" -ModuleHeader MOD_HEADER - = { - "user", - "5.0", - "command /user", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "user", + "5.0", + "command /user", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -86,9 +85,9 @@ CMD_FUNC(cmd_user) username = parv[1]; realname = parv[4]; - + make_user(client); - + client->user->server = me_hash; strlcpy(client->info, realname, sizeof(client->info)); strlcpy(client->user->username, username, sizeof(client->user->username)); @@ -103,7 +102,7 @@ CMD_FUNC(cmd_user) if (USE_BAN_VERSION && MyConnect(client)) { sendto_one(client, NULL, ":IRC!IRC@%s PRIVMSG %s :\1VERSION\1", - me.name, client->name); + me.name, client->name); } register_user(client); return; diff --git a/src/modules/userhost-tag.c b/src/modules/userhost-tag.c index 26a84a635..19e515647 100644 --- a/src/modules/userhost-tag.c +++ b/src/modules/userhost-tag.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "userhost-tag", - "5.0", - "userhost message tag", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "userhost-tag", + "5.0", + "userhost message tag", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ long CAP_ACCOUNT_TAG = 0L; @@ -89,8 +88,9 @@ void mtag_add_userhost(Client *client, MessageTag *recv_mtags, MessageTag **mtag if (m) { m = duplicate_mtag(m); - } else { - char nuh[USERLEN+HOSTLEN+1]; + } else + { + char nuh[USERLEN + HOSTLEN + 1]; snprintf(nuh, sizeof(nuh), "%s@%s", client->user->username, client->user->realhost); diff --git a/src/modules/userhost.c b/src/modules/userhost.c index 05d4399bd..7a9464141 100644 --- a/src/modules/userhost.c +++ b/src/modules/userhost.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_userhost); -#define MSG_USERHOST "USERHOST" +#define MSG_USERHOST "USERHOST" -ModuleHeader MOD_HEADER - = { - "userhost", - "5.0", - "command /userhost", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "userhost", + "5.0", + "command /userhost", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -62,12 +61,12 @@ MOD_UNLOAD() #define MAXUSERHOSTREPLIES 5 CMD_FUNC(cmd_userhost) { - char *p; /* scratch end pointer */ - char *cn; /* current name */ + char *p; /* scratch end pointer */ + char *cn; /* current name */ Client *acptr; char request[BUFSIZE]; char response[MAXUSERHOSTREPLIES][NICKLEN * 2 + CHANNELLEN + USERLEN + HOSTLEN + 30]; - int i; /* loop counter */ + int i; /* loop counter */ int w; if (parc < 2) @@ -95,15 +94,14 @@ CMD_FUNC(cmd_userhost) if ((acptr = find_user(cn, NULL))) { ircsnprintf(response[w], NICKLEN * 2 + CHANNELLEN + USERLEN + HOSTLEN + 30, - "%s%s=%c%s@%s", - acptr->name, - (IsOper(acptr) && (!IsHideOper(acptr) || client == acptr || IsOper(client))) - ? "*" : "", - (acptr->user->away) ? '-' : '+', - acptr->user->username, - ((acptr != client) && !IsOper(client) - && IsHidden(acptr) ? acptr->user->virthost : - acptr->user->realhost)); + "%s%s=%c%s@%s", + acptr->name, + (IsOper(acptr) && (!IsHideOper(acptr) || client == acptr || IsOper(client))) + ? "*" + : "", + (acptr->user->away) ? '-' : '+', + acptr->user->username, + ((acptr != client) && !IsOper(client) && IsHidden(acptr) ? acptr->user->virthost : acptr->user->realhost)); w++; } if (p) diff --git a/src/modules/userip-tag.c b/src/modules/userip-tag.c index 3fba6b9e9..9e8aaafd2 100644 --- a/src/modules/userip-tag.c +++ b/src/modules/userip-tag.c @@ -22,14 +22,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "userip-tag", - "5.0", - "userip message tag", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "userip-tag", + "5.0", + "userip message tag", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Variables */ long CAP_ACCOUNT_TAG = 0L; @@ -89,8 +88,9 @@ void mtag_add_userip(Client *client, MessageTag *recv_mtags, MessageTag **mtag_l if (m) { m = duplicate_mtag(m); - } else { - char nuh[USERLEN+HOSTLEN+1]; + } else + { + char nuh[USERLEN + HOSTLEN + 1]; snprintf(nuh, sizeof(nuh), "%s@%s", client->user->username, GetIP(client)); diff --git a/src/modules/userip.c b/src/modules/userip.c index 5ca5af60a..c4d13af0b 100644 --- a/src/modules/userip.c +++ b/src/modules/userip.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_userip); -#define MSG_USERIP "USERIP" +#define MSG_USERIP "USERIP" -ModuleHeader MOD_HEADER - = { - "userip", - "5.0", - "command /userip", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "userip", + "5.0", + "command /userip", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -65,18 +64,18 @@ MOD_UNLOAD() CMD_FUNC(cmd_userip) { - char *p; /* scratch end pointer */ - char *cn; /* current name */ - char *ip, ipbuf[HOSTLEN+1]; + char *p; /* scratch end pointer */ + char *cn; /* current name */ + char *ip, ipbuf[HOSTLEN + 1]; Client *acptr; char request[BUFSIZE]; char response[MAXUSERHOSTREPLIES][NICKLEN * 2 + CHANNELLEN + USERLEN + HOSTLEN + 30]; - int i; /* loop counter */ + int i; /* loop counter */ int w; if (!MyUser(client)) return; - + if (parc < 2) { sendnumeric(client, ERR_NEEDMOREPARAMS, "USERIP"); @@ -103,18 +102,19 @@ CMD_FUNC(cmd_userip) { if (!(ip = GetIP(acptr))) ip = ""; - if (client != acptr && !ValidatePermissionsForPath("client:see:ip",client,acptr,NULL,NULL) && IsHidden(acptr)) + if (client != acptr && !ValidatePermissionsForPath("client:see:ip", client, acptr, NULL, NULL) && IsHidden(acptr)) { make_cloakedhost(acptr, GetIP(acptr), ipbuf, sizeof(ipbuf)); ip = ipbuf; } ircsnprintf(response[w], NICKLEN * 2 + CHANNELLEN + USERLEN + HOSTLEN + 30, "%s%s=%c%s@%s", - acptr->name, - (IsOper(acptr) && (!IsHideOper(acptr) || client == acptr || IsOper(client))) - ? "*" : "", - (acptr->user->away) ? '-' : '+', - acptr->user->username, ip); + acptr->name, + (IsOper(acptr) && (!IsHideOper(acptr) || client == acptr || IsOper(client))) + ? "*" + : "", + (acptr->user->away) ? '-' : '+', + acptr->user->username, ip); w++; } if (p) diff --git a/src/modules/usermodes/bot.c b/src/modules/usermodes/bot.c index a15f90fff..5b231ee57 100644 --- a/src/modules/usermodes/bot.c +++ b/src/modules/usermodes/bot.c @@ -19,17 +19,16 @@ #include "unrealircd.h" -#define IsBot(cptr) (cptr->umodes & UMODE_BOT) +#define IsBot(cptr) (cptr->umodes & UMODE_BOT) /* Module header */ -ModuleHeader MOD_HEADER - = { - "usermodes/bot", - "4.2", - "User Mode +B", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/bot", + "4.2", + "User Mode +B", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Global variables */ long UMODE_BOT = 0L; @@ -48,11 +47,11 @@ MOD_INIT() { UmodeAdd(modinfo->handle, 'B', UMODE_GLOBAL, 0, NULL, &UMODE_BOT); ISupportAdd(modinfo->handle, "BOT", "B"); - + HookAdd(modinfo->handle, HOOKTYPE_WHOIS, 0, bot_whois); HookAdd(modinfo->handle, HOOKTYPE_WHO_STATUS, 0, bot_who_status); HookAdd(modinfo->handle, HOOKTYPE_UMODE_CHANGE, 0, bot_umode_change); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -86,7 +85,7 @@ int bot_who_status(Client *client, Client *target, Channel *channel, Member *cm, { if (IsBot(target)) return 'B'; - + return 0; } diff --git a/src/modules/usermodes/censor.c b/src/modules/usermodes/censor.c index 3601e6e01..f4438e6d9 100644 --- a/src/modules/usermodes/censor.c +++ b/src/modules/usermodes/censor.c @@ -6,14 +6,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "usermodes/censor", - "4.2", - "User Mode +G", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/censor", + "4.2", + "User Mode +G", + "UnrealIRCd Team", + "unrealircd-6", +}; long UMODE_CENSOR = 0L; @@ -38,7 +37,7 @@ MOD_TEST() HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, censor_config_test); return MOD_SUCCESS; } - + MOD_INIT() { ModInfo = modinfo; @@ -59,7 +58,7 @@ MOD_LOAD() MOD_UNLOAD() { -ConfigItem_badword *badword, *next; + ConfigItem_badword *badword, *next; for (badword = conf_badword_message; badword; badword = next) { @@ -78,18 +77,18 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (type != CONFIG_MAIN) return 0; - + if (!ce || !ce->name || strcmp(ce->name, "badword")) return 0; /* not interested */ if (!ce->value) { config_error("%s:%i: badword without type", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); *errs = 1; return -1; - } - else if (strcmp(ce->value, "message") && strcmp(ce->value, "all")) { + } else if (strcmp(ce->value, "message") && strcmp(ce->value, "all")) + { /* config_error("%s:%i: badword with unknown type", ce->file->filename, ce->line_number); -- can't do that.. */ return 0; /* unhandled */ @@ -106,36 +105,34 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) const char *errbuf; if (has_word) { - config_warn_duplicate(cep->file->filename, - cep->line_number, "badword::word"); + config_warn_duplicate(cep->file->filename, + cep->line_number, "badword::word"); continue; } has_word = 1; - if ((errbuf = badword_config_check_regex(cep->value,1,1))) + if ((errbuf = badword_config_check_regex(cep->value, 1, 1))) { config_error("%s:%i: badword::%s contains an invalid regex: %s", - cep->file->filename, - cep->line_number, - cep->name, errbuf); + cep->file->filename, + cep->line_number, + cep->name, errbuf); errors++; } - } - else if (!strcmp(cep->name, "replace")) + } else if (!strcmp(cep->name, "replace")) { if (has_replace) { - config_warn_duplicate(cep->file->filename, - cep->line_number, "badword::replace"); + config_warn_duplicate(cep->file->filename, + cep->line_number, "badword::replace"); continue; } has_replace = 1; - } - else if (!strcmp(cep->name, "action")) + } else if (!strcmp(cep->name, "action")) { if (has_action) { - config_warn_duplicate(cep->file->filename, - cep->line_number, "badword::action"); + config_warn_duplicate(cep->file->filename, + cep->line_number, "badword::action"); continue; } has_action = 1; @@ -146,16 +143,15 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) else { config_error("%s:%d: Unknown badword::action '%s'", - cep->file->filename, cep->line_number, - cep->value); + cep->file->filename, cep->line_number, + cep->value); errors++; } - - } - else + + } else { config_error_unknown(cep->file->filename, cep->line_number, - "badword", cep->name); + "badword", cep->name); errors++; } } @@ -163,7 +159,7 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!has_word) { config_error_missing(ce->file->filename, ce->line_number, - "badword::word"); + "badword::word"); errors++; } if (has_action) @@ -171,11 +167,11 @@ int censor_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (has_replace && action == 'b') { config_error("%s:%i: badword::action is block but badword::replace exists", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } } - + *errs = errors; return errors ? -1 : 1; } @@ -188,12 +184,12 @@ int censor_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (type != CONFIG_MAIN) return 0; - + if (!ce || !ce->name || strcmp(ce->name, "badword")) return 0; /* not interested */ if (strcmp(ce->value, "message") && strcmp(ce->value, "all")) - return 0; /* not for us */ + return 0; /* not for us */ ca = safe_alloc(sizeof(ConfigItem_badword)); ca->action = BADWORD_REPLACE; @@ -206,12 +202,10 @@ int censor_config_run(ConfigFile *cf, ConfigEntry *ce, int type) { ca->action = BADWORD_BLOCK; } - } - else if (!strcmp(cep->name, "replace")) + } else if (!strcmp(cep->name, "replace")) { safe_strdup(ca->replace, cep->value); - } - else if (!strcmp(cep->name, "word")) + } else if (!strcmp(cep->name, "word")) { word = cep; } @@ -222,8 +216,7 @@ int censor_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (!strcmp(ce->value, "message")) { AddListItem(ca, conf_badword_message); - } else - if (!strcmp(ce->value, "all")) + } else if (!strcmp(ce->value, "all")) { AddListItem(ca, conf_badword_message); return 0; /* pretend we didn't see it, so other modules can handle 'all' as well */ @@ -264,9 +257,9 @@ int censor_stats_badwords_user(Client *client, const char *para) for (words = conf_badword_message; words; words = words->next) { sendtxtnumeric(client, "m %c %s%s%s %s", words->type & BADW_TYPE_REGEX ? 'R' : 'F', - (words->type & BADW_TYPE_FAST_L) ? "*" : "", words->word, - (words->type & BADW_TYPE_FAST_R) ? "*" : "", - words->action == BADWORD_REPLACE ? (words->replace ? words->replace : "") : ""); + (words->type & BADW_TYPE_FAST_L) ? "*" : "", words->word, + (words->type & BADW_TYPE_FAST_R) ? "*" : "", + words->action == BADWORD_REPLACE ? (words->replace ? words->replace : "") : ""); } return 1; } diff --git a/src/modules/usermodes/noctcp.c b/src/modules/usermodes/noctcp.c index 2303c1e68..e757292bc 100644 --- a/src/modules/usermodes/noctcp.c +++ b/src/modules/usermodes/noctcp.c @@ -21,18 +21,17 @@ CMD_FUNC(noctcp); -ModuleHeader MOD_HEADER - = { - "usermodes/noctcp", - "4.2", - "User Mode +T", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/noctcp", + "4.2", + "User Mode +T", + "UnrealIRCd Team", + "unrealircd-6", +}; long UMODE_NOCTCP = 0L; -#define IsNoCTCP(client) (client->umodes & UMODE_NOCTCP) +#define IsNoCTCP(client) (client->umodes & UMODE_NOCTCP) int noctcp_can_send_to_user(Client *client, Client *target, const char **text, const char **errmsg, SendType sendtype, ClientContext *clictx); @@ -43,12 +42,12 @@ MOD_TEST() MOD_INIT() { -CmodeInfo req; + CmodeInfo req; UmodeAdd(modinfo->handle, 'T', UMODE_GLOBAL, 0, NULL, &UMODE_NOCTCP); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, noctcp_can_send_to_user); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } diff --git a/src/modules/usermodes/nokick.c b/src/modules/usermodes/nokick.c index 688ee3aba..6176fc943 100644 --- a/src/modules/usermodes/nokick.c +++ b/src/modules/usermodes/nokick.c @@ -19,17 +19,16 @@ #include "unrealircd.h" -#define IsNokick(client) (client->umodes & UMODE_NOKICK) +#define IsNokick(client) (client->umodes & UMODE_NOKICK) /* Module header */ -ModuleHeader MOD_HEADER - = { - "usermodes/nokick", - "4.2", - "User Mode +q", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/nokick", + "4.2", + "User Mode +q", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Global variables */ long UMODE_NOKICK = 0L; @@ -47,9 +46,9 @@ MOD_TEST() MOD_INIT() { UmodeAdd(modinfo->handle, 'q', UMODE_GLOBAL, 1, umode_allow_unkickable_oper, &UMODE_NOKICK); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_KICK, 0, nokick_can_kick); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -68,7 +67,7 @@ int umode_allow_unkickable_oper(Client *client, int what) { if (MyUser(client)) { - if (IsOper(client) && ValidatePermissionsForPath("self:unkickablemode",client,NULL,NULL,NULL)) + if (IsOper(client) && ValidatePermissionsForPath("self:unkickablemode", client, NULL, NULL, NULL)) return 1; return 0; } @@ -79,20 +78,20 @@ int umode_allow_unkickable_oper(Client *client, int what) int nokick_can_kick(Client *client, Client *target, Channel *channel, const char *comment, const char *client_member_modes, const char *target_member_modes, const char **reject_reason) { - static char errmsg[NICKLEN+256]; + static char errmsg[NICKLEN + 256]; - if (IsNokick(target) && !IsULine(client) && MyUser(client) && !ValidatePermissionsForPath("channel:override:kick:nokick",client,target,channel,NULL)) + if (IsNokick(target) && !IsULine(client) && MyUser(client) && !ValidatePermissionsForPath("channel:override:kick:nokick", client, target, channel, NULL)) { ircsnprintf(errmsg, sizeof(errmsg), ":%s %d %s %s :%s", me.name, ERR_CANNOTDOCOMMAND, client->name, "KICK", - "user is unkickable (user mode +q)"); + "user is unkickable (user mode +q)"); *reject_reason = errmsg; sendnotice(target, - "*** umode q: %s tried to kick you from channel %s (%s)", - client->name, channel->name, comment); - + "*** umode q: %s tried to kick you from channel %s (%s)", + client->name, channel->name, comment); + return EX_ALWAYS_DENY; } diff --git a/src/modules/usermodes/privacy.c b/src/modules/usermodes/privacy.c index 3b43df063..127fc3c24 100644 --- a/src/modules/usermodes/privacy.c +++ b/src/modules/usermodes/privacy.c @@ -19,30 +19,29 @@ #include "unrealircd.h" -#define IsPrivacy(client) (client->umodes & UMODE_PRIVACY) +#define IsPrivacy(client) (client->umodes & UMODE_PRIVACY) /* Module header */ -ModuleHeader MOD_HEADER - = { - "usermodes/privacy", - "4.2", - "User Mode +p", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/privacy", + "4.2", + "User Mode +p", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Global variables */ long UMODE_PRIVACY = 0L; /* Forward declarations */ int privacy_see_channel_in_whois(Client *client, Client *target, Channel *channel); - + MOD_INIT() { UmodeAdd(modinfo->handle, 'p', UMODE_GLOBAL, 0, umode_allow_all, &UMODE_PRIVACY); - + HookAdd(modinfo->handle, HOOKTYPE_SEE_CHANNEL_IN_WHOIS, 0, privacy_see_channel_in_whois); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -64,6 +63,6 @@ int privacy_see_channel_in_whois(Client *client, Client *target, Channel *channe { if (IsPrivacy(target) && !IsMember(client, channel)) return EX_DENY; - + return EX_ALLOW; } diff --git a/src/modules/usermodes/privdeaf.c b/src/modules/usermodes/privdeaf.c index 097422986..292b0dfcf 100644 --- a/src/modules/usermodes/privdeaf.c +++ b/src/modules/usermodes/privdeaf.c @@ -5,13 +5,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "usermodes/privdeaf", - "1.2", - "Private Messages Deaf (+D) -- by Syzop", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "usermodes/privdeaf", + "1.2", + "Private Messages Deaf (+D) -- by Syzop", + "UnrealIRCd Team", + "unrealircd-6", }; static long UMODE_PRIVDEAF = 0; @@ -31,8 +30,8 @@ MOD_INIT() config_error("privdeaf: Could not add usermode 'D': %s", ModuleGetErrorStr(modinfo->handle)); return MOD_FAILED; } - - HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, privdeaf_can_send_to_user); + + HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, privdeaf_can_send_to_user); return MOD_SUCCESS; } diff --git a/src/modules/usermodes/regonlymsg.c b/src/modules/usermodes/regonlymsg.c index d0fbcd22c..606e60ea0 100644 --- a/src/modules/usermodes/regonlymsg.c +++ b/src/modules/usermodes/regonlymsg.c @@ -19,30 +19,29 @@ #include "unrealircd.h" -#define IsRegOnlyMsg(client) (client->umodes & UMODE_REGONLYMSG) +#define IsRegOnlyMsg(client) (client->umodes & UMODE_REGONLYMSG) /* Module header */ -ModuleHeader MOD_HEADER - = { - "usermodes/regonlymsg", - "4.2", - "User Mode +R", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/regonlymsg", + "4.2", + "User Mode +R", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Global variables */ long UMODE_REGONLYMSG = 0L; /* Forward declarations */ int regonlymsg_can_send_to_user(Client *client, Client *target, const char **text, const char **errmsg, SendType sendtype, ClientContext *clictx); - + MOD_INIT() { UmodeAdd(modinfo->handle, 'R', UMODE_GLOBAL, 0, umode_allow_all, &UMODE_REGONLYMSG); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, regonlymsg_can_send_to_user); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -61,7 +60,7 @@ int regonlymsg_can_send_to_user(Client *client, Client *target, const char **tex { if (IsRegOnlyMsg(target) && !IsServer(client) && !IsULine(client) && !IsLoggedIn(client)) { - if (ValidatePermissionsForPath("client:override:message:regonlymsg",client,target,NULL,text?*text:NULL)) + if (ValidatePermissionsForPath("client:override:message:regonlymsg", client, target, NULL, text ? *text : NULL)) return HOOK_CONTINUE; /* bypass this restriction */ if (sendtype != SEND_TYPE_TAGMSG) diff --git a/src/modules/usermodes/secureonlymsg.c b/src/modules/usermodes/secureonlymsg.c index 293bca41c..78cada9a4 100644 --- a/src/modules/usermodes/secureonlymsg.c +++ b/src/modules/usermodes/secureonlymsg.c @@ -20,30 +20,29 @@ #include "unrealircd.h" -#define IsSecureOnlyMsg(client) (client->umodes & UMODE_SECUREONLYMSG) +#define IsSecureOnlyMsg(client) (client->umodes & UMODE_SECUREONLYMSG) /* Module header */ -ModuleHeader MOD_HEADER - = { - "usermodes/secureonlymsg", - "4.2", - "User Mode +Z", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/secureonlymsg", + "4.2", + "User Mode +Z", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Global variables */ long UMODE_SECUREONLYMSG = 0L; /* Forward declarations */ int secureonlymsg_can_send_to_user(Client *client, Client *target, const char **text, const char **errmsg, SendType sendtype, ClientContext *clictx); - + MOD_INIT() { UmodeAdd(modinfo->handle, 'Z', UMODE_GLOBAL, 0, umode_allow_all, &UMODE_SECUREONLYMSG); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, secureonlymsg_can_send_to_user); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -62,17 +61,16 @@ int secureonlymsg_can_send_to_user(Client *client, Client *target, const char ** { if (IsSecureOnlyMsg(target) && !IsServer(client) && !IsULine(client) && !IsSecureConnect(client)) { - if (ValidatePermissionsForPath("client:override:message:secureonlymsg",client,target,NULL,text?*text:NULL)) + if (ValidatePermissionsForPath("client:override:message:secureonlymsg", client, target, NULL, text ? *text : NULL)) return HOOK_CONTINUE; /* bypass this restriction */ *errmsg = "You must be connected via TLS to message this user"; return HOOK_DENY; - } else - if (IsSecureOnlyMsg(client) && !IsSecureConnect(target) && !IsULine(target)) + } else if (IsSecureOnlyMsg(client) && !IsSecureConnect(target) && !IsULine(target)) { - if (ValidatePermissionsForPath("client:override:message:secureonlymsg",client,target,NULL,text?*text:NULL)) + if (ValidatePermissionsForPath("client:override:message:secureonlymsg", client, target, NULL, text ? *text : NULL)) return HOOK_CONTINUE; /* bypass this restriction */ - + /* Similar to above but in this case we are +Z and are trying to message * a secure user (who does not have +Z set, note the 'else'). This does not * make sense since they could never message back to us. Better block the diff --git a/src/modules/usermodes/servicebot.c b/src/modules/usermodes/servicebot.c index 8c7526c5b..4d3e67500 100644 --- a/src/modules/usermodes/servicebot.c +++ b/src/modules/usermodes/servicebot.c @@ -19,30 +19,29 @@ #include "unrealircd.h" -#define IsServiceBot(client) (client->umodes & UMODE_SERVICEBOT) +#define IsServiceBot(client) (client->umodes & UMODE_SERVICEBOT) /* Module header */ -ModuleHeader MOD_HEADER - = { - "usermodes/servicebot", - "4.2", - "User Mode +S", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/servicebot", + "4.2", + "User Mode +S", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Global variables */ long UMODE_SERVICEBOT = 0L; /* Forward declarations */ int servicebot_can_kick(Client *client, Client *target, Channel *channel, - const char *comment, const char *client_member_modes, const char *target_member_modes, const char **reject_reason); + const char *comment, const char *client_member_modes, const char *target_member_modes, const char **reject_reason); int servicebot_mode_deop(Client *client, Client *target, Channel *channel, - u_int what, int modechar, const char *client_access, const char *target_access, const char **reject_reason); + u_int what, int modechar, const char *client_access, const char *target_access, const char **reject_reason); int servicebot_pre_kill(Client *client, Client *target, const char *reason); int servicebot_whois(Client *requester, Client *acptr, NameValuePrioList **list); int servicebot_see_channel_in_whois(Client *client, Client *target, Channel *channel); - + MOD_TEST() { return MOD_SUCCESS; @@ -51,13 +50,13 @@ MOD_TEST() MOD_INIT() { UmodeAdd(modinfo->handle, 'S', UMODE_GLOBAL, 1, umode_allow_none, &UMODE_SERVICEBOT); - + HookAdd(modinfo->handle, HOOKTYPE_CAN_KICK, 0, servicebot_can_kick); HookAdd(modinfo->handle, HOOKTYPE_MODE_DEOP, 0, servicebot_mode_deop); HookAdd(modinfo->handle, HOOKTYPE_PRE_KILL, 0, servicebot_pre_kill); HookAdd(modinfo->handle, HOOKTYPE_WHOIS, 0, servicebot_whois); HookAdd(modinfo->handle, HOOKTYPE_SEE_CHANNEL_IN_WHOIS, 0, servicebot_see_channel_in_whois); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -73,15 +72,15 @@ MOD_UNLOAD() } int servicebot_can_kick(Client *client, Client *target, Channel *channel, const char *comment, - const char *client_member_modes, const char *target_member_modes, const char **reject_reason) + const char *client_member_modes, const char *target_member_modes, const char **reject_reason) { - static char errmsg[NICKLEN+256]; + static char errmsg[NICKLEN + 256]; if (MyUser(client) && !IsULine(client) && IsServiceBot(target)) { - char errmsg2[NICKLEN+32]; + char errmsg2[NICKLEN + 32]; snprintf(errmsg2, sizeof(errmsg2), "%s is a Service Bot", target->name); - + snprintf(errmsg, sizeof(errmsg), ":%s %d %s %s :%s", me.name, ERR_CANNOTDOCOMMAND, client->name, "KICK", errmsg2); @@ -94,26 +93,26 @@ int servicebot_can_kick(Client *client, Client *target, Channel *channel, const } int servicebot_mode_deop(Client *client, Client *target, Channel *channel, - u_int what, int modechar, const char *client_access, const char *target_access, const char **reject_reason) + u_int what, int modechar, const char *client_access, const char *target_access, const char **reject_reason) { - static char errmsg[NICKLEN+256]; - - if (IsServiceBot(target) && MyUser(client) && !ValidatePermissionsForPath("services:servicebot:deop",client,target,channel,NULL) && (what == MODE_DEL)) + static char errmsg[NICKLEN + 256]; + + if (IsServiceBot(target) && MyUser(client) && !ValidatePermissionsForPath("services:servicebot:deop", client, target, channel, NULL) && (what == MODE_DEL)) { snprintf(errmsg, sizeof(errmsg), ":%s %d %s %c :%s is a Service Bot", - me.name, ERR_CANNOTCHANGECHANMODE, client->name, (char)modechar, target->name); - + me.name, ERR_CANNOTCHANGECHANMODE, client->name, (char)modechar, target->name); + *reject_reason = errmsg; - + return EX_DENY; } - + return EX_ALLOW; } int servicebot_pre_kill(Client *client, Client *target, const char *reason) { - if (IsServiceBot(target) && !(ValidatePermissionsForPath("services:servicebot:kill",client,target,NULL,NULL) || IsULine(client))) + if (IsServiceBot(target) && !(ValidatePermissionsForPath("services:servicebot:kill", client, target, NULL, NULL) || IsULine(client))) { sendnumeric(client, ERR_KILLDENY, target->name); return EX_ALWAYS_DENY; @@ -139,6 +138,6 @@ int servicebot_see_channel_in_whois(Client *client, Client *target, Channel *cha { if (IsServiceBot(target)) return EX_DENY; - + return EX_ALLOW; } diff --git a/src/modules/usermodes/showwhois.c b/src/modules/usermodes/showwhois.c index 74d426a29..1101f3a77 100644 --- a/src/modules/usermodes/showwhois.c +++ b/src/modules/usermodes/showwhois.c @@ -19,17 +19,16 @@ #include "unrealircd.h" -#define IsWhois(cptr) (cptr->umodes & UMODE_SHOWWHOIS) +#define IsWhois(cptr) (cptr->umodes & UMODE_SHOWWHOIS) /* Module header */ -ModuleHeader MOD_HEADER - = { - "usermodes/showwhois", - "4.2", - "User Mode +W", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/showwhois", + "4.2", + "User Mode +W", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Global variables */ long UMODE_SHOWWHOIS = 0L; @@ -45,9 +44,9 @@ MOD_TEST() MOD_INIT() { UmodeAdd(modinfo->handle, 'W', UMODE_GLOBAL, 1, umode_allow_opers, &UMODE_SHOWWHOIS); - + HookAdd(modinfo->handle, HOOKTYPE_WHOIS, 0, showwhois_whois); - + MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS; } @@ -67,9 +66,9 @@ int showwhois_whois(Client *requester, Client *target, NameValuePrioList **list) if (IsWhois(target) && (requester != target)) { sendnotice(target, - "*** %s (%s@%s) did a /whois on you.", - requester->name, - requester->user->username, requester->user->realhost); + "*** %s (%s@%s) did a /whois on you.", + requester->name, + requester->user->username, requester->user->realhost); } return 0; diff --git a/src/modules/usermodes/wallops.c b/src/modules/usermodes/wallops.c index 91b715fe0..b210ad0b9 100644 --- a/src/modules/usermodes/wallops.c +++ b/src/modules/usermodes/wallops.c @@ -24,23 +24,22 @@ CMD_FUNC(cmd_wallops); -#define MSG_WALLOPS "WALLOPS" +#define MSG_WALLOPS "WALLOPS" -ModuleHeader MOD_HEADER - = { - "usermodes/wallops", - "5.0", - "command /wallops", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "usermodes/wallops", + "5.0", + "command /wallops", + "UnrealIRCd Team", + "unrealircd-6", +}; long UMODE_WALLOP = 0L; /* send wallops to them */ MOD_INIT() { MARK_AS_OFFICIAL_MODULE(modinfo); - CommandAdd(modinfo->handle, MSG_WALLOPS, cmd_wallops, 1, CMD_USER|CMD_SERVER); + CommandAdd(modinfo->handle, MSG_WALLOPS, cmd_wallops, 1, CMD_USER | CMD_SERVER); UmodeAdd(modinfo->handle, 'w', UMODE_GLOBAL, 0, umode_allow_all, &UMODE_WALLOP); return MOD_SUCCESS; } @@ -55,7 +54,7 @@ MOD_UNLOAD() return MOD_SUCCESS; } -#define SendWallops(x) (!IsMe(x) && IsUser(x) && ((x)->umodes & UMODE_WALLOP)) +#define SendWallops(x) (!IsMe(x) && IsUser(x) && ((x)->umodes & UMODE_WALLOP)) /** Send a message to all wallops, except one. * @param one Skip sending the message to this client/direction @@ -73,10 +72,10 @@ void sendto_wallops(Client *one, Client *from, FORMAT_STRING(const char *pattern { if (!SendWallops(acptr)) continue; - if (acptr->direction->local->serial == current_serial) /* sent message along it already ? */ + if (acptr->direction->local->serial == current_serial) /* sent message along it already ? */ continue; if (acptr->direction == one) - continue; /* ...was the one I should skip */ + continue; /* ...was the one I should skip */ acptr->direction->local->serial = current_serial; va_start(vl, pattern); @@ -99,7 +98,7 @@ CMD_FUNC(cmd_wallops) return; } - if (!ValidatePermissionsForPath("chat:wallops",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("chat:wallops", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; diff --git a/src/modules/utf8functions.c b/src/modules/utf8functions.c index 6eac97f1b..5b3f6251d 100644 --- a/src/modules/utf8functions.c +++ b/src/modules/utf8functions.c @@ -9,13 +9,12 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER -= { - "utf8functions", - "1.0.1", - "UTF8 helper functions", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "utf8functions", + "1.0.1", + "UTF8 helper functions", + "UnrealIRCd Team", + "unrealircd-6", }; typedef struct UnicodeBlocks { @@ -5578,7 +5577,7 @@ ConfusablesConversionTable confusables_table[] = }; /* clang-format on */ -#define IS_IN_RANGE(c, f, l) (((c) >= (f)) && ((c) <= (l))) +#define IS_IN_RANGE(c, f, l) (((c) >= (f)) && ((c) <= (l))) #define SCRIPT_UNDEFINED -1 @@ -5640,24 +5639,21 @@ uint32_t utf8_to_utf32(const char *t, int *bytes) *bytes = 1; c1 = ptr[0]; - if( (c1 & 0x80) == 0 ) + if ((c1 & 0x80) == 0) { - uc = (u_long) (c1 & 0x7F); + uc = (u_long)(c1 & 0x7F); seqlen = 1; - } - else if( (c1 & 0xE0) == 0xC0 ) + } else if ((c1 & 0xE0) == 0xC0) { - uc = (u_long) (c1 & 0x1F); + uc = (u_long)(c1 & 0x1F); seqlen = 2; - } - else if( (c1 & 0xF0) == 0xE0 ) + } else if ((c1 & 0xF0) == 0xE0) { - uc = (u_long) (c1 & 0x0F); + uc = (u_long)(c1 & 0x0F); seqlen = 3; - } - else if( (c1 & 0xF8) == 0xF0 ) + } else if ((c1 & 0xF8) == 0xF0) { - uc = (u_long) (c1 & 0x07); + uc = (u_long)(c1 & 0x07); seqlen = 4; } else return -1; /* should be impossible */ @@ -5666,17 +5662,17 @@ uint32_t utf8_to_utf32(const char *t, int *bytes) { c1 = ptr[i]; - if( (c1 & 0xC0) != 0x80 ) + if ((c1 & 0xC0) != 0x80) return 0; /* Invalid UTF8 */ } - switch( seqlen ) + switch (seqlen) { case 2: { c1 = ptr[0]; - if( !IS_IN_RANGE(c1, 0xC2, 0xDF) ) + if (!IS_IN_RANGE(c1, 0xC2, 0xDF)) return 0; /* Invalid UTF8 */ break; @@ -5745,26 +5741,30 @@ uint32_t utf8_to_utf32(const char *t, int *bytes) int utf32_to_utf8(char *buf, uint32_t code) { - if (code <= 0x7F) { + if (code <= 0x7F) + { buf[0] = code; return 1; } - if (code <= 0x7FF) { - buf[0] = 0xC0 | (code >> 6); /* 110xxxxx */ - buf[1] = 0x80 | (code & 0x3F); /* 10xxxxxx */ + if (code <= 0x7FF) + { + buf[0] = 0xC0 | (code >> 6); /* 110xxxxx */ + buf[1] = 0x80 | (code & 0x3F); /* 10xxxxxx */ return 2; } - if (code <= 0xFFFF) { - buf[0] = 0xE0 | (code >> 12); /* 1110xxxx */ + if (code <= 0xFFFF) + { + buf[0] = 0xE0 | (code >> 12); /* 1110xxxx */ buf[1] = 0x80 | ((code >> 6) & 0x3F); /* 10xxxxxx */ - buf[2] = 0x80 | (code & 0x3F); /* 10xxxxxx */ + buf[2] = 0x80 | (code & 0x3F); /* 10xxxxxx */ return 3; } - if (code <= 0x10FFFF) { - buf[0] = 0xF0 | (code >> 18); /* 11110xxx */ + if (code <= 0x10FFFF) + { + buf[0] = 0xF0 | (code >> 18); /* 11110xxx */ buf[1] = 0x80 | ((code >> 12) & 0x3F); /* 10xxxxxx */ buf[2] = 0x80 | ((code >> 6) & 0x3F); /* 10xxxxxx */ - buf[3] = 0x80 | (code & 0x3F); /* 10xxxxxx */ + buf[3] = 0x80 | (code & 0x3F); /* 10xxxxxx */ return 4; } return 0; @@ -5795,7 +5795,7 @@ int detect_script(uint32_t utfchar) return SCRIPT_UNDEFINED; } - for (i=0; i < elementsof(unicode_blocks); i++) + for (i = 0; i < elementsof(unicode_blocks); i++) { if ((utfchar >= unicode_blocks[i].start) && (utfchar <= unicode_blocks[i].end)) @@ -5906,8 +5906,11 @@ int utf8_text_analysis(Client *client, const char *text, TextAnalysis *e) */ static int utf8_charlen(const char *str) { - struct { char mask; char val; } t[4] = - { { 0x80, 0x00 }, { 0xE0, 0xC0 }, { 0xF0, 0xE0 }, { 0xF8, 0xF0 } }; + struct { + char mask; + char val; + } t[4] = + {{0x80, 0x00}, {0xE0, 0xC0}, {0xF0, 0xE0}, {0xF8, 0xF0}}; unsigned k, j; for (k = 0; k < 4; k++) @@ -5928,17 +5931,18 @@ static int utf8_charlen(const char *str) uint32_t utf8_lookup_confusable(uint32_t c) { int start = 0; - int stop = ARRAY_SIZEOF(confusables_table)-1; + int stop = ARRAY_SIZEOF(confusables_table) - 1; int mid; - while (start <= stop) { - mid = (start+stop)/2; + while (start <= stop) + { + mid = (start + stop) / 2; if (c < confusables_table[mid].from) - stop = mid-1; + stop = mid - 1; else if (c == confusables_table[mid].from) return confusables_table[mid].to; else - start = mid+1; + start = mid + 1; } return 0; } @@ -5969,10 +5973,11 @@ char *_utf8_convert_confusables(const char *i, char *obuf, int olen) /* use as-is */ if (olen < utf8charlen) break; /* cut off */ - for (x=0; x < utf8charlen; x++) + for (x = 0; x < utf8charlen; x++) *o++ = i[x]; olen -= utf8charlen; - } else { + } else + { /* convert */ int replacelen; if (olen < 4) // yeah too lazy to lookup replacelen in advance :D @@ -5990,7 +5995,7 @@ char *_utf8_convert_confusables(const char *i, char *obuf, int olen) /** Get UTF8 name for a block number (eg 0 returns "Basic Latin") */ const char *_utf8_get_block_name(int i) { - if ((i < 0) || (i > ARRAY_SIZEOF(unicode_blocks)-1)) + if ((i < 0) || (i > ARRAY_SIZEOF(unicode_blocks) - 1)) return NULL; return unicode_blocks[i].name; } diff --git a/src/modules/utf8only.c b/src/modules/utf8only.c index 5cc7e6367..671f84948 100644 --- a/src/modules/utf8only.c +++ b/src/modules/utf8only.c @@ -6,14 +6,13 @@ #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "utf8only", - "1.0.0", - "only allow UTF8 traffic on IRC (UTF8ONLY)", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "utf8only", + "1.0.0", + "only allow UTF8 traffic on IRC (UTF8ONLY)", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Forward declarations */ int utf8only_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs); @@ -110,12 +109,15 @@ const char *parse_get_command(const char *msg) static char cmd[64]; /* Skip whitespace at beginning of the line */ - for (; *p == ' '; p++); + for (; *p == ' '; p++) + ; /* Skip message tags (if any) */ if (*p == '@') { - for (p++; *p && (*p != ' '); p++); - for (; *p == ' '; p++); + for (p++; *p && (*p != ' '); p++) + ; + for (; *p == ' '; p++) + ; } if (*p) @@ -128,7 +130,8 @@ const char *parse_get_command(const char *msg) sz--; } *o++ = '\0'; - } else { + } else + { strlcpy(cmd, "*", sizeof(cmd)); } @@ -159,7 +162,8 @@ int utf8only_packet(Client *from, Client *to, Client *intended_to, char **msg, i *length = strlen(*msg); /* Needs to be recalculated */ } return 0; - } else if (IsUser(from)) { + } else if (IsUser(from)) + { /* Connected user: be strict */ if (!unrl_utf8_validate(*msg, NULL)) { diff --git a/src/modules/vhost.c b/src/modules/vhost.c index 42c2f55ed..5c9249d87 100644 --- a/src/modules/vhost.c +++ b/src/modules/vhost.c @@ -20,28 +20,27 @@ #include "unrealircd.h" /* Defines */ -#define MSG_VHOST "VHOST" +#define MSG_VHOST "VHOST" /* Structs */ -ModuleHeader MOD_HEADER - = { - "vhost", - "6.1.8.1", - "command /VHOST and vhost { } blocks", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "vhost", + "6.1.8.1", + "command /VHOST and vhost { } blocks", + "UnrealIRCd Team", + "unrealircd-6", +}; typedef struct ConfigItem_vhost ConfigItem_vhost; struct ConfigItem_vhost { ConfigItem_vhost *prev, *next; - int auto_login; /**< Auto-login users on connect? If they match 'auth' */ + int auto_login; /**< Auto-login users on connect? If they match 'auth' */ SecurityGroup *match; /**< Match criteria for user */ char *login; /**< Login name for 'VHOST login pass' */ - AuthConfig *auth; /**< Password for 'VHOST login pass */ - char *virtuser; /**< Virtual ident to set */ + AuthConfig *auth; /**< Password for 'VHOST login pass */ + char *virtuser; /**< Virtual ident to set */ char *virthost; /**< Virtual host to set */ - SWhois *swhois; /**< SWhois items to set */ + SWhois *swhois; /**< SWhois items to set */ }; /* Variables */ @@ -130,15 +129,14 @@ int vhost_config_test(ConfigFile *conf, ConfigEntry *ce, int type, int *errs) if (!strcmp(cep->name, "auto-login")) { has_auto_login = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "vhost")) + } else if (!strcmp(cep->name, "vhost")) { char *at, *tmp, *host, *p; config_detect_duplicate(&has_vhost, cep, &errors); if (!cep->value) { config_error_empty(cep->file->filename, - cep->line_number, "vhost", "vhost"); + cep->line_number, "vhost", "vhost"); errors++; continue; } @@ -148,52 +146,46 @@ int vhost_config_test(ConfigFile *conf, ConfigEntry *ce, int type, int *errs) * original cep->value and not on fakehost. */ config_error("%s:%i: vhost::vhost contains illegal characters or is too long: '%s'", - cep->file->filename, cep->line_number, cep->value); + cep->file->filename, cep->line_number, cep->value); errors++; } - } - else if (!strcmp(cep->name, "login")) + } else if (!strcmp(cep->name, "login")) { config_detect_duplicate(&has_login, cep, &errors); if (!cep->value) { config_error_empty(cep->file->filename, - cep->line_number, "vhost", "login"); + cep->line_number, "vhost", "login"); errors++; continue; } - } - else if (!strcmp(cep->name, "password")) + } else if (!strcmp(cep->name, "password")) { config_detect_duplicate(&has_password, cep, &errors); if (!cep->value) { config_error_empty(cep->file->filename, - cep->line_number, "vhost", "password"); + cep->line_number, "vhost", "password"); errors++; continue; } if (Auth_CheckError(cep, 0) < 0) errors++; - } - else if (!strcmp(cep->name, "mask")) + } else if (!strcmp(cep->name, "mask")) { has_mask = 1; test_match_block(conf, cep, &errors); - } - else if (!strcmp(cep->name, "match")) + } else if (!strcmp(cep->name, "match")) { has_match = 1; test_match_block(conf, cep, &errors); - } - else if (!strcmp(cep->name, "swhois")) + } else if (!strcmp(cep->name, "swhois")) { /* multiple is ok */ - } - else + } else { config_error_unknown(cep->file->filename, cep->line_number, - "vhost", cep->name); + "vhost", cep->name); errors++; } } @@ -201,7 +193,7 @@ int vhost_config_test(ConfigFile *conf, ConfigEntry *ce, int type, int *errs) if (!has_vhost) { config_error_missing(ce->file->filename, ce->line_number, - "vhost::vhost"); + "vhost::vhost"); errors++; } @@ -210,14 +202,13 @@ int vhost_config_test(ConfigFile *conf, ConfigEntry *ce, int type, int *errs) if (!has_login) { config_error_missing(ce->file->filename, ce->line_number, - "vhost::login"); + "vhost::login"); errors++; - } if (!has_password) { config_error_missing(ce->file->filename, ce->line_number, - "vhost::password"); + "vhost::password"); errors++; } } @@ -225,7 +216,7 @@ int vhost_config_test(ConfigFile *conf, ConfigEntry *ce, int type, int *errs) if (!has_mask && !has_match) { config_error_missing(ce->file->filename, ce->line_number, - "vhost::match"); + "vhost::match"); errors++; } if (has_mask && has_match) @@ -265,8 +256,7 @@ int vhost_config_run(ConfigFile *conf, ConfigEntry *ce, int type) if (!strcmp(cep->name, "auto-login")) { vhost->auto_login = config_checkval(cep->value, CFG_YESNO); - } - else if (!strcmp(cep->name, "vhost")) + } else if (!strcmp(cep->name, "vhost")) { char *user, *host; user = strtok(cep->value, "@"); @@ -278,16 +268,14 @@ int vhost_config_run(ConfigFile *conf, ConfigEntry *ce, int type) safe_strdup(vhost->virtuser, user); safe_strdup(vhost->virthost, host); } - } - else if (!strcmp(cep->name, "login")) + } else if (!strcmp(cep->name, "login")) safe_strdup(vhost->login, cep->value); else if (!strcmp(cep->name, "password")) AuthBlockToAuthConfig(cep, &vhost->auth); else if (!strcmp(cep->name, "match") || !strcmp(cep->name, "mask")) { conf_match_block(conf, cep, &vhost->match); - } - else if (!strcmp(cep->name, "swhois")) + } else if (!strcmp(cep->name, "swhois")) { SWhois *s; if (cep->items) @@ -299,8 +287,7 @@ int vhost_config_run(ConfigFile *conf, ConfigEntry *ce, int type) safe_strdup(s->setby, "vhost"); AddListItem(s, vhost->swhois); } - } else - if (cep->value) + } else if (cep->value) { s = safe_alloc(sizeof(SWhois)); safe_strdup(s->line, cep->value); @@ -338,7 +325,6 @@ static int stats_vhost(Client *client, const char *flag) } - ConfigItem_vhost *find_vhost(const char *name) { ConfigItem_vhost *vhost; @@ -353,7 +339,7 @@ ConfigItem_vhost *find_vhost(const char *name) CMD_FUNC(cmd_vhost) { ConfigItem_vhost *vhost; - char login[HOSTLEN+1]; + char login[HOSTLEN + 1]; const char *password; if (!MyUser(client)) @@ -363,7 +349,6 @@ CMD_FUNC(cmd_vhost) { sendnumeric(client, ERR_NEEDMOREPARAMS, "VHOST"); return; - } /* cut-off too long login names. HOSTLEN is arbitrary, we just don't want our @@ -436,8 +421,8 @@ CMD_FUNC(cmd_vhost) void do_vhost(Client *client, ConfigItem_vhost *vhost) { - char olduser[USERLEN+1]; - char newhost[HOSTLEN+1]; + char olduser[USERLEN + 1]; + char newhost[HOSTLEN + 1]; /* There are various IsUser() checks in the code below, that is because * this code is also called for CLIENT_STATUS_UNKNOWN users in the handshake @@ -488,9 +473,9 @@ void do_vhost(Client *client, ConfigItem_vhost *vhost) if (IsUser(client)) { sendnotice(client, "*** Your vhost is now %s%s%s", - vhost->virtuser ? vhost->virtuser : "", - vhost->virtuser ? "@" : "", - newhost); + vhost->virtuser ? vhost->virtuser : "", + vhost->virtuser ? "@" : "", + newhost); } /* Only notify on logins, not on auto logins (should we make that configurable?) @@ -503,16 +488,17 @@ void do_vhost(Client *client, ConfigItem_vhost *vhost) { /* virtuser@virthost */ unreal_log(ULOG_INFO, "vhost", "VHOST_SUCCESS", client, - "$client.details is now using vhost $virtuser@$virthost [vhost-block: $vhost_block]", - log_data_string("virtuser", vhost->virtuser), - log_data_string("virthost", newhost), - log_data_string("vhost_block", vhost->login)); - } else { + "$client.details is now using vhost $virtuser@$virthost [vhost-block: $vhost_block]", + log_data_string("virtuser", vhost->virtuser), + log_data_string("virthost", newhost), + log_data_string("vhost_block", vhost->login)); + } else + { /* just virthost */ unreal_log(ULOG_INFO, "vhost", "VHOST_SUCCESS", client, - "$client.details is now using vhost $virthost [vhost-block: $vhost_block]", - log_data_string("virthost", newhost), - log_data_string("vhost_block", vhost->login)); + "$client.details is now using vhost $virthost [vhost-block: $vhost_block]", + log_data_string("virthost", newhost), + log_data_string("vhost_block", vhost->login)); } } diff --git a/src/modules/watch-backend.c b/src/modules/watch-backend.c index 970404502..b2ee93d0b 100644 --- a/src/modules/watch-backend.c +++ b/src/modules/watch-backend.c @@ -25,7 +25,7 @@ #define WATCH_HASH_TABLE_SIZE 32768 #define WATCHES(client) (moddata_local_client(client, watchCounterMD).i) -#define WATCH(client) (moddata_local_client(client, watchListMD).ptr) +#define WATCH(client) (moddata_local_client(client, watchListMD).ptr) ModDataInfo *watchCounterMD; ModDataInfo *watchListMD; @@ -44,13 +44,12 @@ int _watch_del(const char *nick, Client *client, int flags); int _watch_del_list(Client *client, int flags); uint64_t hash_watch_nick_name(const char *name); -ModuleHeader MOD_HEADER -= { - "watch-backend", - "6.0.3", - "backend for /WATCH", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "watch-backend", + "6.0.3", + "backend for /WATCH", + "UnrealIRCd Team", + "unrealircd-6", }; MOD_TEST() @@ -71,7 +70,7 @@ void watch_generic_free(ModData *m) } MOD_INIT() -{ +{ ModDataInfo mreq; MARK_AS_OFFICIAL_MODULE(modinfo); @@ -87,7 +86,7 @@ MOD_INIT() if (watchTable == NULL) watchTable = safe_alloc(sizeof(Watch *) * WATCH_HASH_TABLE_SIZE); - memset(&mreq, 0 , sizeof(mreq)); + memset(&mreq, 0, sizeof(mreq)); mreq.type = MODDATATYPE_LOCAL_CLIENT; mreq.name = "watchCount", mreq.free = dummy_free; @@ -98,7 +97,7 @@ MOD_INIT() return MOD_FAILED; } - memset(&mreq, 0 , sizeof(mreq)); + memset(&mreq, 0, sizeof(mreq)); mreq.type = MODDATATYPE_LOCAL_CLIENT; mreq.name = "watchList", mreq.free = watch_free; @@ -152,50 +151,53 @@ int _watch_add(const char *nick, Client *client, int flags) unsigned int hashv; Watch *watch; Link *lp; - - + + /* Get the right bucket... */ hashv = hash_watch_nick_name(nick); - + /* Find the right nick (header) in the bucket, or NULL... */ if ((watch = watchTable[hashv])) while (watch && mycmp(watch->nick, nick)) - watch = watch->hnext; - + watch = watch->hnext; + /* If found NULL (no header for this nick), make one... */ - if (!watch) { - watch = safe_alloc(sizeof(Watch)+strlen(nick)+1); + if (!watch) + { + watch = safe_alloc(sizeof(Watch) + strlen(nick) + 1); watch->lasttime = timeofday; strcpy(watch->nick, nick); - + watch->watch = NULL; - + watch->hnext = watchTable[hashv]; watchTable[hashv] = watch; } /* Is this client already on the watch-list? */ if ((lp = watch->watch)) while (lp && (lp->value.client != client)) - lp = lp->next; - + lp = lp->next; + /* No it isn't, so add it in the bucket and client addint it */ - if (!lp) { + if (!lp) + { lp = watch->watch; watch->watch = make_link(); watch->watch->value.client = client; watch->watch->flags = flags; watch->watch->next = lp; - + lp = make_link(); lp->next = WATCH(client); lp->value.wptr = watch; lp->flags = flags; WATCH(client) = lp; - WATCHES(client)++; - + WATCHES(client) + ++; + RunHook(HOOKTYPE_WATCH_ADD, nick, client, flags); } - + return 0; } @@ -207,23 +209,23 @@ int _watch_check(Client *client, int event, void *data, int (*watch_notify)(Clie /* Get us the right bucket */ hashv = hash_watch_nick_name(client->name); - + /* Find the right header in this bucket */ if ((watch = watchTable[hashv])) while (watch && mycmp(watch->nick, client->name)) - watch = watch->hnext; + watch = watch->hnext; if (!watch) - return 0; /* This nick isn't on watch */ - + return 0; /* This nick isn't on watch */ + /* Update the time of last change to item */ watch->lasttime = TStime(); - + /* Send notifies out to everybody on the list in header */ for (lp = watch->watch; lp; lp = lp->next) { watch_notify(client, watch, lp, event, data); } - + return 0; } @@ -231,13 +233,13 @@ Watch *_watch_get(const char *nick) { unsigned int hashv; Watch *watch; - + hashv = hash_watch_nick_name(nick); - + if ((watch = watchTable[hashv])) while (watch && mycmp(watch->nick, nick)) - watch = watch->hnext; - + watch = watch->hnext; + return watch; } @@ -249,14 +251,14 @@ int _watch_del(const char *nick, Client *client, int flags) /* Get the bucket for this nick... */ hashv = hash_watch_nick_name(nick); - + /* Find the right header, maintaining last-link pointer... */ watch = (Watch **)&watchTable[hashv]; while (*watch && mycmp((*watch)->nick, nick)) watch = &(*watch)->hnext; if (!*watch) - return 0; /* No such watch */ - + return 0; /* No such watch */ + /* Find this client from the list of notifies... with last-ptr. */ lp = &(*watch)->watch; while (*lp) @@ -266,18 +268,18 @@ int _watch_del(const char *nick, Client *client, int flags) lp = &(*lp)->next; } if (!*lp) - return 0; /* No such client to watch */ - + return 0; /* No such client to watch */ + /* Fix the linked list under header, then remove the watch entry */ prev = *lp; *lp = prev->next; free_link(prev); - + /* Do the same regarding the links in client-record... */ lp = (Link **)&WATCH(client); while (*lp && ((*lp)->value.wptr != *watch)) lp = &(*lp)->next; - + /* * Give error on the odd case... probobly not even neccessary * No error checking in ircd is unneccessary ;) -Cabal95 @@ -288,23 +290,26 @@ int _watch_del(const char *nick, Client *client, int flags) "[BUG] watch_del found a watch entry with no client counterpoint, " "while processing nick $nick on client $client.details", log_data_string("nick", nick)); - } else { + } else + { prev = *lp; *lp = prev->next; free_link(prev); } /* In case this header is now empty of notices, remove it */ - if (!(*watch)->watch) { + if (!(*watch)->watch) + { wprev = *watch; *watch = wprev->hnext; safe_free(wprev); } - + /* Update count of notifies on nick */ - WATCHES(client)--; - + WATCHES(client) + --; + RunHook(HOOKTYPE_WATCH_DEL, nick, client, flags); - + return 0; } @@ -313,19 +318,21 @@ int _watch_del_list(Client *client, int flags) unsigned int hashv; Watch *watch; Link **np, **lp, *prev; - + np = (Link **)&WATCH(client); - - while (*np) { + + while (*np) + { if (((*np)->flags & flags) != flags) { /* this entry is not fitting requested flags */ np = &(*np)->next; continue; } - - WATCHES(client)--; - + + WATCHES(client) + --; + /* Find the watch-record from hash-table... */ watch = (*np)->value.wptr; lp = &(watch->watch); @@ -336,23 +343,25 @@ int _watch_del_list(Client *client, int flags) if (!*lp) { unreal_log(ULOG_WARNING, "watch", "BUG_WATCH_DEL_LIST", client, - "[BUG] watch_del_list found a watch entry with no table counterpoint, " - "while processing client $client.details"); - } else { + "[BUG] watch_del_list found a watch entry with no table counterpoint, " + "while processing client $client.details"); + } else + { /* Fix the watch-list and remove entry */ Link *prev = *lp; *lp = prev->next; free_link(prev); - + /* * If this leaves a header without notifies, * remove it. Need to find the last-pointer! */ - if (!watch->watch) { + if (!watch->watch) + { Watch **np2, *wprev; - + hashv = hash_watch_nick_name(watch->nick); - + np2 = &watchTable[hashv]; while (*np2 && *np2 != watch) np2 = &(*np2)->hnext; @@ -362,15 +371,15 @@ int _watch_del_list(Client *client, int flags) safe_free(watch); } } - + prev = *np; /* Save last pointer processed */ *np = prev->next; /* Jump to the next pointer */ free_link(prev); /* Free the previous */ } - + if (!flags) WATCHES(client) = 0; - + return 0; } @@ -378,4 +387,3 @@ uint64_t hash_watch_nick_name(const char *name) { return siphash_nocase(name, siphashkey_watch) % WATCH_HASH_TABLE_SIZE; } - diff --git a/src/modules/watch.c b/src/modules/watch.c index b3d7bffe7..ef963d120 100644 --- a/src/modules/watch.c +++ b/src/modules/watch.c @@ -22,7 +22,7 @@ #include "unrealircd.h" -#define MSG_WATCH "WATCH" +#define MSG_WATCH "WATCH" CMD_FUNC(cmd_watch); int watch_user_quit(Client *client, MessageTag *mtags, const char *comment); @@ -36,19 +36,18 @@ int watch_notification(Client *client, Watch *watch, Link *lp, int event, void * ModDataInfo *watchCounterMD = NULL; ModDataInfo *watchListMD = NULL; -ModuleHeader MOD_HEADER - = { - "watch", - "5.0", - "command /watch", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "watch", + "5.0", + "command /watch", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() -{ +{ MARK_AS_OFFICIAL_MODULE(modinfo); - + CommandAdd(modinfo->handle, MSG_WATCH, cmd_watch, 1, CMD_USER); HookAdd(modinfo->handle, HOOKTYPE_LOCAL_QUIT, 0, watch_user_quit); HookAdd(modinfo->handle, HOOKTYPE_REMOTE_QUIT, 0, watch_user_quit); @@ -88,18 +87,17 @@ static void show_watch(Client *client, char *name, int awaynotify) if (awaynotify && target->user->away) { sendnumeric(client, RPL_NOWISAWAY, - target->name, target->user->username, - IsHidden(target) ? target->user->virthost : target->user->realhost, - (long long)target->user->away_since); + target->name, target->user->username, + IsHidden(target) ? target->user->virthost : target->user->realhost, + (long long)target->user->away_since); return; } - + sendnumeric(client, RPL_NOWON, - target->name, target->user->username, - IsHidden(target) ? target->user->virthost : target->user->realhost, - (long long)target->lastnick); - } - else + target->name, target->user->username, + IsHidden(target) ? target->user->virthost : target->user->realhost, + (long long)target->lastnick); + } else { sendnumeric(client, RPL_NOWOFF, name, "*", "*", 0LL); } @@ -115,18 +113,17 @@ static void show_watch_removed(Client *client, char *name) if ((target = find_user(name, NULL))) { sendnumeric(client, RPL_WATCHOFF, - target->name, target->user->username, - IsHidden(target) ? target->user->virthost : target->user->realhost, - (long long)target->lastnick); - } - else + target->name, target->user->username, + IsHidden(target) ? target->user->virthost : target->user->realhost, + (long long)target->lastnick); + } else { sendnumeric(client, RPL_WATCHOFF, name, "*", "*", 0LL); } } #define WATCHES(client) (moddata_local_client(client, watchCounterMD).i) -#define WATCH(client) (moddata_local_client(client, watchListMD).ptr) +#define WATCH(client) (moddata_local_client(client, watchListMD).ptr) /* * cmd_watch @@ -139,7 +136,7 @@ CMD_FUNC(cmd_watch) char *s, *user; char *p = NULL, *def = "l"; int awaynotify = 0; - int did_l=0, did_s=0; + int did_l = 0, did_s = 0; if (!MyUser(client)) return; @@ -166,8 +163,8 @@ CMD_FUNC(cmd_watch) for (s = strtoken(&p, request, " "); s; s = strtoken(&p, NULL, " ")) { if ((user = strchr(s, '!'))) - *user++ = '\0'; /* Not used */ - + *user++ = '\0'; /* Not used */ + if (!strcmp(s, "A") && WATCH_AWAY_NOTIFICATION) awaynotify = 1; @@ -177,7 +174,7 @@ CMD_FUNC(cmd_watch) */ if (*s == '+') { - if (!*(s+1)) + if (!*(s + 1)) continue; if (do_nick_name(s + 1)) { @@ -188,8 +185,7 @@ CMD_FUNC(cmd_watch) } watch_add(s + 1, client, - WATCH_FLAG_TYPE_WATCH | (awaynotify ? WATCH_FLAG_AWAYNOTIFY : 0) - ); + WATCH_FLAG_TYPE_WATCH | (awaynotify ? WATCH_FLAG_AWAYNOTIFY : 0)); } show_watch(client, s + 1, awaynotify); @@ -202,7 +198,7 @@ CMD_FUNC(cmd_watch) */ if (*s == '-') { - if (!*(s+1)) + if (!*(s + 1)) continue; watch_del(s + 1, client, WATCH_FLAG_TYPE_WATCH); show_watch_removed(client, s + 1); @@ -228,10 +224,10 @@ CMD_FUNC(cmd_watch) { Link *lp; Watch *watch; - int count = 0; - + int count = 0; + did_s = 1; - + /* * Send a list of how many users they have on their WATCH list * and how many WATCH lists they are on. This will also include @@ -241,7 +237,7 @@ CMD_FUNC(cmd_watch) watch = watch_get(client->name); if (watch) for (lp = watch->watch, count = 1; - (lp = lp->next); count++) + (lp = lp->next); count++) ; sendnumeric(client, RPL_WATCHSTAT, WATCHES(client), count); @@ -269,7 +265,7 @@ CMD_FUNC(cmd_watch) strcat(buf, " "); strcat(buf, lp->value.wptr->nick); count += (strlen(lp->value.wptr->nick) + 1); - + lp = lp->next; } if (*buf) @@ -301,10 +297,9 @@ CMD_FUNC(cmd_watch) if ((target = find_user(lp->value.wptr->nick, NULL))) { sendnumeric(client, RPL_NOWON, target->name, - target->user->username, - IsHidden(target) ? target->user-> - virthost : target->user->realhost, - (long long)target->lastnick); + target->user->username, + IsHidden(target) ? target->user->virthost : target->user->realhost, + (long long)target->lastnick); } /* * But actually, only show them offline if its a capital @@ -312,8 +307,8 @@ CMD_FUNC(cmd_watch) */ else if (isupper(*s)) sendnumeric(client, RPL_NOWOFF, - lp->value.wptr->nick, "*", "*", - (long long)lp->value.wptr->lasttime); + lp->value.wptr->nick, "*", "*", + (long long)lp->value.wptr->lasttime); lp = lp->next; } @@ -369,10 +364,10 @@ int watch_user_connect(Client *client) int watch_notification(Client *client, Watch *watch, Link *lp, int event, void *data) { int awaynotify = 0; - + if (!(lp->flags & WATCH_FLAG_TYPE_WATCH)) return 0; - + if ((event == WATCH_EVENT_AWAY) || (event == WATCH_EVENT_NOTAWAY) || (event == WATCH_EVENT_REAWAY)) awaynotify = 1; @@ -385,7 +380,8 @@ int watch_notification(Client *client, Watch *watch, Link *lp, int event, void * (IsUser(client) ? client->user->username : ""), (IsUser(client) ? (IsHidden(client) ? client->user->virthost : client->user->realhost) : ""), (long long)watch->lasttime); - } else { + } else + { sendnumeric(lp->value.client, RPL_LOGON, client->name, (IsUser(client) ? client->user->username : ""), @@ -401,15 +397,14 @@ int watch_notification(Client *client, Watch *watch, Link *lp, int event, void * * they come online, and then we send RPL_GONEAWAY */ sendnumeric(lp->value.client, RPL_GONEAWAY, - client->name, - (IsUser(client) ? client->user->username : ""), - (IsUser(client) ? (IsHidden(client) ? client->user->virthost : client->user->realhost) : ""), - (long long)client->user->away_since, - client->user->away); + client->name, + (IsUser(client) ? client->user->username : ""), + (IsUser(client) ? (IsHidden(client) ? client->user->virthost : client->user->realhost) : ""), + (long long)client->user->away_since, + client->user->away); } } - } - else + } else { /* AWAY or UNAWAY */ if (!(lp->flags & WATCH_FLAG_AWAYNOTIFY)) @@ -418,12 +413,11 @@ int watch_notification(Client *client, Watch *watch, Link *lp, int event, void * if (event == WATCH_EVENT_NOTAWAY) { sendnumeric(lp->value.client, RPL_NOTAWAY, - client->name, - (IsUser(client) ? client->user->username : ""), - (IsUser(client) ? (IsHidden(client) ? client->user->virthost : client->user->realhost) : ""), - (long long)client->user->away_since); - } else - if (event == WATCH_EVENT_AWAY) + client->name, + (IsUser(client) ? client->user->username : ""), + (IsUser(client) ? (IsHidden(client) ? client->user->virthost : client->user->realhost) : ""), + (long long)client->user->away_since); + } else if (event == WATCH_EVENT_AWAY) { sendnumeric(lp->value.client, RPL_GONEAWAY, client->name, @@ -431,8 +425,7 @@ int watch_notification(Client *client, Watch *watch, Link *lp, int event, void * (IsUser(client) ? (IsHidden(client) ? client->user->virthost : client->user->realhost) : ""), (long long)client->user->away_since, client->user->away); - } else - if (event == WATCH_EVENT_REAWAY) + } else if (event == WATCH_EVENT_REAWAY) { sendnumeric(lp->value.client, RPL_REAWAY, client->name, @@ -442,7 +435,6 @@ int watch_notification(Client *client, Watch *watch, Link *lp, int event, void * client->user->away); } } - + return 0; } - diff --git a/src/modules/webirc.c b/src/modules/webirc.c index 59c09a391..dc8effa13 100644 --- a/src/modules/webirc.c +++ b/src/modules/webirc.c @@ -19,13 +19,12 @@ #include "unrealircd.h" /* Module header */ -ModuleHeader MOD_HEADER -= { - "webirc", - "5.0", - "WebIRC/CGI:IRC Support", - "UnrealIRCd Team", - "unrealircd-6", +ModuleHeader MOD_HEADER = { + "webirc", + "5.0", + "WebIRC/CGI:IRC Support", + "UnrealIRCd Team", + "unrealircd-6", }; /* Global variables */ @@ -39,11 +38,23 @@ void webirc_md_unserialize(const char *str, ModData *m); void webirc_md_free(ModData *md); int webirc_secure_connect(Client *client); -#define IsWEBIRC(x) (moddata_client(x, webirc_md).l) -#define IsWEBIRCSecure(x) (moddata_client(x, webirc_md).l == 2) -#define ClearWEBIRC(x) do { moddata_client(x, webirc_md).l = 0; } while(0) -#define SetWEBIRC(x) do { moddata_client(x, webirc_md).l = 1; } while(0) -#define SetWEBIRCSecure(x) do { moddata_client(x, webirc_md).l = 2; } while(0) +#define IsWEBIRC(x) (moddata_client(x, webirc_md).l) +#define IsWEBIRCSecure(x) (moddata_client(x, webirc_md).l == 2) +#define ClearWEBIRC(x) \ + do \ + { \ + moddata_client(x, webirc_md).l = 0; \ + } while (0) +#define SetWEBIRC(x) \ + do \ + { \ + moddata_client(x, webirc_md).l = 1; \ + } while (0) +#define SetWEBIRCSecure(x) \ + do \ + { \ + moddata_client(x, webirc_md).l = 2; \ + } while (0) #define MSG_WEBIRC "WEBIRC" @@ -53,7 +64,7 @@ MOD_INIT() ModDataInfo mreq; MARK_AS_OFFICIAL_MODULE(modinfo); - + memset(&mreq, 0, sizeof(mreq)); mreq.name = "webirc"; mreq.type = MODDATATYPE_CLIENT; @@ -73,7 +84,7 @@ MOD_INIT() HookAdd(modinfo->handle, HOOKTYPE_SECURE_CONNECT, 0, webirc_secure_connect); CommandAdd(modinfo->handle, MSG_WEBIRC, cmd_webirc, MAXPARA, CMD_UNREGISTERED); - + return MOD_SUCCESS; } @@ -125,8 +136,8 @@ ConfigItem_proxy *find_webirc(Client *client, const char *password, ProxyType ty error = "CGI:IRC -- Invalid password"; else return e; /* Found matching block, return straight away */ - } else - if (type == PROXY_WEBIRC_PASS) { + } else if (type == PROXY_WEBIRC_PASS) + { return e; /* The PROXY_WEBIRC_PASS type has no password checking */ } } @@ -140,8 +151,8 @@ ConfigItem_proxy *find_webirc(Client *client, const char *password, ProxyType ty return NULL; } -#define WEBIRC_STRING "WEBIRC_" -#define WEBIRC_STRINGLEN (sizeof(WEBIRC_STRING)-1) +#define WEBIRC_STRING "WEBIRC_" +#define WEBIRC_STRINGLEN (sizeof(WEBIRC_STRING) - 1) /* Does the CGI:IRC host spoofing work */ void dowebirc(Client *client, const char *ip, const char *host, const char *options) @@ -157,7 +168,7 @@ void dowebirc(Client *client, const char *ip, const char *host, const char *opti if (!set_client_ip(client, ip)) return; /* Failed, client exited */ - + /* Update client->local->hostp */ /* (free old) */ if (client->local->hostp) @@ -250,7 +261,7 @@ int webirc_local_pass(Client *client, const char *password) return HOOK_DENY; } *host++ = '\0'; - + dowebirc(client, ip, host, NULL); return HOOK_DENY; } diff --git a/src/modules/webredir.c b/src/modules/webredir.c index 13c3b41e5..c11a32114 100644 --- a/src/modules/webredir.c +++ b/src/modules/webredir.c @@ -23,14 +23,13 @@ CMD_FUNC(webredir); -ModuleHeader MOD_HEADER - = { - "webredir", - "1.0", - "Do 301 redirect for HEAD/GET/POST/PUT commands", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "webredir", + "1.0", + "Do 301 redirect for HEAD/GET/POST/PUT commands", + "UnrealIRCd Team", + "unrealircd-6", +}; struct { char *url; @@ -68,7 +67,7 @@ MOD_LOAD() if (SHOWCONNECTINFO) { config_warn("I'm disabling set::options::show-connect-info for you " - "as this setting is incompatible with the webredir module."); + "as this setting is incompatible with the webredir module."); SHOWCONNECTINFO = 0; } return MOD_SUCCESS; @@ -125,35 +124,33 @@ int webredir_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!cep->value) { config_error("%s:%i: set::webredir::%s with no value", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; - } - else if (!strcmp(cep->name, "url")) + } else if (!strcmp(cep->name, "url")) { if (!*cep->value || strchr(cep->value, ' ')) { config_error("%s:%i: set::webredir::%s with empty value", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; } if (!strstr(cep->value, "://") || !strcmp(cep->value, "https://...")) { config_error("%s:%i: set::webredir::url needs to be a valid URL", - cep->file->filename, cep->line_number); + cep->file->filename, cep->line_number); errors++; } if (has_url) { config_warn_duplicate(cep->file->filename, - cep->line_number, "set::webredir::url"); + cep->line_number, "set::webredir::url"); continue; } has_url = 1; - } - else + } else { config_error("%s:%i: unknown directive set::webredir::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; } } @@ -161,7 +158,7 @@ int webredir_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!has_url) { config_error_missing(ce->file->filename, ce->line_number, - "set::webredir::url"); + "set::webredir::url"); errors++; } @@ -175,11 +172,11 @@ int webredir_config_run(ConfigFile *cf, ConfigEntry *ce, int type) if (type != CONFIG_SET) return 0; - + /* We are only interrested in set::webredir... */ if (!ce || !ce->name || strcmp(ce->name, "webredir")) return 0; - + for (cep = ce->items; cep; cep = cep->next) { if (!strcmp(cep->name, "url")) diff --git a/src/modules/webserver.c b/src/modules/webserver.c index 90c97726c..df7ff927e 100644 --- a/src/modules/webserver.c +++ b/src/modules/webserver.c @@ -3,17 +3,16 @@ * (C)Copyright 2016 Bram Matthys and the UnrealIRCd team * License: GPLv2 or later */ - + #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "webserver", - "1.0.0", - "Webserver", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "webserver", + "1.0.0", + "Webserver", + "UnrealIRCd Team", + "unrealircd-6", +}; #if CHAR_MIN < 0 #error "In UnrealIRCd char should always be unsigned. Check your compiler" @@ -26,11 +25,15 @@ ModuleHeader MOD_HEADER #define WEB_SOFTWARE "UnrealIRCd" /* Macros */ -#define WEB(client) ((WebRequest *)moddata_local_client(client, webserver_md).ptr) -#define WEBSERVER(client) ((client->local && client->local->listener) ? client->local->listener->webserver : NULL) -#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) +#define WEB(client) ((WebRequest *)moddata_local_client(client, webserver_md).ptr) +#define WEBSERVER(client) ((client->local && client->local->listener) ? client->local->listener->webserver : NULL) +#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) -#define reset_handshake_timeout(client, delta) do { client->local->creationtime = TStime() - iConf.handshake_timeout + delta; } while(0) +#define reset_handshake_timeout(client, delta) \ + do \ + { \ + client->local->creationtime = TStime() - iConf.handshake_timeout + delta; \ + } while (0) /* Forward declarations */ int webserver_packet_out(Client *from, Client *to, Client *intended_to, char **msg, int *length); @@ -234,15 +237,13 @@ int webserver_handshake_helper(char *buffer, int len, char **key, char **value, if (*p == ' ') { *p = '\0'; /* terminate before "HTTP/1.X" part */ - } - else if (*p == '\r') + } else if (*p == '\r') { *p = '\0'; /* eat silently, but don't consider EOL */ - } - else if (*p == '\n') + } else if (*p == '\n') { *p = '\0'; - nextptr = p+1; /* safe, there is data or at least a \0 there */ + nextptr = p + 1; /* safe, there is data or at least a \0 there */ break; } } @@ -304,11 +305,10 @@ int webserver_handshake_helper(char *buffer, int len, char **key, char **value, if (*p == '\r') { *p = '\0'; /* eat silently, but don't consider EOL */ - } - else if (*p == '\n') + } else if (*p == '\n') { *p = '\0'; - nextptr = p+1; /* safe, there is data or at least a \0 there */ + nextptr = p + 1; /* safe, there is data or at least a \0 there */ break; } } @@ -339,15 +339,14 @@ char *find_end_of_request(char *header, int totalsize, int *remaining_bytes) if (nextframe1 < nextframe2) { nextframe = nextframe1 + 4; - } else { + } else + { nextframe = nextframe2 + 2; } - } else - if (nextframe1) + } else if (nextframe1) { nextframe = nextframe1 + 4; - } else - if (nextframe2) + } else if (nextframe2) { nextframe = nextframe2 + 2; } @@ -372,12 +371,13 @@ int webserver_handle_request_header(Client *client, const char *readbuf, int *le int totalsize; totalsize = WEB(client)->lefttoparselen + *length; - netbuf = safe_alloc(totalsize+1); + netbuf = safe_alloc(totalsize + 1); if (WEB(client)->lefttoparse) { memcpy(netbuf, WEB(client)->lefttoparse, WEB(client)->lefttoparselen); memcpy(netbuf + WEB(client)->lefttoparselen, readbuf, *length); - } else { + } else + { memcpy(netbuf, readbuf, *length); } safe_free(WEB(client)->lefttoparse); @@ -401,8 +401,7 @@ int webserver_handle_request_header(Client *client, const char *readbuf, int *le if (!strcasecmp(key, "Content-Length")) { WEB(client)->content_length = atoll(value); - } else - if (!strcasecmp(key, "Transfer-Encoding")) + } else if (!strcasecmp(key, "Transfer-Encoding")) { if (!strcasecmp(value, "chunked")) WEB(client)->transfer_encoding = TRANSFER_ENCODING_CHUNKED; @@ -438,7 +437,7 @@ int webserver_handle_request_header(Client *client, const char *readbuf, int *le safe_free(netbuf); return n; /* byebye */ } - + /* There could be data directly after the request header (eg for * a POST or PUT), check for it here so it isn't lost. */ @@ -493,8 +492,8 @@ void _webserver_send_response(Client *client, int status, char *msg) statusmsg = "Range Not Satisfiable"; snprintf(buf, sizeof(buf), - "HTTP/1.1 %d %s\r\nServer: %s\r\nConnection: close\r\n\r\n", - status, statusmsg, WEB_SOFTWARE); + "HTTP/1.1 %d %s\r\nServer: %s\r\nConnection: close\r\n\r\n", + status, statusmsg, WEB_SOFTWARE); if (msg) { strlcat(buf, msg, sizeof(buf)); @@ -514,7 +513,8 @@ void _webserver_close_client(Client *client) { exit_client(client, NULL, "End of request"); //dead_socket(client, ""); - } else { + } else + { send_queued(client); reset_handshake_timeout(client, WEB_CLOSE_TIME); } @@ -549,11 +549,11 @@ int webserver_handle_body_append_buffer(Client *client, const char *buf, int len /* We would overflow */ unreal_log(ULOG_WARNING, "webserver", "HTTP_BODY_TOO_LARGE", client, "[webserver] Client $client: request body too large ($length)", - log_data_integer("length", len+1)); + log_data_integer("length", len + 1)); dead_socket(client, ""); return 0; } - WEB(client)->request_buffer = malloc(len+1); + WEB(client)->request_buffer = malloc(len + 1); } memcpy(WEB(client)->request_buffer + WEB(client)->request_buffer_size, buf, len); WEB(client)->request_buffer_size += len; @@ -595,10 +595,11 @@ int _webserver_handle_body(Client *client, WebRequest *web, const char *readbuf, n = WEB(client)->lefttoparselen + pktsize; free_this_buffer = buf = safe_alloc(n); memcpy(buf, WEB(client)->lefttoparse, WEB(client)->lefttoparselen); - memcpy(buf+WEB(client)->lefttoparselen, readbuf, pktsize); + memcpy(buf + WEB(client)->lefttoparselen, readbuf, pktsize); safe_free(WEB(client)->lefttoparse); WEB(client)->lefttoparselen = 0; - } else { + } else + { n = pktsize; free_this_buffer = buf = safe_alloc(n); memcpy(buf, readbuf, n); @@ -632,8 +633,7 @@ int _webserver_handle_body(Client *client, WebRequest *web, const char *readbuf, { buf += 2; n -= 2; - } else - if ((n >= 1) && !strncmp(buf, "\n", 1)) + } else if ((n >= 1) && !strncmp(buf, "\n", 1)) { buf++; n--; @@ -643,7 +643,7 @@ int _webserver_handle_body(Client *client, WebRequest *web, const char *readbuf, * this is or example '7f' + newline. * So first, check if we have a newline at all. */ - for (i=0; i < n; i++) + for (i = 0; i < n; i++) { if (buf[i] == '\n') { @@ -735,8 +735,7 @@ void do_parse_forwarded_header(const char *input, HTTPForwardedHeader *forwarded * may also cut off the optional local port, * but that is fine: we don't use it. */ - } else - if ((x = strchr(value, ':'))) + } else if ((x = strchr(value, ':'))) { /* For non-IPv6 ip:port, cut off at the ':', * so we only have IP. @@ -744,8 +743,7 @@ void do_parse_forwarded_header(const char *input, HTTPForwardedHeader *forwarded *x = '\0'; } strlcpy(forwarded->ip, value, sizeof(forwarded->ip)); - } else - if (!strcasecmp(name, "proto")) + } else if (!strcasecmp(name, "proto")) { if (!strcasecmp(value, "https")) { @@ -799,7 +797,8 @@ void webserver_handle_proxy(Client *client, ConfigItem_proxy *proxy) if (WEB(client)->forwarded == NULL) { WEB(client)->forwarded = safe_alloc(sizeof(HTTPForwardedHeader)); - } else { + } else + { memset(WEB(client)->forwarded, 0, sizeof(HTTPForwardedHeader)); } forwarded = WEB(client)->forwarded; @@ -811,15 +810,13 @@ void webserver_handle_proxy(Client *client, ConfigItem_proxy *proxy) { if (!strcasecmp(header->name, "Forwarded")) do_parse_forwarded_header(header->value, forwarded); - } else - if (proxy->type == PROXY_X_FORWARDED) + } else if (proxy->type == PROXY_X_FORWARDED) { if (!strcasecmp(header->name, "X-Forwarded-For")) do_parse_x_forwarded_for_header(header->value, forwarded); else if (!strcasecmp(header->name, "X-Forwarded-Proto")) do_parse_x_forwarded_proto_header(header->value, forwarded); - } else - if (proxy->type == PROXY_CLOUDFLARE) + } else if (proxy->type == PROXY_CLOUDFLARE) { /* This is a mix of CF-Connecting-IP and X-Forwarded-Proto */ if (!strcasecmp(header->name, "CF-Connecting-IP")) diff --git a/src/modules/websocket.c b/src/modules/websocket.c index b068c5062..cdaae92a0 100644 --- a/src/modules/websocket.c +++ b/src/modules/websocket.c @@ -4,19 +4,18 @@ * License: GPLv2 or later * This module was sponsored by Aberrant Software Inc. */ - + #include "unrealircd.h" #define WEBSOCKET_VERSION "1.1.0" -ModuleHeader MOD_HEADER - = { - "websocket", - WEBSOCKET_VERSION, - "WebSocket support (RFC6455)", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "websocket", + WEBSOCKET_VERSION, + "WebSocket support (RFC6455)", + "UnrealIRCd Team", + "unrealircd-6", +}; #if CHAR_MIN < 0 #error "In UnrealIRCd char should always be unsigned. Check your compiler" @@ -26,11 +25,11 @@ ModuleHeader MOD_HEADER #define WEBSOCKET_SEND_BUFFER_SIZE 16384 #endif -#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) -#define WEB(client) ((WebRequest *)moddata_local_client(client, webserver_md).ptr) +#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) +#define WEB(client) ((WebRequest *)moddata_local_client(client, webserver_md).ptr) -#define WEBSOCKET_PORT(client) ((client->local && client->local->listener) ? client->local->listener->websocket_options : 0) -#define WEBSOCKET_TYPE(client) (WSU(client)->type) +#define WEBSOCKET_PORT(client) ((client->local && client->local->listener) ? client->local->listener->websocket_options : 0) +#define WEBSOCKET_TYPE(client) (WSU(client)->type) /* Forward declarations */ int websocket_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs); @@ -55,7 +54,7 @@ MOD_TEST() HookAdd(modinfo->handle, HOOKTYPE_CONFIGPOSTTEST, 0, websocket_config_posttest); /* Call MOD_INIT very early, since we manage sockets, but depend on websocket_common */ - ModuleSetOptions(modinfo->handle, MOD_OPT_PRIORITY, WEBSOCKET_MODULE_PRIORITY_INIT+1); + ModuleSetOptions(modinfo->handle, MOD_OPT_PRIORITY, WEBSOCKET_MODULE_PRIORITY_INIT + 1); return MOD_SUCCESS; } @@ -75,7 +74,7 @@ MOD_INIT() HookAdd(modinfo->handle, HOOKTYPE_CONFIG_LISTENER, 0, websocket_config_listener); /* Call MOD_LOAD very late, since we manage sockets, but depend on websocket_common */ - ModuleSetOptions(modinfo->handle, MOD_OPT_PRIORITY, WEBSOCKET_MODULE_PRIORITY_UNLOAD-1); + ModuleSetOptions(modinfo->handle, MOD_OPT_PRIORITY, WEBSOCKET_MODULE_PRIORITY_UNLOAD - 1); return MOD_SUCCESS; } @@ -127,14 +126,12 @@ int websocket_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) errored_once_nick = 1; errors++; } - } - else if (!strcmp(cep->value, "binary")) + } else if (!strcmp(cep->value, "binary")) { - } - else + } else { config_error("%s:%i: listen::options::websocket::type must be either 'binary' or 'text' (not '%s')", - cep->file->filename, cep->line_number, cep->value); + cep->file->filename, cep->line_number, cep->value); errors++; } } else if (!strcmp(cep->name, "forward")) @@ -148,7 +145,7 @@ int websocket_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) } else { config_error("%s:%i: unknown directive listen::options::websocket::%s", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } @@ -157,7 +154,7 @@ int websocket_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) if (!has_type) { config_error("%s:%i: websocket set, but type unspecified. Use something like: listen { ip *; port 443; websocket { type text; } }", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; } @@ -264,8 +261,8 @@ void add_lf_if_needed(char **buf, int *len) if (b[l - 1] == '\n') return; /* already contains \n */ - if (l >= sizeof(newbuf)-2) - l = sizeof(newbuf)-2; /* cut-off if necessary */ + if (l >= sizeof(newbuf) - 2) + l = sizeof(newbuf) - 2; /* cut-off if necessary */ memcpy(newbuf, b, l); newbuf[l] = '\n'; @@ -301,7 +298,7 @@ int websocket_packet_out(Client *from, Client *to, Client *intended_to, char **m * 1 = the space between them * 1 = NULL terminator? */ - static char utf8buf[8192+512+1+1]; + static char utf8buf[8192 + 512 + 1 + 1]; if (MyConnect(to) && !IsRPC(to) && websocket_md && WSU(to) && WSU(to)->handshake_completed) { @@ -347,8 +344,7 @@ int websocket_handle_request(Client *client, WebRequest *web) return -1; } safe_strdup(WSU(client)->handshake_key, value); - } else - if (!strcasecmp(key, "Sec-WebSocket-Protocol")) + } else if (!strcasecmp(key, "Sec-WebSocket-Protocol")) { /* Save it here, will be processed later */ safe_strdup(WSU(client)->sec_websocket_protocol, value); @@ -388,7 +384,7 @@ int websocket_handle_request(Client *client, WebRequest *web) { if (is_module_loaded("webredir")) { - const char *parx[2] = { NULL, NULL }; + const char *parx[2] = {NULL, NULL}; do_cmd(client, NULL, "GET", 1, parx); } webserver_send_response(client, 404, "This port is for IRC WebSocket only"); @@ -410,8 +406,7 @@ int websocket_handle_request(Client *client, WebRequest *web) { negotiated = WEBSOCKET_TYPE_BINARY; break; /* First hit wins */ - } else - if (!strcmp(name, "text.ircv3.net") && ws_text_mode_available) + } else if (!strcmp(name, "text.ircv3.net") && ws_text_mode_available) { negotiated = WEBSOCKET_TYPE_TEXT; break; /* First hit wins */ @@ -421,8 +416,7 @@ int websocket_handle_request(Client *client, WebRequest *web) { WSU(client)->type = WEBSOCKET_TYPE_BINARY; safe_strdup(WSU(client)->sec_websocket_protocol, "binary.ircv3.net"); - } else - if (negotiated == WEBSOCKET_TYPE_TEXT) + } else if (negotiated == WEBSOCKET_TYPE_TEXT) { WSU(client)->type = WEBSOCKET_TYPE_TEXT; safe_strdup(WSU(client)->sec_websocket_protocol, "text.ircv3.net"); @@ -475,7 +469,7 @@ int websocket_handshake_send_response(Client *client) /* using strlen() is safe here since above buffer will not * cause it to be >=512 and thus we won't get into negatives. */ - snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "Sec-WebSocket-Protocol: %s\r\n", WSU(client)->sec_websocket_protocol); } diff --git a/src/modules/websocket_common.c b/src/modules/websocket_common.c index 727bee569..e2c631a73 100644 --- a/src/modules/websocket_common.c +++ b/src/modules/websocket_common.c @@ -4,17 +4,16 @@ * License: GPLv2 or later * The websocket module was sponsored by Aberrant Software Inc. */ - + #include "unrealircd.h" -ModuleHeader MOD_HEADER - = { - "websocket_common", - "6.1.4", - "WebSocket support (RFC6455)", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "websocket_common", + "6.1.4", + "WebSocket support (RFC6455)", + "UnrealIRCd Team", + "unrealircd-6", +}; #if CHAR_MIN < 0 #error "In UnrealIRCd char should always be unsigned. Check your compiler" @@ -24,7 +23,7 @@ ModuleHeader MOD_HEADER #define WEBSOCKET_SEND_BUFFER_SIZE 16384 #endif -#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) +#define WSU(client) ((WebSocketUser *)moddata_client(client, websocket_md).ptr) /* Forward declarations - public functions */ int _websocket_handle_websocket(Client *client, WebRequest *web, const char *readbuf2, int length2, int callback(Client *client, char *buf, int len)); @@ -99,7 +98,7 @@ int _websocket_handle_websocket(Client *client, WebRequest *web, const char *rea char readbuf[MAXLINELENGTH]; length = length1 + length2; - if (length > sizeof(readbuf)-1) + if (length > sizeof(readbuf) - 1) { dead_socket(client, "Illegal buffer stacking/Excess flood"); return 0; @@ -107,13 +106,14 @@ int _websocket_handle_websocket(Client *client, WebRequest *web, const char *rea if (length1 > 0) memcpy(readbuf, WSU(client)->lefttoparse, length1); - memcpy(readbuf+length1, readbuf2, length2); + memcpy(readbuf + length1, readbuf2, length2); safe_free(WSU(client)->lefttoparse); WSU(client)->lefttoparselen = 0; ptr = readbuf; - do { + do + { n = websocket_handle_packet(client, ptr, length, callback); if (n < 0) return -1; /* killed -- STOP processing */ @@ -130,7 +130,7 @@ int _websocket_handle_websocket(Client *client, WebRequest *web, const char *rea ptr += n; if (length < 0) abort(); /* less than 0 is impossible */ - } while(length > 0); + } while (length > 0); return 0; } @@ -162,7 +162,7 @@ int websocket_handle_packet(Client *client, const char *readbuf, int length, int /* fin = readbuf[0] & 0x80; -- unused */ opcode = readbuf[0] & 0x7F; masked = readbuf[1] & 0x80; - len = readbuf[1] & 0x7F; + len = readbuf[1] & 0x7F; p = &readbuf[2]; /* point to next element */ /* actually 'fin' is unused.. we don't care. */ @@ -221,7 +221,7 @@ int websocket_handle_packet(Client *client, const char *readbuf, int length, int if (masked) { memcpy(maskkey, p, maskkeylen); - p+= maskkeylen; + p += maskkeylen; } if (len > 0) @@ -243,7 +243,7 @@ int websocket_handle_packet(Client *client, const char *readbuf, int length, int } } - switch(opcode) + switch (opcode) { case WSOP_CONTINUATION: case WSOP_TEXT: @@ -323,7 +323,8 @@ int _websocket_create_packet_simple(int opcode, const char **buf, int *len) memcpy(&sendbuf[2], *buf, *len); *buf = sendbuf; *len += 2; - } else { + } else + { /* Long payload */ sendbuf[1] = 126; sendbuf[2] = (char)((*len >> 8) & 0xFF); @@ -361,7 +362,8 @@ int _websocket_create_packet_ex(int opcode, char **buf, int *len, char *sendbuf, if (*len == 0) return -1; - do { + do + { /* Find next \r or \n */ for (s2 = s; *s2 && (s2 <= lastbyte); s2++) { @@ -401,15 +403,15 @@ int _websocket_create_packet_ex(int opcode, char **buf, int *len, char *sendbuf, /* Short payload */ o[1] = (char)bytes_to_copy; memcpy(&o[2], s, bytes_to_copy); - } else - if (bytes_to_copy < 65536) + } else if (bytes_to_copy < 65536) { /* Long payload */ o[1] = 126; o[2] = (char)((bytes_to_copy >> 8) & 0xFF); o[3] = (char)(bytes_to_copy & 0xFF); memcpy(&o[4], s, bytes_to_copy); - } else { + } else + { /* Longest payload */ // XXX: yeah we don't support sending more than 4GB. o[1] = 127; @@ -429,8 +431,9 @@ int _websocket_create_packet_ex(int opcode, char **buf, int *len, char *sendbuf, bytes_in_sendbuf += bytes_single_frame; /* Advance source pointer and skip all trailing \n and \r */ - for (s = s2; *s && (s <= lastbyte) && ((*s == '\n') || (*s == '\r')); s++); - } while(s <= lastbyte); + for (s = s2; *s && (s <= lastbyte) && ((*s == '\n') || (*s == '\r')); s++) + ; + } while (s <= lastbyte); *buf = sendbuf; *len = bytes_in_sendbuf; diff --git a/src/modules/who_old.c b/src/modules/who_old.c index d0ebd819c..e3bbfa570 100644 --- a/src/modules/who_old.c +++ b/src/modules/who_old.c @@ -28,16 +28,15 @@ CMD_FUNC(cmd_who); /* Place includes here */ -#define MSG_WHO "WHO" +#define MSG_WHO "WHO" -ModuleHeader MOD_HEADER - = { - "who_old", /* Name of module */ - "5.0", /* Version */ - "command /who (old version)", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "who_old", /* Name of module */ + "5.0", /* Version */ + "command /who (old version)", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; /* This is called on module init, before Server Ready */ MOD_INIT() @@ -76,7 +75,7 @@ static void who_sendhelp(Client *); #define WF_ONCHANNEL 0x02 /**< we're on the channel we're /who'ing */ #define WF_WILDCARD 0x04 /**< a wildcard /who */ #define WF_REALHOST 0x08 /**< want real hostnames */ -#define WF_IP 0x10 /**< want IP addresses */ +#define WF_IP 0x10 /**< want IP addresses */ static int who_flags; @@ -84,9 +83,9 @@ static int who_flags; #define WHO_CANSEE 0x02 /**< set if we can */ #define WHO_OPERSEE 0x04 /**< set if we only saw them because we're an oper */ -#define FVC_HIDDEN 0x01 +#define FVC_HIDDEN 0x01 -#define WHO_WANT 1 +#define WHO_WANT 1 #define WHO_DONTWANT 2 #define WHO_DONTCARE 0 @@ -138,7 +137,7 @@ CMD_FUNC(cmd_who) } } - if (parc-i < 2 || strcmp(parv[1 + i], "0") == 0) + if (parc - i < 2 || strcmp(parv[1 + i], "0") == 0) mask = "*"; else mask = parv[1 + i]; @@ -165,14 +164,13 @@ CMD_FUNC(cmd_who) return; } - if (wfl.channel && wfl.want_channel == WHO_WANT && + if (wfl.channel && wfl.want_channel == WHO_WANT && (target_channel = find_channel(wfl.channel)) != NULL) { do_channel_who(client, target_channel, mask); sendnumeric(client, RPL_ENDOFWHO, mask); return; - } - else + } else { do_other_who(client, mask); sendnumeric(client, RPL_ENDOFWHO, mask); @@ -184,59 +182,59 @@ CMD_FUNC(cmd_who) static void who_sendhelp(Client *client) { - char *who_help[] = { - "/WHO [+|-][achmnsuM] [args]", - "Flags are specified like channel modes, the flags chmnsu all have arguments", - "Flags are set to a positive check by +, a negative check by -", - "The flags work as follows:", - "Flag a: user is away", - "Flag c : user is on ,", - " no wildcards accepted", - "Flag h : user has string in their hostname,", - " wildcards accepted", - "Flag m : user has set, only", - " O/o/C/A/a/N/B are allowed", - "Flag n : user has string in their nickname,", - " wildcards accepted", - "Flag s : user is on server ,", - " wildcards not accepted", - "Flag u : user has string in their username,", - " wildcards accepted", - "Behavior flags:", - "Flag M: check for user in channels I am a member of", - NULL, - }; + char *who_help[] = { + "/WHO [+|-][achmnsuM] [args]", + "Flags are specified like channel modes, the flags chmnsu all have arguments", + "Flags are set to a positive check by +, a negative check by -", + "The flags work as follows:", + "Flag a: user is away", + "Flag c : user is on ,", + " no wildcards accepted", + "Flag h : user has string in their hostname,", + " wildcards accepted", + "Flag m : user has set, only", + " O/o/C/A/a/N/B are allowed", + "Flag n : user has string in their nickname,", + " wildcards accepted", + "Flag s : user is on server ,", + " wildcards not accepted", + "Flag u : user has string in their username,", + " wildcards accepted", + "Behavior flags:", + "Flag M: check for user in channels I am a member of", + NULL, + }; - char *who_oper_help[] = { - "/WHO [+|-][acghimnsuMRI] [args]", - "Flags are specified like channel modes, the flags chigmnsu all have arguments", - "Flags are set to a positive check by +, a negative check by -", - "The flags work as follows:", - "Flag a: user is away", - "Flag c : user is on ,", - " no wildcards accepted", - "Flag g : user has string in their GCOS,", - " wildcards accepted", - "Flag h : user has string in their hostname,", - " wildcards accepted", - "Flag i : user has string in their IP address,", - " wildcards accepted", - "Flag p : user is connecting on port ,", - " local connections only", - "Flag m : user has set", - "Flag n : user has string in their nickname,", - " wildcards accepted", - "Flag s : user is on server ,", - " wildcards not accepted", - "Flag u : user has string in their username,", - " wildcards accepted", - "Behavior flags:", - "Flag M: check for user in channels I am a member of", - "Flag R: show users' real hostnames", - "Flag I: show users' IP addresses", - NULL, - }; - char **s; + char *who_oper_help[] = { + "/WHO [+|-][acghimnsuMRI] [args]", + "Flags are specified like channel modes, the flags chigmnsu all have arguments", + "Flags are set to a positive check by +, a negative check by -", + "The flags work as follows:", + "Flag a: user is away", + "Flag c : user is on ,", + " no wildcards accepted", + "Flag g : user has string in their GCOS,", + " wildcards accepted", + "Flag h : user has string in their hostname,", + " wildcards accepted", + "Flag i : user has string in their IP address,", + " wildcards accepted", + "Flag p : user is connecting on port ,", + " local connections only", + "Flag m : user has set", + "Flag n : user has string in their nickname,", + " wildcards accepted", + "Flag s : user is on server ,", + " wildcards not accepted", + "Flag u : user has string in their username,", + " wildcards accepted", + "Behavior flags:", + "Flag M: check for user in channels I am a member of", + "Flag R: show users' real hostnames", + "Flag I: show users' IP addresses", + NULL, + }; + char **s; if (IsOper(client)) s = who_oper_help; @@ -259,29 +257,44 @@ static int parse_who_options(Client *client, int argc, const char **argv) /* A few helper macro's because this is used a lot, added during recode by Syzop. */ /** function requiress a parameter: check if there's one, if not: return -1. */ -#define REQUIRE_PARAM() { if (i >= argc) { \ - who_sendhelp(client); \ - return -1; \ - } } while(0) +#define REQUIRE_PARAM() \ + { \ + if (i >= argc) \ + { \ + who_sendhelp(client); \ + return -1; \ + } \ + } \ + while (0) /** set option 'x' depending on 'what' (add/want or del/dontwant) */ -#define SET_OPTION(x) { if (what == WHO_ADD) \ - x = WHO_WANT; \ - else \ - x = WHO_DONTWANT; \ - } while(0) +#define SET_OPTION(x) \ + { \ + if (what == WHO_ADD) \ + x = WHO_WANT; \ + else \ + x = WHO_DONTWANT; \ + } \ + while (0) /** Eat a param, set the param in memory and set the option to want or dontwant */ -#define DOIT(x,y) { REQUIRE_PARAM(); x = argv[i]; SET_OPTION(y); i++; } while(0) +#define DOIT(x, y) \ + { \ + REQUIRE_PARAM(); \ + x = argv[i]; \ + SET_OPTION(y); \ + i++; \ + } \ + while (0) if (*s != '-' && *s != '+') return 0; while (*s) - { + { switch (*s) { case '+': - what = WHO_ADD; - break; + what = WHO_ADD; + break; case '-': what = WHO_DEL; break; @@ -363,7 +376,7 @@ static int parse_who_options(Client *client, int argc, const char **argv) break; if (what == WHO_ADD) who_flags |= WF_IP; - + else who_flags &= ~WF_IP; break; @@ -372,9 +385,9 @@ static int parse_who_options(Client *client, int argc, const char **argv) return -1; } s++; - } + } - return i; + return i; #undef REQUIRE_PARAM #undef SET_OPTION #undef DOIT @@ -385,7 +398,8 @@ static int can_see(Client *requester, Client *target, Channel *channel) int ret = 0; char has_common_chan = 0; - do { + do + { /* can only see people */ if (!IsUser(target)) return WHO_CANTSEE; @@ -395,7 +409,8 @@ static int can_see(Client *requester, Client *target, Channel *channel) { if (!IsOper(target)) return ret | WHO_CANTSEE; - if (IsHideOper(target)) { + if (IsHideOper(target)) + { if (IsOper(requester)) ret |= WHO_OPERSEE; else @@ -410,7 +425,7 @@ static int can_see(Client *requester, Client *target, Channel *channel) /* if they only want people on a certain channel. */ if (wfl.want_channel != WHO_DONTCARE) - { + { Channel *chan = find_channel(wfl.channel); if (!chan && wfl.want_channel == WHO_WANT) return WHO_CANTSEE; @@ -477,7 +492,7 @@ static int can_see(Client *requester, Client *target, Channel *channel) if (wfl.want_port != WHO_DONTCARE) { int port; - + if (!MyUser(target)) return WHO_CANTSEE; @@ -546,8 +561,7 @@ static int can_see(Client *requester, Client *target, Channel *channel) if (!user_can_see_member(requester, target, channel)) break; /* invisible (eg: due to delayjoin) */ - } - else + } else { /* a user/mask who */ @@ -583,7 +597,7 @@ static int can_see(Client *requester, Client *target, Channel *channel) static void do_channel_who(Client *client, Channel *channel, const char *mask) { Member *cm = channel->members; - if (IsMember(client, channel) || ValidatePermissionsForPath("channel:see:who:onchannel",client,NULL,channel,NULL)) + if (IsMember(client, channel) || ValidatePermissionsForPath("channel:see:who:onchannel", client, NULL, channel, NULL)) who_flags |= WF_ONCHANNEL; for (cm = channel->members; cm; cm = cm->next) @@ -596,11 +610,11 @@ static void do_channel_who(Client *client, Channel *channel, const char *mask) make_who_status(client, acptr, channel, cm, status, cansee); send_who_reply(client, acptr, channel->name, status, ""); - } + } } -static void make_who_status(Client *client, Client *acptr, Channel *channel, - Member *cm, char *status, int cansee) +static void make_who_status(Client *client, Client *acptr, Channel *channel, + Member *cm, char *status, int cansee) { int i = 0; Hook *h; @@ -622,13 +636,13 @@ static void make_who_status(Client *client, Client *acptr, Channel *channel, if (ret != 0) status[i++] = (char)ret; } - + if (IsOper(acptr) && (!IsHideOper(acptr) || client == acptr || IsOper(client))) status[i++] = '*'; if (IsOper(acptr) && (IsHideOper(acptr) && client != acptr && IsOper(client))) status[i++] = '!'; - + if (cansee & WHO_OPERSEE) status[i++] = '?'; @@ -640,8 +654,7 @@ static void make_who_status(Client *client, Client *acptr, Channel *channel, char c = mode_to_prefix(*cm->member_modes); if (c) status[i++] = c; - } - else + } else { /* NAMES reply with all rights included (multi-prefix / NAMESX) */ strcpy(&status[i], modes_to_prefix(cm->member_modes)); @@ -654,7 +667,7 @@ static void make_who_status(Client *client, Client *acptr, Channel *channel, static void do_other_who(Client *client, const char *mask) { -int oper = IsOper(client); + int oper = IsOper(client); if (strchr(mask, '*') || strchr(mask, '?')) { @@ -665,18 +678,20 @@ int oper = IsOper(client); list_for_each_entry(acptr, &client_list, client_node) { - int cansee; - char status[20]; - const char *channel; - int flg; + int cansee; + char status[20]; + const char *channel; + int flg; if (!IsUser(acptr)) continue; - if (!oper) { + if (!oper) + { /* non-opers can only search on nick here */ if (!match_simple(mask, acptr->name)) continue; - } else { + } else + { /* opers can search on name, ident, virthost, ip and realhost. * Yes, I like readable if's -- Syzop. */ @@ -690,7 +705,7 @@ int oper = IsOper(client); /* nothing matched... */ continue; } -matchok: + matchok: if ((cansee = can_see(client, acptr, NULL)) & WHO_CANTSEE) continue; if (WHOLIMIT && !IsOper(client) && ++i > WHOLIMIT) @@ -703,8 +718,7 @@ matchok: make_who_status(client, acptr, NULL, NULL, status, cansee); send_who_reply(client, acptr, channel, status, (flg & FVC_HIDDEN) ? "~" : ""); } - } - else + } else { /* just a single client (no wildcards detected) */ Client *acptr = find_client(mask, NULL); @@ -725,8 +739,8 @@ matchok: } } -static void send_who_reply(Client *client, Client *acptr, - const char *channel, const char *status, const char *xstat) +static void send_who_reply(Client *client, Client *acptr, + const char *channel, const char *status, const char *xstat) { char *stat; const char *host; @@ -743,35 +757,35 @@ static void send_who_reply(Client *client, Client *acptr, host = (acptr->ip ? acptr->ip : acptr->user->realhost); else host = GetHost(acptr); - } - else + } else host = GetHost(acptr); - - if (IsULine(acptr) && !IsOper(client) && !ValidatePermissionsForPath("server:info:map:ulines",client,acptr,NULL,NULL) && HIDE_ULINES) + + if (IsULine(acptr) && !IsOper(client) && !ValidatePermissionsForPath("server:info:map:ulines", client, acptr, NULL, NULL) && HIDE_ULINES) { - sendnumeric(client, RPL_WHOREPLY, - channel, /* channel name */ - acptr->user->username, /* user name */ - host, /* hostname */ - "hidden", /* let's hide the server from normal users if the server is a uline and HIDE_ULINES is on */ - acptr->name, /* nick */ - stat, /* status */ - 0, /* hops (hidden) */ - acptr->info /* realname */ - ); - - } else { sendnumeric(client, RPL_WHOREPLY, - channel, /* channel name */ - acptr->user->username, /* user name */ - host, /* hostname */ - acptr->user->server, /* server name */ - acptr->name, /* nick */ - stat, /* status */ - flat ? 0 : acptr->hopcount, /* hops */ - acptr->info /* realname */ - ); + channel, /* channel name */ + acptr->user->username, /* user name */ + host, /* hostname */ + "hidden", /* let's hide the server from normal users if the server is a uline and HIDE_ULINES is on */ + acptr->name, /* nick */ + stat, /* status */ + 0, /* hops (hidden) */ + acptr->info /* realname */ + ); + + } else + { + sendnumeric(client, RPL_WHOREPLY, + channel, /* channel name */ + acptr->user->username, /* user name */ + host, /* hostname */ + acptr->user->server, /* server name */ + acptr->name, /* nick */ + stat, /* status */ + flat ? 0 : acptr->hopcount, /* hops */ + acptr->info /* realname */ + ); } safe_free(stat); } @@ -789,7 +803,7 @@ static const char *first_visible_channel(Client *client, Client *acptr, int *flg int ret = EX_ALLOW; int operoverride = 0; int showchannel = 0; - + /* Note that the code below is almost identical to the one in /WHOIS */ if (ShowChannel(client, channel)) @@ -807,23 +821,22 @@ static const char *first_visible_channel(Client *client, Client *acptr, int *flg if (n == EX_DENY) { ret = EX_DENY; - } - else if (n == EX_ALWAYS_DENY) + } else if (n == EX_ALWAYS_DENY) { ret = EX_ALWAYS_DENY; break; } } - + if (ret == EX_DENY) showchannel = 0; - - if (!showchannel && (ValidatePermissionsForPath("channel:see:who:secret",client,NULL,channel,NULL) || ValidatePermissionsForPath("channel:see:whois",client,NULL,channel,NULL))) + + if (!showchannel && (ValidatePermissionsForPath("channel:see:who:secret", client, NULL, channel, NULL) || ValidatePermissionsForPath("channel:see:whois", client, NULL, channel, NULL))) { showchannel = 1; /* OperOverride */ operoverride = 1; } - + if ((ret == EX_ALWAYS_DENY) && (acptr != client)) continue; /* a module asked us to really not expose this channel, so we don't (except target==ourselves). */ diff --git a/src/modules/whois.c b/src/modules/whois.c index ad22d0684..6b8e0f370 100644 --- a/src/modules/whois.c +++ b/src/modules/whois.c @@ -22,19 +22,18 @@ #include "unrealircd.h" /* Structs */ -ModuleHeader MOD_HEADER - = { - "whois", /* Name of module */ - "5.0", /* Version */ - "command /whois", /* Short description of module */ - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "whois", /* Name of module */ + "5.0", /* Version */ + "command /whois", /* Short description of module */ + "UnrealIRCd Team", + "unrealircd-6", +}; typedef enum WhoisConfigUser { - WHOIS_CONFIG_USER_EVERYONE = 1, - WHOIS_CONFIG_USER_SELF = 2, - WHOIS_CONFIG_USER_OPER = 3, + WHOIS_CONFIG_USER_EVERYONE = 1, + WHOIS_CONFIG_USER_SELF = 2, + WHOIS_CONFIG_USER_OPER = 3, } WhoisConfigUser; #define HIGHEST_WHOIS_CONFIG_USER_VALUE 3 /* adjust this if you edit the enum above !! */ @@ -48,7 +47,7 @@ typedef struct WhoisConfig WhoisConfig; struct WhoisConfig { WhoisConfig *prev, *next; char *name; - WhoisConfigDetails permissions[HIGHEST_WHOIS_CONFIG_USER_VALUE+1]; + WhoisConfigDetails permissions[HIGHEST_WHOIS_CONFIG_USER_VALUE + 1]; }; /* Global variables */ @@ -220,7 +219,7 @@ static int whois_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *err if (cep->value) { config_error("%s:%i: set::whois-details::%s item has a value, which is unexpected. Check your syntax!", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); errors++; continue; } @@ -229,14 +228,13 @@ static int whois_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *err if (!whois_config_user_strtovalue(cepp->name)) { config_error("%s:%i: set::whois-details::%s contains unknown user category called '%s', must be one of: everyone, self, ircop", - cepp->file->filename, cepp->line_number, cep->name, cepp->name); + cepp->file->filename, cepp->line_number, cep->name, cepp->name); errors++; continue; - } else - if (!cepp->value || !whois_config_details_strtovalue(cepp->value)) + } else if (!cepp->value || !whois_config_details_strtovalue(cepp->value)) { config_error("%s:%i: set::whois-details::%s contains unknown details type '%s', must be one of: full, limited, none", - cepp->file->filename, cepp->line_number, cep->name, cepp->name); + cepp->file->filename, cepp->line_number, cep->name, cepp->name); errors++; continue; } /* else it is good */ @@ -368,21 +366,21 @@ CMD_FUNC(cmd_whois) if (whois_get_policy(client, target, "basic") > WHOIS_CONFIG_DETAILS_NONE) { add_nvplist_numeric(&list, -1000000, "basic", client, RPL_WHOISUSER, target->name, - target->user->username, - IsHidden(target) ? target->user->virthost : target->user->realhost, - target->info); + target->user->username, + IsHidden(target) ? target->user->virthost : target->user->realhost, + target->info); } if (whois_get_policy(client, target, "modes") > WHOIS_CONFIG_DETAILS_NONE) { add_nvplist_numeric(&list, -100000, "modes", client, RPL_WHOISMODES, target->name, - get_usermode_string(target), target->user->snomask ? target->user->snomask : ""); + get_usermode_string(target), target->user->snomask ? target->user->snomask : ""); } if (whois_get_policy(client, target, "realhost") > WHOIS_CONFIG_DETAILS_NONE) { add_nvplist_numeric(&list, -90000, "realhost", client, RPL_WHOISHOST, target->name, - (MyConnect(target) && strcmp(target->ident, "unknown")) ? target->ident : "*", - target->user->realhost, target->ip ? target->ip : ""); + (MyConnect(target) && strcmp(target->ident, "unknown")) ? target->ident : "*", + target->user->realhost, target->ip ? target->ip : ""); } if (IsRegNick(target) && (whois_get_policy(client, target, "registered-nick") > WHOIS_CONFIG_DETAILS_NONE)) @@ -401,7 +399,7 @@ CMD_FUNC(cmd_whois) Hook *h; int ret = EX_ALLOW; int operoverride = 0; - + channel = lp->channel; showchannel = 0; @@ -420,28 +418,27 @@ CMD_FUNC(cmd_whois) if (n == EX_DENY) { ret = EX_DENY; - } - else if (n == EX_ALWAYS_DENY) + } else if (n == EX_ALWAYS_DENY) { ret = EX_ALWAYS_DENY; break; } } - + if (ret == EX_DENY) showchannel = 0; - + /* If the channel is normally hidden, but the user is an IRCOp, * and has the channel:see:whois privilege, * and set::whois-details for 'channels' has 'oper full', * then show it: */ - if (!showchannel && (ValidatePermissionsForPath("channel:see:whois",client,NULL,channel,NULL)) && (policy == WHOIS_CONFIG_DETAILS_FULL)) + if (!showchannel && (ValidatePermissionsForPath("channel:see:whois", client, NULL, channel, NULL)) && (policy == WHOIS_CONFIG_DETAILS_FULL)) { showchannel = 1; /* OperOverride */ operoverride = 1; } - + if ((ret == EX_ALWAYS_DENY) && (target != client)) continue; /* a module asked us to really not expose this channel, so we don't (except target==ourselves). */ @@ -455,7 +452,7 @@ CMD_FUNC(cmd_whois) { if (len + strlen(channel->name) > (size_t)BUFSIZE - 4 - mlen) { - add_nvplist_numeric_fmt(&list, -70500-channel_whois_lines, "channels", client, RPL_WHOISCHANNELS, + add_nvplist_numeric_fmt(&list, -70500 - channel_whois_lines, "channels", client, RPL_WHOISCHANNELS, "%s :%s", target->name, buf); channel_whois_lines++; *buf = '\0'; @@ -471,8 +468,7 @@ CMD_FUNC(cmd_whois) { /* '?' means it's a secret/private channel (too) */ *(buf + len++) = '?'; - } - else + } else { /* public channel but hidden in WHOIS (umode +p, service bot, etc) */ *(buf + len++) = '!'; @@ -485,8 +481,7 @@ CMD_FUNC(cmd_whois) char c = mode_to_prefix(*lp->member_modes); if (c) *(buf + len++) = c; - } - else + } else { /* NAMES reply with all rights included (multi-prefix / NAMESX) */ strcpy(buf + len, modes_to_prefix(lp->member_modes)); @@ -503,8 +498,8 @@ CMD_FUNC(cmd_whois) if (buf[0] != '\0') { - add_nvplist_numeric_fmt(&list, -70500-channel_whois_lines, "channels", client, RPL_WHOISCHANNELS, - "%s :%s", target->name, buf); + add_nvplist_numeric_fmt(&list, -70500 - channel_whois_lines, "channels", client, RPL_WHOISCHANNELS, + "%s :%s", target->name, buf); channel_whois_lines++; } } @@ -535,8 +530,7 @@ CMD_FUNC(cmd_whois) add_nvplist_numeric_fmt(&list, -40000, "oper", client, RPL_WHOISOPERATOR, "%s :is %s (%s) [%s]", target->name, "an IRC Operator", operlogin, operclass); - } else - if (operlogin) + } else if (operlogin) { add_nvplist_numeric_fmt(&list, -40000, "oper", client, RPL_WHOISOPERATOR, "%s :is %s (%s)", @@ -544,10 +538,9 @@ CMD_FUNC(cmd_whois) } else { add_nvplist_numeric(&list, -40000, "oper", client, RPL_WHOISOPERATOR, - target->name, "an IRC Operator"); + target->name, "an IRC Operator"); } - } else - if (policy == WHOIS_CONFIG_DETAILS_LIMITED) + } else if (policy == WHOIS_CONFIG_DETAILS_LIMITED) { add_nvplist_numeric(&list, -40000, "oper", client, RPL_WHOISOPERATOR, target->name, "an IRC Operator"); @@ -561,8 +554,7 @@ CMD_FUNC(cmd_whois) { add_nvplist_numeric(&list, -30000, "secure", client, RPL_WHOISSECURE, target->name, "is using a Secure Connection"); - } else - if (policy == WHOIS_CONFIG_DETAILS_FULL) + } else if (policy == WHOIS_CONFIG_DETAILS_FULL) { const char *ciphers = tls_get_cipher(target); if (ciphers) @@ -570,9 +562,10 @@ CMD_FUNC(cmd_whois) add_nvplist_numeric_fmt(&list, -30000, "secure", client, RPL_WHOISSECURE, "%s :is using a Secure Connection [%s]", target->name, ciphers); - } else { + } else + { add_nvplist_numeric(&list, -30000, "secure", client, RPL_WHOISSECURE, - target->name, "is using a Secure Connection"); + target->name, "is using a Secure Connection"); } } } @@ -596,10 +589,10 @@ CMD_FUNC(cmd_whois) { if (len + strlen(s->name) > (size_t)BUFSIZE - 4 - mlen) { - buf[len-1] = '\0'; - add_nvplist_numeric_fmt(&list, -15000-security_groups_whois_lines, "security-groups", + buf[len - 1] = '\0'; + add_nvplist_numeric_fmt(&list, -15000 - security_groups_whois_lines, "security-groups", target, RPL_WHOISSPECIAL, - "%s :is in security-groups: %s", target->name, buf); + "%s :is in security-groups: %s", target->name, buf); security_groups_whois_lines++; *buf = '\0'; len = 0; @@ -607,7 +600,7 @@ CMD_FUNC(cmd_whois) if (strcmp(s->name, "known-users") && user_allowed_by_security_group(target, s)) { strcpy(buf + len, s->name); - len += strlen(buf+len); + len += strlen(buf + len); strcpy(buf + len, ","); len++; } @@ -615,10 +608,10 @@ CMD_FUNC(cmd_whois) if (*buf) { - buf[len-1] = '\0'; - add_nvplist_numeric_fmt(&list, -15000-security_groups_whois_lines, "security-groups", + buf[len - 1] = '\0'; + add_nvplist_numeric_fmt(&list, -15000 - security_groups_whois_lines, "security-groups", client, RPL_WHOISSPECIAL, - "%s :is in security-groups: %s", target->name, buf); + "%s :is in security-groups: %s", target->name, buf); security_groups_whois_lines++; } } @@ -637,7 +630,7 @@ CMD_FUNC(cmd_whois) { if (hideoper && !IsOper(client) && s->setby && !strcmp(s->setby, "oper")) continue; /* hide oper-based swhois entries */ - add_nvplist_numeric(&list, 100000+swhois_lines, "swhois", client, RPL_WHOISSPECIAL, + add_nvplist_numeric(&list, 100000 + swhois_lines, "swhois", client, RPL_WHOISSPECIAL, target->name, s->line); swhois_lines++; } diff --git a/src/modules/whowas.c b/src/modules/whowas.c index 85cd641f2..da4d94a78 100644 --- a/src/modules/whowas.c +++ b/src/modules/whowas.c @@ -24,16 +24,15 @@ CMD_FUNC(cmd_whowas); -#define MSG_WHOWAS "WHOWAS" +#define MSG_WHOWAS "WHOWAS" -ModuleHeader MOD_HEADER - = { - "whowas", - "5.0", - "command /whowas", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "whowas", + "5.0", + "command /whowas", + "UnrealIRCd Team", + "unrealircd-6", +}; MOD_INIT() { @@ -64,8 +63,8 @@ CMD_FUNC(cmd_whowas) { char request[BUFSIZE]; WhoWas *temp; - int cur = 0; - int max = -1, found = 0; + int cur = 0; + int max = -1, found = 0; char *p, *nick; if (parc < 2) @@ -99,32 +98,32 @@ CMD_FUNC(cmd_whowas) if (!mycmp(nick, temp->name)) { sendnumeric(client, RPL_WHOWASUSER, temp->name, - temp->username, - BadPtr(temp->virthost) ? temp->hostname : temp->virthost, - temp->realname); - if (!BadPtr(temp->ip) && ValidatePermissionsForPath("client:see:ip",client,NULL,NULL,NULL)) + temp->username, + BadPtr(temp->virthost) ? temp->hostname : temp->virthost, + temp->realname); + if (!BadPtr(temp->ip) && ValidatePermissionsForPath("client:see:ip", client, NULL, NULL, NULL)) { GeoIPResult *geo = geoip_lookup(temp->ip); sendnumericfmt(client, RPL_WHOISHOST, "%s :was connecting from %s@%s %s", - temp->name, - temp->username, temp->hostname, - temp->ip ? temp->ip : ""); + temp->name, + temp->username, temp->hostname, + temp->ip ? temp->ip : ""); if (geo) { if (geo->country_code && geo->country_name) { sendnumericfmt(client, RPL_WHOISCOUNTRY, "%s %s :was connecting from %s", - temp->name, - geo->country_code, - geo->country_name); + temp->name, + geo->country_code, + geo->country_name); } if (geo->asn) { sendnumericfmt(client, RPL_WHOISASN, "%s %u :was connecting from AS%u [%s]", - temp->name, - geo->asn, - geo->asn, - geo->asname ? geo->asname : "UNKNOWN"); + temp->name, + geo->asn, + geo->asn, + geo->asname ? geo->asname : "UNKNOWN"); } free_geoip_result(geo); } @@ -132,8 +131,8 @@ CMD_FUNC(cmd_whowas) if (IsOper(client) && !BadPtr(temp->account)) { sendnumericfmt(client, RPL_WHOISLOGGEDIN, "%s %s :was logged in as", - temp->name, - temp->account); + temp->name, + temp->account); } if (!((find_uline(temp->servername)) && !IsOper(client) && HIDE_ULINES)) { diff --git a/src/modules/whowasdb.c b/src/modules/whowasdb.c index cd0fe2100..b64984fed 100644 --- a/src/modules/whowasdb.c +++ b/src/modules/whowasdb.c @@ -7,15 +7,15 @@ #include "unrealircd.h" ModuleHeader MOD_HEADER = { - "whowasdb", - "1.0", - "Stores and retrieves WHOWAS history", - "UnrealIRCd Team", - "unrealircd-6", + "whowasdb", + "1.0", + "Stores and retrieves WHOWAS history", + "UnrealIRCd Team", + "unrealircd-6", }; /* Our header */ -#define WHOWASDB_HEADER 0x57484F57 +#define WHOWASDB_HEADER 0x57484F57 /* Database version */ #define WHOWASDB_VERSION 100 /* Save whowas of users to file every seconds */ @@ -26,8 +26,8 @@ ModuleHeader MOD_HEADER = { */ #define WHOWASDB_SAVE_EVERY_DELTA -60 -#define MAGIC_WHOWASDB_START 0x11111111 -#define MAGIC_WHOWASDB_END 0x22222222 +#define MAGIC_WHOWASDB_START 0x11111111 +#define MAGIC_WHOWASDB_END 0x22222222 // #undef BENCHMARK @@ -35,43 +35,49 @@ ModuleHeader MOD_HEADER = { * disabling it in the entire file for now... */ #if defined(__GNUC__) -#pragma GCC diagnostic ignored "-Waddress" + #pragma GCC diagnostic ignored "-Waddress" #endif #define WARN_WRITE_ERROR(fname) \ - do { \ + do \ + { \ unreal_log(ULOG_ERROR, "whowasdb", "WHOWASDB_FILE_WRITE_ERROR", NULL, \ - "[whowasdb] Error writing to temporary database file $filename: $system_error", \ - log_data_string("filename", fname), \ - log_data_string("system_error", unrealdb_get_error_string())); \ - } while(0) + "[whowasdb] Error writing to temporary database file $filename: $system_error", \ + log_data_string("filename", fname), \ + log_data_string("system_error", unrealdb_get_error_string())); \ + } while (0) #define W_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ WARN_WRITE_ERROR(tmpfname); \ unrealdb_close(db); \ return 0; \ } \ - } while(0) + } while (0) #define W_SAFE_PROPERTY(db, x, y) \ - do { \ + do \ + { \ if (x && y && (!unrealdb_write_str(db, x) || !unrealdb_write_str(db, y))) \ { \ WARN_WRITE_ERROR(tmpfname); \ unrealdb_close(db); \ return 0; \ } \ - } while(0) + } while (0) #define IsMDErr(x, y, z) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ config_error("A critical error occurred when registering ModData for %s: %s", MOD_HEADER.name, ModuleGetErrorStr((z)->handle)); \ return MOD_FAILED; \ } \ - } while(0) + } while (0) /* Structs */ struct cfgstruct { @@ -197,13 +203,11 @@ int whowasdb_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { config_error("%s:%i: blank set::whowasdb::%s without value", cep->file->filename, cep->line_number, cep->name); errors++; - } else - if (!strcmp(cep->name, "database")) + } else if (!strcmp(cep->name, "database")) { convert_to_absolute_path(&cep->value, PERMDATADIR); safe_strdup(test.database, cep->value); - } else - if (!strcmp(cep->name, "db-secret")) + } else if (!strcmp(cep->name, "db-secret")) { const char *err; if ((err = unrealdb_test_secret(cep->value))) @@ -274,16 +278,15 @@ int count_whowas_and_user_entries(void) int cnt = 0; Client *client; - for (i=0; i < NICKNAMEHISTORYLENGTH; i++) + for (i = 0; i < NICKNAMEHISTORYLENGTH; i++) { WhoWas *e = &WHOWAS[i]; if (e->name) cnt++; } - list_for_each_entry(client, &client_list, client_node) - if (IsUser(client)) - cnt++; + list_for_each_entry(client, &client_list, client_node) if (IsUser(client)) + cnt++; return cnt; } @@ -316,7 +319,7 @@ int write_whowasdb(void) cnt = count_whowas_and_user_entries(); W_SAFE(unrealdb_write_int64(db, cnt)); - for (i=0; i < NICKNAMEHISTORYLENGTH; i++) + for (i = 0; i < NICKNAMEHISTORYLENGTH; i++) { WhoWas *e = &WHOWAS[i]; if (e->name) @@ -364,7 +367,7 @@ int write_whowasdb(void) #ifdef BENCHMARK gettimeofday(&tv_beta, NULL); config_status("[whowasdb] Benchmark: SAVE DB: %ld microseconds", - ((tv_beta.tv_sec - tv_alpha.tv_sec) * 1000000) + (tv_beta.tv_usec - tv_alpha.tv_usec)); + ((tv_beta.tv_sec - tv_alpha.tv_sec) * 1000000) + (tv_beta.tv_usec - tv_alpha.tv_usec)); #endif return 1; } @@ -400,7 +403,8 @@ int write_whowas_entry(UnrealDB *db, const char *tmpfname, WhoWas *e) } #define FreeWhowasEntry() \ - do { \ + do \ + { \ /* Some of these might be NULL */ \ safe_free(key); \ safe_free(value); \ @@ -414,17 +418,19 @@ int write_whowas_entry(UnrealDB *db, const char *tmpfname, WhoWas *e) safe_free(server); \ safe_free(virthost); \ safe_free(account); \ - } while(0) + } while (0) #define R_SAFE(x) \ - do { \ - if (!(x)) { \ + do \ + { \ + if (!(x)) \ + { \ config_warn("[whowasdb] Read error from database file '%s' (possible corruption): %s", cfg.database, unrealdb_get_error_string()); \ unrealdb_close(db); \ FreeWhowasEntry(); \ return 0; \ } \ - } while(0) + } while (0) int read_whowasdb(void) { @@ -462,8 +468,7 @@ int read_whowasdb(void) /* Database does not exist. Could be first boot */ config_warn("[whowasdb] No database present at '%s', will start a new one", cfg.database); return 1; - } else - if (unrealdb_get_error_code() == UNREALDB_ERROR_NOTCRYPTED) + } else if (unrealdb_get_error_code() == UNREALDB_ERROR_NOTCRYPTED) { /* Re-open as unencrypted */ db = unrealdb_open(cfg.database, UNREALDB_MODE_READ, NULL); @@ -497,7 +502,7 @@ int read_whowasdb(void) R_SAFE(unrealdb_read_int64(db, &count)); - for (i=1; i <= count; i++) + for (i = 1; i <= count; i++) { // Variables key = value = NULL; @@ -511,65 +516,53 @@ int read_whowasdb(void) config_error("[whowasdb] Corrupt database (%s) - whowasdb magic start is 0x%x. Further reading aborted.", cfg.database, magic); break; } - while(1) + while (1) { R_SAFE(unrealdb_read_str(db, &key)); R_SAFE(unrealdb_read_str(db, &value)); if (!strcmp(key, "nick")) { safe_strdup(nick, value); - } else - if (!strcmp(key, "username")) + } else if (!strcmp(key, "username")) { safe_strdup(username, value); - } else - if (!strcmp(key, "hostname")) + } else if (!strcmp(key, "hostname")) { safe_strdup(hostname, value); - } else - if (!strcmp(key, "ip")) + } else if (!strcmp(key, "ip")) { safe_strdup(ip, value); - } else - if (!strcmp(key, "realname")) + } else if (!strcmp(key, "realname")) { safe_strdup(realname, value); - } else - if (!strcmp(key, "connected_since")) + } else if (!strcmp(key, "connected_since")) { connected_since = atoll(value); safe_free(value); - } else - if (!strcmp(key, "logontime")) + } else if (!strcmp(key, "logontime")) { logontime = atoll(value); safe_free(value); - } else - if (!strcmp(key, "logofftime")) + } else if (!strcmp(key, "logofftime")) { logofftime = atoll(value); safe_free(value); - } else - if (!strcmp(key, "event")) + } else if (!strcmp(key, "event")) { event = atoi(value); if ((event < WHOWAS_LOWEST_EVENT) || (event > WHOWAS_HIGHEST_EVENT)) event = WHOWAS_EVENT_QUIT; /* safety */ safe_free(value); - } else - if (!strcmp(key, "server")) + } else if (!strcmp(key, "server")) { safe_strdup(server, value); - } else - if (!strcmp(key, "virthost")) + } else if (!strcmp(key, "virthost")) { safe_strdup(virthost, value); - } else - if (!strcmp(key, "account")) + } else if (!strcmp(key, "account")) { safe_strdup(account, value); - } else - if (!strcmp(key, "end")) + } else if (!strcmp(key, "end")) { safe_free(key); safe_free(value); diff --git a/src/modules/whox.c b/src/modules/whox.c index a1ad8538f..d0939c6af 100644 --- a/src/modules/whox.c +++ b/src/modules/whox.c @@ -9,60 +9,66 @@ #include "unrealircd.h" /* Module header */ -ModuleHeader MOD_HEADER - = { - "whox", - "5.0", - "command /who", - "UnrealIRCd Team", - "unrealircd-6", - }; +ModuleHeader MOD_HEADER = { + "whox", + "5.0", + "command /who", + "UnrealIRCd Team", + "unrealircd-6", +}; /* Defines */ -#define FIELD_CHANNEL 0x0001 -#define FIELD_HOP 0x0002 -#define FIELD_FLAGS 0x0004 -#define FIELD_HOST 0x0008 -#define FIELD_IP 0x0010 -#define FIELD_IDLE 0x0020 -#define FIELD_NICK 0x0040 -#define FIELD_INFO 0x0080 -#define FIELD_SERVER 0x0100 -#define FIELD_QUERYTYPE 0x0200 /* cookie for client */ -#define FIELD_USER 0x0400 -#define FIELD_ACCOUNT 0x0800 -#define FIELD_OPLEVEL 0x1000 /* meaningless and stupid, but whatever */ -#define FIELD_REALHOST 0x2000 -#define FIELD_MODES 0x4000 -#define FIELD_REPUTATION 0x8000 +#define FIELD_CHANNEL 0x0001 +#define FIELD_HOP 0x0002 +#define FIELD_FLAGS 0x0004 +#define FIELD_HOST 0x0008 +#define FIELD_IP 0x0010 +#define FIELD_IDLE 0x0020 +#define FIELD_NICK 0x0040 +#define FIELD_INFO 0x0080 +#define FIELD_SERVER 0x0100 +#define FIELD_QUERYTYPE 0x0200 /* cookie for client */ +#define FIELD_USER 0x0400 +#define FIELD_ACCOUNT 0x0800 +#define FIELD_OPLEVEL 0x1000 /* meaningless and stupid, but whatever */ +#define FIELD_REALHOST 0x2000 +#define FIELD_MODES 0x4000 +#define FIELD_REPUTATION 0x8000 -#define WMATCH_NICK 0x0001 -#define WMATCH_USER 0x0002 -#define WMATCH_OPER 0x0004 -#define WMATCH_HOST 0x0008 -#define WMATCH_INFO 0x0010 -#define WMATCH_SERVER 0x0020 -#define WMATCH_ACCOUNT 0x0040 -#define WMATCH_IP 0x0080 -#define WMATCH_MODES 0x0100 -#define WMATCH_CONTIME 0x0200 +#define WMATCH_NICK 0x0001 +#define WMATCH_USER 0x0002 +#define WMATCH_OPER 0x0004 +#define WMATCH_HOST 0x0008 +#define WMATCH_INFO 0x0010 +#define WMATCH_SERVER 0x0020 +#define WMATCH_ACCOUNT 0x0040 +#define WMATCH_IP 0x0080 +#define WMATCH_MODES 0x0100 +#define WMATCH_CONTIME 0x0200 -#define RPL_WHOSPCRPL 354 +#define RPL_WHOSPCRPL 354 #define WHO_ADD 1 #define WHO_DEL 0 #define HasField(x, y) ((x)->fields & (y)) -#define IsMatch(x, y) ((x)->matchsel & (y)) +#define IsMatch(x, y) ((x)->matchsel & (y)) -#define IsMarked(x) (moddata_client(x, whox_md).l) -#define SetMark(x) do { moddata_client(x, whox_md).l = 1; } while(0) -#define ClearMark(x) do { moddata_client(x, whox_md).l = 0; } while(0) +#define IsMarked(x) (moddata_client(x, whox_md).l) +#define SetMark(x) \ + do \ + { \ + moddata_client(x, whox_md).l = 1; \ + } while (0) +#define ClearMark(x) \ + do \ + { \ + moddata_client(x, whox_md).l = 0; \ + } while (0) /* Structs */ -struct who_format -{ +struct who_format { int fields; int matchsel; int umodes; @@ -90,7 +96,7 @@ static int convert_classical_who_request(Client *client, int *parc, const char * const char *whox_md_serialize(ModData *m); void whox_md_unserialize(const char *str, ModData *m); void whox_md_free(ModData *md); -static void append_format(char *buf, size_t bufsize, size_t *pos, const char *fmt, ...) __attribute__((format(printf,4,5))); +static void append_format(char *buf, size_t bufsize, size_t *pos, const char *fmt, ...) __attribute__((format(printf, 4, 5))); MOD_INIT() { @@ -227,16 +233,36 @@ CMD_FUNC(cmd_whox) { switch (ch) { - case 'o': fmt.matchsel |= WMATCH_OPER; continue; - case 'n': fmt.matchsel |= WMATCH_NICK; continue; - case 'u': fmt.matchsel |= WMATCH_USER; continue; - case 'h': fmt.matchsel |= WMATCH_HOST; continue; - case 'i': fmt.matchsel |= WMATCH_IP; continue; - case 'r': fmt.matchsel |= WMATCH_INFO; continue; - case 's': fmt.matchsel |= WMATCH_SERVER; continue; - case 'a': fmt.matchsel |= WMATCH_ACCOUNT; continue; - case 'm': fmt.matchsel |= WMATCH_MODES; continue; - case 't': fmt.matchsel |= WMATCH_CONTIME; continue; + case 'o': + fmt.matchsel |= WMATCH_OPER; + continue; + case 'n': + fmt.matchsel |= WMATCH_NICK; + continue; + case 'u': + fmt.matchsel |= WMATCH_USER; + continue; + case 'h': + fmt.matchsel |= WMATCH_HOST; + continue; + case 'i': + fmt.matchsel |= WMATCH_IP; + continue; + case 'r': + fmt.matchsel |= WMATCH_INFO; + continue; + case 's': + fmt.matchsel |= WMATCH_SERVER; + continue; + case 'a': + fmt.matchsel |= WMATCH_ACCOUNT; + continue; + case 'm': + fmt.matchsel |= WMATCH_MODES; + continue; + case 't': + fmt.matchsel |= WMATCH_CONTIME; + continue; case 'R': if (IsOper(client)) fmt.show_realhost = 1; @@ -256,22 +282,54 @@ CMD_FUNC(cmd_whox) { switch (*s) { - case 'c': fmt.fields |= FIELD_CHANNEL; break; - case 'd': fmt.fields |= FIELD_HOP; break; - case 'f': fmt.fields |= FIELD_FLAGS; break; - case 'h': fmt.fields |= FIELD_HOST; break; - case 'H': fmt.fields |= FIELD_REALHOST; break; - case 'i': fmt.fields |= FIELD_IP; break; - case 'l': fmt.fields |= FIELD_IDLE; break; - case 'n': fmt.fields |= FIELD_NICK; break; - case 'r': fmt.fields |= FIELD_INFO; break; - case 's': fmt.fields |= FIELD_SERVER; break; - case 't': fmt.fields |= FIELD_QUERYTYPE; break; - case 'u': fmt.fields |= FIELD_USER; break; - case 'a': fmt.fields |= FIELD_ACCOUNT; break; - case 'm': fmt.fields |= FIELD_MODES; break; - case 'o': fmt.fields |= FIELD_OPLEVEL; break; - case 'R': fmt.fields |= FIELD_REPUTATION; break; + case 'c': + fmt.fields |= FIELD_CHANNEL; + break; + case 'd': + fmt.fields |= FIELD_HOP; + break; + case 'f': + fmt.fields |= FIELD_FLAGS; + break; + case 'h': + fmt.fields |= FIELD_HOST; + break; + case 'H': + fmt.fields |= FIELD_REALHOST; + break; + case 'i': + fmt.fields |= FIELD_IP; + break; + case 'l': + fmt.fields |= FIELD_IDLE; + break; + case 'n': + fmt.fields |= FIELD_NICK; + break; + case 'r': + fmt.fields |= FIELD_INFO; + break; + case 's': + fmt.fields |= FIELD_SERVER; + break; + case 't': + fmt.fields |= FIELD_QUERYTYPE; + break; + case 'u': + fmt.fields |= FIELD_USER; + break; + case 'a': + fmt.fields |= FIELD_ACCOUNT; + break; + case 'm': + fmt.fields |= FIELD_MODES; + break; + case 'o': + fmt.fields |= FIELD_OPLEVEL; + break; + case 'R': + fmt.fields |= FIELD_REPUTATION; + break; case ',': s++; fmt.querytype = s; @@ -289,8 +347,8 @@ CMD_FUNC(cmd_whox) collapse(mask); - if ((ValidatePermissionsForPath("channel:see:who:secret",client,NULL,NULL,NULL) && - ValidatePermissionsForPath("channel:see:whois",client,NULL,NULL,NULL))) + if ((ValidatePermissionsForPath("channel:see:who:secret", client, NULL, NULL, NULL) && + ValidatePermissionsForPath("channel:see:whois", client, NULL, NULL, NULL))) { operspy = 1; } @@ -300,7 +358,7 @@ CMD_FUNC(cmd_whox) char *s = mask; int *umodes; int what = WHO_ADD; - + while (*s) { Umode *um; @@ -384,8 +442,8 @@ CMD_FUNC(cmd_whox) return; } - if (ValidatePermissionsForPath("channel:see:who:secret",client,NULL,NULL,NULL) || - ValidatePermissionsForPath("channel:see:whois",client,NULL,NULL,NULL)) + if (ValidatePermissionsForPath("channel:see:who:secret", client, NULL, NULL, NULL) || + ValidatePermissionsForPath("channel:see:whois", client, NULL, NULL, NULL)) { operspy = 1; } @@ -417,12 +475,12 @@ static int do_match(Client *client, Client *acptr, char *mask, struct who_format /* default */ if (fmt->matchsel == 0 && (match_simple(mask, acptr->name) || - match_simple(mask, acptr->user->username) || - match_simple(mask, GetHost(acptr)) || - (IsOper(client) && - (match_simple(mask, acptr->user->realhost) || - (acptr->ip && - match_simple(mask, acptr->ip)))))) + match_simple(mask, acptr->user->username) || + match_simple(mask, GetHost(acptr)) || + (IsOper(client) && + (match_simple(mask, acptr->user->realhost) || + (acptr->ip && + match_simple(mask, acptr->ip)))))) { return 1; } @@ -441,8 +499,8 @@ static int do_match(Client *client, Client *acptr, char *mask, struct who_format /* match hostname */ if (IsMatch(fmt, WMATCH_HOST) && (match_simple(mask, GetHost(acptr)) || - (IsOper(client) && (match_simple(mask, acptr->user->realhost) || - (acptr->ip && match_simple(mask, acptr->ip)))))) + (IsOper(client) && (match_simple(mask, acptr->user->realhost) || + (acptr->ip && match_simple(mask, acptr->ip)))))) { return 1; } @@ -453,7 +511,7 @@ static int do_match(Client *client, Client *acptr, char *mask, struct who_format /* match ip address */ if (IsMatch(fmt, WMATCH_IP) && IsOper(client) && acptr->ip && - match_user(mask, acptr, MATCH_CHECK_IP)) + match_user(mask, acptr, MATCH_CHECK_IP)) return 1; /* match account */ @@ -507,7 +565,7 @@ static int do_match(Client *client, Client *acptr, char *mask, struct who_format */ static void who_common_channel(Client *client, Channel *channel, - char *mask, int *maxmatches, struct who_format *fmt) + char *mask, int *maxmatches, struct who_format *fmt) { Membership *us; Member *cm; @@ -572,7 +630,7 @@ static void who_global(Client *client, char *mask, int operspy, struct who_forma /* Initialize the markers to zero */ list_for_each_entry(acptr, &client_list, client_node) - ClearMark(acptr); + ClearMark(acptr); /* First, if not operspy, then list all matching clients on common channels */ if (!operspy) @@ -601,11 +659,11 @@ static void who_global(Client *client, char *mask, int operspy, struct who_forma if (maxmatches > 0) { if (do_match(client, acptr, mask, fmt)) - { + { do_who(client, acptr, NULL, fmt); --maxmatches; - } - } + } + } } if (maxmatches <= 0) @@ -626,7 +684,7 @@ static void who_global(Client *client, char *mask, int operspy, struct who_forma */ static void do_who_on_channel(Client *client, Channel *channel, - int member, int operspy, struct who_format *fmt) + int member, int operspy, struct who_format *fmt) { Membership *us = find_membership_link(client->user->channel, channel); Member *cm; @@ -716,9 +774,9 @@ static void do_who(Client *client, Client *acptr, Channel *channel, struct who_f Hook *h; if (acptr->user->away) - status[i++] = 'G'; - else - status[i++] = 'H'; + status[i++] = 'G'; + else + status[i++] = 'H'; if (IsRegNick(acptr)) status[i++] = 'r'; @@ -751,8 +809,7 @@ static void do_who(Client *client, Client *acptr, Channel *channel, struct who_f char c = mode_to_prefix(*lp->member_modes); if (c) status[i++] = c; - } - else + } else { /* NAMES reply with all rights included (multi-prefix / NAMESX) */ strcpy(&status[i], modes_to_prefix(lp->member_modes)); @@ -762,7 +819,7 @@ static void do_who(Client *client, Client *acptr, Channel *channel, struct who_f } status[i] = '\0'; - + if (fmt->fields == 0) { char *host; @@ -773,10 +830,10 @@ static void do_who(Client *client, Client *acptr, Channel *channel, struct who_f else host = GetHost(acptr); sendnumeric(client, RPL_WHOREPLY, - channel ? channel->name : "*", - acptr->user->username, host, - hide ? "*" : acptr->user->server, - acptr->name, status, hide ? 0 : acptr->hopcount, acptr->info); + channel ? channel->name : "*", + acptr->user->username, host, + hide ? "*" : acptr->user->server, + acptr->name, status, hide ? 0 : acptr->hopcount, acptr->info); } else { str[0] = '\0'; @@ -818,7 +875,8 @@ static void do_who(Client *client, Client *acptr, Channel *channel, struct who_f if (*umodes == '+') umodes++; append_format(str, sizeof str, &pos, " %s", umodes); - } else { + } else + { append_format(str, sizeof str, &pos, " %s", "*"); } } @@ -827,7 +885,7 @@ static void do_who(Client *client, Client *acptr, Channel *channel, struct who_f if (HasField(fmt, FIELD_IDLE)) { append_format(str, sizeof str, &pos, " %d", - (int)((MyUser(acptr) && !hide_idle_time(client, acptr)) ? (TStime() - acptr->local->idle_since) : 0)); + (int)((MyUser(acptr) && !hide_idle_time(client, acptr)) ? (TStime() - acptr->local->idle_since) : 0)); } if (HasField(fmt, FIELD_ACCOUNT)) append_format(str, sizeof str, &pos, " %s", IsLoggedIn(acptr) ? acptr->user->account : "0"); @@ -887,7 +945,8 @@ static int convert_classical_who_request(Client *client, int *parc, const char * * 'WHO +c #something' (which includes 'm') * could mean either WHO or WHOX style */ - } else { + } else + { /* If we get here then it's an classical * UnrealIRCd-style WHO request which has * the order: WHO @@ -900,7 +959,8 @@ static int convert_classical_who_request(Client *client, int *parc, const char * const char *swap = parv[1]; parv[1] = parv[2]; parv[2] = swap; - } else { + } else + { /* A request like 'WHO +I' or 'WHO +R' */ parv[2] = parv[1]; parv[1] = "*"; @@ -973,10 +1033,10 @@ static int convert_classical_who_request(Client *client, int *parc, const char * } if ((*parv[2] == '+') || (*parv[2] == '-')) - parv[2] = parv[2]+1; /* strip '+'/'-' prefix, which does not exist in WHOX */ + parv[2] = parv[2] + 1; /* strip '+'/'-' prefix, which does not exist in WHOX */ sendnotice(client, "WHO request '%s' changed to match new WHOX syntax: 'WHO %s %s'", - oldrequest, parv[1], parv[2]); + oldrequest, parv[1], parv[2]); *orig_mask = parv[1]; } } diff --git a/src/operclass.c b/src/operclass.c index 853374b1b..d5c3fc212 100644 --- a/src/operclass.c +++ b/src/operclass.c @@ -8,23 +8,20 @@ typedef struct OperClassPathNode OperClassPathNode; typedef struct OperClassCallbackNode OperClassCallbackNode; -struct OperClassPathNode -{ - OperClassPathNode *prev,*next; +struct OperClassPathNode { + OperClassPathNode *prev, *next; OperClassPathNode *children; char *identifier; OperClassCallbackNode *callbacks; }; -struct OperClassCallbackNode -{ +struct OperClassCallbackNode { OperClassCallbackNode *prev, *next; OperClassPathNode *parent; OperClassEntryEvalCallback callback; }; -struct OperClassValidator -{ +struct OperClassValidator { Module *owner; OperClassCallbackNode *node; }; @@ -37,9 +34,9 @@ OperClassPathNode *rootEvalNode = NULL; OperClassValidator *OperClassAddValidator(Module *module, char *pathStr, OperClassEntryEvalCallback callback) { - OperClassPathNode *node,*nextNode; + OperClassPathNode *node, *nextNode; OperClassCallbackNode *callbackNode; - OperClassValidator *validator; + OperClassValidator *validator; OperClassACLPath *path = OperClass_parsePath(pathStr); if (!rootEvalNode) @@ -51,12 +48,12 @@ OperClassValidator *OperClassAddValidator(Module *module, char *pathStr, OperCla while (path) { - nextNode = OperClass_findPathNodeForIdentifier(path->identifier,node->children); + nextNode = OperClass_findPathNodeForIdentifier(path->identifier, node->children); if (!nextNode) { nextNode = safe_alloc(sizeof(OperClassPathNode)); safe_strdup(nextNode->identifier, path->identifier); - AddListItem(nextNode,node->children); + AddListItem(nextNode, node->children); } node = nextNode; path = path->next; @@ -64,11 +61,11 @@ OperClassValidator *OperClassAddValidator(Module *module, char *pathStr, OperCla callbackNode = safe_alloc(sizeof(OperClassCallbackNode)); callbackNode->callback = callback; - callbackNode->parent = node; - AddListItem(callbackNode,node->callbacks); + callbackNode->parent = node; + AddListItem(callbackNode, node->callbacks); validator = safe_alloc(sizeof(OperClassValidator)); - validator->node = callbackNode; + validator->node = callbackNode; validator->owner = module; if (module) @@ -101,14 +98,14 @@ void OperClassValidatorDel(OperClassValidator *validator) } validator->owner = NULL; } - + /* Technically, the below leaks memory if you don't re-register * another validator at same path, but it is cheaper than walking * back up and doing cleanup in practice, since this tree is very small */ - DelListItem(validator->node,validator->node->parent->callbacks); + DelListItem(validator->node, validator->node->parent->callbacks); safe_free(validator->node); - safe_free(validator); + safe_free(validator); } OperClassACLPath *OperClass_parsePath(const char *path) @@ -116,13 +113,13 @@ OperClassACLPath *OperClass_parsePath(const char *path) char *pathCopy = raw_strdup(path); OperClassACLPath *pathHead = NULL; OperClassACLPath *tmpPath; - char *str = strtok(pathCopy,":"); + char *str = strtok(pathCopy, ":"); while (str) { tmpPath = safe_alloc(sizeof(OperClassACLPath)); safe_strdup(tmpPath->identifier, str); - AddListItem(tmpPath,pathHead); - str = strtok(NULL,":"); + AddListItem(tmpPath, pathHead); + str = strtok(NULL, ":"); } while (pathHead->next) @@ -133,7 +130,7 @@ OperClassACLPath *OperClass_parsePath(const char *path) pathHead = tmpPath; } pathHead->next = pathHead->prev; - pathHead->prev = NULL; + pathHead->prev = NULL; safe_free(pathCopy); return pathHead; @@ -148,15 +145,15 @@ void OperClass_freePath(OperClassACLPath *path) safe_free(path->identifier); safe_free(path); path = next; - } + } } OperClassACL *OperClass_FindACL(OperClassACL *acl, char *name) { - for (;acl;acl = acl->next) + for (; acl; acl = acl->next) { - if (!strcmp(acl->name,name)) - { + if (!strcmp(acl->name, name)) + { return acl; } } @@ -167,7 +164,7 @@ OperClassPathNode *OperClass_findPathNodeForIdentifier(char *identifier, OperCla { for (; head; head = head->next) { - if (!strcmp(head->identifier,identifier)) + if (!strcmp(head->identifier, identifier)) { return head; } @@ -177,7 +174,7 @@ OperClassPathNode *OperClass_findPathNodeForIdentifier(char *identifier, OperCla unsigned char OperClass_evaluateACLEntry(OperClassACLEntry *entry, OperClassACLPath *path, OperClassCheckParams *params) { - OperClassPathNode *node = rootEvalNode; + OperClassPathNode *node = rootEvalNode; OperClassCallbackNode *callbackNode = NULL; unsigned char eval = 0; @@ -190,7 +187,7 @@ unsigned char OperClass_evaluateACLEntry(OperClassACLEntry *entry, OperClassACLP /* Go as deep as possible */ while (path->next && node) { - node = OperClass_findPathNodeForIdentifier(path->identifier,node); + node = OperClass_findPathNodeForIdentifier(path->identifier, node); /* If we can't find a node we need, and we have vars, no match */ if (!node) { @@ -210,10 +207,10 @@ unsigned char OperClass_evaluateACLEntry(OperClassACLEntry *entry, OperClassACLP /* We have a valid node, execute all callback nodes */ for (callbackNode = node->callbacks; callbackNode; callbackNode = callbackNode->next) { - eval = callbackNode->callback(entry->variables,params); + eval = callbackNode->callback(entry->variables, params); } - return eval; + return eval; } OperPermission ValidatePermissionsForPathEx(OperClassACL *acl, OperClassACLPath *path, OperClassCheckParams *params) @@ -229,7 +226,7 @@ OperPermission ValidatePermissionsForPathEx(OperClassACL *acl, OperClassACLPath path = path->next; /* Avoid first level since we have resolved it */ while (path && acl->acls) { - tmp = OperClass_FindACL(acl->acls,path->identifier); + tmp = OperClass_FindACL(acl->acls, path->identifier); if (!tmp) { aclNotFound = 1; @@ -259,12 +256,11 @@ OperPermission ValidatePermissionsForPathEx(OperClassACL *acl, OperClassACLPath if (entry->type == OPERCLASSENTRY_DENY && deny) continue; - result = OperClass_evaluateACLEntry(entry,basePath,params); + result = OperClass_evaluateACLEntry(entry, basePath, params); if (entry->type == OPERCLASSENTRY_ALLOW) { allow = result; - } - else + } else { deny = result; } @@ -317,7 +313,7 @@ OperPermission ValidatePermissionsForPath(const char *path, Client *client, Clie operPath = OperClass_parsePath(path); while (oc && operPath) { - OperClassACL *acl = OperClass_FindACL(oc->acls,operPath->identifier); + OperClassACL *acl = OperClass_FindACL(oc->acls, operPath->identifier); if (looping++ > 10) { unreal_log(ULOG_ERROR, "operclass", "OPERCLASS_LOOPING", client, @@ -333,7 +329,7 @@ OperPermission ValidatePermissionsForPath(const char *path, Client *client, Clie params->victim = victim; params->channel = channel; params->extra = extra; - + perm = ValidatePermissionsForPathEx(acl, operPath, params); OperClass_freePath(operPath); safe_free(params); @@ -347,7 +343,8 @@ OperPermission ValidatePermissionsForPath(const char *path, Client *client, Clie if (ce_operClass) { oc = ce_operClass->classStruct; - } else { + } else + { break; /* parent not found */ } } diff --git a/src/parse.c b/src/parse.c index cdd170ee7..1747f2a2a 100644 --- a/src/parse.c +++ b/src/parse.c @@ -143,7 +143,7 @@ void parse_client_queued(Client *client) { run_deferred_rule_only_spamfilters(client); } - + if (IsDead(client)) return; } @@ -220,12 +220,12 @@ void parse(Client *cptr, char *buffer, int length) #if defined(RAWCMDLOGGING) unreal_log(ULOG_INFO, "rawtraffic", "TRAFFIC_IN", cptr, - "<- $client: $data", - log_data_string("data", backupbuf)); + "<- $client: $data", + log_data_string("data", backupbuf)); #endif /* This poisons unused para elements that code should never access */ - for (i = 0; i < MAXPARA+2; i++) + for (i = 0; i < MAXPARA + 2; i++) para[i] = (char *)DEADBEEF_ADDR; /* First, skip any whitespace */ @@ -353,7 +353,7 @@ static void parse2(Client *cptr, Client **fromptr, MessageTag *mtags, int mtags_ ch++; } - RunHookReturn(HOOKTYPE_PRE_COMMAND, !=0, from, mtags, ch); + RunHookReturn(HOOKTYPE_PRE_COMMAND, != 0, from, mtags, ch); if (*ch == '\0') { @@ -366,7 +366,7 @@ static void parse2(Client *cptr, Client **fromptr, MessageTag *mtags, int mtags_ bytes = strlen(ch); /* Now let's figure out the command (or numeric)... */ - s = strchr(ch, ' '); /* s -> End of the command code */ + s = strchr(ch, ' '); /* s -> End of the command code */ len = (s) ? (s - ch) : 0; /* An early "guard": check for oversized command name @@ -377,8 +377,8 @@ static void parse2(Client *cptr, Client **fromptr, MessageTag *mtags, int mtags_ { ch[510] = '\0'; sendto_one(from, NULL, ":%s %d %s %s :Unknown command", - me.name, ERR_UNKNOWNCOMMAND, - from->name, ch); + me.name, ERR_UNKNOWNCOMMAND, + from->name, ch); ircstats.is_unco++; return; } @@ -391,8 +391,7 @@ static void parse2(Client *cptr, Client **fromptr, MessageTag *mtags, int mtags_ paramcount = MAXPARA; ircstats.is_num++; parse_addlag(cptr, bytes, mtags_bytes); - } - else + } else { /* Command (eg: PRIVMSG) */ int flags = 0; @@ -441,14 +440,14 @@ static void parse2(Client *cptr, Client **fromptr, MessageTag *mtags, int mtags_ */ if (IsShunned(cptr)) return; - + if (ch[0] != '\0') { if (IsUser(from)) { sendto_one(from, NULL, ":%s %d %s %s :Unknown command", - me.name, ERR_UNKNOWNCOMMAND, - from->name, ch); + me.name, ERR_UNKNOWNCOMMAND, + from->name, ch); } } ircstats.is_unco++; @@ -567,34 +566,36 @@ static void parse2(Client *cptr, Client **fromptr, MessageTag *mtags, int mtags_ memset(&clictx, 0, sizeof(clictx)); clictx.cmd = cmptr; clictx.fake_lag_added_msec = lag_added; - if ((cmptr->flags & CMD_TEXTANALYSIS) && MyUser(from) && (i>1)) + if ((cmptr->flags & CMD_TEXTANALYSIS) && MyUser(from) && (i > 1)) { memset(&text_analysis_storage, 0, sizeof(text_analysis_storage)); clictx.textanalysis = &text_analysis_storage; - RunHook(HOOKTYPE_ANALYZE_TEXT, from, para[i-1], clictx.textanalysis); + RunHook(HOOKTYPE_ANALYZE_TEXT, from, para[i - 1], clictx.textanalysis); } /* Now ready to execute the command */ #ifndef DEBUGMODE if (cmptr->flags & CMD_ALIAS) { - (*cmptr->aliasfunc) (&clictx, from, mtags, i, (const char **)para, cmptr->cmd); - } else { + (*cmptr->aliasfunc)(&clictx, from, mtags, i, (const char **)para, cmptr->cmd); + } else + { if (!cmptr->overriders) - (*cmptr->func) (&clictx, from, mtags, i, (const char **)para); + (*cmptr->func)(&clictx, from, mtags, i, (const char **)para); else - (*cmptr->overriders->func) (cmptr->overriders, &clictx, from, mtags, i, (const char **)para); + (*cmptr->overriders->func)(cmptr->overriders, &clictx, from, mtags, i, (const char **)para); } #else then = clock(); if (cmptr->flags & CMD_ALIAS) { - (*cmptr->aliasfunc) (&clictx, from, mtags, i, (const char **)para, cmptr->cmd); - } else { + (*cmptr->aliasfunc)(&clictx, from, mtags, i, (const char **)para, cmptr->cmd); + } else + { if (!cmptr->overriders) - (*cmptr->func) (&clictx, from, mtags, i, (const char **)para); + (*cmptr->func)(&clictx, from, mtags, i, (const char **)para); else - (*cmptr->overriders->func) (cmptr->overriders, &clictx, from, mtags, i, (const char **)para); + (*cmptr->overriders->func)(cmptr->overriders, &clictx, from, mtags, i, (const char **)para); } if (!IsDead(cptr)) { @@ -621,8 +622,7 @@ static void ban_handshake_data_flooder(Client *client) * affect any other connections from the same IP address. */ exit_client(client, NULL, "Handshake data flood detected"); - } - else + } else { /* take_action also takes care of removing any other clients with same host/ip */ take_action(client, iConf.handshake_data_flood_ban_action, "Handshake data flood detected", iConf.handshake_data_flood_ban_time, 0, NULL); @@ -652,12 +652,12 @@ long parse_addlag(Client *client, int command_bytes, int mtags_bytes) #ifdef FAKELAG_CONFIGURABLE !(client->local->class && (client->local->class->options & CLASS_OPT_NOFAKELAG)) && #endif - !ValidatePermissionsForPath("immune:lag",client,NULL,NULL,NULL)) + !ValidatePermissionsForPath("immune:lag", client, NULL, NULL, NULL)) { FloodSettings *settings = get_floodsettings_for_user(client, FLD_LAG_PENALTY); int lag_penalty = settings->period[FLD_LAG_PENALTY]; int lag_penalty_bytes = settings->limit[FLD_LAG_PENALTY]; - long msec = (1 + (command_bytes/lag_penalty_bytes) + (mtags_bytes/lag_penalty_bytes)) * lag_penalty; + long msec = (1 + (command_bytes / lag_penalty_bytes) + (mtags_bytes / lag_penalty_bytes)) * lag_penalty; client->local->fake_lag_msec += msec; @@ -704,8 +704,7 @@ void subtract_fake_lag(Client *client, long msec) if (total >= 0) { client->local->fake_lag_msec = (int)total; - } - else + } else { /* Readjust to whole seconds */ long secs = (-total + 999) / 1000; @@ -725,7 +724,7 @@ static int client_lagged_up(Client *client) return 0; if (IsServer(client)) return 0; - if (ValidatePermissionsForPath("immune:lag",client,NULL,NULL,NULL)) + if (ValidatePermissionsForPath("immune:lag", client, NULL, NULL, NULL)) return 0; if (client->local->fake_lag - TStime() < 10) return 0; @@ -787,7 +786,7 @@ static int do_numeric(int numeric, Client *client, MessageTag *recv_mtags, int p if (ret < 0) { unreal_log(ULOG_WARNING, "link", "STARTTLS_FAILED", client, - "Switching from plaintext to TLS via STARTTLS failed for server $client, this is unusual."); + "Switching from plaintext to TLS via STARTTLS failed for server $client, this is unusual."); reject_insecure_server(client); return ret; } @@ -829,24 +828,22 @@ static int do_numeric(int numeric, Client *client, MessageTag *recv_mtags, int p if (skip) { sendto_prefix_one(acptr, client, recv_mtags, ":%s %d %s %s", - client->name, numeric, acptr->name, skip+1); + client->name, numeric, acptr->name, skip + 1); } /* else.. malformed (no content) */ - } else { + } else + { sendto_prefix_one(acptr, client, recv_mtags, ":%s %d %s", - client->name, numeric, buffer); + client->name, numeric, buffer); } - } - else if (IsServer(acptr) && acptr->direction != client->direction) + } else if (IsServer(acptr) && acptr->direction != client->direction) sendto_prefix_one(acptr, client, recv_mtags, ":%s %d %s", - client->name, numeric, buffer); - } - else if ((acptr = find_server_quick(nick))) + client->name, numeric, buffer); + } else if ((acptr = find_server_quick(nick))) { if (!IsMe(acptr) && acptr->direction != client->direction) sendto_prefix_one(acptr, client, recv_mtags, ":%s %d %s", - client->name, numeric, buffer); - } - else if ((channel = find_channel(nick))) + client->name, numeric, buffer); + } else if ((channel = find_channel(nick))) { sendto_channel(channel, client, client->direction, 0, 0, SEND_ALL, recv_mtags, @@ -881,7 +878,7 @@ static void remove_unknown(Client *client, char *sender) */ if ((isdigit(*sender) && strlen(sender) <= SIDLEN) || strchr(sender, '.')) sendto_one(client, NULL, ":%s SQUIT %s :Unknown prefix (%s) from %s", - me.id, sender, sender, client->name); + me.id, sender, sender, client->name); else sendto_one(client, NULL, ":%s KILL %s :Ghost user", me.id, sender); } diff --git a/src/proc_io_client.c b/src/proc_io_client.c index 69caa2427..03485268c 100644 --- a/src/proc_io_client.c +++ b/src/proc_io_client.c @@ -40,7 +40,7 @@ int procio_client_connect(const char *file) #else fprintf(stderr, "Cannot communicate to UnrealIRCd: %s\n" "Perhaps your operating system does not support UNIX Sockets?\n", - strerror(ERRNO)); + strerror(ERRNO)); #endif return -1; } @@ -52,7 +52,7 @@ int procio_client_connect(const char *file) if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { fprintf(stderr, "Could not connect to '%s': %s\n", - CONTROLFILE, strerror(errno)); + CONTROLFILE, strerror(errno)); fprintf(stderr, "The IRC server does not appear to be running.\n"); close(fd); return -1; @@ -142,7 +142,7 @@ int procio_client(const char *command, int auto_color_logs) { fprintf(stderr, "Error while communicating to IRCd via '%s': %s\n" "Maybe the IRC server is not running?\n", - CONTROLFILE, strerror(errno)); + CONTROLFILE, strerror(errno)); close(fd); return -1; } @@ -150,16 +150,16 @@ int procio_client(const char *command, int auto_color_logs) if (!procio_send(fd, command)) { fprintf(stderr, "Error while sending command to IRCd via '%s'. Strange!\n", - CONTROLFILE); + CONTROLFILE); close(fd); return -1; } *buf = '\0'; dbuf_queue_init(&queue); - while(1) + while (1) { - n = recv(fd, buf, sizeof(buf)-1, 0); + n = recv(fd, buf, sizeof(buf) - 1, 0); if (n <= 0) break; buf[n] = '\0'; /* terminate the string */ @@ -173,22 +173,21 @@ int procio_client(const char *command, int auto_color_logs) { if (!strncmp(buf, "REPLY ", 6)) { - char *reply = buf+6; + char *reply = buf + 6; if (auto_color_logs == 0) printf("%s\n", reply); else if (auto_color_logs == 1) printf("%s\n", recolor_logs(reply)); else printf("%s\n", recolor_split(reply)); - } else - if (!strncmp(buf, "END ", 4)) + } else if (!strncmp(buf, "END ", 4)) { - int exitcode = atoi(buf+4); + int exitcode = atoi(buf + 4); close(fd); return exitcode; } } - } while(n > 0); + } while (n > 0); } /* IRCd hung up without saying goodbye, possibly problematic, diff --git a/src/proc_io_server.c b/src/proc_io_server.c index 7b8fe6cca..016dd39c3 100644 --- a/src/proc_io_server.c +++ b/src/proc_io_server.c @@ -48,7 +48,7 @@ void add_proc_io_server(void) listener = safe_alloc(sizeof(ConfigItem_listen)); safe_strdup(listener->file, CONTROLFILE); listener->socket_type = SOCKET_TYPE_UNIX; - listener->options = LISTENER_CONTROL|LISTENER_NO_CHECK_CONNECT_FLOOD|LISTENER_NO_CHECK_ZLINED; + listener->options = LISTENER_CONTROL | LISTENER_NO_CHECK_CONNECT_FLOOD | LISTENER_NO_CHECK_ZLINED; listener->start_handshake = start_of_control_client_handshake; listener->fd = -1; AddListItem(listener, conf_listen); @@ -140,7 +140,7 @@ CMD_FUNC(procio_rehash) sendto_one(client, NULL, "END 1"); return; } - + if (parv[1] && !strcmp(parv[1], "-tls")) { @@ -150,7 +150,8 @@ CMD_FUNC(procio_rehash) ret = reinit_tls(); sendto_one(client, NULL, "END %d", ret == 0 ? -1 : 0); ClearMonitorRehash(client); - } else { + } else + { SetMonitorRehash(client); unreal_log(ULOG_INFO, "config", "CONFIG_RELOAD", client, "Rehashing server configuration file [./unrealircd rehash]"); request_rehash(client); diff --git a/src/random.c b/src/random.c index ebb65cbda..a8803f422 100644 --- a/src/random.c +++ b/src/random.c @@ -25,7 +25,7 @@ #ifndef HAVE_ARC4RANDOM -#define KEYSTREAM_ONLY + #define KEYSTREAM_ONLY /* chacha_private.h from openssh/openssh-portable * "chacha-merged.c version 20080118 @@ -40,214 +40,230 @@ typedef unsigned int u32; typedef struct { - u32 input[16]; /* could be compressed */ + u32 input[16]; /* could be compressed */ } chacha_ctx; -#define U8C(v) (v##U) -#define U32C(v) (v##U) + #define U8C(v) (v##U) + #define U32C(v) (v##U) -#define U8V(v) ((u8)(v) & U8C(0xFF)) -#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF)) + #define U8V(v) ((u8)(v) & U8C(0xFF)) + #define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF)) -#define ROTL32(v, n) \ - (U32V((v) << (n)) | ((v) >> (32 - (n)))) + #define ROTL32(v, n) \ + (U32V((v) << (n)) | ((v) >> (32 - (n)))) -#define U8TO32_LITTLE(p) \ - (((u32)((p)[0]) ) | \ - ((u32)((p)[1]) << 8) | \ - ((u32)((p)[2]) << 16) | \ - ((u32)((p)[3]) << 24)) + #define U8TO32_LITTLE(p) \ + (((u32)((p)[0])) | \ + ((u32)((p)[1]) << 8) | \ + ((u32)((p)[2]) << 16) | \ + ((u32)((p)[3]) << 24)) -#define U32TO8_LITTLE(p, v) \ - do { \ - (p)[0] = U8V((v) ); \ - (p)[1] = U8V((v) >> 8); \ - (p)[2] = U8V((v) >> 16); \ - (p)[3] = U8V((v) >> 24); \ - } while (0) + #define U32TO8_LITTLE(p, v) \ + do \ + { \ + (p)[0] = U8V((v)); \ + (p)[1] = U8V((v) >> 8); \ + (p)[2] = U8V((v) >> 16); \ + (p)[3] = U8V((v) >> 24); \ + } while (0) -#define ROTATE(v,c) (ROTL32(v,c)) -#define XOR(v,w) ((v) ^ (w)) -#define PLUS(v,w) (U32V((v) + (w))) -#define PLUSONE(v) (PLUS((v),1)) + #define ROTATE(v, c) (ROTL32(v, c)) + #define XOR(v, w) ((v) ^ (w)) + #define PLUS(v, w) (U32V((v) + (w))) + #define PLUSONE(v) (PLUS((v), 1)) -#define QUARTERROUND(a,b,c,d) \ - a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \ - c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \ - a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \ - c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); + #define QUARTERROUND(a, b, c, d) \ + a = PLUS(a, b); \ + d = ROTATE(XOR(d, a), 16); \ + c = PLUS(c, d); \ + b = ROTATE(XOR(b, c), 12); \ + a = PLUS(a, b); \ + d = ROTATE(XOR(d, a), 8); \ + c = PLUS(c, d); \ + b = ROTATE(XOR(b, c), 7); static const char sigma[16] = "expand 32-byte k"; static const char tau[16] = "expand 16-byte k"; static void -chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits) +chacha_keysetup(chacha_ctx *x, const u8 *k, u32 kbits, u32 ivbits) { - const char *constants; + const char *constants; - x->input[4] = U8TO32_LITTLE(k + 0); - x->input[5] = U8TO32_LITTLE(k + 4); - x->input[6] = U8TO32_LITTLE(k + 8); - x->input[7] = U8TO32_LITTLE(k + 12); - if (kbits == 256) { /* recommended */ - k += 16; - constants = sigma; - } else { /* kbits == 128 */ - constants = tau; - } - x->input[8] = U8TO32_LITTLE(k + 0); - x->input[9] = U8TO32_LITTLE(k + 4); - x->input[10] = U8TO32_LITTLE(k + 8); - x->input[11] = U8TO32_LITTLE(k + 12); - x->input[0] = U8TO32_LITTLE(constants + 0); - x->input[1] = U8TO32_LITTLE(constants + 4); - x->input[2] = U8TO32_LITTLE(constants + 8); - x->input[3] = U8TO32_LITTLE(constants + 12); + x->input[4] = U8TO32_LITTLE(k + 0); + x->input[5] = U8TO32_LITTLE(k + 4); + x->input[6] = U8TO32_LITTLE(k + 8); + x->input[7] = U8TO32_LITTLE(k + 12); + if (kbits == 256) + { /* recommended */ + k += 16; + constants = sigma; + } else + { /* kbits == 128 */ + constants = tau; + } + x->input[8] = U8TO32_LITTLE(k + 0); + x->input[9] = U8TO32_LITTLE(k + 4); + x->input[10] = U8TO32_LITTLE(k + 8); + x->input[11] = U8TO32_LITTLE(k + 12); + x->input[0] = U8TO32_LITTLE(constants + 0); + x->input[1] = U8TO32_LITTLE(constants + 4); + x->input[2] = U8TO32_LITTLE(constants + 8); + x->input[3] = U8TO32_LITTLE(constants + 12); } static void -chacha_ivsetup(chacha_ctx *x,const u8 *iv) +chacha_ivsetup(chacha_ctx *x, const u8 *iv) { - x->input[12] = 0; - x->input[13] = 0; - x->input[14] = U8TO32_LITTLE(iv + 0); - x->input[15] = U8TO32_LITTLE(iv + 4); + x->input[12] = 0; + x->input[13] = 0; + x->input[14] = U8TO32_LITTLE(iv + 0); + x->input[15] = U8TO32_LITTLE(iv + 4); } static void -chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes) +chacha_encrypt_bytes(chacha_ctx *x, const u8 *m, u8 *c, u32 bytes) { - u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; - u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15; - u8 *ctarget = NULL; - u8 tmp[64]; - u_int i; + u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; + u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15; + u8 *ctarget = NULL; + u8 tmp[64]; + u_int i; - if (!bytes) return; + if (!bytes) + return; - j0 = x->input[0]; - j1 = x->input[1]; - j2 = x->input[2]; - j3 = x->input[3]; - j4 = x->input[4]; - j5 = x->input[5]; - j6 = x->input[6]; - j7 = x->input[7]; - j8 = x->input[8]; - j9 = x->input[9]; - j10 = x->input[10]; - j11 = x->input[11]; - j12 = x->input[12]; - j13 = x->input[13]; - j14 = x->input[14]; - j15 = x->input[15]; + j0 = x->input[0]; + j1 = x->input[1]; + j2 = x->input[2]; + j3 = x->input[3]; + j4 = x->input[4]; + j5 = x->input[5]; + j6 = x->input[6]; + j7 = x->input[7]; + j8 = x->input[8]; + j9 = x->input[9]; + j10 = x->input[10]; + j11 = x->input[11]; + j12 = x->input[12]; + j13 = x->input[13]; + j14 = x->input[14]; + j15 = x->input[15]; - for (;;) { - if (bytes < 64) { - for (i = 0;i < bytes;++i) tmp[i] = m[i]; - m = tmp; - ctarget = c; - c = tmp; - } - x0 = j0; - x1 = j1; - x2 = j2; - x3 = j3; - x4 = j4; - x5 = j5; - x6 = j6; - x7 = j7; - x8 = j8; - x9 = j9; - x10 = j10; - x11 = j11; - x12 = j12; - x13 = j13; - x14 = j14; - x15 = j15; - for (i = 20;i > 0;i -= 2) { - QUARTERROUND( x0, x4, x8,x12) - QUARTERROUND( x1, x5, x9,x13) - QUARTERROUND( x2, x6,x10,x14) - QUARTERROUND( x3, x7,x11,x15) - QUARTERROUND( x0, x5,x10,x15) - QUARTERROUND( x1, x6,x11,x12) - QUARTERROUND( x2, x7, x8,x13) - QUARTERROUND( x3, x4, x9,x14) - } - x0 = PLUS(x0,j0); - x1 = PLUS(x1,j1); - x2 = PLUS(x2,j2); - x3 = PLUS(x3,j3); - x4 = PLUS(x4,j4); - x5 = PLUS(x5,j5); - x6 = PLUS(x6,j6); - x7 = PLUS(x7,j7); - x8 = PLUS(x8,j8); - x9 = PLUS(x9,j9); - x10 = PLUS(x10,j10); - x11 = PLUS(x11,j11); - x12 = PLUS(x12,j12); - x13 = PLUS(x13,j13); - x14 = PLUS(x14,j14); - x15 = PLUS(x15,j15); + for (;;) + { + if (bytes < 64) + { + for (i = 0; i < bytes; ++i) + tmp[i] = m[i]; + m = tmp; + ctarget = c; + c = tmp; + } + x0 = j0; + x1 = j1; + x2 = j2; + x3 = j3; + x4 = j4; + x5 = j5; + x6 = j6; + x7 = j7; + x8 = j8; + x9 = j9; + x10 = j10; + x11 = j11; + x12 = j12; + x13 = j13; + x14 = j14; + x15 = j15; + for (i = 20; i > 0; i -= 2) + { + QUARTERROUND(x0, x4, x8, x12) + QUARTERROUND(x1, x5, x9, x13) + QUARTERROUND(x2, x6, x10, x14) + QUARTERROUND(x3, x7, x11, x15) + QUARTERROUND(x0, x5, x10, x15) + QUARTERROUND(x1, x6, x11, x12) + QUARTERROUND(x2, x7, x8, x13) + QUARTERROUND(x3, x4, x9, x14) + } + x0 = PLUS(x0, j0); + x1 = PLUS(x1, j1); + x2 = PLUS(x2, j2); + x3 = PLUS(x3, j3); + x4 = PLUS(x4, j4); + x5 = PLUS(x5, j5); + x6 = PLUS(x6, j6); + x7 = PLUS(x7, j7); + x8 = PLUS(x8, j8); + x9 = PLUS(x9, j9); + x10 = PLUS(x10, j10); + x11 = PLUS(x11, j11); + x12 = PLUS(x12, j12); + x13 = PLUS(x13, j13); + x14 = PLUS(x14, j14); + x15 = PLUS(x15, j15); -#ifndef KEYSTREAM_ONLY - x0 = XOR(x0,U8TO32_LITTLE(m + 0)); - x1 = XOR(x1,U8TO32_LITTLE(m + 4)); - x2 = XOR(x2,U8TO32_LITTLE(m + 8)); - x3 = XOR(x3,U8TO32_LITTLE(m + 12)); - x4 = XOR(x4,U8TO32_LITTLE(m + 16)); - x5 = XOR(x5,U8TO32_LITTLE(m + 20)); - x6 = XOR(x6,U8TO32_LITTLE(m + 24)); - x7 = XOR(x7,U8TO32_LITTLE(m + 28)); - x8 = XOR(x8,U8TO32_LITTLE(m + 32)); - x9 = XOR(x9,U8TO32_LITTLE(m + 36)); - x10 = XOR(x10,U8TO32_LITTLE(m + 40)); - x11 = XOR(x11,U8TO32_LITTLE(m + 44)); - x12 = XOR(x12,U8TO32_LITTLE(m + 48)); - x13 = XOR(x13,U8TO32_LITTLE(m + 52)); - x14 = XOR(x14,U8TO32_LITTLE(m + 56)); - x15 = XOR(x15,U8TO32_LITTLE(m + 60)); -#endif + #ifndef KEYSTREAM_ONLY + x0 = XOR(x0, U8TO32_LITTLE(m + 0)); + x1 = XOR(x1, U8TO32_LITTLE(m + 4)); + x2 = XOR(x2, U8TO32_LITTLE(m + 8)); + x3 = XOR(x3, U8TO32_LITTLE(m + 12)); + x4 = XOR(x4, U8TO32_LITTLE(m + 16)); + x5 = XOR(x5, U8TO32_LITTLE(m + 20)); + x6 = XOR(x6, U8TO32_LITTLE(m + 24)); + x7 = XOR(x7, U8TO32_LITTLE(m + 28)); + x8 = XOR(x8, U8TO32_LITTLE(m + 32)); + x9 = XOR(x9, U8TO32_LITTLE(m + 36)); + x10 = XOR(x10, U8TO32_LITTLE(m + 40)); + x11 = XOR(x11, U8TO32_LITTLE(m + 44)); + x12 = XOR(x12, U8TO32_LITTLE(m + 48)); + x13 = XOR(x13, U8TO32_LITTLE(m + 52)); + x14 = XOR(x14, U8TO32_LITTLE(m + 56)); + x15 = XOR(x15, U8TO32_LITTLE(m + 60)); + #endif - j12 = PLUSONE(j12); - if (!j12) { - j13 = PLUSONE(j13); + j12 = PLUSONE(j12); + if (!j12) + { + j13 = PLUSONE(j13); /* stopping at 2^70 bytes per nonce is user's responsibility */ - } + } - U32TO8_LITTLE(c + 0,x0); - U32TO8_LITTLE(c + 4,x1); - U32TO8_LITTLE(c + 8,x2); - U32TO8_LITTLE(c + 12,x3); - U32TO8_LITTLE(c + 16,x4); - U32TO8_LITTLE(c + 20,x5); - U32TO8_LITTLE(c + 24,x6); - U32TO8_LITTLE(c + 28,x7); - U32TO8_LITTLE(c + 32,x8); - U32TO8_LITTLE(c + 36,x9); - U32TO8_LITTLE(c + 40,x10); - U32TO8_LITTLE(c + 44,x11); - U32TO8_LITTLE(c + 48,x12); - U32TO8_LITTLE(c + 52,x13); - U32TO8_LITTLE(c + 56,x14); - U32TO8_LITTLE(c + 60,x15); + U32TO8_LITTLE(c + 0, x0); + U32TO8_LITTLE(c + 4, x1); + U32TO8_LITTLE(c + 8, x2); + U32TO8_LITTLE(c + 12, x3); + U32TO8_LITTLE(c + 16, x4); + U32TO8_LITTLE(c + 20, x5); + U32TO8_LITTLE(c + 24, x6); + U32TO8_LITTLE(c + 28, x7); + U32TO8_LITTLE(c + 32, x8); + U32TO8_LITTLE(c + 36, x9); + U32TO8_LITTLE(c + 40, x10); + U32TO8_LITTLE(c + 44, x11); + U32TO8_LITTLE(c + 48, x12); + U32TO8_LITTLE(c + 52, x13); + U32TO8_LITTLE(c + 56, x14); + U32TO8_LITTLE(c + 60, x15); - if (bytes <= 64) { - if (bytes < 64) { - for (i = 0;i < bytes;++i) ctarget[i] = c[i]; - } - x->input[12] = j12; - x->input[13] = j13; - return; - } - bytes -= 64; - c += 64; -#ifndef KEYSTREAM_ONLY - m += 64; -#endif - } + if (bytes <= 64) + { + if (bytes < 64) + { + for (i = 0; i < bytes; ++i) + ctarget[i] = c[i]; + } + x->input[12] = j12; + x->input[13] = j13; + return; + } + bytes -= 64; + c += 64; + #ifndef KEYSTREAM_ONLY + m += 64; + #endif + } } /* The following is taken from arc4random.c @@ -281,16 +297,15 @@ chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes) */ - -#define KEYSZ 32 -#define IVSZ 8 -#define BLOCKSZ 64 -#define RSBUFSZ (16*BLOCKSZ) + #define KEYSZ 32 + #define IVSZ 8 + #define BLOCKSZ 64 + #define RSBUFSZ (16 * BLOCKSZ) static int rs_initialized; -static chacha_ctx rs; /* chacha context for random keystream */ -static u_char rs_buf[RSBUFSZ]; /* keystream blocks */ -static size_t rs_have; /* valid bytes at end of rs_buf */ -static size_t rs_count; /* bytes till reseed */ +static chacha_ctx rs; /* chacha context for random keystream */ +static u_char rs_buf[RSBUFSZ]; /* keystream blocks */ +static size_t rs_have; /* valid bytes at end of rs_buf */ +static size_t rs_count; /* bytes till reseed */ static inline void _rs_rekey(u_char *dat, size_t datlen); @@ -314,17 +329,18 @@ static void _rs_stir(void) abort(); } - if (!rs_initialized) { + if (!rs_initialized) + { rs_initialized = 1; _rs_init(rnd, sizeof(rnd)); } else _rs_rekey(rnd, sizeof(rnd)); -#ifdef HAVE_EXPLICIT_BZERO + #ifdef HAVE_EXPLICIT_BZERO explicit_bzero(rnd, sizeof(rnd)); -#else + #else /* Not terribly important in this case */ memset(rnd, 0, sizeof(rnd)); -#endif + #endif /* invalidate rs_buf */ rs_have = 0; memset(rs_buf, 0, RSBUFSZ); @@ -334,7 +350,8 @@ static void _rs_stir(void) static inline void _rs_stir_if_needed(size_t len) { - if (rs_count <= len || !rs_initialized) { + if (rs_count <= len || !rs_initialized) + { _rs_stir(); } else rs_count -= len; @@ -342,13 +359,14 @@ static inline void _rs_stir_if_needed(size_t len) static inline void _rs_rekey(u_char *dat, size_t datlen) { -#ifndef KEYSTREAM_ONLY - memset(rs_buf, 0,RSBUFSZ); -#endif + #ifndef KEYSTREAM_ONLY + memset(rs_buf, 0, RSBUFSZ); + #endif /* fill rs_buf with the keystream */ chacha_encrypt_bytes(&rs, rs_buf, rs_buf, RSBUFSZ); /* mix in optional user provided data */ - if (dat) { + if (dat) + { size_t i, m; m = MIN(datlen, KEYSZ + IVSZ); @@ -367,8 +385,10 @@ static inline void _rs_random_buf(void *_buf, size_t n) size_t m; _rs_stir_if_needed(n); - while (n > 0) { - if (rs_have > 0) { + while (n > 0) + { + if (rs_have > 0) + { m = MIN(n, rs_have); memcpy(buf, rs_buf + RSBUFSZ - rs_have, m); memset(rs_buf + RSBUFSZ - rs_have, 0, m); @@ -403,7 +423,8 @@ void arc4random_doaddrandom(u_char *dat, int datlen) if (!rs_initialized) _rs_stir(); - while (datlen > 0) { + while (datlen > 0) + { m = MIN(datlen, KEYSZ + IVSZ); _rs_rekey(dat, m); dat += m; @@ -439,11 +460,11 @@ void init_random() { struct { #ifndef _WIN32 - struct timeval nowt; /* time */ - char rnd[32]; /* /dev/urandom */ + struct timeval nowt; /* time */ + char rnd[32]; /* /dev/urandom */ #else - struct _timeb nowt; /* time */ - MEMORYSTATUS mstat; /* memory status */ + struct _timeb nowt; /* time */ + MEMORYSTATUS mstat; /* memory status */ #endif } rdat; @@ -464,8 +485,8 @@ void init_random() } #else _ftime(&rdat.nowt); - GlobalMemoryStatus (&rdat.mstat); -#endif + GlobalMemoryStatus(&rdat.mstat); +#endif arc4_addrandom(&rdat, sizeof(rdat)); @@ -508,13 +529,13 @@ void gen_random_alnum(char *buf, int numbytes) { for (; numbytes > 0; numbytes--) { - unsigned char v = getrandom8() % (26+26+10); + unsigned char v = getrandom8() % (26 + 26 + 10); if (v < 26) - *buf++ = 'a'+v; + *buf++ = 'a' + v; else if (v < 52) - *buf++ = 'A'+(v-26); + *buf++ = 'A' + (v - 26); else - *buf++ = '0'+(v-52); + *buf++ = '0' + (v - 52); } *buf = '\0'; } diff --git a/src/scache.c b/src/scache.c index 00a46017d..599de8315 100644 --- a/src/scache.c +++ b/src/scache.c @@ -43,7 +43,7 @@ void clear_scache_hash_table(void) static int hash(char *string) { - int hash_value; + int hash_value; hash_value = 0; while (*string) @@ -63,7 +63,7 @@ static int hash(char *string) */ char *find_or_add(char *name) { - int hash_index; + int hash_index; SCACHE *ptr, *newptr; ptr = scache_hash[hash_index = hash(name)]; @@ -72,8 +72,7 @@ char *find_or_add(char *name) if (!mycmp(ptr->name, name)) { return (ptr->name); - } - else + } else { ptr = ptr->next; } @@ -88,12 +87,11 @@ char *find_or_add(char *name) strlcpy(newptr->name, name, sizeof(newptr->name)); newptr->next = ptr; return (newptr->name); - } - else + } else { ptr = scache_hash[hash_index] = safe_alloc(sizeof(SCACHE)); strlcpy(ptr->name, name, sizeof(newptr->name)); - ptr->next = (SCACHE *) NULL; + ptr->next = (SCACHE *)NULL; return (ptr->name); } } diff --git a/src/securitygroup.c b/src/securitygroup.c index 7d5b44ee2..770448e32 100644 --- a/src/securitygroup.c +++ b/src/securitygroup.c @@ -107,7 +107,7 @@ int unreal_mask_match(Client *client, ConfigItem_mask *mask) if (m->mask[0] != '!') { retval = 0; /* no implicit * */ - if (match_user(m->mask, client, MATCH_CHECK_REAL|MATCH_CHECK_EXTENDED)) + if (match_user(m->mask, client, MATCH_CHECK_REAL | MATCH_CHECK_EXTENDED)) { retval = 1; break; @@ -120,7 +120,7 @@ int unreal_mask_match(Client *client, ConfigItem_mask *mask) /* We matched. Check for exceptions (with ! prefix) */ for (m = mask; m; m = m->next) { - if ((m->mask[0] == '!') && match_user(m->mask+1, client, MATCH_CHECK_REAL|MATCH_CHECK_EXTENDED)) + if ((m->mask[0] == '!') && match_user(m->mask + 1, client, MATCH_CHECK_REAL | MATCH_CHECK_EXTENDED)) return 0; } } @@ -169,7 +169,7 @@ int unreal_mask_match_string(const char *name, ConfigItem_mask *mask) /* We matched. Check for exceptions (with ! prefix) */ for (m = mask; m; m = m->next) { - if ((m->mask[0] == '!') && match_simple(m->mask+1, name)) + if ((m->mask[0] == '!') && match_simple(m->mask + 1, name)) return 0; } } @@ -177,29 +177,31 @@ int unreal_mask_match_string(const char *name, ConfigItem_mask *mask) return retval; } -#define CheckNullX(x) if ((!(x)->value) || (!(*((x)->value)))) { config_error("%s:%i: missing parameter", (x)->file->filename, (x)->line_number); (*errors)++; return 0; } +#define CheckNullX(x) \ + if ((!(x)->value) || (!(*((x)->value)))) \ + { \ + config_error("%s:%i: missing parameter", (x)->file->filename, (x)->line_number); \ + (*errors)++; \ + return 0; \ + } int test_match_item(ConfigFile *conf, ConfigEntry *cep, int *errors) { ConfigEntry *cepp; - int has_rule=0, has_exclude_rule=0; + int has_rule = 0, has_exclude_rule = 0; if (!strcmp(cep->name, "webirc") || !strcmp(cep->name, "exclude-webirc")) { CheckNullX(cep); - } else - if (!strcmp(cep->name, "websocket") || !strcmp(cep->name, "exclude-websocket")) + } else if (!strcmp(cep->name, "websocket") || !strcmp(cep->name, "exclude-websocket")) { CheckNullX(cep); - } else - if (!strcmp(cep->name, "identified") || !strcmp(cep->name, "exclude-identified")) + } else if (!strcmp(cep->name, "identified") || !strcmp(cep->name, "exclude-identified")) { CheckNullX(cep); - } else - if (!strcmp(cep->name, "tls") || !strcmp(cep->name, "exclude-tls")) + } else if (!strcmp(cep->name, "tls") || !strcmp(cep->name, "exclude-tls")) { CheckNullX(cep); - } else - if (!strcmp(cep->name, "reputation-score") || !strcmp(cep->name, "exclude-reputation-score")) + } else if (!strcmp(cep->name, "reputation-score") || !strcmp(cep->name, "exclude-reputation-score")) { const char *str = cep->value; int v; @@ -210,11 +212,10 @@ int test_match_item(ConfigFile *conf, ConfigEntry *cep, int *errors) if ((v < 1) || (v > 10000)) { config_error("%s:%i: %s needs to be a value of 1-10000", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); (*errors)++; } - } else - if (!strcmp(cep->name, "connect-time") || !strcmp(cep->name, "exclude-connect-time")) + } else if (!strcmp(cep->name, "connect-time") || !strcmp(cep->name, "exclude-connect-time")) { const char *str = cep->value; long v; @@ -225,11 +226,10 @@ int test_match_item(ConfigFile *conf, ConfigEntry *cep, int *errors) if (v < 1) { config_error("%s:%i: %s needs to be a time value (and more than 0 seconds)", - cep->file->filename, cep->line_number, cep->name); + cep->file->filename, cep->line_number, cep->name); (*errors)++; } - } else - if (!strcmp(cep->name, "mask") || !strcmp(cep->name, "include-mask") || !strcmp(cep->name, "exclude-mask")) + } else if (!strcmp(cep->name, "mask") || !strcmp(cep->name, "include-mask") || !strcmp(cep->name, "exclude-mask")) { for (cepp = cep->items; cepp; cepp = cepp->next) { @@ -244,20 +244,15 @@ int test_match_item(ConfigFile *conf, ConfigEntry *cep, int *errors) (*errors)++; } } - } else - if (!strcmp(cep->name, "ip") || !strcmp(cep->name, "exclude-ip")) + } else if (!strcmp(cep->name, "ip") || !strcmp(cep->name, "exclude-ip")) { - } else - if (!strcmp(cep->name, "server-port") || !strcmp(cep->name, "exclude-server-port")) + } else if (!strcmp(cep->name, "server-port") || !strcmp(cep->name, "exclude-server-port")) { - } else - if (!strcmp(cep->name, "security-group") || !strcmp(cep->name, "exclude-security-group")) + } else if (!strcmp(cep->name, "security-group") || !strcmp(cep->name, "exclude-security-group")) { - } else - if (!strcmp(cep->name, "destination") || !strcmp(cep->name, "exclude-destination")) + } else if (!strcmp(cep->name, "destination") || !strcmp(cep->name, "exclude-destination")) { - } else - if (!strcmp(cep->name, "rule") || !strcmp(cep->name, "exclude-rule")) + } else if (!strcmp(cep->name, "rule") || !strcmp(cep->name, "exclude-rule")) { int val; @@ -270,10 +265,10 @@ int test_match_item(ConfigFile *conf, ConfigEntry *cep, int *errors) if (val) { config_error("%s:%i: %s contains an invalid expression: %s", - cep->file->filename, - cep->line_number, - cep->name, - crule_errstring(val)); + cep->file->filename, + cep->line_number, + cep->name, + crule_errstring(val)); (*errors)++; } } else @@ -281,7 +276,7 @@ int test_match_item(ConfigFile *conf, ConfigEntry *cep, int *errors) /* Let's see if an extended server ban exists for this item... */ Extban *extban; if (!strncmp(cep->name, "exclude-", 8)) - extban = findmod_by_bantype_raw(cep->name+8, strlen(cep->name+8)); + extban = findmod_by_bantype_raw(cep->name + 8, strlen(cep->name + 8)); else extban = findmod_by_bantype_raw(cep->name, strlen(cep->name)); if (extban && (extban->options & EXTBOPT_TKL) && (extban->is_banned_events & BANCHK_TKL)) @@ -310,7 +305,7 @@ int test_match_block(ConfigFile *conf, ConfigEntry *ce, int *errors_out) if (!test_match_item(conf, cep, &errors) && cep->value) { config_error_unknown(cep->file->filename, cep->line_number, - ce->name, cep->name); + ce->name, cep->name); errors++; continue; } @@ -320,7 +315,7 @@ int test_match_block(ConfigFile *conf, ConfigEntry *ce, int *errors_out) return errors ? 0 : 1; } -#define tmbbw_is_wildcard(x) (!strcmp(x, "*") || !strcmp(x, "*@*")) +#define tmbbw_is_wildcard(x) (!strcmp(x, "*") || !strcmp(x, "*@*")) int test_match_block_too_broad(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep, *cepp; @@ -358,9 +353,10 @@ int _test_security_group(ConfigFile *conf, ConfigEntry *ce) if (!ce->value) { config_error("%s:%i: security-group block needs a name, eg: security-group web-users {", - ce->file->filename, ce->line_number); + ce->file->filename, ce->line_number); errors++; - } else { + } else + { if (!strcasecmp(ce->value, "unknown-users")) { config_error("%s:%i: The 'unknown-users' group is a special group that is the " @@ -384,15 +380,13 @@ int _test_security_group(ConfigFile *conf, ConfigEntry *ce) if (!strcmp(cep->name, "public")) { CheckNull(cep); - } else - if (!strcmp(cep->name, "priority")) + } else if (!strcmp(cep->name, "priority")) { CheckNull(cep); - } else - if (!test_match_item(conf, cep, &errors)) + } else if (!test_match_item(conf, cep, &errors)) { config_error_unknown(cep->file->filename, cep->line_number, - "security-group", cep->name); + "security-group", cep->name); errors++; continue; } @@ -431,43 +425,35 @@ int conf_match_item(ConfigFile *conf, ConfigEntry *cep, SecurityGroup **block) else if (!strcmp(cep->name, "reputation-score")) { if (*cep->value == '<') - s->reputation_score = 0 - atoi(cep->value+1); + s->reputation_score = 0 - atoi(cep->value + 1); else s->reputation_score = atoi(cep->value); - } - else if (!strcmp(cep->name, "connect-time")) + } else if (!strcmp(cep->name, "connect-time")) { if (*cep->value == '<') - s->connect_time = 0 - config_checkval(cep->value+1, CFG_TIME); + s->connect_time = 0 - config_checkval(cep->value + 1, CFG_TIME); else s->connect_time = config_checkval(cep->value, CFG_TIME); - } - else if (!strcmp(cep->name, "mask") || !strcmp(cep->name, "include-mask")) + } else if (!strcmp(cep->name, "mask") || !strcmp(cep->name, "include-mask")) { unreal_add_masks(&s->mask, cep); - } - else if (!strcmp(cep->name, "ip")) + } else if (!strcmp(cep->name, "ip")) { unreal_add_names(&s->ip, cep); - } - else if (!strcmp(cep->name, "server-port")) + } else if (!strcmp(cep->name, "server-port")) { unreal_add_names(&s->server_port, cep); - } - else if (!strcmp(cep->name, "security-group")) + } else if (!strcmp(cep->name, "security-group")) { unreal_add_names(&s->security_group, cep); - } - else if (!strcmp(cep->name, "rule")) + } else if (!strcmp(cep->name, "rule")) { safe_strdup(s->prettyrule, cep->value); s->rule = crule_parse(s->prettyrule); - } - else if (!strcmp(cep->name, "destination")) + } else if (!strcmp(cep->name, "destination")) { unreal_add_names(&s->destination, cep); - } - else if (!strcmp(cep->name, "exclude-webirc")) + } else if (!strcmp(cep->name, "exclude-webirc")) s->exclude_webirc = config_checkval(cep->value, CFG_YESNO); else if (!strcmp(cep->name, "exclude-websocket")) s->exclude_websocket = config_checkval(cep->value, CFG_YESNO); @@ -478,36 +464,29 @@ int conf_match_item(ConfigFile *conf, ConfigEntry *cep, SecurityGroup **block) else if (!strcmp(cep->name, "exclude-reputation-score")) { if (*cep->value == '<') - s->exclude_reputation_score = 0 - atoi(cep->value+1); + s->exclude_reputation_score = 0 - atoi(cep->value + 1); else s->exclude_reputation_score = atoi(cep->value); - } - else if (!strcmp(cep->name, "exclude-mask")) + } else if (!strcmp(cep->name, "exclude-mask")) { unreal_add_masks(&s->exclude_mask, cep); - } - else if (!strcmp(cep->name, "exclude-ip")) + } else if (!strcmp(cep->name, "exclude-ip")) { unreal_add_names(&s->exclude_ip, cep); - } - else if (!strcmp(cep->name, "exclude-server-port")) + } else if (!strcmp(cep->name, "exclude-server-port")) { unreal_add_names(&s->exclude_server_port, cep); - } - else if (!strcmp(cep->name, "exclude-security-group")) + } else if (!strcmp(cep->name, "exclude-security-group")) { unreal_add_names(&s->exclude_security_group, cep); - } - else if (!strcmp(cep->name, "exclude-rule")) + } else if (!strcmp(cep->name, "exclude-rule")) { safe_strdup(s->exclude_prettyrule, cep->value); s->exclude_rule = crule_parse(s->exclude_prettyrule); - } - else if (!strcmp(cep->name, "exclude-destination")) + } else if (!strcmp(cep->name, "exclude-destination")) { unreal_add_names(&s->exclude_destination, cep); - } - else + } else { /* Let's see if an extended server ban exists for this item... this needs to be LAST! */ Extban *extban; @@ -521,7 +500,8 @@ int conf_match_item(ConfigFile *conf, ConfigEntry *cep, SecurityGroup **block) unreal_add_name_values(&s->exclude_extended, name, cep); else return 0; /* Unhandled */ - } else { + } else + { /* Extended (inclusive) */ if (findmod_by_bantype_raw(name, strlen(name))) unreal_add_name_values(&s->extended, name, cep); @@ -536,7 +516,8 @@ int conf_match_item(ConfigFile *conf, ConfigEntry *cep, SecurityGroup **block) ConfigEntry *cep2; for (cep2 = cep->items; cep2; cep2 = cep2->next) add_nvplist(&s->printable_list, s->printable_list_counter++, cep->name, cep2->name); - } else { + } else + { add_nvplist(&s->printable_list, s->printable_list_counter++, cep->name, cep->value); } @@ -583,11 +564,11 @@ int _conf_security_group(ConfigFile *conf, ConfigEntry *ce) s->priority = atoi(cep->value); DelListItem(s, securitygroups); AddListItemPrio(s, securitygroups, s->priority); - } else - if (!strcmp(cep->name, "public")) + } else if (!strcmp(cep->name, "public")) { s->public = config_checkval(cep->value, CFG_YESNO); - } else { + } else + { conf_match_item(conf, cep, &s); } } @@ -1054,6 +1035,6 @@ const char *get_security_groups(Client *client) } if (*buf) - buf[strlen(buf)-1] = '\0'; + buf[strlen(buf) - 1] = '\0'; return buf; } diff --git a/src/send.c b/src/send.c index ed90eb09a..3dcb74175 100644 --- a/src/send.c +++ b/src/send.c @@ -29,9 +29,9 @@ /* Some forward declarions are needed */ void vsendto_one(Client *to, MessageTag *mtags, const char *pattern, va_list vl); -void vsendto_prefix_one(Client *to, Client *from, MessageTag *mtags, const char *pattern, va_list vl) __attribute__((format(printf,4,0))); -static int vmakebuf_local_withprefix(char *buf, size_t buflen, Client *from, const char *pattern, va_list vl) __attribute__((format(printf,4,0))); -static void vsendto_prefix_one_cached(LineCache *cache, int line_opts, Client *to, Client *from, MessageTag *mtags, const char *pattern, va_list vl) __attribute__((format(printf,6,0))); +void vsendto_prefix_one(Client *to, Client *from, MessageTag *mtags, const char *pattern, va_list vl) __attribute__((format(printf, 4, 0))); +static int vmakebuf_local_withprefix(char *buf, size_t buflen, Client *from, const char *pattern, va_list vl) __attribute__((format(printf, 4, 0))); +static void vsendto_prefix_one_cached(LineCache *cache, int line_opts, Client *to, Client *from, MessageTag *mtags, const char *pattern, va_list vl) __attribute__((format(printf, 6, 0))); static void linecache_add(LineCache *cache, int line_opts, Client *to, const char *line, int linelen); static LineCacheLine *linecache_get(LineCache *cache, int line_opts, Client *to); @@ -47,7 +47,7 @@ static char sendbuf3[MAXLINELENGTH]; * it is checked if to->direction->local->serial == current_serial * and if so, sending is skipped. */ -MODVAR int current_serial; +MODVAR int current_serial; /** This is a callback function from the event loop. * All it does is call send_queued(). @@ -68,7 +68,7 @@ void send_queued_cb(int fd, int revents, void *data) */ int send_queued(Client *to) { - int len, rlen; + int len, rlen; dbufbuf *block; int want_read; @@ -112,7 +112,7 @@ int send_queued(Client *to) break; } } - + /* Nothing left to write, stop asking for write-ready notification. */ if ((DBufLength(&to->local->sendQ) == 0) && (to->local->fd >= 0)) fd_setselect(to->local->fd, FD_SELECT_WRITE, NULL, to); @@ -176,21 +176,22 @@ void vsendto_one(Client *to, MessageTag *mtags, const char *pattern, va_list vl) /* Need to ignore -Wformat-nonliteral here */ #if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif - ircvsnprintf(sendbuf, sizeof(sendbuf)-3, pattern, vl); + ircvsnprintf(sendbuf, sizeof(sendbuf) - 3, pattern, vl); #if defined(__GNUC__) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif if (BadPtr(mtags_str)) { /* Simple message without message tags */ sendbufto_one(to, sendbuf, 0); - } else { + } else + { /* Message tags need to be prepended */ - snprintf(sendbuf2, sizeof(sendbuf2)-3, "@%s %s", mtags_str, sendbuf); + snprintf(sendbuf2, sizeof(sendbuf2) - 3, "@%s %s", mtags_str, sendbuf); sendbufto_one(to, sendbuf2, 0); } } @@ -237,24 +238,25 @@ static int sendbufto_one_prepare_line(Client *to, char **input) * (MAXTAGSIZE) and then 512 bytes for * the remainder of the message (BUFSIZE). */ - p = strchr(msg+1, ' '); + p = strchr(msg + 1, ' '); if (!p) { unreal_log(ULOG_WARNING, "send", "SENDBUFTO_ONE_MALFORMED_MSG", to, - "Malformed message to $client: $buf", - log_data_string("buf", msg)); + "Malformed message to $client: $buf", + log_data_string("buf", msg)); return 0; } if (p - msg > MAXTAGSIZE) { unreal_log(ULOG_WARNING, "send", "SENDBUFTO_ONE_OVERSIZED_MSG", to, - "Oversized message to $client (length $length): $buf", - log_data_integer("length", p - msg), - log_data_string("buf", msg)); + "Oversized message to $client (length $length): $buf", + log_data_integer("length", p - msg), + log_data_string("buf", msg)); return 0; } p++; /* skip space character */ - } else { + } else + { p = msg; } @@ -271,22 +273,24 @@ static int sendbufto_one_prepare_line(Client *to, char **input) p[len++] = '\r'; p[len++] = '\n'; p[len] = '\0'; - } else { + } else + { /* BIGLINES case: * - first 'if' is about the total line length, * this is basically an optimized strlen(msg) * - the 'else' applies to non-mtags part, * like in the 'Normal case' from above. */ - if ((p - msg) + len > MAXLINELENGTH-3) + if ((p - msg) + len > MAXLINELENGTH - 3) { - len = MAXLINELENGTH-3; + len = MAXLINELENGTH - 3; if (UTF8ONLY) utf8_valid_cutoff(msg, &len); msg[len++] = '\r'; msg[len++] = '\n'; msg[len] = '\0'; - } else { + } else + { if (UTF8ONLY) utf8_valid_cutoff(p, &len); p[len++] = '\r'; @@ -338,7 +342,7 @@ void sendbufto_one(Client *to, char *msg, unsigned int quick) int len; Hook *h; Client *intended_to = to; - + if (to->direction) to = to->direction; if (IsDeadSocket(to)) @@ -360,16 +364,17 @@ void sendbufto_one(Client *to, char *msg, unsigned int quick) len = sendbufto_one_prepare_line(to, &msg); if (len == 0) return; - } else { + } else + { len = quick; } if (len >= MAXLINELENGTH) { unreal_log(ULOG_WARNING, "send", "SENDBUFTO_ONE_OVERSIZED_MSG2", to, - "Oversized message to $client (length $length): $buf", - log_data_integer("length", len), - log_data_string("buf", msg)); + "Oversized message to $client (length $length): $buf", + log_data_integer("length", len), + log_data_string("buf", msg)); #ifdef DEBUGMODE abort(); #else @@ -384,8 +389,8 @@ void sendbufto_one(Client *to, char *msg, unsigned int quick) strlcpy(tmp_msg, msg, sizeof(tmp_msg)); stripcrlf(tmp_msg); unreal_log(ULOG_WARNING, "send", "SENDBUFTO_ONE_ME_MESSAGE", to, - "Trying to send data to myself: $buf", - log_data_string("buf", tmp_msg)); + "Trying to send data to myself: $buf", + log_data_string("buf", tmp_msg)); return; } @@ -759,7 +764,8 @@ void quit_sendto_local_common_channels(Client *leaving, MessageTag *mtags, const { snprintf(sender, sizeof(sender), "%s!%s@%s", leaving->name, leaving->user->username, GetHost(leaving)); - } else { + } else + { strlcpy(sender, leaving->name, sizeof(sender)); } @@ -832,10 +838,9 @@ void sendto_match_butone(Client *one, Client *from, const char *mask, int what, if (MyConnect(from)) { - cansendlocal = (ValidatePermissionsForPath("chat:notice:local",from,NULL,NULL,NULL)) ? 1 : 0; - cansendglobal = (ValidatePermissionsForPath("chat:notice:global",from,NULL,NULL,NULL)) ? 1 : 0; - } - else + cansendlocal = (ValidatePermissionsForPath("chat:notice:local", from, NULL, NULL, NULL)) ? 1 : 0; + cansendglobal = (ValidatePermissionsForPath("chat:notice:global", from, NULL, NULL, NULL)) ? 1 : 0; + } else cansendlocal = cansendglobal = 1; /* To servers... */ @@ -876,16 +881,15 @@ void sendto_umode(int umodes, FORMAT_STRING(const char *pattern), ...) Client *acptr; char nbuf[1024]; - list_for_each_entry(acptr, &lclient_list, lclient_node) - if (IsUser(acptr) && (acptr->umodes & umodes) == umodes) - { - ircsnprintf(nbuf, sizeof(nbuf), ":%s NOTICE %s :", me.name, acptr->name); - strlcat(nbuf, pattern, sizeof nbuf); + list_for_each_entry(acptr, &lclient_list, lclient_node) if (IsUser(acptr) && (acptr->umodes & umodes) == umodes) + { + ircsnprintf(nbuf, sizeof(nbuf), ":%s NOTICE %s :", me.name, acptr->name); + strlcat(nbuf, pattern, sizeof nbuf); - va_start(vl, pattern); - vsendto_one(acptr, NULL, nbuf, vl); - va_end(vl); - } + va_start(vl, pattern); + vsendto_one(acptr, NULL, nbuf, vl); + va_end(vl); + } } /** Send a message to all users with specified user mode (local & remote users). @@ -915,8 +919,7 @@ void sendto_umode_global(int umodes, FORMAT_STRING(const char *pattern), ...) va_start(vl, pattern); vsendto_one(acptr, NULL, nbuf, vl); va_end(vl); - } else - if (IsServer(acptr) && *modestr) + } else if (IsServer(acptr) && *modestr) { snprintf(nbuf, sizeof(nbuf), ":%s SENDUMODE %s :%s", me.id, modestr, pattern); va_start(vl, pattern); @@ -954,14 +957,16 @@ void send_cap_notify(int add, const char *token) if (!args) { sendto_one(client, NULL, ":%s CAP %s NEW :%s", - me.name, (*client->name ? client->name : "*"), token); - } else { + me.name, (*client->name ? client->name : "*"), token); + } else + { sendto_one(client, NULL, ":%s CAP %s NEW :%s=%s", - me.name, (*client->name ? client->name : "*"), token, args); + me.name, (*client->name ? client->name : "*"), token, args); } - } else { + } else + { sendto_one(client, NULL, ":%s CAP %s DEL :%s", - me.name, (*client->name ? client->name : "*"), token); + me.name, (*client->name ? client->name : "*"), token); } } } @@ -988,7 +993,7 @@ static int vmakebuf_local_withprefix(char *buf, size_t buflen, Client *from, con va_arg(vl, char *); /* eat first parameter */ *buf = ':'; - strlcpy(buf+1, from->name, buflen-1); + strlcpy(buf + 1, from->name, buflen - 1); if (IsUser(from)) { @@ -1008,15 +1013,14 @@ static int vmakebuf_local_withprefix(char *buf, size_t buflen, Client *from, con } /* Now build the remaining string */ #if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif ircvsnprintf(buf + strlen(buf), buflen - strlen(buf), &pattern[3], vl); #if defined(__GNUC__) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif - } - else + } else { ircvsnprintf(buf, buflen, pattern, vl); } @@ -1066,17 +1070,18 @@ void vsendto_prefix_one(Client *to, Client *from, MessageTag *mtags, const char const char *mtags_str = mtags ? mtags_to_string(mtags, to) : NULL; if (to && from && MyUser(to) && from->user) - vmakebuf_local_withprefix(sendbuf, sizeof(sendbuf)-3, from, pattern, vl); + vmakebuf_local_withprefix(sendbuf, sizeof(sendbuf) - 3, from, pattern, vl); else - ircvsnprintf(sendbuf, sizeof(sendbuf)-3, pattern, vl); + ircvsnprintf(sendbuf, sizeof(sendbuf) - 3, pattern, vl); if (BadPtr(mtags_str)) { /* Simple message without message tags */ sendbufto_one(to, sendbuf, 0); - } else { + } else + { /* Message tags need to be prepended */ - snprintf(sendbuf2, sizeof(sendbuf2)-3, "@%s %s", mtags_str, sendbuf); + snprintf(sendbuf2, sizeof(sendbuf2) - 3, "@%s %s", mtags_str, sendbuf); sendbufto_one(to, sendbuf2, 0); } } @@ -1119,7 +1124,8 @@ static unsigned long linecache_caps(Client *to) return -1; /* 0xffffff... (iotw: all) */ else return 0; /* none */ - } else { + } else + { return to->local->caps & clicaps_affecting_mtag; } } @@ -1171,9 +1177,9 @@ static void vsendto_prefix_one_cached(LineCache *cache, int line_opts, Client *t mtags_str = mtags ? mtags_to_string(mtags, to) : NULL; if (to && from && MyUser(to) && from->user) - vmakebuf_local_withprefix(sendbuf, sizeof(sendbuf)-3, from, pattern, vl); + vmakebuf_local_withprefix(sendbuf, sizeof(sendbuf) - 3, from, pattern, vl); else - ircvsnprintf(sendbuf, sizeof(sendbuf)-3, pattern, vl); + ircvsnprintf(sendbuf, sizeof(sendbuf) - 3, pattern, vl); if (BadPtr(mtags_str)) { @@ -1182,10 +1188,11 @@ static void vsendto_prefix_one_cached(LineCache *cache, int line_opts, Client *t len = sendbufto_one_prepare_line(to, &out); linecache_add(cache, line_opts, to, out, len); sendbufto_one(to, out, len); - } else { + } else + { /* Message tags need to be prepended */ char *out = sendbuf2; - snprintf(sendbuf2, sizeof(sendbuf2)-3, "@%s %s", mtags_str, sendbuf); + snprintf(sendbuf2, sizeof(sendbuf2) - 3, "@%s %s", mtags_str, sendbuf); len = sendbufto_one_prepare_line(to, &out); linecache_add(cache, line_opts, to, out, len); sendbufto_one(to, out, 0); @@ -1223,7 +1230,7 @@ void sendto_serv_butone_nickcmd(Client *one, MessageTag *mtags, Client *client, { if (one && acptr == one->direction) continue; - + sendto_one_nickcmd(acptr, mtags, client, umodes); } } @@ -1247,8 +1254,7 @@ void sendto_one_nickcmd(Client *server, MessageTag *mtags, Client *client, const vhost = client->user->virthost; else vhost = client->user->realhost; - } - else + } else { if (IsHidden(client) && client->umodes & UMODE_SETHOST) vhost = client->user->virthost; @@ -1263,12 +1269,12 @@ void sendto_one_nickcmd(Client *server, MessageTag *mtags, Client *client, const } sendto_one(server, mtags, - ":%s UID %s %d %lld %s %s %s %s %s %s %s %s :%s", - client->uplink->id, client->name, client->hopcount, - (long long)client->lastnick, - client->user->username, client->user->realhost, client->id, - client->user->account, umodes, vhost, getcloak(client), - encode_ip(client->ip), client->info); + ":%s UID %s %d %lld %s %s %s %s %s %s %s %s :%s", + client->uplink->id, client->name, client->hopcount, + (long long)client->lastnick, + client->user->username, client->user->realhost, client->id, + client->user->account, umodes, vhost, getcloak(client), + encode_ip(client->ip), client->info); if (mtags_generated) safe_free_message_tags(mtags); @@ -1277,7 +1283,7 @@ void sendto_one_nickcmd(Client *server, MessageTag *mtags, Client *client, const /* sidenote: sendnotice() and sendtxtnumeric() assume no client or server * has a % in their nick, which is a safe assumption since % is illegal. */ - + /** Send a server notice to a client. * @param to The client to send to * @param pattern The format string / pattern to use. @@ -1366,12 +1372,12 @@ void buildnumericfmt(char *buf, size_t buflen, Client *to, int numeric, FORMAT_S va_start(vl, pattern); /* Need to ignore -Wformat-nonliteral here */ #if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif vsnprintf(buf, buflen, realpattern, vl); #if defined(__GNUC__) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif va_end(vl); } @@ -1386,12 +1392,12 @@ void add_nvplist_numeric_fmt(NameValuePrioList **lst, int priority, const char * va_start(vl, pattern); /* Need to ignore -Wformat-nonliteral here */ #if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif vsnprintf(buf, sizeof(buf), realpattern, vl); #if defined(__GNUC__) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif va_end(vl); diff --git a/src/serv.c b/src/serv.c index 075dac4f3..83ba158d6 100644 --- a/src/serv.c +++ b/src/serv.c @@ -31,10 +31,10 @@ #include #ifndef _WIN32 /* for uname(), is POSIX so should be OK... */ -#include + #include #endif -MODVAR int max_connection_count = 1, max_client_count = 1; +MODVAR int max_connection_count = 1, max_client_count = 1; extern int do_garbage_collect; /* We need all these for cached MOTDs -- codemastr */ extern char *buildid; @@ -60,8 +60,8 @@ void reread_motdsandrules(); #if defined(__GNUC__) /* Temporarily ignore for this function. FIXME later!!! */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif /** Send a message upstream if necessary and check if it's for us. @@ -153,7 +153,7 @@ int hunt_server(Client *client, MessageTag *mtags, const char *command, int serv } #if defined(__GNUC__) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif #ifndef _WIN32 @@ -168,13 +168,13 @@ char *getosname(void) if (uname(&osinf) != 0) return ""; snprintf(buf, sizeof(buf), "%s %s %s %s %s", - osinf.sysname, - osinf.nodename, - osinf.release, - osinf.version, - osinf.machine); + osinf.sysname, + osinf.nodename, + osinf.release, + osinf.version, + osinf.machine); /* get rid of cr/lf */ - for (p=buf; *p; p++) + for (p = buf; *p; p++) if ((*p == '\n') || (*p == '\r')) { *p = '\0'; @@ -207,12 +207,12 @@ CMD_FUNC(cmd_version) if (hunt_server(client, recv_mtags, "VERSION", 1, parc, parv) == HUNTED_ISME) { sendnumeric(client, RPL_VERSION, version, debugmode, me.name, - (ValidatePermissionsForPath("server:info",client,NULL,NULL,NULL) ? serveropts : "0"), - extraflags ? extraflags : "", - tainted ? "3" : "", - (ValidatePermissionsForPath("server:info",client,NULL,NULL,NULL) ? MYOSNAME : "*"), - UnrealProtocol); - if (ValidatePermissionsForPath("server:info",client,NULL,NULL,NULL)) + (ValidatePermissionsForPath("server:info", client, NULL, NULL, NULL) ? serveropts : "0"), + extraflags ? extraflags : "", + tainted ? "3" : "", + (ValidatePermissionsForPath("server:info", client, NULL, NULL, NULL) ? MYOSNAME : "*"), + UnrealProtocol); + if (ValidatePermissionsForPath("server:info", client, NULL, NULL, NULL)) { sendnotice(client, "%s", SSLeay_version(SSLEAY_VERSION)); sendnotice(client, "libsodium %s", sodium_version_string()); @@ -253,58 +253,58 @@ void send_proto(Client *client, ConfigItem_link *aconf) /* Second line */ sendto_one(client, NULL, "PROTOCTL CHANMODES=%s%s,%s,%s,%s USERMODES=%s BOOTED=%lld PREFIX=%s SID=%s MLOCK TS=%lld EXTSWHOIS", - CHPAR1, EXPAR1, EXPAR2, EXPAR3, EXPAR4, - umodestring, (long long)me.local->fake_lag, prefix->value, - me.id, (long long)TStime()); + CHPAR1, EXPAR1, EXPAR2, EXPAR3, EXPAR4, + umodestring, (long long)me.local->fake_lag, prefix->value, + me.id, (long long)TStime()); /* Third line */ sendto_one(client, NULL, "PROTOCTL NICKCHARS=%s CHANNELCHARS=%s BIGLINES", - charsys_get_current_languages(), - allowed_channelchars_valtostr(iConf.allowed_channelchars)); + charsys_get_current_languages(), + allowed_channelchars_valtostr(iConf.allowed_channelchars)); } #ifndef IRCDTOTALVERSION -#define IRCDTOTALVERSION BASE_VERSION "-" PATCH1 PATCH2 PATCH3 PATCH4 PATCH5 PATCH6 PATCH7 PATCH8 PATCH9 + #define IRCDTOTALVERSION BASE_VERSION "-" PATCH1 PATCH2 PATCH3 PATCH4 PATCH5 PATCH6 PATCH7 PATCH8 PATCH9 #endif /** Special filter for remote commands */ int remotecmdfilter(Client *client, int parc, const char *parv[]) { /* no remote requests permitted from non-ircops */ - if (MyUser(client) && !ValidatePermissionsForPath("server:remote",client,NULL,NULL,NULL) && !BadPtr(parv[1])) + if (MyUser(client) && !ValidatePermissionsForPath("server:remote", client, NULL, NULL, NULL) && !BadPtr(parv[1])) { sendnumeric(client, ERR_NOPRIVILEGES); return 1; /* STOP */ } /* same as above, but in case an old server forwards a request to us: we ignore it */ - if (!MyUser(client) && !ValidatePermissionsForPath("server:remote",client,NULL,NULL,NULL)) + if (!MyUser(client) && !ValidatePermissionsForPath("server:remote", client, NULL, NULL, NULL)) return 1; /* STOP (return) */ - + return 0; /* Continue */ } /** Output for /INFO */ char *unrealinfo[] = { - "This release was brought to you by the following people:", - "", - "Head coder:", - "* Bram Matthys (Syzop) ", - "", - "Coders:", - "* Krzysztof Beresztant (k4be) ", - "* Gottem ", - "* i ", - "", - "Past UnrealIRCd 4.x coders/contributors:", - "* Heero, binki, nenolod, ..", - "", - "Past UnrealIRCd 3.2.x coders/contributors:", - "* Stskeeps (ret. head coder / project leader)", - "* codemastr (ret. u3.2 head coder)", - "* aquanight, WolfSage, ..", - "* McSkaf, Zogg, NiQuiL, chasm, llthangel, nighthawk, ..", - NULL, + "This release was brought to you by the following people:", + "", + "Head coder:", + "* Bram Matthys (Syzop) ", + "", + "Coders:", + "* Krzysztof Beresztant (k4be) ", + "* Gottem ", + "* i ", + "", + "Past UnrealIRCd 4.x coders/contributors:", + "* Heero, binki, nenolod, ..", + "", + "Past UnrealIRCd 3.2.x coders/contributors:", + "* Stskeeps (ret. head coder / project leader)", + "* codemastr (ret. u3.2 head coder)", + "* aquanight, WolfSage, ..", + "* McSkaf, Zogg, NiQuiL, chasm, llthangel, nighthawk, ..", + NULL, }; /** Send /INFO output */ @@ -404,8 +404,7 @@ const char *get_client_status(Client *client) *p++ = 'C'; if (client->umodes & LISTENER_TLS) *p++ = 's'; - } - else + } else { if (IsTLS(client)) *p++ = 's'; @@ -485,7 +484,7 @@ void load_tunefile(void) /** Rehash motd and rule files (motd_file/rules_file and all tld entries). */ void rehash_motdrules() { -ConfigItem_tld *tlds; + ConfigItem_tld *tlds; reread_motdsandrules(); for (tlds = conf_tld; tlds; tlds = tlds->next) @@ -524,7 +523,7 @@ CMD_FUNC(cmd_rehash) */ labeled_response_inhibit = 1; - if (!ValidatePermissionsForPath("server:rehash",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:rehash", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -536,15 +535,17 @@ CMD_FUNC(cmd_rehash) return; } - if ((parc < 3) || BadPtr(parv[2])) { + if ((parc < 3) || BadPtr(parv[2])) + { /* If the argument starts with a '-' (like -motd, -opermotd, etc) then it's * assumed not to be a server. -- Syzop */ if (parv[1] && (parv[1][0] == '-')) { x = HUNTED_ISME; - } else { - if (!ValidatePermissionsForPath("server:rehash:global",client,NULL,NULL,NULL) && + } else + { + if (!ValidatePermissionsForPath("server:rehash:global", client, NULL, NULL, NULL) && parv[1] && (find_client(parv[1], NULL) != &me)) { sendnumeric(client, ERR_NOPRIVILEGES); @@ -552,12 +553,14 @@ CMD_FUNC(cmd_rehash) } x = hunt_server(client, recv_mtags, "REHASH", 1, parc, parv); } - } else { + } else + { if (match_simple("-glob*", parv[1])) /* This is really ugly... hack to make /rehash -global -something work */ { x = HUNTED_ISME; - } else { - if (!ValidatePermissionsForPath("server:rehash:global",client,NULL,NULL,NULL) && + } else + { + if (!ValidatePermissionsForPath("server:rehash:global", client, NULL, NULL, NULL) && parv[1] && (find_client(parv[1], NULL) != &me)) { sendnumeric(client, ERR_NOPRIVILEGES); @@ -586,7 +589,8 @@ CMD_FUNC(cmd_rehash) /* fallthrough... so we deal with this the same way as local rehashes */ } parv[1] = parv[2]; - } else { + } else + { /* Ok this is in an 'else' because it should be only executed for local clients, * but it's totally unrelated to the above ;). */ @@ -601,17 +605,17 @@ CMD_FUNC(cmd_rehash) } if (parv[1] && (match_simple("-glob*", parv[1]) - /* || (MyUser(client) && !strcasecmp(parv[1], "-all"))*/ )) + /* || (MyUser(client) && !strcasecmp(parv[1], "-all"))*/)) { /* /REHASH -global [options] */ Client *acptr; - if (!ValidatePermissionsForPath("server:rehash:global",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:rehash:global", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; } - + /* Shift parv's to the left */ parv[1] = parv[2]; parv[2] = NULL; @@ -627,9 +631,9 @@ CMD_FUNC(cmd_rehash) if (acptr == &me) continue; sendto_one(acptr, NULL, ":%s REHASH %s %s", - client->name, - acptr->name, - parv[1] ? parv[1] : ""); + client->name, + acptr->name, + parv[1] ? parv[1] : ""); } /* Don't return, continue, because we need to REHASH ourselves as well. */ } @@ -661,7 +665,8 @@ CMD_FUNC(cmd_rehash) if (!iConf.central_spamfilter_enabled) { sendnotice(client, "ERROR: Central Spamfilter is not enabled on this server."); - } else { + } else + { unreal_log(ULOG_INFO, "central-spamfilter", "CENTRAL_SPAMFILTER_RELOAD", client, "Reloading Central Spamfilter rules. [by: $client.details]"); central_spamfilter_last_download = 0; @@ -671,8 +676,7 @@ CMD_FUNC(cmd_rehash) RunHook(HOOKTYPE_REHASHFLAG, client, parv[1]); return; } - } - else + } else { if (loop.rehashing) { @@ -700,7 +704,7 @@ CMD_FUNC(cmd_restart) return; /* Check permissions */ - if (!ValidatePermissionsForPath("server:restart",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:restart", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; @@ -714,8 +718,7 @@ CMD_FUNC(cmd_restart) sendnumeric(client, ERR_NEEDMOREPARAMS, "RESTART"); return; } - } else - if (parc >= 2) + } else if (parc >= 2) { /* Syntax: /restart [reason] */ if (conf_drpass) @@ -735,7 +738,7 @@ CMD_FUNC(cmd_restart) sendnotice(acptr, "Server Restarted by %s", client->name); else if (IsServer(acptr)) sendto_one(acptr, NULL, ":%s ERROR :Restarted by %s: %s", - me.name, get_client_name(client, TRUE), reason ? reason : "No reason"); + me.name, get_client_name(client, TRUE), reason ? reason : "No reason"); } server_reboot(reason ? reason : "No reason"); @@ -851,7 +854,7 @@ void read_motd(const char *filename, MOTDFile *themotd) *tmp = '\0'; if ((tmp = strchr(line, '\r'))) *tmp = '\0'; - + if (strlen(line) > 510) line[510] = '\0'; @@ -871,7 +874,7 @@ void read_motd(const char *filename, MOTDFile *themotd) last->next = NULL; fclose(fd); - + return; } @@ -908,15 +911,15 @@ CMD_FUNC(cmd_die) if (!MyUser(client)) return; - if (!ValidatePermissionsForPath("server:die",client,NULL,NULL,NULL)) + if (!ValidatePermissionsForPath("server:die", client, NULL, NULL, NULL)) { sendnumeric(client, ERR_NOPRIVILEGES); return; } - if (conf_drpass) /* See if we have and DIE/RESTART password */ + if (conf_drpass) /* See if we have and DIE/RESTART password */ { - if (parc < 2) /* And if so, require a password :) */ + if (parc < 2) /* And if so, require a password :) */ { sendnumeric(client, ERR_NEEDMOREPARAMS, "DIE"); return; @@ -935,11 +938,11 @@ CMD_FUNC(cmd_die) list_for_each_entry(acptr, &lclient_list, lclient_node) { if (IsUser(acptr)) - sendnotice(acptr, "Server Terminated by %s", - client->name); + sendnotice(acptr, "Server Terminated by %s", + client->name); else if (IsServer(acptr)) sendto_one(acptr, NULL, ":%s ERROR :Terminated by %s", - me.name, get_client_name(client, TRUE)); + me.name, get_client_name(client, TRUE)); } s_die(); @@ -963,7 +966,7 @@ void add_pending_net(Client *client, const char *str) * and work on a copy. */ if (*str == '*') - strlcpy(buf, str+1, sizeof(buf)); + strlcpy(buf, str + 1, sizeof(buf)); else strlcpy(buf, str, sizeof(buf)); @@ -975,12 +978,12 @@ void add_pending_net(Client *client, const char *str) { if (!*name) continue; - + srv = safe_alloc(sizeof(PendingServer)); strlcpy(srv->sid, name, sizeof(srv->sid)); AddListItem(srv, net->servers); } - + AddListItem(net, pendingnet); } @@ -989,7 +992,7 @@ void free_pending_net(Client *client) { PendingNet *net, *net_next; PendingServer *srv, *srv_next; - + for (net = pendingnet; net; net = net_next) { net_next = net->next; @@ -1035,7 +1038,7 @@ Client *find_pending_net_duplicates(Client *cptr, Client **srv, char **sid) *srv = NULL; *sid = NULL; - + for (net = pendingnet; net; net = net->next) { if (net->client != cptr) @@ -1053,7 +1056,7 @@ Client *find_pending_net_duplicates(Client *cptr, Client **srv, char **sid) } } } - + return NULL; } @@ -1076,7 +1079,7 @@ Client *find_non_pending_net_duplicates(Client *client) return acptr; /* Found another (fully CONNECTED) server with identical numeric */ } } - + return NULL; } @@ -1188,7 +1191,7 @@ int valid_uid(const char *name) return 0; /* For all the remaining characters: digit or uppercase character */ - for (p = name+1; *p; p++) + for (p = name + 1; *p; p++) if (!isdigit(*p) && !isupper(*p)) return 0; @@ -1215,17 +1218,19 @@ void lost_server_link(Client *client, const char *tls_error_string) { /* TLS */ unreal_log(ULOG_ERROR, "link", "LINK_DISCONNECTED", client, - "Lost server link to $client [$client.ip]: $tls_error_string", - log_data_string("tls_error_string", tls_error_string), - client->server->conf ? log_data_link_block(client->server->conf) : NULL); - } else { + "Lost server link to $client [$client.ip]: $tls_error_string", + log_data_string("tls_error_string", tls_error_string), + client->server->conf ? log_data_link_block(client->server->conf) : NULL); + } else + { /* NON-TLS */ unreal_log(ULOG_ERROR, "link", "LINK_DISCONNECTED", client, - "Lost server link to $client [$client.ip]: $socket_error", - log_data_socket_error(client->local->fd), - client->server->conf ? log_data_link_block(client->server->conf) : NULL); + "Lost server link to $client [$client.ip]: $socket_error", + log_data_socket_error(client->local->fd), + client->server->conf ? log_data_link_block(client->server->conf) : NULL); } - } else { + } else + { /* A link attempt failed (it was never a fully connected server) */ /* We send these to local ops only */ if (tls_error_string) @@ -1234,30 +1239,33 @@ void lost_server_link(Client *client, const char *tls_error_string) if (client->server->conf) { unreal_log(ULOG_ERROR, "link", "LINK_ERROR_CONNECT", client, - client->server->conf->outgoing.file - ? "Unable to link with server $client [$link_block.file]: $tls_error_string" - : "Unable to link with server $client [$link_block.ip:$link_block.port]: $tls_error_string", - log_data_string("tls_error_string", tls_error_string), - log_data_link_block(client->server->conf)); - } else { + client->server->conf->outgoing.file + ? "Unable to link with server $client [$link_block.file]: $tls_error_string" + : "Unable to link with server $client [$link_block.ip:$link_block.port]: $tls_error_string", + log_data_string("tls_error_string", tls_error_string), + log_data_link_block(client->server->conf)); + } else + { unreal_log(ULOG_ERROR, "link", "LINK_ERROR_CONNECT", client, - "Unable to link with server $client: $tls_error_string", - log_data_string("tls_error_string", tls_error_string)); + "Unable to link with server $client: $tls_error_string", + log_data_string("tls_error_string", tls_error_string)); } - } else { + } else + { /* non-TLS */ if (client->server->conf) { unreal_log(ULOG_ERROR, "link", "LINK_ERROR_CONNECT", client, - client->server->conf->outgoing.file - ? "Unable to link with server $client [$link_block.file]: $socket_error" - : "Unable to link with server $client [$link_block.ip:$link_block.port]: $socket_error", - log_data_socket_error(client->local->fd), - log_data_link_block(client->server->conf)); - } else { + client->server->conf->outgoing.file + ? "Unable to link with server $client [$link_block.file]: $socket_error" + : "Unable to link with server $client [$link_block.ip:$link_block.port]: $socket_error", + log_data_socket_error(client->local->fd), + log_data_link_block(client->server->conf)); + } else + { unreal_log(ULOG_ERROR, "link", "LINK_ERROR_CONNECT", client, - "Unable to link with server $client: $socket_error", - log_data_socket_error(client->local->fd)); + "Unable to link with server $client: $socket_error", + log_data_socket_error(client->local->fd)); } } } diff --git a/src/socket.c b/src/socket.c index fb498ce40..5b338f835 100644 --- a/src/socket.c +++ b/src/socket.c @@ -113,13 +113,14 @@ static int listener_accept_wrapper(ConfigItem_listen *listener) if (listener->file) { unreal_log(ULOG_FATAL, "listen", "ACCEPT_ERROR", NULL, "Cannot accept incoming connection on file $file: $socket_error", - log_data_socket_error(listener->fd), - log_data_string("file", listener->file)); - } else { + log_data_socket_error(listener->fd), + log_data_string("file", listener->file)); + } else + { unreal_log(ULOG_FATAL, "listen", "ACCEPT_ERROR", NULL, "Cannot accept incoming connection on IP \"$listen_ip\" port $listen_port: $socket_error", - log_data_socket_error(listener->fd), - log_data_string("listen_ip", listener->ip), - log_data_integer("listen_port", listener->port)); + log_data_socket_error(listener->fd), + log_data_string("listen_ip", listener->ip), + log_data_integer("listen_port", listener->port)); } close_listener(listener); start_listeners(); @@ -135,13 +136,13 @@ static int listener_accept_wrapper(ConfigItem_listen *listener) if (listener->options & LISTENER_CONTROL) { /* ... but not unlimited ;) */ - if ((++OpenFiles >= maxclients+(reserved_fds/2)) || (cli_fd >= maxclients+(reserved_fds/2))) + if ((++OpenFiles >= maxclients + (reserved_fds / 2)) || (cli_fd >= maxclients + (reserved_fds / 2))) { ircstats.is_ref++; if (last_allinuse < TStime() - 15) { unreal_log(ULOG_FATAL, "listen", "ACCEPT_ERROR_MAXCLIENTS", NULL, "Cannot accept incoming connection on file $file: All connections in use", - log_data_string("file", listener->file)); + log_data_string("file", listener->file)); last_allinuse = TStime(); } fd_close(cli_fd); @@ -158,11 +159,12 @@ static int listener_accept_wrapper(ConfigItem_listen *listener) if (listener->file) { unreal_log(ULOG_FATAL, "listen", "ACCEPT_ERROR_MAXCLIENTS", NULL, "Cannot accept incoming connection on file $file: All connections in use", - log_data_string("file", listener->file)); - } else { + log_data_string("file", listener->file)); + } else + { unreal_log(ULOG_FATAL, "listen", "ACCEPT_ERROR_MAXCLIENTS", NULL, "Cannot accept incoming connection on IP \"$listen_ip\" port $listen_port: All connections in use", - log_data_string("listen_ip", listener->ip), - log_data_integer("listen_port", listener->port)); + log_data_string("listen_ip", listener->ip), + log_data_integer("listen_port", listener->port)); } last_allinuse = TStime(); } @@ -193,7 +195,7 @@ static void listener_accept(int listener_fd, int revents, void *data) * Better refuse or lag a few new clients than become * unresponse to existing clients. */ - for (i=0; i < 100; i++) + for (i = 0; i < 100; i++) if (!listener_accept_wrapper((ConfigItem_listen *)data)) break; } @@ -226,9 +228,9 @@ int unreal_listen_inet(ConfigItem_listen *listener) { unreal_log(ULOG_FATAL, "listen", "LISTEN_SOCKET_ERROR", NULL, "Could not listen on IP \"$listen_ip\" on port $listen_port: $socket_error", - log_data_socket_error(-1), - log_data_string("listen_ip", ip), - log_data_integer("listen_port", port)); + log_data_socket_error(-1), + log_data_string("listen_ip", ip), + log_data_integer("listen_port", port)); return -1; } @@ -311,8 +313,8 @@ int unreal_listen_unix(ConfigItem_listen *listener) { unreal_log(ULOG_FATAL, "listen", "LISTEN_SOCKET_ERROR", NULL, "Could not create UNIX domain socket for $file: $socket_error", - log_data_socket_error(-1), - log_data_string("file", listener->file)); + log_data_socket_error(-1), + log_data_string("file", listener->file)); return -1; } @@ -382,8 +384,7 @@ int add_listener(ConfigItem_listen *listener) { listener->options |= LISTENER_BOUND; return 1; - } - else + } else { listener->fd = -1; return -1; @@ -403,15 +404,16 @@ void close_listener(ConfigItem_listen *listener) if (listener->socket_type == SOCKET_TYPE_UNIX) { unreal_log(ULOG_INFO, "listen", "LISTEN_REMOVED", NULL, - "UnrealIRCd is now no longer listening on $listen_file [$protocol]", - log_data_string("listen_file", listener->file), - log_data_string("protocol", socket_type_valtostr(listener->socket_type))); - } else { + "UnrealIRCd is now no longer listening on $listen_file [$protocol]", + log_data_string("listen_file", listener->file), + log_data_string("protocol", socket_type_valtostr(listener->socket_type))); + } else + { unreal_log(ULOG_INFO, "listen", "LISTEN_REMOVED", NULL, - "UnrealIRCd is now no longer listening on $listen_ip:$listen_port [$protocol]", - log_data_string("listen_ip", listener->ip), - log_data_integer("listen_port", listener->port), - log_data_string("protocol", socket_type_valtostr(listener->socket_type))); + "UnrealIRCd is now no longer listening on $listen_ip:$listen_port [$protocol]", + log_data_string("listen_ip", listener->ip), + log_data_integer("listen_port", listener->port), + log_data_string("protocol", socket_type_valtostr(listener->socket_type))); } fd_close(listener->fd); --OpenFiles; @@ -471,11 +473,11 @@ void check_user_limit(void) if (setrlimit(RLIMIT_FD_MAX, &limit) == -1) { /* HACK: if it's mac os X then don't error... */ -#ifndef OSXTIGER + #ifndef OSXTIGER fprintf(stderr, "error setting maximum number of open files to %ld\n", - (long)limit.rlim_cur); + (long)limit.rlim_cur); exit(-1); -#endif // OSXTIGER + #endif // OSXTIGER } } /* This can only happen if it is due to resource limits (./Config already rejects <100) */ @@ -487,7 +489,7 @@ void check_user_limit(void) "The recommended ulimit -n setting is at least 1024 and " "preferably 4096.\n" "Note that this error is often seen on small web shells that are not meant for running IRC servers.\n", - m); + m); exit(-1); } maxclients = m; @@ -495,7 +497,7 @@ void check_user_limit(void) #endif // RLIMIT_FD_MAX #ifndef _WIN32 -#ifdef BACKEND_SELECT + #ifdef BACKEND_SELECT if (MAXCONNECTIONS > FD_SETSIZE) { fprintf(stderr, "MAXCONNECTIONS (%d) is higher than FD_SETSIZE (%d)\n", MAXCONNECTIONS, FD_SETSIZE); @@ -503,7 +505,7 @@ void check_user_limit(void) fprintf(stderr, "You might need to recompile the IRCd and answer a lower value to the MAXCONNECTIONS question in ./Config\n"); exit(-1); } -#endif + #endif #endif #ifdef _WIN32 maxclients = MAXCONNECTIONS; @@ -649,13 +651,11 @@ void close_connection(Client *client) { ircstats.is_sv++; ircstats.is_sti += TStime() - client->local->creationtime; - } - else if (IsUser(client)) + } else if (IsUser(client)) { ircstats.is_cl++; ircstats.is_cti += TStime() - client->local->creationtime; - } - else + } else ircstats.is_ni++; /* @@ -673,7 +673,8 @@ void close_connection(Client *client) if (client->local->fd >= 0) { send_queued(client); - if (IsTLS(client) && client->local->ssl) { + if (IsTLS(client) && client->local->ssl) + { SSL_set_shutdown(client->local->ssl, SSL_RECEIVED_SHUTDOWN); SSL_smart_shutdown(client->local->ssl); SSL_free(client->local->ssl); @@ -728,8 +729,8 @@ void set_sock_opts(int fd, Client *client, SocketType socket_type) if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&opt, sizeof(opt)) < 0) { unreal_log(ULOG_WARNING, "socket", "SOCKET_ERROR_SETSOCKOPTS", client, - "Could not setsockopt(SO_REUSEADDR): $socket_error", - log_data_socket_error(-1)); + "Could not setsockopt(SO_REUSEADDR): $socket_error", + log_data_socket_error(-1)); } #endif @@ -738,11 +739,10 @@ void set_sock_opts(int fd, Client *client, SocketType socket_type) if (setsockopt(fd, SOL_SOCKET, SO_USELOOPBACK, (void *)&opt, sizeof(opt)) < 0) { unreal_log(ULOG_WARNING, "socket", "SOCKET_ERROR_SETSOCKOPTS", client, - "Could not setsockopt(SO_USELOOPBACK): $socket_error", - log_data_socket_error(-1)); + "Could not setsockopt(SO_USELOOPBACK): $socket_error", + log_data_socket_error(-1)); } #endif - } /* The following code applies to all socket types: IPv4, IPv6, UNIX domain sockets */ @@ -754,17 +754,16 @@ void set_sock_opts(int fd, Client *client, SocketType socket_type) if (client) { unreal_log(ULOG_WARNING, "socket", "SOCKET_ERROR_SETSOCKOPTS", client, - "Could not get socket options (F_GETFL): $socket_error", - log_data_socket_error(-1)); + "Could not get socket options (F_GETFL): $socket_error", + log_data_socket_error(-1)); } - } - else if (fcntl(fd, F_SETFL, opt | O_NONBLOCK) == -1) + } else if (fcntl(fd, F_SETFL, opt | O_NONBLOCK) == -1) { if (client) { unreal_log(ULOG_WARNING, "socket", "SOCKET_ERROR_SETSOCKOPTS", client, - "Could not get socket options (F_SETFL): $socket_error", - log_data_socket_error(-1)); + "Could not get socket options (F_SETFL): $socket_error", + log_data_socket_error(-1)); } } #else @@ -774,8 +773,8 @@ void set_sock_opts(int fd, Client *client, SocketType socket_type) if (client) { unreal_log(ULOG_WARNING, "socket", "SOCKET_ERROR_SETSOCKOPTS", client, - "Could not ioctlsocket FIONBIO: $socket_error", - log_data_socket_error(-1)); + "Could not ioctlsocket FIONBIO: $socket_error", + log_data_socket_error(-1)); } } #endif @@ -810,7 +809,7 @@ int is_loopback_ip(char *ip) */ const char *getpeerip(Client *client, int fd, SocketType socket_type, int *port) { - static char ret[HOSTLEN+1]; + static char ret[HOSTLEN + 1]; if (socket_type == SOCKET_TYPE_IPV6) { @@ -870,21 +869,21 @@ Client *add_connection(ConfigItem_listen *listener, int fd) { unreal_log(ULOG_ERROR, "listen", "ACCEPT_ERROR", NULL, "Failed to accept new client: unable to get IP address: $socket_error", - log_data_socket_error(fd), - log_data_string("listen_ip", listener->ip), - log_data_integer("listen_port", listener->port)); + log_data_socket_error(fd), + log_data_string("listen_ip", listener->ip), + log_data_integer("listen_port", listener->port)); } -refuse_client: - ircstats.is_ref++; - client->local->fd = -2; - if (!list_empty(&client->client_node)) - list_del(&client->client_node); - if (!list_empty(&client->lclient_node)) - list_del(&client->lclient_node); - free_client(client); - fd_close(fd); - --OpenFiles; - return NULL; + refuse_client: + ircstats.is_ref++; + client->local->fd = -2; + if (!list_empty(&client->client_node)) + list_del(&client->client_node); + if (!list_empty(&client->lclient_node)) + list_del(&client->lclient_node); + free_client(client); + fd_close(fd); + --OpenFiles; + return NULL; } /* Fill in sockhost & ip ASAP */ @@ -916,8 +915,7 @@ refuse_client: deadsocket_exit(client, 1); irccounts.unknown--; goto refuse_client; - } else - if (value == HOOK_DENY) + } else if (value == HOOK_DENY) { if (quick_close || !(listener->options & LISTENER_TLS)) { @@ -928,7 +926,8 @@ refuse_client: deadsocket_exit(client, 1); irccounts.unknown--; goto refuse_client; - } else { + } else + { /* continue, and even do the SSL/TLS handshake */ } } @@ -1000,7 +999,7 @@ int dead_socket(Client *to, const char *notice) */ if (to->local->error_str) return -1; /* don't overwrite & don't send multiple times */ - + if (!IsUser(to) && !IsUnknown(to) && !IsRPC(to) && !IsControl(to) && !IsClosing(to)) { /* Looks like a duplicate error message to me? @@ -1031,25 +1030,26 @@ void deadsocket_exit(Client *client, int special) if (special) { sendto_one(client, NULL, "ERROR :Closing Link: %s (%s)", get_client_name(client, FALSE), - client->local->error_str ? client->local->error_str : "Dead socket"); + client->local->error_str ? client->local->error_str : "Dead socket"); send_queued(client); /* Caller takes care of freeing 'client' - only used by HOOKTYPE_ACCEPT */ return; - } else { + } else + { exit_client(client, NULL, client->local->error_str ? client->local->error_str : "Dead socket"); } } typedef enum DNSFinishedType { - DNS_FINISHED_NONE=0, /**< We finished because DNS lookups are disabled */ - DNS_FINISHED_FAIL=1, /**< DNS lookup failed (cached or uncached) */ - DNS_FINISHED_SUCCESS=2, /**< DNS lookup succeeded (uncached) */ - DNS_FINISHED_SUCCESS_CACHED=3 /**< DNS lookup succeeded (cached DNS entry) */ + DNS_FINISHED_NONE = 0, /**< We finished because DNS lookups are disabled */ + DNS_FINISHED_FAIL = 1, /**< DNS lookup failed (cached or uncached) */ + DNS_FINISHED_SUCCESS = 2, /**< DNS lookup succeeded (uncached) */ + DNS_FINISHED_SUCCESS_CACHED = 3 /**< DNS lookup succeeded (cached DNS entry) */ } DNSFinishedType; void dns_finished(Client *client, DNSFinishedType type) { - switch(type) + switch (type) { case DNS_FINISHED_FAIL: if (should_show_connect_info(client)) @@ -1069,7 +1069,7 @@ void dns_finished(Client *client, DNSFinishedType type) /* Set sockhost to resolved hostname already */ if (client->local->hostp) - set_sockhost(client, client->local->hostp->h_name); + set_sockhost(client, client->local->hostp->h_name); RunHook(HOOKTYPE_DNS_FINISHED, client); } @@ -1118,8 +1118,7 @@ void start_dns_and_ident_lookup(Client *client) { /* Resolving in progress */ SetDNSLookup(client); - } else - if (he->h_name == NULL) + } else if (he->h_name == NULL) { /* Host was negatively cached */ unreal_free_hostent(he); @@ -1130,7 +1129,8 @@ void start_dns_and_ident_lookup(Client *client) client->local->hostp = he; dns_finished(client, DNS_FINISHED_SUCCESS_CACHED); } - } else { + } else + { /* Still need to call this, so our hooks get called */ dns_finished(client, DNS_FINISHED_NONE); } @@ -1218,32 +1218,31 @@ void read_packet(int fd, int revents, void *data) switch (err) { - case SSL_ERROR_WANT_WRITE: - fd_setselect(fd, FD_SELECT_READ, NULL, client); - fd_setselect(fd, FD_SELECT_WRITE, read_packet, client); - length = -1; - SET_ERRNO(P_EWOULDBLOCK); - break; - case SSL_ERROR_WANT_READ: - fd_setselect(fd, FD_SELECT_READ, read_packet, client); - length = -1; - SET_ERRNO(P_EWOULDBLOCK); - break; - case SSL_ERROR_SYSCALL: - break; - case SSL_ERROR_SSL: - if (ERRNO == P_EAGAIN) + case SSL_ERROR_WANT_WRITE: + fd_setselect(fd, FD_SELECT_READ, NULL, client); + fd_setselect(fd, FD_SELECT_WRITE, read_packet, client); + length = -1; + SET_ERRNO(P_EWOULDBLOCK); break; - default: - /*length = 0; + case SSL_ERROR_WANT_READ: + fd_setselect(fd, FD_SELECT_READ, read_packet, client); + length = -1; + SET_ERRNO(P_EWOULDBLOCK); + break; + case SSL_ERROR_SYSCALL: + break; + case SSL_ERROR_SSL: + if (ERRNO == P_EAGAIN) + break; + default: + /*length = 0; SET_ERRNO(0); ^^ why this? we should error. -- todo: is errno correct? */ - break; + break; } } - } - else + } else length = recv(client->local->fd, readbuf, sizeof(readbuf), 0); if (length <= 0) @@ -1289,7 +1288,7 @@ void read_packet(int fd, int revents, void *data) void process_clients(void) { Client *client; - + /* Problem: * When processing a client, that current client may exit due to eg QUIT. * Similarly, current->next may be killed due to /KILL. @@ -1310,7 +1309,8 @@ void process_clients(void) * I think the chosen solution is best, though it remains silly. -- Syzop */ - do { + do + { list_for_each_entry(client, &lclient_list, lclient_node) { if ((client->local->fd >= 0) && DBufLength(&client->local->recvQ) && !IsDead(client)) @@ -1320,9 +1320,10 @@ void process_clients(void) break; } } - } while(&client->lclient_node != &lclient_list); + } while (&client->lclient_node != &lclient_list); - do { + do + { list_for_each_entry(client, &unknown_list, lclient_node) { if ((client->local->fd >= 0) && DBufLength(&client->local->recvQ) && !IsDead(client)) @@ -1332,9 +1333,10 @@ void process_clients(void) break; } } - } while(&client->lclient_node != &unknown_list); + } while (&client->lclient_node != &unknown_list); - do { + do + { list_for_each_entry(client, &control_list, lclient_node) { if ((client->local->fd >= 0) && DBufLength(&client->local->recvQ) && !IsDead(client)) @@ -1344,9 +1346,7 @@ void process_clients(void) break; } } - } while(&client->lclient_node != &control_list); - - + } while (&client->lclient_node != &control_list); } /** Check if 'ip' is a valid IP address, and if so what type. @@ -1417,7 +1417,7 @@ int unix_sockets_capable(void) */ int deliver_it(Client *client, char *str, int len, int *want_read) { - int retval; + int retval; *want_read = 0; @@ -1437,25 +1437,24 @@ int deliver_it(Client *client, char *str, int len, int *want_read) { switch (SSL_get_error(client->local->ssl, retval)) { - case SSL_ERROR_WANT_READ: - SET_ERRNO(P_EWOULDBLOCK); - *want_read = 1; - return 0; - case SSL_ERROR_WANT_WRITE: - SET_ERRNO(P_EWOULDBLOCK); - break; - case SSL_ERROR_SYSCALL: - break; - case SSL_ERROR_SSL: - if (ERRNO == P_EAGAIN) + case SSL_ERROR_WANT_READ: + SET_ERRNO(P_EWOULDBLOCK); + *want_read = 1; + return 0; + case SSL_ERROR_WANT_WRITE: + SET_ERRNO(P_EWOULDBLOCK); break; + case SSL_ERROR_SYSCALL: + break; + case SSL_ERROR_SSL: + if (ERRNO == P_EAGAIN) + break; /* FALLTHROUGH */ - default: - return -1; /* hm.. why was this 0?? we have an error! */ + default: + return -1; /* hm.. why was this 0?? we have an error! */ } } - } - else + } else retval = send(client->local->fd, str, len, 0); /* ** Convert WOULDBLOCK to a return of "0 bytes moved". This @@ -1465,14 +1464,14 @@ int deliver_it(Client *client, char *str, int len, int *want_read) ** ** ...now, would this work on VMS too? --msa */ -# ifndef _WIN32 +#ifndef _WIN32 if (retval < 0 && (errno == EWOULDBLOCK || errno == EAGAIN || - errno == ENOBUFS)) -# else - if (retval < 0 && (WSAGetLastError() == WSAEWOULDBLOCK || - WSAGetLastError() == WSAENOBUFS)) -# endif - retval = 0; + errno == ENOBUFS)) +#else + if (retval < 0 && (WSAGetLastError() == WSAEWOULDBLOCK || + WSAGetLastError() == WSAENOBUFS)) +#endif + retval = 0; if (retval > 0) { @@ -1496,8 +1495,7 @@ int unreal_connect(int fd, const char *ip, int port, SocketType socket_type) inet_pton(AF_INET6, ip, &server.sin6_addr); server.sin6_port = htons(port); n = connect(fd, (struct sockaddr *)&server, sizeof(server)); - } - else if (socket_type == SOCKET_TYPE_IPV4) + } else if (socket_type == SOCKET_TYPE_IPV4) { struct sockaddr_in server; memset(&server, 0, sizeof(server)); @@ -1540,8 +1538,7 @@ int unreal_bind(int fd, const char *ip, int port, SocketType socket_type) if (inet_pton(AF_INET, ip, &server.sin_addr.s_addr) != 1) return 0; return !bind(fd, (struct sockaddr *)&server, sizeof(server)); - } - else if (socket_type == SOCKET_TYPE_IPV6) + } else if (socket_type == SOCKET_TYPE_IPV6) { struct sockaddr_in6 server; memset(&server, 0, sizeof(server)); @@ -1589,7 +1586,7 @@ void init_winsock(void) const char *socket_type_valtostr(SocketType t) { - switch(t) + switch (t) { case SOCKET_TYPE_IPV4: return "IPv4"; @@ -1694,7 +1691,8 @@ int set_client_ip(Client *client, const char *ip) { if (!update_known_user_cache(client)) return 0; /* rejected */ - } else { + } else + { /* Initial set */ client->known_user_cached = user_allowed_by_security_group_name(client, "known-users") ? 1 : 0; } diff --git a/src/support.c b/src/support.c index af7f16e18..c337dd354 100644 --- a/src/support.c +++ b/src/support.c @@ -58,25 +58,25 @@ char *strtoken(char **save, char *str, char *fs) char *pos, *tmp; if (str) - pos = str; /* new string scan */ + pos = str; /* new string scan */ else pos = *save; /* keep last position across calls */ while (pos && *pos && strchr(fs, *pos) != NULL) - pos++; /* skip leading separators */ + pos++; /* skip leading separators */ if (!pos || !*pos) - return (pos = *save = NULL); /* string contains only sep's */ + return (pos = *save = NULL); /* string contains only sep's */ - tmp = pos; /* now, keep position of the token */ + tmp = pos; /* now, keep position of the token */ while (*pos && strchr(fs, *pos) == NULL) - pos++; /* skip content of the token */ + pos++; /* skip content of the token */ if (*pos) - *pos++ = '\0'; /* remove first sep after the token */ + *pos++ = '\0'; /* remove first sep after the token */ else - pos = NULL; /* end of string */ + pos = NULL; /* end of string */ *save = pos; return (tmp); @@ -101,8 +101,9 @@ char *strtoken_noskip(char **save, char *str, char *fs) if (str) { - pos = str; /* new string scan */ - } else { + pos = str; /* new string scan */ + } else + { if (*save == NULL) { /* We reached the end of the string */ @@ -122,7 +123,8 @@ char *strtoken_noskip(char **save, char *str, char *fs) /* Next call is end of string */ *save = NULL; *pos++ = '\0'; - } else { + } else + { *pos++ = '\0'; *save = pos; } @@ -206,7 +208,7 @@ void stripcrlf(char *c) #ifndef HAVE_STRNLEN size_t strnlen(const char *s, size_t maxlen) { - const char *end = memchr (s, 0, maxlen); + const char *end = memchr(s, 0, maxlen); return end ? (size_t)(end - s) : maxlen; } #endif @@ -269,11 +271,12 @@ size_t strlcat(char *dst, const char *src, size_t size) if (len1 + len2 >= size) len2 = size - (len1 + 1); - if (len2 > 0) { + if (len2 > 0) + { memcpy(dst + len1, src, len2); dst[len1 + len2] = 0; } - + return ret; } #endif @@ -289,11 +292,12 @@ size_t strlncat(char *dst, const char *src, size_t size, size_t n) if (size <= len1) return size; - + if (len1 + len2 >= size) len2 = size - (len1 + 1); - if (len2 > 0) { + if (len2 > 0) + { memcpy(dst + len1, src, len2); dst[len1 + len2] = 0; } @@ -306,10 +310,10 @@ size_t strlncat(char *dst, const char *src, size_t size, size_t n) void strlcat_letter(char *buf, char c, size_t buflen) { int n = strlen(buf); - if (!buflen || (n >= buflen-1)) + if (!buflen || (n >= buflen - 1)) return; buf[n] = c; - buf[n+1] = '\0'; + buf[n + 1] = '\0'; } /** Copies a string and ensure the new buffer is at most 'max' size, including NUL. @@ -330,10 +334,10 @@ char *strldup(const char *src, size_t max) return NULL; n = strlen(src); - if (n > max-1) - n = max-1; + if (n > max - 1) + n = max - 1; - ptr = safe_alloc(n+1); + ptr = safe_alloc(n + 1); memcpy(ptr, src, n); ptr[n] = '\0'; @@ -420,7 +424,8 @@ int b64_encode(unsigned char const *src, size_t srclength, char *target, size_t u_char output[4]; size_t i; - while (2 < srclength) { + while (2 < srclength) + { input[0] = *src++; input[1] = *src++; input[2] = *src++; @@ -438,14 +443,15 @@ int b64_encode(unsigned char const *src, size_t srclength, char *target, size_t target[datalength++] = Base64[output[2]]; target[datalength++] = Base64[output[3]]; } - + /* Now we worry about padding. */ - if (0 != srclength) { + if (0 != srclength) + { /* Get what's left. */ input[0] = input[1] = input[2] = '\0'; for (i = 0; i < srclength; i++) input[i] = *src++; - + output[0] = input[0] >> 2; output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); @@ -462,7 +468,7 @@ int b64_encode(unsigned char const *src, size_t srclength, char *target, size_t } if (datalength >= targsize) return (-1); - target[datalength] = '\0'; /* Returned value doesn't count \0. */ + target[datalength] = '\0'; /* Returned value doesn't count \0. */ return (datalength); } @@ -481,59 +487,65 @@ int b64_decode(char const *src, unsigned char *target, size_t targsize) state = 0; tarindex = 0; - while ((ch = *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ + while ((ch = *src++) != '\0') + { + if (isspace(ch)) /* Skip whitespace anywhere. */ continue; if (ch == Pad64) break; pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ + if (pos == 0) /* A non-base64 character. */ return (-1); - switch (state) { - case 0: - if (target) { - if ((size_t)tarindex >= targsize) - return (-1); - target[tarindex] = (pos - Base64) << 2; - } - state = 1; - break; - case 1: - if (target) { - if ((size_t)tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 4; - target[tarindex+1] = ((pos - Base64) & 0x0f) - << 4 ; - } - tarindex++; - state = 2; - break; - case 2: - if (target) { - if ((size_t)tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 2; - target[tarindex+1] = ((pos - Base64) & 0x03) - << 6; - } - tarindex++; - state = 3; - break; - case 3: - if (target) { - if ((size_t)tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64); - } - tarindex++; - state = 0; - break; - default: - abort(); + switch (state) + { + case 0: + if (target) + { + if ((size_t)tarindex >= targsize) + return (-1); + target[tarindex] = (pos - Base64) << 2; + } + state = 1; + break; + case 1: + if (target) + { + if ((size_t)tarindex + 1 >= targsize) + return (-1); + target[tarindex] |= (pos - Base64) >> 4; + target[tarindex + 1] = ((pos - Base64) & 0x0f) + << 4; + } + tarindex++; + state = 2; + break; + case 2: + if (target) + { + if ((size_t)tarindex + 1 >= targsize) + return (-1); + target[tarindex] |= (pos - Base64) >> 2; + target[tarindex + 1] = ((pos - Base64) & 0x03) + << 6; + } + tarindex++; + state = 3; + break; + case 3: + if (target) + { + if ((size_t)tarindex >= targsize) + return (-1); + target[tarindex] |= (pos - Base64); + } + tarindex++; + state = 0; + break; + default: + abort(); } } @@ -542,44 +554,47 @@ int b64_decode(char const *src, unsigned char *target, size_t targsize) * on a byte boundary, and/or with erroneous trailing characters. */ - if (ch == Pad64) { /* We got a pad char. */ - ch = *src++; /* Skip it, get next. */ - switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return (-1); - - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) + if (ch == Pad64) + { /* We got a pad char. */ + ch = *src++; /* Skip it, get next. */ + switch (state) + { + case 0: /* Invalid = in first position */ + case 1: /* Invalid = in second position */ return (-1); - ch = *src++; /* Skip the = */ - /* Fall through to "single trailing =" case. */ - /* FALLTHROUGH */ - case 3: /* Valid, means two bytes of info */ - /* + case 2: /* Valid, means one byte of info */ + /* Skip any number of spaces. */ + for (; ch != '\0'; ch = *src++) + if (!isspace(ch)) + break; + /* Make sure there is another trailing = sign. */ + if (ch != Pad64) + return (-1); + ch = *src++; /* Skip the = */ + /* Fall through to "single trailing =" case. */ + /* FALLTHROUGH */ + + case 3: /* Valid, means two bytes of info */ + /* * We know this char is an =. Is there anything but * whitespace after it? */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - return (-1); + for (; ch != '\0'; ch = *src++) + if (!isspace(ch)) + return (-1); - /* + /* * Now make sure for cases 2 and 3 that the "extra" * bits that slopped past the last full byte were * zeros. If we don't check them, they become a * subliminal channel. */ - if (target && target[tarindex] != 0) - return (-1); + if (target && target[tarindex] != 0) + return (-1); } - } else { + } else + { /* * We ended by seeing the end of the string. Make sure we * have no partial bytes lying around. @@ -637,13 +652,11 @@ static int compare_right(char const *a, char const *b) { if (!bias) bias = -1; - } else - if (*a > *b) + } else if (*a > *b) { if (!bias) bias = +1; - } else - if (!*a && !*b) + } else if (!*a && !*b) return bias; } @@ -682,7 +695,8 @@ static int strnatcmp0(char const *a, char const *b, int fold_case) ai = bi = 0; while (1) { - ca = a[ai]; cb = b[bi]; + ca = a[ai]; + cb = b[bi]; /* skip over leading spaces or zeros */ while (isspace(ca)) @@ -692,15 +706,16 @@ static int strnatcmp0(char const *a, char const *b, int fold_case) cb = b[++bi]; /* process run of digits */ - if (isdigit(ca) && isdigit(cb)) + if (isdigit(ca) && isdigit(cb)) { fractional = (ca == '0' || cb == '0'); if (fractional) { - if ((result = compare_left(a+ai, b+bi)) != 0) + if ((result = compare_left(a + ai, b + bi)) != 0) return result; - } else { - if ((result = compare_right(a+ai, b+bi)) != 0) + } else + { + if ((result = compare_right(a + ai, b + bi)) != 0) return result; } } @@ -813,7 +828,7 @@ void *safe_alloc_sensitive(size_t size) void *p; if (size == 0) return NULL; - p = sodium_malloc(((size/32)*32)+32); + p = sodium_malloc(((size / 32) * 32) + 32); if (!p) outofmemory(size); memset(p, 0, size); @@ -823,7 +838,7 @@ void *safe_alloc_sensitive(size_t size) /** Safely duplicate a string */ char *our_strdup_sensitive(const char *str) { - char *ret = safe_alloc_sensitive(strlen(str)+1); + char *ret = safe_alloc_sensitive(strlen(str) + 1); if (!ret) outofmemory(strlen(str)); strcpy(ret, str); /* safe, see above */ @@ -838,7 +853,7 @@ char *unreal_mktemp(const char *dir, const char *suffix) { FILE *fd; unsigned int i; - static char tempbuf[PATH_MAX+1]; + static char tempbuf[PATH_MAX + 1]; for (i = 500; i > 0; i--) { @@ -849,8 +864,8 @@ char *unreal_mktemp(const char *dir, const char *suffix) fclose(fd); } config_error("Unable to create temporary file in directory '%s': %s", - dir, strerror(errno)); /* eg: permission denied :p */ - return NULL; + dir, strerror(errno)); /* eg: permission denied :p */ + return NULL; } /** Returns the path portion of the given path/file @@ -858,7 +873,7 @@ char *unreal_mktemp(const char *dir, const char *suffix) */ char *unreal_getpathname(const char *filepath, char *path) { - const char *end = filepath+strlen(filepath); + const char *end = filepath + strlen(filepath); while (*end != '\\' && *end != '/' && end > filepath) end--; @@ -866,7 +881,7 @@ char *unreal_getpathname(const char *filepath, char *path) path = NULL; else { - int size = end-filepath; + int size = end - filepath; if (size >= PATH_MAX) path = NULL; else @@ -889,7 +904,7 @@ const char *unreal_getfilename(const char *path) if (!len) return NULL; - end = path+len-1; + end = path + len - 1; if (*end == '\\' || *end == '/') return NULL; @@ -933,10 +948,10 @@ int unreal_create_directory_structure(const char *dname, mode_t mode) int lastresult; char buf[512], *p; strlcpy(buf, dname, sizeof(buf)); /* work on a copy */ - for (p=strchr(buf+1, '/'); p; p=strchr(p+1, '/')) + for (p = strchr(buf + 1, '/'); p; p = strchr(p + 1, '/')) { *p = '\0'; - unreal_mkdir(buf,mode); + unreal_mkdir(buf, mode); *p = '/'; } /* Finally, try the complete path */ @@ -956,7 +971,7 @@ int unreal_create_directory_structure(const char *dname, mode_t mode) */ int unreal_create_directory_structure_for_file(const char *fname, mode_t mode) { - char buf[PATH_MAX+1]; + char buf[PATH_MAX + 1]; const char *path = unreal_getpathname(fname, buf); if (!path) return 0; @@ -973,18 +988,18 @@ const char *unreal_getmodfilename(const char *path) char *p; char *name = NULL; char *directory = NULL; - + if (BadPtr(path)) return path; - + strlcpy(buf, path, sizeof(buf)); - + /* Backtrack... */ for (p = buf + strlen(buf); p >= buf; p--) { if ((*p == '/') || (*p == '\\')) { - name = p+1; + name = p + 1; *p = '\0'; directory = buf; /* fallback */ for (; p >= buf; p--) @@ -998,15 +1013,15 @@ const char *unreal_getmodfilename(const char *path) break; } } - + if (!name) name = buf; - + if (!directory || !strcmp(directory, "modules")) snprintf(ret, sizeof(ret), "%s", name); else snprintf(ret, sizeof(ret), "%s.%s", directory, name); - + return ret; } @@ -1015,9 +1030,9 @@ const char *unreal_getmodfilename(const char *path) */ const char *unreal_mkcache(const char *url) { - static char tempbuf[PATH_MAX+1]; + static char tempbuf[PATH_MAX + 1]; char tmp2[128]; - + snprintf(tempbuf, PATH_MAX, "%s/%s", CACHEDIR, sha256hash(tmp2, url, strlen(url))); return tempbuf; } @@ -1050,7 +1065,7 @@ int unreal_copyfile(const char *src, const char *dest) #ifndef _WIN32 srcfd = open(src, O_RDONLY); #else - srcfd = open(src, _O_RDONLY|_O_BINARY); + srcfd = open(src, _O_RDONLY | _O_BINARY); #endif if (srcfd < 0) @@ -1060,13 +1075,13 @@ int unreal_copyfile(const char *src, const char *dest) } #ifndef _WIN32 -#if defined(DEFAULT_PERMISSIONS) && (DEFAULT_PERMISSIONS != 0) - destfd = open(dest, O_WRONLY|O_CREAT, DEFAULT_PERMISSIONS); + #if defined(DEFAULT_PERMISSIONS) && (DEFAULT_PERMISSIONS != 0) + destfd = open(dest, O_WRONLY | O_CREAT, DEFAULT_PERMISSIONS); + #else + destfd = open(dest, O_WRONLY | O_CREAT, S_IRUSR | S_IXUSR); + #endif /* DEFAULT_PERMISSIONS */ #else - destfd = open(dest, O_WRONLY|O_CREAT, S_IRUSR | S_IXUSR); -#endif /* DEFAULT_PERMISSIONS */ -#else - destfd = open(dest, _O_BINARY|_O_WRONLY|_O_CREAT, _S_IWRITE); + destfd = open(dest, _O_BINARY | _O_WRONLY | _O_CREAT, _S_IWRITE); #endif /* _WIN32 */ if (destfd < 0) { @@ -1079,15 +1094,15 @@ int unreal_copyfile(const char *src, const char *dest) if (write(destfd, buf, len) != len) { config_error("Write error to file '%s': %s [not enough free hd space / quota? need several mb's!]", - dest, strerror(ERRNO)); - cancel_copy(srcfd,destfd,dest); + dest, strerror(ERRNO)); + cancel_copy(srcfd, destfd, dest); return 0; } if (len < 0) /* very unusual.. perhaps an I/O error */ { config_error("Read error from file '%s': %s", src, strerror(errno)); - cancel_copy(srcfd,destfd,dest); + cancel_copy(srcfd, destfd, dest); return 0; } @@ -1120,13 +1135,13 @@ void unreal_setfilemodtime(const char *filename, time_t mtime) FILETIME mTime; LONGLONG llValue; HANDLE hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL); + FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return; llValue = (mtime * 10000000LL) + 116444736000000000LL; mTime.dwLowDateTime = (long)llValue; mTime.dwHighDateTime = llValue >> 32; - + SetFileTime(hFile, &mTime, &mTime, &mTime); CloseHandle(hFile); #endif @@ -1147,7 +1162,7 @@ time_t unreal_getfilemodtime(const char *filename) ULARGE_INTEGER fullTime; time_t result; HANDLE hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL); + FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return 0; if (!GetFileTime(hFile, NULL, NULL, &cTime)) @@ -1163,8 +1178,8 @@ time_t unreal_getfilemodtime(const char *filename) fullTime.HighPart = cTime.dwHighDateTime; fullTime.QuadPart -= 116444736000000000; fullTime.QuadPart /= 10000000; - - return fullTime.LowPart; + + return fullTime.LowPart; #endif } @@ -1179,8 +1194,8 @@ int unreal_touch(const char *filename, time_t mtime) return 1; } -#ifndef AF_INET6 -#define AF_INET6 AF_MAX+1 /* just to let this compile */ +#ifndef AF_INET6 + #define AF_INET6 AF_MAX + 1 /* just to let this compile */ #endif /** Encode an IP string (eg: "1.2.3.4") to a BASE64 encoded value for S2S traffic */ @@ -1197,17 +1212,14 @@ const char *encode_ip(const char *ip) /* IPv6 (likely) */ inet_pton(AF_INET6, ip, addrbuf); /* hack for IPv4-in-IPv6 (::ffff:1.2.3.4) */ - if (addrbuf[0] == 0 && addrbuf[1] == 0 && addrbuf[2] == 0 && addrbuf[3] == 0 - && addrbuf[4] == 0 && addrbuf[5] == 0 && addrbuf[6] == 0 - && addrbuf[7] == 0 && addrbuf[8] == 0 && addrbuf[9] == 0 - && addrbuf[10] == 0xff && addrbuf[11] == 0xff) + if (addrbuf[0] == 0 && addrbuf[1] == 0 && addrbuf[2] == 0 && addrbuf[3] == 0 && addrbuf[4] == 0 && addrbuf[5] == 0 && addrbuf[6] == 0 && addrbuf[7] == 0 && addrbuf[8] == 0 && addrbuf[9] == 0 && addrbuf[10] == 0xff && addrbuf[11] == 0xff) { b64_encode(&addrbuf[12], sizeof(struct in_addr), retbuf, sizeof(retbuf)); - } else { + } else + { b64_encode(addrbuf, 16, retbuf, sizeof(retbuf)); } - } - else + } else { /* IPv4 */ inet_pton(AF_INET, ip, addrbuf); @@ -1235,15 +1247,15 @@ const char *decode_ip(const char *buf) /* IPv6 stuff */ #ifndef IN6ADDRSZ -#define IN6ADDRSZ 16 + #define IN6ADDRSZ 16 #endif #ifndef INT16SZ -#define INT16SZ 2 + #define INT16SZ 2 #endif #ifndef INADDRSZ -#define INADDRSZ 4 + #define INADDRSZ 4 #endif #ifdef _WIN32 @@ -1317,9 +1329,9 @@ const char *sock_strerror(int error) { static char unkerr[64]; int start = 0; - int stop = sizeof(WSAErrors)/sizeof(WSAErrors[0])-1; + int stop = sizeof(WSAErrors) / sizeof(WSAErrors[0]) - 1; int mid; - + if (!error) return "No error"; @@ -1332,14 +1344,14 @@ const char *sock_strerror(int error) */ while (start <= stop) { - mid = (start+stop)/2; + mid = (start + stop) / 2; if (WSAErrors[mid].error_code > error) - stop = mid-1; - + stop = mid - 1; + else if (WSAErrors[mid].error_code < error) - start = mid+1; + start = mid + 1; else - return WSAErrors[mid].error_string; + return WSAErrors[mid].error_string; } snprintf(unkerr, sizeof(unkerr), "Unknown Error: %d", error); return unkerr; @@ -1359,7 +1371,7 @@ void buildvarstring(const char *inbuf, char *outbuf, size_t len, const char *nam NameValuePrioList *list = NULL; int i; - for (i=0; name[i]; i++) + for (i = 0; name[i]; i++) add_nvplist(&list, 0, name[i], value[i]); buildvarstring_nvp(inbuf, outbuf, len, list, 0); @@ -1379,32 +1391,28 @@ char *xmlescape(const char *i, char *buf, int bufsize) strcpy(o, """); o += 6; bufsize -= 6; - } else - if (*i == '\'') + } else if (*i == '\'') { if (bufsize <= 6) break; strcpy(o, "'"); o += 6; bufsize -= 6; - } else - if (*i == '<') + } else if (*i == '<') { if (bufsize <= 4) break; strcpy(o, "<"); o += 4; bufsize -= 4; - } else - if (*i == '>') + } else if (*i == '>') { if (bufsize <= 4) break; strcpy(o, ">"); o += 4; bufsize -= 4; - } else - if (*i == '&') + } else if (*i == '&') { if (bufsize <= 5) break; @@ -1463,10 +1471,11 @@ void buildvarstring_nvp(const char *inbuf, char *outbuf, size_t len, NameValuePr i--; goto literal; } - + /* find termination */ - for (p=i; validvarcharacter(*p); p++); - + for (p = i; validvarcharacter(*p); p++) + ; + /* find variable name in list */ strlncpy(varname, i, sizeof(varname), p - i); n = find_nvplist(list, varname); @@ -1491,7 +1500,8 @@ void buildvarstring_nvp(const char *inbuf, char *outbuf, size_t len, NameValuePr o--; left++; } - } else { + } else + { strlcpy(o, output, left); left -= strlen(output); /* may become <0 */ if (left <= 0) @@ -1517,7 +1527,7 @@ void buildvarstring_nvp(const char *inbuf, char *outbuf, size_t len, NameValuePr i = p - 1; continue; } -literal: + literal: if (!left) break; *o++ = *i; @@ -1534,7 +1544,7 @@ const char *pcre2_version(void) static char buf[256]; strlcpy(buf, "PCRE2 ", sizeof(buf)); - pcre2_config(PCRE2_CONFIG_VERSION, buf+6); + pcre2_config(PCRE2_CONFIG_VERSION, buf + 6); return buf; } @@ -1545,19 +1555,19 @@ int gettimeofday(struct timeval *tp, void *tzp) { // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) // until 00:00:00 January 1, 1970 - static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); + static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); SYSTEMTIME system_time; FILETIME file_time; uint64_t time; - GetSystemTime( &system_time ); - SystemTimeToFileTime( &system_time, &file_time ); - time = ((uint64_t)file_time.dwLowDateTime ) ; + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + time = ((uint64_t)file_time.dwLowDateTime); time += ((uint64_t)file_time.dwHighDateTime) << 32; - tp->tv_sec = (long) ((time - EPOCH) / 10000000L); - tp->tv_usec = (long) (system_time.wMilliseconds * 1000); + tp->tv_sec = (long)((time - EPOCH) / 10000000L); + tp->tv_usec = (long)(system_time.wMilliseconds * 1000); return 0; } #endif @@ -1575,8 +1585,8 @@ int get_terminal_width(void) } #if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif /** Like strftime() but easier. */ @@ -1598,7 +1608,7 @@ char *unreal_strftime(const char *str) } #if defined(__GNUC__) -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif /** Convert a string to lowercase - with separate input/output buffer */ @@ -1662,7 +1672,7 @@ int str_ends_with_case_sensitive(const char *haystack, const char *needle) if (haystacklen < needlelen) return 0; - return !strncmp(haystack+haystacklen-needlelen, needle, needlelen) ? 1 : 0; + return !strncmp(haystack + haystacklen - needlelen, needle, needlelen) ? 1 : 0; } /** Checks if a string starts with a certain substring - case insensitive version. @@ -1682,5 +1692,5 @@ int str_ends_with_case_insensitive(const char *haystack, const char *needle) if (haystacklen < needlelen) return 0; - return !strncasecmp(haystack+haystacklen-needlelen, needle, needlelen) ? 1 : 0; + return !strncasecmp(haystack + haystacklen - needlelen, needle, needlelen) ? 1 : 0; } diff --git a/src/tls.c b/src/tls.c index 772914a39..ce62c2aef 100644 --- a/src/tls.c +++ b/src/tls.c @@ -26,20 +26,20 @@ #include "openssl_hostname_validation.h" #if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER) -#define OSSL_CONST const + #define OSSL_CONST const #else -#define OSSL_CONST + #define OSSL_CONST #endif #ifdef _WIN32 -#define IDC_PASS 1166 + #define IDC_PASS 1166 extern HINSTANCE hInst; extern HWND hwIRCDWnd; #endif -#define FUNC_TLS_READ 1 -#define FUNC_TLS_WRITE 2 -#define FUNC_TLS_ACCEPT 3 +#define FUNC_TLS_READ 1 +#define FUNC_TLS_WRITE 2 +#define FUNC_TLS_ACCEPT 3 #define FUNC_TLS_CONNECT 4 /* Forward declarations */ @@ -67,16 +67,18 @@ MODVAR int tls_client_index = 0; LRESULT TLS_key_passwd_dialog(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam) { static StreamIO *stream; - switch (Message) { + switch (Message) + { case WM_INITDIALOG: - stream = (StreamIO*)lParam; + stream = (StreamIO *)lParam; return TRUE; case WM_COMMAND: - if (LOWORD(wParam) == IDCANCEL) { + if (LOWORD(wParam) == IDCANCEL) + { *stream->buffer = NULL; EndDialog(hDlg, IDCANCEL); - } - else if (LOWORD(wParam) == IDOK) { + } else if (LOWORD(wParam) == IDOK) + { GetDlgItemText(hDlg, IDC_PASS, *stream->buffer, *stream->size); EndDialog(hDlg, IDOK); } @@ -88,7 +90,7 @@ LRESULT TLS_key_passwd_dialog(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lPa return FALSE; } } -#endif +#endif /** Return error string for OpenSSL error. * @param err OpenSSL error number to lookup @@ -100,7 +102,7 @@ const char *ssl_error_str(int err, int my_errno) static char ssl_errbuf[256]; char *ssl_errstr = NULL; - switch(err) + switch (err) { case SSL_ERROR_NONE: ssl_errstr = "OpenSSL: No error"; @@ -141,7 +143,7 @@ int TLS_key_passwd_cb(char *buf, int size, int rwflag, void *password) static char beforebuf[1024]; #ifdef _WIN32 StreamIO stream; - char passbuf[512]; + char passbuf[512]; int passsize = 512; #endif if (before) @@ -155,7 +157,7 @@ int TLS_key_passwd_cb(char *buf, int size, int rwflag, void *password) pass = passbuf; stream.buffer = &pass; stream.size = &passsize; - DialogBoxParam(hInst, "TLSKey", hwIRCDWnd, (DLGPROC)TLS_key_passwd_dialog, (LPARAM)&stream); + DialogBoxParam(hInst, "TLSKey", hwIRCDWnd, (DLGPROC)TLS_key_passwd_dialog, (LPARAM)&stream); #endif if (pass) { @@ -246,8 +248,7 @@ void disable_ssl_protocols(SSL_CTX *ctx, TLSOptions *tlsoptions) !(tlsoptions->protocols & TLS_PROTOCOL_TLSV1_1)) { SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION); - } else - if (!(tlsoptions->protocols & TLS_PROTOCOL_TLSV1)) + } else if (!(tlsoptions->protocols & TLS_PROTOCOL_TLSV1)) { SSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION); } else @@ -329,7 +330,7 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) * _verify_link() will take care of it only after we learned what server * we are dealing with (and if we should verify certificates for that server). */ - SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE | (tlsoptions->options & TLSFLAG_FAILIFNOCERT ? SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0), ssl_verify_callback); + SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | (tlsoptions->options & TLSFLAG_FAILIFNOCERT ? SSL_VERIFY_FAIL_IF_NO_PEER_CERT : 0), ssl_verify_callback); } SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF); #ifndef SSL_OP_NO_TICKET @@ -352,16 +353,16 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) { int saved_errno = errno; unreal_log(ULOG_ERROR, "config", "TLS_LOAD_FAILED", NULL, - "Could not open TLS certificate $filename: $system_error", - log_data_string("filename", n->name), - log_data_string("system_error", strerror(saved_errno))); + "Could not open TLS certificate $filename: $system_error", + log_data_string("filename", n->name), + log_data_string("system_error", strerror(saved_errno))); if (str_ends_with_case_sensitive(n->name, "tls/server.cert.pem")) { unreal_log(ULOG_ERROR, "config", "TLS_LOAD_FAILED_DEFAULT_CERT", NULL, - "It seems the default certificate is missing. " - "Run './unrealircd mkcert' " - "to generate a self-signed cert."); + "It seems the default certificate is missing. " + "Run './unrealircd mkcert' " + "to generate a self-signed cert."); } goto fail; } @@ -374,9 +375,9 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) { int saved_errno = errno; unreal_log(ULOG_ERROR, "config", "TLS_LOAD_FAILED", NULL, - "Could not open TLS key $filename: $system_error", - log_data_string("filename", n->name), - log_data_string("system_error", strerror(saved_errno))); + "Could not open TLS key $filename: $system_error", + log_data_string("filename", n->name), + log_data_string("system_error", strerror(saved_errno))); goto fail; } } @@ -398,39 +399,38 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) if (SSL_CTX_use_certificate_chain_file(ctx, n->name) <= 0) { unreal_log(ULOG_ERROR, "config", "TLS_LOAD_FAILED", NULL, - "Failed to load TLS certificate $filename\n$tls_error.all", - log_data_string("filename", n->name), - log_data_tls_error()); + "Failed to load TLS certificate $filename\n$tls_error.all", + log_data_string("filename", n->name), + log_data_tls_error()); goto fail; } if (SSL_CTX_use_PrivateKey_file(ctx, n2->name, SSL_FILETYPE_PEM) <= 0) { unreal_log(ULOG_ERROR, "config", "TLS_LOAD_FAILED", NULL, - "Failed to load TLS private key $filename\n$tls_error.all", - log_data_string("filename", n2->name), - log_data_tls_error()); + "Failed to load TLS private key $filename\n$tls_error.all", + log_data_string("filename", n2->name), + log_data_tls_error()); goto fail; } if (!SSL_CTX_check_private_key(ctx)) { unreal_log(ULOG_ERROR, "config", "TLS_LOAD_FAILED", NULL, - "Check for TLS private key(s) failed: " - "certificate $certificate_filename vs key $key_filename\n" - "$tls_error.all", - log_data_string("certificate_filename", n->name), - log_data_string("key_filename", n2->name), - log_data_tls_error()); + "Check for TLS private key(s) failed: " + "certificate $certificate_filename vs key $key_filename\n" + "$tls_error.all", + log_data_string("certificate_filename", n->name), + log_data_string("key_filename", n2->name), + log_data_tls_error()); /* An extra hint for dual cert as this mistake will likely happen * to some users and the OpenSSL error may be a bit too cryptic. */ if (tlsoptions->certificate_files->next) { unreal_log(ULOG_ERROR, "config", "TLS_LOAD_FAILED", NULL, - "HINT: You are using multiple 'certificate' and 'key' items. " - "Make sure each certificate/key pair belongs to each other, " - "they should be in the correct order! " - "E.g. certificate \"cert1\"; key \"key1\"; certificate \"cert2\"; key \"key2\";" - ); + "HINT: You are using multiple 'certificate' and 'key' items. " + "Make sure each certificate/key pair belongs to each other, " + "they should be in the correct order! " + "E.g. certificate \"cert1\"; key \"key1\"; certificate \"cert2\"; key \"key2\";"); } goto fail; } @@ -501,9 +501,9 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) if (!SSL_CTX_load_verify_locations(ctx, tlsoptions->trusted_ca_file, NULL)) { unreal_log(ULOG_ERROR, "config", "TLS_LOAD_FAILED", NULL, - "Failed to load trusted-ca-file $filename\n$tls_error.all", - log_data_string("filename", tlsoptions->trusted_ca_file), - log_data_tls_error()); + "Failed to load trusted-ca-file $filename\n$tls_error.all", + log_data_string("filename", tlsoptions->trusted_ca_file), + log_data_tls_error()); goto fail; } } @@ -529,7 +529,7 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) * Added in 2015 for safety. Seems OpenSSL was smart enough * to make this the default in 2016 after a security advisory. */ - SSL_CTX_set_options(ctx, SSL_OP_SINGLE_ECDH_USE|SSL_OP_SINGLE_DH_USE); + SSL_CTX_set_options(ctx, SSL_OP_SINGLE_ECDH_USE | SSL_OP_SINGLE_DH_USE); } #if defined(HAS_SSL_CTX_SET1_CURVES_LIST) || defined(HAS_SSL_CTX_SET1_GROUPS_LIST) @@ -544,15 +544,15 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) if (!unrealircd_set_tls_groups(ctx, UNREALIRCD_DEFAULT_TLS_GROUPS_TERTIARY)) { unreal_log(ULOG_ERROR, "config", "TLS_INVALID_TLS_GROUPS_LIST", NULL, - "Failed to set groups / ecdh-curves to either " - "'$tls_groups_primary', '$tls_groups_secondary' or '$tls_groups_tertiary'.\n" - "$tls_error.all\n" - "It's strange that none of the three worked. " - "Please report at https://bugs.unrealircd.org/ !", - log_data_string("tls_groups_primary", UNREALIRCD_DEFAULT_TLS_GROUPS_PRIMARY), - log_data_string("tls_groups_secondary", UNREALIRCD_DEFAULT_TLS_GROUPS_SECONDARY), - log_data_string("tls_groups_tertiary", UNREALIRCD_DEFAULT_TLS_GROUPS_TERTIARY), - log_data_tls_error()); + "Failed to set groups / ecdh-curves to either " + "'$tls_groups_primary', '$tls_groups_secondary' or '$tls_groups_tertiary'.\n" + "$tls_error.all\n" + "It's strange that none of the three worked. " + "Please report at https://bugs.unrealircd.org/ !", + log_data_string("tls_groups_primary", UNREALIRCD_DEFAULT_TLS_GROUPS_PRIMARY), + log_data_string("tls_groups_secondary", UNREALIRCD_DEFAULT_TLS_GROUPS_SECONDARY), + log_data_string("tls_groups_tertiary", UNREALIRCD_DEFAULT_TLS_GROUPS_TERTIARY), + log_data_tls_error()); goto fail; } } @@ -563,12 +563,12 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) if (!unrealircd_set_tls_groups(ctx, tlsoptions->groups)) { unreal_log(ULOG_ERROR, "config", "TLS_INVALID_TLS_GROUPS_LIST", NULL, - "Failed to set groups / ecdh-curves '$tls_groups'\n$tls_error.all\n" - "HINT: To get a list of supported names, run 'openssl ecparam -list_curves' on the server. " - "Separate multiple curves by colon, for example: " - "groups \"secp521r1:secp384r1\".", - log_data_string("tls_groups", tlsoptions->groups), - log_data_tls_error()); + "Failed to set groups / ecdh-curves '$tls_groups'\n$tls_error.all\n" + "HINT: To get a list of supported names, run 'openssl ecparam -list_curves' on the server. " + "Separate multiple curves by colon, for example: " + "groups \"secp521r1:secp384r1\".", + log_data_string("tls_groups", tlsoptions->groups), + log_data_tls_error()); goto fail; } } @@ -579,7 +579,7 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) * it here too than be sorry if someone screws up: */ unreal_log(ULOG_ERROR, "config", "BUG_TLS_GROUPS", NULL, - "tls groups / ecdh-curves specified but not supported by library -- BAD!"); + "tls groups / ecdh-curves specified but not supported by library -- BAD!"); goto fail; } #endif @@ -590,9 +590,9 @@ SSL_CTX *init_ctx(TLSOptions *tlsoptions, int server) if (!SSL_CTX_set1_sigalgs_list(ctx, tlsoptions->signature_algorithms)) { unreal_log(ULOG_ERROR, "config", "TLS_INVALID_TLS_SIGNATURE_ALGORITHMS", NULL, - "Failed to set signature-algorithms to '$signature_algorithms'.\n$tls_error.all", - log_data_string("signature_algorithms", tlsoptions->signature_algorithms), - log_data_tls_error()); + "Failed to set signature-algorithms to '$signature_algorithms'.\n$tls_error.all", + log_data_string("signature_algorithms", tlsoptions->signature_algorithms), + log_data_tls_error()); goto fail; } #else @@ -843,7 +843,7 @@ int reinit_tls(void) if (ctx_server) SSL_CTX_free(ctx_server); ctx_server = tmp; /* activate */ - + tmp = init_ctx(iConf.tls_options, 0); if (!tmp) { @@ -862,7 +862,7 @@ int reinit_tls(void) if (!tmp) { unreal_log(ULOG_ERROR, "config", "TLS_RELOAD_FAILED", NULL, - "TLS Reload failed at set::server-linking::tls-options. See previous errors."); + "TLS Reload failed at set::server-linking::tls-options. See previous errors."); return 0; } if (ctx_link_server) @@ -873,14 +873,13 @@ int reinit_tls(void) if (!tmp) { unreal_log(ULOG_ERROR, "config", "TLS_RELOAD_FAILED", NULL, - "TLS Reload failed at set::server-linking::tls-options (client). See previous errors."); + "TLS Reload failed at set::server-linking::tls-options (client). See previous errors."); return 0; } if (ctx_link_client) SSL_CTX_free(ctx_link_client); ctx_link_client = tmp; /* activate */ - } - else + } else { if (ctx_link_server) { @@ -903,7 +902,7 @@ int reinit_tls(void) if (!tmp) { unreal_log(ULOG_ERROR, "config", "TLS_RELOAD_FAILED", NULL, - "TLS Reload failed at listen::tls-options. See previous errors."); + "TLS Reload failed at listen::tls-options. See previous errors."); return 0; } if (listen->ssl_ctx) @@ -921,7 +920,7 @@ int reinit_tls(void) if (!tmp) { unreal_log(ULOG_ERROR, "config", "TLS_RELOAD_FAILED", NULL, - "TLS Reload failed at sni::tls-options. See previous errors."); + "TLS Reload failed at sni::tls-options. See previous errors."); return 0; } if (sni->ssl_ctx) @@ -939,8 +938,8 @@ int reinit_tls(void) if (!tmp) { unreal_log(ULOG_ERROR, "config", "TLS_RELOAD_FAILED", NULL, - "TLS Reload failed at link $servername due to outgoing::tls-options. See previous errors.", - log_data_string("servername", link->servername)); + "TLS Reload failed at link $servername due to outgoing::tls-options. See previous errors.", + log_data_string("servername", link->servername)); return 0; } if (link->ssl_ctx) @@ -955,8 +954,8 @@ int reinit_tls(void) /** Set SSL connection as nonblocking */ void SSL_set_nonblocking(SSL *s) { - BIO_set_nbio(SSL_get_rbio(s),1); - BIO_set_nbio(SSL_get_wbio(s),1); + BIO_set_nbio(SSL_get_rbio(s), 1); + BIO_set_nbio(SSL_get_wbio(s), 1); } /** Get TLS ciphersuite */ @@ -1080,7 +1079,7 @@ void unreal_tls_client_handshake(int fd, int revents, void *data) client->local->fd = -1; --OpenFiles; return; - case 0: + case 0: SetTLSConnectHandshake(client); return; case 1: @@ -1088,7 +1087,6 @@ void unreal_tls_client_handshake(int fd, int revents, void *data) default: return; } - } /** Called by I/O engine to (re)try accepting an TLS connection */ @@ -1108,14 +1106,14 @@ int unreal_tls_accept(Client *client, int fd) { char buf[1024]; int n; - + n = recv(fd, buf, sizeof(buf), MSG_PEEK); if ((n >= 8) && !strncmp(buf, "STARTTLS", 8)) { char buf[512]; snprintf(buf, sizeof(buf), - "ERROR :STARTTLS received but this is a TLS-only port. Check your connect settings. " - "If this is a server linking in then add 'tls' in your link::outgoing::options block.\r\n"); + "ERROR :STARTTLS received but this is a TLS-only port. Check your connect settings. " + "If this is a server linking in then add 'tls' in your link::outgoing::options block.\r\n"); (void)send(fd, buf, strlen(buf), 0); return fatal_tls_error(SSL_ERROR_SSL, FUNC_TLS_ACCEPT, ERRNO, client); } @@ -1123,7 +1121,7 @@ int unreal_tls_accept(Client *client, int fd) { char buf[512]; snprintf(buf, sizeof(buf), - "ERROR :NON-TLS command received on TLS-only port. Check your connection settings.\r\n"); + "ERROR :NON-TLS command received on TLS-only port. Check your connection settings.\r\n"); (void)send(fd, buf, strlen(buf), 0); return fatal_tls_error(SSL_ERROR_SSL, FUNC_TLS_ACCEPT, ERRNO, client); } @@ -1131,7 +1129,7 @@ int unreal_tls_accept(Client *client, int fd) { char buf[512]; snprintf(buf, sizeof(buf), - "ERROR :NON-TLS command received on TLS-only port. Check your connection settings.\r\n"); + "ERROR :NON-TLS command received on TLS-only port. Check your connection settings.\r\n"); (void)send(fd, buf, strlen(buf), 0); return fatal_tls_error(SSL_ERROR_SSL, FUNC_TLS_ACCEPT, ERRNO, client); } @@ -1184,7 +1182,7 @@ int unreal_tls_connect(Client *client, int fd) if ((ssl_err = SSL_connect(client->local->ssl)) <= 0) { ssl_err = SSL_get_error(client->local->ssl, ssl_err); - switch(ssl_err) + switch (ssl_err) { case SSL_ERROR_SYSCALL: if (ERRNO == P_EINTR || ERRNO == P_EWOULDBLOCK || ERRNO == P_EAGAIN) @@ -1192,7 +1190,7 @@ int unreal_tls_connect(Client *client, int fd) /* Hmmm. This implementation is different than in unreal_tls_accept(). * One of them must be wrong -- better check! (TODO) */ - fd_setselect(fd, FD_SELECT_READ|FD_SELECT_WRITE, unreal_tls_connect_retry, client); + fd_setselect(fd, FD_SELECT_READ | FD_SELECT_WRITE, unreal_tls_connect_retry, client); return 0; } return fatal_tls_error(ssl_err, FUNC_TLS_CONNECT, ERRNO, client); @@ -1223,7 +1221,7 @@ int SSL_smart_shutdown(SSL *ssl) char i; int rc = 0; - for(i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { if ((rc = SSL_shutdown(ssl))) break; @@ -1256,7 +1254,7 @@ static int fatal_tls_error(int ssl_error, int where, int my_errno, Client *clien if (IsDeadSocket(client)) return -1; - switch(where) + switch (where) { case FUNC_TLS_READ: ssl_func = "SSL_read()"; @@ -1280,7 +1278,8 @@ static int fatal_tls_error(int ssl_error, int where, int my_errno, Client *clien if (two && *two) { snprintf(additional_info, sizeof(additional_info), ": %s", two); - } else { + } else + { *additional_info = '\0'; } #else @@ -1290,7 +1289,8 @@ static int fatal_tls_error(int ssl_error, int where, int my_errno, Client *clien if (one && *one && two && *two) { snprintf(additional_info, sizeof(additional_info), ": %s: %s", one, two); - } else { + } else + { *additional_info = '\0'; } #endif @@ -1299,11 +1299,11 @@ static int fatal_tls_error(int ssl_error, int where, int my_errno, Client *clien SetDeadSocket(client); unreal_log(ULOG_DEBUG, "tls", "DEBUG_TLS_FATAL_ERROR", client, - "Exiting TLS client $client.details [port $port]: $tls_function: $tls_error_string: $tls_additional_info", - log_data_string("tls_function", ssl_func), - log_data_string("tls_error_string", ssl_errstr), - log_data_string("tls_additional_info", additional_info), - log_data_integer("port", client->local->listener ? client->local->listener->port : 0)); + "Exiting TLS client $client.details [port $port]: $tls_function: $tls_error_string: $tls_additional_info", + log_data_string("tls_function", ssl_func), + log_data_string("tls_error_string", ssl_errstr), + log_data_string("tls_additional_info", additional_info), + log_data_integer("port", client->local->listener ? client->local->listener->port : 0)); if (where == FUNC_TLS_CONNECT) @@ -1319,8 +1319,7 @@ static int fatal_tls_error(int ssl_error, int where, int my_errno, Client *clien } snprintf(buf, sizeof(buf), "%s: %s%s%s", ssl_func, ssl_errstr, additional_info, extra); lost_server_link(client, buf); - } else - if (IsServer(client) || (client->server && client->server->conf)) + } else if (IsServer(client) || (client->server && client->server->conf)) { /* Either a trusted fully established server (incoming) or an outgoing server link (established or not) */ snprintf(buf, sizeof(buf), "%s: %s%s", ssl_func, ssl_errstr, additional_info); @@ -1331,7 +1330,8 @@ static int fatal_tls_error(int ssl_error, int where, int my_errno, Client *clien { SET_ERRNO(errtmp); safe_strdup(client->local->error_str, strerror(errtmp)); - } else { + } else + { SET_ERRNO(P_EIO); safe_strdup(client->local->error_str, ssl_errstr); } @@ -1389,7 +1389,7 @@ TLSOptions *FindTLSOptionsForUser(Client *client) { ConfigItem_sni *sni; TLSOptions *sslopt = iConf.tls_options; /* default */ - + if (!MyConnect(client) || !IsSecure(client)) return NULL; @@ -1482,7 +1482,7 @@ int verify_certificate(SSL *ssl, const char *hostname, char **errstr) /* Certificate is verified but is issued for a different hostname */ snprintf(buf, sizeof(buf), "Certificate '%s' is not valid for hostname '%s'", - certificate_name(ssl), hostname); + certificate_name(ssl), hostname); verify_certificate_failed: if (errstr) *errstr = buf; @@ -1510,7 +1510,8 @@ const char *certificate_name(SSL *ssl) X509_NAME_oneline(n, buf, sizeof(buf)); X509_free(cert); return buf; - } else { + } else + { X509_free(cert); return NULL; } @@ -1546,20 +1547,17 @@ int cipher_check(SSL_CTX *ctx, char **errstr) snprintf(errbuf, sizeof(errbuf), "DES is enabled but is a weak cipher"); SSL_free(ssl); return 0; - } - else if (strstr(cipher, "3DES-")) + } else if (strstr(cipher, "3DES-")) { snprintf(errbuf, sizeof(errbuf), "3DES is enabled but is a weak cipher"); SSL_free(ssl); return 0; - } - else if (strstr(cipher, "RC4-")) + } else if (strstr(cipher, "RC4-")) { snprintf(errbuf, sizeof(errbuf), "RC4 is enabled but is a weak cipher"); SSL_free(ssl); return 0; - } - else if (strstr(cipher, "NULL-")) + } else if (strstr(cipher, "NULL-")) { snprintf(errbuf, sizeof(errbuf), "NULL cipher provides no encryption"); SSL_free(ssl); @@ -1721,7 +1719,7 @@ int outdated_tls_client(Client *client) for (name = strtoken(&p, buf, ","); name; name = strtoken(&p, NULL, ",")) { if (match_simple(name, client_protocol)) - return 1; /* outdated protocol */ + return 1; /* outdated protocol */ } strlcpy(buf, tlsoptions->outdated_ciphers, sizeof(buf)); @@ -1795,14 +1793,14 @@ int check_certificate_expiry_ctx(SSL_CTX *ctx, char **errstr) *errstr = errbuf; return 1; } else - /* or near-expiry? */ - if (((days_expiry < 0) || (seconds_expiry < 0)) && (days_expiry > -7)) - { - snprintf(errbuf, sizeof(errbuf), "certificate will expire in %s", pretty_time_val(0 - duration)); - SSL_free(ssl); - *errstr = errbuf; - return 1; - } + /* or near-expiry? */ + if (((days_expiry < 0) || (seconds_expiry < 0)) && (days_expiry > -7)) + { + snprintf(errbuf, sizeof(errbuf), "certificate will expire in %s", pretty_time_val(0 - duration)); + SSL_free(ssl); + *errstr = errbuf; + return 1; + } /* All good */ SSL_free(ssl); @@ -1878,7 +1876,7 @@ SSL_CTX *https_new_ctx(void) #ifdef HAS_SSL_CTX_SET_MIN_PROTO_VERSION SSL_CTX_set_min_proto_version(ctx_client, TLS1_2_VERSION); #endif - SSL_CTX_set_options(ctx_client, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1|SSL_OP_NO_TLSv1_1); + SSL_CTX_set_options(ctx_client, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1); /* Verify peer certificate */ snprintf(buf1, sizeof(buf1), "%s/tls/curl-ca-bundle.crt", CONFDIR); @@ -1886,9 +1884,9 @@ SSL_CTX *https_new_ctx(void) { #ifdef _WIN32 unreal_log(ULOG_ERROR, "url", "CA_BUNDLE_NOT_FOUND", NULL, - "File $filename1 does not exist.\n" - "Cannot use built-in https client without curl-ca-bundle.crt\n", - log_data_string("filename1", buf1)); + "File $filename1 does not exist.\n" + "Cannot use built-in https client without curl-ca-bundle.crt\n", + log_data_string("filename1", buf1)); exit(-1); #else snprintf(buf2, sizeof(buf2), "%s/doc/conf/tls/curl-ca-bundle.crt", BUILDDIR); diff --git a/src/unrealdb.c b/src/unrealdb.c index 8ee706fa3..15b9ccafa 100644 --- a/src/unrealdb.c +++ b/src/unrealdb.c @@ -51,24 +51,24 @@ #define UNREALDB_WRITE_V1 /* If a key is specified, it must be this size */ -#define UNREALDB_KEY_LEN crypto_secretstream_xchacha20poly1305_KEYBYTES +#define UNREALDB_KEY_LEN crypto_secretstream_xchacha20poly1305_KEYBYTES /** Default 'time cost' for Argon2id */ -#define UNREALDB_ARGON2_DEFAULT_TIME_COST 4 +#define UNREALDB_ARGON2_DEFAULT_TIME_COST 4 /** Default 'memory cost' for Argon2id. Note that 15 means 1<<15=32M */ -#define UNREALDB_ARGON2_DEFAULT_MEMORY_COST 15 +#define UNREALDB_ARGON2_DEFAULT_MEMORY_COST 15 /** Default 'parallelism cost' for Argon2id. */ -#define UNREALDB_ARGON2_DEFAULT_PARALLELISM_COST 2 +#define UNREALDB_ARGON2_DEFAULT_PARALLELISM_COST 2 #ifdef _WIN32 /* Ignore this warning on Windows as it is a false positive */ -#pragma warning(disable : 6029) + #pragma warning(disable : 6029) #endif /* Forward declarations - only used for internal (static) functions, of course */ static SecretCache *find_secret_cache(Secret *secr, UnrealDBConfig *cfg); static void unrealdb_add_to_secret_cache(Secret *secr, UnrealDBConfig *cfg); -static void unrealdb_set_error(UnrealDB *c, UnrealDBError errcode, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,3,4))); +static void unrealdb_set_error(UnrealDB *c, UnrealDBError errcode, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 3, 4))); UnrealDBError unrealdb_last_error_code; static char *unrealdb_last_error_string = NULL; @@ -112,11 +112,11 @@ static int unrealdb_kdf(UnrealDB *c, Secret *secr) } /* Need to run argon2 to generate key */ if (argon2id_hash_raw(c->config->t_cost, - 1 << c->config->m_cost, - c->config->p_cost, - secr->password, strlen(secr->password), - c->config->salt, c->config->saltlen, - c->config->key, c->config->keylen) != ARGON2_OK) + 1 << c->config->m_cost, + c->config->p_cost, + secr->password, strlen(secr->password), + c->config->salt, c->config->saltlen, + c->config->key, c->config->keylen) != ARGON2_OK) { /* out of memory or some other very unusual error */ unrealdb_set_error(c, UNREALDB_ERROR_INTERNAL, "Could not generate argon2 hash - out of memory or something weird?"); @@ -164,7 +164,7 @@ UnrealDB *unrealdb_open(const char *filename, UnrealDBMode mode, char *secret_bl UnrealDB *c = safe_alloc_sensitive(sizeof(UnrealDB)); char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES]; char buf[32]; /* don't change this */ - Secret *secr=NULL; + Secret *secr = NULL; SecretCache *dbcache; int cached = 0; char *err; @@ -216,8 +216,7 @@ UnrealDB *unrealdb_open(const char *filename, UnrealDBMode mode, char *secret_bl { unrealdb_set_error(c, UNREALDB_ERROR_CRYPTED, "file is encrypted but no password provided"); goto unrealdb_open_fail; - } else - if (!strcmp(buf, "UnrealIRCd-DB-v1")) + } else if (!strcmp(buf, "UnrealIRCd-DB-v1")) { /* Skip over the 32 byte header, directly to the creationtime */ if (fseek(c->fd, 32L, SEEK_SET) < 0) @@ -231,14 +230,13 @@ UnrealDB *unrealdb_open(const char *filename, UnrealDBMode mode, char *secret_bl goto unrealdb_open_fail; } /* SUCCESS = fallthrough */ - } else - if (str_starts_with_case_sensitive(buf, "UnrealIRCd-DB")) /* any other version than v1 = not supported by us */ + } else if (str_starts_with_case_sensitive(buf, "UnrealIRCd-DB")) /* any other version than v1 = not supported by us */ { /* We don't support this format, so refuse clearly */ unrealdb_set_error(c, UNREALDB_ERROR_HEADER, - "Unsupported version of database. Is this database perhaps created on " - "a new version of UnrealIRCd and are you trying to use it on an older " - "UnrealIRCd version? (Downgrading is not supported!)"); + "Unsupported version of database. Is this database perhaps created on " + "a new version of UnrealIRCd and are you trying to use it on an older " + "UnrealIRCd version? (Downgrading is not supported!)"); goto unrealdb_open_fail; } else { @@ -247,7 +245,8 @@ UnrealDB *unrealdb_open(const char *filename, UnrealDBMode mode, char *secret_bl /* SUCCESS = fallthrough */ } } - } else { + } else + { #ifdef UNREALDB_WRITE_V1 /* WRITE */ memset(buf, 0, sizeof(buf)); @@ -287,7 +286,8 @@ UnrealDB *unrealdb_open(const char *filename, UnrealDBMode mode, char *secret_bl /* Use first found cached config for this secret */ c->config = unrealdb_copy_config(secr->cache->config); cached = 1; - } else { + } else + { /* Create a new config */ c->config = safe_alloc(sizeof(UnrealDBConfig)); c->config->kdf = UNREALDB_KDF_ARGON2ID; @@ -318,7 +318,7 @@ UnrealDB *unrealdb_open(const char *filename, UnrealDBMode mode, char *secret_bl unrealdb_set_error(c, UNREALDB_ERROR_IO, "Unable to write header (2)"); goto unrealdb_open_fail; } - + if (cached) { #ifdef DEBUGMODE @@ -357,7 +357,7 @@ UnrealDB *unrealdb_open(const char *filename, UnrealDBMode mode, char *secret_bl } else { char *validate = NULL; - + /* Read file header */ if (fread(buf, 1, sizeof(buf), c->fd) != sizeof(buf)) { @@ -379,7 +379,7 @@ UnrealDB *unrealdb_open(const char *filename, UnrealDBMode mode, char *secret_bl unrealdb_set_error(c, UNREALDB_ERROR_HEADER, "Header is corrupt/unknown/invalid"); goto unrealdb_open_fail; } - if (c->config->kdf != UNREALDB_KDF_ARGON2ID) + if (c->config->kdf != UNREALDB_KDF_ARGON2ID) { unrealdb_set_error(c, UNREALDB_ERROR_HEADER, "Header contains unknown KDF 0x%x", (int)c->config->kdf); goto unrealdb_open_fail; @@ -423,7 +423,8 @@ UnrealDB *unrealdb_open(const char *filename, UnrealDBMode mode, char *secret_bl "Cache hit for '$secret_block' while reading", log_data_string("secret_block", secr->name)); #endif - } else { + } else + { #ifdef DEBUGMODE unreal_log(ULOG_DEBUG, "unrealdb", "DEBUG_UNREALDB_CACHE_MISS", NULL, "Cache miss for '$secret_block' while reading, need to run argon2", @@ -542,13 +543,13 @@ char *unrealdb_test_db(const char *filename, char *secret_block) if (unrealdb_get_error_code() == UNREALDB_ERROR_PASSWORD) { snprintf(buf, sizeof(buf), "Incorrect password specified in secret block '%s' for file %s", - secret_block, filename); + secret_block, filename); return buf; } if (unrealdb_get_error_code() == UNREALDB_ERROR_CRYPTED) { snprintf(buf, sizeof(buf), "File '%s' is encrypted but no secret block provided for it", - filename); + filename); return buf; } return NULL; @@ -597,7 +598,8 @@ static int unrealdb_write(UnrealDB *c, const void *wbuf, int len) return 1; } - do { + do + { if (c->buflen + len < UNREALDB_CRYPT_FILE_CHUNK_SIZE) { /* New data fits in new buffer. Then we are done with writing. @@ -633,7 +635,7 @@ static int unrealdb_write(UnrealDB *c, const void *wbuf, int len) } /* Buffer is now flushed for sure */ c->buflen = 0; - } while(len > 0); + } while (len > 0); return 1; } @@ -663,12 +665,13 @@ int unrealdb_write_str(UnrealDB *c, const char *x) if (stringlen >= 0xffff) { unrealdb_set_error(c, UNREALDB_ERROR_API, - "unrealdb_write_str(): string has length %d, while maximum allowed is 65534", - stringlen); + "unrealdb_write_str(): string has length %d, while maximum allowed is 65534", + stringlen); return 0; } len = stringlen; - } else { + } else + { len = 0xffff; } @@ -771,7 +774,7 @@ static int unrealdb_read(UnrealDB *c, void *rbuf, int len) if (rlen < len) { unrealdb_set_error(c, UNREALDB_ERROR_IO, "Short read - premature end of file (want:%d, got:%d bytes)", - len, (int)rlen); + len, (int)rlen); return 0; } return 1; @@ -795,7 +798,8 @@ static int unrealdb_read(UnrealDB *c, void *rbuf, int len) abort(); /* If we get here then we need to read some data */ - do { + do + { rlen = fread(buf_in, 1, sizeof(buf_in), c->fd); if (rlen == 0) { @@ -818,15 +822,16 @@ static int unrealdb_read(UnrealDB *c, void *rbuf, int len) memcpy(buf, c->buf, out_len); buf += out_len; len -= out_len; - } else { + } else + { /* This is the only (or last) block we need, we are satisfied */ memcpy(buf, c->buf, len); c->buflen = out_len - len; if (c->buflen > 0) - memmove(c->buf, c->buf+len, c->buflen); + memmove(c->buf, c->buf + len, c->buflen); return 1; /* Done */ } - } while(!feof(c->fd)); + } while (!feof(c->fd)); unrealdb_set_error(c, UNREALDB_ERROR_IO, "Short read - premature end of file?"); return 0; @@ -994,7 +999,7 @@ void unrealdb_test_simple(void) fprintf(stderr, "All good.\n"); } -#define UNREALDB_SPEED_TEST_BYTES 100000000 + #define UNREALDB_SPEED_TEST_BYTES 100000000 void unrealdb_test_speed(char *key) { UnrealDB *c; @@ -1149,9 +1154,9 @@ static void unrealdb_add_to_secret_cache(Secret *secr, UnrealDBConfig *cfg) } #ifdef DEBUGMODE -#define UNREALDB_EXPIRE_SECRET_CACHE_AFTER 1200 + #define UNREALDB_EXPIRE_SECRET_CACHE_AFTER 1200 #else -#define UNREALDB_EXPIRE_SECRET_CACHE_AFTER 86400 + #define UNREALDB_EXPIRE_SECRET_CACHE_AFTER 86400 #endif /** Expire cached secret entries (previous Argon2 runs) */ diff --git a/src/unrealircdctl.c b/src/unrealircdctl.c index 5c1547ec1..43d8ddd4d 100644 --- a/src/unrealircdctl.c +++ b/src/unrealircdctl.c @@ -45,7 +45,8 @@ void unrealircdctl_usage(const char *program_name) "mkpasswd - Hash a password\n" "gencloak - Display 3 random cloak keys\n" "spkifp - Display SPKI Fingerprint\n" - "\n", program_name); + "\n", + program_name); exit(-1); } @@ -100,7 +101,8 @@ void unrealircdctl_mkpasswd(int argc, char *argv[]) if (type == -1) { type = AUTHTYPE_ARGON2; - } else { + } else + { p = argv[3]; } if (BadPtr(p)) @@ -119,7 +121,8 @@ void unrealircdctl_mkpasswd(int argc, char *argv[]) "You are suggested to use the 'argon2' algorithm instead."); p[8] = '\0'; } - if (!(result = Auth_Hash(type, p))) { + if (!(result = Auth_Hash(type, p))) + { printf("Failed to generate password. Deprecated method? Try 'argon2' instead.\n"); exit(0); } @@ -129,7 +132,7 @@ void unrealircdctl_mkpasswd(int argc, char *argv[]) void unrealircdctl_gencloak(int argc, char *argv[]) { - #define GENERATE_CLOAKKEY_LEN 80 /* Length of cloak keys to generate. */ +#define GENERATE_CLOAKKEY_LEN 80 /* Length of cloak keys to generate. */ char keyBuf[GENERATE_CLOAKKEY_LEN + 1]; int keyNum; int charIndex; @@ -147,7 +150,7 @@ void unrealircdctl_gencloak(int argc, char *argv[]) has_lower = 0; has_num = 0; - for (charIndex = 0; charIndex < sizeof(keyBuf)-1; ++charIndex) + for (charIndex = 0; charIndex < sizeof(keyBuf) - 1; ++charIndex) { switch (getrandom8() % 3) { @@ -165,7 +168,7 @@ void unrealircdctl_gencloak(int argc, char *argv[]) break; } } - keyBuf[sizeof(keyBuf)-1] = '\0'; + keyBuf[sizeof(keyBuf) - 1] = '\0'; if (has_upper && has_lower && has_num) printf("\t\t\"%s\";\n", keyBuf); @@ -243,11 +246,11 @@ int main(int argc, char *argv[]) chdir(".."); /* go up one level from "bin" */ init_winsock(); #else -#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) + #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) alarm(60); /* 60 seconds timeout - ASan can be slow... */ -#else + #else alarm(20); /* 20 seconds timeout */ -#endif + #endif #endif dbuf_init(); init_random(); diff --git a/src/url_curl.c b/src/url_curl.c index 44d225def..fb02e27d6 100644 --- a/src/url_curl.c +++ b/src/url_curl.c @@ -29,13 +29,12 @@ extern char *TLSKeyPasswd; */ typedef struct Download Download; -struct Download -{ +struct Download { Download *prev, *next; OutgoingWebRequest *request; struct curl_slist *request_headers_curl; char errorbuf[CURL_ERROR_SIZE]; - FILE *file_fd; /**< File open for writing (otherwise NULL) */ + FILE *file_fd; /**< File open for writing (otherwise NULL) */ char *filename; char *memory_data; /**< Memory for writing response (otherwise NULL) */ long long memory_data_len; /**< Size of memory_data */ @@ -203,7 +202,7 @@ static size_t do_download_memory(void *ptr, size_t size, size_t nmemb, void *str if (size_required >= handle->memory_data_allocated - 1) // the -1 is for zero termination, even though it is binary.. { - long long newsize = ((size_required / URL_MEMORY_BACKED_CHUNK_SIZE)+1)*URL_MEMORY_BACKED_CHUNK_SIZE; + long long newsize = ((size_required / URL_MEMORY_BACKED_CHUNK_SIZE) + 1) * URL_MEMORY_BACKED_CHUNK_SIZE; char *newptr = realloc(handle->memory_data, newsize); if (!newptr) { @@ -249,7 +248,7 @@ static void url_check_multi_handles(void) CURL *easyhand = msg->easy_handle; curl_easy_getinfo(easyhand, CURLINFO_RESPONSE_CODE, &code); - curl_easy_getinfo(easyhand, CURLINFO_PRIVATE, (char **) &handle); + curl_easy_getinfo(easyhand, CURLINFO_PRIVATE, (char **)&handle); curl_easy_getinfo(easyhand, CURLINFO_FILETIME, &last_mod); if (handle->file_fd) { @@ -262,16 +261,14 @@ static void url_check_multi_handles(void) if (code == 304 || (last_mod != -1 && last_mod <= handle->request->cachetime)) { url_callback(handle->request, NULL, handle->memory_data, handle->memory_data_len, NULL, 1, handle->request->callback_data); - } - else + } else { if ((last_mod != -1) && handle->filename) unreal_setfilemodtime(handle->filename, last_mod); url_callback(handle->request, handle->filename, handle->memory_data, handle->memory_data_len, NULL, 0, handle->request->callback_data); } - } - else + } else { char capbuf[128]; const char *err = handle->errorbuf; @@ -319,8 +316,7 @@ static int url_socket_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *so if (what == CURL_POLL_REMOVE) { fd_close(s); - } - else + } else { FDEntry *fde = &fd_table[s]; int flags = 0; @@ -426,11 +422,12 @@ void url_start_async(OutgoingWebRequest *request) { curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, do_download_file); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)handle); - } else { + } else + { curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, do_download_memory); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)handle); handle->memory_data_allocated = URL_MEMORY_BACKED_CHUNK_SIZE; - handle->memory_data = safe_alloc(URL_MEMORY_BACKED_CHUNK_SIZE+1); + handle->memory_data = safe_alloc(URL_MEMORY_BACKED_CHUNK_SIZE + 1); } if (handle->request->http_method == HTTP_METHOD_POST) { diff --git a/src/url_unreal.c b/src/url_unreal.c index ddb45a538..1135f9b1f 100644 --- a/src/url_unreal.c +++ b/src/url_unreal.c @@ -33,7 +33,7 @@ * and perhaps by then it is long enough that we don't need the fallback to older * functions. */ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif /* Maximum length of a single chunked-transfer chunk header @@ -44,7 +44,7 @@ * LF so a server that streams a chunk header with no LF cannot * grow handle->lefttoparse without bound. */ -#define HTTPS_MAX_CHUNK_HEADER_LEN 256 +#define HTTPS_MAX_CHUNK_HEADER_LEN 256 /* Structs */ @@ -54,27 +54,26 @@ */ typedef struct Download Download; -struct Download -{ +struct Download { Download *prev, *next; OutgoingWebRequest *request; - FILE *file_fd; /**< File open for writing (otherwise NULL) */ + FILE *file_fd; /**< File open for writing (otherwise NULL) */ char *filename; char *memory_data; /**< Memory for writing response (otherwise NULL) */ long long memory_data_len; /**< Size of memory_data */ long long memory_data_allocated; /**< Total allocated memory for 'memory_data' */ long long bytes_written_to_file; /**< Bytes written to file_fd so far (for max_size cap) */ char errorbuf[512]; - char *hostname; /**< Parsed hostname (from 'url') */ - int port; /**< Parsed port (from 'url') */ + char *hostname; /**< Parsed hostname (from 'url') */ + int port; /**< Parsed port (from 'url') */ char *username; char *password; - char *document; /**< Parsed document (from 'url') */ - char *ip4; /**< Resolved IP (IPv4) */ - char *ip6; /**< Resolved IP (IPv6) */ - SocketType socket_type; /**< Socket type that we are trying (SOCKET_TYPE_IPV4 or SOCKET_TYPE_IPV6) */ + char *document; /**< Parsed document (from 'url') */ + char *ip4; /**< Resolved IP (IPv4) */ + char *ip6; /**< Resolved IP (IPv6) */ + SocketType socket_type; /**< Socket type that we are trying (SOCKET_TYPE_IPV4 or SOCKET_TYPE_IPV6) */ SSL *ssl; - int fd; /**< Socket */ + int fd; /**< Socket */ int connected; int got_response; int http_status_code; @@ -108,7 +107,7 @@ void https_done_cached(Download *handle); void https_redirect(Download *handle); int https_parse_header(char *buffer, int len, char **key, char **value, char **lastloc, int *end_of_request); char *url_find_end_of_request(char *header, int totalsize, int *remaining_bytes); -int https_cancel(Download *handle, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf,2,3))); +int https_cancel(Download *handle, FORMAT_STRING(const char *pattern), ...) __attribute__((format(printf, 2, 3))); void url_free_handle(Download *handle) { @@ -231,7 +230,8 @@ void url_start_async(OutgoingWebRequest *request) safe_strdup(handle->filename, tmp); safe_free(file); - } else { + } else + { handle->memory_data_allocated = URL_MEMORY_BACKED_CHUNK_SIZE; handle->memory_data = safe_alloc(URL_MEMORY_BACKED_CHUNK_SIZE); } @@ -244,7 +244,8 @@ void url_start_async(OutgoingWebRequest *request) else safe_strdup(handle->ip4, handle->hostname); unreal_https_initiate_connect(handle); - } else { + } else + { /* Hostname, so start resolving... */ handle->dns_refcnt += 2; ares_gethostbyname(resolver_channel_https, handle->hostname, AF_INET, url_resolve_cb, handle); @@ -257,7 +258,7 @@ void url_resolve_cb(void *arg, int status, int timeouts, struct hostent *he) Download *handle = (Download *)arg; int n; struct hostent *he2; - char ipbuf[HOSTLEN+1]; + char ipbuf[HOSTLEN + 1]; const char *ip = NULL; handle->dns_refcnt--; @@ -286,8 +287,7 @@ void url_resolve_cb(void *arg, int status, int timeouts, struct hostent *he) safe_strdup(handle->ip6, ip); else safe_strdup(handle->ip4, ip); - } else - if ((handle->dns_refcnt == 0) && !handle->ip4 && !handle->ip6) + } else if ((handle->dns_refcnt == 0) && !handle->ip4 && !handle->ip6) { https_cancel(handle, "Unable to resolve hostname '%s'", handle->hostname); return; @@ -366,7 +366,8 @@ void unreal_https_connect_handshake(int fd, int revents, void *data) handle->socket_type = SOCKET_TYPE_IPV6; unreal_https_initiate_connect(handle); return; - } else { + } else + { /* Fatal error */ https_cancel(handle, "Connect failed: %s", STRERROR(sockerr)); return; @@ -415,7 +416,7 @@ int https_connect(Download *handle) if ((ssl_err = SSL_connect(handle->ssl)) <= 0) { ssl_err = SSL_get_error(handle->ssl, ssl_err); - switch(ssl_err) + switch (ssl_err) { case SSL_ERROR_SYSCALL: if (ERRNO == P_EINTR || ERRNO == P_EWOULDBLOCK || ERRNO == P_EAGAIN) @@ -423,7 +424,7 @@ int https_connect(Download *handle) /* Hmmm. This implementation is different than in unreal_tls_accept(). * One of them must be wrong -- better check! (TODO) */ - fd_setselect(handle->fd, FD_SELECT_READ|FD_SELECT_WRITE, https_connect_retry, handle); + fd_setselect(handle->fd, FD_SELECT_READ | FD_SELECT_WRITE, https_connect_retry, handle); return 0; } return https_fatal_tls_error(ssl_err, ERRNO, handle); @@ -472,7 +473,8 @@ int https_fatal_tls_error(int ssl_error, int my_errno, Download *handle) if (two && *two) { snprintf(additional_info, sizeof(additional_info), ": %s", two); - } else { + } else + { *additional_info = '\0'; } #else @@ -482,7 +484,8 @@ int https_fatal_tls_error(int ssl_error, int my_errno, Download *handle) if (one && *one && two && *two) { snprintf(additional_info, sizeof(additional_info), ": %s: %s", one, two); - } else { + } else + { *additional_info = '\0'; } #endif @@ -566,40 +569,40 @@ int https_connect_send_header(Download *handle) if (handle->request->http_method == HTTP_METHOD_GET) { snprintf(buf, sizeof(buf), "GET %s HTTP/1.1\r\n" - "User-Agent: UnrealIRCd %s\r\n" - "Host: %s\r\n" - "Connection: close\r\n", - handle->document, - VERSIONONLY, - hostandport); - } else - if (handle->request->http_method == HTTP_METHOD_POST) + "User-Agent: UnrealIRCd %s\r\n" + "Host: %s\r\n" + "Connection: close\r\n", + handle->document, + VERSIONONLY, + hostandport); + } else if (handle->request->http_method == HTTP_METHOD_POST) { if (!handle->request->body || !strlen(handle->request->body)) { snprintf(buf, sizeof(buf), "POST %s HTTP/1.1\r\n" - "User-Agent: UnrealIRCd %s\r\n" - "Host: %s\r\n" - "Connection: close\r\n", - handle->document, - VERSIONONLY, - hostandport); - } else { + "User-Agent: UnrealIRCd %s\r\n" + "Host: %s\r\n" + "Connection: close\r\n", + handle->document, + VERSIONONLY, + hostandport); + } else + { char add_default_content_type = 0; if (!find_nvplist(handle->request->headers, "Content-Type")) add_default_content_type = 1; snprintf(buf, sizeof(buf), "POST %s HTTP/1.1\r\n" - "User-Agent: UnrealIRCd %s\r\n" - "Host: %s\r\n" - "%s" - "Content-Length: %ld\r\n" - "Connection: close\r\n", - handle->document, - VERSIONONLY, - hostandport, - add_default_content_type ? "Content-Type: application/x-www-form-urlencoded\r\n" : "", - (long)strlen(handle->request->body)); + "User-Agent: UnrealIRCd %s\r\n" + "Host: %s\r\n" + "%s" + "Content-Length: %ld\r\n" + "Connection: close\r\n", + handle->document, + VERSIONONLY, + hostandport, + add_default_content_type ? "Content-Type: application/x-www-form-urlencoded\r\n" : "", + (long)strlen(handle->request->body)); } } else abort(); @@ -610,7 +613,7 @@ int https_connect_send_header(Download *handle) char header[512]; snprintf(wbuf, sizeof(wbuf), "%s:%s", handle->username, handle->password); - if (b64_encode(wbuf, strlen(wbuf), obuf, sizeof(obuf)-1) > 0) + if (b64_encode(wbuf, strlen(wbuf), obuf, sizeof(obuf) - 1) > 0) { snprintf(header, sizeof(header), "Authorization: Basic %s\r\n", obuf); strlcat(buf, header, sizeof(buf)); @@ -622,8 +625,8 @@ int https_connect_send_header(Download *handle) if (datestr) { // snprintf_append... - snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), - "If-Modified-Since: %s\r\n", datestr); + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), + "If-Modified-Since: %s\r\n", datestr); } } if (handle->request->headers) @@ -637,7 +640,7 @@ int https_connect_send_header(Download *handle) snprintf(nbuf, sizeof(nbuf), "%s: %s\r\n", n->name, n->value); else snprintf(nbuf, sizeof(nbuf), "%s:\r\n", n->name); - if (strlen(buf)+strlen(nbuf) > sizeof(buf)-8) + if (strlen(buf) + strlen(nbuf) > sizeof(buf) - 8) break; strlcat(buf, nbuf, sizeof(buf)); } @@ -660,7 +663,7 @@ void https_receive_response(int fd, int revents, void *data) int n; char readbuf[2048]; - n = SSL_read(handle->ssl, readbuf, sizeof(readbuf)-1); + n = SSL_read(handle->ssl, readbuf, sizeof(readbuf) - 1); if (n == 0) { /* Graceful close */ @@ -695,8 +698,7 @@ void https_receive_response(int fd, int revents, void *data) { https_handle_response_header(handle, readbuf, n); return; - } else - if (handle->got_response) + } else if (handle->got_response) { if (!https_handle_response_body(handle, readbuf, n)) return; /* handle is already freed! */ @@ -710,7 +712,7 @@ int https_handle_response_header(Download *handle, char *readbuf, int n) int r, end_of_request; char netbuf[4096], netbuf2[4096]; char *lastloc = NULL; - int maxcopy, nprefix=0; + int maxcopy, nprefix = 0; int totalsize; /* Yeah, totally paranoid: */ @@ -735,10 +737,10 @@ int https_handle_response_header(Download *handle, char *readbuf, int n) https_cancel(handle, "Oversized line in HTTP response"); return 0; } - memcpy(netbuf+nprefix, readbuf, n); /* SAFE: see checking above */ + memcpy(netbuf + nprefix, readbuf, n); /* SAFE: see checking above */ totalsize = n + nprefix; netbuf[totalsize] = '\0'; - memcpy(netbuf2, netbuf, totalsize+1); // copy, including the "always present \0 at the end just in case we use strstr etc". + memcpy(netbuf2, netbuf, totalsize + 1); // copy, including the "always present \0 at the end just in case we use strstr etc". safe_free(handle->lefttoparse); /** Now step through the lines.. **/ @@ -755,8 +757,7 @@ int https_handle_response_header(Download *handle, char *readbuf, int n) /* 304 Not Modified: cache hit */ https_done_cached(handle); return 0; - } - else if ((handle->http_status_code >= 301) && (handle->http_status_code <= 308)) + } else if ((handle->http_status_code >= 301) && (handle->http_status_code <= 308)) { /* Redirect */ if (handle->request->max_redirects == 0) @@ -767,23 +768,19 @@ int https_handle_response_header(Download *handle, char *readbuf, int n) /* Let it continue.. we handle it later, as we need to * receive the "Location" header as well. */ - } - else if (handle->http_status_code != 200) + } else if (handle->http_status_code != 200) { /* HTTP Failure code */ https_cancel(handle, "HTTP Error: %s", value); return 0; } - } else - if (!strcasecmp(key, "Last-Modified") && value) + } else if (!strcasecmp(key, "Last-Modified") && value) { handle->last_modified = rfc2616_time_to_unix_time(value); - } else - if (!strcasecmp(key, "Location") && value) + } else if (!strcasecmp(key, "Location") && value) { safe_strdup(handle->redirect_new_location, value); - } else - if (!strcasecmp(key, "Transfer-Encoding") && value) + } else if (!strcasecmp(key, "Transfer-Encoding") && value) { if (value && !strcasecmp(value, "chunked")) handle->transfer_encoding = TRANSFER_ENCODING_CHUNKED; @@ -810,7 +807,8 @@ int https_handle_response_header(Download *handle, char *readbuf, int n) { https_redirect(handle); return 0; /* this old request dies */ - } else { + } else + { https_cancel(handle, "HTTP Redirect encountered but no URL specified!?"); return 0; } @@ -848,7 +846,7 @@ long long https_handle_response_body_memory(Download *handle, const char *ptr, l if (size_required >= handle->memory_data_allocated - 1) // the -1 is for zero termination, even though it is binary.. { - long long newsize = ((size_required / URL_MEMORY_BACKED_CHUNK_SIZE)+1)*URL_MEMORY_BACKED_CHUNK_SIZE; + long long newsize = ((size_required / URL_MEMORY_BACKED_CHUNK_SIZE) + 1) * URL_MEMORY_BACKED_CHUNK_SIZE; char *newptr = realloc(handle->memory_data, newsize); if (!newptr) { @@ -890,8 +888,7 @@ int https_handle_response_body(Download *handle, char *readbuf, int pktsize) return 0; /* handle freed */ } https_handle_response_body_memory(handle, readbuf, pktsize); - } - else if (handle->file_fd) + } else if (handle->file_fd) { if (handle->bytes_written_to_file + pktsize > handle->request->max_size) { @@ -912,10 +909,11 @@ int https_handle_response_body(Download *handle, char *readbuf, int pktsize) n = handle->lefttoparselen + pktsize; free_this_buffer = buf = safe_alloc(n); memcpy(buf, handle->lefttoparse, handle->lefttoparselen); - memcpy(buf+handle->lefttoparselen, readbuf, pktsize); + memcpy(buf + handle->lefttoparselen, readbuf, pktsize); safe_free(handle->lefttoparse); handle->lefttoparselen = 0; - } else { + } else + { n = pktsize; buf = readbuf; } @@ -936,8 +934,7 @@ int https_handle_response_body(Download *handle, char *readbuf, int pktsize) return 0; /* handle freed */ } https_handle_response_body_memory(handle, buf, eat); - } - else if (handle->file_fd) + } else if (handle->file_fd) { if (handle->bytes_written_to_file + eat > handle->request->max_size) { @@ -963,8 +960,7 @@ int https_handle_response_body(Download *handle, char *readbuf, int pktsize) { buf += 2; n -= 2; - } else - if ((n >= 1) && !strncmp(buf, "\n", 1)) + } else if ((n >= 1) && !strncmp(buf, "\n", 1)) { buf++; n--; @@ -974,7 +970,7 @@ int https_handle_response_body(Download *handle, char *readbuf, int pktsize) * this is or example '7f' + newline. * So first, check if we have a newline at all. */ - for (i=0; i < n; i++) + for (i = 0; i < n; i++) { if (buf[i] == '\n') { @@ -1090,7 +1086,8 @@ void https_redirect(Download *handle) safe_free(r->actual_url); r->actual_url = safe_alloc(sz); snprintf(r->actual_url, sz, "https://%s:%d%s", handle->hostname, handle->port, handle->redirect_new_location); - } else { + } else + { safe_strdup(r->actual_url, handle->redirect_new_location); } @@ -1143,7 +1140,7 @@ int https_parse_header(char *buffer, int len, char **key, char **value, char **l /* Note: p *could* point to the NUL byte ('\0') */ /* Special handling for response line itself. */ - if (!strncmp(p, "HTTP/1", 6) && (strlen(p)>=13)) + if (!strncmp(p, "HTTP/1", 6) && (strlen(p) >= 13)) { k = "RESPONSE"; p += 9; @@ -1154,11 +1151,10 @@ int https_parse_header(char *buffer, int len, char **key, char **value, char **l if (*p == '\r') { *p = '\0'; /* eat silently, but don't consider EOL */ - } - else if (*p == '\n') + } else if (*p == '\n') { *p = '\0'; - nextptr = p+1; /* safe, there is data or at least a \0 there */ + nextptr = p + 1; /* safe, there is data or at least a \0 there */ break; } } @@ -1214,11 +1210,10 @@ int https_parse_header(char *buffer, int len, char **key, char **value, char **l if (*p == '\r') { *p = '\0'; /* eat silently, but don't consider EOL */ - } - else if (*p == '\n') + } else if (*p == '\n') { *p = '\0'; - nextptr = p+1; /* safe, there is data or at least a \0 there */ + nextptr = p + 1; /* safe, there is data or at least a \0 there */ break; } } @@ -1249,15 +1244,14 @@ char *url_find_end_of_request(char *header, int totalsize, int *remaining_bytes) if (nextframe1 < nextframe2) { nextframe = nextframe1 + 4; - } else { + } else + { nextframe = nextframe2 + 2; } - } else - if (nextframe1) + } else if (nextframe1) { nextframe = nextframe1 + 4; - } else - if (nextframe2) + } else if (nextframe2) { nextframe = nextframe2 + 2; } @@ -1298,7 +1292,7 @@ void url_init(void) if (!https_ctx) { unreal_log(ULOG_ERROR, "url", "HTTPS_NEW_CTX_FAILED", NULL, - "Unable to initialize SSL context"); + "Unable to initialize SSL context"); exit(-1); } EventAdd(NULL, "url_socket_timeout", url_socket_timeout, NULL, 500, 0); diff --git a/src/user.c b/src/user.c index 81649324a..19022e86d 100644 --- a/src/user.c +++ b/src/user.c @@ -81,7 +81,7 @@ void iNAH_host(Client *client, const char *host) safe_strdup(client->user->virthost, host); if (MyConnect(client)) sendto_server(NULL, 0, 0, NULL, ":%s SETHOST :%s", client->id, client->user->virthost); - client->umodes |= UMODE_SETHOST|UMODE_HIDE; + client->umodes |= UMODE_SETHOST | UMODE_HIDE; userhost_changed(client); } @@ -155,7 +155,7 @@ int target_limit_exceeded(Client *client, void *target, const char *name) int max_concurrent_conversations_users, max_concurrent_conversations_new_user_every; FloodSettings *settings; - if (ValidatePermissionsForPath("immune:max-concurrent-conversations",client,NULL,NULL,NULL)) + if (ValidatePermissionsForPath("immune:max-concurrent-conversations", client, NULL, NULL, NULL)) return 0; if (client->local->targets[0] == hash) @@ -200,9 +200,9 @@ int target_limit_exceeded(Client *client, void *target, const char *name) * This is so client->local->nexttarget=0 will become client->local->nexttarget=currenttime-... */ if (TStime() > client->local->nexttarget + - (max_concurrent_conversations_users * max_concurrent_conversations_new_user_every)) + (max_concurrent_conversations_users * max_concurrent_conversations_new_user_every)) { - client->local->nexttarget = TStime() - ((max_concurrent_conversations_users-1) * max_concurrent_conversations_new_user_every); + client->local->nexttarget = TStime() - ((max_concurrent_conversations_users - 1) * max_concurrent_conversations_new_user_every); } client->local->nexttarget += max_concurrent_conversations_new_user_every; @@ -223,7 +223,7 @@ char *canonize(const char *buffer) static char cbuf[2048]; char tbuf[2048]; char *s, *t, *cp = cbuf; - int l = 0; + int l = 0; char *p = NULL, *p2; *cp = '\0'; @@ -237,13 +237,12 @@ char *canonize(const char *buffer) if (l) { for (p2 = NULL, t = strtoken(&p2, cbuf, ","); t; - t = strtoken(&p2, NULL, ",")) + t = strtoken(&p2, NULL, ",")) if (!mycmp(s, t)) break; else if (p2) p2[-1] = ','; - } - else + } else t = NULL; if (!t) { @@ -254,8 +253,7 @@ char *canonize(const char *buffer) strcpy(cp, s); if (p) cp += (p - s); - } - else if (p2) + } else if (p2) p2[-1] = ','; } return cbuf; @@ -348,7 +346,7 @@ void set_snomask(Client *client, const char *snomask) remove_all_snomasks(client); return; } - + for (p = snomask; p && *p; p++) { switch (*p) @@ -365,7 +363,8 @@ void set_snomask(Client *client, const char *snomask) if (!isalpha(*p) || !is_valid_snomask(*p)) continue; addlettertodynamicstringsorted(&client->user->snomask, *p); - } else { + } else + { delletterfromstring(client->user->snomask, *p); } break; @@ -407,8 +406,7 @@ void build_umode_string(Client *client, long old, long sendmask, char *umode_buf *m++ = '-'; *m++ = um->letter; } - } - else if (!(flag & old) && (client->umodes & flag)) + } else if (!(flag & old) && (client->umodes & flag)) { if (what == MODE_ADD) *m++ = um->letter; @@ -641,32 +639,32 @@ int should_show_connect_info(Client *client) static char uid_int_to_char(int v) { if (v < 10) - return '0'+v; + return '0' + v; else - return 'A'+v-10; + return 'A' + v - 10; } /** Acquire a new unique UID */ const char *uid_get(void) { Client *acptr; - static char uid[IDLEN+1]; + static char uid[IDLEN + 1]; static int uidcounter = 0; uidcounter++; - if (uidcounter == 36*36) + if (uidcounter == 36 * 36) uidcounter = 0; do { snprintf(uid, sizeof(uid), "%s%c%c%c%c%c%c", - me.id, - uid_int_to_char(getrandom8() % 36), - uid_int_to_char(getrandom8() % 36), - uid_int_to_char(getrandom8() % 36), - uid_int_to_char(getrandom8() % 36), - uid_int_to_char(uidcounter / 36), - uid_int_to_char(uidcounter % 36)); + me.id, + uid_int_to_char(getrandom8() % 36), + uid_int_to_char(getrandom8() % 36), + uid_int_to_char(getrandom8() % 36), + uid_int_to_char(getrandom8() % 36), + uid_int_to_char(uidcounter / 36), + uid_int_to_char(uidcounter % 36)); acptr = find_client(uid, NULL); } while (acptr); @@ -698,8 +696,8 @@ void make_cloakedhost(Client *client, const char *curr, char *buf, size_t buflen const char *mask; /* Convert host to lowercase and cut off at 255 bytes just to be sure */ - for (p = curr, q = host; *p && (q < host+sizeof(host)-1); p++, q++) - *q = tolower(*p); + for (p = curr, q = host; *p && (q < host + sizeof(host) - 1); p++, q++) + *q = tolower(*p); *q = '\0'; /* Call the cloaking layer */ @@ -830,7 +828,7 @@ const char *get_connect_extinfo(Client *client) secgroups = get_security_groups(client); if (secgroups) add_nvplist(&list, 100, "security-groups", secgroups); - + /* tkl shunned */ if (IsShunned(client)) add_nvplist(&list, 110, "shunned", NULL); @@ -846,7 +844,7 @@ const char *get_connect_extinfo(Client *client) } /* Cut off last space (unless empty string) */ if (*retbuf) - retbuf[strlen(retbuf)-1] = '\0'; + retbuf[strlen(retbuf) - 1] = '\0'; /* Free the list, as it was only used to build retbuf */ free_nvplist(list); @@ -948,16 +946,16 @@ FloodSettings *get_floodsettings_for_user(Client *client, FloodOption opt) } MODVAR const char *floodoption_names[] = { - "nick-flood", - "join-flood", - "away-flood", - "invite-flood", - "knock-flood", - "max-concurrent-conversations", - "lag-penalty", - "vhost-flood", - "multiline", - NULL, + "nick-flood", + "join-flood", + "away-flood", + "invite-flood", + "knock-flood", + "max-concurrent-conversations", + "lag-penalty", + "vhost-flood", + "multiline", + NULL, }; /* Per-session flood-block counter names, parallel to floodoption_names[]. @@ -967,16 +965,16 @@ MODVAR const char *floodoption_names[] = { * soft penalty rather than a block, and multiline is not counted. */ MODVAR const char *floodoption_shortnames[] = { - "nick", /* FLD_NICK */ - "join", /* FLD_JOIN */ - "away", /* FLD_AWAY */ - "invite", /* FLD_INVITE */ - "knock", /* FLD_KNOCK */ - "conversations", /* FLD_CONVERSATIONS */ - NULL, /* FLD_LAG_PENALTY: not counted (soft penalty, not a block) */ - "vhost", /* FLD_VHOST */ - NULL, /* FLD_MULTILINE: not counted */ - NULL, + "nick", /* FLD_NICK */ + "join", /* FLD_JOIN */ + "away", /* FLD_AWAY */ + "invite", /* FLD_INVITE */ + "knock", /* FLD_KNOCK */ + "conversations", /* FLD_CONVERSATIONS */ + NULL, /* FLD_LAG_PENALTY: not counted (soft penalty, not a block) */ + "vhost", /* FLD_VHOST */ + NULL, /* FLD_MULTILINE: not counted */ + NULL, }; /** Count a flood-block for this client. @@ -1097,7 +1095,7 @@ void bump_tag_serial(Client *client) Tag *add_tag(Client *client, const char *name, int value) { - Tag *e = safe_alloc(sizeof(Tag)+strlen(name)+1); + Tag *e = safe_alloc(sizeof(Tag) + strlen(name) + 1); strcpy(e->name, name); /* safe, allocated above */ e->value = value; AddListItem(e, client->local->tags); @@ -1158,7 +1156,7 @@ int highest_channel_member_count(Client *client) Membership *m; int highest = 0; - for (m = client->user->channel; m; m=m->next) + for (m = client->user->channel; m; m = m->next) if (m->channel->users > highest) highest = m->channel->users; diff --git a/src/utf8.c b/src/utf8.c index 2cde91032..2000e3f04 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -21,10 +21,11 @@ */ #define VALIDATE_BYTE(mask, expect) \ - do { \ - if ((*p & (mask)) != (expect)) \ - goto error; \ - } while(0) + do \ + { \ + if ((*p & (mask)) != (expect)) \ + goto error; \ + } while (0) /* see IETF RFC 3629 Section 4 */ @@ -46,8 +47,7 @@ static const char *fast_validate(const char *str) { goto error; } - } - else + } else { if (*p < 0xf0) /* 1110xxxx */ { @@ -62,8 +62,7 @@ static const char *fast_validate(const char *str) default: VALIDATE_BYTE(0xc0, 0x80); /* 10xxxxxx */ } - } - else if (*p < 0xf5) /* 11110xxx excluding out-of-range */ + } else if (*p < 0xf5) /* 11110xxx excluding out-of-range */ { switch (*p++ & 0x07) { @@ -80,8 +79,7 @@ static const char *fast_validate(const char *str) } p++; VALIDATE_BYTE(0xc0, 0x80); /* 10xxxxxx */ - } - else + } else { goto error; } @@ -92,7 +90,7 @@ static const char *fast_validate(const char *str) continue; -error: + error: return last; } } @@ -129,7 +127,7 @@ int unrl_utf8_validate(const char *str, const char **end) * @returns Byte that is not in the middle of an UTF8 sequence, * or NULL if we reached the beginning and that isn't valid either. */ -char *unrl_utf8_find_prev_char (const char *begin, const char *p) +char *unrl_utf8_find_prev_char(const char *begin, const char *p) { for (--p; p >= begin; --p) { @@ -184,7 +182,8 @@ char *unrl_utf8_make_valid(const char *str, char *outputbuf, size_t outputbuflen replaced = 1; } break; - } else { + } else + { /* We already replaced earlier, now just put the rest at the end. */ strlcat(outputbuf, remainder, outputbuflen); break; @@ -228,7 +227,8 @@ char *unrl_utf8_make_valid(const char *str, char *outputbuf, size_t outputbuflen fix_line = 1; } } - } else { + } else + { /* without message tags */ if (strlen(outputbuf) > 511) { @@ -238,7 +238,7 @@ char *unrl_utf8_make_valid(const char *str, char *outputbuf, size_t outputbuflen } if (fix_line) { - char *cut_at = unrl_utf8_find_prev_char(outputbuf, outputbuf+strlen(outputbuf)); + char *cut_at = unrl_utf8_find_prev_char(outputbuf, outputbuf + strlen(outputbuf)); if (cut_at) *cut_at = '\0'; return outputbuf; /* short-circuit */ @@ -251,9 +251,9 @@ char *unrl_utf8_make_valid(const char *str, char *outputbuf, size_t outputbuflen * NOTE: This may cause us to remove 1 character needlessly at the * end even though there was still (some) space. So be it. */ - if (strlen(outputbuf) == outputbuflen-1) + if (strlen(outputbuf) == outputbuflen - 1) { - char *cut_at = unrl_utf8_find_prev_char(outputbuf, outputbuf+outputbuflen-1); + char *cut_at = unrl_utf8_find_prev_char(outputbuf, outputbuf + outputbuflen - 1); if (cut_at) *cut_at = '\0'; } @@ -307,7 +307,8 @@ void utf8_test(void) if (heapbuf == res) { printf(" %s\n", res); - } else { + } else + { printf("[!] %s\n", res); } free(heapbuf); diff --git a/src/whowas.c b/src/whowas.c index 1b859d9b1..99abab710 100644 --- a/src/whowas.c +++ b/src/whowas.c @@ -108,7 +108,8 @@ void add_history(Client *client, int online, WhoWasEvent event) { new->online = client; add_whowas_to_clist(&(client->user->whowas), new); - } else { + } else + { new->online = NULL; } add_whowas_to_list(&WHOWASHASH[new->hashv], new); @@ -132,7 +133,7 @@ void off_history(Client *client) Client *get_history(const char *nick, time_t timelimit) { WhoWas *temp; - int blah; + int blah; timelimit = TStime() - timelimit; blah = hash_whowas_name(nick); @@ -151,8 +152,8 @@ Client *get_history(const char *nick, time_t timelimit) void count_whowas_memory(int *wwu, u_long *wwum) { WhoWas *tmp; - int i; - int u = 0; + int i; + int u = 0; u_long um = 0; /* count the number of used whowas structs in 'u' */ /* count up the memory used of whowas structs in um */ @@ -170,7 +171,7 @@ void count_whowas_memory(int *wwu, u_long *wwum) void initwhowas() { - int i; + int i; for (i = 0; i < NICKNAMEHISTORYLENGTH; i++) { @@ -181,7 +182,7 @@ void initwhowas() WHOWASHASH[i] = NULL; } -void add_whowas_to_clist(WhoWas ** bucket, WhoWas * whowas) +void add_whowas_to_clist(WhoWas **bucket, WhoWas *whowas) { whowas->cprev = NULL; if ((whowas->cnext = *bucket) != NULL) @@ -189,7 +190,7 @@ void add_whowas_to_clist(WhoWas ** bucket, WhoWas * whowas) *bucket = whowas; } -void del_whowas_from_clist(WhoWas ** bucket, WhoWas * whowas) +void del_whowas_from_clist(WhoWas **bucket, WhoWas *whowas) { if (whowas->cprev) whowas->cprev->cnext = whowas->cnext; @@ -199,7 +200,7 @@ void del_whowas_from_clist(WhoWas ** bucket, WhoWas * whowas) whowas->cnext->cprev = whowas->cprev; } -void add_whowas_to_list(WhoWas ** bucket, WhoWas * whowas) +void add_whowas_to_list(WhoWas **bucket, WhoWas *whowas) { whowas->prev = NULL; if ((whowas->next = *bucket) != NULL) @@ -207,7 +208,7 @@ void add_whowas_to_list(WhoWas ** bucket, WhoWas * whowas) *bucket = whowas; } -void del_whowas_from_list(WhoWas ** bucket, WhoWas * whowas) +void del_whowas_from_list(WhoWas **bucket, WhoWas *whowas) { if (whowas->prev) whowas->prev->next = whowas->next; diff --git a/src/windows/compilerhelp.c b/src/windows/compilerhelp.c index aab1a9ded..65e64a225 100644 --- a/src/windows/compilerhelp.c +++ b/src/windows/compilerhelp.c @@ -13,43 +13,41 @@ #include -void main(int argc,char *argv[]) +void main(int argc, char *argv[]) { FILE *openme; char inbuf[512]; - int i,pb=0,rb=0,mi=0,ma=0; + int i, pb = 0, rb = 0, mi = 0, ma = 0; if (argc == 1) exit(-1); - if ((openme = fopen(argv[1],"r+"))==NULL) + if ((openme = fopen(argv[1], "r+")) == NULL) { printf("error\n"); exit(-1); } - fscanf(openme,"%s %s %d\n",inbuf,inbuf,&pb); /*Read Buffer*/ - fscanf(openme,"%s %s %d\n",inbuf,inbuf,&rb); - fscanf(openme,"%s %s %d\n",inbuf,inbuf,&mi); - fscanf(openme,"%s %s %d\n",inbuf,inbuf,&ma); + fscanf(openme, "%s %s %d\n", inbuf, inbuf, &pb); /*Read Buffer*/ + fscanf(openme, "%s %s %d\n", inbuf, inbuf, &rb); + fscanf(openme, "%s %s %d\n", inbuf, inbuf, &mi); + fscanf(openme, "%s %s %d\n", inbuf, inbuf, &ma); pb++; if (argc > 2) - if (atoi(argv[2])==0) /*Public Build*/ - rb++; + if (atoi(argv[2]) == 0) /*Public Build*/ + rb++; - printf("new version = %d,%d,%d,%d",ma,mi,rb,pb); + printf("new version = %d,%d,%d,%d", ma, mi, rb, pb); rewind(openme); - fprintf(openme,"#define pb %d\n",pb); /*Write Buffer*/ - fprintf(openme,"#define rb %d\n",rb); - fprintf(openme,"#define mi %d\n",mi); - fprintf(openme,"#define ma %d\n",ma); + fprintf(openme, "#define pb %d\n", pb); /*Write Buffer*/ + fprintf(openme, "#define rb %d\n", rb); + fprintf(openme, "#define mi %d\n", mi); + fprintf(openme, "#define ma %d\n", ma); - fprintf(openme,"#define vFILEVERSION ma,mi,rb,pb\n#define vPRODUCTVERSION ma,mi,0,0\n#define vDISPFILEVERSION \"%d,%d,%d,%d\\0\"\n#define vSUBBUILD \"%d\\0\"\n",ma,mi,rb,pb,pb); + fprintf(openme, "#define vFILEVERSION ma,mi,rb,pb\n#define vPRODUCTVERSION ma,mi,0,0\n#define vDISPFILEVERSION \"%d,%d,%d,%d\\0\"\n#define vSUBBUILD \"%d\\0\"\n", ma, mi, rb, pb, pb); fclose(openme); - - } diff --git a/src/windows/config.c b/src/windows/config.c index 2b41cc3e0..068aa7a90 100644 --- a/src/windows/config.c +++ b/src/windows/config.c @@ -1,7 +1,8 @@ #include #include -int main() { +int main() +{ FILE *fd = fopen("Changes", "r"); FILE *fd2; char buf[1024]; @@ -15,17 +16,19 @@ int main() { fd = fopen("src/version.c", "r"); if (!fd) generation = 1; - else { - while (fgets(buf, 1023, fd)) { + else + { + while (fgets(buf, 1023, fd)) + { if (!strstr(buf, "char *generation")) continue; while (!isdigit(buf[i])) - i++; + i++; j = i; - while (isdigit(buf[j])) + while (isdigit(buf[j])) j++; buf[j] = 0; - generation = (atoi(&buf[i])+1); + generation = (atoi(&buf[i]) + 1); } } fd = fopen("src/version.c.sh", "r"); @@ -34,23 +37,23 @@ int main() { fd2 = fopen("src/version.c", "w"); if (!fd2) return 0; - while (fgets(buf, 1023, fd)) { - if (!strncmp("cat >version.c <version.c < #include -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ FILE *fd, *fdout; char buf[1024]; @@ -13,13 +14,13 @@ int main(int argc, char *argv[]) { if (!(fd = fopen(argv[1], "r"))) exit(2); - + if (!(fdout = fopen(argv[2], "w"))) exit(3); while (fgets(buf, 1023, fd)) { - if (*buf == '\t') + if (*buf == '\t') { char *symbol = strtok(buf, " "); @@ -28,12 +29,10 @@ int main(int argc, char *argv[]) { if (!strncmp(symbol, "\t_xmm@", 6)) continue; - fprintf(fdout, "%s\r\n", symbol); - - } - else - fprintf(fdout, "%s", buf); + fprintf(fdout, "%s\r\n", symbol); + } else + fprintf(fdout, "%s", buf); } return 0; } diff --git a/src/windows/editor.c b/src/windows/editor.c index 5f4a1e1b8..a180c79ff 100644 --- a/src/windows/editor.c +++ b/src/windows/editor.c @@ -44,9 +44,9 @@ HWND DrawStatusbar(HINSTANCE hInstance, HWND hwndParent, UINT iId) HWND hStatus, hTip; TOOLINFO ti; RECT clrect; - hStatus = CreateStatusWindow(WS_CHILD|WS_VISIBLE|SBT_TOOLTIPS, NULL, hwndParent, iId); + hStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE | SBT_TOOLTIPS, NULL, hwndParent, iId); hTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, - WS_POPUP|TTS_NOPREFIX|TTS_ALWAYSTIP, 0, 0, 0, 0, hwndParent, NULL, hInstance, NULL); + WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, 0, 0, 0, 0, hwndParent, NULL, hInstance, NULL); GetClientRect(hStatus, &clrect); ti.cbSize = sizeof(TOOLINFO); ti.uFlags = TTF_SUBCLASS; @@ -66,36 +66,36 @@ HWND DrawStatusbar(HINSTANCE hInstance, HWND hwndParent, UINT iId) * Returns: * The handle to the toolbar */ -HWND DrawToolbar(HINSTANCE hInstance, HWND hwndParent) +HWND DrawToolbar(HINSTANCE hInstance, HWND hwndParent) { HWND hTool; TBADDBITMAP tbBit; int newidx; TBBUTTON tbButtons[10] = { - { STD_FILENEW, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, - { STD_FILESAVE, IDM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, - { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0}, 0L, 0}, - { STD_CUT, IDM_CUT, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, - { STD_COPY, IDM_COPY, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, - { STD_PASTE, IDM_PASTE, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, - { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0}, 0L, 0}, - { STD_UNDO, IDM_UNDO, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, - { STD_REDOW, IDM_REDO, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, - { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0}, 0L, 0}, + {STD_FILENEW, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, + {STD_FILESAVE, IDM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, + {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0}, 0L, 0}, + {STD_CUT, IDM_CUT, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, + {STD_COPY, IDM_COPY, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, + {STD_PASTE, IDM_PASTE, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, + {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0}, 0L, 0}, + {STD_UNDO, IDM_UNDO, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, + {STD_REDOW, IDM_REDO, 0, TBSTYLE_BUTTON, {0}, 0L, 0}, + {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0}, 0L, 0}, }; - + TBBUTTON tbAddButtons[7] = { - { 0, IDC_BOLD, TBSTATE_ENABLED, TBSTYLE_CHECK, {0}, 0L, 0}, - { 1, IDC_UNDERLINE, TBSTATE_ENABLED, TBSTYLE_CHECK, {0}, 0L, 0}, - { 2, IDC_COLOR, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, - { 3, IDC_BGCOLOR, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, - { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0}, 0L, 0}, - { 4, IDC_GOTO, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, - { STD_FIND, IDC_FIND, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, + {0, IDC_BOLD, TBSTATE_ENABLED, TBSTYLE_CHECK, {0}, 0L, 0}, + {1, IDC_UNDERLINE, TBSTATE_ENABLED, TBSTYLE_CHECK, {0}, 0L, 0}, + {2, IDC_COLOR, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, + {3, IDC_BGCOLOR, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, + {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0}, 0L, 0}, + {4, IDC_GOTO, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, + {STD_FIND, IDC_FIND, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, }; - hTool = CreateToolbarEx(hwndParent, WS_VISIBLE|WS_CHILD|TBSTYLE_FLAT|TBSTYLE_TOOLTIPS, - IDC_TOOLBAR, 0, HINST_COMMCTRL, IDB_STD_SMALL_COLOR, - tbButtons, 10, 0, 0, 100, 30, sizeof(TBBUTTON)); + hTool = CreateToolbarEx(hwndParent, WS_VISIBLE | WS_CHILD | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS, + IDC_TOOLBAR, 0, HINST_COMMCTRL, IDB_STD_SMALL_COLOR, + tbButtons, 10, 0, 0, 100, 30, sizeof(TBBUTTON)); tbBit.hInst = hInstance; tbBit.nID = IDB_BITMAP1; newidx = SendMessage(hTool, TB_ADDBITMAP, (WPARAM)5, (LPARAM)&tbBit); @@ -117,44 +117,45 @@ HWND DrawToolbar(HINSTANCE hInstance, HWND hwndParent) * Returns: * TRUE if the message was processed, FALSE otherwise */ -LRESULT CALLBACK ColorDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { +LRESULT CALLBACK ColorDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ static HBRUSH hBrushWhite, hBrushBlack, hBrushDarkBlue, hBrushDarkGreen, hBrushRed, - hBrushDarkRed, hBrushPurple, hBrushOrange, hBrushYellow, hBrushGreen, hBrushVDarkGreen, - hBrushLightBlue, hBrushBlue, hBrushPink, hBrushDarkGray, hBrushGray; + hBrushDarkRed, hBrushPurple, hBrushOrange, hBrushYellow, hBrushGreen, hBrushVDarkGreen, + hBrushLightBlue, hBrushBlue, hBrushPink, hBrushDarkGray, hBrushGray; static UINT ResultMsg = 0; - switch (message) + switch (message) { case WM_INITDIALOG: - hBrushWhite = CreateSolidBrush(RGB(255,255,255)); - hBrushBlack = CreateSolidBrush(RGB(0,0,0)); - hBrushDarkBlue = CreateSolidBrush(RGB(0,0,127)); - hBrushDarkGreen = CreateSolidBrush(RGB(0,147,0)); - hBrushRed = CreateSolidBrush(RGB(255,0,0)); - hBrushDarkRed = CreateSolidBrush(RGB(127,0,0)); - hBrushPurple = CreateSolidBrush(RGB(156,0,156)); - hBrushOrange = CreateSolidBrush(RGB(252,127,0)); - hBrushYellow = CreateSolidBrush(RGB(255,255,0)); - hBrushGreen = CreateSolidBrush(RGB(0,252,0)); - hBrushVDarkGreen = CreateSolidBrush(RGB(0,147,147)); - hBrushLightBlue = CreateSolidBrush(RGB(0,255,255)); - hBrushBlue = CreateSolidBrush(RGB(0,0,252)); - hBrushPink = CreateSolidBrush(RGB(255,0,255)); - hBrushDarkGray = CreateSolidBrush(RGB(127,127,127)); - hBrushGray = CreateSolidBrush(RGB(210,210,210)); + hBrushWhite = CreateSolidBrush(RGB(255, 255, 255)); + hBrushBlack = CreateSolidBrush(RGB(0, 0, 0)); + hBrushDarkBlue = CreateSolidBrush(RGB(0, 0, 127)); + hBrushDarkGreen = CreateSolidBrush(RGB(0, 147, 0)); + hBrushRed = CreateSolidBrush(RGB(255, 0, 0)); + hBrushDarkRed = CreateSolidBrush(RGB(127, 0, 0)); + hBrushPurple = CreateSolidBrush(RGB(156, 0, 156)); + hBrushOrange = CreateSolidBrush(RGB(252, 127, 0)); + hBrushYellow = CreateSolidBrush(RGB(255, 255, 0)); + hBrushGreen = CreateSolidBrush(RGB(0, 252, 0)); + hBrushVDarkGreen = CreateSolidBrush(RGB(0, 147, 147)); + hBrushLightBlue = CreateSolidBrush(RGB(0, 255, 255)); + hBrushBlue = CreateSolidBrush(RGB(0, 0, 252)); + hBrushPink = CreateSolidBrush(RGB(255, 0, 255)); + hBrushDarkGray = CreateSolidBrush(RGB(127, 127, 127)); + hBrushGray = CreateSolidBrush(RGB(210, 210, 210)); ResultMsg = (UINT)lParam; SetFocus(NULL); return TRUE; - case WM_DRAWITEM: + case WM_DRAWITEM: { LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam; - if (wParam == IDC_WHITE) + if (wParam == IDC_WHITE) FillRect(lpdis->hDC, &lpdis->rcItem, hBrushWhite); if (wParam == IDC_BLACK) FillRect(lpdis->hDC, &lpdis->rcItem, hBrushBlack); - if (wParam == IDC_DARKBLUE) + if (wParam == IDC_DARKBLUE) FillRect(lpdis->hDC, &lpdis->rcItem, hBrushDarkBlue); - if (wParam == IDC_DARKGREEN) + if (wParam == IDC_DARKGREEN) FillRect(lpdis->hDC, &lpdis->rcItem, hBrushDarkGreen); if (wParam == IDC_RED) FillRect(lpdis->hDC, &lpdis->rcItem, hBrushRed); @@ -183,41 +184,41 @@ LRESULT CALLBACK ColorDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) DrawEdge(lpdis->hDC, &lpdis->rcItem, EDGE_SUNKEN, BF_RECT); return TRUE; } - case WM_COMMAND: + case WM_COMMAND: { COLORREF clrref; - if (LOWORD(wParam) == IDC_WHITE) - clrref = RGB(255,255,255); + if (LOWORD(wParam) == IDC_WHITE) + clrref = RGB(255, 255, 255); else if (LOWORD(wParam) == IDC_BLACK) - clrref = RGB(0,0,0); + clrref = RGB(0, 0, 0); else if (LOWORD(wParam) == IDC_DARKBLUE) - clrref = RGB(0,0,127); + clrref = RGB(0, 0, 127); else if (LOWORD(wParam) == IDC_DARKGREEN) - clrref = RGB(0,147,0); + clrref = RGB(0, 147, 0); else if (LOWORD(wParam) == IDC_RED) - clrref = RGB(255,0,0); + clrref = RGB(255, 0, 0); else if (LOWORD(wParam) == IDC_DARKRED) - clrref = RGB(127,0,0); + clrref = RGB(127, 0, 0); else if (LOWORD(wParam) == IDC_PURPLE) - clrref = RGB(156,0,156); + clrref = RGB(156, 0, 156); else if (LOWORD(wParam) == IDC_ORANGE) - clrref = RGB(252,127,0); + clrref = RGB(252, 127, 0); else if (LOWORD(wParam) == IDC_YELLOW) - clrref = RGB(255,255,0); + clrref = RGB(255, 255, 0); else if (LOWORD(wParam) == IDC_GREEN) - clrref = RGB(0,252,0); + clrref = RGB(0, 252, 0); else if (LOWORD(wParam) == IDC_VDARKGREEN) - clrref = RGB(0,147,147); + clrref = RGB(0, 147, 147); else if (LOWORD(wParam) == IDC_LIGHTBLUE) - clrref = RGB(0,255,255); + clrref = RGB(0, 255, 255); else if (LOWORD(wParam) == IDC_BLUE) - clrref = RGB(0,0,252); + clrref = RGB(0, 0, 252); else if (LOWORD(wParam) == IDC_PINK) - clrref = RGB(255,0,255); + clrref = RGB(255, 0, 255); else if (LOWORD(wParam) == IDC_DARKGRAY) - clrref = RGB(127,127,127); + clrref = RGB(127, 127, 127); else if (LOWORD(wParam) == IDC_GRAY) - clrref = RGB(210,210,210); + clrref = RGB(210, 210, 210); SendMessage(GetParent(hDlg), ResultMsg, (WPARAM)clrref, (LPARAM)hDlg); break; } @@ -255,15 +256,15 @@ LRESULT CALLBACK ColorDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) * Returns: * TRUE if the message was processed, FALSE otherwise */ -LRESULT CALLBACK GotoDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK GotoDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - if (message == WM_COMMAND) + if (message == WM_COMMAND) { if (LOWORD(wParam) == IDCANCEL) EndDialog(hDlg, TRUE); - else if (LOWORD(wParam) == IDOK) + else if (LOWORD(wParam) == IDOK) { - HWND hWnd = GetDlgItem(GetParent(hDlg),IDC_TEXT); + HWND hWnd = GetDlgItem(GetParent(hDlg), IDC_TEXT); int line = GetDlgItemInt(hDlg, IDC_GOTO, NULL, FALSE); int pos = SendMessage(hWnd, EM_LINEINDEX, (WPARAM)--line, 0); SendMessage(hWnd, EM_SETSEL, (WPARAM)pos, (LPARAM)pos); @@ -274,7 +275,7 @@ LRESULT CALLBACK GotoDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return FALSE; } -LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hWnd; static FINDREPLACE find; @@ -291,7 +292,7 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar if (fr->Flags & FR_FINDNEXT) { HWND hRich = GetDlgItem(hDlg, IDC_TEXT); - DWORD flags=0; + DWORD flags = 0; FINDTEXTEX ft; CHARRANGE chrg; @@ -307,29 +308,28 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar { ft.chrg.cpMin = chrg.cpMax; ft.chrg.cpMax = -1; - } - else + } else { ft.chrg.cpMin = chrg.cpMin; ft.chrg.cpMax = -1; } if (SendMessage(hRich, EM_FINDTEXTEX, flags, (LPARAM)&ft) == -1) MessageBox(NULL, "UnrealIRCd has finished searching the document", - "Find", MB_ICONINFORMATION|MB_OK); + "Find", MB_ICONINFORMATION | MB_OK); else { - SendMessage(hRich, EM_EXSETSEL, 0, (LPARAM)&(ft.chrgText)); + SendMessage(hRich, EM_EXSETSEL, 0, (LPARAM) & (ft.chrgText)); SendMessage(hRich, EM_SCROLLCARET, 0, 0); SetFocus(hRich); } } return TRUE; } - switch (message) + switch (message) { - case WM_INITDIALOG: + case WM_INITDIALOG: { - int fd,len; + int fd, len; char *buffer, *string; EDITSTREAM edit; StreamIO *stream = safe_alloc(sizeof(StreamIO)); @@ -339,7 +339,7 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar file = (unsigned char *)lParam; if (file) wsprintf(szText, "UnrealIRCd Editor - %s", file); - else + else strcpy(szText, "UnrealIRCd Editor - New File"); SetWindowText(hDlg, szText); lpfnOldWndProc = (FARPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)RESubClassFunc); @@ -348,18 +348,18 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar SendMessage(hWnd, EM_SETEVENTMASK, 0, (LPARAM)ENM_SELCHANGE); chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_FACE; - strcpy(chars.szFaceName,"Fixedsys"); + strcpy(chars.szFaceName, "Fixedsys"); SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_ALL, (LPARAM)&chars); - if ((fd = open(file, _O_RDONLY|_O_BINARY)) != -1) + if ((fd = open(file, _O_RDONLY | _O_BINARY)) != -1) { - fstat(fd,&sb); + fstat(fd, &sb); /* Only allocate the amount we need */ - buffer = safe_alloc(sb.st_size+1); + buffer = safe_alloc(sb.st_size + 1); len = read(fd, buffer, sb.st_size); buffer[len] = 0; - len = CountRTFSize(buffer)+1; + len = CountRTFSize(buffer) + 1; string = safe_alloc(len); - IRCToRTF(buffer,string); + IRCToRTF(buffer, string); RTFBuf = string; len--; stream->size = &len; @@ -367,7 +367,7 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar edit.dwCookie = (DWORD_PTR)stream; edit.pfnCallback = SplitIt; SendMessage(hWnd, EM_EXLIMITTEXT, 0, (LPARAM)0x7FFFFFFF); - SendMessage(hWnd, EM_STREAMIN, (WPARAM)SF_RTF|SFF_PLAINRTF, (LPARAM)&edit); + SendMessage(hWnd, EM_STREAMIN, (WPARAM)SF_RTF | SFF_PLAINRTF, (LPARAM)&edit); SendMessage(hWnd, EM_SETMODIFY, (WPARAM)FALSE, 0); SendMessage(hWnd, EM_EMPTYUNDOBUFFER, 0, 0); close(fd); @@ -376,11 +376,11 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar safe_free(string); safe_free(stream); hClip = SetClipboardViewer(hDlg); - if (SendMessage(hWnd, EM_CANPASTE, 0, 0)) - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(TRUE,0)); + if (SendMessage(hWnd, EM_CANPASTE, 0, 0)) + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(TRUE, 0)); else - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(FALSE,0)); - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(FALSE,0)); + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(FALSE, 0)); + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(FALSE, 0)); wsprintf(szText, "Line: 1"); SetWindowText(hStatus, szText); } @@ -400,29 +400,29 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar DWORD old_rich_width, old_rich_height; if (hDlg == hFind) return FALSE; - new_width = LOWORD(lParam); + new_width = LOWORD(lParam); new_height = HIWORD(lParam); - hRich = GetDlgItem(hDlg, IDC_TEXT); + hRich = GetDlgItem(hDlg, IDC_TEXT); SendMessage(hStatus, WM_SIZE, 0, 0); SendMessage(hTool, TB_AUTOSIZE, 0, 0); - old_width = rOld.right-rOld.left; - old_height = rOld.bottom-rOld.top; + old_width = rOld.right - rOld.left; + old_height = rOld.bottom - rOld.top; new_width = new_width - old_width; new_height = new_height - old_height; GetWindowRect(hRich, &rOldRich); - old_rich_width = rOldRich.right-rOldRich.left; - old_rich_height = rOldRich.bottom-rOldRich.top; - SetWindowPos(hRich, NULL, 0, 0, old_rich_width+new_width, - old_rich_height+new_height, - SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOZORDER); + old_rich_width = rOldRich.right - rOldRich.left; + old_rich_height = rOldRich.bottom - rOldRich.top; + SetWindowPos(hRich, NULL, 0, 0, old_rich_width + new_width, + old_rich_height + new_height, + SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER); memset(&rOld, 0, sizeof(rOld)); return TRUE; - } + } case WM_NOTIFY: - switch (((NMHDR *)lParam)->code) + switch (((NMHDR *)lParam)->code) { - case EN_SELCHANGE: + case EN_SELCHANGE: { HWND hWnd = GetDlgItem(hDlg, IDC_TEXT); DWORD start, end, currline; @@ -431,101 +431,100 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar chars.cbSize = sizeof(CHARFORMAT2); SendMessage(hWnd, EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); if (chars.dwMask & CFM_BOLD && chars.dwEffects & CFE_BOLD) - SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_BOLD, (LPARAM)MAKELONG(TRUE,0)); + SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_BOLD, (LPARAM)MAKELONG(TRUE, 0)); else - SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_BOLD, (LPARAM)MAKELONG(FALSE,0)); + SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_BOLD, (LPARAM)MAKELONG(FALSE, 0)); if (chars.dwMask & CFM_UNDERLINE && chars.dwEffects & CFE_UNDERLINE) - SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_UNDERLINE, (LPARAM)MAKELONG(TRUE,0)); + SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_UNDERLINE, (LPARAM)MAKELONG(TRUE, 0)); else - SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_UNDERLINE, (LPARAM)MAKELONG(FALSE,0)); - SendMessage(hWnd, EM_GETSEL,(WPARAM)&start, (LPARAM)&end); - if (start == end) + SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_UNDERLINE, (LPARAM)MAKELONG(FALSE, 0)); + SendMessage(hWnd, EM_GETSEL, (WPARAM)&start, (LPARAM)&end); + if (start == end) { - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_COPY, (LPARAM)MAKELONG(FALSE,0)); - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_CUT, (LPARAM)MAKELONG(FALSE,0)); - } - else + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_COPY, (LPARAM)MAKELONG(FALSE, 0)); + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_CUT, (LPARAM)MAKELONG(FALSE, 0)); + } else { - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_COPY, (LPARAM)MAKELONG(TRUE,0)); - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_CUT, (LPARAM)MAKELONG(TRUE,0)); + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_COPY, (LPARAM)MAKELONG(TRUE, 0)); + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_CUT, (LPARAM)MAKELONG(TRUE, 0)); } - if (SendMessage(hWnd, EM_CANUNDO, 0, 0)) - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(TRUE,0)); + if (SendMessage(hWnd, EM_CANUNDO, 0, 0)) + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(TRUE, 0)); else - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(FALSE,0)); - if (SendMessage(hWnd, EM_CANREDO, 0, 0)) - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_REDO, (LPARAM)MAKELONG(TRUE,0)); + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(FALSE, 0)); + if (SendMessage(hWnd, EM_CANREDO, 0, 0)) + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_REDO, (LPARAM)MAKELONG(TRUE, 0)); else - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_REDO, (LPARAM)MAKELONG(FALSE,0)); + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_REDO, (LPARAM)MAKELONG(FALSE, 0)); currline = SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, 0); currline++; - if (currline != prevline) + if (currline != prevline) { wsprintf(buffer, "Line: %d", currline); SetWindowText(hStatus, buffer); prevline = currline; } - return TRUE; - } - case TTN_GETDISPINFO: - { - LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT) lParam; - lpttt->hinst = NULL; - switch (lpttt->hdr.idFrom) - { - case IDM_NEW: - strcpy(lpttt->szText, "New"); - break; - case IDM_SAVE: - strcpy(lpttt->szText, "Save"); - break; - case IDM_CUT: - strcpy(lpttt->szText, "Cut"); - break; - case IDM_COPY: - strcpy(lpttt->szText, "Copy"); - break; - case IDM_PASTE: - strcpy(lpttt->szText, "Paste"); - break; - case IDM_UNDO: - strcpy(lpttt->szText, "Undo"); - break; - case IDM_REDO: - strcpy(lpttt->szText, "Redo"); - break; - case IDC_BOLD: - strcpy(lpttt->szText, "Bold"); - break; - case IDC_UNDERLINE: - strcpy(lpttt->szText, "Underline"); - break; - case IDC_COLOR: - strcpy(lpttt->szText, "Text Color"); - break; - case IDC_BGCOLOR: - strcpy(lpttt->szText, "Background Color"); - break; - case IDC_GOTO: - strcpy(lpttt->szText, "Goto"); - break; - case IDC_FIND: - strcpy(lpttt->szText, "Find"); - break; + return TRUE; } - return TRUE; + case TTN_GETDISPINFO: + { + LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam; + lpttt->hinst = NULL; + switch (lpttt->hdr.idFrom) + { + case IDM_NEW: + strcpy(lpttt->szText, "New"); + break; + case IDM_SAVE: + strcpy(lpttt->szText, "Save"); + break; + case IDM_CUT: + strcpy(lpttt->szText, "Cut"); + break; + case IDM_COPY: + strcpy(lpttt->szText, "Copy"); + break; + case IDM_PASTE: + strcpy(lpttt->szText, "Paste"); + break; + case IDM_UNDO: + strcpy(lpttt->szText, "Undo"); + break; + case IDM_REDO: + strcpy(lpttt->szText, "Redo"); + break; + case IDC_BOLD: + strcpy(lpttt->szText, "Bold"); + break; + case IDC_UNDERLINE: + strcpy(lpttt->szText, "Underline"); + break; + case IDC_COLOR: + strcpy(lpttt->szText, "Text Color"); + break; + case IDC_BGCOLOR: + strcpy(lpttt->szText, "Background Color"); + break; + case IDC_GOTO: + strcpy(lpttt->szText, "Goto"); + break; + case IDC_FIND: + strcpy(lpttt->szText, "Find"); + break; + } + return TRUE; + } + case NM_DBLCLK: + DialogBox(hInst, "GOTO", hDlg, (DLGPROC)GotoDLG); + return (TRUE); } - case NM_DBLCLK: - DialogBox(hInst, "GOTO", hDlg, (DLGPROC)GotoDLG); - return (TRUE); - } - - return (TRUE); + + return (TRUE); case WM_COMMAND: - if (LOWORD(wParam) == IDC_BOLD) + if (LOWORD(wParam) == IDC_BOLD) { hWnd = GetDlgItem(hDlg, IDC_TEXT); - if (SendMessage(hTool, TB_ISBUTTONCHECKED, (WPARAM)IDC_BOLD, (LPARAM)0) != 0) + if (SendMessage(hTool, TB_ISBUTTONCHECKED, (WPARAM)IDC_BOLD, (LPARAM)0) != 0) { chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_BOLD; @@ -533,8 +532,7 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); SendMessage(hWnd, EM_HIDESELECTION, 0, 0); SetFocus(hWnd); - } - else + } else { chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_BOLD; @@ -544,11 +542,10 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar SetFocus(hWnd); } return TRUE; - } - else if (LOWORD(wParam) == IDC_UNDERLINE) + } else if (LOWORD(wParam) == IDC_UNDERLINE) { hWnd = GetDlgItem(hDlg, IDC_TEXT); - if (SendMessage(hTool, TB_ISBUTTONCHECKED, (WPARAM)IDC_UNDERLINE, (LPARAM)0) != 0) + if (SendMessage(hTool, TB_ISBUTTONCHECKED, (WPARAM)IDC_UNDERLINE, (LPARAM)0) != 0) { chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_UNDERLINETYPE; @@ -556,8 +553,7 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); SendMessage(hWnd, EM_HIDESELECTION, 0, 0); SetFocus(hWnd); - } - else + } else { chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_UNDERLINETYPE; @@ -568,14 +564,14 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar } return TRUE; } - if (LOWORD(wParam) == IDC_COLOR) + if (LOWORD(wParam) == IDC_COLOR) { - DialogBoxParam(hInst, "Color", hDlg, (DLGPROC)ColorDLG, (LPARAM)WM_USER+10); + DialogBoxParam(hInst, "Color", hDlg, (DLGPROC)ColorDLG, (LPARAM)WM_USER + 10); return 0; } if (LOWORD(wParam) == IDC_BGCOLOR) { - DialogBoxParam(hInst, "Color", hDlg, (DLGPROC)ColorDLG, (LPARAM)WM_USER+11); + DialogBoxParam(hInst, "Color", hDlg, (DLGPROC)ColorDLG, (LPARAM)WM_USER + 11); return 0; } if (LOWORD(wParam) == IDC_GOTO) @@ -594,49 +590,49 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar hFind = FindText(&fr); return 0; } - + hWnd = GetDlgItem(hDlg, IDC_TEXT); - if (LOWORD(wParam) == IDM_COPY) + if (LOWORD(wParam) == IDM_COPY) { SendMessage(hWnd, WM_COPY, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_SELECTALL) + if (LOWORD(wParam) == IDM_SELECTALL) { SendMessage(hWnd, EM_SETSEL, 0, -1); return 0; } - if (LOWORD(wParam) == IDM_PASTE) + if (LOWORD(wParam) == IDM_PASTE) { SendMessage(hWnd, WM_PASTE, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_CUT) + if (LOWORD(wParam) == IDM_CUT) { SendMessage(hWnd, WM_CUT, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_UNDO) + if (LOWORD(wParam) == IDM_UNDO) { SendMessage(hWnd, EM_UNDO, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_REDO) + if (LOWORD(wParam) == IDM_REDO) { SendMessage(hWnd, EM_REDO, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_DELETE) + if (LOWORD(wParam) == IDM_DELETE) { SendMessage(hWnd, WM_CLEAR, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_SAVE) + if (LOWORD(wParam) == IDM_SAVE) { int fd; EDITSTREAM edit; OPENFILENAME lpopen; - if (!file) + if (!file) { unsigned char path[MAX_PATH]; path[0] = '\0'; @@ -651,46 +647,45 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar lpopen.lpstrFileTitle = NULL; lpopen.lpstrInitialDir = CONFDIR; lpopen.lpstrTitle = NULL; - lpopen.Flags = (OFN_ENABLESIZING|OFN_NONETWORKBUTTON| - OFN_OVERWRITEPROMPT); + lpopen.Flags = (OFN_ENABLESIZING | OFN_NONETWORKBUTTON | + OFN_OVERWRITEPROMPT); if (GetSaveFileName(&lpopen)) file = path; else break; } - fd = open(file, _O_TRUNC|_O_CREAT|_O_WRONLY|_O_BINARY,_S_IWRITE); + fd = open(file, _O_TRUNC | _O_CREAT | _O_WRONLY | _O_BINARY, _S_IWRITE); edit.dwCookie = 0; edit.pfnCallback = BufferIt; - SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_STREAMOUT, (WPARAM)SF_RTF|SFF_PLAINRTF, (LPARAM)&edit); + SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_STREAMOUT, (WPARAM)SF_RTF | SFF_PLAINRTF, (LPARAM)&edit); RTFToIRC(fd, RTFBuf, strlen(RTFBuf)); safe_free(RTFBuf); RTFBuf = NULL; SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_SETMODIFY, (WPARAM)FALSE, 0); - + return 0; } - if (LOWORD(wParam) == IDM_NEW) + if (LOWORD(wParam) == IDM_NEW) { unsigned char text[1024]; BOOL newfile = FALSE; int ans; - if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_GETMODIFY, 0, 0) != 0) + if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_GETMODIFY, 0, 0) != 0) { sprintf(text, "The text in the %s file has changed.\r\n\r\nDo you want to save the changes?", file ? file : "new"); - ans = MessageBox(hDlg, text, "UnrealIRCd", MB_YESNOCANCEL|MB_ICONWARNING); + ans = MessageBox(hDlg, text, "UnrealIRCd", MB_YESNOCANCEL | MB_ICONWARNING); if (ans == IDNO) newfile = TRUE; if (ans == IDCANCEL) return TRUE; - if (ans == IDYES) + if (ans == IDYES) { - SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDM_SAVE,0), 0); + SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDM_SAVE, 0), 0); newfile = TRUE; } - } - else + } else newfile = TRUE; - if (newfile == TRUE) + if (newfile == TRUE) { unsigned char szText[256]; file = NULL; @@ -701,7 +696,7 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar break; } break; - case WM_USER+10: + case WM_USER + 10: { HWND hWnd = GetDlgItem(hDlg, IDC_TEXT); EndDialog((HWND)lParam, TRUE); @@ -713,7 +708,7 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar SetFocus(hWnd); break; } - case WM_USER+11: + case WM_USER + 11: { HWND hWnd = GetDlgItem(hDlg, IDC_TEXT); EndDialog((HWND)lParam, TRUE); @@ -732,31 +727,30 @@ LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar SendMessage(hClip, WM_CHANGECBCHAIN, wParam, lParam); break; case WM_DRAWCLIPBOARD: - if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_CANPASTE, 0, 0)) - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(TRUE,0)); + if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_CANPASTE, 0, 0)) + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(TRUE, 0)); else - SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(FALSE,0)); + SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(FALSE, 0)); SendMessage(hClip, WM_DRAWCLIPBOARD, wParam, lParam); break; - case WM_CLOSE: + case WM_CLOSE: { unsigned char text[256]; int ans; - if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_GETMODIFY, 0, 0) != 0) + if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_GETMODIFY, 0, 0) != 0) { sprintf(text, "The text in the %s file has changed.\r\n\r\nDo you want to save the changes?", file ? file : "new"); - ans = MessageBox(hDlg, text, "UnrealIRCd", MB_YESNOCANCEL|MB_ICONWARNING); + ans = MessageBox(hDlg, text, "UnrealIRCd", MB_YESNOCANCEL | MB_ICONWARNING); if (ans == IDNO) EndDialog(hDlg, TRUE); if (ans == IDCANCEL) return TRUE; - if (ans == IDYES) + if (ans == IDYES) { - SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDM_SAVE,0), 0); + SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDM_SAVE, 0), 0); EndDialog(hDlg, TRUE); } - } - else + } else EndDialog(hDlg, TRUE); break; } diff --git a/src/windows/gui.c b/src/windows/gui.c index 7c23f5c62..eebe6239c 100644 --- a/src/windows/gui.c +++ b/src/windows/gui.c @@ -29,17 +29,16 @@ #include "win.h" #define TOOLBAR_START 82 -#define TOOLBAR_STOP (TOOLBAR_START+20) +#define TOOLBAR_STOP (TOOLBAR_START + 20) -__inline void ShowDialog(HWND *handle, HINSTANCE inst, char *template, HWND parent, - DLGPROC proc) +__inline void ShowDialog(HWND *handle, HINSTANCE inst, char *template, HWND parent, + DLGPROC proc) { - if (!IsWindow(*handle)) + if (!IsWindow(*handle)) { - *handle = CreateDialog(inst, template, parent, (DLGPROC)proc); + *handle = CreateDialog(inst, template, parent, (DLGPROC)proc); ShowWindow(*handle, SW_SHOW); - } - else + } else SetForegroundWindow(*handle); } @@ -75,10 +74,10 @@ unsigned char *errors = NULL; extern VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv); void CleanUp(void) { - Shell_NotifyIcon(NIM_DELETE ,&SysTray); + Shell_NotifyIcon(NIM_DELETE, &SysTray); } HWND hStatusWnd; -HWND hwIRCDWnd=NULL; +HWND hwIRCDWnd = NULL; HWND hwTreeView; HWND hWndMod; UINT WM_TASKBARCREATED, WM_FINDMSGSTRING; @@ -86,20 +85,20 @@ FARPROC lpfnOldWndProc; HMENU hContext; char OSName[OSVER_SIZE]; -void TaskBarCreated() +void TaskBarCreated() { - HICON hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(ICO_MAIN), IMAGE_ICON,16, 16, 0); + HICON hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(ICO_MAIN), IMAGE_ICON, 16, 16, 0); SysTray.cbSize = sizeof(NOTIFYICONDATA); SysTray.hIcon = hIcon; SysTray.hWnd = hwIRCDWnd; SysTray.uCallbackMessage = WM_USER; - SysTray.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE; + SysTray.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; SysTray.uID = 0; strcpy(SysTray.szTip, WIN32_VERSION); - Shell_NotifyIcon(NIM_ADD ,&SysTray); + Shell_NotifyIcon(NIM_ADD, &SysTray); } -LRESULT LinkSubClassFunc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) +LRESULT LinkSubClassFunc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { static HCURSOR hCursor; if (!hCursor) @@ -111,8 +110,7 @@ LRESULT LinkSubClassFunc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) } - -LRESULT RESubClassFunc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) +LRESULT RESubClassFunc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { POINT p; RECT r; @@ -122,42 +120,41 @@ LRESULT RESubClassFunc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) if (Message == WM_GETDLGCODE) return DLGC_WANTALLKEYS; - - if (Message == WM_CONTEXTMENU) + + if (Message == WM_CONTEXTMENU) { p.x = GET_X_LPARAM(lParam); p.y = GET_Y_LPARAM(lParam); - if (GET_X_LPARAM(lParam) == -1 && GET_Y_LPARAM(lParam) == -1) + if (GET_X_LPARAM(lParam) == -1 && GET_Y_LPARAM(lParam) == -1) { GetClientRect(hWnd, &r); - p.x = (int)((r.left + r.right)/2); - p.y = (int)((r.top + r.bottom)/2); - ClientToScreen(hWnd,&p); + p.x = (int)((r.left + r.right) / 2); + p.y = (int)((r.top + r.bottom) / 2); + ClientToScreen(hWnd, &p); } - if (!SendMessage(hWnd, EM_CANUNDO, 0, 0)) - EnableMenuItem(hContext, IDM_UNDO, MF_BYCOMMAND|MF_GRAYED); + if (!SendMessage(hWnd, EM_CANUNDO, 0, 0)) + EnableMenuItem(hContext, IDM_UNDO, MF_BYCOMMAND | MF_GRAYED); else - EnableMenuItem(hContext, IDM_UNDO, MF_BYCOMMAND|MF_ENABLED); - if (!SendMessage(hWnd, EM_CANPASTE, 0, 0)) - EnableMenuItem(hContext, IDM_PASTE, MF_BYCOMMAND|MF_GRAYED); + EnableMenuItem(hContext, IDM_UNDO, MF_BYCOMMAND | MF_ENABLED); + if (!SendMessage(hWnd, EM_CANPASTE, 0, 0)) + EnableMenuItem(hContext, IDM_PASTE, MF_BYCOMMAND | MF_GRAYED); else - EnableMenuItem(hContext, IDM_PASTE, MF_BYCOMMAND|MF_ENABLED); - if (GetWindowLong(hWnd, GWL_STYLE) & ES_READONLY) + EnableMenuItem(hContext, IDM_PASTE, MF_BYCOMMAND | MF_ENABLED); + if (GetWindowLong(hWnd, GWL_STYLE) & ES_READONLY) { - EnableMenuItem(hContext, IDM_CUT, MF_BYCOMMAND|MF_GRAYED); - EnableMenuItem(hContext, IDM_DELETE, MF_BYCOMMAND|MF_GRAYED); - } - else + EnableMenuItem(hContext, IDM_CUT, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(hContext, IDM_DELETE, MF_BYCOMMAND | MF_GRAYED); + } else { - EnableMenuItem(hContext, IDM_CUT, MF_BYCOMMAND|MF_ENABLED); - EnableMenuItem(hContext, IDM_DELETE, MF_BYCOMMAND|MF_ENABLED); + EnableMenuItem(hContext, IDM_CUT, MF_BYCOMMAND | MF_ENABLED); + EnableMenuItem(hContext, IDM_DELETE, MF_BYCOMMAND | MF_ENABLED); } SendMessage(hWnd, EM_GETSEL, (WPARAM)&start, (LPARAM)&end); - if (start == end) - EnableMenuItem(hContext, IDM_COPY, MF_BYCOMMAND|MF_GRAYED); + if (start == end) + EnableMenuItem(hContext, IDM_COPY, MF_BYCOMMAND | MF_GRAYED); else - EnableMenuItem(hContext, IDM_COPY, MF_BYCOMMAND|MF_ENABLED); - TrackPopupMenu(hContext,TPM_LEFTALIGN|TPM_RIGHTBUTTON,p.x,p.y,0,GetParent(hWnd),NULL); + EnableMenuItem(hContext, IDM_COPY, MF_BYCOMMAND | MF_ENABLED); + TrackPopupMenu(hContext, TPM_LEFTALIGN | TPM_RIGHTBUTTON, p.x, p.y, 0, GetParent(hWnd), NULL); return 0; } @@ -177,8 +174,8 @@ int DoCloseUnreal(HWND hWnd) int AskCloseUnreal(HWND hWnd) { - if (MessageBox(hWnd, "Close UnrealIRCd?", "Are you sure?", MB_YESNO|MB_ICONQUESTION) == IDNO) - return 0; + if (MessageBox(hWnd, "Close UnrealIRCd?", "Are you sure?", MB_YESNO | MB_ICONQUESTION) == IDNO) + return 0; DoCloseUnreal(hWnd); exit(0); } @@ -191,11 +188,11 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi HICON hIcon; SC_HANDLE hService, hSCManager; SERVICE_TABLE_ENTRY DispatchTable[] = { - { "UnrealIRCd", ServiceMain }, - { 0, 0 }, + {"UnrealIRCd", ServiceMain}, + {0, 0}, }; DWORD need; - + /* Go one level up, since we are currently in the bin\ subdir * and we want to be in (f.e.) "C:\Program Files\UnrealIRCd 6" */ @@ -221,7 +218,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi if (status.dwCurrentState != SERVICE_STOPPED) { ControlService(hService, - SERVICE_CONTROL_STOP, &status); + SERVICE_CONTROL_STOP, &status); while (status.dwCurrentState == SERVICE_STOP_PENDING) { QueryServiceStatus(hService, &status); @@ -238,7 +235,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi CloseServiceHandle(hSCManager); if (save_err != ERROR_SERVICE_DISABLED) exit(0); - } else { + } else + { CloseServiceHandle(hSCManager); } InitCommonControls(); @@ -249,32 +247,31 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi LoadLibrary("riched32.dll"); InitDebug(); init_winsock(); - hInst = hInstance; + hInst = hInstance; MainDlgBackground = CreateSolidBrush(RGB(75, 134, 238)); /* Background of main dialog */ - hWnd = CreateDialog(hInstance, "UnrealIRCd", 0, (DLGPROC)MainDLG); + hWnd = CreateDialog(hInstance, "UnrealIRCd", 0, (DLGPROC)MainDLG); hwIRCDWnd = hWnd; - + TaskBarCreated(); if (InitUnrealIRCd(__argc, __argv) != 1) { - MessageBox(NULL, "UnrealIRCd has failed to initialize in InitUnrealIRCd()", "UnrealIRCD Initalization Error" ,MB_OK); + MessageBox(NULL, "UnrealIRCd has failed to initialize in InitUnrealIRCd()", "UnrealIRCD Initalization Error", MB_OK); return FALSE; } ShowWindow(hWnd, SW_SHOW); _beginthread(SocketLoop, 0, NULL); while (GetMessage(&msg, NULL, 0, 0)) { - if (!IsWindow(hStatusWnd) || !IsDialogMessage(hStatusWnd, &msg)) + if (!IsWindow(hStatusWnd) || !IsDialogMessage(hStatusWnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return FALSE; - } LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) @@ -292,52 +289,52 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) TaskBarCreated(); return TRUE; } - + switch (message) { - case WM_INITDIALOG: + case WM_INITDIALOG: { ShowWindow(hDlg, SW_HIDE); hCursor = LoadCursor(hInst, MAKEINTRESOURCE(CUR_HAND)); - hContext = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_CONTEXT)),0); + hContext = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_CONTEXT)), 0); /* Rehash popup menu */ - hRehash = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_REHASH)),0); + hRehash = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_REHASH)), 0); /* About popup menu */ - hAbout = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_ABOUT)),0); + hAbout = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_ABOUT)), 0); /* Systray popup menu set the items to point to the other menus*/ - hTray = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_SYSTRAY)),0); - ModifyMenu(hTray, IDM_REHASH, MF_BYCOMMAND|MF_POPUP|MF_STRING, HandleToUlong(hRehash), "&Rehash"); - ModifyMenu(hTray, IDM_ABOUT, MF_BYCOMMAND|MF_POPUP|MF_STRING, HandleToUlong(hAbout), "&About"); - + hTray = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(MENU_SYSTRAY)), 0); + ModifyMenu(hTray, IDM_REHASH, MF_BYCOMMAND | MF_POPUP | MF_STRING, HandleToUlong(hRehash), "&Rehash"); + ModifyMenu(hTray, IDM_ABOUT, MF_BYCOMMAND | MF_POPUP | MF_STRING, HandleToUlong(hAbout), "&About"); + SetWindowText(hDlg, WIN32_VERSION); - SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, - (LPARAM)(HICON)LoadImage(hInst, MAKEINTRESOURCE(ICO_MAIN), IMAGE_ICON,16, 16, 0)); - SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_BIG, - (LPARAM)(HICON)LoadImage(hInst, MAKEINTRESOURCE(ICO_MAIN), IMAGE_ICON,32, 32, 0)); + SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, + (LPARAM)(HICON)LoadImage(hInst, MAKEINTRESOURCE(ICO_MAIN), IMAGE_ICON, 16, 16, 0)); + SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_BIG, + (LPARAM)(HICON)LoadImage(hInst, MAKEINTRESOURCE(ICO_MAIN), IMAGE_ICON, 32, 32, 0)); return TRUE; } case WM_CTLCOLORDLG: return (LONG)HandleToLong(MainDlgBackground); - case WM_SIZE: + case WM_SIZE: { if (wParam & SIZE_MINIMIZED) - ShowWindow(hDlg,SW_HIDE); + ShowWindow(hDlg, SW_HIDE); return 0; } - case WM_CLOSE: + case WM_CLOSE: return DoCloseUnreal(hDlg); - case WM_USER: + case WM_USER: { - switch(LOWORD(lParam)) + switch (LOWORD(lParam)) { case WM_LBUTTONDBLCLK: ShowWindow(hDlg, SW_SHOW); - ShowWindow(hDlg,SW_RESTORE); + ShowWindow(hDlg, SW_RESTORE); SetForegroundWindow(hDlg); case WM_RBUTTONDOWN: SetForegroundWindow(hDlg); break; - case WM_RBUTTONUP: + case WM_RBUTTONUP: { unsigned long i = 60000; MENUITEMINFO mii; @@ -367,8 +364,8 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) AppendMenu(hConfig, MF_STRING, IDM_BOTMOTD, conf_files->botmotd_file); AppendMenu(hConfig, MF_STRING, IDM_RULES, conf_files->rules_file); } - - if (conf_tld) + + if (conf_tld) { ConfigItem_tld *tlds; AppendMenu(hConfig, MF_SEPARATOR, 0, NULL); @@ -388,7 +385,7 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) mii.fMask = MIIM_SUBMENU; mii.hSubMenu = hConfig; SetMenuItemInfo(hTray, IDM_CONFIG, MF_BYCOMMAND, &mii); - TrackPopupMenu(hTray, TPM_LEFTALIGN|TPM_LEFTBUTTON,p.x,p.y,0,hDlg,NULL); + TrackPopupMenu(hTray, TPM_LEFTALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hDlg, NULL); /* Kludge for a win bug */ SendMessage(hDlg, WM_NULL, 0, 0); break; @@ -398,43 +395,41 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } case WM_DESTROY: return 0; - case WM_MOUSEMOVE: + case WM_MOUSEMOVE: { POINT p; p.x = LOWORD(lParam); p.y = HIWORD(lParam); - if ((p.x >= 93) && (p.x <= 150) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) + if ((p.x >= 93) && (p.x <= 150) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) SetCursor(hCursor); - else if ((p.x >= 160) && (p.x <= 208) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) + else if ((p.x >= 160) && (p.x <= 208) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) SetCursor(hCursor); - else if ((p.x >= 219) && (p.x <= 267) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) + else if ((p.x >= 219) && (p.x <= 267) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) SetCursor(hCursor); - else if ((p.x >= 279) && (p.x <= 325) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) + else if ((p.x >= 279) && (p.x <= 325) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) SetCursor(hCursor); - else if ((p.x >= 336) && (p.x <= 411) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) + else if ((p.x >= 336) && (p.x <= 411) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) SetCursor(hCursor); return 0; } - case WM_LBUTTONDOWN: + case WM_LBUTTONDOWN: { POINT p; p.x = LOWORD(lParam); p.y = HIWORD(lParam); if ((p.x >= 93) && (p.x <= 150) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) { - ClientToScreen(hDlg,&p); - TrackPopupMenu(hRehash,TPM_LEFTALIGN|TPM_LEFTBUTTON,p.x,p.y,0,hDlg,NULL); + ClientToScreen(hDlg, &p); + TrackPopupMenu(hRehash, TPM_LEFTALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hDlg, NULL); return 0; - } - else if ((p.x >= 160) && (p.x <= 208) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) + } else if ((p.x >= 160) && (p.x <= 208) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) { ShowDialog(&hStatusWnd, hInst, "Status", hDlg, StatusDLG); return 0; - } - else if ((p.x >= 219) && (p.x <= 267) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) + } else if ((p.x >= 219) && (p.x <= 267) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) { unsigned long i = 60000; - ClientToScreen(hDlg,&p); + ClientToScreen(hDlg, &p); DestroyMenu(hConfig); hConfig = CreatePopupMenu(); DestroyMenu(hLogs); @@ -461,8 +456,8 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) AppendMenu(hConfig, MF_STRING, IDM_BOTMOTD, conf_files->botmotd_file); AppendMenu(hConfig, MF_STRING, IDM_RULES, conf_files->rules_file); } - - if (conf_tld) + + if (conf_tld) { ConfigItem_tld *tlds; AppendMenu(hConfig, MF_SEPARATOR, 0, NULL); @@ -478,17 +473,15 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } AppendMenu(hConfig, MF_SEPARATOR, 0, NULL); AppendMenu(hConfig, MF_STRING, IDM_NEW, "New File"); - TrackPopupMenu(hConfig,TPM_LEFTALIGN|TPM_LEFTBUTTON,p.x,p.y,0,hDlg,NULL); + TrackPopupMenu(hConfig, TPM_LEFTALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hDlg, NULL); return 0; - } - else if ((p.x >= 279) && (p.x <= 325) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) + } else if ((p.x >= 279) && (p.x <= 325) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) { - ClientToScreen(hDlg,&p); - TrackPopupMenu(hAbout,TPM_LEFTALIGN|TPM_LEFTBUTTON,p.x,p.y,0,hDlg,NULL); + ClientToScreen(hDlg, &p); + TrackPopupMenu(hAbout, TPM_LEFTALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hDlg, NULL); return 0; - } - else if ((p.x >= 336) && (p.x <= 411) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) + } else if ((p.x >= 336) && (p.x <= 411) && (p.y >= TOOLBAR_START) && (p.y <= TOOLBAR_STOP)) return AskCloseUnreal(hDlg); } case WM_SYSCOMMAND: @@ -500,17 +493,17 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } break; } - case WM_COMMAND: + case WM_COMMAND: { - if (LOWORD(wParam) >= 60000 && HIWORD(wParam) == 0 && !lParam) + if (LOWORD(wParam) >= 60000 && HIWORD(wParam) == 0 && !lParam) { unsigned char path[MAX_PATH]; if (GetMenuString(hLogs, LOWORD(wParam), path, MAX_PATH, MF_BYCOMMAND)) DialogBoxParam(hInst, "FromVar", hDlg, (DLGPROC)FromFileReadDLG, (LPARAM)path); - - else + + else { - GetMenuString(hConfig,LOWORD(wParam), path, MAX_PATH, MF_BYCOMMAND); + GetMenuString(hConfig, LOWORD(wParam), path, MAX_PATH, MF_BYCOMMAND); if (!url_is_valid(path)) DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, (LPARAM)path); } @@ -522,14 +515,14 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) MessageBox(NULL, "UnrealIRCd not booted due to configuration errors. " "Check other window for error details. Then close that window, " "fix the errors and start UnrealIRCd again.", - "UnrealIRCd not started", - MB_OK); + "UnrealIRCd not started", + MB_OK); return FALSE; } - switch(LOWORD(wParam)) + switch (LOWORD(wParam)) { case IDM_STATUS: - ShowDialog(&hStatusWnd, hInst, "Status", hDlg,StatusDLG); + ShowDialog(&hStatusWnd, hInst, "Status", hDlg, StatusDLG); break; case IDM_SHUTDOWN: return AskCloseUnreal(hDlg); @@ -537,7 +530,7 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) MessageBox(NULL, "Rehashing all files", "Rehashing", MB_OK); dorehash = 1; break; - case IDM_LICENSE: + case IDM_LICENSE: DialogBox(hInst, "FromVar", hDlg, (DLGPROC)LicenseDLG); break; case IDM_INFO: @@ -550,28 +543,28 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) DialogBox(hInst, "Help", hDlg, (DLGPROC)HelpDLG); break; case IDM_CONF: - DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, - (LPARAM)CPATH); + DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, + (LPARAM)CPATH); break; case IDM_MOTD: - DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, - (LPARAM)conf_files->motd_file); + DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, + (LPARAM)conf_files->motd_file); break; case IDM_SMOTD: - DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, - (LPARAM)conf_files->smotd_file); + DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, + (LPARAM)conf_files->smotd_file); break; case IDM_OPERMOTD: DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, - (LPARAM)conf_files->opermotd_file); + (LPARAM)conf_files->opermotd_file); break; case IDM_BOTMOTD: DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, - (LPARAM)conf_files->botmotd_file); + (LPARAM)conf_files->botmotd_file); break; case IDM_RULES: DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, - (LPARAM)conf_files->rules_file); + (LPARAM)conf_files->rules_file); break; case IDM_NEW: DialogBoxParam(hInst, "FromFile", hDlg, (DLGPROC)FromFileDLG, (LPARAM)NULL); @@ -582,28 +575,28 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return FALSE; } -LRESULT CALLBACK LicenseDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK LicenseDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { return FromVarDLG(hDlg, message, wParam, lParam, "UnrealIRCd License", gnulicense); } -LRESULT CALLBACK InfoDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK InfoDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { return FromVarDLG(hDlg, message, wParam, lParam, "UnrealIRCd Team", unrealinfo); } -LRESULT CALLBACK CreditsDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK CreditsDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { return FromVarDLG(hDlg, message, wParam, lParam, "UnrealIRCd Credits", unrealcredits); } LRESULT CALLBACK FromVarDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam, - unsigned char *title, unsigned char **s) + unsigned char *title, unsigned char **s) { HWND hWnd; - switch (message) + switch (message) { - case WM_INITDIALOG: + case WM_INITDIALOG: { #if 0 unsigned char String[16384]; @@ -638,37 +631,37 @@ LRESULT CALLBACK FromVarDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPara #endif } - case WM_COMMAND: + case WM_COMMAND: { hWnd = GetDlgItem(hDlg, IDC_TEXT); if (LOWORD(wParam) == IDOK) return EndDialog(hDlg, TRUE); - if (LOWORD(wParam) == IDM_COPY) + if (LOWORD(wParam) == IDM_COPY) { SendMessage(hWnd, WM_COPY, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_SELECTALL) + if (LOWORD(wParam) == IDM_SELECTALL) { SendMessage(hWnd, EM_SETSEL, 0, -1); return 0; } - if (LOWORD(wParam) == IDM_PASTE) + if (LOWORD(wParam) == IDM_PASTE) { SendMessage(hWnd, WM_PASTE, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_CUT) + if (LOWORD(wParam) == IDM_CUT) { SendMessage(hWnd, WM_CUT, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_UNDO) + if (LOWORD(wParam) == IDM_UNDO) { SendMessage(hWnd, EM_UNDO, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_DELETE) + if (LOWORD(wParam) == IDM_DELETE) { SendMessage(hWnd, WM_CLEAR, 0, 0); return 0; @@ -684,14 +677,14 @@ LRESULT CALLBACK FromVarDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPara return (FALSE); } -LRESULT CALLBACK FromFileReadDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK FromFileReadDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hWnd; - switch (message) + switch (message) { - case WM_INITDIALOG: + case WM_INITDIALOG: { - int fd,len; + int fd, len; unsigned char *buffer = '\0', *string = '\0'; EDITSTREAM edit; StreamIO *stream = safe_alloc(sizeof(StreamIO)); @@ -701,17 +694,17 @@ LRESULT CALLBACK FromFileReadDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM StringCbPrintf(szText, sizeof(szText), "UnrealIRCd Viewer - %s", (unsigned char *)lParam); SetWindowText(hDlg, szText); lpfnOldWndProc = (FARPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)RESubClassFunc); - if ((fd = open((unsigned char *)lParam, _O_RDONLY|_O_BINARY)) != -1) + if ((fd = open((unsigned char *)lParam, _O_RDONLY | _O_BINARY)) != -1) { - fstat(fd,&sb); + fstat(fd, &sb); /* Only allocate the amount we need */ - buffer = safe_alloc(sb.st_size+1); + buffer = safe_alloc(sb.st_size + 1); buffer[0] = 0; - len = read(fd, buffer, sb.st_size); + len = read(fd, buffer, sb.st_size); buffer[len] = 0; - len = CountRTFSize(buffer)+1; + len = CountRTFSize(buffer) + 1; string = safe_alloc(len); - IRCToRTF(buffer,string); + IRCToRTF(buffer, string); RTFBuf = string; len--; stream->size = &len; @@ -719,7 +712,7 @@ LRESULT CALLBACK FromFileReadDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM edit.dwCookie = (DWORD_PTR)stream; edit.pfnCallback = SplitIt; SendMessage(hWnd, EM_EXLIMITTEXT, 0, (LPARAM)0x7FFFFFFF); - SendMessage(hWnd, EM_STREAMIN, (WPARAM)SF_RTF|SFF_PLAINRTF, (LPARAM)&edit); + SendMessage(hWnd, EM_STREAMIN, (WPARAM)SF_RTF | SFF_PLAINRTF, (LPARAM)&edit); close(fd); RTFBuf = NULL; safe_free(buffer); @@ -728,37 +721,37 @@ LRESULT CALLBACK FromFileReadDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM } return TRUE; } - case WM_COMMAND: + case WM_COMMAND: { hWnd = GetDlgItem(hDlg, IDC_TEXT); if (LOWORD(wParam) == IDOK) return EndDialog(hDlg, TRUE); - if (LOWORD(wParam) == IDM_COPY) + if (LOWORD(wParam) == IDM_COPY) { SendMessage(hWnd, WM_COPY, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_SELECTALL) + if (LOWORD(wParam) == IDM_SELECTALL) { SendMessage(hWnd, EM_SETSEL, 0, -1); return 0; } - if (LOWORD(wParam) == IDM_PASTE) + if (LOWORD(wParam) == IDM_PASTE) { SendMessage(hWnd, WM_PASTE, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_CUT) + if (LOWORD(wParam) == IDM_CUT) { SendMessage(hWnd, WM_CUT, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_UNDO) + if (LOWORD(wParam) == IDM_UNDO) { SendMessage(hWnd, EM_UNDO, 0, 0); return 0; } - if (LOWORD(wParam) == IDM_DELETE) + if (LOWORD(wParam) == IDM_DELETE) { SendMessage(hWnd, WM_CLEAR, 0, 0); return 0; @@ -774,35 +767,35 @@ LRESULT CALLBACK FromFileReadDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM return FALSE; } -LRESULT CALLBACK HelpDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK HelpDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HFONT hFont; static HCURSOR hCursor; - switch (message) + switch (message) { case WM_INITDIALOG: hCursor = LoadCursor(hInst, MAKEINTRESOURCE(CUR_HAND)); - hFont = CreateFont(8,0,0,0,0,0,1,0,ANSI_CHARSET,0,0,PROOF_QUALITY,0,"MS Sans Serif"); - SendMessage(GetDlgItem(hDlg, IDC_EMAIL), WM_SETFONT, (WPARAM)hFont,TRUE); - SendMessage(GetDlgItem(hDlg, IDC_URL), WM_SETFONT, (WPARAM)hFont,TRUE); + hFont = CreateFont(8, 0, 0, 0, 0, 0, 1, 0, ANSI_CHARSET, 0, 0, PROOF_QUALITY, 0, "MS Sans Serif"); + SendMessage(GetDlgItem(hDlg, IDC_EMAIL), WM_SETFONT, (WPARAM)hFont, TRUE); + SendMessage(GetDlgItem(hDlg, IDC_URL), WM_SETFONT, (WPARAM)hFont, TRUE); lpfnOldWndProc = (FARPROC)SetWindowLongPtr(GetDlgItem(hDlg, IDC_EMAIL), GWLP_WNDPROC, (LONG_PTR)LinkSubClassFunc); SetWindowLongPtr(GetDlgItem(hDlg, IDC_URL), GWLP_WNDPROC, (LONG_PTR)LinkSubClassFunc); return TRUE; - case WM_DRAWITEM: + case WM_DRAWITEM: { LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam; unsigned char text[500]; COLORREF oldtext; RECT focus; GetWindowText(lpdis->hwndItem, text, 500); - if (wParam == IDC_URL || IDC_EMAIL) + if (wParam == IDC_URL || IDC_EMAIL) { FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_3DFACE)); - oldtext = SetTextColor(lpdis->hDC, RGB(0,0,255)); - DrawText(lpdis->hDC, text, strlen(text), &lpdis->rcItem, DT_CENTER|DT_VCENTER); + oldtext = SetTextColor(lpdis->hDC, RGB(0, 0, 255)); + DrawText(lpdis->hDC, text, strlen(text), &lpdis->rcItem, DT_CENTER | DT_VCENTER); SetTextColor(lpdis->hDC, oldtext); - if (lpdis->itemState & ODS_FOCUS) + if (lpdis->itemState & ODS_FOCUS) { CopyRect(&focus, &lpdis->rcItem); focus.left += 2; @@ -813,18 +806,18 @@ LRESULT CALLBACK HelpDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } return TRUE; } - } + } case WM_COMMAND: if (LOWORD(wParam) == IDOK) EndDialog(hDlg, TRUE); - if (HIWORD(wParam) == BN_DBLCLK) + if (HIWORD(wParam) == BN_DBLCLK) { - if (LOWORD(wParam) == IDC_URL) - ShellExecute(NULL, "open", "https://www.unrealircd.org", NULL, NULL, - SW_MAXIMIZE); + if (LOWORD(wParam) == IDC_URL) + ShellExecute(NULL, "open", "https://www.unrealircd.org", NULL, NULL, + SW_MAXIMIZE); else if (LOWORD(wParam) == IDC_EMAIL) - ShellExecute(NULL, "open", "mailto:unreal-users@lists.sourceforge.net", NULL, NULL, - SW_MAXIMIZE); + ShellExecute(NULL, "open", "mailto:unreal-users@lists.sourceforge.net", NULL, NULL, + SW_MAXIMIZE); EndDialog(hDlg, TRUE); return 0; } @@ -835,23 +828,16 @@ LRESULT CALLBACK HelpDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_DESTROY: DeleteObject(hFont); break; - } return FALSE; } - - - - - - -LRESULT CALLBACK StatusDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK StatusDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) + switch (message) { - case WM_INITDIALOG: + case WM_INITDIALOG: { hwTreeView = GetDlgItem(hDlg, IDC_TREE); win_map(&me, hwTreeView, 0); @@ -864,7 +850,7 @@ LRESULT CALLBACK StatusDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam if (irccounts.clients > irccounts.global_max) irccounts.global_max = irccounts.clients; if (irccounts.me_clients > irccounts.me_max) - irccounts.me_max = irccounts.me_clients; + irccounts.me_max = irccounts.me_clients; SetDlgItemInt(hDlg, IDC_MAXCLIENTS, irccounts.global_max, FALSE); SetDlgItemInt(hDlg, IDC_LCLIENTS, irccounts.me_clients, FALSE); SetDlgItemInt(hDlg, IDC_LSERVERS, irccounts.me_servers, FALSE); @@ -888,7 +874,7 @@ LRESULT CALLBACK StatusDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam if (irccounts.clients > irccounts.global_max) irccounts.global_max = irccounts.clients; if (irccounts.me_clients > irccounts.me_max) - irccounts.me_max = irccounts.me_clients; + irccounts.me_max = irccounts.me_clients; SetDlgItemInt(hDlg, IDC_MAXCLIENTS, irccounts.global_max, FALSE); SetDlgItemInt(hDlg, IDC_LCLIENTS, irccounts.me_clients, FALSE); SetDlgItemInt(hDlg, IDC_LSERVERS, irccounts.me_servers, FALSE); @@ -896,13 +882,12 @@ LRESULT CALLBACK StatusDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam SetTimer(hDlg, 1, 5000, NULL); return TRUE; case WM_COMMAND: - if (LOWORD(wParam) == IDOK) + if (LOWORD(wParam) == IDOK) { DestroyWindow(hDlg); return TRUE; } break; - } return FALSE; } @@ -911,39 +896,39 @@ LRESULT CALLBACK StatusDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam HTREEITEM AddItemToTree(HWND hWnd, LPSTR lpszItem, int nLevel, short remap) { - TVITEM tvi; - TVINSERTSTRUCT tvins; - static HTREEITEM hPrev = (HTREEITEM)TVI_FIRST; - static HTREEITEM hPrevLev[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; - HTREEITEM hti; + TVITEM tvi; + TVINSERTSTRUCT tvins; + static HTREEITEM hPrev = (HTREEITEM)TVI_FIRST; + static HTREEITEM hPrevLev[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + HTREEITEM hti; - if (remap) + if (remap) { hPrev = (HTREEITEM)TVI_FIRST; - memset(hPrevLev, 0, sizeof(HTREEITEM)*10); + memset(hPrevLev, 0, sizeof(HTREEITEM) * 10); } - - tvi.mask = TVIF_TEXT|TVIF_PARAM; - tvi.pszText = lpszItem; - tvi.cchTextMax = lstrlen(lpszItem); - tvi.lParam = (LPARAM)nLevel; - tvins.item = tvi; - tvins.hInsertAfter = hPrev; - if (nLevel == 1) - tvins.hParent = TVI_ROOT; - else - tvins.hParent = hPrevLev[nLevel-1]; - hPrev = (HTREEITEM)SendMessage(hWnd, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT) &tvins); + + tvi.mask = TVIF_TEXT | TVIF_PARAM; + tvi.pszText = lpszItem; + tvi.cchTextMax = lstrlen(lpszItem); + tvi.lParam = (LPARAM)nLevel; + tvins.item = tvi; + tvins.hInsertAfter = hPrev; + if (nLevel == 1) + tvins.hParent = TVI_ROOT; + else + tvins.hParent = hPrevLev[nLevel - 1]; + hPrev = (HTREEITEM)SendMessage(hWnd, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvins); hPrevLev[nLevel] = hPrev; - TreeView_EnsureVisible(hWnd,hPrev); - if (nLevel > 1) - { - hti = TreeView_GetParent(hWnd, hPrev); - tvi.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE; - tvi.hItem = hti; - TreeView_SetItem(hWnd, &tvi); - } - return hPrev; + TreeView_EnsureVisible(hWnd, hPrev); + if (nLevel > 1) + { + hti = TreeView_GetParent(hWnd, hPrev); + tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; + tvi.hItem = hti; + TreeView_SetItem(hWnd, &tvi); + } + return hPrev; } /* @@ -983,23 +968,21 @@ void win_log(FORMAT_STRING(const char *format), ...) ircvsnprintf(buf, sizeof(buf), format, ap); stripcrlf(buf); - if (!IsService) + if (!IsService) { strcat(buf, "\r\n"); - if (errors) + if (errors) { char *tbuf = safe_alloc(strlen(errors) + strlen(buf) + 1); strcpy(tbuf, errors); strcat(tbuf, buf); safe_free(errors); errors = tbuf; - } - else + } else { safe_strdup(errors, buf); } - } - else + } else { FILE *fd = fopen("logs\\service.log", "a"); if (fd) @@ -1019,15 +1002,15 @@ void win_log(FORMAT_STRING(const char *format), ...) va_end(ap); } -void win_error() +void win_error() { if (errors && !IsService) DialogBox(hInst, "ConfigError", hwIRCDWnd, (DLGPROC)ConfigErrorDLG); } -LRESULT CALLBACK ConfigErrorDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK ConfigErrorDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) + switch (message) { case WM_INITDIALOG: MessageBeep(MB_ICONEXCLAMATION); @@ -1044,7 +1027,6 @@ LRESULT CALLBACK ConfigErrorDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM l break; case WM_DESTROY: break; - - } + } return (FALSE); } diff --git a/src/windows/resource.h b/src/windows/resource.h index da92043ea..a0c151429 100644 --- a/src/windows/resource.h +++ b/src/windows/resource.h @@ -2,107 +2,107 @@ // Microsoft Developer Studio generated include file. // Used by Win32GUI.rc // -#define VER_UNREAL 1 -#define MANIFEST_RESOURCE_ID 2 -#define ICO_MAIN 129 -#define BMP_LOGO 130 -#define BMP_BAR 133 -#define CUR_HAND 136 -#define MENU_ABOUT 137 -#define MENU_CONFIG 141 -#define MENU_REHASH 144 -#define MENU_SYSTRAY 145 -#define MENU_CONTEXT 146 -#define IDB_BITMAP1 150 -#define IDC_BAR 1103 -#define IDC_TOOLBAR 1104 -#define IDC_STATUS 1105 -#define IDC_TEXT 1107 -#define IDC_EMAIL 1108 -#define IDC_URL 1109 -#define IDC_TREE 1111 -#define IDC_CHANNELS 1112 -#define IDC_CLIENTS 1113 -#define IDC_SERVERS 1114 -#define IDC_INVISO 1115 -#define IDC_OPERS 1116 -#define IDC_UNKNOWN 1117 -#define IDC_MAXCLIENTS 1118 -#define IDC_LCLIENTS 1122 -#define IDC_LSERVERS 1123 -#define IDC_LMAXCLIENTS 1124 -#define IDC_UPTIME 1125 -#define IDC_CONFIGERROR 1126 -#define IDC_BOLD 1130 -#define IDC_UNDERLINE 1131 -#define IDC_FIND 1132 -#define IDFIND 1133 -#define IDC_FINDTEXT 1135 -#define IDC_GOTO 1135 -#define IDC_MATCHWHOLE 1137 -#define IDC_MATCHCASE 1138 -#define IDC_DIRUP 1139 -#define IDC_DIRDOWN 1140 -#define IDC_COLOR 1141 -#define IDC_BGCOLOR 1142 -#define IDC_WHITE 1163 -#define IDC_BLACK 1164 -#define IDC_DARKBLUE 1165 -#define IDC_DARKGREEN 1166 -#define IDC_PASS 1166 -#define IDC_RED 1167 -#define IDC_DARKRED 1168 -#define IDC_PURPLE 1169 -#define IDC_ORANGE 1170 -#define IDC_YELLOW 1171 -#define IDC_GREEN 1172 -#define IDC_VDARKGREEN 1173 -#define IDC_LIGHTBLUE 1174 -#define IDC_BLUE 1175 -#define IDC_PINK 1176 -#define IDC_DARKGRAY 1177 -#define IDC_GRAY 1178 -#define IDM_INFO 40026 -#define IDM_CREDITS 40027 -#define IDM_DAL 40028 -#define IDM_LICENSE 40029 -#define IDM_HELP 40030 -#define IDM_SAVE 40031 -#define IDM_REDO 40032 -#define IDM_SMOTD 40036 -#define IDM_CONF 40037 -#define IDM_MOTD 40038 -#define IDM_BOTMOTD 40039 -#define IDM_OPERMOTD 40040 -#define IDM_RULES 40041 -#define IDM_RHALL 40042 -#define IDM_RHCONF 40044 -#define IDM_RHMOTD 40045 -#define IDM_RHOMOTD 40046 -#define IDM_RHBMOTD 40047 -#define IDM_RHRULES 40048 -#define IDM_REHASH 40049 -#define IDM_STATUS 40050 -#define IDM_CONFIG 40051 -#define IDM_ABOUT 40052 -#define IDM_SHUTDOWN 40053 -#define IDM_UNDO 40054 -#define IDM_CUT 40055 -#define IDM_COPY 40056 -#define IDM_PASTE 40057 -#define IDM_DELETE 40058 -#define IDM_SELECTALL 40059 -#define IDM_NEW 40060 -#define IDC_STATIC -1 +#define VER_UNREAL 1 +#define MANIFEST_RESOURCE_ID 2 +#define ICO_MAIN 129 +#define BMP_LOGO 130 +#define BMP_BAR 133 +#define CUR_HAND 136 +#define MENU_ABOUT 137 +#define MENU_CONFIG 141 +#define MENU_REHASH 144 +#define MENU_SYSTRAY 145 +#define MENU_CONTEXT 146 +#define IDB_BITMAP1 150 +#define IDC_BAR 1103 +#define IDC_TOOLBAR 1104 +#define IDC_STATUS 1105 +#define IDC_TEXT 1107 +#define IDC_EMAIL 1108 +#define IDC_URL 1109 +#define IDC_TREE 1111 +#define IDC_CHANNELS 1112 +#define IDC_CLIENTS 1113 +#define IDC_SERVERS 1114 +#define IDC_INVISO 1115 +#define IDC_OPERS 1116 +#define IDC_UNKNOWN 1117 +#define IDC_MAXCLIENTS 1118 +#define IDC_LCLIENTS 1122 +#define IDC_LSERVERS 1123 +#define IDC_LMAXCLIENTS 1124 +#define IDC_UPTIME 1125 +#define IDC_CONFIGERROR 1126 +#define IDC_BOLD 1130 +#define IDC_UNDERLINE 1131 +#define IDC_FIND 1132 +#define IDFIND 1133 +#define IDC_FINDTEXT 1135 +#define IDC_GOTO 1135 +#define IDC_MATCHWHOLE 1137 +#define IDC_MATCHCASE 1138 +#define IDC_DIRUP 1139 +#define IDC_DIRDOWN 1140 +#define IDC_COLOR 1141 +#define IDC_BGCOLOR 1142 +#define IDC_WHITE 1163 +#define IDC_BLACK 1164 +#define IDC_DARKBLUE 1165 +#define IDC_DARKGREEN 1166 +#define IDC_PASS 1166 +#define IDC_RED 1167 +#define IDC_DARKRED 1168 +#define IDC_PURPLE 1169 +#define IDC_ORANGE 1170 +#define IDC_YELLOW 1171 +#define IDC_GREEN 1172 +#define IDC_VDARKGREEN 1173 +#define IDC_LIGHTBLUE 1174 +#define IDC_BLUE 1175 +#define IDC_PINK 1176 +#define IDC_DARKGRAY 1177 +#define IDC_GRAY 1178 +#define IDM_INFO 40026 +#define IDM_CREDITS 40027 +#define IDM_DAL 40028 +#define IDM_LICENSE 40029 +#define IDM_HELP 40030 +#define IDM_SAVE 40031 +#define IDM_REDO 40032 +#define IDM_SMOTD 40036 +#define IDM_CONF 40037 +#define IDM_MOTD 40038 +#define IDM_BOTMOTD 40039 +#define IDM_OPERMOTD 40040 +#define IDM_RULES 40041 +#define IDM_RHALL 40042 +#define IDM_RHCONF 40044 +#define IDM_RHMOTD 40045 +#define IDM_RHOMOTD 40046 +#define IDM_RHBMOTD 40047 +#define IDM_RHRULES 40048 +#define IDM_REHASH 40049 +#define IDM_STATUS 40050 +#define IDM_CONFIG 40051 +#define IDM_ABOUT 40052 +#define IDM_SHUTDOWN 40053 +#define IDM_UNDO 40054 +#define IDM_CUT 40055 +#define IDM_COPY 40056 +#define IDM_PASTE 40057 +#define IDM_DELETE 40058 +#define IDM_SELECTALL 40059 +#define IDM_NEW 40060 +#define IDC_STATIC -1 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 152 -#define _APS_NEXT_COMMAND_VALUE 40061 -#define _APS_NEXT_CONTROL_VALUE 1167 -#define _APS_NEXT_SYMED_VALUE 104 -#endif + #ifndef APSTUDIO_READONLY_SYMBOLS + #define _APS_NO_MFC 1 + #define _APS_NEXT_RESOURCE_VALUE 152 + #define _APS_NEXT_COMMAND_VALUE 40061 + #define _APS_NEXT_CONTROL_VALUE 1167 + #define _APS_NEXT_SYMED_VALUE 104 + #endif #endif diff --git a/src/windows/rtf.c b/src/windows/rtf.c index 0ec9564c4..7af2eafae 100644 --- a/src/windows/rtf.c +++ b/src/windows/rtf.c @@ -35,21 +35,19 @@ unsigned char *RTFBuf; */ DWORD CALLBACK SplitIt(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { - StreamIO *stream = (StreamIO*)dwCookie; + StreamIO *stream = (StreamIO *)dwCookie; if (*stream->size == 0) { pcb = 0; *stream->buffer = 0; - } - else if (cb <= *stream->size) + } else if (cb <= *stream->size) { memcpy(pbBuff, *stream->buffer, cb); *stream->buffer += cb; *stream->size -= cb; *pcb = cb; - } - else + } else { memcpy(pbBuff, *stream->buffer, *stream->size); *pcb = *stream->size; @@ -76,12 +74,12 @@ DWORD CALLBACK BufferIt(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) if (!RTFBuf) size = 0; - buf2 = safe_alloc(size+cb+1); + buf2 = safe_alloc(size + cb + 1); if (RTFBuf) - memcpy(buf2,RTFBuf,size); + memcpy(buf2, RTFBuf, size); - memcpy(buf2+size,pbBuff,cb); + memcpy(buf2 + size, pbBuff, cb); size += cb; safe_free(RTFBuf); @@ -115,7 +113,7 @@ void ColorPop(IRCColor **stack) if (!(*stack)) return; safe_free(p->color); - + *stack = p->next; safe_free(p); } @@ -143,16 +141,16 @@ void ColorEmpty(IRCColor **stack) * pbBuff - The buffer containing the RTF text * cb - The length of the RTF text */ -DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) +DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) { - unsigned char *buffer = safe_alloc(cb*2+2); + unsigned char *buffer = safe_alloc(cb * 2 + 2); int colors[17], bold = 0, uline = 0, incolor = 0, inbg = 0; int lastwascf = 0, lastwascf0 = 0; int i = 0; IRCColor *TextColors = NULL; IRCColor *BgColors = NULL; - + memset(buffer, 0, cb); for (; *pbBuff; pbBuff++) @@ -172,16 +170,16 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) ultr[0] = *(++pbBuff); ultr[1] = *(++pbBuff); ultr[2] = 0; - ltr = strtoul(ultr,NULL,16); + ltr = strtoul(ultr, NULL, 16); buffer[i++] = ltr; - } - else + } else { int j; char cmd[128]; /* Capture the control sequence */ for (j = 0; *pbBuff && *pbBuff != '\\' && !isspace(*pbBuff) && - !iseol(*pbBuff); pbBuff++) + !iseol(*pbBuff); + pbBuff++) { cmd[j++] = *pbBuff; } @@ -206,7 +204,7 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) { if (*pbBuff == ';') { - color[k]=0; + color[k] = 0; if (!strcmp(color, "\\red255\\green255\\blue255")) colors[m++] = 0; else if (!strcmp(color, "\\red0\\green0\\blue0")) @@ -237,27 +235,24 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) colors[m++] = 13; else if (!strcmp(color, "\\red127\\green127\\blue127")) colors[m++] = 14; - else if (!strcmp(color, "\\red210\\green210\\blue210")) + else if (!strcmp(color, "\\red210\\green210\\blue210")) colors[m++] = 15; - k=0; - } - else + k = 0; + } else color[k++] = *pbBuff; } lastwascf = lastwascf0 = 0; - } - else if (!strcmp(cmd, "tab")) + } else if (!strcmp(cmd, "tab")) { buffer[i++] = '\t'; lastwascf = lastwascf0 = 0; - } - else if (!strcmp(cmd, "par")) + } else if (!strcmp(cmd, "par")) { if (bold || uline || incolor || inbg) buffer[i++] = '\17'; buffer[i++] = '\r'; buffer[i++] = '\n'; - if (!*(pbBuff+3) || *(pbBuff+3) != '}') + if (!*(pbBuff + 3) || *(pbBuff + 3) != '}') { if (bold) buffer[i++] = '\2'; @@ -274,8 +269,7 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) strcat(buffer, BgColors->color); i += strlen(BgColors->color); } - } - else if (inbg) + } else if (inbg) { buffer[i++] = '\3'; buffer[i++] = '0'; @@ -285,37 +279,31 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) i += strlen(BgColors->color); } } - } - else if (!strcmp(cmd, "b")) + } else if (!strcmp(cmd, "b")) { bold = 1; buffer[i++] = '\2'; lastwascf = lastwascf0 = 0; - } - else if (!strcmp(cmd, "b0")) + } else if (!strcmp(cmd, "b0")) { bold = 0; buffer[i++] = '\2'; lastwascf = lastwascf0 = 0; - } - else if (!strcmp(cmd, "ul")) + } else if (!strcmp(cmd, "ul")) { uline = 1; buffer[i++] = '\37'; lastwascf = lastwascf0 = 0; - } - else if (!strcmp(cmd, "ulnone")) + } else if (!strcmp(cmd, "ulnone")) { uline = 0; buffer[i++] = '\37'; lastwascf = lastwascf0 = 0; - } - else if (!strcmp(cmd, "cf0")) + } else if (!strcmp(cmd, "cf0")) { lastwascf0 = 1; lastwascf = 0; - } - else if (!strcmp(cmd, "highlight0")) + } else if (!strcmp(cmd, "highlight0")) { inbg = 0; ColorPop(&BgColors); @@ -325,8 +313,7 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) incolor = 0; ColorPop(&TextColors); lastwascf0 = 0; - } - else if (incolor) + } else if (incolor) { strcat(buffer, TextColors->color); i += strlen(TextColors->color); @@ -335,8 +322,7 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) buffer[i++] = '0'; } lastwascf = lastwascf0 = 0; - } - else if (!strncmp(cmd, "cf", 2)) + } else if (!strncmp(cmd, "cf", 2)) { unsigned char number[3]; int num; @@ -349,12 +335,11 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) else sprintf(number, "%d", colors[num]); ColorPush(number, &TextColors); - strcat(buffer,number); + strcat(buffer, number); i += strlen(number); lastwascf = 1; lastwascf0 = 0; - } - else if (!strncmp(cmd, "highlight", 9)) + } else if (!strncmp(cmd, "highlight", 9)) { int num; unsigned char number[3]; @@ -369,8 +354,7 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) buffer[i++] = '\3'; strcat(buffer, TextColors->color); i += strlen(TextColors->color); - } - else if (!incolor) + } else if (!incolor) { buffer[i++] = '\3'; buffer[i++] = '0'; @@ -381,8 +365,7 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) i += strlen(number); ColorPush(number, &BgColors); lastwascf = lastwascf0 = 0; - } - else + } else lastwascf = lastwascf0 = 0; if (lastwascf0 && incolor) @@ -392,13 +375,11 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) buffer[i++] = '\3'; } } - } - else + } else { lastwascf = lastwascf0 = 0; buffer[i++] = *pbBuff; } - } write(fd, buffer, i); close(fd); @@ -413,18 +394,19 @@ DWORD CALLBACK RTFToIRC(int fd, unsigned char *pbBuff, long cb) * Returns: * The lenght of the buffer needed to store the RTF translation */ -int CountRTFSize(unsigned char *buffer) { +int CountRTFSize(unsigned char *buffer) +{ int size = 0; char bold = 0, uline = 0, incolor = 0, inbg = 0, reverse = 0; char *buf = buffer; - for (; *buf; buf++) + for (; *buf; buf++) { if (*buf == '{' || *buf == '}' || *buf == '\\') size++; else if (*buf == '\r') { - if (*(buf+1) && *(buf+1) == '\n') + if (*(buf + 1) && *(buf + 1) == '\n') { buf++; if (bold) @@ -440,11 +422,10 @@ int CountRTFSize(unsigned char *buffer) { if (bold || uline || incolor || inbg || reverse) size++; bold = uline = incolor = inbg = reverse = 0; - size +=6; + size += 6; continue; } - } - else if (*buf == '\n') + } else if (*buf == '\n') { if (bold) size += 3; @@ -459,10 +440,9 @@ int CountRTFSize(unsigned char *buffer) { if (bold || uline || incolor || inbg || reverse) size++; bold = uline = incolor = inbg = reverse = 0; - size +=6; - continue; - } - else if (*buf == '\2') + size += 6; + continue; + } else if (*buf == '\2') { if (bold) size += 4; @@ -470,30 +450,28 @@ int CountRTFSize(unsigned char *buffer) { size += 3; bold = !bold; continue; - } - else if (*buf == '\3' && reverse) + } else if (*buf == '\3' && reverse) { - if (*(buf+1) && isdigit(*(buf+1))) + if (*(buf + 1) && isdigit(*(buf + 1))) { ++buf; - if (*(buf+1) && isdigit(*(buf+1))) + if (*(buf + 1) && isdigit(*(buf + 1))) ++buf; - if (*(buf+1) && *(buf+1) == ',') + if (*(buf + 1) && *(buf + 1) == ',') { - if (*(buf+2) && isdigit(*(buf+2))) + if (*(buf + 2) && isdigit(*(buf + 2))) { - buf+=2; - if (*(buf+1) && isdigit(*(buf+1))) + buf += 2; + if (*(buf + 1) && isdigit(*(buf + 1))) ++buf; } } } continue; - } - else if (*buf == '\3' && !reverse) + } else if (*buf == '\3' && !reverse) { size += 3; - if (*(buf+1) && !isdigit(*(buf+1))) + if (*(buf + 1) && !isdigit(*(buf + 1))) { incolor = 0; size++; @@ -502,37 +480,37 @@ int CountRTFSize(unsigned char *buffer) { inbg = 0; size += 11; } - } - else if (*(buf+1)) + } else if (*(buf + 1)) { unsigned char color[3]; int number; color[0] = *(++buf); color[1] = 0; - if (*(buf+1) && isdigit(*(buf+1))) + if (*(buf + 1) && isdigit(*(buf + 1))) color[1] = *(++buf); color[2] = 0; number = atoi(color); - if (number == 99 || number == 1) + if (number == 99 || number == 1) size += 2; - else if (number == 0) + else if (number == 0) size++; - else { + else + { number %= 16; _itoa(number, color, 10); size += strlen(color); } color[2] = 0; number = atoi(color); - if (*(buf+1) && *(buf+1) == ',') + if (*(buf + 1) && *(buf + 1) == ',') { - if (*(buf+2) && isdigit(*(buf+2))) + if (*(buf + 2) && isdigit(*(buf + 2))) { size += 10; buf++; color[0] = *(++buf); color[1] = 0; - if (*(buf+1) && isdigit(*(buf+1))) + if (*(buf + 1) && isdigit(*(buf + 1))) color[1] = *(++buf); color[2] = 0; number = atoi(color); @@ -553,8 +531,7 @@ int CountRTFSize(unsigned char *buffer) { } size++; continue; - } - else if (*buf == '\17') + } else if (*buf == '\17') { if (bold) size += 3; @@ -570,8 +547,7 @@ int CountRTFSize(unsigned char *buffer) { size++; bold = uline = incolor = inbg = reverse = 0; continue; - } - else if (*buf == '\26') + } else if (*buf == '\26') { if (reverse) size += 16; @@ -579,8 +555,7 @@ int CountRTFSize(unsigned char *buffer) { size += 17; reverse = !reverse; continue; - } - else if (*buf == '\37') + } else if (*buf == '\37') { if (uline) size += 8; @@ -590,11 +565,11 @@ int CountRTFSize(unsigned char *buffer) { continue; } size++; - } + } size += strlen("{\\rtf1\\ansi\\ansicpg1252\\deff0{\\fonttbl{\\f0\\fmodern\\fprq1\\" - "fcharset0 Fixedsys;}}\r\n" - MIRC_COLORS - "\\viewkind4\\uc1\\pard\\lang1033\\f0\\fs20")+1; + "fcharset0 Fixedsys;}}\r\n" MIRC_COLORS + "\\viewkind4\\uc1\\pard\\lang1033\\f0\\fs20") + + 1; return (size); } @@ -603,62 +578,59 @@ int CountRTFSize(unsigned char *buffer) { * buffer - The input buffer containing IRC codes * string - The output buffer in RTF */ -void IRCToRTF(unsigned char *buffer, unsigned char *string) +void IRCToRTF(unsigned char *buffer, unsigned char *string) { unsigned char *tmp; int i = 0; short bold = 0, uline = 0, incolor = 0, inbg = 0, reverse = 0; sprintf(string, "{\\rtf1\\ansi\\ansicpg1252\\deff0{\\fonttbl{\\f0\\fmodern\\fprq1\\" - "fcharset0 Fixedsys;}}\r\n" - MIRC_COLORS - "\\viewkind4\\uc1\\pard\\lang1033\\f0\\fs20"); + "fcharset0 Fixedsys;}}\r\n" MIRC_COLORS + "\\viewkind4\\uc1\\pard\\lang1033\\f0\\fs20"); i = strlen(string); for (tmp = buffer; *tmp; tmp++) { if (*tmp == '{') { strcat(string, "\\{"); - i+=2; + i += 2; continue; - } - else if (*tmp == '}') + } else if (*tmp == '}') { strcat(string, "\\}"); - i+=2; + i += 2; continue; - } - else if (*tmp == '\\') + } else if (*tmp == '\\') { strcat(string, "\\\\"); - i+=2; + i += 2; continue; - } - else if (*tmp == '\r') + } else if (*tmp == '\r') { - if (*(tmp+1) && *(tmp+1) == '\n') + if (*(tmp + 1) && *(tmp + 1) == '\n') { tmp++; if (bold) { strcat(string, "\\b0 "); - i+=3; + i += 3; } if (uline) { strcat(string, "\\ulnone"); - i+=7; + i += 7; } if (incolor && !reverse) { strcat(string, "\\cf0"); - i+=4; + i += 4; } if (inbg && !reverse) { strcat(string, "\\highlight0"); - i +=11; + i += 11; } - if (reverse) { + if (reverse) + { strcat(string, "\\cf0\\highlight0"); i += 15; } @@ -666,35 +638,34 @@ void IRCToRTF(unsigned char *buffer, unsigned char *string) string[i++] = ' '; bold = uline = incolor = inbg = reverse = 0; strcat(string, "\\par\r\n"); - i +=6; - } - else - string[i++]='\r'; + i += 6; + } else + string[i++] = '\r'; continue; - } - else if (*tmp == '\n') + } else if (*tmp == '\n') { if (bold) { strcat(string, "\\b0 "); - i+=3; + i += 3; } if (uline) { strcat(string, "\\ulnone"); - i+=7; + i += 7; } if (incolor && !reverse) { strcat(string, "\\cf0"); - i+=4; + i += 4; } if (inbg && !reverse) { strcat(string, "\\highlight0"); - i +=11; + i += 11; } - if (reverse) { + if (reverse) + { strcat(string, "\\cf0\\highlight0"); i += 15; } @@ -702,48 +673,44 @@ void IRCToRTF(unsigned char *buffer, unsigned char *string) string[i++] = ' '; bold = uline = incolor = inbg = reverse = 0; strcat(string, "\\par\r\n"); - i +=6; + i += 6; continue; - } - else if (*tmp == '\2') + } else if (*tmp == '\2') { if (bold) { strcat(string, "\\b0 "); - i+=4; - } - else + i += 4; + } else { strcat(string, "\\b "); - i+=3; + i += 3; } bold = !bold; continue; - } - else if (*tmp == '\3' && reverse) + } else if (*tmp == '\3' && reverse) { - if (*(tmp+1) && isdigit(*(tmp+1))) + if (*(tmp + 1) && isdigit(*(tmp + 1))) { ++tmp; - if (*(tmp+1) && isdigit(*(tmp+1))) + if (*(tmp + 1) && isdigit(*(tmp + 1))) ++tmp; - if (*(tmp+1) && *(tmp+1) == ',') + if (*(tmp + 1) && *(tmp + 1) == ',') { - if (*(tmp+2) && isdigit(*(tmp+2))) + if (*(tmp + 2) && isdigit(*(tmp + 2))) { - tmp+=2; - if (*(tmp+1) && isdigit(*(tmp+1))) + tmp += 2; + if (*(tmp + 1) && isdigit(*(tmp + 1))) ++tmp; } } } continue; - } - else if (*tmp == '\3' && !reverse) + } else if (*tmp == '\3' && !reverse) { strcat(string, "\\cf"); i += 3; - if (*(tmp+1) && !isdigit(*(tmp+1))) + if (*(tmp + 1) && !isdigit(*(tmp + 1))) { incolor = 0; string[i++] = '0'; @@ -753,44 +720,41 @@ void IRCToRTF(unsigned char *buffer, unsigned char *string) strcat(string, "\\highlight0"); i += 11; } - } - else if (*(tmp+1)) + } else if (*(tmp + 1)) { unsigned char color[3]; int number; color[0] = *(++tmp); color[1] = 0; - if (*(tmp+1) && isdigit(*(tmp+1))) + if (*(tmp + 1) && isdigit(*(tmp + 1))) color[1] = *(++tmp); color[2] = 0; number = atoi(color); if (number == 99 || number == 1) { - strcat(string, "16"); + strcat(string, "16"); i += 2; - } - else if (number == 0) + } else if (number == 0) { strcat(string, "1"); i++; - } - else + } else { number %= 16; _itoa(number, color, 10); strcat(string, color); i += strlen(color); } - if (*(tmp+1) && *(tmp+1) == ',') + if (*(tmp + 1) && *(tmp + 1) == ',') { - if (*(tmp+2) && isdigit(*(tmp+2))) + if (*(tmp + 2) && isdigit(*(tmp + 2))) { strcat(string, "\\highlight"); i += 10; tmp++; color[0] = *(++tmp); color[1] = 0; - if (*(tmp+1) && isdigit(*(tmp+1))) + if (*(tmp + 1) && isdigit(*(tmp + 1))) color[1] = *(++tmp); color[2] = 0; number = atoi(color); @@ -798,34 +762,36 @@ void IRCToRTF(unsigned char *buffer, unsigned char *string) { strcat(string, "16"); i += 2; - } - else if (number == 0 || number == 99) + } else if (number == 0 || number == 99) string[i++] = '1'; else { number %= 16; _itoa(number, color, 10); - strcat(string,color); + strcat(string, color); i += strlen(color); } inbg = 1; } } - incolor=1; + incolor = 1; } string[i++] = ' '; continue; - } - else if (*tmp == '\17') { - if (uline) { + } else if (*tmp == '\17') + { + if (uline) + { strcat(string, "\\ulnone"); i += 7; } - if (bold) { + if (bold) + { strcat(string, "\\b0"); i += 3; } - if (incolor && !reverse) { + if (incolor && !reverse) + { strcat(string, "\\cf0"); i += 4; } @@ -834,7 +800,8 @@ void IRCToRTF(unsigned char *buffer, unsigned char *string) strcat(string, "\\highlight0"); i += 11; } - if (reverse) { + if (reverse) + { strcat(string, "\\cf0\\highlight0"); i += 15; } @@ -842,15 +809,13 @@ void IRCToRTF(unsigned char *buffer, unsigned char *string) string[i++] = ' '; uline = bold = incolor = inbg = reverse = 0; continue; - } - else if (*tmp == '\26') + } else if (*tmp == '\26') { if (reverse) { strcat(string, "\\cf0\\highlight0 "); i += 16; - } - else + } else { strcat(string, "\\cf1\\highlight16 "); i += 17; @@ -859,12 +824,14 @@ void IRCToRTF(unsigned char *buffer, unsigned char *string) continue; } - else if (*tmp == '\37') { - if (uline) { + else if (*tmp == '\37') + { + if (uline) + { strcat(string, "\\ulnone "); i += 8; - } - else { + } else + { strcat(string, "\\ul "); i += 4; } diff --git a/src/windows/service.c b/src/windows/service.c index 4286d910c..96abd3974 100644 --- a/src/windows/service.c +++ b/src/windows/service.c @@ -19,7 +19,7 @@ #include "unrealircd.h" -SERVICE_STATUS IRCDStatus; +SERVICE_STATUS IRCDStatus; SERVICE_STATUS_HANDLE IRCDStatusHandle; /* Signal to rehash */ @@ -41,20 +41,20 @@ void SetServiceStop(int code) IRCDStatus.dwWin32ExitCode = code; IRCDStatus.dwServiceSpecificExitCode = code; SetServiceStatus(IRCDStatusHandle, &IRCDStatus); -} +} /* Handles the service messages * Parameters: * opcode - The message to process */ -VOID WINAPI IRCDCtrlHandler(DWORD opcode) +VOID WINAPI IRCDCtrlHandler(DWORD opcode) { DWORD status; int i; Client *acptr; /* Stopping */ - if (opcode == SERVICE_CONTROL_STOP) + if (opcode == SERVICE_CONTROL_STOP) { IRCDStatus.dwCurrentState = SERVICE_STOP_PENDING; SetServiceStatus(IRCDStatusHandle, &IRCDStatus); @@ -75,20 +75,20 @@ VOID WINAPI IRCDCtrlHandler(DWORD opcode) SetServiceStop(0); } /* Rehash */ - else if (opcode == IRCD_SERVICE_CONTROL_REHASH) + else if (opcode == IRCD_SERVICE_CONTROL_REHASH) { request_rehash(NULL); } SetServiceStatus(IRCDStatusHandle, &IRCDStatus); -} +} /* Entry point function * Parameters: * dwArgc - Argument count * lpszArgv - Arguments */ -VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) +VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) { DWORD error = 0; char path[MAX_PATH], *folder; @@ -98,13 +98,13 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) /* Initialize the service structure */ IRCDStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; IRCDStatus.dwCurrentState = SERVICE_START_PENDING; - IRCDStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN; + IRCDStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; IRCDStatus.dwWin32ExitCode = NO_ERROR; IRCDStatus.dwServiceSpecificExitCode = 0; IRCDStatus.dwCheckPoint = 0; IRCDStatus.dwWaitHint = 0; - - GetModuleFileName(NULL,path,MAX_PATH); + + GetModuleFileName(NULL, path, MAX_PATH); folder = strrchr(path, '\\'); *folder = 0; chdir(path); @@ -115,24 +115,24 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) chdir(".."); /* Register the service controller */ - IRCDStatusHandle = RegisterServiceCtrlHandler("UnrealIRCd", IRCDCtrlHandler); - + IRCDStatusHandle = RegisterServiceCtrlHandler("UnrealIRCd", IRCDCtrlHandler); + GetOSName(OSName); InitDebug(); init_winsock(); /* Initialize the IRCd */ - if ((error = InitUnrealIRCd(dwArgc, lpszArgv)) != 1) + if ((error = InitUnrealIRCd(dwArgc, lpszArgv)) != 1) { SetServiceStop(error); return; } - + /* Go into the running state */ IRCDStatus.dwCurrentState = SERVICE_RUNNING; IRCDStatus.dwCheckPoint = 0; - IRCDStatus.dwWaitHint = 0; + IRCDStatus.dwWaitHint = 0; SetServiceStatus(IRCDStatusHandle, &IRCDStatus); SocketLoop(0); diff --git a/src/windows/unrealsvc.c b/src/windows/unrealsvc.c index ed360ec24..27be732ca 100644 --- a/src/windows/unrealsvc.c +++ b/src/windows/unrealsvc.c @@ -25,13 +25,15 @@ HMODULE hAdvapi; UCHANGESERVICECONFIG2 uChangeServiceConfig2; #define IRCD_SERVICE_CONTROL_REHASH 128 -void show_usage() { +void show_usage() +{ fprintf(stderr, "unrealsvc start|stop|rehash|restart|install|uninstall|config