void dict_load_fp(const char *dict_name, VSTREAM *fp) { const char *myname = "dict_load_fp"; VSTRING *buf; char *member; char *val; int lineno; const char *err; struct stat st; DICT *dict; /* * Instantiate the dictionary even if the file is empty. */ DICT_FIND_FOR_UPDATE(dict, dict_name); buf = vstring_alloc(100); lineno = 0; if (fstat(vstream_fileno(fp), &st) < 0) msg_fatal("fstat %s: %m", VSTREAM_PATH(fp)); while (readlline(buf, fp, &lineno)) { if ((err = split_nameval(STR(buf), &member, &val)) != 0) msg_fatal("%s, line %d: %s: \"%s\"", VSTREAM_PATH(fp), lineno, err, STR(buf)); if (msg_verbose > 1) msg_info("%s: %s = %s", myname, member, val); if (dict->update(dict, member, val) != 0) msg_fatal("%s, line %d: unable to update %s:%s", VSTREAM_PATH(fp), lineno, dict->type, dict->name); } vstring_free(buf); dict->owner.uid = st.st_uid; dict->owner.status = (st.st_uid != 0); }
int dict_update(const char *dict_name, const char *member, const char *value) { const char *myname = "dict_update"; DICT *dict; DICT_FIND_FOR_UPDATE(dict, dict_name); if (msg_verbose > 1) msg_info("%s: %s = %s", myname, member, value); return (dict->update(dict, member, value)); }
void dict_load_fp(const char *dict_name, VSTREAM *fp) { const char *myname = "dict_load_fp"; VSTRING *buf; char *member; char *val; const char *old; int old_lineno; int lineno; const char *err; struct stat st; DICT *dict; /* * Instantiate the dictionary even if the file is empty. */ DICT_FIND_FOR_UPDATE(dict, dict_name); buf = vstring_alloc(100); old_lineno = lineno = 0; if (fstat(vstream_fileno(fp), &st) < 0) msg_fatal("fstat %s: %m", VSTREAM_PATH(fp)); for ( /* void */ ; readlline(buf, fp, &lineno); old_lineno = lineno) { if ((err = split_nameval(STR(buf), &member, &val)) != 0) msg_fatal("%s, line %s: %s: \"%s\"", VSTREAM_PATH(fp), format_line_number((VSTRING *) 0, old_lineno + 1, lineno), err, STR(buf)); if (msg_verbose > 1) msg_info("%s: %s = %s", myname, member, val); if ((old = dict->lookup(dict, member)) != 0 && strcmp(old, val) != 0) msg_warn("%s, line %d: overriding earlier entry: %s=%s", VSTREAM_PATH(fp), lineno, member, old); if (dict->update(dict, member, val) != 0) msg_fatal("%s, line %d: unable to update %s:%s", VSTREAM_PATH(fp), lineno, dict->type, dict->name); } vstring_free(buf); dict->owner.uid = st.st_uid; dict->owner.status = (st.st_uid != 0); }