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

Comparing ircd-hybrid-7.2/src/client.c (file contents):
Revision 498 by michael, Wed Mar 1 19:30:58 2006 UTC vs.
Revision 887 by michael, Thu Nov 1 11:54:48 2007 UTC

# Line 53 | Line 53
53   #include "listener.h"
54   #include "irc_res.h"
55   #include "userhost.h"
56 + #include "watch.h"
57  
58   dlink_list listing_client_list = { NULL, NULL, 0 };
59   /* Pointer to beginning of Client list */
# Line 122 | Line 123 | make_client(struct Client *from)
123      client_p->since = client_p->lasttime = client_p->firsttime = CurrentTime;
124  
125      client_p->localClient = BlockHeapAlloc(lclient_heap);
126 +    client_p->localClient->registration = REG_INIT;
127      /* as good a place as any... */
128      dlinkAdd(client_p, make_dlink_node(), &unknown_list);
129    }
# Line 316 | Line 318 | check_pings_list(dlink_list *list)
318              ilog(L_NOTICE, "No response from %s, closing link",
319                   get_client_name(client_p, HIDE_IP));
320            }
321 +
322            ircsprintf(scratch, "Ping timeout: %d seconds",
323                       (int)(CurrentTime - client_p->lasttime));
321
324            exit_client(client_p, &me, scratch);
325          }
326          else if (!IsPingWarning(client_p) && pingwarn > 0 &&
# Line 362 | Line 364 | check_unknowns_list(void)
364      if (client_p->localClient->reject_delay > 0)
365      {
366        if (client_p->localClient->reject_delay <= CurrentTime)
367 <        exit_client(client_p, &me, "Rejected");
367 >        exit_client(client_p, &me, "Rejected");
368        continue;
369      }
370  
371 <    /* Check UNKNOWN connections - if they have been in this state
371 >    /*
372 >     * Check UNKNOWN connections - if they have been in this state
373       * for > 30s, close them.
374       */
375 <    if (client_p->firsttime ? ((CurrentTime - client_p->firsttime) > 30) : 0)
376 <      exit_client(client_p, &me, "Connection timed out");
375 >    if (IsAuthFinished(client_p) && (CurrentTime - client_p->firsttime) > 30)
376 >      exit_client(client_p, &me, "Registration timed out");
377    }
378   }
379  
# Line 694 | Line 697 | get_client_name(struct Client *client, i
697   void
698   free_exited_clients(void)
699   {
700 <  dlink_node *ptr, *next;
698 <  struct Client *target_p;
700 >  dlink_node *ptr = NULL, *next = NULL;
701    
702    DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
703    {
704 <    target_p = ptr->data;
703 <
704 <    if (ptr->data == NULL)
705 <    {
706 <      sendto_realops_flags(UMODE_ALL, L_ALL,
707 <                           "Warning: null client on dead_list!");
708 <      dlinkDelete(ptr, &dead_list);
709 <      free_dlink_node(ptr);
710 <      continue;
711 <    }
712 <
713 <    free_client(target_p);
704 >    free_client(ptr->data);
705      dlinkDelete(ptr, &dead_list);
706      free_dlink_node(ptr);
707    }
# Line 758 | Line 749 | exit_one_client(struct Client *source_p,
749      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
750        remove_user_from_channel(lp->data);
751  
761    /* Clean up allow lists */
762    del_all_accepts(source_p);
752      add_history(source_p, 0);
753      off_history(source_p);
754  
755 +    watch_check_hash(source_p, RPL_LOGOFF);
756 +
757      if (!MyConnect(source_p))
758      {
759        source_p->from->serv->dep_users--;
# Line 773 | Line 764 | exit_one_client(struct Client *source_p,
764        /* Clean up invitefield */
765        DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
766          del_invite(lp->data, source_p);
767 +
768 +      del_all_accepts(source_p);
769      }
770    }
771  
# Line 964 | Line 957 | exit_client(struct Client *source_p, str
957        if (source_p->localClient->list_task != NULL)
958          free_list_task(source_p->localClient->list_task, source_p);
959  
960 +      watch_del_watch_list(source_p);
961        sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]",
962                             source_p->name, source_p->username, source_p->host, comment,
963                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
964                             "255.255.255.255" : source_p->sockhost);
965 +      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, "CLIEXIT: %s %s %s %s 0 %s",
966 +                           source_p->name,
967 +                           source_p->username,
968 +                           source_p->host,
969 +
970 +                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
971 +                           "255.255.255.255" : source_p->sockhost,
972 +                           comment);
973      }
974  
975      /* As soon as a client is known to be a server of some sort
# Line 984 | Line 986 | exit_client(struct Client *source_p, str
986        }
987  
988        if (IsServer(source_p))
987      {
989          Count.myserver--;
989        if (ServerInfo.hub)
990          remove_lazylink_flags(source_p->localClient->serverMask);
991        else
992          uplink = NULL;
993      }
990      }
991  
992      log_user_exit(source_p);
# Line 1030 | Line 1026 | exit_client(struct Client *source_p, str
1026      assert(source_p->serv != NULL && source_p->servptr != NULL);
1027  
1028      if (ConfigServerHide.hide_servers)
1029 <      /* set netsplit message to "*.net *.split" to still show
1029 >      /*
1030 >       * Set netsplit message to "*.net *.split" to still show
1031         * that its a split, but hide the servers splitting
1032         */
1033        strcpy(splitstr, "*.net *.split");
# Line 1055 | Line 1052 | exit_client(struct Client *source_p, str
1052    }
1053    else if (IsClient(source_p) && !IsKilled(source_p))
1054    {
1055 <    sendto_server(from->from, source_p, NULL, CAP_TS6, NOCAPS, NOFLAGS,
1055 >    sendto_server(from->from, NULL, CAP_TS6, NOCAPS,
1056                    ":%s QUIT :%s", ID(source_p), comment);
1057 <    sendto_server(from->from, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS,
1057 >    sendto_server(from->from, NULL, NOCAPS, CAP_TS6,
1058                    ":%s QUIT :%s", source_p->name, comment);
1059    }
1060  
# Line 1135 | Line 1132 | dead_link_on_read(struct Client *client_
1132      }
1133      else
1134      {
1135 <      report_error(L_ADMIN, "Lost connection to %s: %d",
1135 >      report_error(L_ADMIN, "Lost connection to %s: %s",
1136                     get_client_name(client_p, SHOW_IP), current_error);
1137 <      report_error(L_OPER, "Lost connection to %s: %d",
1137 >      report_error(L_OPER, "Lost connection to %s: %s",
1138                     get_client_name(client_p, MASK_IP), current_error);
1139      }
1140  
# Line 1194 | Line 1191 | exit_aborted_clients(void)
1191  
1192   /*
1193   * accept processing, this adds a form of "caller ID" to ircd
1194 < *
1194 > *
1195   * If a client puts themselves into "caller ID only" mode,
1196 < * only clients that match a client pointer they have put on
1196 > * only clients that match a client pointer they have put on
1197   * the accept list will be allowed to message them.
1198   *
1199 < * [ source.on_allow_list ] -> [ target1 ] -> [ target2 ]
1203 < *
1204 < * [target.allow_list] -> [ source1 ] -> [source2 ]
1205 < *
1206 < * i.e. a target will have a link list of source pointers it will allow
1207 < * each source client then has a back pointer pointing back
1208 < * to the client that has it on its accept list.
1209 < * This allows for exit_one_client to remove these now bogus entries
1210 < * from any client having an accept on them.
1199 > * Diane Bruce, "Dianora" db@db.net
1200   */
1201  
1202 < /* accept_message()
1203 < *
1215 < * inputs       - pointer to source client
1216 < *              - pointer to target client
1217 < * output       - 1 if accept this message 0 if not
1218 < * side effects - See if source is on target's allow list
1219 < */
1220 < int
1221 < accept_message(struct Client *source, struct Client *target)
1202 > void
1203 > del_accept(struct split_nuh_item *accept_p, struct Client *client_p)
1204   {
1205 <  dlink_node *ptr;
1205 >  dlinkDelete(&accept_p->node, &client_p->localClient->acceptlist);
1206  
1207 <  DLINK_FOREACH(ptr, target->allow_list.head)
1208 <  {
1209 <    struct Client *target_p = ptr->data;
1207 >  MyFree(accept_p->nickptr);
1208 >  MyFree(accept_p->userptr);
1209 >  MyFree(accept_p->hostptr);
1210 >  MyFree(accept_p);
1211 > }
1212  
1213 <    if (source == target_p)
1214 <      return (1);
1215 <  }
1213 > struct split_nuh_item *
1214 > find_accept(const char *nick, const char *user,
1215 >            const char *host, struct Client *client_p, int do_match)
1216 > {
1217 >  dlink_node *ptr = NULL;
1218 >  /* XXX We wouldn't need that if match() would return 0 on match */
1219 >  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1220  
1221 <  if (IsSoftCallerId(target))
1221 >  DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1222    {
1223 <    DLINK_FOREACH(ptr, target->channel.head)
1224 <      if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1225 <        return (1);
1223 >    struct split_nuh_item *accept_p = ptr->data;
1224 >
1225 >    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1226 >        cmpfunc(accept_p->userptr, user) == do_match &&
1227 >        cmpfunc(accept_p->hostptr, host) == do_match)
1228 >      return accept_p;
1229    }
1230  
1231 <  return (0);
1231 >  return NULL;
1232   }
1233  
1234 < /* del_from_accept()
1244 < *
1245 < * inputs       - pointer to source client
1246 < *              - pointer to target client
1247 < * output       - NONE
1248 < * side effects - Delete's source pointer to targets allow list
1234 > /* accept_message()
1235   *
1236 < * Walk through the target's accept list, remove if source is found,
1237 < * Then walk through the source's on_accept_list remove target if found.
1236 > * inputs       - pointer to source client
1237 > *              - pointer to target client
1238 > * output       - 1 if accept this message 0 if not
1239 > * side effects - See if source is on target's allow list
1240   */
1241 < void
1242 < del_from_accept(struct Client *source, struct Client *target)
1241 > int
1242 > accept_message(struct Client *source,
1243 >               struct Client *target)
1244   {
1245 <  dlink_node *ptr;
1257 <  dlink_node *ptr2;
1258 <  dlink_node *next_ptr;
1259 <  dlink_node *next_ptr2;
1260 <  struct Client *target_p;
1245 >  dlink_node *ptr = NULL;
1246  
1247 <  DLINK_FOREACH_SAFE(ptr, next_ptr, target->allow_list.head)
1248 <  {
1249 <    target_p = ptr->data;
1247 >  if (source == target || find_accept(source->name, source->username,
1248 >                                      source->host, target, 1))
1249 >    return 1;
1250  
1251 <    if (source == target_p)
1252 <    {
1253 <      dlinkDelete(ptr, &target->allow_list);
1254 <      free_dlink_node(ptr);
1270 <
1271 <      DLINK_FOREACH_SAFE(ptr2, next_ptr2, source->on_allow_list.head)
1272 <      {
1273 <        target_p = ptr2->data;
1251 >  if (IsSoftCallerId(target))
1252 >    DLINK_FOREACH(ptr, target->channel.head)
1253 >      if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1254 >        return 1;
1255  
1256 <        if (target == target_p)
1276 <        {
1277 <          dlinkDelete(ptr2, &source->on_allow_list);
1278 <          free_dlink_node(ptr2);
1279 <        }
1280 <      }
1281 <    }
1282 <  }
1256 >  return 0;
1257   }
1258  
1259   /* del_all_accepts()
1260   *
1261 < * inputs       - pointer to exiting client
1262 < * output       - NONE
1263 < * side effects - Walk through given clients allow_list and on_allow_list
1290 < *                remove all references to this client
1261 > * inputs       - pointer to exiting client
1262 > * output       - NONE
1263 > * side effects - Walk through given clients acceptlist and remove all entries
1264   */
1265   void
1266   del_all_accepts(struct Client *client_p)
1267   {
1268 <  dlink_node *ptr, *next_ptr;
1268 >  dlink_node *ptr = NULL, *next_ptr = NULL;
1269  
1270 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->allow_list.head)
1271 <    del_from_accept(ptr->data, client_p);
1299 <
1300 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head)
1301 <    del_from_accept(client_p, ptr->data);
1302 < }
1303 <
1304 < /* del_all_their_accepts()
1305 < *
1306 < * inputs       - pointer to exiting client
1307 < * output       - NONE
1308 < * side effects - Walk through given clients on_allow_list
1309 < *                remove all references to this client,
1310 < *                allow this client to keep their own allow_list
1311 < */
1312 < void
1313 < del_all_their_accepts(struct Client *client_p)
1314 < {
1315 <  dlink_node *ptr, *next_ptr;
1316 <
1317 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head)
1318 <    del_from_accept(client_p, ptr->data);
1270 >  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1271 >    del_accept(ptr->data, client_p);
1272   }
1273  
1274   /* set_initial_nick()
# Line 1337 | Line 1290 | set_initial_nick(struct Client *client_p
1290    
1291    /* This had to be copied here to avoid problems.. */
1292    source_p->tsinfo = CurrentTime;
1293 +  source_p->localClient->registration &= ~REG_NEED_NICK;
1294  
1295    if (source_p->name[0])
1296      hash_del_client(source_p);
# Line 1347 | Line 1301 | set_initial_nick(struct Client *client_p
1301    /* fd_desc is long enough */
1302    fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1303    
1304 <  /* They have the nick they want now.. */
1351 <  client_p->llname[0] = '\0';
1352 <
1353 <  if (source_p->flags & FLAGS_GOTUSER)
1304 >  if (!source_p->localClient->registration)
1305    {
1306      strlcpy(buf, source_p->username, sizeof(buf));
1307  
# Line 1377 | Line 1328 | set_initial_nick(struct Client *client_p
1328   void
1329   change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick)
1330   {
1331 +  int samenick = 0;
1332 +
1333 +  assert(source_p->name[0] && !EmptyString(nick));
1334 +
1335    /*
1336 <  ** Client just changing his/her nick. If he/she is
1337 <  ** on a channel, send note of change to all clients
1338 <  ** on that channel. Propagate notice to other servers.
1339 <  */
1336 >   * Client just changing his/her nick. If he/she is
1337 >   * on a channel, send note of change to all clients
1338 >   * on that channel. Propagate notice to other servers.
1339 >   */
1340    if ((source_p->localClient->last_nick_change +
1341         ConfigFileEntry.max_nick_time) < CurrentTime)
1342      source_p->localClient->number_of_nick_changes = 0;
# Line 1394 | Line 1349 | change_local_nick(struct Client *client_
1349       !ConfigFileEntry.anti_nick_flood ||
1350       (IsOper(source_p) && ConfigFileEntry.no_oper_flood))
1351    {
1352 <    if (irccmp(source_p->name, nick))
1352 >    samenick = !irccmp(source_p->name, nick);
1353 >
1354 >    if (!samenick)
1355 >    {
1356        source_p->tsinfo = CurrentTime;
1357 +      clear_ban_cache_client(source_p);
1358 +      watch_check_hash(source_p, RPL_LOGOFF);
1359 +    }
1360  
1361      /* XXX - the format of this notice should eventually be changed
1362       * to either %s[%s@%s], or even better would be get_client_name() -bill
# Line 1405 | Line 1366 | change_local_nick(struct Client *client_
1366      sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s",
1367                                   source_p->name, source_p->username,
1368                                   source_p->host, nick);
1408
1369      add_history(source_p, 1);
1370 <          
1371 <         /* Only hubs care about lazy link nicks not being sent on yet
1412 <           * lazylink leafs/leafs always send their nicks up to hub,
1413 <           * hence must always propagate nick changes.
1414 <           * hubs might not propagate a nick change, if the leaf
1415 <           * does not know about that client yet.
1416 <           */
1417 <    sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS, NOFLAGS,
1370 >
1371 >    sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
1372                    ":%s NICK %s :%lu",
1373                    ID(source_p), nick, (unsigned long)source_p->tsinfo);
1374 <    sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS,
1374 >    sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
1375                    ":%s NICK %s :%lu",
1376                    source_p->name, nick, (unsigned long)source_p->tsinfo);
1377 +
1378 +    hash_del_client(source_p);
1379 +    strcpy(source_p->name, nick);
1380 +    hash_add_client(source_p);
1381 +
1382 +    if (!samenick)
1383 +      watch_check_hash(source_p, RPL_LOGON);
1384 +
1385 +    /* fd_desc is long enough */
1386 +    fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1387    }
1388    else
1425  {
1389      sendto_one(source_p, form_str(ERR_NICKTOOFAST),
1390                 me.name, source_p->name, source_p->name,
1391                 nick, ConfigFileEntry.max_nick_time);
1429    return;
1430  }
1431
1432  /* Finally, add to hash */
1433  if (source_p->name[0])
1434    hash_del_client(source_p);
1435
1436  strcpy(source_p->name, nick);
1437  hash_add_client(source_p);
1438
1439  /* Make sure everyone that has this client on its accept list
1440   * loses that reference.
1441   */
1442  del_all_their_accepts(source_p);
1443
1444  /* fd_desc is long enough */
1445  fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1392   }

Diff Legend

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