[srvx-commits] CVS: services/src authserv.h,NONE,1.1 authserv.c,NONE,1.1 tools.c,1.98,1.99 service.c
Brought to you by:
entrope
From: Entrope <en...@us...> - 2001-10-12 02:03:37
|
Update of /cvsroot/srvx/services/src In directory usw-pr-cvs1:/tmp/cvs-serv2600/src Modified Files: tools.c service.c proto_ircu_p10.c proto_bahamut.c proto.h modules.h modules.c mod_common.c hash.h hash.c Makefile.am Added Files: authserv.h authserv.c Log Message: start fleshing out some more services rearrange protocol stuff a little (should fix some problems) --- NEW FILE --- /* authserv.h - Authentication service * Copyright 2001 srvx Development Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #if !defined(AUTHSERV_H) #define AUTHSERV_H #include <sys/types.h> #include "common.h" #define AUTHSERV_MAJOR 0 #define AUTHSERV_MINOR 0 #define AUTHSERV_REVISION 0 #define AUTHSERV_VERSION MAKE_VERSION(AUTHSERV_MAJOR, AUTHSERV_MINOR, AUTHSERV_REVISION) /* HI_FLAG_* go into handle_info.flags */ #define HI_FLAG_OPER_SUSPENDED 0x00000001 #define HI_FLAG_USE_PRIVMSG 0x00000002 #define HI_FLAG_HELPER 0x00000004 #define HI_FLAG_HELPING 0x00000008 #define HI_FLAG_SUSPENDED 0x00000010 #define HI_FLAG_MIRC_COLOR 0x00000020 #define HI_FLAG_FROZEN 0x00000040 #define HI_FLAG_NODELETE 0x00000080 /* Flag characters for the above. First char is LSB, etc. */ #define HANDLE_FLAGS "Sphgscfn" /* HI_STYLE_* go into handle_info.userlist_style */ #define HI_STYLE_DEF 'd' #define HI_STYLE_ZOOT 'Z' #define HI_DEFAULT_FLAGS (HI_FLAG_MIRC_COLOR) #define HI_DEFAULT_STYLE HI_STYLE_DEF #define HANDLE_FLAGGED(hi, tok) ((hi)->flags & HI_FLAG_##tok) #define HANDLE_SET_FLAG(hi, tok) ((hi)->flags |= HI_FLAG_##tok) #define HANDLE_TOGGLE_FLAG(hi, tok) ((hi)->flags ^= HI_FLAG_##tok) #define HANDLE_CLEAR_FLAG(hi, tok) ((hi)->flags &= ~HI_FLAG_##tok) #define IsHelping(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, HELPING)) struct handle_info { struct nick_info *nicks; /* linked list of owned nicks */ struct string_list *masks; struct user *users; struct chanList *channels; unsigned long flags; unsigned int opserv_level; unsigned int screen_width; time_t registered, lastseen; char handle[31]; char passwd[MD5_CRYPT_LENGTH+1]; char info[MAXLEN]; char userlist_style; }; struct handle_info *get_handle_info(const char *handle); struct handle_info *smart_get_handle_info(struct user *bot, struct user *source, const unsigned char *name); /* auth_funcs are called when a user gets a new handle_info. They are * called after it has been determined that the user may authenticate * under the new handle, but *before* their handle_info is changed -- * so user->handle_info still points to their previous handle (if they * were previously authenticated). */ typedef void (*auth_func_t)(struct user *user, struct handle_info *new_handle); void reg_auth_func(auth_func_t func); /* unreg_funcs are called right before a handle is unregistered. * `user' is the person who caused the handle to be unregistered (either a * client authed to the handle, or an oper). */ typedef void (*unreg_func_t)(struct user *user, struct handle_info *handle); void reg_unreg_func(unreg_func_t func); #endif --- NEW FILE --- /* authserv.c - Authentication service * Copyright 2001 srvx Development Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include "modules.h" #include "authserv.h" /* TODO: implement authserv */ struct handle_info *get_handle_info(const char *handle); struct handle_info *smart_get_handle_info(struct user *bot, struct user *source, const unsigned char *name); void reg_auth_func(auth_func_t func); void reg_unreg_func(unreg_func_t func); LIB_LOAD_FUNC(mod_init) { (void)lib; /* TODO: implement authserv's mod_init */ return 0; } Index: tools.c =================================================================== RCS file: /cvsroot/srvx/services/src/tools.c,v retrieving revision 1.98 retrieving revision 1.99 diff -C2 -r1.98 -r1.99 *** tools.c 2001/10/10 04:00:41 1.98 --- tools.c 2001/10/12 02:03:34 1.99 *************** *** 43,235 **** #include "hash.h" #include "log.h" - #include "proto.h" #include "recdb.h" #include "tools.h" - static const unsigned char *user_modes = RFC1459_USER_MODE_CHARS; - static unsigned char user_inverse_modes[256]; - static const unsigned char *channel_modes = RFC1459_CHANNEL_MODE_CHARS; - unsigned char channel_inverse_modes[256]; - - static void - tools_build_inverse_modes(void) { - unsigned int nn; - /* Go through and record which bit each character corresponds to. - * Since some modes don't exist in some protocols, the - * corresponding position in the *_modes string is a space; but we - * don't want to give spaces a value, so erase them afterwards. - */ - for (nn=0; user_modes[nn]; nn++) { - user_inverse_modes[user_modes[nn]] = nn + 1; - } - user_inverse_modes[' '] = 0; - for (nn=0; channel_modes[nn]; nn++) { - channel_inverse_modes[channel_modes[nn]] = nn + 1; - } - channel_inverse_modes[' '] = 0; - } - - void - mod_usermode(struct user *user, const char *mode_change) { - unsigned long orig_modes; - int add = 1; - unsigned char modechar; - - if (!user || !mode_change || !*mode_change) return; - orig_modes = user->modes; - while (1) { - switch (modechar = *mode_change++) { - case 0: case ' ': return; - case '+': add = 1; break; - case '-': add = 0; break; - default: - if (user_inverse_modes[modechar]) { - if (add) { - user->modes |= (1 << (user_inverse_modes[modechar]-1)); - } else { - user->modes &= ~(1 << (user_inverse_modes[modechar]-1)); - } - } - } - #undef do_user_mode - } - /* TODO: add callback to notify things of mode changes */ - } - - int - make_usermode(struct user *user, char *out, unsigned int len) - { - unsigned int nn, jj=0; - len--; /* to allow for \0 at end */ - out[jj++] = '+'; - for (nn=0; user_modes[nn] && (jj<len); nn++) { - if ((user_modes[nn] != ' ') && (user->modes & (1 << nn))) { - out[jj++] = user_modes[nn]; - } - } - out[jj++] = 0; - return 1; - } - - void - mod_chanmode(struct channel *channel, const char *mode_change, const char *key, int limit) - { - int add = 1, n; - const char *word = mode_change; - unsigned char modechar; - - if (!mode_change || !*mode_change) return; - while (*word != ' ' && *word) word++; - while (*word == ' ') word++; - while (1) { - switch (modechar = *mode_change++) { - case 0: case ' ': return; - case '+': add = 1; break; - case '-': add = 0; break; - case 'k': - if (add) { - if (key) { - safestrncpy(channel->key, key, sizeof(channel->key)); - } else { - for (n=0; *word != ' ' && *word; n++) { - channel->key[n] = *word++; - } - channel->key[n] = 0; - } - } else { - channel->key[0] = 0; - } - break; - case 'l': - if (add) { - if (limit) { - channel->limit = limit; - } else { - channel->limit = strtoul(word, NULL, 0); - } - while (*word != ' ' && *word) word++; - while (*word == ' ') word++; - } else { - channel->limit = 0; - } - break; - default: - if ((n = channel_inverse_modes[modechar])) { - if (add) { - channel->modes |= 1 << (n-1); - } else { - channel->modes &= ~(1 << (n-1)); - } - } - break; - } - } - } - int - make_chanmode(struct channel *channel, char *out, unsigned int len) - { - unsigned int nn, jj=0; - len--; /* to allow for \0 at end */ - out[jj++] = '+'; - for (nn=0; channel_modes[nn] && (jj<len); nn++) { - if ((channel_modes[nn] != ' ') && (channel->modes & (1 << nn))) { - out[jj++] = channel_modes[nn]; - } - } - if (channel->limit || channel->key[0]) { - if (jj < len-2) { - if (channel->limit) out[jj++] = 'l'; - if (channel->key[0]) out[jj++] = 'k'; - if (channel->limit) { - if (jj < len) out[jj++] = ' '; - jj += snprintf(out+jj, len-jj, "%d", channel->limit); - if (jj >= len) jj = len-1; - } - if (channel->key[0]) { - if (jj < len) out[jj++] = ' '; - jj += snprintf(out+jj, len-jj, "%s", channel->key); - if (jj >= len) jj = len-1; - } - } - } - out[jj++] = 0; - return 1; - } - - int - verify_chanmode(const char *modes) - { - const char *word; - int add = 1; - unsigned char modechar; - - if (!modes) return 0; - if (!*modes) return 1; - if ((*modes != '+') && (*modes != '-')) return 0; - word = modes; - while (*word != ' ' && *word) word++; - while (*word == ' ') word++; - while (1) { - switch (modechar = *modes++) { - case 0: - case ' ': - return 1; - case '+': add = 1; break; - case '-': add = 0; break; - case 'k': - if (add && !*word) return 0; - break; - case 'l': - if (add && (!*word || (strtoul(word, NULL, 0) <= 0))) return 0; - break; - default: - if (!channel_inverse_modes[modechar]) return 0; - break; - } - } - } - - int split_line(unsigned char *line, int irc_colon, int argv_size, unsigned char *argv[]) { --- 43,50 ---- *************** *** 406,446 **** int - user_matches_glob(struct user *user, const char *orig_glob, int include_nick) - { - char *glob, *marker; - /* Make a writable copy of the glob */ - glob = alloca(strlen(orig_glob)+1); - strcpy(glob, orig_glob); - /* Check the nick, if it's present */ - if (include_nick) { - if (!(marker = strchr(glob, '!'))) { - log(MAIN_LOG, LOG_ERROR, "match_glob_user(\"%s\", \"%s\", %d) called, and glob doesn't include a '!'\n", user->nick, orig_glob, include_nick); - return 0; - } - *marker = 0; - if (!match_ircglob(user->nick, glob)) return 0; - glob = marker + 1; - } - /* Check the ident */ - if (!(marker = strchr(glob, '@'))) { - log(MAIN_LOG, LOG_ERROR, "match_glob_user(\"%s\", \"%s\", %d) called, and glob doesn't include an '@'\n", user->nick, orig_glob, include_nick); - return 0; - } - *marker = 0; - if (!match_ircglob(user->username, glob)) return 0; - glob = marker + 1; - /* Now check the host part */ - if (isdigit(*glob) && !glob[strspn(glob, "0123456789./*?")]) { - /* Looks like an IP-based mask */ - unsigned char userip[20]; - sprintf(userip, "%ld.%ld.%ld.%ld", (user->ip >> 24) & 255, (user->ip >> 16) & 255, (user->ip >> 8) & 255, user->ip & 255); - return match_ircglob(userip, glob); - } else { - /* The host part of the mask isn't IP-based */ - return match_ircglob(user->hostname, glob); - } - } - - int is_ircmask(const unsigned char *text) { --- 221,224 ---- *************** *** 485,570 **** } - char * - generate_hostmask(struct user *user, int options) - { - char *nickname, *username, *hostname; - char *mask; - int len, ii; - - /* figure out string parts */ - if (options & GENMASK_OMITNICK) { - nickname = NULL; - } else if (options & GENMASK_USENICK) { - nickname = user->nick; - } else { - nickname = "*"; - } - if (options & GENMASK_STRICT) { - username = user->username; - } else { - username = alloca(strlen(user->username)+2); - username[0] = '*'; - strcpy(username+1, user->username + ((*user->username == '~')?1:0)); - } - hostname = user->hostname; - if (options & GENMASK_STRICT) { - /* leave hostname as is */ - } else if ((options & GENMASK_BYIP) || !hostname[strspn(hostname, "0123456789.")]) { - /* Should generate an IP-based hostmask. By popular acclaim, a /16 - * hostmask is used by default. */ - unsigned masked_ip, mask, masklen; - masklen = 16; - mask = ~0 << masklen; - masked_ip = user->ip & mask; - hostname = alloca(32); - if (options & GENMASK_SRVXMASK) { - sprintf(hostname, "%d.%d.%d.%d/%d", (masked_ip>>24)&0xFF, (masked_ip>>16)&0xFF, (masked_ip>>8)&0xFF, masked_ip&0xFF, masklen); - } else { - int ofs = 0; - for (ii=0; ii<4; ii++) { - if (masklen) { - ofs += sprintf(hostname+ofs, "%d.", (masked_ip>>24)&0xFF); - masklen -= 8; - masked_ip <<= 8; - } else { - ofs += sprintf(hostname+ofs, "*."); - } - } - /* Truncate the last . */ - hostname[ofs-1] = 0; - } - } else { - int cnt; - /* This heuristic could be made smarter. Is it worth the effort? */ - for (ii=cnt=0; hostname[ii]; ii++) { - if (hostname[ii] == '.') cnt++; - } - if (cnt == 1) { - /* only a two-level domain name; leave hostname */ - } else if (cnt == 2) { - for (ii=0; user->hostname[ii] != '.'; ii++) ; - hostname = alloca(strlen(user->hostname+ii)+2); - sprintf(hostname, "*%s", user->hostname+ii+1); - } else { - for (cnt=3, ii--; cnt; ii--) { - if (user->hostname[ii] == '.') cnt--; - } - hostname = alloca(strlen(user->hostname+ii)+2); - sprintf(hostname, "*%s", user->hostname+ii+1); - } - } - /* Emit hostmask */ - len = strlen(username) + strlen(hostname) + 2; - if (nickname) { - len += strlen(nickname) + 1; - mask = malloc(len); - sprintf(mask, "%s!%s@%s", nickname, username, hostname); - } else { - mask = malloc(len); - sprintf(mask, "%s@%s", username, hostname); - } - return mask; - } - static long TypeLength(char type) --- 263,266 ---- *************** *** 823,831 **** strcpy(buf->list+from, repl); } - - void - tools_init(void) - { - tools_build_inverse_modes(); - } - --- 519,520 ---- Index: service.c =================================================================== RCS file: /cvsroot/srvx/services/src/service.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** service.c 2001/10/10 04:51:23 1.4 --- service.c 2001/10/12 02:03:34 1.5 *************** *** 25,28 **** --- 25,29 ---- #include "dict.h" + #include "messages.h" #include "proto.h" #include "rules.h" *************** *** 37,41 **** static struct module *service_module; static dict_t service_templates; - #define SINST(USER) ((USER)->service) void --- 38,41 ---- *************** *** 66,70 **** chan_name = argv[0]; } else { ! /* TODO: whine */ } } else if ((argc > 1) && (argv[1][0] == '#')) { --- 66,71 ---- chan_name = argv[0]; } else { ! send_message(source, bot, MSG_INVALID_CHANNEL); ! return; } } else if ((argc > 1) && (argv[1][0] == '#')) { *************** *** 86,106 **** } if ((cmd->base->flags & (1 << REQUIRE_CHANNEL)) && !chan) { ! /* TODO: whine */ return; } - /* TODO: check for authed state and whine if not */ - if ((cmd->base->flags & (1 << REQUIRE_AUTHED)) && 0) { - } /* Fill in rule context and evaluate it */ rule_ctx.user = source; rule_ctx.channel = chan; if (!expression_evaluate(cmd->rule ? cmd->rule : cmd->base->default_rule, &rule_ctx)) { ! /* TODO: whine */ ! return; ! } ! if (cmd->base->function(source, bot, chan, argc-shift, argv+shift)) { ! /* TODO: whine or something */ return; } } --- 87,101 ---- } if ((cmd->base->flags & (1 << REQUIRE_CHANNEL)) && !chan) { ! send_message(source, bot, MSG_INVALID_CHANNEL); return; } /* Fill in rule context and evaluate it */ rule_ctx.user = source; rule_ctx.channel = chan; if (!expression_evaluate(cmd->rule ? cmd->rule : cmd->base->default_rule, &rule_ctx)) { ! send_message(source, bot, N_("Access to $b%s$b denied."), argv[shift]); return; } + cmd->base->function(source, bot, chan, argc-shift, argv+shift); } Index: proto_ircu_p10.c =================================================================== RCS file: /cvsroot/srvx/services/src/proto_ircu_p10.c,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -r1.26 -r1.27 *** proto_ircu_p10.c 2001/10/10 04:00:41 1.26 --- proto_ircu_p10.c 2001/10/12 02:03:34 1.27 *************** *** 51,60 **** extern int ping_freq, ping_timeout; - const char *proto_user_modes = "dkgh"; - const char *proto_channel_modes = ""; - int proto_chanserv_joins_channels = 1; - unsigned int proto_max_mode_args = 6; - unsigned int proto_max_channel_bans = 30; - static void timed_send_ping(void *data); static void timed_ping_timeout(void *data); --- 51,54 ---- *************** *** 1445,1449 **** } ! if (IsLocal(user) && IsService(user)) { /* TODO: rate limit this so silly things don't happen. */ ReintroduceUser(user); --- 1439,1443 ---- } ! if (IsLocal(user) && user->service) { /* TODO: rate limit this so silly things don't happen. */ ReintroduceUser(user); *************** *** 1671,1674 **** --- 1665,1675 ---- proto_module = module_register("proto", MAKE_VERSION(0, 0, 0), NULL, lib); + /* Set protocol-specific variables */ + proto_user_modes = "dkgh"; + proto_channel_modes = ""; + proto_chanserv_joins_channels = 1; + proto_max_mode_args = 6; + proto_max_channel_bans = 30; + /* initialize data structures */ for (i=0; i<ArrayLength(servers_num); i++) { *************** *** 1773,1776 **** --- 1774,1780 ---- /* register exit functions */ reg_exit_func(free_parse_misc); + + /* let rest of protocol stuff initialize */ + proto_init(); return 0; } Index: proto_bahamut.c =================================================================== RCS file: /cvsroot/srvx/services/src/proto_bahamut.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -r1.16 -r1.17 *** proto_bahamut.c 2001/10/10 04:00:41 1.16 --- proto_bahamut.c 2001/10/12 02:03:34 1.17 *************** *** 52,61 **** extern int ping_freq, ping_timeout; - const char *proto_user_modes = " h"; - const char *proto_channel_modes = " rRcO"; - int proto_chanserv_joins_channels = 0; - unsigned int proto_max_mode_args = MAXNUMPARAMS; - unsigned int proto_max_channel_bans = 30; - static void timed_send_ping(void *data); static void timed_ping_timeout(void *data); --- 52,55 ---- *************** *** 109,113 **** #define CMD_ADMIN "ADMIN" #define CMD_AWAY "AWAY" - #define CMD_BURST "BURST" #define CMD_CAPAB "CAPAB" #define CMD_CLOSE "CLOSE" --- 103,106 ---- *************** *** 120,125 **** #define CMD_DIE "DIE" #define CMD_DNS "DNS" - #define CMD_EOB "END_OF_BURST" - #define CMD_EOB_ACK "EOB_ACK" #define CMD_ERROR "ERROR" #define CMD_GLINE "GLINE" --- 113,116 ---- *************** *** 670,674 **** * server; it was introduced during link authentication) */ ! /* TODO */ /* burst local nicks */ --- 661,665 ---- * server; it was introduced during link authentication) */ ! /* TODO: burst juped servers */ /* burst local nicks */ *************** *** 1255,1259 **** } ! if (IsLocal(user) && IsService(user)) { /* TODO: rate limit this so silly things don't happen. */ ReintroduceUser(user); --- 1246,1250 ---- } ! if (IsLocal(user) && user->service) { /* TODO: rate limit this so silly things don't happen. */ ReintroduceUser(user); *************** *** 1388,1394 **** /* Register things with module registry */ proto_module = module_register("proto", MAKE_VERSION(PROTO_INTERFACE_MAJOR, PROTO_INTERFACE_MINOR, 0), NULL, lib); /* set up command dictionary */ irc_func_dict = dict_new(); - dict_insert(irc_func_dict, CMD_BURST, cmd_dummy); /* just a marker */ dict_insert(irc_func_dict, CMD_CAPAB, cmd_capab); dict_insert(irc_func_dict, CMD_CREATE, cmd_create); --- 1379,1392 ---- /* Register things with module registry */ proto_module = module_register("proto", MAKE_VERSION(PROTO_INTERFACE_MAJOR, PROTO_INTERFACE_MINOR, 0), NULL, lib); + + /* Set protocol-specific variables */ + proto_user_modes = "h"; + proto_channel_modes = "rRcO"; + proto_chanserv_joins_channels = 0; + proto_max_mode_args = MAXNUMPARAMS; + proto_max_channel_bans = 30; + /* set up command dictionary */ irc_func_dict = dict_new(); dict_insert(irc_func_dict, CMD_CAPAB, cmd_capab); dict_insert(irc_func_dict, CMD_CREATE, cmd_create); *************** *** 1448,1451 **** --- 1446,1452 ---- /* create self server */ AddServer(NULL, conf_server_name(), 0, boot_time, now, conf_server_desc()); + + /* let rest of protocol stuff initialize */ + proto_init(); return 0; }; Index: proto.h =================================================================== RCS file: /cvsroot/srvx/services/src/proto.h,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -r1.46 -r1.47 *** proto.h 2001/10/10 04:00:41 1.46 --- proto.h 2001/10/12 02:03:34 1.47 *************** *** 38,44 **** #define MODE_CHANGE_BAN 0x008 - #define MAXLEN 512 - #define MAXNUMPARAMS 200 - #define MIN_LINE_SIZE 40 #define MAX_LINE_SIZE 450 --- 38,41 ---- *************** *** 46,49 **** --- 43,65 ---- typedef char *(*expand_func_t)(const char *variable); void send_message(struct user *dest, struct user *src, const char *format, ...); + + extern unsigned char user_inverse_modes[256]; + void mod_usermode(struct user *user, const char *modes); + int make_usermode(struct user *user, char *out, unsigned int len); + + extern unsigned char channel_inverse_modes[256]; + void mod_chanmode(struct channel *channel, const char *mode_change, const char *key, int limit); + int verify_chanmode(const char *modes); + int make_chanmode(struct channel *chan, char *out, unsigned int len); + + /* The "default" for generate_hostmask is to have all of these options off. */ + #define GENMASK_STRICT 1 + #define GENMASK_USENICK 2 + #define GENMASK_OMITNICK 4 /* Hurray for Kevin! */ + #define GENMASK_BYIP 8 + #define GENMASK_SRVXMASK 16 + char *generate_hostmask(struct user *user, int options); + int user_matches_glob(struct user *user, const char *glob, int include_nick); + void proto_init(void); Index: modules.h =================================================================== RCS file: /cvsroot/srvx/services/src/modules.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** modules.h 2001/10/10 04:00:41 1.8 --- modules.h 2001/10/12 02:03:34 1.9 *************** *** 60,69 **** /* In module_command.flags, bit 1<<N corresponds to (enum command_flag)N. */ enum command_flag { - REQUIRE_AUTHED, TAKES_CHANNEL, REQUIRE_CHANNEL, }; ! #define MODULE_COMMAND(NAME) int NAME(struct user *user, struct user *bot, struct channel *channel, unsigned int argc, unsigned char *argv[]) /* Represents a command loaded from a module. */ --- 60,68 ---- /* In module_command.flags, bit 1<<N corresponds to (enum command_flag)N. */ enum command_flag { TAKES_CHANNEL, REQUIRE_CHANNEL, }; ! #define MODULE_COMMAND(NAME) void NAME(struct user *source, struct user *bot, struct channel *channel, unsigned int argc, unsigned char *argv[]) /* Represents a command loaded from a module. */ Index: modules.c =================================================================== RCS file: /cvsroot/srvx/services/src/modules.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** modules.c 2001/10/10 04:00:41 1.17 --- modules.c 2001/10/12 02:03:34 1.18 *************** *** 73,77 **** struct shared_lib *lib = malloc(sizeof(*lib)); ! if (!(lib->handle = dlopen(so_name, RTLD_NOW))) { free(lib); return NULL; --- 73,77 ---- struct shared_lib *lib = malloc(sizeof(*lib)); ! if (!(lib->handle = dlopen(so_name, RTLD_GLOBAL|RTLD_LAZY))) { free(lib); return NULL; Index: mod_common.c =================================================================== RCS file: /cvsroot/srvx/services/src/mod_common.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** mod_common.c 2001/10/10 04:51:23 1.4 --- mod_common.c 2001/10/12 02:03:34 1.5 *************** *** 22,25 **** --- 22,26 ---- #include <stdlib.h> + #include "authserv.h" #include "hash.h" #include "messages.h" *************** *** 31,35 **** #include "mod_common.h" ! static struct module *common_module; /* Basic approach for help files: --- 32,36 ---- #include "mod_common.h" ! static struct module *mod_common_module; /* Basic approach for help files: *************** *** 41,53 **** * service template, look up the appropriate module's raw help entry, * and prefix the contents of that topic with the bound command name. ! * For instance, in mod_authserv_admin.help: * "oset" { * "" "This command lets opers set stuff."; * "options" "blah blah blah"; * }; ! * If "oset" was bound to "oper-set" in the service template, it would ! * result in the following help bindings: * "oper-set" "This command lets opers set stuff."; * "oper-set options" "blah blah blah"; */ static void --- 42,57 ---- * service template, look up the appropriate module's raw help entry, * and prefix the contents of that topic with the bound command name. ! * For instance, the following might be in mod_authserv_admin.help: * "oset" { * "" "This command lets opers set stuff."; * "options" "blah blah blah"; * }; ! * If "oset" were bound to "oper-set" in the service template, it ! * would result in the following help bindings: * "oper-set" "This command lets opers set stuff."; * "oper-set options" "blah blah blah"; + * + * There are also "miscellaneous" help entries, like "help nemesis". + * These are read first and thus get the highest priority. */ static void *************** *** 70,75 **** cstn = NULL; if (!cstn->help) { ! send_message(user, bot, N_("Helpfile missing.")); ! return 0; } if (argc < 2) { --- 74,79 ---- cstn = NULL; if (!cstn->help) { ! send_message(source, bot, N_("Helpfile missing.")); ! return; } if (argc < 2) { *************** *** 80,88 **** } if (!(data = dict_find(cstn->help, topic, NULL))) { ! send_message(user, bot, N_("No help on that topic.")); ! return 0; } ! send_message(user, bot, "%s", data); ! return 0; } --- 84,91 ---- } if (!(data = dict_find(cstn->help, topic, NULL))) { ! send_message(source, bot, N_("No help on that topic.")); ! return; } ! send_message(source, bot, "%s", data); } *************** *** 93,97 **** (void)channel; (void)argc; (void)argv; gettimeofday(&start, NULL); ! common_readhelp(bot, user); gettimeofday(&stop, NULL); stop.tv_sec -= start.tv_sec; --- 96,100 ---- (void)channel; (void)argc; (void)argv; gettimeofday(&start, NULL); ! common_readhelp(bot, source); gettimeofday(&stop, NULL); stop.tv_sec -= start.tv_sec; *************** *** 101,107 **** stop.tv_usec += 1000000; } ! send_message(user, bot, N_("Loaded help files for $b%s$b in "FMT_TIME_T".%06lu seconds."), bot->nick, stop.tv_sec, stop.tv_usec); ! return 0; ! return 0; } --- 104,108 ---- stop.tv_usec += 1000000; } ! send_message(source, bot, N_("Loaded help files for $b%s$b in "FMT_TIME_T".%06lu seconds."), bot->nick, stop.tv_sec, stop.tv_usec); } *************** *** 111,115 **** unsplit_string(argv+1, argc-1); gettimeofday(&start, NULL); ! service_chanmsg(bot, user, channel, argv[1]); gettimeofday(&stop, NULL); stop.tv_sec -= start.tv_sec; --- 112,116 ---- unsplit_string(argv+1, argc-1); gettimeofday(&start, NULL); ! service_chanmsg(bot, source, channel, argv[1]); gettimeofday(&stop, NULL); stop.tv_sec -= start.tv_sec; *************** *** 119,167 **** stop.tv_usec += 1000000; } ! send_message(user, bot, N_("Command $b%s$b finished in "FMT_TIME_T".%06lu seconds."), argv[1], stop.tv_sec, stop.tv_usec); ! return 0; } static MODULE_COMMAND(cmd_write) { ! (void)user; (void)bot; (void)channel; (void)argc; (void)argv; /* TODO: implement cmd_write */ - return 0; - } - - /* TODO: unkludge IsHelping() */ - #define IsHelping(USER) 1 - - static MODULE_COMMAND(cmd_god) - { - int new_helping; - (void)channel; - - if (argc > 1) { - if (enabled_string(argv[1])) new_helping = 1; - else if (disabled_string(argv[1])) new_helping = 0; - else { - send_message(user, bot, MSG_INVALID_BINARY, argv[1]); - return 0; - } - } else { - new_helping = !IsHelping(user); - } - if (new_helping) { - if (IsHelping(user)) { - send_message(user, bot, N_("You already have security override enabled.")); - return 0; - } - /* TODO: mark user as helping */ - send_message(user, bot, N_("Security override has been enabled.")); - } else { - if (!IsHelping(user)) { - send_message(user, bot, N_("You already have security override disabled.")); - return 0; - } - /* TODO: mark user as not helping */ - send_message(user, bot, N_("Security override has been disabled.")); - } - return 0; } --- 120,130 ---- stop.tv_usec += 1000000; } ! send_message(source, bot, N_("Command $b%s$b finished in "FMT_TIME_T".%06lu seconds."), argv[1], stop.tv_sec, stop.tv_usec); } static MODULE_COMMAND(cmd_write) { ! (void)source; (void)bot; (void)channel; (void)argc; (void)argv; /* TODO: implement cmd_write */ } *************** *** 173,177 **** { "timecmd", 0, NULL, cmd_timecmd }, { "write", 0, NULL, cmd_write }, - { "god", 0, NULL, cmd_god }, { NULL, 0, 0, NULL }, }; --- 136,139 ---- *************** *** 185,194 **** module_deplist_init(&deps); module_deplist_append(&deps, &hash_dependency); ! common_module = module_register("common", COMMON_VERSION, &deps, lib); ! if (!common_module) return 1; /* Register functions */ for (nn=0; cmds[nn].name; nn++) { ! if (module_define_command(common_module, cmds+nn)) return 2+nn; } --- 147,156 ---- module_deplist_init(&deps); module_deplist_append(&deps, &hash_dependency); ! mod_common_module = module_register("mod_common", COMMON_VERSION, &deps, lib); ! if (!mod_common_module) return 1; /* Register functions */ for (nn=0; cmds[nn].name; nn++) { ! if (module_define_command(mod_common_module, cmds+nn)) return 2+nn; } Index: hash.h =================================================================== RCS file: /cvsroot/srvx/services/src/hash.h,v retrieving revision 1.73 retrieving revision 1.74 diff -C2 -r1.73 -r1.74 *** hash.h 2001/10/10 04:00:41 1.73 --- hash.h 2001/10/12 02:03:34 1.74 *************** *** 42,86 **** #define RFC1459_MODENODE_MODE_CHARS "ov" - /* in channel->modes */ - #define MODE_PRIVATE 0x0001 /* Private (+p) */ - #define MODE_SECRET 0x0002 /* Secret (+s); exclusive of MODE_PRIVATE */ - #define MODE_MODERATED 0x0004 /* Moderated (+m) */ - #define MODE_TOPICLIMIT 0x0008 /* Topic semi-locked (+t) */ - #define MODE_INVITEONLY 0x0010 /* Invite only (+i) */ - #define MODE_NOPRIVMSGS 0x0020 /* No outside privmsgs (+n) */ - #define MODE_KEY 0x0040 /* Actually only used by ChanServ */ - #define MODE_LIMIT 0x0080 /* Actually only used by ChanServ */ - #define MODE_REGISTERED 0x0100 /* Channel is registered (Bahamut; +r) */ - #define MODE_REGONLY 0x0200 /* Only auth'ed users may join (Bahamut; +R) */ - #define MODE_NOCOLOR 0x0400 /* No colored msgs to channel (Bahamut; +c) */ - #define MODE_OPERONLY 0x0800 /* Only irc operators may join (Bahamut; +O) */ - #define RFC1459_CHANNEL_MODES (MODE_PRIVATE|MODE_SECRET|MODE_MODERATED|MODE_TOPICLIMIT|MODE_INVITEONLY|MODE_NOPRIVMSGS) - #define RFC1459_CHANNEL_MODE_CHARS "psmtin" - - /* in userNode->modes */ - #define FLAGS_OPER 0x0001 /* IRC Operator +o */ - #define FLAGS_INVISIBLE 0x0002 /* invisible +i */ - #define FLAGS_WALLOP 0x0004 /* receives wallops +w */ - #define FLAGS_SERVNOTICE 0x0008 /* receives server notices +s */ - #define FLAGS_DEAF 0x0010 /* deaf +d */ - #define FLAGS_SERVICE 0x0020 /* cannot be kicked, killed or deoped +k */ - #define FLAGS_GLOBAL 0x0040 /* receives global messages +g */ - #define FLAGS_HELPER 0x0080 /* (network?) helper +h */ - #define FLAGS_PERSISTENT 0x0100 /* for reserved nicks, this isn't just one-shot */ - #define FLAGS_GAGGED 0x0200 /* for gagged users */ - #define FLAGS_AWAY 0x0400 /* for away users */ - #define RFC1459_USER_MODES (FLAGS_OPER|FLAGS_INVISIBLE|FLAGS_WALLOP|FLAGS_SERVNOTICE) - #define RFC1459_USER_MODE_CHARS "oiws" - - #define IsOper(x) ((x)->modes & FLAGS_OPER) - #define IsService(x) ((x)->modes & FLAGS_SERVICE) - #define IsInvisible(x) ((x)->modes & FLAGS_INVISIBLE) - #define IsGlobal(x) ((x)->modes & FLAGS_GLOBAL) - #define IsWallOp(x) ((x)->modes & FLAGS_WALLOP) - #define IsServNotice(x) ((x)->modes & FLAGS_SERVNOTICE) - #define IsHelper(x) ((x)->modes & FLAGS_HELPER) - #define IsGagged(x) ((x)->modes & FLAGS_GAGGED) - #define IsAway(x) ((x)->modes & FLAGS_AWAY) - #define NICKLEN 31 #define USERLEN 11 --- 42,45 ---- *************** *** 98,134 **** DECLARE_LIST(serverList, struct server*); ! struct user { ! unsigned long dead : 1; ! unsigned long modes; /* user flags +isw etc... */ ! unsigned long ip; ! time_t timestamp; unsigned char nick[NICKLEN]; /* Unique name of the client */ unsigned char username[USERLEN]; /* Username on client's machine */ unsigned char info[REALLEN]; /* Additional client information */ ! unsigned char hostname[HOSTLEN]; struct server *uplink; struct modeList channels; struct user_proto *proto; struct service_instance *service; }; typedef unsigned long channel_mode_t; struct channel { char name[CHANNELLEN]; - channel_mode_t modes; - unsigned int limit; - time_t timestamp; /* creation time */ - char key[KEYLEN]; - char topic[TOPICLEN]; char topic_nick[NICKLEN]; time_t topic_time; /* time topic set */ - struct modeList members; struct banList banlist; struct channel_proto *proto; --- 57,121 ---- DECLARE_LIST(serverList, struct server*); ! /* in (struct user*)->modes */ ! #define FLAGS_OPER 0x0001 /* IRC Operator +o */ ! #define FLAGS_INVISIBLE 0x0002 /* invisible +i */ ! #define FLAGS_WALLOP 0x0004 /* receives wallops +w */ ! #define FLAGS_SERVNOTICE 0x0008 /* receives server notices +s */ ! #define FLAGS_DEAF 0x0010 /* deaf +d */ ! #define FLAGS_SERVICE 0x0020 /* cannot be kicked, killed or deoped +k */ ! #define FLAGS_GLOBAL 0x0040 /* receives global messages +g */ ! #define FLAGS_HELPER 0x0080 /* (network?) helper +h */ ! #define FLAGS_GAGGED 0x0100 /* ignored by services (srvx-only) */ ! #define FLAGS_AWAY 0x0200 /* marked as away (srvx-only) */ + #define IsOper(X) ((X)->modes & FLAGS_OPER) + #define IsGagged(X) ((X)->modes & FLAGS_GAGGED) + + struct user { unsigned char nick[NICKLEN]; /* Unique name of the client */ unsigned char username[USERLEN]; /* Username on client's machine */ unsigned char info[REALLEN]; /* Additional client information */ ! unsigned char hostname[HOSTLEN]; /* Hostname, or IP in numeric form */ struct server *uplink; struct modeList channels; + /* these are (should be) only interpreted by the protocol-related code */ + unsigned long modes; + unsigned long ip; + time_t timestamp; struct user_proto *proto; + + /* pointers to various other bits */ struct service_instance *service; }; + /* in (struct channel*)->modes */ + #define MODE_PRIVATE 0x0001 /* Private (+p) */ + #define MODE_SECRET 0x0002 /* Secret (+s); exclusive of MODE_PRIVATE */ + #define MODE_MODERATED 0x0004 /* Moderated (+m) */ + #define MODE_TOPICLIMIT 0x0008 /* Topic semi-locked (+t) */ + #define MODE_INVITEONLY 0x0010 /* Invite only (+i) */ + #define MODE_NOPRIVMSGS 0x0020 /* No outside privmsgs (+n) */ + #define MODE_REGISTERED 0x0040 /* Channel is registered (+r) */ + #define MODE_REGONLY 0x0080 /* Only auth'ed users may join (+R) */ + #define MODE_NOCOLOR 0x0100 /* No colored msgs to channel (+c) */ + #define MODE_OPERONLY 0x0200 /* Only irc operators may join (+O) */ + typedef unsigned long channel_mode_t; struct channel { char name[CHANNELLEN]; char topic[TOPICLEN]; char topic_nick[NICKLEN]; + char key[KEYLEN]; time_t topic_time; /* time topic set */ struct modeList members; struct banList banlist; + + /* These are (should be) only interpreted by protocol-specific code */ + channel_mode_t modes; + unsigned int limit; + time_t timestamp; /* creation time */ struct channel_proto *proto; Index: hash.c =================================================================== RCS file: /cvsroot/srvx/services/src/hash.c,v retrieving revision 1.148 retrieving revision 1.149 diff -C2 -r1.148 -r1.149 *** hash.c 2001/10/10 04:00:41 1.148 --- hash.c 2001/10/12 02:03:34 1.149 *************** *** 484,490 **** /* The 'banlist' was originally NULL, which i'm not sure is correct thing to do - do we really want to ignore newer ! bans? ! ! TODO: tell other server that we have the right ban list */ } --- 484,488 ---- /* The 'banlist' was originally NULL, which i'm not sure is correct thing to do - do we really want to ignore newer ! bans? */ } *************** *** 716,720 **** KickChannelUser(struct user *target, struct channel *channel, struct user *kicker, const char *why) { ! if (!target || !channel || IsService(target) || !GetUserMode(channel, target)) return; /* don't remove them from the channel, since the server will send a PART */ irc_kick(kicker, target, channel, why); --- 714,718 ---- KickChannelUser(struct user *target, struct channel *channel, struct user *kicker, const char *why) { ! if (!target || !channel || target->service || !GetUserMode(channel, target)) return; /* don't remove them from the channel, since the server will send a PART */ irc_kick(kicker, target, channel, why); *************** *** 744,748 **** unsigned int n; ! if (!kicker || !victim || !channel || IsService(victim) || !GetUserMode(channel, victim)) return; for (n=0; n<kf_used; n++) { --- 742,746 ---- unsigned int n; ! if (!kicker || !victim || !channel || victim->service || !GetUserMode(channel, victim)) return; for (n=0; n<kf_used; n++) { Index: Makefile.am =================================================================== RCS file: /cvsroot/srvx/services/src/Makefile.am,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -r1.41 -r1.42 *** Makefile.am 2001/10/02 16:04:36 1.41 --- Makefile.am 2001/10/12 02:03:34 1.42 *************** *** 3,6 **** --- 3,7 ---- bin_PROGRAMS = srvx lib_LTLIBRARIES = libmod_common.la \ + libauthserv.la \ libproto_bahamut.la libproto_ircu_p10.la EXTRA_PROGRAMS = checkdb globtest pwcracker *************** *** 31,44 **** uplink.c uplink.h libmod_common_la_SOURCES = \ ! mod_common.c mod_common.h \ ! dict.h modules.h libproto_bahamut_la_SOURCES = \ - proto.h proto.def \ proto_bahamut.c libproto_ircu_p10_la_SOURCES = \ - proto.h proto.def \ proto_ircu_p10.c --- 32,45 ---- uplink.c uplink.h + libauthserv_la_SOURCES = \ + authserv.c authserv.h + libmod_common_la_SOURCES = \ ! mod_common.c mod_common.h libproto_bahamut_la_SOURCES = \ proto_bahamut.c libproto_ircu_p10_la_SOURCES = \ proto_ircu_p10.c *************** *** 50,53 **** LINT = lclint LINTOPTS = +showscan +posixlib -boolops -predboolint -noeffect ! lint: ! $(LINT) $(LINTOPTS) compat.c conf.c dict-splay.c getopt.c getopt1.c gline.c hash.c heap.c log.c main.c md5.c mod_common.c modules.c policer.c proto.c proto_bahamut.c recdb.c rules.c saxdb.c service.c timeq.c --- 51,58 ---- LINT = lclint LINTOPTS = +showscan +posixlib -boolops -predboolint -noeffect ! LINT_FILES = compat.c conf.c getopt.c getopt1.c gline.c hash.c heap.c log.c main.c md5.c modules.c policer.c proto.c recdb.c rules.c saxdb.c service.c timeq.c ! LINT_FILES += dict-splay.c # or dict-hash.c ! LINT_FILES += proto_bahamut.c # or proto_ircu_p10.c ! LINT_FILES += mod_common.c authserv.c ! lint: $(LINT_FILES) ! $(LINT) $(LINTOPTS) $^ |