2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
29 #include "conn-func.h"
39 #include "irc-write.h"
42 #include "irc-login.h"
45 static bool Hello_User PARAMS(( CLIENT *Client ));
46 static bool Hello_User_PostAuth PARAMS(( CLIENT *Client ));
47 static void Kill_Nick PARAMS(( char *Nick, char *Reason ));
48 static void Introduce_Client PARAMS((CLIENT *To, CLIENT *Client, int Type));
49 static void Reject_Client PARAMS((CLIENT *Client));
51 static void cb_introduceClient PARAMS((CLIENT *Client, CLIENT *Prefix,
55 static void cb_Read_Auth_Result PARAMS((int r_fd, UNUSED short events));
59 * Handler for the IRC command "PASS".
60 * See RFC 2813 section 4.1.1, and RFC 2812 section 3.1.1.
63 IRC_PASS( CLIENT *Client, REQUEST *Req )
65 char *type, *orig_flags;
66 int protohigh, protolow;
68 assert( Client != NULL );
69 assert( Req != NULL );
71 /* Return an error if this is not a local client */
72 if (Client_Conn(Client) <= NONE)
73 return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
74 Client_ID(Client), Req->command);
76 if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
77 /* Not yet registered "unknown" connection, PASS with one
78 * argument: either a regular client, service, or server
79 * using the old RFC 1459 section 4.1.1 syntax. */
80 LogDebug("Connection %d: got PASS command (RFC 1459) ...",
82 } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
83 Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
84 (Req->argc == 3 || Req->argc == 4)) {
85 /* Not yet registered "unknown" connection or outgoing server
86 * link, PASS with three or four argument: server using the
87 * RFC 2813 section 4.1.1 syntax. */
88 LogDebug("Connection %d: got PASS command (RFC 2813, new server link) ...",
90 } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
91 Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
92 /* Unregistered connection, but wrong number of arguments: */
93 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
94 Client_ID(Client), Req->command);
96 /* Registered connection, PASS command is not allowed! */
97 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
101 Client_SetPassword(Client, Req->argv[0]);
103 /* Protocol version */
104 if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
107 c2 = Req->argv[1][2];
108 c4 = Req->argv[1][4];
110 Req->argv[1][4] = '\0';
111 protolow = atoi(&Req->argv[1][2]);
112 Req->argv[1][2] = '\0';
113 protohigh = atoi(Req->argv[1]);
115 Req->argv[1][2] = c2;
116 Req->argv[1][4] = c4;
118 Client_SetType(Client, CLIENT_GOTPASS_2813);
120 protohigh = protolow = 0;
121 Client_SetType(Client, CLIENT_GOTPASS);
124 /* Protocol type, see doc/Protocol.txt */
125 if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
126 type = &Req->argv[1][4];
130 /* Protocol flags/options */
132 orig_flags = Req->argv[3];
136 /* Implementation, version and IRC+ flags */
137 if (Req->argc >= 3) {
138 char *impl, *ptr, *serverver, *flags;
141 ptr = strchr(impl, '|');
145 if (type && strcmp(type, PROTOIRCPLUS) == 0) {
146 /* The peer seems to be a server which supports the
147 * IRC+ protocol (see doc/Protocol.txt). */
148 serverver = ptr ? ptr + 1 : "?";
149 flags = strchr(ptr ? serverver : impl, ':');
156 "Peer on conenction %d announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
157 Client_Conn(Client), impl, serverver,
158 protohigh, protolow, flags);
160 /* The peer seems to be a server supporting the
161 * "original" IRC protocol (RFC 2813). */
162 if (strchr(orig_flags, 'Z'))
167 "Peer on connection %d announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
168 Client_Conn(Client), impl,
169 protohigh, protolow, flags);
171 Client_SetFlags(Client, flags);
179 * IRC "NICK" command.
180 * This function implements the IRC command "NICK" which is used to register
181 * with the server, to change already registered nicknames and to introduce
182 * new users which are connected to other servers.
185 IRC_NICK( CLIENT *Client, REQUEST *Req )
187 CLIENT *intr_c, *target, *c;
188 char *nick, *user, *hostname, *modes, *info;
191 assert( Client != NULL );
192 assert( Req != NULL );
194 /* Some IRC clients, for example BitchX, send the NICK and USER
195 * commands in the wrong order ... */
196 if(Client_Type(Client) == CLIENT_UNKNOWN
197 || Client_Type(Client) == CLIENT_GOTPASS
198 || Client_Type(Client) == CLIENT_GOTNICK
200 || Client_Type(Client) == CLIENT_GOTUSER
202 || Client_Type(Client) == CLIENT_USER
203 || Client_Type(Client) == CLIENT_SERVICE
204 || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
206 /* User registration or change of nickname */
208 /* Wrong number of arguments? */
210 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
214 /* Search "target" client */
215 if( Client_Type( Client ) == CLIENT_SERVER )
217 target = Client_Search( Req->prefix );
219 return IRC_WriteStrClient( Client,
226 /* Is this a restricted client? */
227 if( Client_HasMode( Client, 'r' ))
228 return IRC_WriteStrClient( Client,
230 Client_ID( Client ));
236 /* If the clients tries to change to its own nickname we won't
237 * do anything. This is how the original ircd behaves and some
238 * clients (for example Snak) expect it to be like this.
239 * But I doubt that this is "really the right thing" ... */
240 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 )
244 /* Check that the new nickname is available. Special case:
245 * the client only changes from/to upper to lower case. */
246 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
248 if( ! Client_CheckNick( target, Req->argv[0] ))
252 if (Client_Type(target) != CLIENT_USER &&
253 Client_Type(target) != CLIENT_SERVICE &&
254 Client_Type(target) != CLIENT_SERVER) {
256 LogDebug("Connection %d: got valid NICK command ...",
257 Client_Conn( Client ));
259 /* Register new nickname of this client */
260 Client_SetID( target, Req->argv[0] );
262 /* If we received a valid USER command already then
263 * register the new client! */
264 if( Client_Type( Client ) == CLIENT_GOTUSER )
265 return Hello_User( Client );
267 Client_SetType( Client, CLIENT_GOTNICK );
269 /* Nickname change */
270 if (Client_Conn(target) > NONE) {
273 "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
274 Client_TypeText(target), Client_Mask(target),
275 Client_Conn(target), Client_ID(target),
277 Conn_UpdateIdle(Client_Conn(target));
280 LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
281 Client_TypeText(target),
282 Client_Mask(target), Client_ID(target),
286 /* Inform all users and servers (which have to know)
287 * of this nickname change */
288 if( Client_Type( Client ) == CLIENT_USER )
289 IRC_WriteStrClientPrefix( Client, Client,
292 IRC_WriteStrServersPrefix( Client, target,
293 "NICK :%s", Req->argv[0] );
294 IRC_WriteStrRelatedPrefix( target, target, false,
295 "NICK :%s", Req->argv[0] );
297 /* Register old nickname for WHOWAS queries */
298 Client_RegisterWhowas( target );
300 /* Save new nickname */
301 Client_SetID( target, Req->argv[0] );
303 IRC_SetPenalty( target, 2 );
307 } else if(Client_Type(Client) == CLIENT_SERVER ||
308 Client_Type(Client) == CLIENT_SERVICE) {
309 /* Server or service introduces new client */
311 /* Bad number of parameters? */
312 if (Req->argc != 2 && Req->argc != 7)
313 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
314 Client_ID(Client), Req->command);
316 if (Req->argc >= 7) {
317 /* RFC 2813 compatible syntax */
319 hops = atoi(Req->argv[1]);
321 hostname = Req->argv[3];
322 token = atoi(Req->argv[4]);
323 modes = Req->argv[5] + 1;
326 /* RFC 1459 compatible syntax */
330 hostname = Client_ID(Client);
331 token = atoi(Req->argv[1]);
336 c = Client_Search(nick);
339 * the new nick is already present on this server:
340 * the new and the old one have to be disconnected now.
342 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
343 Kill_Nick( Req->argv[0], "Nick collision" );
347 /* Find the Server this client is connected to */
348 intr_c = Client_GetFromToken(Client, token);
351 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
352 Kill_Nick( Req->argv[0], "Unknown server" );
356 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
357 token, modes, info, true);
360 /* out of memory, need to disconnect client to keep network state consistent */
361 Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
362 Kill_Nick( Req->argv[0], "Server error" );
366 /* RFC 2813: client is now fully registered, inform all the
367 * other servers about the new user.
368 * RFC 1459: announce the new client only after receiving the
369 * USER command, first we need more information! */
371 LogDebug("Client \"%s\" is being registered (RFC 1459) ...",
373 Client_SetType(c, CLIENT_GOTNICK);
375 Introduce_Client(Client, c, CLIENT_USER);
379 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
384 * Handler for the IRC command "USER".
387 IRC_USER(CLIENT * Client, REQUEST * Req)
394 assert(Client != NULL);
397 if (Client_Type(Client) == CLIENT_GOTNICK ||
399 Client_Type(Client) == CLIENT_UNKNOWN ||
401 Client_Type(Client) == CLIENT_GOTPASS)
405 return IRC_WriteStrClient(Client,
406 ERR_NEEDMOREPARAMS_MSG,
412 ptr = Client_User(Client);
413 if (!ptr || !*ptr || *ptr == '~')
414 Client_SetUser(Client, Req->argv[0], false);
416 Client_SetUser(Client, Req->argv[0], false);
418 Client_SetOrigUser(Client, Req->argv[0]);
420 /* "Real name" or user info text: Don't set it to the empty
421 * string, the original ircd can't deal with such "real names"
422 * (e. g. "USER user * * :") ... */
424 Client_SetInfo(Client, Req->argv[3]);
426 Client_SetInfo(Client, "-");
428 LogDebug("Connection %d: got valid USER command ...",
429 Client_Conn(Client));
430 if (Client_Type(Client) == CLIENT_GOTNICK)
431 return Hello_User(Client);
433 Client_SetType(Client, CLIENT_GOTUSER);
436 } else if (Client_Type(Client) == CLIENT_SERVER ||
437 Client_Type(Client) == CLIENT_SERVICE) {
438 /* Server/service updating an user */
440 return IRC_WriteStrClient(Client,
441 ERR_NEEDMOREPARAMS_MSG,
444 c = Client_Search(Req->prefix);
446 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
450 Client_SetUser(c, Req->argv[0], true);
451 Client_SetOrigUser(c, Req->argv[0]);
452 Client_SetHostname(c, Req->argv[1]);
453 Client_SetInfo(c, Req->argv[3]);
455 LogDebug("Connection %d: got valid USER command for \"%s\".",
456 Client_Conn(Client), Client_Mask(c));
458 /* RFC 1459 style user registration?
459 * Introduce client to network: */
460 if (Client_Type(c) == CLIENT_GOTNICK)
461 Introduce_Client(Client, c, CLIENT_USER);
464 } else if (Client_Type(Client) == CLIENT_USER) {
465 /* Already registered connection */
466 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
469 /* Unexpected/invalid connection state? */
470 return IRC_WriteStrClient(Client, ERR_NOTREGISTERED_MSG,
477 * Handler for the IRC command "SERVICE".
478 * This function implements IRC Services registration using the SERVICE command
479 * defined in RFC 2812 3.1.6 and RFC 2813 4.1.4.
480 * At the moment ngIRCd doesn't support directly linked services, so this
481 * function returns ERR_ERRONEUSNICKNAME when the SERVICE command has not been
482 * received from a peer server.
485 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
488 char *nick, *user, *host, *info, *modes, *ptr;
491 assert(Client != NULL);
494 if (Client_Type(Client) != CLIENT_GOTPASS &&
495 Client_Type(Client) != CLIENT_SERVER)
496 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
500 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
501 Client_ID(Client), Req->command);
503 if (Client_Type(Client) != CLIENT_SERVER)
504 return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
505 Client_ID(Client), Req->argv[0]);
507 /* Bad number of parameters? */
509 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
510 Client_ID(Client), Req->command);
513 user = NULL; host = NULL;
514 token = atoi(Req->argv[1]);
515 hops = atoi(Req->argv[4]);
518 /* Validate service name ("nick name") */
519 c = Client_Search(nick);
521 /* Nick name collission: disconnect (KILL) both clients! */
522 Log(LOG_ERR, "Server %s introduces already registered service \"%s\"!",
523 Client_ID(Client), nick);
524 Kill_Nick(nick, "Nick collision");
528 /* Get the server to which the service is connected */
529 intr_c = Client_GetFromToken(Client, token);
531 Log(LOG_ERR, "Server %s introduces service \"%s\" on unknown server!?",
532 Client_ID(Client), nick);
533 Kill_Nick(nick, "Unknown server");
537 /* Get user and host name */
538 ptr = strchr(nick, '@');
544 host = Client_Hostname(intr_c);
545 ptr = strchr(nick, '!');
553 /* According to RFC 2812/2813 parameter 4 <type> "is currently reserved
554 * for future usage"; but we use it to transfer the modes and check
555 * that the first character is a '+' sign and ignore it otherwise. */
556 modes = (Req->argv[3][0] == '+') ? ++Req->argv[3] : "";
558 c = Client_NewRemoteUser(intr_c, nick, hops, user, host,
559 token, modes, info, true);
561 /* Couldn't create client structure, so KILL the service to
562 * keep network status consistent ... */
563 Log(LOG_ALERT, "Can't create client structure! (on connection %d)",
564 Client_Conn(Client));
565 Kill_Nick(nick, "Server error");
569 Introduce_Client(Client, c, CLIENT_SERVICE);
575 * Handler for the IRC command "WEBIRC".
576 * Syntax: WEBIRC <password> <username> <real-hostname> <real-IP-address>
579 IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
581 /* Exactly 4 parameters are requited */
583 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
584 Client_ID(Client), Req->command);
586 if (!Conf_WebircPwd[0] || strcmp(Req->argv[0], Conf_WebircPwd) != 0)
587 return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
590 LogDebug("Connection %d: got valid WEBIRC command: user=%s, host=%s, ip=%s",
591 Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
593 Client_SetUser(Client, Req->argv[1], true);
594 Client_SetOrigUser(Client, Req->argv[1]);
595 Client_SetHostname(Client, Req->argv[2]);
601 IRC_QUIT( CLIENT *Client, REQUEST *Req )
604 char quitmsg[LINE_LEN];
606 assert( Client != NULL );
607 assert( Req != NULL );
609 /* Wrong number of arguments? */
611 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
614 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
616 if ( Client_Type( Client ) == CLIENT_SERVER )
619 target = Client_Search( Req->prefix );
622 Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
626 Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
632 if (Req->argc == 1 && quitmsg[0] != '\"') {
633 /* " " to avoid confusion */
634 strlcpy(quitmsg, "\"", sizeof quitmsg);
635 strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
636 strlcat(quitmsg, "\"", sizeof quitmsg );
639 /* User, Service, or not yet registered */
640 Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
648 IRC_PING(CLIENT *Client, REQUEST *Req)
650 CLIENT *target, *from;
652 assert(Client != NULL);
656 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
659 /* Don't ignore additional arguments when in "strict" mode */
661 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
662 Client_ID(Client), Req->command);
666 /* A target has been specified ... */
667 target = Client_Search(Req->argv[1]);
669 if (!target || Client_Type(target) != CLIENT_SERVER)
670 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
671 Client_ID(Client), Req->argv[1]);
673 if (target != Client_ThisServer()) {
674 /* Ok, we have to forward the PING */
675 if (Client_Type(Client) == CLIENT_SERVER)
676 from = Client_Search(Req->prefix);
680 return IRC_WriteStrClient(Client,
681 ERR_NOSUCHSERVER_MSG,
682 Client_ID(Client), Req->prefix);
684 return IRC_WriteStrClientPrefix(target, from,
685 "PING %s :%s", Req->argv[0],
690 if (Client_Type(Client) == CLIENT_SERVER) {
692 from = Client_Search(Req->prefix);
696 from = Client_ThisServer();
698 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
699 Client_ID(Client), Req->prefix);
701 Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
702 Client_Conn(Client));
705 return IRC_WriteStrClient(Client, "PONG %s :%s",
706 Client_ID(from), Client_ID(Client));
708 /* Some clients depend on the argument being returned in the PONG
709 * reply (not mentioned in any RFC, though) */
710 return IRC_WriteStrClient(Client, "PONG %s :%s",
711 Client_ID(from), Req->argv[0]);
717 IRC_PONG(CLIENT *Client, REQUEST *Req)
719 CLIENT *target, *from;
722 assert(Client != NULL);
725 /* Wrong number of arguments? */
727 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
730 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
731 Client_ID(Client), Req->command);
734 if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
735 target = Client_Search(Req->argv[0]);
737 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
738 Client_ID(Client), Req->argv[0]);
740 from = Client_Search(Req->prefix);
742 if (target != Client_ThisServer() && target != from) {
743 /* Ok, we have to forward the message. */
745 return IRC_WriteStrClient(Client,
746 ERR_NOSUCHSERVER_MSG,
747 Client_ID(Client), Req->prefix);
749 if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
753 return IRC_WriteStrClientPrefix(target, from,
754 "PONG %s :%s", s, Req->argv[1]);
758 /* The connection timestamp has already been updated when the data has
759 * been read from so socket, so we don't need to update it here. */
761 if (Client_Conn(Client) > NONE)
763 "Connection %d: received PONG. Lag: %ld seconds.",
765 time(NULL) - Conn_LastPing(Client_Conn(Client)));
768 "Connection %d: received PONG.", Client_Conn(Client));
775 Hello_User(CLIENT * Client)
778 int pipefd[2], result;
782 assert(Client != NULL);
783 conn = Client_Conn(Client);
786 /* Don't do any PAM authentication at all, instead emulate
787 * the beahiour of the daemon compiled without PAM support:
788 * because there can't be any "server password", all
789 * passwords supplied are classified as "wrong". */
790 if(Client_Password(Client)[0] == '\0')
791 return Hello_User_PostAuth(Client);
792 Reject_Client(Client);
796 /* Fork child process for PAM authentication; and make sure that the
797 * process timeout is set higher than the login timeout! */
798 pid = Proc_Fork(Conn_GetProcStat(conn), pipefd,
799 cb_Read_Auth_Result, Conf_PongTimeout + 1);
801 LogDebug("Authenticator for connection %d created (PID %d).",
806 Log_Init_Subprocess("Auth");
807 result = PAM_Authenticate(Client);
808 write(pipefd[1], &result, sizeof(result));
809 Log_Exit_Subprocess("Auth");
813 assert(Client != NULL);
815 /* Check global server password ... */
816 if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
818 Reject_Client(Client);
821 return Hello_User_PostAuth(Client);
829 * Read result of the authenticatior sub-process from pipe
832 cb_Read_Auth_Result(int r_fd, UNUSED short events)
840 LogDebug("Auth: Got callback on fd %d, events %d", r_fd, events);
841 conn = Conn_GetFromProc(r_fd);
843 /* Ops, none found? Probably the connection has already
844 * been closed!? We'll ignore that ... */
846 LogDebug("Auth: Got callback for unknown connection!?");
849 proc = Conn_GetProcStat(conn);
850 client = Conn_GetClient(conn);
852 /* Read result from pipe */
853 len = Proc_Read(proc, &result, sizeof(result));
857 if (len != sizeof(result)) {
858 Log(LOG_CRIT, "Auth: Got malformed result!");
859 Reject_Client(client);
863 if (result == true) {
864 Client_SetUser(client, Client_OrigUser(client), true);
865 (void)Hello_User_PostAuth(client);
867 Reject_Client(client);
874 Reject_Client(CLIENT *Client)
877 "User \"%s\" rejected (connection %d): Access denied!",
878 Client_Mask(Client), Client_Conn(Client));
879 Conn_Close(Client_Conn(Client), NULL,
880 "Access denied! Bad password?", true);
885 Hello_User_PostAuth(CLIENT *Client)
887 Introduce_Client(NULL, Client, CLIENT_USER);
889 if (!IRC_WriteStrClient
890 (Client, RPL_WELCOME_MSG, Client_ID(Client), Client_Mask(Client)))
892 if (!IRC_WriteStrClient
893 (Client, RPL_YOURHOST_MSG, Client_ID(Client),
894 Client_ID(Client_ThisServer()), PACKAGE_VERSION, TARGET_CPU,
895 TARGET_VENDOR, TARGET_OS))
897 if (!IRC_WriteStrClient
898 (Client, RPL_CREATED_MSG, Client_ID(Client), NGIRCd_StartStr))
900 if (!IRC_WriteStrClient
901 (Client, RPL_MYINFO_MSG, Client_ID(Client),
902 Client_ID(Client_ThisServer()), PACKAGE_VERSION, USERMODES,
906 /* Features supported by this server (005 numeric, ISUPPORT),
907 * see <http://www.irc.org/tech_docs/005.html> for details. */
908 if (!IRC_Send_ISUPPORT(Client))
911 if (!IRC_Send_LUSERS(Client))
913 if (!IRC_Show_MOTD(Client))
916 /* Suspend the client for a second ... */
917 IRC_SetPenalty(Client, 1);
924 Kill_Nick( char *Nick, char *Reason )
928 assert( Nick != NULL );
929 assert( Reason != NULL );
931 r.prefix = (char *)Client_ThisServer( );
936 Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
937 IRC_KILL( Client_ThisServer( ), &r );
942 Introduce_Client(CLIENT *From, CLIENT *Client, int Type)
944 /* Set client type (user or service) */
945 Client_SetType(Client, Type);
948 if (Conf_IsService(Conf_GetServer(Client_Conn(From)),
950 Client_SetType(Client, CLIENT_SERVICE);
951 LogDebug("%s \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
952 Client_TypeText(Client), Client_Mask(Client),
953 Client_Modes(Client), Client_ID(From),
954 Client_ID(Client_Introducer(Client)),
955 Client_Hops(Client), Client_Hops(Client) > 1 ? "s": "");
957 Log(LOG_NOTICE, "%s \"%s\" registered (connection %d).",
958 Client_TypeText(Client), Client_Mask(Client),
959 Client_Conn(Client));
960 Log_ServerNotice('c', "Client connecting: %s (%s@%s) [%s] - %s",
961 Client_ID(Client), Client_User(Client),
962 Client_Hostname(Client),
963 Conn_IPA(Client_Conn(Client)),
964 Client_TypeText(Client));
967 /* Inform other servers */
968 IRC_WriteStrServersPrefixFlag_CB(From,
969 From != NULL ? From : Client_ThisServer(),
970 '\0', cb_introduceClient, (void *)Client);
971 } /* Introduce_Client */
975 cb_introduceClient(CLIENT *To, CLIENT *Prefix, void *data)
977 CLIENT *c = (CLIENT *)data;
979 char *modes, *user, *host;
981 modes = Client_Modes(c);
982 user = Client_User(c) ? Client_User(c) : "-";
983 host = Client_Hostname(c) ? Client_Hostname(c) : "-";
985 conn = Client_Conn(To);
986 if (Conn_Options(conn) & CONN_RFC1459) {
987 /* RFC 1459 mode: separate NICK and USER commands */
988 Conn_WriteStr(conn, "NICK %s :%d", Client_ID(c),
990 Conn_WriteStr(conn, ":%s USER %s %s %s :%s",
991 Client_ID(c), user, host,
992 Client_ID(Client_Introducer(c)), Client_Info(c));
994 Conn_WriteStr(conn, ":%s MODE %s +%s",
995 Client_ID(c), Client_ID(c), modes);
997 /* RFC 2813 mode: one combined NICK or SERVICE command */
998 if (Client_Type(c) == CLIENT_SERVICE
999 && strchr(Client_Flags(To), 'S'))
1000 IRC_WriteStrClientPrefix(To, Prefix,
1001 "SERVICE %s %d * +%s %d :%s",
1003 Client_MyToken(Client_Introducer(c)),
1004 Client_Modes(c), Client_Hops(c) + 1,
1007 IRC_WriteStrClientPrefix(To, Prefix,
1008 "NICK %s %d %s %s %d +%s :%s",
1009 Client_ID(c), Client_Hops(c) + 1,
1011 Client_MyToken(Client_Introducer(c)),
1012 modes, Client_Info(c));
1014 } /* cb_introduceClient */