1 /* nickserv.h - Nick/authentiction service
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 #include "hash.h" /* for NICKLEN, etc., and common.h */
26 #include <tre/regex.h> /* for regex in nickserv_config */
29 #define NICKSERV_HANDLE_LEN ACCOUNTLEN
32 /* HI_FLAG_* go into handle_info.flags */
33 #define HI_FLAG_OPER_SUSPENDED 0x00000001
34 #define HI_FLAG_USE_PRIVMSG 0x00000002
35 #define HI_FLAG_SUPPORT_HELPER 0x00000004
36 #define HI_FLAG_HELPING 0x00000008
37 #define HI_FLAG_SUSPENDED 0x00000010
38 #define HI_FLAG_MIRC_COLOR 0x00000020
39 #define HI_FLAG_FROZEN 0x00000040
40 #define HI_FLAG_NODELETE 0x00000080
41 #define HI_FLAG_NETWORK_HELPER 0x00000100
42 #define HI_FLAG_BOT 0x00000200
43 #define HI_FLAG_AUTOHIDE 0x00000400
44 #define HI_FLAG_ADVANCED 0x00000800
45 /* Flag characters for the above. First char is LSB, etc. */
46 #define HANDLE_FLAGS "SphgscfnHbx"
48 /* HI_STYLE_* go into handle_info.userlist_style */
49 #define HI_STYLE_NORMAL 'n'
50 #define HI_STYLE_CLEAN 'c'
51 #define HI_STYLE_ADVANCED 'a'
52 #define HI_STYLE_CLASSIC 'k'
54 #define HI_DEFAULT_FLAGS (HI_FLAG_MIRC_COLOR)
56 /* This is overridden by conf file */
57 #define HI_DEFAULT_STYLE HI_STYLE_NORMAL
59 #define HANDLE_FLAGGED(hi, tok) ((hi)->flags & HI_FLAG_##tok)
60 #define HANDLE_SET_FLAG(hi, tok) ((hi)->flags |= HI_FLAG_##tok)
61 #define HANDLE_TOGGLE_FLAG(hi, tok) ((hi)->flags ^= HI_FLAG_##tok)
62 #define HANDLE_CLEAR_FLAG(hi, tok) ((hi)->flags &= ~HI_FLAG_##tok)
64 #define IsSupportHelper(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, SUPPORT_HELPER))
65 #define IsNetworkHelper(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, NETWORK_HELPER))
66 #define IsHelper(user) (IsSupportHelper(user) || IsNetworkHelper(user))
67 #define IsHelping(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, HELPING))
68 #define IsStaff(user) (IsOper(user) || IsSupportHelper(user) || IsNetworkHelper(user))
69 #define IsBot(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, BOT))
78 struct handle_cookie
{
79 struct handle_info
*hi
;
81 enum cookie_type type
;
83 char cookie
[COOKIELEN
+1];
87 char setter
[NICKSERV_HANDLE_LEN
+1];
93 struct nick_info
*nicks
;
94 struct string_list
*masks
;
95 struct string_list
*sslfps
;
96 struct string_list
*ignores
;
97 struct userNode
*users
;
98 struct userData
*channels
;
99 struct handle_cookie
*cookie
;
100 struct handle_note
*note
;
101 struct language
*language
;
110 unsigned short flags
;
111 unsigned short opserv_level
;
112 unsigned short screen_width
;
113 unsigned short table_width
;
114 unsigned char userlist_style
;
115 unsigned char announcements
;
116 unsigned char maxlogins
;
117 char passwd
[MD5_CRYPT_LENGTH
+1];
118 char last_quit_host
[USERLEN
+HOSTLEN
+2];
122 struct handle_info
*owner
;
123 struct nick_info
*next
; /* next nick owned by same handle */
124 char nick
[NICKLEN
+1];
129 struct handle_info_list
{
130 unsigned int used
, size
;
131 struct handle_info
**list
;
132 char *tag
; /* e.g. email address */
135 extern const char *handle_flags
;
137 enum reclaim_action
{
144 struct nickserv_config
{
145 unsigned int disable_nicks
: 1;
146 unsigned int valid_handle_regex_set
: 1;
147 unsigned int valid_nick_regex_set
: 1;
148 unsigned int valid_fakehost_regex_set
: 1;
149 unsigned int autogag_enabled
: 1;
150 unsigned int email_enabled
: 1;
151 unsigned int email_required
: 1;
152 unsigned int default_hostmask
: 1;
153 unsigned int warn_nick_owned
: 1;
154 unsigned int warn_clone_auth
: 1;
155 unsigned int sync_log
: 1;
156 unsigned int expire_nicks
: 1;
157 unsigned long nicks_per_handle
;
158 unsigned long password_min_length
;
159 unsigned long password_min_digits
;
160 unsigned long password_min_upper
;
161 unsigned long password_min_lower
;
162 unsigned long db_backup_frequency
;
163 unsigned long handle_expire_frequency
;
164 unsigned long autogag_duration
;
165 unsigned long email_visible_level
;
166 unsigned long cookie_timeout
;
167 unsigned long handle_expire_delay
;
168 unsigned long nochan_handle_expire_delay
;
169 unsigned long modoper_level
;
170 unsigned long set_epithet_level
;
171 unsigned long set_title_level
;
172 unsigned long set_fakehost_level
;
173 unsigned long handles_per_email
;
174 unsigned long email_search_level
;
175 unsigned long nick_expire_frequency
;
176 unsigned long nick_expire_delay
;
177 const char *network_name
;
178 const char *titlehost_suffix
;
179 regex_t valid_handle_regex
;
180 regex_t valid_nick_regex
;
181 regex_t valid_fakehost_regex
;
182 dict_t weak_password_dict
;
183 struct policer_params
*auth_policer_params
;
184 enum reclaim_action reclaim_action
;
185 enum reclaim_action auto_reclaim_action
;
186 unsigned long auto_reclaim_delay
;
187 unsigned char default_maxlogins
;
188 unsigned char hard_maxlogins
;
189 unsigned long ounregister_inactive
;
190 unsigned long ounregister_flags
;
191 const char *auto_oper
;
192 const char *auto_admin
;
193 const char *auto_oper_privs
;
194 const char *auto_admin_privs
;
196 struct string_list
*denied_fakehost_words
;
197 unsigned int force_handles_lowercase
;
198 unsigned int ldap_enable
;
200 const char *ldap_uri
;
201 const char *ldap_base
;
202 const char *ldap_dn_fmt
;
203 unsigned int ldap_version
;
204 unsigned int ldap_autocreate
;
206 const char *ldap_admin_dn
;
207 const char *ldap_admin_pass
;
208 const char *ldap_field_account
;
209 const char *ldap_field_password
;
210 const char *ldap_field_email
;
211 const char *ldap_field_oslevel
;
212 struct string_list
*ldap_object_classes
;
213 const char *ldap_oper_group_dn
;
214 unsigned int ldap_oper_group_level
;
215 const char *ldap_field_group_member
;
216 unsigned int ldap_timeout
;
220 void init_nickserv(const char *nick
);
221 struct handle_info
*get_handle_info(const char *handle
);
222 struct handle_info
*smart_get_handle_info(struct userNode
*service
, struct userNode
*user
, const char *name
);
223 int oper_try_set_access(struct userNode
*user
, struct userNode
*bot
, struct handle_info
*target
, unsigned int new_level
);
224 int oper_outranks(struct userNode
*user
, struct handle_info
*hi
);
225 struct nick_info
*get_nick_info(const char *nick
);
226 struct modeNode
*find_handle_in_channel(struct chanNode
*channel
, struct handle_info
*handle
, struct userNode
*except
);
227 int nickserv_modify_handle_flags(struct userNode
*user
, struct userNode
*bot
, const char *str
, unsigned long *add
, unsigned long *remove
);
228 int oper_has_access(struct userNode
*user
, struct userNode
*bot
, unsigned int min_level
, unsigned int quiet
);
229 void nickserv_show_oper_accounts(struct userNode
*user
, struct svccmd
*cmd
);
231 struct handle_info
*get_victim_oper(struct userNode
*user
, const char *target
);
232 struct handle_info
*loc_auth(char *sslfp
, char *handle
, char *password
, char *userhost
);
234 typedef void (*user_mode_func_t
)(struct userNode
*user
, const char *mode_change
, void *extra
);
235 void reg_user_mode_func(user_mode_func_t func
, void *extra
);
236 typedef void (*channel_mode_func_t
)(struct userNode
*who
, struct chanNode
*channel
, char **mode
, unsigned int argc
, void *extra
);
237 void reg_channel_mode_func(channel_mode_func_t func
, void *extra
);
239 /* auth_funcs are called when a user gets a new handle_info. They are
240 * called *after* user->handle_info has been updated. */
241 typedef void (*auth_func_t
)(struct userNode
*user
, struct handle_info
*old_handle
, void *extra
);
242 void reg_auth_func(auth_func_t func
, void *extra
);
244 /* Called just after a handle is renamed. */
245 typedef void (*handle_rename_func_t
)(struct handle_info
*handle
, const char *old_handle
, void *extra
);
246 void reg_handle_rename_func(handle_rename_func_t func
, void *extra
);
248 /* unreg_funcs are called right before a handle is unregistered.
249 * `user' is the person who caused the handle to be unregistered (either a
250 * client authed to the handle, or an oper). */
251 typedef void (*unreg_func_t
)(struct userNode
*user
, struct handle_info
*handle
, void *extra
);
252 void reg_unreg_func(unreg_func_t func
, void *extra
);
254 /* Called just before a handle is merged */
255 typedef void (*handle_merge_func_t
)(struct userNode
*user
, struct handle_info
*handle_to
, struct handle_info
*handle_from
, void *extra
);
256 void reg_handle_merge_func(handle_merge_func_t
, void *extra
);
258 /* Called after an allowauth. handle is null if allowauth authorization was
260 typedef void (*allowauth_func_t
)(struct userNode
*user
, struct userNode
*target
, struct handle_info
*handle
, void *extra
);
261 void reg_allowauth_func(allowauth_func_t func
, void *extra
);
263 /* Called when an auth attempt fails because of a bad password */
264 typedef void (*failpw_func_t
)(struct userNode
*user
, struct handle_info
*handle
, void *extra
);
265 void reg_failpw_func(failpw_func_t func
, void *extra
);
267 void send_func_list(struct userNode
*user
);
269 extern dict_t nickserv_handle_dict
;