1 |
/* NickServ-related structures. |
2 |
* |
3 |
* IRC Services is copyright (c) 1996-2009 Andrew Church. |
4 |
* E-mail: <achurch@achurch.org> |
5 |
* Parts written by Andrew Kempe and others. |
6 |
* This program is free but copyrighted software; see the file GPL.txt for |
7 |
* details. |
8 |
*/ |
9 |
|
10 |
#ifndef NICKSERV_H |
11 |
#define NICKSERV_H |
12 |
|
13 |
#ifndef ENCRYPT_H |
14 |
# include "../../encrypt.h" |
15 |
#endif |
16 |
#ifndef MEMOSERV_H |
17 |
# include "../memoserv/memoserv.h" |
18 |
#endif |
19 |
|
20 |
/*************************************************************************/ |
21 |
/*************************************************************************/ |
22 |
|
23 |
/* Data structure for a single nickname. */ |
24 |
|
25 |
struct nickinfo_ { |
26 |
NickInfo *next, *prev; |
27 |
int usecount; |
28 |
|
29 |
char nick[NICKMAX]; |
30 |
|
31 |
int16 status; /* See NS_* below */ |
32 |
char *last_usermask; /* Last user@host mask (uses fakehost if avail.) */ |
33 |
char *last_realmask; /* Last user@realhost (not fakehost) mask seen */ |
34 |
char *last_realname; |
35 |
char *last_quit; |
36 |
time_t time_registered; |
37 |
time_t last_seen; |
38 |
|
39 |
uint32 nickgroup; /* ID of nick group for this nick */ |
40 |
|
41 |
uint32 id_stamp; /* Services stamp of user who last ID'd for nick */ |
42 |
|
43 |
/* Online-only information: */ |
44 |
|
45 |
User *user; /* User using this nick, NULL if not online */ |
46 |
int16 authstat; /* Authorization status; see NA_* below */ |
47 |
int bad_passwords; /* # of bad passwords for nick since last good one */ |
48 |
}; |
49 |
|
50 |
/*************************************************************************/ |
51 |
|
52 |
/* Data for a group of nicks. */ |
53 |
|
54 |
struct nickgroupinfo_ { |
55 |
NickGroupInfo *next, *prev; |
56 |
int usecount; |
57 |
|
58 |
uint32 id; |
59 |
nickname_t *nicks; /* Array of nicks */ |
60 |
uint16 nicks_count; /* Number of nicks in this nick group */ |
61 |
uint16 mainnick; /* Index of "main" nick (for chan access lists etc) */ |
62 |
|
63 |
Password pass; |
64 |
char *url; |
65 |
char *email; |
66 |
char *last_email; /* Previous (authenticated) E-mail address */ |
67 |
char *info; |
68 |
|
69 |
int32 flags; /* See NF_* below */ |
70 |
int16 os_priv; /* OperServ privilege level; see NP_* below */ |
71 |
|
72 |
int32 authcode; /* Authentication code (used by mail-auth module) */ |
73 |
time_t authset; /* Time authentication code was set */ |
74 |
int16 authreason; /* Reason auth. code was set; see NICKAUTH_* below */ |
75 |
|
76 |
char suspend_who[NICKMAX]; /* Who suspended this nickname */ |
77 |
char *suspend_reason; /* Reason for suspension */ |
78 |
time_t suspend_time; /* Time nick was suspended */ |
79 |
time_t suspend_expires; /* Time suspension expires, 0 for no expiry */ |
80 |
|
81 |
int16 language; /* Language selected by nickname owner (LANG_*) */ |
82 |
int16 timezone; /* Offset from UTC, in minutes */ |
83 |
int16 channelmax; /* Maximum number of registered channels allowed */ |
84 |
|
85 |
char **access; /* Array of access masks */ |
86 |
int16 access_count; /* # of entries */ |
87 |
|
88 |
char **ajoin; /* Array of autojoin channel */ |
89 |
int16 ajoin_count; /* # of entries */ |
90 |
|
91 |
char **ignore; /* Array of memo ignore entries */ |
92 |
int16 ignore_count; /* # of entries */ |
93 |
|
94 |
MemoInfo memos; |
95 |
|
96 |
/* Online-only info: */ |
97 |
|
98 |
channame_t *channels; /* Array of names of channels currently registered */ |
99 |
int16 channels_count; /* Number of channels currently registered */ |
100 |
User **id_users; /* Users who have identified for this group (array) */ |
101 |
int id_users_count; |
102 |
time_t last_sendauth; /* Time of last SENDAUTH (mail-auth module) */ |
103 |
int bad_auths; /* Number of bad AUTH commands for this group */ |
104 |
}; |
105 |
|
106 |
/*************************************************************************/ |
107 |
|
108 |
/* Nickname status flags: */ |
109 |
#define NS_VERBOTEN 0x0002 /* Nick may not be registered or used */ |
110 |
#define NS_NOEXPIRE 0x0004 /* Nick never expires */ |
111 |
#define NS_PERMANENT 0x0006 /* All permanent flags */ |
112 |
/* The following flags are temporary: */ |
113 |
#define NS_KILL_HELD 0x8000 /* Nick is being held after a kill */ |
114 |
#define NS_GUESTED 0x4000 /* SVSNICK has been sent but nick has not |
115 |
* yet changed. An enforcer will be |
116 |
* introduced when it does change. */ |
117 |
#define NS_TEMPORARY 0xC000 /* All temporary flags */ |
118 |
|
119 |
|
120 |
/* Nickname authorization flags: */ |
121 |
#define NA_IDENTIFIED 0x0001 /* User has IDENTIFY'd */ |
122 |
#define NA_IDENT_NOMAIL 0x0002 /* User has identified, but hasn't set an |
123 |
* E-mail address and one is required |
124 |
* (in this case we don't allow privs |
125 |
* except for SET EMAIL on the nick) */ |
126 |
#define NA_RECOGNIZED 0x0004 /* User is recognized as nick owner */ |
127 |
|
128 |
|
129 |
/* Nickgroup setting flags: */ |
130 |
#define NF_KILLPROTECT 0x00000001 /* Kill others who take this nick */ |
131 |
#define NF_SECURE 0x00000002 /* Don't recognize unless IDENTIFY'd */ |
132 |
#define NF_MEMO_HARDMAX 0x00000008 /* Don't allow user to change memo limit */ |
133 |
#define NF_MEMO_SIGNON 0x00000010 /* Notify of memos at signon and un-away */ |
134 |
#define NF_MEMO_RECEIVE 0x00000020 /* Notify of new memos when sent */ |
135 |
#define NF_PRIVATE 0x00000040 /* Don't show in LIST to non-servadmins */ |
136 |
#define NF_HIDE_EMAIL 0x00000080 /* Don't show E-mail in INFO */ |
137 |
#define NF_HIDE_MASK 0x00000100 /* Don't show last seen address in INFO */ |
138 |
#define NF_HIDE_QUIT 0x00000200 /* Don't show last quit message in INFO */ |
139 |
#define NF_KILL_QUICK 0x00000400 /* Kill in 20 seconds instead of 60 */ |
140 |
#define NF_KILL_IMMED 0x00000800 /* Kill immediately instead of in 60 sec */ |
141 |
#define NF_MEMO_FWD 0x00001000 /* Forward memos to E-mail address */ |
142 |
#define NF_MEMO_FWDCOPY 0x00002000 /* Save copy of forwarded memos */ |
143 |
#define NF_SUSPENDED 0x00004000 /* Nickgroup is suspended */ |
144 |
#define NF_NOOP 0x00008000 /* Do not add to channel access lists */ |
145 |
|
146 |
#define NF_ALLFLAGS 0x0000FFFB /* All flags */ |
147 |
|
148 |
#define NF_NOGROUP 0x00000004 /* Used by database/version4 during load */ |
149 |
|
150 |
|
151 |
/* Nickgroup OperServ privilege levels: */ |
152 |
#define NP_SERVOPER 0x1000 |
153 |
#define NP_SERVADMIN 0x2000 |
154 |
|
155 |
|
156 |
/* Maximum number of nicks we can record for a nick group: */ |
157 |
#define MAX_NICKCOUNT 32767 |
158 |
|
159 |
/* Maximum number of access entries: */ |
160 |
#define MAX_NICK_ACCESS 32767 |
161 |
|
162 |
/* Maximum number of channels we can record: */ |
163 |
#define MAX_CHANNELCOUNT 32767 |
164 |
/* Value indicating "no limit" */ |
165 |
#define CHANMAX_UNLIMITED -2 |
166 |
/* Value indicating "default limit" (as set in configuration file) */ |
167 |
#define CHANMAX_DEFAULT -1 |
168 |
|
169 |
/* Value indicating "no time zone set, use local default" */ |
170 |
#define TIMEZONE_DEFAULT 0x7FFF |
171 |
|
172 |
/* Used when we can't retrieve the NickGroupInfo record for a nick, to |
173 |
* prevent the nick from being registered. */ |
174 |
#define NICKGROUPINFO_INVALID ((NickGroupInfo *)PTR_INVALID) |
175 |
|
176 |
/* Authentication code reasons: */ |
177 |
#define NICKAUTH_MIN NICKAUTH_REGISTER |
178 |
#define NICKAUTH_REGISTER 1 /* Newly registered */ |
179 |
#define NICKAUTH_SET_EMAIL 2 /* E-mail address changed */ |
180 |
#define NICKAUTH_SETAUTH 3 /* SETAUTH command used */ |
181 |
#define NICKAUTH_REAUTH 4 /* REAUTH command used */ |
182 |
#define NICKAUTH_MAX NICKAUTH_REAUTH |
183 |
|
184 |
/*************************************************************************/ |
185 |
|
186 |
/* Macros for checking whether a user is recognized or has identified for |
187 |
* their nickname, by either NickInfo or User structure. */ |
188 |
|
189 |
#define nick_recognized(ni) ((ni) && ((ni)->authstat & NA_RECOGNIZED)) |
190 |
#define user_recognized(u) nick_recognized((u)->ni) |
191 |
|
192 |
#define nick_identified(ni) ((ni) && ((ni)->authstat & NA_IDENTIFIED)) |
193 |
#define user_identified(u) nick_identified((u)->ni) |
194 |
|
195 |
#define nick_id_or_rec(ni) \ |
196 |
((ni) && ((ni)->authstat & (NA_IDENTIFIED|NA_RECOGNIZED))) |
197 |
#define user_id_or_rec(u) nick_id_or_rec((u)->ni) |
198 |
|
199 |
#define nick_ident_nomail(ni) ((ni) && ((ni)->authstat & NA_IDENT_NOMAIL)) |
200 |
#define user_ident_nomail(u) nick_ident_nomail((u)->ni) |
201 |
|
202 |
|
203 |
/* Is the given nickgroup unauthenticated? (Currently, this means that the |
204 |
* nickgroup has an authcode set from something other than REAUTH.) */ |
205 |
|
206 |
#define ngi_unauthed(ngi) \ |
207 |
((ngi) && (ngi)->authcode && ((ngi)->authreason != NICKAUTH_REAUTH)) |
208 |
|
209 |
|
210 |
/* Does the given user have a valid NickGroupInfo? */ |
211 |
|
212 |
#define valid_ngi(u) ((u) && ((u)->ngi) && ((u)->ngi != NICKGROUPINFO_INVALID)) |
213 |
|
214 |
|
215 |
/* Macro to retrieve the main nick for a given NickGroupInfo. */ |
216 |
|
217 |
#define ngi_mainnick(ngi) ((ngi)->nicks[(ngi)->mainnick]) |
218 |
|
219 |
/*************************************************************************/ |
220 |
/*************************************************************************/ |
221 |
|
222 |
/* Prototypes for exported functions and variables. */ |
223 |
|
224 |
E char *s_NickServ; |
225 |
|
226 |
E NickInfo *add_nickinfo(NickInfo *ni); |
227 |
E void del_nickinfo(NickInfo *ni); |
228 |
E NickInfo *get_nickinfo(const char *nick); |
229 |
E NickInfo *put_nickinfo(NickInfo *ni); |
230 |
E NickInfo *first_nickinfo(void); |
231 |
E NickInfo *next_nickinfo(void); |
232 |
E NickGroupInfo *add_nickgroupinfo(NickGroupInfo *ngi); |
233 |
E void del_nickgroupinfo(NickGroupInfo *ngi); |
234 |
E NickGroupInfo *get_nickgroupinfo(uint32 id); |
235 |
E NickGroupInfo *put_nickgroupinfo(NickGroupInfo *ngi); |
236 |
E NickGroupInfo *first_nickgroupinfo(void); |
237 |
E NickGroupInfo *next_nickgroupinfo(void); |
238 |
|
239 |
#ifdef STANDALONE_NICKSERV /* see util.c */ |
240 |
# define E2 static |
241 |
#else |
242 |
# define E2 extern |
243 |
#endif |
244 |
E2 NickInfo *new_nickinfo(void); |
245 |
E2 void free_nickinfo(NickInfo *ni); |
246 |
E2 NickGroupInfo *new_nickgroupinfo(const char *seed); |
247 |
E2 void free_nickgroupinfo(NickGroupInfo *ngi); |
248 |
#undef E2 |
249 |
|
250 |
E NickInfo *get_nickinfo_noexpire(const char *nick); |
251 |
|
252 |
#define get_ngi(ni) _get_ngi((ni), __FILE__, __LINE__) |
253 |
#define check_ngi(ni) (put_nickgroupinfo(get_ngi((ni))) != NULL) |
254 |
#define get_ngi_id(id) _get_ngi_id((id), __FILE__, __LINE__) |
255 |
#define check_ngi_id(id) (put_nickgroupinfo(get_ngi_id((id))) != NULL) |
256 |
E NickGroupInfo *_get_ngi(const NickInfo *ni, const char *file, int line); |
257 |
E NickGroupInfo *_get_ngi_id(uint32 id, const char *file, int line); |
258 |
E int has_identified_nick(const User *u, uint32 group); |
259 |
|
260 |
/*************************************************************************/ |
261 |
|
262 |
#endif /* NICKSERV_H */ |
263 |
|
264 |
/* |
265 |
* Local variables: |
266 |
* c-file-style: "stroustrup" |
267 |
* c-file-offsets: ((case-label . *) (statement-case-intro . *)) |
268 |
* indent-tabs-mode: nil |
269 |
* End: |
270 |
* |
271 |
* vim: expandtab shiftwidth=4: |
272 |
*/ |