Fix bugs; better handle oplevels from ircu2.10.12
[srvx.git] / src / nickserv.c
index b2f5afda1a08ddd8b138a443d2b45420b4251dee..d11c80ad15f2631a334da0fab3080cddf390141e 100644 (file)
@@ -179,6 +179,7 @@ static const struct message_entry msgtab[] = {
     { "NSMSG_STAMPED_RESETPASS", "You have already authenticated to an account once this session; you may not reset your password to authenticate again." },
     { "NSMSG_STAMPED_AUTHCOOKIE",  "You have already authenticated to an account once this session; you may not use a cookie to authenticate to another account." },
     { "NSMSG_TITLE_INVALID", "Titles cannot contain any dots; please choose another." },
+    { "NSMSG_TITLE_TRUNCATED", "That title combined with the user's account name would result in a truncated host; please choose a shorter title." },
     { "NSMSG_FAKEHOST_INVALID", "Fake hosts must be shorter than %d characters and cannot start with a dot." },
     { "NSMSG_HANDLEINFO_ON", "Account information for $b%s$b:" },
     { "NSMSG_HANDLEINFO_ID", "  Account ID: %lu" },
@@ -427,13 +428,6 @@ register_nick(const char *nick, struct handle_info *owner)
     dict_insert(nickserv_nick_dict, ni->nick, ni);
 }
 
-static void
-free_nick_info(void *vni)
-{
-    struct nick_info *ni = vni;
-    free(ni);
-}
-
 static void
 delete_nick(struct nick_info *ni)
 {
@@ -2443,6 +2437,12 @@ static OPTION_FUNC(opt_title)
             send_message(user, nickserv, "NSMSG_TITLE_INVALID");
             return 0;
         }
+        if ((strlen(user->handle_info->handle) + strlen(title) +
+             strlen(nickserv_conf.titlehost_suffix) + 2) > HOSTLEN) {
+            send_message(user, nickserv, "NSMSG_TITLE_TRUNCATED");
+            return 0;
+        }
+
         free(hi->fakehost);
         if (!strcmp(title, "*")) {
             hi->fakehost = NULL;
@@ -2474,7 +2474,7 @@ static OPTION_FUNC(opt_fakehost)
     if ((argc > 1) && oper_has_access(user, nickserv, nickserv_conf.set_fakehost_level, 0)) {
         fake = argv[1];
         if ((strlen(fake) > HOSTLEN) || (fake[0] == '.')) {
-            send_message(user, nickserv, "NSMSG_FAKEHOST_INVALID");
+            send_message(user, nickserv, "NSMSG_FAKEHOST_INVALID", HOSTLEN);
             return 0;
         }
         free(hi->fakehost);
@@ -2595,7 +2595,7 @@ static NICKSERV_FUNC(cmd_ounregister)
     if (!(hi = get_victim_oper(user, argv[1])))
         return 0;
     nickserv_unregister_handle(hi, user);
-    return 0;
+    return 1;
 }
 
 static NICKSERV_FUNC(cmd_status)
@@ -3819,7 +3819,7 @@ init_nickserv(const char *nick)
     dict_set_free_keys(nickserv_id_dict, free);
 
     nickserv_nick_dict = dict_new();
-    dict_set_free_data(nickserv_nick_dict, free_nick_info);
+    dict_set_free_data(nickserv_nick_dict, free);
 
     nickserv_allow_auth_dict = dict_new();