1
0

client.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
  4. *
  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.
  10. */
  11. #define __client_c__
  12. #include "portab.h"
  13. /**
  14. * @file
  15. * Client management.
  16. */
  17. #include "imp.h"
  18. #include <assert.h>
  19. #include <unistd.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <strings.h>
  24. #include <netdb.h>
  25. #include "defines.h"
  26. #include "conn.h"
  27. #include "exp.h"
  28. #include "client.h"
  29. #include <imp.h>
  30. #include "ngircd.h"
  31. #include "channel.h"
  32. #include "conf.h"
  33. #include "conn-func.h"
  34. #include "hash.h"
  35. #include "irc-write.h"
  36. #include "log.h"
  37. #include "messages.h"
  38. #include <exp.h>
  39. #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
  40. static CLIENT *This_Server, *My_Clients;
  41. static WHOWAS My_Whowas[MAX_WHOWAS];
  42. static int Last_Whowas = -1;
  43. static long Max_Users, My_Max_Users;
  44. static unsigned long Count PARAMS(( CLIENT_TYPE Type ));
  45. static unsigned long MyCount PARAMS(( CLIENT_TYPE Type ));
  46. static CLIENT *New_Client_Struct PARAMS(( void ));
  47. static void Generate_MyToken PARAMS(( CLIENT *Client ));
  48. static void Adjust_Counters PARAMS(( CLIENT *Client ));
  49. static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer,
  50. CLIENT *TopServer, int Type, const char *ID,
  51. const char *User, const char *Hostname, const char *Info,
  52. int Hops, int Token, const char *Modes,
  53. bool Idented));
  54. static void Destroy_UserOrService PARAMS((CLIENT *Client,const char *Txt, const char *FwdMsg,
  55. bool SendQuit));
  56. static void cb_introduceClient PARAMS((CLIENT *Client, CLIENT *Prefix,
  57. void *i));
  58. GLOBAL void
  59. Client_Init( void )
  60. {
  61. struct hostent *h;
  62. This_Server = New_Client_Struct( );
  63. if( ! This_Server )
  64. {
  65. Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
  66. Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
  67. exit( 1 );
  68. }
  69. /* Client-Struktur dieses Servers */
  70. This_Server->next = NULL;
  71. This_Server->type = CLIENT_SERVER;
  72. This_Server->conn_id = NONE;
  73. This_Server->introducer = This_Server;
  74. This_Server->mytoken = 1;
  75. This_Server->hops = 0;
  76. gethostname( This_Server->host, CLIENT_HOST_LEN );
  77. if (Conf_DNS) {
  78. h = gethostbyname( This_Server->host );
  79. if (h) strlcpy(This_Server->host, h->h_name, sizeof(This_Server->host));
  80. }
  81. Client_SetID( This_Server, Conf_ServerName );
  82. Client_SetInfo( This_Server, Conf_ServerInfo );
  83. My_Clients = This_Server;
  84. memset( &My_Whowas, 0, sizeof( My_Whowas ));
  85. } /* Client_Init */
  86. GLOBAL void
  87. Client_Exit( void )
  88. {
  89. CLIENT *c, *next;
  90. int cnt;
  91. if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, false );
  92. else Client_Destroy( This_Server, "Server going down.", NULL, false );
  93. cnt = 0;
  94. c = My_Clients;
  95. while( c )
  96. {
  97. cnt++;
  98. next = (CLIENT *)c->next;
  99. free( c );
  100. c = next;
  101. }
  102. if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
  103. } /* Client_Exit */
  104. GLOBAL CLIENT *
  105. Client_ThisServer( void )
  106. {
  107. return This_Server;
  108. } /* Client_ThisServer */
  109. /**
  110. * Initialize new local client; wrapper function for Init_New_Client().
  111. * @return New CLIENT structure.
  112. */
  113. GLOBAL CLIENT *
  114. Client_NewLocal(CONN_ID Idx, const char *Hostname, int Type, bool Idented)
  115. {
  116. return Init_New_Client(Idx, This_Server, NULL, Type, NULL, NULL,
  117. Hostname, NULL, 0, 0, NULL, Idented);
  118. } /* Client_NewLocal */
  119. /**
  120. * Initialize new remote server; wrapper function for Init_New_Client().
  121. * @return New CLIENT structure.
  122. */
  123. GLOBAL CLIENT *
  124. Client_NewRemoteServer(CLIENT *Introducer, const char *Hostname, CLIENT *TopServer,
  125. int Hops, int Token, const char *Info, bool Idented)
  126. {
  127. return Init_New_Client(NONE, Introducer, TopServer, CLIENT_SERVER,
  128. Hostname, NULL, Hostname, Info, Hops, Token, NULL, Idented);
  129. } /* Client_NewRemoteServer */
  130. /**
  131. * Initialize new remote client; wrapper function for Init_New_Client().
  132. * @return New CLIENT structure.
  133. */
  134. GLOBAL CLIENT *
  135. Client_NewRemoteUser(CLIENT *Introducer, const char *Nick, int Hops, const char *User,
  136. const char *Hostname, int Token, const char *Modes, const char *Info, bool Idented)
  137. {
  138. return Init_New_Client(NONE, Introducer, NULL, CLIENT_USER, Nick,
  139. User, Hostname, Info, Hops, Token, Modes, Idented);
  140. } /* Client_NewRemoteUser */
  141. /**
  142. * Initialize new client and set up the given parameters like client type,
  143. * user name, host name, introducing server etc. ...
  144. * @return New CLIENT structure.
  145. */
  146. static CLIENT *
  147. Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
  148. int Type, const char *ID, const char *User, const char *Hostname,
  149. const char *Info, int Hops, int Token, const char *Modes, bool Idented)
  150. {
  151. CLIENT *client;
  152. assert(Idx >= NONE);
  153. assert(Introducer != NULL);
  154. client = New_Client_Struct();
  155. if (!client)
  156. return NULL;
  157. client->starttime = time(NULL);
  158. client->conn_id = Idx;
  159. client->introducer = Introducer;
  160. client->topserver = TopServer;
  161. client->type = Type;
  162. if (ID)
  163. Client_SetID(client, ID);
  164. if (User) {
  165. Client_SetUser(client, User, Idented);
  166. Client_SetOrigUser(client, User);
  167. }
  168. if (Hostname)
  169. Client_SetHostname(client, Hostname);
  170. if (Info)
  171. Client_SetInfo(client, Info);
  172. client->hops = Hops;
  173. client->token = Token;
  174. if (Modes)
  175. Client_SetModes(client, Modes);
  176. if (Type == CLIENT_SERVER)
  177. Generate_MyToken(client);
  178. if (strchr(client->modes, 'a'))
  179. strlcpy(client->away, DEFAULT_AWAY_MSG, sizeof(client->away));
  180. client->next = (POINTER *)My_Clients;
  181. My_Clients = client;
  182. Adjust_Counters(client);
  183. return client;
  184. } /* Init_New_Client */
  185. GLOBAL void
  186. Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit )
  187. {
  188. /* remove a client */
  189. CLIENT *last, *c;
  190. char msg[LINE_LEN];
  191. const char *txt;
  192. assert( Client != NULL );
  193. if( LogMsg ) txt = LogMsg;
  194. else txt = FwdMsg;
  195. if( ! txt ) txt = "Reason unknown.";
  196. /* netsplit message */
  197. if( Client->type == CLIENT_SERVER ) {
  198. strlcpy(msg, This_Server->id, sizeof (msg));
  199. strlcat(msg, " ", sizeof (msg));
  200. strlcat(msg, Client->id, sizeof (msg));
  201. }
  202. last = NULL;
  203. c = My_Clients;
  204. while( c )
  205. {
  206. if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
  207. {
  208. /*
  209. * The client that is about to be removed is a server,
  210. * the client we are checking right now is a child of that
  211. * server and thus has to be removed, too.
  212. *
  213. * Call Client_Destroy() recursively with the server as the
  214. * new "object to be removed". This starts the cycle again, until
  215. * all servers that are linked via the original server have been
  216. * removed.
  217. */
  218. Client_Destroy( c, NULL, msg, false );
  219. last = NULL;
  220. c = My_Clients;
  221. continue;
  222. }
  223. if( c == Client )
  224. {
  225. /* found the client: remove it */
  226. if( last ) last->next = c->next;
  227. else My_Clients = (CLIENT *)c->next;
  228. if(c->type == CLIENT_USER || c->type == CLIENT_SERVICE)
  229. Destroy_UserOrService(c, txt, FwdMsg, SendQuit);
  230. else if( c->type == CLIENT_SERVER )
  231. {
  232. if( c != This_Server )
  233. {
  234. if( c->conn_id != NONE ) Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
  235. else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt );
  236. }
  237. /* inform other servers */
  238. if( ! NGIRCd_SignalQuit )
  239. {
  240. if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );
  241. else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id );
  242. }
  243. }
  244. else
  245. {
  246. if( c->conn_id != NONE )
  247. {
  248. if( c->id[0] ) Log( LOG_NOTICE, "Client \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
  249. else Log( LOG_NOTICE, "Client unregistered (connection %d): %s", c->conn_id, txt );
  250. } else {
  251. Log(LOG_WARNING, "Unregistered unknown client \"%s\": %s",
  252. c->id[0] ? c->id : "(No Nick)", txt );
  253. }
  254. }
  255. free( c );
  256. break;
  257. }
  258. last = c;
  259. c = (CLIENT *)c->next;
  260. }
  261. } /* Client_Destroy */
  262. /**
  263. * Set client hostname.
  264. *
  265. * If global hostname cloaking is in effect, don't set the real hostname
  266. * but the configured one.
  267. *
  268. * @param Client The client of which the hostname should be set.
  269. * @param Hostname The new hostname.
  270. */
  271. GLOBAL void
  272. Client_SetHostname( CLIENT *Client, const char *Hostname )
  273. {
  274. assert(Client != NULL);
  275. assert(Hostname != NULL);
  276. if (strlen(Conf_CloakHost)) {
  277. LogDebug("Updating hostname of \"%s\": \"%s\" -> \"%s\"",
  278. Client_ID(Client), Client->host, Conf_CloakHost);
  279. strlcpy(Client->host, Conf_CloakHost, sizeof(Client->host));
  280. } else {
  281. LogDebug("Updating hostname of \"%s\": \"%s\" -> \"%s\"",
  282. Client_ID(Client), Client->host, Hostname);
  283. strlcpy(Client->host, Hostname, sizeof(Client->host));
  284. }
  285. } /* Client_SetHostname */
  286. GLOBAL void
  287. Client_SetID( CLIENT *Client, const char *ID )
  288. {
  289. assert( Client != NULL );
  290. assert( ID != NULL );
  291. strlcpy( Client->id, ID, sizeof( Client->id ));
  292. if (Conf_CloakUserToNick) {
  293. strlcpy( Client->user, ID, sizeof( Client->user ));
  294. strlcpy( Client->info, ID, sizeof( Client->info ));
  295. }
  296. /* Hash */
  297. Client->hash = Hash( Client->id );
  298. } /* Client_SetID */
  299. GLOBAL void
  300. Client_SetUser( CLIENT *Client, const char *User, bool Idented )
  301. {
  302. /* set clients username */
  303. assert( Client != NULL );
  304. assert( User != NULL );
  305. if (Conf_CloakUserToNick) {
  306. strlcpy(Client->user, Client->id, sizeof(Client->user));
  307. } else if (Idented) {
  308. strlcpy(Client->user, User, sizeof(Client->user));
  309. } else {
  310. Client->user[0] = '~';
  311. strlcpy(Client->user + 1, User, sizeof(Client->user) - 1);
  312. }
  313. } /* Client_SetUser */
  314. /**
  315. * Set "original" user name of a client.
  316. * This function saves the "original" user name, the user name specified by
  317. * the peer using the USER command, into the CLIENT structure. This user
  318. * name may be used for authentication, for example.
  319. * @param Client The client.
  320. * @param User User name to set.
  321. */
  322. GLOBAL void
  323. Client_SetOrigUser(CLIENT UNUSED *Client, const char UNUSED *User)
  324. {
  325. assert(Client != NULL);
  326. assert(User != NULL);
  327. #if defined(PAM) && defined(IDENTAUTH)
  328. strlcpy(Client->orig_user, User, sizeof(Client->orig_user));
  329. #endif
  330. } /* Client_SetOrigUser */
  331. GLOBAL void
  332. Client_SetInfo( CLIENT *Client, const char *Info )
  333. {
  334. /* set client hostname */
  335. assert( Client != NULL );
  336. assert( Info != NULL );
  337. if (Conf_CloakUserToNick)
  338. strlcpy(Client->info, Client->id, sizeof(Client->info));
  339. else
  340. strlcpy(Client->info, Info, sizeof(Client->info));
  341. } /* Client_SetInfo */
  342. GLOBAL void
  343. Client_SetModes( CLIENT *Client, const char *Modes )
  344. {
  345. assert( Client != NULL );
  346. assert( Modes != NULL );
  347. strlcpy(Client->modes, Modes, sizeof( Client->modes ));
  348. } /* Client_SetModes */
  349. GLOBAL void
  350. Client_SetFlags( CLIENT *Client, const char *Flags )
  351. {
  352. assert( Client != NULL );
  353. assert( Flags != NULL );
  354. strlcpy(Client->flags, Flags, sizeof(Client->flags));
  355. } /* Client_SetFlags */
  356. GLOBAL void
  357. Client_SetPassword( CLIENT *Client, const char *Pwd )
  358. {
  359. /* set password sent by client */
  360. assert( Client != NULL );
  361. assert( Pwd != NULL );
  362. strlcpy(Client->pwd, Pwd, sizeof(Client->pwd));
  363. } /* Client_SetPassword */
  364. GLOBAL void
  365. Client_SetAway( CLIENT *Client, const char *Txt )
  366. {
  367. /* Set AWAY reason of client */
  368. assert( Client != NULL );
  369. assert( Txt != NULL );
  370. strlcpy( Client->away, Txt, sizeof( Client->away ));
  371. LogDebug("%s \"%s\" is away: %s", Client_TypeText(Client),
  372. Client_Mask(Client), Txt);
  373. } /* Client_SetAway */
  374. GLOBAL void
  375. Client_SetType( CLIENT *Client, int Type )
  376. {
  377. assert( Client != NULL );
  378. Client->type = Type;
  379. if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
  380. Adjust_Counters( Client );
  381. } /* Client_SetType */
  382. GLOBAL void
  383. Client_SetHops( CLIENT *Client, int Hops )
  384. {
  385. assert( Client != NULL );
  386. Client->hops = Hops;
  387. } /* Client_SetHops */
  388. GLOBAL void
  389. Client_SetToken( CLIENT *Client, int Token )
  390. {
  391. assert( Client != NULL );
  392. Client->token = Token;
  393. } /* Client_SetToken */
  394. GLOBAL void
  395. Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
  396. {
  397. assert( Client != NULL );
  398. assert( Introducer != NULL );
  399. Client->introducer = Introducer;
  400. } /* Client_SetIntroducer */
  401. GLOBAL void
  402. Client_SetOperByMe( CLIENT *Client, bool OperByMe )
  403. {
  404. assert( Client != NULL );
  405. Client->oper_by_me = OperByMe;
  406. } /* Client_SetOperByMe */
  407. GLOBAL bool
  408. Client_ModeAdd( CLIENT *Client, char Mode )
  409. {
  410. /* Set Mode.
  411. * If Client already alread had Mode, return false.
  412. * If the Mode was newly set, return true.
  413. */
  414. char x[2];
  415. assert( Client != NULL );
  416. x[0] = Mode; x[1] = '\0';
  417. if (!strchr( Client->modes, x[0])) {
  418. strlcat( Client->modes, x, sizeof( Client->modes ));
  419. return true;
  420. }
  421. else return false;
  422. } /* Client_ModeAdd */
  423. GLOBAL bool
  424. Client_ModeDel( CLIENT *Client, char Mode )
  425. {
  426. /* Delete Mode.
  427. * If Mode was removed, return true.
  428. * If Client did not have Mode, return false.
  429. */
  430. char x[2], *p;
  431. assert( Client != NULL );
  432. x[0] = Mode; x[1] = '\0';
  433. p = strchr( Client->modes, x[0] );
  434. if( ! p ) return false;
  435. /* Client has Mode -> delete */
  436. while( *p )
  437. {
  438. *p = *(p + 1);
  439. p++;
  440. }
  441. return true;
  442. } /* Client_ModeDel */
  443. GLOBAL CLIENT *
  444. Client_Search( const char *Nick )
  445. {
  446. /* return Client-Structure that has the corresponding Nick.
  447. * If none is found, return NULL.
  448. */
  449. char search_id[CLIENT_ID_LEN], *ptr;
  450. CLIENT *c = NULL;
  451. UINT32 search_hash;
  452. assert( Nick != NULL );
  453. /* copy Nick and truncate hostmask if necessary */
  454. strlcpy( search_id, Nick, sizeof( search_id ));
  455. ptr = strchr( search_id, '!' );
  456. if( ptr ) *ptr = '\0';
  457. search_hash = Hash(search_id);
  458. c = My_Clients;
  459. while (c) {
  460. if (c->hash == search_hash && strcasecmp(c->id, search_id) == 0)
  461. return c;
  462. c = (CLIENT *)c->next;
  463. }
  464. return NULL;
  465. } /* Client_Search */
  466. /**
  467. * Get client structure ("introducer") identfied by a server token.
  468. * @return CLIENT structure or NULL if none could be found.
  469. */
  470. GLOBAL CLIENT *
  471. Client_GetFromToken( CLIENT *Client, int Token )
  472. {
  473. CLIENT *c;
  474. assert( Client != NULL );
  475. if (!Token)
  476. return NULL;
  477. c = My_Clients;
  478. while (c) {
  479. if ((c->type == CLIENT_SERVER) && (c->introducer == Client) &&
  480. (c->token == Token))
  481. return c;
  482. c = (CLIENT *)c->next;
  483. }
  484. return NULL;
  485. } /* Client_GetFromToken */
  486. GLOBAL int
  487. Client_Type( CLIENT *Client )
  488. {
  489. assert( Client != NULL );
  490. return Client->type;
  491. } /* Client_Type */
  492. GLOBAL CONN_ID
  493. Client_Conn( CLIENT *Client )
  494. {
  495. assert( Client != NULL );
  496. return Client->conn_id;
  497. } /* Client_Conn */
  498. GLOBAL char *
  499. Client_ID( CLIENT *Client )
  500. {
  501. assert( Client != NULL );
  502. #ifdef DEBUG
  503. if(Client->type == CLIENT_USER)
  504. assert(strlen(Client->id) < Conf_MaxNickLength);
  505. #endif
  506. if( Client->id[0] ) return Client->id;
  507. else return "*";
  508. } /* Client_ID */
  509. GLOBAL char *
  510. Client_Info( CLIENT *Client )
  511. {
  512. assert( Client != NULL );
  513. return Client->info;
  514. } /* Client_Info */
  515. GLOBAL char *
  516. Client_User( CLIENT *Client )
  517. {
  518. assert( Client != NULL );
  519. return Client->user[0] ? Client->user : "~";
  520. } /* Client_User */
  521. #ifdef PAM
  522. /**
  523. * Get the "original" user name as supplied by the USER command.
  524. * The user name as given by the client is used for authentication instead
  525. * of the one detected using IDENT requests.
  526. * @param Client The client.
  527. * @return Original user name.
  528. */
  529. GLOBAL char *
  530. Client_OrigUser(CLIENT *Client) {
  531. #ifndef IDENTAUTH
  532. char *user = Client->user;
  533. if (user[0] == '~')
  534. user++;
  535. return user;
  536. #else
  537. return Client->orig_user;
  538. #endif
  539. } /* Client_OrigUser */
  540. #endif
  541. /**
  542. * Return the hostname of a client.
  543. * @param Client Pointer to client structure
  544. * @return Pointer to client hostname
  545. */
  546. GLOBAL char *
  547. Client_Hostname(CLIENT *Client)
  548. {
  549. assert (Client != NULL);
  550. return Client->host;
  551. } /* Client_Hostname */
  552. /**
  553. * Get potentially cloaked hostname of a client.
  554. * If the client has not enabled cloaking, the real hostname is used.
  555. * @param Client Pointer to client structure
  556. * @return Pointer to client hostname
  557. */
  558. GLOBAL char *
  559. Client_HostnameCloaked(CLIENT *Client)
  560. {
  561. assert(Client != NULL);
  562. if (Client_HasMode(Client, 'x'))
  563. return Client_ID(Client->introducer);
  564. else
  565. return Client_Hostname(Client);
  566. } /* Client_HostnameCloaked */
  567. GLOBAL char *
  568. Client_Password( CLIENT *Client )
  569. {
  570. assert( Client != NULL );
  571. return Client->pwd;
  572. } /* Client_Password */
  573. GLOBAL char *
  574. Client_Modes( CLIENT *Client )
  575. {
  576. assert( Client != NULL );
  577. return Client->modes;
  578. } /* Client_Modes */
  579. GLOBAL char *
  580. Client_Flags( CLIENT *Client )
  581. {
  582. assert( Client != NULL );
  583. return Client->flags;
  584. } /* Client_Flags */
  585. GLOBAL bool
  586. Client_OperByMe( CLIENT *Client )
  587. {
  588. assert( Client != NULL );
  589. return Client->oper_by_me;
  590. } /* Client_OperByMe */
  591. GLOBAL int
  592. Client_Hops( CLIENT *Client )
  593. {
  594. assert( Client != NULL );
  595. return Client->hops;
  596. } /* Client_Hops */
  597. GLOBAL int
  598. Client_Token( CLIENT *Client )
  599. {
  600. assert( Client != NULL );
  601. return Client->token;
  602. } /* Client_Token */
  603. GLOBAL int
  604. Client_MyToken( CLIENT *Client )
  605. {
  606. assert( Client != NULL );
  607. return Client->mytoken;
  608. } /* Client_MyToken */
  609. GLOBAL CLIENT *
  610. Client_NextHop( CLIENT *Client )
  611. {
  612. CLIENT *c;
  613. assert( Client != NULL );
  614. c = Client;
  615. while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server ))
  616. c = c->introducer;
  617. return c;
  618. } /* Client_NextHop */
  619. /**
  620. * Return ID of a client: "client!user@host"
  621. * This client ID is used for IRC prefixes, for example.
  622. * Please note that this function uses a global static buffer, so you can't
  623. * nest invocations without overwriting earlier results!
  624. * @param Client Pointer to client structure
  625. * @return Pointer to global buffer containing the client ID
  626. */
  627. GLOBAL char *
  628. Client_Mask( CLIENT *Client )
  629. {
  630. static char Mask_Buffer[GETID_LEN];
  631. assert (Client != NULL);
  632. /* Servers: return name only, there is no "mask" */
  633. if (Client->type == CLIENT_SERVER)
  634. return Client->id;
  635. snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
  636. Client->id, Client->user, Client->host);
  637. return Mask_Buffer;
  638. } /* Client_Mask */
  639. /**
  640. * Return ID of a client with cloaked hostname: "client!user@server-name"
  641. * This client ID is used for IRC prefixes, for example.
  642. * Please note that this function uses a global static buffer, so you can't
  643. * nest invocations without overwriting earlier results!
  644. * If the client has not enabled cloaking, the real hostname is used.
  645. * @param Client Pointer to client structure
  646. * @return Pointer to global buffer containing the client ID
  647. */
  648. GLOBAL char *
  649. Client_MaskCloaked(CLIENT *Client)
  650. {
  651. static char Mask_Buffer[GETID_LEN];
  652. assert (Client != NULL);
  653. /* Is the client using cloaking at all? */
  654. if (!Client_HasMode(Client, 'x'))
  655. return Client_Mask(Client);
  656. snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
  657. Client->id, Client->user,
  658. *Conf_CloakHostModeX ? Conf_CloakHostModeX
  659. : Client_ID(Client->introducer));
  660. return Mask_Buffer;
  661. } /* Client_MaskCloaked */
  662. GLOBAL CLIENT *
  663. Client_Introducer( CLIENT *Client )
  664. {
  665. assert( Client != NULL );
  666. return Client->introducer;
  667. } /* Client_Introducer */
  668. GLOBAL CLIENT *
  669. Client_TopServer( CLIENT *Client )
  670. {
  671. assert( Client != NULL );
  672. return Client->topserver;
  673. } /* Client_TopServer */
  674. GLOBAL bool
  675. Client_HasMode( CLIENT *Client, char Mode )
  676. {
  677. assert( Client != NULL );
  678. return strchr( Client->modes, Mode ) != NULL;
  679. } /* Client_HasMode */
  680. GLOBAL char *
  681. Client_Away( CLIENT *Client )
  682. {
  683. assert( Client != NULL );
  684. return Client->away;
  685. } /* Client_Away */
  686. /**
  687. * Make sure that a given nickname is valid.
  688. *
  689. * If the nickname is not valid for the given client, this function sends back
  690. * the appropriate error messages.
  691. *
  692. * @param Client Client that wants to change the nickname.
  693. * @param Nick New nick name.
  694. * @returns true if nickname is valid, false otherwise.
  695. */
  696. GLOBAL bool
  697. Client_CheckNick(CLIENT *Client, char *Nick)
  698. {
  699. assert(Client != NULL);
  700. assert(Nick != NULL);
  701. if (!Client_IsValidNick(Nick)) {
  702. if (strlen(Nick ) >= Conf_MaxNickLength)
  703. IRC_WriteStrClient(Client, ERR_NICKNAMETOOLONG_MSG,
  704. Client_ID(Client), Nick,
  705. Conf_MaxNickLength - 1);
  706. else
  707. IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
  708. Client_ID(Client), Nick);
  709. return false;
  710. }
  711. /* Nickname already registered? */
  712. if (Client_Search(Nick)) {
  713. IRC_WriteStrClient(Client, ERR_NICKNAMEINUSE_MSG,
  714. Client_ID(Client), Nick);
  715. return false;
  716. }
  717. return true;
  718. } /* Client_CheckNick */
  719. GLOBAL bool
  720. Client_CheckID( CLIENT *Client, char *ID )
  721. {
  722. char str[COMMAND_LEN];
  723. CLIENT *c;
  724. assert( Client != NULL );
  725. assert( Client->conn_id > NONE );
  726. assert( ID != NULL );
  727. /* ID too long? */
  728. if (strlen(ID) > CLIENT_ID_LEN) {
  729. IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID(Client), ID);
  730. return false;
  731. }
  732. /* ID already in use? */
  733. c = My_Clients;
  734. while (c) {
  735. if (strcasecmp(c->id, ID) == 0) {
  736. snprintf(str, sizeof(str), "ID \"%s\" already registered", ID);
  737. if (c->conn_id != NONE)
  738. Log(LOG_ERR, "%s (on connection %d)!", str, c->conn_id);
  739. else
  740. Log(LOG_ERR, "%s (via network)!", str);
  741. Conn_Close(Client->conn_id, str, str, true);
  742. return false;
  743. }
  744. c = (CLIENT *)c->next;
  745. }
  746. return true;
  747. } /* Client_CheckID */
  748. GLOBAL CLIENT *
  749. Client_First( void )
  750. {
  751. return My_Clients;
  752. } /* Client_First */
  753. GLOBAL CLIENT *
  754. Client_Next( CLIENT *c )
  755. {
  756. assert( c != NULL );
  757. return (CLIENT *)c->next;
  758. } /* Client_Next */
  759. GLOBAL long
  760. Client_UserCount( void )
  761. {
  762. return Count( CLIENT_USER );
  763. } /* Client_UserCount */
  764. GLOBAL long
  765. Client_ServiceCount( void )
  766. {
  767. return Count( CLIENT_SERVICE );;
  768. } /* Client_ServiceCount */
  769. GLOBAL long
  770. Client_ServerCount( void )
  771. {
  772. return Count( CLIENT_SERVER );
  773. } /* Client_ServerCount */
  774. GLOBAL long
  775. Client_MyUserCount( void )
  776. {
  777. return MyCount( CLIENT_USER );
  778. } /* Client_MyUserCount */
  779. GLOBAL long
  780. Client_MyServiceCount( void )
  781. {
  782. return MyCount( CLIENT_SERVICE );
  783. } /* Client_MyServiceCount */
  784. GLOBAL unsigned long
  785. Client_MyServerCount( void )
  786. {
  787. CLIENT *c;
  788. unsigned long cnt = 0;
  789. c = My_Clients;
  790. while( c )
  791. {
  792. if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
  793. c = (CLIENT *)c->next;
  794. }
  795. return cnt;
  796. } /* Client_MyServerCount */
  797. GLOBAL unsigned long
  798. Client_OperCount( void )
  799. {
  800. CLIENT *c;
  801. unsigned long cnt = 0;
  802. c = My_Clients;
  803. while( c )
  804. {
  805. if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
  806. c = (CLIENT *)c->next;
  807. }
  808. return cnt;
  809. } /* Client_OperCount */
  810. GLOBAL unsigned long
  811. Client_UnknownCount( void )
  812. {
  813. CLIENT *c;
  814. unsigned long cnt = 0;
  815. c = My_Clients;
  816. while( c )
  817. {
  818. if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
  819. c = (CLIENT *)c->next;
  820. }
  821. return cnt;
  822. } /* Client_UnknownCount */
  823. GLOBAL long
  824. Client_MaxUserCount( void )
  825. {
  826. return Max_Users;
  827. } /* Client_MaxUserCount */
  828. GLOBAL long
  829. Client_MyMaxUserCount( void )
  830. {
  831. return My_Max_Users;
  832. } /* Client_MyMaxUserCount */
  833. /**
  834. * Check that a given nickname is valid.
  835. *
  836. * @param Nick the nickname to check.
  837. * @returns true if nickname is valid, false otherwise.
  838. */
  839. GLOBAL bool
  840. Client_IsValidNick(const char *Nick)
  841. {
  842. const char *ptr;
  843. static const char goodchars[] = ";0123456789-";
  844. assert (Nick != NULL);
  845. if (strchr(goodchars, Nick[0]))
  846. return false;
  847. if (strlen(Nick ) >= Conf_MaxNickLength)
  848. return false;
  849. ptr = Nick;
  850. while (*ptr) {
  851. if (*ptr < 'A' && !strchr(goodchars, *ptr ))
  852. return false;
  853. if (*ptr > '}')
  854. return false;
  855. ptr++;
  856. }
  857. return true;
  858. } /* Client_IsValidNick */
  859. /**
  860. * Return pointer to "My_Whowas" structure.
  861. */
  862. GLOBAL WHOWAS *
  863. Client_GetWhowas( void )
  864. {
  865. return My_Whowas;
  866. } /* Client_GetWhowas */
  867. /**
  868. * Return the index of the last used WHOWAS entry.
  869. */
  870. GLOBAL int
  871. Client_GetLastWhowasIndex( void )
  872. {
  873. return Last_Whowas;
  874. } /* Client_GetLastWhowasIndex */
  875. /**
  876. * Get the start time of this client.
  877. * The result is the start time in seconds since 1970-01-01, as reported
  878. * by the C function time(NULL).
  879. */
  880. GLOBAL time_t
  881. Client_StartTime(CLIENT *Client)
  882. {
  883. assert( Client != NULL );
  884. return Client->starttime;
  885. } /* Client_Uptime */
  886. /**
  887. * Reject a client when logging in.
  888. *
  889. * This function is called when a client isn't allowed to connect to this
  890. * server. Possible reasons are bad server password, bad PAM password,
  891. * or that the client is G/K-Line'd.
  892. *
  893. * After calling this function, the client isn't connected any more.
  894. *
  895. * @param Client The client to reject.
  896. * @param Reason The reason why the client has been rejected.
  897. * @param InformClient If true, send the exact reason to the client.
  898. */
  899. GLOBAL void
  900. Client_Reject(CLIENT *Client, const char *Reason, bool InformClient)
  901. {
  902. char info[COMMAND_LEN];
  903. assert(Client != NULL);
  904. assert(Reason != NULL);
  905. if (InformClient)
  906. snprintf(info, sizeof(info), "Access denied: %s", Reason);
  907. else
  908. strcpy(info, "Access denied: Bad password?");
  909. Log(LOG_ERR,
  910. "User \"%s\" rejected (connection %d): %s!",
  911. Client_Mask(Client), Client_Conn(Client), Reason);
  912. Conn_Close(Client_Conn(Client), Reason, info, true);
  913. }
  914. /**
  915. * Introduce a new user or service client in the network.
  916. *
  917. * @param From Remote server introducing the client or NULL (local).
  918. * @param Client New client.
  919. * @param Type Type of the client (CLIENT_USER or CLIENT_SERVICE).
  920. */
  921. GLOBAL void
  922. Client_Introduce(CLIENT *From, CLIENT *Client, int Type)
  923. {
  924. /* Set client type (user or service) */
  925. Client_SetType(Client, Type);
  926. if (From) {
  927. if (Conf_IsService(Conf_GetServer(Client_Conn(From)),
  928. Client_ID(Client)))
  929. Client_SetType(Client, CLIENT_SERVICE);
  930. LogDebug("%s \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
  931. Client_TypeText(Client), Client_Mask(Client),
  932. Client_Modes(Client), Client_ID(From),
  933. Client_ID(Client_Introducer(Client)),
  934. Client_Hops(Client), Client_Hops(Client) > 1 ? "s": "");
  935. } else {
  936. Log(LOG_NOTICE, "%s \"%s\" registered (connection %d).",
  937. Client_TypeText(Client), Client_Mask(Client),
  938. Client_Conn(Client));
  939. Log_ServerNotice('c', "Client connecting: %s (%s@%s) [%s] - %s",
  940. Client_ID(Client), Client_User(Client),
  941. Client_Hostname(Client),
  942. Conn_IPA(Client_Conn(Client)),
  943. Client_TypeText(Client));
  944. }
  945. /* Inform other servers */
  946. IRC_WriteStrServersPrefixFlag_CB(From,
  947. From != NULL ? From : Client_ThisServer(),
  948. '\0', cb_introduceClient, (void *)Client);
  949. } /* Client_Introduce */
  950. static unsigned long
  951. Count( CLIENT_TYPE Type )
  952. {
  953. CLIENT *c;
  954. unsigned long cnt = 0;
  955. c = My_Clients;
  956. while( c )
  957. {
  958. if( c->type == Type ) cnt++;
  959. c = (CLIENT *)c->next;
  960. }
  961. return cnt;
  962. } /* Count */
  963. static unsigned long
  964. MyCount( CLIENT_TYPE Type )
  965. {
  966. CLIENT *c;
  967. unsigned long cnt = 0;
  968. c = My_Clients;
  969. while( c )
  970. {
  971. if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
  972. c = (CLIENT *)c->next;
  973. }
  974. return cnt;
  975. } /* MyCount */
  976. static CLIENT *
  977. New_Client_Struct( void )
  978. {
  979. /* Neue CLIENT-Struktur pre-initialisieren */
  980. CLIENT *c;
  981. c = (CLIENT *)malloc( sizeof( CLIENT ));
  982. if( ! c )
  983. {
  984. Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
  985. return NULL;
  986. }
  987. memset( c, 0, sizeof ( CLIENT ));
  988. c->type = CLIENT_UNKNOWN;
  989. c->conn_id = NONE;
  990. c->oper_by_me = false;
  991. c->hops = -1;
  992. c->token = -1;
  993. c->mytoken = -1;
  994. return c;
  995. } /* New_Client */
  996. static void
  997. Generate_MyToken( CLIENT *Client )
  998. {
  999. CLIENT *c;
  1000. int token;
  1001. c = My_Clients;
  1002. token = 2;
  1003. while( c )
  1004. {
  1005. if( c->mytoken == token )
  1006. {
  1007. /* Das Token wurde bereits vergeben */
  1008. token++;
  1009. c = My_Clients;
  1010. continue;
  1011. }
  1012. else c = (CLIENT *)c->next;
  1013. }
  1014. Client->mytoken = token;
  1015. LogDebug("Assigned token %d to server \"%s\".", token, Client->id);
  1016. } /* Generate_MyToken */
  1017. static void
  1018. Adjust_Counters( CLIENT *Client )
  1019. {
  1020. long count;
  1021. assert( Client != NULL );
  1022. if( Client->type != CLIENT_USER ) return;
  1023. if( Client->conn_id != NONE )
  1024. {
  1025. /* Local connection */
  1026. count = Client_MyUserCount( );
  1027. if( count > My_Max_Users ) My_Max_Users = count;
  1028. }
  1029. count = Client_UserCount( );
  1030. if( count > Max_Users ) Max_Users = count;
  1031. } /* Adjust_Counters */
  1032. /**
  1033. * Register client in My_Whowas structure for further recall by WHOWAS.
  1034. * Note: Only clients that have been connected at least 30 seconds will be
  1035. * registered to prevent automated IRC bots to "destroy" a nice server
  1036. * history database.
  1037. */
  1038. GLOBAL void
  1039. Client_RegisterWhowas( CLIENT *Client )
  1040. {
  1041. int slot;
  1042. time_t now;
  1043. assert( Client != NULL );
  1044. /* Don't register WHOWAS information when "MorePrivacy" is enabled. */
  1045. if (Conf_MorePrivacy)
  1046. return;
  1047. now = time(NULL);
  1048. /* Don't register clients that were connected less than 30 seconds. */
  1049. if( now - Client->starttime < 30 )
  1050. return;
  1051. slot = Last_Whowas + 1;
  1052. if( slot >= MAX_WHOWAS || slot < 0 ) slot = 0;
  1053. #ifdef DEBUG
  1054. Log( LOG_DEBUG, "Saving WHOWAS information to slot %d ...", slot );
  1055. #endif
  1056. My_Whowas[slot].time = now;
  1057. strlcpy( My_Whowas[slot].id, Client_ID( Client ),
  1058. sizeof( My_Whowas[slot].id ));
  1059. strlcpy( My_Whowas[slot].user, Client_User( Client ),
  1060. sizeof( My_Whowas[slot].user ));
  1061. strlcpy( My_Whowas[slot].host, Client_HostnameCloaked( Client ),
  1062. sizeof( My_Whowas[slot].host ));
  1063. strlcpy( My_Whowas[slot].info, Client_Info( Client ),
  1064. sizeof( My_Whowas[slot].info ));
  1065. strlcpy( My_Whowas[slot].server, Client_ID( Client_Introducer( Client )),
  1066. sizeof( My_Whowas[slot].server ));
  1067. Last_Whowas = slot;
  1068. } /* Client_RegisterWhowas */
  1069. GLOBAL const char *
  1070. Client_TypeText(CLIENT *Client)
  1071. {
  1072. assert(Client != NULL);
  1073. switch (Client_Type(Client)) {
  1074. case CLIENT_USER:
  1075. return "User";
  1076. break;
  1077. case CLIENT_SERVICE:
  1078. return "Service";
  1079. break;
  1080. case CLIENT_SERVER:
  1081. return "Server";
  1082. break;
  1083. default:
  1084. return "Client";
  1085. }
  1086. } /* Client_TypeText */
  1087. /**
  1088. * Destroy user or service client.
  1089. */
  1090. static void
  1091. Destroy_UserOrService(CLIENT *Client, const char *Txt, const char *FwdMsg, bool SendQuit)
  1092. {
  1093. if(Client->conn_id != NONE) {
  1094. /* Local (directly connected) client */
  1095. Log(LOG_NOTICE,
  1096. "%s \"%s\" unregistered (connection %d): %s",
  1097. Client_TypeText(Client), Client_Mask(Client),
  1098. Client->conn_id, Txt);
  1099. Log_ServerNotice('c', "Client exiting: %s (%s@%s) [%s]",
  1100. Client_ID(Client), Client_User(Client),
  1101. Client_Hostname(Client), Txt);
  1102. if (SendQuit) {
  1103. /* Inforam all the other servers */
  1104. if (FwdMsg)
  1105. IRC_WriteStrServersPrefix(NULL,
  1106. Client, "QUIT :%s", FwdMsg );
  1107. else
  1108. IRC_WriteStrServersPrefix(NULL,
  1109. Client, "QUIT :");
  1110. }
  1111. } else {
  1112. /* Remote client */
  1113. LogDebug("%s \"%s\" unregistered: %s",
  1114. Client_TypeText(Client), Client_Mask(Client), Txt);
  1115. if(SendQuit) {
  1116. /* Inform all the other servers, but the ones in the
  1117. * direction we got the QUIT from */
  1118. if(FwdMsg)
  1119. IRC_WriteStrServersPrefix(Client_NextHop(Client),
  1120. Client, "QUIT :%s", FwdMsg );
  1121. else
  1122. IRC_WriteStrServersPrefix(Client_NextHop(Client),
  1123. Client, "QUIT :" );
  1124. }
  1125. }
  1126. /* Unregister client from channels */
  1127. Channel_Quit(Client, FwdMsg ? FwdMsg : Client->id);
  1128. /* Register client in My_Whowas structure */
  1129. Client_RegisterWhowas(Client);
  1130. } /* Destroy_UserOrService */
  1131. /**
  1132. * Introduce a new user or service client to a remote server.
  1133. *
  1134. * This function differentiates between RFC1459 and RFC2813 server links and
  1135. * generates the appropriate commands to register the new user or service.
  1136. *
  1137. * @param To The remote server to inform.
  1138. * @param Prefix Prefix for the generated commands.
  1139. * @param data CLIENT structure of the new client.
  1140. */
  1141. static void
  1142. cb_introduceClient(CLIENT *To, CLIENT *Prefix, void *data)
  1143. {
  1144. CLIENT *c = (CLIENT *)data;
  1145. CONN_ID conn;
  1146. char *modes, *user, *host;
  1147. modes = Client_Modes(c);
  1148. user = Client_User(c) ? Client_User(c) : "-";
  1149. host = Client_Hostname(c) ? Client_Hostname(c) : "-";
  1150. conn = Client_Conn(To);
  1151. if (Conn_Options(conn) & CONN_RFC1459) {
  1152. /* RFC 1459 mode: separate NICK and USER commands */
  1153. Conn_WriteStr(conn, "NICK %s :%d", Client_ID(c),
  1154. Client_Hops(c) + 1);
  1155. Conn_WriteStr(conn, ":%s USER %s %s %s :%s",
  1156. Client_ID(c), user, host,
  1157. Client_ID(Client_Introducer(c)), Client_Info(c));
  1158. if (modes[0])
  1159. Conn_WriteStr(conn, ":%s MODE %s +%s",
  1160. Client_ID(c), Client_ID(c), modes);
  1161. } else {
  1162. /* RFC 2813 mode: one combined NICK or SERVICE command */
  1163. if (Client_Type(c) == CLIENT_SERVICE
  1164. && strchr(Client_Flags(To), 'S'))
  1165. IRC_WriteStrClientPrefix(To, Prefix,
  1166. "SERVICE %s %d * +%s %d :%s",
  1167. Client_Mask(c),
  1168. Client_MyToken(Client_Introducer(c)),
  1169. Client_Modes(c), Client_Hops(c) + 1,
  1170. Client_Info(c));
  1171. else
  1172. IRC_WriteStrClientPrefix(To, Prefix,
  1173. "NICK %s %d %s %s %d +%s :%s",
  1174. Client_ID(c), Client_Hops(c) + 1,
  1175. user, host,
  1176. Client_MyToken(Client_Introducer(c)),
  1177. modes, Client_Info(c));
  1178. }
  1179. } /* cb_introduceClient */
  1180. #ifdef DEBUG
  1181. GLOBAL void
  1182. Client_DebugDump(void)
  1183. {
  1184. CLIENT *c;
  1185. Log(LOG_DEBUG, "Client status:");
  1186. c = My_Clients;
  1187. while (c) {
  1188. Log(LOG_DEBUG,
  1189. " - %s: type=%d, host=%s, user=%s, conn=%d, start=%ld, flags=%s",
  1190. Client_ID(c), Client_Type(c), Client_Hostname(c),
  1191. Client_User(c), Client_Conn(c), Client_StartTime(c),
  1192. Client_Flags(c));
  1193. c = (CLIENT *)c->next;
  1194. }
  1195. } /* Client_DumpClients */
  1196. #endif
  1197. /* -eof- */