Exemple #1
0
void newserv_shutdown() {
  module *mods;
  char buf[1024];

  while (modules.cursi) {
    mods=(module *)(modules.content);

    strlcpy(buf, mods[0].name->content, sizeof(buf));

    /* Unload the module unless we're running on Valgrind -
     * in which case unloading the module would invalidate
     * stacktraces Valgrind has captured so far. */
    rmmod(buf, !RUNNING_ON_VALGRIND);
  }
  
  clearmoduledeps();

  if (moddir!=NULL)
    freesstring(moddir);

  if (modsuffix!=NULL)
    freesstring(modsuffix);

  Error("core",ERR_INFO,"All modules removed.  Exiting.");
}
Exemple #2
0
int tg_modify(trustgroup *oldtg, trustgroup *newtg) {
  trustgroup vnewtg;

  memcpy(&vnewtg, oldtg, sizeof(trustgroup));

  /* unfortunately we can't just memcpy the new one over */

  vnewtg.name = getsstring(newtg->name->content, TRUSTNAMELEN);
  vnewtg.createdby = getsstring(newtg->createdby->content, CREATEDBYLEN);
  vnewtg.contact = getsstring(newtg->contact->content, CONTACTLEN);
  vnewtg.comment = getsstring(newtg->comment->content, COMMENTLEN);
  if(!vnewtg.name || !vnewtg.createdby || !vnewtg.contact || !vnewtg.comment) {
    freesstring(vnewtg.name);
    freesstring(vnewtg.createdby);
    freesstring(vnewtg.contact);
    freesstring(vnewtg.comment);
    return 0;
  }

  /* id remains the same, count/hosts/marker/next/exts are ignored */
  vnewtg.trustedfor = newtg->trustedfor;
  vnewtg.flags = newtg->flags;
  vnewtg.maxperident = newtg->maxperident;
  vnewtg.maxusage = newtg->maxusage;
  vnewtg.expires = newtg->expires;
  vnewtg.lastseen = newtg->lastseen;
  vnewtg.lastmaxusereset = newtg->lastmaxusereset;

  memcpy(oldtg, &vnewtg, sizeof(trustgroup));

  return 1;
}
Exemple #3
0
void _fini(void) {
  struct service_node *tp, *lp;
  int i;

  if(ping)
    deregister_service(ping);

  for(tp=tree;tp;) {
    lp = tp;
    tp = tp->next;
    free_handlers(lp);
    ntfree(lp);
  }
  tree = NULL;

  if((accept_fd != -1) && nterfacer_sock) {
    esocket_clean_by_token(nterfacer_token);
    nterfacer_sock = NULL;
    accept_fd = -1;
  }

  if(permits && permit_count) {
    for(i=0;i<permit_count;i++) {
      freesstring(permits[i].hostname);
      freesstring(permits[i].password);
    }
    ntfree(permits);
    permit_count = 0;
    permits = NULL;
  }

  nrl = nterface_close_log(nrl);
  nscheckfreeall(POOL_NTERFACER);
}
Exemple #4
0
void modulerehash() {
  int i;
  sstring **mods;
  array *autoloads;
  
  if (moddir!=NULL)
    freesstring(moddir);
  
  if (modsuffix!=NULL)
    freesstring(modsuffix);

  clearmoduledeps();
  
  moddir=getcopyconfigitem("core","moduledir",".",100);
  modsuffix=getcopyconfigitem("core","modulesuffix",".so",5);  

  initmoduledeps();

  /* Check for auto-load modules */
  autoloads=getconfigitems("core","loadmodule");
  if (autoloads!=NULL) {
    mods=(sstring **)(autoloads->content);
    for (i=0;i<autoloads->cursi;i++) {
      insmod(mods[i]->content);
    }
  }
}
Exemple #5
0
void tg_free(trustgroup *tg, int created) {
  if(created)
    triggerhook(HOOK_TRUSTS_LOSTGROUP, tg);

  freesstring(tg->name);
  freesstring(tg->createdby);
  freesstring(tg->contact);
  freesstring(tg->comment);
  nsfree(POOL_TRUSTS, tg);
}
Exemple #6
0
void _fini(void) {
  int i;

  deleteallschedules(&patrol_sched_repool);

  for (i = 0; i < patrol_hostpoolsize; i++)
    freesstring(patrol_hostpool[i]);

  for (i = 0; i < patrol_tailpoolsize; i++)
    freesstring(patrol_tailpool[i]);
}
Exemple #7
0
hcensor *hcensor_del(hcensor **hcens, hcensor *ptr)
{
    for (;*hcens;hcens = &(*hcens)->next)
        if (*hcens == ptr)
        {
            hcensor *tmp = (*hcens)->next;
            freesstring((*hcens)->pattern);
            freesstring((*hcens)->reason);
            free (*hcens);
            *hcens = tmp;
            return NULL;
        }
    return ptr;
}
Exemple #8
0
int csc_docleartopic(void *source, int cargc, char **cargv) {
  nick *sender=source;
  chanindex *cip;
  regchan *rcp;

  if (cargc<1) {
    chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "cleartopic");
    return CMD_ERROR;
  }

  if (!(cip=cs_checkaccess(sender, cargv[0], CA_TOPICPRIV, 
			   NULL, "cleartopic", 0, 0)))
    return CMD_ERROR;

  rcp=cip->exts[chanservext];

  if (rcp->topic)
    freesstring(rcp->topic);

  rcp->topic=NULL;
  
  if (cip->channel) {
    localsettopic(chanservnick, cip->channel, "");
  }

  chanservstdmessage(sender, QM_DONE);
  csdb_updatechannel(rcp);
  return CMD_OK;
}
Exemple #9
0
void free_handler(struct handler *hp) {
  struct rline *li, *pi = NULL;

  for(li=rlines;li;) {
    if(li->handler == hp) {
      if(li->socket) {
        esocket_write_line(li->socket, "%d,OE%d,%s", li->id, BF_UNLOADED, "Service was unloaded.");
      } else if(li->callback) {
        nterfacer_sendcallback(li, BF_UNLOADED, "Service was unloaded.");
      }
      if(pi) {
        pi->next = li->next;
        ntfree(li);
        li = pi->next;
      } else {
        rlines = li->next;
        ntfree(li);
        li = rlines;
      }
    } else {
      pi=li,li=li->next;
    }
  }

  freesstring(hp->command);
  ntfree(hp);
}
Exemple #10
0
void lua_unloadscript(lua_list *l) {
  triggerhook(HOOK_LUA_UNLOADSCRIPT, l->l);

  lua_onunload(l->l);
  lua_deregisternicks(l);
  lua_socket_closeall(l);
  lua_scheduler_freeall(l);
  lua_close(l->l);
  freesstring(l->name);

  /* well, at least it's O(1) */

  if(!l->prev) { /* head */
    lua_head = l->next;
    if(!lua_head) {
      lua_tail = NULL;
    } else {
      lua_head->prev = NULL;
    }
  } else {
    if(!l->next) { /* tail */
      lua_tail = lua_tail->prev;
      if(!lua_tail) {
        lua_head = NULL;
      } else {
        lua_tail->next = NULL;
      }
    } else {
      l->prev->next = l->next;
      l->next->prev = l->prev;
     }
  }

  luafree(l);
}
Exemple #11
0
int handletopicmsg(void *source, int cargc, char **cargv) {
  channel *cp;
  nick *np;
  void *harg[2];
  time_t topictime=0, timestamp=0;
  
  if (cargc<2) {
    return CMD_OK;
  }
  
  if (cargc>2)
    topictime=strtol(cargv[cargc-2], NULL, 10);
  
  if (cargc>3)
    timestamp=strtol(cargv[cargc-3], NULL, 10);
  
  np=getnickbynumericstr((char *)source);

  /* The following check removed because servers can set topics.. */
#if 0
  if (np==NULL) {
    /* We should check the sender exists, but we still change the topic even if it doesn't */
    Error("channel",ERR_WARNING,"Topic change by non-existent user %s",(char *)source);
  }
#endif
  
  /* Grab channel pointer */
  if ((cp=findchannel(cargv[0]))==NULL) {
    /* We're not going to create a channel for the sake of a topic.. */
    return CMD_OK;
  } else {
    if (timestamp && (cp->timestamp < timestamp)) {
      /* Ignore topic change for younger channel 
       * (note that topic change for OLDER channel should be impossible!) */
      return CMD_OK;
    }
    if (topictime && (cp->topictime > topictime)) {
      /* Ignore topic change with older topic */
      return CMD_OK;
    }
    if (cp->topic!=NULL) {
      freesstring(cp->topic);
    }
    if (cargv[cargc-1][0]=='\0') {
      cp->topic=NULL;
      cp->topictime=0;
    } else {
      cp->topic=getsstring(cargv[cargc-1],TOPICLEN);
      cp->topictime=topictime?topictime:getnettime();
    }
    /* Trigger hook */
    harg[0]=cp;
    harg[1]=np;
    triggerhook(HOOK_CHANNEL_TOPIC,harg);
  }
  
  return CMD_OK;
}
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;
}
Exemple #13
0
void safereload(char *themodule) {
  if (safereload_str)
    freesstring(safereload_str);
  
  safereload_str=getsstring(themodule, 100);
  
  if (safereload_sched)
    deleteschedule(safereload_sched, safereloadcallback, NULL);
  
  scheduleoneshot(1, safereloadcallback, NULL);
}
Exemple #14
0
void _init(void) {
  char buf[32];
  sstring *m;

  snprintf(buf, sizeof(buf), "%d", PATROL_MINIMUM_HOSTS_BEFORE_POOL);
  m = getcopyconfigitem("patrol", "minpoolhosts", buf, 32);
  patrol_min_hosts = atoi(m->content);
  freesstring(m);

  scheduleoneshot(time(NULL) + 5, &patrol_sched_repool, NULL);
}
Exemple #15
0
void _fini(void) {
  int i;

  deregisterhook(HOOK_SERVER_NEWSERVER, &sphook_newserver);
  deregisterhook(HOOK_SERVER_LOSTSERVER, &sphook_lostserver);

  for (i = 0; i < splitlist.cursi; i++) {
    freesstring(((splitserver*)splitlist.content)[i].name);
  }

  array_free(&splitlist);
}
Exemple #16
0
int rmmod(char *modulename, int close) {
  int i,j;
  module *mods;
  struct module_dep *mdp;
  char modulebuf[1024];

  strlcpy(modulebuf, modulename, sizeof(modulebuf));
  delchars(modulebuf,"./\\;");
  
  i=getindex(modulebuf);
  if (i<0)
    return 1;

  if ((mdp=getmoduledep(modulebuf))) {
    for (j=0;j<mdp->numchildren;j++) {
      if (isloaded(mdp->children[j]->name->content)) {
        if (rmmod(mdp->children[j]->name->content, close)) {
          Error("core",ERR_WARNING,"Unable to remove child module %s (depends on %s)",
                 mdp->children[j]->name->content, modulebuf);
          return 1;
        }
      }
    }

    /* We may have removed other modules - reaquire the index number in case it has changed. */
    i=getindex(modulebuf);
    if (i<0)
      return 1;
  } else {
    Error("core",ERR_WARNING,"Removing module %s without dependency information",modulebuf);
  }
  
  mods=(module *)(modules.content);
    
  if (!close
#ifdef BROKEN_DLCLOSE
      || 1
#endif
     ) {
    void (*fini)();
    fini = dlsym(mods[i].handle, "__fini");
    if(!dlerror())
      fini();
  } else
    dlclose(mods[i].handle);

  freesstring(mods[i].name);
  array_delslot(&modules,i);

  Error("core",ERR_INFO,"Removed module %s.",modulebuf);
  
  return 0;
}    
Exemple #17
0
void sp_deletesplit(const char *name) {
  int i;

  if (splitlist.cursi == 0)
    return;

  for (i = splitlist.cursi - 1; i >= 0; i--) {
    if (strcmp(name, ((splitserver*)splitlist.content)[i].name->content) == 0) {
      freesstring(((splitserver*)splitlist.content)[i].name);
      array_delslot(&splitlist, i);
    }
  }
}
Exemple #18
0
void chanservcryptoinit(void) {
  int ret;

  FILE *e = fopen(ENTROPYSOURCE, "rb");
  if(!e) {
    Error("chanserv",ERR_STOP,"Unable to open entropy source."); 
    /* shouldn't be running now... */
  }

  ret = fread(rng.randrsl, 1, sizeof(rng.randrsl), e);
  fclose(e);

  if(ret != sizeof(rng.randrsl)) {
    Error("chanserv",ERR_STOP,"Unable to read entropy.");
    /* shouldn't be running now... */
  }

  prnginit(&rng, 1);

  secret=getcopyconfigitem("chanserv","secret","",128);
  if(!secret || !secret->content || !secret->content[0]) {
    unsigned char buf[32];
    char hexbuf[sizeof(buf) * 2 + 1];
    freesstring(secret);
    Error("chanserv",ERR_WARNING,"Shared secret not set, generating a random string...");

    cs_getrandbytes(buf, 32);
    hmac_printhex(buf, hexbuf, sizeof(buf));
    secret=getsstring(hexbuf, strlen(hexbuf));
  }
  codesecret=combinesecret("codegenerator");

  ticketsecret=getcopyconfigitem("chanserv","ticketsecret","",256);
  if(!ticketsecret || !ticketsecret->content[0]) {
    Error("chanserv",ERR_WARNING,"Ticket secret not set, ticketauth disabled.");
    freesstring(ticketsecret);
    ticketsecret = NULL;
  }
}
Exemple #19
0
void safereloadcallback(void *arg) {
  safereload_sched=NULL;
  
  if (!safereload_str)
    return;
  
  preparereload(safereload_str->content);
  rmmod(safereload_str->content, 1);
  insmod(safereload_str->content);
  reloadmarked();

  freesstring(safereload_str);
  safereload_str=NULL;
}
Exemple #20
0
void releasehost(host *hp) {
  host **mhp;
  if (--(hp->clonecount)==0) {
    for(mhp=&(hosttable[hosthash(hp->name->content)]);*mhp;mhp=(host **)&((*mhp)->next)) {
      if ((*mhp)==hp) {
        (*mhp)=(host *)hp->next;
        freesstring(hp->name);
        freehost(hp);
        return;
      }
    }
    Error("nick",ERR_ERROR,"Unable to remove host %s from hashtable",hp->name->content);
  }
}
Exemple #21
0
void fininickhelpers() {
  host *hnp, *hnpn;
  realname *rnp, *rnpn;
  int i;

  for(i=0;i<HOSTHASHSIZE;i++) {
    for(hnp=hosttable[i];hnp;hnp=hnpn) {
      hnpn=hnp->next;
      freesstring(hnp->name);
      freehost(hnp);
    }
    hosttable[i]=NULL;
  }

  for(i=0;i<REALNAMEHASHSIZE;i++) {
    for(rnp=realnametable[i];rnp;rnp=rnpn) {
      rnpn=rnp->next;
      freesstring(rnp->name);
      freerealname(rnp);
    }
    realnametable[i]=NULL;
  }
}
Exemple #22
0
void releaserealname(realname *rnp) {
  realname **mrnp;
  if (--(rnp->usercount)==0) {
    for(mrnp=&(realnametable[realnamehash(rnp->name->content)]);*mrnp;mrnp=(realname **)&((*mrnp)->next)) {
      if ((*mrnp)==rnp) {
        (*mrnp)=(realname *)rnp->next;
        freesstring(rnp->name);
        freerealname(rnp);
        return;
      }
    }
    Error("nick",ERR_ERROR,"Unable to remove realname %s from hashtable",rnp->name->content);
  }
}
Exemple #23
0
void __fini() {
#else
void _fini() {
#endif

  if(loaded) {
    if(startsched)
      deleteschedule(startsched, &lua_startup, NULL);

    while(lua_head)
      lua_unloadscript(lua_head);

    lua_destroybot();
    lua_destroycontrol();
  }

  freesstring(cpath);
  freesstring(suffix);
  freesstring(dummy.name);

  lua_freedebugsocket();
  nscheckfreeall(POOL_LUA);
}

void lua_loadscripts(void) {
  array *ls;

  ls = getconfigitems("lua", "script");
  if(!ls) {
    Error("lua", ERR_INFO, "No scripts loaded.");
  } else {
    sstring **scripts = (sstring **)(ls->content);
    int i;
    for(i=0;i<ls->cursi;i++)
      lua_loadscript(scripts[i]->content);
  }
}
Exemple #24
0
hchanban *hchanban_del(hchanban *hcban)
{
    hchanban **ptr = &hchanbans;
    for (;*ptr;ptr = &(*ptr)->next)
        if (*ptr == hcban)
        {
            hchanban *tmp = (*ptr)->next;
            freesstring((*ptr)->banmask);
            free(*ptr);
            *ptr = tmp;

            return NULL;
        }
    return hcban;
}
Exemple #25
0
hticket *hticket_del(hticket *htick, struct hchannel_struct *hchan)
{
    hticket **ptr;
    for (ptr = &hchan->htickets;*ptr;ptr = &(*ptr)->next)
        if (*ptr == htick)
        {
	    hticket *tmp = (*ptr)->next;
	    if ((*ptr)->message)
                freesstring((*ptr)->message);
            free(*ptr);
            *ptr = tmp;
            return NULL;
        }

    return htick;
}
Exemple #26
0
/* Clear out and free the dependencies. */
void clearmoduledeps() {
  unsigned int i;
  
  for (i=0;i<knownmodules;i++) {
    freesstring(moduledeps[i].name);
    if (moduledeps[i].parents) {
      free(moduledeps[i].parents);
      moduledeps[i].parents=NULL;
    }
    if (moduledeps[i].children) {
      free(moduledeps[i].children);
      moduledeps[i].children=NULL;
    }
  }
  
  knownmodules=0;
}
void lua_destroybot(void) {
  if(myutick)
    deleteschedule(myutick, &lua_tick, NULL);

  if(myublip)
    deleteschedule(myublip, &lua_blip, NULL);

  lua_deregisterevents();

  if (myureconnect)
    deleteschedule(myureconnect, &lua_startbot, NULL);

  if(lua_nick)
    deregisterlocaluser(lua_nick, NULL);

  if(luabotnick) {
    freesstring(luabotnick);
    luabotnick = NULL;
  }
}
Exemple #28
0
void _fini(void) {
  patrolchannel *pc, *next;

  deregistercontrolcmd("patroljoin", &pc_cmd_patroljoin);
  deregistercontrolcmd("patrolpart", &pc_cmd_patrolpart);
  deregistercontrolcmd("patrollist", &pc_cmd_patrollist);

  deleteallschedules(&pc_sched_check);

  for (pc = patrolchannels; pc; pc = next) {
    next = pc->next;

    freesstring(pc->channel);

    if (pc->nick)
      deregisterlocaluser(pc->nick, NULL);

    free(pc);
  }
}
Exemple #29
0
static int pc_part(char *name) {
  patrolchannel **pnext, *pc;

  for (pnext = &patrolchannels; *pnext; pnext = &((*pnext)->next)) {
    pc = *pnext;

    if (ircd_strcmp(pc->channel->content, name) == 0) {
      freesstring(pc->channel);

      if (pc->nick)
        deregisterlocaluser(pc->nick, NULL);

      *pnext = pc->next;
      free(pc);

      return 0;
    }
  }

  return -1;
}
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;
}