2 * IRC - Internet Relay Chat, ircd/jupe.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Finland
5 * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 1, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include "ircd_alloc.h"
31 #include "ircd_policy.h"
32 #include "ircd_reply.h"
33 #include "ircd_string.h"
43 #include "sys.h" /* FALSE bleah */
48 static struct Jupe *GlobalJupeList = 0;
51 make_jupe(char *server, char *reason, time_t expire, time_t lastmod,
56 ajupe = (struct Jupe*) MyMalloc(sizeof(struct Jupe)); /* alloc memory */
59 DupString(ajupe->ju_server, server); /* copy vital information */
60 DupString(ajupe->ju_reason, reason);
61 ajupe->ju_expire = expire;
62 ajupe->ju_lastmod = lastmod;
63 ajupe->ju_flags = flags & JUPE_MASK; /* set jupe flags */
65 ajupe->ju_next = GlobalJupeList; /* link it into the list */
66 ajupe->ju_prev_p = &GlobalJupeList;
68 GlobalJupeList->ju_prev_p = &ajupe->ju_next;
69 GlobalJupeList = ajupe;
75 do_jupe(struct Client *cptr, struct Client *sptr, struct Jupe *jupe)
79 if (!JupeIsActive(jupe)) /* no action to be taken on inactive jupes */
82 acptr = FindServer(jupe->ju_server);
84 /* server isn't online or isn't local or is me */
85 if (!acptr || !MyConnect(acptr) || IsMe(acptr))
88 return exit_client_msg(cptr, acptr, &me, "Juped: %s", jupe->ju_reason);
92 propagate_jupe(struct Client *cptr, struct Client *sptr, struct Jupe *jupe)
94 if (JupeIsLocal(jupe)) /* don't propagate local jupes */
97 sendcmdto_serv_butone(sptr, CMD_JUPE, cptr, "* %c%s %Tu %Tu :%s",
98 JupeIsRemActive(jupe) ? '+' : '-', jupe->ju_server,
99 jupe->ju_expire - CurrentTime, jupe->ju_lastmod,
104 jupe_add(struct Client *cptr, struct Client *sptr, char *server, char *reason,
105 time_t expire, time_t lastmod, unsigned int flags)
113 * You cannot set a negative (or zero) expire time, nor can you set an
114 * expiration time for greater than JUPE_MAX_EXPIRE.
116 if (expire <= 0 || expire > JUPE_MAX_EXPIRE) {
117 if (!IsServer(cptr) && MyConnect(cptr))
118 send_reply(cptr, ERR_BADEXPIRE, expire);
122 expire += CurrentTime; /* convert from lifetime to timestamp */
124 /* Inform ops and log it */
125 sendto_opmask_butone(0, SNO_NETWORK, "%s adding %sJUPE for %s, expiring at "
127 #ifdef HEAD_IN_SAND_SNOTICES
130 IsServer(sptr) ? cli_name(sptr) :
131 cli_name(cli_user(sptr)->server),
133 flags & JUPE_LOCAL ? "local " : "", server,
134 expire + TSoffset, reason);
136 log_write(LS_JUPE, L_INFO, LOG_NOSNOTICE,
137 "%#C adding %sJUPE for %s, expiring at %Tu: %s", sptr,
138 flags & JUPE_LOCAL ? "local " : "", server, expire + TSoffset,
142 ajupe = make_jupe(server, reason, expire, lastmod, flags);
144 propagate_jupe(cptr, sptr, ajupe);
146 return do_jupe(cptr, sptr, ajupe); /* remove server if necessary */
150 jupe_activate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe,
151 time_t lastmod, unsigned int flags)
153 unsigned int saveflags = 0;
156 assert(!JupeIsLocal(jupe));
158 saveflags = jupe->ju_flags;
160 if (flags & JUPE_LOCAL)
161 jupe->ju_flags &= ~JUPE_LDEACT;
163 jupe->ju_flags |= JUPE_ACTIVE;
165 if (jupe->ju_lastmod >= lastmod) /* force lastmod to increase */
168 jupe->ju_lastmod = lastmod;
171 if ((saveflags & JUPE_ACTMASK) == JUPE_ACTIVE)
172 return 0; /* was active to begin with */
174 /* Inform ops and log it */
175 sendto_opmask_butone(0, SNO_NETWORK, "%s activating JUPE for %s, expiring "
177 #ifdef HEAD_IN_SAND_SNOTICES
180 IsServer(sptr) ? cli_name(sptr) :
181 cli_name(cli_user(sptr)->server),
183 jupe->ju_server, jupe->ju_expire + TSoffset,
186 log_write(LS_JUPE, L_INFO, LOG_NOSNOTICE,
187 "%#C activating JUPE for %s, expiring at %Tu: %s",sptr,
188 jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
190 if (!(flags & JUPE_LOCAL)) /* don't propagate local changes */
191 propagate_jupe(cptr, sptr, jupe);
193 return do_jupe(cptr, sptr, jupe);
197 jupe_deactivate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe,
198 time_t lastmod, unsigned int flags)
200 unsigned int saveflags = 0;
204 saveflags = jupe->ju_flags;
206 if (!JupeIsLocal(jupe)) {
207 if (flags & JUPE_LOCAL)
208 jupe->ju_flags |= JUPE_LDEACT;
210 jupe->ju_flags &= ~JUPE_ACTIVE;
212 if (jupe->ju_lastmod >= lastmod) /* force lastmod to increase */
215 jupe->ju_lastmod = lastmod;
218 if ((saveflags & JUPE_ACTMASK) != JUPE_ACTIVE)
219 return 0; /* was inactive to begin with */
222 /* Inform ops and log it */
223 sendto_opmask_butone(0, SNO_NETWORK, "%s %s JUPE for %s, expiring at %Tu: "
225 #ifdef HEAD_IN_SAND_SNOTICES
228 IsServer(sptr) ? cli_name(sptr) :
229 cli_name(cli_user(sptr)->server),
231 JupeIsLocal(jupe) ? "removing local" : "deactivating",
232 jupe->ju_server, jupe->ju_expire + TSoffset,
235 log_write(LS_JUPE, L_INFO, LOG_NOSNOTICE,
236 "%#C %s JUPE for %s, expiring at %Tu: %s", sptr,
237 JupeIsLocal(jupe) ? "removing local" : "deactivating",
238 jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
240 if (JupeIsLocal(jupe))
242 else if (!(flags & JUPE_LOCAL)) /* don't propagate local changes */
243 propagate_jupe(cptr, sptr, jupe);
249 jupe_find(char *server)
254 for (jupe = GlobalJupeList; jupe; jupe = sjupe) { /* go through jupes */
255 sjupe = jupe->ju_next;
257 if (jupe->ju_expire <= CurrentTime) /* expire any that need expiring */
259 else if (0 == ircd_strcmp(server, jupe->ju_server)) /* found it yet? */
267 jupe_free(struct Jupe* jupe)
271 *jupe->ju_prev_p = jupe->ju_next; /* squeeze this jupe out */
273 jupe->ju_next->ju_prev_p = jupe->ju_prev_p;
275 MyFree(jupe->ju_server); /* and free up the memory */
276 MyFree(jupe->ju_reason);
281 jupe_burst(struct Client *cptr)
286 for (jupe = GlobalJupeList; jupe; jupe = sjupe) { /* go through jupes */
287 sjupe = jupe->ju_next;
289 if (jupe->ju_expire <= CurrentTime) /* expire any that need expiring */
291 else if (!JupeIsLocal(jupe)) /* forward global jupes */
292 sendcmdto_one(&me, CMD_JUPE, cptr, "* %c%s %Tu %Tu :%s",
293 JupeIsRemActive(jupe) ? '+' : '-', jupe->ju_server,
294 jupe->ju_expire - CurrentTime, jupe->ju_lastmod,
300 jupe_resend(struct Client *cptr, struct Jupe *jupe)
302 if (JupeIsLocal(jupe)) /* don't propagate local jupes */
305 sendcmdto_one(&me, CMD_JUPE, cptr, "* %c%s %Tu %Tu :%s",
306 JupeIsRemActive(jupe) ? '+' : '-', jupe->ju_server,
307 jupe->ju_expire - CurrentTime, jupe->ju_lastmod,
314 jupe_list(struct Client *sptr, char *server)
320 if (!(jupe = jupe_find(server))) /* no such jupe */
321 return send_reply(sptr, ERR_NOSUCHJUPE, server);
323 /* send jupe information along */
324 send_reply(sptr, RPL_JUPELIST, jupe->ju_server, jupe->ju_expire + TSoffset,
325 JupeIsLocal(jupe) ? cli_name(&me) : "*",
326 JupeIsActive(jupe) ? '+' : '-', jupe->ju_reason);
328 for (jupe = GlobalJupeList; jupe; jupe = sjupe) { /* go through jupes */
329 sjupe = jupe->ju_next;
331 if (jupe->ju_expire <= CurrentTime) /* expire any that need expiring */
333 else /* send jupe information along */
334 send_reply(sptr, RPL_JUPELIST, jupe->ju_server,
335 jupe->ju_expire + TSoffset,
336 JupeIsLocal(jupe) ? cli_name(&me) : "*",
337 JupeIsActive(jupe) ? '+' : '-', jupe->ju_reason);
341 /* end of jupe information */
342 return send_reply(sptr, RPL_ENDOFJUPELIST);