]>
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
;
29 char reason
[NSMAX_REASON_LEN
];
32 struct searchNode
*gline_parse(searchCtx
*ctx
, int type
, 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 localdata
->type
= type
;
44 if (type
== SEARCHTYPE_CHANNEL
)
45 localdata
->marker
= nextchanmarker();
47 localdata
->marker
= nextnickmarker();
51 localdata
->duration
= NSGLINE_DURATION
;
52 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
56 if (strchr(argv
[0], ' ') == NULL
) { /* duration specified */
57 localdata
->duration
= durationtolong(argv
[0]);
58 /* error checking on gline duration */
59 if (localdata
->duration
== 0)
60 localdata
->duration
= NSGLINE_DURATION
;
61 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
63 else { /* reason specified */
64 localdata
->duration
= NSGLINE_DURATION
;
69 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
70 if(len
>= sizeof(localdata
->reason
)) {
71 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
73 localdata
->reason
[len
-1] = '\0';
79 localdata
->duration
= durationtolong(argv
[0]);
80 /* error checking on gline duration */
81 if (localdata
->duration
== 0)
82 localdata
->duration
= NSGLINE_DURATION
;
87 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
88 if(len
>= sizeof(localdata
->reason
)) {
89 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
91 localdata
->reason
[len
-1] = '\0';
97 parseError
= "gline: invalid number of arguments";
101 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
102 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
103 parseError
= "malloc: could not allocate memory for this search.";
108 thenode
->returntype
= RETURNTYPE_BOOL
;
109 thenode
->localdata
= localdata
;
110 thenode
->exe
= gline_exe
;
111 thenode
->free
= gline_free
;
116 void *gline_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
117 struct gline_localdata
*localdata
;
121 localdata
= thenode
->localdata
;
123 if (localdata
->type
== SEARCHTYPE_CHANNEL
) {
124 cip
= (chanindex
*)theinput
;
125 cip
->marker
= localdata
->marker
;
126 localdata
->count
+= cip
->channel
->users
->totalusers
;
129 np
= (nick
*)theinput
;
130 np
->marker
= localdata
->marker
;
137 void gline_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
138 struct gline_localdata
*localdata
;
140 chanindex
*cip
, *ncip
;
143 time_t ti
= time(NULL
);
145 localdata
= thenode
->localdata
;
147 if (localdata
->count
> NSMAX_GLINE_LIMIT
) {
148 /* need to warn the user that they have just tried to twat half the network ... */
149 ctx
->reply(senderNSExtern
, "Warning: your pattern matches too many users (%d) - nothing done.", localdata
->count
);
155 if (localdata
->type
== SEARCHTYPE_CHANNEL
) {
156 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
157 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
159 if (cip
!= NULL
&& cip
->channel
!= NULL
&& cip
->marker
== localdata
->marker
) {
160 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
161 if (cip
->channel
->users
->content
[j
]==nouser
)
164 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
]))) {
165 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
166 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
167 if (np
->host
->clonecount
<= NSMAX_GLINE_CLONES
)
168 irc_send("%s GL * +*@%s %u %d :%s", mynumeric
->content
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
170 irc_send("%s GL * +%s@%s %u %d :%s", mynumeric
->content
, np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
181 for (i
=0;i
<NICKHASHSIZE
;i
++) {
182 for (np
=nicktable
[i
];np
;np
=nnp
) {
184 if (np
->marker
== localdata
->marker
) {
185 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
186 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
187 if (np
->host
->clonecount
<= NSMAX_GLINE_CLONES
)
188 irc_send("%s GL * +*@%s %u %d :%s", mynumeric
->content
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
190 irc_send("%s GL * +%s@%s %u %d :%s", mynumeric
->content
, np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->duration
, ti
, msgbuf
);
199 ctx
->reply(senderNSExtern
, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe
);
200 /* notify opers of the action */
201 ctx
->wall(NL_GLINES
, "%s/%s glined %d %s via %s for %s [%d untouched].", senderNSExtern
->nick
, senderNSExtern
->authname
, (localdata
->count
- safe
),
202 (localdata
->count
- safe
) != 1 ? "users" : "user", (localdata
->type
== SEARCHTYPE_CHANNEL
) ? "chansearch" : "nicksearch", longtoduration(localdata
->duration
, 1), safe
);