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/s_user.c (file contents):
Revision 3176 by michael, Tue Mar 18 20:00:16 2014 UTC vs.
Revision 3272 by michael, Sun Apr 6 11:34:14 2014 UTC

# Line 51 | Line 51
51   #include "watch.h"
52  
53   static char umode_buffer[IRCD_BUFSIZE];
54
55 static void user_welcome(struct Client *);
56 static void report_and_set_user_flags(struct Client *, const struct MaskItem *);
57 static int check_xline(struct Client *);
58 static void introduce_client(struct Client *);
54   static const char *uid_get(void);
55  
56   /* Used for building up the isupport string,
57   * used with init_isupport, add_isupport, delete_isupport
58   */
64
59   struct Isupport
60   {
61    dlink_node node;
# Line 224 | Line 218 | show_isupport(struct Client *source_p)
218      sendto_one_numeric(source_p, &me, RPL_ISUPPORT, ptr->data);
219   }
220  
221 +
222 + /* report_and_set_user_flags()
223 + *
224 + * inputs       - pointer to source_p
225 + *              - pointer to conf for this user
226 + * output       - NONE
227 + * side effects - Report to user any special flags
228 + *                they are getting, and set them.
229 + */
230 + static void
231 + report_and_set_user_flags(struct Client *source_p, const struct MaskItem *conf)
232 + {
233 +  /* If this user is being spoofed, tell them so */
234 +  if (IsConfDoSpoofIp(conf))
235 +    sendto_one_notice(source_p, &me, ":*** Spoofing your IP. Congrats.");
236 +
237 +  /* If this user is in the exception class, Set it "E lined" */
238 +  if (IsConfExemptKline(conf))
239 +  {
240 +    SetExemptKline(source_p);
241 +    sendto_one_notice(source_p, &me, ":*** You are exempt from K/D/G lines. Congrats.");
242 +  }
243 +
244 +  /*
245 +   * The else here is to make sure that G line exempt users
246 +   * do not get noticed twice.
247 +   */
248 +  else if (IsConfExemptGline(conf))
249 +  {
250 +    SetExemptGline(source_p);
251 +    sendto_one_notice(source_p, &me, ":*** You are exempt from G lines. Congrats.");
252 +  }
253 +
254 +  if (IsConfExemptResv(conf))
255 +  {
256 +    SetExemptResv(source_p);
257 +    sendto_one_notice(source_p, &me, ":*** You are exempt from resvs. Congrats.");
258 +  }
259 +
260 +  /* If this user is exempt from user limits set it "F lined" */
261 +  if (IsConfExemptLimits(conf))
262 +  {
263 +    SetExemptLimits(source_p);
264 +    sendto_one_notice(source_p, &me, ":*** You are exempt from user limits. Congrats.");
265 +  }
266 +
267 +  if (IsConfCanFlood(conf))
268 +  {
269 +    SetCanFlood(source_p);
270 +    sendto_one_notice(source_p, &me, ":*** You are exempt from flood "
271 +                      "protection, aren't you fearsome.");
272 +  }
273 + }
274 +
275 + /* introduce_client()
276 + *
277 + * inputs       - source_p
278 + * output       - NONE
279 + * side effects - This common function introduces a client to the rest
280 + *                of the net, either from a local client connect or
281 + *                from a remote connect.
282 + */
283 + static void
284 + introduce_client(struct Client *source_p)
285 + {
286 +  dlink_node *ptr = NULL;
287 +  char ubuf[IRCD_BUFSIZE] = "";
288 +
289 +  if (MyClient(source_p))
290 +    send_umode(source_p, source_p, 0, SEND_UMODES, ubuf);
291 +  else
292 +    send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
293 +
294 +  watch_check_hash(source_p, RPL_LOGON);
295 +
296 +  if (ubuf[0] == '\0')
297 +  {
298 +    ubuf[0] = '+';
299 +    ubuf[1] = '\0';
300 +  }
301 +
302 +  DLINK_FOREACH(ptr, serv_list.head)
303 +  {
304 +    struct Client *server = ptr->data;
305 +
306 +    if (server == source_p->from)
307 +      continue;
308 +
309 +    if (IsCapable(server, CAP_SVS))
310 +      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
311 +                 source_p->servptr->id,
312 +                 source_p->name, source_p->hopcount+1,
313 +                 (unsigned long)source_p->tsinfo,
314 +                 ubuf, source_p->username, source_p->host,
315 +                 (MyClient(source_p) && IsIPSpoof(source_p)) ?
316 +                 "0" : source_p->sockhost, source_p->id,
317 +                 source_p->svid,
318 +                 source_p->info);
319 +    else
320 +      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
321 +                 source_p->servptr->id,
322 +                 source_p->name, source_p->hopcount+1,
323 +                 (unsigned long)source_p->tsinfo,
324 +                 ubuf, source_p->username, source_p->host,
325 +                 (MyClient(source_p) && IsIPSpoof(source_p)) ?
326 +                 "0" : source_p->sockhost, source_p->id, source_p->info);
327 +
328 +    if (!EmptyString(source_p->certfp))
329 +      sendto_one(server, ":%s CERTFP %s", source_p->id, source_p->certfp);
330 +  }
331 + }
332 +
333 + /* user_welcome()
334 + *
335 + * inputs       - client pointer to client to welcome
336 + * output       - NONE
337 + * side effects -
338 + */
339 + static void
340 + user_welcome(struct Client *source_p)
341 + {
342 + #if defined(__TIME__) && defined(__DATE__)
343 +  static const char built_date[] = __DATE__ " at " __TIME__;
344 + #else
345 +  static const char built_date[] = "unknown";
346 + #endif
347 +
348 + #ifdef HAVE_LIBCRYPTO
349 +  if (HasFlag(source_p, FLAGS_SSL))
350 +  {
351 +    AddUMode(source_p, UMODE_SSL);
352 +    sendto_one_notice(source_p, &me, ":*** Connected securely via %s",
353 +                      ssl_get_cipher(source_p->localClient->fd.ssl));
354 +  }
355 + #endif
356 +
357 +  sendto_one_numeric(source_p, &me, RPL_WELCOME, ServerInfo.network_name,
358 +                     source_p->name);
359 +  sendto_one_numeric(source_p, &me, RPL_YOURHOST,
360 +                     get_listener_name(source_p->localClient->listener), ircd_version);
361 +  sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
362 +  sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer);
363 +  show_isupport(source_p);
364 +
365 +  if (source_p->id[0])
366 +    sendto_one_numeric(source_p, &me, RPL_YOURID, source_p->id);
367 +
368 +  show_lusers(source_p);
369 +  motd_signon(source_p);
370 + }
371 +
372 + /* check_xline()
373 + *
374 + * inputs       - pointer to client to test
375 + * outupt       - 1 if exiting 0 if ok
376 + * side effects -
377 + */
378 + static int
379 + check_xline(struct Client *source_p)
380 + {
381 +  struct MaskItem *conf = NULL;
382 +  const char *reason = NULL;
383 +
384 +  if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
385 +  {
386 +    ++conf->count;
387 +
388 +    if (conf->reason)
389 +      reason = conf->reason;
390 +    else
391 +      reason = CONF_NOREASON;
392 +
393 +    sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
394 +                         "X-line Rejecting [%s] [%s], user %s [%s]",
395 +                         source_p->info, reason,
396 +                         get_client_name(source_p, HIDE_IP),
397 +                         source_p->sockhost);
398 +
399 +    ++ServerStats.is_ref;
400 +    exit_client(source_p, "Bad user info");
401 +    return 1;
402 +  }
403 +
404 +  return 0;
405 + }
406 +
407   /*
408   ** register_local_user
409   **      This function is called when both NICK and USER messages
# Line 253 | Line 433 | register_local_user(struct Client *sourc
433    const char *id = NULL;
434    const struct MaskItem *conf = NULL;
435  
256  assert(source_p != NULL);
436    assert(source_p == source_p->from);
437    assert(MyConnect(source_p));
438    assert(!source_p->localClient->registration);
# Line 297 | Line 476 | register_local_user(struct Client *sourc
476  
477    if (!IsGotId(source_p))
478    {
479 <    char username[USERLEN + 1];
479 >    char username[USERLEN + 1] = "";
480      const char *p = username;
481      unsigned int i = 0;
482  
# Line 370 | Line 549 | register_local_user(struct Client *sourc
549    /* valid user name check */
550    if (!valid_username(source_p->username, 1))
551    {
552 <    char tmpstr2[IRCD_BUFSIZE];
552 >    char tmpstr2[IRCD_BUFSIZE] = "";
553  
554      sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
555                           "Invalid username: %s (%s@%s)",
# Line 385 | Line 564 | register_local_user(struct Client *sourc
564    if (check_xline(source_p))
565      return;
566  
567 <  while (hash_find_id((id = uid_get())) != NULL)
567 >  while (hash_find_id((id = uid_get())))
568      ;
569  
570    strlcpy(source_p->id, id, sizeof(source_p->id));
# Line 454 | Line 633 | register_remote_user(struct Client *sour
633   {
634    struct Client *target_p = NULL;
635  
457  assert(source_p != NULL);
636    assert(source_p->username != username);
637  
638    strlcpy(source_p->host, host, sizeof(source_p->host));
# Line 478 | Line 656 | register_remote_user(struct Client *sour
656                           source_p->host, source_p->from->name);
657      sendto_one(source_p->from,
658                 ":%s KILL %s :%s (Ghosted, server %s doesn't exist)",
659 <               ID(&me), ID(source_p), me.name, server);
659 >               me.id, source_p->id, me.name, server);
660  
661      AddFlag(source_p, FLAGS_KILLED);
662      exit_client(source_p, "Ghosted Client");
# Line 494 | Line 672 | register_remote_user(struct Client *sour
672                           target_p->name, target_p->from->name);
673      sendto_one(source_p->from,
674                 ":%s KILL %s :%s (NICK from wrong direction (%s != %s))",
675 <               ID(&me), ID(source_p), me.name, source_p->servptr->name,
675 >               me.id, source_p->id, me.name, source_p->servptr->name,
676                 target_p->from->name);
677  
678      AddFlag(source_p, FLAGS_KILLED);
# Line 528 | Line 706 | register_remote_user(struct Client *sour
706    introduce_client(source_p);
707   }
708  
531 /* introduce_client()
532 *
533 * inputs       - source_p
534 * output       - NONE
535 * side effects - This common function introduces a client to the rest
536 *                of the net, either from a local client connect or
537 *                from a remote connect.
538 */
539 static void
540 introduce_client(struct Client *source_p)
541 {
542  dlink_node *server_node = NULL;
543  char ubuf[IRCD_BUFSIZE];
544
545  if (MyClient(source_p))
546    send_umode(source_p, source_p, 0, SEND_UMODES, ubuf);
547  else
548    send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
549
550  watch_check_hash(source_p, RPL_LOGON);
551
552  if (ubuf[0] == '\0')
553  {
554    ubuf[0] = '+';
555    ubuf[1] = '\0';
556  }
557
558  DLINK_FOREACH(server_node, serv_list.head)
559  {
560    struct Client *server = server_node->data;
561
562    if (server == source_p->from)
563        continue;
564
565    if (IsCapable(server, CAP_SVS))
566      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
567                 source_p->servptr->id,
568                 source_p->name, source_p->hopcount+1,
569                 (unsigned long)source_p->tsinfo,
570                 ubuf, source_p->username, source_p->host,
571                 (MyClient(source_p) && IsIPSpoof(source_p)) ?
572                 "0" : source_p->sockhost, source_p->id,
573                 source_p->svid,
574                 source_p->info);
575    else
576      sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
577                 source_p->servptr->id,
578                 source_p->name, source_p->hopcount+1,
579                 (unsigned long)source_p->tsinfo,
580                 ubuf, source_p->username, source_p->host,
581                 (MyClient(source_p) && IsIPSpoof(source_p)) ?
582                 "0" : source_p->sockhost, source_p->id, source_p->info);
583
584    if (!EmptyString(source_p->certfp))
585      sendto_one(server, ":%s CERTFP %s", ID(source_p), source_p->certfp);
586  }
587 }
588
709   /* valid_hostname()
710   *
711   * Inputs       - pointer to hostname
# Line 600 | Line 720 | valid_hostname(const char *hostname)
720   {
721    const char *p = hostname;
722  
723 <  assert(p != NULL);
723 >  assert(p);
724  
725    if (EmptyString(p) || *p == '.' || *p == ':')
726      return 0;
# Line 629 | Line 749 | valid_username(const char *username, con
749    int dots      = 0;
750    const char *p = username;
751  
752 <  assert(p != NULL);
752 >  assert(p);
753  
754    if (*p == '~')
755      ++p;
# Line 680 | Line 800 | valid_nickname(const char *nickname, con
800    const char *p = nickname;
801    assert(nickname && *nickname);
802  
803 +  assert(p);
804 +
805    /* nicks can't start with a digit or - or be 0 length */
806    /* This closer duplicates behaviour of hybrid-6 */
807    if (*p == '-' || (IsDigit(*p) && local) || *p == '\0')
# Line 692 | Line 814 | valid_nickname(const char *nickname, con
814    return p - nickname <= NICKLEN;
815   }
816  
695 /* report_and_set_user_flags()
696 *
697 * inputs       - pointer to source_p
698 *              - pointer to conf for this user
699 * output       - NONE
700 * side effects - Report to user any special flags
701 *                they are getting, and set them.
702 */
703 static void
704 report_and_set_user_flags(struct Client *source_p, const struct MaskItem *conf)
705 {
706  /* If this user is being spoofed, tell them so */
707  if (IsConfDoSpoofIp(conf))
708    sendto_one_notice(source_p, &me, ":*** Spoofing your IP. Congrats.");
709
710  /* If this user is in the exception class, Set it "E lined" */
711  if (IsConfExemptKline(conf))
712  {
713    SetExemptKline(source_p);
714    sendto_one_notice(source_p, &me, ":*** You are exempt from K/D/G lines. Congrats.");
715  }
716
717  /*
718   * The else here is to make sure that G line exempt users
719   * do not get noticed twice.
720   */
721  else if (IsConfExemptGline(conf))
722  {
723    SetExemptGline(source_p);
724    sendto_one_notice(source_p, &me, ":*** You are exempt from G lines. Congrats.");
725  }
726
727  if (IsConfExemptResv(conf))
728  {
729    SetExemptResv(source_p);
730    sendto_one_notice(source_p, &me, ":*** You are exempt from resvs. Congrats.");
731  }
732
733  /* If this user is exempt from user limits set it "F lined" */
734  if (IsConfExemptLimits(conf))
735  {
736    SetExemptLimits(source_p);
737    sendto_one_notice(source_p, &me, ":*** You are exempt from user limits. Congrats.");
738  }
739
740  if (IsConfCanFlood(conf))
741  {
742    SetCanFlood(source_p);
743    sendto_one_notice(source_p, &me, ":*** You are exempt from flood "
744                      "protection, aren't you fearsome.");
745  }
746 }
747
817   /* set_user_mode()
818   *
819   * added 15/10/91 By Darren Reed.
# Line 756 | Line 825 | void
825   set_user_mode(struct Client *source_p, const int parc, char *parv[])
826   {
827    unsigned int flag, setflags;
828 <  char **p, *m, buf[IRCD_BUFSIZE];
828 >  char **p, *m, buf[IRCD_BUFSIZE] = "";
829    struct Client *target_p;
830    int what = MODE_ADD, badflag = 0, i;
831  
# Line 824 | Line 893 | set_user_mode(struct Client *source_p, c
893  
894              if (MyConnect(source_p))
895              {
896 <              dlink_node *dm = NULL;
896 >              dlink_node *ptr = NULL;
897  
898                detach_conf(source_p, CONF_OPER);
899                ClrOFlag(source_p);
900                DelUMode(source_p, ConfigFileEntry.oper_only_umodes);
901  
902 <              if ((dm = dlinkFindDelete(&oper_list, source_p)) != NULL)
903 <                free_dlink_node(dm);
902 >              if ((ptr = dlinkFindDelete(&oper_list, source_p)))
903 >                free_dlink_node(ptr);
904              }
905            }
906  
# Line 962 | Line 1031 | void
1031   send_umode_out(struct Client *client_p, struct Client *source_p,
1032                 unsigned int old)
1033   {
1034 <  char buf[IRCD_BUFSIZE] = { '\0' };
966 <  dlink_node *ptr = NULL;
1034 >  char buf[IRCD_BUFSIZE] = "";
1035  
1036    send_umode(NULL, source_p, old, SEND_UMODES, buf);
1037  
1038    if (buf[0])
1039      sendto_server(source_p, NOCAPS, NOCAPS, ":%s MODE %s :%s",
1040 <                  ID(source_p), ID(source_p), buf);
1040 >                  source_p->id, source_p->id, buf);
1041  
1042    if (client_p && MyClient(client_p))
1043      send_umode(client_p, source_p, old, 0xffffffff, buf);
# Line 1021 | Line 1089 | user_set_hostmask(struct Client *target_
1089  
1090    DLINK_FOREACH(ptr, target_p->channel.head)
1091    {
1092 <    char modebuf[4], nickbuf[NICKLEN * 3 + 3] = { '\0' };
1092 >    char modebuf[4], nickbuf[NICKLEN * 3 + 3] = "";
1093      char *p = modebuf;
1094      int len = 0;
1095      const struct Membership *ms = ptr->data;
# Line 1063 | Line 1131 | user_set_hostmask(struct Client *target_
1131                                   target_p->host, target_p->away);
1132   }
1133  
1066 /* user_welcome()
1067 *
1068 * inputs       - client pointer to client to welcome
1069 * output       - NONE
1070 * side effects -
1071 */
1072 static void
1073 user_welcome(struct Client *source_p)
1074 {
1075 #if defined(__TIME__) && defined(__DATE__)
1076  static const char built_date[] = __DATE__ " at " __TIME__;
1077 #else
1078  static const char built_date[] = "unknown";
1079 #endif
1080
1081 #ifdef HAVE_LIBCRYPTO
1082  if (HasFlag(source_p, FLAGS_SSL))
1083  {
1084    AddUMode(source_p, UMODE_SSL);
1085    sendto_one_notice(source_p, &me, ":*** Connected securely via %s",
1086                      ssl_get_cipher(source_p->localClient->fd.ssl));
1087  }
1088 #endif
1089
1090  sendto_one_numeric(source_p, &me, RPL_WELCOME, ServerInfo.network_name,
1091                     source_p->name);
1092  sendto_one_numeric(source_p, &me, RPL_YOURHOST,
1093                     get_listener_name(source_p->localClient->listener), ircd_version);
1094  sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
1095  sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer);
1096  show_isupport(source_p);
1097
1098  if (source_p->id[0] != '\0')
1099    sendto_one_numeric(source_p, &me, RPL_YOURID, source_p->id);
1100
1101  show_lusers(source_p);
1102  motd_signon(source_p);
1103 }
1104
1105 /* check_xline()
1106 *
1107 * inputs       - pointer to client to test
1108 * outupt       - 1 if exiting 0 if ok
1109 * side effects -
1110 */
1111 static int
1112 check_xline(struct Client *source_p)
1113 {
1114  struct MaskItem *conf = NULL;
1115  const char *reason = NULL;
1116
1117  if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
1118  {
1119    ++conf->count;
1120
1121    if (conf->reason != NULL)
1122      reason = conf->reason;
1123    else
1124      reason = "No Reason";
1125
1126    sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
1127                         "X-line Rejecting [%s] [%s], user %s [%s]",
1128                         source_p->info, reason,
1129                         get_client_name(source_p, HIDE_IP),
1130                         source_p->sockhost);
1131
1132    ++ServerStats.is_ref;
1133    exit_client(source_p, "Bad user info");
1134    return 1;
1135  }
1136
1137  return 0;
1138 }
1139
1134   /* oper_up()
1135   *
1136   * inputs       - pointer to given client to oper
# Line 1205 | Line 1199 | valid_sid(const char *sid)
1199   void
1200   init_uid(void)
1201   {
1208  unsigned int i;
1209
1202    memset(new_uid, 0, sizeof(new_uid));
1203  
1204    if (!EmptyString(ServerInfo.sid))
1205      strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1206  
1207 <  for (i = 0; i < IRC_MAXSID; ++i)
1207 >  for (unsigned int i = 0; i < IRC_MAXSID; ++i)
1208      if (new_uid[i] == '\0')
1209        new_uid[i] = 'A';
1210  

Diff Legend

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