Exemplo n.º 1
0
Arquivo: hash.c Projeto: NX-Andro/x3
void
set_geoip_info(struct userNode *user)
{
    if(IsLocal(user))
        return;
/* Need the libs and the headers if this is going to compile properly */
#if defined(HAVE_LIBGEOIP)&&defined(HAVE_GEOIP_H)&&defined(HAVE_GEOIPCITY_H)
    GeoIPRecord * gir;
    const char *geoip_data_file = NULL;
    const char *geoip_city_file = NULL;

    geoip_data_file = conf_get_data("services/opserv/geoip_data_file", RECDB_QSTRING);
    geoip_city_file = conf_get_data("services/opserv/geoip_city_data_file", RECDB_QSTRING);

    if ((!geoip_data_file && !geoip_city_file))
        return; /* Admin doesnt want to use geoip functions */

    if (geoip_data_file && !gi)
        gi  = GeoIP_open(geoip_data_file, GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE);

    if (geoip_city_file && !cgi)
        cgi = GeoIP_open(geoip_city_file, GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE);

    if (cgi) {
        gir = GeoIP_record_by_name(cgi, user->hostname);
        if (gir) {
            user->country_name = strdup(gir->country_name ? gir->country_name : "");
            user->country_code = strdup(gir->country_code ? gir->country_code : "");
            user->city         = strdup(gir->city ? gir->city : "");
            user->region       = strdup(gir->region ? gir->region : "");
            user->postal_code  = strdup(gir->postal_code ? gir->postal_code : "");

            user->latitude  = gir->latitude ? gir->latitude : 0;
            user->longitude = gir->longitude ? gir->longitude : 0;
            user->dma_code  = gir->dma_code ? gir->dma_code : 0;
            user->area_code = gir->area_code ? gir->area_code : 0;

            GeoIPRecord_delete(gir);
        }

        return;
    } else if (gi) {
        const char *country = GeoIP_country_name_by_name(gi, user->hostname);
        user->country_name = strdup(country ? country : "");
        return;
    }

    return;
#endif
}
Exemplo n.º 2
0
static void
qserver_conf_read(void)
{
    struct addrinfo hints;
    struct addrinfo *ai;
    dict_t node;
    const char *str1;
    const char *str2;
    int res;

    ioset_close(qserver_listener, 1);
    qserver_listener = NULL;
    node = conf_get_data("modules/qserver", RECDB_OBJECT);
    if (!node)
        return;
    str1 = database_get_data(node, "bind_address", RECDB_QSTRING);
    if (!str1)
        str1 = database_get_data(node, "address", RECDB_QSTRING);
    str2 = database_get_data(node, "port", RECDB_QSTRING);
    if (!str2)
        return;
    memset(&hints, 0, sizeof(hints));
    hints.ai_flags = AI_PASSIVE;
    hints.ai_socktype = SOCK_STREAM;
    res = getaddrinfo(str1, str2, &hints, &ai);
    if (res) {
        log_module(qserver_log, LOG_ERROR, "Unable to find address [%s]:%s: %s", str1 ? str1 : "", str2, gai_strerror(res));
    } else if (!(qserver_listener = ioset_listen(ai->ai_addr, ai->ai_addrlen, NULL, qserver_accept))) {
        log_module(qserver_log, LOG_ERROR, "Unable to listen on [%s]:%s", str1 ? str1 : "", str2);
    }
    conf.password = database_get_data(node, "password", RECDB_QSTRING);
    freeaddrinfo(ai);
}
Exemplo n.º 3
0
int
track_finalize(void) {
    struct mod_chanmode change;
    dict_t node;
    char *str;

    finalized = 1;
    node = conf_get_data("modules/track", RECDB_OBJECT);
    if (!node)
        return 0;
    str = database_get_data(node, "snomask", RECDB_QSTRING);
    if (!str)
	    track_cfg.snomask = TRACK_NICK|TRACK_KICK|TRACK_JOIN|TRACK_PART|TRACK_CHANMODE|TRACK_NEW|TRACK_DEL|TRACK_AUTH;
    else
	    parse_track_conf(str);
    str = database_get_data(node, "bot", RECDB_QSTRING);
    if (!str)
        return 0;
    track_cfg.bot = GetUserH(str);
    if (!track_cfg.bot)
        return 0;
    mod_chanmode_init(&change);
    change.argc = 1;
    change.args[0].mode = MODE_CHANOP;
    change.args[0].u.member = AddChannelUser(track_cfg.bot, track_cfg.channel);
    mod_chanmode_announce(track_cfg.bot, track_cfg.channel, &change);
    return 1;
}
Exemplo n.º 4
0
static void
iauth_loc_conf_read(void)
{
    dict_t node;
    const char *str1;
    const char *str2;


    node = conf_get_data("modules/blacklist", RECDB_OBJECT);
    if (node == NULL)
        return;

    str1 = database_get_data(node, "debug_bot", RECDB_QSTRING);
    if (str1)
        conf.debug_bot = GetUserH(str1);

    str1 = database_get_data(node, "debug_channel", RECDB_QSTRING);
    if (conf.debug_bot && str1) {
        str2 = database_get_data(node, "debug_channel_modes", RECDB_QSTRING);
        if (!str2)
            str2 = "+tinms";
        conf.debug_channel = AddChannel(str1, now, str2, NULL);
        AddChannelUser(conf.debug_bot, conf.debug_channel)->modes |= MODE_CHANOP;
    } else {
        conf.debug_channel = NULL;
    }
}
Exemplo n.º 5
0
static void
track_conf_read(void) {
    dict_t node;
    char *str, *modes;

    node = conf_get_data("modules/track", RECDB_OBJECT);
    if (!node)
        return;
    str = database_get_data(node, "snomask", RECDB_QSTRING);
    if (!str)
	    track_cfg.snomask = TRACK_NICK|TRACK_KICK|TRACK_JOIN|TRACK_PART|TRACK_CHANMODE|TRACK_NEW|TRACK_DEL|TRACK_AUTH;
    else
	    parse_track_conf(str);
    str = database_get_data(node, "channel", RECDB_QSTRING);
    modes = database_get_data(node, "channel_modes", RECDB_QSTRING);
    if (!str)
        return;
    // XXX - dont do addchannel if the channel is being shared with
    // another module:
    track_cfg.channel = AddChannel(str, now, (modes ? modes : "+sntOm"), NULL, NULL);
    if (!track_cfg.channel)
        return;
    str = database_get_data(node, "show_bursts", RECDB_QSTRING);
    track_cfg.show_bursts = str ? enabled_string(str) : 0;
    track_cfg.enabled = 1;
    if (finalized)
        track_finalize();
}
Exemplo n.º 6
0
static CMD_FUNC(cmd_admin)
{
    struct userNode *user;
    struct string_list *slist;

    if (!(user = GetUserH(origin))) {
        log_module(MAIN_LOG, LOG_ERROR, "Could not find ADMIN origin user %s", origin);
        return 0;
    }
    if ((slist = conf_get_data("server/admin", RECDB_STRING_LIST)) && slist->used) {
        unsigned int i;

        irc_numeric(user, 256, ":Administrative info about %s", self->name);
        for (i = 0; i < slist->used && i < 3; i++)
            irc_numeric(user, 257 + i, ":%s", slist->list[i]);
    } else {
        irc_numeric(user, 423, ":No administrative info available");
    }
    return 1;
}
Exemplo n.º 7
0
static void
global_conf_read(void)
{
    dict_t conf_node;
    const char *str;

    if (!(conf_node = conf_get_data(GLOBAL_CONF_NAME, RECDB_OBJECT))) {
	log_module(G_LOG, LOG_ERROR, "config node `%s' is missing or has wrong type.", GLOBAL_CONF_NAME);
	return;
    }

    str = database_get_data(conf_node, KEY_DB_BACKUP_FREQ, RECDB_QSTRING);
    global_conf.db_backup_frequency = str ? ParseInterval(str) : 7200;
    str = database_get_data(conf_node, KEY_ANNOUNCEMENTS_DEFAULT, RECDB_QSTRING);
    global_conf.announcements_default = str ? enabled_string(str) : 1;

    str = database_get_data(conf_node, KEY_NICK, RECDB_QSTRING);
    if(global && str)
        NickChange(global, str, 0);
}
Exemplo n.º 8
0
static void
snoop_conf_read(void) {
    dict_t node;
    char *str, *modes;

    node = conf_get_data("modules/snoop", RECDB_OBJECT);
    if (!node)
        return;
    str = database_get_data(node, "channel", RECDB_QSTRING);
    modes = database_get_data(node, "channel_modes", RECDB_QSTRING);
    if (!str)
        return;
    snoop_cfg.channel = AddChannel(str, now, (modes ? modes : "+sntim"), NULL, NULL);
    if (!snoop_cfg.channel)
        return;
    str = database_get_data(node, "show_bursts", RECDB_QSTRING);
    snoop_cfg.show_bursts = str ? enabled_string(str) : 0;
    snoop_cfg.enabled = 1;
    if (finalized)
        snoop_finalize();
}
Exemplo n.º 9
0
int
snoop_finalize(void) {
    struct mod_chanmode change;
    dict_t node;
    char *str;

    finalized = 1;
    node = conf_get_data("modules/snoop", RECDB_OBJECT);
    if (!node)
        return 0;
    str = database_get_data(node, "bot", RECDB_QSTRING);
    if (!str)
        return 0;
    snoop_cfg.bot = GetUserH(str);
    if (!snoop_cfg.bot)
        return 0;
    mod_chanmode_init(&change);
    change.argc = 1;
    change.args[0].mode = MODE_CHANOP;
    change.args[0].u.member = AddChannelUser(snoop_cfg.bot, snoop_cfg.channel);
    mod_chanmode_announce(snoop_cfg.bot, snoop_cfg.channel, &change);
    return 1;
}
Exemplo n.º 10
0
void
init_global(const char *nick)
{
    struct chanNode *chan;
    unsigned int i;
    G_LOG = log_register_type("Global", "file:global.log");
    reg_new_user_func(global_process_user, NULL);
    reg_auth_func(global_process_auth, NULL);
    reg_oper_func(global_process_oper, NULL);

    conf_register_reload(global_conf_read);

    global_module = module_register("Global", G_LOG, "global.help", NULL);
    modcmd_register(global_module, "LIST", cmd_list, 1, 0, "flags", "+oper", NULL);
    modcmd_register(global_module, "MESSAGE", cmd_message, 3, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
    modcmd_register(global_module, "MESSAGES", cmd_messages, 1, 0, NULL);
    modcmd_register(global_module, "NOTICE", cmd_notice, 3, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
    modcmd_register(global_module, "REMOVE", cmd_remove, 2, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);

    if(nick)
    {
        const char *modes = conf_get_data("services/global/modes", RECDB_QSTRING);
        global = AddLocalUser(nick, nick, NULL, "Global Services", modes);
        global_service = service_register(global);
    }

    if(autojoin_channels && global) {
        for (i = 0; i < autojoin_channels->used; i++) {
            chan = AddChannel(autojoin_channels->list[i], now, "+nt", NULL, NULL);
            AddChannelUser(global, chan)->modes |= MODE_CHANOP;
        }    
    }

    saxdb_register("Global", global_saxdb_read, global_saxdb_write);
    reg_exit_func(global_db_cleanup, NULL);
    message_register_table(msgtab);
}
Exemplo n.º 11
0
char *
generate_hostmask(struct userNode *user, int options)
{
    irc_in_addr_t ip;
    char *nickname, *ident, *hostname, *mask;
    int len, ii;

    /* figure out string parts */
    if (options & GENMASK_OMITNICK)
        nickname = NULL;
    else if (options & GENMASK_USENICK)
        nickname = user->nick;
    else
        nickname = "*";
    if (options & GENMASK_STRICT_IDENT)
        // sethost - reed/apples
        if (IsSetHost(user)) {
          ident = alloca(strcspn(user->sethost, "@")+2);
          safestrncpy(ident, user->sethost, strcspn(user->sethost, "@")+1);
        }
        else
        ident = user->ident;
    else if (options & GENMASK_ANY_IDENT)
        ident = "*";
    else {
        // sethost - reed/apples
        if (IsSetHost(user)) {
          ident = alloca(strcspn(user->sethost, "@")+3);
          ident[0] = '*';
          safestrncpy(ident+1, user->sethost, strcspn(user->sethost, "@")+1);
        } else {
        ident = alloca(strlen(user->ident)+2);
        ident[0] = '*';
        strcpy(ident+1, user->ident + ((*user->ident == '~')?1:0));
    }
    }
    hostname = user->hostname;
    if (IsFakeHost(user) && IsHiddenHost(user) && !(options & GENMASK_NO_HIDING)) {
        hostname = user->fakehost;
    } else if (IsHiddenHost(user)) {
        int style = 1;
        char *data;
        data = conf_get_data("server/hidden_host_type", RECDB_QSTRING);
        if (data)
            style = atoi(data);

        if (((style == 1) || (style == 3)) && user->handle_info && hidden_host_suffix && !(options & GENMASK_NO_HIDING)) {
            hostname = alloca(strlen(user->handle_info->handle) + strlen(hidden_host_suffix) + 2);
            sprintf(hostname, "%s.%s", user->handle_info->handle, hidden_host_suffix);
        } else if (((style == 2) || (style == 3)) && !(options & GENMASK_NO_HIDING)) {
            hostname = alloca(strlen(user->crypthost));
            sprintf(hostname, "%s", user->crypthost);
        }
    } else if (options & GENMASK_STRICT_HOST) {
        if (options & GENMASK_BYIP)
            hostname = (char*)irc_ntoa(&user->ip);
    } else if ((options & GENMASK_BYIP) || irc_pton(&ip, NULL, hostname)) {
        /* Should generate an IP-based hostmask. */
        hostname = alloca(IRC_NTOP_MAX_SIZE);
        hostname[IRC_NTOP_MAX_SIZE-1] = '\0';
        if (irc_in_addr_is_ipv4(user->ip)) {
            /* By popular acclaim, a /16 hostmask is used. */
            sprintf(hostname, "%d.%d.*", user->ip.in6_8[12], user->ip.in6_8[13]);
        } else if (irc_in_addr_is_ipv6(user->ip)) {
            /* Who knows what the default mask should be?  Use a /48 to start with. */
            sprintf(hostname, "%x:%x:%x:*", user->ip.in6[0], user->ip.in6[1], user->ip.in6[2]);
        } else {
            /* Unknown type; just copy IP directly. */
            irc_ntop(hostname, IRC_NTOP_MAX_SIZE, &user->ip);
        }
    } else {
        int cnt;
        /* This heuristic could be made smarter.  Is it worth the effort? */
        for (ii=cnt=0; hostname[ii]; ii++)
            if (hostname[ii] == '.')
                cnt++;
        if (cnt == 0 || cnt == 1) {
            /* only a one- or two-level domain name; leave hostname */
        } else if (cnt == 2) {
            for (ii=0; user->hostname[ii] != '.'; ii++) ;
            /* Add 3 to account for the *. and \0. */
            hostname = alloca(strlen(user->hostname+ii)+3);
            sprintf(hostname, "*.%s", user->hostname+ii+1);
        } else {
            for (cnt=3, ii--; cnt; ii--)
                if (user->hostname[ii] == '.')
                    cnt--;
            /* The loop above will overshoot the dot one character;
               we skip forward two (the one character and the dot)
               when printing, so we only add one for the \0. */
            hostname = alloca(strlen(user->hostname+ii)+1);
            sprintf(hostname, "*.%s", user->hostname+ii+2);
        }
    }
    // sethost - reed/apples
    if (IsSetHost(user)) 
      hostname = strchr(user->sethost, '@') + 1;

    /* Emit hostmask */
    len = strlen(ident) + strlen(hostname) + 2;
    if (nickname) {
        len += strlen(nickname) + 1;
        mask = malloc(len);
        sprintf(mask, "%s!%s@%s", nickname, ident, hostname);
    } else {
        mask = malloc(len);
        sprintf(mask, "%s@%s", ident, hostname);
    }
    return mask;
}