]> jfr.im git - irc/quakenet/newserv.git/blobdiff - chanserv/usercmds/whois.c
CHANSERV: don't allow non-opers to see last realhosts in AUTHHISTORY / WHOIS
[irc/quakenet/newserv.git] / chanserv / usercmds / whois.c
index 47eaa7d9e81c7d8ab07cb8480911748b9183007e..8a3c59e444e2b9cc6e861c1a68b0e20919a4064c 100644 (file)
 #include "../chanserv.h"
 #include "../../lib/irc_string.h"
 #include "../../lib/strlfunc.h"
+#include "../../lib/ccassert.h"
 #include <stdio.h>
 #include <string.h>
 
 int csu_dowhois(void *source, int cargc, char **cargv) {
   nick *sender=source;
-  reguser *rup=getreguserfromnick(sender), *target;
+  reguser *rup, *target;
   char buf[200];
   char nbpos=0;
-  struct tm *tmp;
   regchanuser *rcup, *rcup2;
   flag_t flagmask, flags;
   int doneheader=0;
   authname *anp;
   nick *tnp;
 
+  CCASSERT(sizeof(buf) > TIMELEN);
+
   if (!(rup=getreguserfromnick(sender)))
     return CMD_ERROR;
   
@@ -66,9 +68,11 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
       flagmask=QUFLAG_ALL;
 
     if (UHasSuspension(target)) {
-      char expiresbuf[100], timebuf[100];
+      char expiresbuf[100];
       char *reason, *suspendtype, *whom;
 
+      CCASSERT(sizeof(expiresbuf) > TIMELEN);
+
       if(UIsDelayedGline(target)) {
         suspendtype = "delayed gline";
       } else if(UIsGline(target)) {
@@ -83,14 +87,13 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
         if(time(NULL) >= target->suspendexp) {
           strlcpy(expiresbuf, "(next auth)", sizeof(expiresbuf));
         } else {
-          strftime(expiresbuf, 15, "%d/%m/%y %H:%M", gmtime(&(target->suspendexp)));
+          q9strftime(expiresbuf, sizeof(expiresbuf), target->suspendexp);
         }
       } else {
         strlcpy(expiresbuf, "(never)", sizeof(expiresbuf));
       }
-      strftime(timebuf, 15, "%d/%m/%y %H:%M", gmtime(&(target->suspendtime)));
 
-      if(UHasOperPriv(rup)) {
+      if(cs_privcheck(QPRIV_VIEWSUSPENDEDBY, sender)) {
         reguser *trup = findreguserbyID(target->suspendby);
         if(trup) {
           whom = trup->username;
@@ -110,7 +113,7 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
       chanservstdmessage(sender, QM_USERSUSPENDEDTYPE, suspendtype);
       chanservstdmessage(sender, QM_USERSUSPENDEDBY, whom);
       chanservstdmessage(sender, QM_USERSUSPENDEDREASON, reason);
-      chanservstdmessage(sender, QM_USERSUSPENDEDAT, timebuf);
+      chanservstdmessage(sender, QM_USERSUSPENDEDAT, target->suspendtime);
       chanservstdmessage(sender, QM_USERSUSPENDEDEXPIRY, expiresbuf);
     }
   } else {  
@@ -131,8 +134,8 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
   }
 
   if (rup==target)
-    flagmask|=(QUFLAG_OPER | QUFLAG_DEV | QUFLAG_HELPER | 
-              QUFLAG_ADMIN | QUFLAG_INFO | QUFLAG_NOTICE | QUFLAG_STAFF);
+    flagmask|=(QUFLAG_OPER | QUFLAG_DEV | QUFLAG_HELPER | QUFLAG_ADMIN |
+              QUFLAG_INFO | QUFLAG_NOTICE | QUFLAG_STAFF | QUFLAG_ACHIEVEMENTS);
 
   if (flagmask & target->flags)
     chanservstdmessage(sender, QM_WHOIS_FLAGS, printflagsornone(flagmask & target->flags, ruflags));
@@ -153,35 +156,34 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
     }
   }
 
-  if (target->created) {
-    tmp=gmtime(&(target->created));
-    strftime(buf,15,"%d/%m/%y %H:%M",tmp);
-    
-    chanservstdmessage(sender, QM_WHOIS_CREATED, buf);
-  }
+  if (target->created)
+    chanservstdmessage(sender, QM_WHOIS_CREATED, target->created);
 
   if (target->lastauth == 0) {
     snprintf(buf,sizeof(buf),"(never)");
   } else {
-    tmp=gmtime(&(target->lastauth));
-    strftime(buf,15,"%d/%m/%y %H:%M",tmp);
+    q9strftime(buf,sizeof(buf),target->lastauth);
   }
   chanservstdmessage(sender, QM_WHOIS_LASTAUTH, buf);
   
-  if (target->lastuserhost && (rup==target || cs_privcheck(QPRIV_VIEWFULLWHOIS, sender))) {
+  /* The third clause of this hides user@host of opers from non-opered staff. */
+  if (target->lastuserhost && (rup==target || cs_privcheck(QPRIV_VIEWFULLWHOIS, sender)) &&
+      (!UHasOperPriv(target) || UHasOperPriv(rup)) ) {
 /* Commenting out language until we implement some - splidge 
     chanservstdmessage(sender, QM_WHOIS_USERLANG, cslanguages[target->languageid] ?
                       cslanguages[target->languageid]->name->content : "(unknown)");  */
-    chanservstdmessage(sender, QM_WHOIS_LASTUSERHOST, target->lastuserhost->content);
+    if(rup==target || cs_privcheck(QPRIV_VIEWREALHOST, sender)) {
+      chanservstdmessage(sender, QM_WHOIS_LASTUSERHOST, target->lastuserhost->content);
+    }
   }
 
   if (target->email && (rup==target || cs_privcheck(QPRIV_VIEWEMAIL, sender))) {
     chanservstdmessage(sender, QM_WHOIS_EMAIL, target->email->content);
 
-    tmp=gmtime(&(target->lastemailchange));
-    strftime(buf,15,"%d/%m/%y %H:%M",tmp);
-    
-    chanservstdmessage(sender, QM_WHOIS_EMAILSET, buf);    
+    if (target->lastemailchange)
+      chanservstdmessage(sender, QM_WHOIS_EMAILSET, target->lastemailchange);
+    if (target->lastpasschange)
+      chanservstdmessage(sender, QM_WHOIS_PASSSET, target->lastpasschange);
   }
 
   if (target->info && *target->info->content) {
@@ -225,5 +227,11 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
 
   chanservstdmessage(sender, QM_ENDOFLIST);
 
+  if (rup==target) {
+    triggerhook(HOOK_CHANSERV_WHOAMI, sender);
+  } else {
+    triggerhook(HOOK_CHANSERV_WHOIS, sender);
+  }
+
   return CMD_OK;
 }