Beispiel #1
0
/** Find an existing module instance and verify it implements the specified method
 *
 * Extracts the method from the module name where the format is @verbatim <module>.<method> @endverbatim
 * and ensures the module implements the specified method.
 *
 * @param[out] method		the method component we found associated with the module. May be NULL.
 * @param[in] modules		section in the main config.
 * @param[in] name 		The name of the module we're attempting to find, concatenated with
 *				the method.
 * @return
 *	- The module instance on success.
 *	- NULL on error (or not found).
 */
module_instance_t *module_find_with_method(rlm_components_t *method, CONF_SECTION *modules, char const *name)
{
	char			*p;
	rlm_components_t	i;
	module_instance_t	*mi;

	/*
	 *	Module names are allowed to contain '.'
	 *	so we search for the bare module name first.
	 */
	mi = module_find(modules, name);
	if (mi) return mi;

	/*
	 *	Find out if the instance name contains
	 *	a method, if it doesn't, then the module
	 *	doesn't exist.
	 */
	p = strrchr(name, '.');
	if (!p) return NULL;

	/*
	 *	Find the component.
	 */
	for (i = MOD_AUTHENTICATE; i < MOD_COUNT; i++) {
		if (strcmp(p + 1, section_type_value[i].section) == 0) {
			char *inst_name;

			inst_name = talloc_bstrndup(NULL, name, p - name);
			mi = module_find(modules, inst_name);
			talloc_free(inst_name);
			if (!mi) return NULL;

			/*
			 *	Verify the module actually implements
			 *	the specified method.
			 */
			if (!mi->module->methods[i]) {
				cf_log_debug(modules, "%s does not implement method \"%s\"",
					     mi->module->name, p + 1);
				return NULL;
			}
			if (method) *method = i;

			return mi;
		}
	}

	return mi;
}
Beispiel #2
0
/* Completely removes a channel.
 *
 * This includes the removal of all channel-bans, -exempts and -invites, as
 * well as all user flags related to the channel.
 */
static void remove_channel(struct chanset_t *chan)
{
  int i;
  module_entry *me;

  /* Remove the channel from the list, so that noone can pull it
   * away from under our feet during the check_tcl_part() call. */
  (void) chanset_unlink(chan);

  if ((me = module_find("irc", 1, 3)) != NULL)
    (me->funcs[IRC_DO_CHANNEL_PART]) (chan);

  clear_channel(chan, 0);
  noshare = 1;
  /* Remove channel-bans */
  while (chan->bans)
    u_delban(chan, chan->bans->mask, 1);
  /* Remove channel-exempts */
  while (chan->exempts)
    u_delexempt(chan, chan->exempts->mask, 1);
  /* Remove channel-invites */
  while (chan->invites)
    u_delinvite(chan, chan->invites->mask, 1);
  /* Remove channel specific user flags */
  user_del_chan(chan->dname);
  noshare = 0;
  nfree(chan->channel.key);
  for (i = 0; i < MODES_PER_LINE_MAX && chan->cmode[i].op; i++)
    nfree(chan->cmode[i].op);
  if (chan->key)
    nfree(chan->key);
  if (chan->rmkey)
    nfree(chan->rmkey);
  nfree(chan);
}
Beispiel #3
0
int	module_init (int ver, struct module *mod, struct session *sess)
{
	/* This check *MUST* be done first */
	if (ver != MODULE_IFACE_VER)
		return 1;
	
	if (module_find (name) != NULL) {
		/* We are already loaded */
		PrintText(sess, "Module xchat-autogb already loaded\n");
		return 1;
	}
	PrintText(sess, "Loaded module xchat-autogb\n");
	mod->name = name;
	mod->desc = desc;
		
	chanmsg_sig.signal = XP_CHANMSG;
	chanmsg_sig.callback = XP_CALLBACK(autogb_chanmsg);
	chanmsg_sig.naddr = &chanmsg_next;
	chanmsg_sig.mod = mod;

	privmsg_sig.signal = XP_PRIVMSG;
	privmsg_sig.callback = XP_CALLBACK(autogb_privmsg);
	privmsg_sig.naddr = &privmsg_next;
	privmsg_sig.mod = mod;
	
	hook_signal(&chanmsg_sig);
	hook_signal(&privmsg_sig);
	big2gb_init();
	
	return 0;
}
Beispiel #4
0
int send_uptime(void)
{
  struct sockaddr_in sai;
  struct stat st;
  PackUp *mem;
  int len, servidx;
  char servhost[UHOSTLEN] = "none";
  module_entry *me;

  if (uptimeip == -1) {
    uptimeip = get_ip();
    if (uptimeip == -1)
      return -2;
  }

  uptimecount++;
  upPack.packets_sent = htonl(uptimecount); /* Tell the server how many
					       uptime packets we've sent. */
  upPack.now2 = htonl(time(NULL));
  upPack.ontime = 0;

  if ((me = module_find("server", 1, 0))) {
    Function *server_funcs = me->funcs;

    if (server_online) {
      servidx = findanyidx(serv);
      strncpyz(servhost, dcc[servidx].host, sizeof servhost);
      upPack.ontime = htonl(server_online);
    }
  }

  if (!upPack.pid)
    upPack.pid = htonl(getpid());

  if (!upPack.uptime)
    upPack.uptime = htonl(online_since);

  if (stat("/proc", &st) < 0)
    upPack.sysup = 0;
  else
    upPack.sysup = htonl(st.st_ctime);

  len = sizeof(upPack) + strlen(botnetnick) + strlen(servhost) +
        strlen(uptime_version);
  mem = (PackUp *) nmalloc(len);
  egg_bzero(mem, len); /* mem *should* be completely filled before it's
                             * sent to the server.  But belt-and-suspenders
                             * is always good.
                             */
  my_memcpy(mem, &upPack, sizeof(upPack));
  sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version);
  egg_bzero(&sai, sizeof(sai));
  sai.sin_family = AF_INET;
  sai.sin_addr.s_addr = uptimeip;
  sai.sin_port = htons(uptime_port);
  len = sendto(uptimesock, (void *) mem, len, 0, (struct sockaddr *) &sai,
               sizeof(sai));
  nfree(mem);
  return len;
}
Beispiel #5
0
/* filereq <sock:nick@bot> <bot:file>
 */
