예제 #1
0
파일: moddata.c 프로젝트: wodim/irc-hispano
/**
 * Delete the key/value pair indicated by "key" for the current module.
 * This allows module coders to remove a previously stored key/value pair.
 * @param md The module data for the struct to be used
 * @param key The key to delete the key/value pair for
 **/
void moduleDelData(ModuleData ** md, char *key)
{
    char *mod_name = sstrdup(mod_current_module_name);
    ModuleData *modcurrent = *md;
    ModuleData *prev = NULL;
    ModuleData *next = NULL;

    SET_SEGV_LOCATION();

    if (mod_current_module_name == NULL) {
        alog(LOG_DEBUG,
             "debug: moduleDelData() called with mod_current_module_name being NULL");
        if (denora->debug) {
            do_backtrace(0);
        }
    }

    if (key) {
        while (modcurrent) {
            next = modcurrent->next;
            if ((stricmp(modcurrent->moduleName, mod_name) == 0)
                && (stricmp(modcurrent->key, key) == 0)) {
                if (prev) {
                    prev->next = modcurrent->next;
                } else {
                    *md = modcurrent->next;
                }
                free(modcurrent->moduleName);
                free(modcurrent->key);
                free(modcurrent->value);
                modcurrent->next = NULL;
                free(modcurrent);
            } else {
                prev = modcurrent;
            }
            prev = modcurrent;
            modcurrent = next;
        }
    }
    free(mod_name);
}
예제 #2
0
파일: opensex.c 프로젝트: Gryllida/atheme
static database_handle_t *opensex_db_open_write(const char *filename)
{
	database_handle_t *db;
	opensex_t *rs;
	int fd;
	FILE *f;
	int errno1;
	char bpath[BUFSIZE], path[BUFSIZE];

	snprintf(bpath, BUFSIZE, "%s/%s", datadir, filename != NULL ? filename : "services.db");

	mowgli_strlcpy(path, bpath, sizeof path);
	mowgli_strlcat(path, ".new", sizeof path);

	fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
	if (fd < 0 || ! (f = fdopen(fd, "w")))
	{
		errno1 = errno;
		slog(LG_ERROR, "db-open-write: cannot open '%s' for writing: %s", path, strerror(errno1));
		wallops(_("\2DATABASE ERROR\2: db-open-write: cannot open '%s' for writing: %s"), path, strerror(errno1));
		return NULL;
	}

	rs = scalloc(sizeof(opensex_t), 1);
	rs->f = f;
	rs->grver = 1;

	db = scalloc(sizeof(database_handle_t), 1);
	db->priv = rs;
	db->vt = &opensex_vt;
	db->txn = DB_WRITE;
	db->file = sstrdup(bpath);
	db->line = 0;
	db->token = 0;

	db_start_row(db, "GRVER");
	db_write_int(db, rs->grver);
	db_commit_row(db);

	return db;
}
예제 #3
0
int loadConfParam(char *name, char *defaultVal, char **ptr)
{
	char *tmp = NULL;

	Directive directivas[] = {
		{name, {{PARAM_STRING, PARAM_RELOAD, &tmp}}},
	};

	Directive *d = &directivas[0];
	moduleGetConfigDirective(d);

	if (tmp) {
		*ptr = tmp;
	} else {
		*ptr = sstrdup(defaultVal);
	}

	alog("ns_qdbban: Directive %s loaded (%s)...", name, *ptr);

	return 0;
}
예제 #4
0
파일: scarynet.c 프로젝트: danopia/denora
/* (AB S trystan.nomadirc.net 2 0 1106520454 P10 ACAP] +h :Test Server) */
int denora_event_server(char *source, int ac, char **av)
{
    Server *s;
    char uplinknum[3];

    if (denora->protocoldebug) {
        protocol_debug(source, ac, av);
    }

    *uplinknum = '\0';
    strlcpy(uplinknum, av[5], sizeof(uplinknum));

    if (!stricmp(av[1], "1")) {
        denora->uplink = sstrdup(av[0]);
        do_server(source, av[0], av[1], av[7], uplinknum);
    } else {
        s = server_find(source);
        do_server((s ? s->name : source), av[0], av[1], av[7], uplinknum);
    }
    return MOD_CONT;
}
예제 #5
0
파일: main.c 프로젝트: Canternet/atheme
void _modinit(module_t *m)
{
	MODULE_TRY_REQUEST_SYMBOL(m, httpd_path_handlers, "misc/httpd", "httpd_path_handlers");

	hook_add_event("config_ready");
	hook_add_config_ready(xmlrpc_config_ready);

	xmlrpc_config.path = sstrdup("/xmlrpc");

	add_subblock_top_conf("XMLRPC", &conf_xmlrpc_table);
	add_dupstr_conf_item("PATH", &conf_xmlrpc_table, 0, &xmlrpc_config.path, NULL);

	xmlrpc_set_buffer(dump_buffer);
	xmlrpc_set_options(XMLRPC_HTTP_HEADER, XMLRPC_OFF);
	xmlrpc_register_method("atheme.login", xmlrpcmethod_login);
	xmlrpc_register_method("atheme.logout", xmlrpcmethod_logout);
	xmlrpc_register_method("atheme.command", xmlrpcmethod_command);
	xmlrpc_register_method("atheme.privset", xmlrpcmethod_privset);
	xmlrpc_register_method("atheme.ison", xmlrpcmethod_ison);
	xmlrpc_register_method("atheme.metadata", xmlrpcmethod_metadata);
}
예제 #6
0
파일: ss_export.c 프로젝트: danopia/denora
static int do_export(User * u, int ac, char **av)
{
    char *filename = NULL;

    if (ac < 1) {
        syntax_error(s_StatServ, u, "EXPORT", STATS_EXPORT_SYNTAX);
        return MOD_CONT;
    }
    if (!stricmp("channels", av[0])) {
        filename = sstrdup("channels.xml");
        xml_export_channels(filename);
        notice_lang(s_StatServ, u, STATS_EXPORT_CHANNELS, "channels.xml");
    } else if (!stricmp("users", av[0])) {
        filename = sstrdup("users.xml");
        xml_export_users(filename);
        notice_lang(s_StatServ, u, STATS_EXPORT_USERS, "users.xml");
    } else if (!stricmp("tld", av[0])) {
        filename = sstrdup("tld.xml");
        xml_export_tld(filename);
        notice_lang(s_StatServ, u, STATS_EXPORT_TLD, "tld.xml");
    } else if (!stricmp("servers", av[0])) {
        filename = sstrdup("servers.xml");
        xml_export_servers(filename);
        notice_lang(s_StatServ, u, STATS_EXPORT_SERVERS, "servers.xml");
    } else if (!stricmp("stats", av[0])) {
        filename = sstrdup("stats.xml");
        xml_export_stats(filename);
        notice_lang(s_StatServ, u, STATS_EXPORT_STATS, "stats.xml");
    } else if (!stricmp("all", av[0])) {
        filename = sstrdup("denora.xml");
        xml_export_all(filename);
        notice_lang(s_StatServ, u, STATS_EXPORT_ALL, "denora.xml");
    } else if (!stricmp("ctcp", av[0])) {
        filename = sstrdup("ctcp.xml");
        xml_export_ctcp(filename);
        notice_lang(s_StatServ, u, STATS_EXPORT_ALL, "ctcp.xml");
    } else {
        syntax_error(s_StatServ, u, "EXPORT", STATS_EXPORT_SYNTAX);
    }
    free(filename);
    return MOD_CONT;
}
예제 #7
0
파일: s_misc.c 프로젝트: klamonte/maximus
int makedir(char *d)
{
  char temp[PATHLEN];
  int x;

  for (*temp='\0';;)
  {
    if (!do_unattended)
    {
      printf("\rCreate dir `%s' [Y,n]? ",d);

      fgets(temp,PATHLEN,stdin);

      Strip_Trailing(temp, '\n');

      *temp=(char)toupper(*temp);

      Compiling(-1, NULL, NULL);
    }

    if (do_unattended || *temp=='Y' || *temp=='\n' || *temp=='\0')
    {
      char *fn;

      printf("\rCreating directory `%s'\n", d);
      Compiling(-1, NULL, NULL);

      fn=sstrdup(d);

      Strip_Trailing(fn, PATH_DELIM);

      x=make_dir(fn);
      free(fn);
      return x;
    }
    else if (*temp=='N')
      return 0;
  }
}
예제 #8
0
파일: nefarious.c 프로젝트: danopia/denora
/* ABAAB J #ircops 1098031328 */
void nefarious_cmd_join(char *user, char *channel, time_t chantime)
{
    Uid *ud;
    char *modes = NULL;

    ud = find_uid(user);

    if (started) {
        send_cmd((ud ? ud->uid : user), "J %s %ld", channel,
                 (long int) chantime);
    } else {
        if (AutoOp && AutoMode) {
            modes = sstrdup(AutoMode);
            modes++;            /* since the first char is +, we skip it */
            send_cmd(p10id, "B %s %ld %s:%s", channel,
                     (long int) chantime, (ud ? ud->uid : user), modes);
        } else {
            send_cmd(p10id, "B %s %ld %s", channel,
                     (long int) chantime, (ud ? ud->uid : user));
        }
    }
}
예제 #9
0
void helpserv(const char *whoami, const char *source, char *buf)
{
    char *cmd, *topic, *s;
#if defined(IRC_UNDERNET_P10)
    User *u = finduser(source);
    
    if (!u)
        return;
#endif        

    topic = buf ? sstrdup(buf) : NULL;
    cmd = strtok(buf, " ");
    if (cmd && stricmp(cmd, "\1PING") == 0) {
	if (!(s = strtok(NULL, "")))
	    s = "\1";
#if defined(IRC_UNDERNET_P10)
	notice(s_HelpServ, u->numerico, "\1PING %s", s);
    } else {
        do_help(whoami, u->numerico, topic);    
#else
        notice(s_HelpServ, source, "\1PING %s", s);
    } else if (stricmp(cmd, "\1VERSION\1") == 0) {
static int
basic_aggregator_config (const char *key, const char *value)
{
		int status=0;
		if (strcasecmp ("Aggregators_config_file", key) == 0)
		{
				if(configuration_filename) sfree (configuration_filename);
				configuration_filename = sstrdup (value);
		}
		else
		{
				ERROR (OUTPUT_PREFIX_STRING "Unknown config option: %s", key);
				return (-1);
		}

		if(NULL == configuration_filename) {
				ERROR (OUTPUT_PREFIX_STRING "No configuration filename 'Aggregators_config_file' was set in the collectd config file");
				return(-1);
		}

		return (status);
}
예제 #11
0
int match_userip(const char *mask, User * user, char *iphost)
{
    char *mask2;
    char *nick, *username, *host;
    int result;

    if (!mask || !*mask) {
        return 0;
    }

    mask2 = sstrdup(mask);

    if (strchr(mask2, '!')) {
        nick = strtok(mask2, "!");
        username = strtok(NULL, "@");
    } else {
        nick = NULL;
        username = strtok(mask2, "@");
    }
    host = strtok(NULL, "");
    if (!username || !host) {
        free(mask2);
        return 0;
    }

    if (nick) {
        result = match_wild_nocase(nick, user->nick)
            && match_wild_nocase(username, user->username)
            && (match_wild_nocase(host, iphost)
                || match_wild_nocase(host, user->vhost));
    } else {
        result = match_wild_nocase(username, user->username)
            && (match_wild_nocase(host, iphost)
                || match_wild_nocase(host, user->vhost));
    }

    free(mask2);
    return result;
}
예제 #12
0
/**
 * Add a message to the MessageHash.
 * @param msgTable the MessageHash we want to add a message to
 * @param m the Message we want to add
 * @return MOD_ERR_OK on a successful add.
 **/
int addEventHook(EvtHookHash * hookEvtTable[], EvtHook * evh)
{
    /* We can assume both param's have been checked by this point.. */
    int index = 0;
    EvtHookHash *current = NULL;
    EvtHookHash *newHash = NULL;
    EvtHookHash *lastHash = NULL;

    if (!hookEvtTable || !evh) {
        return MOD_ERR_PARAMS;
    }

    index = CMD_HASH(evh->name);

    for (current = hookEvtTable[index]; current; current = current->next) {
        if (stricmp(evh->name, current->name) == 0) {   /* the msg exist's we are a addHead */
            evh->next = current->evh;
            current->evh = evh;
            if (debug)
                alog("debug: existing msg: (0x%p), new msg (0x%p)",
                     (void *) evh->next, (void *) evh);
            return MOD_ERR_OK;
        }
        lastHash = current;
    }

    if ((newHash = malloc(sizeof(EvtHookHash))) == NULL) {
        fatal("Out of memory");
    }
    newHash->next = NULL;
    newHash->name = sstrdup(evh->name);
    newHash->evh = evh;

    if (lastHash == NULL)
        hookEvtTable[index] = newHash;
    else
        lastHash->next = newHash;
    return MOD_ERR_OK;
}
예제 #13
0
/**
 * The /ns update command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
static int do_nickupdate(User * u)
{
    NickAlias *na;

    if (!nick_identified(u)) {
        notice_lang(s_NickServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
    } else {
        na = u->na;
        do_setmodes(u);
        check_memos(u);
        if (na->last_realname)
            free(na->last_realname);
        na->last_realname = sstrdup(u->realname);
        na->status |= NS_IDENTIFIED;
        na->last_seen = time(NULL);
        if (ircd->vhost) {
            do_on_id(u);
        }
        notice_lang(s_NickServ, u, NICK_UPDATE_SUCCESS, s_NickServ);
    }
    return MOD_CONT;
}
예제 #14
0
static c_psql_database_t *c_psql_database_new (const char *name)
{
	c_psql_database_t *db;

	db = (c_psql_database_t *)malloc (sizeof (*db));
	if (NULL == db) {
		log_err ("Out of memory.");
		return NULL;
	}

	db->conn = NULL;

	C_COMPLAIN_INIT (&db->conn_complaint);

	db->proto_version = 0;
	db->server_version = 0;

	db->max_params_num = 0;

	db->q_prep_areas   = NULL;
	db->queries        = NULL;
	db->queries_num    = 0;

	db->interval   = 0;

	db->database   = sstrdup (name);
	db->host       = NULL;
	db->port       = NULL;
	db->user       = NULL;
	db->password   = NULL;

	db->sslmode    = NULL;

	db->krbsrvname = NULL;

	db->service    = NULL;
	return db;
} /* c_psql_database_new */
예제 #15
0
static c_psql_database_t *c_psql_database_new (const char *name)
{
	c_psql_database_t *db;

	++databases_num;
	if (NULL == (databases = (c_psql_database_t *)realloc (databases,
				databases_num * sizeof (*databases)))) {
		log_err ("Out of memory.");
		exit (5);
	}

	db = databases + (databases_num - 1);

	db->conn = NULL;

	C_COMPLAIN_INIT (&db->conn_complaint);

	db->proto_version = 0;
	db->server_version = 0;

	db->max_params_num = 0;

	db->queries        = NULL;
	db->queries_num    = 0;

	db->database   = sstrdup (name);
	db->host       = NULL;
	db->port       = NULL;
	db->user       = NULL;
	db->password   = NULL;

	db->sslmode    = NULL;

	db->krbsrvname = NULL;

	db->service    = NULL;
	return db;
} /* c_psql_database_new */
예제 #16
0
/**
 * Add a module message to the IRCD message hash
 * @param m the Message to add
 * @param pos the Position to add the message to, e.g. MOD_HEAD, MOD_TAIL, MOD_UNIQUE
 * @return MOD_ERR_OK on success, althing else on fail.
 **/
int moduleAddEventHook(EvtHook * evh)
{
    int status;

    if (!evh) {
        return MOD_ERR_PARAMS;
    }

    if (!mod_current_module) {
        return MOD_ERR_UNKNOWN;
    }                           /* shouldnt happen */

    evh->core = 0;
    if (!evh->mod_name) {
        evh->mod_name = sstrdup(mod_current_module->name);
    }

    status = addEventHook(EVENTHOOKS, evh);
    if (debug) {
        displayHookFromHash(evh->name);
    }
    return status;
}
예제 #17
0
/**
 * Add a module message to the IRCD message hash
 * @param m the Message to add
 * @param pos the Position to add the message to, e.g. MOD_HEAD, MOD_TAIL, MOD_UNIQUE
 * @return MOD_ERR_OK on success, althing else on fail.
 **/
int moduleAddEventHandler(EvtMessage * evm)
{
    int status;

    if (!evm) {
        return MOD_ERR_PARAMS;
    }

    if (!mod_current_module) {
        return MOD_ERR_UNKNOWN;
    }                           /* shouldnt happen */

    evm->core = 0;
    if (!evm->mod_name) {
        evm->mod_name = sstrdup(mod_current_module->name);
    }

    status = addEventHandler(EVENT, evm);
    if (debug) {
        displayEvtMessageFromHash(evm->name);
    }
    return status;
}
예제 #18
0
파일: inspircd11.c 프로젝트: danopia/denora
/* Event: PROTOCTL */
int denora_event_capab(char *source, int ac, char **av)
{
    int argc = 5;
    char *argv[5];

    if (strcasecmp(av[0], "START") == 0) {
        /* reset CAPAB */
        has_globopsmod = 0;
    } else if (strcasecmp(av[0], "MODULES") == 0
               && strstr(av[1], "m_globops.so")) {
        has_globopsmod = 1;
    } else if (strcasecmp(av[0], "END") == 0) {
        if (has_globopsmod == 0) {
            send_cmd(NULL,
                     "ERROR :m_globops.so is not loaded. This is required by Denora");
            denora->qmsg =
                sstrdup
                ("Remote server does not have the m_globops.so module loaded, and this is required.");
            denora->quitting = 1;
            return MOD_STOP;
        }

        /* Generate a fake capabs parsing call so things like NOQUIT work
         * fine. It's ugly, but it works....
         */
        argv[0] = sstrdup("NOQUIT");
        argv[1] = sstrdup("SSJ3");
        argv[2] = sstrdup("NICK2");
        argv[3] = sstrdup("VL");
        argv[4] = sstrdup("TLKEXT");

        capab_parse(argc, argv);

        free(argv[0]);
        free(argv[1]);
        free(argv[2]);
        free(argv[3]);
        free(argv[4]);
    }
    return MOD_CONT;
}
예제 #19
0
파일: win32.c 프로젝트: danopia/denora
/**
 * Return the CPU architecture
 * @return char that needs to be free'd
 */
char *WindowsCPUArchitecture(void)
{
    SYSTEM_INFO si;
    char buf[BUFSIZE];
    char *cpuarch;

    GetSystemInfo(&si);
    if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
        cpuarch = sstrdup("x64 (AMD or Intel)");
    } else if (si.wProcessorArchitecture ==
               PROCESSOR_ARCHITECTURE_IA32_ON_WIN64) {
        cpuarch = sstrdup("Emmulation \"WOW64\"");
    } else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) {
        cpuarch = sstrdup("Intel Itanium Processor Family (IPF)");
    } else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) {
        cpuarch = sstrdup("x86");
    } else {
        cpuarch = sstrdup("Unknown processor");
    }
    ircsnprintf(buf, sizeof(buf), "arch: %s  number %d", cpuarch,
                si.dwNumberOfProcessors);
    return sstrdup(buf);
}
예제 #20
0
static int ds_get (char ***ret, /* {{{ */
                   const data_set_t *ds, const value_list_t *vl,
                   const rrdcreate_config_t *cfg)
{
    char **ds_def;
    int ds_num;

    char min[32];
    char max[32];
    char buffer[128];

    ds_def = (char **) malloc (ds->ds_num * sizeof (char *));
    if (ds_def == NULL)
    {
        char errbuf[1024];
        ERROR ("rrdtool plugin: malloc failed: %s",
               sstrerror (errno, errbuf, sizeof (errbuf)));
        return (-1);
    }
    memset (ds_def, '\0', ds->ds_num * sizeof (char *));

    for (ds_num = 0; ds_num < ds->ds_num; ds_num++)
    {
        data_source_t *d = ds->ds + ds_num;
        char *type;
        int status;

        ds_def[ds_num] = NULL;

        if (d->type == DS_TYPE_COUNTER)
            type = "COUNTER";
        else if (d->type == DS_TYPE_GAUGE)
            type = "GAUGE";
        else if (d->type == DS_TYPE_DERIVE)
            type = "DERIVE";
        else if (d->type == DS_TYPE_ABSOLUTE)
            type = "ABSOLUTE";
        else
        {
            ERROR ("rrdtool plugin: Unknown DS type: %i",
                   d->type);
            break;
        }

        if (isnan (d->min))
        {
            sstrncpy (min, "U", sizeof (min));
        }
        else
            ssnprintf (min, sizeof (min), "%f", d->min);

        if (isnan (d->max))
        {
            sstrncpy (max, "U", sizeof (max));
        }
        else
            ssnprintf (max, sizeof (max), "%f", d->max);

        status = ssnprintf (buffer, sizeof (buffer),
                            "DS:%s:%s:%i:%s:%s",
                            d->name, type,
                            (cfg->heartbeat > 0) ? cfg->heartbeat : (2 * vl->interval),
                            min, max);
        if ((status < 1) || ((size_t) status >= sizeof (buffer)))
            break;

        ds_def[ds_num] = sstrdup (buffer);
    } /* for ds_num = 0 .. ds->ds_num */

    if (ds_num != ds->ds_num)
    {
        ds_free (ds_num, ds_def);
        return (-1);
    }

    *ret = ds_def;
    return (ds_num);
} /* }}} int ds_get */
예제 #21
0
/* * * * * * * * * *
 * WARNING:  Magic *
 * * * * * * * * * */
