5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
24 /* Forward declarations */
25 typedef struct SilcServerEntryStruct *SilcServerEntry;
26 typedef struct SilcClientEntryStruct *SilcClientEntry;
27 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
29 /* Context for holding cache information to periodically purge
36 /* Channel key re-key context. */
39 SilcChannelEntry channel;
41 } *SilcServerChannelRekey;
43 /* Generic rekey context for connections */
45 /* Current sending encryption key, provided for re-key. The `pfs'
46 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
47 unsigned char *send_enc_key;
56 Generic ID list data structure.
58 This structure is included in all ID list entries and it includes data
59 pointers that are common to all ID entries. This structure is always
60 defined to the first field in the ID entries and is used to explicitly
61 cast to this type without first explicitly casting to correct ID entry
62 type. Hence, the ID list entry is casted to this type to get this data
63 from the ID entry (which is usually opaque pointer).
65 Note that some of the fields may be NULL.
69 /* Send and receive symmetric keys */
71 SilcCipher receive_key;
74 SilcServerRekey rekey;
76 /* Hash selected in the SKE protocol, NULL if not needed at all */
81 SilcHmac hmac_receive;
84 SilcPublicKey public_key;
86 long last_receive; /* Time last received data */
87 long last_sent; /* Time last sent data */
88 bool registered; /* Boolean whether connection is registered */
89 } *SilcIDListData, SilcIDListDataStruct;
92 SILC Server entry object.
94 This entry holds information about servers in SILC network. However,
95 contents of this entry is highly dependent of what kind of server we are
96 (normal server or router server) and whether the entry is used as a local
97 list or a global list. These factors dictates the contents of this entry.
99 This entry is defined as follows:
101 Server type List type Contents
102 =======================================================================
103 server local list Server itself
104 server global list NULL
105 router local list All servers is the cell
106 router global list All servers in the SILC network
108 Following short description of the fields:
110 SilcIDListDataStruct data
112 Generic data structure to hold data common to all ID entries.
116 Logical name of the server. There is no limit of the length of the
117 server name. This is usually the same name as defined in DNS.
121 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
126 ID of the server. This includes all the relevant information about
127 the server SILC will ever need. These are also the informations
128 that is broadcasted between servers and routers in the SILC network.
133 Server info (from INFO command) saved temporarily and motd (from
134 MOTD command) saved temporarily.
136 SilcServerEntry router
138 This is a pointer back to the server list. This is the router server
139 where this server is connected to. If this is the router itself and
140 it doesn't have a route this is NULL.
143 SilcCipher receive_key
145 Data sending and receiving keys.
149 A pointer, usually, to the socket list for fast referencing to
150 the data used in connection with this server. This may be anything
151 but as just said, this is usually pointer to the socket connection
155 struct SilcServerEntryStruct {
156 /* Generic data structure. DO NOT add anything before this! */
157 SilcIDListDataStruct data;
165 /* Pointer to the router */
166 SilcServerEntry router;
168 /* Connection data */
173 SILC Channel Client entry structure.
175 This entry used only by the SilcChannelEntry object and it holds
176 information about current clients (ie. users) on channel. Following
177 short description of the fields:
179 SilcClientEntry client
181 Pointer to the client list. This is the client currently on channel.
185 Client's current mode on the channel.
187 SilcChannelEntry channel
189 Back pointer back to channel. As this structure is also used by
190 SilcClientEntry we have this here for fast access to the channel when
191 used by SilcClientEntry.
193 struct SilcChannelClientEntryStruct *client_list
194 struct SilcChannelClientEntryStruct *channel_list
196 List member pointers. This structure is used by channel entry and
197 client entry thus we must have separate list member pointers for
198 them since we are using same entry for both lists (the entry is not
199 duplicated). SilcList requires this.
202 typedef struct SilcChannelClientEntryStruct {
203 SilcClientEntry client;
205 SilcChannelEntry channel;
206 struct SilcChannelClientEntryStruct *client_list;
207 struct SilcChannelClientEntryStruct *channel_list;
208 } *SilcChannelClientEntry;
211 SILC Client entry object.
213 This entry holds information about connected clients ie. users in the SILC
214 network. The contents of this entrt is depended on whether we are normal
215 server or router server and whether the list is a local or global list.
217 This entry is defined as follows:
219 Server type List type Contents
220 =======================================================================
221 server local list All clients in server
222 server global list NULL
223 router local list All clients in cell
224 router global list All clients in SILC
226 Following short description of the fields:
228 SilcIDListDataStruct data
230 Generic data structure to hold data common to all ID entries.
232 unsigned char *nickname
234 The nickname of the client.
238 The name of the server where the client is from. MAy be NULL.
242 Client's usename. This is defined in the following manner:
244 Server type List type Contents
245 ====================================================
246 server local list User's name
247 router local list NULL
248 router global list NULL
250 Router doesn't hold this information since it is not vital data
251 for the router. If this information is needed by the client it is
252 fetched when it is needed.
256 Information about user. This is free information and can be virtually
257 anything. This is defined in following manner:
259 Server type List type Contents
260 ====================================================
261 server local list User's information
262 router local list NULL
263 router global list NULL
265 Router doesn't hold this information since it is not vital data
266 for the router. If this information is needed by the client it is
267 fetched when it is needed.
271 ID of the client. This includes all the information SILC will ever
272 need. Notice that no nickname of the user is saved anywhere. This is
273 beacuse of SilcClientID includes 88 bit hash value of the user's
274 nickname which can be used to track down specific user by their
275 nickname. Nickname is not relevant information that would need to be
280 Client's mode. Client maybe for example server operator or
281 router operator (SILC operator).
285 Time of last time client executed command. We are strict and will
286 not allow any command to be exeucted more than once in about
287 2 seconds. This is result of normal time().
291 Counter to check command bursts. By default, up to 5 commands
292 are allowed before limiting the execution. See command flags
295 SilcServerEntry router
297 This is a pointer to the server list. This is the router server whose
298 cell this client is coming from. This is used to route messages to
303 List of channels this client has joined.
307 A pointer, usually, to the socket list for fast referencing to
308 the data used in connection with this client. This may be anything
309 but as just said, this is usually pointer to the socket connection
313 struct SilcClientEntryStruct {
314 /* Generic data structure. DO NOT add anything before this! */
315 SilcIDListDataStruct data;
317 unsigned char *nickname;
327 /* Pointer to the router */
328 SilcServerEntry router;
330 /* List of channels client has joined to */
333 /* Connection data */
338 SILC Channel entry object.
340 This entry holds information about channels in SILC network. The contents
341 of this entry is depended on whether we are normal server or router server
342 and whether the list is a local or global list.
344 This entry is defined as follows:
346 Server type List type Contents
347 =======================================================================
348 server local list All channels in server
349 server global list NULL
350 router local list All channels in cell
351 router global list All channels in SILC
353 Following short description of the fields:
357 Logical name of the channel.
361 Current mode of the channel. See lib/silccore/silcchannel.h for
366 ID of the channel. This includes all the information SILC will ever
371 Boolean value to tell whether there are users outside this server
372 on this channel. This is set to TRUE if router sends message to
373 the server that there are users outside your server on your
374 channel as well. This way server knows that messages needs to be
375 sent to the router for further routing. If this is a normal
376 server and this channel is not created on this server this field
377 is always TRUE. If this server is a router this field is ignored.
381 Current topic of the channel.
385 Default cipher of the channel. If this is NULL then server picks
386 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
390 Default hmac of the channel. If this is NULL then server picks
391 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
393 SilcPublicKey founder_key
394 SilcAuthMethod founder_method
395 unsigned char *founder_passwd
396 uint32 founder_passwd_len
398 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
399 the founder's public key, authentication method and the password
400 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
401 then the `founder_passwd' is NULL.
403 SilcServerEntry router
405 This is a pointer to the server list. This is the router server
406 whose cell this channel belongs to. This is used to route messages
409 SilcCipher channel_key
411 The key of the channel (the cipher actually).
416 Raw key data of the channel key.
418 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
420 Current initial vector. Initial vector is received always along
421 with the channel packet. By default this is filled with NULL.
427 SilcServerChannelRekey rekey
429 Channel key re-key context.
432 struct SilcChannelEntryStruct {
441 SilcPublicKey founder_key;
442 SilcAuthMethod founder_method;
443 unsigned char *founder_passwd;
444 uint32 founder_passwd_len;
447 unsigned char *passphrase;
451 /* List of users on channel */
454 /* Pointer to the router */
455 SilcServerEntry router;
458 SilcCipher channel_key;
461 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
464 SilcServerChannelRekey rekey;
470 As for remainder these lists are defined as follows:
472 Entry list (cache) Server type List type Contents
473 =======================================================================
474 servers server local list Server itself
475 servers server global list NULL
476 servers router local list All servers in cell
477 servers router global list All servers in SILC
479 clients server local list All clients in server
480 clients server global list NULL
481 clients router local list All clients in cell
482 clients router global list All clients in SILC
484 channels server local list All channels in server
485 channels server global list NULL
486 channels router local list All channels in cell
487 channels router global list All channels in SILC
489 As seen on the list normal server never defines a global list. This is
490 because of normal server don't know anything about anything global data,
491 they get it from the router if and when they need it. Routers, on the
492 other hand, always define local and global lists because routers really
493 know all the relevant data in the SILC network.
495 This object is used as local and global list by the server/router.
496 Above table shows how this is defined on different conditions.
498 This object holds pointers to the ID cache system. Every ID cache entry
499 has a specific context pointer to allocated entry (server, client or
503 typedef struct SilcIDListStruct {
506 SilcIDCache channels;
510 ID Entry for Unknown connections.
512 This is used during authentication phases where we still don't know
513 what kind of connection remote connection is, hence, we will use this
514 structure instead until we know what type of connection remote end is.
516 This is not in any list. This is always individually allocated and
521 /* Generic data structure. DO NOT add anything before this! */
522 SilcIDListDataStruct data;
526 void silc_idlist_add_data(void *entry, SilcIDListData idata);
527 void silc_idlist_del_data(void *entry);
528 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
530 silc_idlist_add_server(SilcIDList id_list,
531 char *server_name, int server_type,
532 SilcServerID *id, SilcServerEntry router,
535 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
536 SilcIDCacheEntry *ret_entry);
538 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
539 SilcIDCacheEntry *ret_entry);
541 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
542 int port, SilcIDCacheEntry *ret_entry);
544 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
545 SilcServerID *new_id);
546 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
548 silc_idlist_add_client(SilcIDList id_list, unsigned char *nickname,
549 uint32 nickname_len, char *username,
550 char *userinfo, SilcClientID *id,
551 SilcServerEntry router, void *connection);
552 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
553 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
555 SilcClientEntry **clients,
556 uint32 *clients_count);
557 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
559 SilcClientEntry **clients,
560 uint32 *clients_count);
562 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
563 SilcIDCacheEntry *ret_entry);
565 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
566 SilcClientID *new_id);
567 void silc_idlist_client_destructor(SilcIDCache cache,
568 SilcIDCacheEntry entry);
570 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
571 SilcChannelID *id, SilcServerEntry router,
572 SilcCipher channel_key, SilcHmac hmac);
573 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
575 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
576 SilcIDCacheEntry *ret_entry);
578 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
579 SilcIDCacheEntry *ret_entry);
581 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
582 SilcChannelID *new_id);
584 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
585 uint32 *channels_count);