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.
27 #include "conn-func.h"
37 #include "irc-write.h"
40 #include "irc-login.h"
43 static bool Hello_User PARAMS(( CLIENT *Client ));
44 static bool Hello_User_PostAuth PARAMS(( CLIENT *Client ));
45 static void Kill_Nick PARAMS(( char *Nick, char *Reason ));
46 static void Introduce_Client PARAMS((CLIENT *To, CLIENT *Client, int Type));
47 static void Reject_Client PARAMS((CLIENT *Client));
49 static void cb_introduceClient PARAMS((CLIENT *Client, CLIENT *Prefix,
53 static void cb_Read_Auth_Result PARAMS((int r_fd, UNUSED short events));
57 * Handler for the IRC command "PASS".
58 * See RFC 2813 section 4.1.1, and RFC 2812 section 3.1.1.
61 IRC_PASS( CLIENT *Client, REQUEST *Req )
63 char *type, *orig_flags;
64 int protohigh, protolow;
66 assert( Client != NULL );
67 assert( Req != NULL );
69 /* Return an error if this is not a local client */
70 if (Client_Conn(Client) <= NONE)
71 return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
72 Client_ID(Client), Req->command);
74 if (Client_Type(Client) == CLIENT_UNKNOWN && Req->argc == 1) {
75 /* Not yet registered "unknown" connection, PASS with one
76 * argument: either a regular client, service, or server
77 * using the old RFC 1459 section 4.1.1 syntax. */
78 LogDebug("Connection %d: got PASS command (RFC 1459) ...",
80 } else if ((Client_Type(Client) == CLIENT_UNKNOWN ||
81 Client_Type(Client) == CLIENT_UNKNOWNSERVER) &&
82 (Req->argc == 3 || Req->argc == 4)) {
83 /* Not yet registered "unknown" connection or outgoing server
84 * link, PASS with three or four argument: server using the
85 * RFC 2813 section 4.1.1 syntax. */
86 LogDebug("Connection %d: got PASS command (RFC 2813, new server link) ...",
88 } else if (Client_Type(Client) == CLIENT_UNKNOWN ||
89 Client_Type(Client) == CLIENT_UNKNOWNSERVER) {
90 /* Unregistered connection, but wrong number of arguments: */
91 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
92 Client_ID(Client), Req->command);
94 /* Registered connection, PASS command is not allowed! */
95 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
99 Client_SetPassword(Client, Req->argv[0]);
101 /* Protocol version */
102 if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
105 c2 = Req->argv[1][2];
106 c4 = Req->argv[1][4];
108 Req->argv[1][4] = '\0';
109 protolow = atoi(&Req->argv[1][2]);
110 Req->argv[1][2] = '\0';
111 protohigh = atoi(Req->argv[1]);
113 Req->argv[1][2] = c2;
114 Req->argv[1][4] = c4;
116 Client_SetType(Client, CLIENT_GOTPASS_2813);
118 protohigh = protolow = 0;
119 Client_SetType(Client, CLIENT_GOTPASS);
122 /* Protocol type, see doc/Protocol.txt */
123 if (Req->argc >= 2 && strlen(Req->argv[1]) > 4)
124 type = &Req->argv[1][4];
128 /* Protocol flags/options */
130 orig_flags = Req->argv[3];
134 /* Implementation, version and IRC+ flags */
135 if (Req->argc >= 3) {
136 char *impl, *ptr, *serverver, *flags;
139 ptr = strchr(impl, '|');
143 if (type && strcmp(type, PROTOIRCPLUS) == 0) {
144 /* The peer seems to be a server which supports the
145 * IRC+ protocol (see doc/Protocol.txt). */
147 flags = strchr(serverver, ':');
154 "Peer announces itself as %s-%s using protocol %d.%d/IRC+ (flags: \"%s\").",
155 impl, serverver, protohigh, protolow, flags);
157 /* The peer seems to be a server supporting the
158 * "original" IRC protocol (RFC 2813). */
159 if (strchr(orig_flags, 'Z'))
164 "Peer announces itself as \"%s\" using protocol %d.%d (flags: \"%s\").",
165 impl, protohigh, protolow, flags);
167 Client_SetFlags(Client, flags);
175 * IRC "NICK" command.
176 * This function implements the IRC command "NICK" which is used to register
177 * with the server, to change already registered nicknames and to introduce
178 * new users which are connected to other servers.
181 IRC_NICK( CLIENT *Client, REQUEST *Req )
183 CLIENT *intr_c, *target, *c;
184 char *nick, *user, *hostname, *modes, *info;
187 assert( Client != NULL );
188 assert( Req != NULL );
190 /* Some IRC clients, for example BitchX, send the NICK and USER
191 * commands in the wrong order ... */
192 if(Client_Type(Client) == CLIENT_UNKNOWN
193 || Client_Type(Client) == CLIENT_GOTPASS
194 || Client_Type(Client) == CLIENT_GOTNICK
196 || Client_Type(Client) == CLIENT_GOTUSER
198 || Client_Type(Client) == CLIENT_USER
199 || Client_Type(Client) == CLIENT_SERVICE
200 || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
202 /* User registration or change of nickname */
204 /* Wrong number of arguments? */
206 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
210 /* Search "target" client */
211 if( Client_Type( Client ) == CLIENT_SERVER )
213 target = Client_Search( Req->prefix );
215 return IRC_WriteStrClient( Client,
222 /* Is this a restricted client? */
223 if( Client_HasMode( Client, 'r' ))
224 return IRC_WriteStrClient( Client,
226 Client_ID( Client ));
232 /* If the clients tries to change to its own nickname we won't
233 * do anything. This is how the original ircd behaves and some
234 * clients (for example Snak) expect it to be like this.
235 * But I doubt that this is "really the right thing" ... */
236 if( strcmp( Client_ID( target ), Req->argv[0] ) == 0 )
240 /* Check that the new nickname is available. Special case:
241 * the client only changes from/to upper to lower case. */
242 if( strcasecmp( Client_ID( target ), Req->argv[0] ) != 0 )
244 if( ! Client_CheckNick( target, Req->argv[0] ))
248 if (Client_Type(target) != CLIENT_USER &&
249 Client_Type(target) != CLIENT_SERVICE &&
250 Client_Type(target) != CLIENT_SERVER) {
252 LogDebug("Connection %d: got valid NICK command ...",
253 Client_Conn( Client ));
255 /* Register new nickname of this client */
256 Client_SetID( target, Req->argv[0] );
258 /* If we received a valid USER command already then
259 * register the new client! */
260 if( Client_Type( Client ) == CLIENT_GOTUSER )
261 return Hello_User( Client );
263 Client_SetType( Client, CLIENT_GOTNICK );
265 /* Nickname change */
266 if (Client_Conn(target) > NONE) {
269 "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
270 Client_TypeText(target), Client_Mask(target),
271 Client_Conn(target), Client_ID(target),
273 Conn_UpdateIdle(Client_Conn(target));
276 LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
277 Client_TypeText(target),
278 Client_Mask(target), Client_ID(target),
282 /* Inform all users and servers (which have to know)
283 * of this nickname change */
284 if( Client_Type( Client ) == CLIENT_USER )
285 IRC_WriteStrClientPrefix( Client, Client,
288 IRC_WriteStrServersPrefix( Client, target,
289 "NICK :%s", Req->argv[0] );
290 IRC_WriteStrRelatedPrefix( target, target, false,
291 "NICK :%s", Req->argv[0] );
293 /* Register old nickname for WHOWAS queries */
294 Client_RegisterWhowas( target );
296 /* Save new nickname */
297 Client_SetID( target, Req->argv[0] );
299 IRC_SetPenalty( target, 2 );
303 } else if(Client_Type(Client) == CLIENT_SERVER ||
304 Client_Type(Client) == CLIENT_SERVICE) {
305 /* Server or service introduces new client */
307 /* Bad number of parameters? */
308 if (Req->argc != 2 && Req->argc != 7)
309 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
310 Client_ID(Client), Req->command);
312 if (Req->argc >= 7) {
313 /* RFC 2813 compatible syntax */
315 hops = atoi(Req->argv[1]);
317 hostname = Req->argv[3];
318 token = atoi(Req->argv[4]);
319 modes = Req->argv[5] + 1;
322 /* RFC 1459 compatible syntax */
326 hostname = Client_ID(Client);
327 token = atoi(Req->argv[1]);
332 c = Client_Search(nick);
335 * the new nick is already present on this server:
336 * the new and the old one have to be disconnected now.
338 Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] );
339 Kill_Nick( Req->argv[0], "Nick collision" );
343 /* Find the Server this client is connected to */
344 intr_c = Client_GetFromToken(Client, token);
347 Log( LOG_ERR, "Server %s introduces nick \"%s\" on unknown server!?", Client_ID( Client ), Req->argv[0] );
348 Kill_Nick( Req->argv[0], "Unknown server" );
352 c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname,
353 token, modes, info, true);
356 /* out of memory, need to disconnect client to keep network state consistent */
357 Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client ));
358 Kill_Nick( Req->argv[0], "Server error" );
362 /* RFC 2813: client is now fully registered, inform all the
363 * other servers about the new user.
364 * RFC 1459: announce the new client only after receiving the
365 * USER command, first we need more information! */
367 LogDebug("Client \"%s\" is being registered (RFC 1459) ...",
369 Client_SetType(c, CLIENT_GOTNICK);
371 Introduce_Client(Client, c, CLIENT_USER);
375 else return IRC_WriteStrClient( Client, ERR_ALREADYREGISTRED_MSG, Client_ID( Client ));
380 * Handler for the IRC command "USER".
383 IRC_USER(CLIENT * Client, REQUEST * Req)
390 assert(Client != NULL);
393 if (Client_Type(Client) == CLIENT_GOTNICK ||
395 Client_Type(Client) == CLIENT_UNKNOWN ||
397 Client_Type(Client) == CLIENT_GOTPASS)
401 return IRC_WriteStrClient(Client,
402 ERR_NEEDMOREPARAMS_MSG,
408 ptr = Client_User(Client);
409 if (!ptr || !*ptr || *ptr == '~')
410 Client_SetUser(Client, Req->argv[0], false);
412 Client_SetUser(Client, Req->argv[0], false);
414 Client_SetOrigUser(Client, Req->argv[0]);
416 /* "Real name" or user info text: Don't set it to the empty
417 * string, the original ircd can't deal with such "real names"
418 * (e. g. "USER user * * :") ... */
420 Client_SetInfo(Client, Req->argv[3]);
422 Client_SetInfo(Client, "-");
424 LogDebug("Connection %d: got valid USER command ...",
425 Client_Conn(Client));
426 if (Client_Type(Client) == CLIENT_GOTNICK)
427 return Hello_User(Client);
429 Client_SetType(Client, CLIENT_GOTUSER);
432 } else if (Client_Type(Client) == CLIENT_SERVER ||
433 Client_Type(Client) == CLIENT_SERVICE) {
434 /* Server/service updating an user */
436 return IRC_WriteStrClient(Client,
437 ERR_NEEDMOREPARAMS_MSG,
440 c = Client_Search(Req->prefix);
442 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
446 Client_SetUser(c, Req->argv[0], true);
447 Client_SetOrigUser(c, Req->argv[0]);
448 Client_SetHostname(c, Req->argv[1]);
449 Client_SetInfo(c, Req->argv[3]);
451 LogDebug("Connection %d: got valid USER command for \"%s\".",
452 Client_Conn(Client), Client_Mask(c));
454 /* RFC 1459 style user registration?
455 * Introduce client to network: */
456 if (Client_Type(c) == CLIENT_GOTNICK)
457 Introduce_Client(Client, c, CLIENT_USER);
460 } else if (Client_Type(Client) == CLIENT_USER) {
461 /* Already registered connection */
462 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
465 /* Unexpected/invalid connection state? */
466 return IRC_WriteStrClient(Client, ERR_NOTREGISTERED_MSG,
473 * Handler for the IRC command "SERVICE".
474 * This function implements IRC Services registration using the SERVICE command
475 * defined in RFC 2812 3.1.6 and RFC 2813 4.1.4.
476 * At the moment ngIRCd doesn't support directly linked services, so this
477 * function returns ERR_ERRONEUSNICKNAME when the SERVICE command has not been
478 * received from a peer server.
481 IRC_SERVICE(CLIENT *Client, REQUEST *Req)
484 char *nick, *user, *host, *info, *modes, *ptr;
487 assert(Client != NULL);
490 if (Client_Type(Client) != CLIENT_GOTPASS &&
491 Client_Type(Client) != CLIENT_SERVER)
492 return IRC_WriteStrClient(Client, ERR_ALREADYREGISTRED_MSG,
496 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
497 Client_ID(Client), Req->command);
499 if (Client_Type(Client) != CLIENT_SERVER)
500 return IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
501 Client_ID(Client), Req->argv[0]);
503 /* Bad number of parameters? */
505 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
506 Client_ID(Client), Req->command);
509 user = NULL; host = NULL;
510 token = atoi(Req->argv[1]);
511 hops = atoi(Req->argv[4]);
514 /* Validate service name ("nick name") */
515 c = Client_Search(nick);
517 /* Nick name collission: disconnect (KILL) both clients! */
518 Log(LOG_ERR, "Server %s introduces already registered service \"%s\"!",
519 Client_ID(Client), nick);
520 Kill_Nick(nick, "Nick collision");
524 /* Get the server to which the service is connected */
525 intr_c = Client_GetFromToken(Client, token);
527 Log(LOG_ERR, "Server %s introduces service \"%s\" on unknown server!?",
528 Client_ID(Client), nick);
529 Kill_Nick(nick, "Unknown server");
533 /* Get user and host name */
534 ptr = strchr(nick, '@');
540 host = Client_Hostname(intr_c);
541 ptr = strchr(nick, '!');
549 /* According to RFC 2812/2813 parameter 4 <type> "is currently reserved
550 * for future usage"; but we use it to transfer the modes and check
551 * that the first character is a '+' sign and ignore it otherwise. */
552 modes = (Req->argv[3][0] == '+') ? ++Req->argv[3] : "";
554 c = Client_NewRemoteUser(intr_c, nick, hops, user, host,
555 token, modes, info, true);
557 /* Couldn't create client structure, so KILL the service to
558 * keep network status consistent ... */
559 Log(LOG_ALERT, "Can't create client structure! (on connection %d)",
560 Client_Conn(Client));
561 Kill_Nick(nick, "Server error");
565 Introduce_Client(Client, c, CLIENT_SERVICE);
571 * Handler for the IRC command "WEBIRC".
572 * Syntax: WEBIRC <password> <username> <real-hostname> <real-IP-address>
575 IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
577 /* Exactly 4 parameters are requited */
579 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
580 Client_ID(Client), Req->command);
582 if (!Conf_WebircPwd[0] || strcmp(Req->argv[0], Conf_WebircPwd) != 0)
583 return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
586 LogDebug("Connection %d: got valid WEBIRC command: user=%s, host=%s, ip=%s",
587 Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
589 Client_SetUser(Client, Req->argv[1], true);
590 Client_SetOrigUser(Client, Req->argv[1]);
591 Client_SetHostname(Client, Req->argv[2]);
597 IRC_QUIT( CLIENT *Client, REQUEST *Req )
600 char quitmsg[LINE_LEN];
602 assert( Client != NULL );
603 assert( Req != NULL );
605 /* Wrong number of arguments? */
607 return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
610 strlcpy(quitmsg, Req->argv[0], sizeof quitmsg);
612 if ( Client_Type( Client ) == CLIENT_SERVER )
615 target = Client_Search( Req->prefix );
618 Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client ));
622 Client_Destroy( target, "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
628 if (Req->argc == 1 && quitmsg[0] != '\"') {
629 /* " " to avoid confusion */
630 strlcpy(quitmsg, "\"", sizeof quitmsg);
631 strlcat(quitmsg, Req->argv[0], sizeof quitmsg-1);
632 strlcat(quitmsg, "\"", sizeof quitmsg );
635 /* User, Service, or not yet registered */
636 Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true);
644 IRC_PING(CLIENT *Client, REQUEST *Req)
646 CLIENT *target, *from;
648 assert(Client != NULL);
652 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
655 /* Don't ignore additional arguments when in "strict" mode */
657 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
658 Client_ID(Client), Req->command);
662 /* A target has been specified ... */
663 target = Client_Search(Req->argv[1]);
665 if (!target || Client_Type(target) != CLIENT_SERVER)
666 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
667 Client_ID(Client), Req->argv[1]);
669 if (target != Client_ThisServer()) {
670 /* Ok, we have to forward the PING */
671 if (Client_Type(Client) == CLIENT_SERVER)
672 from = Client_Search(Req->prefix);
676 return IRC_WriteStrClient(Client,
677 ERR_NOSUCHSERVER_MSG,
678 Client_ID(Client), Req->prefix);
680 return IRC_WriteStrClientPrefix(target, from,
681 "PING %s :%s", Req->argv[0],
686 if (Client_Type(Client) == CLIENT_SERVER) {
688 from = Client_Search(Req->prefix);
692 from = Client_ThisServer();
694 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
695 Client_ID(Client), Req->prefix);
697 Log(LOG_DEBUG, "Connection %d: got PING, sending PONG ...",
698 Client_Conn(Client));
701 return IRC_WriteStrClient(Client, "PONG %s :%s",
702 Client_ID(from), Client_ID(Client));
704 /* Some clients depend on the argument being returned in the PONG
705 * reply (not mentioned in any RFC, though) */
706 return IRC_WriteStrClient(Client, "PONG %s :%s",
707 Client_ID(from), Req->argv[0]);
713 IRC_PONG(CLIENT *Client, REQUEST *Req)
715 CLIENT *target, *from;
718 assert(Client != NULL);
721 /* Wrong number of arguments? */
723 return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG,
726 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
727 Client_ID(Client), Req->command);
730 if (Req->argc == 2 && Client_Type(Client) == CLIENT_SERVER) {
731 target = Client_Search(Req->argv[0]);
733 return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
734 Client_ID(Client), Req->argv[0]);
736 from = Client_Search(Req->prefix);
738 if (target != Client_ThisServer() && target != from) {
739 /* Ok, we have to forward the message. */
741 return IRC_WriteStrClient(Client,
742 ERR_NOSUCHSERVER_MSG,
743 Client_ID(Client), Req->prefix);
745 if (Client_Type(Client_NextHop(target)) != CLIENT_SERVER)
749 return IRC_WriteStrClientPrefix(target, from,
750 "PONG %s :%s", s, Req->argv[1]);
754 /* The connection timestamp has already been updated when the data has
755 * been read from so socket, so we don't need to update it here. */
757 if (Client_Conn(Client) > NONE)
759 "Connection %d: received PONG. Lag: %ld seconds.",
761 time(NULL) - Conn_LastPing(Client_Conn(Client)));
764 "Connection %d: received PONG.", Client_Conn(Client));
771 Hello_User(CLIENT * Client)
774 int pipefd[2], result;
778 assert(Client != NULL);
779 conn = Client_Conn(Client);
782 /* Don't do any PAM authentication at all, instead emulate
783 * the beahiour of the daemon compiled without PAM support:
784 * because there can't be any "server password", all
785 * passwords supplied are classified as "wrong". */
786 if(Client_Password(Client)[0] == '\0')
787 return Hello_User_PostAuth(Client);
788 Reject_Client(Client);
792 pid = Proc_Fork(Conn_GetProcStat(conn), pipefd, cb_Read_Auth_Result);
794 LogDebug("Authenticator for connection %d created (PID %d).",
799 Log_Init_Subprocess("Auth");
800 result = PAM_Authenticate(Client);
801 write(pipefd[1], &result, sizeof(result));
802 Log_Exit_Subprocess("Auth");
806 assert(Client != NULL);
808 /* Check global server password ... */
809 if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
811 Reject_Client(Client);
814 return Hello_User_PostAuth(Client);
822 * Read result of the authenticatior sub-process from pipe
825 cb_Read_Auth_Result(int r_fd, UNUSED short events)
833 LogDebug("Auth: Got callback on fd %d, events %d", r_fd, events);
834 conn = Conn_GetFromProc(r_fd);
836 /* Ops, none found? Probably the connection has already
837 * been closed!? We'll ignore that ... */
839 LogDebug("Auth: Got callback for unknown connection!?");
842 proc = Conn_GetProcStat(conn);
843 client = Conn_GetClient(conn);
845 /* Read result from pipe */
846 len = Proc_Read(proc, &result, sizeof(result));
850 if (len != sizeof(result)) {
851 Log(LOG_CRIT, "Auth: Got malformed result!");
852 Reject_Client(client);
856 if (result == true) {
857 Client_SetUser(client, Client_OrigUser(client), true);
858 (void)Hello_User_PostAuth(client);
860 Reject_Client(client);
867 Reject_Client(CLIENT *Client)
870 "User \"%s\" rejected (connection %d): Access denied!",
871 Client_Mask(Client), Client_Conn(Client));
872 Conn_Close(Client_Conn(Client), NULL,
873 "Access denied! Bad password?", true);
878 Hello_User_PostAuth(CLIENT *Client)
880 Introduce_Client(NULL, Client, CLIENT_USER);
882 if (!IRC_WriteStrClient
883 (Client, RPL_WELCOME_MSG, Client_ID(Client), Client_Mask(Client)))
885 if (!IRC_WriteStrClient
886 (Client, RPL_YOURHOST_MSG, Client_ID(Client),
887 Client_ID(Client_ThisServer()), PACKAGE_VERSION, TARGET_CPU,
888 TARGET_VENDOR, TARGET_OS))
890 if (!IRC_WriteStrClient
891 (Client, RPL_CREATED_MSG, Client_ID(Client), NGIRCd_StartStr))
893 if (!IRC_WriteStrClient
894 (Client, RPL_MYINFO_MSG, Client_ID(Client),
895 Client_ID(Client_ThisServer()), PACKAGE_VERSION, USERMODES,
899 /* Features supported by this server (005 numeric, ISUPPORT),
900 * see <http://www.irc.org/tech_docs/005.html> for details. */
901 if (!IRC_Send_ISUPPORT(Client))
904 if (!IRC_Send_LUSERS(Client))
906 if (!IRC_Show_MOTD(Client))
909 /* Suspend the client for a second ... */
910 IRC_SetPenalty(Client, 1);
917 Kill_Nick( char *Nick, char *Reason )
921 assert( Nick != NULL );
922 assert( Reason != NULL );
924 r.prefix = (char *)Client_ThisServer( );
929 Log( LOG_ERR, "User(s) with nick \"%s\" will be disconnected: %s", Nick, Reason );
930 IRC_KILL( Client_ThisServer( ), &r );
935 Introduce_Client(CLIENT *From, CLIENT *Client, int Type)
937 /* Set client type (user or service) */
938 Client_SetType(Client, Type);
941 if (Conf_IsService(Conf_GetServer(Client_Conn(From)),
943 Client_SetType(Client, CLIENT_SERVICE);
944 LogDebug("%s \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
945 Client_TypeText(Client), Client_Mask(Client),
946 Client_Modes(Client), Client_ID(From),
947 Client_ID(Client_Introducer(Client)),
948 Client_Hops(Client), Client_Hops(Client) > 1 ? "s": "");
950 Log(LOG_NOTICE, "%s \"%s\" registered (connection %d).",
951 Client_TypeText(Client), Client_Mask(Client),
952 Client_Conn(Client));
953 Log_ServerNotice('c', "Client connecting: %s (%s@%s) [%s] - %s",
954 Client_ID(Client), Client_User(Client),
955 Client_Hostname(Client),
956 Conn_IPA(Client_Conn(Client)),
957 Client_TypeText(Client));
960 /* Inform other servers */
961 IRC_WriteStrServersPrefixFlag_CB(From,
962 From != NULL ? From : Client_ThisServer(),
963 '\0', cb_introduceClient, (void *)Client);
964 } /* Introduce_Client */
968 cb_introduceClient(CLIENT *To, CLIENT *Prefix, void *data)
970 CLIENT *c = (CLIENT *)data;
972 char *modes, *user, *host;
974 modes = Client_Modes(c);
975 user = Client_User(c) ? Client_User(c) : "-";
976 host = Client_Hostname(c) ? Client_Hostname(c) : "-";
978 conn = Client_Conn(To);
979 if (Conn_Options(conn) & CONN_RFC1459) {
980 /* RFC 1459 mode: separate NICK and USER commands */
981 Conn_WriteStr(conn, "NICK %s :%d", Client_ID(c),
983 Conn_WriteStr(conn, ":%s USER %s %s %s :%s",
984 Client_ID(c), user, host,
985 Client_ID(Client_Introducer(c)), Client_Info(c));
987 Conn_WriteStr(conn, ":%s MODE %s +%s",
988 Client_ID(c), Client_ID(c), modes);
990 /* RFC 2813 mode: one combined NICK or SERVICE command */
991 if (Client_Type(c) == CLIENT_SERVICE
992 && strchr(Client_Flags(To), 'S'))
993 IRC_WriteStrClientPrefix(To, Prefix,
994 "SERVICE %s %d * +%s %d :%s",
996 Client_MyToken(Client_Introducer(c)),
997 Client_Modes(c), Client_Hops(c) + 1,
1000 IRC_WriteStrClientPrefix(To, Prefix,
1001 "NICK %s %d %s %s %d +%s :%s",
1002 Client_ID(c), Client_Hops(c) + 1,
1004 Client_MyToken(Client_Introducer(c)),
1005 modes, Client_Info(c));
1007 } /* cb_introduceClient */