static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */
                    const rrdcreate_config_t *cfg)
{
    char **rra_def;
    int rra_num;

    int *rts;
    int  rts_num;

    int rra_max;

    int span;

    int cdp_num;
    int cdp_len;
    int i, j;

    char buffer[128];

    /* The stepsize we use here: If it is user-set, use it. If not, use the
     * interval of the value-list. */
    int ss;

    if (cfg->rrarows <= 0)
    {
        *ret = NULL;
        return (-1);
    }

    if ((cfg->xff < 0) || (cfg->xff >= 1.0))
    {
        *ret = NULL;
        return (-1);
    }

    ss = (cfg->stepsize > 0) ? cfg->stepsize : vl->interval;
    if (ss <= 0)
    {
        *ret = NULL;
        return (-1);
    }

    /* Use the configured timespans or fall back to the built-in defaults */
    if (cfg->timespans_num != 0)
    {
        rts = cfg->timespans;
        rts_num = cfg->timespans_num;
    }
    else
    {
        rts = rra_timespans;
        rts_num = rra_timespans_num;
    }

    rra_max = rts_num * rra_types_num;

    if ((rra_def = (char **) malloc ((rra_max + 1) * sizeof (char *))) == NULL)
        return (-1);
    memset (rra_def, '\0', (rra_max + 1) * sizeof (char *));
    rra_num = 0;

    cdp_len = 0;
    for (i = 0; i < rts_num; i++)
    {
        span = rts[i];

        if ((span / ss) < cfg->rrarows)
            span = ss * cfg->rrarows;

        if (cdp_len == 0)
            cdp_len = 1;
        else
            cdp_len = (int) floor (((double) span)
                                   / ((double) (cfg->rrarows * ss)));

        cdp_num = (int) ceil (((double) span)
                              / ((double) (cdp_len * ss)));

        for (j = 0; j < rra_types_num; j++)
        {
            int status;

            if (rra_num >= rra_max)
                break;

            status = ssnprintf (buffer, sizeof (buffer), "RRA:%s:%.10f:%u:%u",
                                rra_types[j], cfg->xff, cdp_len, cdp_num);

            if ((status < 0) || ((size_t) status >= sizeof (buffer)))
            {
                ERROR ("rra_get: Buffer would have been truncated.");
                continue;
            }

            rra_def[rra_num++] = sstrdup (buffer);
        }
    }

    *ret = rra_def;
    return (rra_num);
} /* }}} int rra_get */
예제 #22
0
int handle_putval (FILE *fh, char *buffer)
{
	char *command;
	char *identifier;
	char *hostname;
	char *plugin;
	char *plugin_instance;
	char *type;
	char *type_instance;
	int   status;
	int   values_submitted;

	char *identifier_copy;

	const data_set_t *ds;
	value_list_t vl = VALUE_LIST_INIT;

	DEBUG ("utils_cmd_putval: handle_putval (fh = %p, buffer = %s);",
			(void *) fh, buffer);

	command = NULL;
	status = parse_string (&buffer, &command);
	if (status != 0)
	{
		print_to_socket (fh, "-1 Cannot parse command.\n");
		return (-1);
	}
	assert (command != NULL);

	if (strcasecmp ("PUTVAL", command) != 0)
	{
		print_to_socket (fh, "-1 Unexpected command: `%s'.\n", command);
		return (-1);
	}

	identifier = NULL;
	status = parse_string (&buffer, &identifier);
	if (status != 0)
	{
		print_to_socket (fh, "-1 Cannot parse identifier.\n");
		return (-1);
	}
	assert (identifier != NULL);

	/* parse_identifier() modifies its first argument,
	 * returning pointers into it */
	identifier_copy = sstrdup (identifier);

	status = parse_identifier (identifier_copy, &hostname,
			&plugin, &plugin_instance,
			&type, &type_instance);
	if (status != 0)
	{
		DEBUG ("handle_putval: Cannot parse identifier `%s'.",
				identifier);
		print_to_socket (fh, "-1 Cannot parse identifier `%s'.\n",
				identifier);
		sfree (identifier_copy);
		return (-1);
	}

	if ((strlen (hostname) >= sizeof (vl.host))
			|| (strlen (plugin) >= sizeof (vl.plugin))
			|| ((plugin_instance != NULL)
				&& (strlen (plugin_instance) >= sizeof (vl.plugin_instance)))
			|| ((type_instance != NULL)
				&& (strlen (type_instance) >= sizeof (vl.type_instance))))
	{
		print_to_socket (fh, "-1 Identifier too long.\n");
		sfree (identifier_copy);
		return (-1);
	}

	sstrncpy (vl.host, hostname, sizeof (vl.host));
	sstrncpy (vl.plugin, plugin, sizeof (vl.plugin));
	sstrncpy (vl.type, type, sizeof (vl.type));
	if (plugin_instance != NULL)
		sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
	if (type_instance != NULL)
		sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));

	ds = plugin_get_ds (type);
	if (ds == NULL) {
		print_to_socket (fh, "-1 Type `%s' isn't defined.\n", type);
		sfree (identifier_copy);
		return (-1);
	}

	/* Free identifier_copy */
	hostname = NULL;
	plugin = NULL; plugin_instance = NULL;
	type = NULL;   type_instance = NULL;
	sfree (identifier_copy);

	vl.values_len = ds->ds_num;
	vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
	if (vl.values == NULL)
	{
		print_to_socket (fh, "-1 malloc failed.\n");
		return (-1);
	}

	/* All the remaining fields are part of the optionlist. */
	values_submitted = 0;
	while (*buffer != 0)
	{
		char *string = NULL;
		char *value  = NULL;

		status = parse_option (&buffer, &string, &value);
		if (status < 0)
		{
			/* parse_option failed, buffer has been modified.
			 * => we need to abort */
			print_to_socket (fh, "-1 Misformatted option.\n");
			return (-1);
		}
		else if (status == 0)
		{
			assert (string != NULL);
			assert (value != NULL);
			set_option (&vl, string, value);
			continue;
		}
		/* else: parse_option but buffer has not been modified. This is
		 * the default if no `=' is found.. */

		status = parse_string (&buffer, &string);
		if (status != 0)
		{
			print_to_socket (fh, "-1 Misformatted value.\n");
			return (-1);
		}
		assert (string != NULL);

		status = dispatch_values (ds, &vl, fh, string);
		if (status != 0)
		{
			/* An error has already been printed. */
			return (-1);
		}
		values_submitted++;
	} /* while (*buffer != 0) */
	/* Done parsing the options. */

	print_to_socket (fh, "0 Success: %i %s been dispatched.\n",
			values_submitted,
			(values_submitted == 1) ? "value has" : "values have");

	sfree (vl.values); 

	return (0);
} /* int handle_putval */
예제 #23
0
static c_psql_database_t *c_psql_database_new (const char *name)
{
	c_psql_database_t **tmp;
	c_psql_database_t  *db;

	db = (c_psql_database_t *)malloc (sizeof(*db));
	if (NULL == db) {
		log_err ("Out of memory.");
		return NULL;
	}

	tmp = (c_psql_database_t **)realloc (databases,
			(databases_num + 1) * sizeof (*databases));
	if (NULL == tmp) {
		log_err ("Out of memory.");
		sfree (db);
		return NULL;
	}

	databases = tmp;
	databases[databases_num] = db;
	++databases_num;

	db->conn = NULL;

	C_COMPLAIN_INIT (&db->conn_complaint);

	db->proto_version = 0;
	db->server_version = 0;

	db->max_params_num = 0;

	db->q_prep_areas   = NULL;
	db->queries        = NULL;
	db->queries_num    = 0;

	db->writers        = NULL;
	db->writers_num    = 0;

	pthread_mutex_init (&db->db_lock, /* attrs = */ NULL);

	db->interval   = 0;

	db->commit_interval = 0;
	db->next_commit     = 0;

	db->database   = sstrdup (name);
	db->host       = NULL;
	db->port       = NULL;
	db->user       = NULL;
	db->password   = NULL;

	db->instance   = sstrdup (name);

	db->sslmode    = NULL;

	db->krbsrvname = NULL;

	db->service    = NULL;

	db->ref_cnt    = 0;
	return db;
} /* c_psql_database_new */
예제 #24
0
/**
 * Adds a new user to anopes internal userlist.
 *
 * If the SVID passed is 2, the user will not be marked registered or requested to ID.
 * This is an addition to accomodate IRCds where we cannot determine this based on the NICK 
 * or UID command. Some IRCd's keep +r on when changing nicks and do not use SVID (ex. InspIRCd 1.2).
 * Instead we get a METADATA command containing the accountname the user was last identified to.
 * Since this is received after the user is introduced to us we should not yet mark the user
 * as identified or ask him to identify. We will mark him as recognized for the time being and let
 * him keep his +r if he has it.
 * It is the responsibility of the protocol module to make sure that this is either invalidated,
 * or changed to identified. ~ Viper
 **/
