added LOC Support with privilege exchange and privilege class interface
[srvx.git] / src / nickserv.h
1 /* nickserv.h - Nick/authentiction service
2  * Copyright 2000-2004 srvx Development Team
3  *
4  * This file is part of srvx.
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #ifndef _nickserv_h
22 #define _nickserv_h
23
24 #include "hash.h"   /* for NICKLEN, etc., and common.h */
25 struct svccmd;
26
27 #define NICKSERV_HANDLE_LEN NICKLEN
28 #define COOKIELEN 10
29
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 /* Flag characters for the above.  First char is LSB, etc. */
43 #define HANDLE_FLAGS "SphgscfnHbx"
44
45 /* HI_STYLE_* go into handle_info.userlist_style */
46 #define HI_STYLE_DEF    'd'
47 #define HI_STYLE_ZOOT   'Z'
48
49 #define HI_DEFAULT_FLAGS       (HI_FLAG_MIRC_COLOR)
50 #define HI_DEFAULT_STYLE       HI_STYLE_DEF
51
52 #define HANDLE_FLAGGED(hi, tok) ((hi)->flags & HI_FLAG_##tok)
53 #define HANDLE_SET_FLAG(hi, tok) ((hi)->flags |= HI_FLAG_##tok)
54 #define HANDLE_TOGGLE_FLAG(hi, tok) ((hi)->flags ^= HI_FLAG_##tok)
55 #define HANDLE_CLEAR_FLAG(hi, tok) ((hi)->flags &= ~HI_FLAG_##tok)
56
57 #define IsSupportHelper(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, SUPPORT_HELPER))
58 #define IsNetworkHelper(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, NETWORK_HELPER))
59 #define IsHelper(user) (IsSupportHelper(user) || IsNetworkHelper(user))
60 #define IsHelping(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, HELPING))
61 #define IsStaff(user) (IsOper(user) || IsSupportHelper(user) || IsNetworkHelper(user))
62 #define IsBot(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, BOT))
63
64 enum cookie_type {
65     ACTIVATION,
66     PASSWORD_CHANGE,
67     EMAIL_CHANGE,
68     ALLOWAUTH
69 };
70
71 struct handle_cookie {
72     struct handle_info *hi;
73     char *data;
74     enum cookie_type type;
75     unsigned long expires;
76     char cookie[COOKIELEN+1];
77 };
78
79 struct handle_note {
80     struct handle_note *next;
81     unsigned long expires;
82     unsigned long set;
83     int id;
84     char setter[NICKSERV_HANDLE_LEN+1];
85     char note[1];
86 };
87
88 struct handle_info {
89     struct nick_info *nicks;
90     struct string_list *masks;
91     struct userNode *users;
92     struct userData *channels;
93     struct handle_cookie *cookie;
94     struct handle_note *notes;
95     struct language *language;
96     char *website;
97     char *devnull;
98     char *email_addr;
99     char *epithet;
100     char *infoline;
101     char *handle;
102     char *fakehost;
103     char *fakeident;
104     unsigned long id;
105     unsigned long registered;
106     unsigned long lastseen;
107     int karma;
108     unsigned short flags;
109     unsigned short opserv_level;
110     unsigned short screen_width;
111     unsigned short table_width;
112     unsigned char userlist_style;
113     unsigned char maxlogins;
114     char passwd[MD5_CRYPT_LENGTH+1];
115     char last_quit_host[USERLEN+HOSTLEN+2];
116 };
117
118 struct nick_info {
119     struct handle_info *owner;
120     struct nick_info *next; /* next nick owned by same handle */
121     char nick[NICKLEN+1];
122 };
123
124 struct handle_info_list {
125     unsigned int used, size;
126     struct handle_info **list;
127     char *tag; /* e.g. email address */
128 };
129
130 extern const char *handle_flags;
131
132 void init_nickserv(const char *nick);
133 struct handle_info *get_handle_info(const char *handle);
134 struct handle_info *smart_get_handle_info(struct userNode *service, struct userNode *user, const char *name);
135 int oper_try_set_access(struct userNode *user, struct userNode *bot, struct handle_info *target, unsigned int new_level);
136 int oper_outranks(struct userNode *user, struct handle_info *hi);
137 struct nick_info *get_nick_info(const char *nick);
138 struct modeNode *find_handle_in_channel(struct chanNode *channel, struct handle_info *handle, struct userNode *except);
139 int nickserv_modify_handle_flags(struct userNode *user, struct userNode *bot, const char *str, unsigned long *add, unsigned long *remove);
140 int oper_has_access(struct userNode *user, struct userNode *bot, unsigned int min_level, unsigned int quiet);
141 void nickserv_show_oper_accounts(struct userNode *user, struct svccmd *cmd);
142 struct handle_info *checklogin(const char *user, const char *pass, const char *numeric, const char *hostmask);
143 char *getfakehost(const char *user);
144 void nickserv_devnull_delete(char *name);
145 void nickserv_devnull_rename(char *oldname, char *newname);
146
147 /* auth_funcs are called when a user gets a new handle_info.  They are
148  * called *after* user->handle_info has been updated.  */
149 typedef void (*auth_func_t)(struct userNode *user, struct handle_info *old_handle);
150 void reg_auth_func(auth_func_t func);
151
152 /* Called just after a handle is renamed. */
153 typedef void (*handle_rename_func_t)(struct handle_info *handle, const char *old_handle);
154 void reg_handle_rename_func(handle_rename_func_t func);
155
156 /* unreg_funcs are called right before a handle is unregistered.
157  * `user' is the person who caused the handle to be unregistered (either a
158  * client authed to the handle, or an oper). */
159 typedef void (*unreg_func_t)(struct userNode *user, struct handle_info *handle);
160 void reg_unreg_func(unreg_func_t func);
161
162 /* Called just before a handle is merged */
163 typedef void (*handle_merge_func_t)(struct userNode *user, struct handle_info *handle_to, struct handle_info *handle_from);
164 void reg_handle_merge_func(handle_merge_func_t);
165
166 /* Called after an allowauth. handle is null if allowauth authorization was
167  * removed */
168 typedef void (*allowauth_func_t)(struct userNode *user, struct userNode *target, struct handle_info *handle);
169 void reg_allowauth_func(allowauth_func_t func);
170
171 /* Called when an auth attempt fails because of a bad password */
172 typedef void (*failpw_func_t)(struct userNode *user, struct handle_info *handle);
173 void reg_failpw_func(failpw_func_t func);
174
175 #endif