]>
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
->type
== SEARCHTYPE_CHANNEL
)
43 localdata
->marker
= nextchanmarker();
45 localdata
->marker
= nextnickmarker();
49 localdata
->duration
= NSGLINE_DURATION
;
50 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
54 if (strchr(argv
[0], ' ') == NULL
) { /* duration specified */
55 localdata
->duration
= durationtolong(argv
[0]);
56 /* error checking on gline duration */
57 if (localdata
->duration
== 0)
58 localdata
->duration
= NSGLINE_DURATION
;
59 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
61 else { /* reason specified */
62 localdata
->duration
= NSGLINE_DURATION
;
67 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
68 if(len
>= sizeof(localdata
->reason
)) {
69 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
71 localdata
->reason
[len
-1] = '\0';
77 localdata
->duration
= durationtolong(argv
[0]);
78 /* error checking on gline duration */
79 if (localdata
->duration
== 0)
80 localdata
->duration
= NSGLINE_DURATION
;
85 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
86 if(len
>= sizeof(localdata
->reason
)) {
87 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
89 localdata
->reason
[len
-1] = '\0';
95 parseError
= "gline: invalid number of arguments";
99 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
100 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
101 parseError
= "malloc: could not allocate memory for this search.";
106 thenode
->returntype
= RETURNTYPE_BOOL
;
107 thenode
->localdata
= localdata
;
108 thenode
->exe
= gline_exe
;
109 thenode
->free
= gline_free
;
114 void *gline_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
115 struct gline_localdata
*localdata
;
119 localdata
= thenode
->localdata
;
121 if (ctx
->type
== SEARCHTYPE_CHANNEL
) {
122 cip
= (chanindex
*)theinput
;
123 cip
->marker
= localdata
->marker
;
124 localdata
->count
+= cip
->channel
->users
->totalusers
;
127 np
= (nick
*)theinput
;
128 np
->marker
= localdata
->marker
;
135 void gline_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
136 struct gline_localdata
*localdata
;
138 chanindex
*cip
, *ncip
;
141 time_t ti
= time(NULL
);
143 localdata
= thenode
->localdata
;
145 if (localdata
->count
> NSMAX_GLINE_LIMIT
) {
146 /* need to warn the user that they have just tried to twat half the network ... */
147 ctx
->reply(senderNSExtern
, "Warning: your pattern matches too many users (%d) - nothing done.", localdata
->count
);
153 if (ctx
->type
== SEARCHTYPE_CHANNEL
) {
154 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
155 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
157 if (cip
!= NULL
&& cip
->channel
!= NULL
&& cip
->marker
== localdata
->marker
) {
158 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
159 if (cip
->channel
->users
->content
[j
]==nouser
)
162 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
]))) {
163 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
164 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
165 if (np
->host
->clonecount
<= NSMAX_GLINE_CLONES
)
166 irc_send("%s GL * +*@%s %u %d :%s", mynumeric
->content
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
168 irc_send("%s GL * +%s@%s %u %d :%s", mynumeric
->content
, np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
179 for (i
=0;i
<NICKHASHSIZE
;i
++) {
180 for (np
=nicktable
[i
];np
;np
=nnp
) {
182 if (np
->marker
== localdata
->marker
) {
183 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
184 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
185 if (np
->host
->clonecount
<= NSMAX_GLINE_CLONES
)
186 irc_send("%s GL * +*@%s %u %d :%s", mynumeric
->content
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
188 irc_send("%s GL * +%s@%s %u %d :%s", mynumeric
->content
, np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
197 ctx
->reply(senderNSExtern
, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe
);
198 /* notify opers of the action */
199 ctx
->wall(NL_GLINES
, "%s/%s glined %d %s via %s for %s [%d untouched].", senderNSExtern
->nick
, senderNSExtern
->authname
, (localdata
->count
- safe
),
200 (localdata
->count
- safe
) != 1 ? "users" : "user", (ctx
->type
== SEARCHTYPE_CHANNEL
) ? "chansearch" : "nicksearch", longtoduration(localdata
->duration
, 1), safe
);