]> jfr.im git - irc/atheme/atheme.git/commitdiff
nickserv/resetpass: reduce duplicated code, honor frozen flag
authorMantas Mikulėnas <redacted>
Wed, 18 Feb 2015 22:15:28 +0000 (00:15 +0200)
committerMantas Mikulėnas <redacted>
Wed, 18 Feb 2015 22:15:32 +0000 (00:15 +0200)
modules/nickserv/resetpass.c
modules/nickserv/sendpass_user.c

index 48717a74b2e6670717220d04a9c2f3ffb0d84597..8de99c52c2231c2cd45e10ccd32003f04f508005 100644 (file)
@@ -56,28 +56,32 @@ static void ns_cmd_resetpass(sourceinfo_t *si, int parc, char *parv[])
                return;
        }
 
-       if ((md = metadata_find(mu, "private:mark:setter")) && has_priv(si, PRIV_MARK))
+       if (metadata_find(mu, "private:freeze:freezer"))
        {
-               wallops("%s reset the password for the \2MARKED\2 account %s.", get_oper_name(si), entity(mu)->name);
-               logcommand(si, CMDLOG_ADMIN, "RESETPASS: \2%s\2 (overriding mark by \2%s\2)", entity(mu)->name, md->value);
-               command_success_nodata(si, _("Overriding MARK placed by %s on the account %s."), md->value, entity(mu)->name);
-
-               newpass = random_string(12);
-               set_password(mu, newpass);
-               command_success_nodata(si, _("The password for \2%s\2 has been changed to \2%s\2."), entity(mu)->name, newpass);
-               free(newpass);
+               command_fail(si, fault_noprivs, _("%s has been frozen by the %s administration."), entity(mu)->name, me.netname);
                return;
        }
 
        if ((md = metadata_find(mu, "private:mark:setter")))
        {
-               logcommand(si, CMDLOG_ADMIN, "failed RESETPASS \2%s\2 (marked by \2%s\2)", entity(mu)->name, md->value);
-               command_fail(si, fault_badparams, _("This operation cannot be performed on %s, because the account has been marked by %s."), entity(mu)->name, md->value);
-               return;
+               if (has_priv(si, PRIV_MARK))
+               {
+                       wallops("%s reset the password for the \2MARKED\2 account %s.", get_oper_name(si), entity(mu)->name);
+                       logcommand(si, CMDLOG_ADMIN, "RESETPASS: \2%s\2 (overriding mark by \2%s\2)", entity(mu)->name, md->value);
+                       command_success_nodata(si, _("Overriding MARK placed by %s on the account %s."), md->value, entity(mu)->name);
+               }
+               else
+               {
+                       logcommand(si, CMDLOG_ADMIN, "failed RESETPASS \2%s\2 (marked by \2%s\2)", entity(mu)->name, md->value);
+                       command_fail(si, fault_badparams, _("This operation cannot be performed on %s, because the account has been marked by %s."), entity(mu)->name, md->value);
+                       return;
+               }
+       }
+       else
+       {
+               wallops("%s reset the password for the account %s", get_oper_name(si), entity(mu)->name);
+               logcommand(si, CMDLOG_ADMIN, "RESETPASS: \2%s\2", entity(mu)->name);
        }
-
-       wallops("%s reset the password for the account %s", get_oper_name(si), entity(mu)->name);
-       logcommand(si, CMDLOG_ADMIN, "RESETPASS: \2%s\2", entity(mu)->name);
 
        metadata_delete(mu, "private:setpass:key");
        metadata_delete(mu, "private:sendpass:sender");
@@ -85,13 +89,14 @@ static void ns_cmd_resetpass(sourceinfo_t *si, int parc, char *parv[])
 
        newpass = random_string(12);
        set_password(mu, newpass);
-       command_success_nodata(si, _("The password for \2%s\2 has been changed to \2%s\2."), entity(mu)->name, newpass);
        free(newpass);
 
+       command_success_nodata(si, _("The password for \2%s\2 has been changed to \2%s\2."), entity(mu)->name, newpass);
+
        if (mu->flags & MU_NOPASSWORD)
        {
                mu->flags &= ~MU_NOPASSWORD;
-               command_success_nodata(si, _("The NOPASSWORD flag for \2%s\2 has been disabled."), entity(mu)->name);
+               command_success_nodata(si, _("The \2%s\2 flag has been removed for account \2%s\2."), "NOPASSWORD", entity(mu)->name);
        }
 }
 
index af3f353adca56d40edf6b2dcc80f91fb12c975c5..25cc605ee815b36adb50e98f266599812612391b 100644 (file)
@@ -114,7 +114,7 @@ static void ns_cmd_sendpass(sourceinfo_t *si, int parc, char *parv[])
 
        if (metadata_find(mu, "private:freeze:freezer"))
        {
-               command_success_nodata(si, _("%s has been frozen by the %s administration."), entity(mu)->name, me.netname);
+               command_fail(si, fault_noprivs, _("%s has been frozen by the %s administration."), entity(mu)->name, me.netname);
                return;
        }