[srvx-commits] CVS: services/src/modules authserv.c,1.2,1.3 authserv.h,1.2,1.3
Brought to you by:
entrope
From: Entrope <en...@us...> - 2001-10-22 13:51:14
|
Update of /cvsroot/srvx/services/src/modules In directory usw-pr-cvs1:/tmp/cvs-serv6220 Modified Files: authserv.c authserv.h Log Message: implement more of AuthServ module consistently put service bot before user in argument lists Index: authserv.c =================================================================== RCS file: /cvsroot/srvx/services/src/modules/authserv.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** authserv.c 2001/10/20 19:23:12 1.2 --- authserv.c 2001/10/22 13:51:11 1.3 *************** *** 61,69 **** #define NEED_CHANNEL() do { if (!channel) { \ ! send_message(source, bot, MSG_INVALID_CHANNEL); \ return; } } while (0) #define MIN_PARMS(N, NEEDCHAN) do { \ if (argc < N) { \ ! send_message(source, bot, MSG_MISSING_PARAMS, argv[0]); \ return; } \ if (NEEDCHAN) NEED_CHANNEL(); } \ --- 61,69 ---- #define NEED_CHANNEL() do { if (!channel) { \ ! send_message(bot, source, MSG_INVALID_CHANNEL); \ return; } } while (0) #define MIN_PARMS(N, NEEDCHAN) do { \ if (argc < N) { \ ! send_message(bot, source, MSG_MISSING_PARAMS, argv[0]); \ return; } \ if (NEEDCHAN) NEED_CHANNEL(); } \ *************** *** 96,105 **** default: if (!(pos = handle_inverse_flags[flags[n]])) { ! send_message(source, bot, N_("$b%c$b is not a valid handle flag."), flags[n]); return 0; } if (source->handle_info->opserv_level < flag_access_levels[pos-1]) { /* cheesy avoidance of looking up the flag name.. */ ! send_message(source, bot, MSG_SETTING_PRIVILEGED, "That flag"); return 0; } --- 96,105 ---- default: if (!(pos = handle_inverse_flags[flags[n]])) { ! send_message(bot, source, N_("$b%c$b is not a valid handle flag."), flags[n]); return 0; } if (source->handle_info->opserv_level < flag_access_levels[pos-1]) { /* cheesy avoidance of looking up the flag name.. */ ! send_message(bot, source, MSG_SETTING_PRIVILEGED, "That flag"); return 0; } *************** *** 257,261 **** case '*': if (!(hi = get_handle_info(++name))) { ! send_message(source, bot, MSG_HANDLE_UNKNOWN, name); return 0; } --- 257,261 ---- case '*': if (!(hi = get_handle_info(++name))) { ! send_message(bot, source, MSG_HANDLE_UNKNOWN, name); return 0; } *************** *** 263,271 **** default: if (!(target = GetUser(name))) { ! send_message(source, bot, MSG_NICK_UNKNOWN, name); return 0; } if (!(hi = target->handle_info)) { ! send_message(source, bot, MSG_USER_AUTHENTICATE, target->nick); return 0; } --- 263,271 ---- default: if (!(target = GetUser(name))) { ! send_message(bot, source, MSG_NICK_UNKNOWN, name); return 0; } if (!(hi = target->handle_info)) { ! send_message(bot, source, MSG_USER_AUTHENTICATE, target->nick); return 0; } *************** *** 275,279 **** int ! authserv_addmask(struct user *source, struct user *bot, struct handle_info *hi, const char *mask) { unsigned int i; --- 275,279 ---- int ! authserv_addmask(struct user *bot, struct user *source, struct handle_info *hi, const char *mask) { unsigned int i; *************** *** 283,287 **** for (i=0; i<hi->masks->used; i++) { if (!strcasecmp(new_mask, hi->masks->list[i])) { ! send_message(source, bot, N_("$b%s$b is already a hostmask in your handle."), new_mask); free(new_mask); return 0; --- 283,287 ---- for (i=0; i<hi->masks->used; i++) { if (!strcasecmp(new_mask, hi->masks->list[i])) { ! send_message(bot, source, N_("$b%s$b is already a hostmask in your handle."), new_mask); free(new_mask); return 0; *************** *** 289,293 **** } string_list_append(hi->masks, new_mask); ! send_message(source, bot, N_("Hostmask $b%s$b added."), new_mask); log(NS_LOG, LOG_OTHER, "'%s' added new mask '%s' to handle '%s'.\n", source->nick, new_mask, hi->handle); return 1; --- 289,293 ---- } string_list_append(hi->masks, new_mask); ! send_message(bot, source, N_("Hostmask $b%s$b added."), new_mask); log(NS_LOG, LOG_OTHER, "'%s' added new mask '%s' to handle '%s'.\n", source->nick, new_mask, hi->handle); return 1; *************** *** 295,299 **** int ! authserv_delmask(struct user *source, struct user *bot, struct handle_info *hi, const char *del_mask) { unsigned int i; --- 295,299 ---- int ! authserv_delmask(struct user *bot, struct user *source, struct handle_info *hi, const char *del_mask) { unsigned int i; *************** *** 303,311 **** char *old_mask = hi->masks->list[i]; if (hi->masks->used == 1) { ! send_message(source, bot, N_("You may not delete your last hostmask.")); return 0; } hi->masks->list[i] = hi->masks->list[--hi->masks->used]; ! send_message(source, bot, N_("Hostmask %s deleted."), old_mask); log(NS_LOG, LOG_OTHER, N_("'%s' deleted mask '%s' from handle '%s'.\n"), source->nick, old_mask, hi->handle); free(old_mask); --- 303,311 ---- char *old_mask = hi->masks->list[i]; if (hi->masks->used == 1) { ! send_message(bot, source, N_("You may not delete your last hostmask.")); return 0; } hi->masks->list[i] = hi->masks->list[--hi->masks->used]; ! send_message(bot, source, N_("Hostmask %s deleted."), old_mask); log(NS_LOG, LOG_OTHER, N_("'%s' deleted mask '%s' from handle '%s'.\n"), source->nick, old_mask, hi->handle); free(old_mask); *************** *** 313,320 **** } } ! send_message(source, bot, N_("Unable to find mask to be deleted.")); return 0; } /*******************/ /* MODULE COMMANDS */ --- 313,370 ---- } } ! send_message(bot, source, N_("Unable to find mask to be deleted.")); return 0; } + struct handle_info * + get_oper_victim(struct user *bot, struct user *source, const char *target) + { + struct handle_info *hi; + int outranked; + + if (!(hi = smart_get_handle_info(bot, source, target))) return NULL; + if (HANDLE_FLAGGED(source->handle_info, OPER_SUSPENDED)) { + send_message(bot, source, MSG_OPER_SUSPENDED); + return NULL; + } + outranked = 1; + if (hi->opserv_level < source->handle_info->opserv_level) outranked = 0; + if (hi->opserv_level == source->handle_info->opserv_level) { + if ((source->handle_info->opserv_level == 1000) + || (source->handle_info == hi) + || ((hi->opserv_level == 0) + && !HANDLE_FLAGGED(hi, HELPER) + && IsHelping(source))) { + outranked = 0; + } + } + if (outranked) { + send_message(bot, source, MSG_USER_OUTRANKED, hi->handle); + return NULL; + } + return hi; + } + + int + is_valid_oper(struct user *bot, struct user *source, unsigned int min_level) + { + if (!IsPrivileged(source) || (min_level && !IsOper(source))) { + send_message(bot, source, N_("Access denied!")); + return 0; + } + + if (HANDLE_FLAGGED(source->handle_info, OPER_SUSPENDED)) { + send_message(bot, source, MSG_OPER_SUSPENDED); + return 0; + } + + if (source->handle_info->opserv_level < min_level) { + send_message(bot, source, N_("Access denied!")); + return 0; + } + + return 1; + } + /*******************/ /* MODULE COMMANDS */ *************** *** 334,366 **** passwd = argv[1]; } else { ! send_message(source, bot, MSG_MISSING_PARAMS, argv[0]); return; } if (!hi) { ! send_message(source, bot, N_("Handle not found -- did you register yet?")); return; } if (!valid_user_for(source, hi)) { ! send_message(source, bot, N_("Your hostmask is not valid.")); log(NS_LOG, LOG_OTHER, N_(IDENT_FORMAT" did not have a matching host for handle '%s'.\n"), IDENT_DATA(source), hi->handle); return; } if (!checkpass(passwd, hi->passwd)) { ! send_message(source, bot, MODMSG_PASSWORD_INVALID); log(NS_LOG, LOG_OTHER, N_(IDENT_FORMAT" had the wrong password for handle '%s'.\n"), IDENT_DATA(source), hi->handle); return; } if (HANDLE_FLAGGED(hi, SUSPENDED)) { ! send_message(source, bot, N_("Your handle has been suspended, and cannot be used.")); log(NS_LOG, LOG_OTHER, N_(IDENT_FORMAT" tried to auth to suspended handle '%s'.\n"), IDENT_DATA(source), hi->handle); return; } if ((reason = is_insecure_password(hi->handle, passwd))) { ! send_message(source, bot, N_("WARNING: You are using a password that is considered weak (easy to guess): %s. It is STRONGLY recommended you change it using the $bPASS$b command."), reason); } dict_remove(allow_auth_dict, source->nick); HANDLE_CLEAR_FLAG(hi, FROZEN); set_user_handle_info(source, hi); ! send_message(source, bot, N_("I recognize you.")); log(NS_LOG, LOG_INFO, N_(IDENT_FORMAT" was authenticated to handle '%s'.\n"), IDENT_DATA(source), hi->handle); } --- 384,416 ---- passwd = argv[1]; } else { ! send_message(bot, source, MSG_MISSING_PARAMS, argv[0]); return; } if (!hi) { ! send_message(bot, source, N_("Handle not found -- did you register yet?")); return; } if (!valid_user_for(source, hi)) { ! send_message(bot, source, N_("Your hostmask is not valid.")); log(NS_LOG, LOG_OTHER, N_(IDENT_FORMAT" did not have a matching host for handle '%s'.\n"), IDENT_DATA(source), hi->handle); return; } if (!checkpass(passwd, hi->passwd)) { ! send_message(bot, source, MODMSG_PASSWORD_INVALID); log(NS_LOG, LOG_OTHER, N_(IDENT_FORMAT" had the wrong password for handle '%s'.\n"), IDENT_DATA(source), hi->handle); return; } if (HANDLE_FLAGGED(hi, SUSPENDED)) { ! send_message(bot, source, N_("Your handle has been suspended, and cannot be used.")); log(NS_LOG, LOG_OTHER, N_(IDENT_FORMAT" tried to auth to suspended handle '%s'.\n"), IDENT_DATA(source), hi->handle); return; } if ((reason = is_insecure_password(hi->handle, passwd))) { ! send_message(bot, source, N_("WARNING: You are using a password that is considered weak (easy to guess): %s. It is STRONGLY recommended you change it using the $bPASS$b command."), reason); } dict_remove(allow_auth_dict, source->nick); HANDLE_CLEAR_FLAG(hi, FROZEN); set_user_handle_info(source, hi); ! send_message(bot, source, N_("I recognize you.")); log(NS_LOG, LOG_INFO, N_(IDENT_FORMAT" was authenticated to handle '%s'.\n"), IDENT_DATA(source), hi->handle); } *************** *** 371,381 **** if (argc < 2) { char *mask = generate_hostmask(source, GENMASK_OMITNICK); ! authserv_addmask(source, bot, source->handle_info, mask); free(mask); } else { if (is_gline(argv[1])) { ! authserv_addmask(source, bot, source->handle_info, argv[1]); } else { ! send_message(source, bot, N_("$b%s$b is an invalid hostmask."), argv[1]); } } --- 421,431 ---- if (argc < 2) { char *mask = generate_hostmask(source, GENMASK_OMITNICK); ! authserv_addmask(bot, source, source->handle_info, mask); free(mask); } else { if (is_gline(argv[1])) { ! authserv_addmask(bot, source, source->handle_info, argv[1]); } else { ! send_message(bot, source, N_("$b%s$b is an invalid hostmask."), argv[1]); } } *************** *** 390,416 **** MIN_PARMS(3, 0); if (!(target = GetUser(argv[1]))) { ! send_message(source, bot, MSG_NICK_UNKNOWN, argv[1]); return; } if (!strcasecmp(argv[2], "none")) hi = NULL; else if (!(hi = get_handle_info(argv[2]))) { ! send_message(source, bot, MSG_HANDLE_UNKNOWN, argv[2]); return; } if (hi) { if (hi->opserv_level > source->handle_info->opserv_level) { ! send_message(source, bot, MSG_USER_OUTRANKED, hi->handle); return; } dict_insert(allow_auth_dict, target->nick, hi); ! send_message(source, bot, N_("User $b%s$b may now authenticate to handle $b%s$b."), target->nick, hi->handle); send_message(target, bot, N_("You may now authenticate to handle $b%s$b by typing $b/msg $n auth %s password$b (using your password)."), hi->handle, hi->handle); log(NS_LOG, LOG_INFO, "%s allowed "IDENT_FORMAT" to authenticate to handle '%s'.\n", source->handle_info->handle, IDENT_DATA(target), hi->handle); } else { if (dict_remove(allow_auth_dict, target->nick)) { ! send_message(source, bot, N_("User $b%s$b may now only authenticate to handles with matching hostmasks."), target->nick); log(NS_LOG, LOG_INFO, "%s removed "IDENT_FORMAT"'s authorization to auth without hostmask.", source->handle_info->handle, IDENT_DATA(target)); } else { ! send_message(source, bot, N_("User $b%s$b did not have any special auth allowance."), target->nick); } } --- 440,466 ---- MIN_PARMS(3, 0); if (!(target = GetUser(argv[1]))) { ! send_message(bot, source, MSG_NICK_UNKNOWN, argv[1]); return; } if (!strcasecmp(argv[2], "none")) hi = NULL; else if (!(hi = get_handle_info(argv[2]))) { ! send_message(bot, source, MSG_HANDLE_UNKNOWN, argv[2]); return; } if (hi) { if (hi->opserv_level > source->handle_info->opserv_level) { ! send_message(bot, source, MSG_USER_OUTRANKED, hi->handle); return; } dict_insert(allow_auth_dict, target->nick, hi); ! send_message(bot, source, N_("User $b%s$b may now authenticate to handle $b%s$b."), target->nick, hi->handle); send_message(target, bot, N_("You may now authenticate to handle $b%s$b by typing $b/msg $n auth %s password$b (using your password)."), hi->handle, hi->handle); log(NS_LOG, LOG_INFO, "%s allowed "IDENT_FORMAT" to authenticate to handle '%s'.\n", source->handle_info->handle, IDENT_DATA(target), hi->handle); } else { if (dict_remove(allow_auth_dict, target->nick)) { ! send_message(bot, source, N_("User $b%s$b may now only authenticate to handles with matching hostmasks."), target->nick); log(NS_LOG, LOG_INFO, "%s removed "IDENT_FORMAT"'s authorization to auth without hostmask.", source->handle_info->handle, IDENT_DATA(target)); } else { ! send_message(bot, source, N_("User $b%s$b did not have any special auth allowance."), target->nick); } } *************** *** 421,431 **** (void)channel; MIN_PARMS(2, 0); ! authserv_delmask(source, bot, source->handle_info, argv[1]); } MODULE_COMMAND(cmd_handleinfo) { ! (void)source; (void)bot; (void)channel; (void)argc; (void)argv; ! /* TODO: implement cmd_handleinfo */ } --- 471,565 ---- (void)channel; MIN_PARMS(2, 0); ! authserv_delmask(bot, source, source->handle_info, argv[1]); } MODULE_COMMAND(cmd_handleinfo) { ! char buff[400]; ! unsigned int i, pos=0, herelen; ! struct user *target, *next_user; ! struct handle_info *hi; ! ! (void)channel; ! ! if (argc < 2) { ! if (!(hi = source->handle_info)) { ! send_message(bot, source, N_("You must authenticate first.")); ! return; ! } ! } else if (!(hi = smart_get_handle_info(bot, source, argv[1]))) { ! return; ! } ! ! send_message(bot, source, N_("Handle information for $b%s$b:"), hi->handle); ! send_message(bot, source, N_(" Registered on: %s"), ctime(&hi->registered)); ! ! if (!hi->users) { ! intervalString(buff, now - hi->lastseen); ! send_message(bot, source, N_(" Last seen: %s"), buff); ! } else { ! send_message(bot, source, N_(" Last seen: Right now!")); ! } ! ! if (hi->info[0]) send_message(bot, source, N_(" Infoline: %s"), hi->info); ! if (HANDLE_FLAGGED(hi, FROZEN)) send_message(bot, source, N_(" On vacation.")); ! ! /* Don't allow non-privileged users to look at somebody else's handle details. */ ! if (hi != source->handle_info ! && (!source->handle_info ! || !IsPrivileged(source) ! || !is_valid_oper(bot, source, 0))) { ! return; ! } ! ! if (hi->flags) { ! unsigned long flen = 1; ! char *flags = alloca(strlen(handle_flags) + 2); ! flags[0] = '+'; ! for (i=0, flen=1; handle_flags[i]; i++) { ! if (hi->flags & 1 << i) flags[flen++] = handle_flags[i]; ! } ! flags[flen] = 0; ! send_message(bot, source, N_("Flags: %s"), flags); ! } else { ! send_message(bot, source, N_("Flags: (none)")); ! } ! ! if (hi->masks->used) { ! for (i=0; i < hi->masks->used; i++) { ! herelen = strlen(hi->masks->list[i]); ! if (pos + herelen + 1 > ArrayLength(buff)) { ! i--; goto print_mask_buff; ! } ! memcpy(buff+pos, hi->masks->list[i], herelen); ! pos += herelen; buff[pos++] = ' '; ! if (i+1 == hi->masks->used) { ! print_mask_buff: ! buff[pos-1] = 0; ! send_message(bot, source, N_(" Hostmask(s): %s"), buff); ! pos = 0; ! } ! } ! } else { ! send_message(bot, source, N_(" Hostmask(s): (none)")); ! } ! ! for (target = hi->users; target; target = next_user) { ! herelen = strlen(target->nick); ! if (pos + herelen + 1 > ArrayLength(buff)) { ! next_user = target; ! goto print_cnick_buff; ! } else { ! next_user = target->next_authed; ! } ! memcpy(buff+pos, target->nick, herelen); ! pos += herelen; buff[pos++] = ' '; ! if (!next_user) { ! print_cnick_buff: ! buff[pos-1] = 0; ! send_message(bot, source, N_(" Current nickname(s): %s"), buff); ! pos = 0; ! } ! } } Index: authserv.h =================================================================== RCS file: /cvsroot/srvx/services/src/modules/authserv.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** authserv.h 2001/10/20 19:23:12 1.2 --- authserv.h 2001/10/22 13:51:11 1.3 *************** *** 52,56 **** --- 52,58 ---- #define HANDLE_CLEAR_FLAG(hi, tok) ((hi)->flags &= ~HI_FLAG_##tok) + #define IsHelper(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, HELPER)) #define IsHelping(user) (user->handle_info && HANDLE_FLAGGED(user->handle_info, HELPING)) + #define IsPrivileged(user) (IsOper(user) || IsHelping(user)) struct handle_info { *************** *** 71,76 **** 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); ! int authserv_addmask(struct user *user, struct user *bot, struct handle_info *hi, const char *mask); ! int authserv_delmask(struct user *source, struct user *bot, struct handle_info *hi, const char *del_mask); /* auth_funcs are called when a user gets a new handle_info. They are --- 73,80 ---- 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); ! struct handle_info *get_oper_victim(struct user *bot, struct user *source, const char *target); ! int authserv_addmask(struct user *bot, struct user *source, struct handle_info *hi, const char *mask); ! int authserv_delmask(struct user *bot, struct user *source, struct handle_info *hi, const char *del_mask); ! int is_valid_oper(struct user *bot, struct user *source, unsigned int min_level); /* auth_funcs are called when a user gets a new handle_info. They are |