[srvx-commits] CVS: services/src nickserv.c,1.259,1.260 nickserv.h,1.46,1.47
Brought to you by:
entrope
From: Entrope <en...@us...> - 2003-10-04 01:35:47
|
Update of /cvsroot/srvx/services/src In directory sc8-pr-cvs1:/tmp/cvs-serv15507/src Modified Files: nickserv.c nickserv.h Log Message: implement MAXLOGINS option for accounts (closes SF#774205) correctly iterate over second account's memberships when merging accounts (closes SF#797829) Index: nickserv.c =================================================================== RCS file: /cvsroot/srvx/services/src/nickserv.c,v retrieving revision 1.259 retrieving revision 1.260 diff -C2 -r1.259 -r1.260 *** nickserv.c 26 Sep 2003 15:28:17 -0000 1.259 --- nickserv.c 4 Oct 2003 01:35:40 -0000 1.260 *************** *** 92,95 **** --- 92,96 ---- #define KEY_TABLE_WIDTH "table_width" #define KEY_ANNOUNCEMENTS "announcements" + #define KEY_MAXLOGINS "maxlogins" #define NSMSG_RIGHT_NOW "Right now!" *************** *** 138,141 **** --- 139,144 ---- #define NSMSG_USER_PREV_AUTH "$b%s$b is already authenticated." #define NSMSG_USER_PREV_STAMP "$b%s$b has authenticated to an account once and cannot authenticate again." + #define NSMSG_BAD_MAX_LOGINS "MaxLogins must be at most %d." + #define NSMSG_MAX_LOGINS "Your account already has its limit of %d user(s) logged in." #define NSMSG_STAMPED_REGISTER "You have already authenticated to an account once this session; you may not register a new account." *************** *** 309,312 **** --- 312,317 ---- enum reclaim_action auto_reclaim_action; unsigned long auto_reclaim_delay; + unsigned char default_maxlogins; + unsigned char hard_maxlogins; } nickserv_conf; *************** *** 1426,1432 **** static NICKSERV_FUNC(cmd_auth) { ! int pw_arg; struct handle_info *hi; const char *passwd; if (user->handle_info) { --- 1431,1438 ---- static NICKSERV_FUNC(cmd_auth) { ! int pw_arg, used, maxlogins; struct handle_info *hi; const char *passwd; + struct userNode *other; if (user->handle_info) { *************** *** 1506,1517 **** return 1; } ! if (nickserv_conf.email_required && !hi->email_addr) { nickserv_notice(user, NSMSG_PLEASE_SET_EMAIL); ! } ! if (!is_secure_password(hi->handle, passwd, NULL)) { nickserv_notice(user, NSMSG_WEAK_PASSWORD); ! } ! if (hi->passwd[0] != '$') cryptpass(passwd, hi->passwd); nickserv_notice(user, NSMSG_AUTH_SUCCESS); --- 1512,1530 ---- return 1; } + maxlogins = hi->maxlogins ? hi->maxlogins : nickserv_conf.default_maxlogins; + for (used = 0, other = hi->users; other; other = other->next_authed) { + if (++used >= maxlogins) { + reply(NSMSG_MAX_LOGINS, maxlogins); + argv[pw_arg] = "MAXLOGINS"; + return 1; + } + } ! if (nickserv_conf.email_required && !hi->email_addr) nickserv_notice(user, NSMSG_PLEASE_SET_EMAIL); ! if (!is_secure_password(hi->handle, passwd, NULL)) nickserv_notice(user, NSMSG_WEAK_PASSWORD); ! if (hi->passwd[0] != '$') ! cryptpass(passwd, hi->passwd); nickserv_notice(user, NSMSG_AUTH_SUCCESS); *************** *** 1950,1967 **** { option_func_t *opt; ! unsigned int i = 0; char *set_display[] = { ! "INFO", "WIDTH", "TABLEWIDTH", "COLOR", "PRIVMSG", "STYLE", "EMAIL", "ANNOUNCEMENTS"}; nickserv_notice(user, NSMSG_SETTING_LIST); /* Do this so options are presented in a consistent order. */ ! while(i < ArrayLength(set_display)) ! { ! if((opt = dict_find(nickserv_opt_dict, set_display[i++], NULL))) ! { opt(user, hi, override, 0, NULL); - } - } } --- 1963,1978 ---- { option_func_t *opt; ! unsigned int i; char *set_display[] = { ! "INFO", "WIDTH", "TABLEWIDTH", "COLOR", "PRIVMSG", "STYLE", ! "EMAIL", "ANNOUNCEMENTS", "MAXLOGINS" ! }; nickserv_notice(user, NSMSG_SETTING_LIST); /* Do this so options are presented in a consistent order. */ ! for (i = 0; i < ArrayLength(set_display); ++i) ! if ((opt = dict_find(nickserv_opt_dict, set_display[i], NULL))) opt(user, hi, override, 0, NULL); } *************** *** 1990,1994 **** NICKSERV_MIN_PARMS(2); ! if (!(hi = get_victim_oper(user, argv[1]))) return 0; if (argc < 3) { --- 2001,2006 ---- NICKSERV_MIN_PARMS(2); ! if (!(hi = get_victim_oper(user, argv[1]))) ! return 0; if (argc < 3) { *************** *** 2213,2216 **** --- 2225,2244 ---- } + static OPTION_FUNC(opt_maxlogins) + { + unsigned char maxlogins; + if (argc > 1) { + maxlogins = strtoul(argv[1], NULL, 0); + if ((maxlogins > nickserv_conf.hard_maxlogins) && !override) { + nickserv_notice(user, NSMSG_BAD_MAX_LOGINS, nickserv_conf.hard_maxlogins); + return 0; + } + hi->maxlogins = maxlogins; + } + maxlogins = hi->maxlogins ? hi->maxlogins : nickserv_conf.default_maxlogins; + nickserv_notice(user, NSMSG_NUM_SETTING, "MAXLOGINS:", maxlogins); + return 1; + } + int oper_try_set_access(struct userNode *user, struct userNode *bot, struct handle_info *target, unsigned int new_level) { *************** *** 2493,2496 **** --- 2521,2525 ---- saxdb_write_int(ctx, KEY_LAST_SEEN, hi->lastseen); if (hi->masks->used) saxdb_write_string_list(ctx, KEY_MASKS, hi->masks); + if (hi->maxlogins) saxdb_write_int(ctx, KEY_MAXLOGINS, hi->maxlogins); if (hi->nicks) { struct string_list *slist; *************** *** 2574,2579 **** NICKSERV_MIN_PARMS(3); ! if (!(hi_from = get_victim_oper(user, argv[1]))) return 0; ! if (!(hi_to = get_victim_oper(user, argv[2]))) return 0; if (hi_to == hi_from) { nickserv_notice(user, NSMSG_CANNOT_MERGE_SELF, hi_to->handle); --- 2603,2610 ---- NICKSERV_MIN_PARMS(3); ! if (!(hi_from = get_victim_oper(user, argv[1]))) ! return 0; ! if (!(hi_to = get_victim_oper(user, argv[2]))) ! return 0; if (hi_to == hi_from) { nickserv_notice(user, NSMSG_CANNOT_MERGE_SELF, hi_to->handle); *************** *** 2581,2585 **** } ! for (n=0; n<handle_merge_func_used; n++) handle_merge_func_list[n](user, hi_to, hi_from); /* Append "from" handle's nicks to "to" handle's nick list. */ --- 2612,2617 ---- } ! for (n=0; n<handle_merge_func_used; n++) ! handle_merge_func_list[n](user, hi_to, hi_from); /* Append "from" handle's nicks to "to" handle's nick list. */ *************** *** 2597,2607 **** for (ii=0; ii<hi_from->masks->used; ii++) { char *mask = hi_from->masks->list[ii]; ! for (jj=0; jj<hi_to->masks->used; jj++) { ! if (match_ircglobs(hi_to->masks->list[jj], mask)) break; ! } ! if (jj==hi_to->masks->used) { ! /* Nothing from the "to" handle covered this mask, so add it. */ string_list_append(hi_to->masks, strdup(mask)); - } } --- 2629,2637 ---- for (ii=0; ii<hi_from->masks->used; ii++) { char *mask = hi_from->masks->list[ii]; ! for (jj=0; jj<hi_to->masks->used; jj++) ! if (match_ircglobs(hi_to->masks->list[jj], mask)) ! break; ! if (jj==hi_to->masks->used) /* Nothing from the "to" handle covered this mask, so add it. */ string_list_append(hi_to->masks, strdup(mask)); } *************** *** 2623,2635 **** struct userData *cList2; cListNext = cList->u_next; ! for (cList2=hi_to->channels; cList2; cList2=cList2->next) { ! if (cList->channel == cList2->channel) break; ! } if (cList2 && (cList2->access >= cList->access)) { /* keep cList2 in hi_to; remove cList from hi_from */ del_channel_user(cList, 1); } else { if (cList2) { ! /* hi_from handle has higher access; remove cList2 from hi_to */ del_channel_user(cList2, 1); } --- 2653,2671 ---- struct userData *cList2; cListNext = cList->u_next; ! for (cList2=hi_to->channels; cList2; cList2=cList2->u_next) ! if (cList->channel == cList2->channel) ! break; ! log_module(NS_LOG, LOG_DEBUG, "Merging %s->%s@%s: before %p->%p->%-p, %p->%p->%p", ! hi_from->handle, hi_to->handle, cList->channel->channel->name, ! cList->u_prev, cList, cList->u_next, ! (cList2?cList2->u_prev:0), cList2, (cList2?cList2->u_next:0)); if (cList2 && (cList2->access >= cList->access)) { /* keep cList2 in hi_to; remove cList from hi_from */ + log_module(NS_LOG, LOG_DEBUG, "Deleting %p", cList); del_channel_user(cList, 1); } else { if (cList2) { ! /* remove the lower-ranking cList2 from hi_to */ ! log_module(NS_LOG, LOG_DEBUG, "Deleting %p", cList2); del_channel_user(cList2, 1); } *************** *** 2637,2660 **** cList->handle = hi_to; /* Remove from linked list for hi_from */ ! if (cList->u_prev) cList->u_prev->next = cList->u_next; ! else hi_from->channels = cList->u_next; ! if (cList->u_next) cList->u_next->u_prev = cList->u_prev; /* Add to linked list for hi_to */ cList->u_prev = NULL; - if (hi_to->channels) hi_to->channels->u_prev = cList; cList->u_next = hi_to->channels; hi_to->channels = cList; } } /* Do they get an OpServ level promotion? */ ! if (hi_from->opserv_level > hi_to->opserv_level) { hi_to->opserv_level = hi_from->opserv_level; - } /* What about last seen time? */ ! if (hi_from->lastseen > hi_to->lastseen) { hi_to->lastseen = hi_from->lastseen; - } /* Notify of success. */ --- 2673,2698 ---- cList->handle = hi_to; /* Remove from linked list for hi_from */ ! assert(!cList->u_prev); ! hi_from->channels = cList->u_next; ! if (cList->u_next) ! cList->u_next->u_prev = cList->u_prev; /* Add to linked list for hi_to */ cList->u_prev = NULL; cList->u_next = hi_to->channels; + if (hi_to->channels) + hi_to->channels->u_prev = cList; hi_to->channels = cList; + log_module(NS_LOG, LOG_DEBUG, "Now %p->%p->%p", + cList->u_prev, cList, cList->u_next); } } /* Do they get an OpServ level promotion? */ ! if (hi_from->opserv_level > hi_to->opserv_level) hi_to->opserv_level = hi_from->opserv_level; /* What about last seen time? */ ! if (hi_from->lastseen > hi_to->lastseen) hi_to->lastseen = hi_from->lastseen; /* Notify of success. */ *************** *** 2960,2963 **** --- 2998,3005 ---- masks = database_get_data(obj, KEY_MASKS, RECDB_STRING_LIST); hi->masks = masks ? string_list_copy(masks) : alloc_string_list(1); + str = database_get_data(obj, KEY_MAXLOGINS, RECDB_QSTRING); + hi->maxlogins = str ? strtoul(str, NULL, 0) : 0; + if (hi->maxlogins > nickserv_conf.hard_maxlogins) + hi->maxlogins = nickserv_conf.hard_maxlogins; str = database_get_data(obj, KEY_OPSERV_LEVEL, RECDB_QSTRING); hi->opserv_level = str ? strtoul(str, NULL, 0) : 0; *************** *** 3187,3190 **** --- 3229,3236 ---- str = database_get_data(conf_node, "warn_clone_auth", RECDB_QSTRING); nickserv_conf.warn_clone_auth = str ? !disabled_string(str) : 1; + str = database_get_data(conf_node, "default_maxlogins", RECDB_QSTRING); + nickserv_conf.default_maxlogins = str ? strtoul(str, NULL, 0) : 2; + str = database_get_data(conf_node, "hard_maxlogins", RECDB_QSTRING); + nickserv_conf.hard_maxlogins = str ? strtoul(str, NULL, 0) : 10; if (!nickserv_conf.disable_nicks) { str = database_get_data(conf_node, "reclaim_action", RECDB_QSTRING); *************** *** 3397,3402 **** free(handle_merge_func_list); free(failpw_func_list); ! if (nickserv_conf.valid_handle_regex_set) regfree(&nickserv_conf.valid_handle_regex); ! if (nickserv_conf.valid_nick_regex_set) regfree(&nickserv_conf.valid_nick_regex); } --- 3443,3450 ---- free(handle_merge_func_list); free(failpw_func_list); ! if (nickserv_conf.valid_handle_regex_set) ! regfree(&nickserv_conf.valid_handle_regex); ! if (nickserv_conf.valid_nick_regex_set) ! regfree(&nickserv_conf.valid_nick_regex); } *************** *** 3482,3485 **** --- 3530,3534 ---- dict_insert(nickserv_opt_dict, "EPITHET", opt_epithet); dict_insert(nickserv_opt_dict, "ANNOUNCEMENTS", opt_announcements); + dict_insert(nickserv_opt_dict, "MAXLOGINS", opt_maxlogins); nickserv_handle_dict = dict_new(); Index: nickserv.h =================================================================== RCS file: /cvsroot/srvx/services/src/nickserv.h,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -r1.46 -r1.47 *** nickserv.h 9 Sep 2003 16:40:29 -0000 1.46 --- nickserv.h 4 Oct 2003 01:35:41 -0000 1.47 *************** *** 85,97 **** char *infoline; unsigned long flags; - unsigned int opserv_level; - unsigned int screen_width; - unsigned int table_width; time_t registered, lastseen; char *handle; char passwd[MD5_CRYPT_LENGTH+1]; char last_quit_host[USERLEN+HOSTLEN+2]; ! char userlist_style; ! char announcements; }; --- 85,98 ---- char *infoline; unsigned long flags; time_t registered, lastseen; char *handle; char passwd[MD5_CRYPT_LENGTH+1]; char last_quit_host[USERLEN+HOSTLEN+2]; ! unsigned short opserv_level; ! unsigned short screen_width; ! unsigned short table_width; ! unsigned char userlist_style; ! unsigned char announcements; ! unsigned char maxlogins; }; |