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 317 by michael, Sat Dec 24 14:45:17 2005 UTC vs.
Revision 889 by michael, Thu Nov 1 12:59:05 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 731 | Line 722 | exit_one_client(struct Client *source_p,
722  
723    if (IsServer(source_p))
724    {
725 <    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers);
725 >    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
726  
727      if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
728        free_dlink_node(lp);
738
739    if (!MyConnect(source_p))
740    {
741      source_p->from->serv->dep_servers--;
742      assert(source_p->from->serv->dep_servers > 0);
743    }
729    }
730    else if (IsClient(source_p))
731    {
732      if (source_p->servptr->serv != NULL)
733 <      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->users);
733 >      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
734  
735      /* If a person is on a channel, send a QUIT notice
736      ** to every client (person) on the same channel (so
# Line 758 | Line 743 | exit_one_client(struct Client *source_p,
743      DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
744        remove_user_from_channel(lp->data);
745  
761    /* Clean up allow lists */
762    del_all_accepts(source_p);
746      add_history(source_p, 0);
747      off_history(source_p);
748  
749 <    if (!MyConnect(source_p))
750 <    {
751 <      source_p->from->serv->dep_users--;
769 <      assert(source_p->from->serv->dep_users >= 0);
770 <    }
771 <    else
749 >    watch_check_hash(source_p, RPL_LOGOFF);
750 >
751 >    if (MyConnect(source_p))
752      {
753        /* Clean up invitefield */
754        DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
755          del_invite(lp->data, source_p);
756 +
757 +      del_all_accepts(source_p);
758      }
759    }
760  
# Line 829 | Line 811 | recurse_send_quits(struct Client *origin
811     * hidden behind fakename. If so, send out the QUITs -adx
812     */
813    if (hidden || !IsCapable(to, CAP_QS))
814 <    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head)
814 >    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
815      {
816        target_p = ptr->data;
817        sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
818      }
819  
820 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head)
820 >  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
821      recurse_send_quits(original_source_p, ptr->data, from, to,
822                         comment, splitstr, myname);
823  
# Line 859 | Line 841 | recurse_remove_clients(struct Client *so
841   {
842    dlink_node *ptr, *next;
843  
844 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head)
844 >  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
845      exit_one_client(ptr->data, quitmsg);
846  
847 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head)
847 >  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
848    {
849      recurse_remove_clients(ptr->data, quitmsg);
850      exit_one_client(ptr->data, quitmsg);
851    }
870
871  assert(source_p->serv->dep_servers == 1);
872  assert(source_p->serv->dep_users == 0);
852   }
853  
854   /*
# Line 964 | Line 943 | exit_client(struct Client *source_p, str
943        if (source_p->localClient->list_task != NULL)
944          free_list_task(source_p->localClient->list_task, source_p);
945  
946 +      watch_del_watch_list(source_p);
947        sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]",
948                             source_p->name, source_p->username, source_p->host, comment,
949                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
950                             "255.255.255.255" : source_p->sockhost);
951 +      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, "CLIEXIT: %s %s %s %s 0 %s",
952 +                           source_p->name,
953 +                           source_p->username,
954 +                           source_p->host,
955 +
956 +                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
957 +                           "255.255.255.255" : source_p->sockhost,
958 +                           comment);
959      }
960  
961      /* As soon as a client is known to be a server of some sort
# Line 984 | Line 972 | exit_client(struct Client *source_p, str
972        }
973  
974        if (IsServer(source_p))
987      {
975          Count.myserver--;
989        if (ServerInfo.hub)
990          remove_lazylink_flags(source_p->localClient->serverMask);
991        else
992          uplink = NULL;
993      }
976      }
977  
978      log_user_exit(source_p);
# Line 1030 | Line 1012 | exit_client(struct Client *source_p, str
1012      assert(source_p->serv != NULL && source_p->servptr != NULL);
1013  
1014      if (ConfigServerHide.hide_servers)
1015 <      /* set netsplit message to "*.net *.split" to still show
1015 >      /*
1016 >       * Set netsplit message to "*.net *.split" to still show
1017         * that its a split, but hide the servers splitting
1018         */
1019        strcpy(splitstr, "*.net *.split");
# Line 1055 | Line 1038 | exit_client(struct Client *source_p, str
1038    }
1039    else if (IsClient(source_p) && !IsKilled(source_p))
1040    {
1041 <    sendto_server(NULL, source_p, NULL, CAP_TS6, NOCAPS, NOFLAGS,
1041 >    sendto_server(from->from, NULL, CAP_TS6, NOCAPS,
1042                    ":%s QUIT :%s", ID(source_p), comment);
1043 <    sendto_server(NULL, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS,
1043 >    sendto_server(from->from, NULL, NOCAPS, CAP_TS6,
1044                    ":%s QUIT :%s", source_p->name, comment);
1045    }
1046  
# Line 1135 | Line 1118 | dead_link_on_read(struct Client *client_
1118      }
1119      else
1120      {
1121 <      report_error(L_ADMIN, "Lost connection to %s: %d",
1121 >      report_error(L_ADMIN, "Lost connection to %s: %s",
1122                     get_client_name(client_p, SHOW_IP), current_error);
1123 <      report_error(L_OPER, "Lost connection to %s: %d",
1123 >      report_error(L_OPER, "Lost connection to %s: %s",
1124                     get_client_name(client_p, MASK_IP), current_error);
1125      }
1126  
# Line 1194 | Line 1177 | exit_aborted_clients(void)
1177  
1178   /*
1179   * accept processing, this adds a form of "caller ID" to ircd
1180 < *
1180 > *
1181   * If a client puts themselves into "caller ID only" mode,
1182 < * only clients that match a client pointer they have put on
1182 > * only clients that match a client pointer they have put on
1183   * the accept list will be allowed to message them.
1184   *
1185 < * [ 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.
1185 > * Diane Bruce, "Dianora" db@db.net
1186   */
1187  
1188 < /* accept_message()
1189 < *
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)
1188 > void
1189 > del_accept(struct split_nuh_item *accept_p, struct Client *client_p)
1190   {
1191 <  dlink_node *ptr;
1191 >  dlinkDelete(&accept_p->node, &client_p->localClient->acceptlist);
1192  
1193 <  DLINK_FOREACH(ptr, target->allow_list.head)
1194 <  {
1195 <    struct Client *target_p = ptr->data;
1193 >  MyFree(accept_p->nickptr);
1194 >  MyFree(accept_p->userptr);
1195 >  MyFree(accept_p->hostptr);
1196 >  MyFree(accept_p);
1197 > }
1198  
1199 <    if (source == target_p)
1200 <      return (1);
1201 <  }
1199 > struct split_nuh_item *
1200 > find_accept(const char *nick, const char *user,
1201 >            const char *host, struct Client *client_p, int do_match)
1202 > {
1203 >  dlink_node *ptr = NULL;
1204 >  /* XXX We wouldn't need that if match() would return 0 on match */
1205 >  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1206  
1207 <  if (IsSoftCallerId(target))
1207 >  DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1208    {
1209 <    DLINK_FOREACH(ptr, target->channel.head)
1210 <      if (IsMember(source, ptr->data))
1211 <        return (1);
1209 >    struct split_nuh_item *accept_p = ptr->data;
1210 >
1211 >    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1212 >        cmpfunc(accept_p->userptr, user) == do_match &&
1213 >        cmpfunc(accept_p->hostptr, host) == do_match)
1214 >      return accept_p;
1215    }
1216  
1217 <  return (0);
1217 >  return NULL;
1218   }
1219  
1220 < /* 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
1220 > /* accept_message()
1221   *
1222 < * Walk through the target's accept list, remove if source is found,
1223 < * Then walk through the source's on_accept_list remove target if found.
1222 > * inputs       - pointer to source client
1223 > *              - pointer to target client
1224 > * output       - 1 if accept this message 0 if not
1225 > * side effects - See if source is on target's allow list
1226   */
1227 < void
1228 < del_from_accept(struct Client *source, struct Client *target)
1227 > int
1228 > accept_message(struct Client *source,
1229 >               struct Client *target)
1230   {
1231 <  dlink_node *ptr;
1257 <  dlink_node *ptr2;
1258 <  dlink_node *next_ptr;
1259 <  dlink_node *next_ptr2;
1260 <  struct Client *target_p;
1231 >  dlink_node *ptr = NULL;
1232  
1233 <  DLINK_FOREACH_SAFE(ptr, next_ptr, target->allow_list.head)
1234 <  {
1235 <    target_p = ptr->data;
1233 >  if (source == target || find_accept(source->name, source->username,
1234 >                                      source->host, target, 1))
1235 >    return 1;
1236  
1237 <    if (source == target_p)
1238 <    {
1239 <      dlinkDelete(ptr, &target->allow_list);
1240 <      free_dlink_node(ptr);
1270 <
1271 <      DLINK_FOREACH_SAFE(ptr2, next_ptr2, source->on_allow_list.head)
1272 <      {
1273 <        target_p = ptr2->data;
1237 >  if (IsSoftCallerId(target))
1238 >    DLINK_FOREACH(ptr, target->channel.head)
1239 >      if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1240 >        return 1;
1241  
1242 <        if (target == target_p)
1276 <        {
1277 <          dlinkDelete(ptr2, &source->on_allow_list);
1278 <          free_dlink_node(ptr2);
1279 <        }
1280 <      }
1281 <    }
1282 <  }
1242 >  return 0;
1243   }
1244  
1245   /* del_all_accepts()
1246   *
1247 < * inputs       - pointer to exiting client
1248 < * output       - NONE
1249 < * side effects - Walk through given clients allow_list and on_allow_list
1290 < *                remove all references to this client
1247 > * inputs       - pointer to exiting client
1248 > * output       - NONE
1249 > * side effects - Walk through given clients acceptlist and remove all entries
1250   */
1251   void
1252   del_all_accepts(struct Client *client_p)
1253   {
1254 <  dlink_node *ptr, *next_ptr;
1296 <
1297 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->allow_list.head)
1298 <    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;
1254 >  dlink_node *ptr = NULL, *next_ptr = NULL;
1255  
1256 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head)
1257 <    del_from_accept(client_p, ptr->data);
1256 >  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1257 >    del_accept(ptr->data, client_p);
1258   }
1259  
1260   /* set_initial_nick()
# Line 1337 | Line 1276 | set_initial_nick(struct Client *client_p
1276    
1277    /* This had to be copied here to avoid problems.. */
1278    source_p->tsinfo = CurrentTime;
1279 +  source_p->localClient->registration &= ~REG_NEED_NICK;
1280  
1281    if (source_p->name[0])
1282      hash_del_client(source_p);
# Line 1347 | Line 1287 | set_initial_nick(struct Client *client_p
1287    /* fd_desc is long enough */
1288    fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1289    
1290 <  /* They have the nick they want now.. */
1351 <  client_p->llname[0] = '\0';
1352 <
1353 <  if (source_p->flags & FLAGS_GOTUSER)
1290 >  if (!source_p->localClient->registration)
1291    {
1292      strlcpy(buf, source_p->username, sizeof(buf));
1293  
# Line 1377 | Line 1314 | set_initial_nick(struct Client *client_p
1314   void
1315   change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick)
1316   {
1317 +  int samenick = 0;
1318 +
1319 +  assert(source_p->name[0] && !EmptyString(nick));
1320 +
1321    /*
1322 <  ** Client just changing his/her nick. If he/she is
1323 <  ** on a channel, send note of change to all clients
1324 <  ** on that channel. Propagate notice to other servers.
1325 <  */
1322 >   * Client just changing his/her nick. If he/she is
1323 >   * on a channel, send note of change to all clients
1324 >   * on that channel. Propagate notice to other servers.
1325 >   */
1326    if ((source_p->localClient->last_nick_change +
1327         ConfigFileEntry.max_nick_time) < CurrentTime)
1328      source_p->localClient->number_of_nick_changes = 0;
# Line 1394 | Line 1335 | change_local_nick(struct Client *client_
1335       !ConfigFileEntry.anti_nick_flood ||
1336       (IsOper(source_p) && ConfigFileEntry.no_oper_flood))
1337    {
1338 <    if (irccmp(source_p->name, nick))
1338 >    samenick = !irccmp(source_p->name, nick);
1339 >
1340 >    if (!samenick)
1341 >    {
1342        source_p->tsinfo = CurrentTime;
1343 +      clear_ban_cache_client(source_p);
1344 +      watch_check_hash(source_p, RPL_LOGOFF);
1345 +    }
1346  
1347      /* XXX - the format of this notice should eventually be changed
1348       * to either %s[%s@%s], or even better would be get_client_name() -bill
# Line 1405 | Line 1352 | change_local_nick(struct Client *client_
1352      sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s",
1353                                   source_p->name, source_p->username,
1354                                   source_p->host, nick);
1408
1355      add_history(source_p, 1);
1356 <          
1357 <         /* 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,
1356 >
1357 >    sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
1358                    ":%s NICK %s :%lu",
1359                    ID(source_p), nick, (unsigned long)source_p->tsinfo);
1360 <    sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS,
1360 >    sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
1361                    ":%s NICK %s :%lu",
1362                    source_p->name, nick, (unsigned long)source_p->tsinfo);
1363 +
1364 +    hash_del_client(source_p);
1365 +    strcpy(source_p->name, nick);
1366 +    hash_add_client(source_p);
1367 +
1368 +    if (!samenick)
1369 +      watch_check_hash(source_p, RPL_LOGON);
1370 +
1371 +    /* fd_desc is long enough */
1372 +    fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1373    }
1374    else
1425  {
1375      sendto_one(source_p, form_str(ERR_NICKTOOFAST),
1376                 me.name, source_p->name, source_p->name,
1377                 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);
1378   }

Diff Legend

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