1 /* nickserv.h - Nick/authentiction service
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of srvx.
6 * srvx 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 2 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 */
27 #define NICKSERV_HANDLE_LEN NICKLEN
30 /* HI_FLAG_* go into handle_info.flags */
31 #define HI_FLAG_OPER_SUSPENDED 0x00000001
32 #define HI_FLAG_USE_PRIVMSG 0x00000002
33 #define HI_FLAG_SUPPORT_HELPER 0x00000004
34 #define HI_FLAG_HELPING 0x00000008
35 #define HI_FLAG_SUSPENDED 0x00000010
36 #define HI_FLAG_MIRC_COLOR 0x00000020
37 #define HI_FLAG_FROZEN 0x00000040
38 #define HI_FLAG_NODELETE 0x00000080
39 #define HI_FLAG_NETWORK_HELPER 0x00000100
40 #define HI_FLAG_BOT 0x00000200
41 #define HI_FLAG_AUTOHIDE 0x00000400
42 #define HI_FLAG_INVI 0x00000800
44 /* Flag characters for the above. First char is LSB, etc. */
45 #define HANDLE_FLAGS "SphgscfnHbxI"
47 /* HI_STYLE_* go into handle_info.userlist_style */
48 #define HI_STYLE_DEF 'd'
49 #define HI_STYLE_ZOOT 'Z'
51 #define HI_DEFAULT_FLAGS (HI_FLAG_MIRC_COLOR)
52 #define HI_DEFAULT_STYLE HI_STYLE_DEF
54 #define HANDLE_FLAGGED(hi, tok) ((hi)->flags & HI_FLAG_##tok)
55 #define HANDLE_SET_FLAG(hi, tok) ((hi)->flags |= HI_FLAG_##tok)
56 #define HANDLE_TOGGLE_FLAG(hi, tok) ((hi)->flags ^= HI_FLAG_##tok)
57 #define HANDLE_CLEAR_FLAG(hi, tok) ((hi)->flags &= ~HI_FLAG_##tok)
59 #define IsSupportHelper(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, SUPPORT_HELPER))
60 #define IsNetworkHelper(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, NETWORK_HELPER))
61 #define IsHelper(user) (IsSupportHelper(user) || IsNetworkHelper(user))
62 #define IsHelping(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, HELPING))
63 #define IsStaff(user) (IsOper(user) || IsSupportHelper(user) || IsNetworkHelper(user))
64 #define IsBot(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, BOT))
65 #define IsInvi(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, INVI))
74 struct handle_cookie {
75 struct handle_info *hi;
77 enum cookie_type type;
78 unsigned long expires;
79 char cookie[COOKIELEN+1];
83 struct handle_note *next;
84 unsigned long expires;
87 char setter[NICKSERV_HANDLE_LEN+1];
92 unsigned long login_time;
93 unsigned long logout_time;
95 const char *quit_reason;
96 struct userNode *user;
97 struct authlogEntry *next;
101 struct nick_info *nicks;
102 struct string_list *masks;
103 struct userNode *users;
104 struct userData *channels;
105 struct handle_cookie *cookie;
106 struct handle_note *notes;
107 struct language *language;
108 struct authlogEntry *authlog;
118 unsigned long registered;
119 unsigned long lastseen;
121 unsigned short flags;
122 unsigned short opserv_level;
123 unsigned short staff_level;
124 unsigned short screen_width;
125 unsigned short table_width;
126 unsigned char userlist_style;
127 unsigned char maxlogins;
128 char passwd[MD5_CRYPT_LENGTH+1];
129 char last_quit_host[USERLEN+HOSTLEN+2];
133 struct handle_info *owner;
134 struct nick_info *next; /* next nick owned by same handle */
135 char nick[NICKLEN+1];
138 struct handle_info_list {
139 unsigned int used, size;
140 struct handle_info **list;
141 char *tag; /* e.g. email address */
144 extern const char *handle_flags;
146 void init_nickserv(const char *nick);
147 struct handle_info *get_handle_info(const char *handle);
148 struct handle_info *smart_get_handle_info(struct userNode *service, struct userNode *user, const char *name);
149 int oper_try_set_access(struct userNode *user, struct userNode *bot, struct handle_info *target, unsigned int new_level);
150 int oper_outranks(struct userNode *user, struct handle_info *hi);
151 struct nick_info *get_nick_info(const char *nick);
152 struct modeNode *find_handle_in_channel(struct chanNode *channel, struct handle_info *handle, struct userNode *except);
153 int nickserv_modify_handle_flags(struct userNode *user, struct userNode *bot, const char *str, unsigned long *add, unsigned long *remove);
154 int oper_has_access(struct userNode *user, struct userNode *bot, unsigned int min_level, unsigned int quiet);
155 int staff_has_access(struct userNode *user, struct userNode *bot, unsigned int min_level, unsigned int quiet);
156 void nickserv_show_oper_accounts(struct userNode *user, struct svccmd *cmd);
157 struct handle_info *checklogin(const char *user, const char *pass, const char *numeric, const char *hostmask, const char *ipmask);
158 char *getfakehost(const char *user);
159 void nickserv_devnull_delete(char *name);
160 void nickserv_devnull_rename(char *oldname, char *newname);
161 char *generate_fakehost(struct handle_info *handle);
162 char *generate_fakeident(struct handle_info *handle, struct userNode *user);
163 void apply_fakehost(struct handle_info *handle, struct userNode *user);
165 /* auth_funcs are called when a user gets a new handle_info. They are
166 * called *after* user->handle_info has been updated. */
167 typedef void (*auth_func_t)(struct userNode *user, struct handle_info *old_handle);
168 void reg_auth_func(auth_func_t func);
170 /* Called just after a handle is renamed. */
171 typedef void (*handle_rename_func_t)(struct handle_info *handle, const char *old_handle);
172 void reg_handle_rename_func(handle_rename_func_t func);
174 /* unreg_funcs are called right before a handle is unregistered.
175 * `user' is the person who caused the handle to be unregistered (either a
176 * client authed to the handle, or an oper). */
177 typedef void (*unreg_func_t)(struct userNode *user, struct handle_info *handle);
178 void reg_unreg_func(unreg_func_t func);
180 /* Called just before a handle is merged */
181 typedef void (*handle_merge_func_t)(struct userNode *user, struct handle_info *handle_to, struct handle_info *handle_from);
182 void reg_handle_merge_func(handle_merge_func_t);
184 /* Called after an allowauth. handle is null if allowauth authorization was
186 typedef void (*allowauth_func_t)(struct userNode *user, struct userNode *target, struct handle_info *handle);
187 void reg_allowauth_func(allowauth_func_t func);
189 /* Called when an auth attempt fails because of a bad password */
190 typedef void (*failpw_func_t)(struct userNode *user, struct handle_info *handle);
191 void reg_failpw_func(failpw_func_t func);