#include "sendmail.h"
#include "timeq.h"
-#ifdef HAVE_REGEX_H
#include <regex.h>
-#endif
#define NICKSERV_CONF_NAME "services/nickserv"
{ "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." },
return 0;
}
-static struct handle_info *
+struct handle_info *
get_victim_oper(struct userNode *user, const char *target)
{
struct handle_info *hi;
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;
}
{
unsigned int i;
struct userNode *target;
- char *new_mask = canonicalize_hostmask(strdup(mask));
+ char *new_mask = pretty_mask(strdup(mask));
for (i=0; i<hi->ignores->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;
}
}
NICKSERV_MIN_PARMS(3);
if (!(hi = get_victim_oper(user, argv[1])))
return 0;
+
return nickserv_ignore(user, hi, argv[2]);
}
{
unsigned int i;
struct userNode *target;
+ char *dmask = pretty_mask(strdup(del_mask));
for (i=0; i<hi->ignores->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;
}
}
qsort(hil.list, hil.used, sizeof(hil.list[0]), nickserv_sort_accounts_by_access);
tbl.length = hil.used + 1;
tbl.width = 2;
- tbl.flags = TABLE_NO_FREE;
+ tbl.flags = TABLE_NO_FREE | TABLE_REPEAT_ROWS | TABLE_REPEAT_HEADERS;
tbl.contents = malloc(tbl.length * sizeof(tbl.contents[0]));
tbl.contents[0] = ary = malloc(tbl.width * sizeof(ary[0]));
ary[0] = "Account";
tbl.contents[++ii] = ary;
}
table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
- reply("MSG_MATCH_COUNT", hil.used);
+ /*reply("MSG_MATCH_COUNT", hil.used); */
for (ii = 0; ii < hil.used; ii++)
free(tbl.contents[ii]);
free(tbl.contents);