/[cvs]/eggdrop1.9/src/tcluser.c
ViewVC logotype

Contents of /eggdrop1.9/src/tcluser.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.49 - (show annotations) (download) (as text)
Tue Feb 25 06:52:19 2003 UTC (16 years, 9 months ago) by stdarg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.48: +1 -1 lines
File MIME type: text/x-chdr
FILE REMOVED
* Well, I think Tcl is finally removed from the core (except for detection/configuration).

1 /*
2 * tcluser.c --
3 *
4 * Tcl stubs for the user-record-oriented commands
5 */
6 /*
7 * Copyright (C) 1997 Robey Pointer
8 * Copyright (C) 1999, 2000, 2001, 2002, 2003 Eggheads Development Team
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25 #ifndef lint
26 static const char rcsid[] = "$Id: tcluser.c,v 1.48 2003/02/15 05:04:58 wcc Exp $";
27 #endif
28
29 #include "main.h"
30 #include "users.h"
31 #include "chan.h"
32 #include "flags.h" /* FR_*, FLAGS_*, flags_*, :-P */
33 #include "chanprog.h" /* reload */
34 #include "userrec.h" /* count_users, u_pass_match, deluser,
35 delhost_by_handle, write_userfile,
36 change_handle */
37
38 extern struct userrec *userlist;
39 extern int default_flags, dcc_total, ignore_time;
40 extern struct dcc_t *dcc;
41 extern char myname[];
42 extern time_t now;
43
44 #ifndef MAKING_MODS
45 extern struct dcc_table DCC_BOT;
46 #endif /* MAKING_MODS */
47
48 static int script_countusers()
49 {
50 return count_users(userlist);
51 }
52
53 static int script_validuser(char *handle)
54 {
55 struct userrec *u;
56
57 u = get_user_by_handle(userlist, handle);
58 if (u) return(1);
59 return(0);
60 }
61
62 static struct userrec *script_finduser(char *nick_user_host)
63 {
64 return get_user_by_host(nick_user_host);
65 }
66
67 static int script_passwd_ok(struct userrec *u, char *trypass)
68 {
69 if (u && u_pass_match(u, trypass)) return(1);
70 return(0);
71 }
72
73 /* client_data will be NULL for chattr, non-NULL for botattr. */
74 /* I combined them since there are only minor differences. */
75 static char *script_chattr_botattr(void *client_data, struct userrec *u, char *changes, char *chan)
76 {
77 static char work[128]; /* Static so it can be a return value. */
78 struct flag_record pls, mns, user;
79 int desired_flags;
80
81 if (!u || (client_data && !(u->flags & USER_BOT))) return("*");
82
83 if (client_data) desired_flags = FR_BOT;
84 else desired_flags = FR_GLOBAL;
85
86 if (chan) {
87 user.match = desired_flags | FR_CHAN;
88 }
89 else if (changes) {
90 if ((strchr(CHANMETA, changes[0]) != NULL)) {
91 /* Determine if 'changes' is actually a channel name. */
92 if (findchan_by_dname(changes)) {
93 /* Yup. */
94 chan = changes;
95 changes = NULL;
96 user.match = desired_flags | FR_CHAN;
97 }
98 else if (changes[0] != '+' && changes[1] != '-') {
99 /* Invalid channel. */
100 return("*");
101 }
102 else {
103 /* Nope, they really are changes. */
104 user.match = desired_flags;
105 }
106 }
107 else {
108 /* Ditto... */
109 user.match = desired_flags;
110 }
111 }
112 else {
113 /* And again... */
114 user.match = desired_flags;
115 }
116 if (chan && !findchan_by_dname(chan)) {
117 return("*");
118 }
119 get_user_flagrec(u, &user, chan);
120 /* Make changes */
121 if (changes) {
122 pls.match = user.match;
123 break_down_flags(changes, &pls, &mns);
124 user.global = sanity_check((user.global|pls.global) & (~mns.global));
125 user.bot = sanity_check((user.bot|pls.bot) & (~mns.bot));
126 user.udef_global = (user.udef_global | pls.udef_global) & (~mns.udef_global);
127 if (chan) {
128 if (client_data) user.chan = (user.chan | pls.chan) & (~mns.chan);
129 else user.chan = chan_sanity_check((user.chan | pls.chan) & (~mns.chan), user.global);
130
131 user.udef_chan = (user.udef_chan | pls.udef_chan) & (~mns.udef_chan);
132 }
133 set_user_flagrec(u, &user, chan);
134 }
135 /* Retrieve current flags and return them */
136 build_flags(work, &user, NULL);
137 return(work);
138 }
139
140 static int script_matchattr(struct userrec *u, char *flags, char *chan)
141 {
142 struct flag_record plus, minus, user;
143 int has_minus_flags;
144
145 if (!u) return(0);
146 user.match = FR_GLOBAL | FR_BOT;
147 if (chan) user.match |= FR_CHAN;
148 get_user_flagrec(u, &user, chan);
149 plus.match = user.match;
150 break_down_flags(flags, &plus, &minus);
151 has_minus_flags = (minus.global || minus.udef_global || minus.chan || minus.udef_chan || minus.bot);
152 if (flagrec_eq(&plus, &user)) {
153 if (!has_minus_flags) return(1);
154 else {
155 minus.match = plus.match ^ (FR_AND | FR_OR);
156 if (!flagrec_eq(&minus, &user)) return(1);
157 }
158 }
159 return(0);
160 }
161
162 static int script_adduser(char *handle, char *hostmask)
163 {
164 char realhandle[HANDLEN];
165
166 strncpy(realhandle, handle, HANDLEN);
167 realhandle[HANDLEN-1] = 0;
168
169 if (realhandle[0] == '*' || get_user_by_handle(userlist, realhandle)) return(0);
170
171 userlist = adduser(userlist, handle, hostmask, "-", default_flags);
172 return(1);
173 }
174
175 static int script_addbot(char *handle, char *address)
176 {
177 struct bot_addr *bi;
178 char *p, *q;
179 char *orig, *addr, realhandle[HANDLEN];
180 int addrlen = 0;
181
182 strncpy(realhandle, handle, HANDLEN);
183 realhandle[HANDLEN-1] = 0;
184 if (get_user_by_handle(userlist, realhandle)) return(0);
185 if (realhandle[0] == '*') return(0);
186 userlist = adduser(userlist, realhandle, "none", "-", USER_BOT);
187
188 bi = (struct bot_addr *)malloc(sizeof(*bi));
189 addr = strdup(address);
190 orig = addr;
191 if (*addr == '[') {
192 addr++;
193 if ((q = strchr(addr, ']'))) {
194 addrlen = q - addr;
195 q++;
196 if (*q != ':') q = 0;
197 else addrlen = strlen(addr);
198 }
199 }
200 else if ((q = strchr(addr, ':'))) addrlen = q - addr;
201 else addrlen = strlen(addr);
202 if (!q) {
203 bi->address = strdup(addr);
204 bi->telnet_port = 3333;
205 bi->relay_port = 3333;
206 }
207 else {
208 bi->address = malloc(q - addr + 1);
209 strlcpy(bi->address, addr, addrlen + 1);
210 p = q + 1;
211 bi->telnet_port = atoi(p);
212 q = strchr(p, '/');
213 if (!q) bi->relay_port = bi->telnet_port;
214 else bi->relay_port = atoi(q + 1);
215 }
216 free(orig);
217 set_user(&USERENTRY_BOTADDR, get_user_by_handle(userlist, realhandle), bi);
218 return(1);
219 }
220
221 static int script_deluser(struct userrec *u)
222 {
223 if (!u) return(0);
224 return deluser(u->handle);
225 }
226
227 static int script_delhost(char *handle, char *hostmask)
228 {
229 return delhost_by_handle(handle, hostmask);
230 }
231
232 static int script_userlist(script_var_t *retval, char *flags, char *chan)
233 {
234 struct userrec *u;
235 struct flag_record user, plus, minus;
236 int ok = 1, f = 0;
237
238 retval->type = SCRIPT_ARRAY | SCRIPT_VAR | SCRIPT_FREE;
239 retval->len = 0;
240 retval->value = NULL;
241
242 if (chan && !findchan_by_dname(chan)) return(0);
243 if (flags) {
244 plus.match = FR_GLOBAL | FR_CHAN | FR_BOT;
245 break_down_flags(flags, &plus, &minus);
246 f = (minus.global || minus.udef_global || minus.chan ||
247 minus.udef_chan || minus.bot);
248 }
249 minus.match = plus.match ^ (FR_AND | FR_OR);
250 for (u = userlist; u; u = u->next) {
251 if (flags) {
252 user.match = FR_GLOBAL | FR_CHAN | FR_BOT | (chan ? 0 : FR_ANYWH);
253 get_user_flagrec(u, &user, chan);
254 if (flagrec_eq(&plus, &user) && !(f && flagrec_eq(&minus, &user)))
255 ok = 1;
256 else
257 ok = 0;
258 }
259 if (ok) script_list_append(retval, script_string(u->handle, -1));
260 }
261 return(0);
262 }
263
264 static int script_save()
265 {
266 write_userfile(-1);
267 return(0);
268 }
269
270 static int script_reload()
271 {
272 reload();
273 return(0);
274 }
275
276 static int script_chhandle(struct userrec *u, char *desired_handle)
277 {
278 char newhand[HANDLEN + 1];
279 int i;
280
281 if (!u) return(0);
282 strlcpy(newhand, desired_handle, sizeof(newhand));
283 for (i = 0; i < strlen(newhand); i++)
284 if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
285 newhand[i] = '?';
286 if (strchr(BADHANDCHARS, newhand[0]) != NULL) return(0);
287 if (strlen(newhand) < 1) return(0);
288 if (get_user_by_handle(userlist, newhand)) return(0);
289 if (!strcasecmp(myname, newhand) && (!(u->flags & USER_BOT)))
290 return(0);
291 if (newhand[0] == '*') return(0);
292
293 return change_handle(u, newhand);
294 }
295
296 static int script_isignore(char *nick_user_host)
297 {
298 return match_ignore(nick_user_host);
299 }
300
301 static int script_newignore(int nargs, char *hostmask, char *creator, char *comment, int lifetime)
302 {
303 time_t expire_time;
304 char ign[UHOSTLEN], cmt[66], from[HANDLEN + 1];
305
306 //BADARGS(4, 5, " hostmask creator comment ?lifetime?");
307 strlcpy(ign, hostmask, sizeof ign);
308 strlcpy(from, creator, sizeof from);
309 strlcpy(cmt, comment, sizeof cmt);
310 if (lifetime < 0) lifetime = 0;
311 if (nargs == 3) expire_time = now + (60 * ignore_time);
312 else {
313 if (!lifetime) expire_time = 0L;
314 else expire_time = now + (60 * lifetime);
315 }
316 addignore(ign, from, cmt, expire_time);
317 return TCL_OK;
318 }
319
320 static int script_killignore(char *hostmask)
321 {
322 return delignore(hostmask);
323 }
324
325 /* { hostmask note expire-time create-time creator }
326 */
327 static int script_ignorelist(script_var_t *retval)
328 {
329 script_var_t *sublist;
330 struct igrec *i;
331
332 retval->type = SCRIPT_ARRAY | SCRIPT_VAR | SCRIPT_FREE;
333 retval->len = 0;
334 retval->value = NULL;
335
336 for (i = global_ign; i; i = i->next) {
337 sublist = script_list(5, script_string(i->igmask, -1),
338 script_string(i->msg, -1),
339 script_int(i->expire),
340 script_int(i->added),
341 script_string(i->user, -1));
342 script_list_append(retval, sublist);
343 }
344 return(0);
345 }
346
347 script_command_t script_user_cmds[] = {
348 {"", "countusers", script_countusers, NULL, 0, "", "", SCRIPT_INTEGER, 0},
349 {"", "validuser", script_validuser, NULL, 1, "s", "handle", SCRIPT_INTEGER, 0},
350 {"", "finduser", (Function) script_finduser, NULL, 1, "s", "nick!user@host", SCRIPT_USER, 0},
351 {"", "passwdok", script_passwd_ok, NULL, 2, "Us", "handle password", SCRIPT_INTEGER, 0},
352 {"", "chattr", (Function) script_chattr_botattr, NULL, 1, "Uss", "handle ?changes ?channel??", SCRIPT_STRING, SCRIPT_PASS_CDATA|SCRIPT_VAR_ARGS},
353 {"", "botattr", (Function) script_chattr_botattr, (void *)1, 1, "Uss", "bot ?changes ?channel??", SCRIPT_STRING, SCRIPT_PASS_CDATA|SCRIPT_VAR_ARGS},
354 {"", "matchattr", (Function) script_matchattr, NULL, 2, "Uss", "handle flags ?channel?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
355 {"", "adduser", (Function) script_adduser, NULL, 1, "ss", "handle ?hostmask?", SCRIPT_INTEGER, SCRIPT_VAR_ARGS},
356 {"", "addbot", (Function) script_addbot, NULL, 2, "ss", "handle address", SCRIPT_INTEGER, 0},
357 {"", "deluser", (Function) script_deluser, NULL, 1, "U", "handle", SCRIPT_INTEGER, 0},
358 {"", "delhost", (Function) script_delhost, NULL, 2, "ss", "handle hostmask", SCRIPT_INTEGER, 0},
359 {"", "userlist", (Function) script_userlist, NULL, 0, "ss", "?flags ?channel??", 0, SCRIPT_PASS_RETVAL | SCRIPT_VAR_ARGS},
360 {"", "save", (Function) script_save, NULL, 0, "", "", SCRIPT_INTEGER, 0},
361 {"", "reload", (Function) script_reload, NULL, 0, "", "", SCRIPT_INTEGER, 0},
362 {"", "chhandle", (Function) script_chhandle, NULL, 2, "Us", "handle new-handle", SCRIPT_INTEGER, 0},
363 {"", "isignore", (Function) script_isignore, NULL, 1, "s", "nick!user@host", SCRIPT_INTEGER, 0},
364 {"", "newignore", (Function) script_newignore, NULL, 3, "sssi", "hostmask creator comment ?minutes?", SCRIPT_INTEGER, SCRIPT_PASS_COUNT | SCRIPT_VAR_ARGS},
365 {"", "killignore", (Function) script_killignore, NULL, 1, "s", "hostmask", SCRIPT_INTEGER, 0},
366 {"", "ignorelist", (Function) script_ignorelist, NULL, 0, "", "", 0, SCRIPT_PASS_RETVAL},
367 {0}
368 };

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23