#include "meta.h" /* * This file contains fops for the files and directories in * an xlator directory */ /* /.meta/xlators/.../type */ int32_t meta_xlator_type_readv (call_frame_t *frame, xlator_t *this, dict_t *fd, size_t size, off_t offset) { meta_private_t *priv = (meta_private_t *) this->private; meta_dirent_t *root = priv->tree; data_t *path_data = dict_get (fd, this->name); if (path_data) { const char *path = data_to_str (path_data); meta_dirent_t *file = lookup_meta_entry (root, path, NULL); xlator_t *view_xlator = file->view_xlator; int type_size; type_size = strlen (view_xlator->type); struct iovec vec; vec.iov_base = view_xlator->type + offset; vec.iov_len = min (type_size - offset, size); STACK_UNWIND (frame, vec.iov_len, 0, &vec, 1); return 0;
auth_result_t gf_auth (dict_t *input_params, dict_t *config_params) { auth_result_t result = AUTH_DONT_CARE; int ret = 0; data_t *allow_user = NULL; data_t *username_data = NULL; data_t *passwd_data = NULL; data_t *password_data = NULL; char *username = NULL; char *password = NULL; char *brick_name = NULL; char *searchstr = NULL; char *username_str = NULL; char *tmp = NULL; char *username_cpy = NULL; username_data = dict_get (input_params, "username"); if (!username_data) { gf_log ("auth/login", GF_LOG_DEBUG, "username not found, returning DONT-CARE"); goto out; } username = data_to_str (username_data); password_data = dict_get (input_params, "password"); if (!password_data) { gf_log ("auth/login", GF_LOG_WARNING, "password not found, returning DONT-CARE"); goto out; } password = data_to_str (password_data); brick_name = data_to_str (dict_get (input_params, "remote-subvolume")); if (!brick_name) { gf_log ("auth/login", GF_LOG_ERROR, "remote-subvolume not specified"); result = AUTH_REJECT; goto out; } ret = gf_asprintf (&searchstr, "auth.login.%s.allow", brick_name); if (-1 == ret) { gf_log ("auth/login", GF_LOG_WARNING, "asprintf failed while setting search string, " "returning DONT-CARE"); goto out; } allow_user = dict_get (config_params, searchstr); GF_FREE (searchstr); if (allow_user) { username_cpy = gf_strdup (allow_user->data); if (!username_cpy) goto out; username_str = strtok_r (username_cpy, " ,", &tmp); while (username_str) { if (!fnmatch (username_str, username, 0)) { ret = gf_asprintf (&searchstr, "auth.login.%s.password", username); if (-1 == ret) { gf_log ("auth/login", GF_LOG_WARNING, "asprintf failed while setting search string"); goto out; } passwd_data = dict_get (config_params, searchstr); GF_FREE (searchstr); if (!passwd_data) { gf_log ("auth/login", GF_LOG_ERROR, "wrong username/password combination"); result = AUTH_REJECT; goto out; } result = !((strcmp (data_to_str (passwd_data), password)) ? AUTH_ACCEPT : AUTH_REJECT); if (result == AUTH_REJECT) gf_log ("auth/login", GF_LOG_ERROR, "wrong password for user %s", username); break; } username_str = strtok_r (NULL, " ,", &tmp); } } out: if (username_cpy) GF_FREE (username_cpy); return result; }
TransitionCanvas * TransitionCanvas::read(char * & st, UmlCanvas * canvas, char * k) { if (!strcmp(k, "transitioncanvas_ref")) return ((TransitionCanvas *) dict_get(read_id(st), "transitioncanvas", canvas)); else if (!strcmp(k, "transitioncanvas")) { int id = read_id(st); BrowserTransition * br = BrowserTransition::read_ref(st); TransitionData * tr = (TransitionData *) br->get_data(); LineGeometry geo; bool fixed = FALSE; k = read_keyword(st); if (! strcmp(k, "geometry")) { geo = line_geometry(read_keyword(st)); k = read_keyword(st); if (! strcmp(k, "unfixed")) k = read_keyword(st); else fixed = TRUE; } else geo = NoGeometry; float dbegin; float dend; if (! strcmp(k, "decenter_begin")) { dbegin = read_double(st) / 1000; k = read_keyword(st); } else dbegin = -1; if (! strcmp(k, "decenter_end")) { dend = read_double(st) / 1000; k = read_keyword(st); } else dend = -1; unread_keyword(k, st); read_keyword(st, "from"); read_keyword(st, "ref"); DiagramItem * bi = dict_get(read_id(st), "canvas", canvas); BrowserNode * b = tr->get_start_node(); QString s = br->get_name(); TransitionCanvas * first = 0; TransitionCanvas * result; LabelCanvas * label; LabelCanvas * stereotype; double z; for (;;) { read_keyword(st, "z"); z = read_double(st); k = read_keyword(st); if ((label = LabelCanvas::read(st, canvas, k)) != 0) { // the transition name can't be empty label->setZ(z); k = read_keyword(st); } if (!strcmp(k, "stereotype")) { (void) read_string(st); read_keyword(st, "xyz"); int x = (int) read_double(st); int y = (int) read_double(st); if ((tr == 0) || (*(tr->get_stereotype()) == 0)) { stereotype = 0; read_double(st); // z } else { stereotype = new LabelCanvas(QString("<<") + toUnicode(tr->get_short_stereotype()) + ">>", canvas, x, y); stereotype->setZ(read_double(st)); } k = read_keyword(st); } else stereotype = 0; if (strcmp(k, "to")) wrong_keyword(k, "to"); DiagramItem * di; if (strcmp(k = read_keyword(st), "ref")) { di = ArrowPointCanvas::read(st, canvas, k); if (di == 0) unknown_keyword(k); } else di = dict_get(read_id(st), "statecanvas/pseudostate", canvas); // do not give tr to not call update() result = new TransitionCanvas(canvas, bi, di, b, id, dbegin, dend); result->geometry = geo; result->fixed_geometry = fixed; result->set_z(z); result->data = tr; connect(tr, SIGNAL(changed()), result, SLOT(modified())); connect(tr, SIGNAL(deleted()), result, SLOT(deleted())); if (first == 0) { first = result; if (read_file_format() == 30) // to remove redondant transitions made by release 2.22 RelsToCheck.append(result); } if (label != 0) result->label = label; if (stereotype != 0) (result->stereotype = stereotype)->show(); result->show(); if (di->type() != UmlArrowPoint) break; bi = di; read_keyword(st, "line"); id = read_id(st); } read_keyword(st, "write_horizontally"); result->write_horizontally = state(read_keyword(st)); k = read_keyword(st); if (!strcmp(k, "show_definition")) { result->show_definition = state(read_keyword(st)); k = read_keyword(st); } if (strcmp(k, "drawing_language")) wrong_keyword(k, "drawing_language"); result->drawing_language = ::drawing_language(read_keyword(st)); result->propagate_drawing_settings(); if (read_file_format() >= 58) { // stereotype property k = read_keyword(st); first->stereotypeproperties = StereotypePropertiesCanvas::read(st, canvas, k, first); if (first->stereotypeproperties != 0) k = read_keyword(st); if (strcmp(k, "end")) wrong_keyword(k, "end"); } // to add label, stereotype ... if needed first->update(FALSE); if (first != result) result->update(FALSE); first->check_stereotypeproperties(); // manage case where the relation is deleted but present in the browser if (result->data->get_start()->deletedp()) RelsToDel.append(result); else result->update_geometry(); return result; } else return 0; }
UcClassCanvas * UcClassCanvas::read(char * & st, UmlCanvas * canvas, char * k) { if (!strcmp(k, "classcanvas_ref")) return ((UcClassCanvas *) dict_get(read_id(st), "classcanvas", canvas)); else if (!strcmp(k, "classcanvas")) { int id = read_id(st); BrowserNode * br = BrowserClass::read_ref(st); UcClassCanvas * result; if (read_file_format() < 52) { read_keyword(st, "xyz"); int x = (int) read_double(st); result = new UcClassCanvas(br, canvas, x, (int) read_double(st), id); result->setZ(read_double(st)); // move the actor in its initial position x = ACTOR_CANVAS_SIZE - result->width(); if (x < 0) result->Q3CanvasRectangle::moveBy(x/2, 0); k = read_keyword(st); read_double(st); read_double(st); if (!strcmp(k, "label_xyz")) // old version read_double(st); else if (strcmp(k, "label_xy")) wrong_keyword(k, "label_xy/label_xyz"); } else { result = new UcClassCanvas(canvas, id); result->browser_node = br; connect(br->get_data(), SIGNAL(changed()), result, SLOT(modified())); connect(br->get_data(), SIGNAL(deleted()), result, SLOT(deleted())); k = read_keyword(st); result->settings.read(st, k); // updates k read_color(st, "color", result->itscolor, k); // updates k if (strcmp(k, "xyz")) wrong_keyword(k, "xyz"); read_xyz(st, result); result->compute_size(); if ((read_file_format() < 72) && (result->used_view_mode == asInterface)) { result->settings.class_drawing_mode = asClass; result->compute_size(); } if (read_file_format() >= 58) { k = read_keyword(st); result->read_stereotype_property(st, k); if (strcmp(k, "end")) wrong_keyword(k, "end"); } } result->set_center100(); result->show(); result->check_stereotypeproperties(); return result; } else return 0; }
mCfg *mms_cfg_read(Octstr *file) { Octstr *sf; List *lines; int i, n; mCfg *cfg; mCfgGrp *grp = NULL; int skip = 0; gw_assert(file); if ((sf = octstr_read_file(octstr_get_cstr(file))) == NULL) { error(errno, "failed to read config from `%s'", octstr_get_cstr(file)); return NULL; } cfg = gw_malloc(sizeof *cfg); cfg->file = octstr_duplicate(file); cfg->grps = dict_create(7, NULL); lines = octstr_split(sf, octstr_imm("\n")); for (i = 0, n = gwlist_len(lines); i < n; i++) { Octstr *current = gwlist_get(lines,i); int pos; octstr_strip_blanks(current); if (octstr_len(current) == 0) { /* end of group. */ grp = NULL; skip = 0; continue; } else if (skip || octstr_get_char(current, 0) == '#') continue; if ((pos = octstr_search_char(current, '=',0)) > 0) { /* a field name. first see if start of grp */ Octstr *field = octstr_copy(current,0,pos); Octstr *value = octstr_copy(current,pos+1,octstr_len(current)); octstr_strip_blanks(field); fixup_value(value, i+1); #if 0 info(0, "field/value: [%s - %s]", octstr_get_cstr(field), octstr_get_cstr(value)); #endif if (octstr_case_compare(field, octstr_imm("group")) == 0) if (grp == NULL) { /* grp name. */ int ismulti = is_multigroup(value); if (ismulti < 0) { info(0, "Skipping unknown group `%s' at line %d of conf file", octstr_get_cstr(value), i+1); skip = 1; } else { grp = gw_malloc(sizeof *grp); grp->name = octstr_duplicate(value); grp->fields = dict_create(23, (void (*)(void *))octstr_destroy); if (ismulti) { List *l = dict_get(cfg->grps, value); if (l == NULL) { l = gwlist_create(); dict_put(cfg->grps, value, l); } gwlist_append(l, grp); } else if (dict_put_once(cfg->grps, value, grp) == 0) panic(0, "Group `%s' [at line %d] cannot appear more " "than once in config!", octstr_get_cstr(value), i+1); } } else panic(0,"`group' is an illegal field name " "within a group at line %d in config file!", i+1); else if (grp) /* an ordinary field name. */ check_and_add_field(grp, field, value,i+1); else panic(0, "A group must begin with a `group = group_name' " "clause [at line %d in config file]", i+1); octstr_destroy(field); octstr_destroy(value); } else panic(0, "mal-formed entry in conf file at line %d!", i+1); } gwlist_destroy(lines, (gwlist_item_destructor_t *)octstr_destroy); octstr_destroy(sf); return cfg; }
static struct config * config_load(const char *path) { struct config *conf; FILE *fp; size_t flen; char *key, *value, *buf, *lbuf; const char *e; long long ll; lbuf = NULL; conf = calloc(1, sizeof(*conf)); if (conf == NULL) { log_warn("warn: table-mysql: calloc"); return (NULL); } dict_init(&conf->conf); dict_init(&conf->sources); conf->source_refresh = DEFAULT_REFRESH; conf->source_expire = DEFAULT_EXPIRE; fp = fopen(path, "r"); if (fp == NULL) { log_warn("warn: table-mysql: fopen"); goto end; } while ((buf = fgetln(fp, &flen))) { if (buf[flen - 1] == '\n') buf[flen - 1] = '\0'; else { lbuf = malloc(flen + 1); if (lbuf == NULL) { log_warn("warn: table-mysql: malloc"); goto end; } memcpy(lbuf, buf, flen); lbuf[flen] = '\0'; buf = lbuf; } key = buf; while (isspace((unsigned char)*key)) ++key; if (*key == '\0' || *key == '#') continue; value = key; strsep(&value, " \t:"); if (value) { while (*value) { if (!isspace((unsigned char)*value) && !(*value == ':' && isspace((unsigned char)*(value + 1)))) break; ++value; } if (*value == '\0') value = NULL; } if (value == NULL) { log_warnx("warn: table-mysql: missing value for key %s", key); goto end; } if (dict_check(&conf->conf, key)) { log_warnx("warn: table-mysql: duplicate key %s", key); goto end; } value = strdup(value); if (value == NULL) { log_warn("warn: table-mysql: malloc"); goto end; } dict_set(&conf->conf, key, value); } if ((value = dict_get(&conf->conf, "fetch_source_expire"))) { e = NULL; ll = strtonum(value, 0, INT_MAX, &e); if (e) { log_warnx("warn: table-mysql: bad value for fetch_source_expire: %s", e); goto end; } conf->source_expire = ll; } if ((value = dict_get(&conf->conf, "fetch_source_refresh"))) { e = NULL; ll = strtonum(value, 0, INT_MAX, &e); if (e) { log_warnx("warn: table-mysql: bad value for fetch_source_refresh: %s", e); goto end; } conf->source_refresh = ll; } free(lbuf); fclose(fp); return (conf); end: free(lbuf); if (fp) fclose(fp); config_free(conf); return (NULL); }
char *cmap_map(char *c) { int i = dict_get(cmap, c); return i >= 0 ? cmap_dst[i] : c; }
PseudoStateCanvas * PseudoStateCanvas::read(char * & st, UmlCanvas * canvas, char * k) { if (!strcmp(k, "pseudostatecanvas_ref")) return ((PseudoStateCanvas *) dict_get(read_id(st), "PseudoStateCanvas", canvas)); else if (!strcmp(k, "pseudostatecanvas")) { int id = read_id(st); BrowserPseudoState * ps = BrowserPseudoState::read_ref(st); PseudoStateCanvas * result = new PseudoStateCanvas(canvas, id); result->browser_node = ps; connect(ps->get_data(), SIGNAL(changed()), result, SLOT(modified())); connect(ps->get_data(), SIGNAL(deleted()), result, SLOT(deleted())); connect(DrawingSettings::instance(), SIGNAL(changed()), result, SLOT(modified())); k = read_keyword(st); if (!strcmp(k, "horizontal")) { result->horiz = TRUE; k = read_keyword(st); } if (!strcmp(k, "xyzwh")) { read_xyzwh(st, result); result->manual_size = TRUE; } else if (strcmp(k, "xyz")) wrong_keyword(k, "xyz"); else read_xyz(st, result); if (!ps->allow_empty()) { result->label = new LabelCanvas(ps->get_name(), canvas, 0, 0); read_keyword(st, "label_xy"); read_xy(st, result->label); result->label->setZ(result->z()); result->label->set_center100(); } if (read_file_format() >= 58) { k = read_keyword(st); result->read_stereotype_property(st, k); // updates k if (strcmp(k, "end")) wrong_keyword(k, "end"); } result->set_xpm(); if (result->manual_size) { result->width_scale100 = result->width(); result->height_scale100 = result->height(); } result->set_center100(); result->show(); result->check_stereotypeproperties(); if (canvas->paste()) result->remove_if_already_present(); return result; } else return 0; }
ActivityActionCanvas * ActivityActionCanvas::read(char * & st, UmlCanvas * canvas, char * k) { if (!strcmp(k, "activityactioncanvas_ref")) return ((ActivityActionCanvas *) dict_get(read_id(st), "activitycanvas", canvas)); else if (!strcmp(k, "activityactioncanvas")) { int id = read_id(st); BrowserActivityAction * br = BrowserActivityAction::read_ref(st); ActivityActionCanvas * result = new ActivityActionCanvas(canvas, id); result->browser_node = br; connect(br->get_data(), SIGNAL(changed()), result, SLOT(modified())); connect(br->get_data(), SIGNAL(deleted()), result, SLOT(deleted())); k = read_keyword(st); result->settings.read(st, k); // updates k if (! strcmp(k, "show_opaque_action_definition")) { result->show_opaque_action_definition = state(read_keyword(st)); k = read_keyword(st); } read_color(st, "color", result->itscolor, k); // updates k if (!strcmp(k, "xyzwh")) read_xyzwh(st, result); else wrong_keyword(k, "xyzwh"); result->width_scale100 = result->width(); result->height_scale100 = result->height(); result->set_center100(); result->update(); result->show(); k = read_keyword(st); if (! strcmp(k, "pins")) { while (strcmp(k = read_keyword(st), "end") != 0) result->pins.append(PinCanvas::read(st, canvas, k, result)); k = read_keyword(st); } if (! strcmp(k, "parameter_sets")) { while (strcmp(k = read_keyword(st), "end") != 0) result->paramsets.append(ParameterSetCanvas::read(st, canvas, k, result)); k = read_keyword(st); } if (! strcmp(k, "pre")) { k = read_keyword(st); result->pre = InfoCanvas::read(st, canvas, k, result); k = read_keyword(st); } if (! strcmp(k, "post")) { k = read_keyword(st); result->post = InfoCanvas::read(st, canvas, k, result); k = read_keyword(st); } if (! strcmp(k, "constraint")) { k = read_keyword(st); result->constraint = InfoCanvas::read(st, canvas, k, result); k = read_keyword(st); } result->read_stereotype_property(st, k); // updates k if (strcmp(k, "end")) wrong_keyword(k, "end"); result->check_pins(); result->check_parametersets(); result->check_conditions_constraint(); result->check_stereotypeproperties(); if (canvas->paste()) result->remove_if_already_present(); return result; } else return 0; }
static Octstr *store_file_status(int status_type) { char *frmt; Octstr *ret, *key; unsigned long l; struct tm tm; Msg *msg; List *keys; char id[UUID_STR_LEN + 1]; ret = octstr_create(""); /* set the type based header */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret, "<table border=1>\n" "<tr><td>SMS ID</td><td>Type</td><td>Time</td><td>Sender</td><td>Receiver</td>" "<td>SMSC ID</td><td>BOX ID</td><td>UDH</td><td>Message</td>" "</tr>\n"); } else if (status_type == BBSTATUS_TEXT) { octstr_append_cstr(ret, "[SMS ID] [Type] [Time] [Sender] [Receiver] [SMSC ID] [BOX ID] [UDH] [Message]\n"); } /* if there is no store-file, then don't loop in sms_store */ if (filename == NULL) goto finish; keys = dict_keys(sms_dict); for (l = 0; l < gwlist_len(keys); l++) { key = gwlist_get(keys, l); msg = dict_get(sms_dict, key); if (msg == NULL) continue; if (msg_type(msg) == sms) { if (status_type == BBSTATUS_HTML) { frmt = "<tr><td>%s</td><td>%s</td>" "<td>%04d-%02d-%02d %02d:%02d:%02d</td>" "<td>%s</td><td>%s</td><td>%s</td>" "<td>%s</td><td>%s</td><td>%s</td></tr>\n"; } else if (status_type == BBSTATUS_XML) { frmt = "<message>\n\t<id>%s</id>\n\t<type>%s</type>\n\t" "<time>%04d-%02d-%02d %02d:%02d:%02d</time>\n\t" "<sender>%s</sender>\n\t" "<receiver>%s</receiver>\n\t<smsc-id>%s</smsc-id>\n\t" "<box-id>%s</box-id>\n\t" "<udh-data>%s</udh-data>\n\t<msg-data>%s</msg-data>\n\t" "</message>\n"; } else { frmt = "[%s] [%s] [%04d-%02d-%02d %02d:%02d:%02d] [%s] [%s] [%s] [%s] [%s] [%s]\n"; } /* transform the time value */ #if LOG_TIMESTAMP_LOCALTIME tm = gw_localtime(msg->sms.time); #else tm = gw_gmtime(msg->sms.time); #endif if (msg->sms.udhdata) octstr_binary_to_hex(msg->sms.udhdata, 1); if (msg->sms.msgdata && (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 || (msg->sms.coding == DC_UNDEF && msg->sms.udhdata))) octstr_binary_to_hex(msg->sms.msgdata, 1); uuid_unparse(msg->sms.id, id); octstr_format_append(ret, frmt, id, (msg->sms.sms_type == mo ? "MO" : msg->sms.sms_type == mt_push ? "MT-PUSH" : msg->sms.sms_type == mt_reply ? "MT-REPLY" : msg->sms.sms_type == report_mo ? "DLR-MO" : msg->sms.sms_type == report_mt ? "DLR-MT" : ""), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""), (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""), (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""), (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""), (msg->sms.udhdata ? octstr_get_cstr(msg->sms.udhdata) : ""), (msg->sms.msgdata ? octstr_get_cstr(msg->sms.msgdata) : "")); if (msg->sms.udhdata) octstr_hex_to_binary(msg->sms.udhdata); if (msg->sms.msgdata && (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 || (msg->sms.coding == DC_UNDEF && msg->sms.udhdata))) octstr_hex_to_binary(msg->sms.msgdata); } } gwlist_destroy(keys, octstr_destroy_item); finish: /* set the type based footer */ if (status_type == BBSTATUS_HTML) { octstr_append_cstr(ret,"</table>"); } return ret; }
static int config_connect(struct config *conf) { static const struct { const char *name; const char *default_query; } qspec[SQL_MAX] = { { "query_alias", "GET alias:%s" }, { "query_domain", "GET domain:%s" }, { "query_credentials", "GET credentials:%s" }, { "query_netaddr", "GET netaddr:%s" }, { "query_userinfo", "GET userinfo:%s" }, { "query_source", "GET source:%s" }, { "query_mailaddr", "GET mailaddr:%s" }, { "query_addrname", "GET addrname:%s" }, }; size_t i; char *host; int port; char *q; char *value; const char *e; long long ll; host = "127.0.0.1"; port = 6379; log_debug("debug: table-redis: (re)connecting"); /* Disconnect first, if needed */ config_reset(conf); if ((value = dict_get(&conf->conf, "host"))) host = value; if ((value = dict_get(&conf->conf, "port"))) { e = NULL; ll = strtonum(value, 0, 65535, &e); if (e) { log_warnx("warn: table-redis: bad value for port: %s", e); goto end; } port = ll; } conf->db = redisConnect(host, port); if (conf->db == NULL) { log_warnx("warn: table-redis: redisConnect return NULL"); goto end; } for (i = 0; i < SQL_MAX; i++) { q = dict_get(&conf->conf, qspec[i].name); if (q) conf->statements[i] = strdup(q); else conf->statements[i] = strdup(qspec[i].default_query); } log_debug("debug: table-redis: connected"); return (1); end: config_reset(conf); return (0); }
int match_hostaddr(MATCH_LIST *list, const char *addr, const char *pattern) { const char *myname = "match_hostaddr"; char *saved_patt; CIDR_MATCH match_info; DICT *dict; VSTRING *err; int rc; if (msg_verbose) msg_info("%s: %s ~? %s", myname, addr, pattern); #define V4_ADDR_STRING_CHARS "01234567890." #define V6_ADDR_STRING_CHARS V4_ADDR_STRING_CHARS "abcdefABCDEF:" if (addr[strspn(addr, V6_ADDR_STRING_CHARS)] != 0) return (0); /* * Try dictionary lookup. This can be case insensitive. */ if (MATCH_DICTIONARY(pattern)) { if ((dict = dict_handle(pattern)) == 0) msg_panic("%s: unknown dictionary: %s", myname, pattern); if (dict_get(dict, addr) != 0) return (1); if ((list->error = dict->error) != 0) return (match_error(list, "%s:%s: table lookup problem", dict->type, dict->name)); return (0); } /* * Try an exact match with the host address. */ if (pattern[0] != '[') { if (strcasecmp(addr, pattern) == 0) return (1); } else { size_t addr_len = strlen(addr); if (strncasecmp(addr, pattern + 1, addr_len) == 0 && strcmp(pattern + 1 + addr_len, "]") == 0) return (1); } /* * Light-weight tests before we get into expensive operations. * * - Don't bother matching IPv4 against IPv6. Postfix transforms * IPv4-in-IPv6 to native IPv4 form when IPv4 support is enabled in * Postfix; if not, then Postfix has no business dealing with IPv4 * addresses anyway. * * - Don't bother unless the pattern is either an IPv6 address or net/mask. * * We can safely skip IPv4 address patterns because their form is * unambiguous and they did not match in the strcasecmp() calls above. * * XXX We MUST skip (parent) domain names, which may appear in NAMADR_LIST * input, to avoid triggering false cidr_match_parse() errors. * * The last two conditions below are for backwards compatibility with * earlier Postfix versions: don't abort with fatal errors on junk that * was silently ignored (principle of least astonishment). */ if (!strchr(addr, ':') != !strchr(pattern, ':') || pattern[strcspn(pattern, ":/")] == 0 || pattern[strspn(pattern, V4_ADDR_STRING_CHARS)] == 0 || pattern[strspn(pattern, V6_ADDR_STRING_CHARS "[]/")] != 0) return (0); /* * No escape from expensive operations: either we have a net/mask * pattern, or we have an address that can have multiple valid * representations (e.g., 0:0:0:0:0:0:0:1 versus ::1, etc.). The only way * to find out if the address matches the pattern is to transform * everything into to binary form, and to do the comparison there. */ saved_patt = mystrdup(pattern); err = cidr_match_parse(&match_info, saved_patt, (VSTRING *) 0); myfree(saved_patt); if (err != 0) { list->error = DICT_ERR_RETRY; rc = match_error(list, "%s", vstring_str(err)); vstring_free(err); return (rc); } return (cidr_match_execute(&match_info, addr) != 0); }
int match_hostname(MATCH_LIST *list, const char *name, const char *pattern) { const char *myname = "match_hostname"; const char *pd; const char *entry; const char *next; int match; DICT *dict; if (msg_verbose) msg_info("%s: %s ~? %s", myname, name, pattern); /* * Try dictionary lookup: exact match and parent domains. * * Don't look up parent domain substrings with regexp maps etc. */ if (MATCH_DICTIONARY(pattern)) { if ((dict = dict_handle(pattern)) == 0) msg_panic("%s: unknown dictionary: %s", myname, pattern); match = 0; for (entry = name; *entry != 0; entry = next) { if (entry == name || (dict->flags & DICT_FLAG_FIXED)) { match = (dict_get(dict, entry) != 0); if (msg_verbose > 1) msg_info("%s: lookup %s:%s %s: %s", myname, dict->type, dict->name, entry, match ? "found" : "notfound"); if (match != 0) break; if ((list->error = dict->error) != 0) return (match_error(list, "%s:%s: table lookup problem", dict->type, dict->name)); } if ((next = strchr(entry + 1, '.')) == 0) break; if (list->flags & MATCH_FLAG_PARENT) next += 1; } return (match); } /* * Try an exact match with the host name. */ if (strcasecmp(name, pattern) == 0) { return (1); } /* * See if the pattern is a parent domain of the hostname. */ else { if (list->flags & MATCH_FLAG_PARENT) { pd = name + strlen(name) - strlen(pattern); if (pd > name && pd[-1] == '.' && strcasecmp(pd, pattern) == 0) return (1); } else if (pattern[0] == '.') { pd = name + strlen(name) - strlen(pattern); if (pd > name && strcasecmp(pd, pattern) == 0) return (1); } } return (0); }
void dict_cache_control(DICT_CACHE *cp,...) { const char *myname = "dict_cache_control"; const char *last_done; time_t next_interval; int cache_cleanup_is_active = (cp->exp_validator && cp->exp_interval); va_list ap; int name; /* * Update the control settings. */ va_start(ap, cp); while ((name = va_arg(ap, int)) > 0) { switch (name) { case DICT_CACHE_CTL_END: break; case DICT_CACHE_CTL_FLAGS: cp->user_flags = va_arg(ap, int); cp->log_delay = (cp->user_flags & DICT_CACHE_FLAG_VERBOSE) ? 0 : DC_DEF_LOG_DELAY; break; case DICT_CACHE_CTL_INTERVAL: cp->exp_interval = va_arg(ap, int); if (cp->exp_interval < 0) msg_panic("%s: bad %s cache cleanup interval %d", myname, cp->name, cp->exp_interval); break; case DICT_CACHE_CTL_VALIDATOR: cp->exp_validator = va_arg(ap, DICT_CACHE_VALIDATOR_FN); break; case DICT_CACHE_CTL_CONTEXT: cp->exp_context = va_arg(ap, char *); break; default: msg_panic("%s: bad command: %d", myname, name); } } va_end(ap); /* * Schedule the cache cleanup thread. */ if (cp->exp_interval && cp->exp_validator) { /* * Sanity checks. */ if (cache_cleanup_is_active) msg_panic("%s: %s cache cleanup is already scheduled", myname, cp->name); /* * The next start time depends on the last completion time. */ #define NEXT_START(last, delta) ((delta) + (unsigned long) atol(last)) #define NOW (time((time_t *) 0)) /* NOT: event_time() */ if ((last_done = dict_get(cp->db, DC_LAST_CACHE_CLEANUP_COMPLETED)) == 0 || (next_interval = (NEXT_START(last_done, cp->exp_interval) - NOW)) < 0) next_interval = 0; if (next_interval > cp->exp_interval) next_interval = cp->exp_interval; if ((cp->user_flags & DICT_CACHE_FLAG_VERBOSE) && next_interval > 0) msg_info("%s cache cleanup will start after %ds", cp->name, (int) next_interval); event_request_timer(dict_cache_clean_event, (char *) cp, (int) next_interval); } /* * Cancel the cache cleanup thread. */ else if (cache_cleanup_is_active) { if (cp->retained || cp->dropped) dict_cache_clean_stat_log_reset(cp, "partial"); dict_cache_delete_behind_reset(cp); event_cancel_timer(dict_cache_clean_event, (char *) cp); } }
/* * Updates the internal RADIUS mapping tables. Returns 1 if the * mapping has been processes and the PDU should be proxied to the * remote RADIUS server, otherwise if it is a duplicate returns 0. */ static int update_tables(RADIUS_PDU *pdu) { Octstr *client_ip, *msisdn; Octstr *type, *session_id; int ret = 0; Octstr *rm_item; client_ip = msisdn = type = session_id = NULL; /* only add if we have a Accounting-Request PDU */ if (pdu->type == 0x04) { /* check if we have a START or STOP event */ type = dict_get(pdu->attr, octstr_imm("Acct-Status-Type")); /* get the sesion id */ session_id = dict_get(pdu->attr, octstr_imm("Acct-Session-Id")); /* grep the needed data */ client_ip = dict_get(pdu->attr, octstr_imm("Framed-IP-Address")); msisdn = dict_get(pdu->attr, octstr_imm("Calling-Station-Id")); /* we can't add mapping without both components */ if (client_ip == NULL || msisdn == NULL) { warning(0, "RADIUS: NAS did either not send 'Framed-IP-Address' or/and " "'Calling-Station-Id', dropping mapping but will forward."); /* anyway forward the packet to remote RADIUS server */ return 1; } if (octstr_compare(type, octstr_imm("1")) == 0 && session_id && msisdn) { /* session START */ if (dict_get(radius_table, client_ip) == NULL && dict_get(session_table, session_id) == NULL) { Octstr *put_msisdn = octstr_duplicate(msisdn); Octstr *put_client_ip = octstr_duplicate(client_ip); Octstr *put_session_id = octstr_duplicate(session_id); Octstr *old_session_id, *old_client_ip; /* ok, this is a new session. If it contains an IP that is still * in the session/client tables then remove the old session from the * two tables session/client */ if ((old_session_id = dict_get(client_table, client_ip)) != NULL && (old_client_ip = dict_get(session_table, old_session_id)) != NULL && octstr_compare(old_session_id, session_id) != 0) { rm_item = dict_remove(client_table, client_ip); octstr_destroy(rm_item); rm_item = dict_remove(session_table, old_session_id); octstr_destroy(rm_item); octstr_destroy(old_session_id); octstr_destroy(old_client_ip); } /* insert both, new client IP and session to mapping tables */ dict_put(radius_table, client_ip, put_msisdn); dict_put(session_table, session_id, put_client_ip); dict_put(client_table, client_ip, put_session_id); info(0, "RADIUS: Mapping `%s <-> %s' for session id <%s> added.", octstr_get_cstr(client_ip), octstr_get_cstr(msisdn), octstr_get_cstr(session_id)); ret = 1; } else { warning(0, "RADIUS: Duplicate mapping `%s <-> %s' for session " "id <%s> received, ignoring.", octstr_get_cstr(client_ip), octstr_get_cstr(msisdn), octstr_get_cstr(session_id)); } } else if (octstr_compare(type, octstr_imm("2")) == 0) { /* session STOP */ Octstr *comp_client_ip; if ((msisdn = dict_get(radius_table, client_ip)) != NULL && (comp_client_ip = dict_get(session_table, session_id)) != NULL && octstr_compare(client_ip, comp_client_ip) == 0) { dict_remove(radius_table, client_ip); rm_item = dict_remove(client_table, client_ip); octstr_destroy(rm_item); dict_remove(session_table, session_id); info(0, "RADIUS: Mapping `%s <-> %s' for session id <%s> removed.", octstr_get_cstr(client_ip), octstr_get_cstr(msisdn), octstr_get_cstr(session_id)); octstr_destroy(msisdn); octstr_destroy(comp_client_ip); ret = 1; } else { warning(0, "RADIUS: Could not find mapping for `%s' session " "id <%s>, ignoring.", octstr_get_cstr(client_ip), octstr_get_cstr(session_id)); } } else { error(0, "RADIUS: unknown Acct-Status-Type `%s' received, ignoring.", octstr_get_cstr(type)); } } return ret; }
static int postalias_queries(VSTREAM *in, char **maps, const int map_count, const int dict_flags) { int found = 0; VSTRING *keybuf = vstring_alloc(100); DICT **dicts; const char *map_name; const char *value; int n; /* * Sanity check. */ if (map_count <= 0) msg_panic("postalias_queries: bad map count"); /* * Prepare to open maps lazily. */ dicts = (DICT **) mymalloc(sizeof(*dicts) * map_count); for (n = 0; n < map_count; n++) dicts[n] = 0; /* * Perform all queries. Open maps on the fly, to avoid opening unnecessary * maps. */ while (vstring_get_nonl(keybuf, in) != VSTREAM_EOF) { for (n = 0; n < map_count; n++) { if (dicts[n] == 0) dicts[n] = ((map_name = split_at(maps[n], ':')) != 0 ? dict_open3(maps[n], map_name, O_RDONLY, dict_flags) : dict_open3(var_db_type, maps[n], O_RDONLY, dict_flags)); if ((value = dict_get(dicts[n], STR(keybuf))) != 0) { if (*value == 0) { msg_warn("table %s:%s: key %s: empty string result is not allowed", dicts[n]->type, dicts[n]->name, STR(keybuf)); msg_warn("table %s:%s should return NO RESULT in case of NOT FOUND", dicts[n]->type, dicts[n]->name); } vstream_printf("%s: %s\n", STR(keybuf), value); found = 1; break; } if (dicts[n]->error) msg_fatal("table %s:%s: query error: %m", dicts[n]->type, dicts[n]->name); } } if (found) vstream_fflush(VSTREAM_OUT); /* * Cleanup. */ for (n = 0; n < map_count; n++) if (dicts[n]) dict_close(dicts[n]); myfree((void *) dicts); vstring_free(keybuf); return (found); }
void ca_imsg(struct mproc *p, struct imsg *imsg) { RSA *rsa; const void *from = NULL; unsigned char *to = NULL; struct msg m; const char *pkiname; size_t flen, tlen, padding; struct pki *pki; int ret = 0; uint64_t id; int v; if (p->proc == PROC_PARENT) { switch (imsg->hdr.type) { case IMSG_CONF_START: return; case IMSG_CONF_END: ca_init(); /* Start fulfilling requests */ mproc_enable(p_pony); return; } } if (p->proc == PROC_CONTROL) { switch (imsg->hdr.type) { case IMSG_CTL_VERBOSE: m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); log_verbose(v); return; case IMSG_CTL_PROFILE: m_msg(&m, imsg); m_get_int(&m, &v); m_end(&m); profiling = v; return; } } if (p->proc == PROC_PONY) { switch (imsg->hdr.type) { case IMSG_CA_PRIVENC: case IMSG_CA_PRIVDEC: m_msg(&m, imsg); m_get_id(&m, &id); m_get_string(&m, &pkiname); m_get_data(&m, &from, &flen); m_get_size(&m, &tlen); m_get_size(&m, &padding); m_end(&m); pki = dict_get(env->sc_pki_dict, pkiname); if (pki == NULL || pki->pki_pkey == NULL || (rsa = EVP_PKEY_get1_RSA(pki->pki_pkey)) == NULL) fatalx("ca_imsg: invalid pki"); if ((to = calloc(1, tlen)) == NULL) fatalx("ca_imsg: calloc"); switch (imsg->hdr.type) { case IMSG_CA_PRIVENC: ret = RSA_private_encrypt(flen, from, to, rsa, padding); break; case IMSG_CA_PRIVDEC: ret = RSA_private_decrypt(flen, from, to, rsa, padding); break; } m_create(p, imsg->hdr.type, 0, 0, -1); m_add_id(p, id); m_add_int(p, ret); if (ret > 0) m_add_data(p, to, (size_t)ret); m_close(p); free(to); RSA_free(rsa); return; } } errx(1, "ca_imsg: unexpected %s imsg", imsg_to_str(imsg->hdr.type)); }
} return ret; } static int32_t af_unix_client_bind (rpc_transport_t *this, struct sockaddr *sockaddr, socklen_t sockaddr_len, int sock) { data_t *path_data = NULL; struct sockaddr_un *addr = NULL; int32_t ret = 0; path_data = dict_get (this->options, "transport.socket.bind-path"); if (path_data) { char *path = data_to_str (path_data); if (!path || strlen (path) > UNIX_PATH_MAX) { gf_log (this->name, GF_LOG_TRACE, "bind-path not specified for unix socket, " "letting connect to assign default value"); goto err; } addr = (struct sockaddr_un *) sockaddr; strcpy (addr->sun_path, path); ret = bind (sock, (struct sockaddr *)addr, sockaddr_len); if (ret == -1) { gf_log (this->name, GF_LOG_ERROR, "cannot bind to unix-domain socket %d (%s)",
static int config_connect(struct config *conf) { static const struct { const char *name; int cols; } qspec[SQL_MAX] = { { "query_alias", 1 }, { "query_domain", 1 }, { "query_credentials", 2 }, { "query_netaddr", 1 }, { "query_userinfo", 3 }, { "query_source", 1 }, { "query_mailaddr", 1 }, { "query_addrname", 1 }, }; my_bool reconn; size_t i; char *host, *username, *password, *database, *q; log_debug("debug: table-mysql: (re)connecting"); /* Disconnect first, if needed */ config_reset(conf); host = dict_get(&conf->conf, "host"); username = dict_get(&conf->conf, "username"); database = dict_get(&conf->conf, "database"); password = dict_get(&conf->conf, "password"); conf->db = mysql_init(NULL); if (conf->db == NULL) { log_warnx("warn: table-mysql: mysql_init failed"); goto end; } reconn = 1; if (mysql_options(conf->db, MYSQL_OPT_RECONNECT, &reconn) != 0) { log_warnx("warn: table-mysql: mysql_options: %s", mysql_error(conf->db)); goto end; } if (!mysql_real_connect(conf->db, host, username, password, database, 0, NULL, 0)) { log_warnx("warn: table-mysql: mysql_real_connect: %s", mysql_error(conf->db)); goto end; } for (i = 0; i < SQL_MAX; i++) { q = dict_get(&conf->conf, qspec[i].name); if (q && (conf->statements[i] = table_mysql_prepare_stmt( conf->db, q, 1, qspec[i].cols)) == NULL) goto end; } q = dict_get(&conf->conf, "fetch_source"); if (q && (conf->stmt_fetch_source = table_mysql_prepare_stmt(conf->db, q, 0, 1)) == NULL) goto end; log_debug("debug: table-mysql: connected"); return (1); end: config_reset(conf); return (0); }
void dict_test(int argc, char **argv) { VSTRING *keybuf = vstring_alloc(1); VSTRING *inbuf = vstring_alloc(1); DICT *dict; char *dict_name; int open_flags; char *bufp; char *cmd; const char *key; const char *value; int ch; int dict_flags = DICT_FLAG_LOCK | DICT_FLAG_DUP_REPLACE; int n; int rc; signal(SIGPIPE, SIG_IGN); msg_vstream_init(argv[0], VSTREAM_ERR); while ((ch = GETOPT(argc, argv, "v")) > 0) { switch (ch) { default: usage(argv[0]); case 'v': msg_verbose++; break; } } optind = OPTIND; if (argc - optind < 2) usage(argv[0]); if (strcasecmp(argv[optind + 1], "create") == 0) open_flags = O_CREAT | O_RDWR | O_TRUNC; else if (strcasecmp(argv[optind + 1], "write") == 0) open_flags = O_RDWR; else if (strcasecmp(argv[optind + 1], "read") == 0) open_flags = O_RDONLY; else msg_fatal("unknown access mode: %s", argv[2]); for (n = 2; argv[optind + n]; n++) { if (strcasecmp(argv[optind + 2], "fold") == 0) dict_flags |= DICT_FLAG_FOLD_ANY; else if (strcasecmp(argv[optind + 2], "sync") == 0) dict_flags |= DICT_FLAG_SYNC_UPDATE; else usage(argv[0]); } dict_name = argv[optind]; dict_allow_surrogate = 1; dict = dict_open(dict_name, open_flags, dict_flags); dict_register(dict_name, dict); while (vstring_fgets_nonl(inbuf, VSTREAM_IN)) { bufp = vstring_str(inbuf); if (!isatty(0)) { vstream_printf("> %s\n", bufp); vstream_fflush(VSTREAM_OUT); } if (*bufp == '#') continue; if ((cmd = mystrtok(&bufp, " ")) == 0) { vstream_printf("usage: verbose|del key|get key|put key=value|first|next|masks|flags\n"); vstream_fflush(VSTREAM_OUT); continue; } if (dict_changed_name()) msg_warn("dictionary has changed"); key = *bufp ? vstring_str(unescape(keybuf, mystrtok(&bufp, " ="))) : 0; value = mystrtok(&bufp, " ="); if (strcmp(cmd, "verbose") == 0 && !key) { msg_verbose++; } else if (strcmp(cmd, "del") == 0 && key && !value) { if ((rc = dict_del(dict, key)) > 0) vstream_printf("%s: not found\n", key); else if (rc < 0) vstream_printf("%s: error\n", key); else vstream_printf("%s: deleted\n", key); } else if (strcmp(cmd, "get") == 0 && key && !value) { if ((value = dict_get(dict, key)) == 0) { vstream_printf("%s: %s\n", key, dict->error ? "error" : "not found"); } else { vstream_printf("%s=%s\n", key, value); } } else if (strcmp(cmd, "put") == 0 && key && value) { if (dict_put(dict, key, value) != 0) vstream_printf("%s: %s\n", key, dict->error ? "error" : "not updated"); else vstream_printf("%s=%s\n", key, value); } else if (strcmp(cmd, "first") == 0 && !key && !value) { if (dict_seq(dict, DICT_SEQ_FUN_FIRST, &key, &value) == 0) vstream_printf("%s=%s\n", key, value); else vstream_printf("%s\n", dict->error ? "error" : "not found"); } else if (strcmp(cmd, "next") == 0 && !key && !value) { if (dict_seq(dict, DICT_SEQ_FUN_NEXT, &key, &value) == 0) vstream_printf("%s=%s\n", key, value); else vstream_printf("%s\n", dict->error ? "error" : "not found"); } else if (strcmp(cmd, "flags") == 0 && !key && !value) { vstream_printf("dict flags %s\n", dict_flags_str(dict->flags)); } else if (strcmp(cmd, "masks") == 0 && !key && !value) { vstream_printf("DICT_FLAG_IMPL_MASK %s\n", dict_flags_str(DICT_FLAG_IMPL_MASK)); vstream_printf("DICT_FLAG_PARANOID %s\n", dict_flags_str(DICT_FLAG_PARANOID)); vstream_printf("DICT_FLAG_RQST_MASK %s\n", dict_flags_str(DICT_FLAG_RQST_MASK)); vstream_printf("DICT_FLAG_INST_MASK %s\n", dict_flags_str(DICT_FLAG_INST_MASK)); } else { vstream_printf("usage: del key|get key|put key=value|first|next|masks|flags\n"); } vstream_fflush(VSTREAM_OUT); } vstring_free(keybuf); vstring_free(inbuf); dict_close(dict); }
auth_result_t gf_auth (dict_t *input_params, dict_t *config_params) { auth_result_t result = AUTH_DONT_CARE; int ret = 0; data_t *allow_user = NULL; data_t *username_data = NULL; data_t *passwd_data = NULL; data_t *password_data = NULL; char *username = NULL; char *password = NULL; char *brick_name = NULL; char *searchstr = NULL; char *username_str = NULL; char *tmp = NULL; char *username_cpy = NULL; gf_boolean_t using_ssl = _gf_false; username_data = dict_get (input_params, "ssl-name"); if (username_data) { gf_log ("auth/login", GF_LOG_INFO, "connecting user name: %s", username_data->data); using_ssl = _gf_true; } else { username_data = dict_get (input_params, "username"); if (!username_data) { gf_log ("auth/login", GF_LOG_DEBUG, "username not found, returning DONT-CARE"); goto out; } password_data = dict_get (input_params, "password"); if (!password_data) { gf_log ("auth/login", GF_LOG_WARNING, "password not found, returning DONT-CARE"); goto out; } password = data_to_str (password_data); } username = data_to_str (username_data); brick_name = data_to_str (dict_get (input_params, "remote-subvolume")); if (!brick_name) { gf_log ("auth/login", GF_LOG_ERROR, "remote-subvolume not specified"); result = AUTH_REJECT; goto out; } ret = gf_asprintf (&searchstr, "auth.login.%s.%s", brick_name, using_ssl ? "ssl-allow" : "allow"); if (-1 == ret) { gf_log ("auth/login", GF_LOG_WARNING, "asprintf failed while setting search string, " "returning DONT-CARE"); goto out; } allow_user = dict_get (config_params, searchstr); GF_FREE (searchstr); if (allow_user) { gf_log ("auth/login", GF_LOG_INFO, "allowed user names: %s", allow_user->data); /* * There's a subtle difference between SSL and non-SSL behavior * if we can't match anything in the "while" loop below. * Intuitively, we should AUTH_REJECT if there's no match. * However, existing code depends on allowing untrusted users * to connect with *no credentials at all* by falling through * the loop. They're still distinguished from trusted users * who do provide a valid username and password (in fact that's * pretty much the only thing we use non-SSL login auth for), * but they are allowed to connect. It's wrong, but it's not * worth changing elsewhere. Therefore, we do the sane thing * only for SSL here. * * For SSL, if there's a list *you must be on it*. Note that * if there's no list we don't care. In that case (and the * ssl-allow=* case as well) authorization is effectively * disabled, though authentication and encryption are still * active. */ if (using_ssl) { result = AUTH_REJECT; } username_cpy = gf_strdup (allow_user->data); if (!username_cpy) goto out; username_str = strtok_r (username_cpy, " ,", &tmp); /* * We have to match a user's *authenticated* name to one in the * list. If we're using SSL, they're already authenticated. * Otherwise, they need a matching password to complete the * process. */ while (username_str) { if (!fnmatch (username_str, username, 0)) { if (using_ssl) { result = AUTH_ACCEPT; break; } ret = gf_asprintf (&searchstr, "auth.login.%s.password", username); if (-1 == ret) { gf_log ("auth/login", GF_LOG_WARNING, "asprintf failed while setting search string"); goto out; } passwd_data = dict_get (config_params, searchstr); GF_FREE (searchstr); if (!passwd_data) { gf_log ("auth/login", GF_LOG_ERROR, "wrong username/password combination"); result = AUTH_REJECT; goto out; } result = !((strcmp (data_to_str (passwd_data), password)) ? AUTH_ACCEPT : AUTH_REJECT); if (result == AUTH_REJECT) gf_log ("auth/login", GF_LOG_ERROR, "wrong password for user %s", username); break; } username_str = strtok_r (NULL, " ,", &tmp); } } out: GF_FREE (username_cpy); return result; }
OdClassInstCanvas * OdClassInstCanvas::read(char * & st, UmlCanvas * canvas, char * k) { if (!strcmp(k, "classinstance_ref")) return ((OdClassInstCanvas *) dict_get(read_id(st), "classinstance", canvas)); else if (!strcmp(k, "classinstance")) { // old release int id = read_id(st); BrowserClass * cl = BrowserClass::read_ref(st); k = read_keyword(st); UmlColor co = UmlDefaultColor; read_color(st, "color", co, k); // updates k Uml3States ho; if (!strcmp(k, "write_horizontally") || !strcmp(k, "write_horizontaly")) { ho = state(read_keyword(st)); k = read_keyword(st); } else ho = UmlDefaultState; if (strcmp(k, "xyz")) wrong_keyword(k, "xyz"); int x = (int) read_double(st); int y = (int) read_double(st); double z = read_double(st); read_keyword(st, "name"); BrowserNode * parent = canvas->browser_diagram()->container(UmlClass); BrowserClassInstance * icl = // create a new one, don't look at already exising instances // contrarilly to the collaboration and sequence diagram // because of attributes & relations new BrowserClassInstance(read_string(st), cl, parent); OdClassInstCanvas * result = new OdClassInstCanvas(icl, canvas, x, y, id); result->setZ(z); result->itscolor = co; result->write_horizontally = ho; result->show_context_mode = noContext; k = read_keyword(st); if (!strcmp(k, "values")) ((ClassInstanceData *) icl->get_data())->read_attributes(st, k); // updates k else if (strcmp(k, "end") && strcmp(k, "xyz")) wrong_keyword(k, "end or xyz"); if (*k == 'x') read_xyz(st, result); result->compute_size(); result->set_center100(); result->show(); // to save new instance and diagram def result->package_modified(); canvas->browser_diagram()->modified(); return result; } else if (!strcmp(k, "classinstancecanvas")) { int id = read_id(st); BrowserClassInstance * icl = BrowserClassInstance::read_ref(st); read_keyword(st, "xyz"); int x = (int) read_double(st); OdClassInstCanvas * result = new OdClassInstCanvas(icl, canvas, x, (int) read_double(st), id); result->setZ(read_double(st)); result->ClassInstCanvas::read(st, k); if (read_file_format() < 74) result->show_context_mode = noContext; result->read_stereotype_property(st, k); // updates k if (strcmp(k, "end")) wrong_keyword(k, "end"); if (result->get_type() != 0) { // not a deleted instance result->compute_size(); result->set_center100(); result->show(); result->check_stereotypeproperties(); } return result; } else return 0; }
void smpp_route_message_database(SMPPServer *smpp_server, int direction, Octstr *smsc_id, Octstr *system_id, Msg *msg, void(*callback)(void *context, int result, double cost), void *context) { SMPPRouting *smpp_routing = smpp_server->routing; List *routes; long i, num_routes; int found = 0; SMPPRoute *route; gw_rwlock_rdlock(smpp_routing->lock); if(msg_type(msg) == sms) { /* we can only route sms's */ if((direction == SMPP_ROUTE_DIRECTION_OUTBOUND) && octstr_len(system_id)) { /* Look for our ESME routes */ gw_rwlock_wrlock(smpp_routing->outbound_lock); routes = dict_get(smpp_routing->outbound_routes, system_id); if(!routes) { routes = smpp_database_get_routes(smpp_server, direction, system_id); dict_put(smpp_routing->outbound_routes, system_id, routes); } gw_rwlock_unlock(smpp_routing->outbound_lock); num_routes = gwlist_len(routes); for(i=0;i<num_routes;i++) { route = gwlist_get(routes, i); found = gw_regex_match_pre(route->regex, msg->sms.receiver); if(found) { break; } } if(found) { octstr_destroy(msg->sms.smsc_id); msg->sms.smsc_id = octstr_duplicate(route->smsc_id); debug("smpp.route.message.database", 0, "SMPP[%s] Found outbound route for %s towards %s", octstr_get_cstr(system_id), octstr_get_cstr(msg->sms.receiver), octstr_get_cstr(msg->sms.smsc_id)); callback(context, 1, route->cost); } else { callback(context, 0, 0); } } else if((direction == SMPP_ROUTE_DIRECTION_INBOUND) && octstr_len(smsc_id)) { routes = smpp_routing->inbound_routes; num_routes = gwlist_len(routes); for(i=0;i<num_routes;i++) { route = gwlist_get(routes, i); found = gw_regex_match_pre(route->regex, msg->sms.receiver); if(found) { break; } } if(found) { octstr_destroy(msg->sms.service); msg->sms.service = octstr_duplicate(route->system_id); debug("smpp.route.message.database", 0, "SMPP[%s] Found inbound route for %s from %s", octstr_get_cstr(route->system_id), octstr_get_cstr(msg->sms.receiver), octstr_get_cstr(smsc_id)); callback(context, 1, route->cost); } else { callback(context, 0, 0); } } else { callback(context, 0, 0); } } else { callback(context, 0, 0); } gw_rwlock_unlock(smpp_routing->lock); }
fts_doc_t *fts_get(fts_t *fts, robj *title) { return dict_get(fts->docs, title->ptr); }
hash_t *port_hash_init(list_t * ports_list, list_t * packages, conf_t * conf) { hash_t *self; dict_t *pkgmk_confs_exploded; port_t *port, *found, *package; unsigned i; int cmp; char *locked_version, *pkgmk_conf; assert(ports_list != NULL && packages != NULL && conf != NULL); pkgmk_confs_exploded = pkgmk_confs_explode(conf->pkgmk_confs, ports_list); self = hash_new_with_size(1000); for (i = 0; i < ports_list->length; i++) { port = list_get(ports_list, i); if ((pkgmk_conf = dict_get(pkgmk_confs_exploded, port->name)) != NULL) port->pkgmk_conf = xstrdup(pkgmk_conf); if (list_get_position(conf->never_install, strequ, port->name) != -1) port->status = PRT_NEVERINSTALL; if ((locked_version = dict_get(conf->locked_versions, port->name))) { if (!strcmp(port->version, locked_version)) hash_add(self, port->name, port); } else if (locked_version == NULL && (found = dict_get(conf->favourite_repositories, port->name)) != NULL) { if (strcmp(found->repository->name, port->repository->name) == 0) hash_add(self, port->name, port); } else if (!locked_version && !(found = hash_get(self, port->name))) hash_add(self, port->name, port); else if (!locked_version && port->repository->priority > found->repository->priority) hash_add(self, port->name, port); else if (!locked_version && port->repository->priority == found->repository->priority && strverscmp(port->version, found->version) > 0) hash_add(self, port->name, port); } for (i = 0; i < packages->length; i++) { package = list_get(packages, i); if (!(port = hash_get(self, package->name))) { hash_add(self, package->name, package); continue; } if(port->status == PRT_NEVERINSTALL) continue; if ((cmp = strverscmp(port->version, package->version)) > 0) port->status = PRT_OUTDATED; else if (cmp < 0) port->status = PRT_DIFF; else port->status = PRT_INSTALLED; } dict_free(pkgmk_confs_exploded, free); return self; }
START_TEST(test_uri_relative_file) _create_uri("file:some/path"); ck_assert_str_eq(uri -> scheme, "file"); ck_assert_str_eq(name_tostring_sep(uri -> path, "/"), "some/path"); END_TEST START_TEST(test_uri_absolute_file) _create_uri("file:/some/path"); ck_assert_str_eq(uri -> scheme, "file"); ck_assert_str_eq(name_tostring_sep(uri -> path, "/"), "//some/path"); END_TEST START_TEST(test_uri_query) _create_uri("http://localhost/some/url?param1=value1¶m2=value2"); ck_assert_str_eq((char *) dict_get(uri -> query, "param1"), "value1"); ck_assert_str_eq((char *) dict_get(uri -> query, "param2"), "value2"); END_TEST /* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */ void create_uri(void) { TCase *tc = tcase_create("URI"); tcase_add_checked_fixture(tc, NULL, _teardown); tcase_add_test(tc, test_uri_create); tcase_add_test(tc, test_uri_create_ipv4); tcase_add_test(tc, test_uri_create_localhost); tcase_add_test(tc, test_uri_create_localhost_8080); tcase_add_test(tc, test_uri_auth);