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
33 SilcSchedule schedule;
36 /* Channel key re-key context. */
39 SilcChannelEntry channel;
42 } *SilcServerChannelRekey;
44 /* Generic rekey context for connections */
46 /* Current sending encryption key, provided for re-key. The `pfs'
47 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
48 unsigned char *send_enc_key;
56 /* ID List Entry status type and all the types. */
57 typedef uint8 SilcIDListStatus;
58 #define SILC_IDLIST_STATUS_NONE 0x00 /* No status */
59 #define SILC_IDLIST_STATUS_REGISTERED 0x01 /* Entry is registered */
60 #define SILC_IDLIST_STATUS_RESOLVED 0x02 /* Entry info is resolved */
61 #define SILC_IDLIST_STATUS_RESOLVING 0x04 /* Entry is being resolved
62 with WHOIS or IDENTIFY */
63 #define SILC_IDLIST_STATUS_DISABLED 0x08 /* Entry is disabled */
66 Generic ID list data structure.
68 This structure is included in all ID list entries and it includes data
69 pointers that are common to all ID entries. This structure is always
70 defined to the first field in the ID entries and is used to explicitly
71 type cast to this type without first explicitly casting to correct ID
72 entry type. Hence, the ID list entry is type casted to this type to
73 get this data from the ID entry (which is usually opaque pointer).
75 Note that some of the fields may be NULL.
79 /* Send and receive symmetric keys */
81 SilcCipher receive_key;
85 SilcHmac hmac_receive;
87 /* Packet sequence numbers */
91 /* Hash selected in the SKE protocol, NULL if not needed at all */
95 SilcPublicKey public_key;
98 SilcServerRekey rekey;
100 long last_receive; /* Time last received data */
101 long last_sent; /* Time last sent data */
103 unsigned long created; /* Time when entry was created */
105 SilcIDListStatus status; /* Status mask of the entry */
106 } *SilcIDListData, SilcIDListDataStruct;
109 SILC Server entry object.
111 This entry holds information about servers in SILC network. However,
112 contents of this entry is highly dependent of what kind of server we are
113 (normal server or router server) and whether the entry is used as a local
114 list or a global list. These factors dictates the contents of this entry.
116 This entry is defined as follows:
118 Server type List type Contents
119 =======================================================================
120 server local list Server itself
121 server global list NULL
122 router local list All servers is the cell
123 router global list All servers in the SILC network
125 Following short description of the fields:
127 SilcIDListDataStruct data
129 Generic data structure to hold data common to all ID entries.
133 Logical name of the server. There is no limit of the length of the
134 server name. This is usually the same name as defined in DNS.
138 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
143 ID of the server. This includes all the relevant information about
144 the server SILC will ever need. These are also the informations
145 that is broadcasted between servers and routers in the SILC network.
150 Server info (from INFO command) saved temporarily and motd (from
151 MOTD command) saved temporarily.
153 SilcServerEntry router
155 This is a pointer back to the server list. This is the router server
156 where this server is connected to. If this is the router itself and
157 it doesn't have a route this is NULL.
160 SilcCipher receive_key
162 Data sending and receiving keys.
166 A pointer, usually, to the socket list for fast referencing to
167 the data used in connection with this server. This may be anything
168 but as just said, this is usually pointer to the socket connection
172 struct SilcServerEntryStruct {
173 /* Generic data structure. DO NOT add anything before this! */
174 SilcIDListDataStruct data;
182 /* Pointer to the router */
183 SilcServerEntry router;
185 /* Connection data */
190 SILC Channel Client entry structure.
192 This entry used only by the SilcChannelEntry object and it holds
193 information about current clients (ie. users) on channel. Following
194 short description of the fields:
196 SilcClientEntry client
198 Pointer to the client list. This is the client currently on channel.
202 Client's current mode on the channel.
204 SilcChannelEntry channel
206 Back pointer back to channel. As this structure is also used by
207 SilcClientEntry we have this here for fast access to the channel when
208 used by SilcClientEntry.
211 typedef struct SilcChannelClientEntryStruct {
212 SilcClientEntry client;
214 SilcChannelEntry channel;
215 } *SilcChannelClientEntry;
218 SILC Client entry object.
220 This entry holds information about connected clients ie. users in the SILC
221 network. The contents of this entrt is depended on whether we are normal
222 server or router server and whether the list is a local or global list.
224 This entry is defined as follows:
226 Server type List type Contents
227 =======================================================================
228 server local list All clients in server
229 server global list NULL
230 router local list All clients in cell
231 router global list All clients in SILC
233 Following short description of the fields:
235 SilcIDListDataStruct data
237 Generic data structure to hold data common to all ID entries.
239 unsigned char *nickname
241 The nickname of the client.
245 The name of the server where the client is from. MAy be NULL.
249 Client's usename. This is defined in the following manner:
251 Server type List type Contents
252 ====================================================
253 server local list User's name
254 router local list NULL
255 router global list NULL
257 Router doesn't hold this information since it is not vital data
258 for the router. If this information is needed by the client it is
259 fetched when it is needed.
263 Information about user. This is free information and can be virtually
264 anything. This is defined in following manner:
266 Server type List type Contents
267 ====================================================
268 server local list User's information
269 router local list NULL
270 router global list NULL
272 Router doesn't hold this information since it is not vital data
273 for the router. If this information is needed by the client it is
274 fetched when it is needed.
278 ID of the client. This includes all the information SILC will ever
279 need. Notice that no nickname of the user is saved anywhere. This is
280 beacuse of SilcClientID includes 88 bit hash value of the user's
281 nickname which can be used to track down specific user by their
282 nickname. Nickname is not relevant information that would need to be
287 Client's mode. Client maybe for example server operator or
288 router operator (SILC operator).
292 Time of last time client executed command. We are strict and will
293 not allow any command to be exeucted more than once in about
294 2 seconds. This is result of normal time().
298 Counter to check command bursts. By default, up to 5 commands
299 are allowed before limiting the execution. See command flags
302 SilcServerEntry router
304 This is a pointer to the server list. This is the router server whose
305 cell this client is coming from. This is used to route messages to
308 SilcHashTable channels;
310 All the channels this client has joined. The context saved in the
311 hash table shares memory with the channel entrys `user_list' hash
316 A pointer, usually, to the socket list for fast referencing to
317 the data used in connection with this client. This may be anything
318 but as just said, this is usually pointer to the socket connection
321 uint16 resolve_cmd_ident
323 Command identifier for the entry when the entry's data.status
324 is SILC_IDLIST_STATUS_RESOLVING. If this entry is asked to be
325 resolved when the status is set then the resolver may attach to
326 this command identifier and handle the process after the resolving
330 struct SilcClientEntryStruct {
331 /* Generic data structure. DO NOT add anything before this! */
332 SilcIDListDataStruct data;
334 unsigned char *nickname;
344 /* Pointer to the router */
345 SilcServerEntry router;
347 /* All channels this client has joined */
348 SilcHashTable channels;
350 /* Connection data */
353 /* data.status is RESOLVING and this includes the resolving command
355 uint16 resolve_cmd_ident;
359 SILC Channel entry object.
361 This entry holds information about channels in SILC network. The contents
362 of this entry is depended on whether we are normal server or router server
363 and whether the list is a local or global list.
365 This entry is defined as follows:
367 Server type List type Contents
368 =======================================================================
369 server local list All channels in server
370 server global list NULL
371 router local list All channels in cell
372 router global list All channels in SILC
374 Following short description of the fields:
378 Logical name of the channel.
382 Current mode of the channel. See lib/silccore/silcchannel.h for
387 ID of the channel. This includes all the information SILC will ever
392 Boolean value to tell whether there are users outside this server
393 on this channel. This is set to TRUE if router sends message to
394 the server that there are users outside your server on your
395 channel as well. This way server knows that messages needs to be
396 sent to the router for further routing. If this is a normal
397 server and this channel is not created on this server this field
398 is always TRUE. If this server is a router this field is ignored.
402 Current topic of the channel.
406 Default cipher of the channel. If this is NULL then server picks
407 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
411 Default hmac of the channel. If this is NULL then server picks
412 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
414 SilcPublicKey founder_key
415 SilcAuthMethod founder_method
416 unsigned char *founder_passwd
417 uint32 founder_passwd_len
419 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
420 the founder's public key, authentication method and the password
421 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
422 then the `founder_passwd' is NULL.
424 SilcHashTable user_list
426 All users joined on this channel. Note that the context saved to
427 this entry shares memory with the client entrys `channels' hash
430 SilcServerEntry router
432 This is a pointer to the server list. This is the router server
433 whose cell this channel belongs to. This is used to route messages
436 SilcCipher channel_key
438 The key of the channel (the cipher actually).
443 Raw key data of the channel key.
445 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
447 Current initial vector. Initial vector is received always along
448 with the channel packet. By default this is filled with NULL.
454 SilcServerChannelRekey rekey
456 Channel key re-key context.
459 struct SilcChannelEntryStruct {
468 SilcPublicKey founder_key;
469 SilcAuthMethod founder_method;
470 unsigned char *founder_passwd;
471 uint32 founder_passwd_len;
474 unsigned char *passphrase;
478 /* All users on this channel */
479 SilcHashTable user_list;
481 /* Pointer to the router */
482 SilcServerEntry router;
485 SilcCipher channel_key;
488 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
491 SilcServerChannelRekey rekey;
493 unsigned long created;
499 As for remainder these lists are defined as follows:
501 Entry list (cache) Server type List type Contents
502 =======================================================================
503 servers server local list Server itself
504 servers server global list NULL
505 servers router local list All servers in cell
506 servers router global list All servers in SILC
508 clients server local list All clients in server
509 clients server global list NULL
510 clients router local list All clients in cell
511 clients router global list All clients in SILC
513 channels server local list All channels in server
514 channels server global list NULL
515 channels router local list All channels in cell
516 channels router global list All channels in SILC
518 As seen on the list normal server never defines a global list. This is
519 because of normal server don't know anything about anything global data,
520 they get it from the router if and when they need it. Routers, on the
521 other hand, always define local and global lists because routers really
522 know all the relevant data in the SILC network.
524 This object is used as local and global list by the server/router.
525 Above table shows how this is defined on different conditions.
527 This object holds pointers to the ID cache system. Every ID cache entry
528 has a specific context pointer to allocated entry (server, client or
532 typedef struct SilcIDListStruct {
535 SilcIDCache channels;
539 ID Entry for Unknown connections.
541 This is used during authentication phases where we still don't know
542 what kind of connection remote connection is, hence, we will use this
543 structure instead until we know what type of connection remote end is.
545 This is not in any list. This is always individually allocated and
550 /* Generic data structure. DO NOT add anything before this! */
551 SilcIDListDataStruct data;
555 void silc_idlist_add_data(void *entry, SilcIDListData idata);
556 void silc_idlist_del_data(void *entry);
557 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
559 silc_idlist_add_server(SilcIDList id_list,
560 char *server_name, int server_type,
561 SilcServerID *id, SilcServerEntry router,
564 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
565 bool registered, SilcIDCacheEntry *ret_entry);
567 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
568 bool registered, SilcIDCacheEntry *ret_entry);
570 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
571 int port, bool registered,
572 SilcIDCacheEntry *ret_entry);
574 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
575 SilcServerID *new_id);
576 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
578 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
579 char *userinfo, SilcClientID *id,
580 SilcServerEntry router, void *connection);
581 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
582 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
584 SilcClientEntry **clients,
585 uint32 *clients_count);
586 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
588 SilcClientEntry **clients,
589 uint32 *clients_count);
591 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
592 bool registered, SilcIDCacheEntry *ret_entry);
594 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
595 SilcClientID *new_id);
596 void silc_idlist_client_destructor(SilcIDCache cache,
597 SilcIDCacheEntry entry);
599 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
600 SilcChannelID *id, SilcServerEntry router,
601 SilcCipher channel_key, SilcHmac hmac);
602 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
604 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
605 SilcIDCacheEntry *ret_entry);
607 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
608 SilcIDCacheEntry *ret_entry);
610 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
611 SilcChannelID *new_id);
613 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
614 uint32 *channels_count);