static void bot_filereq(int idx, char *tobot)
{
  char *from, *path;
  int i;

  from = newsplit(&tobot);
  if ((path = strchr(tobot, ':'))) {
    *path++ = 0;

    if (!egg_strcasecmp(tobot, botnetnick)) {   /* For me! */
      /* Process this */
      module_entry *fs = module_find("filesys", 0, 0);

      if (fs == NULL)
        botnet_send_priv(idx, botnetnick, from, NULL, MOD_NOFILESYSMOD);
      else {
        Function f = fs->funcs[FILESYS_REMOTE_REQ];

        f(idx, from, path);
      }
    } else {                      /* Pass it on */
      i = nextbot(tobot);
      if (i >= 0)
        botnet_send_filereq(i, from, tobot, path);
    }
  }
}
Beispiel #6
0
/* Got 442: not on channel
 */
static int got442(char *from, char *msg)
{
  char *chname, *key;
  struct chanset_t *chan;

  if (!realservername || egg_strcasecmp(from, realservername))
    return 0;
  newsplit(&msg);
  chname = newsplit(&msg);
  chan = findchan(chname);
  if (chan && !channel_inactive(chan)) {
    module_entry *me = module_find("channels", 0, 0);

    putlog(LOG_MISC, chname, IRC_SERVNOTONCHAN, chname);
    if (me && me->funcs)
      (me->funcs[CHANNEL_CLEAR]) (chan, 1);
    chan->status &= ~CHAN_ACTIVE;

    key = chan->channel.key[0] ? chan->channel.key : chan->key_prot;
    if (key[0])
      dprintf(DP_SERVER, "JOIN %s %s\n", chan->name, key);
    else
      dprintf(DP_SERVER, "JOIN %s\n", chan->name);
  }
  return 0;
}
Beispiel #7
0
/* SYNTAX: UNLOAD <module> [<submodule>] */
static void cmd_unload(const char *data)
{
    MODULE_REC *module;
    MODULE_FILE_REC *file;
    char *rootmodule, *submodule;
    void *free_arg;

    g_return_if_fail(data != NULL);

    if (!cmd_get_params(data, &free_arg, 2 , &rootmodule, &submodule))
        return;
    if (*rootmodule == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

    module = module_find(rootmodule);
    if (module != NULL) {
        if (*submodule == '\0')
            module_unload(module);
        else {
            file = module_file_find(module, submodule);
            if (file != NULL)
                module_file_unload(file);
            else
                module = NULL;
        }
    }

    if (module == NULL) {
        printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
                    TXT_MODULE_NOT_LOADED, rootmodule, submodule);
    }

    cmd_params_free(free_arg);
}
Beispiel #8
0
static int module_load_full(const char *path, const char *rootmodule,
			    const char *submodule, int start, int end,
			    char **prefixes)
{
	MODULE_REC *module;
        int status, try_prefixes;

	if (!g_module_supported())
		return FALSE;

	module = module_find(rootmodule);
	if (module != NULL && (strcmp(submodule, rootmodule) == 0 ||
			       module_file_find(module, submodule) != NULL)) {
                /* module is already loaded */
		module_error(MODULE_ERROR_ALREADY_LOADED, NULL,
			     rootmodule, submodule);
                return FALSE;
	}

	/* check if the given module exists.. */
	try_prefixes = strcmp(rootmodule, submodule) == 0;
	status = module_load_name(path, rootmodule, submodule, try_prefixes);
	if (status == -1 && try_prefixes) {
		/* nope, try loading the module_core,
		   fe_module, etc. */
		status = module_load_prefixes(path, rootmodule,
					      start, end, prefixes);
	}

	return status > 0;
}
Beispiel #9
0
static int tcl_echo(ClientData cd, Tcl_Interp *irp,
                    int argc, char *argv[])
{
  int i;
  module_entry *me;

  BADARGS(2, 3, " idx ?status?");

  i = findidx(atoi(argv[1]));
  if (i < 0 || dcc[i].type != &DCC_CHAT) {
    Tcl_AppendResult(irp, "invalid idx", NULL);
    return TCL_ERROR;
  }
  if (argc == 3) {
    if (atoi(argv[2]))
      dcc[i].status |= STAT_ECHO;
    else
      dcc[i].status &= ~STAT_ECHO;
  }
  if (dcc[i].status & STAT_ECHO)
    Tcl_AppendResult(irp, "1", NULL);
  else
    Tcl_AppendResult(irp, "0", NULL);
  /* Console autosave. */
  if (argc > 2 && (me = module_find("console", 1, 1))) {
    Function *func = me->funcs;

    (func[CONSOLE_DOSTORE]) (i);
  }
  return TCL_OK;
}
Beispiel #10
0
int engine_register(struct engine *engine, const char *name, const char *precedence, const char* ref)
{
	if (engine == NULL || name == NULL) {
		return kr_error(EINVAL);
	}
	/* Make sure module is unloaded */
	(void) engine_unregister(engine, name);
	/* Find the index of referenced module. */
	module_array_t *mod_list = &engine->modules;
	size_t ref_pos = mod_list->len;
	if (precedence && ref) {
		ref_pos = module_find(mod_list, ref);
		if (ref_pos >= mod_list->len) {
			return kr_error(EIDRM);
		}
	}
	/* Attempt to load binary module */
	struct kr_module *module = malloc(sizeof(*module));
	if (!module) {
		return kr_error(ENOMEM);
	}
	module->data = engine;
	int ret = kr_module_load(module, name, NULL);
	/* Load Lua module if not a binary */
	if (ret == kr_error(ENOENT)) {
		ret = ffimodule_register_lua(engine, module, name);
	}
	if (ret != 0) {
		free(module);
		return ret;
	}
	if (array_push(engine->modules, module) < 0) {
		engine_unload(engine, module);
		return kr_error(ENOMEM);
	}
	/* Evaluate precedence operator */
	if (precedence) {
		struct kr_module **arr = mod_list->at;
		size_t emplacement = mod_list->len;
		if (strcasecmp(precedence, ">") == 0) {
			if (ref_pos + 1 < mod_list->len)
				emplacement = ref_pos + 1; /* Insert after target */
		}
		if (strcasecmp(precedence, "<") == 0) {
			emplacement = ref_pos; /* Insert at target */
		}
		/* Move the tail if it has some elements. */
		if (emplacement + 1 < mod_list->len) {
			memmove(&arr[emplacement + 1], &arr[emplacement], sizeof(*arr) * (mod_list->len - (emplacement + 1)));
			arr[emplacement] = module;
		}
	}

	/* Register properties */
	if (module->props || module->config) {
		return register_properties(engine, module);
	}

	return kr_ok();
}
Beispiel #11
0
static int tcl_console(ClientData cd, Tcl_Interp *irp,
                       int argc, char *argv[])
{
  int i, j, pls, arg;
  module_entry *me;

  BADARGS(2, 4, " idx ?channel? ?console-modes?");

  i = findidx(atoi(argv[1]));
  if (i < 0 || dcc[i].type != &DCC_CHAT) {
    Tcl_AppendResult(irp, "invalid idx", NULL);
    return TCL_ERROR;
  }
  pls = 1;

  for (arg = 2; arg < argc; arg++) {
    if (argv[arg][0] && ((strchr(CHANMETA, argv[arg][0]) != NULL) ||
        (argv[arg][0] == '*'))) {
      if ((argv[arg][0] != '*') && (!findchan_by_dname(argv[arg]))) {
        /* If we dont find the channel, and it starts with a +, assume it
         * should be the console flags to set. */
        if (argv[arg][0] == '+')
          goto do_console_flags;
        Tcl_AppendResult(irp, "invalid channel", NULL);
        return TCL_ERROR;
      }
      strncpyz(dcc[i].u.chat->con_chan, argv[arg], 81);
    } else {
      if ((argv[arg][0] != '+') && (argv[arg][0] != '-'))
        dcc[i].u.chat->con_flags = 0;
    do_console_flags:
      for (j = 0; j < strlen(argv[arg]); j++) {
        if (argv[arg][j] == '+')
          pls = 1;
        else if (argv[arg][j] == '-')
          pls = -1;
        else {
          char s[2];

          s[0] = argv[arg][j];
          s[1] = 0;
          if (pls == 1)
            dcc[i].u.chat->con_flags |= logmodes(s);
          else
            dcc[i].u.chat->con_flags &= ~logmodes(s);
        }
      }
    }
  }
  Tcl_AppendElement(irp, dcc[i].u.chat->con_chan);
  Tcl_AppendElement(irp, masktype(dcc[i].u.chat->con_flags));
  /* Console autosave. */
  if (argc > 2 && (me = module_find("console", 1, 1))) {
    Function *func = me->funcs;

    (func[CONSOLE_DOSTORE]) (i);
  }
  return TCL_OK;
}
Beispiel #12
0
int main(int argc, char **argv)
{
	const struct pppoat_module    *m;
	const struct pppoat_if_module *im;
	void                          *m_data;
	void                          *im_data;
	int                            rd[2];
	int                            wr[2];
	int                            rc;

	pppoat_log_init(PPPOAT_DEBUG);

	if (argc > 1 && strcmp(argv[1], "--help") == 0) {
		help_print(stdout, argv[0]);
		exit(0);
	}
	if (argc > 1 && strcmp(argv[1], "--list") == 0) {
		module_list_print(stdout);
		exit(0);
	}

	im = if_module_tbl[0];
	PPPOAT_ASSERT(im != NULL);
	m = module_find("udp");
	PPPOAT_ASSERT(m != NULL);

	/* init modules */
	rc = im->im_init(argc, argv, &im_data);
	PPPOAT_ASSERT_INFO(rc == 0, "rc=%d", rc);
	rc = m->m_init(argc, argv, &m_data);
	PPPOAT_ASSERT_INFO(rc == 0, "rc=%d", rc);

	/* create pipes for communication with pppd */
	rc = pipe(rd);
	PPPOAT_ASSERT(rc == 0);
	rc = pipe(wr);
	PPPOAT_ASSERT(rc == 0);

	/* exec pppd */
	rc = im->im_run(wr[0], rd[1], im_data);
	PPPOAT_ASSERT_INFO(rc == 0, "rc=%d", rc);
	close(rd[1]);
	close(wr[0]);

	/* run appropriate module's function */
	rc = m->m_run(rd[0], wr[1], 0 /* XXX */, m_data);
	pppoat_error("main", "rc=%d", rc);

	/* finalisation */
	im->im_stop(im_data);
	im->im_fini(im_data);
	m->m_fini(m_data);
	close(rd[0]);
	close(wr[1]);

	pppoat_log_fini();

	return 0;
}
Beispiel #13
0
int
module_deregister(const char *filename)
{
  ModuleList *p;

  p = module_find(filename);
  return module_delete(p);
}
Beispiel #14
0
static int tcl_setchan(ClientData cd, Tcl_Interp *irp,
                       int argc, char *argv[])
{
  int idx, chan;
  module_entry *me;

  BADARGS(3, 3, " idx channel");

  idx = findidx(atoi(argv[1]));
  if (idx < 0 || (dcc[idx].type != &DCC_CHAT &&
      dcc[idx].type != &DCC_SCRIPT)) {
    Tcl_AppendResult(irp, "invalid idx", NULL);
    return TCL_ERROR;
  }
  if (argv[2][0] < '0' || argv[2][0] > '9') {
    if (!strcmp(argv[2], "-1") || !egg_strcasecmp(argv[2], "off"))
      chan = -1;
    else {
      Tcl_SetVar(irp, "chan", argv[2], 0);
      if (Tcl_VarEval(irp, "assoc ", "$chan", NULL) != TCL_OK ||
          !interp->result[0]) {
        Tcl_AppendResult(irp, "channel name is invalid", NULL);
        return TCL_ERROR;
      }
      chan = atoi(interp->result);
    }
  } else
    chan = atoi(argv[2]);
  if ((chan < -1) || (chan > 199999)) {
    Tcl_AppendResult(irp, "channel out of range; must be -1 through 199999",
                     NULL);
    return TCL_ERROR;
  }
  if (dcc[idx].type == &DCC_SCRIPT)
    dcc[idx].u.script->u.chat->channel = chan;
  else {
    int oldchan = dcc[idx].u.chat->channel;

    if (dcc[idx].u.chat->channel >= 0) {
      if ((chan >= GLOBAL_CHANS) && (oldchan < GLOBAL_CHANS))
        botnet_send_part_idx(idx, "*script*");
      check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
                     dcc[idx].u.chat->channel);
    }
    dcc[idx].u.chat->channel = chan;
    if (chan < GLOBAL_CHANS)
      botnet_send_join_idx(idx, oldchan);
    check_tcl_chjn(botnetnick, dcc[idx].nick, chan, geticon(idx),
                   dcc[idx].sock, dcc[idx].host);
  }
  /* Console autosave. */
  if ((me = module_find("console", 1, 1))) {
    Function *func = me->funcs;

    (func[CONSOLE_DOSTORE]) (idx);
  }
  return TCL_OK;
}
Beispiel #15
0
/* 001: welcome to IRC (use it to fix the server name) */
static int got001(char *from, char *msg)
{
  int i;
  char *key;
  struct chanset_t *chan;
  struct server_list *x = serverlist;

  /* FIXME - x should never be NULL anywhere in this function, but
   * apparently it sometimes is. */
  if (x) {
    for (i = curserv; i > 0 && x; i--)
      x = x->next;
    if (!x) {
      putlog(LOG_MISC, "*", "Invalid server list!");
    } else {
      if (x->realname)
        nfree(x->realname);
      x->realname = nmalloc(strlen(from) + 1);
      strcpy(x->realname, from);
    }
    if (realservername)
      nfree(realservername);
    realservername = nmalloc(strlen(from) + 1);
    strcpy(realservername, from);
  } else
    putlog(LOG_MISC, "*", "No server list!");

  server_online = now;
  fixcolon(msg);
  strncpyz(botname, msg, NICKLEN);
  altnick_char = 0;
  dprintf(DP_SERVER, "WHOIS %s\n", botname); /* get user@host */
  if (initserver[0])
    do_tcl("init-server", initserver); /* Call Tcl init-server */
  check_tcl_event("init-server");

  if (!x)
    return 0;

  if (module_find("irc", 0, 0)) {  /* Only join if the IRC module is loaded. */
    for (chan = chanset; chan; chan = chan->next) {
      chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
      if (!channel_inactive(chan)) {

        key = chan->channel.key[0] ? chan->channel.key : chan->key_prot;
        if (key[0])
          dprintf(DP_SERVER, "JOIN %s %s\n",
                  chan->name[0] ? chan->name : chan->dname, key);
        else
          dprintf(DP_SERVER, "JOIN %s\n",
                  chan->name[0] ? chan->name : chan->dname);
      }
    }
  }

  return 0;
}
Beispiel #16
0
// Unload module by name
void module_unload(const char* name)
{
    // Get full path to module file, and hash of path
    char path[60];
    unsigned int hash = get_module_path(path, name);

    // Find loaded module, and unload it
    module_unload_idx(module_find(hash));
}
Beispiel #17
0
HMODULE
module_lookup(const char *filename)
{
  ModuleList *p;

  if ((p = module_find(filename)) == NULL)
    return NULL;
  return p->module;
}
Beispiel #18
0
/* info? <from@bot>   -> send priv
 */
