Merged silc_1_0_branch to trunk.
[silc.git] / apps / silcd / server_util.h
1 /*
2
3   server_util.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2003 Pekka Riikonen
8
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; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef SERVER_UTIL_H
21 #define SERVER_UTIL_H
22
23 /* This function removes all client entries that are originated from
24    `router' and are owned by `entry'.  `router' and `entry' can be same
25    too.  If `server_signoff' is TRUE then SERVER_SIGNOFF notify is
26    distributed to our local clients. */
27 bool silc_server_remove_clients_by_server(SilcServer server,
28                                           SilcServerEntry router,
29                                           SilcServerEntry entry,
30                                           bool server_signoff);
31
32 /* Updates the clients that are originated from the `from' to be originated
33    from the `to'. If the `resolve_real_server' is TRUE then this will
34    attempt to figure out which clients really are originated from the
35    `from' and which are originated from a server that we have connection
36    to, when we've acting as backup router. If it is FALSE the `to' will
37    be the new source.  If `from' is NULL then all clients (except locally
38    connected) are updated `to'. */
39 void silc_server_update_clients_by_server(SilcServer server,
40                                           SilcServerEntry from,
41                                           SilcServerEntry to,
42                                           bool resolve_real_server);
43
44 /* Updates servers that are from `from' to be originated from `to'.  This
45    will also update the server's connection to `to's connection. */
46 void silc_server_update_servers_by_server(SilcServer server,
47                                           SilcServerEntry from,
48                                           SilcServerEntry to);
49
50 /* Toggles the enabled/disabled status of local server connections.  Packets
51    can be sent to the servers when `toggle_enabled' is TRUE and will be
52    dropped if `toggle_enabled' is FALSE, after this function is called. */
53 void silc_server_local_servers_toggle_enabled(SilcServer server,
54                                               bool toggle_enabled);
55
56 /* Removes servers that are originated from the `from'.  The server
57    entry is deleted in this function.  If `remove_clients' is TRUE then
58    all clients originated from the server are removed too, and server
59    signoff is sent.  Note that this does not remove the `from'.  This
60    also does not remove locally connected servers. */
61 void silc_server_remove_servers_by_server(SilcServer server,
62                                           SilcServerEntry from,
63                                           bool remove_clients);
64
65 /* Removes channels that are from `from. */
66 void silc_server_remove_channels_by_server(SilcServer server,
67                                            SilcServerEntry from);
68
69 /* Updates channels that are from `from' to be originated from `to'.  */
70 void silc_server_update_channels_by_server(SilcServer server,
71                                            SilcServerEntry from,
72                                            SilcServerEntry to);
73
74 /* Checks whether given channel has global users.  If it does this returns
75    TRUE and FALSE if there is only locally connected clients on the channel. */
76 bool silc_server_channel_has_global(SilcChannelEntry channel);
77
78 /* Checks whether given channel has locally connected users.  If it does this
79    returns TRUE and FALSE if there is not one locally connected client. */
80 bool silc_server_channel_has_local(SilcChannelEntry channel);
81
82 /* This function removes the channel and all users on the channel, unless
83    the channel is permanent.  In this case the channel is disabled but all
84    users are removed from the channel.  Returns TRUE if the channel is
85    destroyed totally, and FALSE if it is permanent and remains. */
86 bool silc_server_channel_delete(SilcServer server,
87                                 SilcChannelEntry channel);
88
89 /* Returns TRUE if the given client is on the channel.  FALSE if not.
90    This works because we assure that the user list on the channel is
91    always in up to date thus we can only check the channel list from
92    `client' which is faster than checking the user list from `channel'. */
93 bool silc_server_client_on_channel(SilcClientEntry client,
94                                    SilcChannelEntry channel,
95                                    SilcChannelClientEntry *chl);
96
97 /* Checks string for bad characters and returns TRUE if they are found. */
98 bool silc_server_name_bad_chars(const char *name, SilcUInt32 name_len);
99 bool silc_server_name_bad_chchars(const char *name, SilcUInt32 name_len);
100
101 /* Modifies the `nick' if it includes bad characters and returns new
102    allocated nickname that does not include bad characters. */
103 char *silc_server_name_modify_bad(const char *name, SilcUInt32 name_len);
104
105 /* Find number of sockets by IP address indicated by `ip'. Returns 0 if
106    socket connections with the IP address does not exist. */
107 SilcUInt32 silc_server_num_sockets_by_ip(SilcServer server, const char *ip,
108                                          SilcSocketType type);
109
110 /* Find number of sockets by IP address indicated by remote host, indicated
111    by `ip' or `hostname', `port', and `type'.  Returns 0 if socket connections
112    does not exist. If `ip' is provided then `hostname' is ignored. */
113 SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server,
114                                              const char *ip,
115                                              const char *hostname,
116                                              SilcUInt16 port,
117                                              SilcSocketType type);
118
119 /* Finds locally cached public key by the public key received in the SKE.
120    If we have it locally cached then we trust it and will use it in the
121    authentication protocol.  Returns the locally cached public key or NULL
122    if we do not find the public key.  */
123 SilcPublicKey silc_server_find_public_key(SilcServer server,
124                                           SilcHashTable local_public_keys,
125                                           SilcPublicKey remote_public_key);
126
127 /* This returns the first public key from the table of public keys.  This
128    is used only in cases where single public key exists in the table and
129    we want to get a pointer to it.  For public key tables that has multiple
130    keys in it the silc_server_find_public_key must be used. */
131 SilcPublicKey silc_server_get_public_key(SilcServer server,
132                                          SilcHashTable local_public_keys);
133
134 /* Check whether the connection `sock' is allowed to connect to us.  This
135    checks for example whether there is too much connections for this host,
136    and required version for the host etc. */
137 bool silc_server_connection_allowed(SilcServer server,
138                                     SilcSocketConnection sock,
139                                     SilcSocketType type,
140                                     SilcServerConfigConnParams *global,
141                                     SilcServerConfigConnParams *params,
142                                     SilcSKE ske);
143
144 /* Checks that client has rights to add or remove channel modes. If any
145    of the checks fails FALSE is returned. */
146 bool silc_server_check_cmode_rights(SilcServer server,
147                                     SilcChannelEntry channel,
148                                     SilcChannelClientEntry client,
149                                     SilcUInt32 mode);
150
151 /* Check that the client has rights to change its user mode.  Returns
152    FALSE if setting some mode is not allowed. */
153 bool silc_server_check_umode_rights(SilcServer server,
154                                     SilcClientEntry client,
155                                     SilcUInt32 mode);
156
157 /* This function is used to send the notify packets and motd to the
158    incoming client connection. */
159 void silc_server_send_connect_notifys(SilcServer server,
160                                       SilcSocketConnection sock,
161                                       SilcClientEntry client);
162
163 /* Kill the client indicated by `remote_client' sending KILLED notify
164    to the client, to all channels client has joined and to primary
165    router if needed.  The killed client is also removed from all channels. */
166 void silc_server_kill_client(SilcServer server,
167                              SilcClientEntry remote_client,
168                              const char *comment,
169                              void *killer_id,
170                              SilcIdType killer_id_type);
171
172 /* This function checks whether the `client' nickname is being watched
173    by someone, and notifies the watcher of the notify change of notify
174    type indicated by `notify'. */
175 bool silc_server_check_watcher_list(SilcServer server,
176                                     SilcClientEntry client,
177                                     const char *new_nick,
178                                     SilcNotifyType notify);
179
180 /* Remove the `client' from watcher list. After calling this the `client'
181    is not watching any nicknames. */
182 bool silc_server_del_from_watcher_list(SilcServer server,
183                                        SilcClientEntry client);
184
185 /* Force the client indicated by `chl' to change the channel user mode
186    on channel indicated by `channel' to `forced_mode'. */
187 bool silc_server_force_cumode_change(SilcServer server,
188                                      SilcSocketConnection sock,
189                                      SilcChannelEntry channel,
190                                      SilcChannelClientEntry chl,
191                                      SilcUInt32 forced_mode);
192
193 /* Find active socket connection by the IP address and port indicated by
194    `ip' and `port', and socket connection type of `type'. */
195 SilcSocketConnection
196 silc_server_find_socket_by_host(SilcServer server,
197                                 SilcSocketType type,
198                                 const char *ip, SilcUInt16 port);
199
200 /* This function can be used to match the invite and ban lists. */
201 bool silc_server_inviteban_match(SilcServer server, SilcHashTable list,
202                                  SilcUInt8 type, void *check);
203
204 /* Process invite or ban information */
205 void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
206                                    SilcUInt8 action, SilcArgumentPayload args);
207
208 /* Destructor for invite or ban list entrys */
209 void silc_server_inviteban_destruct(void *key, void *context,
210                                     void *user_context);
211
212 /* Creates connections according to configuration. */
213 void silc_server_create_connections(SilcServer server);
214
215
216 /* Processes a channel public key, either adds or removes it. */
217 SilcStatus
218 silc_server_process_channel_pk(SilcServer server,
219                                SilcChannelEntry channel,
220                                SilcUInt32 type, const unsigned char *pk,
221                                SilcUInt32 pk_len);
222
223 /* Returns the channel public keys as Argument List payload. */
224 SilcBuffer silc_server_get_channel_pk_list(SilcServer server,
225                                            SilcChannelEntry channel,
226                                            bool announce,
227                                            bool delete);
228
229 /* Sets the channel public keys into channel from the list of public keys. */
230 SilcStatus silc_server_set_channel_pk_list(SilcServer server,
231                                            SilcSocketConnection sender,
232                                            SilcChannelEntry channel,
233                                            const unsigned char *pklist,
234                                            SilcUInt32 pklist_len);
235
236 /* Verifies the Authentication Payload `auth' with one of the public keys
237    on the `channel' public key list. */
238 bool silc_server_verify_channel_auth(SilcServer server,
239                                      SilcChannelEntry channel,
240                                      SilcClientID *client_id,
241                                      const unsigned char *auth,
242                                      SilcUInt32 auth_len);
243
244 #endif /* SERVER_UTIL_H */