ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/user.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/user.c (file contents):
Revision 6764 by michael, Fri Nov 13 18:38:18 2015 UTC vs.
Revision 8963 by michael, Sat May 11 21:06:49 2019 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2015 ircd-hybrid development team
4 > *  Copyright (c) 1997-2019 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 38 | Line 38
38   #include "motd.h"
39   #include "numeric.h"
40   #include "conf.h"
41 + #include "conf_gecos.h"
42   #include "log.h"
43   #include "server.h"
44 + #include "server_capab.h" /* TBR: RHOST compatibility mode */
45   #include "send.h"
46   #include "memory.h"
47   #include "packet.h"
48   #include "rng_mt.h"
47 – #include "userhost.h"
49   #include "misc.h"
50   #include "parse.h"
51   #include "watch.h"
52   #include "isupport.h"
53 + #include "tls.h"
54 + #include "patchlevel.h"
55  
56 < static char umode_buffer[IRCD_BUFSIZE];
56 > static char umode_buffer[UMODE_MAX_STR];
57  
58   const struct user_modes *umode_map[256];
59   const struct user_modes  umode_tab[] =
# Line 59 | Line 62 | const struct user_modes  umode_tab[] =
62    { 'F', UMODE_FARCONNECT   },
63    { 'G', UMODE_SOFTCALLERID },
64    { 'H', UMODE_HIDDEN       },
65 +  { 'X', UMODE_EXPIRATION   },
66    { 'R', UMODE_REGONLY      },
67    { 'S', UMODE_SSL          },
68    { 'W', UMODE_WEBIRC       },
# Line 81 | Line 85 | const struct user_modes  umode_tab[] =
85    { 's', UMODE_SERVNOTICE   },
86    { 'u', UMODE_UNAUTH       },
87    { 'w', UMODE_WALLOP       },
84 –  { 'x', UMODE_HIDDENHOST   },
88    { 'y', UMODE_SPY          },
89    { '\0', 0 }
90   };
# Line 107 | Line 110 | user_modes_init(void)
110   * side effects - display to client user counts etc.
111   */
112   void
113 < show_lusers(struct Client *source_p)
113 > show_lusers(struct Client *client_p)
114   {
115 <  if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
116 <    sendto_one_numeric(source_p, &me, RPL_LUSERCLIENT, (Count.total - Count.invisi),
115 >  if (ConfigServerHide.hide_servers == 0 || HasUMode(client_p, UMODE_OPER))
116 >    sendto_one_numeric(client_p, &me, RPL_LUSERCLIENT, (dlink_list_length(&global_client_list) - Count.invisi),
117                         Count.invisi, dlink_list_length(&global_server_list));
118    else
119 <    sendto_one_numeric(source_p, &me, RPL_LUSERCLIENT, (Count.total - Count.invisi),
119 >    sendto_one_numeric(client_p, &me, RPL_LUSERCLIENT, (dlink_list_length(&global_client_list) - Count.invisi),
120                         Count.invisi, 1);
121  
122    if (Count.oper)
123 <    sendto_one_numeric(source_p, &me, RPL_LUSEROP, Count.oper);
123 >    sendto_one_numeric(client_p, &me, RPL_LUSEROP, Count.oper);
124  
125    if (dlink_list_length(&unknown_list))
126 <    sendto_one_numeric(source_p, &me, RPL_LUSERUNKNOWN, dlink_list_length(&unknown_list));
126 >    sendto_one_numeric(client_p, &me, RPL_LUSERUNKNOWN, dlink_list_length(&unknown_list));
127  
128 <  if (dlink_list_length(&channel_list))
129 <    sendto_one_numeric(source_p, &me, RPL_LUSERCHANNELS, dlink_list_length(&channel_list));
128 >  if (dlink_list_length(channel_get_list()))
129 >    sendto_one_numeric(client_p, &me, RPL_LUSERCHANNELS, dlink_list_length(channel_get_list()));
130  
131 <  if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
131 >  if (ConfigServerHide.hide_servers == 0 || HasUMode(client_p, UMODE_OPER))
132    {
133 <    sendto_one_numeric(source_p, &me, RPL_LUSERME, Count.local, Count.myserver);
134 <    sendto_one_numeric(source_p, &me, RPL_LOCALUSERS, Count.local, Count.max_loc);
133 >    sendto_one_numeric(client_p, &me, RPL_LUSERME, dlink_list_length(&local_client_list), dlink_list_length(&local_server_list));
134 >    sendto_one_numeric(client_p, &me, RPL_LOCALUSERS, dlink_list_length(&local_client_list), Count.max_loc);
135 >    sendto_one_numeric(client_p, &me, RPL_GLOBALUSERS, dlink_list_length(&global_client_list), Count.max_tot);
136 >    sendto_one_numeric(client_p, &me, RPL_STATSCONN, Count.max_loc_con, Count.max_loc, Count.totalrestartcount);
137    }
138    else
139    {
140 <    sendto_one_numeric(source_p, &me, RPL_LUSERME, Count.total, 0);
141 <    sendto_one_numeric(source_p, &me, RPL_LOCALUSERS, Count.total, Count.max_tot);
140 >    sendto_one_numeric(client_p, &me, RPL_LUSERME, dlink_list_length(&global_client_list), 0);
141 >    sendto_one_numeric(client_p, &me, RPL_LOCALUSERS, dlink_list_length(&global_client_list), Count.max_tot);
142 >    sendto_one_numeric(client_p, &me, RPL_GLOBALUSERS, dlink_list_length(&global_client_list), Count.max_tot);
143    }
138 –
139 –  sendto_one_numeric(source_p, &me, RPL_GLOBALUSERS, Count.total, Count.max_tot);
140 –
141 –  if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
142 –    sendto_one_numeric(source_p, &me, RPL_STATSCONN, Count.max_loc_con,
143 –                       Count.max_loc_cli, Count.totalrestartcount);
144 –
145 –  if (Count.local > Count.max_loc_cli)
146 –    Count.max_loc_cli = Count.local;
147 –
148 –  if ((Count.local + Count.myserver) > Count.max_loc_con)
149 –    Count.max_loc_con = Count.local + Count.myserver;
144   }
145  
146   /* report_and_set_user_flags()
147   *
148 < * inputs       - pointer to source_p
148 > * inputs       - pointer to client_p
149   *              - pointer to conf for this user
150   * output       - NONE
151   * side effects - Report to user any special flags
152   *                they are getting, and set them.
153   */
154   static void
155 < report_and_set_user_flags(struct Client *source_p, const struct MaskItem *conf)
155 > report_and_set_user_flags(struct Client *client_p, const struct MaskItem *conf)
156   {
157    /* If this user is being spoofed, tell them so */
158    if (IsConfDoSpoofIp(conf))
159 <    sendto_one_notice(source_p, &me, ":*** Spoofing your IP. Congrats.");
159 >    sendto_one_notice(client_p, &me, ":*** Spoofing your IP");
160  
161    /* If this user is in the exception class, set it "E lined" */
162    if (IsConfExemptKline(conf))
163    {
164 <    AddFlag(source_p, FLAGS_EXEMPTKLINE);
165 <    sendto_one_notice(source_p, &me, ":*** You are exempt from K/D lines. Congrats.");
164 >    AddFlag(client_p, FLAGS_EXEMPTKLINE);
165 >    sendto_one_notice(client_p, &me, ":*** You are exempt from K/D lines");
166    }
167  
168    if (IsConfExemptXline(conf))
169    {
170 <    AddFlag(source_p, FLAGS_EXEMPTXLINE);
171 <    sendto_one_notice(source_p, &me, ":*** You are exempt from X lines. Congrats.");
170 >    AddFlag(client_p, FLAGS_EXEMPTXLINE);
171 >    sendto_one_notice(client_p, &me, ":*** You are exempt from X lines");
172    }
173  
174    if (IsConfExemptResv(conf))
175    {
176 <    AddFlag(source_p, FLAGS_EXEMPTRESV);
177 <    sendto_one_notice(source_p, &me, ":*** You are exempt from resvs. Congrats.");
176 >    AddFlag(client_p, FLAGS_EXEMPTRESV);
177 >    sendto_one_notice(client_p, &me, ":*** You are exempt from resvs");
178    }
179  
180    /* If this user is exempt from user limits set it "F lined" */
181    if (IsConfExemptLimits(conf))
182    {
183 <    AddFlag(source_p, FLAGS_NOLIMIT);
184 <    sendto_one_notice(source_p, &me, ":*** You are exempt from user limits. Congrats.");
183 >    AddFlag(client_p, FLAGS_NOLIMIT);
184 >    sendto_one_notice(client_p, &me, ":*** You are exempt from user limits");
185    }
186  
187    if (IsConfCanFlood(conf))
188    {
189 <    AddFlag(source_p, FLAGS_CANFLOOD);
190 <    sendto_one_notice(source_p, &me, ":*** You are exempt from flood "
197 <                      "protection, aren't you fearsome.");
189 >    AddFlag(client_p, FLAGS_CANFLOOD);
190 >    sendto_one_notice(client_p, &me, ":*** You are exempt from flood protection");
191    }
192   }
193  
194   /* introduce_client()
195   *
196 < * inputs       - source_p
196 > * inputs       - client_p
197   * output       - NONE
198   * side effects - This common function introduces a client to the rest
199   *                of the net, either from a local client connect or
200   *                from a remote connect.
201   */
202   static void
203 < introduce_client(struct Client *source_p)
203 > introduce_client(struct Client *client_p)
204   {
205 <  dlink_node *node = NULL;
206 <  char ubuf[IRCD_BUFSIZE] = "";
205 >  dlink_node *node;
206 >  char buf[UMODE_MAX_STR] = "";
207  
208 <  if (MyClient(source_p))
209 <    send_umode(source_p, source_p, 0, ubuf);
217 <  else
218 <    send_umode(NULL, source_p, 0, ubuf);
208 >  send_umode(client_p, MyConnect(client_p), 0, buf);
209 >  watch_check_hash(client_p, RPL_LOGON);
210  
211 <  watch_check_hash(source_p, RPL_LOGON);
221 <
222 <  if (ubuf[0] == '\0')
211 >  if (buf[0] == '\0')
212    {
213 <    ubuf[0] = '+';
214 <    ubuf[1] = '\0';
213 >    buf[0] = '+';
214 >    buf[1] = '\0';
215    }
216  
217    DLINK_FOREACH(node, local_server_list.head)
218    {
219 <    struct Client *server = node->data;
219 >    struct Client *server_p = node->data;
220  
221 <    if (server == source_p->from)
221 >    if (server_p == client_p->from)
222        continue;
223  
224 <    if (IsCapable(server, CAPAB_SVS))
225 <      sendto_one(server, ":%s UID %s %u %lu %s %s %s %s %s %s :%s",
226 <                 source_p->servptr->id,
227 <                 source_p->name, source_p->hopcount+1,
228 <                 (unsigned long)source_p->tsinfo,
229 <                 ubuf, source_p->username, source_p->host,
230 <                 source_p->sockhost, source_p->id,
231 <                 source_p->account,
232 <                 source_p->info);
224 >    /* TBR: compatibility mode */
225 >    if (IsCapable(server_p, CAPAB_RHOST))
226 >      sendto_one(server_p, ":%s UID %s %u %ju %s %s %s %s %s %s %s :%s",
227 >                 client_p->servptr->id,
228 >                 client_p->name, client_p->hopcount+1,
229 >                 client_p->tsinfo,
230 >                 buf, client_p->username, client_p->host, client_p->realhost,
231 >                 client_p->sockhost, client_p->id,
232 >                 client_p->account,
233 >                 client_p->info);
234      else
235 <      sendto_one(server, ":%s UID %s %u %lu %s %s %s %s %s :%s",
236 <                 source_p->servptr->id,
237 <                 source_p->name, source_p->hopcount+1,
238 <                 (unsigned long)source_p->tsinfo,
239 <                 ubuf, source_p->username, source_p->host,
240 <                 source_p->sockhost, source_p->id, source_p->info);
235 >      sendto_one(server_p, ":%s UID %s %u %ju %s %s %s %s %s %s :%s",
236 >                 client_p->servptr->id,
237 >                 client_p->name, client_p->hopcount+1,
238 >                 client_p->tsinfo,
239 >                 buf, client_p->username, client_p->host,
240 >                 client_p->sockhost, client_p->id,
241 >                 client_p->account,
242 >                 client_p->info);
243  
244 <    if (!EmptyString(source_p->certfp))
245 <      sendto_one(server, ":%s CERTFP %s", source_p->id, source_p->certfp);
244 >    if (!EmptyString(client_p->certfp))
245 >      sendto_one(server_p, ":%s CERTFP %s", client_p->id, client_p->certfp);
246    }
247   }
248  
# Line 261 | Line 253 | introduce_client(struct Client *source_p
253   * side effects -
254   */
255   static void
256 < user_welcome(struct Client *source_p)
256 > user_welcome(struct Client *client_p)
257   {
258    static const char built_date[] = __DATE__ " at " __TIME__;
259  
260 < #ifdef HAVE_LIBCRYPTO
269 <  if (HasFlag(source_p, FLAGS_SSL))
260 >  if (HasFlag(client_p, FLAGS_SSL))
261    {
262 <    AddUMode(source_p, UMODE_SSL);
263 <    sendto_one_notice(source_p, &me, ":*** Connected securely via %s",
264 <                      ssl_get_cipher(source_p->connection->fd.ssl));
265 <  }
266 < #endif
267 <
268 <  sendto_one_numeric(source_p, &me, RPL_WELCOME, ConfigServerInfo.network_name,
269 <                     source_p->name);
270 <  sendto_one_numeric(source_p, &me, RPL_YOURHOST,
271 <                     listener_get_name(source_p->connection->listener), ircd_version);
272 <  sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
273 <  sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer);
274 <
275 <  isupport_show(source_p);
276 <  show_lusers(source_p);
286 <  motd_signon(source_p);
262 >    AddUMode(client_p, UMODE_SSL);
263 >    sendto_one_notice(client_p, &me, ":*** Connected securely via %s",
264 >                      tls_get_cipher(&client_p->connection->fd->ssl));
265 >  }
266 >
267 >  sendto_one_numeric(client_p, &me, RPL_WELCOME, ConfigServerInfo.network_name,
268 >                     client_p->name, client_p->username, client_p->realhost);
269 >  sendto_one_numeric(client_p, &me, RPL_YOURHOST,
270 >                     listener_get_name(client_p->connection->listener), PATCHLEVEL);
271 >  sendto_one_numeric(client_p, &me, RPL_CREATED, built_date);
272 >  sendto_one_numeric(client_p, &me, RPL_MYINFO, me.name, PATCHLEVEL, umode_buffer);
273 >
274 >  isupport_show(client_p);
275 >  show_lusers(client_p);
276 >  motd_signon(client_p);
277   }
278  
279   /* check_xline()
# Line 292 | Line 282 | user_welcome(struct Client *source_p)
282   * outupt       - 1 if exiting 0 if ok
283   * side effects -
284   */
285 < static int
286 < check_xline(struct Client *source_p)
285 > static bool
286 > check_xline(struct Client *client_p)
287   {
288 <  struct MaskItem *conf = NULL;
288 >  const struct GecosItem *gecos = NULL;
289  
290 <  if (HasFlag(source_p, FLAGS_EXEMPTXLINE))
291 <    return 0;
290 >  if (HasFlag(client_p, FLAGS_EXEMPTXLINE))
291 >    return false;
292  
293 <  if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
293 >  if ((gecos = gecos_find(client_p->info, match)))
294    {
305 –    ++conf->count;
295      sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
296                           "X-line Rejecting [%s] [%s], user %s [%s]",
297 <                         source_p->info, conf->reason,
298 <                         get_client_name(source_p, HIDE_IP),
299 <                         source_p->sockhost);
297 >                         client_p->info, gecos->reason,
298 >                         client_get_name(client_p, HIDE_IP),
299 >                         client_p->sockhost);
300  
301      ++ServerStats.is_ref;
302 <    exit_client(source_p, "Bad user info");
303 <    return 1;
302 >    exit_client(client_p, "Bad user info");
303 >    return true;
304    }
305  
306 <  return 0;
306 >  return false;
307   }
308  
309   /*! \brief This function is called when both NICK and USER messages
310   *      have been accepted for the client, in whatever order. Only
311   *      after this, is the UID message propagated.
312 < * \param source_p Pointer to given client to introduce
312 > * \param client_p Pointer to given client to introduce
313   */
314   void
315 < register_local_user(struct Client *source_p)
315 > register_local_user(struct Client *client_p)
316   {
328 –  const char *id = NULL;
317    const struct MaskItem *conf = NULL;
318  
319 <  assert(source_p == source_p->from);
320 <  assert(MyConnect(source_p));
321 <  assert(IsUnknown(source_p));
322 <  assert(!source_p->connection->registration);
319 >  assert(client_p == client_p->from);
320 >  assert(client_p->connection->registration == 0);
321 >  assert(MyConnect(client_p));
322 >  assert(IsUnknown(client_p));
323  
324    if (ConfigGeneral.ping_cookie)
325    {
326 <    if (!HasFlag(source_p, FLAGS_PINGSENT) && !source_p->connection->random_ping)
326 >    if (!HasFlag(client_p, FLAGS_PINGSENT) && client_p->connection->random_ping == 0)
327      {
328        do
329 <        source_p->connection->random_ping = genrand_int32();
330 <      while (!source_p->connection->random_ping);
329 >        client_p->connection->random_ping = genrand_int32();
330 >      while (client_p->connection->random_ping == 0);
331  
332 <      sendto_one(source_p, "PING :%u", source_p->connection->random_ping);
333 <      AddFlag(source_p, FLAGS_PINGSENT);
332 >      sendto_one(client_p, "PING :%u", client_p->connection->random_ping);
333 >      AddFlag(client_p, FLAGS_PINGSENT);
334        return;
335      }
336  
337 <    if (!HasFlag(source_p, FLAGS_PING_COOKIE))
337 >    if (!HasFlag(client_p, FLAGS_PING_COOKIE))
338        return;
339    }
340  
341 <  source_p->connection->last_privmsg = CurrentTime;
354 <  /* Straight up the maximum rate of flooding... */
355 <  source_p->connection->allow_read = MAX_FLOOD_BURST;
356 <
357 <  if (!check_client(source_p))
341 >  if (check_client(client_p) == 0)
342      return;
343  
344 <  if (!valid_hostname(source_p->host))
361 <  {
362 <    sendto_one_notice(source_p, &me, ":*** Notice -- You have an illegal "
363 <                      "character in your hostname");
364 <    strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
365 <  }
344 >  conf = client_p->connection->confs.head->data;
345  
346 <  conf = source_p->connection->confs.head->data;
368 <
369 <  if (!HasFlag(source_p, FLAGS_GOTID))
346 >  if (!HasFlag(client_p, FLAGS_GOTID))
347    {
348      char username[USERLEN + 1] = "";
349      unsigned int i = 0;
# Line 374 | Line 351 | register_local_user(struct Client *sourc
351      if (IsNeedIdentd(conf))
352      {
353        ++ServerStats.is_ref;
354 <      sendto_one_notice(source_p, &me, ":*** Notice -- You need to install "
354 >      sendto_one_notice(client_p, &me, ":*** Notice -- You need to install "
355                          "identd to use this server");
356 <      exit_client(source_p, "Install identd");
356 >      exit_client(client_p, "Install identd");
357        return;
358      }
359  
360 <    strlcpy(username, source_p->username, sizeof(username));
360 >    strlcpy(username, client_p->username, sizeof(username));
361  
362      if (!IsNoTilde(conf))
363 <      source_p->username[i++] = '~';
363 >      client_p->username[i++] = '~';
364  
365      for (const char *p = username; *p && i < USERLEN; ++p)
366 <      source_p->username[i++] = *p;
366 >      client_p->username[i++] = *p;
367  
368 <    source_p->username[i] = '\0';
368 >    client_p->username[i] = '\0';
369    }
370  
371    /* Password check */
372    if (!EmptyString(conf->passwd))
373    {
374 <    if (!match_conf_password(source_p->connection->password, conf))
374 >    if (match_conf_password(client_p->connection->password, conf) == false)
375      {
376        ++ServerStats.is_ref;
377  
378 <      sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
379 <      exit_client(source_p, "Bad Password");
378 >      sendto_one_numeric(client_p, &me, ERR_PASSWDMISMATCH);
379 >      exit_client(client_p, "Bad Password");
380        return;
381      }
382    }
383  
384    /*
385 <   * Don't free source_p->connection->password here - it can be required
385 >   * Don't free client_p->connection->password here - it can be required
386     * by masked /stats I if there are auth {} blocks with need_password = no;
387     * --adx
388     */
389  
390    /*
391 <   * Report if user has &^>= etc. and set flags as needed in source_p
391 >   * Report if user has &^>= etc. and set flags as needed in client_p
392     */
393 <  report_and_set_user_flags(source_p, conf);
393 >  report_and_set_user_flags(client_p, conf);
394  
395 <  if (IsDead(source_p))
395 >  if (IsDead(client_p))
396      return;
397  
398    /*
# Line 426 | Line 403 | register_local_user(struct Client *sourc
403     * probably be just a percentage of the MAXCLIENTS...
404     *   -Taner
405     */
406 <  if ((Count.local >= GlobalSetOptions.maxclients + MAX_BUFFER) ||
407 <      (Count.local >= GlobalSetOptions.maxclients && !HasFlag(source_p, FLAGS_NOLIMIT)))
406 >  if ((dlink_list_length(&local_client_list) >= GlobalSetOptions.maxclients + MAX_BUFFER) ||
407 >      (dlink_list_length(&local_client_list) >= GlobalSetOptions.maxclients && !HasFlag(client_p, FLAGS_NOLIMIT)))
408    {
409      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
410                           "Too many clients, rejecting %s[%s].",
411 <                         source_p->name, source_p->host);
411 >                         client_p->name, client_p->host);
412      ++ServerStats.is_ref;
413 <    exit_client(source_p, "Sorry, server is full - try later");
413 >    exit_client(client_p, "Sorry, server is full - try later");
414      return;
415    }
416  
417 <  if (!valid_username(source_p->username, 1))
417 >  if (valid_username(client_p->username, true) == false)
418    {
419      char buf[IRCD_BUFSIZE] = "";
420  
421      sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
422                           "Invalid username: %s (%s@%s)",
423 <                         source_p->name, source_p->username, source_p->host);
423 >                         client_p->name, client_p->username, client_p->host);
424      ++ServerStats.is_ref;
425 <    snprintf(buf, sizeof(buf), "Invalid username [%s]", source_p->username);
426 <    exit_client(source_p, buf);
425 >    snprintf(buf, sizeof(buf), "Invalid username [%s]", client_p->username);
426 >    exit_client(client_p, buf);
427      return;
428    }
429  
430 <  if (check_xline(source_p))
430 >  if (check_xline(client_p))
431      return;
432  
433 +  const char *id;
434    while (hash_find_id((id = uid_get())))
435      ;
436  
437 <  strlcpy(source_p->id, id, sizeof(source_p->id));
438 <  hash_add_id(source_p);
437 >  strlcpy(client_p->id, id, sizeof(client_p->id));
438 >  hash_add_id(client_p);
439  
440    sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
441                         "Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s>",
442 <                       source_p->name, source_p->username, source_p->host,
443 <                       source_p->sockhost,
444 <                       get_client_class(&source_p->connection->confs),
445 <                       source_p->info, source_p->id);
442 >                       client_p->name, client_p->username, client_p->realhost,
443 >                       client_p->sockhost,
444 >                       get_client_class(&client_p->connection->confs),
445 >                       client_p->info, client_p->id);
446  
447    if (ConfigGeneral.invisible_on_connect)
448    {
449 <    AddUMode(source_p, UMODE_INVISIBLE);
449 >    AddUMode(client_p, UMODE_INVISIBLE);
450      ++Count.invisi;
451    }
452  
453 <  if (++Count.local > Count.max_loc)
453 >  assert(client_p->servptr == &me);
454 >
455 >  SetClient(client_p);
456 >  client_p->connection->last_privmsg = event_base->time.sec_monotonic;
457 >
458 >  dlinkAdd(client_p, &client_p->lnode, &client_p->servptr->serv->client_list);
459 >  dlinkAdd(client_p, &client_p->node, &global_client_list);
460 >
461 >  assert(dlinkFind(&unknown_list, client_p));
462 >
463 >  dlink_move_node(&client_p->connection->lclient_node,
464 >                  &unknown_list, &local_client_list);
465 >
466 >  if (dlink_list_length(&local_client_list) > Count.max_loc)
467    {
468 <    Count.max_loc = Count.local;
468 >    Count.max_loc = dlink_list_length(&local_client_list);
469  
470      if (!(Count.max_loc % 10))
471        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
# Line 482 | Line 473 | register_local_user(struct Client *sourc
473                             Count.max_loc);
474    }
475  
476 <  if (++Count.total > Count.max_tot)
477 <    Count.max_tot = Count.total;
478 <  ++Count.totalrestartcount;
476 >  if ((dlink_list_length(&local_client_list) +
477 >       dlink_list_length(&local_server_list)) > Count.max_loc_con)
478 >    Count.max_loc_con = dlink_list_length(&local_client_list) +
479 >                        dlink_list_length(&local_server_list);
480  
481 <  assert(source_p->servptr == &me);
482 <  SetClient(source_p);
483 <  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
492 <  dlinkAdd(source_p, &source_p->node, &global_client_list);
493 <
494 <  assert(dlinkFind(&unknown_list, source_p));
495 <
496 <  dlink_move_node(&source_p->connection->lclient_node,
497 <                  &unknown_list, &local_client_list);
481 >  if (dlink_list_length(&global_client_list) > Count.max_tot)
482 >    Count.max_tot = dlink_list_length(&global_client_list);
483 >  ++Count.totalrestartcount;
484  
485 <  user_welcome(source_p);
500 <  userhost_add(source_p->username, source_p->host, 0);
501 <  AddFlag(source_p, FLAGS_USERHOST);
485 >  user_welcome(client_p);
486  
487 <  introduce_client(source_p);
487 >  introduce_client(client_p);
488   }
489  
490   /* register_remote_user()
491   *
492 < * inputs       - source_p remote or directly connected client
492 > * inputs       - client_p remote or directly connected client
493   *              - username to register as
494   *              - host name to register as
495   *              - server name
# Line 514 | Line 498 | register_local_user(struct Client *sourc
498   *                is introduced by a server.
499   */
500   void
501 < register_remote_user(struct Client *source_p)
501 > register_remote_user(struct Client *client_p)
502   {
503 <  const struct Client *target_p = NULL;
520 <
521 <  if ((target_p = source_p->servptr) && target_p->from != source_p->from)
522 <  {
523 <    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
524 <                         "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
525 <                         source_p->from->name, source_p->name, source_p->username,
526 <                         source_p->host, source_p->servptr->name,
527 <                         target_p->name, target_p->from->name);
528 <    sendto_one(source_p->from,
529 <               ":%s KILL %s :%s (UID from wrong direction (%s != %s))",
530 <               me.id, source_p->id, me.name, source_p->servptr->name,
531 <               target_p->from->name);
532 <
533 <    AddFlag(source_p, FLAGS_KILLED);
534 <    exit_client(source_p, "UID server wrong direction");
535 <    return;
536 <  }
503 >  assert(client_p->servptr->from == client_p->from);
504  
505    /*
506     * If the nick has been introduced by a services server,
507     * make it a service as well.
508     */
509 <  if (HasFlag(source_p->servptr, FLAGS_SERVICE))
510 <    AddFlag(source_p, FLAGS_SERVICE);
509 >  if (HasFlag(client_p->servptr, FLAGS_SERVICE))
510 >    AddFlag(client_p, FLAGS_SERVICE);
511  
512 <  if (++Count.total > Count.max_tot)
513 <    Count.max_tot = Count.total;
512 >  SetClient(client_p);
513 >  dlinkAdd(client_p, &client_p->lnode, &client_p->servptr->serv->client_list);
514 >  dlinkAdd(client_p, &client_p->node, &global_client_list);
515  
516 <  SetClient(source_p);
517 <  dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
550 <  dlinkAdd(source_p, &source_p->node, &global_client_list);
551 <  userhost_add(source_p->username, source_p->host, 1);
552 <  AddFlag(source_p, FLAGS_USERHOST);
516 >  if (dlink_list_length(&global_client_list) > Count.max_tot)
517 >    Count.max_tot = dlink_list_length(&global_client_list);
518  
519 <  if (HasFlag(source_p->servptr, FLAGS_EOB))
519 >  if (HasFlag(client_p->servptr, FLAGS_EOB))
520      sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
521                           "Client connecting at %s: %s (%s@%s) [%s] [%s] <%s>",
522 <                         source_p->servptr->name,
523 <                         source_p->name, source_p->username, source_p->host,
524 <                         source_p->sockhost, source_p->info, source_p->id);
522 >                         client_p->servptr->name,
523 >                         client_p->name, client_p->username, client_p->realhost,
524 >                         client_p->sockhost, client_p->info, client_p->id);
525  
526 <  introduce_client(source_p);
526 >  introduce_client(client_p);
527   }
528  
529   /* valid_hostname()
# Line 570 | Line 535 | register_remote_user(struct Client *sour
535   * NOTE: this doesn't allow a hostname to begin with a dot and
536   * will not allow more dots than chars.
537   */
538 < int
538 > bool
539   valid_hostname(const char *hostname)
540   {
541    const char *p = hostname;
# Line 578 | Line 543 | valid_hostname(const char *hostname)
543    assert(p);
544  
545    if (EmptyString(p) || *p == '.' || *p == ':')
546 <    return 0;
546 >    return false;
547  
548    for (; *p; ++p)
549      if (!IsHostChar(*p))
550 <      return 0;
550 >      return false;
551  
552    return p - hostname <= HOSTLEN;
553   }
# Line 598 | Line 563 | valid_hostname(const char *hostname)
563   * Allow '.' in username to allow for "first.last"
564   * style of username
565   */
566 < int
567 < valid_username(const char *username, const int local)
566 > bool
567 > valid_username(const char *username, bool local)
568   {
569    const char *p = username;
570  
# Line 614 | Line 579 | valid_username(const char *username, con
579     * or "-hi-@somehost", "h-----@somehost" would still be accepted.
580     */
581    if (!IsAlNum(*p))
582 <    return 0;
582 >    return false;
583  
584    if (local)
585    {
# Line 625 | Line 590 | valid_username(const char *username, con
590        if (*p == '.' && ConfigGeneral.dots_in_ident)
591        {
592          if (++dots > ConfigGeneral.dots_in_ident)
593 <          return 0;
593 >          return false;
594          if (!IsUserChar(*(p + 1)))
595 <          return 0;
595 >          return false;
596        }
597        else if (!IsUserChar(*p))
598 <        return 0;
598 >        return false;
599      }
600    }
601    else
602    {
603      while (*++p)
604        if (!IsUserChar(*p))
605 <        return 0;
605 >        return false;
606    }
607  
608    return p - username <= USERLEN;
# Line 650 | Line 615 | valid_username(const char *username, con
615   * output       - none
616   * side effects - walks through the nickname, returning 0 if erroneous
617   */
618 < int
619 < valid_nickname(const char *nickname, const int local)
618 > bool
619 > valid_nickname(const char *nickname, bool local)
620   {
621    const char *p = nickname;
622  
# Line 661 | Line 626 | valid_nickname(const char *nickname, con
626     * Nicks can't start with a digit or - or be 0 length.
627     */
628    if (EmptyString(p) || *p == '-' || (IsDigit(*p) && local))
629 <    return 0;
629 >    return false;
630  
631    for (; *p; ++p)
632      if (!IsNickChar(*p))
633 <      return 0;
633 >      return false;
634  
635    return p - nickname <= NICKLEN;
636   }
637  
638 < /* send_umode()
639 < * send the MODE string for user (user) to connection client_p
640 < * -avalon
641 < *
642 < * inputs       - client_p
678 < *              - source_p
679 < *              - int old
680 < *              - suplied umode_buf
681 < * output       - NONE
638 > /*! \brief Builds a mode change string to buffer pointed by \a buf
639 > * \param client_p  Pointer to client
640 > * \param dispatch  Whether to send a MODE message to client_p
641 > * \param old       Old user mode to compare against when building new mode buffer
642 > * \param buf       Pointer to buffer to build string in
643   */
644   void
645 < send_umode(struct Client *client_p, struct Client *source_p,
685 <           unsigned int old, char *umode_buf)
645 > send_umode(struct Client *client_p, bool dispatch, unsigned int old, char *buf)
646   {
647 <  char *m = umode_buf;
647 >  char *m = buf;
648    int what = 0;
649  
650    /*
651     * Build a string in umode_buf to represent the change in the user's
652 <   * mode between the new (source_p->umodes) and 'old'.
652 >   * mode between the new (client_p->umodes) and 'old'.
653     */
654    for (const struct user_modes *tab = umode_tab; tab->c; ++tab)
655    {
656 <    if ((tab->flag & old) && !HasUMode(source_p, tab->flag))
656 >    if ((tab->flag & old) && !HasUMode(client_p, tab->flag))
657      {
658        if (what == MODE_DEL)
659          *m++ = tab->c;
# Line 704 | Line 664 | send_umode(struct Client *client_p, stru
664          *m++ = tab->c;
665        }
666      }
667 <    else if (!(tab->flag & old) && HasUMode(source_p, tab->flag))
667 >    else if (!(tab->flag & old) && HasUMode(client_p, tab->flag))
668      {
669        if (what == MODE_ADD)
670          *m++ = tab->c;
# Line 719 | Line 679 | send_umode(struct Client *client_p, stru
679  
680    *m = '\0';
681  
682 <  if (*umode_buf && client_p)
682 >  if (dispatch == true && *buf)
683      sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
684                 client_p->name, client_p->username,
685 <               client_p->host, client_p->name, umode_buf);
685 >               client_p->host, client_p->name, buf);
686   }
687  
688   /* send_umode_out()
# Line 732 | Line 692 | send_umode(struct Client *client_p, stru
692   * side effects - Only send ubuf out to servers that know about this client
693   */
694   void
695 < send_umode_out(struct Client *source_p, unsigned int old)
695 > send_umode_out(struct Client *client_p, unsigned int old)
696   {
697 <  char buf[IRCD_BUFSIZE] = "";
697 >  char buf[UMODE_MAX_STR] = "";
698  
699 <  send_umode(MyClient(source_p) ? source_p : NULL, source_p, old, buf);
699 >  send_umode(client_p, MyConnect(client_p), old, buf);
700  
701    if (buf[0])
702 <    sendto_server(source_p, 0, 0, ":%s MODE %s :%s",
703 <                  source_p->id, source_p->id, buf);
702 >    sendto_server(client_p, 0, 0, ":%s MODE %s :%s",
703 >                  client_p->id, client_p->id, buf);
704   }
705  
706   void
707 < user_set_hostmask(struct Client *target_p, const char *hostname, const int what)
707 > user_set_hostmask(struct Client *client_p, const char *hostname)
708   {
709 <  dlink_node *node = NULL;
709 >  dlink_node *node;
710  
711 <  if (!strcmp(target_p->host, hostname))
711 >  if (strcmp(client_p->host, hostname) == 0)
712      return;
713  
754 –  switch (what)
755 –  {
756 –    case MODE_ADD:
757 –      AddUMode(target_p, UMODE_HIDDENHOST);
758 –      break;
759 –    case MODE_DEL:
760 –      DelUMode(target_p, UMODE_HIDDENHOST);
761 –      break;
762 –    default: return;
763 –  }
764 –
714    if (ConfigGeneral.cycle_on_host_change)
715 <    sendto_common_channels_local(target_p, 0, 0, ":%s!%s@%s QUIT :Changing hostname",
716 <                                 target_p->name, target_p->username, target_p->host);
768 <
769 <  if (HasFlag(target_p, FLAGS_USERHOST))
770 <    userhost_del(target_p->username, target_p->host, !MyConnect(target_p));
715 >    sendto_common_channels_local(client_p, false, 0, CAP_CHGHOST, ":%s!%s@%s QUIT :Changing hostname",
716 >                                 client_p->name, client_p->username, client_p->host);
717  
718 <  strlcpy(target_p->host, hostname, sizeof(target_p->host));
718 >  sendto_common_channels_local(client_p, true, CAP_CHGHOST, 0, ":%s!%s@%s CHGHOST %s %s",
719 >                               client_p->name, client_p->username,
720 >                               client_p->host, client_p->username, hostname);
721  
722 <  userhost_add(target_p->username, target_p->host, !MyConnect(target_p));
775 <  AddFlag(target_p, FLAGS_USERHOST);
722 >  strlcpy(client_p->host, hostname, sizeof(client_p->host));
723  
724 <  if (MyConnect(target_p))
724 >  if (MyConnect(client_p))
725    {
726 <    sendto_one_numeric(target_p, &me, RPL_VISIBLEHOST, target_p->host);
727 <    clear_ban_cache_client(target_p);
726 >    sendto_one_numeric(client_p, &me, RPL_VISIBLEHOST, client_p->host);
727 >    clear_ban_cache_list(&client_p->channel);
728    }
729  
730 <  if (!ConfigGeneral.cycle_on_host_change)
730 >  if (ConfigGeneral.cycle_on_host_change == 0)
731      return;
732  
733 <  DLINK_FOREACH(node, target_p->channel.head)
733 >  DLINK_FOREACH(node, client_p->channel.head)
734    {
735 <    char modebuf[4], nickbuf[NICKLEN * 3 + 3] = "";
735 >    char modebuf[CMEMBER_STATUS_FLAGS_LEN + 1];
736 >    char nickbuf[CMEMBER_STATUS_FLAGS_LEN * NICKLEN + CMEMBER_STATUS_FLAGS_LEN] = "";
737      char *p = modebuf;
738      int len = 0;
739      const struct Membership *member = node->data;
# Line 793 | Line 741 | user_set_hostmask(struct Client *target_
741      if (has_member_flags(member, CHFL_CHANOP))
742      {
743        *p++ = 'o';
744 <      len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
744 >      len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", client_p->name);
745      }
746  
747      if (has_member_flags(member, CHFL_HALFOP))
748      {
749        *p++ = 'h';
750 <      len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
750 >      len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", client_p->name);
751      }
752  
753      if (has_member_flags(member, CHFL_VOICE))
754      {
755        *p++ = 'v';
756 <      len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
756 >      len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", client_p->name);
757      }
758  
759      *p = '\0';
760  
761 <
762 <    sendto_channel_local(target_p, member->chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
763 <                         target_p->name, target_p->username,
764 <                         target_p->host, member->chptr->name,
765 <                         (!IsDigit(target_p->account[0]) && target_p->account[0] != '*') ? target_p->account : "*",
766 <                         target_p->info);
767 <    sendto_channel_local(target_p, member->chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
820 <                         target_p->name, target_p->username,
821 <                         target_p->host, member->chptr->name);
761 >    sendto_channel_local(client_p, member->chptr, 0, CAP_EXTENDED_JOIN, CAP_CHGHOST, ":%s!%s@%s JOIN %s %s :%s",
762 >                         client_p->name, client_p->username,
763 >                         client_p->host, member->chptr->name,
764 >                         client_p->account, client_p->info);
765 >    sendto_channel_local(client_p, member->chptr, 0, 0, CAP_EXTENDED_JOIN | CAP_CHGHOST, ":%s!%s@%s JOIN :%s",
766 >                         client_p->name, client_p->username,
767 >                         client_p->host, member->chptr->name);
768  
769      if (nickbuf[0])
770 <      sendto_channel_local(target_p, member->chptr, 0, 0, 0, ":%s MODE %s +%s %s",
771 <                           target_p->servptr->name, member->chptr->name,
770 >      sendto_channel_local(client_p, member->chptr, 0, 0, CAP_CHGHOST, ":%s MODE %s +%s %s",
771 >                           client_p->servptr->name, member->chptr->name,
772                             modebuf, nickbuf);
827 –    if (target_p->away[0])
828 –      sendto_channel_local(target_p, member->chptr, 0, CAP_AWAY_NOTIFY, 0,
829 –                           ":%s!%s@%s AWAY :%s",
830 –                           target_p->name, target_p->username,
831 –                           target_p->host, target_p->away);
773    }
774 +
775 +  if (client_p->away[0])
776 +    sendto_common_channels_local(client_p, false, CAP_AWAY_NOTIFY, CAP_CHGHOST,
777 +                                 ":%s!%s@%s AWAY :%s",
778 +                                 client_p->name, client_p->username,
779 +                                 client_p->host, client_p->away);
780   }

Comparing ircd-hybrid/trunk/src/user.c (property svn:keywords):
Revision 6764 by michael, Fri Nov 13 18:38:18 2015 UTC vs.
Revision 8963 by michael, Sat May 11 21:06:49 2019 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

– Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)