]> jfr.im git - irc/quakenet/newserv.git/blobdiff - chanserv/authcmds/authhistory.c
Merge - fixed conflicts in chanserv/authcmds/authhistory.c.
[irc/quakenet/newserv.git] / chanserv / authcmds / authhistory.c
index 9ca20a73ae097c0565439cbd3956c48d6754ee5e..44f32a278a105cfb68edd88462ba789744828697 100644 (file)
@@ -3,7 +3,7 @@
  *
  * CMDNAME: authhistory
  * CMDLEVEL: QCMD_AUTHED
- * CMDARGS: 1
+ * CMDARGS: 2
  * CMDDESC: View auth history for an account.
  * CMDFUNC: csa_doauthhistory
  * CMDPROTO: int csa_doauthhistory(void *source, int cargc, char **cargv);
@@ -33,8 +33,7 @@ void csdb_doauthhistory_real(DBConn *dbconn, void *arg) {
   time_t ahauthtime, ahdisconnecttime;
   DBResult *pgres;
   int count=0;
-  struct tm *tmp;
-  char tbuf1[15], tbuf2[15], uhbuf[51];
+  char tbuf1[TIMELEN], tbuf2[TIMELEN], uhbuf[NICKLEN+HOSTLEN+USERLEN+5];
 
   if(!dbconn) {
     free(ahi);
@@ -67,7 +66,7 @@ void csdb_doauthhistory_real(DBConn *dbconn, void *arg) {
     free(ahi);
     return;
   }
-  chanservstdmessage(np, QM_AUTHHISTORYHEADER);
+  chanservstdmessage(np, QM_AUTHHISTORYHEADER); /* @TIMELEN */
   while(dbfetchrow(pgres)) {
     if (!UHasHelperPriv(rup) && (strtoul(dbgetvalue(pgres, 0), NULL, 10) != rup->ID)) {
       dbclear(pgres);
@@ -79,14 +78,13 @@ void csdb_doauthhistory_real(DBConn *dbconn, void *arg) {
     ahhost=dbgetvalue(pgres, 3);
     ahauthtime=strtoul(dbgetvalue(pgres, 4), NULL, 10);
     ahdisconnecttime=strtoul(dbgetvalue(pgres, 5), NULL, 10);
-    tmp=gmtime(&ahauthtime);
-    strftime(tbuf1, sizeof(tbuf1), Q9_FORMAT_TIME, tmp);
-    if (ahdisconnecttime) {
-      tmp=gmtime(&ahdisconnecttime);
-      strftime(tbuf2, sizeof(tbuf2), Q9_FORMAT_TIME, tmp);
-    }
-    snprintf(uhbuf,50,"%s!%s@%s", ahnick, ahuser, ahhost);
-    chanservsendmessage(np, "#%-2d %-50s %-15s %-15s %s", ++count, uhbuf, tbuf1, ahdisconnecttime?tbuf2:"never", dbgetvalue(pgres,6));
+
+    q9strftime(tbuf1, sizeof(tbuf1), ahauthtime);
+    if (ahdisconnecttime)
+      q9strftime(tbuf2, sizeof(tbuf2), ahdisconnecttime);
+
+    snprintf(uhbuf,sizeof(uhbuf),"%s!%s@%s", ahnick, ahuser, ahhost);
+    chanservsendmessage(np, "#%-2d %-50s %-19s %-19s %s", ++count, uhbuf, tbuf1, ahdisconnecttime?tbuf2:"never", dbgetvalue(pgres,6)); /* @TIMELEN */
   }
   chanservstdmessage(np, QM_ENDOFLIST);
 
@@ -96,36 +94,67 @@ void csdb_doauthhistory_real(DBConn *dbconn, void *arg) {
 
 void csdb_retreiveauthhistory(nick *np, reguser *rup, int limit) {
   struct authhistoryinfo *ahi;
+  char limitstr[30];
+
+  if (limit) {
+    sprintf(limitstr, " limit %d",limit);
+  } else {
+    limitstr[0]='\0';
+  }
 
   ahi=(struct authhistoryinfo *)malloc(sizeof(struct authhistoryinfo));
   ahi->numeric=np->numeric;
   ahi->userID=rup->ID;
   q9a_asyncquery(csdb_doauthhistory_real, (void *)ahi,
     "SELECT userID, nick, username, host, authtime, disconnecttime, quitreason from chanserv.authhistory where "
-    "userID=%u order by authtime desc limit %d", rup->ID, limit);
+    "userID=%u order by authtime desc%s", rup->ID, limitstr);
 }
 
 int csa_doauthhistory(void *source, int cargc, char **cargv) {
   reguser *rup, *trup;
   nick *sender=source;
-
+  unsigned int arg=0;
+  unsigned int limit=10;
+  
   if (!(rup=getreguserfromnick(sender)))
     return CMD_ERROR;
 
-  if (cargc >= 1) {
-    if (!(trup=findreguser(sender, cargv[0])))
-      return CMD_ERROR;
+  if (cargc) {
+    if (!ircd_strcmp(cargv[0], "-a")) {
+      if (UHasOperPriv(rup))
+        limit=0;
+      
+      arg++;
+    }
+  }
 
-    /* don't allow non-opers to view oper auth history, but allow helpers to view non-oper history */
-    if ((trup != rup) && ((UHasOperPriv(trup) && !UHasOperPriv(rup)) || !UHasHelperPriv(rup))) {
-      chanservstdmessage(sender, QM_NOACCESSONUSER, "authhistory", cargv[0]);
+  if (cargc > arg) {
+    if (!(trup=findreguser(sender, cargv[arg])))
       return CMD_ERROR;
+
+    /* if target != command issuer */
+    if (trup != rup) {
+      /* only opers and helpers can view authhistory of other users */
+      if (!UHasHelperPriv(rup)) {
+        chanservstdmessage(sender, QM_NOACCESSONUSER, "authhistory", cargv[arg]);
+        return CMD_ERROR;
+      }
+
+      /* and only opers can view opers history */
+      if (UHasOperPriv(trup) && !UHasOperPriv(rup)) {
+        chanservwallmessage("%s (%s) just FAILED using AUTHHISTORY on %s", sender->nick, rup->username, trup->username);
+        chanservstdmessage(sender, QM_NOACCESSONUSER, "authhistory", cargv[arg]);
+        return CMD_ERROR;
+      }
+
+      /* checks passed */
+      chanservwallmessage("%s (%s) used AUTHHISTORY on %s", sender->nick, rup->username, trup->username);
     }
   } else {
     trup=rup;
   }
-  
-  csdb_retreiveauthhistory(sender, trup, 10);
+
+  csdb_retreiveauthhistory(sender, trup, limit);
 
   return CMD_OK;
 }