Example #1
0
swd::blacklist_filters swd::database::get_blacklist_filters() {
    swd::log::i()->send(swd::notice, "Get blacklist filters from db");

    ensure_connection();

    boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

    dbi_result res = dbi_conn_query(conn_, "SELECT id, impact, rule FROM blacklist_filters");

    if (!res) {
        throw swd::exceptions::database_exception("Can't execute blacklist_filters query");
    }

    swd::blacklist_filters filters;

    while (dbi_result_next_row(res)) {
        swd::blacklist_filter_ptr filter(new swd::blacklist_filter());
        filter->set_id(dbi_result_get_uint(res, "id"));
        filter->set_impact(dbi_result_get_uint(res, "impact"));
        filter->set_regex(dbi_result_get_string(res, "rule"));

        filters.push_back(filter);
    }

    dbi_result_free(res);

    return filters;
}
/**
 * Go through the database, read and add to the server all
 * the registrations stored.
 *
 * @param c the configuration of the db
 * @param s the server
 */
int db_create_registrations(struct config *c, struct server *s)
{
	char *q = "SELECT * FROM registrations WHERE server_id = %i;";
	struct registration *r;
	char *name, *pass;
	dbi_result res;

	res = dbi_conn_queryf(c->conn, q, s->id);

	if (res) {
		while (dbi_result_next_row(res)) {
			r = new_registration();
			r->db_id = dbi_result_get_uint(res, "id");
			r->global_flags = dbi_result_get_uint(res, "serveradmin");
			name = dbi_result_get_string_copy(res, "name");
			strncpy(r->name, name, MIN(29, strlen(name)));
			pass = dbi_result_get_string_copy(res, "password");
			strcpy(r->password, pass);
			add_registration(s, r);
			/* free temporary variables */
			free(pass); free(name);
		}
		dbi_result_free(res);
	}
	return 1;
}
Example #3
0
//*******************************************************************
// RETRIEVE PRECEDING RAW RECORD FROM DATABASE (well just the color)
//*******************************************************************
static struct probe_result *get_previous_record(trx *t)
{
  dbi_result result;
  struct probe_result *prv;

  prv = g_malloc0(sizeof(struct probe_result));
  if (prv == NULL) {
    return(NULL);
  }
  prv->stattime = t->res->stattime;
  prv->color = t->res->color;

  if (!t->probe->store_results) return(prv); // we probably don't have a xxxx_raw table

