ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/whowas.c
Revision: 2748
Committed: Sun Jan 5 19:20:09 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 3308 byte(s)
Log Message:
- Fixed server name leak for hidden servers in /who, /whois and /whowas

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * whowas.c: WHOWAS user cache.
4     *
5     * Copyright (C) 2005 by the past and present ircd coders, and others.
6     *
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 2 of the License, or
10     * (at your option) any later version.
11     *
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.
16     *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1358 #include "list.h"
27 adx 30 #include "whowas.h"
28     #include "client.h"
29     #include "hash.h"
30     #include "irc_string.h"
31     #include "ircd.h"
32    
33    
34 michael 1358 static struct Whowas WHOWAS[NICKNAMEHISTORYLENGTH];
35     dlink_list WHOWASHASH[HASHSIZE];
36 adx 30
37    
38     void
39 michael 1997 whowas_init(void)
40     {
41     unsigned int idx;
42    
43     for (idx = 0; idx < NICKNAMEHISTORYLENGTH; ++idx)
44     WHOWAS[idx].hashv = -1;
45     }
46    
47     void
48 michael 2300 whowas_add_history(struct Client *client_p, const int online)
49 adx 30 {
50 michael 1358 static unsigned int whowas_next = 0;
51 adx 30 struct Whowas *who = &WHOWAS[whowas_next];
52    
53 michael 507 assert(client_p && client_p->servptr);
54 adx 30
55 michael 1358 if (++whowas_next == NICKNAMEHISTORYLENGTH)
56     whowas_next = 0;
57    
58 adx 30 if (who->hashv != -1)
59     {
60     if (who->online)
61 michael 1358 dlinkDelete(&who->cnode, &who->online->whowas);
62    
63     dlinkDelete(&who->tnode, &WHOWASHASH[who->hashv]);
64 adx 30 }
65    
66 michael 507 who->hashv = strhash(client_p->name);
67 michael 2748 who->shide = IsHidden(client_p->servptr) != 0;
68 adx 30 who->logoff = CurrentTime;
69    
70     strlcpy(who->name, client_p->name, sizeof(who->name));
71 michael 1358 strlcpy(who->username, client_p->username, sizeof(who->username));
72     strlcpy(who->hostname, client_p->host, sizeof(who->hostname));
73     strlcpy(who->realname, client_p->info, sizeof(who->realname));
74 adx 30 strlcpy(who->servername, client_p->servptr->name, sizeof(who->servername));
75    
76     if (online)
77     {
78     who->online = client_p;
79 michael 1358 dlinkAdd(who, &who->cnode, &client_p->whowas);
80 adx 30 }
81     else
82     who->online = NULL;
83    
84 michael 1358 dlinkAdd(who, &who->tnode, &WHOWASHASH[who->hashv]);
85 adx 30 }
86    
87     void
88 michael 2300 whowas_off_history(struct Client *client_p)
89 adx 30 {
90 michael 1358 dlink_node *ptr = NULL, *ptr_next = NULL;
91 adx 30
92 michael 1358 DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->whowas.head)
93 adx 30 {
94 michael 1358 struct Whowas *temp = ptr->data;
95    
96 adx 30 temp->online = NULL;
97 michael 1358 dlinkDelete(&temp->cnode, &client_p->whowas);
98 adx 30 }
99     }
100    
101     struct Client *
102 michael 2300 whowas_get_history(const char *nick, time_t timelimit)
103 adx 30 {
104 michael 1358 dlink_node *ptr = NULL;
105 adx 30
106     timelimit = CurrentTime - timelimit;
107    
108 michael 1358 DLINK_FOREACH(ptr, WHOWASHASH[strhash(nick)].head)
109 adx 30 {
110 michael 1358 struct Whowas *temp = ptr->data;
111    
112     if (temp->logoff < timelimit)
113     continue;
114 adx 30 if (irccmp(nick, temp->name))
115     continue;
116 michael 1298 return temp->online;
117 adx 30 }
118    
119 michael 1298 return NULL;
120 adx 30 }
121    
122     void
123 michael 2297 whowas_count_memory(unsigned int *const count, uint64_t *const bytes)
124 adx 30 {
125 michael 2297 const struct Whowas *tmp = &WHOWAS[0];
126     unsigned int i = 0;
127 adx 30
128 michael 2297 for (; i < NICKNAMEHISTORYLENGTH; ++i, ++tmp)
129 adx 30 {
130     if (tmp->hashv != -1)
131     {
132 michael 2297 (*count)++;
133     (*bytes) += sizeof(struct Whowas);
134 adx 30 }
135     }
136     }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision