]>
jfr.im git - irc/quakenet/newserv.git/blob - glines/glines_formats.c
4 #include "../lib/irc_string.h"
5 #include "../lib/version.h"
6 #include "../core/schedule.h"
7 #include "../irc/irc.h"
8 #include "../trusts/trusts.h"
9 #include "../control/control.h"
12 gline
*makegline(const char *mask
) {
13 /* populate gl-> user,host,node,nick and set appropriate flags */
15 char nick
[512], user
[512], host
[512];
16 const char *pnick
= NULL
, *puser
= NULL
, *phost
= NULL
;
20 /* Make sure there are no spaces in the mask, glstore_* depends on this */
21 if (strchr(mask
, ' ') != NULL
)
27 Error("gline", ERR_ERROR
, "Failed to allocate new gline");
31 if (mask
[0] == '#' || mask
[0] == '&') {
32 gl
->flags
|= GLINE_BADCHAN
;
33 gl
->user
= getsstring(mask
, CHANNELLEN
);
43 gl
->flags
|= GLINE_REALNAME
;
44 gl
->user
= getsstring(mask
+ 2, REALLEN
);
48 if (sscanf(mask
, "%[^!]!%[^@]@%s", nick
, user
, host
) == 3) {
52 } else if (sscanf(mask
, "%[^@]@%s", user
, host
) == 2) {
59 /* validate length of the mask components */
60 if ((pnick
&& (pnick
[0] == '\0' || strlen(pnick
) > NICKLEN
)) ||
61 (puser
&& (puser
[0] == '\0' || strlen(puser
) > USERLEN
)) ||
62 (phost
&& (phost
[0] == '\0' || strlen(phost
) > HOSTLEN
))) {
67 /* ! and @ are not allowed in the mask components */
68 if ((pnick
&& (strchr(pnick
, '!') || strchr(pnick
, '@'))) ||
69 (puser
&& (strchr(puser
, '!') || strchr(puser
, '@'))) ||
70 (phost
&& (strchr(phost
, '!') || strchr(phost
, '@')))) {
75 if (phost
&& ipmask_parse(phost
, &gl
->ip
, &gl
->bits
))
76 gl
->flags
|= GLINE_IPMASK
;
78 gl
->flags
|= GLINE_HOSTMASK
;
80 /* Don't allow invalid IPv6 bans as those match * on snircd 1.3.4 */
84 for (pos
= phost
; *pos
; pos
++)
89 controlwall(NO_OPER
, NL_GLINES
, "Warning: Parsed invalid IPv6 G-Line: %s", mask
);
95 if (pnick
&& strcmp(pnick
, "*") != 0)
96 gl
->nick
= getsstring(pnick
, NICKLEN
);
98 if (puser
&& strcmp(puser
, "*") != 0)
99 gl
->user
= getsstring(puser
, USERLEN
);
101 if (phost
&& strcmp(phost
, "*") != 0)
102 gl
->host
= getsstring(phost
, HOSTLEN
);
107 char *glinetostring(gline
*gl
) {
108 static char mask
[512]; /* check */
110 if (gl
->flags
& GLINE_REALNAME
) {
112 snprintf(mask
, sizeof(mask
), "$R%s", gl
->user
->content
);
114 strncpy(mask
, "$R*", sizeof(mask
));
119 if (gl
->flags
& GLINE_BADCHAN
) {
122 strncpy(mask
, gl
->user
->content
, sizeof(mask
));
126 snprintf(mask
, sizeof(mask
), "%s!%s@%s",
127 gl
->nick
? gl
->nick
->content
: "*",
128 gl
->user
? gl
->user
->content
: "*",
129 gl
->host
? gl
->host
->content
: "*");