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

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

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


Revision 1.49 - (hide annotations) (download) (as text)
Tue Feb 25 06:52:19 2003 UTC (16 years, 8 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 guppy 1.19 /*
2 tothwolf 1.42 * tcluser.c --
3 guppy 1.19 *
4 tothwolf 1.42 * Tcl stubs for the user-record-oriented commands
5 segfault 1.1 */
6 guppy 1.19 /*
7     * Copyright (C) 1997 Robey Pointer
8 wcc 1.46 * Copyright (C) 1999, 2000, 2001, 2002, 2003 Eggheads Development Team
9 guppy 1.19 *
10 fabian 1.8 * 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 guppy 1.19 *
15 fabian 1.8 * 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 guppy 1.19 *
20 fabian 1.8 * 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 segfault 1.1 */
24 tothwolf 1.42
25     #ifndef lint
26 stdarg 1.49 static const char rcsid[] = "$Id: tcluser.c,v 1.48 2003/02/15 05:04:58 wcc Exp $";
27 tothwolf 1.42 #endif
28 segfault 1.1
29     #include "main.h"
30     #include "users.h"
31     #include "chan.h"
32 wingman 1.41 #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 segfault 1.1
38 wcc 1.47 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 segfault 1.1
44 wingman 1.41 #ifndef MAKING_MODS
45     extern struct dcc_table DCC_BOT;
46     #endif /* MAKING_MODS */
47 segfault 1.1
48 stdarg 1.33 static int script_countusers()
49 fabian 1.14 {
50 stdarg 1.33 return count_users(userlist);
51 segfault 1.1 }
52 fabian 1.14
53 stdarg 1.44 static int script_validuser(char *handle)
54 fabian 1.14 {
55 stdarg 1.44 struct userrec *u;
56    
57     u = get_user_by_handle(userlist, handle);
58 stdarg 1.33 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 segfault 1.1 }
139    
140 stdarg 1.34 static int script_matchattr(struct userrec *u, char *flags, char *chan)
141 fabian 1.14 {
142 stdarg 1.34 struct flag_record plus, minus, user;
143     int has_minus_flags;
144 segfault 1.1
145 stdarg 1.34 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 stdarg 1.40 break_down_flags(flags, &plus, &minus);
151 stdarg 1.34 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 segfault 1.1 }
161    
162 stdarg 1.34 static int script_adduser(char *handle, char *hostmask)
163 fabian 1.14 {
164 stdarg 1.34 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 segfault 1.1
171 stdarg 1.34 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 ite 1.36 bi->address = strdup(addr);
204 stdarg 1.34 bi->telnet_port = 3333;
205     bi->relay_port = 3333;
206     }
207     else {
208     bi->address = malloc(q - addr + 1);
209 ite 1.39 strlcpy(bi->address, addr, addrlen + 1);
210 stdarg 1.34 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 segfault 1.1 }
220    
221 stdarg 1.34 static int script_deluser(struct userrec *u)
222 fabian 1.14 {
223 stdarg 1.34 if (!u) return(0);
224     return deluser(u->handle);
225 segfault 1.1 }
226    
227 stdarg 1.34 static int script_delhost(char *handle, char *hostmask)
228 fabian 1.14 {
229 stdarg 1.34 return delhost_by_handle(handle, hostmask);
230 segfault 1.1 }
231    
232 stdarg 1.34 static int script_userlist(script_var_t *retval, char *flags, char *chan)
233 fabian 1.14 {
234 guppy 1.22 struct userrec *u;
235 segfault 1.1 struct flag_record user, plus, minus;
236     int ok = 1, f = 0;
237    
238 stdarg 1.34 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 segfault 1.1 plus.match = FR_GLOBAL | FR_CHAN | FR_BOT;
245 stdarg 1.34 break_down_flags(flags, &plus, &minus);
246 segfault 1.1 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 guppy 1.22 for (u = userlist; u; u = u->next) {
251 stdarg 1.34 if (flags) {
252     user.match = FR_GLOBAL | FR_CHAN | FR_BOT | (chan ? 0 : FR_ANYWH);
253     get_user_flagrec(u, &user, chan);
254 segfault 1.1 if (flagrec_eq(&plus, &user) && !(f && flagrec_eq(&minus, &user)))
255     ok = 1;
256     else
257     ok = 0;
258     }
259 stdarg 1.34 if (ok) script_list_append(retval, script_string(u->handle, -1));
260 segfault 1.1 }
261 stdarg 1.34 return(0);
262 segfault 1.1 }
263    
264 stdarg 1.34 static int script_save()
265 fabian 1.14 {
266 segfault 1.1 write_userfile(-1);
267 stdarg 1.34 return(0);
268 segfault 1.1 }
269    
270 stdarg 1.34 static int script_reload()
271 fabian 1.14 {
272 segfault 1.1 reload();
273 stdarg 1.34 return(0);
274 segfault 1.1 }
275    
276 stdarg 1.34 static int script_chhandle(struct userrec *u, char *desired_handle)
277 fabian 1.14 {
278 fabian 1.2 char newhand[HANDLEN + 1];
279 stdarg 1.34 int i;
280 segfault 1.1
281 stdarg 1.34 if (!u) return(0);
282 ite 1.39 strlcpy(newhand, desired_handle, sizeof(newhand));
283 fabian 1.2 for (i = 0; i < strlen(newhand); i++)
284     if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
285     newhand[i] = '?';
286 stdarg 1.34 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 wcc 1.47 if (!strcasecmp(myname, newhand) && (!(u->flags & USER_BOT)))
290 stdarg 1.43 return(0);
291 stdarg 1.34 if (newhand[0] == '*') return(0);
292    
293     return change_handle(u, newhand);
294 segfault 1.1 }
295    
296 stdarg 1.34 static int script_isignore(char *nick_user_host)
297 fabian 1.14 {
298 stdarg 1.34 return match_ignore(nick_user_host);
299 segfault 1.1 }
300    
301 stdarg 1.34 static int script_newignore(int nargs, char *hostmask, char *creator, char *comment, int lifetime)
302 fabian 1.14 {
303 segfault 1.1 time_t expire_time;
304     char ign[UHOSTLEN], cmt[66], from[HANDLEN + 1];
305    
306 stdarg 1.34 //BADARGS(4, 5, " hostmask creator comment ?lifetime?");
307 ite 1.39 strlcpy(ign, hostmask, sizeof ign);
308     strlcpy(from, creator, sizeof from);
309     strlcpy(cmt, comment, sizeof cmt);
310 stdarg 1.34 if (lifetime < 0) lifetime = 0;
311     if (nargs == 3) expire_time = now + (60 * ignore_time);
312 segfault 1.1 else {
313 stdarg 1.34 if (!lifetime) expire_time = 0L;
314     else expire_time = now + (60 * lifetime);
315 segfault 1.1 }
316     addignore(ign, from, cmt, expire_time);
317     return TCL_OK;
318     }
319    
320 stdarg 1.34 static int script_killignore(char *hostmask)
321 fabian 1.14 {
322 stdarg 1.34 return delignore(hostmask);
323 segfault 1.1 }
324    
325 fabian 1.14 /* { hostmask note expire-time create-time creator }
326     */
327 stdarg 1.34 static int script_ignorelist(script_var_t *retval)
328 fabian 1.14 {
329 stdarg 1.34 script_var_t *sublist;
330 segfault 1.1 struct igrec *i;
331    
332 stdarg 1.34 retval->type = SCRIPT_ARRAY | SCRIPT_VAR | SCRIPT_FREE;
333     retval->len = 0;
334     retval->value = NULL;
335    
336 segfault 1.1 for (i = global_ign; i; i = i->next) {
337 stdarg 1.34 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 segfault 1.1 }
344 stdarg 1.34 return(0);
345 segfault 1.1 }
346    
347 stdarg 1.33 script_command_t script_user_cmds[] = {
348     {"", "countusers", script_countusers, NULL, 0, "", "", SCRIPT_INTEGER, 0},
349 stdarg 1.44 {"", "validuser", script_validuser, NULL, 1, "s", "handle", SCRIPT_INTEGER, 0},
350 stdarg 1.33 {"", "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 stdarg 1.34 {"", "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 stdarg 1.33 {0}
368 segfault 1.1 };

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23