  result = db_query(t->probe->db, 0,
                    "select   color, stattime "
                    "from     pr_%s_raw use index(probstat) "
                    "where    probe = '%u' and stattime < '%u' "
                    "order by stattime desc limit 1", 
                    t->res->name, t->def->probeid, t->res->stattime);
  if (!result) return(prv);
  if (dbi_result_next_row(result)) {
    prv->color = dbi_result_get_uint(result, "color");
    prv->stattime = dbi_result_get_uint(result, "stattime");
  }
  dbi_result_free(result);
  t->res->prevcolor = prv->color;
  return(prv);
}
Example #4
0
void refresh_database(dbi_conn conn)
{
  dbi_result result;
  char qry[1024];

  sprintf(qry,  "SELECT pr_pop3_def.id, pr_pop3_def.domid, pr_pop3_def.tblid, pr_realm.name, "
                "       pr_pop3_def.ipaddress, pr_pop3_def.username, "
                "       pr_pop3_def.password, "
                "       pr_pop3_def.yellow,  pr_pop3_def.red "
                "FROM   pr_pop3_def, pr_realm "
                "WHERE  pr_pop3_def.id > 1 and pr_pop3_def.disable <> 'yes'"
                "       and pr_pop3_def.pgroup = '%d' and pr_realm.id = pr_pop3_def.domid",
                (unsigned)OPT_VALUE_GROUPID);

  result = db_query(conn, 1, qry);
  if (!result) {
    return;
  }
    
  while (dbi_result_next_row(result)) {
    int id;
    struct probedef *probe;

    id = dbi_result_get_uint(result, "id");
    probe = g_hash_table_lookup(cache, &id);
    if (!probe) {
      probe = g_malloc0(sizeof(struct probedef));
      if (dbi_result_get_uint(result, "domid") > 1) {
        probe->probeid = dbi_result_get_uint(result, "tblid");
        probe->realm=strdup(dbi_result_get_string(result, "name"));
      } else {
        probe->probeid = probe->id;
      }
      g_hash_table_insert(cache, guintdup(id), probe);
    }

    if (probe->ipaddress) g_free(probe->ipaddress);
    probe->ipaddress = dbi_result_get_string_copy(result, "ipaddress");
    if (probe->username) g_free(probe->username);
    probe->username = dbi_result_get_string_copy(result, "username");
    if (probe->password) g_free(probe->password);
    probe->password = dbi_result_get_string_copy(result, "password");
    probe->yellow = dbi_result_get_float(result, "yellow");
    probe->red = dbi_result_get_float(result, "red");
    if (probe->msg) g_free(probe->msg);
    probe->msg = NULL;
    probe->seen = 1;
  }
  if (dbi_conn_error_flag(conn)) {
    const char *errmsg;
    dbi_conn_error(conn, &errmsg);
    LOG(LOG_ERR, "%s", errmsg);
    g_hash_table_foreach(cache, reset_seen, NULL);
  } else {
    g_hash_table_foreach_remove(cache, return_seen, NULL);
  }
  dbi_result_free(result);
}
Example #5
0
swd::whitelist_rules swd::database::get_whitelist_rules(const int& profile_id,
 const std::string& caller, const std::string& path) {
    swd::log::i()->send(swd::notice, "Get whitelist rules from db");

    ensure_connection();

    boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

    char *caller_esc = strdup(caller.c_str());
    dbi_conn_quote_string(conn_, &caller_esc);

    char *path_esc = strdup(path.c_str());
    dbi_conn_quote_string(conn_, &path_esc);

    /**
     * Remove LIKE single character wildcard, because it could result easily in security
     * problems if a user forgets to escape an underscore. And instead of a percentage sign
     * it is nicer to use an asterisk, because it is more common.
     */
    dbi_result res = dbi_conn_queryf(conn_, "SELECT r.id, r.path, f.id as filter_id, "
     "f.rule, f.impact, r.min_length, r.max_length FROM whitelist_rules AS r, "
     "whitelist_filters AS f WHERE r.filter_id = f.id AND r.profile_id = %i AND %s LIKE "
     "prepare_wildcard(r.caller) AND %s LIKE prepare_wildcard(r.path) AND r.status = %i",
     profile_id, caller_esc, path_esc, STATUS_ACTIVATED);

    free(caller_esc);
    free(path_esc);

    if (!res) {
        throw swd::exceptions::database_exception("Can't execute whitelist_rules query");
    }

    swd::whitelist_rules rules;

    while (dbi_result_next_row(res)) {
        swd::whitelist_filter_ptr filter(new swd::whitelist_filter());
        filter->set_id(dbi_result_get_uint(res, "filter_id"));
        filter->set_regex(dbi_result_get_string(res, "rule"));

        swd::whitelist_rule_ptr rule(new swd::whitelist_rule());
        rule->set_id(dbi_result_get_uint(res, "id"));
        rule->set_filter(filter);
        rule->set_min_length(dbi_result_get_uint(res, "min_length"));
        rule->set_max_length(dbi_result_get_uint(res, "max_length"));

        rules.push_back(rule);
    }

    dbi_result_free(res);

    return rules;
}
Example #6
0
swd::profile_ptr swd::database::get_profile(const std::string& server_ip,
 const int& profile_id) {
    std::stringstream log_message;
    log_message << "Get profile from db -> server_ip: " << server_ip
     << "; profile_id: " << profile_id;

    swd::log::i()->send(swd::notice, log_message.str());

    /* Test the database connection status. Tries to reconnect if disconnected. */
    ensure_connection();

    /* Mutex to avoid race conditions. */
    boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

    /**
     * First we escape server_ip. It comes from a trusted source, but better safe
     * than sorry. This does not work with std::string though.
     */
    char *server_ip_esc = strdup(server_ip.c_str());
    dbi_conn_quote_string(conn_, &server_ip_esc);

    /* Insert the ip and execute the query. */
    dbi_result res = dbi_conn_queryf(conn_, "SELECT id, hmac_key, mode, "
     "whitelist_enabled, blacklist_enabled, integrity_enabled, flooding_enabled, "
     "blacklist_threshold, cache_outdated FROM profiles WHERE %s LIKE "
     "prepare_wildcard(server_ip) AND id = %i", server_ip_esc, profile_id);

    /* Don't forget to free server_ip_esc to avoid a memory leak. */
    free(server_ip_esc);

    if (!res) {
        throw swd::exceptions::database_exception("Can't execute profile query");
    }

    if (dbi_result_get_numrows(res) != 1) {
        throw swd::exceptions::database_exception("Can't get profile");
    }

    if (!dbi_result_next_row(res)) {
        throw swd::exceptions::database_exception("No profile?");
    }

    swd::profile_ptr profile(new swd::profile());
    profile->set_server_ip(server_ip),
    profile->set_id(dbi_result_get_uint(res, "id"));
    profile->set_mode(dbi_result_get_uint(res, "mode"));
    profile->set_whitelist_enabled(dbi_result_get_uint(res, "whitelist_enabled") == 1);
    profile->set_blacklist_enabled(dbi_result_get_uint(res, "blacklist_enabled") == 1);
    profile->set_integrity_enabled(dbi_result_get_uint(res, "integrity_enabled") == 1);
    profile->set_flooding_enabled(dbi_result_get_uint(res, "flooding_enabled") == 1);
    profile->set_key(dbi_result_get_string(res, "hmac_key"));
    profile->set_blacklist_threshold(dbi_result_get_uint(res, "blacklist_threshold"));
    profile->set_cache_outdated(dbi_result_get_uint(res, "cache_outdated") == 1);

    dbi_result_free(res);

    return profile;
}
Example #7
0
bool swd::database::is_flooding(const std::string& client_ip,
 const int& profile_id) {
    ensure_connection();

    boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

    char *client_ip_esc = strdup(client_ip.c_str());
    dbi_conn_quote_string(conn_, &client_ip_esc);

    dbi_result res = dbi_conn_queryf(conn_, "SELECT is_flooding(%i, %s) AS result",
     profile_id, client_ip_esc);

    free(client_ip_esc);

    if (!res) {
        throw swd::exceptions::database_exception("Can't execute request count query");
    }

    bool flooding = false;

    if (dbi_result_get_numrows(res) == 1) {
        if (!dbi_result_next_row(res)) {
            throw swd::exceptions::database_exception("No flooding?");
        }

        flooding = (dbi_result_get_uint(res, "result") == 1);
    }

    dbi_result_free(res);

    return flooding;
}
Example #8
0
//*******************************************************************
// UPDATE SERVER COLOR
//*******************************************************************
static void update_server_color(trx *t, struct probe_result *prv)
{
  dbi_result result;
  int maxcolor, newcolor;

  if (t->def->server < 2) return;

  if (t->probe->fuse && (t->res->color < prv->color)) {
    // if this probe acts like a fuse, use the previous color if it's higher
    newcolor = prv->color;
  } else {
    newcolor = t->res->color;
  }
  maxcolor = newcolor; // init

  result = db_query(t->probe->db, 0,
                    "select max(color) as color from pr_status where server = '%u'", t->def->server);
  if (result && dbi_result_next_row(result)) {
    maxcolor = dbi_result_get_uint(result, "color");
  }
  dbi_result_free(result);
  //if (t->res->color <= maxcolor) return;

  result = db_query(t->probe->db, 0,
                    // update server set color = '200' where id = '345'
                    "update %s set %s = '%u' where %s = '%u'",
                     OPT_ARG(SERVER_TABLE_NAME), OPT_ARG(SERVER_TABLE_COLOR_FIELD), 
                     maxcolor, OPT_ARG(SERVER_TABLE_ID_FIELD), t->def->server);
  dbi_result_free(result);
}
Example #9
0
int find_expired_probes(struct dbspec *dbspec)
{
  xmlDocPtr doc;
  xmlNodePtr probe;
  dbi_result result;
  dbi_conn conn;
  int count = 0;
  char buf[10];

  sprintf(buf, "%d", dbspec->port);

  conn = open_database(OPT_ARG(DBTYPE), dbspec->host, buf, dbspec->db,
                     dbspec->user, dbspec->password);
  if (!conn) return 0;

  doc = UpwatchXmlDoc("result", NULL);

  // find all expired probes, but skip those for which processing
  // has been stopped for some reason
  result = db_query(conn, 0, "select probe.name, pr_status.probe, " 
                             "       pr_status.server, pr_status.color, "
                             "       pr_status.expires "
                             "from   pr_status, probe "
                             "where  probe.id = pr_status.class and color <> 400 "
                             "       and expires < UNIX_TIMESTAMP()-30 "
                             "       and expires < probe.lastseen"
                             "       and probe.expiry = 'yes'");
  if (!result) goto errexit;

  while (dbi_result_next_row(result)) {
    char buffer[256];
    time_t now = time(NULL);

    probe = xmlNewChild(xmlDocGetRootElement(doc), NULL, dbi_result_get_string(result, "name"), NULL);
    xmlSetProp(probe, "realm", dbspec->realm);
    xmlSetProp(probe, "id", dbi_result_get_string(result, "probe"));
    xmlSetProp(probe, "server", dbi_result_get_string(result, "server"));
    sprintf(buffer, "%u", (int) now);	xmlSetProp(probe, "date", buffer);
    xmlSetProp(probe, "expires", dbi_result_get_string(result, "expires"));

    xmlNewChild(probe, NULL, "color", "400");  // PURPLE
    xmlNewChild(probe, NULL, "prevcolor", dbi_result_get_string(result, "color"));

    LOG(LOG_INFO, "%s: purpled %s %d", dbspec->realm, dbi_result_get_string(result, "name"), 
                                                      dbi_result_get_uint(result, "probe"));
    count++;
  }
  if (count) {
    xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS);
    spool_result(OPT_ARG(SPOOLDIR), OPT_ARG(OUTPUT), doc, NULL);
    LOG(LOG_INFO, "%s: purpled %u probes", dbspec->realm, count);
  }

