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;
96 unsigned char fingerprint[20];
99 SilcServerRekey rekey;
101 long last_receive; /* Time last received data */
102 long last_sent; /* Time last sent data */
104 unsigned long created; /* Time when entry was created */
106 SilcIDListStatus status; /* Status mask of the entry */
107 } *SilcIDListData, SilcIDListDataStruct;
110 SILC Server entry object.
112 This entry holds information about servers in SILC network. However,
113 contents of this entry is highly dependent of what kind of server we are
114 (normal server or router server) and whether the entry is used as a local
115 list or a global list. These factors dictates the contents of this entry.
117 This entry is defined as follows:
119 Server type List type Contents
120 =======================================================================
121 server local list Server itself
122 server global list NULL
123 router local list All servers is the cell
124 router global list All servers in the SILC network
126 Following short description of the fields:
128 SilcIDListDataStruct data
130 Generic data structure to hold data common to all ID entries.
134 Logical name of the server. There is no limit of the length of the
135 server name. This is usually the same name as defined in DNS.
139 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
144 ID of the server. This includes all the relevant information about
145 the server SILC will ever need. These are also the informations
146 that is broadcasted between servers and routers in the SILC network.
151 Server info (from INFO command) saved temporarily and motd (from
152 MOTD command) saved temporarily.
154 SilcServerEntry router
156 This is a pointer back to the server list. This is the router server
157 where this server is connected to. If this is the router itself and
158 it doesn't have a route this is NULL.
161 SilcCipher receive_key
163 Data sending and receiving keys.
167 A pointer, usually, to the socket list for fast referencing to
168 the data used in connection with this server. This may be anything
169 but as just said, this is usually pointer to the socket connection
173 struct SilcServerEntryStruct {
174 /* Generic data structure. DO NOT add anything before this! */
175 SilcIDListDataStruct data;
183 /* Pointer to the router */
184 SilcServerEntry router;
186 /* Connection data */
191 SILC Channel Client entry structure.
193 This entry used only by the SilcChannelEntry object and it holds
194 information about current clients (ie. users) on channel. Following
195 short description of the fields:
197 SilcClientEntry client
199 Pointer to the client list. This is the client currently on channel.
203 Client's current mode on the channel.
205 SilcChannelEntry channel
207 Back pointer back to channel. As this structure is also used by
208 SilcClientEntry we have this here for fast access to the channel when
209 used by SilcClientEntry.
212 typedef struct SilcChannelClientEntryStruct {
213 SilcClientEntry client;
215 SilcChannelEntry channel;
216 } *SilcChannelClientEntry;
219 SILC Client entry object.
221 This entry holds information about connected clients ie. users in the SILC
222 network. The contents of this entrt is depended on whether we are normal
223 server or router server and whether the list is a local or global list.
225 This entry is defined as follows:
227 Server type List type Contents
228 =======================================================================
229 server local list All clients in server
230 server global list NULL
231 router local list All clients in cell
232 router global list All clients in SILC
234 Following short description of the fields:
236 SilcIDListDataStruct data
238 Generic data structure to hold data common to all ID entries.
240 unsigned char *nickname
242 The nickname of the client.
246 The name of the server where the client is from. MAy be NULL.
250 Client's usename. This is defined in the following manner:
252 Server type List type Contents
253 ====================================================
254 server local list User's name
255 router local list NULL
256 router global list NULL
258 Router doesn't hold this information since it is not vital data
259 for the router. If this information is needed by the client it is
260 fetched when it is needed.
264 Information about user. This is free information and can be virtually
265 anything. This is defined in following manner:
267 Server type List type Contents
268 ====================================================
269 server local list User's information
270 router local list NULL
271 router global list NULL
273 Router doesn't hold this information since it is not vital data
274 for the router. If this information is needed by the client it is
275 fetched when it is needed.
279 ID of the client. This includes all the information SILC will ever
280 need. Notice that no nickname of the user is saved anywhere. This is
281 beacuse of SilcClientID includes 88 bit hash value of the user's
282 nickname which can be used to track down specific user by their
283 nickname. Nickname is not relevant information that would need to be
288 Client's mode. Client maybe for example server operator or
289 router operator (SILC operator).
293 Time of last time client executed command. We are strict and will
294 not allow any command to be exeucted more than once in about
295 2 seconds. This is result of normal time().
299 Counter to check command bursts. By default, up to 5 commands
300 are allowed before limiting the execution. See command flags
303 SilcServerEntry router
305 This is a pointer to the server list. This is the router server whose
306 cell this client is coming from. This is used to route messages to
309 SilcHashTable channels;
311 All the channels this client has joined. The context saved in the
312 hash table shares memory with the channel entrys `user_list' hash
317 A pointer, usually, to the socket list for fast referencing to
318 the data used in connection with this client. This may be anything
319 but as just said, this is usually pointer to the socket connection
322 uint16 resolve_cmd_ident
324 Command identifier for the entry when the entry's data.status
325 is SILC_IDLIST_STATUS_RESOLVING. If this entry is asked to be
326 resolved when the status is set then the resolver may attach to
327 this command identifier and handle the process after the resolving
331 struct SilcClientEntryStruct {
332 /* Generic data structure. DO NOT add anything before this! */
333 SilcIDListDataStruct data;
335 unsigned char *nickname;
345 /* Pointer to the router */
346 SilcServerEntry router;
348 /* All channels this client has joined */
349 SilcHashTable channels;
351 /* Connection data */
354 /* data.status is RESOLVING and this includes the resolving command
356 uint16 resolve_cmd_ident;
360 SILC Channel entry object.
362 This entry holds information about channels in SILC network. The contents
363 of this entry is depended on whether we are normal server or router server
364 and whether the list is a local or global list.
366 This entry is defined as follows:
368 Server type List type Contents
369 =======================================================================
370 server local list All channels in server
371 server global list NULL
372 router local list All channels in cell
373 router global list All channels in SILC
375 Following short description of the fields:
379 Logical name of the channel.
383 Current mode of the channel. See lib/silccore/silcchannel.h for
388 ID of the channel. This includes all the information SILC will ever
393 Boolean value to tell whether there are users outside this server
394 on this channel. This is set to TRUE if router sends message to
395 the server that there are users outside your server on your
396 channel as well. This way server knows that messages needs to be
397 sent to the router for further routing. If this is a normal
398 server and this channel is not created on this server this field
399 is always TRUE. If this server is a router this field is ignored.
403 Current topic of the channel.
407 Default cipher of the channel. If this is NULL then server picks
408 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
412 Default hmac of the channel. If this is NULL then server picks
413 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
415 SilcPublicKey founder_key
416 SilcAuthMethod founder_method
417 unsigned char *founder_passwd
418 uint32 founder_passwd_len
420 If the SILC_CMODE_FOUNDER_AUTH has been set then these will include
421 the founder's public key, authentication method and the password
422 if the method is SILC_AUTH_PASSWORD. If it is SILC_AUTH_PUBLIC_KEY
423 then the `founder_passwd' is NULL.
425 SilcHashTable user_list
427 All users joined on this channel. Note that the context saved to
428 this entry shares memory with the client entrys `channels' hash
431 SilcServerEntry router
433 This is a pointer to the server list. This is the router server
434 whose cell this channel belongs to. This is used to route messages
437 SilcCipher channel_key
439 The key of the channel (the cipher actually).
444 Raw key data of the channel key.
446 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
448 Current initial vector. Initial vector is received always along
449 with the channel packet. By default this is filled with NULL.
455 SilcServerChannelRekey rekey
457 Channel key re-key context.
460 struct SilcChannelEntryStruct {
469 SilcPublicKey founder_key;
470 SilcAuthMethod founder_method;
471 unsigned char *founder_passwd;
472 uint32 founder_passwd_len;
475 unsigned char *passphrase;
479 /* All users on this channel */
480 SilcHashTable user_list;
482 /* Pointer to the router */
483 SilcServerEntry router;
486 SilcCipher channel_key;
489 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
492 SilcServerChannelRekey rekey;
494 unsigned long created;
501 As for remainder these lists are defined as follows:
503 Entry list (cache) Server type List type Contents
504 =======================================================================
505 servers server local list Server itself
506 servers server global list NULL
507 servers router local list All servers in cell
508 servers router global list All servers in SILC
510 clients server local list All clients in server
511 clients server global list NULL
512 clients router local list All clients in cell
513 clients router global list All clients in SILC
515 channels server local list All channels in server
516 channels server global list NULL
517 channels router local list All channels in cell
518 channels router global list All channels in SILC
520 As seen on the list normal server never defines a global list. This is
521 because of normal server don't know anything about anything global data,
522 they get it from the router if and when they need it. Routers, on the
523 other hand, always define local and global lists because routers really
524 know all the relevant data in the SILC network.
526 This object is used as local and global list by the server/router.
527 Above table shows how this is defined on different conditions.
529 This object holds pointers to the ID cache system. Every ID cache entry
530 has a specific context pointer to allocated entry (server, client or
534 typedef struct SilcIDListStruct {
537 SilcIDCache channels;
541 ID Entry for Unknown connections.
543 This is used during authentication phases where we still don't know
544 what kind of connection remote connection is, hence, we will use this
545 structure instead until we know what type of connection remote end is.
547 This is not in any list. This is always individually allocated and
552 /* Generic data structure. DO NOT add anything before this! */
553 SilcIDListDataStruct data;
557 void silc_idlist_add_data(void *entry, SilcIDListData idata);
558 void silc_idlist_del_data(void *entry);
559 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
561 silc_idlist_add_server(SilcIDList id_list,
562 char *server_name, int server_type,
563 SilcServerID *id, SilcServerEntry router,
566 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
567 bool registered, SilcIDCacheEntry *ret_entry);
569 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
570 bool registered, SilcIDCacheEntry *ret_entry);
572 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
573 int port, bool registered,
574 SilcIDCacheEntry *ret_entry);
576 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
577 SilcServerID *new_id);
578 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
580 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
581 char *userinfo, SilcClientID *id,
582 SilcServerEntry router, void *connection);
583 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
584 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
586 SilcClientEntry **clients,
587 uint32 *clients_count);
588 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
590 SilcClientEntry **clients,
591 uint32 *clients_count);
593 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
594 bool registered, SilcIDCacheEntry *ret_entry);
596 silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id,
597 SilcClientID *new_id);
598 void silc_idlist_client_destructor(SilcIDCache cache,
599 SilcIDCacheEntry entry);
601 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
602 SilcChannelID *id, SilcServerEntry router,
603 SilcCipher channel_key, SilcHmac hmac);
604 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
606 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
607 SilcIDCacheEntry *ret_entry);
609 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
610 SilcIDCacheEntry *ret_entry);
612 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
613 SilcChannelID *new_id);
615 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
616 uint32 *channels_count);