]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-gline.c
12 #include "../control/control.h"
13 #include "../irc/irc.h" /* irc_send() */
14 #include "../lib/irc_string.h" /* IPtostr(), longtoduration(), durationtolong() */
15 #include "../lib/strlfunc.h"
17 /* used for *_free functions that need to warn users of certain things
18 i.e. hitting too many users in a (kill) or (gline) - declared in newsearch.c */
19 extern nick
*senderNSExtern
;
20 static const char *defaultreason
= "You (%u) have been g-lined for violating our terms of service";
22 void *gline_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
23 void gline_free(searchCtx
*ctx
, struct searchNode
*thenode
);
25 struct gline_localdata
{
27 unsigned int duration
;
29 char reason
[NSMAX_REASON_LEN
];
32 struct searchNode
*gline_parse(searchCtx
*ctx
, int argc
, char **argv
) {
33 struct gline_localdata
*localdata
;
34 struct searchNode
*thenode
;
38 if (!(localdata
= (struct gline_localdata
*) malloc(sizeof(struct gline_localdata
)))) {
39 parseError
= "malloc: could not allocate memory for this search.";
43 if (ctx
->searchcmd
== reg_chansearch
)
44 localdata
->marker
= nextchanmarker();
45 else if (ctx
->searchcmd
== reg_nicksearch
)
46 localdata
->marker
= nextnickmarker();
48 parseError
= "gline: invalid search type";
54 localdata
->duration
= NSGLINE_DURATION
;
55 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
59 if (strchr(argv
[0], ' ') == NULL
) { /* duration specified */
60 localdata
->duration
= durationtolong(argv
[0]);
61 /* error checking on gline duration */
62 if (localdata
->duration
== 0)
63 localdata
->duration
= NSGLINE_DURATION
;
64 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
66 else { /* reason specified */
67 localdata
->duration
= NSGLINE_DURATION
;
72 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
73 if(len
>= sizeof(localdata
->reason
)) {
74 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
76 localdata
->reason
[len
-1] = '\0';
82 localdata
->duration
= durationtolong(argv
[0]);
83 /* error checking on gline duration */
84 if (localdata
->duration
== 0)
85 localdata
->duration
= NSGLINE_DURATION
;
90 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
91 if(len
>= sizeof(localdata
->reason
)) {
92 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
94 localdata
->reason
[len
-1] = '\0';
100 parseError
= "gline: invalid number of arguments";
104 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
105 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
106 parseError
= "malloc: could not allocate memory for this search.";
111 thenode
->returntype
= RETURNTYPE_BOOL
;
112 thenode
->localdata
= localdata
;
113 thenode
->exe
= gline_exe
;
114 thenode
->free
= gline_free
;
119 void *gline_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
120 struct gline_localdata
*localdata
;
124 localdata
= thenode
->localdata
;
126 if (ctx
->searchcmd
== reg_chansearch
) {
127 cip
= (chanindex
*)theinput
;
128 cip
->marker
= localdata
->marker
;
129 localdata
->count
+= cip
->channel
->users
->totalusers
;
132 np
= (nick
*)theinput
;
133 np
->marker
= localdata
->marker
;
140 void gline_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
141 struct gline_localdata
*localdata
;
143 chanindex
*cip
, *ncip
;
146 time_t ti
= time(NULL
);
148 localdata
= thenode
->localdata
;
150 if (localdata
->count
> NSMAX_GLINE_LIMIT
) {
151 /* need to warn the user that they have just tried to twat half the network ... */
152 ctx
->reply(senderNSExtern
, "Warning: your pattern matches too many users (%d) - nothing done.", localdata
->count
);
158 if (ctx
->searchcmd
== reg_chansearch
) {
159 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
160 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
162 if (cip
!= NULL
&& cip
->channel
!= NULL
&& cip
->marker
== localdata
->marker
) {
163 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
164 if (cip
->channel
->users
->content
[j
]==nouser
)
167 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
]))) {
168 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
169 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
170 if (np
->host
->clonecount
<= NSMAX_GLINE_CLONES
)
171 irc_send("%s GL * +*@%s %u %jd :%s", mynumeric
->content
, IPtostr(np
->p_ipaddr
), localdata
->duration
, (intmax_t)ti
, msgbuf
);
173 irc_send("%s GL * +%s@%s %u %jd :%s", mynumeric
->content
, np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->duration
, (intmax_t)ti
, msgbuf
);
184 for (i
=0;i
<NICKHASHSIZE
;i
++) {
185 for (np
=nicktable
[i
];np
;np
=nnp
) {
187 if (np
->marker
== localdata
->marker
) {
188 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
189 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
190 if (np
->host
->clonecount
<= NSMAX_GLINE_CLONES
)
191 irc_send("%s GL * +*@%s %u %jd :%s", mynumeric
->content
, IPtostr(np
->p_ipaddr
), localdata
->duration
, (intmax_t)ti
, msgbuf
);
193 irc_send("%s GL * +%s@%s %u %jd :%s", mynumeric
->content
, np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->duration
, (intmax_t)ti
, msgbuf
);
202 ctx
->reply(senderNSExtern
, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe
);
203 /* notify opers of the action */
204 ctx
->wall(NL_GLINES
, "%s/%s glined %d %s via %s for %s [%d untouched].", senderNSExtern
->nick
, senderNSExtern
->authname
, (localdata
->count
- safe
),
205 (localdata
->count
- safe
) != 1 ? "users" : "user", (ctx
->searchcmd
== reg_chansearch
) ? "chansearch" : "nicksearch", longtoduration(localdata
->duration
, 1), safe
);