errexit:
  if (result) dbi_result_free(result);
  if (conn) close_database(conn);
  if (doc) xmlFreeDoc(doc);
  return count;
}
Example #10
0
swd::blacklist_rules swd::database::get_blacklist_rules(const int& profile_id,
 const std::string& caller, const std::string& path) {
    swd::log::i()->send(swd::notice, "Get blacklist rules from db");

    ensure_connection();

    boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

    char *caller_esc = strdup(caller.c_str());
    dbi_conn_quote_string(conn_, &caller_esc);

    char *path_esc = strdup(path.c_str());
    dbi_conn_quote_string(conn_, &path_esc);

    dbi_result res = dbi_conn_queryf(conn_, "SELECT r.id, r.path, r.threshold "
     "FROM blacklist_rules AS r WHERE r.profile_id = %i AND %s LIKE "
     "prepare_wildcard(r.caller) AND %s LIKE prepare_wildcard(r.path) AND "
     "r.status = %i", profile_id, caller_esc, path_esc, STATUS_ACTIVATED);

    free(caller_esc);
    free(path_esc);

    if (!res) {
        throw swd::exceptions::database_exception("Can't execute blacklist_rules query");
    }

    swd::blacklist_rules rules;

    while (dbi_result_next_row(res)) {
        swd::blacklist_rule_ptr rule(new swd::blacklist_rule());
        rule->set_id(dbi_result_get_uint(res, "id"));
        rule->set_threshold(dbi_result_get_uint(res, "threshold"));

        rules.push_back(rule);
    }

    dbi_result_free(res);

    return rules;
}
Example #11
0
//*******************************************************************
// SEE IF THE USER HAS BEEN NOTIFIED FOR THIS COLOR
//*******************************************************************
void get_previous_pr_hist(trx *t)
{
  dbi_result result;

  t->res->changed = 0;
  strcpy(t->res->notified, "yes"); // if we cannot find pr_hist record, assume the user has already been warned
  result = db_query(t->probe->db, 0,
                    "select   id, stattime, notified, prv_color "
                    "from     pr_hist  "
                    "where    probe = '%u' and class = '%u' and stattime <= '%u' "
                    "order by stattime desc limit 1",
                    t->def->probeid, t->probe->class, t->res->stattime);
  if (!result) return;
  if (dbi_result_next_row(result)) {
    t->res->prevhistid = dbi_result_get_longlong(t->probe->db, "id");
    t->res->changed = dbi_result_get_uint(t->probe->db, "stattime");
    strcpy(t->res->notified, dbi_result_get_string(t->probe->db, "notified"));
    t->res->prevhistcolor = dbi_result_get_uint(t->probe->db, "prv_color");
  }
  dbi_result_free(result);
  return;
}
Example #12
0
//************************************************************************
// read pr_status file for expired probes. Construct fake results
// for those.
//***********************************************************************
int run(void)
{
  dbi_result result;
  dbi_conn conn;
  int count = 0;

  conn = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_ARG(DBPORT), OPT_ARG(DBNAME),
                        OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
  if (!conn) return 0;

  LOG(LOG_INFO, "processing ..");
  uw_setproctitle("reading info from database");
  result = db_query(conn, 0, "select pr_realm.id, pr_realm.name, pr_realm.host, "
                              "       pr_realm.port, pr_realm.db, pr_realm.user, "
                              "       pr_realm.password "
                              "from   pr_realm "
                              "where  pr_realm.id > 1");
  if (result) {
    while (dbi_result_next_row(result)) {
      struct dbspec db;

      db.domid = dbi_result_get_uint(result, "id");
      db.realm = dbi_result_get_string(result, "name");
      db.host = dbi_result_get_string(result, "host");
      db.port = dbi_result_get_uint(result, "port");
      db.db = dbi_result_get_string(result, "db");
      db.user = dbi_result_get_string(result, "user");
      db.password = dbi_result_get_string(result, "password");
      uw_setproctitle("checking %s", dbi_result_get_string(result, "name"));
      LOG(LOG_DEBUG, "checking %s", dbi_result_get_string(result, "name"));
      count += find_expired_probes(&db);
    }
    dbi_result_free(result);
  }
  close_database(conn);
  LOG(LOG_INFO, "sleeping");
  return count;
}
Example #13
0
//*******************************************************************
// RETRIEVE FOLLOWING RAW RECORD FROM DATABASE (well just the color)
//*******************************************************************
static struct probe_result *get_following_record(trx *t)
{
  dbi_result result;
  struct probe_result *nxt = NULL;

