Ejemplo n.º 1
0
int csa_doactivateuser(void *source, int cargc, char **cargv) {
  reguser *rup;
  nick *sender=(nick *)source;

  if(cargc<1) {
    controlreply(sender, "ACTIVATEUSER FALSE args");
    return CMD_ERROR;
  }

  rup = findreguserbyID(atoi(cargv[0]));
  if(rup == NULL) {
    controlreply(sender, "ACTIVATEUSER FALSE useridnotexist");
    return CMD_ERROR;
  }

  if(!UIsInactive(rup)) {
    controlreply(sender, "ACTIVATEUSER FALSE accountactive");
    return CMD_ERROR;
  }

  UClearInactive(rup);
  csdb_updateuser(rup);

  cs_log(sender,"ACTIVATEUSER OK username %s",rup->username);
  controlreply(sender, "ACTIVATEUSER TRUE");

  return CMD_OK;
}
Ejemplo n.º 2
0
int csa_doresendemail(void *source, int cargc, char **cargv) {
  reguser *rup;
  nick *sender=(nick *)source;

  if(cargc<1) {
    controlreply(sender, "RESENDEMAIL FALSE args");
    return CMD_ERROR;
  }

  rup = findreguserbyID(atoi(cargv[0]));
  if(rup == NULL) {
    controlreply(sender, "RESENDEMAIL FALSE useridnotexist");
    return CMD_ERROR;
  }

  if(!UIsInactive(rup)) {
    controlreply(sender, "RESENDEMAIL FALSE accountactive");
    return CMD_ERROR;
  }

  sendemail(rup);
  controlreply(sender, "RESENDEMAIL TRUE");
  cs_log(sender,"RESENDEMAIL OK username %s",rup->username);

  return CMD_OK;
}
Ejemplo n.º 3
0
int csa_dosetemail(void *source, int cargc, char **cargv) {
  char *email;
  char *error;
  reguser *rup;
  nick *sender=(nick *)source;

  if(cargc<3) {
    controlreply(sender, "SETEMAIL FALSE args");
    return CMD_ERROR;
  }

  rup = findreguserbyID(atoi(cargv[0]));
  if(rup == NULL) {
    controlreply(sender, "SETEMAIL FALSE useridnotexist");
    return CMD_ERROR;
  }

  if(UHasStaffPriv(rup)) {
    controlreply(sender, "SETEMAIL FALSE privuser");
    return CMD_ERROR;
  }

  if(UHasSuspension(rup)) {
    controlreply(sender, "SETEMAIL FALSE suspended");
    return CMD_ERROR;
  }

  if(rup->lastpasschange > atoi(cargv[1])) {
    controlreply(sender, "SETEMAIL FALSE passwordchanged");
    return CMD_ERROR;
  }

  email = cargv[2];

  if(!strcmp(email, rup->email->content)) {
    /* setting to the same thing? fine! */
    controlreply(sender, "SETEMAIL TRUE");
    return CMD_OK;
  }

  error = email_to_error(email);
  if(error) {
    controlreply(sender, "SETEMAIL FALSE %s", error);
    return CMD_ERROR;
  }

  freesstring(rup->email);
  rup->email=getsstring(email,EMAILLEN);
  cs_log(sender,"SETEMAIL OK username %s email %s",rup->username, rup->email->content);

  csdb_updateuser(rup);
  sendemail(rup);

  controlreply(sender, "SETEMAIL TRUE");

  return CMD_OK;
}
Ejemplo n.º 4
0
int csa_doaddchan(void *source, int cargc, char **cargv) {
  nick *sender=(nick *)source;
  reguser *rup = getreguserfromnick(sender), *founder;
  chanindex *cip;
  short type;
  regchan *rcp;

  if(cargc<3) {
    controlreply(sender, "ADDCHAN FALSE args");
    return CMD_ERROR;
  }

  if (*cargv[0] != '#' || strlen(cargv[0]) > CHANNELLEN) {
    controlreply(sender, "ADDCHAN FALSE invalidchannel");
    return CMD_ERROR;
  }

  if (!(cip=findorcreatechanindex(cargv[0]))) {
    controlreply(sender, "ADDCHAN FALSE invalidchannel");
    return CMD_ERROR;
  }

  founder = findreguserbyID(atoi(cargv[1]));
  if(founder == NULL) {
    controlreply(sender, "ADDCHAN FALSE useridnotexist");
    return CMD_ERROR;
  }

  if(UIsInactive(founder)) {
    controlreply(sender, "ADDCHAN FALSE accountinactive");
    return CMD_ERROR;
  }

  for(type=CHANTYPES-1;type;type--)
    if(!ircd_strcmp(chantypes[type]->content, cargv[2]))
      break;

  if(!type) {
    controlreply(sender, "ADDCHAN FALSE invalidchantype");
    return CMD_ERROR;
  }

  rcp = cs_addchan(cip, sender, rup, founder, QCFLAG_JOINED | QCFLAG_AUTOOP | QCFLAG_BITCH | QCFLAG_FORCETOPIC | QCFLAG_PROTECT | QCFLAG_TOPICSAVE, CHANMODE_NOCTCP | CHANMODE_DELJOINS | CHANMODE_MODNOAUTH | CHANMODE_NONOTICE | CHANMODE_NOEXTMSG | CHANMODE_SINGLETARG | CHANMODE_TOPICLIMIT | CHANMODE_NOQUITMSG, 0, type);
  if(!rcp) {
    controlreply(sender, "ADDCHAN FALSE alreadyregistered");
    return CMD_ERROR;
  }

  cs_log(sender, "ADDCHAN %s #%s %s %s", cip->name->content, founder->username, printflags(rcp->flags, rcflags), chantypes[type]->content);
  controlreply(sender, "ADDCHAN TRUE %u", rcp->ID);
  return CMD_OK;
}
Ejemplo n.º 5
0
int csa_dosettempemail(void *source, int cargc, char **cargv) {
  char *email;
  char *error;
  reguser *rup;
  nick *sender=(nick *)source;

  if(cargc<2) {
    controlreply(sender, "SETTEMPEMAIL FALSE args");
    return CMD_ERROR;
  }

  rup = findreguserbyID(atoi(cargv[0]));
  if(rup == NULL) {
    controlreply(sender, "SETTEMPEMAIL FALSE useridnotexist");
    return CMD_ERROR;
  }

  if(!UIsInactive(rup)) {
    controlreply(sender, "SETTEMPEMAIL FALSE accountactive");
    return CMD_ERROR;
  }

  email = cargv[1];
  error = email_to_error(email);
  if(error) {
    controlreply(sender, "SETTEMPEMAIL FALSE %s", error);
    return CMD_ERROR;
  }

  freesstring(rup->email);
  rup->email=getsstring(email,EMAILLEN);
  cs_log(sender,"SETTEMPEMAIL OK username %s email %s",rup->username, rup->email->content);

  csdb_updateuser(rup);
  sendemail(rup);

  controlreply(sender, "SETTEMPEMAIL TRUE");

  return CMD_OK;
}
Ejemplo n.º 6
0
void csc_dorollbackchan_real(DBConn *dbconn, void *arg) {
  nick *np=getnickbynumeric((unsigned long)arg);
  reguser *rup, *crup1, *crup2;
  chanindex *cip = NULL;
  regchan *rcp=NULL;
  regchanuser *rcup;
  unsigned int userID, channelID, targetID;
  time_t changetime, authtime;
  flag_t oldflags, newflags;
  DBResult *pgres;
  int j, newuser;
  char fbuf[18];

  if(!dbconn)
    return;

  pgres=dbgetresult(dbconn);

  if (!dbquerysuccessful(pgres)) {
    Error("chanserv", ERR_ERROR, "Error loading chanlev history data.");
    return;
  }

  if (dbnumfields(pgres) != 7) {
    Error("chanserv", ERR_ERROR, "Chanlev history data format error.");
    dbclear(pgres);
    return;
  }

  if (!np) {
    Error("chanserv", ERR_ERROR, "No nick pointer in rollback.");
    dbclear(pgres);
    return;
  }
  if (!(rup=getreguserfromnick(np)) || !UHasOperPriv(rup)) {
    Error("chanserv", ERR_ERROR, "No reguser pointer or oper privs in rollback.");
    dbclear(pgres);
    return;
  }

  while(dbfetchrow(pgres)) {
    userID=strtoul(dbgetvalue(pgres, 0), NULL, 10);
    channelID=strtoul(dbgetvalue(pgres, 1), NULL, 10);

    if (!rcp) {
      for (j=0; j<CHANNELHASHSIZE && !rcp; j++) {
        for (cip=chantable[j]; cip && !rcp; cip=cip->next) {
          if (!cip->exts[chanservext])
            continue;

          if (((regchan*)cip->exts[chanservext])->ID == channelID)
            rcp=(regchan*)cip->exts[chanservext];
        }
      }

      if (!rcp) {
        Error("chanserv", ERR_ERROR, "No regchan pointer or oper privs in rollback.");
        dbclear(pgres);
        return;
      }

      cip=rcp->index;

      chanservsendmessage(np, "Attempting to roll back %s:", cip->name->content);
    }
    targetID=strtoul(dbgetvalue(pgres, 2), NULL, 10);
    changetime=strtoul(dbgetvalue(pgres, 3), NULL, 10);
    authtime=strtoul(dbgetvalue(pgres, 4), NULL, 10);
    oldflags=strtoul(dbgetvalue(pgres, 5), NULL, 10);
    newflags=strtoul(dbgetvalue(pgres, 6), NULL, 10);
    strncpy(fbuf, printflags(newflags, rcuflags), 17);
    fbuf[17]='\0';
    crup1=findreguserbyID(userID);
    crup2=findreguserbyID(targetID);

    if (!crup2) {
      chanservsendmessage(np, "Affected user (ID: %d) is no longer in database, continuing...", targetID);
      continue;
    }

    if (!(rcup=findreguseronchannel(rcp, crup2))) {
      rcup=getregchanuser();
      rcup->user=crup2;
      rcup->chan=rcp;
      rcup->flags=0;
      rcup->changetime=time(NULL);
      rcup->usetime=0;
      rcup->info=NULL;
      newuser=1;
    }
    else
      newuser=0;
    csdb_chanlevhistory_insert(rcp, np, rcup->user, rcup->flags, oldflags);
    rcup->flags=oldflags;
    chanservsendmessage(np, "%s user flags for %s (%s -> %s)", newflags?oldflags?"Restoring":"Deleting":"Readding",
      crup2->username, fbuf, printflags(oldflags, rcuflags));

    if (rcup->flags) {
      if (newuser) {
        addregusertochannel(rcup);
        csdb_createchanuser(rcup);
      }
      else
        csdb_updatechanuser(rcup);
    }
    else {
      if (!newuser) {
        csdb_deletechanuser(rcup);
        delreguserfromchannel(rcp, crup2);
      }

      freesstring(rcup->info);
      freeregchanuser(rcup);
      rcup=NULL;

      for (j=0; j<REGCHANUSERHASHSIZE; j++)
        if (rcp->regusers[j])
          break;

      if (j==REGCHANUSERHASHSIZE) {
        cs_log(np, "DELCHAN %s (Cleared chanlev from rollback)", cip->name->content);
        chanservsendmessage(np, "Rollback cleared chanlev list, channel deleted.");
        rcp=NULL;
      }
    }
  }
  chanservstdmessage(np, QM_DONE);

  dbclear(pgres);
}
Ejemplo n.º 7
0
int csu_dosuspenduserlist(void *source, int cargc, char **cargv) {
  nick *sender=source;
  reguser *rup=getreguserfromnick(sender);
  reguser *dbrup, *trup;
  int i, seewhom;
  unsigned int count=0;
  char buf[TIMELEN], buf2[TIMELEN], *bywhom;
  time_t now=time(NULL);
  
  if (!rup)
    return CMD_ERROR;
  
  if (cargc < 1) {
    chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "suspenduserlist");
    return CMD_ERROR;
  }
  
  seewhom = cs_privcheck(QPRIV_VIEWSUSPENDEDBY, sender);
  if(!seewhom)
    bywhom = "(hidden)";

  /* @TIMELEN */
  chanservstdmessage(sender, QM_SUSPENDUSERLISTHEADER);
  for (i=0;i<REGUSERHASHSIZE;i++) {
    for (dbrup=regusernicktable[i]; dbrup; dbrup=dbrup->nextbyname) {
      if (!UHasSuspension(dbrup))
        continue;
      
      if (!match(cargv[0], dbrup->username)) {
        char suspendtype[100];
        
        if (UIsDelayedGline(dbrup))
          strcpy(suspendtype, "delayed gline");
        else if (UIsGline(dbrup))
          strcpy(suspendtype, "instant gline");
        else if (UIsSuspended(dbrup))
          strcpy(suspendtype, "suspended");
        else
          strcpy(suspendtype, "not used");
        
        if(seewhom) {
          trup=findreguserbyID(dbrup->suspendby);
          if (trup)
            bywhom=trup->username;
          else
            bywhom="(unknown)";
        }

        if (dbrup->suspendexp)
          q9strftime(buf,sizeof(buf),dbrup->suspendexp);
        
        q9strftime(buf2,sizeof(buf2),dbrup->suspendtime);

        count++;

        /* @TIMELEN */
        chanservsendmessage(sender, "%-15s %-13s %-15s %-19s %-19s %s", dbrup->username, suspendtype, bywhom, buf2, (dbrup->suspendexp)?((now >= dbrup->suspendexp)?"next auth":buf):"never", dbrup->suspendreason?dbrup->suspendreason->content:"(none)");
        if (count >= 2000) {
          chanservstdmessage(sender, QM_TOOMANYRESULTS, 2000, "users");
          return CMD_ERROR;
        }
      }
    }
  }
  chanservstdmessage(sender, QM_RESULTCOUNT, count, "user", (count==1)?"":"s");
  
  return CMD_OK;
}