X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/92fac64ccdd4ffe3f79ae1e23f4b0b16dca0dc49..512d7958d12cef042c7324ad086cced98dc720bf:/src/nickserv.c diff --git a/src/nickserv.c b/src/nickserv.c index 1247f1f..9137435 100644 --- a/src/nickserv.c +++ b/src/nickserv.c @@ -176,7 +176,7 @@ static const struct message_entry msgtab[] = { { "NSMSG_ATE_FOREIGN_COOKIE", "I ate the cookie for account $b%s$b. It may now have another." }, { "NSMSG_USE_RENAME", "You are already authenticated to account $b%s$b -- contact the support staff to rename your account." }, { "NSMSG_ALREADY_REGISTERING", "You have already used $bREGISTER$b once this session; you may not use it again." }, - { "NSMSG_REGISTER_BAD_NICKMASK", "Could not recognize $b%s$b as either a current nick or a hostmask." }, + { "NSMSG_REGISTER_BAD_NICKMASK", "You must provide a hostmask, or online nick to generate one automatically. (or set a default hostmask in the config such as *@*)." }, { "NSMSG_NICK_NOT_REGISTERED", "Nick $b%s$b has not been registered to any account." }, { "NSMSG_HANDLE_NOT_FOUND", "Could not find your account -- did you register yet?" }, { "NSMSG_ALREADY_AUTHED", "You are already authed to account $b%s$b; you must reconnect to auth to a different account." }, @@ -809,7 +809,7 @@ oper_outranks(struct userNode *user, struct handle_info *hi) { return 0; } -static struct handle_info * +struct handle_info * get_victim_oper(struct userNode *user, const char *target) { struct handle_info *hi; @@ -1404,57 +1404,78 @@ static NICKSERV_FUNC(cmd_register) static NICKSERV_FUNC(cmd_oregister) { - char *mask; - struct userNode *settee; + struct userNode *settee = NULL; struct handle_info *hi; + char* account = NULL; + char* pass = NULL; + char* email = NULL; + char* mask = NULL; + char* nick = NULL; - NICKSERV_MIN_PARMS(nickserv_conf.email_required ? 4 : 3); - - if (!is_valid_handle(argv[1])) { - reply("NSMSG_BAD_HANDLE", argv[1]); - return 0; - } - + NICKSERV_MIN_PARMS(3); + + account = argv[1]; + pass = argv[2]; if (nickserv_conf.email_required) { - if (!valid_email(argv[4])) { - reply("NSMSG_BAD_EMAIL_ADDR"); - return 0; + NICKSERV_MIN_PARMS(4); + email = argv[3]; + if (argc >= 5) {/* take: "acct pass email mask nick" or "acct pass email mask" or "acct pass email nick" */ + if (strchr(argv[4], '@') || argc >= 6) /* If @, its mask not nick */ + mask = argv[4]; + else + nick = argv[4]; + } + if (argc >= 6) { + nick = argv[5]; } } - - if (strchr(argv[3], '@')) { - mask = canonicalize_hostmask(strdup(argv[3])); - if (argc > 4) { - settee = GetUserH(nickserv_conf.email_required ? argv[5] : argv[4]); - if (!settee) { - reply("MSG_NICK_UNKNOWN", nickserv_conf.email_required ? argv[5] : argv[4]); - free(mask); - return 0; - } - } else { - settee = NULL; - } - } else if ((settee = GetUserH(argv[3]))) { - mask = generate_hostmask(settee, GENMASK_OMITNICK|GENMASK_NO_HIDING|GENMASK_ANY_IDENT); - } else { - reply("NSMSG_REGISTER_BAD_NICKMASK", argv[3]); - return 0; + else { + if (argc >= 4) {/* take: "account pass mask nick" or "account pass mask" or "account pass nick" */ + if (strchr(argv[3], '@') || argc >= 5) /* If @, its mask not nick */ + mask = argv[3]; + else + nick = argv[3]; + } + if (argc >= 5) { + nick = argv[4]; + } } + /* If they passed a nick, look for that user.. */ + if (nick && !(settee = GetUserH(nick))) { + reply("MSG_NICK_UNKNOWN", argv[4]); + return 0; + } + /* If the setee is already authed, we cant add a 2nd account for them.. */ if (settee && settee->handle_info) { reply("NSMSG_USER_PREV_AUTH", settee->nick); - free(mask); return 0; } - if (!(hi = nickserv_register(user, settee, argv[1], argv[2], 0))) { - if (nickserv_conf.email_required) { - nickserv_set_email_addr(hi, argv[4]); - if (nickserv_conf.sync_log) - SyncLog("REGISTER %s %s %s %s", hi->handle, hi->passwd, argv[4], user->info); + /* If there is no default mask in the conf, and they didn't pass a mask, + * but we did find a user by nick, generate the mask */ + if (!mask) { + if (nickserv_conf.default_hostmask) + mask = "*@*"; + else if (settee) + mask = generate_hostmask(settee, GENMASK_OMITNICK|GENMASK_NO_HIDING|GENMASK_ANY_IDENT); + else { + reply("NSMSG_REGISTER_BAD_NICKMASK"); + return 0; } - free(mask); - return 0; } - string_list_append(hi->masks, mask); + + if (!(hi = nickserv_register(user, settee, account, pass, 0))) { + return 0; /* error reply handled by above */ + } + if (email) { + nickserv_set_email_addr(hi, email); + } + if (mask) { + char* mask_canonicalized = canonicalize_hostmask(strdup(mask)); + string_list_append(hi->masks, mask_canonicalized); + } + + if (nickserv_conf.sync_log) + SyncLog("REGISTER %s %s %s %s", hi->handle, hi->passwd, email ? email : "@", user->info); /* Send just @ for email if none */ return 1; } @@ -1463,11 +1484,11 @@ nickserv_ignore(struct userNode *user, struct handle_info *hi, const char *mask) { unsigned int i; struct userNode *target; - char *new_mask = canonicalize_hostmask(strdup(mask)); + char *new_mask = pretty_mask(strdup(mask)); for (i=0; iignores->used; i++) { if (!irccasecmp(new_mask, hi->ignores->list[i])) { send_message(user, nickserv, "NSMSG_ADDIGNORE_ALREADY", new_mask); - free(new_mask); +/* free(new_mask); i hate glibc */ return 0; } } @@ -1494,6 +1515,7 @@ static NICKSERV_FUNC(cmd_oaddignore) NICKSERV_MIN_PARMS(3); if (!(hi = get_victim_oper(user, argv[1]))) return 0; + return nickserv_ignore(user, hi, argv[2]); } @@ -1502,15 +1524,16 @@ nickserv_delignore(struct userNode *user, struct handle_info *hi, const char *de { unsigned int i; struct userNode *target; + char *dmask = pretty_mask(strdup(del_mask)); for (i=0; iignores->used; i++) { - if (!strcmp(del_mask, hi->ignores->list[i])) { + if (!strcmp(dmask, hi->ignores->list[i])) { char *old_mask = hi->ignores->list[i]; hi->ignores->list[i] = hi->ignores->list[--hi->ignores->used]; send_message(user, nickserv, "NSMSG_DELMASK_SUCCESS", old_mask); for (target = hi->users; target; target = target->next_authed) { irc_silence(user, old_mask, 0); } - free(old_mask); +/* free(old_mask); i hate glibc */ return 1; } }