static void bot_infoq(int idx, char *par)
{
  char s[200], s2[32], *realnick;
  struct chanset_t *chan;
  time_t now2;
  int hr, min;

  /* Strip the idx from user@bot */
  realnick = strchr(par, ':');
  if (realnick)
    realnick++;
  else
    realnick = par;
  putlog(LOG_BOTS, "*", "#%s# botinfo", realnick);

  now2 = now - online_since;
  s2[0] = 0;
  if (now2 > 86400) {
    int days = now2 / 86400;

    /* Days */
    sprintf(s2, "%d day", days);
    if (days >= 2)
      strcat(s2, "s");
    strcat(s2, ", ");
    now2 -= days * 86400;
  }
  hr = (time_t) ((int) now2 / 3600);
  now2 -= (hr * 3600);
  min = (time_t) ((int) now2 / 60);
  sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
  if (module_find("server", 0, 0)) {
    s[0] = 0;
    for (chan = chanset; chan; chan = chan->next) {
      if (!channel_secret(chan)) {
        if ((strlen(s) + strlen(chan->dname) + strlen(network)
             + strlen(botnetnick) + strlen(ver) + 1) >= 200) {
          strcat(s, "++  ");
          break;                /* Yegads..! */
        }
        strcat(s, chan->dname);
        strcat(s, ", ");
      }
    }
    if (s[0]) {
      s[strlen(s) - 2] = 0;
      botnet_send_priv(idx, botnetnick, par, NULL,
                       "%s <%s> (%s) [UP %s]", ver, network, s, s2);
    } else
      botnet_send_priv(idx, botnetnick, par, NULL, "%s <%s> (%s) [UP %s]", ver,
                       network, BOT_NOCHANNELS, s2);
  } else
    botnet_send_priv(idx, botnetnick, par, NULL,
                     "%s <NO_IRC> [UP %s]", ver, s2);
  botnet_send_infoq(idx, par);
}
Beispiel #19
0
int engine_unregister(struct engine *engine, const char *name)
{
	module_array_t *mod_list = &engine->modules;
	size_t found = module_find(mod_list, name);
	if (found < mod_list->len) {
		engine_unload(engine, mod_list->at[found]);
		array_del(*mod_list, found);
		return kr_ok();
	}

	return kr_error(ENOENT);
}
Beispiel #20
0
void *dlopen(const char *path, int flag)
{
	module_t *m;

	m = module_find(runtime_env, path);
	if (m == NULL) {
		m = module_load(runtime_env, path, mlf_local);
		module_load_deps(m, mlf_local);
		/* Now relocate. */
		module_process_relocs(m);
	}

	return (void *) m;
}
Beispiel #21
0
static void kill_server(int idx, void *x)
{
  module_entry *me;

  disconnect_server(idx);
  if ((me = module_find("channels", 0, 0)) && me->funcs) {
    struct chanset_t *chan;

    for (chan = chanset; chan; chan = chan->next)
      (me->funcs[CHANNEL_CLEAR]) (chan, 1);
  }
  /* A new server connection will be automatically initiated in
   * about 2 seconds. */
}
Beispiel #22
0
static int script_newsomething(void *type, char *chan_name, char *mask, char *creator, char *comment, char *lifetime, char *options)
{
	time_t expire_time;
	struct chanset_t *chan = NULL;
	int sticky = 0;
	int r;
	module_entry *me;

	if (chan_name[0]) {
		chan = findchan_by_dname(chan_name);
		if (!chan) return(-1);
	}

	if (lifetime) {
		expire_time = atoi(lifetime);
		if (expire_time) expire_time = expire_time * 60 + now;
	}
	expire_time = now + (60 * (((int) type == 'b') ?
			    ((chan->ban_time == 0) ? 0L : chan->ban_time) :
			    (((int) type == 'e') ? ((chan->exempt_time == 0) ?
			    0L : chan->exempt_time) :
			    ((chan->invite_time == 0) ?
			    0L : chan->invite_time))));

	if (options && !strcasecmp(options, "sticky")) sticky = 1;

	r = u_addmask((int) type, chan, mask, creator, comment, expire_time, sticky);
	if (chan && !r) return(-1);

	if ((int) type == 'b') {
		me = module_find("irc", 0, 0);
		if (me) {
			if (chan) (me->funcs[IRC_CHECK_THIS_BAN])(chan, mask, sticky);
			else for (chan = chanset; chan; chan = chan->next) {
				(me->funcs[IRC_CHECK_THIS_BAN])(chan, mask, sticky);
			}
		}
		return(0);
	}

	if (chan) add_mode(chan, '+', (int) type, mask);
	else {
		for (chan = chanset; chan; chan = chan->next) {
			add_mode(chan, '+', (int) type, mask);
		}
	}
	return(0);
}
Beispiel #23
0
static int _module_load(module_handler_t* hMod)
{
    int idx;

    // Check if module loaded
    idx = module_find(hMod->name);
    if ( idx>=0 )
        return idx;

    // Find empty slot   
    for ( idx=0; idx<MAX_NUM_LOADED_MODULES && modules[idx].hdr; idx++ );

    if  ( idx == MAX_NUM_LOADED_MODULES )
    {
        moduleload_error("%d already loaded",MAX_NUM_LOADED_MODULES);
        return -1;
    }

    if (module_preload(hMod->name, hMod->version) != 0)
    {
        // Module is valid. Finalize binding
        modules[idx].hdr = flat_buf;

        // store runtime params
        flat_module_name_make(modules[idx].modulename, module_filename);
        modules[idx].hMod = hMod;

        int bind_err = bind_module( hMod, flat_buf->_module_info->lib );

        if ( flat_buf->_module_info->lib->loader )
        {
            uint32_t x = flat_buf->_module_info->lib->loader();
            bind_err = bind_err || x;
        }

        if ( bind_err )
        {
            module_unload(module_filename);
            moduleload_error("chdk mismatch",0);
            return -1;
        }

        return idx;
    }

    return -1;
}
Beispiel #24
0
static int tcl_strip(ClientData cd, Tcl_Interp *irp,
                     int argc, char *argv[])
{
  int i, j, pls, arg;
  module_entry *me;

  BADARGS(2, 4, " idx ?strip-flags?");

  i = findidx(atoi(argv[1]));
  if (i < 0 || dcc[i].type != &DCC_CHAT) {
    Tcl_AppendResult(irp, "invalid idx", NULL);
    return TCL_ERROR;
  }
  pls = 1;

  for (arg = 2; arg < argc; arg++) {
    if ((argv[arg][0] != '+') && (argv[arg][0] != '-'))
      dcc[i].u.chat->strip_flags = 0;
    for (j = 0; j < strlen(argv[arg]); j++) {
      if (argv[arg][j] == '+')
        pls = 1;
      else if (argv[arg][j] == '-')
        pls = -1;
      else {
        char s[2];

        s[0] = argv[arg][j];
        s[1] = 0;
        if (pls == 1)
          dcc[i].u.chat->strip_flags |= stripmodes(s);
        else
          dcc[i].u.chat->strip_flags &= ~stripmodes(s);
      }
    }
  }
  Tcl_AppendElement(irp, stripmasktype(dcc[i].u.chat->strip_flags));
  /* Console autosave. */
  if (argc > 2 && (me = module_find("console", 1, 1))) {
    Function *func = me->funcs;

    (func[CONSOLE_DOSTORE]) (i);
  }
  return TCL_OK;
}
Beispiel #25
0
int __char_device_register(unsigned int major, const char *name,
                           struct file_operations *fops,
                           unsigned int this_module) {

    struct device *dev;
    struct kernel_module *mod;

    if (new(dev)) return -ENOMEM;

    dev->fops = fops;
    dev->owner = 0;
    strcpy(dev->name, name);
    if ((mod = module_find(this_module))) dev->owner = mod;

    char_devices[major] = dev;

    return 0;

}
Beispiel #26
0
/* SYNTAX: UNLOAD <module> [<submodule>] */
static void cmd_unload(const char *data)
{
	MODULE_REC *module;
        MODULE_FILE_REC *file;
        char *rootmodule, *submodule;
	void *free_arg;
	GSList *tmp;
	int all_dynamic;

	g_return_if_fail(data != NULL);

	if (!cmd_get_params(data, &free_arg, 2 , &rootmodule, &submodule))
		return;
	if (*rootmodule == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	module = module_find(rootmodule);
	if (module != NULL) {
		if (*submodule == '\0') {
			all_dynamic = 1;
			for (tmp = module->files; tmp != NULL; tmp = tmp->next)
				all_dynamic &= !MODULE_IS_STATIC((MODULE_FILE_REC*) tmp->data);
			if (all_dynamic)
				module_unload(module);
		}
		else {
			file = module_file_find(module, submodule);
			if (file != NULL) {
				if (!MODULE_IS_STATIC(file))
					module_file_unload(file);
			}
			else
				module = NULL;
		}
	}

	if (module == NULL) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
                            TXT_MODULE_NOT_LOADED, rootmodule, submodule);
	}

	cmd_params_free(free_arg);
}
Beispiel #27
0
int	module_init (int ver, struct module *mod, struct session *sess)
{
	/* This check *MUST* be done first */
	if (ver != MODULE_IFACE_VER)
		return 1;
	
	if (module_find (name) != NULL) {
		/* We are already loaded */
		PrintText(sess, "Module sample already loaded\n");
		return 1;
	}
	PrintText(sess, "Loaded module sample\n");
	mod->name = name;
	mod->desc = desc;
		
	privmsg_sig.signal = XP_PRIVMSG;
	privmsg_sig.callback = XP_CALLBACK(sample_privmsg);
	privmsg_sig.naddr = &privmsg_next;
	privmsg_sig.mod = mod;
	
	test_sig.signal = XP_USERCOMMAND;
	test_sig.callback = XP_CALLBACK(sample_test);
	test_sig.naddr = &test_next;
	test_sig.mod = mod;
	
	test2_sig.signal = XP_USERCOMMAND;
	test2_sig.callback = XP_CALLBACK(sample_test2);
	test2_sig.naddr = &test2_next;
	test2_sig.mod = mod;
	
	hook_signal(&test_sig);
	hook_signal(&test2_sig);
	hook_signal(&privmsg_sig);

	sample_cmd_set.mod = mod;
	sample_cmd_set.cmds = sample_cmds;
	
	module_add_cmds (&sample_cmd_set);
	
	return 0;
}
Beispiel #28
0
int
module_register(const char *filename, HMODULE module)
{
  if (mod_list == NULL) {
    mod_list = malloc(sizeof(ModuleList));
    mod_list->next = mod_list->prev = NULL;
  } else {
    if (module_find(filename))
      return 1;

    mod_list->next = malloc(sizeof(ModuleList));
    mod_list->next->prev = mod_list;
    mod_list->next->next = NULL;
    mod_list = mod_list->next;
  }

  mod_list->filename = filename ? strdup(filename) : NULL;
  mod_list->module = module;

  return 1;
}
Beispiel #29
0
static void irc_proc_cmd_privmsg_user_cmd (struct irc_t * irc)
{
    struct mod_c_t * mod_c;
    char token[MAX_IRC_MSG];
    char str[MAX_IRC_MSG];
    char * t;

    strncpy(str, irc->request, MAX_IRC_MSG);
    if ( !(t = strtok(str, " \r\n")) )
        return;

    strncpy(token, t, MAX_IRC_MSG);

    if ( (mod_c = module_find(token+1)) )
    {
        char reply_msg[MAX_IRC_MSG];

        reply_msg[0] = '\0';
        mod_c->func(irc, reply_msg);
        
        if (reply_msg[0])
            snprintf(irc->response, MAX_IRC_MSG, "PRIVMSG %s :%s\r\n", irc->from, reply_msg);
    }
#ifdef USE_PYTHON_MODULES
    else
    {
        char * ret;
        struct py_module_t * mod = py_find_loaded_name (token); 

        if (mod) {
            ret = py_call_module ( mod, irc );
            snprintf( irc->response, MAX_IRC_MSG , "PRIVMSG %s :%s\r\n", irc->from, ret );
            free(ret);
        }
    }
#endif
    if ( !strncmp (irc->session->admin, irc->nick_to_msg, strlen(irc->session->admin)) ) 
        irc_proc_cmd_privmsg_user_cmd_admin (irc);
}
Beispiel #30
0
static int tcl_page(ClientData cd, Tcl_Interp *irp,
                    int argc, char *argv[])
{
  int i;
  char x[20];
  module_entry *me;

  BADARGS(2, 3, " idx ?status?");

  i = findidx(atoi(argv[1]));
  if (i < 0 || dcc[i].type != &DCC_CHAT) {
    Tcl_AppendResult(irp, "invalid idx", NULL);
    return TCL_ERROR;
  }
  if (argc == 3) {
    int l = atoi(argv[2]);

    if (!l)
      dcc[i].status &= ~STAT_PAGE;
    else {
      dcc[i].status |= STAT_PAGE;
      dcc[i].u.chat->max_line = l;
    }
  }
  if (dcc[i].status & STAT_PAGE) {
    egg_snprintf(x, sizeof x, "%d", dcc[i].u.chat->max_line);
    Tcl_AppendResult(irp, x, NULL);
  } else
    Tcl_AppendResult(irp, "0", NULL);
  /* Console autosave. */
  if ((argc > 2) && (me = module_find("console", 1, 1))) {
    Function *func = me->funcs;

    (func[CONSOLE_DOSTORE]) (i);
  }
  return TCL_OK;
}