User *do_nick(const char *source, char *nick, char *username, char *host,
              char *server, char *realname, time_t ts, uint32 svid,
              uint32 ip, char *vhost, char *uid)
{
    User *user = NULL;

    char *tmp = NULL;
    NickAlias *old_na;          /* Old nick rec */
    int nc_changed = 1;         /* Did nick core change? */
    int status = 0;             /* Status to apply */
    char mask[USERMAX + HOSTMAX + 2];
    char *logrealname;
    char *oldnick;

    if (!*source) {
        char ipbuf[16];
        struct in_addr addr;

        if (ircd->nickvhost) {
            if (vhost) {
                if (!strcmp(vhost, "*")) {
                    vhost = NULL;
                    if (debug)
                        alog("debug: new user�with no vhost in NICK command: %s", nick);
                }
            }
        }

        /* This is a new user; create a User structure for it. */
        if (debug)
            alog("debug: new user: %s", nick);

        if (ircd->nickip) {
            addr.s_addr = htonl(ip);
            ntoa(addr, ipbuf, sizeof(ipbuf));
        }


        if (LogUsers) {
        /**
         * Ugly swap routine for Flop's bug :)
         **/
            if (realname) {
                tmp = strchr(realname, '%');
                while (tmp) {
                    *tmp = '-';
                    tmp = strchr(realname, '%');
                }
            }
            logrealname = normalizeBuffer(realname);

        /**
         * End of ugly swap
         **/

            if (ircd->nickvhost) {
                if (ircd->nickip) {
                    alog("LOGUSERS: %s (%s@%s => %s) (%s) [%s] connected to the network (%s).", nick, username, host, (vhost ? vhost : "none"), logrealname, ipbuf, server);
                } else {
                    alog("LOGUSERS: %s (%s@%s => %s) (%s) connected to the network (%s).", nick, username, host, (vhost ? vhost : "none"), logrealname, server);
                }
            } else {
                if (ircd->nickip) {
                    alog("LOGUSERS: %s (%s@%s) (%s) [%s] connected to the network (%s).", nick, username, host, logrealname, ipbuf, server);
                } else {
                    alog("LOGUSERS: %s (%s@%s) (%s) connected to the network (%s).", nick, username, host, logrealname, server);
                }
            }
            Anope_Free(logrealname);
        }

        /* We used to ignore the ~ which a lot of ircd's use to indicate no
         * identd response.  That caused channel bans to break, so now we
         * just take what the server gives us.  People are still encouraged
         * to read the RFCs and stop doing anything to usernames depending
         * on the result of an identd lookup.
         */

        /* First check for AKILLs. */
        /* DONT just return null if its an akill match anymore - yes its more efficent to, however, now that ircd's are
         * starting to use things like E/F lines, we cant be 100% sure the client will be removed from the network :/
         * as such, create a user_struct, and if the client is removed, we'll delete it again when the QUIT notice
         * comes in from the ircd.
         **/
        if (check_akill(nick, username, host, vhost, ipbuf)) {
/*            return NULL; */
        }

/**
 * DefCon AKILL system, if we want to akill all connecting user's here's where to do it
 * then force check_akill again on them...
 **/
        /* don't akill on netmerges -Certus */
        /* don't akill clients introduced by ulines. -Viper */
        if (is_sync(findserver(servlist, server))
            && checkDefCon(DEFCON_AKILL_NEW_CLIENTS) && !is_ulined(server)) {
            strncpy(mask, "*@", 3);
            strncat(mask, host, HOSTMAX);
            alog("DEFCON: adding akill for %s", mask);
            add_akill(NULL, mask, s_OperServ,
                      time(NULL) + dotime(DefConAKILL),
                      DefConAkillReason ? DefConAkillReason :
                      "DEFCON AKILL");
            if (check_akill(nick, username, host, vhost, ipbuf)) {
/*            return NULL; */
            }
        }

        /* SGLINE */
        if (ircd->sgline) {
            if (check_sgline(nick, realname))
                return NULL;
        }

        /* SQLINE */
        if (ircd->sqline) {
            if (check_sqline(nick, 0))
                return NULL;
        }

        /* SZLINE */
        if (ircd->szline && ircd->nickip) {
            if (check_szline(nick, ipbuf))
                return NULL;
        }
        /* Now check for session limits */
        if (LimitSessions && !is_ulined(server)
            && !add_session(nick, host, ipbuf))
            return NULL;

        /* Allocate User structure and fill it in. */
        user = new_user(nick);
        user->username = sstrdup(username);
        user->host = sstrdup(host);
        user->server = findserver(servlist, server);
        user->realname = sstrdup(realname);
        user->timestamp = ts;
        user->my_signon = time(NULL);
        user->chost = vhost ? sstrdup(vhost) : sstrdup(host);
        user->vhost = vhost ? sstrdup(vhost) : sstrdup(host);
        if (uid) {
            user->uid = sstrdup(uid);   /* p10/ts6 stuff */
        } else {
            user->uid = NULL;
        }
        user->vident = sstrdup(username);
        /* We now store the user's ip in the user_ struct,
         * because we will use it in serveral places -- DrStein */
        if (ircd->nickip) {
            user->hostip = sstrdup(ipbuf);
        } else {
            user->hostip = NULL;
        }

        if (svid == 0) {
            display_news(user, NEWS_LOGON);
            display_news(user, NEWS_RANDOM);
        }

        if (svid == 2 && user->na) {
            /* We do not yet know if the user should be identified or not.
             * mark him as recognized for now. 
             * It s up to the protocol module to make sure this either becomes ID'd or
             * is invalidated. ~ Viper */
            if (debug) 
                alog("debug: Marking %s as recognized..", user->nick);
            user->svid = 1;
            user->na->status |= NS_RECOGNIZED;
            nc_changed = 0;
        } else if (svid == ts && user->na) {
            /* Timestamp and svid match, and nick is registered; automagically identify the nick */
            user->svid = svid;
            user->na->status |= NS_IDENTIFIED;
            check_memos(user);
            nc_changed = 0;

            /* Start nick tracking if available */
            if (NSNickTracking)
                nsStartNickTracking(user);

        } else if (svid != 1) {
            /* Resets the svid because it doesn't match */
            user->svid = 1;

            anope_cmd_svid_umode(user->nick, user->timestamp);

        } else {
            user->svid = 1;
        }
        send_event(EVENT_NEWNICK, 1, nick);

    } else {
        /* An old user changing nicks. */
        if (UseTS6 && ircd->ts6)
            user = find_byuid(source);

        if (!user)
            user = finduser(source);

        if (!user) {
            alog("user: NICK from nonexistent nick %s", source);
            return NULL;
        }
        user->isSuperAdmin = 0; /* Dont let people nick change and stay SuperAdmins */
        if (debug)
            alog("debug: %s changes nick to %s", source, nick);

        if (LogUsers) {
            logrealname = normalizeBuffer(user->realname);
            if (ircd->vhost) {
                alog("LOGUSERS: %s (%s@%s => %s) (%s) changed nick to %s (%s).", user->nick, user->username, user->host, (user->vhost ? user->vhost : "(none)"), logrealname, nick, user->server->name);
            } else {
                alog("LOGUSERS: %s (%s@%s) (%s) changed nick to %s (%s).",
                     user->nick, user->username, user->host, logrealname,
                     nick, user->server->name);
            }
            if (logrealname) {
                free(logrealname);
            }
        }

        user->timestamp = ts;

        if (stricmp(nick, user->nick) == 0) {
            /* No need to redo things */
            change_user_nick(user, nick);
            nc_changed = 0;
        } else {
            /* Update this only if nicks aren't the same */
            user->my_signon = time(NULL);

            old_na = user->na;
            if (old_na) {
                if (nick_recognized(user))
                    user->na->last_seen = time(NULL);
                status = old_na->status & NS_TRANSGROUP;
                cancel_user(user);
            }

            oldnick = sstrdup(user->nick);
            change_user_nick(user, nick);

            if ((old_na ? old_na->nc : NULL) ==
                (user->na ? user->na->nc : NULL))
                nc_changed = 0;

            if (!nc_changed && (user->na))
                user->na->status |= status;
            else {
                anope_cmd_nc_change(user);
            }

            send_event(EVENT_CHANGE_NICK, 2, nick, oldnick);
            free(oldnick);
        }

        if (ircd->sqline) {
            if (!is_oper(user) && check_sqline(user->nick, 1))
                return NULL;
        }

    }                           /* if (!*source) */

    /* Check for nick tracking to bypass identification */
    if (NSNickTracking && nsCheckNickTracking(user)) {
        user->na->status |= NS_IDENTIFIED;
        nc_changed = 0;
    }

    if (nc_changed || !nick_recognized(user)) {
        if (validate_user(user))
            check_memos(user);

    } else {
        if (nick_identified(user)) {
            char tsbuf[16];
            user->na->last_seen = time(NULL);

            if (user->na->last_usermask)
                free(user->na->last_usermask);
            user->na->last_usermask =
                smalloc(strlen(common_get_vident(user)) +
                        strlen(common_get_vhost(user)) + 2);
            sprintf(user->na->last_usermask, "%s@%s",
                    common_get_vident(user), common_get_vhost(user));

            snprintf(tsbuf, sizeof(tsbuf), "%lu",
                     (unsigned long int) user->timestamp);
            anope_cmd_svid_umode2(user, tsbuf);

            alog("%s: %s!%s@%s automatically identified for nick %s",
                 s_NickServ, user->nick, user->username,
                 user->host, user->nick);
        }
    }

    /* Bahamut sets -r on every nick changes, so we must test it even if nc_changed == 0 */
    if (ircd->check_nick_id) {
        if (nick_identified(user)) {
            char tsbuf[16];
            snprintf(tsbuf, sizeof(tsbuf), "%lu",
                     (unsigned long int) user->timestamp);
            anope_cmd_svid_umode3(user, tsbuf);
        }
    }

    return user;
}
예제 #25
0
/**
 * The /ns identify command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
int do_identify(User * u)
{
    char *pass = strtok(NULL, " ");
    NickAlias *na;
    NickRequest *nr;
    int res;
    char tsbuf[16];
    char modes[512];
    int len;

    if (!pass) {
        syntax_error(s_NickServ, u, "IDENTIFY", NICK_IDENTIFY_SYNTAX);
    } else if (!(na = u->na)) {
        if ((nr = findrequestnick(u->nick))) {
            notice_lang(s_NickServ, u, NICK_IS_PREREG);
        } else {
            notice_lang(s_NickServ, u, NICK_NOT_REGISTERED);
        }
    } else if (na->status & NS_VERBOTEN) {
        notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
    } else if (na->nc->flags & NI_SUSPENDED) {
        notice_lang(s_NickServ, u, NICK_X_SUSPENDED, na->nick);
    } else if (nick_identified(u)) {
        notice_lang(s_NickServ, u, NICK_ALREADY_IDENTIFIED);
    } else if (!(res = enc_check_password(pass, na->nc->pass))) {
        alog("%s: Failed IDENTIFY for %s!%s@%s", s_NickServ, u->nick,
             u->username, u->host);
        notice_lang(s_NickServ, u, PASSWORD_INCORRECT);
        bad_password(u);
    } else if (res == -1) {
        notice_lang(s_NickServ, u, NICK_IDENTIFY_FAILED);
    } else {
        if (!(na->status & NS_IDENTIFIED) && !(na->status & NS_RECOGNIZED)) {
            if (na->last_usermask)
                free(na->last_usermask);
            na->last_usermask =
                scalloc(strlen(common_get_vident(u)) +
                        strlen(common_get_vhost(u)) + 2, 1);
            sprintf(na->last_usermask, "%s@%s", common_get_vident(u),
                    common_get_vhost(u));
            if (na->last_realname)
                free(na->last_realname);
            na->last_realname = sstrdup(u->realname);
        }

        na->status |= NS_IDENTIFIED;
        na->last_seen = time(NULL);
        snprintf(tsbuf, sizeof(tsbuf), "%lu",
                 (unsigned long int) u->timestamp);

        if (ircd->modeonreg) {
            len = strlen(ircd->modeonreg);
	    strncpy(modes,ircd->modeonreg,512);
	    if(ircd->rootmodeonid && is_services_root(u)) { 
                strncat(modes,ircd->rootmodeonid,512-len);
	    } else if(ircd->adminmodeonid && is_services_admin(u)) {
                strncat(modes,ircd->adminmodeonid,512-len);
	    } else if(ircd->opermodeonid && is_services_oper(u)) {
                strncat(modes,ircd->opermodeonid,512-len);
	    }
            if (ircd->tsonmode) {
                common_svsmode(u, modes, tsbuf);
            } else {
                common_svsmode(u, modes, "");
            }
        }
        send_event(EVENT_NICK_IDENTIFY, 1, u->nick);
        alog("%s: %s!%s@%s identified for nick %s", s_NickServ, u->nick,
             u->username, u->host, u->nick);
        notice_lang(s_NickServ, u, NICK_IDENTIFY_SUCCEEDED);
        if (ircd->vhost) {
            do_on_id(u);
        }
        if (NSModeOnID) {
            do_setmodes(u);
        }

        if (NSForceEmail && u->na && !u->na->nc->email) {
            notice_lang(s_NickServ, u, NICK_IDENTIFY_EMAIL_REQUIRED);
            notice_help(s_NickServ, u, NICK_IDENTIFY_EMAIL_HOWTO);
        }

        if (!(na->status & NS_RECOGNIZED))
            check_memos(u);

        /* Enable nick tracking if enabled */
        if (NSNickTracking)
            nsStartNickTracking(u);

        /* Clear any timers */
        if (na->nc->flags & NI_KILLPROTECT) {
            del_ns_timeout(na, TO_COLLIDE);
        }

    }
    return MOD_CONT;
}
예제 #26
0
파일: seen.c 프로젝트: wodim/irc-hispano
/**
 * Seen
 **/
