]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-gline.c
11 #include "../control/control.h"
12 #include "../irc/irc.h" /* irc_send() */
13 #include "../lib/irc_string.h" /* IPtostr(), longtoduration(), durationtolong() */
14 #include "../lib/strlfunc.h"
16 /* used for *_free functions that need to warn users of certain things
17 i.e. hitting too many users in a (kill) or (gline) - declared in newsearch.c */
18 extern nick
*senderNSExtern
;
19 static const char *defaultreason
= "You (%u) have been g-lined for violating our terms of service";
21 void *gline_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
22 void gline_free(searchCtx
*ctx
, struct searchNode
*thenode
);
24 struct gline_localdata
{
26 unsigned int duration
;
28 char reason
[NSMAX_REASON_LEN
];
31 struct searchNode
*gline_parse(searchCtx
*ctx
, int argc
, char **argv
) {
32 struct gline_localdata
*localdata
;
33 struct searchNode
*thenode
;
37 if (!(localdata
= (struct gline_localdata
*) malloc(sizeof(struct gline_localdata
)))) {
38 parseError
= "malloc: could not allocate memory for this search.";
42 if (ctx
->searchcmd
== reg_chansearch
)
43 localdata
->marker
= nextchanmarker();
44 else if (ctx
->searchcmd
== reg_nicksearch
)
45 localdata
->marker
= nextnickmarker();
47 parseError
= "gline: invalid search type";
53 localdata
->duration
= NSGLINE_DURATION
;
54 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
58 if (strchr(argv
[0], ' ') == NULL
) { /* duration specified */
59 localdata
->duration
= durationtolong(argv
[0]);
60 /* error checking on gline duration */
61 if (localdata
->duration
== 0)
62 localdata
->duration
= NSGLINE_DURATION
;
63 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
65 else { /* reason specified */
66 localdata
->duration
= NSGLINE_DURATION
;
71 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
72 if(len
>= sizeof(localdata
->reason
)) {
73 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
75 localdata
->reason
[len
-1] = '\0';
81 localdata
->duration
= durationtolong(argv
[0]);
82 /* error checking on gline duration */
83 if (localdata
->duration
== 0)
84 localdata
->duration
= NSGLINE_DURATION
;
89 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
90 if(len
>= sizeof(localdata
->reason
)) {
91 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
93 localdata
->reason
[len
-1] = '\0';
99 parseError
= "gline: invalid number of arguments";
103 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
104 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
105 parseError
= "malloc: could not allocate memory for this search.";
110 thenode
->returntype
= RETURNTYPE_BOOL
;
111 thenode
->localdata
= localdata
;
112 thenode
->exe
= gline_exe
;
113 thenode
->free
= gline_free
;
118 void *gline_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
119 struct gline_localdata
*localdata
;
123 localdata
= thenode
->localdata
;
125 if (ctx
->searchcmd
== reg_chansearch
) {
126 cip
= (chanindex
*)theinput
;
127 cip
->marker
= localdata
->marker
;
128 localdata
->count
+= cip
->channel
->users
->totalusers
;
131 np
= (nick
*)theinput
;
132 np
->marker
= localdata
->marker
;
139 void gline_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
140 struct gline_localdata
*localdata
;
142 chanindex
*cip
, *ncip
;
145 time_t ti
= time(NULL
);
147 localdata
= thenode
->localdata
;
149 if (localdata
->count
> NSMAX_GLINE_LIMIT
) {
150 /* need to warn the user that they have just tried to twat half the network ... */
151 ctx
->reply(senderNSExtern
, "Warning: your pattern matches too many users (%d) - nothing done.", localdata
->count
);
157 if (ctx
->searchcmd
== reg_chansearch
) {
158 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
159 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
161 if (cip
!= NULL
&& cip
->channel
!= NULL
&& cip
->marker
== localdata
->marker
) {
162 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
163 if (cip
->channel
->users
->content
[j
]==nouser
)
166 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
]))) {
167 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
168 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
169 if (np
->host
->clonecount
<= NSMAX_GLINE_CLONES
)
170 irc_send("%s GL * +*@%s %u %d :%s", mynumeric
->content
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
172 irc_send("%s GL * +%s@%s %u %d :%s", mynumeric
->content
, np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
183 for (i
=0;i
<NICKHASHSIZE
;i
++) {
184 for (np
=nicktable
[i
];np
;np
=nnp
) {
186 if (np
->marker
== localdata
->marker
) {
187 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
188 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
189 if (np
->host
->clonecount
<= NSMAX_GLINE_CLONES
)
190 irc_send("%s GL * +*@%s %u %d :%s", mynumeric
->content
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
192 irc_send("%s GL * +%s@%s %u %d :%s", mynumeric
->content
, np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
201 ctx
->reply(senderNSExtern
, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe
);
202 /* notify opers of the action */
203 ctx
->wall(NL_GLINES
, "%s/%s glined %d %s via %s for %s [%d untouched].", senderNSExtern
->nick
, senderNSExtern
->authname
, (localdata
->count
- safe
),
204 (localdata
->count
- safe
) != 1 ? "users" : "user", (ctx
->searchcmd
== reg_chansearch
) ? "chansearch" : "nicksearch", longtoduration(localdata
->duration
, 1), safe
);