Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_oper.c
index 8de332648edbf5f7e236963f1d22fe1edd58009c..3681506e15385512b8cb1cacaefc6af848f526ee 100644 (file)
 #include "s_conf.h"
 #include "s_debug.h"
 #include "s_user.h"
+#include "s_misc.h"
 #include "send.h"
+#include "support.h"
 
 #include <assert.h>
 #include <stdlib.h>
@@ -116,12 +118,7 @@ int oper_password_match(const char* to_match, const char* passwd)
    * passwd may be NULL. Head it off at the pass...
    */
   if (to_match && passwd) {
-    char salt[3];
-    const char* encr;
-    salt[0] = passwd[0];
-    salt[1] = passwd[1];
-    salt[2] = '\0';
-    encr = ircd_crypt(to_match, salt);
+    const char *encr = ircd_crypt(to_match, passwd);
     return (0 == strcmp(encr, passwd));
   }
   return 0;
@@ -151,27 +148,27 @@ int m_oper(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   if (EmptyString(name) || EmptyString(password))
     return need_more_params(sptr, "OPER");
 
-  aconf = find_conf_exact(name, sptr->username, sptr->sockhost, CONF_OPS);
+  aconf = find_conf_exact(name, cli_username(sptr), cli_sockhost(sptr), CONF_OPS);
   if (!aconf) 
-    aconf = find_conf_exact(name, sptr->username,
-                            ircd_ntoa((const char*) &cptr->ip), CONF_OPS);
+    aconf = find_conf_exact(name, cli_username(sptr),
+                            ircd_ntoa((const char*) &(cli_ip(cptr))), CONF_OPS);
 
   if (!aconf || IsIllegal(aconf)) {
     send_reply(sptr, ERR_NOOPERHOST);
     sendto_opmask_butone(0, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s)",
-                        parv[0], sptr->user->username, sptr->sockhost);
+                        parv[0], cli_user(sptr)->username, cli_sockhost(sptr));
     return 0;
   }
   assert(0 != (aconf->status & CONF_OPS));
 
   if (oper_password_match(password, aconf->passwd)) {
-    unsigned int old_mode = (sptr->flags & ALL_UMODES);
+    unsigned int old_mode = (cli_flags(sptr) & ALL_UMODES);
 
     if (ACR_OK != attach_conf(sptr, aconf)) {
       send_reply(sptr, ERR_NOOPERHOST);
       sendto_opmask_butone(0, SNO_OLDREALOP, "Failed OPER attempt by %s "
-                          "(%s@%s)", parv[0], sptr->user->username,
-                          sptr->sockhost);
+                          "(%s@%s)", parv[0], cli_user(sptr)->username,
+                          cli_sockhost(sptr));
       return 0;
     }
     if (CONF_LOCOP == aconf->status) {
@@ -186,31 +183,25 @@ int m_oper(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
       SetOper(sptr);
       ++UserStats.opers;
     }
-    cptr->handler = OPER_HANDLER;
+    cli_handler(cptr) = OPER_HANDLER;
 
     
-    sptr->flags |= (FLAGS_WALLOP | FLAGS_SERVNOTICE | FLAGS_DEBUG);
+    cli_flags(sptr) |= (FLAGS_WALLOP | FLAGS_SERVNOTICE | FLAGS_DEBUG);
 
     set_snomask(sptr, SNO_OPERDEFAULT, SNO_ADD);
     send_umode_out(cptr, sptr, old_mode);
     send_reply(sptr, RPL_YOUREOPER);
 
     sendto_opmask_butone(0, SNO_OLDSNO, "%s (%s@%s) is now operator (%c)",
-                        parv[0], sptr->user->username, sptr->sockhost,
+                        parv[0], cli_user(sptr)->username, cli_sockhost(sptr),
                         IsOper(sptr) ? 'O' : 'o');
 
-    ircd_log(L_INFO, "OPER (%s) by (%s!%s@%s)",
-             name, parv[0], sptr->user->username, sptr->sockhost);
-#ifdef FNAME_OPERLOG
-    if (IsUser(sptr))
-      write_log(FNAME_OPERLOG,
-                "%s OPER (%s) by (%#C)\n", myctime(CurrentTime), name, sptr);
-#endif
+    log_write(LS_OPER, L_INFO, 0, "OPER (%s) by (%#C)", name, sptr);
   }
   else {
     send_reply(sptr, ERR_PASSWDMISMATCH);
     sendto_opmask_butone(0, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s)",
-                        parv[0], sptr->user->username, sptr->sockhost);
+                        parv[0], cli_user(sptr)->username, cli_sockhost(sptr));
   }
   return 0;
 }
@@ -227,7 +218,7 @@ int ms_oper(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
    */
   if (!IsServer(sptr) && !IsOper(sptr)) {
     ++UserStats.opers;
-    sptr->flags |= FLAGS_OPER;
+    cli_flags(sptr) |= FLAGS_OPER;
     sendcmdto_serv_butone(sptr, CMD_MODE, cptr, "%s :+o", parv[0]);
   }
   return 0;
@@ -344,11 +335,11 @@ int m_oper(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     send_umode_out(cptr, sptr, old);
     sendto_one(sptr, rpl_str(RPL_YOUREOPER), me.name, parv[0]); /* XXX DEAD */
 
-    ircd_log(L_INFO, "OPER (%s) by (%s!%s@%s)",
+    ircd_log(L_INFO, "OPER (%s) by (%s!%s@%s)", /* XXX DEAD */
              name, parv[0], sptr->user->username, sptr->sockhost);
 #ifdef FNAME_OPERLOG
     if (IsUser(sptr))
-      write_log(FNAME_OPERLOG,
+      write_log(FNAME_OPERLOG, /* XXX DEAD */
           "%s OPER (%s) by (%s!%s@%s)\n", myctime(CurrentTime),
           name, parv[0], sptr->user->username, sptr->sockhost);
 #endif