char *do_seen(User * u, char *target)
{
    char *split1 = NULL;
    char *seenhost = NULL;
    char *seennick = NULL;
    char *seenuname = NULL;
    struct tm tm;
    char buf[255];
    int i;
    MYSQL_RES *mysql_res;
    char *sqltarget;
    char usrchans[1024] = "\0";
    time_t tsnow = time(NULL);
    MYSQL_RES *mysql_res2;
    MYSQL_ROW mysql_row2;
    char cmodep[32] = "\0";
    char cmodes[32] = "\0";
    char cmodeA[32] = "\0";
    char cmodeO[32] = "\0";
    char umodep[32] = "\0";
	char umodeQ[32] = "\0";
	char umodeI[32] = "\0";
    double ctsdiff;
    time_t time0 = time(NULL);
    time_t time1 = time(NULL);
	time_t tt = time(NULL);
    char *message;
	char *uname = NULL;
    message = malloc(1024);

    sqltarget = rdb_escape(rdb_escape(target));
    for (i = 0; sqltarget[i]; i++)
        if (sqltarget[i] == '*')
            sqltarget[i] = '%';
    seenhost = myStrGetToken(sqltarget, '@', 1);
    split1 = myStrGetToken(sqltarget, '@', 0);
    seennick = myStrGetToken(split1, '!', 0);
    seenuname = myStrGetToken(split1, '!', 1);
    if (seenhost == NULL)
        seenhost = (char *) "%";
    if (seennick == NULL)
        seennick = (char *) "%";
    if (seenuname == NULL)
        seenuname = (char *) "%";
    free(sqltarget);
	
	if (!strcmp(seennick, "%")) {
		uname = sstrdup("%");
	} else {	
		rdb_query(QUERY_LOW, "SELECT uname FROM %s WHERE nick LIKE \'%s\' ",
					  AliasesTable, seennick);
		mysql_res = mysql_store_result(mysql);
		if (mysql_res && mysql_num_rows(mysql_res)) {
			mysql_row = mysql_fetch_row(mysql_res);
			uname = rdb_escape(mysql_row[0]);
		}
	}
	
	if (uname) {
		rdb_query(QUERY_LOW,
              "SELECT %s.nickid, %s.nick, %s.hostname, %s.hiddenhostname, %s.username, UNIX_TIMESTAMP(%s.connecttime), %s.away, %s.awaymsg, %s.online, UNIX_TIMESTAMP(%s.lastquit), %s.lastquitmsg FROM %s,%s,%s WHERE %s.uname LIKE \"%s\" AND %s.nick = %s.nick AND %s.username LIKE \"%s\" AND (%s.hostname LIKE \"%s\" OR %s.hiddenhostname LIKE \"%s\") AND %s.server = %s.server AND %s.uline = \"0\" ORDER BY online,lastquit DESC, %s.connecttime ASC LIMIT 1;",
              UserTable, UserTable, UserTable, UserTable, UserTable,
              UserTable, UserTable, UserTable, UserTable, UserTable,
              UserTable, UserTable, ServerTable, AliasesTable,
              AliasesTable, uname, UserTable,
              AliasesTable, UserTable, seenuname, UserTable, seenhost,
              UserTable, seenhost, UserTable, ServerTable, ServerTable, UserTable);
		mysql_res = mysql_store_result(mysql);
	} else {
		rdb_query(QUERY_LOW,
              "SELECT %s.nickid, %s.nick, %s.hostname, %s.hiddenhostname, %s.username, UNIX_TIMESTAMP(%s.connecttime), %s.away, %s.awaymsg, %s.online, UNIX_TIMESTAMP(%s.lastquit), %s.lastquitmsg FROM %s,%s WHERE %s.nick LIKE \"%s\" AND %s.username LIKE \"%s\" AND (%s.hostname LIKE \"%s\" OR %s.hiddenhostname LIKE \"%s\") AND %s.server = %s.server AND %s.uline = \"0\" ORDER BY online,lastquit DESC, %s.connecttime ASC LIMIT 1;",
              UserTable, UserTable, UserTable, UserTable, UserTable,
              UserTable, UserTable, UserTable, UserTable, UserTable,
              UserTable, UserTable, ServerTable, UserTable, seennick,
              UserTable, seenuname, UserTable, seenhost,
              UserTable, seenhost, UserTable, ServerTable, ServerTable, UserTable);
		mysql_res = mysql_store_result(mysql);
	}

    if (mysql_num_rows(mysql_res) > 0) {
        SET_SEGV_LOCATION();
        while ((mysql_row = mysql_fetch_row(mysql_res)) != NULL) {
            double tsdiff;
            if (mysql_row[5] != NULL) { 
                time0 = atoi(mysql_row[5]); /* connect time */
            }
            if (mysql_row[9] != NULL) {   
                time1 = atoi(mysql_row[9]); /* quit time */
            }
            if (strlen(mysql_row[3]) <= 1)
                mysql_row[3] = mysql_row[2];    /* no vhost, so using real host */
            if (stricmp(mysql_row[8], "Y") == 0) {
                if (mysql_row[5] != NULL) {
					tt = atoi(mysql_row[5]);
					tm = *localtime(&tt);
                    strftime(buf, sizeof(buf), "%d.%m %H:%M", &tm);
                    mysql_row[5] = buf;
                }

                /* Display channels the user is in */
                /* check for ircd compatibility: chanmodes +AOsp and usermode +p */
                if (denora_cmode(CMODE_p) == 1)
                    sprintf(cmodep, "AND %s.mode_lp = 'N' ", ChanTable);
                if (denora_cmode(CMODE_s) == 1)
                    sprintf(cmodes, "AND %s.mode_ls = 'N' ", ChanTable);
                if (denora_cmode(CMODE_A) == 1)
                    sprintf(cmodeA, "AND %s.mode_ua = 'N' ", ChanTable);
                if (denora_cmode(CMODE_O) == 1)
                    sprintf(cmodeO, "AND %s.mode_uo = 'N' ", ChanTable);
                if (denora_umode(UMODE_p) == 1)
                    sprintf(umodep, "AND %s.mode_lp = 'N' ", UserTable);
				if (denora_get_ircd() == IRC_INSPIRCD11 || denora_get_ircd() == IRC_INSPIRCD12) {
					if (denora_umode(UMODE_Q) == 1)
						sprintf(umodeQ, "AND %s.mode_uq = 'N' ", UserTable);
					if (denora_umode(UMODE_I) == 1)
						sprintf(umodeI, "AND %s.mode_ui = 'N' ", UserTable);
				}
                rdb_query(QUERY_LOW,
                          "SELECT %s.channel FROM %s,%s,%s WHERE %s.nickid =%s AND %s.chanid = %s.chanid AND %s.nickid = %s.nickid %s%s%s%s%s%s%s ORDER BY %s.channel ASC",
                          ChanTable, ChanTable, UserTable, IsOnTable,
                          IsOnTable, mysql_row[0], ChanTable, IsOnTable,
                          UserTable, IsOnTable, cmodep, cmodes, cmodeA,
                          cmodeO, umodep, umodeQ, umodeI, ChanTable);
                mysql_res2 = mysql_store_result(mysql);
                while ((mysql_row2 = mysql_fetch_row(mysql_res2)) != NULL) {
                    strlcat(usrchans, mysql_row2[0], sizeof(usrchans));
                    strlcat(usrchans, " ", sizeof(usrchans));
                }
                mysql_free_result(mysql_res2);

                ctsdiff = difftime(tsnow, time0);       /* total online time */

                /* Prepare the reply for the user */
                if (stricmp(mysql_row[6], "N") == 0) {
                    if (strlen(usrchans) < 3) {
                        sprintf(message,
                                moduleGetLangString(u, SEEN_ONLINE),
                                mysql_row[1], mysql_row[4], mysql_row[3],
                                get_timestring(u, ctsdiff), mysql_row[5]);
                    } else {
                        sprintf(message,
                                moduleGetLangString(u, SEEN_ONLINEC),
                                mysql_row[1], mysql_row[4], mysql_row[3],
                                get_timestring(u, ctsdiff), mysql_row[5],
                                usrchans);
                    }
                } else {
                    if (strlen(usrchans) < 3) {
                        sprintf(message, moduleGetLangString(u, SEEN_AWAY),
                                mysql_row[1], mysql_row[4], mysql_row[3],
                                get_timestring(u, ctsdiff), mysql_row[5],
                                mysql_row[7]);
                    } else {
                        sprintf(message,
                                moduleGetLangString(u, SEEN_AWAYC),
                                mysql_row[1], mysql_row[4], mysql_row[3],
                                get_timestring(u, ctsdiff), mysql_row[5],
                                mysql_row[7], usrchans);
                    }
                }
            } else {
                double dtsdiff;
                if (mysql_row[9] != NULL && mysql_row[5] != NULL) {
					tt = atoi(mysql_row[9]);
					tm = *localtime(&tt);
                    strftime(buf, sizeof(buf), "%d.%m %H:%M", &tm);
                    mysql_row[9] = buf;
                    dtsdiff = difftime(tsnow, time1);   /* total offline time */
                    tsdiff = difftime(time1, time0);    /* total online time */
                    sprintf(message, moduleGetLangString(u, SEEN_OFFLINE),
                            mysql_row[1], mysql_row[4], mysql_row[3],
                            get_timestring(u, dtsdiff), mysql_row[9],
                            get_timestring(u, tsdiff), mysql_row[10]);
                } else {
                    sprintf(message, moduleGetLangString(u, SEEN_UNKNOWN),
                            mysql_row[1], mysql_row[4], mysql_row[3]);
                }
            }
        }
    } else {
        sprintf(message, moduleGetLangString(u, SEEN_EMPTY), target);
    }
    SET_SEGV_LOCATION();
    mysql_free_result(mysql_res);

    return message;
}
예제 #27
0
int do_saregister(User *u)
{
	char *buf, *nick, *pass, *email;
	NickRequest *nr;
	NickAlias *na;
	User *user;

	buf = moduleGetLastBuffer();
	nick = myStrGetToken(buf, ' ', 0);
	pass = myStrGetToken(buf, ' ', 1);
	email = myStrGetToken(buf, ' ', 2);

	if (!email)
	{
		notice_user(s_NickServ, u, "Syntax: \2SAREGISTER \37nick\37 \37password\37 \37email\37");
		notice_lang(s_NickServ, u, MORE_INFO, s_NickServ, "SAREGISTER");
	}
	else if (readonly)
	{
		notice_lang(s_NickServ, u, NICK_REGISTRATION_DISABLED);
	}
	else if ((nr = findrequestnick(nick)))
	{
		notice_lang(s_NickServ, u, NICK_REQUESTED);
	}
	else if (!anope_valid_nick(nick))
	{
		notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick);
	}
	else if ((na = findnick(nick)))
	{
		if (na->status & NS_VERBOTEN)
			notice_lang(s_NickServ, u, NICK_CANNOT_BE_REGISTERED, nick);
		else
			notice_lang(s_NickServ, u, NICK_ALREADY_REGISTERED, nick);
	}
	else if (!MailValidate(email))
	{
		notice_lang(s_NickServ, u, MAIL_X_INVALID, email);
	}
	else
	{
		na = makenick(nick);

		if (!na)
		{
			alog("%s: makenick(%s) failed", s_NickServ, u->nick);
			notice_lang(s_NickServ, u, NICK_REGISTRATION_FAILED);
		}
		else
		{
			user = finduser(nick);

			enc_encrypt(pass, strlen(pass), na->nc->pass, PASSMAX - 1);
			na->nc->flags |= NSDefFlags;
			na->nc->memos.memomax = MSMaxMemos;
			if (user)
				na->last_usermask = user->vhost ? sstrdup(user->vhost) : sstrdup(user->host);
			else
				na->last_usermask = sstrdup("*@*");
			if (user)
				na->last_realname = sstrdup(user->realname);
			else
				na->last_realname = sstrdup("unknown");
			na->time_registered = na->last_seen = time(NULL);
			na->nc->language = NSDefLanguage;
			na->nc->email = sstrdup(email);

			send_event(EVENT_NICK_REGISTERED, 1, nick);
			
			alog("%s: %s (%s@%s) used saregister to register %s", s_NickServ, u->nick, u->username, u->host, nick);

			notice_user(s_NickServ, u, "Nick \2%s\2 has been registered", nick);

			if (user)
			{
				user->na = na;
				validate_user(user);
			}
		}
	}

	if (email)
		free(email);
	if (pass)
		free(pass);
	if (nick)
		free(nick);

	return MOD_CONT;
}
예제 #28
0
int handle_getthreshold (FILE *fh, char *buffer)
{
  char *command;
  char *identifier;
  char *identifier_copy;

  char *host;
  char *plugin;
  char *plugin_instance;
  char *type;
  char *type_instance;

  value_list_t vl;
  threshold_t threshold;

  int   status;
  size_t i;

  if ((fh == NULL) || (buffer == NULL))
    return (-1);

  DEBUG ("utils_cmd_getthreshold: handle_getthreshold (fh = %p, buffer = %s);",
      (void *) fh, buffer);

  command = NULL;
  status = parse_string (&buffer, &command);
  if (status != 0)
  {
    print_to_socket (fh, "-1 Cannot parse command.\n");
    return (-1);
  }
  assert (command != NULL);

  if (strcasecmp ("GETTHRESHOLD", command) != 0)
  {
    print_to_socket (fh, "-1 Unexpected command: `%s'.\n", command);
    return (-1);
  }

  identifier = NULL;
  status = parse_string (&buffer, &identifier);
  if (status != 0)
  {
    print_to_socket (fh, "-1 Cannot parse identifier.\n");
    return (-1);
  }
  assert (identifier != NULL);

  if (*buffer != 0)
  {
    print_to_socket (fh, "-1 Garbage after end of command: %s\n", buffer);
    return (-1);
  }

  /* parse_identifier() modifies its first argument,
   * returning pointers into it */
  identifier_copy = sstrdup (identifier);

  status = parse_identifier (identifier_copy, &host,
      &plugin, &plugin_instance,
      &type, &type_instance);
  if (status != 0)
  {
    DEBUG ("handle_getthreshold: Cannot parse identifier `%s'.", identifier);
    print_to_socket (fh, "-1 Cannot parse identifier `%s'.\n", identifier);
    sfree (identifier_copy);
    return (-1);
  }

  memset (&vl, 0, sizeof (vl));
  sstrncpy (vl.host, host, sizeof (vl.host));
  sstrncpy (vl.plugin, plugin, sizeof (vl.plugin));
  if (plugin_instance != NULL)
    sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
  sstrncpy (vl.type, type, sizeof (vl.type));
  if (type_instance != NULL)
    sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
  sfree (identifier_copy);

  memset (&threshold, 0, sizeof (threshold));
  status = ut_search_threshold (&vl, &threshold);
  if (status == ENOENT)
  {
    print_to_socket (fh, "-1 No threshold found for identifier %s\n",
        identifier);
    return (0);
  }
  else if (status != 0)
  {
    print_to_socket (fh, "-1 Error while looking up threshold: %i\n",
        status);
    return (-1);
  }

  /* Lets count the number of lines we'll return. */
  i = 0;
  if (threshold.host[0] != 0)            i++;
  if (threshold.plugin[0] != 0)          i++;
  if (threshold.plugin_instance[0] != 0) i++;
  if (threshold.type[0] != 0)            i++;
  if (threshold.type_instance[0] != 0)   i++;
  if (threshold.data_source[0] != 0)     i++;
  if (!isnan (threshold.warning_min))    i++;
  if (!isnan (threshold.warning_max))    i++;
  if (!isnan (threshold.failure_min))    i++;
  if (!isnan (threshold.failure_max))    i++;
  if (threshold.hysteresis > 0.0)        i++;
  if (threshold.hits > 1)                i++;

  /* Print the response */
  print_to_socket (fh, "%zu Threshold found\n", i);

  if (threshold.host[0] != 0)
    print_to_socket (fh, "Host: %s\n", threshold.host)
  if (threshold.plugin[0] != 0)
    print_to_socket (fh, "Plugin: %s\n", threshold.plugin)
  if (threshold.plugin_instance[0] != 0)
    print_to_socket (fh, "Plugin Instance: %s\n", threshold.plugin_instance)
  if (threshold.type[0] != 0)
    print_to_socket (fh, "Type: %s\n", threshold.type)
  if (threshold.type_instance[0] != 0)
    print_to_socket (fh, "Type Instance: %s\n", threshold.type_instance)
  if (threshold.data_source[0] != 0)
    print_to_socket (fh, "Data Source: %s\n", threshold.data_source)
  if (!isnan (threshold.warning_min))
    print_to_socket (fh, "Warning Min: %g\n", threshold.warning_min)
  if (!isnan (threshold.warning_max))
    print_to_socket (fh, "Warning Max: %g\n", threshold.warning_max)
  if (!isnan (threshold.failure_min))
    print_to_socket (fh, "Failure Min: %g\n", threshold.failure_min)
  if (!isnan (threshold.failure_max))
    print_to_socket (fh, "Failure Max: %g\n", threshold.failure_max)
  if (threshold.hysteresis > 0.0)
    print_to_socket (fh, "Hysteresis: %g\n", threshold.hysteresis)
  if (threshold.hits > 1)
    print_to_socket (fh, "Hits: %i\n", threshold.hits)

  return (0);
} /* int handle_getthreshold */
예제 #29
0
int atheme_main(int argc, char *argv[])
{
	int daemonize_pipe[2];
	bool have_conf = false;
	bool have_log = false;
	bool have_datadir = false;
	char buf[32];
	int pid, r;
	FILE *pid_file;
	const char *pidfilename = RUNDIR "/atheme.pid";
	char *log_p = NULL;
	mowgli_getopt_option_t long_opts[] = {
		{ NULL, 0, NULL, 0, 0 },
	};

	atheme_bootstrap();

	/* do command-line options */
	while ((r = mowgli_getopt_long(argc, argv, "c:dhrl:np:D:v", long_opts, NULL)) != -1)
	{
		switch (r)
		{
		  case 'c':
			  config_file = sstrdup(mowgli_optarg);
			  have_conf = true;
			  break;
		  case 'd':
			  log_force = true;
			  break;
		  case 'h':
			  print_help();
			  exit(EXIT_SUCCESS);
			  break;
		  case 'r':
			  readonly = true;
			  break;
		  case 'l':
			  log_p = sstrdup(mowgli_optarg);
			  have_log = true;
			  break;
		  case 'n':
			  runflags |= RF_LIVE;
			  break;
		  case 'p':
			  pidfilename = mowgli_optarg;
			  break;
		  case 'D':
			  datadir = mowgli_optarg;
			  have_datadir = true;
			  break;
		  case 'v':
			  print_version();
			  exit(EXIT_SUCCESS);
			  break;
		  default:
			  printf("usage: atheme [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n");
			  exit(EXIT_FAILURE);
			  break;
		}
	}

	if (!have_conf)
		config_file = sstrdup(SYSCONFDIR "/atheme.conf");

	if (!have_log)
		log_p = sstrdup(LOGDIR "/atheme.log");

	if (!have_datadir)
		datadir = sstrdup(DATADIR);

	cold_start = true;

	runflags |= RF_STARTING;

	atheme_init(argv[0], log_p);

	slog(LG_INFO, "%s is starting up...", PACKAGE_STRING);

	/* check for pid file */
#ifndef MOWGLI_OS_WIN
	if ((pid_file = fopen(pidfilename, "r")))
	{
		if (fgets(buf, 32, pid_file))
		{
			pid = atoi(buf);

			if (!kill(pid, 0))
			{
				fprintf(stderr, "atheme: daemon is already running\n");
				exit(EXIT_FAILURE);
			}
		}

		fclose(pid_file);
	}
#endif

	if (!(runflags & RF_LIVE))
		daemonize(daemonize_pipe);

	atheme_setup();

	conf_init();
	if (!conf_parse(config_file))
	{
		slog(LG_ERROR, "Error loading config file %s, aborting",
				config_file);
		exit(EXIT_FAILURE);
	}

	if (config_options.languagefile)
	{
		slog(LG_DEBUG, "Using language: %s", config_options.languagefile);
		if (!conf_parse(config_options.languagefile))
			slog(LG_INFO, "Error loading language file %s, continuing",
					config_options.languagefile);
	}

	if (!backend_loaded && authservice_loaded)
	{
		slog(LG_ERROR, "atheme: no backend modules loaded, see your configuration file.");
		exit(EXIT_FAILURE);
	}

	/* we've done the critical startup steps now */
	cold_start = false;

	/* load our db */
	if (db_load)
		db_load(NULL);
	else if (backend_loaded)
	{
		slog(LG_ERROR, "atheme: backend module does not provide db_load()!");
		exit(EXIT_FAILURE);
	}
	db_check();

#ifdef HAVE_GETPID
	/* write pid */
	if ((pid_file = fopen(pidfilename, "w")))
	{
		fprintf(pid_file, "%d\n", getpid());
		fclose(pid_file);
	}
	else
	{
		fprintf(stderr, "atheme: unable to write pid file\n");
		exit(EXIT_FAILURE);
	}
#endif

	/* detach from terminal */
	if ((runflags & RF_LIVE) || !detach_console(daemonize_pipe))
	{
#ifdef HAVE_GETPID
		slog(LG_INFO, "pid %d", getpid());
#endif
		slog(LG_INFO, "running in foreground mode from %s", PREFIX);
	}

	/* no longer starting */
	runflags &= ~RF_STARTING;

	/* we probably have a few open already... */
	me.maxfd = 3;

	/* DB commit interval is configurable */
	if (db_save && !readonly)
		mowgli_timer_add(base_eventloop, "db_save", db_save, NULL, config_options.commit_interval);

	/* check expires every hour */
	mowgli_timer_add(base_eventloop, "expire_check", expire_check, NULL, 3600);

	/* check k/x/q line expires every minute */
	mowgli_timer_add(base_eventloop, "kline_expire", kline_expire, NULL, 60);
	mowgli_timer_add(base_eventloop, "xline_expire", xline_expire, NULL, 60);
	mowgli_timer_add(base_eventloop, "qline_expire", qline_expire, NULL, 60);

	/* check authcookie expires every ten minutes */
	mowgli_timer_add(base_eventloop, "authcookie_expire", authcookie_expire, NULL, 600);

	/* reseed rng a little every five minutes */
	mowgli_timer_add(base_eventloop, "rng_reseed", rng_reseed, NULL, 293);

	me.connected = false;
	uplink_connect();

	/* main loop */
	io_loop();

	/* we're shutting down */
	hook_call_shutdown();

	if (db_save && !readonly)
		db_save(NULL);

	remove(pidfilename);
	errno = 0;
	if (curr_uplink != NULL && curr_uplink->conn != NULL)
		sendq_flush(curr_uplink->conn);
	connection_close_all();

	me.connected = false;

	/* should we restart? */
	if (runflags & RF_RESTART)
	{
		slog(LG_INFO, "main(): restarting");

#ifdef HAVE_EXECVE
		execv(BINDIR "/atheme-services", argv);
#endif
	}

	slog(LG_INFO, "main(): shutting down");

	mowgli_eventloop_destroy(base_eventloop);
	log_shutdown();

	return 0;
}
예제 #30
0
static int tbl_config_table (oconfig_item_t *ci)
{
	tbl_t *tbl;

	int status = 0;
	size_t i;

	if ((1 != ci->values_num)
			|| (OCONFIG_TYPE_STRING != ci->values[0].type)) {
		log_err ("<Table> expects a single string argument.");
		return 1;
	}

	tbl = realloc (tables, (tables_num + 1) * sizeof (*tables));
	if (NULL == tbl) {
		char errbuf[1024];
		log_err ("realloc failed: %s.",
				sstrerror (errno, errbuf, sizeof (errbuf)));
		return -1;
	}

	tables = tbl;
	++tables_num;

	tbl = tables + tables_num - 1;
	tbl_setup (tbl, ci->values[0].value.string);

	for (i = 0; i < ((size_t) ci->children_num); ++i) {
		oconfig_item_t *c = ci->children + i;

		if (0 == strcasecmp (c->key, "Separator"))
			tbl_config_set_s (c->key, &tbl->sep, c);
		else if (0 == strcasecmp (c->key, "Instance"))
			tbl_config_set_s (c->key, &tbl->instance, c);
		else if (0 == strcasecmp (c->key, "Result"))
			tbl_config_result (tbl, c);
		else
			log_warn ("Ignoring unknown config key \"%s\" "
					"in <Table %s>.", c->key, tbl->file);
	}

	if (NULL == tbl->sep) {
		log_err ("Table \"%s\" does not specify any separator.", tbl->file);
		status = 1;
	} else {
		strunescape (tbl->sep, strlen (tbl->sep) + 1);
	}

	if (NULL == tbl->instance) {
		tbl->instance = sstrdup (tbl->file);
		replace_special (tbl->instance, strlen (tbl->instance));
	}

	if (NULL == tbl->results) {
		log_err ("Table \"%s\" does not specify any (valid) results.",
				tbl->file);
		status = 1;
	}

	if (0 != status) {
		tbl_clear (tbl);
		--tables_num;
		return status;
	}

	for (i = 0; i < tbl->results_num; ++i) {
		tbl_result_t *res = tbl->results + i;
		size_t j;

		for (j = 0; j < res->instances_num; ++j)
			if (res->instances[j] > tbl->max_colnum)
				tbl->max_colnum = res->instances[j];

		for (j = 0; j < res->values_num; ++j)
			if (res->values[j] > tbl->max_colnum)
				tbl->max_colnum = res->values[j];
	}
	return 0;
} /* tbl_config_table */