Initial import (again)
[srvx.git] / src / nickserv.h
1 /* nickserv.h - Nick/authentiction service
2  * Copyright 2000-2004 srvx Development Team
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.  Important limitations are
8  * listed in the COPYING file that accompanies this software.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, email srvx-maintainers@srvx.net.
17  */
18
19 #ifndef _nickserv_h
20 #define _nickserv_h
21
22 #include "hash.h"   /* for NICKLEN, etc., and common.h */
23 struct svccmd;
24
25 #define NICKSERV_HANDLE_LEN NICKLEN
26 #define COOKIELEN 10
27
28 /* HI_FLAG_* go into handle_info.flags */
29 #define HI_FLAG_OPER_SUSPENDED 0x00000001
30 #define HI_FLAG_USE_PRIVMSG    0x00000002
31 #define HI_FLAG_SUPPORT_HELPER 0x00000004
32 #define HI_FLAG_HELPING        0x00000008
33 #define HI_FLAG_SUSPENDED      0x00000010
34 #define HI_FLAG_MIRC_COLOR     0x00000020
35 #define HI_FLAG_FROZEN         0x00000040
36 #define HI_FLAG_NODELETE       0x00000080
37 #define HI_FLAG_NETWORK_HELPER 0x00000100
38 #define HI_FLAG_BOT            0x00000200
39 /* Flag characters for the above.  First char is LSB, etc. */
40 #define HANDLE_FLAGS "SphgscfnHb"
41
42 /* HI_STYLE_* go into handle_info.userlist_style */
43 #define HI_STYLE_DEF           'd'
44 #define HI_STYLE_ZOOT          'Z'
45
46 #define HI_DEFAULT_FLAGS       (HI_FLAG_MIRC_COLOR)
47 #define HI_DEFAULT_STYLE       HI_STYLE_DEF
48
49 #define HANDLE_FLAGGED(hi, tok) ((hi)->flags & HI_FLAG_##tok)
50 #define HANDLE_SET_FLAG(hi, tok) ((hi)->flags |= HI_FLAG_##tok)
51 #define HANDLE_TOGGLE_FLAG(hi, tok) ((hi)->flags ^= HI_FLAG_##tok)
52 #define HANDLE_CLEAR_FLAG(hi, tok) ((hi)->flags &= ~HI_FLAG_##tok)
53
54 #define IsSupportHelper(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, SUPPORT_HELPER))
55 #define IsNetworkHelper(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, NETWORK_HELPER))
56 #define IsHelper(user) (IsSupportHelper(user) || IsNetworkHelper(user))
57 #define IsHelping(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, HELPING))
58 #define IsStaff(user) (IsOper(user) || IsSupportHelper(user) || IsNetworkHelper(user))
59 #define IsBot(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, BOT))
60
61 enum cookie_type {
62     ACTIVATION,
63     PASSWORD_CHANGE,
64     EMAIL_CHANGE,
65     ALLOWAUTH
66 };
67
68 struct handle_cookie {
69     struct handle_info *hi;
70     char *data;
71     enum cookie_type type;
72     time_t expires;
73     char cookie[COOKIELEN+1];
74 };
75
76 struct handle_info {
77     struct nick_info *nicks;
78     struct string_list *masks;
79     struct userNode *users;
80     struct userData *channels;
81     struct handle_cookie *cookie;
82     struct language *language;
83     char *email_addr;
84     char *epithet;
85     char *infoline;
86     char *handle;
87 #ifdef WITH_PROTOCOL_BAHAMUT
88     unsigned long id;
89 #endif
90     time_t registered;
91     time_t lastseen;
92     unsigned short flags;
93     unsigned short opserv_level;
94     unsigned short screen_width;
95     unsigned short table_width;
96     unsigned char userlist_style;
97     unsigned char announcements;
98     unsigned char maxlogins;
99     char passwd[MD5_CRYPT_LENGTH+1];
100     char last_quit_host[USERLEN+HOSTLEN+2];
101 };
102
103 struct nick_info {
104     struct handle_info *owner;
105     struct nick_info *next; /* next nick owned by same handle */
106     char nick[NICKLEN+1];
107 };
108
109 struct handle_info_list {
110     unsigned int used, size;
111     struct handle_info **list;
112     char *tag; /* e.g. email address */
113 };
114
115 extern const char *handle_flags;
116
117 void init_nickserv(const char *nick);
118 struct handle_info *get_handle_info(const char *handle);
119 struct handle_info *smart_get_handle_info(struct userNode *service, struct userNode *user, const char *name);
120 int oper_try_set_access(struct userNode *user, struct userNode *bot, struct handle_info *target, unsigned int new_level);
121 int oper_outranks(struct userNode *user, struct handle_info *hi);
122 struct nick_info *get_nick_info(const char *nick);
123 struct modeNode *find_handle_in_channel(struct chanNode *channel, struct handle_info *handle, struct userNode *except);
124 int nickserv_modify_handle_flags(struct userNode *user, struct userNode *bot, const char *str, unsigned long *add, unsigned long *remove);
125 int oper_has_access(struct userNode *user, struct userNode *bot, unsigned int min_level, unsigned int quiet);
126 void nickserv_show_oper_accounts(struct userNode *user, struct svccmd *cmd);
127
128 /* auth_funcs are called when a user gets a new handle_info.  They are
129  * called *after* user->handle_info has been updated.  */
130 typedef void (*auth_func_t)(struct userNode *user, struct handle_info *old_handle);
131 void reg_auth_func(auth_func_t func);
132
133 /* Called just after a handle is renamed. */
134 typedef void (*handle_rename_func_t)(struct handle_info *handle, const char *old_handle);
135 void reg_handle_rename_func(handle_rename_func_t func);
136
137 /* unreg_funcs are called right before a handle is unregistered.
138  * `user' is the person who caused the handle to be unregistered (either a
139  * client authed to the handle, or an oper). */
140 typedef void (*unreg_func_t)(struct userNode *user, struct handle_info *handle);
141 void reg_unreg_func(unreg_func_t func);
142
143 /* Called just before a handle is merged */
144 typedef void (*handle_merge_func_t)(struct userNode *user, struct handle_info *handle_to, struct handle_info *handle_from);
145 void reg_handle_merge_func(handle_merge_func_t);
146
147 /* Called after an allowauth. handle is null if allowauth authorization was
148  * removed */
149 typedef void (*allowauth_func_t)(struct userNode *user, struct userNode *target, struct handle_info *handle);
150 void reg_allowauth_func(allowauth_func_t func);
151
152 /* Called when an auth attempt fails because of a bad password */
153 typedef void (*failpw_func_t)(struct userNode *user, struct handle_info *handle);
154 void reg_failpw_func(failpw_func_t func);
155
156 #endif