  if (!t->probe->store_results) return(NULL); // we probably don't have a xxxx_raw table

  result = db_query(t->probe->db, 0,
                    "select   color, stattime "
                    "from     pr_%s_raw use index(probstat) "
                    "where    probe = '%u' and stattime > '%u' "
                    "order by stattime asc limit 1", 
                    t->res->name, t->def->probeid, t->res->stattime);
  if (result) {
    if (dbi_result_next_row(result)) {
      nxt = g_malloc0(sizeof(struct probe_result));

      nxt->color = dbi_result_get_uint(result, "color");
      nxt->stattime = dbi_result_get_uint(result, "stattime");
    }
    dbi_result_free(result);
  }
  return(nxt);
}
Example #14
0
void db_create_pl_ch_privileges(struct config *c, struct server *s)
{
	dbi_result res;
	int flags;
	size_t iter, iter2;
	int reg_id;
	struct channel *ch;
	struct registration *reg;
	struct player_channel_privilege *tmp_priv;
	char *q = "SELECT * FROM player_channel_privileges WHERE channel_id = %i;";


	logger(LOG_INFO, "Reading player channel privileges...");
	ar_each(struct channel *, ch, iter, s->chans)
		if (!(ch->flags & CHANNEL_FLAG_UNREGISTERED)) {
			res = dbi_conn_queryf(c->conn, q, ch->db_id);
			if (res) {
				while (dbi_result_next_row(res)) {
					tmp_priv = new_player_channel_privilege();
					tmp_priv->ch = ch;
					flags = 0;
					if (dbi_result_get_uint(res, "channel_admin"))
						flags |= CHANNEL_PRIV_CHANADMIN;
					if (dbi_result_get_uint(res, "operator"))
						flags |= CHANNEL_PRIV_OP;
					if (dbi_result_get_uint(res, "voice"))
						flags |= CHANNEL_PRIV_VOICE;
					if (dbi_result_get_uint(res, "auto_operator"))
						flags |= CHANNEL_PRIV_AUTOOP;
					if (dbi_result_get_uint(res, "auto_voice"))
						flags |= CHANNEL_PRIV_AUTOVOICE;
					tmp_priv->flags = flags;
					tmp_priv->reg = PL_CH_PRIV_REGISTERED;
					reg_id = dbi_result_get_uint(res, "player_id");
					ar_each(struct registration *, reg, iter2, s->regs)
						if (reg->db_id == reg_id)
							tmp_priv->pl_or_reg.reg = reg;
					ar_end_each;
					if (tmp_priv->pl_or_reg.reg != NULL)
						add_player_channel_privilege(ch, tmp_priv);
					else
						free(tmp_priv);
				}
				dbi_result_free(res);
			} else {
Example #15
0
//*******************************************************************
// IS THIS SLOT COMPLETELY FILLED?
//*******************************************************************
int slot_is_complete(trx *t, int i, guint slotlow, guint slothigh)
{
  dbi_result result;
  int val = FALSE;

  /* 
   * don't know how many raw records go into a day slot, 
   * so we fake it is filled, so it'll always be summarized
   */
  if (i == 0) return 1;
  result = db_query(t->probe->db, 0,
                    "select count(*) as count from pr_%s_%s use index(probstat) "
                    "where  probe = '%u' and stattime >= '%u' and stattime <= '%u'",
                    t->res->name, summ_info[i].from, t->def->probeid, slotlow, slothigh);
  if (!result) return(FALSE);
  if (dbi_result_next_row(result)) {
    if (dbi_result_get_uint(result, "count") >= summ_info[i].perslot) {
      val = TRUE;
    }
  }
  dbi_result_free(result);
  return(val);
}
Example #16
0
swd::integrity_rules swd::database::get_integrity_rules(const int& profile_id,
 const std::string& caller) {
    swd::log::i()->send(swd::notice, "Get integrity rules from db");

    ensure_connection();

    boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

    char *caller_esc = strdup(caller.c_str());
    dbi_conn_quote_string(conn_, &caller_esc);

    dbi_result res = dbi_conn_queryf(conn_, "SELECT r.id, r.algorithm, r.digest FROM "
     "integrity_rules AS r WHERE r.profile_id = %i AND %s LIKE prepare_wildcard(r.caller) "
     "AND r.status = %i", profile_id, caller_esc, STATUS_ACTIVATED);

    free(caller_esc);

    if (!res) {
        throw swd::exceptions::database_exception("Can't execute whitelist_rules query");
    }

    swd::integrity_rules rules;

    while (dbi_result_next_row(res)) {
        swd::integrity_rule_ptr rule(new swd::integrity_rule());
        rule->set_id(dbi_result_get_uint(res, "id"));
        rule->set_algorithm(dbi_result_get_string(res, "algorithm"));
        rule->set_digest(dbi_result_get_string(res, "digest"));

        rules.push_back(rule);
    }

    dbi_result_free(res);

    return rules;
}
Example #17
0
/**
 * Go through the database, read and add to the server all
 * the server permissions stored.
 *
 * @param c the configuration of the db
 * @param s the server
 */
int db_create_sv_privileges(struct config *c, struct server *s)
{
	char *q = "SELECT * FROM server_privileges WHERE server_id = %i;";
	dbi_result res;
	const char *group;
	int g;
	struct server_privileges *sp = s->privileges;

	logger(LOG_INFO, "Loading server privileges.");

	res = dbi_conn_queryf(c->conn, q, s->id);
	if (res) {
		while (dbi_result_next_row(res)) {
			/* Get the id of the group from the string */
			group = dbi_result_get_string(res, "user_group");
			if (strcmp(group, "server_admin") == 0) {
				g = PRIV_SERVER_ADMIN;
			} else if (strcmp(group, "channel_admin") == 0) {
				g = PRIV_CHANNEL_ADMIN;
			} else if (strcmp(group, "operator") == 0) {
				g = PRIV_OPERATOR;
			} else if (strcmp(group, "voice") == 0) {
				g = PRIV_VOICE;
			} else if (strcmp(group, "registered") == 0) {
				g = PRIV_REGISTERED;
			} else if (strcmp(group, "anonymous") == 0) {
				g = PRIV_ANONYMOUS;
			} else {
				logger(LOG_ERR, "server_privileges.user_group = %s, \
						expected : server_admin, channel_admin, \
						operator, voice, registered, anonymous.",
						group);
				continue;
			}
			logger(LOG_DBG, "GROUP : %i", g);
			/* Copy all privileges to the server... */
			sp->priv[g][SP_ADM_DEL_SERVER] = dbi_result_get_uint(res, "adm_del_server");
			sp->priv[g][SP_ADM_ADD_SERVER] = dbi_result_get_uint(res, "adm_add_server");
			sp->priv[g][SP_ADM_LIST_SERVERS] = dbi_result_get_uint(res, "adm_list_servers");
			sp->priv[g][SP_ADM_SET_PERMISSIONS] = dbi_result_get_uint(res, "adm_set_permissions");
			sp->priv[g][SP_ADM_CHANGE_USER_PASS] = dbi_result_get_uint(res, "adm_change_user_pass");
			sp->priv[g][SP_ADM_CHANGE_OWN_PASS] = dbi_result_get_uint(res, "adm_change_own_pass");
			sp->priv[g][SP_ADM_LIST_REGISTRATIONS] = dbi_result_get_uint(res, "adm_list_registrations");
			sp->priv[g][SP_ADM_REGISTER_PLAYER] = dbi_result_get_uint(res, "adm_register_player");

			sp->priv[g][SP_ADM_CHANGE_SERVER_CODECS] = dbi_result_get_uint(res, "adm_change_server_codecs");
			sp->priv[g][SP_ADM_CHANGE_SERVER_TYPE] = dbi_result_get_uint(res, "adm_change_server_type");
			sp->priv[g][SP_ADM_CHANGE_SERVER_PASS] = dbi_result_get_uint(res, "adm_change_server_pass");
			sp->priv[g][SP_ADM_CHANGE_SERVER_WELCOME] = dbi_result_get_uint(res, "adm_change_server_welcome");
			sp->priv[g][SP_ADM_CHANGE_SERVER_MAXUSERS] = dbi_result_get_uint(res, "adm_change_server_maxusers");
			sp->priv[g][SP_ADM_CHANGE_SERVER_NAME] = dbi_result_get_uint(res, "adm_change_server_name");
			sp->priv[g][SP_ADM_CHANGE_WEBPOST_URL] = dbi_result_get_uint(res, "adm_change_webpost_url");
			sp->priv[g][SP_ADM_CHANGE_SERVER_PORT] = dbi_result_get_uint(res, "adm_change_server_port");

			sp->priv[g][SP_ADM_START_SERVER] = dbi_result_get_uint(res, "adm_start_server");
			sp->priv[g][SP_ADM_STOP_SERVER] = dbi_result_get_uint(res, "adm_stop_server");
			sp->priv[g][SP_ADM_MOVE_PLAYER] = dbi_result_get_uint(res, "adm_move_player");
			sp->priv[g][SP_ADM_BAN_IP] = dbi_result_get_uint(res, "adm_ban_ip");

			sp->priv[g][SP_CHA_DELETE] = dbi_result_get_uint(res, "cha_delete");
			sp->priv[g][SP_CHA_CREATE_MODERATED] = dbi_result_get_uint(res, "cha_create_moderated");
			sp->priv[g][SP_CHA_CREATE_SUBCHANNELED] = dbi_result_get_uint(res, "cha_create_subchanneled");
			sp->priv[g][SP_CHA_CREATE_DEFAULT] = dbi_result_get_uint(res, "cha_create_default");
			sp->priv[g][SP_CHA_CREATE_UNREGISTERED] = dbi_result_get_uint(res, "cha_create_unregistered");
			sp->priv[g][SP_CHA_CREATE_REGISTERED] = dbi_result_get_uint(res, "cha_create_registered");
			sp->priv[g][SP_CHA_JOIN_REGISTERED] = dbi_result_get_uint(res, "cha_join_registered");

			sp->priv[g][SP_CHA_JOIN_WO_PASS] = dbi_result_get_uint(res, "cha_join_wo_pass");
			sp->priv[g][SP_CHA_CHANGE_CODEC] = dbi_result_get_uint(res, "cha_change_codec");
			sp->priv[g][SP_CHA_CHANGE_MAXUSERS] = dbi_result_get_uint(res, "cha_change_maxusers");
			sp->priv[g][SP_CHA_CHANGE_ORDER] = dbi_result_get_uint(res, "cha_change_order");
			sp->priv[g][SP_CHA_CHANGE_DESC] = dbi_result_get_uint(res, "cha_change_desc");
			sp->priv[g][SP_CHA_CHANGE_TOPIC] = dbi_result_get_uint(res, "cha_change_topic");
			sp->priv[g][SP_CHA_CHANGE_PASS] = dbi_result_get_uint(res, "cha_change_pass");
			sp->priv[g][SP_CHA_CHANGE_NAME] = dbi_result_get_uint(res, "cha_change_name");

			sp->priv[g][SP_PL_GRANT_ALLOWREG] = dbi_result_get_uint(res, "pl_grant_allowreg");
			sp->priv[g][SP_PL_GRANT_VOICE] = dbi_result_get_uint(res, "pl_grant_voice");
			sp->priv[g][SP_PL_GRANT_AUTOVOICE] = dbi_result_get_uint(res, "pl_grant_autovoice");
			sp->priv[g][SP_PL_GRANT_OP] = dbi_result_get_uint(res, "pl_grant_op");
			sp->priv[g][SP_PL_GRANT_AUTOOP] = dbi_result_get_uint(res, "pl_grant_autoop");
			sp->priv[g][SP_PL_GRANT_CA] = dbi_result_get_uint(res, "pl_grant_ca");
			sp->priv[g][SP_PL_GRANT_SA] = dbi_result_get_uint(res, "pl_grant_sa");

			sp->priv[g][SP_PL_REGISTER_PLAYER] = dbi_result_get_uint(res, "pl_register_player");
			sp->priv[g][SP_PL_REVOKE_ALLOWREG] = dbi_result_get_uint(res, "pl_revoke_allowreg");
			sp->priv[g][SP_PL_REVOKE_VOICE] = dbi_result_get_uint(res, "pl_revoke_voice");
			sp->priv[g][SP_PL_REVOKE_AUTOVOICE] = dbi_result_get_uint(res, "pl_revoke_autovoice");
			sp->priv[g][SP_PL_REVOKE_OP] = dbi_result_get_uint(res, "pl_revoke_op");
			sp->priv[g][SP_PL_REVOKE_AUTOOP] = dbi_result_get_uint(res, "pl_revoke_autoop");
			sp->priv[g][SP_PL_REVOKE_CA] = dbi_result_get_uint(res, "pl_revoke_ca");
			sp->priv[g][SP_PL_REVOKE_SA] = dbi_result_get_uint(res, "pl_revoke_sa");

			sp->priv[g][SP_PL_ALLOW_SELF_REG] = dbi_result_get_uint(res, "pl_allow_self_reg");
			sp->priv[g][SP_PL_DEL_REGISTRATION] = dbi_result_get_uint(res, "pl_del_registration");

			sp->priv[g][SP_OTHER_CH_COMMANDER] = dbi_result_get_uint(res, "other_ch_commander");
			sp->priv[g][SP_OTHER_CH_KICK] = dbi_result_get_uint(res, "other_ch_kick");
			sp->priv[g][SP_OTHER_SV_KICK] = dbi_result_get_uint(res, "other_sv_kick");
			sp->priv[g][SP_OTHER_TEXT_PL] = dbi_result_get_uint(res, "other_text_pl");
			sp->priv[g][SP_OTHER_TEXT_ALL_CH] = dbi_result_get_uint(res, "other_text_all_ch");
			sp->priv[g][SP_OTHER_TEXT_IN_CH] = dbi_result_get_uint(res, "other_text_in_ch");
			sp->priv[g][SP_OTHER_TEXT_ALL] = dbi_result_get_uint(res, "other_text_all");
		}
		dbi_result_free(res);
	}
	return 1;
}
Example #18
0
static void _bind_helper_uint(_field_binding_t *binding) {
  *(unsigned int *)binding->bindto = dbi_result_get_uint((dbi_result)binding->result, binding->fieldname);
}
Example #19
0
unsigned int dbi_result_get_fields(dbi_result Result, const char *format, ...) {
  char **tokens, **fieldnames;
  unsigned int curidx = 0, numtokens = 0, uflag;
  va_list ap;

  if (!RESULT) return DBI_FIELD_ERROR;

  numtokens = _parse_field_formatstr(format, &tokens, &fieldnames);

  if (numtokens == DBI_FIELD_ERROR) {
    return numtokens;
  }
	
  va_start(ap, format);
  while (curidx < numtokens) {
    uflag = strlen(tokens[curidx]) > 1 && tokens[curidx][0] == 'u';
    switch (tokens[curidx][strlen(tokens[curidx])-1]) {
    case 'c': /* char */
      if (uflag) /* unsigned */
        *va_arg(ap, unsigned char *) = dbi_result_get_uchar(Result, fieldnames[curidx]);
      else
        *va_arg(ap, char *) = dbi_result_get_char(Result, fieldnames[curidx]);
      break;
    case 'h': /* sHort ("S"tring was taken) */
      if (uflag) /* unsigned */
        *va_arg(ap, unsigned short *) = dbi_result_get_ushort(Result, fieldnames[curidx]);
      else
        *va_arg(ap, short *) = dbi_result_get_short(Result, fieldnames[curidx]);
      break;
    case 'l': /* 4-byte integer (both l and i work) */
    case 'i':
      if (uflag) /* unsigned */
        *va_arg(ap, unsigned int *) = dbi_result_get_uint(Result, fieldnames[curidx]);
      else
        *va_arg(ap, int *) = dbi_result_get_int(Result, fieldnames[curidx]);
      break;
    case 'L': /* long long */
      if (uflag) /* unsigned */
        *va_arg(ap, unsigned long long *) = dbi_result_get_ulonglong(Result, fieldnames[curidx]);
      else
        *va_arg(ap, long long *) = dbi_result_get_longlong(Result, fieldnames[curidx]);
      break;
    case 'f': /* float */
      *va_arg(ap, float *) = dbi_result_get_float(Result, fieldnames[curidx]); 
      break;
    case 'd': /* double */
      *va_arg(ap, double *) = dbi_result_get_double(Result, fieldnames[curidx]); 
      break;
    case 's': /* string */
      *va_arg(ap, const char **) = dbi_result_get_string(Result, fieldnames[curidx]); 
      break;
    case 'b': /* binary */
      *va_arg(ap, const unsigned char **) = dbi_result_get_binary(Result, fieldnames[curidx]); 
      break;
    case 'S': /* string copy */
      *va_arg(ap, char **) = dbi_result_get_string_copy(Result, fieldnames[curidx]); 
      break;
    case 'B': /* binary copy */
      *va_arg(ap, unsigned char **) = dbi_result_get_binary_copy(Result, fieldnames[curidx]); 
      break;
    case 'm': /* datetiMe (what... you have any better ideas?? */
      *va_arg(ap, time_t *) = dbi_result_get_datetime(Result, fieldnames[curidx]);
      break;
    }
    curidx++;
  }
  va_end(ap);

  _free_string_list(tokens, numtokens);
  _free_string_list(fieldnames, numtokens);
  return numtokens;
}
Example #20
0
unsigned int dbi_result_get_ulong(dbi_result Result, const char *fieldname) {
  return dbi_result_get_uint(Result, fieldname);
}